~jamesodhunt/ubuntu/raring/upstart/1.6

« back to all changes in this revision

Viewing changes to nih-dbus-tool/tests/expected/test_method_proxy_function_no_args.c

  • Committer: Scott James Remnant
  • Date: 2010-02-04 23:39:59 UTC
  • mfrom: (1182.1.45 upstart)
  • mto: This revision was merged to the branch mainline in revision 1250.
  • Revision ID: scott@netsplit.com-20100204233959-7kajqjnaoh7208ob
Tags: upstream-0.6.5
ImportĀ upstreamĀ versionĀ 0.6.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
DBusPendingCall *
2
 
my_test_method (NihDBusProxy *      proxy,
3
 
                MyTestMethodReply   handler,
4
 
                NihDBusErrorHandler error_handler,
5
 
                void *              data,
6
 
                int                 timeout)
7
 
{
8
 
        DBusMessage *       method_call;
9
 
        DBusMessageIter     iter;
10
 
        DBusPendingCall *   pending_call;
11
 
        NihDBusPendingData *pending_data;
12
 
 
13
 
        nih_assert (proxy != NULL);
14
 
        nih_assert ((handler == NULL) || (error_handler != NULL));
15
 
 
16
 
        /* Construct the method call message. */
17
 
        method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "TestMethod");
18
 
        if (! method_call)
19
 
                nih_return_no_memory_error (NULL);
20
 
 
21
 
        dbus_message_set_auto_start (method_call, proxy->auto_start);
22
 
 
23
 
        dbus_message_iter_init_append (method_call, &iter);
24
 
 
25
 
        /* Handle a fire-and-forget message */
26
 
        if (! error_handler) {
27
 
                dbus_message_set_no_reply (method_call, TRUE);
28
 
                if (! dbus_connection_send (proxy->connection, method_call, NULL)) {
29
 
                        dbus_message_unref (method_call);
30
 
                        nih_return_no_memory_error (NULL);
31
 
                }
32
 
 
33
 
                dbus_message_unref (method_call);
34
 
                return (DBusPendingCall *)TRUE;
35
 
        }
36
 
 
37
 
        /* Send the message and set up the reply notification. */
38
 
        pending_data = nih_dbus_pending_data_new (NULL, proxy->connection,
39
 
                                                  (NihDBusReplyHandler)handler,
40
 
                                                  error_handler, data);
41
 
        if (! pending_data) {
42
 
                dbus_message_unref (method_call);
43
 
                nih_return_no_memory_error (NULL);
44
 
        }
45
 
 
46
 
        pending_call = NULL;
47
 
        if (! dbus_connection_send_with_reply (proxy->connection, method_call,
48
 
                                               &pending_call, timeout)) {
49
 
                dbus_message_unref (method_call);
50
 
                nih_free (pending_data);
51
 
                nih_return_no_memory_error (NULL);
52
 
        }
53
 
 
54
 
        dbus_message_unref (method_call);
55
 
 
56
 
        NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_TestMethod_notify,
57
 
                                                pending_data, (DBusFreeFunction)nih_discard));
58
 
 
59
 
        return pending_call;
60
 
}