Changeset 60504 in vbox for trunk/include
- Timestamp:
- Apr 14, 2016 4:39:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/ptr.h
r58110 r60504 4 4 5 5 /* 6 * Copyright (C) 2006-201 5Oracle Corporation6 * Copyright (C) 2006-2016 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 35 35 #endif 36 36 37 #if !defined (VBOX_WITH_XPCOM) 38 #include <atlbase.h> 39 #ifndef _ATL_IIDOF 40 # define _ATL_IIDOF(c) __uuidof(c) 41 #endif 42 #else 43 #include <nsISupportsUtils.h> 44 45 #endif /* !defined (VBOX_WITH_XPCOM) */ 37 #ifdef VBOX_WITH_XPCOM 38 # include <nsISupportsUtils.h> 39 #endif /* VBOX_WITH_XPCOM */ 46 40 47 41 #include <VBox/com/defs.h> … … 62 56 const char *serverName, 63 57 const nsIID &id, 64 void **ppobj);58 void **ppobj); 65 59 HRESULT GlueCreateInstance(const CLSID &clsid, 66 60 const nsIID &id, 67 void **ppobj);61 void **ppobj); 68 62 } 69 63 … … 130 124 m_p = NULL; 131 125 if (!that.isNull()) 132 that->QueryInterface(COM_IIDOF(T), (void **)&m_p);126 that->QueryInterface(COM_IIDOF(T), (void **)&m_p); 133 127 } 134 128 … … 155 149 m_p = NULL; 156 150 if (p) 157 p->QueryInterface(COM_IIDOF(T), (void **)&m_p);158 } 159 160 /** 161 * Specialization: copy constructor from a plain T * pointer. Calls AddRef().151 p->QueryInterface(COM_IIDOF(T), (void **)&m_p); 152 } 153 154 /** 155 * Specialization: copy constructor from a plain T * pointer. Calls AddRef(). 162 156 */ 163 157 ComPtr(T *that_p) … … 178 172 ComPtr& operator=(const ComPtr<T2> &that) 179 173 { 180 return operator=((T2 *)that);174 return operator=((T2 *)that); 181 175 } 182 176 … … 187 181 ComPtr& operator=(const ComPtr &that) 188 182 { 189 return operator=((T *)that);183 return operator=((T *)that); 190 184 } 191 185 … … 204 198 cleanup(); 205 199 if (p) 206 p->QueryInterface(COM_IIDOF(T), (void **)&m_p);200 p->QueryInterface(COM_IIDOF(T), (void **)&m_p); 207 201 return *this; 208 202 } 209 203 210 204 /** 211 * Specialization of the previous: assignment from a plain T * pointer.205 * Specialization of the previous: assignment from a plain T * pointer. 212 206 * Calls Release() on the previous member pointer, if any, and AddRef() on the new one. 213 207 */ … … 243 237 } 244 238 245 246 bool operator<(T* p) const 239 bool operator<(T *p) const 247 240 { 248 241 return m_p < p; … … 253 246 * parameters to COM method calls. 254 247 */ 255 operator T *() const248 operator T *() const 256 249 { 257 250 return m_p; … … 262 255 * pointer). 263 256 */ 264 T *operator->() const257 T *operator->() const 265 258 { 266 259 return m_p; … … 276 269 * can get cleaned up properly. 277 270 */ 278 T **asOutParam()271 T **asOutParam() 279 272 { 280 273 cleanup(); … … 294 287 { 295 288 if (m_p) 296 return m_p->QueryInterface(COM_IIDOF(T2), (void **)pp);289 return m_p->QueryInterface(COM_IIDOF(T2), (void **)pp); 297 290 else 298 291 { … … 310 303 */ 311 304 template <class T2> 312 bool operator==(T2 *p)305 bool operator==(T2 *p) 313 306 { 314 307 IUnknown *p1 = NULL; 315 308 bool fNeedsRelease1 = false; 316 309 if (m_p) 317 fNeedsRelease1 = (SUCCEEDED(m_p->QueryInterface(COM_IIDOF(IUnknown), (void **)&p1)));310 fNeedsRelease1 = (SUCCEEDED(m_p->QueryInterface(COM_IIDOF(IUnknown), (void **)&p1))); 318 311 319 312 IUnknown *p2 = NULL; 320 313 bool fNeedsRelease2 = false; 321 314 if (p) 322 fNeedsRelease2 = (SUCCEEDED(p->QueryInterface(COM_IIDOF(IUnknown), (void **)&p2)));315 fNeedsRelease2 = (SUCCEEDED(p->QueryInterface(COM_IIDOF(IUnknown), (void **)&p2))); 323 316 324 317 bool f = p1 == p2; … … 338 331 HRESULT rc; 339 332 T *obj = NULL; 340 #if !defined (VBOX_WITH_XPCOM)341 rc = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, _ATL_IIDOF(T),342 (void **)&obj);343 #else /* !defined (VBOX_WITH_XPCOM)*/333 #ifndef VBOX_WITH_XPCOM 334 rc = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, COM_IIDOF(T), 335 (void **)&obj); 336 #else /* VBOX_WITH_XPCOM */ 344 337 using namespace com; 345 rc = GlueCreateInstance(clsid, NS_GET_IID(T), (void **)&obj);346 #endif /* !defined (VBOX_WITH_XPCOM)*/338 rc = GlueCreateInstance(clsid, NS_GET_IID(T), (void **)&obj); 339 #endif /* VBOX_WITH_XPCOM */ 347 340 *this = obj; 348 341 if (SUCCEEDED(rc)) … … 362 355 HRESULT createLocalObject(const CLSID &clsid) 363 356 { 364 #if !defined (VBOX_WITH_XPCOM)357 #ifndef VBOX_WITH_XPCOM 365 358 HRESULT rc; 366 359 T *obj = NULL; 367 rc = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, _ATL_IIDOF(T),368 (void **)&obj);360 rc = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, COM_IIDOF(T), 361 (void **)&obj); 369 362 *this = obj; 370 363 if (SUCCEEDED(rc)) 371 364 obj->Release(); 372 365 return rc; 373 #else /* !defined (VBOX_WITH_XPCOM)*/366 #else /* VBOX_WITH_XPCOM */ 374 367 return createInprocObject(clsid); 375 #endif /* !defined (VBOX_WITH_XPCOM)*/368 #endif /* VBOX_WITH_XPCOM */ 376 369 } 377 370 … … 386 379 { 387 380 T *obj = NULL; 388 HRESULT rc = GlueCreateObjectOnServer(clsid, serverName, NS_GET_IID(T), (void **)&obj);381 HRESULT rc = GlueCreateObjectOnServer(clsid, serverName, NS_GET_IID(T), (void **)&obj); 389 382 *this = obj; 390 383 if (SUCCEEDED(rc)) … … 395 388 396 389 protected: 397 void copyFrom(T *p)390 void copyFrom(T *p) 398 391 { 399 392 m_p = p; … … 411 404 } 412 405 406 public: 407 // Do NOT access this member unless you really know what you're doing! 413 408 T *m_p; 414 409 }; … … 479 474 { 480 475 HRESULT rc; 481 #if !defined (VBOX_WITH_XPCOM)482 # 483 CComObjectNoLock<T> *obj = newCComObjectNoLock<T>();476 #ifndef VBOX_WITH_XPCOM 477 # ifdef VBOX_COM_OUTOFPROC_MODULE 478 ATL::CComObjectNoLock<T> *obj = new ATL::CComObjectNoLock<T>(); 484 479 if (obj) 485 480 { … … 490 485 else 491 486 rc = E_OUTOFMEMORY; 492 # 493 CComObject<T> *obj = NULL;494 rc = CComObject<T>::CreateInstance(&obj);495 # 496 #else /* !defined (VBOX_WITH_XPCOM)*/487 # else 488 ATL::CComObject<T> *obj = NULL; 489 rc = ATL::CComObject<T>::CreateInstance(&obj); 490 # endif 491 #else /* VBOX_WITH_XPCOM */ 497 492 CComObject<T> *obj = new CComObject<T>(); 498 493 if (obj) … … 500 495 else 501 496 rc = E_OUTOFMEMORY; 502 #endif /* !defined (VBOX_WITH_XPCOM)*/497 #endif /* VBOX_WITH_XPCOM */ 503 498 *this = obj; 504 499 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.