Client.h
1 /*
2  * Copyright (C) 2014 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_Soap_Client_h
30 #define Pt_Soap_Client_h
31 
32 #include <Pt/Soap/Api.h>
33 #include <Pt/Soap/Fault.h>
34 #include <Pt/Soap/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/Types.h>
43 #include <string>
44 
45 namespace Pt {
46 
47 namespace Soap {
48 
49 class Operation;
50 class ServiceDeclaration;
51 
54 class PT_SOAP_API Client : public Pt::Remoting::Client
55 {
56  public:
59  Client(ServiceDeclaration& service);
60 
63  virtual ~Client();
64 
67  bool isFailed() const;
68 
69  protected:
70  virtual void onBeginCall(Composer& r, Pt::Remoting::RemoteCall& method, Decomposer** argv, unsigned argc);
71 
72  virtual void onEndCall();
73 
74  virtual void onCall(Composer& r, Pt::Remoting::RemoteCall& method, Decomposer** argv, unsigned argc);
75 
76  virtual void onCancel();
77 
78  protected:
84  virtual void onBeginInvoke() = 0;
85 
86  virtual void onEndInvoke() = 0;
87 
93  virtual void onInvoke() = 0;
94 
95  protected:
101  void beginMessage(std::ostream& os);
102 
109  bool advanceMessage();
110 
117  void finishMessage();
118 
124  void beginResult(std::istream& is);
125 
132  bool parseResult();
133 
139  void processResult(std::istream& is);
140 
147  void setFault(int rc, const char* msg);
148 
149  private:
151  bool advance(const Xml::Node& node);
152 
153  private:
154  enum State
155  {
156  OnBegin,
157  OnEnvelope,
158  OnBody,
159  OnMethod,
160  OnParam,
161  OnParamEnd,
162  OnMethodEnd,
163  OnFault,
164  OnFaultCode,
165  OnFaultCodeValue,
166  OnFaultReason,
167  OnFaultReasonText,
168  OnFaultEnd,
169  OnBodyEnd,
170  OnEnvelopeEnd
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  ServiceDeclaration* _serviceDef;
187  const Operation* _op;
188  Formatter _fmt;
189  Fault _fault;
190  bool _isFault;
191 
192  Pt::varint_t _r1;
193  Pt::varint_t _r2;
194 };
195 
196 } // namespace Soap
197 
198 } // namespace Pt
199 
200 #endif // Pt_Soap_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:54
Binary input source for the XML reader.
Definition: InputSource.h:248
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