VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/COMDefs.h@ 35740

Last change on this file since 35740 was 35638, checked in by vboxsync, 13 years ago

Main. QT/FE: fix long standing COM issue

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * Various COM definitions and COM wrapper class declarations
5 *
6 * This header is used in conjunction with the header generated from
7 * XIDL expressed interface definitions to provide cross-platform Qt-based
8 * interface wrapper classes.
9 */
10
11/*
12 * Copyright (C) 2006-2008 Oracle Corporation
13 *
14 * This file is part of VirtualBox Open Source Edition (OSE), as
15 * available from http://www.virtualbox.org. This file is free software;
16 * you can redistribute it and/or modify it under the terms of the GNU
17 * General Public License (GPL) as published by the Free Software
18 * Foundation, in version 2 as it comes in the "COPYING" file of the
19 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
20 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
21 */
22
23#ifndef __COMDefs_h__
24#define __COMDefs_h__
25
26/** @defgroup grp_QT_COM Qt-COM Support Layer
27 * @{
28 *
29 * The Qt-COM support layer provides a set of definitions and smart classes for
30 * writing simple, clean and platform-independent code to access COM/XPCOM
31 * components through exposed COM interfaces. This layer is based on the
32 * COM/XPCOM Abstraction Layer library (the VBoxCOM glue library defined in
33 * include/VBox/com and implemented in src/VBox/Main/glue).
34 *
35 * ...
36 *
37 * @defgroup grp_QT_COM_arrays Arrays
38 * @{
39 *
40 * COM/XPCOM arrays are mapped to QVector objects. QVector templates declared
41 * with a type that corresponds to the COM type of elements in the array using
42 * normal Qt-COM type mapping rules. Here is a code example that demonstrates
43 * how to call interface methods that take and return arrays (this example is
44 * based on examples given in @ref grp_COM_arrays):
45 * @code
46
47 CSomething component;
48
49 // ...
50
51 QVector <LONG> in (3);
52 in [0] = -1;
53 in [1] = -2;
54 in [2] = -3;
55
56 QVector <LONG> out;
57 QVector <LONG> ret;
58
59 ret = component.TestArrays (in, out);
60
61 for (size_t i = 0; i < ret.size(); ++ i)
62 LogFlow (("*** ret[%u]=%d\n", i, ret [i]));
63
64 * @endcode
65 * @}
66 */
67
68/* Both VBox/com/assert.h and qglobal.h contain a definition of ASSERT.
69 * Either of them can be already included here, so try to shut them up. */
70#undef ASSERT
71
72#include <VBox/com/com.h>
73#include <VBox/com/array.h>
74#include <VBox/com/assert.h>
75
76#undef ASSERT
77
78/* Qt includes */
79#include <QString>
80#include <QRect>
81#include <QUuid>
82#include <QVector>
83#include <QStringList>
84#include <QMetaType>
85
86/*
87 * Additional COM / XPCOM defines and includes
88 */
89
90#if !defined (VBOX_WITH_XPCOM)
91
92#else /* !defined (VBOX_WITH_XPCOM) */
93
94#include <nsXPCOM.h>
95#include <nsMemory.h>
96#include <nsIComponentManager.h>
97
98class XPCOMEventQSocketListener;
99
100#endif /* !defined (VBOX_WITH_XPCOM) */
101
102
103/* VirtualBox interfaces declarations */
104#if !defined (VBOX_WITH_XPCOM)
105 #include <VirtualBox.h>
106#else /* !defined (VBOX_WITH_XPCOM) */
107 #include <VirtualBox_XPCOM.h>
108#endif /* !defined (VBOX_WITH_XPCOM) */
109
110#include "VBoxDefs.h"
111
112
113/////////////////////////////////////////////////////////////////////////////
114
115class CVirtualBoxErrorInfo;
116
117/** Represents extended error information */
118class COMErrorInfo
119{
120public:
121
122 COMErrorInfo()
123 : mIsNull(true),
124 mIsBasicAvailable(false),
125 mIsFullAvailable(false),
126 mResultCode(S_OK),
127 m_pNext(NULL)
128 {}
129
130 COMErrorInfo(const COMErrorInfo &info)
131 {
132 copyFrom(info);
133 }
134
135 COMErrorInfo(const CVirtualBoxErrorInfo &info)
136 {
137 init(info);
138 }
139
140 ~COMErrorInfo()
141 {
142 cleanup();
143 }
144
145 COMErrorInfo& operator=(const COMErrorInfo &info)
146 {
147 cleanup();
148 copyFrom(info);
149 return *this;
150 }
151
152 bool isNull() const { return mIsNull; }
153
154 bool isBasicAvailable() const { return mIsBasicAvailable; }
155 bool isFullAvailable() const { return mIsFullAvailable; }
156
157 HRESULT resultCode() const { return mResultCode; }
158 QUuid interfaceID() const { return mInterfaceID; }
159 QString component() const { return mComponent; }
160 QString text() const { return mText; }
161
162 const COMErrorInfo *next() const { return m_pNext; }
163
164 QString interfaceName() const { return mInterfaceName; }
165 QUuid calleeIID() const { return mCalleeIID; }
166 QString calleeName() const { return mCalleeName; }
167
168private:
169 void init(const CVirtualBoxErrorInfo &info);
170 void copyFrom(const COMErrorInfo &x);
171 void cleanup();
172
173 void fetchFromCurrentThread(IUnknown *callee, const GUID *calleeIID);
174
175 static QString getInterfaceNameFromIID (const QUuid &id);
176
177 bool mIsNull : 1;
178 bool mIsBasicAvailable : 1;
179 bool mIsFullAvailable : 1;
180
181 HRESULT mResultCode;
182 QUuid mInterfaceID;
183 QString mComponent;
184 QString mText;
185
186 COMErrorInfo *m_pNext;
187
188 QString mInterfaceName;
189 QUuid mCalleeIID;
190 QString mCalleeName;
191
192 friend class COMBaseWithEI;
193};
194
195/////////////////////////////////////////////////////////////////////////////
196
197/**
198 * Base COM class the CInterface template and all wrapper classes are derived
199 * from. Provides common functionality for all COM wrappers.
200 */
201class COMBase
202{
203public:
204
205 static HRESULT InitializeCOM(bool fGui);
206 static HRESULT CleanupCOM();
207
208 /**
209 * Returns the result code of the last interface method called by the
210 * wrapper instance or the result of CInterface::createInstance()
211 * operation.
212 */
213 HRESULT lastRC() const { return mRC; }
214
215#if !defined (VBOX_WITH_XPCOM)
216
217 /** Converts a GUID value to QUuid */
218 static QUuid ToQUuid (const GUID &id)
219 {
220 return QUuid (id.Data1, id.Data2, id.Data3,
221 id.Data4[0], id.Data4[1], id.Data4[2], id.Data4[3],
222 id.Data4[4], id.Data4[5], id.Data4[6], id.Data4[7]);
223 }
224
225#else /* !defined (VBOX_WITH_XPCOM) */
226
227 /** Converts a GUID value to QUuid */
228 static QUuid ToQUuid (const nsID &id)
229 {
230 return QUuid (id.m0, id.m1, id.m2,
231 id.m3[0], id.m3[1], id.m3[2], id.m3[3],
232 id.m3[4], id.m3[5], id.m3[6], id.m3[7]);
233 }
234
235#endif /* !defined (VBOX_WITH_XPCOM) */
236
237 /* Arrays of arbitrary types */
238
239 template <typename QT, typename CT>
240 static void ToSafeArray (const QVector <QT> &aVec, com::SafeArray <CT> &aArr)
241 {
242 aArr.reset (aVec.size());
243 for (int i = 0; i < aVec.size(); ++i)
244 aArr [i] = static_cast<CT> (aVec.at (i));
245 }
246
247 template <typename CT, typename QT>
248 static void FromSafeArray (const com::SafeArray <CT> &aArr, QVector <QT> &aVec)
249 {
250 aVec.resize (static_cast<int> (aArr.size()));
251 for (int i = 0; i < aVec.size(); ++i)
252 aVec [i] = static_cast<QT> (aArr [i]);
253 }
254
255 template <typename QT, typename CT>
256 static void ToSafeArray (const QVector <QT *> &aVec, com::SafeArray <CT *> &aArr)
257 {
258 Q_UNUSED (aVec);
259 Q_UNUSED (aArr);
260 AssertMsgFailedReturnVoid (("No conversion!\n"));
261 }
262
263 template <typename CT, typename QT>
264 static void FromSafeArray (const com::SafeArray <CT *> &aArr, QVector <QT *> &aVec)
265 {
266 Q_UNUSED (aArr);
267 Q_UNUSED (aVec);
268 AssertMsgFailedReturnVoid (("No conversion!\n"));
269 }
270
271 /* Arrays of equal types */
272
273 template <typename T>
274 static void ToSafeArray (const QVector <T> &aVec, com::SafeArray <T> &aArr)
275 {
276 aArr.reset (aVec.size());
277 for (int i = 0; i < aVec.size(); ++i)
278 aArr [i] = aVec.at (i);
279 }
280
281 template <typename T>
282 static void FromSafeArray (const com::SafeArray <T> &aArr, QVector <T> &aVec)
283 {
284 aVec.resize (static_cast<int> (aArr.size()));
285 for (int i = 0; i < aVec.size(); ++i)
286 aVec [i] = aArr [i];
287 }
288
289 /* Arrays of strings */
290
291 static void ToSafeArray (const QVector <QString> &aVec,
292 com::SafeArray <BSTR> &aArr);
293 static void FromSafeArray (const com::SafeArray <BSTR> &aArr,
294 QVector <QString> &aVec);
295
296 /* Arrays of GUID */
297
298 static void ToSafeArray (const QVector <QUuid> &aVec,
299 com::SafeGUIDArray &aArr);
300 static void FromSafeArray (const com::SafeGUIDArray &aArr,
301 QVector <QUuid> &aVec);
302
303 /* Arrays of enums. Does a cast similar to what ENUMOut does. */
304
305 template <typename QE, typename CE>
306 static void ToSafeArray (const QVector <QE> &aVec,
307 com::SafeIfaceArray <CE> &aArr)
308 {
309 aArr.reset (static_cast <int> (aVec.size()));
310 for (int i = 0; i < aVec.size(); ++i)
311 aArr [i] = static_cast <CE> (aVec.at (i));
312 }
313
314 template <typename CE, typename QE>
315 static void FromSafeArray (const com::SafeIfaceArray <CE> &aArr,
316 QVector <QE> &aVec)
317 {
318 aVec.resize (static_cast <int> (aArr.size()));
319 for (int i = 0; i < aVec.size(); ++i)
320 aVec [i] = static_cast <QE> (aArr [i]);
321 }
322
323 /* Arrays of interface pointers. Note: we need a separate pair of names
324 * only because the MSVC8 template matching algorithm is poor and tries to
325 * instantiate a com::SafeIfaceArray <BSTR> (!!!) template otherwise for
326 * *no* reason and fails. Note that it's also not possible to choose the
327 * correct function by specifying template arguments explicitly because then
328 * it starts to try to instantiate the com::SafeArray <I> template for
329 * *no* reason again and fails too. Definitely, broken. Works in GCC like a
330 * charm. */
331
332 template <class CI, class I>
333 static void ToSafeIfaceArray (const QVector <CI> &aVec,
334 com::SafeIfaceArray <I> &aArr)
335 {
336 aArr.reset (static_cast<int> (aVec.size()));
337 for (int i = 0; i < aVec.size(); ++i)
338 {
339 aArr [i] = aVec.at (i).raw();
340 if (aArr [i])
341 aArr [i]->AddRef();
342 }
343 }
344
345 template <class I, class CI>
346 static void FromSafeIfaceArray (const com::SafeIfaceArray <I> &aArr,
347 QVector <CI> &aVec)
348 {
349 aVec.resize (static_cast<int> (aArr.size()));
350 for (int i = 0; i < aVec.size(); ++i)
351 aVec [i].attach (aArr [i]);
352 }
353
354protected:
355
356 /* no arbitrary instance creations */
357 COMBase() : mRC (S_OK) {}
358
359#if defined (VBOX_WITH_XPCOM)
360 static XPCOMEventQSocketListener *sSocketListener;
361#endif
362
363 /** Adapter to pass QString as input BSTR params */
364 class BSTRIn
365 {
366 public:
367
368 BSTRIn (const QString &s) : bstr (SysAllocString ((const OLECHAR *)
369 (s.isNull() ? 0 : s.utf16()))) {}
370
371 ~BSTRIn()
372 {
373 if (bstr)
374 SysFreeString (bstr);
375 }
376
377 operator BSTR() const { return bstr; }
378
379 private:
380
381 BSTR bstr;
382 };
383
384 /** Adapter to pass QString as output BSTR params */
385 class BSTROut
386 {
387 public:
388
389 BSTROut (QString &s) : str (s), bstr (0) {}
390
391 ~BSTROut()
392 {
393 if (bstr) {
394 str = QString::fromUtf16 (bstr);
395 SysFreeString (bstr);
396 }
397 }
398
399 operator BSTR *() { return &bstr; }
400
401 private:
402
403 QString &str;
404 BSTR bstr;
405 };
406
407 /**
408 * Adapter to pass K* enums as output COM enum params (*_T).
409 *
410 * @param QE K* enum.
411 * @param CE COM enum.
412 */
413 template <typename QE, typename CE>
414 class ENUMOut
415 {
416 public:
417
418 ENUMOut (QE &e) : qe (e), ce ((CE) 0) {}
419 ~ENUMOut() { qe = (QE) ce; }
420 operator CE *() { return &ce; }
421
422 private:
423
424 QE &qe;
425 CE ce;
426 };
427
428#if !defined (VBOX_WITH_XPCOM)
429
430 /** Adapter to pass QUuid as input GUID params */
431 static GUID GUIDIn (const QUuid &uuid) { return uuid; }
432
433 /** Adapter to pass QUuid as output GUID params */
434 class GUIDOut
435 {
436 public:
437
438 GUIDOut (QUuid &id) : uuid (id)
439 {
440 ::memset (&guid, 0, sizeof (GUID));
441 }
442
443 ~GUIDOut()
444 {
445 uuid = QUuid (
446 guid.Data1, guid.Data2, guid.Data3,
447 guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
448 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
449 }
450
451 operator GUID *() { return &guid; }
452
453 private:
454
455 QUuid &uuid;
456 GUID guid;
457 };
458
459#else /* !defined (VBOX_WITH_XPCOM) */
460
461 /** Adapter to pass QUuid as input GUID params */
462 static const nsID &GUIDIn (const QUuid &uuid)
463 {
464 return *(const nsID *) &uuid;
465 }
466
467 /** Adapter to pass QUuid as output GUID params */
468 class GUIDOut
469 {
470 public:
471
472 GUIDOut (QUuid &id) : uuid (id), nsid (0) {}
473
474 ~GUIDOut()
475 {
476 if (nsid)
477 {
478 uuid = QUuid (
479 nsid->m0, nsid->m1, nsid->m2,
480 nsid->m3[0], nsid->m3[1], nsid->m3[2], nsid->m3[3],
481 nsid->m3[4], nsid->m3[5], nsid->m3[6], nsid->m3[7]);
482 nsMemory::Free (nsid);
483 }
484 }
485
486 operator nsID **() { return &nsid; }
487
488 private:
489
490 QUuid &uuid;
491 nsID *nsid;
492 };
493
494#endif /* !defined (VBOX_WITH_XPCOM) */
495
496 static void addref (IUnknown *aIface) { if (aIface) aIface->AddRef(); }
497 static void release (IUnknown *aIface) { if (aIface) aIface->Release(); }
498
499protected:
500
501 mutable HRESULT mRC;
502
503 friend class COMErrorInfo;
504};
505
506/////////////////////////////////////////////////////////////////////////////
507
508/**
509 * Alternative base class for the CInterface template that adds the errorInfo()
510 * method for providing extended error info about unsuccessful invocation of the
511 * last called interface method.
512 */
513class COMBaseWithEI : public COMBase
514{
515public:
516
517 /**
518 * Returns error info set by the last unsuccessfully invoked interface
519 * method. Returned error info is useful only if CInterface::lastRC()
520 * represents a failure or a warning (i.e. CInterface::isReallyOk() is
521 * false).
522 */
523 const COMErrorInfo &errorInfo() const { return mErrInfo; }
524
525protected:
526
527 /* no arbitrary instance creation */
528 COMBaseWithEI() : COMBase () {};
529
530 void setErrorInfo (const COMErrorInfo &aErrInfo) { mErrInfo = aErrInfo; }
531
532 void fetchErrorInfo (IUnknown *aCallee, const GUID *aCalleeIID) const
533 {
534 mErrInfo.fetchFromCurrentThread (aCallee, aCalleeIID);
535 }
536
537 mutable COMErrorInfo mErrInfo;
538};
539
540/////////////////////////////////////////////////////////////////////////////
541
542/**
543 * Simple class that encapsulates the result code and COMErrorInfo.
544 */
545class COMResult
546{
547public:
548
549 COMResult() : mRC (S_OK) {}
550
551 /**
552 * Queries the current result code from the given component.
553 */
554 explicit COMResult (const COMBase &aComponent)
555 : mRC (aComponent.lastRC()) {}
556
557 /**
558 * Queries the current result code and error info from the given component.
559 */
560 COMResult(const COMBaseWithEI &aComponent)
561 : mRC(aComponent.lastRC()),
562 mErrInfo(aComponent.errorInfo())
563 { }
564
565 /**
566 * Queries the current result code from the given component.
567 */
568 COMResult &operator= (const COMBase &aComponent)
569 {
570 mRC = aComponent.lastRC();
571 return *this;
572 }
573
574 /**
575 * Queries the current result code and error info from the given component.
576 */
577 COMResult &operator= (const COMBaseWithEI &aComponent)
578 {
579 mRC = aComponent.lastRC();
580 mErrInfo = aComponent.errorInfo();
581 return *this;
582 }
583
584 bool isNull() const { return mErrInfo.isNull(); }
585
586 /**
587 * Returns @c true if the result code represents success (with or without
588 * warnings).
589 */
590 bool isOk() const { return SUCCEEDED (mRC); }
591
592 /**
593 * Returns @c true if the result code represents success with one or more
594 * warnings.
595 */
596 bool isWarning() const { return SUCCEEDED_WARNING (mRC); }
597
598 /**
599 * Returns @c true if the result code represents success with no warnings.
600 */
601 bool isReallyOk() const { return mRC == S_OK; }
602
603 COMErrorInfo errorInfo() const { return mErrInfo; }
604 HRESULT rc() const { return mRC; }
605
606private:
607
608 HRESULT mRC;
609 COMErrorInfo mErrInfo;
610};
611
612/////////////////////////////////////////////////////////////////////////////
613
614/**
615 * Wrapper template class for all interfaces.
616 *
617 * All interface methods named as they are in the original, i.e. starting
618 * with the capital letter. All utility non-interface methods are named
619 * starting with the small letter. Utility methods should be not normally
620 * called by the end-user client application.
621 *
622 * @param I Interface class (i.e. derived from IUnknown/nsISupports).
623 * @param B Base class, either COMBase (by default) or COMBaseWithEI.
624 */
625template <class I, class B = COMBase>
626class CInterface : public B
627{
628public:
629
630 typedef B Base;
631 typedef I Iface;
632
633 // constructors & destructor
634
635 CInterface()
636 {
637 clear();
638 }
639
640 CInterface (const CInterface &that) : B (that)
641 {
642 clear();
643 mIface = that.mIface;
644 addref(ptr());
645 }
646
647 CInterface (I *aIface)
648 {
649 clear();
650 setPtr (aIface);
651 addref (aIface);
652 }
653
654 virtual ~CInterface()
655 {
656 detach();
657#ifdef DEBUG
658 mDead = true;
659#endif
660 }
661
662 // utility methods
663 void createInstance (const CLSID &aClsId)
664 {
665 AssertMsg (ptr() == NULL, ("Instance is already non-NULL\n"));
666 if (ptr() == NULL)
667 {
668 I* pObj = NULL;
669#if !defined (VBOX_WITH_XPCOM)
670 B::mRC = CoCreateInstance (aClsId, NULL, CLSCTX_ALL,
671 _ATL_IIDOF (I), (void **) &pObj);
672#else
673 nsCOMPtr <nsIComponentManager> manager;
674 B::mRC = NS_GetComponentManager (getter_AddRefs (manager));
675 if (SUCCEEDED (B::mRC))
676 B::mRC = manager->CreateInstance (aClsId, nsnull, NS_GET_IID (I),
677 (void **) &pObj);
678#endif
679
680 if (SUCCEEDED (B::mRC))
681 setPtr(pObj);
682 else
683 setPtr(NULL);
684
685 /* fetch error info, but don't assert if it's missing -- many other
686 * reasons can lead to an error (w/o providing error info), not only
687 * the instance initialization code (that should always provide it) */
688 B::fetchErrorInfo (NULL, NULL);
689 }
690 }
691
692 /**
693 * Attaches to the given foreign interface pointer by querying the own
694 * interface on it. The operation may fail.
695 */
696 template <class OI>
697 void attach (OI *aIface)
698 {
699#ifdef DEBUG
700 Assert(!mDead);
701#endif
702 /* be aware of self assignment */
703 I* amIface = ptr();
704 addref (aIface);
705 release (amIface);
706 if (aIface)
707 {
708 amIface = NULL;
709 B::mRC = aIface->QueryInterface (COM_IIDOF (I), (void **) &amIface);
710 release (aIface);
711 setPtr(amIface);
712 }
713 else
714 {
715 setPtr(NULL);
716 B::mRC = S_OK;
717 }
718 };
719
720 /** Specialization of attach() for our own interface I. Never fails. */
721 void attach (I *aIface)
722 {
723#ifdef DEBUG
724 Assert(!mDead);
725#endif
726 /* be aware of self assignment */
727 addref (aIface);
728 release (ptr());
729 setPtr(aIface);
730 B::mRC = S_OK;
731 };
732
733 /** Detaches from the underlying interface pointer. */
734 void detach()
735 {
736#ifdef DEBUG
737 Assert(!mDead);
738#endif
739 release (ptr());
740 setPtr(NULL);
741 }
742
743 /** Returns @c true if not attached to any interface pointer. */
744 bool isNull() const
745 {
746#ifdef DEBUG
747 Assert(!mDead);
748#endif
749 return mIface == NULL;
750 }
751
752 /**
753 * Returns @c true if the result code represents success (with or without
754 * warnings).
755 */
756 bool isOk() const { return !isNull() && SUCCEEDED (B::mRC); }
757
758 /**
759 * Returns @c true if the result code represents success with one or more
760 * warnings.
761 */
762 bool isWarning() const { return !isNull() && SUCCEEDED_WARNING (B::mRC); }
763
764 /**
765 * Returns @c true if the result code represents success with no warnings.
766 */
767 bool isReallyOk() const { return !isNull() && B::mRC == S_OK; }
768
769 // utility operators
770
771 CInterface &operator= (const CInterface &that)
772 {
773 attach (that.ptr());
774 B::operator= (that);
775 return *this;
776 }
777
778 CInterface &operator= (I *aIface)
779 {
780 attach (aIface);
781 return *this;
782 }
783
784 /**
785 * Returns the raw interface pointer. Not intended to be used for anything
786 * else but in generated wrappers and for debugging. You've been warned.
787 */
788 I *raw() const
789 {
790 return ptr();
791 }
792
793 bool operator== (const CInterface &that) const { return ptr() == that.ptr(); }
794 bool operator!= (const CInterface &that) const { return ptr() != that.ptr(); }
795
796 I* ptr() const
797 {
798#ifdef DEBUG
799 Assert(!mDead);
800#endif
801
802 return mIface;
803 }
804
805 void setPtr(I* aObj) const
806 {
807#ifdef DEBUG
808 Assert(!mDead);
809#endif
810 mIface = aObj;
811 }
812
813private:
814#ifdef DEBUG
815 bool mDead;
816#endif
817 mutable I * mIface;
818
819 void clear()
820 {
821 mIface = NULL;
822#ifdef DEBUG
823 mDead = false;
824#endif
825 }
826};
827
828/////////////////////////////////////////////////////////////////////////////
829
830class CUnknown : public CInterface <IUnknown, COMBaseWithEI>
831{
832public:
833
834 typedef CInterface <IUnknown, COMBaseWithEI> Base;
835
836 CUnknown() {}
837
838 /** Creates an instance given another CInterface-based instance. */
839 template <class OI, class OB>
840 explicit CUnknown (const CInterface <OI, OB> &that)
841 {
842 attach (that.ptr());
843 if (SUCCEEDED (mRC))
844 {
845 /* preserve old error info if any */
846 mRC = that.lastRC();
847 setErrorInfo (that.errorInfo());
848 }
849 }
850
851 /** Constructor specialization for IUnknown. */
852 CUnknown (const CUnknown &that) : Base (that) {}
853
854 /** Creates an instance given a foreign interface pointer. */
855 template <class OI>
856 explicit CUnknown (OI *aIface)
857 {
858 attach (aIface);
859 }
860
861 /** Constructor specialization for IUnknown. */
862 explicit CUnknown (IUnknown *aIface) : Base (aIface) {}
863
864 /** Assigns from another CInterface-based instance. */
865 template <class OI, class OB>
866 CUnknown &operator= (const CInterface <OI, OB> &that)
867 {
868 attach (that.ptr());
869 if (SUCCEEDED (mRC))
870 {
871 /* preserve old error info if any */
872 mRC = that.lastRC();
873 setErrorInfo (that.errorInfo());
874 }
875 return *this;
876 }
877
878 /** Assignment specialization for CUnknown. */
879 CUnknown &operator= (const CUnknown &that)
880 {
881 Base::operator= (that);
882 return *this;
883 }
884
885 /** Assigns from a foreign interface pointer. */
886 template <class OI>
887 CUnknown &operator= (OI *aIface)
888 {
889 attach (aIface);
890 return *this;
891 }
892
893 /** Assignment specialization for IUnknown. */
894 CUnknown &operator= (IUnknown *aIface)
895 {
896 Base::operator= (aIface);
897 return *this;
898 }
899};
900
901/////////////////////////////////////////////////////////////////////////////
902
903/* Include the generated header containing wrapper definitions: */
904#include "COMWrappers.h"
905
906/* Declare metatypes for particular wrappers: */
907Q_DECLARE_METATYPE(CProgress);
908Q_DECLARE_METATYPE(CHost);
909Q_DECLARE_METATYPE(CMachine);
910Q_DECLARE_METATYPE(CConsole);
911Q_DECLARE_METATYPE(CHostNetworkInterface);
912
913/** @} */
914
915#endif // __COMDefs_h__
916
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use