initial load of upstream version 1.06.32
[xmlrpc-c] / include / xmlrpc-c / client.hpp
1 #ifndef CLIENT_HPP_INCLUDED
2 #define CLIENT_HPP_INCLUDED
3
4 #include <string>
5 #include <vector>
6 #include <memory>
7
8 #include <xmlrpc-c/girerr.hpp>
9 #include <xmlrpc-c/girmem.hpp>
10 #include <xmlrpc-c/base.hpp>
11 #include <xmlrpc-c/timeout.hpp>
12 #include <xmlrpc-c/client_transport.hpp>
13
14 namespace xmlrpc_c {
15
16 class clientTransactionPtr;
17
18 class clientTransaction : public girmem::autoObject {
19
20     friend class clientTransactionPtr;
21
22 public:
23     virtual void
24     finish(xmlrpc_c::rpcOutcome const& outcome) = 0;
25     
26     virtual void
27     finishErr(girerr::error const& error) = 0;
28
29 protected:
30     clientTransaction();
31 };
32
33 class clientTransactionPtr : public girmem::autoObjectPtr {
34     
35 public:
36     clientTransactionPtr();
37
38     virtual ~clientTransactionPtr();
39
40     virtual xmlrpc_c::clientTransaction *
41     operator->() const;
42 };
43
44 class clientPtr;
45
46 class client : public girmem::autoObject {
47 /*----------------------------------------------------------------------------
48    A generic client -- a means of performing an RPC.  This is so generic
49    that it can be used for clients that are not XML-RPC.
50
51    This is a base class.  Derived classes define things such as that
52    XML and HTTP get used to perform the RPC.
53 -----------------------------------------------------------------------------*/
54     friend class clientTransactionPtr;
55
56 public:
57     virtual ~client();
58
59     virtual void
60     call(xmlrpc_c::carriageParm * const  carriageParmP,
61          std::string              const& methodName,
62          xmlrpc_c::paramList      const& paramList,
63          xmlrpc_c::rpcOutcome *   const  outcomeP) = 0;
64
65     virtual void
66     start(xmlrpc_c::carriageParm *       const  carriageParmP,
67           std::string                    const& methodName,
68           xmlrpc_c::paramList            const& paramList,
69           xmlrpc_c::clientTransactionPtr const& tranP);
70 };
71
72 class clientPtr : public girmem::autoObjectPtr {
73 public:
74     clientPtr();
75
76     explicit clientPtr(xmlrpc_c::client * const clientP);
77
78     xmlrpc_c::client *
79     operator->() const;
80
81     xmlrpc_c::client *
82     get() const;
83 };
84
85 class serverAccessor : public girmem::autoObject {
86     
87 public:
88     serverAccessor(xmlrpc_c::clientPtr       const clientP,
89                    xmlrpc_c::carriageParmPtr const carriageParmP);
90
91     void
92     call(std::string            const& methodName,
93          xmlrpc_c::paramList    const& paramList,
94          xmlrpc_c::rpcOutcome * const  outcomeP) const;
95
96 private:
97     xmlrpc_c::clientPtr       const clientP;
98     xmlrpc_c::carriageParmPtr const carriageParmP;
99 };
100
101 class serverAccessorPtr : public girmem::autoObjectPtr {
102 public:
103     serverAccessorPtr();
104
105     explicit
106     serverAccessorPtr(xmlrpc_c::serverAccessor * const serverAccessorP);
107
108     xmlrpc_c::serverAccessor *
109     operator->() const;
110
111     xmlrpc_c::serverAccessor *
112     get() const;
113 };
114
115 class connection {
116 /*----------------------------------------------------------------------------
117    A nexus of a particular client and a particular server, along with
118    carriage parameters for performing RPCs between the two.
119
120    This is a minor convenience for client programs that always talk to
121    the same server the same way.
122
123    Use this as a parameter to rpc.call().
124 -----------------------------------------------------------------------------*/
125 public:
126     connection(xmlrpc_c::client *       const clientP,
127                xmlrpc_c::carriageParm * const carriageParmP);
128
129     ~connection();
130
131     xmlrpc_c::client *       clientP;
132     xmlrpc_c::carriageParm * carriageParmP;
133 };
134
135 class client_xml : public xmlrpc_c::client {
136 /*----------------------------------------------------------------------------
137    A client that uses XML-RPC XML in the RPC.  This class does not define
138    how the XML gets transported, though (i.e. does not require HTTP).
139 -----------------------------------------------------------------------------*/
140 public:
141     client_xml(xmlrpc_c::clientXmlTransport * const transportP);
142
143     client_xml(xmlrpc_c::clientXmlTransportPtr const transportP);
144
145     void
146     call(carriageParm *         const  carriageParmP,
147          std::string            const& methodName,
148          xmlrpc_c::paramList    const& paramList,
149          xmlrpc_c::rpcOutcome * const  outcomeP);
150
151     void
152     start(xmlrpc_c::carriageParm *       const  carriageParmP,
153           std::string                    const& methodName,
154           xmlrpc_c::paramList            const& paramList,
155           xmlrpc_c::clientTransactionPtr const& tranP);
156
157     void
158     finishAsync(xmlrpc_c::timeout const timeout);
159
160 private:
161     /* We have both kinds of pointers to give the user flexibility -- we
162        have constructors that take both.  But the simple pointer
163        'transportP' is valid in both cases.
164     */
165     xmlrpc_c::clientXmlTransport * transportP;
166     xmlrpc_c::clientXmlTransportPtr transportPtr;
167 };
168
169 class xmlTransaction_client : public xmlrpc_c::xmlTransaction {
170
171 public:
172     xmlTransaction_client(xmlrpc_c::clientTransactionPtr const& tranP);
173
174     void
175     finish(std::string const& responseXml) const;
176
177     void
178     finishErr(girerr::error const& error) const;
179 private:
180     xmlrpc_c::clientTransactionPtr const tranP;
181 };
182
183 class xmlTransaction_clientPtr : public xmlTransactionPtr {
184 public:
185     xmlTransaction_clientPtr();
186     
187     xmlTransaction_clientPtr(xmlrpc_c::clientTransactionPtr const& tranP);
188
189     xmlrpc_c::xmlTransaction_client *
190     operator->() const;
191 };
192
193 class rpcPtr;
194
195 class rpc : public clientTransaction {
196 /*----------------------------------------------------------------------------
197    An RPC.  An RPC consists of method name, parameters, and result.  It
198    does not specify in any way how the method name and parameters get
199    turned into a result.  It does not presume XML or HTTP.
200
201    You don't create an object of this class directly.  All references to
202    an rpc object should be by an rpcPtr object.  Create a new RPC by
203    creating a new rpcPtr.  Accordingly, our constructors and destructors
204    are protected, but available to our friend class rpcPtr.
205
206    In order to do asynchronous RPCs, you normally have to create a derived
207    class that defines a useful notifyComplete().  If you do that, you'll
208    want to make sure the derived class objects get accessed only via rpcPtrs
209    as well.
210 -----------------------------------------------------------------------------*/
211     friend class xmlrpc_c::rpcPtr;
212
213 public:
214     void
215     call(xmlrpc_c::client       * const clientP,
216          xmlrpc_c::carriageParm * const carriageParmP);
217
218     void
219     call(xmlrpc_c::connection const& connection);
220
221     void
222     start(xmlrpc_c::client       * const clientP,
223           xmlrpc_c::carriageParm * const carriageParmP);
224     
225     void
226     start(xmlrpc_c::connection const& connection);
227     
228     void
229     finish(xmlrpc_c::rpcOutcome const& outcome);
230
231     void
232     finishErr(girerr::error const& error);
233
234     virtual void
235     notifyComplete();
236
237     bool
238     isFinished() const;
239
240     bool
241     isSuccessful() const;
242
243     xmlrpc_c::value
244     getResult() const;
245
246     xmlrpc_c::fault
247     getFault() const;
248
249     rpc(std::string         const  methodName,
250         xmlrpc_c::paramList const& paramList);
251
252     virtual ~rpc();
253
254 private:
255     enum state {
256         STATE_UNFINISHED,  // RPC is running or not started yet
257         STATE_ERROR,       // We couldn't execute the RPC
258         STATE_FAILED,      // RPC executed successfully, but failed per XML-RPC
259         STATE_SUCCEEDED    // RPC is done, no exception
260     };
261     enum state state;
262     girerr::error * errorP;     // Defined only in STATE_ERROR
263     xmlrpc_c::rpcOutcome outcome;
264         // Defined only in STATE_FAILED and STATE_SUCCEEDED
265     std::string methodName;
266     xmlrpc_c::paramList paramList;
267 };
268
269 class rpcPtr : public clientTransactionPtr {
270 public:
271     rpcPtr();
272
273     explicit rpcPtr(xmlrpc_c::rpc * const rpcP);
274
275     rpcPtr(std::string         const  methodName,
276            xmlrpc_c::paramList const& paramList);
277
278     xmlrpc_c::rpc *
279     operator->() const;
280 };
281
282 } // namespace
283 #endif