- Timestamp:
- Jul 2, 2010 4:39:53 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 63308
- Location:
- trunk/src/VBox/Main/webservice
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/webservice/vboxweb.cpp
r30577 r30583 1168 1168 } 1169 1169 1170 _pISession = new ManagedObjectRef(*this, g_pcszISession, session );1170 _pISession = new ManagedObjectRef(*this, g_pcszISession, session, com::Guid(COM_IIDOF(ISession))); 1171 1171 1172 1172 if (g_fVerbose) … … 1197 1197 * @return The existing ManagedObjectRef that represents the COM object, or NULL if there's none yet. 1198 1198 */ 1199 ManagedObjectRef* WebServiceSession::findRefFromPtr(const ComPtr<IUnknown> &pcu)1199 ManagedObjectRef* WebServiceSession::findRefFromPtr(const IUnknown *pObject) 1200 1200 { 1201 1201 Assert(g_pSessionsLockHandle->isWriteLockOnCurrentThread()); 1202 1202 1203 IUnknown *p = pcu; 1204 uintptr_t ulp = (uintptr_t)p; 1205 ManagedObjectRef *pRef; 1203 uintptr_t ulp = (uintptr_t)pObject; 1206 1204 // WEBDEBUG((" %s: looking up 0x%lX\n", __FUNCTION__, ulp)); 1207 1205 ManagedObjectsMapByPtr::iterator it = _pp->_mapManagedObjectsByPtr.find(ulp); 1208 1206 if (it != _pp->_mapManagedObjectsByPtr.end()) 1209 1207 { 1210 pRef = it->second;1208 ManagedObjectRef *pRef = it->second; 1211 1209 WSDLT_ID id = pRef->toWSDL(); 1212 1210 WEBDEBUG((" %s: found existing ref %s (%s) for COM obj 0x%lX\n", __FUNCTION__, id.c_str(), pRef->getInterfaceName(), ulp)); 1213 }1214 else1215 pRef = NULL; 1216 return pRef;1211 return pRef; 1212 } 1213 1214 return NULL; 1217 1215 } 1218 1216 … … 1266 1264 } 1267 1265 1268 /**1269 *1270 */1271 void WebServiceSession::DumpRefs()1272 {1273 WEBDEBUG((" dumping object refs:\n"));1274 ManagedObjectsIteratorById1275 iter = _pp->_mapManagedObjectsById.begin(),1276 end = _pp->_mapManagedObjectsById.end();1277 for (;1278 iter != end;1279 ++iter)1280 {1281 ManagedObjectRef *pRef = iter->second;1282 uint64_t id = pRef->getID();1283 void *p = pRef->getComPtr();1284 WEBDEBUG((" objid %llX: comptr 0x%lX\n", id, p));1285 }1286 }1287 1266 1288 1267 /**************************************************************************** … … 1309 1288 * instance already exists for a given COM pointer. 1310 1289 * 1290 * This constructor calls AddRef() on the given COM object, and 1291 * the destructor will call Release(). 1292 * 1311 1293 * This does _not_ check whether another instance already 1312 1294 * exists in the hash. This gets called only from the … … 1320 1302 ManagedObjectRef::ManagedObjectRef(WebServiceSession &session, 1321 1303 const char *pcszInterface, 1322 const ComPtr<IUnknown> &pc) 1304 IUnknown *pObject, 1305 const com::Guid &guidInterface) 1323 1306 : _session(session), 1324 _pObj(pc), 1307 _pvObj(pObject), 1308 _guidInterface(guidInterface), 1325 1309 _pcszInterface(pcszInterface) 1326 1310 { 1327 ComPtr<IUnknown> pcUnknown(pc); 1328 _ulp = (uintptr_t)(IUnknown*)pcUnknown; 1311 Assert(pObject); 1312 pObject->AddRef(); 1313 _ulp = (uintptr_t)pObject; 1329 1314 1330 1315 Assert(g_pSessionsLockHandle->isWriteLockOnCurrentThread()); … … 1347 1332 /** 1348 1333 * Destructor; removes the instance from the global hash of 1349 * managed objects. 1334 * managed objects. Calls Release() on the contained COM object. 1350 1335 * 1351 1336 * Preconditions: Caller must have locked g_pSessionsLockHandle. … … 1356 1341 ULONG64 cTotal = --g_cManagedObjects; 1357 1342 1358 WEBDEBUG((" * %s: deleting MOR for ID %llX (%s); now %lld objects total\n", __FUNCTION__, _id, _pcszInterface, cTotal)); 1343 Assert(_pvObj); 1344 1345 uint32_t cRefs = ((IUnknown*)_pvObj)->Release(); 1346 WEBDEBUG((" * %s: deleting MOR for ID %llX (%s; COM refcount now %RI32); now %lld objects total\n", __FUNCTION__, _id, _pcszInterface, cRefs, cTotal)); 1359 1347 1360 1348 // if we're being destroyed from the session's destructor, … … 1424 1412 } 1425 1413 1426 WEBDEBUG((" %s(): sessid %llX, objid %llX\n", __FUNCTION__, sessid, objid));1427 1414 SessionsMapIterator it = g_mapSessions.find(sessid); 1428 1415 if (it == g_mapSessions.end()) … … 1597 1584 // that it will be implicitly be included in all future requests of this 1598 1585 // webservice client 1599 ManagedObjectRef *pRef = new ManagedObjectRef(*pSession, g_pcszIVirtualBox, g_pVirtualBox );1586 ManagedObjectRef *pRef = new ManagedObjectRef(*pSession, g_pcszIVirtualBox, g_pVirtualBox, COM_IIDOF(IVirtualBox)); 1600 1587 resp->returnval = pRef->toWSDL(); 1601 1588 WEBDEBUG(("VirtualBox object ref is %s\n", resp->returnval.c_str())); … … 1672 1659 return SOAP_OK; 1673 1660 } 1661 -
trunk/src/VBox/Main/webservice/vboxweb.h
r30577 r30583 121 121 const char *pcszPassword); 122 122 123 ManagedObjectRef* findRefFromPtr(const ComPtr<IUnknown> &pcu);123 ManagedObjectRef* findRefFromPtr(const IUnknown *pObject); 124 124 125 125 uint64_t getID() const … … 157 157 WebServiceSession &_session; 158 158 159 // value: 160 ComPtr<IUnknown> _pObj; 159 void *_pvObj; // COM object 160 com::Guid _guidInterface; // and the interface for which it was created 161 161 162 const char *_pcszInterface; 162 163 … … 171 172 ManagedObjectRef(WebServiceSession &session, 172 173 const char *pcszInterface, 173 const ComPtr<IUnknown> &obj); 174 IUnknown *pObject, 175 const com::Guid &guidInterface); 174 176 ~ManagedObjectRef(); 175 177 … … 179 181 } 180 182 181 ComPtr<IUnknown> getComPtr() 182 { 183 return _pObj; 183 /** 184 * Returns the contained COM pointer and the UUID of the COM interface 185 * which it supports. 186 * @param 187 * @return 188 */ 189 const com::Guid& getPtr(void** pp) 190 { 191 *pp = _pvObj; 192 return _guidInterface; 184 193 } 185 194 … … 202 211 /** 203 212 * Template function that resolves a managed object reference to a COM pointer 204 * of the template class T. Gets called from tons of generated code in213 * of the template class T. Gets called only from tons of generated code in 205 214 * methodmaps.cpp. 206 215 * … … 236 245 if (fNullAllowed && pRef == NULL) 237 246 { 247 WEBDEBUG((" %s(): returning NULL object as permitted\n", __FUNCTION__)); 238 248 pComPtr.setNull(); 239 249 return 0; 240 250 } 241 251 242 // pRef->getComPtr returns a ComPtr<IUnknown>; by casting it to 243 // ComPtr<T>, we implicitly do a COM queryInterface() call 244 if (pComPtr = pRef->getComPtr()) 252 const com::Guid &guidCaller = COM_IIDOF(T); 253 254 // pRef->getPtr returns a void* 255 void *p; 256 const com::Guid &guidInterface = pRef->getPtr(&p); 257 258 if (guidInterface == guidCaller) 259 { 260 // same interface: then no QueryInterface needed 261 WEBDEBUG((" %s(): returning pointer 0x%lX for original interface %s\n", __FUNCTION__, p, pRef->getInterfaceName())); 262 pComPtr = (T*)p; // calls AddRef() once 245 263 return 0; 264 } 265 266 // QueryInterface tests whether p actually supports the templated T interface 267 T *pT; 268 ((IUnknown*)p)->QueryInterface(guidCaller, (void**)&pT); // this adds a reference count 269 if (pT) 270 { 271 // assign to caller's ComPtr<T>; use asOutParam() to avoid adding another reference 272 WEBDEBUG((" %s(): returning pointer 0x%lX for queried interface %RTuuid\n", __FUNCTION__, p, guidCaller.raw())); 273 *(pComPtr.asOutParam()) = pT; 274 return 0; 275 } 246 276 247 277 WEBDEBUG((" Interface not supported for object reference %s, which is of class %s\n", id.c_str(), pRef->getInterfaceName())); … … 254 284 255 285 /** 256 * Template function that creates a new managed object for the given COM 257 * pointer of the template class T. If a reference already exists for the 258 * given pointer, then that reference's ID is returned instead. 286 * Creates a new managed object for the given COM pointer. If a reference already exists 287 * for the given pointer, then that reference's ID is returned instead. 259 288 * 260 289 * @param idParent managed object reference of calling object; used to extract session ID … … 265 294 WSDLT_ID createOrFindRefFromComPtr(const WSDLT_ID &idParent, 266 295 const char *pcszInterface, 267 constComPtr<T> &pc)296 ComPtr<T> &pc) 268 297 { 269 298 // NULL comptr should return NULL MOR 270 299 if (pc.isNull()) 271 300 { 272 WEBDEBUG((" createOrFindRefFromComPtr(): returning empty MOR for NULL %s pointer\n", pcszInterface));301 WEBDEBUG((" createOrFindRefFromComPtr(): returning empty MOR for NULL COM pointer\n")); 273 302 return ""; 274 303 } … … 278 307 if ((pSession = WebServiceSession::findSessionFromRef(idParent))) 279 308 { 280 // WEBDEBUG(("\n-- found session for %s\n", idParent.c_str()));281 309 ManagedObjectRef *pRef; 282 if ( ((pRef = pSession->findRefFromPtr(pc))) 283 || ((pRef = new ManagedObjectRef(*pSession, pcszInterface, pc))) 310 ComPtr<IUnknown> pUnknown = pc; // this calls QueryInterface(IUnknown) 311 if ( ((pRef = pSession->findRefFromPtr(pUnknown))) 312 || ((pRef = new ManagedObjectRef(*pSession, 313 pcszInterface, 314 pUnknown, // IUnknown *pObject 315 COM_IIDOF(T)))) 284 316 ) 285 317 return pRef->toWSDL(); … … 290 322 return ""; 291 323 } 292
Note:
See TracChangeset
for help on using the changeset viewer.