void JsonRPCServerModule::invoke(const string& method, const AmArg& args, AmArg& ret) { if (method == "execRpc"){ // todo: add connection id args.assertArrayFmt("sssisis"); // evq_link, notificationReceiver, requestReceiver, // flags(i), host, port (i), method, [params] if (args.size() > 7) { if (!isArgArray(args.get(7)) && !isArgStruct(args.get(7))) { ERROR("internal error: params to JSON-RPC must be struct or array\n"); throw AmArg::TypeMismatchException(); } } execRpc(args, ret); // sendRequestList(args, ret); } else if (method == "sendMessage"){ args.assertArrayFmt("sisss"); // conn_id, type, method, id, reply_sink, [params] if (args.size() > 5) { if (!isArgArray(args.get(5)) && !isArgStruct(args.get(5))) { ERROR("internal error: params to JSON-RPC must be struct or array\n"); throw AmArg::TypeMismatchException(); } } sendMessage(args, ret); } else if (method == "execServerFunction"){ args.assertArrayFmt("ss"); // method, id, params JsonRpcServer::execRpc(args.get(0).asCStr(), args.get(1).asCStr(), args.get(2), ret); // JsonRpcServer::execRpc(args, ret); } else if (method == "getServerPort"){ ret.push(port); } else if(method == "_list"){ ret.push(AmArg("execRpc")); ret.push(AmArg("sendMessage")); ret.push(AmArg("getServerPort")); ret.push(AmArg("execServerFunction")); // ret.push(AmArg("newConnection")); // ret.push(AmArg("sendRequest")); // ret.push(AmArg("sendRequestList")); } else throw AmDynInvoke::NotImplemented(method); }
void string2argarray(const string& key, const string& val, AmArg& res) { if (key.empty()) return; if (!(isArgStruct(res) || isArgUndef(res))) { WARN("array element [%s] is shadowed by value '%s'\n", key.c_str(), AmArg::print(res).c_str()); return; } size_t delim = key.find("."); if (delim == string::npos) { res[key]=val; return; } string2argarray(key.substr(delim+1), val, res[key.substr(0,delim)]); }