Author: lslezak Date: Wed Jun 17 15:17:37 2009 New Revision: 57615 URL: http://svn.opensuse.org/viewcvs/yast?rev=57615&view=rev Log: - DBusModulesServer::Y2Dtype() moved to DBusMsg::YCPTypeSignature() - returning list<any>, list<string> works correctly now Modified: branches/tmp/lslezak/core/dbus/namespace_service/src/DBusModulesServer.cc branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h Modified: branches/tmp/lslezak/core/dbus/namespace_service/src/DBusModulesServer.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/src/DBusModulesServer.cc?rev=57615&r1=57614&r2=57615&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/src/DBusModulesServer.cc (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/src/DBusModulesServer.cc Wed Jun 17 15:17:37 2009 @@ -23,14 +23,6 @@ #include "yast_dbus_names.h" -class SignatureException : std::exception -{ - public: - SignatureException() - { - y2error("Signature exception"); - } -}; void DBusModulesServer::init_wfm() { @@ -130,7 +122,7 @@ try { // add return type - rett = Y2Dtype(rettype); + rett = DBusMsg::YCPTypeSignature(rettype); } catch (const SignatureException &excpt) { @@ -160,7 +152,7 @@ { try { - std::string partype_raw(Y2Dtype(fptr->parameterType(parindex))); + std::string partype_raw(DBusMsg::YCPTypeSignature(fptr->parameterType(parindex))); DBusArgument param("param", partype_raw); p_raw.push_back(param); @@ -279,81 +271,6 @@ register_method(YAST_DBUS_OBJ_PREFIX, YAST_DBUS_MGR_INTERFACE, YAST_DBUS_MANAGER_LOCK_METHOD, void_sig, manager_callback); } -std::string DBusModulesServer::Y2Dtype(constTypePtr type) const -{ - // handle any type specially - if (type->isAny()) - { - return "v"; - } - - if (type->isList()) - { - constTypePtr list_type = ((constListTypePtr)type)->type(); - y2debug("type list<%s>", list_type->toString().c_str()); - - std::string list_type_str(Y2Dtype(list_type)); - - if (list_type_str.empty()) - { - throw SignatureException(); - } - - return std::string("a") + list_type_str; - } - - if (type->isMap()) - { - constMapTypePtr mt = (constMapTypePtr)type; - constTypePtr key_type = mt->keytype(); - constTypePtr val_type = mt->valuetype(); - - if (key_type->isAny()) - { - y2error("Type of key in map must not be 'any'!"); - throw SignatureException(); - } - - if (key_type->isMap() || key_type->isList()) - { - y2error("Type of key in map must be basic type"); - throw SignatureException(); - } - - y2debug("type map<%s,%s>", key_type->toString().c_str(), val_type->toString().c_str()); - - std::string key_type_str(Y2Dtype(key_type)); - std::string val_type_str(Y2Dtype(val_type)); - - if (key_type_str.empty() || val_type_str.empty()) - { - throw SignatureException(); - } - - return std::string("a{") + key_type_str + val_type_str + "}"; - } - - YCPValueType vt = type->valueType(); - std::string ret; - - switch (vt) - { - case(YT_VOID) : ret = ""; break; - case(YT_BOOLEAN) : ret = DBUS_TYPE_BOOLEAN_AS_STRING; break; - case(YT_INTEGER) : ret = DBUS_TYPE_INT64_AS_STRING; break; - case(YT_FLOAT) : ret = DBUS_TYPE_DOUBLE_AS_STRING; break; - 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_TERM) : ret = DBUS_TYPE_STRING_AS_STRING; break; -// case(YT_CODE) : ret = DBUS_TYPE_STRING_AS_STRING; break; - - default : y2error("Type '%s' is not supported", type->toString().c_str()); throw SignatureException(); - } - - return ret; -} - constTypePtr DBusModulesServer::searchFuncType(const std::string &objname, const std::string &fname) const { if (nsmap.find(objname) == nsmap.end()) 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=57615&r1=57614&r2=57615&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc Wed Jun 17 15:17:37 2009 @@ -246,10 +246,13 @@ bool DBusMsg::addValueAt(const YCPValue &val, DBusMessageIter *i, constTypePtr rtype) { - if (rtype) + if (!rtype) + { + // return as the current type if not specified + rtype = Type::vt2type(val->valuetype()); + } + else { - y2internal("Returning YCP value as type: %s", rtype->toString().c_str()); - // the required type does not match the value if (rtype->matchvalue(val) < 0) { @@ -263,6 +266,8 @@ } } + y2milestone("Returning YCP value as type: %s", rtype->toString().c_str()); + int type = typeInt(val); DBusMessageIter variant_it; @@ -270,7 +275,6 @@ if (rtype && rtype->isAny()) { // open variant container for "any" type - y2debug("Opening VARIANT container with type %s", typeStr(val, rtype == NULL).c_str()); dbus_message_iter_open_container(i, DBUS_TYPE_VARIANT, typeStr(val, rtype == NULL).c_str(), &variant_it); @@ -308,11 +312,19 @@ else if (val->isList()) { YCPList lst = val->asList(); - int sz = lst->size(); - int index = 0; + std::string list_type("v"); + constTypePtr list_type_ptr = Type::Any; + + if (rtype->isList()) + { + list_type_ptr = ((constListTypePtr)rtype)->type(); + y2debug("Found type list<%s>", list_type_ptr->toString().c_str()); - // use string as fallback for empty list - std::string list_type(sz ? typeStr(lst->value(0), NULL /*FIXME bsv_encoding*/) : DBUS_TYPE_STRING_AS_STRING); + if (!list_type_ptr->isAny()) + { + list_type = YCPTypeSignature(list_type_ptr); + } + } DBusMessageIter array_it; @@ -320,25 +332,16 @@ y2debug("Opening array container with type: %s", list_type.c_str()); dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, list_type.c_str(), &array_it); + + int sz = lst->size(); + int index = 0; while(index < sz) { y2debug("Adding YCP value at index %d", index); -/* YCPValue list_item = lst->value(index); + // add the raw YCP value + addValueAt(lst->value(index), &array_it, list_type_ptr); - if (typeStr(list_item, bsv_encoding) != list_type) - { - y2error("Found different type in list: %s (expected %s) - ignoring item %s", - typeStr(list_item, bsv_encoding).c_str(), list_type.c_str(), - list_item->toString().c_str()); - return false; - } - else - { - // add the raw YCP value - addValueAt(lst->value(index), &array_it, bsv_encoding); - } -*/ index++; } @@ -1206,3 +1209,83 @@ { return "(bsv)"; } + +std::string DBusMsg::YCPTypeSignature(constTypePtr type) +{ + // handle any type specially + if (type->isAny()) + { + return "v"; + } + + if (type->isList()) + { + constTypePtr list_type = ((constListTypePtr)type)->type(); + y2debug("type list<%s>", list_type->toString().c_str()); + + std::string list_type_str(YCPTypeSignature(list_type)); + + if (list_type_str.empty()) + { + throw SignatureException(); + } + + return std::string("a") + list_type_str; + } + + if (type->isMap()) + { + constMapTypePtr mt = (constMapTypePtr)type; + constTypePtr key_type = mt->keytype(); + constTypePtr val_type = mt->valuetype(); + + if (key_type->isAny()) + { + y2error("Type of key in map must not be 'any'!"); + throw SignatureException(); + } + + if (key_type->isMap() || key_type->isList()) + { + y2error("Type of key in map must be basic type"); + throw SignatureException(); + } + + y2debug("type map<%s,%s>", key_type->toString().c_str(), val_type->toString().c_str()); + + std::string key_type_str(YCPTypeSignature(key_type)); + std::string val_type_str(YCPTypeSignature(val_type)); + + if (key_type_str.empty() || val_type_str.empty()) + { + throw SignatureException(); + } + + return std::string("a{") + key_type_str + val_type_str + "}"; + } + + YCPValueType vt = type->valueType(); + std::string ret; + + switch (vt) + { + case(YT_VOID) : ret = ""; break; + case(YT_BOOLEAN) : ret = DBUS_TYPE_BOOLEAN_AS_STRING; break; + case(YT_INTEGER) : ret = DBUS_TYPE_INT64_AS_STRING; break; + case(YT_FLOAT) : ret = DBUS_TYPE_DOUBLE_AS_STRING; break; + 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_TERM) : ret = DBUS_TYPE_STRING_AS_STRING; break; +// case(YT_CODE) : ret = DBUS_TYPE_STRING_AS_STRING; break; + + default : y2error("Type '%s' is not supported", type->toString().c_str()); throw SignatureException(); + } + + return ret; +} + +SignatureException::SignatureException() +{ + y2error("Signature exception"); +} 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=57615&r1=57614&r2=57615&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h Wed Jun 17 15:17:37 2009 @@ -63,6 +63,7 @@ std::string sender() const; static const char *YCPValueSignature(); + static std::string YCPTypeSignature(constTypePtr type); private: @@ -81,5 +82,11 @@ YCPValue getYCPValueRaw(DBusMessageIter *it, const std::string &ycp_type = std::string()) const; }; +class SignatureException : std::exception +{ + public: + SignatureException(); +}; + #endif -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org