Changeset 2976 in vbox
- Timestamp:
- Jun 1, 2007 1:47:51 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
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 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include <VBox/err.h> 42 43 43 #include <iprt/path.h> 44 44 #include <iprt/dir.h> … … 48 48 #include <iprt/thread.h> 49 49 #include <iprt/process.h> 50 51 #include <VBox/err.h> 50 52 #include <VBox/param.h> 51 53 #include <VBox/VBoxHDD.h> … … 54 56 #include <VBox/version.h> 55 57 58 #include <VBox/com/com.h> 59 56 60 #include <algorithm> 57 61 #include <set> … … 61 65 ///////////////////////////////////////////////////////////////////////////// 62 66 63 #ifdef __DARWIN__ 64 #define VBOXCONFIGDIR "Library/VirtualBox" 65 #else 66 #define VBOXCONFIGDIR ".VirtualBox" 67 #endif 68 #define VBOXCONFIGGLOBALFILE "VirtualBox.xml" 67 #define VBOX_GLOBAL_SETTINGS_FILE "VirtualBox.xml" 69 68 70 69 // globals … … 138 137 LogFlowThisFunc (("Version: %ls\n", sVersion.raw())); 139 138 140 int vrc = VINF_SUCCESS; 141 char buf [RTPATH_MAX]; 142 143 /* 144 * Detect the VirtualBox home directory. Note that the code below must 145 * be in sync with the appropriate code in Logging.cpp 146 * (MainReleaseLoggerInit()). 147 */ 148 { 149 /* check if an alternative VBox Home directory is set */ 150 const char *vboxUserHome = getenv ("VBOX_USER_HOME"); 151 if (vboxUserHome) 152 { 153 /* get the full path name */ 154 vrc = RTPathAbs (vboxUserHome, buf, sizeof (buf)); 155 if (VBOX_FAILURE (vrc)) 156 return setError (E_FAIL, 157 tr ("Invalid home directory file path '%s' (%Vrc)"), 158 vboxUserHome, vrc); 159 unconst (mData.mHomeDir) = buf; 160 } 161 else 162 { 163 /* compose the config directory (full path) */ 164 RTPathUserHome (buf, sizeof (buf)); 165 unconst (mData.mHomeDir) = Utf8StrFmt ("%s%c%s", buf, 166 RTPATH_DELIMITER, 167 VBOXCONFIGDIR); 168 } 169 170 /* ensure the home directory exists */ 171 if (!RTDirExists (mData.mHomeDir)) 172 { 173 vrc = RTDirCreateFullPath (mData.mHomeDir, 0777); 174 if (VBOX_FAILURE (vrc)) 175 { 176 return setError (E_FAIL, 177 tr ("Could not create the VirtualBox home directory '%s'" 178 "(%Vrc)"), 179 mData.mHomeDir.raw(), vrc); 180 } 181 } 182 } 139 /* Get the VirtualBox home directory. */ 140 int vrc = com::GetVBoxUserHomeDirectory (unconst (mData.mHomeDir)); 141 if (VBOX_FAILURE (vrc)) 142 return setError (E_FAIL, 143 tr ("Could not create the VirtualBox home directory '%s'" 144 "(%Vrc)"), 145 mData.mHomeDir.raw(), vrc); 183 146 184 147 /* compose the global config file name (always full path) */ 185 148 Utf8StrFmt vboxConfigFile ("%s%c%s", mData.mHomeDir.raw(), 186 RTPATH_DELIMITER, VBOX CONFIGGLOBALFILE);149 RTPATH_DELIMITER, VBOX_GLOBAL_SETTINGS_FILE); 187 150 188 151 /* store the config file name */ -
trunk/src/VBox/Main/glue/com.cpp
r2754 r2976 23 23 #include <objbase.h> 24 24 25 #else 25 #else /* !defined (VBOX_WITH_XPCOM) */ 26 26 27 27 #include <stdlib.h> 28 #include <VBox/err.h>29 #include <iprt/path.h>30 28 31 #include <nsXPCOMGlue.h>32 #include <nsIComponentRegistrar.h>33 #include <nsIServiceManager.h>34 29 #include <nsCOMPtr.h> 35 #include <ns EventQueueUtils.h>30 #include <nsIServiceManagerUtils.h> 36 31 37 32 #include <nsIInterfaceInfo.h> 38 33 #include <nsIInterfaceInfoManager.h> 39 34 40 #endif 35 #endif /* !defined (VBOX_WITH_XPCOM) */ 41 36 37 #include <iprt/param.h> 38 #include <iprt/path.h> 39 #include <iprt/dir.h> 40 #include <iprt/env.h> 42 41 #include <iprt/string.h> 42 43 43 #include <VBox/err.h> 44 44 45 45 #include "VBox/com/com.h" 46 46 #include "VBox/com/assert.h" 47 48 49 #ifdef __DARWIN__ 50 #define VBOX_USER_HOME_SUFFIX "Library/VirtualBox" 51 #else 52 #define VBOX_USER_HOME_SUFFIX ".VirtualBox" 53 #endif 54 47 55 48 56 namespace com … … 95 103 } 96 104 97 #else 105 #else /* !defined (VBOX_WITH_XPCOM) */ 98 106 99 107 nsresult rv; … … 122 130 } 123 131 124 #endif 132 #endif /* !defined (VBOX_WITH_XPCOM) */ 133 } 134 135 int GetVBoxUserHomeDirectory (Utf8Str &aDir) 136 { 137 /* start with null */ 138 aDir.setNull(); 139 140 const char *VBoxUserHome = RTEnvGet ("VBOX_USER_HOME"); 141 142 char path [RTPATH_MAX]; 143 int vrc = VINF_SUCCESS; 144 145 if (VBoxUserHome) 146 { 147 /* get the full path name */ 148 char *VBoxUserHomeUtf8 = NULL; 149 vrc = RTStrCurrentCPToUtf8 (&VBoxUserHomeUtf8, VBoxUserHome); 150 if (RT_SUCCESS (vrc)) 151 { 152 vrc = RTPathAbs (VBoxUserHomeUtf8, path, sizeof (path)); 153 if (RT_SUCCESS (vrc)) 154 aDir = path; 155 RTStrFree (VBoxUserHomeUtf8); 156 } 157 } 158 else 159 { 160 /* compose the config directory (full path) */ 161 vrc = RTPathUserHome (path, sizeof (path)); 162 aDir = Utf8StrFmt ("%s%c%s", path, RTPATH_DELIMITER, 163 VBOX_USER_HOME_SUFFIX); 164 } 165 166 /* ensure the home directory exists */ 167 if (RT_SUCCESS (vrc)) 168 if (!RTDirExists (aDir)) 169 vrc = RTDirCreateFullPath (aDir, 0777); 170 171 return vrc; 125 172 } 126 173 -
trunk/src/VBox/Main/glue/initterm.cpp
r2754 r2976 23 23 #include <objbase.h> 24 24 25 #else 25 #else /* !defined (VBOX_WITH_XPCOM) */ 26 26 27 27 #include <stdlib.h> 28 #include <VBox/err.h>29 #include <iprt/path.h>30 28 31 29 #include <nsXPCOMGlue.h> … … 34 32 #include <nsCOMPtr.h> 35 33 #include <nsEventQueueUtils.h> 36 37 #include <nsIInterfaceInfo.h> 38 #include <nsIInterfaceInfoManager.h> 39 40 #endif 41 34 #include <nsEmbedString.h> 35 36 #include <nsILocalFile.h> 37 #include <nsIDirectoryService.h> 38 #include <nsDirectoryServiceDefs.h> 39 40 #endif /* !defined (VBOX_WITH_XPCOM) */ 41 42 #include <iprt/param.h> 43 #include <iprt/path.h> 42 44 #include <iprt/string.h> 45 #include <iprt/env.h> 46 43 47 #include <VBox/err.h> 44 48 … … 46 50 #include "VBox/com/assert.h" 47 51 52 48 53 namespace com 49 54 { 55 56 #if defined (VBOX_WITH_XPCOM) 57 58 class DirectoryServiceProvider : public nsIDirectoryServiceProvider 59 { 60 public: 61 62 NS_DECL_ISUPPORTS 63 64 DirectoryServiceProvider() 65 : mCompRegLocation (NULL), mXPTIDatLocation (NULL) 66 {} 67 68 virtual ~DirectoryServiceProvider(); 69 70 HRESULT init (const char *aCompRegLocation, 71 const char *aXPTIDatLocation); 72 73 NS_DECL_NSIDIRECTORYSERVICEPROVIDER 74 75 private: 76 77 char *mCompRegLocation; 78 char *mXPTIDatLocation; 79 }; 80 81 NS_IMPL_ISUPPORTS1 (DirectoryServiceProvider, nsIDirectoryServiceProvider) 82 83 DirectoryServiceProvider::~DirectoryServiceProvider() 84 { 85 if (mCompRegLocation) 86 { 87 RTStrFree (mCompRegLocation); 88 mCompRegLocation = NULL; 89 } 90 if (mXPTIDatLocation) 91 { 92 RTStrFree (mXPTIDatLocation); 93 mXPTIDatLocation = NULL; 94 } 95 } 96 97 /** 98 * @param aCompRegLocation Path to compreg.dat, in Utf8. 99 * @param aXPTIDatLocation Path to xpti.data, in Utf8. 100 */ 101 HRESULT 102 DirectoryServiceProvider::init (const char *aCompRegLocation, 103 const char *aXPTIDatLocation) 104 { 105 AssertReturn (aCompRegLocation, NS_ERROR_INVALID_ARG); 106 AssertReturn (aXPTIDatLocation, NS_ERROR_INVALID_ARG); 107 108 int vrc = RTStrUtf8ToCurrentCP (&mCompRegLocation, aCompRegLocation); 109 if (RT_SUCCESS (vrc)) 110 vrc = RTStrUtf8ToCurrentCP (&mXPTIDatLocation, aXPTIDatLocation); 111 112 return RT_SUCCESS (vrc) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; 113 } 114 115 NS_IMETHODIMP 116 DirectoryServiceProvider::GetFile (const char *aProp, 117 PRBool *aPersistent, 118 nsIFile **aRetval) 119 { 120 nsCOMPtr <nsILocalFile> localFile; 121 nsresult rv = NS_ERROR_FAILURE; 122 123 *aRetval = nsnull; 124 *aPersistent = PR_TRUE; 125 126 const char *fileLocation = NULL; 127 128 if (strcmp (aProp, NS_XPCOM_COMPONENT_REGISTRY_FILE) == 0) 129 fileLocation = mCompRegLocation; 130 else if (strcmp (aProp, NS_XPCOM_XPTI_REGISTRY_FILE) == 0) 131 fileLocation = mXPTIDatLocation; 132 else 133 return NS_ERROR_FAILURE; 134 135 rv = NS_NewNativeLocalFile (nsEmbedCString (fileLocation), 136 PR_TRUE, getter_AddRefs (localFile)); 137 if (NS_FAILED(rv)) 138 return rv; 139 140 return localFile->QueryInterface (NS_GET_IID (nsIFile), 141 (void **) aRetval); 142 } 143 144 #endif /* defined (VBOX_WITH_XPCOM) */ 50 145 51 146 HRESULT Initialize() … … 59 154 COINIT_SPEED_OVER_MEMORY); 60 155 61 #else 156 #else /* !defined (VBOX_WITH_XPCOM) */ 62 157 63 158 /* Set VBOX_XPCOM_HOME if not present */ 64 if (! getenv("VBOX_XPCOM_HOME"))159 if (!RTEnvExist ("VBOX_XPCOM_HOME")) 65 160 { 66 161 /* get the executable path */ 67 char szPathProgram[1024]; 68 int rcVBox = RTPathProgram(szPathProgram, sizeof(szPathProgram)); 69 if (VBOX_SUCCESS(rcVBox)) 70 { 71 setenv("VBOX_XPCOM_HOME", szPathProgram, 1); 72 } 162 char pathProgram [RTPATH_MAX]; 163 int vrc = RTPathProgram (pathProgram, sizeof (pathProgram)); 164 if (RT_SUCCESS (vrc)) 165 { 166 char *pathProgramCP = NULL; 167 vrc = RTStrUtf8ToCurrentCP (&pathProgramCP, pathProgram); 168 if (RT_SUCCESS (vrc)) 169 { 170 vrc = RTEnvSet ("VBOX_XPCOM_HOME", pathProgramCP); 171 RTStrFree (pathProgramCP); 172 } 173 } 174 AssertRC (vrc); 73 175 } 74 176 … … 78 180 { 79 181 XPCOMGlueStartup (nsnull); 80 nsCOMPtr <nsIServiceManager> serviceManager; 81 rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager), nsnull, nsnull); 182 183 nsCOMPtr <DirectoryServiceProvider> dsProv; 184 185 /* prepare paths for registry files */ 186 Utf8Str homeDir; 187 int vrc = GetVBoxUserHomeDirectory (homeDir); 188 if (RT_SUCCESS (vrc)) 189 { 190 Utf8Str compReg = Utf8StrFmt ("%s%c%s", homeDir.raw(), 191 RTPATH_DELIMITER, "compreg.dat"); 192 Utf8Str xptiDat = Utf8StrFmt ("%s%c%s", homeDir.raw(), 193 RTPATH_DELIMITER, "xpti.dat"); 194 dsProv = new DirectoryServiceProvider(); 195 if (dsProv) 196 rc = dsProv->init (compReg, xptiDat); 197 else 198 rc = NS_ERROR_OUT_OF_MEMORY; 199 } 200 else 201 rc = NS_ERROR_FAILURE; 202 203 /* get the path to the executable */ 204 nsCOMPtr <nsIFile> appDir; 205 { 206 char path [RTPATH_MAX]; 207 char *appDirCP = NULL; 208 #if defined (DEBUG) 209 const char *env = RTEnvGet ("VIRTUALBOX_APP_HOME"); 210 if (env) 211 { 212 char *appDirUtf8 = NULL; 213 vrc = RTStrCurrentCPToUtf8 (&appDirUtf8, env); 214 if (RT_SUCCESS (vrc)) 215 { 216 vrc = RTPathReal (appDirUtf8, path, RTPATH_MAX); 217 if (RT_SUCCESS (vrc)) 218 vrc = RTStrUtf8ToCurrentCP (&appDirCP, appDirUtf8); 219 RTStrFree (appDirUtf8); 220 } 221 } 222 else 223 #endif 224 { 225 vrc = RTPathProgram (path, RTPATH_MAX); 226 if (RT_SUCCESS (vrc)) 227 vrc = RTStrUtf8ToCurrentCP (&appDirCP, path); 228 } 229 230 if (RT_SUCCESS (vrc)) 231 { 232 nsCOMPtr<nsILocalFile> file; 233 rc = NS_NewNativeLocalFile (nsEmbedCString (appDirCP), 234 PR_FALSE, getter_AddRefs (file)); 235 if (NS_SUCCEEDED (rc)) 236 appDir = do_QueryInterface (file, &rc); 237 238 RTStrFree (appDirCP); 239 } 240 else 241 rc = NS_ERROR_FAILURE; 242 } 243 244 /* Finally, initialize XPCOM */ 82 245 if (NS_SUCCEEDED (rc)) 83 246 { 84 nsCOMPtr <nsIComponentRegistrar> registrar = 85 do_QueryInterface (serviceManager, &rc); 247 nsCOMPtr <nsIServiceManager> serviceManager; 248 rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager), 249 appDir, dsProv); 250 86 251 if (NS_SUCCEEDED (rc)) 87 registrar->AutoRegister (nsnull); 88 } 89 } 90 91 #endif 252 { 253 nsCOMPtr <nsIComponentRegistrar> registrar = 254 do_QueryInterface (serviceManager, &rc); 255 if (NS_SUCCEEDED (rc)) 256 registrar->AutoRegister (nsnull); 257 } 258 } 259 } 260 261 #endif /* !defined (VBOX_WITH_XPCOM) */ 92 262 93 263 AssertComRC (rc); … … 96 266 } 97 267 98 void Shutdown() 99 { 268 HRESULT Shutdown() 269 { 270 HRESULT rc = S_OK; 271 100 272 #if !defined (VBOX_WITH_XPCOM) 101 273 102 274 CoUninitialize(); 103 275 104 #else 276 #else /* !defined (VBOX_WITH_XPCOM) */ 105 277 106 278 nsCOMPtr <nsIEventQueue> eventQ; 107 nsresult rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 108 if (NS_SUCCEEDED (rc)) 109 { 279 rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 280 281 if (NS_SUCCEEDED (rc) || rc == NS_ERROR_NOT_AVAILABLE) 282 { 283 /* NS_ERROR_NOT_AVAILABLE seems to mean that 284 * nsIEventQueue::StopAcceptingEvents() has been called (see 285 * nsEventQueueService.cpp). We hope that this error code always means 286 * just that in this case and assume that we're on the main thread 287 * (it's a kind of unexpected behavior if a non-main thread ever calls 288 * StopAcceptingEvents() on the main event queue). */ 289 110 290 BOOL isOnMainThread = FALSE; 111 eventQ->IsOnCurrentThread (&isOnMainThread); 112 eventQ = nsnull; /* early release */ 113 if (isOnMainThread) 291 if (NS_SUCCEEDED (rc)) 292 { 293 rc = eventQ->IsOnCurrentThread (&isOnMainThread); 294 eventQ = nsnull; /* early release */ 295 } 296 else 297 { 298 isOnMainThread = TRUE; 299 rc = NS_OK; 300 } 301 302 if (NS_SUCCEEDED (rc) && isOnMainThread) 114 303 { 115 304 /* only the main thread needs to uninitialize XPCOM */ 116 NS_ShutdownXPCOM (nsnull);305 rc = NS_ShutdownXPCOM (nsnull); 117 306 XPCOMGlueShutdown(); 118 307 } 119 308 } 120 309 121 #endif 310 #endif /* !defined (VBOX_WITH_XPCOM) */ 311 312 AssertComRC (rc); 313 314 return rc; 122 315 } 123 316 -
trunk/src/VBox/Main/linux/server.cpp
r2331 r2976 23 23 #include <ipcCID.h> 24 24 25 #include <nsIServiceManager.h>26 25 #include <nsIComponentRegistrar.h> 27 26 … … 29 28 #include <nsEventQueueUtils.h> 30 29 31 // for NS_InitXPCOM2 with bin dir parameter 32 #include <nsEmbedString.h> 33 #include <nsIFile.h> 34 #include <nsILocalFile.h> 30 // for nsMyFactory 31 #include <nsIGenericFactory.h> 32 #include <nsIClassInfo.h> 35 33 36 34 #include "linux/server.h" 35 37 36 #include "Logging.h" 38 37 … … 45 44 #include <VBox/version.h> 46 45 47 // for nsMyFactory 48 #include "nsIGenericFactory.h" 49 #include "nsIClassInfo.h" 46 #include <VBox/com/com.h> 50 47 51 48 #include <stdio.h> … … 1073 1070 do 1074 1071 { 1075 XPCOMGlueStartup (nsnull); 1076 1077 char path [RTPATH_MAX]; 1078 path [0] = '\0'; 1079 1080 nsCOMPtr<nsIFile> nsAppPath; 1081 { 1082 /* get the path to the executable */ 1083 char *appPath = NULL; 1084 #if defined (DEBUG) 1085 appPath = getenv ("VIRTUALBOX_APP_HOME"); 1086 if (appPath) 1087 RTPathReal (appPath, path, RTPATH_MAX); 1088 else 1089 #endif 1090 RTPathProgram (path, RTPATH_MAX); 1091 appPath = path; 1092 1093 nsCOMPtr<nsILocalFile> file; 1094 rc = NS_NewNativeLocalFile (nsEmbedCString (appPath), 1095 PR_FALSE, getter_AddRefs (file)); 1096 if (NS_SUCCEEDED (rc)) 1097 nsAppPath = do_QueryInterface (file, &rc); 1098 } 1072 rc = com::Initialize(); 1099 1073 if (NS_FAILED (rc)) 1100 1074 { 1101 printf ("ERROR: Failed to create file object! (rc=%08X)\n", rc);1075 printf ("ERROR: Failed to initialize XPCOM! (rc=%08X)\n", rc); 1102 1076 break; 1103 1077 } 1104 1078 1105 /* not really necessary at the moment */ 1106 #if 0 1107 if (!RTProcGetExecutableName (path, sizeof (path))) 1108 { 1109 printf ("ERROR: Failed to get executable name!\n"); 1110 break; 1111 } 1112 #endif 1113 1114 nsCOMPtr<nsIServiceManager> servMan; 1115 NS_InitXPCOM2 (getter_AddRefs (servMan), nsAppPath, nsnull); 1116 if (!servMan) 1117 { 1118 printf ("ERROR: Failed to get service manager!\n"); 1119 break; 1120 } 1121 1122 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface (servMan); 1123 if (!registrar) 1124 { 1125 printf ("ERROR: Failed to get component registrar!\n"); 1079 nsCOMPtr <nsIComponentRegistrar> registrar; 1080 rc = NS_GetComponentRegistrar (getter_AddRefs (registrar)); 1081 if (NS_FAILED (rc)) 1082 { 1083 printf ("ERROR: Failed to get component registrar! (rc=%08X)\n", rc); 1126 1084 break; 1127 1085 } … … 1229 1187 } 1230 1188 1231 gIpcServ->RemoveName ( path);1232 1233 / / stop accepting new events1189 gIpcServ->RemoveName (VBOXSVC_IPC_NAME); 1190 1191 /* stop accepting new events */ 1234 1192 gEventQ->StopAcceptingEvents(); 1235 // process any remaining events 1193 1194 /* process any remaining events */ 1236 1195 gEventQ->ProcessPendingEvents(); 1237 1196 1238 1197 printf ("Terminated event loop.\n"); 1239 1240 1198 } 1241 1199 while (0); // this scopes the nsCOMPtrs … … 1244 1202 NS_IF_RELEASE (gEventQ); 1245 1203 1246 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM 1247 LogFlowFunc (("Calling NS_ShutdownXPCOM()...\n")); 1248 rc = NS_ShutdownXPCOM (nsnull); 1249 LogFlowFunc (("Finished NS_ShutdownXPCOM() (rc=%08X)\n", rc)); 1204 /* no nsCOMPtrs are allowed to be alive when you call com::Shutdown(). */ 1205 1206 LogFlowFunc (("Calling com::Shutdown()...\n")); 1207 rc = com::Shutdown(); 1208 LogFlowFunc (("Finished com::Shutdown() (rc=%08X)\n", rc)); 1250 1209 1251 1210 if (NS_FAILED (rc)) 1252 1211 printf ("ERROR: Failed to shutdown XPCOM! (rc=%08X)\n", rc); 1253 1212 1254 XPCOMGlueShutdown();1255 1256 1213 printf ("XPCOM server has shutdown.\n"); 1257 1214
Note:
See TracChangeset
for help on using the changeset viewer.