Author: lslezak Date: Tue Feb 3 14:19:41 2009 New Revision: 55202 URL: http://svn.opensuse.org/viewcvs/yast?rev=55202&view=rev Log: - Dbus service - replace invalid characters in the name space by underscore ('_') when registering a DBus object (e.g. "YaPI::USERS"->"YaPI__USERS"), export two interfaces: org.opensuse.yast.modules.YCPValues for using marshalled YCPValues in '(bsv)' structure org.opensuse.yast.modules.Values for using native DBus types, missing types are encoded as strings Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc?rev=55202&r1=55201&r2=55202&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc Tue Feb 3 14:19:41 2009 @@ -36,6 +36,19 @@ } } +void MakeValidObjectName(std::string &name) +{ + for(std::string::iterator it = name.begin(); + it != name.end(); + ++it) + { + if (!isalnum(*it) && (*it) != '_') + { + *it = '_'; + } + } +} + DBusModulesServer::DBusModulesServer(const NameSpaceList &name_spaces) : e(this), wfm(NULL) { init_wfm(); @@ -55,12 +68,14 @@ else { ns->initialize(); - y2milestone("Imported name space: %s", it->c_str()); + std::string objname(*it); + MakeValidObjectName(objname); - nsmap[*it] = ns; + y2milestone("Imported name space: %s, using object name: %s", it->c_str(), objname.c_str()); + + nsmap[objname] = ns; } } - } DBusModulesServer::~DBusModulesServer() @@ -73,7 +88,7 @@ } } -void DBusModulesServer::registerFunctions(const std::string &interface_prefix) +void DBusModulesServer::registerFunctions(const std::string &interface_prefix, bool do_marshalling) { for (NameSpaceMap::const_iterator it = nsmap.begin(); it != nsmap.end(); @@ -106,7 +121,7 @@ DBusSignature sig; // add return type - std::string rett(Y2Dtype(rettype)); + std::string rett(do_marshalling ? "(bsv)" : Y2Dtype(rettype)); if (!rett.empty()) { @@ -121,7 +136,7 @@ bool params_ok = true; while(parindex < params) { - std::string partype(Y2Dtype(fptr->parameterType(parindex))); + std::string partype(do_marshalling ? "(bsv)" : Y2Dtype(fptr->parameterType(parindex))); if (!partype.empty()) { @@ -142,7 +157,7 @@ { sig.params = p; // register the function: register_function(object, interface, method, signature, handler) - register_method(ns->name(), interface_prefix, name, sig, e); + register_method(it->first, interface_prefix, name, sig, e); } } } @@ -167,25 +182,12 @@ case(YT_STRING) : ret = DBUS_TYPE_STRING_AS_STRING; break; case(YT_PATH) : ret = DBUS_TYPE_STRING_AS_STRING; break; case(YT_SYMBOL) : ret = DBUS_TYPE_STRING_AS_STRING; break; -// case(YT_LIST) : ret = DBUS_TYPE_ARRAY_AS_STRING; break; + case(YT_LIST) : ret = DBUS_TYPE_ARRAY_AS_STRING; break; + case(YT_MAP) : ret = DBUS_TYPE_ARRAY_AS_STRING; break; + case(YT_TERM) : ret = DBUS_TYPE_STRING_AS_STRING; break; + case(YT_CODE) : ret = DBUS_TYPE_STRING_AS_STRING; break; default : y2warning("Value type %d is not supported", vt); break; -/* - case(YT_MAP) : ret = DBUS_TYPE__AS_STRING; break; - case(YT_) : ret = DBUS_TYPE__AS_STRING; break; - - YT_BYTEBLOCK = 5, - YT_LIST = 8, - YT_TERM = 9, - YT_MAP = 10, - YT_CODE = 11, // YCode as YCPValue - YT_RETURN = 12, // value of 'return;' - YT_BREAK = 13, // value of 'break;' - YT_ENTRY = 14, // just a placeholder for a SymbolEntry belonging to a function (i.e. foreach()) - YT_ERROR = 15, // error value, will cause trouble - YT_REFERENCE = 16, // a reference to a variable - YT_EXTERNAL = 17 // a reference to an external data -*/ } return ret; @@ -228,7 +230,8 @@ bool DBusModulesServer::connect() { - registerFunctions("org.opensuse.yast.modules"); + registerFunctions("org.opensuse.yast.modules.YCPValues", true); + registerFunctions("org.opensuse.yast.modules.Values", false); return DBusServerBase::connect(SYSTEM, "org.opensuse.yast.modules"); } @@ -237,8 +240,9 @@ YCPValue ret; DBusMsg reply; - std::string method = request.method(); - std::string object = request.path(); + std::string method(request.method()); + std::string object(request.path()); + std::string interface(request.interface()); // remove the leading slash from the object name if (!object.empty() && object[0] == '/') @@ -246,7 +250,7 @@ object.erase(object.begin()); } - y2debug("Requested object: %s, method: %s", object.c_str(), method.c_str()); + y2debug("Requested object: %s, interface: %s, method: %s", object.c_str(), interface.c_str(), method.c_str()); constTypePtr t = searchFuncType(object, method); @@ -303,7 +307,15 @@ if (!ret.isNull()) { y2milestone("Result: %s", ret->toString().c_str()); - reply.addYCPValue(ret); + + if (interface == "org.opensuse.yast.modules.Values") + { + reply.addValue(ret); + } + else + { + reply.addYCPValue(ret); + } } return reply; Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h?rev=55202&r1=55201&r2=55202&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h Tue Feb 3 14:19:41 2009 @@ -46,7 +46,7 @@ std::string Y2Dtype(constTypePtr type) const; // register the functions from the namespace to DBus service - void registerFunctions(const std::string &interface_prefix); + void registerFunctions(const std::string &interface_prefix, bool do_marshalling); DBusMsg handler(const DBusMsg &request); Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc?rev=55202&r1=55201&r2=55202&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc Tue Feb 3 14:19:41 2009 @@ -222,6 +222,148 @@ return ret; } +bool DBusMsg::addValue(const YCPValue &val) +{ + if (val.isNull()) + { + y2milestone("Ignoring YCPNull value"); + return false; + } + + y2debug("Adding YCP value: %s", val->toString().c_str()); + + // create insert iterator + DBusMessageIter it; + dbus_message_iter_init_append(msg, &it); + + // add the value + bool ret = addValueAt(val, &it); + + return ret; +} + +bool DBusMsg::addValueAt(const YCPValue &val, DBusMessageIter *i) +{ + int type = typeInt(val); + + if (val->isInteger()) + { + dbus_int64_t i64 = val->asInteger()->value(); + addValue(type, &i64, i); + } + else if (val->isFloat()) + { + double d = val->asFloat()->value(); + addValue(type, &d, i); + } + else if (val->isString()) + { + const char *str = val->asString()->value().c_str(); + addValue(type, &str, i); + } + else if (val->isBoolean()) + { + dbus_bool_t b = val->asBoolean()->value(); + addValue(type, &b, i); + } + // add path and symbol as string + else if (val->isPath() || val->isSymbol() || val->isTerm() || val->isCode()) + { + std::string val_str(val->toString()); + const char *str = val_str.c_str(); + // add path as a string + addValue(type, &str, i); + } + else if (val->isList()) + { + YCPList lst = val->asList(); + int sz = lst->size(); + int index = 0; + + DBusMessageIter array_it; + + // open array container + y2debug("Opening array container"); + dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "v", &array_it); + while(index < sz) + { + y2debug("Adding YCP value at index %d", index); + // add VARIANT container + DBusMessageIter var_it; + dbus_message_iter_open_container(&array_it, DBUS_TYPE_VARIANT, typeStr(lst->value(index)), &var_it); + + // add the raw YCP value + addValueAt(lst->value(index), &array_it); + + y2debug("Closing VARIANT container"); + dbus_message_iter_close_container(&array_it, &var_it); + + index++; + } + + // close array container + y2debug("Closing array container"); + dbus_message_iter_close_container(i, &array_it); + } + else if (val->isMap()) + { + YCPMap map = val->asMap(); + + DBusMessageIter array_it; + + // open array container + y2debug("Opening DICT container"); + dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "{vv}", &array_it); + + for(YCPMapIterator mit = map.begin(); mit != map.end() ; ++mit) + { + YCPValue key = mit.key(); + YCPValue val = mit.value(); + + DBusMessageIter map_item_it; + y2debug("Opening map item container"); + + dbus_message_iter_open_container(&array_it, DBUS_TYPE_DICT_ENTRY, 0, &map_item_it); + + // add VARIANT container + DBusMessageIter var_it; + dbus_message_iter_open_container(&array_it, DBUS_TYPE_VARIANT, typeStr(key), &var_it); + + // add the key + addValueAt(key, &var_it); + + y2debug("Closing VARIANT container"); + dbus_message_iter_close_container(&array_it, &var_it); + + + // add VARIANT container + DBusMessageIter var_it2; + dbus_message_iter_open_container(&array_it, DBUS_TYPE_VARIANT, typeStr(val), &var_it2); + + // add the key + addValueAt(val, &var_it2); + + y2debug("Closing VARIANT container"); + dbus_message_iter_close_container(&array_it, &var_it2); + + // close map item + dbus_message_iter_close_container(&array_it, &map_item_it); + } + + // close array container + dbus_message_iter_close_container(i, &array_it); + } + else + { + y2error("Unsupported type %s, value: %s", Type::vt2type(val->valuetype())->toString().c_str(), + val->toString().c_str()); + + // TODO add as string? + } + + return true; +} + bool DBusMsg::addYCPValueRaw(const YCPValue &val, DBusMessageIter *i) { int type = typeInt(val); Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h?rev=55202&r1=55201&r2=55202&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h Tue Feb 3 14:19:41 2009 @@ -43,6 +43,8 @@ bool addDouble(double val); bool addYCPValue(const YCPValue &val); + bool addValue(const YCPValue &val); + YCPValue getYCPValue(int index) const; bool isMethodCall(const std::string &interface, const std::string &method) const; @@ -62,6 +64,7 @@ bool addValue(int type, void* data); bool addValue(int type, void* data, DBusMessageIter *i); + bool addValueAt(const YCPValue &val, DBusMessageIter *i); bool addYCPValue(const YCPValue &v, DBusMessageIter *i); bool addYCPValueRaw(const YCPValue &val, DBusMessageIter *i); void release(); Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc?rev=55202&r1=55201&r2=55202&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Tue Feb 3 14:19:41 2009 @@ -175,7 +175,7 @@ // handle Introspection request from "org.freedesktop.DBus.Introspectable" "Introspect" if (request.isMethodCall(DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { - y2milestone("Requesting path: %s", request.path().c_str()); + y2milestone("Introspecting object: %s", request.path().c_str()); std::string introspect; // root node? -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org