clean up things a little bit

This commit is contained in:
Tristan Hume 2017-04-23 14:37:19 -04:00
parent d395af0f4c
commit debcc8fbc6
2 changed files with 9 additions and 12 deletions

View file

@ -36,8 +36,9 @@ void buildIter(TS...)(DBusMessageIter *iter, TS args) if(allCanDBus!TS) {
static if(is(T == Variant!DBusAny)) { static if(is(T == Variant!DBusAny)) {
auto val = arg.data; auto val = arg.data;
val.explicitVariant = true; val.explicitVariant = true;
} else } else {
auto val = arg; auto val = arg;
}
DBusMessageIter subStore; DBusMessageIter subStore;
DBusMessageIter* sub = &subStore; DBusMessageIter* sub = &subStore;
char[] sig = [cast(char) val.type]; char[] sig = [cast(char) val.type];
@ -51,11 +52,9 @@ void buildIter(TS...)(DBusMessageIter *iter, TS args) if(allCanDBus!TS) {
else else
dbus_message_iter_open_container(iter, 'v', sig.ptr, sub); dbus_message_iter_open_container(iter, 'v', sig.ptr, sub);
if(val.type == 's') { if(val.type == 's') {
immutable(char)* cStr = val.str.toStringz(); buildIter(sub, val.str);
dbus_message_iter_append_basic(sub,'s',&cStr);
} else if(val.type == 'b') { } else if(val.type == 'b') {
dbus_bool_t longerBool = val.boolean; // dbus bools are ints buildIter(sub,val.boolean);
dbus_message_iter_append_basic(sub,'b',&longerBool);
} else if(dbus_type_is_basic(val.type)) { } else if(dbus_type_is_basic(val.type)) {
dbus_message_iter_append_basic(sub,val.type,&val.int64); dbus_message_iter_append_basic(sub,val.type,&val.int64);
} else if(val.type == 'a') { } else if(val.type == 'a') {
@ -160,13 +159,9 @@ T readIter(T)(DBusMessageIter *iter) if (canDBus!T) {
ret.type = dbus_message_iter_get_arg_type(iter); ret.type = dbus_message_iter_get_arg_type(iter);
ret.explicitVariant = false; ret.explicitVariant = false;
if(ret.type == 's') { if(ret.type == 's') {
const(char)* cStr; ret.str = readIter!string(iter);
dbus_message_iter_get_basic(iter, &cStr);
ret.str = cStr.fromStringz().idup; // copy string
} else if(ret.type == 'b') { } else if(ret.type == 'b') {
dbus_bool_t longerBool; ret.boolean = readIter!bool(iter);
dbus_message_iter_get_basic(iter, &longerBool);
ret.boolean = cast(bool)longerBool;
} else if(dbus_type_is_basic(ret.type)) { } else if(dbus_type_is_basic(ret.type)) {
dbus_message_iter_get_basic(iter, &ret.int64); dbus_message_iter_get_basic(iter, &ret.int64);
} else if(ret.type == 'a') { } else if(ret.type == 'a') {

View file

@ -292,8 +292,10 @@ struct DBusAny {
if(type != 'a' || !signature || signature[0] != '{') if(type != 'a' || !signature || signature[0] != '{')
throw new Exception("Can't convert type " ~ cast(char) type ~ " to " ~ T.stringof); throw new Exception("Can't convert type " ~ cast(char) type ~ " to " ~ T.stringof);
T ret; T ret;
foreach(pair; array) foreach(pair; array) {
enforce(pair.type == 'e');
ret[pair.entry.key.to!(KeyType!T)] = pair.entry.value.to!(ValueType!T); ret[pair.entry.key.to!(KeyType!T)] = pair.entry.value.to!(ValueType!T);
}
return ret; return ret;
} else static assert(false, "Can't convert variant to " ~ T.stringof); } else static assert(false, "Can't convert variant to " ~ T.stringof);
} }