VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/xpcom/module.cpp@ 66891

Last change on this file since 66891 was 62258, checked in by vboxsync, 8 years ago

Main/VirtualBoxClient: Turn into a proper COM/XPCOM singleton object. Destruction is currently pretty late and might be better handled differently, but it seems to work as intended.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette