Back to index

indicator-power  12.10.0
Classes | Defines | Enumerations | Functions | Variables
dbus-listener.c File Reference
#include "dbus-listener.h"
#include "device.h"

Go to the source code of this file.

Classes

struct  _IndicatorPowerDbusListenerPrivate

Defines

#define INDICATOR_POWER_DBUS_LISTENER_GET_PRIVATE(o)   (INDICATOR_POWER_DBUS_LISTENER(o)->priv)

Enumerations

enum  { SIGNAL_DEVICES, SIGNAL_LAST }

Functions

static void indicator_power_dbus_listener_class_init (IndicatorPowerDbusListenerClass *klass)
static void indicator_power_dbus_listener_init (IndicatorPowerDbusListener *self)
static void indicator_power_dbus_listener_dispose (GObject *object)
static void indicator_power_dbus_listener_finalize (GObject *object)
static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
 G_DEFINE_TYPE (IndicatorPowerDbusListener, indicator_power_dbus_listener, G_TYPE_OBJECT)
static void get_devices_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
static void request_device_list (IndicatorPowerDbusListener *self)
static void receive_properties_changed (GDBusProxy *proxy G_GNUC_UNUSED, GVariant *changed_properties G_GNUC_UNUSED, GStrv invalidated_properties G_GNUC_UNUSED, gpointer user_data)
static void service_proxy_cb (GObject *object, GAsyncResult *res, gpointer user_data)

Variables

static guint signals [SIGNAL_LAST] = { 0 }

Class Documentation

struct _IndicatorPowerDbusListenerPrivate

Definition at line 27 of file dbus-listener.c.

Class Members
GCancellable * cancellable
GDBusProxy * proxy
guint watcher_id

Define Documentation

Definition at line 34 of file dbus-listener.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
SIGNAL_DEVICES 
SIGNAL_LAST 

Definition at line 37 of file dbus-listener.c.


Function Documentation

G_DEFINE_TYPE ( IndicatorPowerDbusListener  ,
indicator_power_dbus_listener  ,
G_TYPE_OBJECT   
)
static void get_devices_cb ( GObject *  source_object,
GAsyncResult *  res,
gpointer  user_data 
) [static]

Definition at line 140 of file dbus-listener.c.

