dcopclient.h
00001 /* 00002 Copyright (c) 1999 Preston Brown <pbrown@kde.org> 00003 Copyright (c) 1999, 2000 Matthias Ettrich <ettrich@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 _DCOPCLIENT_H 00024 #define _DCOPCLIENT_H 00025 00026 #include <qobject.h> 00027 #include <qcstring.h> 00028 #include <qvaluelist.h> 00029 #include <qstring.h> 00030 #include <kdatastream.h> // needed for proper bool marshalling 00031 #include <kdelibs_export.h> 00032 00033 class DCOPObjectProxy; 00034 class DCOPClientPrivate; 00035 class DCOPClientTransaction; 00036 00037 typedef QValueList<QCString> QCStringList; 00038 00068 class DCOP_EXPORT DCOPClient : public QObject 00069 { 00070 Q_OBJECT 00071 00072 public: 00075 DCOPClient(); 00076 00080 virtual ~DCOPClient(); 00081 00089 static void setServerAddress(const QCString &addr); 00090 00109 bool attach(); 00110 00117 void bindToApp(); 00118 00123 bool detach(); 00124 00129 bool isAttached() const; 00130 00136 bool isAttachedToForeignServer() const; 00137 00142 bool acceptCalls() const; 00143 00150 void setAcceptCalls(bool b); 00151 00158 bool qtBridgeEnabled(); // ### KDE 4.0: make const 00159 00167 void setQtBridgeEnabled(bool b); 00168 00194 QCString registerAs( const QCString &appId, bool addPID = true ); 00195 00200 bool isRegistered() const; 00201 00207 QCString appId() const; 00208 00213 int socket() const; 00214 00227 void suspend(); 00228 00234 void resume(); 00235 00242 bool isSuspended() const; 00243 00254 bool send(const QCString &remApp, const QCString &remObj, 00255 const QCString &remFun, const QByteArray &data); 00256 00268 bool send(const QCString &remApp, const QCString &remObj, 00269 const QCString &remFun, const QString &data); 00270 00300 bool call(const QCString &remApp, const QCString &remObj, 00301 const QCString &remFun, const QByteArray &data, 00302 QCString& replyType, QByteArray &replyData, 00303 bool useEventLoop/*=false*/, int timeout/*=-1*/); 00307 // KDE4 merge with above 00308 bool call(const QCString &remApp, const QCString &remObj, 00309 const QCString &remFun, const QByteArray &data, 00310 QCString& replyType, QByteArray &replyData, 00311 bool useEventLoop=false); 00312 00341 int callAsync(const QCString &remApp, const QCString &remObj, 00342 const QCString &remFun, const QByteArray &data, 00343 QObject *callBackObj, const char *callBackSlot); 00344 00381 bool findObject(const QCString &remApp, const QCString &remObj, 00382 const QCString &remFun, const QByteArray &data, 00383 QCString &foundApp, QCString &foundObj, 00384 bool useEventLoop/*=false*/, int timeout/*=-1*/); 00385 00389 // KDE4 merge with above 00390 bool findObject(const QCString &remApp, const QCString &remObj, 00391 const QCString &remFun, const QByteArray &data, 00392 QCString &foundApp, QCString &foundObj, 00393 bool useEventLoop=false); 00394 00395 00400 void emitDCOPSignal( const QCString &object, const QCString &signal, 00401 const QByteArray &data); 00402 00403 /* For backwards compatibility */ 00404 void emitDCOPSignal( const QCString &signal, const QByteArray &data); 00405 00426 bool connectDCOPSignal( const QCString &sender, const QCString &senderObj, 00427 const QCString &signal, 00428 const QCString &receiverObj, const QCString &slot, 00429 bool Volatile); 00430 00435 bool connectDCOPSignal( const QCString &sender, const QCString &signal, 00436 const QCString &receiverObj, const QCString &slot, 00437 bool Volatile) KDE_DEPRECATED; 00438 00456 bool disconnectDCOPSignal( const QCString &sender, const QCString &senderObj, 00457 const QCString &signal, 00458 const QCString &receiverObj, const QCString &slot); 00459 00464 bool disconnectDCOPSignal( const QCString &sender, const QCString &signal, 00465 const QCString &receiverObj, const QCString &slot) KDE_DEPRECATED; 00466 00482 virtual bool process(const QCString &fun, const QByteArray &data, 00483 QCString& replyType, QByteArray &replyData); 00484 00494 DCOPClientTransaction *beginTransaction( ); 00495 00503 void endTransaction( DCOPClientTransaction *t, QCString& replyType, QByteArray &replyData); 00504 00514 Q_INT32 transactionId() const; 00515 00521 bool isApplicationRegistered( const QCString& remApp); 00522 00528 QCStringList registeredApplications(); 00529 00537 QCStringList remoteObjects( const QCString& remApp, bool *ok = 0 ); 00538 00548 QCStringList remoteInterfaces( const QCString& remApp, const QCString& remObj , bool *ok = 0 ); 00549 00559 QCStringList remoteFunctions( const QCString& remApp, const QCString& remObj , bool *ok = 0 ); 00560 00575 bool receive(const QCString &app, const QCString &obj, 00576 const QCString &fun, const QByteArray& data, 00577 QCString& replyType, QByteArray &replyData); 00578 00592 bool find(const QCString &app, const QCString &obj, 00593 const QCString &fun, const QByteArray& data, 00594 QCString& replyType, QByteArray &replyData); 00595 00613 static QCString normalizeFunctionSignature( const QCString& fun ); 00614 00615 00621 QCString senderId() const; 00622 00623 00631 void setDefaultObject( const QCString& objId ); 00632 00641 QCString defaultObject() const; 00642 00654 void setNotifications( bool enabled ); 00655 00664 void setDaemonMode( bool daemonMode ); 00665 00671 void setPriorityCall(bool); 00672 00680 static DCOPClient* mainClient(); 00681 00689 static void setMainClient( DCOPClient* mainClient); 00690 00696 static DCOPClient* findLocalClient( const QCString &_appId ); 00697 00701 static void emergencyClose(); 00702 00708 static const char *postMortemSender(); 00710 static const char *postMortemObject(); 00712 static const char *postMortemFunction(); 00713 00721 static QCString dcopServerFile(const QCString &hostname=0); 00722 00728 static QCString dcopServerFileOld(const QCString &hostname=0) KDE_DEPRECATED; 00729 00733 static QCString iceauthPath(); 00734 00735 signals: 00744 void applicationRegistered( const QCString& appId ); 00753 void applicationRemoved( const QCString& appId ); 00754 00763 void attachFailed(const QString &msg); 00764 00782 void blockUserInput( bool block ); 00783 00793 void callBack(int, const QCString&, const QByteArray &); 00794 00795 public slots: 00800 void processSocketData(int socknum); 00801 00802 protected slots: 00803 00804 private slots: 00805 void processPostedMessagesInternal(); 00806 void asyncReplyReady(); 00807 void eventLoopTimeout(); 00808 00809 public: 00810 class ReplyStruct; 00811 00815 void handleAsyncReply(ReplyStruct *replyStruct); 00816 00817 private: 00818 00819 bool isLocalTransactionFinished(Q_INT32 id, QCString &replyType, QByteArray &replyData); 00820 00821 bool attachInternal( bool registerAsAnonymous = true ); 00822 00823 bool callInternal(const QCString &remApp, const QCString &remObj, 00824 const QCString &remFun, const QByteArray &data, 00825 QCString& replyType, QByteArray &replyData, 00826 bool useEventLoop, int timeout, int minor_opcode); 00827 00828 00829 bool callInternal(const QCString &remApp, const QCString &remObjId, 00830 const QCString &remFun, const QByteArray &data, 00831 ReplyStruct *replyStruct, 00832 bool useEventLoop, int timeout, int minor_opcode); 00833 00834 protected: 00835 virtual void virtual_hook( int id, void* data ); 00836 private: 00837 DCOPClientPrivate *d; 00838 }; 00839 00840 #endif