qcom.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef QCOM_H
00022 #define QCOM_H
00023
00024 #include <qstringlist.h>
00025
00026 #ifndef QT_NO_COMPONENT
00027
00028 #include <qpe/quuid.h>
00029
00030 #define QRESULT unsigned long
00031 #define QS_OK (QRESULT)0x00000000
00032 #define QS_FALSE (QRESULT)0x00000001
00033
00034 #define QE_NOTIMPL (QRESULT)0x80000001
00035 #define QE_OUTOFMEMORY (QRESULT)0x80000002
00036 #define QE_INVALIDARG (QRESULT)0x80000003
00037 #define QE_NOINTERFACE (QRESULT)0x80000004
00038 #define QE_NOCOMPONENT (QRESULT)0x80000005
00039
00040
00041 #ifndef IID_QUnknown
00042 #define IID_QUnknown QUuid(0x1d8518cd, 0xe8f5, 0x4366, 0x99, 0xe8, 0x87, 0x9f, 0xd7, 0xe4, 0x82, 0xde)
00043 #endif
00044
00045 struct Q_EXPORT QUnknownInterface
00046 {
00047 virtual QRESULT queryInterface( const QUuid&, QUnknownInterface** ) = 0;
00048 virtual ulong addRef() = 0;
00049 virtual ulong release() = 0;
00050 };
00051
00052
00053 #ifndef IID_QLibrary
00054 #define IID_QLibrary QUuid( 0xd16111d4, 0xe1e7, 0x4c47, 0x85, 0x99, 0x24, 0x48, 0x3d, 0xae, 0x2e, 0x07)
00055 #endif
00056
00057 struct Q_EXPORT QLibraryInterface : public QUnknownInterface
00058 {
00059 virtual bool init() = 0;
00060 virtual void cleanup() = 0;
00061 virtual bool canUnload() const = 0;
00062 };
00063
00064 #define Q_CREATE_INSTANCE( IMPLEMENTATION ) \
00065 IMPLEMENTATION *i = new IMPLEMENTATION; \
00066 QUnknownInterface* iface = 0; \
00067 i->queryInterface( IID_QUnknown, &iface ); \
00068 return iface;
00069
00070 template <class T>
00071 class QInterfacePtr
00072 {
00073 public:
00074 QInterfacePtr():iface(0){}
00075
00076 QInterfacePtr( T* i) {
00077 if ( (iface = i) )
00078 iface->addRef();
00079 }
00080
00081 QInterfacePtr(const QInterfacePtr<T> &p) {
00082 if ( (iface = p.iface) )
00083 iface->addRef();
00084 }
00085
00086 ~QInterfacePtr() {
00087 if ( iface )
00088 iface->release();
00089 }
00090
00091 QInterfacePtr<T> &operator=(const QInterfacePtr<T> &p) {
00092 if ( iface != p.iface ) {
00093 if ( iface )
00094 iface->release();
00095 if ( (iface = p.iface) )
00096 iface->addRef();
00097 }
00098 return *this;
00099 }
00100
00101 QInterfacePtr<T> &operator=(T* i) {
00102 if (iface != i ) {
00103 if ( iface )
00104 iface->release();
00105 if ( (iface = i) )
00106 iface->addRef();
00107 }
00108 return *this;
00109 }
00110
00111 bool operator==( const QInterfacePtr<T> &p ) const { return iface == p.iface; }
00112
00113 bool operator!= ( const QInterfacePtr<T>& p ) const { return !( *this == p ); }
00114
00115 bool isNull() const { return !iface; }
00116
00117 T* operator->() const { return iface; }
00118
00119 T& operator*() const { return *iface; }
00120
00121 operator T*() const { return iface; }
00122
00123 QUnknownInterface** operator &() const {
00124 if( iface )
00125 iface->release();
00126 return (QUnknownInterface**)&iface;
00127 }
00128
00129 T** operator &() {
00130 if ( iface )
00131 iface->release();
00132 return &iface;
00133 }
00134
00135 private:
00136 T* iface;
00137 };
00138
00139
00140
00141 struct Q_EXPORT QtULong
00142 {
00143 QtULong() : ref( 0 ) { }
00144 operator unsigned long () const { return ref; }
00145 unsigned long& operator++() { return ++ref; }
00146 unsigned long operator++( int ) { return ref++; }
00147 unsigned long& operator--() { return --ref; }
00148 unsigned long operator--( int ) { return ref--; }
00149
00150 unsigned long ref;
00151 };
00152
00153 #define Q_EXPORT_INTERFACE() \
00154 extern "C" QUnknownInterface* ucm_instantiate()
00155
00156 #define Q_REFCOUNT \
00157 private: \
00158 QtULong qtrefcount; \
00159 public: \
00160 ulong addRef() {return qtrefcount++;} \
00161 ulong release() {if(!--qtrefcount){delete this;return 0;}return qtrefcount;}
00162
00163 #else // QT_NO_COMPONENT
00164
00165 struct Q_EXPORT QUnknownInterface
00166 {
00167 };
00168
00169 #endif // QT_NO_COMPONENT
00170
00171 #endif // QCOM_H
This file is part of the documentation for OPIE Version 1.5.5.