Changeset 69731 in vbox for trunk/src/VBox/Main/src-server/win
- Timestamp:
- Nov 17, 2017 9:41:44 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 119127
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/svcmain.cpp
r69729 r69731 27 27 28 28 #include "VirtualBoxImpl.h" 29 #ifdef VBOX_WITH_SDS_PLAN_B 30 # include "VBoxSVCWrap.h" 31 #endif 29 32 #include "Logging.h" 30 33 … … 139 142 140 143 #ifdef VBOX_WITH_SDS_PLAN_B 144 class VBoxSVC; 141 145 142 146 /** … … 150 154 /** Tri state: 0=uninitialized or initializing; 1=success; -1=failure. 151 155 * This will be updated after both m_hrcCreate and m_pObj have been set. */ 152 volatile int32_t m_iState;156 volatile int32_t m_iState; 153 157 /** The result of the instantiation attempt. */ 154 HRESULT m_hrcCreate;158 HRESULT m_hrcCreate; 155 159 /** The IUnknown of the VirtualBox object/interface we're working with. */ 156 IUnknown *m_pObj; 160 IUnknown *m_pObj; 161 /** Pointer to the IVBoxSVC implementation that VBoxSDS works with. */ 162 ComObjPtr<VBoxSVC> m_ptrVBoxSVC; 163 /** The VBoxSDS interface. */ 164 ComPtr<IVirtualBoxSDS> m_ptrVirtualBoxSDS; 157 165 158 166 public: … … 172 180 STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void **ppvObj); 173 181 174 / / IVBoxSVC175 STDMETHOD(GetVirtualBox)(IUnknown **ppOtherObj);182 /** Worker for VBoxSVC::getVirtualBox. */ 183 HRESULT i_getVirtualBox(ComPtr<IUnknown> &aResult); 176 184 177 185 private: … … 181 189 182 190 191 /** 192 * The VBoxSVC class is handed to VBoxSDS so it can call us back and ask for the 193 * VirtualBox object when the next VBoxSVC for this user registers itself. 194 */ 195 class ATL_NO_VTABLE VBoxSVC : public VBoxSVCWrap 196 { 197 public: 198 DECLARE_EMPTY_CTOR_DTOR(VBoxSVC) 199 200 HRESULT FinalConstruct() 201 { 202 return BaseFinalConstruct(); 203 } 204 205 void FinalRelease() 206 { 207 uninit(); 208 BaseFinalRelease(); 209 } 210 211 // public initializer/uninitializer for internal purposes only 212 HRESULT init(VirtualBoxClassFactory *pFactory) 213 { 214 AutoInitSpan autoInitSpan(this); 215 AssertReturn(autoInitSpan.isOk(), E_FAIL); 216 217 m_pFactory = pFactory; 218 219 autoInitSpan.setSucceeded(); 220 return S_OK; 221 } 222 223 void uninit() 224 { 225 AutoUninitSpan autoUninitSpan(this); 226 if (!autoUninitSpan.uninitDone()) 227 m_pFactory = NULL; 228 } 229 230 private: 231 // Wrapped IVBoxSVC method. 232 HRESULT getVirtualBox(ComPtr<IUnknown> &aResult) 233 { 234 if (m_pFactory) 235 return m_pFactory->i_getVirtualBox(aResult); 236 return E_FAIL; 237 } 238 239 public: 240 /** Pointer to the factory. */ 241 VirtualBoxClassFactory *m_pFactory; 242 }; 243 244 DEFINE_EMPTY_CTOR_DTOR(VBoxSVC); 245 246 183 247 HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox) 184 248 { 249 /* 250 * Connect to VBoxSDS. 251 */ 252 ComPtr<IVirtualBoxSDS> m_ptrVirtualBoxSDS; 253 HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxSDS, NULL, CLSCTX_LOCAL_SERVER, IID_IVirtualBoxSDS, 254 (void **)m_ptrVirtualBoxSDS.asOutParam()); 255 if (SUCCEEDED(hrc)) 256 { 257 /* 258 * Create VBoxSVC object and hand that to VBoxSDS. 259 */ 260 hrc = m_ptrVBoxSVC.createObject(); 261 if (SUCCEEDED(hrc)) 262 { 263 hrc = m_ptrVBoxSVC->init(this); 264 if (SUCCEEDED(hrc)) 265 { 266 hrc = m_ptrVirtualBoxSDS->RegisterVBoxSVC(m_ptrVBoxSVC, GetCurrentProcessId(), ppOtherVirtualBox); 267 if (SUCCEEDED(hrc)) 268 { 269 return hrc; 270 } 271 } 272 } 273 } 274 m_ptrVirtualBoxSDS.setNull(); 275 m_ptrVBoxSVC.setNull(); 185 276 *ppOtherVirtualBox = NULL; 186 return S_OK;277 return hrc; 187 278 } 188 279 … … 194 285 195 286 196 STDMETHODIMP VirtualBoxClassFactory::GetVirtualBox(IUnknown **ppUnkVirtualBox)287 HRESULT VirtualBoxClassFactory::i_getVirtualBox(ComPtr<IUnknown> &aResult) 197 288 { 198 289 IUnknown *pObj = m_pObj; … … 201 292 /** @todo Do we need to do something regarding server locking? Hopefully COM 202 293 * deals with that........... */ 203 pObj->AddRef(); 204 *ppUnkVirtualBox = pObj; 294 aResult = pObj; 205 295 Log(("VirtualBoxClassFactory::GetVirtualBox: S_OK - %p\n", pObj)); 206 296 return S_OK; 207 297 } 208 *ppUnkVirtualBox = NULL;298 aResult.setNull(); 209 299 Log(("VirtualBoxClassFactory::GetVirtualBox: E_FAIL\n")); 210 300 return E_FAIL;
Note:
See TracChangeset
for help on using the changeset viewer.