[gnome-applets] cpufreq: port to GDBus
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets] cpufreq: port to GDBus
- Date: Tue, 13 Dec 2016 18:08:49 +0000 (UTC)
commit ed5418eed57cb00976603923d2ccf2b1b8acddf4
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Dec 13 17:45:10 2016 +0200
cpufreq: port to GDBus
cpufreq/src/Makefile.am | 2 -
cpufreq/src/cpufreq-selector.c | 146 ++++++++++++++++++++++++++--------------
cpufreq/src/cpufreq-utils.c | 42 +++++++----
3 files changed, 122 insertions(+), 68 deletions(-)
---
diff --git a/cpufreq/src/Makefile.am b/cpufreq/src/Makefile.am
index 89d1074..de84a5f 100644
--- a/cpufreq/src/Makefile.am
+++ b/cpufreq/src/Makefile.am
@@ -21,7 +21,6 @@ libcpu_frequency_applet_la_CPPFLAGS = \
libcpu_frequency_applet_la_CFLAGS = \
$(GNOME_APPLETS_CFLAGS) \
$(LIBGLADE_CFLAGS) \
- $(DBUS_CFLAGS) \
$(WARN_CFLAGS) \
$(AM_CFLAGS) \
$(NULL)
@@ -51,7 +50,6 @@ libcpu_frequency_applet_la_LIBADD = \
$(GNOME_APPLETS_LIBS) \
$(LIBGLADE_LIBS) \
$(LIBCPUFREQ_LIBS) \
- $(DBUS_LIBS) \
$(NULL)
-include $(top_srcdir)/git.mk
diff --git a/cpufreq/src/cpufreq-selector.c b/cpufreq/src/cpufreq-selector.c
index 9697f61..5e79370 100644
--- a/cpufreq/src/cpufreq-selector.c
+++ b/cpufreq/src/cpufreq-selector.c
@@ -16,11 +16,9 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
+#include "config.h"
-#ifdef HAVE_POLKIT
-#include <dbus/dbus-glib.h>
-#endif /* HAVE_POLKIT */
+#include <gio/gio.h>
#include "cpufreq-selector.h"
@@ -28,7 +26,8 @@ struct _CPUFreqSelector {
GObject parent;
#ifdef HAVE_POLKIT
- DBusGConnection *system_bus;
+ GDBusConnection *system_bus;
+ GDBusProxy *proxy;
#endif /* HAVE_POLKIT */
};
@@ -44,7 +43,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);
@@ -92,9 +92,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)
{
@@ -112,36 +109,55 @@ 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.gnome.CPUFreqSelector",
+ "/org/gnome/cpufreq_selector/selector",
+ "org.gnome.CPUFreqSelector",
+ NULL,
+ error);
+
+ return (selector->proxy != NULL);
+}
+
static void
-dbus_set_call_notify_cb (DBusGProxy *proxy,
- DBusGProxyCall *call,
- gpointer user_data)
+set_frequency_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
SelectorAsyncData *data;
- GError *error = NULL;
+ GError *error;
- data = (SelectorAsyncData *)user_data;
-
- if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) {
- selector_async_data_free (data);
- return;
+ data = (SelectorAsyncData *) user_data;
+
+ error = NULL;
+ g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (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);
@@ -152,19 +168,23 @@ selector_set_frequency_async (SelectorAsyncData *data)
return;
}
- proxy = dbus_g_proxy_new_for_name (data->selector->system_bus,
- "org.gnome.CPUFreqSelector",
- "/org/gnome/cpufreq_selector/selector",
- "org.gnome.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,
+ G_MAXINT,
+ NULL,
+ set_frequency_cb,
+ data);
}
void
@@ -187,10 +207,30 @@ cpufreq_selector_set_frequency_async (CPUFreqSelector *selector,
}
static void
+set_governor_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ SelectorAsyncData *data;
+ GError *error;
+
+ data = (SelectorAsyncData *) user_data;
+
+ error = NULL;
+ g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ selector_async_data_free (data);
+}
+
+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);
@@ -201,19 +241,23 @@ selector_set_governor_async (SelectorAsyncData *data)
return;
}
- proxy = dbus_g_proxy_new_for_name (data->selector->system_bus,
- "org.gnome.CPUFreqSelector",
- "/org/gnome/cpufreq_selector/selector",
- "org.gnome.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,
+ G_MAXINT,
+ NULL,
+ set_governor_cb,
+ data);
}
void
diff --git a/cpufreq/src/cpufreq-utils.c b/cpufreq/src/cpufreq-utils.c
index f5cd2f1..7fc7386 100644
--- a/cpufreq/src/cpufreq-utils.c
+++ b/cpufreq/src/cpufreq-utils.c
@@ -31,10 +31,6 @@
#include "cpufreq-utils.h"
-#ifdef HAVE_POLKIT
-#include <dbus/dbus-glib.h>
-#endif /* HAVE_POLKIT */
-
guint
cpufreq_utils_get_n_cpus (void)
{
@@ -110,13 +106,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);
@@ -125,18 +122,33 @@ selector_is_available (void)
}
}
- proxy = dbus_g_proxy_new_for_name (system_bus,
- "org.gnome.CPUFreqSelector",
- "/org/gnome/cpufreq_selector/selector",
- "org.gnome.CPUFreqSelector");
+ proxy = g_dbus_proxy_new_sync (system_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.gnome.CPUFreqSelector",
+ "/org/gnome/cpufreq_selector/selector",
+ "org.gnome.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.gnome.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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]