зеркало из https://github.com/mozilla/gecko-dev.git
Add nsService constructor that allows you to get a service by ProgID using the statically linked nsServiceManager API.
This commit is contained in:
Родитель
4256db97c8
Коммит
402b1dcdaa
|
@ -234,6 +234,17 @@ public:
|
|||
// if (NS_FAILED(rv)) return rv;
|
||||
// compMgr->RegisterComponent(...); // use the service
|
||||
// }
|
||||
//
|
||||
// Note that both NS_WITH_SERVICE and NS_WITH_SERVICE1 can be used with a
|
||||
// "progid" as well as a "clsid"; for example,
|
||||
//
|
||||
// nsresult rv;
|
||||
// NS_WITH_SERVICE(nsIObserverService,
|
||||
// observer,
|
||||
// "component://netscape/observer-service", /* or NS_OBSERVERSERVICE_PROGID */
|
||||
// &rv);
|
||||
//
|
||||
|
||||
|
||||
#define NS_WITH_SERVICE(T, var, cid, rvAddr) \
|
||||
nsService _serv##var(cid, T::GetIID(), rvAddr); \
|
||||
|
@ -280,6 +291,16 @@ public:
|
|||
(nsISupports**)&mService);
|
||||
}
|
||||
|
||||
nsService(const char* aProgID, const nsIID& aIID, nsresult *rv)
|
||||
: mService(0)
|
||||
{
|
||||
*rv = nsComponentManager::ProgIDToCLSID(aProgID, &mCID);
|
||||
if (NS_FAILED(*rv)) return;
|
||||
|
||||
*rv = nsServiceManager::GetService(mCID, aIID,
|
||||
(nsISupports**)&mService);
|
||||
}
|
||||
|
||||
~nsService() {
|
||||
if (mService) { // mService could be null if the constructor fails
|
||||
nsresult rv = NS_OK;
|
||||
|
|
Загрузка…
Ссылка в новой задаче