1 | /** @file
|
---|
2 | *
|
---|
3 | * XPCOM module implementation functions
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2014 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Make sure all the stdint.h macros are included - must come first! */
|
---|
19 | #ifndef __STDC_LIMIT_MACROS
|
---|
20 | # define __STDC_LIMIT_MACROS
|
---|
21 | #endif
|
---|
22 | #ifndef __STDC_CONSTANT_MACROS
|
---|
23 | # define __STDC_CONSTANT_MACROS
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #include <nsIGenericFactory.h>
|
---|
27 |
|
---|
28 | // generated file
|
---|
29 | #include "VirtualBox_XPCOM.h"
|
---|
30 |
|
---|
31 | #include "SessionImpl.h"
|
---|
32 | #include "VirtualBoxClientImpl.h"
|
---|
33 | #include "RemoteUSBDeviceImpl.h"
|
---|
34 | #include "USBDeviceImpl.h"
|
---|
35 |
|
---|
36 | #include "Logging.h"
|
---|
37 |
|
---|
38 | // XPCOM glue code unfolding
|
---|
39 |
|
---|
40 | #ifndef VBOX_COM_INPROC_API_CLIENT
|
---|
41 | NS_DECL_CLASSINFO(RemoteUSBDevice)
|
---|
42 | NS_IMPL_THREADSAFE_ISUPPORTS2_CI(RemoteUSBDevice, IHostUSBDevice, IUSBDevice)
|
---|
43 | #endif /* VBOX_COM_INPROC_API_CLIENT */
|
---|
44 |
|
---|
45 | /*
|
---|
46 | * Declare extern variables here to tell the compiler that
|
---|
47 | * NS_DECL_CLASSINFO(SessionWrap)
|
---|
48 | * already exists in the VBoxAPIWrap library.
|
---|
49 | */
|
---|
50 | NS_DECL_CI_INTERFACE_GETTER(SessionWrap)
|
---|
51 | extern nsIClassInfo *NS_CLASSINFO_NAME(SessionWrap);
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * Declare extern variables here to tell the compiler that
|
---|
55 | * NS_DECL_CLASSINFO(VirtualBoxClientWrap)
|
---|
56 | * already exists in the VBoxAPIWrap library.
|
---|
57 | */
|
---|
58 | NS_DECL_CI_INTERFACE_GETTER(VirtualBoxClientWrap)
|
---|
59 | extern nsIClassInfo *NS_CLASSINFO_NAME(VirtualBoxClientWrap);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Singleton class factory that holds a reference to the created instance
|
---|
63 | * (preventing it from being destroyed) until the module is explicitly
|
---|
64 | * unloaded by the XPCOM shutdown code.
|
---|
65 | *
|
---|
66 | * Suitable for IN-PROC components.
|
---|
67 | */
|
---|
68 | class SessionClassFactory : public Session
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | virtual ~SessionClassFactory() {
|
---|
72 | FinalRelease();
|
---|
73 | instance = 0;
|
---|
74 | }
|
---|
75 | static nsresult getInstance (Session **inst) {
|
---|
76 | int rv = NS_OK;
|
---|
77 | if (instance == 0) {
|
---|
78 | instance = new SessionClassFactory();
|
---|
79 | if (instance) {
|
---|
80 | instance->AddRef(); // protect FinalConstruct()
|
---|
81 | rv = instance->FinalConstruct();
|
---|
82 | if (NS_FAILED(rv))
|
---|
83 | instance->Release();
|
---|
84 | else
|
---|
85 | instance->AddRef(); // self-reference
|
---|
86 | } else {
|
---|
87 | rv = NS_ERROR_OUT_OF_MEMORY;
|
---|
88 | }
|
---|
89 | } else {
|
---|
90 | instance->AddRef();
|
---|
91 | }
|
---|
92 | *inst = instance;
|
---|
93 | return rv;
|
---|
94 | }
|
---|
95 | static nsresult releaseInstance () {
|
---|
96 | if (instance)
|
---|
97 | instance->Release();
|
---|
98 | return NS_OK;
|
---|
99 | }
|
---|
100 |
|
---|
101 | private:
|
---|
102 | static Session *instance;
|
---|
103 | };
|
---|
104 |
|
---|
105 | /** @note this is for singleton; disabled for now */
|
---|
106 | //
|
---|
107 | //Session *SessionClassFactory::instance = 0;
|
---|
108 | //
|
---|
109 | //NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC (
|
---|
110 | // Session, SessionClassFactory::getInstance
|
---|
111 | //)
|
---|
112 |
|
---|
113 | NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC(Session)
|
---|
114 |
|
---|
115 | NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC(VirtualBoxClient)
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Component definition table.
|
---|
119 | * Lists all components defined in this module.
|
---|
120 | */
|
---|
121 | static const nsModuleComponentInfo components[] =
|
---|
122 | {
|
---|
123 | {
|
---|
124 | "Session component", // description
|
---|
125 | NS_SESSION_CID, NS_SESSION_CONTRACTID, // CID/ContractID
|
---|
126 | SessionConstructor, // constructor function
|
---|
127 | NULL, // registration function
|
---|
128 | NULL, // deregistration function
|
---|
129 | /** @note this is for singleton; disabled for now */
|
---|
130 | // SessionClassFactory::releaseInstance,
|
---|
131 | NULL, // destructor function
|
---|
132 | NS_CI_INTERFACE_GETTER_NAME(SessionWrap), // interfaces function
|
---|
133 | NULL, // language helper
|
---|
134 | &NS_CLASSINFO_NAME(SessionWrap) // global class info & flags
|
---|
135 | },
|
---|
136 | {
|
---|
137 | "VirtualBoxClient component", // description
|
---|
138 | NS_VIRTUALBOXCLIENT_CID, NS_VIRTUALBOXCLIENT_CONTRACTID, // CID/ContractID
|
---|
139 | VirtualBoxClientConstructor, // constructor function
|
---|
140 | NULL, // registration function
|
---|
141 | NULL, // deregistration function
|
---|
142 | NULL, // destructor function
|
---|
143 | NS_CI_INTERFACE_GETTER_NAME(VirtualBoxClientWrap), // interfaces function
|
---|
144 | NULL, // language helper
|
---|
145 | &NS_CLASSINFO_NAME(VirtualBoxClientWrap) // global class info & flags
|
---|
146 | },
|
---|
147 | };
|
---|
148 |
|
---|
149 | NS_IMPL_NSGETMODULE (VirtualBox_Client_Module, components)
|
---|
150 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|