|
@@ -15,7 +15,7 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
#include <assert.h>
|
|
#include <assert.h>
|
|
-#include <dbus/dbus.h>
|
|
|
|
|
|
+#include <gio/gio.h>
|
|
#include "bmem.h"
|
|
#include "bmem.h"
|
|
|
|
|
|
/* NOTE: This is basically just the VLC implementation from its d-bus power
|
|
/* NOTE: This is basically just the VLC implementation from its d-bus power
|
|
@@ -66,22 +66,15 @@ static const size_t num_services =
|
|
|
|
|
|
struct dbus_sleep_info {
|
|
struct dbus_sleep_info {
|
|
const struct service_info *service;
|
|
const struct service_info *service;
|
|
- DBusPendingCall *pending;
|
|
|
|
- DBusConnection *c;
|
|
|
|
- dbus_uint32_t cookie;
|
|
|
|
|
|
+ GDBusConnection *c;
|
|
|
|
+ uint32_t cookie;
|
|
enum service_type type;
|
|
enum service_type type;
|
|
};
|
|
};
|
|
|
|
|
|
void dbus_sleep_info_destroy(struct dbus_sleep_info *info)
|
|
void dbus_sleep_info_destroy(struct dbus_sleep_info *info)
|
|
{
|
|
{
|
|
if (info) {
|
|
if (info) {
|
|
- if (info->pending) {
|
|
|
|
- dbus_pending_call_cancel(info->pending);
|
|
|
|
- dbus_pending_call_unref(info->pending);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dbus_connection_close(info->c);
|
|
|
|
- dbus_connection_unref(info->c);
|
|
|
|
|
|
+ g_clear_object(&info->c);
|
|
bfree(info);
|
|
bfree(info);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -89,25 +82,30 @@ void dbus_sleep_info_destroy(struct dbus_sleep_info *info)
|
|
struct dbus_sleep_info *dbus_sleep_info_create(void)
|
|
struct dbus_sleep_info *dbus_sleep_info_create(void)
|
|
{
|
|
{
|
|
struct dbus_sleep_info *info = bzalloc(sizeof(*info));
|
|
struct dbus_sleep_info *info = bzalloc(sizeof(*info));
|
|
- DBusError err;
|
|
|
|
|
|
+ g_autoptr(GError) error = NULL;
|
|
|
|
|
|
- dbus_error_init(&err);
|
|
|
|
-
|
|
|
|
- info->c = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
|
|
|
|
|
|
+ info->c = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
|
|
if (!info->c) {
|
|
if (!info->c) {
|
|
blog(LOG_ERROR, "Could not create dbus connection: %s",
|
|
blog(LOG_ERROR, "Could not create dbus connection: %s",
|
|
- err.message);
|
|
|
|
|
|
+ error->message);
|
|
bfree(info);
|
|
bfree(info);
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
for (size_t i = 0; i < num_services; i++) {
|
|
for (size_t i = 0; i < num_services; i++) {
|
|
const struct service_info *service = &services[i];
|
|
const struct service_info *service = &services[i];
|
|
|
|
+ g_autoptr(GVariant) reply = NULL;
|
|
|
|
|
|
if (!service->name)
|
|
if (!service->name)
|
|
continue;
|
|
continue;
|
|
|
|
|
|
- if (dbus_bus_name_has_owner(info->c, service->name, NULL)) {
|
|
|
|
|
|
+ reply = g_dbus_connection_call_sync(
|
|
|
|
+ info->c, "org.freedesktop.DBus",
|
|
|
|
+ "/org/freedesktop/DBus", "org.freedesktop.DBus",
|
|
|
|
+ "GetNameOwner", g_variant_new("(s)", service->name),
|
|
|
|
+ NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, NULL);
|
|
|
|
+
|
|
|
|
+ if (reply != NULL) {
|
|
blog(LOG_DEBUG, "Found dbus service: %s",
|
|
blog(LOG_DEBUG, "Found dbus service: %s",
|
|
service->name);
|
|
service->name);
|
|
info->service = service;
|
|
info->service = service;
|
|
@@ -123,79 +121,52 @@ struct dbus_sleep_info *dbus_sleep_info_create(void)
|
|
void dbus_inhibit_sleep(struct dbus_sleep_info *info, const char *reason,
|
|
void dbus_inhibit_sleep(struct dbus_sleep_info *info, const char *reason,
|
|
bool active)
|
|
bool active)
|
|
{
|
|
{
|
|
- DBusMessage *reply;
|
|
|
|
|
|
+ g_autoptr(GVariant) reply = NULL;
|
|
|
|
+ g_autoptr(GError) error = NULL;
|
|
const char *method;
|
|
const char *method;
|
|
- dbus_bool_t success;
|
|
|
|
-
|
|
|
|
- if (info->pending) {
|
|
|
|
-
|
|
|
|
- dbus_pending_call_block(info->pending);
|
|
|
|
- reply = dbus_pending_call_steal_reply(info->pending);
|
|
|
|
- dbus_pending_call_unref(info->pending);
|
|
|
|
- info->pending = NULL;
|
|
|
|
-
|
|
|
|
- if (reply) {
|
|
|
|
- success = dbus_message_get_args(reply, NULL,
|
|
|
|
- DBUS_TYPE_UINT32,
|
|
|
|
- &info->cookie,
|
|
|
|
- DBUS_TYPE_INVALID);
|
|
|
|
- if (!success)
|
|
|
|
- info->cookie = 0;
|
|
|
|
- dbus_message_unref(reply);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ GVariant *params;
|
|
|
|
|
|
if (active == !!info->cookie)
|
|
if (active == !!info->cookie)
|
|
return;
|
|
return;
|
|
|
|
|
|
method = active ? "Inhibit" : info->service->uninhibit;
|
|
method = active ? "Inhibit" : info->service->uninhibit;
|
|
|
|
|
|
- reply = dbus_message_new_method_call(info->service->name,
|
|
|
|
- info->service->path,
|
|
|
|
- info->service->name, method);
|
|
|
|
- if (reply == NULL) {
|
|
|
|
- blog(LOG_ERROR, "dbus_message_new_method_call failed");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (active) {
|
|
if (active) {
|
|
const char *program = "libobs";
|
|
const char *program = "libobs";
|
|
- dbus_uint32_t flags = 0xC;
|
|
|
|
- dbus_uint32_t xid = 0;
|
|
|
|
|
|
+ uint32_t flags = 0xC;
|
|
|
|
+ uint32_t xid = 0;
|
|
|
|
|
|
assert(info->cookie == 0);
|
|
assert(info->cookie == 0);
|
|
|
|
|
|
switch (info->type) {
|
|
switch (info->type) {
|
|
case MATE_SM:
|
|
case MATE_SM:
|
|
case GNOME_SM:
|
|
case GNOME_SM:
|
|
- success = dbus_message_append_args(
|
|
|
|
- reply, DBUS_TYPE_STRING, &program,
|
|
|
|
- DBUS_TYPE_UINT32, &xid, DBUS_TYPE_STRING,
|
|
|
|
- &reason, DBUS_TYPE_UINT32, &flags,
|
|
|
|
- DBUS_TYPE_INVALID);
|
|
|
|
|
|
+ params = g_variant_new("(s@usu)", program,
|
|
|
|
+ g_variant_new_uint32(xid),
|
|
|
|
+ reason, flags);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- success = dbus_message_append_args(
|
|
|
|
- reply, DBUS_TYPE_STRING, &program,
|
|
|
|
- DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (success) {
|
|
|
|
- success = dbus_connection_send_with_reply(
|
|
|
|
- info->c, reply, &info->pending, -1);
|
|
|
|
- if (!success)
|
|
|
|
- info->pending = NULL;
|
|
|
|
|
|
+ params = g_variant_new("(ss)", program, reason);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
assert(info->cookie != 0);
|
|
assert(info->cookie != 0);
|
|
- success = dbus_message_append_args(
|
|
|
|
- reply, DBUS_TYPE_UINT32, &info->cookie, DBUS_TYPE_INVALID);
|
|
|
|
- if (success)
|
|
|
|
- success = dbus_connection_send(info->c, reply, NULL);
|
|
|
|
- if (!success)
|
|
|
|
- info->cookie = 0;
|
|
|
|
|
|
+ params = g_variant_new("(u)", info->cookie);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ reply = g_dbus_connection_call_sync(info->c, info->service->name,
|
|
|
|
+ info->service->path,
|
|
|
|
+ info->service->name, method, params,
|
|
|
|
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1,
|
|
|
|
+ NULL, &error);
|
|
|
|
+
|
|
|
|
+ if (error != NULL) {
|
|
|
|
+ blog(LOG_ERROR, "Failed to call %s: %s", method,
|
|
|
|
+ error->message);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
- dbus_connection_flush(info->c);
|
|
|
|
- dbus_message_unref(reply);
|
|
|
|
|
|
+ if (active)
|
|
|
|
+ g_variant_get(reply, "(u)", &info->cookie);
|
|
|
|
+ else
|
|
|
|
+ info->cookie = 0;
|
|
}
|
|
}
|