mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 22:07:41 +00:00
Add CallCreateInstance and CallGetService. b=87735 r=jaggernaut sr=scc
This commit is contained in:
parent
17bc9725da
commit
1758134ebc
@ -281,6 +281,63 @@ do_CreateInstanceFromCategory( const char *aCategory, const char *aEntry,
|
||||
return nsCreateInstanceFromCategory(aCategory, aEntry, aOuter, aErrorPtr);
|
||||
}
|
||||
|
||||
// type-safe shortcuts for calling |CreateInstance|
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aClass, aDelegate,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const nsCID &aClass,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aClass, nsnull,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const char *aContractID,
|
||||
nsISupports *aDelegate,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aContractID, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aContractID, aDelegate,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const char *aContractID,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aContractID, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aContractID, nsnull,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
/* keys for registry use */
|
||||
extern const char xpcomKeyName[];
|
||||
extern const char xpcomComponentsKeyName[];
|
||||
|
@ -318,6 +318,37 @@ do_GetServiceFromCategory( const char* category, const char* entry,
|
||||
return nsGetServiceFromCategory(category, entry, 0, error);
|
||||
}
|
||||
|
||||
// type-safe shortcuts for calling |GetService|
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallGetService( const nsCID &aClass,
|
||||
DestinationType** aDestination,
|
||||
nsIShutdownListener* shutdownListener = nsnull)
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsServiceManager::GetService(aClass,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(nsISupports**, aDestination),
|
||||
shutdownListener);
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallGetService( const char *aContractID,
|
||||
DestinationType** aDestination,
|
||||
nsIShutdownListener* shutdownListener = nsnull)
|
||||
{
|
||||
NS_PRECONDITION(aContractID, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsServiceManager::GetService(aContractID,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(nsISupports**, aDestination),
|
||||
shutdownListener);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// NS_WITH_SERVICE: macro to make using services easier.
|
||||
//
|
||||
@ -326,7 +357,15 @@ do_GetServiceFromCategory( const char* category, const char* entry,
|
||||
//
|
||||
// NOTE: ReleaseService() is OBSOLETE.
|
||||
//
|
||||
// Now you can replace this:
|
||||
// NOTE: NS_WITH_SERVICE is deprecated. This:
|
||||
// {
|
||||
// nsCOMPtr<nsIMyService> service( do_GetService(NS_MYSERVICE_CONTRACTID, &rv) );
|
||||
// if (NS_FAILED(rv)) return rv;
|
||||
// service->Doit(...); // use my service
|
||||
// }
|
||||
// is preferred over either of the blocks of code below.
|
||||
//
|
||||
// Back when NS_WITH_SERVICE wasn't deprecated you could replace this:
|
||||
// {
|
||||
// nsIMyService* service;
|
||||
// rv = nsServiceManager::GetService(kMyServiceCID, NS_GET_IID(nsIMyService),
|
||||
|
@ -281,6 +281,63 @@ do_CreateInstanceFromCategory( const char *aCategory, const char *aEntry,
|
||||
return nsCreateInstanceFromCategory(aCategory, aEntry, aOuter, aErrorPtr);
|
||||
}
|
||||
|
||||
// type-safe shortcuts for calling |CreateInstance|
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aClass, aDelegate,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const nsCID &aClass,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aClass, nsnull,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const char *aContractID,
|
||||
nsISupports *aDelegate,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aContractID, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aContractID, aDelegate,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const char *aContractID,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aContractID, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aContractID, nsnull,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
/* keys for registry use */
|
||||
extern const char xpcomKeyName[];
|
||||
extern const char xpcomComponentsKeyName[];
|
||||
|
Loading…
x
Reference in New Issue
Block a user