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
|
int
my_async_method_reply (NihDBusMessage * message,
const MyAsyncMethodStructure *structure)
{
DBusMessage * reply;
DBusMessageIter iter;
DBusMessageIter structure_iter;
const char * structure_item0;
uint32_t structure_item1;
nih_assert (message != NULL);
nih_assert (structure != NULL);
/* 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 0;
/* Construct the reply message. */
reply = dbus_message_new_method_return (message->message);
if (! reply)
return -1;
dbus_message_iter_init_append (reply, &iter);
/* Marshal a structure onto the message */
if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &structure_iter)) {
dbus_message_unref (reply);
return -1;
}
structure_item0 = structure->item0;
/* Marshal a char * onto the message */
if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_STRING, &structure_item0)) {
dbus_message_iter_abandon_container (&iter, &structure_iter);
dbus_message_unref (reply);
return -1;
}
structure_item1 = structure->item1;
/* Marshal a uint32_t onto the message */
if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_UINT32, &structure_item1)) {
dbus_message_iter_abandon_container (&iter, &structure_iter);
dbus_message_unref (reply);
return -1;
}
if (! dbus_message_iter_close_container (&iter, &structure_iter)) {
dbus_message_unref (reply);
return -1;
}
/* Send the reply, appending it to the outgoing queue. */
if (! dbus_connection_send (message->connection, reply, NULL)) {
dbus_message_unref (reply);
return -1;
}
dbus_message_unref (reply);
return 0;
}
|