00001 /*************************************************************************** 00002 ulxr_call.h - create xml-rpc calling data 00003 ------------------- 00004 begin : Sun Mar 10 2002 00005 copyright : (C) 2002-2007 by Ewald Arnold 00006 email : ulxmlrpcpp@ewald-arnold.de 00007 00008 $Id: ulxr_call.cpp 1026 2007-07-25 07:48:09Z ewald-arnold $ 00009 00010 ***************************************************************************/ 00011 00012 /************************************************************************** 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU Lesser General Public License as 00016 * published by the Free Software Foundation; either version 2 of the License, 00017 * or (at your option) any later version. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program; if not, write to the Free Software 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 * 00028 ***************************************************************************/ 00029 00030 //#define ULXR_SHOW_TRACE 00031 //#define ULXR_DEBUG_OUTPUT 00032 //#define ULXR_SHOW_READ 00033 //#define ULXR_SHOW_WRITE 00034 00035 #define ULXR_NEED_EXPORTS 00036 #include <ulxmlrpcpp/ulxmlrpcpp.h> // always first header 00037 00038 #include <ulxmlrpcpp/ulxr_call.h> 00039 #include <ulxmlrpcpp/ulxr_except.h> 00040 #include <ulxmlrpcpp/ulxr_callparse_wb.h> 00041 #include <ulxmlrpcpp/ulxr_wbxmlparse.h> 00042 00043 00044 namespace ulxr { 00045 00046 00047 ULXR_API_IMPL0 MethodCall::MethodCall(const ulxr::Char *name) 00048 { 00049 methodname = name; 00050 } 00051 00052 00053 ULXR_API_IMPL0 MethodCall::MethodCall() 00054 { 00055 } 00056 00057 00058 ULXR_API_IMPL0 MethodCall::~MethodCall() 00059 { 00060 } 00061 00062 00063 ULXR_API_IMPL0 MethodCall::MethodCall(const CppString &name) 00064 { 00065 methodname = name; 00066 } 00067 00068 00069 MethodCall& /*ULXR_API_IMPL0*/ MethodCall::addParam (const Value &val) 00070 { 00071 params.push_back(val); 00072 return *this; 00073 } 00074 00075 00076 MethodCall& /*ULXR_API_IMPL0*/ MethodCall::setParam (const Value &val) 00077 { 00078 clear(); 00079 return addParam(val); 00080 } 00081 00082 00083 ULXR_API_IMPL(CppString) MethodCall::getSignature(bool name_braces) const 00084 { 00085 CppString s; 00086 if (name_braces) 00087 s += methodname + ULXR_PCHAR("("); 00088 00089 bool comma = params.size() >= 1; 00090 for (unsigned i = 0; i < params.size(); ++i) { 00091 if (comma && i != 0) 00092 s += ','; 00093 s += params[i].getSignature(); 00094 } 00095 00096 if (name_braces) 00097 s += ULXR_PCHAR(")"); 00098 return s; 00099 } 00100 00101 00102 ULXR_API_IMPL(CppString) MethodCall::getXml(int indent) const 00103 { 00104 CppString ind = getXmlIndent(indent); 00105 CppString ind1 = getXmlIndent(indent+1); 00106 CppString ind2 = getXmlIndent(indent+2); 00107 CppString s = ULXR_PCHAR("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + getXmlLinefeed(); 00108 s += ind + ULXR_PCHAR("<methodCall>") + getXmlLinefeed(); 00109 s += ind1 + ULXR_PCHAR("<methodName>")+methodname+ULXR_PCHAR("</methodName>") + getXmlLinefeed(); 00110 00111 s += ind1 + ULXR_PCHAR("<params>") + getXmlLinefeed(); 00112 00113 for (std::vector<Value>::const_iterator 00114 it = params.begin(); it != params.end(); ++it) 00115 { 00116 s += ind2 + ULXR_PCHAR("<param>") + getXmlLinefeed(); 00117 s += (*it).getXml(indent+3) + getXmlLinefeed(); 00118 s += ind2 + ULXR_PCHAR("</param>") + getXmlLinefeed(); 00119 } 00120 00121 s += ind1 + ULXR_PCHAR("</params>") + getXmlLinefeed(); 00122 s += ind + ULXR_PCHAR("</methodCall>"); 00123 return s; 00124 } 00125 00126 00127 ULXR_API_IMPL(std::string) MethodCall::getWbXml() const 00128 { 00129 std::string s; 00130 s.assign(WbXmlParser::wbxml_START_SEQ_STR, WbXmlParser::wbxml_START_SEQ_LEN); 00131 s += MethodCallParserWb::wbToken_MethodCall; 00132 s += MethodCallParserWb::wbToken_MethodName; 00133 s += getWbXmlString(methodname); 00134 s += WbXmlParser::wbxml_END; 00135 00136 s += MethodCallParserWb::wbToken_Params; 00137 00138 for (std::vector<Value>::const_iterator 00139 it = params.begin(); it != params.end(); ++it) 00140 { 00141 s += MethodCallParserWb::wbToken_Param; 00142 s += (*it).getWbXml(); 00143 s += WbXmlParser::wbxml_END; 00144 } 00145 00146 s += WbXmlParser::wbxml_END; 00147 s += WbXmlParser::wbxml_END; 00148 return s; 00149 } 00150 00151 00152 ULXR_API_IMPL(Value) MethodCall::getParam(unsigned ind) const 00153 { 00154 if (ind < params.size() ) 00155 return params[ind]; 00156 00157 throw ParameterException(InvalidMethodParameterError, 00158 ulxr_i18n(ULXR_PCHAR("Not enough actual parameters for call to method: ") 00159 +getSignature())); 00160 } 00161 00162 ULXR_API_IMPL(unsigned) MethodCall::numParams() const 00163 { 00164 return params.size(); 00165 } 00166 00167 00168 ULXR_API_IMPL(void) MethodCall::clear() 00169 { 00170 params.clear(); 00171 } 00172 00173 00174 ULXR_API_IMPL(CppString) MethodCall::getMethodName() const 00175 { 00176 return methodname; 00177 } 00178 00179 00180 ULXR_API_IMPL(void) MethodCall::setMethodName(const CppString &nm) 00181 { 00182 methodname = nm; 00183 } 00184 00185 00186 } // namespace ulxr 00187