# dcop Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# dcopref.cpp

    00001 /*****************************************************************
    00002
    00003 Copyright (c) 1999 Preston Brown <pbrown@kde.org>
    00004 Copyright (c) 1999 Matthias Ettrich <ettrich@kde.org>
    00005
    00006 Permission is hereby granted, free of charge, to any person obtaining a copy
    00007 of this software and associated documentation files (the "Software"), to deal
    00008 in the Software without restriction, including without limitation the rights
    00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00010 copies of the Software, and to permit persons to whom the Software is
    00011 furnished to do so, subject to the following conditions:
    00012
    00013 The above copyright notice and this permission notice shall be included in
    00014 all copies or substantial portions of the Software.
    00015
    00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00019 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    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 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:42:41 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001