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