Commit e16dafeb authored by Owen Fraser-Green's avatar Owen Fraser-Green

Handle empty iterators.

parent c2920b8f
2004-05-01 Owen Fraser-Green <owen@discobabe.net>
* mono/DBusType/Dict.cs: Handle empty dicts
* mono/DBusType/Array.cs: Handle empty arrays
* mono/Arguments.cs: Handle empty arguments
2004-04-30 Owen Fraser-Green <owen@discobabe.net>
* dbus-sharp.pc.in: Modified to include include Libs and Requires
......
......@@ -181,15 +181,17 @@ namespace DBus
string key = "";
// Iterate through the parameters getting the type codes to a string
dbus_message_iter_init(message.RawMessage, iter);
bool empty = dbus_message_iter_init(message.RawMessage, iter);
do {
char code = (char) dbus_message_iter_get_arg_type(iter);
if (code == '\0')
return key;
key += code;
} while (dbus_message_iter_next(iter));
if (!empty) {
do {
char code = (char) dbus_message_iter_get_arg_type(iter);
if (code == '\0')
return key;
key += code;
} while (dbus_message_iter_next(iter));
}
Marshal.FreeCoTaskMem(iter);
......@@ -219,6 +221,7 @@ namespace DBus
{
private Arguments arguments;
private bool started = false;
private bool empty = false;
private IntPtr iter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
public ArgumentsEnumerator(Arguments arguments)
......@@ -238,13 +241,13 @@ namespace DBus
return dbus_message_iter_next(iter);
} else {
started = true;
return true;
return !empty;
}
}
public void Reset()
{
dbus_message_iter_init(arguments.message.RawMessage, iter);
empty = dbus_message_iter_init(arguments.message.RawMessage, iter);
started = false;
}
......@@ -274,7 +277,7 @@ namespace DBus
private extern static bool dbus_message_iter_next(IntPtr iter);
[DllImport("dbus-1")]
private extern static void dbus_message_iter_init(IntPtr rawMessage, IntPtr iter);
private extern static bool dbus_message_iter_init(IntPtr rawMessage, IntPtr iter);
[DllImport("dbus-1")]
private extern static int dbus_message_iter_get_arg_type(IntPtr iter);
......
......@@ -36,18 +36,20 @@ namespace DBus.DBusType
IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
int elementTypeCode;
dbus_message_iter_init_array_iterator(iter, arrayIter, out elementTypeCode);
bool empty = dbus_message_iter_init_array_iterator(iter, arrayIter, out elementTypeCode);
this.elementType = (Type) Arguments.DBusTypes[(char) elementTypeCode];
elements = new ArrayList();
do {
object [] pars = new Object[2];
pars[0] = arrayIter;
pars[1] = service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
elements.Add(dbusType);
} while (dbus_message_iter_next(arrayIter));
if (!empty) {
do {
object [] pars = new Object[2];
pars[0] = arrayIter;
pars[1] = service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
elements.Add(dbusType);
} while (dbus_message_iter_next(arrayIter));
}
Marshal.FreeCoTaskMem(arrayIter);
}
......@@ -118,7 +120,7 @@ namespace DBus.DBusType
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_init_array_iterator(IntPtr iter,
private extern static bool dbus_message_iter_init_array_iterator(IntPtr iter,
IntPtr arrayIter,
out int elementType);
......
......@@ -31,20 +31,22 @@ namespace DBus.DBusType
{
IntPtr dictIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
dbus_message_iter_init_dict_iterator(iter, dictIter);
bool empty = dbus_message_iter_init_dict_iterator(iter, dictIter);
this.val = new Hashtable();
do {
string key = dbus_message_iter_get_dict_key(dictIter);
// Get the argument type and get the value
Type elementType = (Type) DBus.Arguments.DBusTypes[(char) dbus_message_iter_get_arg_type(dictIter)];
object [] pars = new Object[1];
pars[0] = dictIter;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
this.val.Add(key, dbusType);
} while (dbus_message_iter_next(dictIter));
if (!empty) {
do {
string key = dbus_message_iter_get_dict_key(dictIter);
// Get the argument type and get the value
Type elementType = (Type) DBus.Arguments.DBusTypes[(char) dbus_message_iter_get_arg_type(dictIter)];
object [] pars = new Object[1];
pars[0] = dictIter;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
this.val.Add(key, dbusType);
} while (dbus_message_iter_next(dictIter));
}
Marshal.FreeCoTaskMem(dictIter);
}
......@@ -120,7 +122,7 @@ namespace DBus.DBusType
}
[DllImport("dbus-1")]
private extern static void dbus_message_iter_init_dict_iterator(IntPtr iter,
private extern static bool dbus_message_iter_init_dict_iterator(IntPtr iter,
IntPtr dictIter);
[DllImport("dbus-1")]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment