00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _DCOPREF_H
00024 #define _DCOPREF_H
00025
00026 #include <qcstring.h>
00027 #include <dcoptypes.h>
00028 #include <kdatastream.h>
00029 #include "kdelibs_export.h"
00030
00031 class QDataStream;
00032 class DCOPObject;
00033 class DCOPClient;
00034
00044 class DCOP_EXPORT DCOPReply
00045 {
00046 public:
00053 template<class T>
00054 operator T() {
00055 T t;
00056 dcopTypeInit(t);
00057 if ( typeCheck( dcopTypeName(t), true ) ) {
00058 QDataStream reply( data, IO_ReadOnly );
00059 reply >> t;
00060 }
00061 return t;
00062 }
00070 template <class T> bool get( T& t, const char* tname ) {
00071 if ( typeCheck( tname, false ) ) {
00072 QDataStream reply( data, IO_ReadOnly );
00073 reply >> t;
00074 return true;
00075 }
00076 return false;
00077 }
00086 template <class T> bool get( T& t ) {
00087 if ( typeCheck( dcopTypeName(t), false ) ) {
00088 QDataStream reply( data, IO_ReadOnly );
00089 reply >> t;
00090 return true;
00091 }
00092 return false;
00093 }
00094
00099 inline bool isValid() const { return !type.isNull(); }
00100
00102 QByteArray data;
00104 QCString type;
00105 private:
00106 bool typeCheck( const char* t );
00107 bool typeCheck( const char* t, bool warn );
00108 };
00109
00120 class DCOP_EXPORT 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
00278 class DCOP_EXPORT DCOPRef
00279 {
00280 public:
00285 DCOPRef();
00286
00290 DCOPRef( const DCOPRef& ref );
00298 DCOPRef( const QCString& app, const QCString& obj = "" );
00299
00305 DCOPRef( DCOPObject *object );
00306
00316 DCOPRef( const QCString& app, const QCString& obj, const QCString& type );
00317
00323 bool isNull() const;
00324
00329 QCString app() const;
00330
00336 QCString obj() const;
00337
00341 QCString object() const;
00342
00347 QCString type() const;
00348
00349
00353 DCOPRef& operator=( const DCOPRef& );
00354
00361 void setRef( const QCString& app, const QCString& obj = "" );
00362
00369 void setRef( const QCString& app, const QCString& obj, const QCString& type );
00370
00371
00376 void clear();
00377
00378
00385 DCOPClient* dcopClient() const;
00386
00393 void setDCOPClient( DCOPClient *client );
00394
00403 enum EventLoopFlag { NoEventLoop, UseEventLoop };
00417 DCOPReply call( const QCString& fun ) {
00418 QByteArray data;
00419 return callInternal( fun, "()", data );
00420 }
00421
00435 DCOPReply callExt( const QCString& fun, EventLoopFlag useEventLoop=NoEventLoop,
00436 int timeout=-1 ) {
00437 QByteArray data;
00438 return callInternal( fun, "()", data, useEventLoop, timeout );
00439 }
00440
00456 template <class T1>
00457 DCOPReply call( const QCString& fun, const T1& t1 ) {
00458 QCString args;
00459 args.sprintf( "(%s)",
00460 dcopTypeName(t1) );
00461 QByteArray data;
00462 QDataStream ds( data, IO_WriteOnly );
00463 ds << t1;
00464 return callInternal( fun, args, data );
00465 }
00466
00482 template <class T1>
00483 DCOPReply callExt( const QCString& fun,
00484 EventLoopFlag useEventLoop, int timeout,
00485 const T1& t1) {
00486 QCString args;
00487 args.sprintf( "(%s)",
00488 dcopTypeName(t1) );
00489 QByteArray data;
00490 QDataStream ds( data, IO_WriteOnly );
00491 ds << t1;
00492 return callInternal( fun, args, data, useEventLoop, timeout );
00493 }
00494
00512 template <class T1, class T2>
00513 DCOPReply call( const QCString& fun,
00514 const T1& t1,
00515 const T2& t2 ) {
00516 QCString args;
00517 args.sprintf( "(%s,%s)",
00518 dcopTypeName(t1),
00519 dcopTypeName(t2) );
00520 QByteArray data;
00521 QDataStream ds( data, IO_WriteOnly );
00522 ds << t1 << t2;
00523 return callInternal( fun, args, data );
00524 }
00525
00543 template <class T1, class T2>
00544 DCOPReply callExt( const QCString& fun,
00545 EventLoopFlag useEventLoop, int timeout,
00546 const T1& t1,
00547 const T2& t2) {
00548 QCString args;
00549 args.sprintf( "(%s,%s)",
00550 dcopTypeName(t1),
00551 dcopTypeName(t2) );
00552 QByteArray data;
00553 QDataStream ds( data, IO_WriteOnly );
00554 ds << t1 << t2;
00555 return callInternal( fun, args, data, useEventLoop, timeout );
00556 }
00557
00577 template <class T1, class T2, class T3>
00578 DCOPReply call( const QCString& fun,
00579 const T1& t1,
00580 const T2& t2,
00581 const T3& t3 ) {
00582 QCString args;
00583 args.sprintf( "(%s,%s,%s)",
00584 dcopTypeName(t1),
00585 dcopTypeName(t2),
00586 dcopTypeName(t3) );
00587 QByteArray data;
00588 QDataStream ds( data, IO_WriteOnly );
00589 ds << t1 << t2 << t3;
00590 return callInternal( fun, args, data );
00591 }
00592
00612 template <class T1, class T2, class T3>
00613 DCOPReply callExt( const QCString& fun,
00614 EventLoopFlag useEventLoop, int timeout,
00615 const T1& t1,
00616 const T2& t2,
00617 const T3& t3) {
00618 QCString args;
00619 args.sprintf( "(%s,%s,%s)",
00620 dcopTypeName(t1),
00621 dcopTypeName(t2),
00622 dcopTypeName(t3) );
00623 QByteArray data;
00624 QDataStream ds( data, IO_WriteOnly );
00625 ds << t1 << t2 << t3;
00626 return callInternal( fun, args, data, useEventLoop, timeout );
00627 }
00628
00650 template <class T1,class T2,class T3,class T4>
00651 DCOPReply call( const QCString& fun,
00652 const T1& t1,
00653 const T2& t2,
00654 const T3& t3,
00655 const T4& t4 ) {
00656 QCString args;
00657 args.sprintf( "(%s,%s,%s,%s)",
00658 dcopTypeName(t1),
00659 dcopTypeName(t2),
00660 dcopTypeName(t3),
00661 dcopTypeName(t4) );
00662 QByteArray data;
00663 QDataStream ds( data, IO_WriteOnly );
00664 ds << t1 << t2 << t3 << t4;
00665 return callInternal( fun, args, data );
00666 }
00667
00689 template <class T1,class T2,class T3,class T4>
00690 DCOPReply callExt( const QCString& fun,
00691 EventLoopFlag useEventLoop, int timeout,
00692 const T1& t1,
00693 const T2& t2,
00694 const T3& t3,
00695 const T4& t4) {
00696 QCString args;
00697 args.sprintf( "(%s,%s,%s,%s)",
00698 dcopTypeName(t1),
00699 dcopTypeName(t2),
00700 dcopTypeName(t3),
00701 dcopTypeName(t4) );
00702 QByteArray data;
00703 QDataStream ds( data, IO_WriteOnly );
00704 ds << t1 << t2 << t3 << t4;
00705 return callInternal( fun, args, data, useEventLoop, timeout );
00706 }
00707
00731 template <class T1,class T2,class T3,class T4,class T5>
00732 DCOPReply call( const QCString& fun,
00733 const T1& t1,
00734 const T2& t2,
00735 const T3& t3,
00736 const T4& t4,
00737 const T5& t5 ) {
00738 QCString args;
00739 args.sprintf( "(%s,%s,%s,%s,%s)",
00740 dcopTypeName(t1),
00741 dcopTypeName(t2),
00742 dcopTypeName(t3),
00743 dcopTypeName(t4),
00744 dcopTypeName(t5) );
00745 QByteArray data;
00746 QDataStream ds( data, IO_WriteOnly );
00747 ds << t1 << t2 << t3 << t4 << t5;
00748 return callInternal( fun, args, data );
00749 }
00750
00774 template <class T1,class T2,class T3,class T4,class T5>
00775 DCOPReply callExt( const QCString& fun,
00776 EventLoopFlag useEventLoop, int timeout,
00777 const T1& t1,
00778 const T2& t2,
00779 const T3& t3,
00780 const T4& t4,
00781 const T5& t5 ) {
00782 QCString args;
00783 args.sprintf( "(%s,%s,%s,%s,%s)",
00784 dcopTypeName(t1),
00785 dcopTypeName(t2),
00786 dcopTypeName(t3),
00787 dcopTypeName(t4),
00788 dcopTypeName(t5) );
00789 QByteArray data;
00790 QDataStream ds( data, IO_WriteOnly );
00791 ds << t1 << t2 << t3 << t4 << t5;
00792 return callInternal( fun, args, data, useEventLoop, timeout );
00793 }
00794
00820 template <class T1,class T2,class T3,class T4,class T5,class T6>
00821 DCOPReply call( const QCString& fun,
00822 const T1& t1,
00823 const T2& t2,
00824 const T3& t3,
00825 const T4& t4,
00826 const T5& t5,
00827 const T6& t6 ) {
00828 QCString args;
00829 args.sprintf( "(%s,%s,%s,%s,%s,%s)",
00830 dcopTypeName(t1),
00831 dcopTypeName(t2),
00832 dcopTypeName(t3),
00833 dcopTypeName(t4),
00834 dcopTypeName(t5),
00835 dcopTypeName(t6) );
00836 QByteArray data;
00837 QDataStream ds( data, IO_WriteOnly );
00838 ds << t1 << t2 << t3 << t4 << t5 << t6;
00839 return callInternal( fun, args, data );
00840 }
00841
00867 template <class T1,class T2,class T3,class T4,class T5,class T6>
00868 DCOPReply callExt( const QCString& fun,
00869 EventLoopFlag useEventLoop, int timeout,
00870 const T1& t1,
00871 const T2& t2,
00872 const T3& t3,
00873 const T4& t4,
00874 const T5& t5,
00875 const T6& t6) {
00876 QCString args;
00877 args.sprintf( "(%s,%s,%s,%s,%s,%s)",
00878 dcopTypeName(t1),
00879 dcopTypeName(t2),
00880 dcopTypeName(t3),
00881 dcopTypeName(t4),
00882 dcopTypeName(t5),
00883 dcopTypeName(t6) );
00884 QByteArray data;
00885 QDataStream ds( data, IO_WriteOnly );
00886 ds << t1 << t2 << t3 << t4 << t5 << t6;
00887 return callInternal( fun, args, data, useEventLoop, timeout );
00888 }
00916 template <class T1,class T2,class T3,class T4,class T5,class T6,class T7>
00917 DCOPReply call( const QCString& fun,
00918 const T1& t1,
00919 const T2& t2,
00920 const T3& t3,
00921 const T4& t4,
00922 const T5& t5,
00923 const T6& t6,
00924 const T7& t7 ) {
00925 QCString args;
00926 args.sprintf( "(%s,%s,%s,%s,%s,%s,%s)",
00927 dcopTypeName(t1),
00928 dcopTypeName(t2),
00929 dcopTypeName(t3),
00930 dcopTypeName(t4),
00931 dcopTypeName(t5),
00932 dcopTypeName(t6),
00933 dcopTypeName(t7) );
00934 QByteArray data;
00935 QDataStream ds( data, IO_WriteOnly );
00936 ds << t1 << t2 << t3 << t4 << t5 << t6 << t7;
00937 return callInternal( fun, args, data );
00938 }
00939
00967 template <class T1,class T2,class T3,class T4,class T5,class T6,class T7>
00968 DCOPReply callExt( const QCString& fun,
00969 EventLoopFlag useEventLoop, int timeout,
00970 const T1& t1,
00971 const T2& t2,
00972 const T3& t3,
00973 const T4& t4,
00974 const T5& t5,
00975 const T6& t6,
00976 const T7& t7) {
00977 QCString args;
00978 args.sprintf( "(%s,%s,%s,%s,%s,%s,%s)",
00979 dcopTypeName(t1),
00980 dcopTypeName(t2),
00981 dcopTypeName(t3),
00982 dcopTypeName(t4),
00983 dcopTypeName(t5),
00984 dcopTypeName(t6),
00985 dcopTypeName(t7) );
00986 QByteArray data;
00987 QDataStream ds( data, IO_WriteOnly );
00988 ds << t1 << t2 << t3 << t4 << t5 << t6 << t7;
00989 return callInternal( fun, args, data, useEventLoop, timeout );
00990 }
00991
01021 template <class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
01022 DCOPReply call( const QCString& fun,
01023 const T1& t1,
01024 const T2& t2,
01025 const T3& t3,
01026 const T4& t4,
01027 const T5& t5,
01028 const T6& t6,
01029 const T7& t7,
01030 const T8& t8 ) {
01031 QCString args;
01032 args.sprintf( "(%s,%s,%s,%s,%s,%s,%s,%s)",
01033 dcopTypeName(t1),
01034 dcopTypeName(t2),
01035 dcopTypeName(t3),
01036 dcopTypeName(t4),
01037 dcopTypeName(t5),
01038 dcopTypeName(t6),
01039 dcopTypeName(t7),
01040 dcopTypeName(t8) );
01041 QByteArray data;
01042 QDataStream ds( data, IO_WriteOnly );
01043 ds << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
01044 return callInternal( fun, args, data );
01045 }
01046
01076 template <class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
01077 DCOPReply callExt( const QCString& fun,
01078 EventLoopFlag useEventLoop, int timeout,
01079 const T1& t1,
01080 const T2& t2,
01081 const T3& t3,
01082 const T4& t4,
01083 const T5& t5,
01084 const T6& t6,
01085 const T7& t7,
01086 const T8& t8) {
01087 QCString args;
01088 args.sprintf( "(%s,%s,%s,%s,%s,%s,%s,%s)",
01089 dcopTypeName(t1),
01090 dcopTypeName(t2),
01091 dcopTypeName(t3),
01092 dcopTypeName(t4),
01093 dcopTypeName(t5),
01094 dcopTypeName(t6),
01095 dcopTypeName(t7),
01096 dcopTypeName(t8) );
01097 QByteArray data;
01098 QDataStream ds( data, IO_WriteOnly );
01099 ds << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
01100 return callInternal( fun, args, data, useEventLoop, timeout );
01101 }
01102
01116 bool send( const QCString& fun ) {
01117 QByteArray data;
01118 return sendInternal( fun, "()", data );
01119 }
01120
01137 template <class T1>
01138 bool send( const QCString& fun, const T1& t1 ) {
01139 QCString args;
01140 args.sprintf( "(%s)",
01141 dcopTypeName(t1) );
01142 QByteArray data;
01143 QDataStream ds( data, IO_WriteOnly );
01144 ds << t1;
01145 return sendInternal( fun, args, data );
01146 }
01165 template <class T1, class T2>
01166 bool send( const QCString& fun,
01167 const T1& t1,
01168 const T2& t2 ) {
01169 QCString args;
01170 args.sprintf( "(%s,%s)",
01171 dcopTypeName(t1),
01172 dcopTypeName(t2) );
01173 QByteArray data;
01174 QDataStream ds( data, IO_WriteOnly );
01175 ds << t1 << t2;
01176 return sendInternal( fun, args, data );
01177 }
01198 template <class T1, class T2, class T3>
01199 bool send( const QCString& fun,
01200 const T1& t1,
01201 const T2& t2,
01202 const T3& t3 ) {
01203 QCString args;
01204 args.sprintf( "(%s,%s,%s)",
01205 dcopTypeName(t1),
01206 dcopTypeName(t2),
01207 dcopTypeName(t3) );
01208 QByteArray data;
01209 QDataStream ds( data, IO_WriteOnly );
01210 ds << t1 << t2 << t3;
01211 return sendInternal( fun, args, data );
01212 }
01235 template <class T1,class T2,class T3,class T4>
01236 bool send( const QCString& fun,
01237 const T1& t1,
01238 const T2& t2,
01239 const T3& t3,
01240 const T4& t4 ) {
01241 QCString args;
01242 args.sprintf( "(%s,%s,%s,%s)",
01243 dcopTypeName(t1),
01244 dcopTypeName(t2),
01245 dcopTypeName(t3),
01246 dcopTypeName(t4) );
01247 QByteArray data;
01248 QDataStream ds( data, IO_WriteOnly );
01249 ds << t1 << t2 << t3 << t4;
01250 return sendInternal( fun, args, data );
01251 }
01276 template <class T1,class T2,class T3,class T4,class T5>
01277 bool send( const QCString& fun,
01278 const T1& t1,
01279 const T2& t2,
01280 const T3& t3,
01281 const T4& t4,
01282 const T5& t5 ) {
01283 QCString args;
01284 args.sprintf( "(%s,%s,%s,%s,%s)",
01285 dcopTypeName(t1),
01286 dcopTypeName(t2),
01287 dcopTypeName(t3),
01288 dcopTypeName(t4),
01289 dcopTypeName(t5) );
01290 QByteArray data;
01291 QDataStream ds( data, IO_WriteOnly );
01292 ds << t1 << t2 << t3 << t4 << t5;
01293 return sendInternal( fun, args, data );
01294 }
01321 template <class T1,class T2,class T3,class T4,class T5,class T6>
01322 bool send( const QCString& fun,
01323 const T1& t1,
01324 const T2& t2,
01325 const T3& t3,
01326 const T4& t4,
01327 const T5& t5,
01328 const T6& t6 ) {
01329 QCString args;
01330 args.sprintf( "(%s,%s,%s,%s,%s,%s)",
01331 dcopTypeName(t1),
01332 dcopTypeName(t2),
01333 dcopTypeName(t3),
01334 dcopTypeName(t4),
01335 dcopTypeName(t5),
01336 dcopTypeName(t6) );
01337 QByteArray data;
01338 QDataStream ds( data, IO_WriteOnly );
01339 ds << t1 << t2 << t3 << t4 << t5 << t6;
01340 return sendInternal( fun, args, data );
01341 }
01370 template <class T1,class T2,class T3,class T4,class T5,class T6,class T7>
01371 bool send( const QCString& fun,
01372 const T1& t1,
01373 const T2& t2,
01374 const T3& t3,
01375 const T4& t4,
01376 const T5& t5,
01377 const T6& t6,
01378 const T7& t7 ) {
01379 QCString args;
01380 args.sprintf( "(%s,%s,%s,%s,%s,%s,%s)",
01381 dcopTypeName(t1),
01382 dcopTypeName(t2),
01383 dcopTypeName(t3),
01384 dcopTypeName(t4),
01385 dcopTypeName(t5),
01386 dcopTypeName(t6),
01387 dcopTypeName(t7) );
01388 QByteArray data;
01389 QDataStream ds( data, IO_WriteOnly );
01390 ds << t1 << t2 << t3 << t4 << t5 << t6 << t7;
01391 return sendInternal( fun, args, data );
01392 }
01423 template <class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
01424 bool send( const QCString& fun,
01425 const T1& t1,
01426 const T2& t2,
01427 const T3& t3,
01428 const T4& t4,
01429 const T5& t5,
01430 const T6& t6,
01431 const T7& t7,
01432 const T8& t8 ) {
01433 QCString args;
01434 args.sprintf( "(%s,%s,%s,%s,%s,%s,%s,%s)",
01435 dcopTypeName(t1),
01436 dcopTypeName(t2),
01437 dcopTypeName(t3),
01438 dcopTypeName(t4),
01439 dcopTypeName(t5),
01440 dcopTypeName(t6),
01441 dcopTypeName(t7),
01442 dcopTypeName(t8) );
01443 QByteArray data;
01444 QDataStream ds( data, IO_WriteOnly );
01445 ds << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
01446 return sendInternal( fun, args, data );
01447 }
01448
01449
01450
01451 private:
01452 DCOPReply callInternal( const QCString& fun, const QCString& args, const QByteArray& data,
01453 EventLoopFlag useEventLoop, int timeout );
01454 DCOPReply callInternal( const QCString& fun, const QCString& args, const QByteArray& data );
01455 bool sendInternal( const QCString& fun, const QCString& args, const QByteArray& data );
01456
01457 QCString m_app;
01458 QCString m_obj;
01459 QCString m_type;
01460
01461 class DCOPRefPrivate;
01462 DCOPRefPrivate *d;
01463 };
01464
01468 DCOP_EXPORT QDataStream& operator<<( QDataStream&, const DCOPRef& ref );
01472 DCOP_EXPORT QDataStream& operator>>( QDataStream&, DCOPRef& ref );
01473
01474 #endif