VirtualBox

source: vbox/trunk/src/VBox/Main/webservice/vboxweb.h@ 16120

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

export webservices to OSE

  • Property filesplitter.c set to Makefile.kmk
  • Property svn:eol-style set to native
File size: 7.1 KB
Line 
1/*
2 * vboxweb.h:
3 * header file for "real" web server code.
4 *
5 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
6 *
7 * Sun Microsystems, Inc. confidential
8 * All rights reserved
9 */
10
11/****************************************************************************
12 *
13 * debug macro
14 *
15 ****************************************************************************/
16
17void WebLog(const char *pszFormat, ...);
18
19// #ifdef DEBUG
20#define WEBDEBUG(a) if (g_fVerbose) { WebLog a; }
21// #else
22// #define WEBDEBUG(a) do { } while(0)
23// #endif
24
25/****************************************************************************
26 *
27 * global variables
28 *
29 ****************************************************************************/
30
31extern ComPtr <IVirtualBox> G_pVirtualBox;
32extern bool g_fVerbose;
33
34extern PRTSTREAM g_pstrLog;
35
36/****************************************************************************
37 *
38 * typedefs
39 *
40 ****************************************************************************/
41
42// type used by gSOAP-generated code
43typedef std::string WSDLT_ID; // combined managed object ref (session ID plus object ID)
44typedef std::string vbox__uuid;
45
46// type used internally by our class
47// typedef WSDLT_ID ManagedObjectID;
48
49// #define VBOXWEB_ERROR_BASE 10000
50// #define VBOXWEB_INVALID_MANAGED_OBJECT (VBOXWEB_ERROR_BASE + 0)
51// #define VBOXWEB_INVALID_MANAGED_OBJECT_TYPE (VBOXWEB_ERROR_BASE + 1)
52
53/****************************************************************************
54 *
55 * SOAP exceptions
56 *
57 ****************************************************************************/
58
59void RaiseSoapInvalidObjectFault(struct soap *soap, WSDLT_ID obj);
60
61void RaiseSoapRuntimeFault(struct soap *soap, HRESULT apirc, IUnknown *pObj);
62
63/****************************************************************************
64 *
65 * conversion helpers
66 *
67 ****************************************************************************/
68
69std::string ConvertComString(const com::Bstr &bstr);
70
71std::string ConvertComString(const com::Guid &bstr);
72
73/****************************************************************************
74 *
75 * managed object reference classes
76 *
77 ****************************************************************************/
78
79class WebServiceSessionPrivate;
80class ManagedObjectRef;
81
82/**
83 *
84 */
85class WebServiceSession
86{
87 friend class ManagedObjectRef;
88
89 private:
90 uint64_t _uSessionID;
91 WebServiceSessionPrivate *_pp;
92 bool _fDestructing;
93
94 ManagedObjectRef *_pISession;
95
96 time_t _tLastObjectLookup;
97
98 // hide the copy constructor because we're not copyable
99 WebServiceSession(const WebServiceSession &copyFrom);
100
101 public:
102 WebServiceSession();
103
104 ~WebServiceSession();
105
106 int authenticate(const char *pcszUsername,
107 const char *pcszPassword);
108
109 ManagedObjectRef* findRefFromPtr(const ComPtr<IUnknown> &pcu);
110
111 uint64_t getID() const
112 {
113 return _uSessionID;
114 }
115
116 WSDLT_ID getSessionObject() const;
117
118 void touch();
119
120 time_t getLastObjectLookup() const
121 {
122 return _tLastObjectLookup;
123 }
124
125 static WebServiceSession* findSessionFromRef(const WSDLT_ID &id);
126
127 void DumpRefs();
128};
129
130/**
131 * ManagedObjectRef is used to map COM pointers to object IDs
132 * within a session. Such object IDs are 64-bit integers.
133 *
134 * When a webservice method call is invoked on an object, it
135 * has an opaque string called a "managed object reference". Such
136 * a string consists of a session ID combined with an object ID.
137 *
138 */
139class ManagedObjectRef
140{
141 protected:
142 // owning session:
143 WebServiceSession &_session;
144
145 // value:
146 ComPtr<IUnknown> _pObj;
147 const char *_pcszInterface;
148
149 // keys:
150 uint64_t _id;
151 uintptr_t _ulp;
152
153 // long ID as string
154 WSDLT_ID _strID;
155
156 public:
157 ManagedObjectRef(WebServiceSession &session,
158 const char *pcszInterface,
159 const ComPtr<IUnknown> &obj);
160 ~ManagedObjectRef();
161
162 uint64_t getID()
163 {
164 return _id;
165 }
166
167 ComPtr<IUnknown> getComPtr()
168 {
169 return _pObj;
170 }
171
172 WSDLT_ID toWSDL() const;
173 const char* getInterfaceName() const
174 {
175 return _pcszInterface;
176 }
177
178 static int findRefFromId(const WSDLT_ID &id,
179 ManagedObjectRef **pRef);
180
181 static ManagedObjectRef* findFromPtr(ComPtr<IUnknown> pcu);
182 static ManagedObjectRef* create(const WSDLT_ID &idParent,
183 ComPtr<IUnknown> pcu);
184
185};
186
187/**
188 * Template function that resolves a managed object reference to a COM pointer
189 * of the template class T. Gets called from tons of generated code in
190 * methodmaps.cpp.
191 *
192 * This is a template function so that we can support ComPtr's for arbitrary
193 * interfaces and automatically verify that the managed object reference on
194 * the internal stack actually is of the expected interface.
195 *
196 * @param soap
197 * @param id integer managed object reference, as passed in by web service client
198 * @param pComPtr reference to COM pointer object that receives the com pointer,
199 * if SOAP_OK is returned
200 * @return error code or SOAP_OK if no error
201 */
202template <class T>
203int findComPtrFromId(struct soap *soap,
204 const WSDLT_ID &id,
205 ComPtr<T> &pComPtr)
206{
207 int rc;
208 ManagedObjectRef *pRef;
209 if ((rc = ManagedObjectRef::findRefFromId(id, &pRef)))
210 RaiseSoapInvalidObjectFault(soap, id);
211 else
212 {
213 if (pComPtr = pRef->getComPtr())
214 return 0;
215
216 WEBDEBUG((" Interface not support for object reference %s, which is of class %s\n", id.c_str(), pRef->getInterfaceName()));
217 rc = VERR_WEB_UNSUPPORTED_INTERFACE;
218 RaiseSoapInvalidObjectFault(soap, id); // @todo better message
219 }
220
221 return rc;
222}
223
224/**
225 * Template function that creates a new managed object for the given COM
226 * pointer of the template class T. If a reference already exists for the
227 * given pointer, then that reference's ID is returned instead.
228 *
229 * @param idParent managed object reference of calling object; used to extract session ID
230 * @param pc COM object for which to create a reference
231 * @return existing or new managed object reference
232 */
233template <class T>
234WSDLT_ID createOrFindRefFromComPtr(const WSDLT_ID &idParent,
235 const char *pcszInterface,
236 const ComPtr<T> &pc)
237{
238 WebServiceSession* pSession;
239 if ((pSession = WebServiceSession::findSessionFromRef(idParent)))
240 {
241 // WEBDEBUG(("\n-- found session for %s\n", idParent.c_str()));
242 ManagedObjectRef *pRef;
243 if ( ((pRef = pSession->findRefFromPtr(pc)))
244 || ((pRef = new ManagedObjectRef(*pSession, pcszInterface, pc)))
245 )
246 return pRef->toWSDL();
247 }
248
249 return 0;
250}
251
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