nsIServiceManager 编辑

xpcom/components/nsIServiceManager.idlScriptable This interface provides a means to obtain global services in an application. The service manager depends on the repository to find and instantiate factories to obtain services. Inherits from: nsISupports Last changed in Gecko 1.0

Method overview

void getService(in nsCIDRef aClass, in nsIIDRef aIID, [iid_is(aIID),retval] out nsQIResult result);
void getServiceByContractID(in string aContractID, in nsIIDRef aIID, [iid_is(aIID),retval] out nsQIResult result);
boolean isServiceInstantiated(in nsCIDRef aClass, in nsIIDRef aIID);
boolean isServiceInstantiatedByContractID(in string aContractID, in nsIIDRef aIID);

Methods

getService()

This method returns a reference to a particular XPCOM service given the ClassID of the service. Unlike createInstance, this will always return the same object each time it is called with the same arguments.

void getService(
  in nsCIDRef aClass,
  in nsIIDRef aIID,
  [iid_is(aIID),retval] out nsQIResult result
);
Parameters
aClass
The ClassID of the service that is being requested.
aIID
The interface type to be returned.
result
The resulting interface pointer.
Exceptions thrown
NS_ERROR_FACTORY_NOT_REGISTERED
Indicates that the specified class is not registered.

getServiceByContractID()

This method returns a reference to a particular XPCOM service given the ContractID of the service.

void getServiceByContractID(
  in string aContractID,
  in nsIIDRef aIID,
  [iid_is(aIID),retval] out nsQIResult result
);
Parameters
aContractID
The ContractID of the service that is being requested.
aIID
The interface type to be returned.
result
The resulting interface pointer.
Exceptions thrown
NS_ERROR_FACTORY_NOT_REGISTERED
Indicates that the specified class is not registered.

isServiceInstantiated()

This method tests whether or not a XPCOM service, identified by ClassID, has been instantiated.

boolean isServiceInstantiated(
  in nsCIDRef aClass,
  in nsIIDRef aIID
);
Parameters
aClass
The ClassID of the service that is being tested.
aIID
The interface type to be tested.
Return value

true if the service has already been created.

Exceptions thrown
NS_ERROR_SERVICE_NOT_AVAILABLE
Indicates that the service hasn't been instantiated.
NS_NOINTERFACE
Indicates that the IID given isn't supported.

isServiceInstantiatedByContractID()

This method tests whether or not a XPCOM service, identified by ContractID, has been instantiated.

boolean isServiceInstantiatedByContractID(
  in string aContractID,
  in nsIIDRef aIID
);
Parameters
aContractID
The ContractID of the service that is being tested.
aIID
The interface type to be tested.
Return value

true if the service has already been created.

Exceptions thrown
NS_ERROR_SERVICE_NOT_AVAILABLE
Indicates that the service hasn't been instantiated.
NS_NOINTERFACE
Indicates that the IID given isn't supported.

Remarks

The service manager depends on the repository to find and instantiate factories to obtain services.

Because services are instantiated lazily, methods are provided to test whether or not a service has already been instantiated.

Users of the service manager must first obtain a pointer to the global service manager by calling NS_GetServiceManager. After that, they can request specific services by calling getService(). When they are finished they should call nsISupports.release() on the service as they would with any interface pointer. In some language bindings, such as JavaScript, this step is unnecessary. And, moreover such languages typically offer more convenient mechanisms to acquire references to XPCOM services and components.

A user of a service may keep references to services until application shutdown.

This interface was frozen for Gecko 1.0. See bug 99147 for details. From Gecko 2.0 interfaces are no longer frozen.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:47 次

字数:7688

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文