Author: lslezak
Date: Wed Jun 17 17:19:30 2009
New Revision: 57622
URL: http://svn.opensuse.org/viewcvs/yast?rev=57622&view=rev
Log:
- added map support, send map as map (DBus requires
a basic type as key, convert integer keys to strings in this case.)
Modified:
branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc
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=57622&r1=57621&r2=57622&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc Wed Jun 17 17:19:30 2009
@@ -354,24 +354,40 @@
{
YCPMap map = val->asMap();
- DBusMessageIter array_it;
+ std::string map_key_type("s");
+ std::string map_val_type("v");
- YCPMap::const_iterator mit = map.begin();
- // use string as fallback for empty map
- std::string key_type(mit == map.end() ? DBUS_TYPE_STRING_AS_STRING : typeStr(mit->first, rtype == NULL));
- std::string val_type(mit == map.end() ? DBUS_TYPE_STRING_AS_STRING : typeStr(mit->second, rtype == NULL));
+ // YCPMap can contain only YCPString, YCPInteger or YCPSymbol as the key
+ constTypePtr map_key_type_ptr = Type::String;
+ constTypePtr map_val_type_ptr = Type::Any;
+
+ if (rtype->isMap())
+ {
+ map_key_type_ptr = ((constMapTypePtr)rtype)->keytype();
- // dbus allows only basic types as key type in a map
- const std::string valid_key_types(DBUS_TYPE_INT64_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_BOOLEAN_AS_STRING);
+ if (map_key_type_ptr->isAny())
+ {
+ map_key_type_ptr = Type::String;
+ }
- if (valid_key_types.find(key_type) == std::string::npos)
- {
- y2error("Invalid type of key in map (non-basic type): %s, ignoring the map", key_type.c_str());
- return false;
+ map_val_type_ptr = ((constMapTypePtr)rtype)->valuetype();
+ y2debug("Found type map<%s,%s>", map_key_type_ptr->toString().c_str(), map_val_type_ptr->toString().c_str());
+
+ if (!map_key_type_ptr->isAny())
+ {
+ map_key_type = YCPTypeSignature(map_key_type_ptr);
+ }
+ if (!map_val_type_ptr->isAny())
+ {
+ map_val_type = YCPTypeSignature(map_val_type_ptr);
+ }
}
- std::string map_signature("{" + key_type + (rtype == NULL ? "v" : val_type) + "}");
+ DBusMessageIter array_it;
+
+ YCPMap::const_iterator mit = map.begin();
+
+ std::string map_signature("{" + map_key_type + map_val_type + "}");
// open array container
y2debug("Opening DICT container with signature: %s", map_signature.c_str());
@@ -382,41 +398,23 @@
YCPValue key = mit->first;
YCPValue val = mit->second;
- // error: this is a different key type than the announced type
- if (key_type != typeStr(key, rtype == NULL))
- {
- y2error("Found different key type %s (expected %s) - ignoring pair $[ %s : %s ]",
- typeStr(key, rtype == NULL).c_str(), key_type.c_str(),
- key->toString().c_str(), val->toString().c_str());
-
- continue;
- }
-
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 the key
- addValueAt(key, &map_item_it, NULL);
-
- if (rtype == NULL)
+ // convert YCPInteger key to string for "any" type
+ if (key->isInteger() && map_key_type_ptr == Type::String)
{
- DBusMessageIter var_it2;
- // add VARIANT container
- y2debug("Opening VARIANT container with type %s", typeStr(val, rtype == NULL).c_str());
- dbus_message_iter_open_container(&map_item_it, DBUS_TYPE_VARIANT, typeStr(val, rtype == NULL).c_str(), &var_it2);
- // add the value
- addValueAt(val, &var_it2, NULL);
-
- y2debug("Closing VARIANT container");
- dbus_message_iter_close_container(&map_item_it, &var_it2);
- }
- else
- {
- addValueAt(val, &map_item_it, NULL);
+ key = YCPString(key->toString());
}
+ // add the key
+ addValueAt(key, &map_item_it, map_key_type_ptr);
+
+ // add the value
+ addValueAt(val, &map_item_it, map_val_type_ptr);
+
// close map item
dbus_message_iter_close_container(&array_it, &map_item_it);
y2debug("Closing map item container");
@@ -1166,10 +1164,7 @@
}
else
{
- std::string val_type((map.size() > 0) ? typeStr(map.begin()->second) : "s");
-
- return std::string(DBUS_TYPE_ARRAY_AS_STRING) + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING +
- + key_type.c_str() + val_type + DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
+ return "a{sv}";
}
}
@@ -1240,14 +1235,7 @@
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();
+ key_type = Type::String;
}
y2debug("type map<%s,%s>", key_type->toString().c_str(), val_type->toString().c_str());
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org