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