Author: lslezak Date: Fri Feb 27 10:56:56 2009 New Revision: 55809
URL: http://svn.opensuse.org/viewcvs/yast?rev=55809&view=rev Log: - DBus service - use /org/opensuse/YaST/modules object prefix
Modified: branches/tmp/lslezak/core/configure.in.in branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc
Modified: branches/tmp/lslezak/core/configure.in.in URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/configure.in.... ============================================================================== --- branches/tmp/lslezak/core/configure.in.in (original) +++ branches/tmp/lslezak/core/configure.in.in Fri Feb 27 10:56:56 2009 @@ -144,6 +144,8 @@ AC_SUBST(YAST_DBUS_YCP_INTERFACE) YAST_DBUS_MGR_INTERFACE=org.opensuse.YaST.modules.ModuleManager AC_SUBST(YAST_DBUS_MGR_INTERFACE) +YAST_DBUS_OBJ_PREFIX=/org/opensuse/YaST/modules +AC_SUBST(YAST_DBUS_OBJ_PREFIX)
YAST_POLKIT_PREFIX_MANAGER=org.opensuse.yast.module-manager AC_SUBST(YAST_POLKIT_PREFIX_MANAGER)
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 Feb 27 10:56:56 2009 @@ -135,11 +135,11 @@ { sig_raw.params = p_raw; // register the function: register_function(object, interface, method, signature, handler) - register_method(nspace, YAST_DBUS_RAW_INTERFACE, fname, sig_raw, e); + register_method(YAST_DBUS_OBJ_PREFIX"/" + nspace, YAST_DBUS_RAW_INTERFACE, fname, sig_raw, e); }
sig_marshalled.params = p_marshalled; - register_method(nspace, YAST_DBUS_YCP_INTERFACE, fname, sig_marshalled, e); + register_method(YAST_DBUS_OBJ_PREFIX"/" + nspace, YAST_DBUS_YCP_INTERFACE, fname, sig_marshalled, e);
return true; } @@ -221,12 +221,12 @@ sig.params = p;
// register the manager object: register_function(object, interface, method, signature, handler) - register_method("", YAST_DBUS_MGR_INTERFACE, YAST_DBUS_MANAGER_IMPORT_METHOD, sig, manager_callback); + register_method("/", YAST_DBUS_MGR_INTERFACE, YAST_DBUS_MANAGER_IMPORT_METHOD, sig, manager_callback);
DBusSignature void_sig; // register the manager object: register_function(object, interface, method, signature, handler) - register_method("", YAST_DBUS_MGR_INTERFACE, YAST_DBUS_MANAGER_UNLOCK_METHOD, void_sig, manager_callback); - register_method("", YAST_DBUS_MGR_INTERFACE, YAST_DBUS_MANAGER_LOCK_METHOD, void_sig, manager_callback); + register_method("/", YAST_DBUS_MGR_INTERFACE, YAST_DBUS_MANAGER_UNLOCK_METHOD, void_sig, manager_callback); + register_method("/", YAST_DBUS_MGR_INTERFACE, YAST_DBUS_MANAGER_LOCK_METHOD, void_sig, manager_callback); }
std::string DBusModulesServer::Y2Dtype(constTypePtr type) const @@ -599,10 +599,18 @@ ? YAST_POLKIT_PREFIX_MANAGER : YAST_POLKIT_PREFIX_MODULES);
std::string obj(msg.path()); - + + // convert object path "/org/opensuse/yast/Label" to PolKit path "Label" if (!obj.empty()) { - if (obj[0] == '/') + if (obj[obj.size() - 1] == '/') + { + obj.erase(obj.end()); + } + + obj.erase(0, obj.rfind("/")); + + if (!obj.empty() && obj[0] == '/') { obj.erase(obj.begin()); } @@ -615,6 +623,7 @@
ret += '.' + msg.method();
+ // make it valid action ID (lowercase chars, replace invalid chars) if (!PolKit::isValidActionID(ret)) { ret = PolKit::makeValidActionID(ret);
Modified: branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespac... ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in Fri Feb 27 10:56:56 2009 @@ -9,6 +9,9 @@ // name of the Yast DBus service #define YAST_DBUS_SERVICE_NAME "@YAST_DBUS_SERVICE@"
+// object(path) prefix +#define YAST_DBUS_OBJ_PREFIX "@YAST_DBUS_OBJ_PREFIX@" + // interface name for marshalled YCPValues - using (bsv) DBus structure #define YAST_DBUS_YCP_INTERFACE "@YAST_DBUS_YCP_INTERFACE@" // interface name for raw (direct) DBus values
Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src... ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Fri Feb 27 10:56:56 2009 @@ -12,6 +12,8 @@
#include <ycp/y2log.h>
+#include <algorithm> + // timeout for reading a DBus message (in miliseconds) #define YAST_DBUS_TIMEOUT_VALUE 15000 // the count of timeout events before exiting @@ -164,12 +166,7 @@ if (request.isMethodCall(DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { y2milestone("Introspecting object: %s", request.path().c_str()); - std::string introspect; - - // root node? - if (request.path() == "/") - { - introspect = + std::string introspect( // introcpection data for the root node DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE "\n<node>\n" @@ -177,65 +174,65 @@ " <method name='Introspect'>\n" " <arg name='xml_data' type='s' direction='out'/>\n" " </method>\n" - " </interface>\n"; + " </interface>\n"); + + // add "static" methods (with empty object) + std::string requested_path(request.path()); + + std::liststd::string announced_objects;
- // add "static" methods (with empty object) + for(Objects::const_iterator i = registered_objects.begin(); + i != registered_objects.end(); + ++i) + { + std::string object(i->first);
- for(Objects::const_iterator i = registered_objects.begin(); - i != registered_objects.end(); - ++i) + // exact match or a subtree match? + if (object != requested_path) { - std::string object(i->first); + std::string obj_prefix(object, 0, requested_path.size());
- if (!object.empty()) + // subtree match + if (obj_prefix == requested_path) { - introspect += " <node name='" + object + "'/>\n"; - } - else - { - introspect += CreateObjectIntrospection(i->second); - } - } + y2debug("Object: %s, Requested path: %s, Prefix: %s", object.c_str(), + requested_path.c_str(), obj_prefix.c_str() + );
- // close the node section - introspect += "</node>\n"; - } - else - { - introspect = - // introcpection data for the root node - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE - "\n<node>\n" - " <interface name='"DBUS_INTERFACE_INTROSPECTABLE"'>\n" - " <method name='Introspect'>\n" - " <arg name='xml_data' type='s' direction='out'/>\n" - " </method>\n" - " </interface>\n"; + std::string sub_path(object, obj_prefix.size()); + if (sub_path.size() > 0 && sub_path[0] == '/') + { + sub_path.erase(sub_path.begin()); + }
- std::string objname = request.path(); + y2debug("sub_path: %s", sub_path.c_str());
- // remove the slash at the beginning - if (objname.size() > 0 && objname[0] == '/') - { - objname.erase(objname.begin()); - } + std::string node_name(sub_path, 0, sub_path.find("/")); + if (node_name.size() > 0 && node_name[0] == '/') + { + node_name.erase(node_name.begin()); + }
- // return properties of the registered object only - Objects::const_iterator i = registered_objects.find(objname); - - if (i == registered_objects.end()) - { - y2warning("Requested object %s is not registered", objname.c_str()); + y2debug("Using node name: %s", node_name.c_str()); + + // check if it has been already added + if (find(announced_objects.begin(), announced_objects.end(), node_name) + == announced_objects.end()) + { + introspect += " <node name='" + node_name + "'/>\n"; + announced_objects.push_back(node_name); + } + } } else { - ObjectData od = i->second; - introspect += CreateObjectIntrospection(od); + introspect += CreateObjectIntrospection(i->second); } - - introspect += " </node>\n"; }
+ // close the node section + introspect += "</node>\n"; + // create a reply to the request reply.createReply(request); reply.addString(introspect.c_str());
yast-commit@lists.opensuse.org