[Telepathy-commits] [telepathy-mission-control/master] Implement client-side of account statistics interface

Alberto Mardegan alberto.mardegan at nokia.com
Mon Jan 5 01:40:43 PST 2009


---
 libmcclient/Makefile.am        |    1 +
 libmcclient/account.xml        |    1 +
 libmcclient/mc-account-priv.h  |   19 +++++
 libmcclient/mc-account-stats.c |  172 ++++++++++++++++++++++++++++++++++++++++
 libmcclient/mc-account.c       |   14 +---
 libmcclient/mc-account.h       |    5 +
 6 files changed, 201 insertions(+), 11 deletions(-)
 create mode 100644 libmcclient/mc-account-stats.c

diff --git a/libmcclient/Makefile.am b/libmcclient/Makefile.am
index bb21138..e7992dd 100644
--- a/libmcclient/Makefile.am
+++ b/libmcclient/Makefile.am
@@ -26,6 +26,7 @@ libmcclient_la_SOURCES = \
 	mc-account-conditions.c \
 	mc-account-manager.c \
 	mc-account-request.c \
+	mc-account-stats.c \
 	mc-dispatch-operation.c \
 	mc-errors.c \
 	mc-profile.c \
diff --git a/libmcclient/account.xml b/libmcclient/account.xml
index 71d2f5c..9bfcfb5 100644
--- a/libmcclient/account.xml
+++ b/libmcclient/account.xml
@@ -7,5 +7,6 @@
 <xi:include href="../xml/Account_Interface_ChannelRequests.xml"/>
 <xi:include href="../xml/Account_Interface_Compat.xml"/>
 <xi:include href="../xml/Account_Interface_Conditions.xml"/>
+<xi:include href="../xml/Account_Interface_Stats.xml"/>
 
 </tp:spec>
diff --git a/libmcclient/mc-account-priv.h b/libmcclient/mc-account-priv.h
index dc4d6bb..2437b91 100644
--- a/libmcclient/mc-account-priv.h
+++ b/libmcclient/mc-account-priv.h
@@ -37,6 +37,7 @@ enum
     FLAG_CHANGED,
     PARAMETERS_CHANGED,
     AVATAR_CHANGED,
+    CHANNEL_COUNT_CHANGED,
     LAST_SIGNAL
 };
 
@@ -47,6 +48,7 @@ typedef struct _McAccountAvatarProps McAccountAvatarProps;
 typedef struct _McAccountChannelrequestsProps McAccountChannelrequestsProps;
 typedef struct _McAccountCompatProps McAccountCompatProps;
 typedef struct _McAccountConditionsProps McAccountConditionsProps;
