00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "dcopref.h"
00026 #include "dcopclient.h"
00027 #include "dcopobject.h"
00028
00029 #include <qdatastream.h>
00030
00031 #define STR( s ) ( s.data() ? s.data() : "" )
00032
00033 bool DCOPReply::typeCheck( const char* t )
00034 {
00035 if ( type == t )
00036 return TRUE;
00037 qWarning( "DCOPReply<%s>: cast to '%s' error",
00038 STR( type ), t );
00039 return FALSE;
00040 }
00041
00042 DCOPReply DCOPRef::callInternal( const QCString& fun, const QCString& args, const QByteArray& data )
00043 {
00044 DCOPReply reply;
00045 if ( isNull() ) {
00046 qWarning( "DCOPRef: call '%s' on null reference error",
00047 STR( fun ) );
00048 return reply;
00049 }
00050 QCString sig = fun;
00051 if ( fun.find('(') == -1 ) {
00052 sig += args;
00053 if( args.find( "<unknown" ) != -1 )
00054 qWarning("DCOPRef: unknown type error "
00055 "<\"%s\",\"%s\">::call(\"%s\",%s",
00056 STR(m_app), STR(m_obj), STR(fun), args.data()+1 );
00057 }
00058 DCOPClient* dc = dcopClient();
00059 if ( !dc || !dc->isAttached() ) {
00060 qWarning( "DCOPRef::call(): no DCOP client or client not attached error" );
00061 return reply;
00062 }
00063 dc->call( m_app, m_obj, sig, data, reply.type, reply.data );
00064 return reply;
00065 }
00066
00067 bool DCOPRef::sendInternal( const QCString& fun, const QCString& args, const QByteArray& data )
00068 {
00069 if ( isNull() ) {
00070 qWarning( "DCOPRef: send '%s' on null reference error",
00071 STR( fun ) );
00072 return FALSE;
00073 }
00074 Q_UNUSED( data );
00075 QCString sig = fun;
00076 if ( fun.find('(') == -1 ) {
00077 sig += args;
00078 if( args.find( "<unknown" ) != -1 )
00079 qWarning("DCOPRef: unknown type error "
00080 "<\"%s\",\"%s\">::send(\"%s\",%s",
00081 STR(m_app), STR(m_obj), STR(fun), args.data()+1 );
00082 }
00083 DCOPClient* dc = dcopClient();
00084 if ( !dc || !dc->isAttached() ) {
00085 qWarning( "DCOPRef::send(): no DCOP client or client not attached error" );
00086 return false;
00087 }
00088 return dc->send( m_app, m_obj, sig, data );
00089 }
00090
00091 DCOPRef::DCOPRef()
00092 :d(0)
00093 {
00094 }
00095
00096 DCOPRef::DCOPRef( const DCOPRef& ref )
00097 :d( ref.d )
00098 {
00099 m_app = ref.app();
00100 m_obj = ref.obj();
00101 m_type = ref.type();
00102 }
00103
00104 DCOPRef::DCOPRef( DCOPObject *o )
00105 : m_app( DCOPClient::mainClient() ? DCOPClient::mainClient()->appId() : QCString() ),
00106 m_obj( o->objId() ), m_type( o->interfaces().last() ), d(0)
00107
00108 {
00109 }
00110
00111 DCOPRef::DCOPRef( const QCString& _app, const QCString& obj )
00112 : m_app( _app ), m_obj( obj ), d(0)
00113 {
00114 }
00115
00116 DCOPRef::DCOPRef( const QCString& _app, const QCString& _obj, const QCString& _type )
00117 : m_app( _app ), m_obj( _obj ), m_type( _type ), d(0)
00118 {
00119 }
00120
00121 bool DCOPRef::isNull() const
00122 {
00123 return ( m_app.isNull() || m_obj.isNull() );
00124 }
00125
00126 QCString DCOPRef::app() const
00127 {
00128 return m_app;
00129 }
00130
00131 QCString DCOPRef::obj() const
00132 {
00133 return m_obj;
00134 }
00135
00136 QCString DCOPRef::object() const
00137 {
00138 return m_obj;
00139 }
00140
00141
00142 QCString DCOPRef::type() const
00143 {
00144 return m_type;
00145 }
00146
00147 void DCOPRef::setDCOPClient( DCOPClient* dc )
00148 {
00149 d = (DCOPRefPrivate*) dc;
00150 }
00151
00152 DCOPClient* DCOPRef::dcopClient() const
00153 {
00154 return d ? (DCOPClient*)d : DCOPClient::mainClient();
00155 }
00156
00157 DCOPRef& DCOPRef::operator=( const DCOPRef& ref )
00158 {
00159 d = ref.d;
00160 m_app = ref.app();
00161 m_obj = ref.obj();
00162 m_type = ref.type();
00163 return *this;
00164 }
00165
00166 void DCOPRef::setRef( const QCString& _app, const QCString& _obj )
00167 {
00168 m_app = _app;
00169 m_obj = _obj;
00170 m_type = 0;
00171 }
00172
00173 void DCOPRef::setRef( const QCString& _app, const QCString& _obj, const QCString& _type )
00174 {
00175 m_app = _app;
00176 m_obj = _obj;
00177 m_type = _type;
00178 }
00179
00180 void DCOPRef::clear()
00181 {
00182 m_app = 0;
00183 m_obj = 0;
00184 m_type = 0;
00185 }
00186
00187 QDataStream& operator<<( QDataStream& str, const DCOPRef& ref )
00188 {
00189 str << ref.app();
00190 str << ref.obj();
00191 str << ref.type();
00192
00193 return str;
00194 }
00195
00196 QDataStream& operator>>( QDataStream& str, DCOPRef& ref )
00197 {
00198 QCString a, o, t;
00199 str >> a >> o >> t;
00200
00201 ref.setRef( a, o, t );
00202
00203 return str;
00204 }