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
|
DBusHandlerResult
my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object,
NihDBusMessage *message)
{
DBusMessageIter iter;
DBusMessage * reply;
nih_assert (object != NULL);
nih_assert (message != NULL);
/* Iterate the arguments to the message and demarshal into arguments
* for our own function call.
*/
dbus_message_iter_init (message->message, &iter);
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
"Invalid arguments to Method method");
if (! reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (! dbus_connection_send (message->connection, reply, NULL)) {
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
/* Call the handler function */
nih_error_push_context ();
if (my_method (object->data, message) < 0) {
NihError *err;
err = nih_error_get ();
if (err->number == ENOMEM) {
nih_free (err);
nih_error_pop_context ();
return DBUS_HANDLER_RESULT_NEED_MEMORY;
} else if (err->number == NIH_DBUS_ERROR) {
NihDBusError *dbus_err = (NihDBusError *)err;
reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
nih_free (err);
nih_error_pop_context ();
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
} else {
reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
nih_free (err);
nih_error_pop_context ();
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
}
nih_error_pop_context ();
/* If the sender doesn't care about a reply, don't bother wasting
* effort constructing and sending one.
*/
if (dbus_message_get_no_reply (message->message))
return DBUS_HANDLER_RESULT_HANDLED;
do {
__label__ enomem;
/* Construct the reply message. */
reply = dbus_message_new_method_return (message->message);
if (! reply)
goto enomem;
dbus_message_iter_init_append (reply, &iter);
enomem: __attribute__ ((unused));
} while (! reply);
/* Send the reply, appending it to the outgoing queue. */
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
|