2
my_method_sync (const void * parent,
9
DBusMessage * method_call;
14
DBusMessageIter output_local_iter;
15
size_t output_local_size;
18
nih_assert (proxy != NULL);
19
nih_assert (str != NULL);
20
nih_assert (output != NULL);
21
nih_assert (length != NULL);
23
/* Construct the method call message. */
24
method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method");
26
nih_return_no_memory_error (-1);
28
dbus_message_set_auto_start (method_call, proxy->auto_start);
30
dbus_message_iter_init_append (method_call, &iter);
32
/* Marshal a char * onto the message */
33
if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) {
34
dbus_message_unref (method_call);
35
nih_return_no_memory_error (-1);
38
/* Marshal a int32_t onto the message */
39
if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) {
40
dbus_message_unref (method_call);
41
nih_return_no_memory_error (-1);
44
/* Send the message, and wait for the reply. */
45
dbus_error_init (&error);
47
reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);
49
dbus_message_unref (method_call);
51
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {
52
nih_error_raise_no_memory ();
54
nih_dbus_error_raise (error.name, error.message);
57
dbus_error_free (&error);
61
dbus_message_unref (method_call);
63
/* Iterate the arguments of the reply */
64
dbus_message_iter_init (reply, &iter);
69
/* Demarshal an array from the message */
70
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {
71
dbus_message_unref (reply);
72
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
73
_(NIH_DBUS_INVALID_ARGS_STR));
76
dbus_message_iter_recurse (&iter, &output_local_iter);
78
output_local_size = 0;
81
output_local = nih_alloc (parent, sizeof (char *));
87
output_local[output_local_size] = NULL;
89
while (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_INVALID) {
90
const char *output_local_element_dbus;
91
char ** output_local_tmp;
92
char * output_local_element;
94
/* Demarshal a char * from the message */
95
if (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_STRING) {
97
nih_free (output_local);
98
dbus_message_unref (reply);
99
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
100
_(NIH_DBUS_INVALID_ARGS_STR));
103
dbus_message_iter_get_basic (&output_local_iter, &output_local_element_dbus);
105
output_local_element = nih_strdup (output_local, output_local_element_dbus);
106
if (! output_local_element) {
108
nih_free (output_local);
113
dbus_message_iter_next (&output_local_iter);
115
if (output_local_size + 2 > SIZE_MAX / sizeof (char *)) {
117
nih_free (output_local);
118
dbus_message_unref (reply);
119
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
120
_(NIH_DBUS_INVALID_ARGS_STR));
123
output_local_tmp = nih_realloc (output_local, parent, sizeof (char *) * (output_local_size + 2));
124
if (! output_local_tmp) {
126
nih_free (output_local);
131
output_local = output_local_tmp;
132
output_local[output_local_size] = output_local_element;
133
output_local[output_local_size + 1] = NULL;
138
dbus_message_iter_next (&iter);
140
*output = output_local;
141
enomem: __attribute__ ((unused));
147
/* Demarshal a int32_t from the message */
148
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) {
149
nih_free (output_local);
151
dbus_message_unref (reply);
152
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
153
_(NIH_DBUS_INVALID_ARGS_STR));
156
dbus_message_iter_get_basic (&iter, &length_local);
158
dbus_message_iter_next (&iter);
160
*length = length_local;
161
enomem: __attribute__ ((unused));
164
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
165
nih_free (output_local);
167
dbus_message_unref (reply);
168
nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
169
_(NIH_DBUS_INVALID_ARGS_STR));
172
dbus_message_unref (reply);