1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
int
my_get_property_sync (const void * parent,
NihDBusProxy *proxy,
MyProperty ** value)
{
DBusMessage * method_call;
DBusMessageIter iter;
DBusMessageIter variter;
DBusError error;
DBusMessage * reply;
const char * interface;
const char * property;
DBusMessageIter local_iter;
const char * local_item0_dbus;
char * local_item0;
uint32_t local_item1;
MyProperty * local;
nih_assert (proxy != NULL);
nih_assert (value != NULL);
/* Construct the method call message. */
method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get");
if (! method_call)
nih_return_no_memory_error (-1);
dbus_message_set_auto_start (method_call, proxy->auto_start);
dbus_message_iter_init_append (method_call, &iter);
interface = "com.netsplit.Nih.Test";
if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {
dbus_message_unref (method_call);
nih_return_no_memory_error (-1);
}
property = "property";
if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) {
dbus_message_unref (method_call);
nih_return_no_memory_error (-1);
}
/* Send the message, and wait for the reply. */
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);
if (! reply) {
dbus_message_unref (method_call);
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {
nih_error_raise_no_memory ();
} else {
nih_dbus_error_raise (error.name, error.message);
}
dbus_error_free (&error);
return -1;
}
dbus_message_unref (method_call);
/* Iterate the method arguments, recursing into the variant */
dbus_message_iter_init (reply, &iter);
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) {
dbus_message_unref (reply);
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
}
dbus_message_iter_recurse (&iter, &variter);
dbus_message_iter_next (&iter);
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
dbus_message_unref (reply);
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
}
do {
__label__ enomem;
/* Demarshal a structure from the message */
if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) {
dbus_message_unref (reply);
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
}
dbus_message_iter_recurse (&variter, &local_iter);
local = nih_new (parent, MyProperty);
if (! local) {
*value = NULL;
goto enomem;
}
/* Demarshal a char * from the message */
if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_STRING) {
nih_free (local);
dbus_message_unref (reply);
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
}
dbus_message_iter_get_basic (&local_iter, &local_item0_dbus);
local_item0 = nih_strdup (local, local_item0_dbus);
if (! local_item0) {
nih_free (local);
*value = NULL;
goto enomem;
}
dbus_message_iter_next (&local_iter);
local->item0 = local_item0;
/* Demarshal a uint32_t from the message */
if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_UINT32) {
nih_free (local);
dbus_message_unref (reply);
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
}
dbus_message_iter_get_basic (&local_iter, &local_item1);
dbus_message_iter_next (&local_iter);
local->item1 = local_item1;
if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_INVALID) {
nih_free (local);
dbus_message_unref (reply);
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
}
dbus_message_iter_next (&variter);
*value = local;
enomem: __attribute__ ((unused));
} while (! *value);
dbus_message_unref (reply);
return 0;
}
|