2
my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object,
3
NihDBusMessage *message)
11
DBusMessageIter output_iter;
13
nih_assert (object != NULL);
14
nih_assert (message != NULL);
16
/* Iterate the arguments to the message and demarshal into arguments
17
* for our own function call.
19
dbus_message_iter_init (message->message, &iter);
21
/* Demarshal a char * from the message */
22
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) {
23
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
24
"Invalid arguments to Method method");
26
return DBUS_HANDLER_RESULT_NEED_MEMORY;
28
if (! dbus_connection_send (message->connection, reply, NULL)) {
29
dbus_message_unref (reply);
30
return DBUS_HANDLER_RESULT_NEED_MEMORY;
33
dbus_message_unref (reply);
34
return DBUS_HANDLER_RESULT_HANDLED;
37
dbus_message_iter_get_basic (&iter, &str_dbus);
39
str = nih_strdup (message, str_dbus);
41
return DBUS_HANDLER_RESULT_NEED_MEMORY;
44
dbus_message_iter_next (&iter);
46
/* Demarshal a int32_t from the message */
47
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) {
48
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
49
"Invalid arguments to Method method");
51
return DBUS_HANDLER_RESULT_NEED_MEMORY;
53
if (! dbus_connection_send (message->connection, reply, NULL)) {
54
dbus_message_unref (reply);
55
return DBUS_HANDLER_RESULT_NEED_MEMORY;
58
dbus_message_unref (reply);
59
return DBUS_HANDLER_RESULT_HANDLED;
62
dbus_message_iter_get_basic (&iter, &flags);
64
dbus_message_iter_next (&iter);
66
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
67
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
68
"Invalid arguments to Method method");
70
return DBUS_HANDLER_RESULT_NEED_MEMORY;
72
if (! dbus_connection_send (message->connection, reply, NULL)) {
73
dbus_message_unref (reply);
74
return DBUS_HANDLER_RESULT_NEED_MEMORY;
77
dbus_message_unref (reply);
78
return DBUS_HANDLER_RESULT_HANDLED;
81
/* Call the handler function */
82
nih_error_push_context ();
83
if (my_method (object->data, message, str, flags, &output) < 0) {
86
err = nih_error_get ();
87
if (err->number == ENOMEM) {
89
nih_error_pop_context ();
91
return DBUS_HANDLER_RESULT_NEED_MEMORY;
92
} else if (err->number == NIH_DBUS_ERROR) {
93
NihDBusError *dbus_err = (NihDBusError *)err;
95
reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
97
nih_error_pop_context ();
99
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
101
dbus_message_unref (reply);
102
return DBUS_HANDLER_RESULT_HANDLED;
104
reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
106
nih_error_pop_context ();
108
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
110
dbus_message_unref (reply);
111
return DBUS_HANDLER_RESULT_HANDLED;
114
nih_error_pop_context ();
116
/* If the sender doesn't care about a reply, don't bother wasting
117
* effort constructing and sending one.
119
if (dbus_message_get_no_reply (message->message))
120
return DBUS_HANDLER_RESULT_HANDLED;
125
/* Construct the reply message. */
126
reply = dbus_message_new_method_return (message->message);
130
dbus_message_iter_init_append (reply, &iter);
132
/* Marshal an array onto the message */
133
if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &output_iter)) {
134
dbus_message_unref (reply);
139
for (size_t output_i = 0; output[output_i]; output_i++) {
140
const char *output_element;
142
output_element = output[output_i];
144
/* Marshal a char * onto the message */
145
if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) {
146
dbus_message_iter_abandon_container (&iter, &output_iter);
147
dbus_message_unref (reply);
153
if (! dbus_message_iter_close_container (&iter, &output_iter)) {
154
dbus_message_unref (reply);
158
enomem: __attribute__ ((unused));
161
/* Send the reply, appending it to the outgoing queue. */
162
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
164
dbus_message_unref (reply);
166
return DBUS_HANDLER_RESULT_HANDLED;