Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qcom.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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 #include <qpe/qpeglobal.h>
00030 
00031 #define QRESULT         unsigned long
00032 #define QS_OK           (QRESULT)0x00000000
00033 #define QS_FALSE        (QRESULT)0x00000001
00034 
00035 #define QE_NOTIMPL      (QRESULT)0x80000001
00036 #define QE_OUTOFMEMORY  (QRESULT)0x80000002
00037 #define QE_INVALIDARG   (QRESULT)0x80000003
00038 #define QE_NOINTERFACE  (QRESULT)0x80000004
00039 #define QE_NOCOMPONENT  (QRESULT)0x80000005
00040 
00041 // {1D8518CD-E8F5-4366-99E8-879FD7E482DE}
00042 #ifndef IID_QUnknown
00043 #define IID_QUnknown QUuid(0x1d8518cd, 0xe8f5, 0x4366, 0x99, 0xe8, 0x87, 0x9f, 0xd7, 0xe4, 0x82, 0xde)
00044 #endif
00045 
00046 struct Q_EXPORT QUnknownInterface
00047 {
00048     virtual QRESULT queryInterface( const QUuid&, QUnknownInterface** ) = 0;
00049     virtual ulong   addRef() = 0;
00050     virtual ulong   release() = 0;
00051 };
00052 
00053 // {D16111D4-E1E7-4C47-8599-24483DAE2E07}
00054 #ifndef IID_QLibrary
00055 #define IID_QLibrary QUuid( 0xd16111d4, 0xe1e7, 0x4c47, 0x85, 0x99, 0x24, 0x48, 0x3d, 0xae, 0x2e, 0x07)
00056 #endif
00057  
00058 struct Q_EXPORT QLibraryInterface : public QUnknownInterface
00059 {
00060     virtual bool    init() = 0;
00061     virtual void    cleanup() = 0;
00062     virtual bool    canUnload() const = 0;
00063 };
00064 
00065 #define Q_CREATE_INSTANCE( IMPLEMENTATION )         \
00066         IMPLEMENTATION *i = new IMPLEMENTATION; \
00067         QUnknownInterface* iface = 0;                   \
00068         i->queryInterface( IID_QUnknown, &iface );      \
00069         return iface;
00070 
00071 template <class T>
00072 class QInterfacePtr
00073 {
00074 public:
00075     QInterfacePtr():iface(0){}
00076 
00077     QInterfacePtr( T* i) {
00078         if ( (iface = i) )
00079             iface->addRef();
00080     }
00081 
00082     QInterfacePtr(const QInterfacePtr<T> &p) {
00083         if ( (iface = p.iface) )
00084             iface->addRef();
00085     }
00086 
00087     ~QInterfacePtr() {
00088         if ( iface )
00089             iface->release();
00090     }
00091 
00092     QInterfacePtr<T> &operator=(const QInterfacePtr<T> &p) {
00093         if ( iface != p.iface ) {
00094             if ( iface )
00095                 iface->release();
00096             if ( (iface = p.iface) )
00097                 iface->addRef();
00098         }
00099         return *this;
00100     }
00101 
00102     QInterfacePtr<T> &operator=(T* i) {
00103         if (iface != i ) {
00104             if ( iface )
00105                 iface->release();
00106             if ( (iface = i) )
00107                 iface->addRef();
00108         }
00109         return *this;
00110     }
00111 
00112     bool operator==( const QInterfacePtr<T> &p ) const { return iface == p.iface; }
00113 
00114     bool operator!= ( const QInterfacePtr<T>& p ) const {  return !( *this == p ); }
00115 
00116     bool isNull() const { return !iface; }
00117 
00118     T* operator->() const { return iface; }
00119 
00120     T& operator*() const { return *iface; }
00121 
00122     operator T*() const { return iface; }
00123 
00124     QUnknownInterface** operator &() const {
00125         if( iface )
00126             iface->release();
00127         return (QUnknownInterface**)&iface;
00128     }
00129 
00130     T** operator &() {
00131         if ( iface )
00132             iface->release();
00133         return &iface;
00134     }
00135 
00136 private:
00137     T* iface;
00138 };
00139 
00140 
00141 // internal class that wraps an initialized ulong
00142 struct Q_EXPORT QtULong
00143 {
00144     QtULong() : ref( 0 ) { }
00145     operator unsigned long () const { return ref; }
00146     unsigned long& operator++() { return ++ref; }
00147     unsigned long operator++( int ) { return ref++; }
00148     unsigned long& operator--() { return --ref; }
00149     unsigned long operator--( int ) { return ref--; }
00150 
00151     unsigned long ref;
00152 };
00153 
00154 #define Q_EXPORT_INTERFACE() \
00155         extern "C" QPE_EXPORT_SYMBOL QUnknownInterface* ucm_instantiate  ()
00156 
00157 #define Q_REFCOUNT \
00158 private:          \
00159     QtULong qtrefcount;   \
00160 public:          \
00161     ulong addRef() {return qtrefcount++;} \
00162     ulong release() {if(!--qtrefcount){delete this;return 0;}return qtrefcount;}
00163 
00164 #else // QT_NO_COMPONENT
00165 
00166 struct Q_EXPORT QUnknownInterface
00167 {
00168 };
00169 
00170 #endif // QT_NO_COMPONENT
00171 
00172 #endif // QCOM_H

Generated on Sat Nov 5 16:16:38 2005 for OPIE by  doxygen 1.4.2