initial load of upstream version 1.06.32
[xmlrpc-c] / include / xmlrpc-c / registry.hpp
1 #ifndef REGISTRY_HPP_INCLUDED
2 #define REGISTRY_HPP_INCLUDED
3
4 #include <string>
5 #include <vector>
6 #include <list>
7
8 #include <xmlrpc-c/server.h>
9 #include <xmlrpc-c/girmem.hpp>
10 #include <xmlrpc-c/base.hpp>
11
12 namespace xmlrpc_c {
13
14
15 class method : public girmem::autoObject {
16 /*----------------------------------------------------------------------------
17    An XML-RPC method.
18
19    This base class is abstract.  You can't create an object in it.
20    Define a useful method with this as a base class, with an
21    execute() method.
22 -----------------------------------------------------------------------------*/
23 public:
24     method();
25
26     virtual ~method();
27
28     virtual void
29     execute(xmlrpc_c::paramList const& paramList,
30             xmlrpc_c::value *   const  resultP) = 0;
31
32     std::string signature() const { return _signature; };
33     std::string help() const { return _help; };
34
35 protected:
36     std::string _signature;
37     std::string _help;
38 };
39
40 /* Example of a specific method class:
41
42    class sample_add : public xmlrpc_c::method {
43    public:
44        sample_add() {
45            this->_signature = "ii";
46            this->_help = "This method adds two integers together";
47        }
48        void
49        execute(xmlrpc_c::param_list    const paramList,
50                const xmlrpc_c::value * const retvalP) {
51           
52            int const addend(paramList.getInt(0));
53            int const adder(paramList.getInt(1));
54
55            *retvalP = xmlrpc_c::value(addend, adder);
56       }
57    };
58
59
60    Example of creating such a method:
61
62    methodPtr const sampleAddMethodP(new sample_add);
63
64    You pass around, copy, etc. the handle sampleAddMethodP and when
65    the last copy of the handle is gone, the sample_add object itself
66    gets deleted.
67
68 */
69
70
71 class methodPtr : public girmem::autoObjectPtr {
72
73 public:
74     methodPtr(xmlrpc_c::method * const methodP);
75
76     xmlrpc_c::method *
77     operator->() const;
78 };
79
80 class defaultMethod : public girmem::autoObject {
81
82 public:
83     virtual ~defaultMethod();
84
85     virtual void
86     execute(std::string         const& methodName,
87             xmlrpc_c::paramList const& paramList,
88             xmlrpc_c::value *   const  resultP) = 0;
89 };
90
91 class defaultMethodPtr : public girmem::autoObjectPtr {
92
93 public:
94     defaultMethodPtr();
95
96     defaultMethodPtr(xmlrpc_c::defaultMethod * const methodP);
97
98     xmlrpc_c::defaultMethod *
99     operator->() const;
100
101     xmlrpc_c::defaultMethod *
102     get() const;
103 };
104
105 class registry : public girmem::autoObject {
106 /*----------------------------------------------------------------------------
107    An Xmlrpc-c server method registry.  An Xmlrpc-c server transport
108    (e.g.  an HTTP server) uses this object to process an incoming
109    Xmlrpc-c call.
110 -----------------------------------------------------------------------------*/
111
112 public:
113
114     registry();
115     ~registry();
116
117     void
118     addMethod(std::string         const name,
119               xmlrpc_c::methodPtr const methodP);
120
121     void
122     setDefaultMethod(xmlrpc_c::defaultMethodPtr const methodP);
123
124     void
125     disableIntrospection();
126     
127     void
128     processCall(std::string   const& body,
129                 std::string * const  responseP) const;
130
131     xmlrpc_registry *
132     c_registry() const;
133         /* This is meant to be private except to other objects in the
134            Xmlrpc-c library.
135         */
136
137 private:
138
139     xmlrpc_registry * c_registryP;
140         /* Pointer to the C registry object we use to implement this
141            object.
142         */
143
144     std::list<xmlrpc_c::methodPtr> methodList;
145         /* This is a list of all the method objects (actually, pointers
146            to them).  But since the real registry is the C registry object,
147            all this list is for is to maintain references to the objects
148            to which the C registry points so that they continue to exist.
149         */
150     xmlrpc_c::defaultMethodPtr defaultMethodP;
151         /* The real identifier of the default method is the C registry
152            object; this member exists only to maintain a reference to the
153            object to which the C registry points so that it will continue
154            to exist.
155         */
156 };
157
158
159 class registryPtr : public girmem::autoObjectPtr {
160
161 public:
162     registryPtr();
163
164     registryPtr(xmlrpc_c::registry * const registryP);
165
166     xmlrpc_c::registry *
167     operator->() const;
168
169     xmlrpc_c::registry *
170     get() const;
171 };
172
173 } // namespace
174
175 #endif