1 | /* $Id: VirtualBoxSDSImpl.h 69741 2017-11-18 04:04:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Global COM Class definition
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2015-2017 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 ____H_VIRTUALBOXSDSIMPL
|
---|
19 | #define ____H_VIRTUALBOXSDSIMPL
|
---|
20 |
|
---|
21 | #include "VirtualBoxSDSWrap.h"
|
---|
22 | #include "TokenWrap.h"
|
---|
23 |
|
---|
24 | #ifdef RT_OS_WINDOWS
|
---|
25 | # include "win/resource.h"
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * The MediumLockToken class automates cleanup of a Medium lock.
|
---|
30 | */
|
---|
31 | class ATL_NO_VTABLE VirtualBoxToken :
|
---|
32 | public TokenWrap
|
---|
33 | {
|
---|
34 | public:
|
---|
35 |
|
---|
36 | DECLARE_EMPTY_CTOR_DTOR(VirtualBoxToken)
|
---|
37 |
|
---|
38 | HRESULT FinalConstruct();
|
---|
39 | void FinalRelease();
|
---|
40 |
|
---|
41 | // public initializer/uninitializer for internal purposes only
|
---|
42 | HRESULT init(const std::wstring& wstrUserName);
|
---|
43 | void uninit();
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Fabrique method to create and initialize COM token object.
|
---|
47 | *
|
---|
48 | * @param aToken Pointer to result Token COM object.
|
---|
49 | * @param wstrUserName User name of client for that we create the token
|
---|
50 | */
|
---|
51 | static HRESULT CreateToken(ComPtr<IToken>& aToken, const std::wstring& wstrUserName);
|
---|
52 |
|
---|
53 | // Trace COM reference counting in debug mode
|
---|
54 | #ifdef RT_STRICT
|
---|
55 | virtual ULONG InternalAddRef();
|
---|
56 | virtual ULONG InternalRelease();
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | private:
|
---|
60 |
|
---|
61 | // wrapped IToken methods
|
---|
62 | HRESULT abandon(AutoCaller &aAutoCaller);
|
---|
63 | HRESULT dummy();
|
---|
64 |
|
---|
65 | // data
|
---|
66 | struct Data
|
---|
67 | {
|
---|
68 | std::wstring wstrUserName;
|
---|
69 | };
|
---|
70 |
|
---|
71 | Data m;
|
---|
72 | };
|
---|
73 |
|
---|
74 | class ATL_NO_VTABLE VirtualBoxSDS :
|
---|
75 | public VirtualBoxSDSWrap
|
---|
76 | #ifdef RT_OS_WINDOWS
|
---|
77 | , public ATL::CComCoClass<VirtualBoxSDS, &CLSID_VirtualBoxSDS>
|
---|
78 | #endif
|
---|
79 | {
|
---|
80 | public:
|
---|
81 |
|
---|
82 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxSDS)
|
---|
83 |
|
---|
84 | //DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
|
---|
85 |
|
---|
86 | // Kind of redundant (VirtualBoxSDSWrap declares itself not aggregatable
|
---|
87 | // and CComCoClass<VirtualBoxSDS, &CLSID_VirtualBoxSDS> as aggregatable,
|
---|
88 | // the former is the first inheritance), but the C multiple inheritance
|
---|
89 | // rules and the class factory in VBoxSDS.cpp needs this to disambiguate.
|
---|
90 | DECLARE_NOT_AGGREGATABLE(VirtualBoxSDS)
|
---|
91 |
|
---|
92 | DECLARE_EMPTY_CTOR_DTOR(VirtualBoxSDS)
|
---|
93 |
|
---|
94 | HRESULT FinalConstruct();
|
---|
95 | void FinalRelease();
|
---|
96 |
|
---|
97 | // public initializers/uninitializers for internal purposes only
|
---|
98 | HRESULT init();
|
---|
99 | void uninit();
|
---|
100 |
|
---|
101 | private:
|
---|
102 |
|
---|
103 | // Wrapped IVirtualBoxSDS properties
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Returns the instance of VirtualBox for client.
|
---|
107 | * It impersonates client and returns his VirtualBox instance
|
---|
108 | * either from cahce or makes new one.
|
---|
109 | */
|
---|
110 | HRESULT getVirtualBox(ComPtr<IVirtualBox> &aVirtualBox, ComPtr<IToken> &aToken);
|
---|
111 |
|
---|
112 | /* SDS plan B interfaces: */
|
---|
113 | HRESULT registerVBoxSVC(const ComPtr<IVBoxSVC> &aVBoxSVC, LONG aPid, ComPtr<IUnknown> &aExistingVirtualBox);
|
---|
114 | HRESULT deregisterVBoxSVC(const ComPtr<IVBoxSVC> &aVBoxSVC, LONG aPid);
|
---|
115 |
|
---|
116 | // Wrapped IVirtualBoxSDS methods
|
---|
117 |
|
---|
118 | // Inner methods
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Gets the current user name of current thread
|
---|
122 | */
|
---|
123 | int GetCurrentUserName(std::wstring& wstrUserName);
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Prints current user name of this thread to the log
|
---|
127 | * @param prefix string fragment that will be inserted at the beginning
|
---|
128 | * of the logging line
|
---|
129 | */
|
---|
130 | void LogUserName(char *prefix);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Thread that periodically checks items in cache and cleans obsolete items
|
---|
134 | */
|
---|
135 | static DWORD WINAPI CheckCacheThread(LPVOID);
|
---|
136 |
|
---|
137 | // data fields
|
---|
138 | class VirtualBoxCache;
|
---|
139 | static VirtualBoxCache m_cache;
|
---|
140 | friend VirtualBoxToken;
|
---|
141 |
|
---|
142 | #ifdef VBOX_WITH_SDS_PLAN_B
|
---|
143 | // quick and dirty for checking the concept.
|
---|
144 | ComPtr<IVBoxSVC> m_ptrVBoxSVC;
|
---|
145 | ComPtr<IVBoxSVC> m_ptrOtherVBoxSVC;
|
---|
146 | #endif
|
---|
147 | };
|
---|
148 |
|
---|
149 |
|
---|
150 | #endif // !____H_VIRTUALBOXSDSIMPL
|
---|
151 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|