TDE network applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xmlrpciface.h 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * kxmlrpcclient.h - (c) 2003 Frerich Raabe <raabe@kde.org>
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef KXMLRPCCLIENT_H
  26. #define KXMLRPCCLIENT_H
  27. #include <kurl.h>
  28. #include <tqbuffer.h>
  29. #include <tqdatastream.h>
  30. #include <tqobject.h>
  31. #include <tqvariant.h>
  32. #include <tqvaluelist.h>
  33. class TQDomDocument;
  34. class TQDomElement;
  35. namespace TDEIO
  36. {
  37. class Job;
  38. }
  39. namespace KXMLRPC
  40. {
  41. class Query;
  42. class QueryResult;
  43. class Server;
  44. class Query : public TQObject
  45. {
  46. Q_OBJECT
  47. public:
  48. class Result
  49. {
  50. friend class Query;
  51. friend TQDataStream &operator>>( TQDataStream &s, Query::Result &r );
  52. public:
  53. Result() { }
  54. bool success() const { return m_success; }
  55. int errorCode() const { return m_errorCode; }
  56. TQString errorString() const { return m_errorString; }
  57. TQValueList<TQVariant> data() const { return m_data; }
  58. TQString server() const { return m_server; }
  59. TQString method() const { return m_method; }
  60. TQValueList<TQVariant> args() const { return m_args; }
  61. private:
  62. bool m_success;
  63. int m_errorCode;
  64. TQString m_errorString;
  65. TQValueList<TQVariant> m_data;
  66. TQString m_server;
  67. TQString m_method;
  68. TQValueList<TQVariant> m_args;
  69. };
  70. static Query *create( TQObject *parent = 0, const char *name = 0 );
  71. static TQString marshal( const TQVariant &v );
  72. static TQVariant demarshal( const TQDomElement &e );
  73. public slots:
  74. void call( const TQString &server, const TQString &method,
  75. const TQValueList<TQVariant> &args = TQValueList<TQVariant>(),
  76. const TQString &userAgent = "KDE-XMLRPC" );
  77. signals:
  78. void infoMessage( const TQString &msg );
  79. void finished( const KXMLRPC::Query::Result &result );
  80. private slots:
  81. void slotInfoMessage( TDEIO::Job *job, const TQString &msg );
  82. void slotData( TDEIO::Job *job, const TQByteArray &data );
  83. void slotResult( TDEIO::Job *job );
  84. private:
  85. bool isMessageResponse( const TQDomDocument &doc ) const;
  86. bool isFaultResponse( const TQDomDocument &doc ) const;
  87. Result parseMessageResponse( const TQDomDocument &doc ) const;
  88. Result parseFaultResponse( const TQDomDocument &doc ) const;
  89. TQString markupCall( const TQString &method,
  90. const TQValueList<TQVariant> &args ) const;
  91. Query( TQObject *parent = 0, const char *name = 0 );
  92. TQBuffer m_buffer;
  93. TQString m_server;
  94. TQString m_method;
  95. TQValueList<TQVariant> m_args;
  96. };
  97. class Server : public TQObject
  98. {
  99. Q_OBJECT
  100. public:
  101. Server( const KURL &url = KURL(),
  102. TQObject *parent = 0, const char *name = 0 );
  103. const KURL &url() const { return m_url; }
  104. void setUrl( const KURL &url );
  105. TQString userAgent() const { return m_userAgent; }
  106. void setUserAgent( const TQString &userAgent) { m_userAgent = userAgent; }
  107. template <typename T>
  108. void call( const TQString &method, const TQValueList<T> &arg,
  109. TQObject *object, const char *slot );
  110. static TQValueList<TQVariant> toVariantList( const TQVariant &arg );
  111. static TQValueList<TQVariant> toVariantList( int arg );
  112. static TQValueList<TQVariant> toVariantList( bool arg );
  113. static TQValueList<TQVariant> toVariantList( double arg );
  114. static TQValueList<TQVariant> toVariantList( const TQString &arg );
  115. static TQValueList<TQVariant> toVariantList( const TQCString &arg );
  116. static TQValueList<TQVariant> toVariantList( const TQByteArray &arg );
  117. static TQValueList<TQVariant> toVariantList( const TQDateTime &arg );
  118. static TQValueList<TQVariant> toVariantList( const TQStringList &arg );
  119. signals:
  120. void infoMessage( const TQString &msg );
  121. public slots:
  122. void call( const TQString &method, const TQValueList<TQVariant> &args,
  123. TQObject *object, const char *slot );
  124. void call( const TQString &method, const TQValueList<TQVariant> &args,
  125. TQObject *object, const char *slot,
  126. TQObject *infoObject, const char *infoSlot );
  127. private:
  128. KURL m_url;
  129. TQString m_userAgent;
  130. };
  131. inline TQDataStream &operator>>( TQDataStream &s, Query::Result &r )
  132. {
  133. return s >> r.m_errorCode >> r.m_errorString >> r.m_data
  134. >> r.m_server >> r.m_method >> r.m_args;
  135. }
  136. }
  137. template <typename T>
  138. void KXMLRPC::Server::call( const TQString &method, const TQValueList<T> &arg,
  139. TQObject *object, const char *slot )
  140. {
  141. TQValueList<TQVariant> args;
  142. typename TQValueList<T>::ConstIterator it = arg.begin();
  143. typename TQValueList<T>::ConstIterator end = arg.end();
  144. for ( ; it != end; ++it )
  145. args << TQVariant( *it );
  146. call( method, args, object, slot );
  147. }
  148. inline TQDataStream &operator<<( TQDataStream &s, const KXMLRPC::Query::Result &r )
  149. {
  150. return s << r.errorCode() << r.errorString() << r.data()
  151. << r.server() << r.method() << r.args();
  152. }
  153. #endif // KXMLRPCCLIENT_H
  154. // vim:ts=4:sw=4:noet