summaryrefslogtreecommitdiff
path: root/cpufreq
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-05-18 10:43:17 +0200
committerraveit65 <[email protected]>2020-05-21 20:22:59 +0200
commit5a4eaf4f6948401a7affa2aa63ed9038a9d5e1f6 (patch)
treed6b712bd47e55b77f02dd8bdd8765f4ce572694b /cpufreq
parentc77596c251b9964d177b72f4aea8139be31d1bfa (diff)
downloadmate-applets-5a4eaf4f6948401a7affa2aa63ed9038a9d5e1f6.tar.bz2
mate-applets-5a4eaf4f6948401a7affa2aa63ed9038a9d5e1f6.tar.xz
cpufreq: Port client of selector service to GDBus
https://gitlab.gnome.org/GNOME/gnome-applets/-/commit/ed5418eed57cb00976603923d2ccf2b1b8acddf4
Diffstat (limited to 'cpufreq')
-rw-r--r--cpufreq/src/Makefile.am8
-rw-r--r--cpufreq/src/cpufreq-selector.c127
-rw-r--r--cpufreq/src/cpufreq-utils.c46
3 files changed, 109 insertions, 72 deletions
diff --git a/cpufreq/src/Makefile.am b/cpufreq/src/Makefile.am
index af5982f9..83ed7faa 100644
--- a/cpufreq/src/Makefile.am
+++ b/cpufreq/src/Makefile.am
@@ -8,10 +8,6 @@ AM_CPPFLAGS = \
-DCPUFREQ_MENU_UI_DIR=\""$(datadir)/mate/ui"\" \
$(MATE_APPLETS4_CFLAGS)
-if HAVE_DBUS
-AM_CPPFLAGS += $(DBUS_CFLAGS)
-endif
-
libexec_PROGRAMS = mate-cpufreq-applet
if HAVE_LIBCPUFREQ
@@ -38,8 +34,4 @@ mate_cpufreq_applet_LDADD = \
$(MATE_APPLETS4_LIBS) \
$(LIBCPUFREQ_LIBS)
-if HAVE_DBUS
-mate_cpufreq_applet_LDADD += $(DBUS_LIBS)
-endif
-
-include $(top_srcdir)/git.mk
diff --git a/cpufreq/src/cpufreq-selector.c b/cpufreq/src/cpufreq-selector.c
index 59b3dabb..4bdac4df 100644
--- a/cpufreq/src/cpufreq-selector.c
+++ b/cpufreq/src/cpufreq-selector.c
@@ -21,7 +21,7 @@
#include <sys/sysinfo.h>
#ifdef HAVE_POLKIT
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#endif /* HAVE_POLKIT */
#include "cpufreq-selector.h"
@@ -30,7 +30,8 @@ struct _CPUFreqSelector {
GObject parent;
#ifdef HAVE_POLKIT
- DBusGConnection *system_bus;
+ GDBusConnection *system_bus;
+ GDBusProxy *proxy;
#endif /* HAVE_POLKIT */
};
@@ -46,7 +47,8 @@ cpufreq_selector_finalize (GObject *object)
CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
#ifdef HAVE_POLKIT
- selector->system_bus = NULL;
+ g_clear_object (&selector->proxy);
+ g_clear_object (&selector->system_bus);
#endif /* HAVE_POLKIT */
G_OBJECT_CLASS (cpufreq_selector_parent_class)->finalize (object);
@@ -84,7 +86,7 @@ typedef enum {
typedef struct {
CPUFreqSelector *selector;
-
+
CPUFreqSelectorCall call;
guint cpu;
@@ -94,9 +96,6 @@ typedef struct {
guint32 parent_xid;
} SelectorAsyncData;
-static void selector_set_frequency_async (SelectorAsyncData *data);
-static void selector_set_governor_async (SelectorAsyncData *data);
-
static void
selector_async_data_free (SelectorAsyncData *data)
{
@@ -114,36 +113,52 @@ cpufreq_selector_connect_to_system_bus (CPUFreqSelector *selector,
if (selector->system_bus)
return TRUE;
- selector->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
+ selector->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
return (selector->system_bus != NULL);
}
+
+static gboolean
+cpufreq_selector_create_proxy (CPUFreqSelector *selector,
+ GError **error)
+{
+ if (selector->proxy)
+ return TRUE;
+
+ selector->proxy = g_dbus_proxy_new_sync (selector->system_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.mate.CPUFreqSelector",
+ "/org/mate/cpufreq_selector/selector",
+ "org.mate.CPUFreqSelector",
+ NULL,
+ error);
+
+ return (selector->proxy != NULL);
+}
+
static void
-dbus_set_call_notify_cb (DBusGProxy *proxy,
- DBusGProxyCall *call,
- gpointer user_data)
+selector_setter_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- SelectorAsyncData *data;
- GError *error = NULL;
+ GDBusProxy *proxy = G_DBUS_PROXY (source);
+ SelectorAsyncData *data = (SelectorAsyncData *)user_data;
+ GError *error = NULL;
- data = (SelectorAsyncData *)user_data;
-
- if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) {
- selector_async_data_free (data);
- return;
+ g_dbus_proxy_call_finish (proxy, result, &error);
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
}
-
selector_async_data_free (data);
- g_warning ("%s", error->message);
- g_error_free (error);
}
static void
selector_set_frequency_async (SelectorAsyncData *data)
{
- DBusGProxy *proxy;
- GError *error = NULL;
+ GError *error = NULL;
if (!cpufreq_selector_connect_to_system_bus (data->selector, &error)) {
g_warning ("%s", error->message);
@@ -154,19 +169,24 @@ selector_set_frequency_async (SelectorAsyncData *data)
return;
}
- proxy = dbus_g_proxy_new_for_name (data->selector->system_bus,
- "org.mate.CPUFreqSelector",
- "/org/mate/cpufreq_selector/selector",
- "org.mate.CPUFreqSelector");
-
- dbus_g_proxy_begin_call_with_timeout (proxy, "SetFrequency",
- dbus_set_call_notify_cb,
- data, NULL,
- INT_MAX,
- G_TYPE_UINT, data->cpu,
- G_TYPE_UINT, data->frequency,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ if (!cpufreq_selector_create_proxy (data->selector, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ selector_async_data_free (data);
+ return;
+ }
+
+ g_dbus_proxy_call (data->selector->proxy,
+ "SetFrequency",
+ g_variant_new ("(uu)",
+ data->cpu,
+ data->frequency),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ selector_setter_cb,
+ data);
}
void
@@ -193,8 +213,7 @@ cpufreq_selector_set_frequency_async (CPUFreqSelector *selector,
static void
selector_set_governor_async (SelectorAsyncData *data)
{
- DBusGProxy *proxy;
- GError *error = NULL;
+ GError *error = NULL;
if (!cpufreq_selector_connect_to_system_bus (data->selector, &error)) {
g_warning ("%s", error->message);
@@ -205,19 +224,25 @@ selector_set_governor_async (SelectorAsyncData *data)
return;
}
- proxy = dbus_g_proxy_new_for_name (data->selector->system_bus,
- "org.mate.CPUFreqSelector",
- "/org/mate/cpufreq_selector/selector",
- "org.mate.CPUFreqSelector");
-
- dbus_g_proxy_begin_call_with_timeout (proxy, "SetGovernor",
- dbus_set_call_notify_cb,
- data, NULL,
- INT_MAX,
- G_TYPE_UINT, data->cpu,
- G_TYPE_STRING, data->governor,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ if (!cpufreq_selector_create_proxy (data->selector, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ selector_async_data_free (data);
+
+ return;
+ }
+
+ g_dbus_proxy_call (data->selector->proxy,
+ "SetGovernor",
+ g_variant_new ("(us)",
+ data->cpu,
+ data->governor),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ selector_setter_cb,
+ data);
}
void
diff --git a/cpufreq/src/cpufreq-utils.c b/cpufreq/src/cpufreq-utils.c
index 3e3325ca..7dd358fa 100644
--- a/cpufreq/src/cpufreq-utils.c
+++ b/cpufreq/src/cpufreq-utils.c
@@ -33,7 +33,7 @@
#include "cpufreq-utils.h"
#ifdef HAVE_POLKIT
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#endif /* HAVE_POLKIT */
guint
@@ -45,7 +45,7 @@ cpufreq_utils_get_n_cpus (void)
if (n_cpus > 0)
return n_cpus;
-
+
do {
if (file)
g_free (file);
@@ -111,13 +111,14 @@ cpufreq_utils_display_error (const gchar *message,
static gboolean
selector_is_available (void)
{
- DBusGProxy *proxy;
- static DBusGConnection *system_bus = NULL;
+ GDBusProxy *proxy;
+ static GDBusConnection *system_bus = NULL;
GError *error = NULL;
+ GVariant *reply;
gboolean result;
if (!system_bus) {
- system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!system_bus) {
g_warning ("%s", error->message);
g_error_free (error);
@@ -126,18 +127,37 @@ selector_is_available (void)
}
}
- proxy = dbus_g_proxy_new_for_name (system_bus,
- "org.mate.CPUFreqSelector",
- "/org/mate/cpufreq_selector/selector",
- "org.mate.CPUFreqSelector");
+ proxy = g_dbus_proxy_new_sync (system_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.mate.CPUFreqSelector",
+ "/org/mate/cpufreq_selector/selector",
+ "org.mate.CPUFreqSelector",
+ NULL,
+ &error);
+
+ if (!proxy) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ reply = g_dbus_proxy_call_sync (proxy,
+ "CanSet",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
- if (!dbus_g_proxy_call (proxy, "CanSet", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &result,
- G_TYPE_INVALID)) {
+ if (!reply) {
g_warning ("Error calling org.mate.CPUFreqSelector.CanSet: %s", error->message);
g_error_free (error);
result = FALSE;
+ } else {
+ g_variant_get (reply, "(b)", &result);
+ g_variant_unref (reply);
}
g_object_unref (proxy);