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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
DBusHandlerResult
my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object,
NihDBusMessage *message)
{
DBusMessageIter iter;
DBusMessage * reply;
MyMethodStructure *structure;
DBusMessageIter structure_iter;
const char * structure_item0_dbus;
char * structure_item0;
uint32_t structure_item1;
nih_assert (object != NULL);
nih_assert (message != NULL);
/* Iterate the arguments to the message and demarshal into arguments
* for our own function call.
*/
dbus_message_iter_init (message->message, &iter);
/* Demarshal a structure from the message */
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) {
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
"Invalid arguments to Method method");
if (! reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (! dbus_connection_send (message->connection, reply, NULL)) {
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_iter_recurse (&iter, &structure_iter);
structure = nih_new (message, MyMethodStructure);
if (! structure) {
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
/* Demarshal a char * from the message */
if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_STRING) {
nih_free (structure);
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
"Invalid arguments to Method method");
if (! reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (! dbus_connection_send (message->connection, reply, NULL)) {
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_iter_get_basic (&structure_iter, &structure_item0_dbus);
structure_item0 = nih_strdup (structure, structure_item0_dbus);
if (! structure_item0) {
nih_free (structure);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
dbus_message_iter_next (&structure_iter);
structure->item0 = structure_item0;
/* Demarshal a uint32_t from the message */
if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_UINT32) {
nih_free (structure);
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
"Invalid arguments to Method method");
if (! reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (! dbus_connection_send (message->connection, reply, NULL)) {
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_iter_get_basic (&structure_iter, &structure_item1);
dbus_message_iter_next (&structure_iter);
structure->item1 = structure_item1;
if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_INVALID) {
nih_free (structure);
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
"Invalid arguments to Method method");
if (! reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (! dbus_connection_send (message->connection, reply, NULL)) {
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_iter_next (&iter);
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
"Invalid arguments to Method method");
if (! reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (! dbus_connection_send (message->connection, reply, NULL)) {
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
/* Call the handler function */
nih_error_push_context ();
if (my_method (object->data, message, structure) < 0) {
NihError *err;
err = nih_error_get ();
if (err->number == ENOMEM) {
nih_free (err);
nih_error_pop_context ();
return DBUS_HANDLER_RESULT_NEED_MEMORY;
} else if (err->number == NIH_DBUS_ERROR) {
NihDBusError *dbus_err = (NihDBusError *)err;
reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
nih_free (err);
nih_error_pop_context ();
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
} else {
reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
nih_free (err);
nih_error_pop_context ();
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
}
nih_error_pop_context ();
/* 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 DBUS_HANDLER_RESULT_HANDLED;
do {
__label__ enomem;
/* Construct the reply message. */
reply = dbus_message_new_method_return (message->message);
if (! reply)
goto enomem;
dbus_message_iter_init_append (reply, &iter);
enomem: __attribute__ ((unused));
} while (! reply);
/* Send the reply, appending it to the outgoing queue. */
NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
|