# dcop Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | 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     return typeCheck( t, true );
    00036 }
    00037
    00038 bool DCOPReply::typeCheck( const char* t, bool warn )
    00039 {
    00040     if ( type == t )
    00041     return true;
    00042     if( warn
    00043     || strcmp( t, "<unknown>" )) // type not listed in dcoptypes.h
    00044     qWarning( "WARNING: DCOPReply<%s>: cast to '%s' error",
    00045              STR( type ), t );
    00046     return false;
    00047 }
    00048
    00049 // this has to stay BC too even if private, because it's called from inlines
    00050 DCOPReply DCOPRef::callInternal( const QCString& fun, const QCString& args, const QByteArray& data )
    00051 {
    00052     return callInternal( fun, args, data, NoEventLoop, -1 );
    00053 }
    00054
    00055 DCOPReply DCOPRef::callInternal( const QCString& fun, const QCString& args, const QByteArray& data,
    00056                  EventLoopFlag useEventLoop, int timeout )
    00057 {
    00058     DCOPReply reply;
    00059     if ( isNull() ) {
    00060     qWarning( "DCOPRef: call '%s' on null reference error",
    00061           STR( fun ) );
    00062     return reply;
    00063     }
    00064     QCString sig = fun;
    00065     if ( fun.find('(') == -1 ) {
    00066     sig += args;
    00067     if( args.find( "<unknown" ) != -1 )
    00068         qWarning("DCOPRef: unknown type error "
    00069              "<\"%s\",\"%s\">::call(\"%s\",%s",
    00070              STR(m_app), STR(m_obj), STR(fun), args.data()+1 );
    00071     }
    00072     DCOPClient* dc = dcopClient();
    00073     if ( !dc || !dc->isAttached() ) {
    00074     qWarning( "DCOPRef::call():  no DCOP client or client not attached error" );
    00075     return reply;
    00076     }
    00077     dc->call( m_app, m_obj, sig, data, reply.type, reply.data, useEventLoop == UseEventLoop, timeout );
    00078     return reply;
    00079 }
    00080
    00081 bool DCOPRef::sendInternal( const QCString& fun, const QCString& args, const QByteArray& data )
    00082 {
    00083     if ( isNull() ) {
    00084     qWarning( "DCOPRef: send '%s' on null reference error",
    00085           STR( fun ) );
    00086     return false;
    00087     }
    00088     Q_UNUSED( data );
    00089     QCString sig = fun;
    00090     if ( fun.find('(') == -1 ) {
    00091     sig += args;
    00092     if( args.find( "<unknown" ) != -1 )
    00093         qWarning("DCOPRef: unknown type error "
    00094              "<\"%s\",\"%s\">::send(\"%s\",%s",
    00095              STR(m_app), STR(m_obj), STR(fun), args.data()+1 );
    00096     }
    00097     DCOPClient* dc = dcopClient();
    00098     if ( !dc || !dc->isAttached() ) {
    00099     qWarning( "DCOPRef::send(): no DCOP client or client not attached error" );
    00100     return false;
    00101     }
    00102     return dc->send( m_app, m_obj, sig, data );
    00103 }
    00104
    00105 DCOPRef::DCOPRef()
    00106     :d(0)
    00107 {
    00108 }
    00109
    00110 DCOPRef::DCOPRef( const DCOPRef& ref )
    00111     :d( ref.d )
    00112 {
    00113     m_app = ref.app();
    00114     m_obj = ref.obj();
    00115     m_type = ref.type();
    00116 }
    00117
    00118 DCOPRef::DCOPRef( DCOPObject *o )
    00119     : m_app( DCOPClient::mainClient() ? DCOPClient::mainClient()->appId() : QCString() ),
    00120     m_obj( o->objId() ), m_type( o->interfaces().last() ), d(0)
    00121
    00122 {
    00123 }
    00124
    00125 DCOPRef::DCOPRef( const QCString& _app, const QCString& obj )
    00126     : m_app( _app ), m_obj( obj ), d(0)
    00127 {
    00128 }
    00129
    00130 DCOPRef::DCOPRef( const QCString& _app, const QCString& _obj, const QCString& _type )
    00131     : m_app( _app ), m_obj( _obj ), m_type( _type ), d(0)
    00132 {
    00133 }
    00134
    00135 bool DCOPRef::isNull() const
    00136 {
    00137     return ( m_app.isNull() || m_obj.isNull() );
    00138 }
    00139
    00140 QCString DCOPRef::app() const
    00141 {
    00142     return m_app;
    00143 }
    00144
    00145 QCString DCOPRef::obj() const
    00146 {
    00147     return m_obj;
    00148 }
    00149
    00150 QCString DCOPRef::object() const
    00151 {
    00152     return m_obj;
    00153 }
    00154
    00155
    00156 QCString DCOPRef::type() const
    00157 {
    00158     return m_type;
    00159 }
    00160
    00161 void DCOPRef::setDCOPClient( DCOPClient* dc )
    00162 {
    00163     d = (DCOPRefPrivate*) dc;
    00164 }
    00165
    00166 DCOPClient* DCOPRef::dcopClient() const
    00167 {
    00168     return d ? (DCOPClient*)d : DCOPClient::mainClient();
    00169 }
    00170
    00171 DCOPRef& DCOPRef::operator=( const DCOPRef& ref )
    00172 {
    00173     d = ref.d;
    00174     m_app = ref.app();
    00175     m_obj = ref.obj();
    00176     m_type = ref.type();
    00177     return *this;
    00178 }
    00179
    00180 void DCOPRef::setRef( const QCString& _app, const QCString& _obj )
    00181 {
    00182     m_app = _app;
    00183     m_obj = _obj;
    00184     m_type = 0;
    00185 }
    00186
    00187 void DCOPRef::setRef( const QCString& _app, const QCString& _obj, const QCString& _type )
    00188 {
    00189     m_app = _app;
    00190     m_obj = _obj;
    00191     m_type = _type;
    00192 }
    00193
    00194 void DCOPRef::clear()
    00195 {
    00196     m_app = 0;
    00197     m_obj = 0;
    00198     m_type = 0;
    00199 }
    00200
    00201 QDataStream& operator<<( QDataStream& str, const DCOPRef& ref )
    00202 {
    00203     str << ref.app();
    00204     str << ref.obj();
    00205     str << ref.type();
    00206
    00207     return str;
    00208 }
    00209
    00210 QDataStream& operator>>( QDataStream& str, DCOPRef& ref )
    00211 {
    00212     QCString a, o, t;
    00213     str >> a >> o >> t;
    00214
    00215     ref.setRef( a, o, t );
    00216
    00217     return str;
    00218 }

This file is part of the documentation for dcop Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:16:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003