[gnome-settings-daemon/wip/benzea/cleanups-and-small-fixes] rfkill: Use G_DEFINE_FINAL_TYPE for GsdRfkillManager
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/benzea/cleanups-and-small-fixes] rfkill: Use G_DEFINE_FINAL_TYPE for GsdRfkillManager
- Date: Wed, 20 Feb 2019 17:47:16 +0000 (UTC)
commit fce20fc4017c180132e582f0bd290c034f29a669
Author: Benjamin Berg <bberg redhat com>
Date: Wed Feb 20 17:50:57 2019 +0100
rfkill: Use G_DEFINE_FINAL_TYPE for GsdRfkillManager
plugins/rfkill/gsd-rfkill-manager.c | 163 +++++++++++++++++-------------------
plugins/rfkill/gsd-rfkill-manager.h | 22 +----
2 files changed, 81 insertions(+), 104 deletions(-)
---
diff --git a/plugins/rfkill/gsd-rfkill-manager.c b/plugins/rfkill/gsd-rfkill-manager.c
index a4e03560..5ad560eb 100644
--- a/plugins/rfkill/gsd-rfkill-manager.c
+++ b/plugins/rfkill/gsd-rfkill-manager.c
@@ -50,10 +50,10 @@
#include "rfkill-glib.h"
#include "gnome-settings-bus.h"
-#define GSD_RFKILL_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_RFKILL_MANAGER,
GsdRfkillManagerPrivate))
-
-struct GsdRfkillManagerPrivate
+struct _GsdRfkillManager
{
+ GObject parent;
+
GDBusNodeInfo *introspection_data;
guint name_id;
GDBusConnection *connection;
@@ -117,14 +117,11 @@ gsd_rfkill_manager_class_init (GsdRfkillManagerClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gsd_rfkill_manager_finalize;
-
- g_type_class_add_private (klass, sizeof (GsdRfkillManagerPrivate));
}
static void
gsd_rfkill_manager_init (GsdRfkillManager *manager)
{
- manager->priv = GSD_RFKILL_MANAGER_GET_PRIVATE (manager);
}
static gboolean
@@ -153,7 +150,7 @@ engine_get_airplane_mode_helper (GHashTable *killswitches)
static gboolean
engine_get_bluetooth_airplane_mode (GsdRfkillManager *manager)
{
- return engine_get_airplane_mode_helper (manager->priv->bt_killswitches);
+ return engine_get_airplane_mode_helper (manager->bt_killswitches);
}
static gboolean
@@ -163,10 +160,10 @@ engine_get_bluetooth_hardware_airplane_mode (GsdRfkillManager *manager)
gpointer key, value;
/* If we have no killswitches, hw airplane mode is off. */
- if (g_hash_table_size (manager->priv->bt_killswitches) == 0)
+ if (g_hash_table_size (manager->bt_killswitches) == 0)
return FALSE;
- g_hash_table_iter_init (&iter, manager->priv->bt_killswitches);
+ g_hash_table_iter_init (&iter, manager->bt_killswitches);
while (g_hash_table_iter_next (&iter, &key, &value)) {
int state;
@@ -184,17 +181,17 @@ engine_get_bluetooth_hardware_airplane_mode (GsdRfkillManager *manager)
static gboolean
engine_get_has_bluetooth_airplane_mode (GsdRfkillManager *manager)
{
- return (g_hash_table_size (manager->priv->bt_killswitches) > 0);
+ return (g_hash_table_size (manager->bt_killswitches) > 0);
}
static gboolean
engine_get_airplane_mode (GsdRfkillManager *manager)
{
- if (!manager->priv->wwan_interesting)
- return engine_get_airplane_mode_helper (manager->priv->killswitches);
+ if (!manager->wwan_interesting)
+ return engine_get_airplane_mode_helper (manager->killswitches);
/* wwan enabled? then airplane mode is off (because an USB modem
could be on in this state) */
- return engine_get_airplane_mode_helper (manager->priv->killswitches) && !manager->priv->wwan_enabled;
+ return engine_get_airplane_mode_helper (manager->killswitches) && !manager->wwan_enabled;
}
static gboolean
@@ -204,10 +201,10 @@ engine_get_hardware_airplane_mode (GsdRfkillManager *manager)
gpointer key, value;
/* If we have no killswitches, hw airplane mode is off. */
- if (g_hash_table_size (manager->priv->killswitches) == 0)
+ if (g_hash_table_size (manager->killswitches) == 0)
return FALSE;
- g_hash_table_iter_init (&iter, manager->priv->killswitches);
+ g_hash_table_iter_init (&iter, manager->killswitches);
while (g_hash_table_iter_next (&iter, &key, &value)) {
int state;
@@ -225,17 +222,17 @@ engine_get_hardware_airplane_mode (GsdRfkillManager *manager)
static gboolean
engine_get_has_airplane_mode (GsdRfkillManager *manager)
{
- return (g_hash_table_size (manager->priv->killswitches) > 0) ||
- manager->priv->wwan_interesting;
+ return (g_hash_table_size (manager->killswitches) > 0) ||
+ manager->wwan_interesting;
}
static gboolean
engine_get_should_show_airplane_mode (GsdRfkillManager *manager)
{
- return (g_strcmp0 (manager->priv->chassis_type, "desktop") != 0) &&
- (g_strcmp0 (manager->priv->chassis_type, "server") != 0) &&
- (g_strcmp0 (manager->priv->chassis_type, "vm") != 0) &&
- (g_strcmp0 (manager->priv->chassis_type, "container") != 0);
+ return (g_strcmp0 (manager->chassis_type, "desktop") != 0) &&
+ (g_strcmp0 (manager->chassis_type, "server") != 0) &&
+ (g_strcmp0 (manager->chassis_type, "vm") != 0) &&
+ (g_strcmp0 (manager->chassis_type, "container") != 0);
}
static void
@@ -245,7 +242,7 @@ engine_properties_changed (GsdRfkillManager *manager)
GVariant *props_changed = NULL;
/* not yet connected to the session bus */
- if (manager->priv->connection == NULL)
+ if (manager->connection == NULL)
return;
g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}"));
@@ -269,7 +266,7 @@ engine_properties_changed (GsdRfkillManager *manager)
g_variant_builder_end (&props_builder),
g_variant_new_strv (NULL, 0));
- g_dbus_connection_emit_signal (manager->priv->connection,
+ g_dbus_connection_emit_signal (manager->connection,
NULL,
GSD_RFKILL_DBUS_PATH,
"org.freedesktop.DBus.Properties",
@@ -298,11 +295,11 @@ rfkill_changed (CcRfkillGlib *rfkill,
else
value = RFKILL_STATE_UNBLOCKED;
- g_hash_table_insert (manager->priv->killswitches,
+ g_hash_table_insert (manager->killswitches,
GINT_TO_POINTER (event->idx),
GINT_TO_POINTER (value));
if (event->type == RFKILL_TYPE_BLUETOOTH)
- g_hash_table_insert (manager->priv->bt_killswitches,
+ g_hash_table_insert (manager->bt_killswitches,
GINT_TO_POINTER (event->idx),
GINT_TO_POINTER (value));
g_debug ("%s %srfkill with ID %d",
@@ -311,10 +308,10 @@ rfkill_changed (CcRfkillGlib *rfkill,
event->idx);
break;
case RFKILL_OP_DEL:
- g_hash_table_remove (manager->priv->killswitches,
+ g_hash_table_remove (manager->killswitches,
GINT_TO_POINTER (event->idx));
if (event->type == RFKILL_TYPE_BLUETOOTH)
- g_hash_table_remove (manager->priv->bt_killswitches,
+ g_hash_table_remove (manager->bt_killswitches,
GINT_TO_POINTER (event->idx));
g_debug ("Removed %srfkill with ID %d", event->type == RFKILL_TYPE_BLUETOOTH ?
"Bluetooth " : "",
event->idx);
@@ -368,8 +365,8 @@ static gboolean
engine_set_bluetooth_airplane_mode (GsdRfkillManager *manager,
gboolean enable)
{
- cc_rfkill_glib_send_change_all_event (manager->priv->rfkill, RFKILL_TYPE_BLUETOOTH,
- enable, manager->priv->cancellable, rfkill_set_cb, manager);
+ cc_rfkill_glib_send_change_all_event (manager->rfkill, RFKILL_TYPE_BLUETOOTH,
+ enable, manager->cancellable, rfkill_set_cb, manager);
return TRUE;
}
@@ -378,13 +375,13 @@ static gboolean
engine_set_airplane_mode (GsdRfkillManager *manager,
gboolean enable)
{
- cc_rfkill_glib_send_change_all_event (manager->priv->rfkill, RFKILL_TYPE_ALL,
- enable, manager->priv->cancellable, rfkill_set_cb, manager);
+ cc_rfkill_glib_send_change_all_event (manager->rfkill, RFKILL_TYPE_ALL,
+ enable, manager->cancellable, rfkill_set_cb, manager);
/* Note: we set the the NM property even if there are no modems, so we don't
need to resync when one is plugged in */
- if (manager->priv->nm_client) {
- g_dbus_proxy_call (manager->priv->nm_client,
+ if (manager->nm_client) {
+ g_dbus_proxy_call (manager->nm_client,
"org.freedesktop.DBus.Properties.Set",
g_variant_new ("(ssv)",
"org.freedesktop.NetworkManager",
@@ -392,7 +389,7 @@ engine_set_airplane_mode (GsdRfkillManager *manager,
g_variant_new_boolean (!enable)),
G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout */
- manager->priv->cancellable,
+ manager->cancellable,
set_wwan_complete, NULL);
}
@@ -437,7 +434,7 @@ handle_get_property (GDBusConnection *connection,
/* Check session pointer as a proxy for whether the manager is in the
start or stop state */
- if (manager->priv->connection == NULL) {
+ if (manager->connection == NULL) {
return NULL;
}
@@ -508,17 +505,17 @@ on_bus_gotten (GObject *source_object,
g_error_free (error);
return;
}
- manager->priv->connection = connection;
+ manager->connection = connection;
g_dbus_connection_register_object (connection,
GSD_RFKILL_DBUS_PATH,
- manager->priv->introspection_data->interfaces[0],
+ manager->introspection_data->interfaces[0],
&interface_vtable,
manager,
NULL,
NULL);
- manager->priv->name_id = g_bus_own_name_on_connection (connection,
+ manager->name_id = g_bus_own_name_on_connection (connection,
GSD_RFKILL_DBUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
NULL,
@@ -526,9 +523,9 @@ on_bus_gotten (GObject *source_object,
NULL,
NULL);
- manager->priv->session = gnome_settings_bus_get_session_proxy ();
- manager->priv->rfkill_input_inhibit_binding = g_object_bind_property (manager->priv->session,
"session-is-active",
- manager->priv->rfkill,
"rfkill-input-inhibited",
+ manager->session = gnome_settings_bus_get_session_proxy ();
+ manager->rfkill_input_inhibit_binding = g_object_bind_property (manager->session,
"session-is-active",
+ manager->rfkill,
"rfkill-input-inhibited",
G_BINDING_SYNC_CREATE);
}
@@ -537,7 +534,7 @@ sync_wwan_enabled (GsdRfkillManager *manager)
{
GVariant *property;
- property = g_dbus_proxy_get_cached_property (manager->priv->nm_client,
+ property = g_dbus_proxy_get_cached_property (manager->nm_client,
"WwanEnabled");
if (property == NULL) {
@@ -545,7 +542,7 @@ sync_wwan_enabled (GsdRfkillManager *manager)
return;
}
- manager->priv->wwan_enabled = g_variant_get_boolean (property);
+ manager->wwan_enabled = g_variant_get_boolean (property);
engine_properties_changed (manager);
g_variant_unref (property);
@@ -597,9 +594,9 @@ on_nm_proxy_gotten (GObject *source,
goto out;
}
- manager->priv->nm_client = proxy;
+ manager->nm_client = proxy;
- g_signal_connect (manager->priv->nm_client, "g-signal",
+ g_signal_connect (manager->nm_client, "g-signal",
G_CALLBACK (nm_signal), manager);
sync_wwan_enabled (manager);
@@ -617,7 +614,7 @@ sync_wwan_interesting (GDBusObjectManager *object_manager,
GList *objects;
objects = g_dbus_object_manager_get_objects (object_manager);
- manager->priv->wwan_interesting = (objects != NULL);
+ manager->wwan_interesting = (objects != NULL);
engine_properties_changed (manager);
g_list_free_full (objects, g_object_unref);
@@ -644,13 +641,13 @@ on_mm_proxy_gotten (GObject *source,
goto out;
}
- manager->priv->mm_client = proxy;
+ manager->mm_client = proxy;
- g_signal_connect (manager->priv->mm_client, "interface-added",
+ g_signal_connect (manager->mm_client, "interface-added",
G_CALLBACK (sync_wwan_interesting), manager);
- g_signal_connect (manager->priv->mm_client, "interface-removed",
+ g_signal_connect (manager->mm_client, "interface-removed",
G_CALLBACK (sync_wwan_interesting), manager);
- sync_wwan_interesting (manager->priv->mm_client, NULL, NULL, manager);
+ sync_wwan_interesting (manager->mm_client, NULL, NULL, manager);
out:
g_object_unref (manager);
@@ -664,23 +661,23 @@ gsd_rfkill_manager_start (GsdRfkillManager *manager,
gnome_settings_profile_start (NULL);
- manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
- g_assert (manager->priv->introspection_data != NULL);
+ manager->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+ g_assert (manager->introspection_data != NULL);
- manager->priv->killswitches = g_hash_table_new (g_direct_hash, g_direct_equal);
- manager->priv->bt_killswitches = g_hash_table_new (g_direct_hash, g_direct_equal);
- manager->priv->rfkill = cc_rfkill_glib_new ();
- g_signal_connect (G_OBJECT (manager->priv->rfkill), "changed",
+ manager->killswitches = g_hash_table_new (g_direct_hash, g_direct_equal);
+ manager->bt_killswitches = g_hash_table_new (g_direct_hash, g_direct_equal);
+ manager->rfkill = cc_rfkill_glib_new ();
+ g_signal_connect (G_OBJECT (manager->rfkill), "changed",
G_CALLBACK (rfkill_changed), manager);
- if (!cc_rfkill_glib_open (manager->priv->rfkill, &local_error)) {
+ if (!cc_rfkill_glib_open (manager->rfkill, &local_error)) {
g_warning ("Error setting up rfkill: %s", local_error->message);
g_clear_error (&local_error);
}
- manager->priv->cancellable = g_cancellable_new ();
+ manager->cancellable = g_cancellable_new ();
- manager->priv->chassis_type = gnome_settings_get_chassis_type ();
+ manager->chassis_type = gnome_settings_get_chassis_type ();
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
@@ -688,7 +685,7 @@ gsd_rfkill_manager_start (GsdRfkillManager *manager,
"org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
- manager->priv->cancellable,
+ manager->cancellable,
on_nm_proxy_gotten, g_object_ref (manager));
g_dbus_object_manager_client_new_for_bus (G_BUS_TYPE_SYSTEM,
@@ -696,12 +693,12 @@ gsd_rfkill_manager_start (GsdRfkillManager *manager,
"org.freedesktop.ModemManager1",
"/org/freedesktop/ModemManager1",
NULL, NULL, NULL, /* get_proxy_type and closure */
- manager->priv->cancellable,
+ manager->cancellable,
on_mm_proxy_gotten, g_object_ref (manager));
/* Start process of owning a D-Bus name */
g_bus_get (G_BUS_TYPE_SESSION,
- manager->priv->cancellable,
+ manager->cancellable,
(GAsyncReadyCallback) on_bus_gotten,
manager);
@@ -713,34 +710,32 @@ gsd_rfkill_manager_start (GsdRfkillManager *manager,
void
gsd_rfkill_manager_stop (GsdRfkillManager *manager)
{
- GsdRfkillManagerPrivate *p = manager->priv;
-
g_debug ("Stopping rfkill manager");
- if (manager->priv->name_id != 0) {
- g_bus_unown_name (manager->priv->name_id);
- manager->priv->name_id = 0;
+ if (manager->name_id != 0) {
+ g_bus_unown_name (manager->name_id);
+ manager->name_id = 0;
}
- g_clear_pointer (&p->introspection_data, g_dbus_node_info_unref);
- g_clear_object (&p->connection);
- g_clear_object (&p->rfkill_input_inhibit_binding);
- g_clear_object (&p->session);
- g_clear_object (&p->rfkill);
- g_clear_pointer (&p->killswitches, g_hash_table_destroy);
- g_clear_pointer (&p->bt_killswitches, g_hash_table_destroy);
-
- if (p->cancellable) {
- g_cancellable_cancel (p->cancellable);
- g_clear_object (&p->cancellable);
+ g_clear_pointer (&manager->introspection_data, g_dbus_node_info_unref);
+ g_clear_object (&manager->connection);
+ g_clear_object (&manager->rfkill_input_inhibit_binding);
+ g_clear_object (&manager->session);
+ g_clear_object (&manager->rfkill);
+ g_clear_pointer (&manager->killswitches, g_hash_table_destroy);
+ g_clear_pointer (&manager->bt_killswitches, g_hash_table_destroy);
+
+ if (manager->cancellable) {
+ g_cancellable_cancel (manager->cancellable);
+ g_clear_object (&manager->cancellable);
}
- g_clear_object (&p->nm_client);
- g_clear_object (&p->mm_client);
- p->wwan_enabled = FALSE;
- p->wwan_interesting = FALSE;
+ g_clear_object (&manager->nm_client);
+ g_clear_object (&manager->mm_client);
+ manager->wwan_enabled = FALSE;
+ manager->wwan_interesting = FALSE;
- g_clear_pointer (&p->chassis_type, g_free);
+ g_clear_pointer (&manager->chassis_type, g_free);
}
static void
@@ -753,7 +748,7 @@ gsd_rfkill_manager_finalize (GObject *object)
manager = GSD_RFKILL_MANAGER (object);
- g_return_if_fail (manager->priv != NULL);
+ g_return_if_fail (manager != NULL);
gsd_rfkill_manager_stop (manager);
diff --git a/plugins/rfkill/gsd-rfkill-manager.h b/plugins/rfkill/gsd-rfkill-manager.h
index c8a0c030..025a7d84 100644
--- a/plugins/rfkill/gsd-rfkill-manager.h
+++ b/plugins/rfkill/gsd-rfkill-manager.h
@@ -26,26 +26,8 @@
G_BEGIN_DECLS
#define GSD_TYPE_RFKILL_MANAGER (gsd_rfkill_manager_get_type ())
-#define GSD_RFKILL_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_RFKILL_MANAGER,
GsdRfkillManager))
-#define GSD_RFKILL_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_RFKILL_MANAGER,
GsdRfkillManagerClass))
-#define GSD_IS_RFKILL_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_RFKILL_MANAGER))
-#define GSD_IS_RFKILL_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_RFKILL_MANAGER))
-#define GSD_RFKILL_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_RFKILL_MANAGER,
GsdRfkillManagerClass))
-
-typedef struct GsdRfkillManagerPrivate GsdRfkillManagerPrivate;
-
-typedef struct
-{
- GObject parent;
- GsdRfkillManagerPrivate *priv;
-} GsdRfkillManager;
-
-typedef struct
-{
- GObjectClass parent_class;
-} GsdRfkillManagerClass;
-
-GType gsd_rfkill_manager_get_type (void);
+
+G_DECLARE_FINAL_TYPE (GsdRfkillManager, gsd_rfkill_manager, GSD, RFKILL_MANAGER, GObject)
GsdRfkillManager * gsd_rfkill_manager_new (void);
gboolean gsd_rfkill_manager_start (GsdRfkillManager *manager,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]