1 /***************************************************************************
2                  ulxr_response.cpp  -  create xml-rpc response
3                              -------------------
4     begin                : Sun Mar 10 2002
5     copyright            : (C) 2002-2007 by Ewald Arnold
6     email                : ulxmlrpcpp@ewald-arnold.de
7 
8     $Id: ulxr_response.h 940 2006-12-30 18:22:05Z ewald-arnold $
9 
10  ***************************************************************************/
11 
12 /**************************************************************************
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License as
16  * published by the Free Software Foundation; either version 2 of the License,
17  * or (at your option) any later version.
18  *
19  * This program 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
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  *
28  ***************************************************************************/
29 
30 #ifndef ULXR_RESPONSE_H
31 #define ULXR_RESPONSE_H
32 
33 
34 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
35 #include <ulxmlrpcpp/ulxr_value.h>
36 
37 
38 namespace ulxr {
39 
40 class Void;
41 
42 
43 /** Abstraction of a response from a remote server.
44   * You should take care to interpret the data correctly as XML-RPC
45   * distinguishes between "normal" return values from the remote method
46   * and error messages that indicate problems while transporting and
47   * invoking the call.
48   * @ingroup grp_ulxr_rpc
49   */
50 class ULXR_API_DECL0 MethodResponse
51 {
52  public:
53 
54  /** Default constructor for an empty response.
55    */
56    explicit MethodResponse();
57 
58  /** Destroys the method response.
59    */
60    virtual ~MethodResponse();
61 
62  /** Constructs a "fault reponse" to indicate RPC problems.
63    * The number and string are system dependent.
64    * @param  fval   error code
65    * @param  fstr   human readable desciption of the error
66    */
67    MethodResponse(int fval, const CppString &fstr);
68 
69  /** Constructs a return value from the remote method.
70    * the value can be of any type. To return more than one
71    * Value at once use an array or a Struct.
72    * @param  val   the return value.
73    */
74    MethodResponse (const Value &val);
75 
76  /** Constructs an empty return value from the remote method.
77    * Only exists for completeness and yields the same as the default constructor.
78    * @param  val   the return value.
79    */
80    MethodResponse (const Void &val);
81 
82  /** Returns the signature of this call.
83    * The signature consists of all type names in this call delimited by
84    * commas. Elements of arrays are surrounded by braces. Structure elements
85    * and element pairs of structs are grouped by curly braces.
86    *
87    * Example:
88    * <pre>
89    *  Array:  [int,double,string]
90    *  Struct: {{first,int},{second,double}}
91    * </pre>
92    *
93    * @param deep  if nested types exist, include them
94    * @return  The signature
95    */
96    virtual CppString getSignature(bool deep = false) const;
97 
98  /** Returns the call as binary xml string.
99    * The method call is converted to a wbxml sequence. It is prepended with
100    * the necessary xml procession instruction with version and encoding
101    * set to UTF-8.
102    * @return  The wbxml content
103    */
104    virtual std::string getWbXml() const;
105 
106  /** Returns the call as xml string.
107    * The method cal is converted to an xml text. It is prepended with
108    * the necessary xml procession instruction with version and encoding
109    * set to UTF-8. The structure of the text is indented to facilitate
110    * easy reading.
111    * @param  indent   current indentation level
112    * @return  The xml conentent
113    */
114    virtual CppString getXml(int indent = 0) const;
115 
116  /** Constructs a "fault reponse" to indicate RPC problems.
117    * The number and string are system dependent.
118    * @param  fval   error code
119    * @param  fstr   human readable desciption of the error
120    */
121    void setFault(int fval, const CppString &fstr);
122 
123  /** Sets the return value from the remote method.
124    * The value can be of any type. To return more than one
125    * Value at once use an Array or a Struct.
126    * @param  val   the return value.
127    */
128    void setResult (const Value &val);
129 
130  /** Gets the return value from the remote method.
131    * The value can be of any type, even an Array or a Struct.
132    * If the response is faulty, is contains a Struct with two elements:
133    *  @li  an int named "faultCode"
134    *  @li  a string with name "faultString"
135    * @return the return value.
136    */
137    const Value& getResult() const;
138 
139  /** Tests the method response state.
140    * @return  true if RPC processing went OK.
141    */
142    bool isOK() const;
143 
144  private:
145 
146    bool   wasOk;
147    Value  respval;
148 };
149 
150 
151 }  // namespace ulxr
152 
153 #endif // ULXR_RESPONSE_H
154