VirtualBox

source: vbox/trunk/src/VBox/Main/cbinding/VBoxXPCOMC.cpp@ 17762

Last change on this file since 17762 was 17757, checked in by vboxsync, 16 years ago

Cbinding: removed unnecessary functions

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: VBoxXPCOMC.cpp 17757 2009-03-12 15:31:16Z vboxsync $ */
2/** @file VBoxXPCOMC.cpp
3 * Utility functions to use with the C binding for XPCOM.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#define LOG_GROUP LOG_GROUP_MAIN
23#include <nsMemory.h>
24#include <nsIServiceManager.h>
25#include <nsEventQueueUtils.h>
26
27#include <iprt/string.h>
28#include <iprt/env.h>
29#include <VBox/log.h>
30
31#include "VirtualBox_XPCOM.h"
32#include "VirtualBox_CXPCOM.h"
33#include "VBox/com/com.h"
34
35using namespace std;
36
37static ISession *Session;
38static IVirtualBox *Ivirtualbox;
39static nsIServiceManager *serviceManager;
40static nsIComponentManager *manager;
41
42void VBoxComUninitialize(void);
43
44int
45VBoxUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString)
46{
47 return RTUtf16ToUtf8(pwszString, ppszString);
48}
49
50int
51VBoxUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString)
52{
53 return RTStrToUtf16(pszString, ppwszString);
54}
55
56void
57VBoxUtf16Free(PRUnichar *pwszString)
58{
59 RTUtf16Free(pwszString);
60}
61
62void
63VBoxUtf8Free(char *pszString)
64{
65 RTStrFree(pszString);
66}
67
68void
69VBoxComUnallocMem(void *ptr)
70{
71 if (ptr)
72 {
73 nsMemory::Free(ptr);
74 }
75}
76
77void
78VBoxComInitialize(IVirtualBox **virtualBox, ISession **session)
79{
80 nsresult rc;
81
82 *session = NULL;
83 *virtualBox = NULL;
84
85 Session = *session;
86 Ivirtualbox = *virtualBox;
87
88 rc = com::Initialize();
89 if (NS_FAILED(rc))
90 {
91 Log(("Cbinding: XPCOM could not be initialized! rc=%Rhrc\n",rc));
92 VBoxComUninitialize();
93 return;
94 }
95
96 rc = NS_GetComponentManager (&manager);
97 if (NS_FAILED(rc))
98 {
99 Log(("Cbinding: Could not get component manager! rc=%Rhrc\n",rc));
100 VBoxComUninitialize();
101 return;
102 }
103
104 rc = manager->CreateInstanceByContractID(NS_VIRTUALBOX_CONTRACTID,
105 nsnull,
106 NS_GET_IID(IVirtualBox),
107 (void **)virtualBox);
108 if (NS_FAILED(rc))
109 {
110 Log(("Cbinding: Could not instantiate VirtualBox object! rc=%Rhrc\n",rc));
111 VBoxComUninitialize();
112 return;
113 }
114
115 Log(("Cbinding: IVirtualBox object created.\n"));
116
117 rc = manager->CreateInstanceByContractID (NS_SESSION_CONTRACTID,
118 nsnull,
119 NS_GET_IID(ISession),
120 (void **)session);
121 if (NS_FAILED(rc))
122 {
123 Log(("Cbinding: Could not instantiate Session object! rc=%Rhrc\n",rc));
124 VBoxComUninitialize();
125 return;
126 }
127
128 Log(("Cbinding: ISession object created.\n"));
129}
130
131void
132VBoxComUninitialize(void)
133{
134 if (Session)
135 NS_RELEASE(Session); // decrement refcount
136 if (Ivirtualbox)
137 NS_RELEASE(Ivirtualbox); // decrement refcount
138 if (manager)
139 NS_RELEASE(manager); // decrement refcount
140 if (serviceManager)
141 NS_RELEASE(serviceManager); // decrement refcount
142 com::Shutdown();
143 Log(("Cbinding: Cleaned up the created IVirtualBox and ISession Objects.\n"));
144}
145
146
147VBOXXPCOMC_DECL(PCVBOXXPCOM)
148VBoxGetXPCOMCFunctions(unsigned uVersion)
149{
150 /* The current version. */
151 static const VBOXXPCOMC s_Functions =
152 {
153 sizeof(VBOXXPCOMC),
154 VBOX_XPCOMC_VERSION,
155
156 VBoxComInitialize,
157 VBoxComUninitialize,
158
159 VBoxComUnallocMem,
160 VBoxUtf16Free,
161 VBoxUtf8Free,
162
163 VBoxUtf16ToUtf8,
164 VBoxUtf8ToUtf16,
165
166 VBOX_XPCOMC_VERSION
167 };
168
169 if ((uVersion & 0xffff0000U) != VBOX_XPCOMC_VERSION)
170 return NULL; /* not supported. */
171
172 return &s_Functions;
173}
174
175/* vim: set ts=4 sw=4 et: */
Note: See TracBrowser for help on using the repository browser.

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