{
  GError *error;
  GSList * devices = NULL;
  GVariant * devices_container;
  IndicatorPowerDbusListener * self = INDICATOR_POWER_DBUS_LISTENER (user_data);

  /* build an array of IndicatorPowerDevices from the DBus response */
  error = NULL;
  devices_container = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
  if (devices_container == NULL)
    {
      g_message ("Couldn't get devices: %s\n", error->message);
      g_error_free (error);
    }
  else
    {
      gsize i;
      GVariant * devices_variant = g_variant_get_child_value (devices_container, 0);
      const int device_count = devices_variant ? g_variant_n_children (devices_variant) : 0;

      for (i=0; i<device_count; i++)
        {
          GVariant * v = g_variant_get_child_value (devices_variant, i);
          devices = g_slist_prepend (devices, indicator_power_device_new_from_variant (v));
          g_variant_unref (v);
        }

      devices = g_slist_reverse (devices);

      g_variant_unref (devices_variant);
      g_variant_unref (devices_container);
    }

  g_signal_emit (self, signals[SIGNAL_DEVICES], (GQuark)0, devices);
  g_slist_free_full (devices, g_object_unref);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void gsd_appeared_callback ( GDBusConnection *  connection,
const gchar *  name,
const gchar *  name_owner,
gpointer  user_data 
) [static]

Definition at line 230 of file dbus-listener.c.

{
  IndicatorPowerDbusListener * self = INDICATOR_POWER_DBUS_LISTENER(user_data);
  IndicatorPowerDbusListenerPrivate * priv = self->priv;

  g_dbus_proxy_new (connection,
                    G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
                    NULL,
                    name,
                    GSD_POWER_DBUS_PATH,
                    GSD_POWER_DBUS_INTERFACE,
                    priv->cancellable,
                    service_proxy_cb,
                    self);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void indicator_power_dbus_listener_class_init ( IndicatorPowerDbusListenerClass *  klass) [static]

IndicatorPowerDbusListener::devices-enumerated:

: the IndicatorPowerDbusListener : a GSList of #IndicatorPowerDevice objects. (transfer none)

This is emitted each time a new set of devices is enumerated over the bus.

Definition at line 57 of file dbus-listener.c.

{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  g_type_class_add_private (klass, sizeof (IndicatorPowerDbusListenerPrivate));

  /* methods */
  object_class->dispose = indicator_power_dbus_listener_dispose;
  object_class->finalize = indicator_power_dbus_listener_finalize;

  signals[SIGNAL_DEVICES] = g_signal_new (INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED,
                                          G_TYPE_FROM_CLASS(klass), 0,
                                          G_STRUCT_OFFSET (IndicatorPowerDbusListenerClass, devices_enumerated),
                                          NULL, NULL,
                                          g_cclosure_marshal_VOID__POINTER,
                                          G_TYPE_NONE, 1, G_TYPE_POINTER);
}

Here is the call graph for this function:

static void indicator_power_dbus_listener_dispose ( GObject *  object) [static]

Definition at line 107 of file dbus-listener.c.

{
  IndicatorPowerDbusListener * self = INDICATOR_POWER_DBUS_LISTENER(object);
  IndicatorPowerDbusListenerPrivate * priv = self->priv;

  g_clear_object (&priv->proxy);

  if (priv->cancellable != NULL)
    {
      g_cancellable_cancel (priv->cancellable);
      g_clear_object (&priv->cancellable);
    }

  if (priv->watcher_id)
    {
      g_bus_unwatch_name (priv->watcher_id);
      priv->watcher_id = 0;
    }

  G_OBJECT_CLASS (indicator_power_dbus_listener_parent_class)->dispose (object);
}

Here is the caller graph for this function:

static void indicator_power_dbus_listener_finalize ( GObject *  object) [static]

Definition at line 130 of file dbus-listener.c.

{
  G_OBJECT_CLASS (indicator_power_dbus_listener_parent_class)->finalize (object);
}

Here is the caller graph for this function:

static void indicator_power_dbus_listener_init ( IndicatorPowerDbusListener *  self) [static]

Definition at line 85 of file dbus-listener.c.

{
  IndicatorPowerDbusListenerPrivate * priv;

  priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
                                      INDICATOR_POWER_DBUS_LISTENER_TYPE,
                                      IndicatorPowerDbusListenerPrivate);

  priv->cancellable = g_cancellable_new ();

  priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
                                       GSD_SERVICE,
                                       G_BUS_NAME_WATCHER_FLAGS_NONE,
                                       gsd_appeared_callback,
                                       NULL,
                                       self,
                                       NULL);

  self->priv = priv;
}

Here is the call graph for this function:

static void receive_properties_changed ( GDBusProxy *proxy  G_GNUC_UNUSED,
GVariant *changed_properties  G_GNUC_UNUSED,
GStrv invalidated_properties  G_GNUC_UNUSED,
gpointer  user_data 
) [static]

Definition at line 194 of file dbus-listener.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void request_device_list ( IndicatorPowerDbusListener *  self) [static]

Definition at line 181 of file dbus-listener.c.

{
  g_dbus_proxy_call (self->priv->proxy,
                     "GetDevices",
                     NULL,
                     G_DBUS_CALL_FLAGS_NONE,
                     -1,
                     self->priv->cancellable,
                     get_devices_cb,
                     self);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void service_proxy_cb ( GObject *  object,
GAsyncResult *  res,
gpointer  user_data 
) [static]

Definition at line 204 of file dbus-listener.c.

{
  GError * error = NULL;
  IndicatorPowerDbusListener * self = INDICATOR_POWER_DBUS_LISTENER(user_data);
  IndicatorPowerDbusListenerPrivate * priv = self->priv;

  priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);

  if (error != NULL)
    {
      g_error ("Error creating proxy: %s", error->message);
      g_error_free (error);
      return;
    }

  /* we want to change the primary device changes */
  g_signal_connect (priv->proxy, "g-properties-changed",
                    G_CALLBACK (receive_properties_changed), user_data);

  /* get the initial state */
  request_device_list (self);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

guint signals[SIGNAL_LAST] = { 0 } [static]

Definition at line 41 of file dbus-listener.c.