1 | /* $Id: VirtualBoxClientImpl.h 107588 2025-01-09 11:04:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Header file for the VirtualBoxClient (IVirtualBoxClient) class, VBoxC.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2024 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 | #ifndef MAIN_INCLUDED_VirtualBoxClientImpl_h
|
---|
29 | #define MAIN_INCLUDED_VirtualBoxClientImpl_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "VirtualBoxClientWrap.h"
|
---|
35 | #include "EventImpl.h"
|
---|
36 | #include "VirtualBoxTranslator.h"
|
---|
37 | #ifdef VBOX_WITH_MAIN_OBJECT_TRACKER
|
---|
38 | # include "ObjectsTracker.h"
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #ifdef RT_OS_WINDOWS
|
---|
42 | # include "win/resource.h"
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | class ATL_NO_VTABLE VirtualBoxClient :
|
---|
46 | public VirtualBoxClientWrap
|
---|
47 | #ifdef RT_OS_WINDOWS
|
---|
48 | , public ATL::CComCoClass<VirtualBoxClient, &CLSID_VirtualBoxClient>
|
---|
49 | #endif
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxClient)
|
---|
53 |
|
---|
54 | // Do not use any ATL registry support.
|
---|
55 | //DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
|
---|
56 |
|
---|
57 | DECLARE_NOT_AGGREGATABLE(VirtualBoxClient)
|
---|
58 |
|
---|
59 | HRESULT FinalConstruct();
|
---|
60 | void FinalRelease();
|
---|
61 |
|
---|
62 | // public initializer/uninitializer for internal purposes only
|
---|
63 | HRESULT init();
|
---|
64 | void uninit();
|
---|
65 |
|
---|
66 | #ifdef RT_OS_WINDOWS
|
---|
67 | /* HACK ALERT! Implemented in dllmain.cpp. */
|
---|
68 | ULONG InternalRelease();
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | private:
|
---|
72 | // wrapped IVirtualBoxClient properties
|
---|
73 | virtual HRESULT getVirtualBox(ComPtr<IVirtualBox> &aVirtualBox);
|
---|
74 | virtual HRESULT getSession(ComPtr<ISession> &aSession);
|
---|
75 | virtual HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
76 |
|
---|
77 | // wrapped IVirtualBoxClient methods
|
---|
78 | virtual HRESULT checkMachineError(const ComPtr<IMachine> &aMachine);
|
---|
79 |
|
---|
80 | /** Instance counter for simulating something similar to a singleton.
|
---|
81 | * Only the first instance will be a usable object, all additional
|
---|
82 | * instances will return a failure at creation time and will not work. */
|
---|
83 | static uint32_t g_cInstances;
|
---|
84 |
|
---|
85 | #ifdef RT_OS_WINDOWS
|
---|
86 | virtual HRESULT i_investigateVirtualBoxObjectCreationFailure(HRESULT hrc);
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | #ifdef VBOX_WITH_SDS
|
---|
90 | int i_getServiceAccountAndStartType(const wchar_t *pwszServiceName,
|
---|
91 | wchar_t *pwszAccountName, size_t cwcAccountName, uint32_t *puStartType);
|
---|
92 | #endif
|
---|
93 |
|
---|
94 | static DECLCALLBACK(int) SVCWatcherThread(RTTHREAD ThreadSelf, void *pvUser);
|
---|
95 |
|
---|
96 | struct Data
|
---|
97 | {
|
---|
98 | Data()
|
---|
99 | : m_ThreadWatcher(NIL_RTTHREAD)
|
---|
100 | , m_SemEvWatcher(NIL_RTSEMEVENT)
|
---|
101 | #ifdef VBOX_WITH_MAIN_NLS
|
---|
102 | , m_pVBoxTranslator(NULL)
|
---|
103 | , m_pTrComponent(NULL)
|
---|
104 | #endif
|
---|
105 | #ifdef VBOX_WITH_MAIN_OBJECT_TRACKER
|
---|
106 | , m_objectTrackerTask(NULL)
|
---|
107 | #endif
|
---|
108 | {}
|
---|
109 |
|
---|
110 | ~Data()
|
---|
111 | {
|
---|
112 | /* HACK ALERT! This is for DllCanUnloadNow(). */
|
---|
113 | if (m_pEventSource.isNotNull())
|
---|
114 | {
|
---|
115 | s_cUnnecessaryAtlModuleLocks--;
|
---|
116 | AssertMsg(s_cUnnecessaryAtlModuleLocks == 0, ("%d\n", s_cUnnecessaryAtlModuleLocks));
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | ComPtr<IVirtualBox> m_pVirtualBox;
|
---|
121 | ComPtr<IToken> m_pToken;
|
---|
122 | const ComObjPtr<EventSource> m_pEventSource;
|
---|
123 | ComPtr<IEventSource> m_pVBoxEventSource;
|
---|
124 | ComPtr<IEventListener> m_pVBoxEventListener;
|
---|
125 |
|
---|
126 | RTTHREAD m_ThreadWatcher;
|
---|
127 | RTSEMEVENT m_SemEvWatcher;
|
---|
128 | #ifdef VBOX_WITH_MAIN_NLS
|
---|
129 | VirtualBoxTranslator *m_pVBoxTranslator;
|
---|
130 | PTRCOMPONENT m_pTrComponent;
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | #ifdef VBOX_WITH_MAIN_OBJECT_TRACKER
|
---|
134 | ObjectTracker *m_objectTrackerTask;
|
---|
135 | #endif
|
---|
136 | };
|
---|
137 |
|
---|
138 | Data mData;
|
---|
139 |
|
---|
140 | public:
|
---|
141 | /** Hack for discounting the AtlModule lock held by Data::m_pEventSource during
|
---|
142 | * DllCanUnloadNow(). This is incremented to 1 when init() initialized
|
---|
143 | * m_pEventSource and is decremented by the Data destructor (above). */
|
---|
144 | static LONG s_cUnnecessaryAtlModuleLocks;
|
---|
145 |
|
---|
146 | #ifdef VBOX_WITH_MAIN_NLS
|
---|
147 | HRESULT i_reloadApiLanguage();
|
---|
148 | HRESULT i_registerEventListener();
|
---|
149 | void i_unregisterEventListener();
|
---|
150 | #endif
|
---|
151 | };
|
---|
152 |
|
---|
153 | #endif /* !MAIN_INCLUDED_VirtualBoxClientImpl_h */
|
---|
154 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|