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