* of the thread that @connection was constructed in.
*
* This is an asynchronous method. When the operation is finished,
- * @callback will be invoked in the
+ * @callback will be invoked in the
* [thread-default main context][g-main-context-push-thread-default]
* of the thread you are calling this method from. You can
* then call g_dbus_connection_close_finish() to get the result of the
#ifdef G_OS_UNIX
if (connection->kdbus_worker)
- return _g_kdbus_StartServiceByName (connection->kdbus_worker, name, flags, error);
+ return _g_kdbus_StartServiceByName (connection->kdbus_worker, name, flags, NULL, error);
#endif
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
* the operation fails with %G_IO_ERROR_INVALID_ARGUMENT.
*
* This is an asynchronous method. When the operation is finished, @callback
- * will be invoked in the
+ * will be invoked in the
* [thread-default main context][g-main-context-push-thread-default]
* of the thread you are calling this method from. You can then call
* g_dbus_connection_send_message_with_reply_finish() to get the result of the operation.
* subscription is removed or %NULL
*
* Subscribes to signals on @connection and invokes @callback with a whenever
- * the signal is received. Note that @callback will be invoked in the
+ * the signal is received. Note that @callback will be invoked in the
* [thread-default main context][g-main-context-push-thread-default]
* of the thread you are calling this method from.
*
* D-Bus interface that is described in @interface_info.
*
* Calls to functions in @vtable (and @user_data_free_func) will happen
- * in the
+ * in the
* [thread-default main context][g-main-context-push-thread-default]
* of the thread you are calling this method from.
*
return sec_label;
}
+typedef struct
+{
+ GKDBusWorker *worker;
+ GDBusMessage *message;
+} SyntheticReplyData;
+
+static gboolean
+deliver_synthetic_reply (gpointer user_data)
+{
+ SyntheticReplyData *data;
+ GKDBusWorker *worker;
+ GDBusMessage *message;
+
+ data = user_data;
+ worker = data->worker;
+ message = data->message;
+
+ (* worker->message_received_callback) (message, worker->user_data);
+
+ g_object_unref (message);
+ g_free (data);
+
+ return FALSE;
+}
+
+static gboolean
+_g_kdbus_StartServiceByName_helper (gpointer user_data)
+{
+ SyntheticReplyData *data;
+ GKDBusWorker *worker;
+ GDBusMessage *message;
+ const gchar *name;
+ GDBusMessage *ping_message;
+ GDBusMessage *reply;
+ GError *local_error;
+ gboolean ret;
+ GVariant *body;
+
+ data = (SyntheticReplyData *)user_data;
+ worker = data->worker;
+ message = data->message;
+
+ name = NULL;
+ reply = NULL;
+ local_error = NULL;
+
+ body = g_dbus_message_get_body (message);
+ g_variant_get(body, "(su)", &name, NULL);
+
+ ping_message = g_dbus_message_new_method_call (name, "/", "org.freedesktop.DBus.Peer", "Ping");
+
+ g_dbus_message_set_serial (ping_message, -1);
+
+ /* check synchronous */
+ ret = _g_kdbus_send (worker, ping_message, &reply, 25000, NULL, NULL);
+ if (!ret)
+ {
+ gchar *dbus_error_name;
+
+ g_set_error (&local_error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_SERVICE_UNKNOWN,
+ "The name %s was not provided by any .service files", g_dbus_message_get_destination(message));
+
+ dbus_error_name = g_dbus_error_encode_gerror (local_error);
+ reply = g_dbus_message_new_method_error (message, dbus_error_name, "%s", local_error->message);
+
+ g_free (dbus_error_name);
+ g_error_free (local_error);
+ }
+ else
+ {
+ reply = g_dbus_message_new_method_reply (message);
+ g_dbus_message_set_body (reply, g_variant_new ("(u)", G_BUS_START_SERVICE_REPLY_SUCCESS));
+ }
+
+ g_dbus_message_set_serial (reply, -1);
+ data->message = reply;
+ g_main_context_invoke (worker->context, deliver_synthetic_reply, data);
+
+ g_free (name);
+ g_object_unref (ping_message);
+ g_object_unref (message);
+
+ return FALSE;
+}
/* < internal >
*
_g_kdbus_StartServiceByName (GKDBusWorker *worker,
const gchar *name,
guint32 flags,
+ GDBusMessage *message,
GError **error)
{
GBusStartServiceReplyFlags status;
if (!g_kdbus_NameHasOwner_internal (worker, name))
{
- GDBusMessage *message;
+ gboolean ret;
GDBusMessage *reply;
- gint ret;
+ gboolean sync;
reply = NULL;
+ status = G_BUS_START_SERVICE_REPLY_SUCCESS;
+ sync = message ? FALSE : TRUE;
- message = g_dbus_message_new_method_call (name, "/", "org.freedesktop.DBus.Peer", "Ping");
- g_dbus_message_set_serial (message, -1);
-
- ret = _g_kdbus_send (worker, message, &reply, 25000, NULL, NULL);
- if (!ret)
+ if (sync)
{
- g_set_error (error,
- G_DBUS_ERROR,
- G_DBUS_ERROR_SERVICE_UNKNOWN,
- "The name %s was not provided by any .service files", name);
- status = G_BUS_START_SERVICE_REPLY_ERROR;
+ GDBusMessage *ping_message;
+
+ ping_message = g_dbus_message_new_method_call (name, "/", "org.freedesktop.DBus.Peer", "Ping");
+ g_dbus_message_set_serial (ping_message, -1);
+
+ ret = _g_kdbus_send (worker, ping_message, &reply, 25000, NULL, NULL);
+ g_object_unref (reply);
+
+ if (!ret)
+ {
+ status = G_BUS_START_SERVICE_REPLY_ERROR;
+
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_SERVICE_UNKNOWN,
+ "The name %s was not provided by any .service files", name);
+ }
+ g_object_unref (ping_message);
}
else
{
- g_object_unref (reply);
- status = G_BUS_START_SERVICE_REPLY_SUCCESS;
+ SyntheticReplyData *data;
+
+ data = g_new0 (SyntheticReplyData, 1);
+
+ data->worker = worker;
+ data->message = g_object_ref (message);
+
+ g_main_context_invoke (worker->context, _g_kdbus_StartServiceByName_helper, data);
}
- g_object_unref (message);
}
else
status = G_BUS_START_SERVICE_REPLY_ALREADY_RUNNING;
return sizeof (struct kdbus_msg) + items_size;
}
-typedef struct
-{
- GKDBusWorker *worker;
- GDBusMessage *message;
-} SyntheticReplyData;
-
-static gboolean
-deliver_synthetic_reply (gpointer user_data)
-{
- SyntheticReplyData *data;
- GKDBusWorker *worker;
- GDBusMessage *message;
-
- data = user_data;
- worker = data->worker;
- message = data->message;
-
- (* worker->message_received_callback) (message, worker->user_data);
-
- g_object_unref (message);
- g_free (data);
-
- return FALSE;
-}
-
#ifdef LIBDBUSPOLICY
static GDBusMessage*
create_access_error_reply (GDBusMessage *message,
#ifdef DBUS_DAEMON_EMULATION
if (_is_message_to_dbus_daemon (message))
{
- SyntheticReplyData *data;
+ GDBusMessage *reply = NULL;
+ reply = _dbus_daemon_synthetic_reply (worker, message, FALSE);
- data = g_new0 (SyntheticReplyData, 1);
+ if (reply)
+ {
+ SyntheticReplyData *data;
+
+ data = g_new0 (SyntheticReplyData, 1);
- data->worker = worker;
- data->message = _dbus_daemon_synthetic_reply (worker, message);
+ data->worker = worker;
+ data->message = reply;
- g_main_context_invoke (worker->context, deliver_synthetic_reply, data);
+ g_main_context_invoke (worker->context, deliver_synthetic_reply, data);
+ }
return TRUE;
}
#ifdef DBUS_DAEMON_EMULATION
if (_is_message_to_dbus_daemon (message))
{
- *out_reply = _dbus_daemon_synthetic_reply (worker, message);
+ *out_reply = _dbus_daemon_synthetic_reply (worker, message, TRUE);
return TRUE;
}
#endif /* DBUS_DAEMON_EMULATION */