VirtualBox

source: vbox/trunk/src/VBox/Main/include/VirtualBoxClientImpl.h@ 106908

Last change on this file since 106908 was 106881, checked in by vboxsync, 3 months ago

Added gTrackedObjectsCollector initialization and uninitialization.

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