[Telepathy-commits] [telepathy-mission-control/master] Server-side implementation of the account Stats interface

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


---
 src/Makefile.am         |    4 +
 src/mcd-account-stats.c |  156 +++++++++++++++++++++++++++++++++++++++++++++++
 src/mcd-account-stats.h |   43 +++++++++++++
 src/mcd-account.c       |    4 +
 src/mcd-dbusprop.c      |    2 +
 5 files changed, 209 insertions(+), 0 deletions(-)
 create mode 100644 src/mcd-account-stats.c
 create mode 100644 src/mcd-account-stats.h

diff --git a/src/Makefile.am b/src/Makefile.am
index b801467..e6aa50d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,7 @@ mission_control_include = \
 	mcd-account-manager.h \
 	mcd-account-manager-creation.h \
 	mcd-account-manager-query.h \
+	mcd-account-stats.h \
 	mcd-dbusprop.h \
 	mcd-debug.h \
 	mcd-dispatch-operation.h \
@@ -52,6 +53,7 @@ nodist_geninclude_HEADERS = \
 	_gen/svc-Account_Interface_ChannelRequests.h \
 	_gen/svc-Account_Interface_Compat.h \
 	_gen/svc-Account_Interface_Conditions.h \
+	_gen/svc-Account_Interface_Stats.h \
 	_gen/svc-Account_Manager.h \
 	_gen/svc-Account_Manager_Interface_Creation.h \
 	_gen/svc-Account_Manager_Interface_Query.h \
@@ -71,6 +73,7 @@ nodist_libmissioncontrol_server_la_SOURCES = \
 	_gen/svc-Account_Interface_ChannelRequests.c \
 	_gen/svc-Account_Interface_Compat.c \
 	_gen/svc-Account_Interface_Conditions.c \
+	_gen/svc-Account_Interface_Stats.c \
 	_gen/svc-Account_Manager.c \
 	_gen/svc-Account_Manager_Interface_Creation.c \
 	_gen/svc-Account_Manager_Interface_Query.c \
@@ -120,6 +123,7 @@ libmissioncontrol_server_la_SOURCES = \
 	mcd-account-conditions.c \
 	mcd-account-connection.c \
 	mcd-account-requests.c \
+	mcd-account-stats.c \
 	mcd-account-manager.c \
 	mcd-account-manager-creation.c \
 	mcd-account-manager-query.c \
