~jamesodhunt/ubuntu/raring/upstart/1.6

« back to all changes in this revision

Viewing changes to nih-dbus-tool/tests/expected/test_method_proxy_notify_function_structure.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
 
void
2
 
my_com_netsplit_Nih_Test_Method_notify (DBusPendingCall *   pending_call,
3
 
                                        NihDBusPendingData *pending_data)
4
 
{
5
 
        DBusMessage *      reply;
6
 
        DBusMessageIter    iter;
7
 
        NihDBusMessage *   message;
8
 
        DBusError          error;
9
 
        MyMethodStructure *structure;
10
 
        DBusMessageIter    structure_iter;
11
 
        const char *       structure_item0_dbus;
12
 
        char *             structure_item0;
13
 
        uint32_t           structure_item1;
14
 
 
15
 
        nih_assert (pending_call != NULL);
16
 
        nih_assert (pending_data != NULL);
17
 
 
18
 
        nih_assert (dbus_pending_call_get_completed (pending_call));
19
 
 
20
 
        /* Steal the reply from the pending call. */
21
 
        reply = dbus_pending_call_steal_reply (pending_call);
22
 
        nih_assert (reply != NULL);
23
 
 
24
 
        /* Handle error replies */
25
 
        if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
26
 
                message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));
27
 
 
28
 
                dbus_error_init (&error);
29
 
                dbus_set_error_from_message (&error, message->message);
30
 
 
31
 
                nih_error_push_context ();
32
 
                nih_dbus_error_raise (error.name, error.message);
33
 
                pending_data->error_handler (pending_data->data, message);
34
 
                nih_error_pop_context ();
35
 
 
36
 
                dbus_error_free (&error);
37
 
                nih_free (message);
38
 
                dbus_message_unref (reply);
39
 
                return;
40
 
        }
41
 
 
42
 
        nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN);
43
 
 
44
 
        do {
45
 
                __label__ enomem;
46
 
 
47
 
                /* Create a message context for the reply, and iterate
48
 
                 * over its arguments.
49
 
                 */
50
 
                message = nih_dbus_message_new (pending_data, pending_data->connection, reply);
51
 
                if (! message)
52
 
                        goto enomem;
53
 
 
54
 
                dbus_message_iter_init (message->message, &iter);
55
 
 
56
 
                /* Demarshal a structure from the message */
57
 
                if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) {
58
 
                        nih_error_push_context ();
59
 
                        nih_error_raise (NIH_DBUS_INVALID_ARGS,
60
 
                                         _(NIH_DBUS_INVALID_ARGS_STR));
61
 
                        pending_data->error_handler (pending_data->data, message);
62
 
                        nih_error_pop_context ();
63
 
 
64
 
                        nih_free (message);
65
 
                        dbus_message_unref (reply);
66
 
                        return;
67
 
                }
68
 
 
69
 
                dbus_message_iter_recurse (&iter, &structure_iter);
70
 
 
71
 
                structure = nih_new (message, MyMethodStructure);
72
 
                if (! structure) {
73
 
                        nih_free (message);
74
 
                        message = NULL;
75
 
                        goto enomem;
76
 
                }
77
 
 
78
 
                /* Demarshal a char * from the message */
79
 
                if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_STRING) {
80
 
                        nih_free (structure);
81
 
                        nih_error_push_context ();
82
 
                        nih_error_raise (NIH_DBUS_INVALID_ARGS,
83
 
                                         _(NIH_DBUS_INVALID_ARGS_STR));
84
 
                        pending_data->error_handler (pending_data->data, message);
85
 
                        nih_error_pop_context ();
86
 
 
87
 
                        nih_free (message);
88
 
                        dbus_message_unref (reply);
89
 
                        return;
90
 
                }
91
 
 
92
 
                dbus_message_iter_get_basic (&structure_iter, &structure_item0_dbus);
93
 
 
94
 
                structure_item0 = nih_strdup (structure, structure_item0_dbus);
95
 
                if (! structure_item0) {
96
 
                        nih_free (structure);
97
 
                        nih_free (message);
98
 
                        message = NULL;
99
 
                        goto enomem;
100
 
                }
101
 
 
102
 
                dbus_message_iter_next (&structure_iter);
103
 
 
104
 
                structure->item0 = structure_item0;
105
 
 
106
 
                /* Demarshal a uint32_t from the message */
107
 
                if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_UINT32) {
108
 
                        nih_free (structure);
109
 
                        nih_error_push_context ();
110
 
                        nih_error_raise (NIH_DBUS_INVALID_ARGS,
111
 
                                         _(NIH_DBUS_INVALID_ARGS_STR));
112
 
                        pending_data->error_handler (pending_data->data, message);
113
 
                        nih_error_pop_context ();
114
 
 
115
 
                        nih_free (message);
116
 
                        dbus_message_unref (reply);
117
 
                        return;
118
 
                }
119
 
 
120
 
                dbus_message_iter_get_basic (&structure_iter, &structure_item1);
121
 
 
122
 
                dbus_message_iter_next (&structure_iter);
123
 
 
124
 
                structure->item1 = structure_item1;
125
 
 
126
 
                if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_INVALID) {
127
 
                        nih_free (structure);
128
 
                        nih_error_push_context ();
129
 
                        nih_error_raise (NIH_DBUS_INVALID_ARGS,
130
 
                                         _(NIH_DBUS_INVALID_ARGS_STR));
131
 
                        pending_data->error_handler (pending_data->data, message);
132
 
                        nih_error_pop_context ();
133
 
 
134
 
                        nih_free (message);
135
 
                        dbus_message_unref (reply);
136
 
                        return;
137
 
                }
138
 
 
139
 
                dbus_message_iter_next (&iter);
140
 
 
141
 
                if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
142
 
                        nih_error_push_context ();
143
 
                        nih_error_raise (NIH_DBUS_INVALID_ARGS,
144
 
                                         _(NIH_DBUS_INVALID_ARGS_STR));
145
 
                        pending_data->error_handler (pending_data->data, message);
146
 
                        nih_error_pop_context ();
147
 
 
148
 
                        nih_free (message);
149
 
                        dbus_message_unref (reply);
150
 
                        return;
151
 
                }
152
 
 
153
 
        enomem: __attribute__ ((unused));
154
 
        } while (! message);
155
 
 
156
 
        /* Call the handler function */
157
 
        if (pending_data->handler) {
158
 
                nih_error_push_context ();
159
 
                ((MyMethodReply)pending_data->handler) (pending_data->data, message, structure);
160
 
                nih_error_pop_context ();
161
 
        }
162
 
 
163
 
        nih_free (message);
164
 
        dbus_message_unref (reply);
165
 
}