# dcop Library API Documentation

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

# dcopref.h

    00001 /*
    00002 Copyright (c) 2002 Matthias Ettrich <ettrich@kde.org>
    00003 Copyright (c) 1999 Preston Brown <pbrown@kde.org>
    00004
    00005 Permission is hereby granted, free of charge, to any person obtaining a copy
    00006 of this software and associated documentation files (the "Software"), to deal
    00007 in the Software without restriction, including without limitation the rights
    00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00009 copies of the Software, and to permit persons to whom the Software is
    00010 furnished to do so, subject to the following conditions:
    00011
    00012 The above copyright notice and this permission notice shall be included in
    00013 all copies or substantial portions of the Software.
    00014
    00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00018 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    00019 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00020 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00021 */
    00022
    00023 #ifndef _DCOPREF_H
    00024 #define _DCOPREF_H
    00025
    00026 #include <qcstring.h>
    00027 #include <dcoptypes.h>
    00028 #include <kdatastream.h> // needed for proper bool marshalling
    00029
    00030 class QDataStream;
    00031 class DCOPObject;
    00032 class DCOPClient;
    00033
    00043 class DCOPReply
    00044 {
    00045 public:
    00052     template<class T>
    00053     operator T() {
    00054         T t;
    00055         if ( typeCheck( dcopTypeName(t) ) ) {
    00056             QDataStream reply( data, IO_ReadOnly );
    00057             reply >> t;
    00058         } else {
    00059             dcopTypeInit(t);
    00060         }
    00061         return t;
    00062     }
    00070     template <class T> bool get(  T& t, const char* tname ) {
    00071         if ( typeCheck( tname ) ) {
    00072             QDataStream reply( data, IO_ReadOnly );
    00073             reply >> t;
    00074             return true;
    00075         }
    00076         return false;
    00077     }
    00087     template <class T> bool get(  T& t ) {
    00088         if ( typeCheck( dcopTypeName(t) ) ) {
    00089             QDataStream reply( data, IO_ReadOnly );
    00090             reply >> t;
    00091             return true;
    00092         }
    00093         return false;
    00094     }
    00095
    00100     inline bool isValid() const { return !type.isNull(); }
    00101
    00103     QByteArray data;
    00105     QCString type;
    00106 private:
    00107     bool typeCheck( const char* t );
    00108 };
    00109
    00120 class DCOPArg  {
    00121 public:
    00130     template <class T> DCOPArg( const T& t, const char* tname_arg )
    00131         : tname(tname_arg)
    00132         {
    00133             QDataStream ds( data, IO_WriteOnly );
    00134             ds << t;
    00135         }
    00144     template <class T> DCOPArg( const T& t )
    00145         : tname( dcopTypeName(t) )
    00146         {
    00147             QDataStream ds( data, IO_WriteOnly );
    00148             ds << t;
    00149         }
    00150
    00152     QByteArray data;
    00154     const char* tname;
    00155 };
    00156
    00157 inline const char* dcopTypeName( const DCOPArg &arg )  { return arg.tname; }
    00158 inline QDataStream & operator << (QDataStream & str, const DCOPArg& arg )
    00159    { str.writeRawBytes( arg.data.data(), arg.data.size() ); return str; }
    00160
    00161
    00162
    00275 class DCOPRef
    00276 {
    00277 public:
    00281     DCOPRef();
    00282
    00286     DCOPRef( const DCOPRef& ref );
    00294     DCOPRef( const QCString& app, const QCString& obj = "" );
    00295
    00301     DCOPRef( DCOPObject *object );
    00302
    00312     DCOPRef( const QCString& app, const QCString& obj, const QCString& type );
    00313
    00318     bool isNull() const;
    00319
    00324     QCString app() const;
    00325
    00331     QCString obj() const;
    00332
    00336     QCString object() const;
    00337
    00342     QCString type() const;
    00343
    00344
    00348     DCOPRef& operator=( const DCOPRef& );
    00349
    00355     void setRef( const QCString& app, const QCString& obj = "" );
    00356
    00363     void setRef( const QCString& app, const QCString& obj, const QCString& type );
    00364
    00365
    00369     void clear();
    00370
    00371
    00378     DCOPClient* dcopClient() const;
    00379
    00386     void setDCOPClient( DCOPClient *client );
    00387
    00401     DCOPReply call( const QCString& fun ) {
    00402         QByteArray data;
    00403         return callInternal( fun, "()", data );
    00404     }
    00405
    00421     template <class T1>
    00422     DCOPReply call( const QCString& fun, const T1& t1 ) {
    00423         QCString args;
    00424         args.sprintf( "(%s)",
    00425                      dcopTypeName(t1) );
    00426         QByteArray data;
    00427         QDataStream ds( data, IO_WriteOnly );
    00428         ds << t1;
    00429         return callInternal( fun, args, data );
    00430     }
    00431
    00449     template <class T1, class T2>
    00450     DCOPReply call( const QCString& fun,
    00451                     const T1& t1,
    00452                     const T2& t2 ) {
    00453         QCString args;
    00454         args.sprintf( "(%s,%s)",
    00455                      dcopTypeName(t1),
    00456                      dcopTypeName(t2) );
    00457         QByteArray data;
    00458         QDataStream ds( data, IO_WriteOnly );
    00459         ds << t1 << t2;
    00460         return callInternal( fun, args, data );
    00461     }
    00462
    00482     template <class T1, class T2, class T3>
    00483     DCOPReply call( const QCString& fun,
    00484                     const T1& t1,
    00485                     const T2& t2,
    00486                     const T3& t3 ) {
    00487         QCString args;
    00488         args.sprintf( "(%s,%s,%s)",
    00489                      dcopTypeName(t1),
    00490                      dcopTypeName(t2),
    00491                      dcopTypeName(t3) );
    00492         QByteArray data;
    00493         QDataStream ds( data, IO_WriteOnly );
    00494         ds << t1 << t2 << t3;
    00495         return callInternal( fun, args, data );
    00496     }
    00497
    00519     template <class T1,class T2,class T3,class T4>
    00520     DCOPReply call( const QCString& fun,
    00521                     const T1& t1,
    00522                     const T2& t2,
    00523                     const T3& t3,
    00524                     const T4& t4 ) {
    00525         QCString args;
    00526         args.sprintf( "(%s,%s,%s,%s)",
    00527                      dcopTypeName(t1),
    00528                      dcopTypeName(t2),
    00529                      dcopTypeName(t3),
    00530                      dcopTypeName(t4) );
    00531         QByteArray data;
    00532         QDataStream ds( data, IO_WriteOnly );
    00533         ds << t1 << t2 << t3 << t4;
    00534         return callInternal( fun, args, data );
    00535     }
    00536
    00560     template <class T1,class T2,class T3,class T4,class T5>
    00561     DCOPReply call( const QCString& fun,
    00562                     const T1& t1,
    00563                     const T2& t2,
    00564                     const T3& t3,
    00565                     const T4& t4,
    00566                     const T5& t5 ) {
    00567         QCString args;
    00568         args.sprintf( "(%s,%s,%s,%s,%s)",
    00569                      dcopTypeName(t1),
    00570                      dcopTypeName(t2),
    00571                      dcopTypeName(t3),
    00572                      dcopTypeName(t4),
    00573                      dcopTypeName(t5) );
    00574         QByteArray data;
    00575         QDataStream ds( data, IO_WriteOnly );
    00576         ds << t1 << t2 << t3 << t4 << t5;
    00577         return callInternal( fun, args, data );
    00578     }
    00579
    00605     template <class T1,class T2,class T3,class T4,class T5,class T6>
    00606     DCOPReply call( const QCString& fun,
    00607                     const T1& t1,
    00608                     const T2& t2,
    00609                     const T3& t3,
    00610                     const T4& t4,
    00611                     const T5& t5,
    00612                     const T6& t6 ) {
    00613         QCString args;
    00614         args.sprintf( "(%s,%s,%s,%s,%s,%s)",
    00615                      dcopTypeName(t1),
    00616                      dcopTypeName(t2),
    00617                      dcopTypeName(t3),
    00618                      dcopTypeName(t4),
    00619                      dcopTypeName(t5),
    00620                      dcopTypeName(t6) );
    00621         QByteArray data;
    00622         QDataStream ds( data, IO_WriteOnly );
    00623         ds << t1 << t2 << t3 << t4 << t5 << t6;
    00624         return callInternal( fun, args, data );
    00625     }
    00626
    00654     template <class T1,class T2,class T3,class T4,class T5,class T6,class T7>
    00655     DCOPReply call( const QCString& fun,
    00656                     const T1& t1,
    00657                     const T2& t2,
    00658                     const T3& t3,
    00659                     const T4& t4,
    00660                     const T5& t5,
    00661                     const T6& t6,
    00662                     const T7& t7 ) {
    00663         QCString args;
    00664         args.sprintf( "(%s,%s,%s,%s,%s,%s,%s)",
    00665                      dcopTypeName(t1),
    00666                      dcopTypeName(t2),
    00667                      dcopTypeName(t3),
    00668                      dcopTypeName(t4),
    00669                      dcopTypeName(t5),
    00670                      dcopTypeName(t6),
    00671                      dcopTypeName(t7) );
    00672         QByteArray data;
    00673         QDataStream ds( data, IO_WriteOnly );
    00674         ds << t1 << t2 << t3 << t4 << t5 << t6 << t7;
    00675         return callInternal( fun, args, data );
    00676     }
    00677
    00707     template <class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
    00708     DCOPReply call( const QCString& fun,
    00709                     const T1& t1,
    00710                     const T2& t2,
    00711                     const T3& t3,
    00712                     const T4& t4,
    00713                     const T5& t5,
    00714                     const T6& t6,
    00715                     const T7& t7,
    00716                     const T8& t8 ) {
    00717         QCString args;
    00718         args.sprintf( "(%s,%s,%s,%s,%s,%s,%s,%s)",
    00719                      dcopTypeName(t1),
    00720                      dcopTypeName(t2),
    00721                      dcopTypeName(t3),
    00722                      dcopTypeName(t4),
    00723                      dcopTypeName(t5),
    00724                      dcopTypeName(t6),
    00725                      dcopTypeName(t7),
    00726                      dcopTypeName(t8) );
    00727         QByteArray data;
    00728         QDataStream ds( data, IO_WriteOnly );
    00729         ds << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
    00730         return callInternal( fun, args, data );
    00731     }
    00732
    00746     bool send( const QCString& fun ) {
    00747         QByteArray data;
    00748         return sendInternal( fun, "()", data );
    00749     }
    00750
    00767     template <class T1>
    00768     bool send( const QCString& fun, const T1& t1 ) {
    00769         QCString args;
    00770         args.sprintf( "(%s)",
    00771                      dcopTypeName(t1) );
    00772         QByteArray data;
    00773         QDataStream ds( data, IO_WriteOnly );
    00774         ds << t1;
    00775         return sendInternal( fun, args, data );
    00776     }
    00795     template <class T1, class T2>
    00796     bool send( const QCString& fun,
    00797                     const T1& t1,
    00798                     const T2& t2 ) {
    00799         QCString args;
    00800         args.sprintf( "(%s,%s)",
    00801                      dcopTypeName(t1),
    00802                      dcopTypeName(t2) );
    00803         QByteArray data;
    00804         QDataStream ds( data, IO_WriteOnly );
    00805         ds << t1 << t2;
    00806         return sendInternal( fun, args, data );
    00807     }
    00828     template <class T1, class T2, class T3>
    00829     bool send( const QCString& fun,
    00830                     const T1& t1,
    00831                     const T2& t2,
    00832                     const T3& t3 ) {
    00833         QCString args;
    00834         args.sprintf( "(%s,%s,%s)",
    00835                      dcopTypeName(t1),
    00836                      dcopTypeName(t2),
    00837                      dcopTypeName(t3) );
    00838         QByteArray data;
    00839         QDataStream ds( data, IO_WriteOnly );
    00840         ds << t1 << t2 << t3;
    00841         return sendInternal( fun, args, data );
    00842     }
    00865     template <class T1,class T2,class T3,class T4>
    00866     bool send( const QCString& fun,
    00867                     const T1& t1,
    00868                     const T2& t2,
    00869                     const T3& t3,
    00870                     const T4& t4 ) {
    00871         QCString args;
    00872         args.sprintf( "(%s,%s,%s,%s)",
    00873                      dcopTypeName(t1),
    00874                      dcopTypeName(t2),
    00875                      dcopTypeName(t3),
    00876                      dcopTypeName(t4) );
    00877         QByteArray data;
    00878         QDataStream ds( data, IO_WriteOnly );
    00879         ds << t1 << t2 << t3 << t4;
    00880         return sendInternal( fun, args, data );
    00881     }
    00906     template <class T1,class T2,class T3,class T4,class T5>
    00907     bool send( const QCString& fun,
    00908                     const T1& t1,
    00909                     const T2& t2,
    00910                     const T3& t3,
    00911                     const T4& t4,
    00912                     const T5& t5 ) {
    00913         QCString args;
    00914         args.sprintf( "(%s,%s,%s,%s,%s)",
    00915                      dcopTypeName(t1),
    00916                      dcopTypeName(t2),
    00917                      dcopTypeName(t3),
    00918                      dcopTypeName(t4),
    00919                      dcopTypeName(t5) );
    00920         QByteArray data;
    00921         QDataStream ds( data, IO_WriteOnly );
    00922         ds << t1 << t2 << t3 << t4 << t5;
    00923         return sendInternal( fun, args, data );
    00924     }
    00951     template <class T1,class T2,class T3,class T4,class T5,class T6>
    00952     bool send( const QCString& fun,
    00953                     const T1& t1,
    00954                     const T2& t2,
    00955                     const T3& t3,
    00956                     const T4& t4,
    00957                     const T5& t5,
    00958                     const T6& t6 ) {
    00959         QCString args;
    00960         args.sprintf( "(%s,%s,%s,%s,%s,%s)",
    00961                      dcopTypeName(t1),
    00962                      dcopTypeName(t2),
    00963                      dcopTypeName(t3),
    00964                      dcopTypeName(t4),
    00965                      dcopTypeName(t5),
    00966                      dcopTypeName(t6) );
    00967         QByteArray data;
    00968         QDataStream ds( data, IO_WriteOnly );
    00969         ds << t1 << t2 << t3 << t4 << t5 << t6;
    00970         return sendInternal( fun, args, data );
    00971     }
    01000     template <class T1,class T2,class T3,class T4,class T5,class T6,class T7>
    01001     bool send( const QCString& fun,
    01002                     const T1& t1,
    01003                     const T2& t2,
    01004                     const T3& t3,
    01005                     const T4& t4,
    01006                     const T5& t5,
    01007                     const T6& t6,
    01008                     const T7& t7 ) {
    01009         QCString args;
    01010         args.sprintf( "(%s,%s,%s,%s,%s,%s,%s)",
    01011                      dcopTypeName(t1),
    01012                      dcopTypeName(t2),
    01013                      dcopTypeName(t3),
    01014                      dcopTypeName(t4),
    01015                      dcopTypeName(t5),
    01016                      dcopTypeName(t6),
    01017                      dcopTypeName(t7) );
    01018         QByteArray data;
    01019         QDataStream ds( data, IO_WriteOnly );
    01020         ds << t1 << t2 << t3 << t4 << t5 << t6 << t7;
    01021         return sendInternal( fun, args, data );
    01022     }
    01053     template <class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
    01054     bool send( const QCString& fun,
    01055                     const T1& t1,
    01056                     const T2& t2,
    01057                     const T3& t3,
    01058                     const T4& t4,
    01059                     const T5& t5,
    01060                     const T6& t6,
    01061                     const T7& t7,
    01062                     const T8& t8 ) {
    01063         QCString args;
    01064         args.sprintf( "(%s,%s,%s,%s,%s,%s,%s,%s)",
    01065                      dcopTypeName(t1),
    01066                      dcopTypeName(t2),
    01067                      dcopTypeName(t3),
    01068                      dcopTypeName(t4),
    01069                      dcopTypeName(t5),
    01070                      dcopTypeName(t6),
    01071                      dcopTypeName(t7),
    01072                      dcopTypeName(t8) );
    01073         QByteArray data;
    01074         QDataStream ds( data, IO_WriteOnly );
    01075         ds << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
    01076         return sendInternal( fun, args, data );
    01077     }
    01078
    01079
    01080
    01081 private:
    01082     DCOPReply callInternal( const QCString& fun, const QCString& args, const QByteArray& data );
    01083     bool sendInternal( const QCString& fun, const QCString& args, const QByteArray& data );
    01084
    01085     QCString m_app;
    01086     QCString m_obj;
    01087     QCString m_type;
    01088
    01089     class DCOPRefPrivate;
    01090     DCOPRefPrivate *d;
    01091 };
    01092
    01096 QDataStream& operator<<( QDataStream&, const DCOPRef& ref );
    01100 QDataStream& operator>>( QDataStream&, DCOPRef& ref );
    01101
    01102 #endif

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