diff --git a/src/mcd-account-stats.c b/src/mcd-account-stats.c
new file mode 100644
index 0000000..3092f5b
--- /dev/null
+++ b/src/mcd-account-stats.c
@@ -0,0 +1,156 @@
+/* vi: set et sw=4 ts=8 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
+/*
+ * This file is part of mission-control
+ *
+ * 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
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 <string.h>
+#include <glib.h>
+#include <config.h>
+
+#include "mcd-account.h"
+#include "mcd-account-priv.h"
+#include "mcd-account-stats.h"
+#include "mcd-account-manager.h"
+#include "_gen/interfaces.h"
+#include "_gen/gtypes.h"
+#include <telepathy-glib/svc-generic.h>
+#include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/util.h>
+
+
+static GHashTable *
+mcd_account_get_channel_count (McdAccount *account)
+{
+    GHashTable *stats;
+    McdConnection *connection;
+
+    stats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+    connection = mcd_account_get_connection (account);
+    if (connection)
+    {
+        const GList *channels;
+
+        channels = mcd_operation_get_missions (MCD_OPERATION (connection));
+        for (; channels != NULL; channels = channels->next)
+        {
+            McdChannel *channel;
+            const gchar *channel_type;
+            guint count;
+
+            channel = MCD_CHANNEL (channels->data);
+            channel_type = mcd_channel_get_channel_type (channel);
+            if (G_UNLIKELY (!channel_type)) continue;
+
+            count = GPOINTER_TO_UINT (g_hash_table_lookup (stats,
+                                                           channel_type));
+            count++;
+            g_hash_table_insert (stats, g_strdup (channel_type),
+                                 GUINT_TO_POINTER (count));
+        }
+    }
+
+    return stats;
+}
+
+static void
+get_channel_count (TpSvcDBusProperties *self, const gchar *name, GValue *value)
+{
+    GHashTable *stats;
+
+    stats = mcd_account_get_channel_count (MCD_ACCOUNT (self));
+
+    g_value_init (value, MC_HASH_TYPE_CHANNEL_COUNT_MAP);
+    g_value_take_boxed (value, stats);
+}
+
+
+const McdDBusProp account_stats_properties[] = {
+    { "ChannelCount", NULL, get_channel_count },
+    { 0 },
+};
+
+void
+account_stats_iface_init (McSvcAccountInterfaceStatsClass *iface,
+                          gpointer iface_data)
+{
+}
+
+static void
+on_channel_count_changed (McdConnection *connection, McdChannel *channel,
+                          McdAccount *account)
+{
+    GHashTable *stats, *properties;
+    GValue value = { 0 };
+
+    stats = mcd_account_get_channel_count (account);
+
+    g_value_init (&value, MC_HASH_TYPE_CHANNEL_COUNT_MAP);
+    g_value_take_boxed (&value, stats);
+
+    properties = g_hash_table_new (g_str_hash, g_str_equal);
+    g_hash_table_insert (properties, (gpointer)"ChannelCount", &value);
+
+    mc_svc_account_interface_stats_emit_stats_changed (account, properties);
+
+    g_hash_table_destroy (properties);
+    g_value_unset (&value);
+}
+
+static void
+watch_connection (McdAccount *account)
+{
+    McdConnection *connection;
+
+    connection = mcd_account_get_connection (account);
+    if (G_UNLIKELY (!connection)) return;
+
+    g_signal_connect (connection, "mission-taken",
+                      G_CALLBACK (on_channel_count_changed), account);
+    g_signal_connect (connection, "mission-removed",
+                      G_CALLBACK (on_channel_count_changed), account);
+}
+
+static void
+on_account_connection_status_changed (McdAccount *account,
+                                      TpConnectionStatus status,
+                                      TpConnectionStatusReason reason)
+{
+    if (status == TP_CONNECTION_STATUS_CONNECTED)
+        watch_connection (account);
+}
+
+void
+account_stats_instance_init (TpSvcDBusProperties *self)
+{
+    McdAccount *account = MCD_ACCOUNT (self);
+
+    if (mcd_account_get_connection_status (account) ==
+        TP_CONNECTION_STATUS_CONNECTED)
+    {
+        watch_connection (account);
+    }
+
+    g_signal_connect (account, "connection-status-changed",
+                      G_CALLBACK (on_account_connection_status_changed), NULL);
+}
+
diff --git a/src/mcd-account-stats.h b/src/mcd-account-stats.h
new file mode 100644
index 0000000..1d42af6
--- /dev/null
+++ b/src/mcd-account-stats.h
@@ -0,0 +1,43 @@
+/* vi: set et sw=4 ts=8 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
+/*
+ * mcd-account.h - the Telepathy Account D-Bus interface (service side)
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * 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
+ */
+
+#ifndef __MCD_ACCOUNT_STATS_H__
+#define __MCD_ACCOUNT_STATS_H__
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/enums.h>
+/* auto-generated stubs */
+#include "_gen/svc-Account_Interface_Stats.h"
+
+#include "mcd-dbusprop.h"
+
+G_BEGIN_DECLS
+
+extern const McdDBusProp account_stats_properties[];
+
+void account_stats_iface_init (McSvcAccountInterfaceStatsClass *iface,
+                               gpointer iface_data);
+void account_stats_instance_init (TpSvcDBusProperties *self);
+
+G_END_DECLS
+#endif
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 04697b7..2480335 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -42,6 +42,7 @@
 #include "mcd-account-conditions.h"
 #include "mcd-account-connection.h"
 #include "mcd-account-requests.h"
+#include "mcd-account-stats.h"
 #include "mcd-misc.h"
 #include "mcd-signals-marshal.h"
 #include "mcd-manager.h"
@@ -81,6 +82,9 @@ static const McdInterfaceData account_interfaces[] = {
     MCD_IMPLEMENT_IFACE (mc_svc_account_interface_conditions_get_type,
 			 account_conditions,
 			 MC_IFACE_ACCOUNT_INTERFACE_CONDITIONS),
+    MCD_IMPLEMENT_IFACE_WITH_INIT (mc_svc_account_interface_stats_get_type,
+                                   account_stats,
+                                   MC_IFACE_ACCOUNT_INTERFACE_STATS),
     { G_TYPE_INVALID, }
 };
 
diff --git a/src/mcd-dbusprop.c b/src/mcd-dbusprop.c
index 9b902c6..50cc4ba 100644
--- a/src/mcd-dbusprop.c
+++ b/src/mcd-dbusprop.c
@@ -28,6 +28,8 @@
 #include "mcd-dbusprop.h"
 #include <_gen/interfaces.h>
 #include <_gen/interfaces-body.h>
+#include <_gen/gtypes.h>
+#include <_gen/gtypes-body.h>
 
 #define MCD_INTERFACES_QUARK get_interfaces_quark()
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list