~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/xmlrpcpp/XmlRpcServer.h

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-06-07 11:28:52 UTC
  • Revision ID: package-import@ubuntu.com-20140607112852-pj9xhtlvwpgqjy5x
Tags: 1.3.15-1
* Initial release (Closes: #750861)
  flrig version 1.3.15 plus the following upstream commits:
  - 0001-License-Declaration.patch
  - 0002-FL_APPS-folder.patch
  - 0003-rig-home-dir.patch
  - 0004-RTS-DTR-restore.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#ifndef _XMLRPCSERVER_H_
 
3
#define _XMLRPCSERVER_H_
 
4
//
 
5
// XmlRpc++ Copyright (c) 2002-2008 by Chris Morley
 
6
//
 
7
#if defined(_MSC_VER)
 
8
# pragma warning(disable:4786)    // identifier was truncated in debug info
 
9
#endif
 
10
 
 
11
#include <map>
 
12
#include <string>
 
13
 
 
14
 
 
15
#include "XmlRpcDispatch.h"
 
16
#include "XmlRpcSource.h"
 
17
 
 
18
namespace XmlRpc {
 
19
 
 
20
 
 
21
  // An abstract class supporting XML RPC methods
 
22
  class XmlRpcServerMethod;
 
23
 
 
24
  // Class representing connections to specific clients
 
25
  class XmlRpcServerConnection;
 
26
 
 
27
  // Class representing argument and result values
 
28
  class XmlRpcValue;
 
29
 
 
30
 
 
31
  //! A class to handle XML RPC requests
 
32
  class XmlRpcServer : public XmlRpcSource {
 
33
  public:
 
34
    //! Create a server object.
 
35
    XmlRpcServer();
 
36
    //! Destructor.
 
37
    virtual ~XmlRpcServer();
 
38
 
 
39
    //! Specify whether introspection is enabled or not. Default is not enabled.
 
40
    void enableIntrospection(bool enabled=true);
 
41
 
 
42
    //! Add a command to the RPC server
 
43
    void addMethod(XmlRpcServerMethod* method);
 
44
 
 
45
    //! Remove a command from the RPC server
 
46
    void removeMethod(XmlRpcServerMethod* method);
 
47
 
 
48
    //! Remove a command from the RPC server by name
 
49
    void removeMethod(const std::string& methodName);
 
50
 
 
51
    //! Look up a method by name
 
52
    XmlRpcServerMethod* findMethod(const std::string& name) const;
 
53
 
 
54
    //! Create a socket, bind to the specified port, and
 
55
    //! set it in listen mode to make it available for clients.
 
56
    //! @param port The port to bind and listen on (zero to choose an arbitrary port)
 
57
    bool bindAndListen(int port, int backlog = 5);
 
58
 
 
59
    //! Get the port number this server is listening on.
 
60
    int getPort(void) const;
 
61
 
 
62
    //! Process client requests for the specified time (in seconds)
 
63
    void work(double timeSeconds);
 
64
 
 
65
    //! Temporarily stop processing client requests and exit the work() method.
 
66
    void exit();
 
67
 
 
68
    //! Close all connections with clients and the socket file descriptor
 
69
    void shutdown();
 
70
 
 
71
    //! Introspection support
 
72
    void listMethods(XmlRpcValue& result);
 
73
 
 
74
 
 
75
    //! Parses the request xml, runs the method, generates the response (header+xml).
 
76
    //! Returns a fault response if an error occurs during method execution.
 
77
    virtual std::string executeRequest(std::string const& request);
 
78
 
 
79
 
 
80
    // XmlRpcSource interface implementation
 
81
 
 
82
    //! Handle client connection requests
 
83
    virtual unsigned handleEvent(unsigned eventType);
 
84
 
 
85
    //! Remove a connection from the dispatcher
 
86
    virtual void removeConnection(XmlRpcServerConnection*);
 
87
 
 
88
  protected:
 
89
 
 
90
    // Static data
 
91
    static const char METHODNAME_TAG[];
 
92
    static const char PARAMS_TAG[];
 
93
    static const char PARAM_TAG[];
 
94
 
 
95
    static const std::string SYSTEM_MULTICALL;
 
96
    static const std::string METHODNAME;
 
97
    static const std::string PARAMS;
 
98
 
 
99
    static const std::string FAULTCODE;
 
100
    static const std::string FAULTSTRING;
 
101
 
 
102
 
 
103
    //! Accept a client connection request
 
104
    virtual void acceptConnection();
 
105
 
 
106
    //! Create a new connection object for processing requests from a specific client.
 
107
    //! If the client is not authorized to connect, close the socket and return 0.
 
108
    virtual XmlRpcServerConnection* createConnection(XmlRpcSocket::Socket socket);
 
109
 
 
110
    //! Hand off a new connection object to a dispatcher.
 
111
    virtual void dispatchConnection(XmlRpcServerConnection* sc);
 
112
 
 
113
 
 
114
    //! Parse the methodName and parameters from the request.
 
115
    //! @returns the methodName
 
116
    std::string parseRequest(std::string const& request, XmlRpcValue& params);
 
117
 
 
118
    //! Execute a named method with the specified params.
 
119
    bool executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
 
120
 
 
121
    //! Execute multiple calls and return the results in an array.
 
122
    //! System.multicall implementation
 
123
    bool executeMulticall(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result);
 
124
 
 
125
    //! Construct a response from the result XML.
 
126
    std::string generateResponse(std::string const& resultXml);
 
127
 
 
128
    //! Construct a fault response.
 
129
    std::string generateFaultResponse(std::string const& msg, int errorCode = -1);
 
130
 
 
131
    //! Return the appropriate headers for the response.
 
132
    std::string generateHeader(std::string const& body);
 
133
 
 
134
 
 
135
    
 
136
    //! Whether the introspection API is supported by this server
 
137
    bool _introspectionEnabled;
 
138
 
 
139
    //! Event dispatcher
 
140
    XmlRpcDispatch _disp;
 
141
 
 
142
    //! Collection of methods. This could be a set keyed on method name if we wanted...
 
143
    typedef std::map< std::string, XmlRpcServerMethod* > MethodMap;
 
144
 
 
145
    //! Registered RPC methods.
 
146
    MethodMap _methods;
 
147
 
 
148
    //! List all registered RPC methods (only available if introspection is enabled)
 
149
    XmlRpcServerMethod* _listMethods;
 
150
 
 
151
    //! Return help string for a specified method (only available if introspection is enabled)
 
152
    XmlRpcServerMethod* _methodHelp;
 
153
 
 
154
  };
 
155
} // namespace XmlRpc
 
156
 
 
157
#endif //_XMLRPCSERVER_H_