/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Ben Turner categoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr enumerator; rv = categoryManager->EnumerateCategory(aTopic, getter_AddRefs(enumerator)); if (NS_FAILED(rv)) return rv; nsCOMPtr entry; while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) { nsCOMPtr category = do_QueryInterface(entry, &rv); if (NS_SUCCEEDED(rv)) { nsCAutoString categoryEntry; rv = category->GetData(categoryEntry); nsXPIDLCString contractId; categoryManager->GetCategoryEntry(aTopic, categoryEntry.get(), getter_Copies(contractId)); if (NS_SUCCEEDED(rv)) { // If we see the word "service," in the beginning // of the contractId then we create it as a service // if not we do a createInstance nsCOMPtr startupInstance; if (Substring(contractId, 0, 8).EqualsLiteral("service,")) startupInstance = do_GetService(contractId.get() + 8, &rv); else startupInstance = do_CreateInstance(contractId, &rv); if (NS_SUCCEEDED(rv)) { // Try to QI to nsIObserver nsCOMPtr startupObserver = do_QueryInterface(startupInstance, &rv); if (NS_SUCCEEDED(rv)) { rv = startupObserver->Observe(nsnull, aTopic, nsnull); // mainly for debugging if you want to know if your observer worked. NS_ASSERTION(NS_SUCCEEDED(rv), "Startup Observer failed!\n"); } } else { #ifdef NS_DEBUG nsCAutoString warnStr("Cannot create startup observer : "); warnStr += contractId.get(); NS_WARNING(warnStr.get()); #endif } } } } return NS_OK; }