+typedef struct _McAccountStatsProps McAccountStatsProps;
 
 struct _McAccountPrivate {
     McAccountProps *props;
@@ -54,6 +56,20 @@ struct _McAccountPrivate {
     McAccountChannelrequestsProps *request_props;
     McAccountCompatProps *compat_props;
     McAccountConditionsProps *conditions_props;
+    McAccountStatsProps *stats_props;
+};
+
+/**
+ * McAccountClass:
+ *
+ * The class of a #McAccount.
+ */
+struct _McAccountClass {
+    TpProxyClass parent_class;
+
+    /* signals */
+    void (*stats_channel_count_changed) (McAccount *account,
+                                         GHashTable *channel_count);
 };
 
 void _mc_account_avatar_props_free (McAccountAvatarProps *props);
@@ -69,6 +85,9 @@ void _mc_account_compat_class_init (McAccountClass *klass);
 void _mc_account_conditions_props_free (McAccountConditionsProps *props);
 void _mc_account_conditions_class_init (McAccountClass *klass);
 
+void _mc_account_stats_props_free (McAccountStatsProps *props);
+void _mc_account_stats_class_init (McAccountClass *klass);
+
 G_END_DECLS
 
 #endif
diff --git a/libmcclient/mc-account-stats.c b/libmcclient/mc-account-stats.c
new file mode 100644
index 0000000..0b90e0e
--- /dev/null
+++ b/libmcclient/mc-account-stats.c
@@ -0,0 +1,172 @@
+/* vi: set et sw=4 ts=8 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
+/*
+ * mc-account-stats.c - Telepathy Account D-Bus interface (client side)
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Contact: Alberto Mardegan  <alberto.mardegan at nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "mc-account.h"
+#include "mc-account-priv.h"
+#include "dbus-api.h"
+#include "mc-signals-marshal.h"
+
+struct _McAccountStatsProps {
+    GHashTable *channel_count;
+};
+
+static void create_props (TpProxy *proxy, GHashTable *props);
+static void setup_props_monitor (TpProxy *proxy, GQuark interface);
+
+static McIfaceDescription iface_description = {
+    G_STRUCT_OFFSET (McAccountPrivate, stats_props),
+    create_props,
+    setup_props_monitor,
+};
+
+
+void
+_mc_account_stats_props_free (McAccountStatsProps *props)
+{
+    g_hash_table_unref (props->channel_count);
+    g_slice_free (McAccountStatsProps, props);
+}
+
+static void
+channel_count_changed (McAccount *account, GHashTable *channel_count)
+{
+    McAccountStatsProps *props = account->priv->stats_props;
+
+    if (props->channel_count)
+        g_hash_table_unref (props->channel_count);
+    props->channel_count = channel_count;
+}
+
+void
+_mc_account_stats_class_init (McAccountClass *klass)
+{
+    klass->stats_channel_count_changed = channel_count_changed;
+
+    _mc_iface_add (MC_TYPE_ACCOUNT,
+		   MC_IFACE_QUARK_ACCOUNT_INTERFACE_STATS,
+		   &iface_description);
+
+    /**
+     * McAccount::channel-count-changed:
+     * @account: the #McAccount.
+     * @channel_count: a #GHashTable with the new channel counters.
+     *
+     * Emitted when the stats changes.
+     * The McAccount member data are updated in the signal closure, so use
+     * g_signal_connect_after() if you need them to reflect the new status.
+     */
+    _mc_account_signals[CHANNEL_COUNT_CHANGED] =
+        g_signal_new ("channel-count-changed",
+                      G_OBJECT_CLASS_TYPE (klass),
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET (McAccountClass,
+                                       stats_channel_count_changed),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__BOXED,
+                      G_TYPE_NONE,
+                      1, G_TYPE_HASH_TABLE);
+}
+
+static void
+update_property (gpointer key, gpointer ht_value, gpointer user_data)
+{
+    McAccount *account = MC_ACCOUNT (user_data);
+    McAccountStatsProps *props = account->priv->stats_props;
+    GValue *value = ht_value;
+    const gchar *name = key;
+
+    g_return_if_fail (props != NULL);
+
+    if (strcmp (name, "ChannelCount") == 0)
+    {
+        GHashTable *channel_count;
+
+        channel_count = g_value_dup_boxed (value);
+        if (props->channel_count)
+            g_signal_emit (account, _mc_account_signals[CHANNEL_COUNT_CHANGED],
+                           0, channel_count);
+        else
+            props->channel_count = channel_count;
+    }
+}
+
+static void
+create_props (TpProxy *proxy, GHashTable *props)
+{
+    McAccount *account = MC_ACCOUNT (proxy);
+    McAccountPrivate *priv = account->priv;
+
+    priv->stats_props = g_slice_new0 (McAccountStatsProps);
+    g_hash_table_foreach (props, update_property, account);
+}
+
+static void
+on_stats_changed (TpProxy *proxy, GHashTable *properties, gpointer user_data,
+                  GObject *weak_object)
+{
+    McAccount *account = MC_ACCOUNT (proxy);
+    McAccountPrivate *priv = account->priv;
+
+    /* if the GetAll method hasn't returned yet, we do nothing */
+    if (G_UNLIKELY (!priv->stats_props)) return;
+
+    g_hash_table_foreach (properties, update_property, account);
+}
+
+static void
+setup_props_monitor (TpProxy *proxy, GQuark interface)
+{
+    McAccount *account = MC_ACCOUNT (proxy);
+
+    mc_cli_account_interface_stats_connect_to_stats_changed (account,
+                                                             on_stats_changed,
+                                                             NULL, NULL,
+                                                             NULL, NULL);
+}
+
+/**
+ * mc_account_stats_get_channel_count:
+ * @account: the #McAccount.
+ *
+ * Retrieves the number of account active channels, by channel type. This also
+ * includes channel requests.
+ *
+ * Returns: a #GHashTable which maps channel types to their usage count (use
+ * GPOINTER_TO_UINT() to convert the values into integers).
+ */
+GHashTable *
+mc_account_stats_get_channel_count (McAccount *account)
+{
+    McAccountStatsProps *props;
+
+    g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
+    props = account->priv->stats_props;
+    if (G_UNLIKELY (!props))
+        return NULL;
+
+    return props->channel_count;
+}
+
diff --git a/libmcclient/mc-account.c b/libmcclient/mc-account.c
index 774706b..0548bcd 100644
--- a/libmcclient/mc-account.c
+++ b/libmcclient/mc-account.c
@@ -41,17 +41,6 @@
  * Account D-Bus API.
  */
 
-/**
- * McAccountClass:
- *
- * The class of a #McAccount.
- */
-struct _McAccountClass {
-    TpProxyClass parent_class;
-    /*<private>*/
-    gpointer priv;
-};
-
 struct _McAccountProps {
     gchar *display_name;
     gchar *icon;
@@ -165,6 +154,8 @@ mc_account_init (McAccount *account)
 				  MC_IFACE_QUARK_ACCOUNT_INTERFACE_COMPAT);
     tp_proxy_add_interface_by_id ((TpProxy *)account,
 				  MC_IFACE_QUARK_ACCOUNT_INTERFACE_CONDITIONS);
+    tp_proxy_add_interface_by_id ((TpProxy *)account,
+				  MC_IFACE_QUARK_ACCOUNT_INTERFACE_STATS);
 }
 
 static GObject *
@@ -368,6 +359,7 @@ mc_account_class_init (McAccountClass *klass)
     _mc_account_avatar_class_init (klass);
     _mc_account_compat_class_init (klass);
     _mc_account_conditions_class_init (klass);
+    _mc_account_stats_class_init (klass);
 }
 
 /**
diff --git a/libmcclient/mc-account.h b/libmcclient/mc-account.h
index 83729a4..713b5be 100644
--- a/libmcclient/mc-account.h
+++ b/libmcclient/mc-account.h
@@ -295,6 +295,11 @@ const gchar *mc_account_channelrequest_get_path (McAccount *account,
 guint mc_account_channelrequest_get_from_path (McAccount *account,
                                                const gchar *object_path);
 
+
+/* Account statistics */
+
+GHashTable *mc_account_stats_get_channel_count (McAccount *account);
+
 G_END_DECLS
 
 #include <libmcclient/_gen/mc-quark.h>
-- 
1.5.6.5




More information about the Telepathy-commits mailing list