VirtualBox

source: vbox/trunk/src/VBox/Main/glue/com.cpp@ 1756

Last change on this file since 1756 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/** @file
2 *
3 * MS COM / XPCOM Abstraction Layer
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#if defined (__WIN__)
23
24#include <objbase.h>
25
26#else // !defined (__WIN__)
27
28#include <stdlib.h>
29#include <VBox/err.h>
30#include <iprt/path.h>
31
32#include <nsXPCOMGlue.h>
33#include <nsIComponentRegistrar.h>
34#include <nsIServiceManager.h>
35#include <nsCOMPtr.h>
36#include <nsEventQueueUtils.h>
37
38#endif // !defined (__WIN__)
39
40#include "VBox/com/com.h"
41#include "VBox/com/assert.h"
42
43namespace com
44{
45
46HRESULT Initialize()
47{
48 HRESULT rc = E_FAIL;
49
50#if defined (__WIN__)
51 rc = CoInitializeEx (NULL, COINIT_MULTITHREADED |
52 COINIT_DISABLE_OLE1DDE |
53 COINIT_SPEED_OVER_MEMORY);
54#else
55 /*
56 * Set VBOX_XPCOM_HOME if not present
57 */
58 if (!getenv("VBOX_XPCOM_HOME"))
59 {
60 /* get the executable path */
61 char szPathProgram[1024];
62 int rcVBox = RTPathProgram(szPathProgram, sizeof(szPathProgram));
63 if (VBOX_SUCCESS(rcVBox))
64 {
65 setenv("VBOX_XPCOM_HOME", szPathProgram, 1);
66 }
67 }
68
69 nsCOMPtr <nsIEventQueue> eventQ;
70 rc = NS_GetMainEventQ (getter_AddRefs (eventQ));
71 if (rc == NS_ERROR_NOT_INITIALIZED)
72 {
73 XPCOMGlueStartup (nsnull);
74 nsCOMPtr <nsIServiceManager> serviceManager;
75 rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager), nsnull, nsnull);
76 if (NS_SUCCEEDED (rc))
77 {
78 nsCOMPtr <nsIComponentRegistrar> registrar =
79 do_QueryInterface (serviceManager, &rc);
80 if (NS_SUCCEEDED (rc))
81 registrar->AutoRegister (nsnull);
82 }
83 }
84#endif
85
86 AssertComRC (rc);
87
88 return rc;
89}
90
91void Shutdown()
92{
93#if defined (__WIN__)
94 CoUninitialize();
95#else
96 nsCOMPtr <nsIEventQueue> eventQ;
97 nsresult rc = NS_GetMainEventQ (getter_AddRefs (eventQ));
98 if (NS_SUCCEEDED (rc))
99 {
100 BOOL isOnMainThread = FALSE;
101 eventQ->IsOnCurrentThread (&isOnMainThread);
102 eventQ = nsnull; // early release
103 if (isOnMainThread)
104 {
105 // only the main thread needs to uninitialize XPCOM
106 NS_ShutdownXPCOM (nsnull);
107 XPCOMGlueShutdown();
108 }
109 }
110#endif
111}
112
113}; // namespace com
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette