Changeset 2976
- Timestamp:
- 06/01/07 15:47:51 (2 years ago)
- Files:
-
- trunk/include/VBox/com/com.h (modified) (3 diffs)
- trunk/include/VBox/com/defs.h (modified) (1 diff)
- trunk/include/VBox/com/ptr.h (modified) (11 diffs)
- trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp (modified) (1 diff)
- trunk/src/VBox/Frontends/VirtualBox/include/COMDefs.h (modified) (17 diffs)
- trunk/src/VBox/Frontends/VirtualBox/src/COMDefs.cpp (modified) (12 diffs)
- trunk/src/VBox/Main/VirtualBoxImpl.cpp (modified) (5 diffs)
- trunk/src/VBox/Main/glue/com.cpp (modified) (3 diffs)
- trunk/src/VBox/Main/glue/initterm.cpp (modified) (6 diffs)
- trunk/src/VBox/Main/linux/server.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/include/VBox/com/com.h
r2672 r2976 25 25 26 26 #include "VBox/com/defs.h" 27 #include "VBox/com/string.h" 27 28 28 29 namespace com … … 42 43 * No COM calls may be made after this method returns. 43 44 */ 44 voidShutdown();45 HRESULT Shutdown(); 45 46 46 47 /** … … 55 56 void GetInterfaceNameByIID (const GUID &aIID, BSTR *aName); 56 57 58 /** 59 * Returns the VirtualBox user home directory. 60 * 61 * On failure, this function will return a path that caused a failure (or a 62 * null string if the faiulre is not path-related). 63 * 64 * On success, this function will try to create the returned directory if it 65 * doesn't exist yet. This may also fail with the corresponding status code. 66 * 67 * @param aDir Where to return the directory to. 68 * @return VBox status code. 69 */ 70 int GetVBoxUserHomeDirectory (Utf8Str &aDir); 71 57 72 }; // namespace com 58 73 trunk/include/VBox/com/defs.h
r612 r2976 138 138 #define E_ABORT NS_ERROR_ABORT 139 139 #define E_FAIL NS_ERROR_FAILURE 140 /* Note: a better analog for E_ACCESSDENIED would probably be 141 * NS_ERROR_NOT_AVAILABLE, but we want binary compatibility for now. */ 140 142 #define E_ACCESSDENIED ((nsresult) 0x80070005L) 141 143 trunk/include/VBox/com/ptr.h
r1472 r2976 24 24 #define __VBox_com_ptr_h__ 25 25 26 #if defined (__WIN__)26 #if !defined (VBOX_WITH_XPCOM) 27 27 28 28 #include <atlbase.h> … … 32 32 #endif 33 33 34 #else / / !defined (__WIN__)34 #else /* !defined (VBOX_WITH_XPCOM) */ 35 35 36 36 #include <nsXPCOM.h> … … 46 46 "@mozilla.org/ipc/dconnect-service;1" 47 47 48 #endif / / !defined (__WIN__)48 #endif /* !defined (VBOX_WITH_XPCOM) */ 49 49 50 50 #include <VBox/com/defs.h> … … 85 85 class NoAddRefRelease : public I { 86 86 private: 87 #if def __WIN__87 #if !defined (VBOX_WITH_XPCOM) 88 88 STDMETHOD_(ULONG, AddRef)() = 0; 89 89 STDMETHOD_(ULONG, Release)() = 0; 90 #else 90 #else /* !defined (VBOX_WITH_XPCOM) */ 91 91 NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; 92 92 NS_IMETHOD_(nsrefcnt) Release(void) = 0; 93 #endif 93 #endif /* !defined (VBOX_WITH_XPCOM) */ 94 94 }; 95 95 … … 255 255 HRESULT rc; 256 256 I *obj = NULL; 257 #if defined (__WIN__)257 #if !defined (VBOX_WITH_XPCOM) 258 258 rc = CoCreateInstance (clsid, NULL, CLSCTX_INPROC_SERVER, _ATL_IIDOF (I), 259 259 (void **) &obj); 260 #else 260 #else /* !defined (VBOX_WITH_XPCOM) */ 261 261 nsCOMPtr <nsIComponentManager> manager; 262 262 rc = NS_GetComponentManager (getter_AddRefs (manager)); … … 264 264 rc = manager->CreateInstance (clsid, nsnull, NS_GET_IID (I), 265 265 (void **) &obj); 266 #endif 266 #endif /* !defined (VBOX_WITH_XPCOM) */ 267 267 *this = obj; 268 268 if (SUCCEEDED (rc)) … … 282 282 HRESULT createLocalObject (const CLSID &clsid) 283 283 { 284 #if defined (__WIN__)284 #if !defined (VBOX_WITH_XPCOM) 285 285 HRESULT rc; 286 286 I *obj = NULL; … … 291 291 obj->Release(); 292 292 return rc; 293 #else 293 #else /* !defined (VBOX_WITH_XPCOM) */ 294 294 return createInprocObject (clsid); 295 #endif 295 #endif /* !defined (VBOX_WITH_XPCOM) */ 296 296 } 297 297 … … 410 410 HRESULT createObject() { 411 411 HRESULT rc; 412 #if defined (__WIN__)412 #if !defined (VBOX_WITH_XPCOM) 413 413 # ifdef VBOX_COM_OUTOFPROC_MODULE 414 414 CComObjectNoLock <C> *obj = new CComObjectNoLock <C>(); … … 424 424 rc = CComObject <C>::CreateInstance (&obj); 425 425 # endif 426 #else 426 #else /* !defined (VBOX_WITH_XPCOM) */ 427 427 CComObject <C> *obj = new CComObject <C>(); 428 428 if (obj) { … … 431 431 rc = E_OUTOFMEMORY; 432 432 } 433 #endif 433 #endif /* !defined (VBOX_WITH_XPCOM) */ 434 434 *this = obj; 435 435 return rc; trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r2920 r2976 6074 6074 else 6075 6075 { 6076 // check if an alternative VBox Home directory is set 6077 Utf8Str homeDir = getenv ("VBOX_USER_HOME"); 6078 if (!homeDir) 6079 { 6080 // compose the config directory (full path) 6081 char home [RTPATH_MAX]; 6082 RTPathUserHome (home, RTPATH_MAX); 6083 homeDir = Utf8StrFmt ("%s%c%s", home, RTPATH_DELIMITER, ".VirtualBox"); 6084 } 6076 Utf8Str homeDir; 6077 GetVBoxUserHomeDirectory (homeDir); 6085 6078 6086 6079 RTPrintf ("Updating settings files in the following VirtualBox Home Directory:\n" trunk/src/VBox/Frontends/VirtualBox/include/COMDefs.h
r2671 r2976 28 28 #define __COMDefs_h__ 29 29 30 31 /* Both VBox/com/assert.h and qglobal.h contain a definition of ASSERT. 32 * Either of them can be already included here, so try to shut them up. */ 33 #undef ASSERT 34 35 #include <VBox/com/com.h> 36 37 #undef ASSERT 38 30 39 #include <qglobal.h> 31 40 #include <qstring.h> … … 35 44 36 45 /* 37 * common COM / XPCOM includes and defines46 * Additional COM / XPCOM defines and includes 38 47 */ 39 48 40 #if defined(Q_OS_WIN32) 41 42 #include <objbase.h> 43 /* for _ATL_IIDOF */ 44 #include <atldef.h> 45 46 #include <VBox/types.h> 47 48 /* these are XPCOM only */ 49 #define NS_DECL_ISUPPORTS 50 51 /* makes interface getter/setter names (n must be capitalized) */ 52 #define COMGETTER(n) get_##n 53 #define COMSETTER(n) put_##n 54 55 #define IN_BSTRPARAM BSTR 56 #define IN_GUIDPARAM GUID 57 58 /* const reference to IID of the interface */ 59 #define COM_IIDOF(I) _ATL_IIDOF (I) 60 61 #else 62 63 #include <VBox/types.h> 64 65 #include <nsMemory.h> 66 #include <nsIComponentManager.h> 67 #include <ipcIDConnectService.h> 68 69 class nsIComponentManager; 70 class nsIEventQueue; 71 class ipcIDConnectService; 72 73 typedef nsCID CLSID; 74 typedef nsIID IID; 75 76 class XPCOMEventQSocketListener; 77 78 #define STDMETHOD(a) NS_IMETHOD a 79 #define STDMETHODIMP NS_IMETHODIMP 80 81 #define HRESULT nsresult 82 #define SUCCEEDED NS_SUCCEEDED 83 #define FAILED NS_FAILED 84 85 /// @todo error code mappings 86 #define S_OK NS_OK 87 #define E_UNEXPECTED (HRESULT)0x8000FFFFL 88 #define E_NOTIMPL (HRESULT)0x80004001L 89 #define E_OUTOFMEMORY (HRESULT)0x8007000EL 90 #define E_INVALIDARG (HRESULT)0x80070057L 91 #define E_NOINTERFACE (HRESULT)0x80004002L 92 #define E_POINTER (HRESULT)0x80004003L 93 #define E_HANDLE (HRESULT)0x80070006L 94 #define E_ABORT (HRESULT)0x80004004L 95 #define E_FAIL (HRESULT)0x80004005L 96 #define E_ACCESSDENIED (HRESULT)0x80070005L 97 98 #define IUnknown nsISupports 99 100 #define BOOL PRBool 101 #define BYTE PRUint8 102 #define SHORT PRInt16 103 #define USHORT PRUint16 104 #define LONG PRInt32 105 #define ULONG PRUint32 106 #define LONG64 PRInt64 107 #define ULONG64 PRUint64 108 109 #define BSTR PRUnichar* 110 #define LPBSTR BSTR* 111 #define OLECHAR wchar_t 112 #define GUID nsID 113 114 #define IN_BSTRPARAM const BSTR 115 #define IN_GUIDPARAM const nsID & 116 117 /* makes interface getter/setter names (n must be capitalized) */ 118 #define COMGETTER(n) Get##n 119 #define COMSETTER(n) Set##n 120 121 /* const reference to IID of the interface */ 122 #define COM_IIDOF(I) NS_GET_IID (I) 123 124 /* helper functions (defined in the Runtime3 library) */ 125 extern "C" { 126 BSTR SysAllocString (const OLECHAR* sz); 127 BSTR SysAllocStringByteLen (char *psz, unsigned int len); 128 BSTR SysAllocStringLen (const OLECHAR *pch, unsigned int cch); 129 void SysFreeString (BSTR bstr); 130 int SysReAllocString (BSTR *pbstr, const OLECHAR *psz); 131 int SysReAllocStringLen (BSTR *pbstr, const OLECHAR *psz, unsigned int cch); 132 unsigned int SysStringByteLen (BSTR bstr); 133 unsigned int SysStringLen (BSTR bstr); 134 } 135 136 #endif 49 #define IN_BSTRPARAM INPTR BSTR 50 #define IN_GUIDPARAM INPTR GUIDPARAM 51 52 #if !defined (VBOX_WITH_XPCOM) 53 54 #else /* !defined (VBOX_WITH_XPCOM) */ 55 56 #include <nsXPCOM.h> 57 #include <nsMemory.h> 58 #include <nsIComponentManager.h> 59 60 class XPCOMEventQSocketListener; 61 62 #endif /* !defined (VBOX_WITH_XPCOM) */ 63 137 64 138 65 /* VirtualBox interfaces declarations */ 139 #if defined(Q_OS_WIN32)66 #if !defined (VBOX_WITH_XPCOM) 140 67 #include <VirtualBox.h> 141 #else 68 #else /* !defined (VBOX_WITH_XPCOM) */ 142 69 #include <VirtualBox_XPCOM.h> 143 #endif 70 #endif /* !defined (VBOX_WITH_XPCOM) */ 144 71 145 72 #include "VBoxDefs.h" 73 146 74 147 75 ///////////////////////////////////////////////////////////////////////////// … … 217 145 static HRESULT cleanupCOM(); 218 146 147 #if !defined (VBOX_WITH_XPCOM) 148 219 149 /** Converts a GUID value to QUuid */ 220 #if defined (Q_OS_WIN32)221 static QUuid toQUuid (const GUID &id){150 static QUuid toQUuid (const GUID &id) 151 { 222 152 return QUuid (id.Data1, id.Data2, id.Data3, 223 153 id.Data4[0], id.Data4[1], id.Data4[2], id.Data4[3], 224 154 id.Data4[4], id.Data4[5], id.Data4[6], id.Data4[7]); 225 155 } 226 #else 227 static QUuid toQUuid (const nsID &id) { 156 157 #else /* !defined (VBOX_WITH_XPCOM) */ 158 159 /** Converts a GUID value to QUuid */ 160 static QUuid toQUuid (const nsID &id) 161 { 228 162 return QUuid (id.m0, id.m1, id.m2, 229 163 id.m3[0], id.m3[1], id.m3[2], id.m3[3], 230 164 id.m3[4], id.m3[5], id.m3[6], id.m3[7]); 231 165 } 232 #endif 166 167 #endif /* !defined (VBOX_WITH_XPCOM) */ 233 168 234 169 /** … … 251 186 COMBase() : mRC (S_OK) {}; 252 187 253 #if !defined (Q_OS_WIN32) 254 static nsIComponentManager *gComponentManager; 255 static nsIEventQueue* gEventQ; 256 static ipcIDConnectService *gDConnectService; 257 static PRUint32 gVBoxServerID; 258 259 static XPCOMEventQSocketListener *gSocketListener; 188 #if defined (VBOX_WITH_XPCOM) 189 static XPCOMEventQSocketListener *sSocketListener; 260 190 #endif 261 191 … … 264 194 { 265 195 public: 196 266 197 BSTRIn (const QString &s) : bstr (SysAllocString ((const OLECHAR *) s.ucs2())) {} 267 ~BSTRIn() { 198 199 ~BSTRIn() 200 { 268 201 if (bstr) 269 202 SysFreeString (bstr); 270 203 } 204 271 205 operator BSTR() const { return bstr; } 272 206 273 207 private: 208 274 209 BSTR bstr; 275 210 }; … … 279 214 { 280 215 public: 216 281 217 BSTROut (QString &s) : str (s), bstr (0) {} 282 ~BSTROut() { 218 219 ~BSTROut() 220 { 283 221 if (bstr) { 284 222 str = QString::fromUcs2 (bstr); … … 286 224 } 287 225 } 226 288 227 operator BSTR *() { return &bstr; } 289 228 290 229 private: 230 291 231 QString &str; 292 232 BSTR bstr; … … 298 238 { 299 239 public: 240 300 241 ENUMOut (CE &e) : ce (e), ve ((VE) 0) {} 301 242 ~ENUMOut() { ce = (CE) ve; } … … 303 244 304 245 private: 246 305 247 CE &ce; 306 248 VE ve; 307 249 }; 308 250 309 #if defined (Q_OS_WIN32)251 #if !defined (VBOX_WITH_XPCOM) 310 252 311 253 /** Adapter to pass QUuid as input GUID params */ 312 GUID GUIDIn (const QUuid &uuid) const{ return uuid; }254 static GUID GUIDIn (const QUuid &uuid) { return uuid; } 313 255 314 256 /** Adapter to pass QUuid as output GUID params */ … … 316 258 { 317 259 public: 318 GUIDOut (QUuid &id) : uuid (id) { 260 261 GUIDOut (QUuid &id) : uuid (id) 262 { 319 263 ::memset (&guid, 0, sizeof (GUID)); 320 264 } 321 ~GUIDOut() { 265 266 ~GUIDOut() 267 { 322 268 uuid = QUuid ( 323 269 guid.Data1, guid.Data2, guid.Data3, 324 270 guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], 325 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] 326 );327 } 271 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); 272 } 273 328 274 operator GUID *() { return &guid; } 329 275 330 276 private: 277 331 278 QUuid &uuid; 332 279 GUID guid; 333 280 }; 334 281 335 #else 282 #else /* !defined (VBOX_WITH_XPCOM) */ 336 283 337 284 /** Adapter to pass QUuid as input GUID params */ 338 static const nsID &GUIDIn (const QUuid &uuid) { 285 static const nsID &GUIDIn (const QUuid &uuid) 286 { 339 287 return *(const nsID *) &uuid; 340 288 } … … 344 292 { 345 293 public: 294 346 295 GUIDOut (QUuid &id) : uuid (id), nsid (0) {} 347 ~GUIDOut() { 348 if (nsid) { 296 297 ~GUIDOut() 298 { 299 if (nsid) 300 { 349 301 uuid = QUuid ( 350 302 nsid->m0, nsid->m1, nsid->m2, 351 303 nsid->m3[0], nsid->m3[1], nsid->m3[2], nsid->m3[3], 352 nsid->m3[4], nsid->m3[5], nsid->m3[6], nsid->m3[7] 353 ); 304 nsid->m3[4], nsid->m3[5], nsid->m3[6], nsid->m3[7]); 354 305 nsMemory::Free (nsid); 355 306 } 356 307 } 308 357 309 operator nsID **() { return &nsid; } 358 310 359 311 private: 312 360 313 QUuid &uuid; 361 314 nsID *nsid; 362 315 }; 363 316 364 #endif 317 #endif /* !defined (VBOX_WITH_XPCOM) */ 365 318 366 319 void fetchErrorInfo (IUnknown * /*callee*/, const GUID * /*calleeIID*/) const {} … … 394 347 COMBaseWithEI() : COMBase () {}; 395 348 396 void fetchErrorInfo (IUnknown *callee, const GUID *calleeIID) const { 349 void fetchErrorInfo (IUnknown *callee, const GUID *calleeIID) const 350 { 397 351 mErrInfo.fetchFromCurrentThread (callee, calleeIID); 398 352 } … … 484 438 if (!mIface) 485 439 { 486 #if defined (Q_OS_WIN32) 440 #if !defined (VBOX_WITH_XPCOM) 441 487 442 B::mRC = CoCreateInstance (clsid, NULL, CLSCTX_ALL, 488 _ATL_IIDOF (I), (void**) &mIface); 489 #else 490 /* first, try to create an instance within the in-proc server 491 * (for compatibility with Win32) */ 492 B::mRC = B::gComponentManager-> 493 CreateInstance (clsid, nsnull, NS_GET_IID (I), (void**) &mIface); 494 if (FAILED (B::mRC) && B::gDConnectService && B::gVBoxServerID) 495 { 496 /* now try the out-of-proc server if it exists */ 497 B::mRC = B::gDConnectService-> 498 CreateInstance (B::gVBoxServerID, clsid, 499 NS_GET_IID (I), (void**) &mIface); 500 } 501 #endif 443 _ATL_IIDOF (I), (void **) &mIface); 444 445 #else /* !defined (VBOX_WITH_XPCOM) */ 446 447 nsCOMPtr <nsIComponentManager> manager; 448 B::mRC = NS_GetComponentManager (getter_AddRefs (manager)); 449 if (SUCCEEDED (B::mRC)) 450 B::mRC = manager->CreateInstance (clsid, nsnull, NS_GET_IID (I), 451 (void **) &mIface); 452 453 #endif /* !defined (VBOX_WITH_XPCOM) */ 454 502 455 /* fetch error info, but don't assert if it's missing -- many other 503 456 * reasons can lead to an error (w/o providing error info), not only … … 524 477 B::mRC = S_OK; 525 478 if (i) 526 #if defined (Q_OS_WIN32)527 B::mRC = i->QueryInterface (_ATL_IIDOF (I), (void **) &mIface);528 #else 529 B::mRC = i->QueryInterface (NS_GET_IID (I), (void **) &mIface);530 #endif 479 #if !defined (VBOX_WITH_XPCOM) 480 B::mRC = i->QueryInterface (_ATL_IIDOF (I), (void **) &mIface); 481 #else /* !defined (VBOX_WITH_XPCOM) */ 482 B::mRC = i->QueryInterface (NS_GET_IID (I), (void **) &mIface); 483 #endif /* !defined (VBOX_WITH_XPCOM) */ 531 484 release (old_iface); 532 485 }; … … 575 528 mIface = NULL; 576 529 if (that.mIface) 577 #if defined (Q_OS_WIN32)530 #if !defined (VBOX_WITH_XPCOM) 578 531 mRC = that.mIface->QueryInterface (_ATL_IIDOF (IUnknown), (void**) &mIface); 579 #else 532 #else /* !defined (VBOX_WITH_XPCOM) */ 580 533 mRC = that.mIface->QueryInterface (NS_GET_IID (IUnknown), (void**) &mIface); 581 #endif 582 if (SUCCEEDED (mRC)) { 534 #endif /* !defined (VBOX_WITH_XPCOM) */ 535 if (SUCCEEDED (mRC)) 536 { 583 537 mRC = that.lastRC(); 584 538 mErrInfo = that.errorInfo(); 585 539 } 586 540 } 541 587 542 /* specialization for CUnknown */ 588 CUnknown (const CUnknown &that) : CInterface <IUnknown, COMBaseWithEI> () { 543 CUnknown (const CUnknown &that) : CInterface <IUnknown, COMBaseWithEI> () 544 { 589 545 mIface = that.mIface; 590 546 addref (mIface); … … 593 549 594 550 template <class C> 595 CUnknown &operator= (const C &that) { 551 CUnknown &operator= (const C &that) 552 { 596 553 /* be aware of self (from COM point of view) assignment */ 597 554 IUnknown *old_iface = mIface; 598 555 mIface = NULL; 599 556 mRC = S_OK; 600 #if defined (Q_OS_WIN32)557 #if !defined (VBOX_WITH_XPCOM) 601 558 if (that.mIface) 602 559 mRC = that.mIface->QueryInterface (_ATL_IIDOF (IUnknown), (void**) &mIface); 603 #else 560 #else /* !defined (VBOX_WITH_XPCOM) */ 604 561 if (that.mIface) 605 562 mRC = that.mIface->QueryInterface (NS_GET_IID (IUnknown), (void**) &mIface); 606 #endif 607 if (SUCCEEDED (mRC)) { 563 #endif /* !defined (VBOX_WITH_XPCOM) */ 564 if (SUCCEEDED (mRC)) 565 { 608 566 mRC = that.lastRC(); 609 567 mErrInfo = that.errorInfo(); … … 612 570 return *this; 613 571 } 572 614 573 /* specialization for CUnknown */ 615 CUnknown &operator= (const CUnknown &that) { 574 CUnknown &operator= (const CUnknown &that) 575 { 616 576 attach (that.mIface); 617 577 COMBaseWithEI::operator= (that); trunk/src/VBox/Frontends/VirtualBox/src/COMDefs.cpp
r2671 r2976 23 23 #include "COMDefs.h" 24 24 25 #if defined (Q_OS_WIN32) 26 27 // for CComPtr/CComQIPtr 28 #include <atlcomcli.h> 29 #include <VBox/com/assert.h> 30 31 #else // !defined (Q_OS_WIN32) 25 #if !defined (VBOX_WITH_XPCOM) 26 27 #else /* !defined (VBOX_WITH_XPCOM) */ 32 28 33 29 #include <qobject.h> 34 #include <qapplication.h>35 #include <qfile.h>36 30 #include <qsocketnotifier.h> 37 #ifdef DEBUG 38 #include <qfileinfo.h> 39 #endif 40 41 #include <nsXPCOMGlue.h> 42 #include <nsIServiceManager.h> 43 #include <nsIComponentRegistrar.h> 44 // for NS_InitXPCOM2 with bin dir parameter 45 #include <nsEmbedString.h> 46 #include <nsIFile.h> 47 #include <nsILocalFile.h> 48 // for dconnect 49 #include <ipcIService.h> 50 #include <ipcCID.h> 51 // XPCOM headers still do not define this, so define by hand 52 #define IPC_DCONNECTSERVICE_CONTRACTID \ 53 "@mozilla.org/ipc/dconnect-service;1" 54 // for event queue management 31 55 32 #include <nsEventQueueUtils.h> 56 33 #include <nsIEventQueue.h> 57 34 58 // for IID to name resolution59 #include <nsIInterfaceInfo.h>60 #include <nsIInterfaceInfoManager.h>61 62 35 // for exception fetching 63 36 #include <nsIExceptionService.h> 64 37 65 #undef ASSERT66 #include <VBox/com/assert.h>67 38 #include <iprt/env.h> 68 39 #include <iprt/path.h> 69 40 #include <iprt/param.h> 70 41 #include <iprt/err.h> 71 72 nsIComponentManager *COMBase::gComponentManager = nsnull;73 nsIEventQueue* COMBase::gEventQ = nsnull;74 ipcIDConnectService *COMBase::gDConnectService = nsnull;75 PRUint32 COMBase::gVBoxServerID = 0;76 42 77 43 /* Mac OS X (Carbon mode) and OS/2 will notify the native queue … … 80 46 very silly. */ 81 47 # if !defined (Q_OS_MAC) && !defined (Q_OS_OS2) 82 XPCOMEventQSocketListener *COMBase::gSocketListener = 0; 48 XPCOMEventQSocketListener *COMBase::sSocketListener = 0; 49 83 50 # endif 84 51 … … 103 70 } 104 71 72 virtual ~XPCOMEventQSocketListener() 73 { 74 delete mNotifier; 75 } 76 105 77 public slots: 106 78 … … 110 82 111 83 QSocketNotifier *mNotifier; 112 ns IEventQueue *mEventQ;84 nsCOMPtr <nsIEventQueue> mEventQ; 113 85 }; 114 86 115 #endif / / !defined (Q_OS_WIN32)87 #endif /* !defined (VBOX_WITH_XPCOM) */ 116 88 117 89 /** … … 122 94 LogFlowFuncEnter(); 123 95 124 #if defined (Q_OS_WIN32) 96 HRESULT rc = S_OK; 97 98 #if !defined (VBOX_WITH_XPCOM) 125 99 126 100 /* disable this damn CoInitialize* somehow made by Qt during … … 128 102 * why does it do this) */ 129 103 CoUninitialize(); 130 CoInitializeEx (NULL, COINIT_MULTITHREADED | 131 COINIT_DISABLE_OLE1DDE | 132 COINIT_SPEED_OVER_MEMORY); 133 134 LogFlowFuncLeave(); 135 return S_OK; 136 137 #else 138 139 if (gComponentManager) 140 { 141 LogFlowFuncLeave(); 142 return S_OK; 143 } 144 145 /* 146 * Set VBOX_XPCOM_HOME if not present like we do in the common glue code. 147 * (XPCOMGlueStartup will query this.) 148 */ 149 if (!RTEnvExist ("VBOX_XPCOM_HOME")) 150 { 151 /* get the executable path */ 152 char szPathProgram [RTPATH_MAX]; 153 int rcVBox = RTPathProgram (szPathProgram, sizeof (szPathProgram)); 154 if (RT_SUCCESS (rcVBox)) 155 RTEnvSet ("VBOX_XPCOM_HOME", szPathProgram); 156 } 157 158 HRESULT rc; 159 XPCOMGlueStartup (nsnull); 160 161 nsCOMPtr <nsIServiceManager> serviceManager; 162 163 /* create a file object containing the path to the executable */ 164 QCString appDir; 104 105 #endif /* !defined (VBOX_WITH_XPCOM) */ 106 107 rc = com::Initialize(); 108 109 #if defined (VBOX_WITH_XPCOM) 110 111 #if !defined (__DARWIN__) && !defined (__OS2__) 112 113 if (NS_SUCCEEDED (rc)) 114 { 115 nsCOMPtr <nsIEventQueue> eventQ; 116 rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 117 if (NS_SUCCEEDED (rc)) 118 { 165 119 #ifdef DEBUG 166 appDir = getenv ("VIRTUALBOX_APP_HOME"); 167 if (!appDir.isNull()) 168 appDir = QFile::encodeName (QFileInfo (QFile::decodeName (appDir)).absFilePath()); 169 else 120 BOOL isNative = FALSE; 121 eventQ->IsQueueNative (&isNative); 122 AssertMsg (isNative, ("The event queue must be native")); 170 123 #endif 171 appDir = QFile::encodeName (qApp->applicationDirPath()); 172 nsCOMPtr <nsILocalFile> lfAppDir; 173 rc = NS_NewNativeLocalFile (nsEmbedCString (appDir.data()), PR_FALSE, 174 getter_AddRefs (lfAppDir)); 175 if (SUCCEEDED (rc)) 176 { 177 nsCOMPtr <nsIFile> fAppDir = do_QueryInterface (lfAppDir, &rc); 178 if (SUCCEEDED( rc )) 179 { 180 /* initialize XPCOM and get the service manager */ 181 rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager), fAppDir, nsnull); 182 } 183 } 184 185 if (SUCCEEDED (rc)) 186 { 187 /* get the registrar */ 188 nsCOMPtr <nsIComponentRegistrar> registrar = 189 do_QueryInterface (serviceManager, &rc); 190 if (SUCCEEDED (rc)) 191 { 192 /* autoregister components from a component directory */ 193 registrar->AutoRegister (nsnull); 194 195 /* get the component manager */ 196 rc = registrar->QueryInterface (NS_GET_IID (nsIComponentManager), 197 (void**) &gComponentManager); 198 if (SUCCEEDED (rc)) 124 BOOL isOnMainThread = FALSE; 125 rc = eventQ->IsOnCurrentThread (&isOnMainThread); 126 if (NS_SUCCEEDED (rc) && isOnMainThread) 199 127 { 200 /* get the main thread's event queue (afaik, the 201 * dconnect service always gets created upon XPCOM 202 * startup, so it will use the main (this) thread's 203 * event queue to receive IPC events) */ 204 rc = NS_GetMainEventQ (&gEventQ); 205 #ifdef DEBUG 206 BOOL isNative = FALSE; 207 gEventQ->IsQueueNative (&isNative); 208 AssertMsg (isNative, ("The event queue must be native")); 209 #endif 210 # if !defined (__DARWIN__) && !defined (__OS2__) 211 gSocketListener = new XPCOMEventQSocketListener (gEventQ); 212 # endif 213 214 /// @todo remove the below code and corresponding variables etc. when 215 /// the server autostart feature is finished and well tested. 216 /// 217 // /* get the IPC service */ 218 // nsCOMPtr <ipcIService> ipcServ = 219 // do_GetService (IPC_SERVICE_CONTRACTID, serviceManager, &rc); 220 // if (SUCCEEDED (rc)) 221 // { 222 // /* get the VirtualBox out-of-proc server ID */ 223 // rc = ipcServ->ResolveClientName ("VirtualBoxServer", 224 // &gVBoxServerID); 225 // if (SUCCEEDED (rc)) 226 // { 227 // /* get the DConnect service */ 228 // rc = serviceManager-> 229 // GetServiceByContractID (IPC_DCONNECTSERVICE_CONTRACTID, 230 // NS_GET_IID (ipcIDConnectService), 231 // (void **) &gDConnectService); 232 // } 233 // } 128 sSocketListener = new XPCOMEventQSocketListener (eventQ); 234 129 } 235 130 } 236 131 } 237 132 133 #endif 134 135 #endif /* defined (VBOX_WITH_XPCOM) */ 136 238 137 if (FAILED (rc)) 239 138 cleanupCOM(); 139 140 AssertComRC (rc); 240 141 241 142 LogFlowFunc (("rc=%08X\n", rc)); … … 243 144 return rc; 244 145 245 #endif246 146 } 247 147 248 148 /** 249 * InitializesCOM/XPCOM.149 * Cleans up COM/XPCOM. 250 150 */ 251 151 HRESULT COMBase::cleanupCOM() … … 253 153 LogFlowFuncEnter(); 254 154 255 #if defined (Q_OS_WIN32) 256 CoUninitialize(); 257 # else258 if (gComponentManager) 259 {260 PRBool isOnCurrentThread = true;261 if (gEventQ)262 gEventQ->IsOnCurrentThread (&isOnCurrentThread);263 264 if ( isOnCurrentThread)155 HRESULT rc = S_OK; 156 157 #if defined (VBOX_WITH_XPCOM) 158 159 /* scope the code to make smart references are released before calling 160 * com::Shutdown() */ 161 { 162 nsCOMPtr <nsIEventQueue> eventQ; 163 rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 164 if (NS_SUCCEEDED (rc)) 265 165 { 266 LogFlowFunc (("Doing cleanup...\n")); 166 BOOL isOnMainThread = FALSE; 167 rc = eventQ->IsOnCurrentThread (&isOnMainThread); 168 if (NS_SUCCEEDED (rc) && isOnMainThread) 169 { 267 170 # if !defined (__DARWIN__) && !defined (__OS2__) 268 if (gSocketListener) 269 delete gSocketListener; 171 if (sSocketListener) 172 { 173 delete sSocketListener; 174 sSocketListener = NULL; 175 } 270 176 # endif 271 if (gDConnectService)272 {273 gDConnectService->Release();274 gDConnectService = nsnull;275 177 } 276 if (gEventQ)277 {278 gEventQ->Release();279 gEventQ = nsnull;280 }281 gComponentManager->Release();282 gComponentManager = nsnull;283 /* note: gComponentManager = nsnull indicates that we're284 * cleaned up */285 NS_ShutdownXPCOM (nsnull);286 XPCOMGlueShutdown();287 178 } 288 179 } 289 #endif 290 180 181 #endif /* defined (VBOX_WITH_XPCOM) */ 182 183 HRESULT rc2 = com::Shutdown(); 184 if (SUCCEEDED (rc)) 185 rc = rc2; 186 187 AssertComRC (rc); 188 189 LogFlowFunc (("rc=%08X\n", rc)); 291 190 LogFlowFuncLeave(); 292 return S_OK;191 return rc; 293 192 } 294 193 … … 358 257 HRESULT rc = E_FAIL; 359 258 360 #if defined (__WIN__)259 #if !defined (VBOX_WITH_XPCOM) 361 260 362 261 if (callee) … … 405 304 } 406 305 407 #else / / !defined (__WIN__)306 #else /* !defined (VBOX_WITH_XPCOM) */ 408 307 409 308 nsCOMPtr <nsIExceptionService> es; … … 458 357 AssertComRC (rc); 459 358 460 #endif / / !defined (__WIN__)359 #endif /* !defined (VBOX_WITH_XPCOM) */ 461 360 462 361 if (callee && calleeIID && mIsBasicAvailable) … … 472 371 QString name; 473 372 474 #if defined (__WIN__) 475 476 LONG rc; 477 LPOLESTR iidStr = NULL; 478 if (StringFromIID (id, &iidStr) == S_OK) 479 { 480 HKEY ifaceKey; 481 rc = RegOpenKeyExW (HKEY_CLASSES_ROOT, L"Interface", 0, KEY_QUERY_VALUE, &ifaceKey); 482 if (rc == ERROR_SUCCESS) 483 { 484 HKEY iidKey; 485 rc = RegOpenKeyExW (ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey); 486 if (rc == ERROR_SUCCESS) 487 { 488 // determine the size and type 489 DWORD sz, type; 490 rc = RegQueryValueExW (iidKey, NULL, NULL, &type, NULL, &sz); 491 if (rc == ERROR_SUCCESS && type == REG_SZ) 492 { 493 // query the value to BSTR 494 BSTR bstrName = SysAllocStringLen (NULL, (sz + 1) / sizeof (TCHAR) + 1); 495 rc = RegQueryValueExW (iidKey, NULL, NULL, NULL, (LPBYTE) bstrName, &sz); 496 if (rc == ERROR_SUCCESS) 497 { 498 name = QString::fromUcs2 (bstrName); 499 } 500 SysFreeString (bstrName); 501 } 502 RegCloseKey (iidKey); 503 } 504 RegCloseKey (ifaceKey); 505 } 506 CoTaskMemFree (iidStr); 507 } 508 509 #else 510 511 nsresult rv; 512 nsCOMPtr <nsIInterfaceInfoManager> iim = 513 do_GetService (NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv); 514 if (NS_SUCCEEDED (rv)) 515 { 516 nsCOMPtr <nsIInterfaceInfo> iinfo; 517 rv = iim->GetInfoForIID (&COMBase::GUIDIn (id), getter_AddRefs (iinfo)); 518 if (NS_SUCCEEDED (rv)) 519 { 520 const char *iname = NULL; 521 iinfo->GetNameShared (&iname); 522 name = QString::fromLocal8Bit (iname); 523 } 524 } 525 526 #endif 373 com::GetInterfaceNameByIID (COMBase::GUIDIn (id), COMBase::BSTROut (name)); 527 374 528 375 return name; 529 376 } 530 377 531 #if !defined (Q_OS_WIN32)378 #if defined (VBOX_WITH_XPCOM) 532 379 #include "COMDefs.moc" 533 380 #endif trunk/src/VBox/Main/VirtualBoxImpl.cpp
r2610 r2976

