Qtopia library API Documentation

qcom.h

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 
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 // {1D8518CD-E8F5-4366-99E8-879FD7E482DE}
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 // {D16111D4-E1E7-4C47-8599-24483DAE2E07}
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 // internal class that wraps an initialized ulong
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
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:06 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001