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  void reset(ServiceDeclaration& service);
68 
71  bool isFailed() const;
72 
73  protected:
74  virtual void onBeginCall(Composer& r, Pt::Remoting::RemoteCall& method, Decomposer** argv, unsigned argc);
75 
76  virtual void onEndCall();
77 
78  virtual void onCall(Composer& r, Pt::Remoting::RemoteCall& method, Decomposer** argv, unsigned argc);
79 
80  virtual void onCancel();
81 
82  protected:
88  virtual void onBeginInvoke() = 0;
89 
90  virtual void onEndInvoke() = 0;
91 
97  virtual void onInvoke() = 0;
98 
99  protected:
105  void beginMessage(std::ostream& os);
106 
114 
122 
128  void beginResult(std::istream& is);
129 
136  bool parseResult();
137 
143  void processResult(std::istream& is);
144 
151  void setFault(int rc, const char* msg);
152 
153  private:
155  bool advance(const Xml::Node& node);
156 
157  private:
158  enum State
159  {
160  OnBegin,
161  OnEnvelope,
162  OnBody,
163  OnMethod,
164  OnParam,
165  OnParamEnd,
166  OnMethodEnd,
167  OnFault,
168  OnFaultCode,
169  OnFaultCodeValue,
170  OnFaultReason,
171  OnFaultReasonText,
172  OnFaultEnd,
173  OnBodyEnd,
174  OnEnvelopeEnd
175  };
176 
177  Composer* _r;
178  Decomposer** _argv;
179  unsigned _argc;
180  Decomposer* _arg;
181  unsigned _argn;
182 
183  Pt::Utf8Codec _utf8;
184  TextOStream _ts;
185 
187  Xml::XmlReader _reader;
188  State _state;
189 
190  ServiceDeclaration* _serviceDef;
191  const Operation* _op;
192  Formatter _fmt;
193  Fault _fault;
194  bool _isFault;
195 
196  Pt::varint_t _r1;
197  Pt::varint_t _r2;
198 };
199 
200 } // namespace Soap
201 
202 } // namespace Pt
203 
204 #endif // Pt_Soap_Client_h
Core module.
Definition: pt-gfx-images.dox:14
Manages the decomposition of types during serialization.
Definition: Decomposer.h:44
Reads XML as a Stream of XML Nodes.
Definition: XmlReader.h:80
void beginMessage(std::ostream &os)
Formats the XML-RPC message.
bool isFailed() const
Indicates if the procedure has failed.
Convert between unicode and UTF-8.
Definition: Utf8Codec.h:44
void reset(ServiceDeclaration &service)
Resets the client.
bool advanceMessage()
Formats the XML-RPC message.
XML-RPC fault exception.
Definition: Fault.h:44
void processResult(std::istream &is)
Parses the XML-RPC result.
virtual void onCancel()
Cancels the remote procedure call.
void beginResult(std::istream &is)
Parses the XML-RPC result.
XML document node.
Definition: Node.h:51
void finishMessage()
Formats the XML-RPC message.
virtual void onBeginInvoke()=0
An asynchronous remote procedure is invoked.
Composes types during serialization.
Definition: Composer.h:43
Client(ServiceDeclaration &service)
Constructor.
void setFault(int rc, const char *msg)
Fails the current procedure.
A client for remote procedure calls.
Definition: Client.h:48
Binary input source for the XML reader.
Definition: InputSource.h:249
virtual ~Client()
Destructor.
A client for remote procedure calls.
Definition: Client.h:55
bool parseResult()
Parses the XML-RPC result.
virtual void onInvoke()=0
A synchronous remote procedure is called.