source: sources/src/rpcXmlMethod.cc @ 1439:b23bfdd8a935

Revision 1439:b23bfdd8a935, 4.1 KB checked in by niam, 2 years ago (diff)

change contact info

Line 
1/***************************************************************************
2 *            rpcXmlMethod.cc
3 *
4 *  Wed Apr 09 2008
5 *  Copyright  2008  Dmytro Milinevskyy
6 *  milinevskyy@gmail.com
7 ****************************************************************************/
8
9/*
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU Lesser General Public License version 2.1 as published by
12 *  the Free Software Foundation;
13 *
14 *  This program is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU Library General Public License for more details.
18 *
19 *  You should have received a copy of the GNU Lesser General Public License
20 *  along with this program; if not, write to the Free Software
21 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24/**
25 * vim indentation settings
26 * set tabstop=4
27 * set shiftwidth=4
28 */
29
30#include <libdodo/directives.h>
31
32#include <libdodo/rpcXmlMethod.h>
33#include <libdodo/types.h>
34#include <libdodo/dataFormatXmlNode.h>
35#include <libdodo/toolsString.h>
36#include <libdodo/rpcMethod.h>
37#include <libdodo/rpcValue.h>
38#include <libdodo/rpcXmlValue.h>
39
40using namespace dodo::rpc::xml;
41
42const char method::trimSymbols[] = {
43    ' ',
44    '\r'
45};
46
47//-------------------------------------------------------------------
48
49dodo::rpc::method
50method::xmlToMethod(dodo::data::format::xml::node &node)
51{
52    rpc::method meth;
53
54    dodoMap<dodo::string, dodoArray<dodo::data::format::xml::node>, dodoMapStringCompare>::iterator i = node.nodeChildren.begin(), j = node.nodeChildren.end();
55    for (; i != j; ++i) {
56        if (tools::string::iequal(i->first, "methodName")) {
57            dodoArray<dodo::data::format::xml::node> &arr0 = i->second;
58            if (arr0.size() > 0)
59                meth.name = tools::string::trim(arr0[0].nodeValue, trimSymbols, 2);
60            else
61                meth.name = __dodostring__;
62        } else {
63            if (tools::string::iequal(i->first, "params")) {
64                dodoArray<dodo::data::format::xml::node> &arr0 = i->second;
65                if (arr0.size() == 0)
66                    return meth;
67
68                dodoArray<dodo::data::format::xml::node> &nodeArray = arr0[0].nodeChildren["param"];
69
70                dodoArray<dodo::data::format::xml::node>::iterator o = nodeArray.begin(), p = nodeArray.end();
71                for (; o != p; ++o) {
72                    dodoArray<dodo::data::format::xml::node> &arr1 = o->nodeChildren["value"];
73                    if (arr0.size() > 0)
74                        meth.arguments.push_back(value::xmlToValue(arr1[0]));
75                }
76            }
77        }
78    }
79
80    return meth;
81}
82
83//-------------------------------------------------------------------
84
85dodo::data::format::xml::node
86method::methodToXml(const rpc::method &data)
87{
88    dodoArray<dodo::data::format::xml::node> nodeArr;
89
90    dodo::data::format::xml::node meth;
91    meth.name = "methodCall";
92
93    dodo::data::format::xml::node methodName;
94    methodName.name = "methodName";
95    methodName.nodeValue = data.name;
96
97    nodeArr.assign(1, methodName);
98    meth.nodeChildren.insert(std::make_pair(methodName.name, nodeArr));
99
100    dodoArray<rpc::value>::const_iterator i = data.arguments.begin(), j = data.arguments.end();
101    if (i != j) {
102        dodo::data::format::xml::node params;
103        params.name = "params";
104
105        dodo::data::format::xml::node param;
106        param.name = "param";
107
108        dodoArray<dodo::data::format::xml::node> subNodeArr;
109
110        for (; i != j; ++i) {
111            param.nodeChildren.clear();
112
113            nodeArr.assign(1, value::valueToXml(*i));
114            param.nodeChildren.insert(std::make_pair("value", nodeArr));
115
116            subNodeArr.push_back(param);
117        }
118        params.nodeChildren.insert(std::make_pair("param", subNodeArr));
119
120        nodeArr.assign(1, params);
121        meth.nodeChildren.insert(std::make_pair(params.name, nodeArr));
122    }
123
124    return meth;
125}
126
127//-------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.