~jamesodhunt/ubuntu/raring/upstart/1.6

« back to all changes in this revision

Viewing changes to nih-dbus-tool/tests/expected/test_property_proxy_get_sync_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
 
int
2
 
my_get_property_sync (const void *  parent,
3
 
                      NihDBusProxy *proxy,
4
 
                      MyProperty ** value)
5
 
{
6
 
        DBusMessage *   method_call;
7
 
        DBusMessageIter iter;
8
 
        DBusMessageIter variter;
9
 
        DBusError       error;
10
 
        DBusMessage *   reply;
11
 
        const char *    interface;
12
 
        const char *    property;
13
 
        DBusMessageIter local_iter;
14
 
        const char *    local_item0_dbus;
15
 
        char *          local_item0;
16
 
        uint32_t        local_item1;
17
 
        MyProperty *    local;
18
 
 
19
 
        nih_assert (proxy != NULL);
20
 
        nih_assert (value != NULL);
21
 
 
22
 
        /* Construct the method call message. */
23
 
        method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get");
24
 
        if (! method_call)
25
 
                nih_return_no_memory_error (-1);
26
 
 
27
 
        dbus_message_set_auto_start (method_call, proxy->auto_start);
28
 
 
29
 
        dbus_message_iter_init_append (method_call, &iter);
30
 
 
31
 
        interface = "com.netsplit.Nih.Test";
32
 
        if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {
33
 
                dbus_message_unref (method_call);
34
 
                nih_return_no_memory_error (-1);
35
 
        }
36
 
 
37
 
        property = "property";
38
 
        if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) {
39
 
                dbus_message_unref (method_call);
40
 
                nih_return_no_memory_error (-1);
41
 
        }
42
 
 
43
 
        /* Send the message, and wait for the reply. */
44
 
        dbus_error_init (&error);
45
 
 
46
 
        reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);
47
 
        if (! reply) {
48
 
                dbus_message_unref (method_call);
49
 
 
50
 
                if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {
51
 
                        nih_error_raise_no_memory ();
52
 
                } else {
53
 
                        nih_dbus_error_raise (error.name, error.message);
54
 
                }
55
 
 
56
 
                dbus_error_free (&error);
57
 
                return -1;
58
 
        }
59
 
 
60
 
        dbus_message_unref (method_call);
61
 
 
62
 
        /* Iterate the method arguments, recursing into the variant */
63
 
        dbus_message_iter_init (reply, &iter);
64
 
 
65
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) {
66
 
                dbus_message_unref (reply);
67
 
                nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
68
 
                                  _(NIH_DBUS_INVALID_ARGS_STR));
69
 
        }
70
 
 
71
 
        dbus_message_iter_recurse (&iter, &variter);
72
 
 
73
 
        dbus_message_iter_next (&iter);
74
 
 
75
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
76
 
                dbus_message_unref (reply);
77
 
                nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
78
 
                                  _(NIH_DBUS_INVALID_ARGS_STR));
79
 
        }
80
 
 
81
 
        do {
82
 
                __label__ enomem;
83
 
 
84
 
                /* Demarshal a structure from the message */
85
 
                if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) {
86
 
                        dbus_message_unref (reply);
87
 
                        nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
88
 
                                          _(NIH_DBUS_INVALID_ARGS_STR));
89
 
                }
90
 
 
91
 
                dbus_message_iter_recurse (&variter, &local_iter);
92
 
 
93
 
                local = nih_new (parent, MyProperty);
94
 
                if (! local) {
95
 
                        *value = NULL;
96
 
                        goto enomem;
97
 
                }
98
 
 
99
 
                /* Demarshal a char * from the message */
100
 
                if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_STRING) {
101
 
                        nih_free (local);
102
 
                        dbus_message_unref (reply);
103
 
                        nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
104
 
                                          _(NIH_DBUS_INVALID_ARGS_STR));
105
 
                }
106
 
 
107
 
                dbus_message_iter_get_basic (&local_iter, &local_item0_dbus);
108
 
 
109
 
                local_item0 = nih_strdup (local, local_item0_dbus);
110
 
                if (! local_item0) {
111
 
                        nih_free (local);
112
 
                        *value = NULL;
113
 
                        goto enomem;
114
 
                }
115
 
 
116
 
                dbus_message_iter_next (&local_iter);
117
 
 
118
 
                local->item0 = local_item0;
119
 
 
120
 
                /* Demarshal a uint32_t from the message */
121
 
                if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_UINT32) {
122
 
                        nih_free (local);
123
 
                        dbus_message_unref (reply);
124
 
                        nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
125
 
                                          _(NIH_DBUS_INVALID_ARGS_STR));
126
 
                }
127
 
 
128
 
                dbus_message_iter_get_basic (&local_iter, &local_item1);
129
 
 
130
 
                dbus_message_iter_next (&local_iter);
131
 
 
132
 
                local->item1 = local_item1;
133
 
 
134
 
                if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_INVALID) {
135
 
                        nih_free (local);
136
 
                        dbus_message_unref (reply);
137
 
                        nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
138
 
                                          _(NIH_DBUS_INVALID_ARGS_STR));
139
 
                }
140
 
 
141
 
                dbus_message_iter_next (&variter);
142
 
 
143
 
                *value = local;
144
 
        enomem: __attribute__ ((unused));
145
 
        } while (! *value);
146
 
 
147
 
        dbus_message_unref (reply);
148
 
 
149
 
        return 0;
150
 
}