Responder.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_Responder_h
30 #define Pt_Soap_Responder_h
31 
32 #include <Pt/Soap/Api.h>
33 #include <Pt/Soap/ServiceDeclaration.h>
34 #include <Pt/Soap/Formatter.h>
35 #include <Pt/Soap/Fault.h>
36 #include <Pt/Remoting/Responder.h>
37 #include <Pt/Xml/InputSource.h>
38 #include <Pt/Xml/XmlReader.h>
39 #include <Pt/System/EventLoop.h>
40 #include <Pt/SerializationContext.h>
41 #include <Pt/TextStream.h>
42 #include <Pt/NonCopyable.h>
43 #include <Pt/Types.h>
44 
45 namespace Pt {
46 
47 namespace Soap {
48 
51 class PT_SOAP_API Responder : public Remoting::Responder
52 {
53  public:
56  Responder(const ServiceDeclaration& decl, Remoting::ServiceDefinition& def);
57 
60  virtual ~Responder();
61 
64  bool isFailed() const;
65 
66  protected:
67  // inheritdoc
68  virtual void onReady();
69 
70  // inheritdoc
71  virtual void onCancel();
72 
80  virtual void onFault(const Fault& fault) = 0;
81 
89  virtual void onResult() = 0;
90 
91  protected:
97  void beginMessage(std::istream& is);
98 
107  bool parseMessage();
108 
115  void finishMessage(System::EventLoop& loop);
116 
122  void beginResult(std::ostream& os);
123 
124  void beginFault(std::ostream& os, const Fault& fault);
125 
132  bool advanceResult();
133 
140  void finishResult();
141 
148  void setFault(int rc, const char* msg);
149 
150  private:
152  bool advance(const Pt::Xml::Node& node);
153 
154  private:
155  enum State
156  {
157  OnBegin,
158  OnEnvelope,
159  OnBody,
160  OnMethod,
161  OnParam,
162  OnMethodEnd,
163  OnBodyEnd,
164  OnEnvelopeEnd,
165  };
166 
167  const ServiceDeclaration* _serviceDecl;
168  const Operation* _op;
169 
171  Xml::XmlReader _reader;
172  Composer** _args;
173  State _state;
174 
175  Utf8Codec _utf8;
176  TextOStream _ts;
177  Decomposer* _result;
178 
179  Formatter _formatter;
180  Fault _fault;
181  bool _isFault;
182  Pt::varint_t _r1;
183  Pt::varint_t _r2;
184 };
185 
186 } // namespace Soap
187 
188 } // namespace Pt
189 
190 #endif // Pt_Soap_SoapHttpService_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
Dispatches requests to a service procedure.
Definition: Responder.h:51
Remote service definition.
Definition: ServiceDefinition.h:19
Binary input source for the XML reader.
Definition: InputSource.h:248
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:72
Text output stream for unicode character conversion.
XML document node.
Definition: Node.h:50
Dispatches requests to a service procedure.
Definition: Responder.h:49
Manages the decomposition of types during serialization.
Definition: Decomposer.h:43
Convert between unicode and UTF-8.
Definition: Utf8Codec.h:43