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
|
DBusPendingCall *
my_test_method (NihDBusProxy * proxy,
const char * str,
int32_t flags,
MyTestMethodReply handler,
NihDBusErrorHandler error_handler,
void * data,
int timeout)
{
DBusMessage * method_call;
DBusMessageIter iter;
DBusPendingCall * pending_call;
NihDBusPendingData *pending_data;
nih_assert (proxy != NULL);
nih_assert (str != NULL);
nih_assert ((handler == NULL) || (error_handler != NULL));
/* Construct the method call message. */
method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "TestMethod");
if (! method_call)
nih_return_no_memory_error (NULL);
dbus_message_set_auto_start (method_call, proxy->auto_start);
dbus_message_iter_init_append (method_call, &iter);
/* Marshal a char * onto the message */
if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) {
dbus_message_unref (method_call);
nih_return_no_memory_error (NULL);
}
/* Marshal a int32_t onto the message */
if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) {
dbus_message_unref (method_call);
nih_return_no_memory_error (NULL);
}
/* Handle a fire-and-forget message */
if (! error_handler) {
dbus_message_set_no_reply (method_call, TRUE);
if (! dbus_connection_send (proxy->connection, method_call, NULL)) {
dbus_message_unref (method_call);
nih_return_no_memory_error (NULL);
}
dbus_message_unref (method_call);
return (DBusPendingCall *)TRUE;
}
/* Send the message and set up the reply notification. */
pending_data = nih_dbus_pending_data_new (NULL, proxy->connection,
(NihDBusReplyHandler)handler,
error_handler, data);
if (! pending_data) {
dbus_message_unref (method_call);
nih_return_no_memory_error (NULL);
}
pending_call = NULL;
if (! dbus_connection_send_with_reply (proxy->connection, method_call,
&pending_call, timeout)) {
dbus_message_unref (method_call);
nih_free (pending_data);
nih_return_no_memory_error (NULL);
}
dbus_message_unref (method_call);
if (! pending_call) {
nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED,
"Connection is closed");
nih_free (pending_data);
return NULL;
}
NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_TestMethod_notify,
pending_data, (DBusFreeFunction)nih_discard));
return pending_call;
}
|