Client.h
1 /*
2  * Copyright (C) 2009-2013 by Dr. Marc Boris Duerner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 #ifndef Pt_XmlRpc_Client_h
30 #define Pt_XmlRpc_Client_h
31 
32 #include <Pt/XmlRpc/Api.h>
33 #include <Pt/XmlRpc/Fault.h>
34 #include <Pt/XmlRpc/Formatter.h>
35 #include <Pt/Remoting/Client.h>
36 #include <Pt/Xml/InputSource.h>
37 #include <Pt/Xml/XmlReader.h>
38 #include <Pt/Composer.h>
39 #include <Pt/Decomposer.h>
40 #include <Pt/Utf8Codec.h>
41 #include <Pt/TextStream.h>
42 #include <Pt/NonCopyable.h>
43 #include <Pt/Types.h>
44 #include <string>
45 
46 namespace Pt {
47 
48 namespace XmlRpc {
49 
52 class PT_XMLRPC_API Client : public Pt::Remoting::Client
53 {
54  public:
57  Client();
58 
61  virtual ~Client();
62 
65  bool isFailed() const;
66 
67  protected:
68  virtual void onBeginCall(Composer& r, Pt::Remoting::RemoteCall& method, Decomposer** argv, unsigned argc);
69 
70  virtual void onEndCall();
71 
72  virtual void onCall(Composer& r, Pt::Remoting::RemoteCall& method, Decomposer** argv, unsigned argc);
73 
74  virtual void onCancel();
75 
81  virtual void onBeginInvoke() = 0;
82 
83  virtual void onEndInvoke() = 0;
84 
90  virtual void onInvoke() = 0;
91 
92  protected:
98  void beginMessage(std::ostream& os);
99 
106  bool advanceMessage();
107 
114  void finishMessage();
115 
121  void beginResult(std::istream& is);
122 
129  bool parseResult();
130 
137  //void finishResult();
138 
144  void processResult(std::istream& is);
145 
152  void setFault(int rc, const char* msg);
153 
154  private:
156  bool advance(const Xml::Node& node);
157 
158  private:
159  enum State
160  {
161  OnBegin,
162  OnMethodResponseBegin,
163  OnFaultBegin,
164  OnFaultEnd,
165  OnFaultResponseEnd,
166  OnParamsBegin,
167  OnParam,
168  OnParamEnd,
169  OnParamsEnd,
170  OnMethodResponseEnd
171  };
172 
173  Composer* _r;
174  Decomposer** _argv;
175  unsigned _argc;
176  Decomposer* _arg;
177  unsigned _argn;
178 
179  Pt::Utf8Codec _utf8;
180  TextOStream _ts;
181 
183  Xml::XmlReader _reader;
184  State _state;
185 
186  Formatter _formatter;
187  Fault _fault;
189  bool _isFault;
190  Pt::varint_t _r1;
191  Pt::varint_t _r2;
192 };
193 
194 } // namespace XmlRpc
195 
196 } // namespace Pt
197 
198 #endif // Pt_XmlRpc_Client_h
XML-RPC fault exception.
Definition: Fault.h:43
Composes types during serialization.
Definition: Composer.h:42
Reads XML as a Stream of XML Nodes.
Definition: XmlReader.h:79
A client for remote procedure calls.
Definition: Client.h:52
Binary input source for the XML reader.
Definition: InputSource.h:248
Manages the composition of types during serialization.
Definition: Composer.h:268
A client for remote procedure calls.
Definition: Client.h:47
Text output stream for unicode character conversion.
XML document node.
Definition: Node.h:50
Manages the decomposition of types during serialization.
Definition: Decomposer.h:43
Convert between unicode and UTF-8.
Definition: Utf8Codec.h:43