[yast-commit] r55174 - in /branches/tmp/lslezak/core/dbus/namespace_service: DBusModulesServer.cc DBusModulesServer.h modules_dbus_server.cc

Author: lslezak Date: Fri Jan 30 18:33:51 2009 New Revision: 55174 URL: http://svn.opensuse.org/viewcvs/yast?rev=55174&view=rev Log: - handle multiple namespaces in the service Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h branches/tmp/lslezak/core/dbus/namespace_service/modules_dbus_server.cc Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespac... ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc Fri Jan 30 18:33:51 2009 @@ -36,23 +36,31 @@ } } -DBusModulesServer::DBusModulesServer(const std::string &name_space) : e(this), wfm(NULL) +DBusModulesServer::DBusModulesServer(const NameSpaceList &name_spaces) : e(this), wfm(NULL) { init_wfm(); - Import import(name_space); // has an iternal static cache + for (NameSpaceList::const_iterator it = name_spaces.begin(); + it != name_spaces.end(); + ++it) + { + Import import(*it); // has an iternal static cache - ns = import.nameSpace(); + Y2Namespace *ns = import.nameSpace(); - if (ns == NULL) - { - y2error("Import name space %s failed", name_space.c_str()); - } - else - { - ns->initialize(); - y2milestone("Imported name space: %s", name_space.c_str()); + if (ns == NULL) + { + y2error("Import name space %s failed", it->c_str()); + } + else + { + ns->initialize(); + y2milestone("Imported name space: %s", it->c_str()); + + nsmap[*it] = ns; + } } + } DBusModulesServer::~DBusModulesServer() @@ -67,6 +75,12 @@ void DBusModulesServer::registerFunctions(const std::string &interface_prefix) { + for (NameSpaceMap::const_iterator it = nsmap.begin(); + it != nsmap.end(); + ++it) + { + Y2Namespace *ns = it->second; + if (ns) { unsigned symbols = ns->symbolCount(); @@ -136,6 +150,7 @@ index++; } } + } } std::string DBusModulesServer::Y2Dtype(constTypePtr type) const @@ -176,8 +191,10 @@ return ret; } -constTypePtr DBusModulesServer::searchFuncType(const std::string &fname) const +constTypePtr DBusModulesServer::searchFuncType(const std::string &objname, const std::string &fname) const { + Y2Namespace *ns = nsmap.find(objname)->second; + if (ns) { unsigned symbols = ns->symbolCount(); @@ -221,8 +238,17 @@ DBusMsg reply; std::string method = request.method(); + std::string object = request.path(); - constTypePtr t = searchFuncType(method); + // remove the leading slash from the object name + if (!object.empty() && object[0] == '/') + { + object.erase(object.begin()); + } + + y2debug("Requested object: %s, method: %s", object.c_str(), method.c_str()); + + constTypePtr t = searchFuncType(object, method); if (t) { @@ -231,28 +257,34 @@ if (request.arguments() == reqarg) { - // create function call - Y2Function *y2func = ns->createFunctionCall(method.c_str(), t); + // TODO improve it, Y2Namespace was already found in searchFuncType() + Y2Namespace *ns = nsmap[object]; - if (y2func) + if (ns) { - int index = 0; + // create function call + Y2Function *y2func = ns->createFunctionCall(method.c_str(), t); - while(index < reqarg) + if (y2func) { - YCPValue arg = request.getYCPValue(index); - y2func->appendParameter(arg); - index ++; - } + int index = 0; - if (y2func->finishParameters()) - { - // call the function - ret = y2func->evaluateCall(); - } - else - { - y2error("Wrong parameters to function %s", method.c_str()); + while(index < reqarg) + { + YCPValue arg = request.getYCPValue(index); + y2func->appendParameter(arg); + index ++; + } + + if (y2func->finishParameters()) + { + // call the function + ret = y2func->evaluateCall(); + } + else + { + y2error("Wrong parameters to function %s", method.c_str()); + } } } } Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespac... ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h Fri Jan 30 18:33:51 2009 @@ -15,6 +15,7 @@ #include <y2/Y2Component.h> #include <functional> +#include <list> class Y2Namespace; @@ -22,7 +23,9 @@ { public: - DBusModulesServer(const std::string &name_space); + typedef std::list<std::string> NameSpaceList; + + DBusModulesServer(const NameSpaceList &name_spaces); virtual ~DBusModulesServer(); virtual bool connect(); @@ -30,10 +33,11 @@ private: - // the wrapped Yast namespace - Y2Namespace *ns; + // the wrapped Yast namespaces + typedef std::map<const std::string, Y2Namespace *> NameSpaceMap; + NameSpaceMap nsmap; - constTypePtr searchFuncType(const std::string &fname) const; + constTypePtr searchFuncType(const std::string &objname, const std::string &fname) const; std::string Y2Dtype(constTypePtr type) const; // register the functions from the namespace to DBus service Modified: branches/tmp/lslezak/core/dbus/namespace_service/modules_dbus_server.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespac... ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/modules_dbus_server.cc (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/modules_dbus_server.cc Fri Jan 30 18:33:51 2009 @@ -18,44 +18,35 @@ bool forever = false; bool badopts = false; - std::string module; + DBusModulesServer::NameSpaceList modules; if (argc > 1) { - if (!strcmp(argv[1], "--disable-timer")) // like in packagekitd + + int index = 1; + + if (!strcmp(argv[index], "--disable-timer")) // like in packagekitd { forever = true; - - if (argc > 2) - { - module = argv[2]; - } - else - { - badopts = true; - } + ++index; } - else - { - module = argv[1]; - if (argc > 2) - badopts = true; + while(index < argc) + { + modules.push_back(argv[index]); + index++; } - - if (argc > 3) - badopts = true; } else badopts = true; - if (badopts) + if (badopts || modules.empty()) { - y2error ("Usage: %s [--disable-timer] <YCP_namespace>", argv[0]); - std::cerr << "Usage: " << argv[0] << " [--disable-timer] <YCP_namespace>" << std::endl; + y2error ("Usage: %s [--disable-timer] namespace <namespace> <namespace>....", argv[0]); + std::cerr << "Usage: " << argv[0] << " [--disable-timer] namespace <namespace> <namespace>..." << std::endl; return 1; } - DBusModulesServer server(module); + DBusModulesServer server(modules); bool connected = server.connect(); if (connected) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn.opensuse.org