Author: sayer
Date: 2008-10-14 21:26:38 +0200 (Tue, 14 Oct 2008)
New Revision: 1112
Modified:
trunk/apps/xmlrpc2di/Makefile
trunk/apps/xmlrpc2di/XMLRPC2DI.cpp
trunk/apps/xmlrpc2di/XMLRPC2DI.h
Log:
function to send XMLRPC request which takes args as list (mainly for simplicity
in DSM)
Modified: trunk/apps/xmlrpc2di/Makefile
===================================================================
--- trunk/apps/xmlrpc2di/Makefile 2008-10-14 19:06:17 UTC (rev 1111)
+++ trunk/apps/xmlrpc2di/Makefile 2008-10-14 19:26:38 UTC (rev 1112)
@@ -3,7 +3,7 @@
plug_in_name = xmlrpc2di
module_ldflags = -lxmlrpc++
-module_cflags =
+module_cflags = -DHAVE_XMLRPCPP_SSL
# for gentoo ebuild or cvs-20040713 version:
# module_cflags = -DHAVE_XMLRPCPP_SSL
#
Modified: trunk/apps/xmlrpc2di/XMLRPC2DI.cpp
===================================================================
--- trunk/apps/xmlrpc2di/XMLRPC2DI.cpp 2008-10-14 19:06:17 UTC (rev 1111)
+++ trunk/apps/xmlrpc2di/XMLRPC2DI.cpp 2008-10-14 19:26:38 UTC (rev 1112)
@@ -228,6 +228,47 @@
}
}
+void XMLRPC2DI::sendRequestList(const AmArg& args, AmArg& ret) {
+ string app_name = args.get(0).asCStr();
+ string method = args.get(1).asCStr();
+
+ while (true) {
+ XMLRPCServerEntry* srv = getServer(app_name);
+ if (NULL == srv) {
+ ret.push(-1);
+ ret.push("no active connections");
+ return;
+ }
+ XmlRpcClient c((const char*)srv->server.c_str(), (int)srv->port,
+ (const char*)srv->uri.empty()?NULL:srv->uri.c_str()
+#ifdef HAVE_XMLRPCPP_SSL
+ , false
+#endif
+ );
+
+ XmlRpcValue x_args, x_result;
+
+ x_args.setSize(args.size()-2);
+ for (size_t i=2;i<args.size();i++) {
+ XMLRPC2DIServer::amarg2xmlrpcval(args.get(i), x_args[i]);
+ }
+
+ if (c.execute(method.c_str(), x_args, x_result) && !c.isFault()) {
+ DBG("successfully executed method %s on server %s:%d\n",
+ method.c_str(), srv->server.c_str(), srv->port);
+ ret.push(0);
+ ret.push("OK");
+// ret.assertArray(3);
+ XMLRPC2DIServer::xmlrpcval2amarg(x_result, ret, 0);
+ return;
+ } else {
+ DBG("executing method %s failed on server %s:%d\n",
+ method.c_str(), srv->server.c_str(), srv->port);
+ srv->set_failed();
+ }
+ }
+}
+
void XMLRPC2DI::invoke(const string& method,
const AmArg& args, AmArg& ret) {
@@ -237,9 +278,13 @@
} else if(method == "sendRequest"){
args.assertArrayFmt("ssa"); // app, method, args
sendRequest(args, ret);
+ } else if(method == "sendRequestList"){
+ args.assertArrayFmt("ss"); // app, method, ...
+ sendRequestList(args, ret);
} else if(method == "_list"){
ret.push(AmArg("newConnection"));
ret.push(AmArg("sendRequest"));
+ ret.push(AmArg("sendRequestList"));
} else
throw AmDynInvoke::NotImplemented(method);
@@ -429,7 +474,15 @@
a[a.size()-1].assertArray(0);
AmArg arr;
xmlrpcval2amarg(v[i], a[a.size()-1], 0);
+ } break;
+ case XmlRpcValue::TypeStruct: {
+ for (XmlRpc::XmlRpcValue::ValueStruct::iterator it=
+ ((XmlRpcValue::ValueStruct)v).begin(); it !=
((XmlRpcValue::ValueStruct)v).end(); it++) {
+ a[it->first] = AmArg();
+ xmlrpcval2amarg(it->second, a[it->first], 0);
+ }
} break;
+
// TODO: support more types (datetime, struct, ...)
default: throw XmlRpcException("unsupported parameter type", 400);
};
Modified: trunk/apps/xmlrpc2di/XMLRPC2DI.h
===================================================================
--- trunk/apps/xmlrpc2di/XMLRPC2DI.h 2008-10-14 19:06:17 UTC (rev 1111)
+++ trunk/apps/xmlrpc2di/XMLRPC2DI.h 2008-10-14 19:26:38 UTC (rev 1112)
@@ -142,6 +142,7 @@
void newConnection(const AmArg& args, AmArg& ret);
void sendRequest(const AmArg& args, AmArg& ret);
+ void sendRequestList(const AmArg& args, AmArg& ret);
public:
XMLRPC2DI(const string& mod_name);
~XMLRPC2DI() { }
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev