Responder.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_Responder_h
30#define Pt_XmlRpc_Responder_h
31
32#include <Pt/XmlRpc/Api.h>
33#include <Pt/XmlRpc/Fault.h>
34#include <Pt/XmlRpc/Formatter.h>
35#include <Pt/Remoting/Responder.h>
36#include <Pt/Xml/InputSource.h>
37#include <Pt/Xml/XmlReader.h>
38#include <Pt/TextStream.h>
39#include <Pt/NonCopyable.h>
40#include <Pt/Types.h>
41
42namespace Pt {
43
44namespace XmlRpc {
45
48class PT_XMLRPC_API Responder : public Remoting::Responder
49{
50 public:
54
57 virtual ~Responder();
58
61 bool isFailed() const;
62
63 protected:
64 // inheritdoc
65 virtual void onReady();
66
67 // inheritdoc
68 virtual void onCancel();
69
77 virtual void onFault(const Fault& fault) = 0;
78
86 virtual void onResult() = 0;
87
88 protected:
94 void beginMessage(std::istream& is);
95
105
113
119 void beginResult(std::ostream& os);
120
121 void beginFault(std::ostream& os, const Fault& fault);
122
130
138
145 void setFault(int rc, const char* msg);
146
147 private:
149 bool advance(const Pt::Xml::Node& node);
150
151 private:
152 enum State
153 {
154 OnBegin,
155 OnMethodCallBegin,
156 OnMethodNameBegin,
157 OnMethodName,
158 OnMethodNameEnd,
159 OnParams,
160 OnParam,
161 OnParamsEnd,
162 OnMethodCallEnd
163 };
164
166 Xml::XmlReader _reader;
167 Composer** _args;
168 State _state;
169
170 Utf8Codec _utf8;
171 TextOStream _ts;
172 Decomposer* _result;
173
174 Formatter _formatter;
175 Fault _fault;
176 bool _isFault;
177 Pt::varint_t _r1;
178 Pt::varint_t _r2;
179};
180
181} // namespace XmlRpc
182
183} // namespace Pt
184
185#endif // Pt_XmlRpc_Responder_h
Composes types during serialization.
Definition Composer.h:101
Manages the decomposition of types during serialization.
Definition Decomposer.h:121
Dispatches requests to a service procedure.
Definition Responder.h:50
Remote service definition.
Definition ServiceDefinition.h:59
Event loop of a thread or process.
Definition EventLoop.h:83
Convert between unicode and UTF-8.
Definition Utf8Codec.h:44
XML-RPC fault exception.
Definition Fault.h:44
Responder(Remoting::ServiceDefinition &service)
Construct with Service.
virtual ~Responder()
Destructor.
virtual void onCancel()
Cancels all operations.
void beginMessage(std::istream &is)
Parses the XML-RPC message.
void beginResult(std::ostream &os)
Formats the XML-RPC result.
virtual void onReady()
The service procedure has finished.
void setFault(int rc, const char *msg)
Fails the service procedure.
bool advanceResult()
Formats the XML-RPC message.
bool parseMessage()
Parses the XML-RPC message.
void finishResult()
Formats the XML-RPC message.
bool isFailed() const
Indicates if the procedure has failed.
virtual void onFault(const Fault &fault)=0
The service procedure has failed.
virtual void onResult()=0
The service procedure has finished.
void finishMessage(System::EventLoop &loop)
Parses the XML-RPC message.
Binary input source for the XML reader.
Definition InputSource.h:249
XML document node.
Definition Node.h:51
Reads XML as a Stream of XML Nodes.
Definition XmlReader.h:80
XML RPC services and clients.
Core module.
Definition Allocator.h:33