diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-08-06 21:35:41 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-09-05 15:39:00 +0200 |
commit | 4878c5647b1608a08142a3b7fd0f7f70dea65ab8 (patch) | |
tree | 94999b66238bc49a4433723dee5cea355e65c55f | |
parent | f22e42f7afa4001f0685070eca465d453f0b6570 (diff) | |
download | libqmi-4878c5647b1608a08142a3b7fd0f7f70dea65ab8.tar.gz |
libqmi-glib,proxy: new property exposing the current number of connected clients
-rw-r--r-- | docs/reference/libqmi-glib/libqmi-glib-common.sections | 2 | ||||
-rw-r--r-- | src/libqmi-glib/qmi-proxy.c | 58 | ||||
-rw-r--r-- | src/libqmi-glib/qmi-proxy.h | 5 |
3 files changed, 64 insertions, 1 deletions
diff --git a/docs/reference/libqmi-glib/libqmi-glib-common.sections b/docs/reference/libqmi-glib/libqmi-glib-common.sections index 3be4f374..ea769683 100644 --- a/docs/reference/libqmi-glib/libqmi-glib-common.sections +++ b/docs/reference/libqmi-glib/libqmi-glib-common.sections @@ -82,8 +82,10 @@ qmi_device_get_type <FILE>qmi-proxy</FILE> <TITLE>QmiProxy</TITLE> QMI_PROXY_SOCKET_PATH +QMI_PROXY_N_CLIENTS QmiProxy qmi_proxy_new +qmi_proxy_get_n_clients <SUBSECTION Standard> QmiProxyClass QMI_PROXY diff --git a/src/libqmi-glib/qmi-proxy.c b/src/libqmi-glib/qmi-proxy.c index ca3e0e0e..e511f2ce 100644 --- a/src/libqmi-glib/qmi-proxy.c +++ b/src/libqmi-glib/qmi-proxy.c @@ -42,6 +42,14 @@ G_DEFINE_TYPE (QmiProxy, qmi_proxy, G_TYPE_OBJECT) +enum { + PROP_0, + PROP_N_CLIENTS, + PROP_LAST +}; + +static GParamSpec *properties[PROP_LAST]; + struct _QmiProxyPrivate { /* Unix socket service */ GSocketService *socket_service; @@ -55,6 +63,24 @@ struct _QmiProxyPrivate { /*****************************************************************************/ +/** + * qmi_proxy_get_n_clients: + * @self: a #QmiProxy. + * + * Get the number of clients currently connected to the proxy. + * + * Returns: a #guint. + */ +guint +qmi_proxy_get_n_clients (QmiProxy *self) +{ + g_return_val_if_fail (QMI_IS_PROXY (self), 0); + + return g_list_length (self->priv->clients); +} + +/*****************************************************************************/ + typedef struct { QmiProxy *proxy; /* not full ref */ GSocketConnection *connection; @@ -91,6 +117,7 @@ connection_close (Client *client) client_free (client); self->priv->clients = g_list_remove (self->priv->clients, client); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_CLIENTS]); } static QmiDevice * @@ -425,6 +452,7 @@ incoming_cb (GSocketService *service, /* Keep the client info around */ self->priv->clients = g_list_append (self->priv->clients, client); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_CLIENTS]); } static gboolean @@ -499,6 +527,24 @@ qmi_proxy_init (QmiProxy *self) } static void +get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + QmiProxy *self = QMI_PROXY (object); + + switch (prop_id) { + case PROP_N_CLIENTS: + g_value_set_uint (value, g_list_length (self->priv->clients)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void dispose (GObject *object) { QmiProxyPrivate *priv = QMI_PROXY (object)->priv; @@ -527,5 +573,17 @@ qmi_proxy_class_init (QmiProxyClass *proxy_class) g_type_class_add_private (object_class, sizeof (QmiProxyPrivate)); /* Virtual methods */ + object_class->get_property = get_property; object_class->dispose = dispose; + + /* Properties */ + properties[PROP_N_CLIENTS] = + g_param_spec_uint (QMI_PROXY_N_CLIENTS, + "Number of clients", + "Number of clients currently connected to the proxy", + 0, + G_MAXUINT, + 0, + G_PARAM_READABLE); + g_object_class_install_property (object_class, PROP_N_CLIENTS, properties[PROP_N_CLIENTS]); } diff --git a/src/libqmi-glib/qmi-proxy.h b/src/libqmi-glib/qmi-proxy.h index 9845dbef..ce64976a 100644 --- a/src/libqmi-glib/qmi-proxy.h +++ b/src/libqmi-glib/qmi-proxy.h @@ -39,6 +39,8 @@ typedef struct _QmiProxyPrivate QmiProxyPrivate; #define QMI_PROXY_SOCKET_PATH "qmi-proxy" +#define QMI_PROXY_N_CLIENTS "qmi-proxy-n-clients" + struct _QmiProxy { GObject parent; QmiProxyPrivate *priv; @@ -50,6 +52,7 @@ struct _QmiProxyClass { GType qmi_proxy_get_type (void); -QmiProxy *qmi_proxy_new (GError **error); +QmiProxy *qmi_proxy_new (GError **error); +guint qmi_proxy_get_n_clients (QmiProxy *self); #endif /* QMI_PROXY_H */ |