summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Staudinger <robsta@linux.intel.com>2011-10-25 13:22:40 +0200
committerRob Staudinger <robsta@linux.intel.com>2011-10-25 13:22:40 +0200
commit48a9feecee56b9458d8d70799d3a529a961a380a (patch)
treeab164ecaf4f3f0de44d81ab96f0eefa3dc13f8dc
parent665a9de24172dcd93e6fb3d2ef0963ebcbb2c116 (diff)
Roster: get rid of Client reference.
No other objects depend on having a pointer to the Client object now. Tags: refactoring
-rw-r--r--configure.ac2
-rw-r--r--examples/video-profile/player.c2
-rw-r--r--examples/video-profile/remote.c2
-rw-r--r--ytstenut/marshal.list1
-rw-r--r--ytstenut/yts-client-internal.h5
-rw-r--r--ytstenut/yts-client.c137
-rw-r--r--ytstenut/yts-contact.c14
-rw-r--r--ytstenut/yts-roster-internal.h2
-rw-r--r--ytstenut/yts-roster.c62
-rw-r--r--ytstenut/yts-roster.h3
10 files changed, 121 insertions, 109 deletions
diff --git a/configure.ac b/configure.ac
index 046317f..729fc54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,7 +58,7 @@ AC_SUBST(GLIB_PREFIX)
TELEPATHY_VERSION=">= 0.11.7"
AC_SUBST(TELEPATHY_VERSION)
-YTS_PC_MODULES="$YTS_PC_MODULES telepathy-glib $TELEPATHY_VERSION telepathy-ytstenut-glib >= 0.2.0 gio-unix-2.0 rest >= 0.7 glib-2.0 gobject-2.0"
+YTS_PC_MODULES="$YTS_PC_MODULES telepathy-glib $TELEPATHY_VERSION telepathy-ytstenut-glib >= 0.2.0 gio-unix-2.0 rest-0.7 >= 0.7 glib-2.0 gobject-2.0"
AC_ARG_ENABLE([debug],
[AC_HELP_STRING([--enable-debug],
diff --git a/examples/video-profile/player.c b/examples/video-profile/player.c
index 230b302..d967a53 100644
--- a/examples/video-profile/player.c
+++ b/examples/video-profile/player.c
@@ -131,6 +131,8 @@ main (int argc,
{ NULL, }
};
+ g_type_init ();
+
/* Initialisation and command-line argument handling. */
context = g_option_context_new ("- mock player");
g_option_context_add_main_entries (context, entries, NULL);
diff --git a/examples/video-profile/remote.c b/examples/video-profile/remote.c
index 21c5c5c..0724df5 100644
--- a/examples/video-profile/remote.c
+++ b/examples/video-profile/remote.c
@@ -317,6 +317,8 @@ main (int argc,
{ NULL }
};
+ g_type_init ();
+
memset (&remote, 0, sizeof (remote));
remote.player_volume = -1.0;
diff --git a/ytstenut/marshal.list b/ytstenut/marshal.list
index 52221d6..a5828b9 100644
--- a/ytstenut/marshal.list
+++ b/ytstenut/marshal.list
@@ -9,6 +9,7 @@ BOOLEAN:STRING,STRING,UINT64,UINT64,OBJECT
VOID:STRING,STRING,BOOLEAN
BOOLEAN:POINTER,UINT
VOID:OBJECT,OBJECT
+VOID:OBJECT,OBJECT,OBJECT
VOID:STRING,BOOLEAN
VOID:STRING,BOXED
VOID:STRING,STRING
diff --git a/ytstenut/yts-client-internal.h b/ytstenut/yts-client-internal.h
index 77189ec..2e717f3 100644
--- a/ytstenut/yts-client-internal.h
+++ b/ytstenut/yts-client-internal.h
@@ -38,11 +38,6 @@ yts_client_send_message (YtsClient *client,
char const *uid,
YtsMetadata *message);
-
-void
-yts_client_cleanup_contact (YtsClient *self,
- YtsContact const *contact);
-
void
yts_client_emit_error (YtsClient *self,
YtsError error);
diff --git a/ytstenut/yts-client.c b/ytstenut/yts-client.c
index a9e3eaf..c9c00c4 100644
--- a/ytstenut/yts-client.c
+++ b/ytstenut/yts-client.c
@@ -1199,6 +1199,75 @@ yts_client_account_cb (GObject *object, GAsyncResult *res, gpointer self)
}
static void
+_roster_send_message (YtsRoster *roster,
+ YtsContact *contact,
+ YtsService *service,
+ YtsMetadata *message,
+ YtsClient *self)
+{
+ char const *service_id;
+
+ service_id = yts_service_get_service_id (service);
+
+ yts_client_send_message (self, contact, service_id, message);
+}
+
+static void
+_roster_contact_removed (YtsRoster *roster,
+ YtsContact *contact,
+ YtsClient *self)
+{
+ YtsClientPrivate *priv = GET_PRIVATE (self);
+ GHashTableIter iter;
+ bool start_over;
+
+ /*
+ * Clear pending responses.
+ */
+
+ // FIXME this would be better solved using g_hash_table_foreach_remove().
+ do {
+ char const *invocation_id;
+ InvocationData *data;
+ start_over = false;
+ g_hash_table_iter_init (&iter, priv->invocations);
+ while (g_hash_table_iter_next (&iter,
+ (void **) &invocation_id,
+ (void **) &data)) {
+
+ if (data->contact == contact) {
+ g_hash_table_remove (priv->invocations, invocation_id);
+ start_over = true;
+ break;
+ }
+ }
+ } while (start_over);
+
+ /*
+ * Unregister proxies
+ */
+
+ // FIXME this would be better solved using g_hash_table_foreach_remove().
+ do {
+ char const *capability;
+ ProxyList *proxy_list;
+ start_over = false;
+ g_hash_table_iter_init (&iter, priv->proxies);
+ while (g_hash_table_iter_next (&iter,
+ (void **) &capability,
+ (void **) &proxy_list)) {
+
+ proxy_list_purge_contact (proxy_list, contact);
+ if (proxy_list_is_empty (proxy_list)) {
+ g_hash_table_remove (priv->proxies, capability);
+ start_over = true;
+ break;
+ }
+ }
+ } while (start_over);
+}
+
+static void
yts_client_constructed (GObject *object)
{
YtsClientPrivate *priv = GET_PRIVATE (object);
@@ -1207,8 +1276,17 @@ yts_client_constructed (GObject *object)
if (G_OBJECT_CLASS (yts_client_parent_class)->constructed)
G_OBJECT_CLASS (yts_client_parent_class)->constructed (object);
- priv->roster = yts_roster_new (YTS_CLIENT (object));
- priv->unwanted = yts_roster_new (YTS_CLIENT (object));
+ priv->roster = yts_roster_new ();
+ g_signal_connect (priv->roster, "send-message",
+ G_CALLBACK (_roster_send_message), object);
+ g_signal_connect (priv->roster, "contact-removed",
+ G_CALLBACK (_roster_contact_removed), object);
+
+ priv->unwanted = yts_roster_new ();
+ g_signal_connect (priv->unwanted, "send-message",
+ G_CALLBACK (_roster_send_message), object);
+ g_signal_connect (priv->unwanted, "contact-removed",
+ G_CALLBACK (_roster_contact_removed), object);
if (!priv->uid || !*priv->uid)
g_error ("UID must be set at construction time.");
@@ -2759,6 +2837,7 @@ yts_client_has_capability (YtsClient *self, YtsCaps cap)
return FALSE;
}
+// TODO get rid of this, it invalidates the proxies
static void
yts_client_refresh_roster (YtsClient *self)
{
@@ -3511,60 +3590,6 @@ yts_client_publish_service (YtsClient *self,
return TRUE;
}
-void
-yts_client_cleanup_contact (YtsClient *self,
- YtsContact const *contact)
-{
- YtsClientPrivate *priv = GET_PRIVATE (self);
- GHashTableIter iter;
- bool start_over;
-
- /*
- * Clear pending responses.
- */
-
- // FIXME this would be better solved using g_hash_table_foreach_remove().
- do {
- char const *invocation_id;
- InvocationData *data;
- start_over = false;
- g_hash_table_iter_init (&iter, priv->invocations);
- while (g_hash_table_iter_next (&iter,
- (void **) &invocation_id,
- (void **) &data)) {
-
- if (data->contact == contact) {
- g_hash_table_remove (priv->invocations, invocation_id);
- start_over = true;
- break;
- }
- }
- } while (start_over);
-
- /*
- * Unregister proxies
- */
-
- // FIXME this would be better solved using g_hash_table_foreach_remove().
- do {
- char const *capability;
- ProxyList *proxy_list;
- start_over = false;
- g_hash_table_iter_init (&iter, priv->proxies);
- while (g_hash_table_iter_next (&iter,
- (void **) &capability,
- (void **) &proxy_list)) {
-
- proxy_list_purge_contact (proxy_list, contact);
- if (proxy_list_is_empty (proxy_list)) {
- g_hash_table_remove (priv->proxies, capability);
- start_over = true;
- break;
- }
- }
- } while (start_over);
-}
-
bool
yts_client_get_invocation_proxy (YtsClient *self,
char const *invocation_id,
diff --git a/ytstenut/yts-contact.c b/ytstenut/yts-contact.c
index 2699359..5582599 100644
--- a/ytstenut/yts-contact.c
+++ b/ytstenut/yts-contact.c
@@ -411,13 +411,13 @@ yts_contact_class_init (YtsContactClass *klass)
* Maybe in the future when we allow for custom contact subclasses.</note>
*/
_signals[SIG_SEND_MESSAGE] = g_signal_new ("send-message",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- yts_marshal_VOID__OBJECT_OBJECT,
- G_TYPE_NONE, 2,
- YTS_TYPE_SERVICE,
- YTS_TYPE_METADATA);
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ yts_marshal_VOID__OBJECT_OBJECT,
+ G_TYPE_NONE, 2,
+ YTS_TYPE_SERVICE,
+ YTS_TYPE_METADATA);
/**
* YtsContact::service-added:
diff --git a/ytstenut/yts-roster-internal.h b/ytstenut/yts-roster-internal.h
index 9814b8d..92cf481 100644
--- a/ytstenut/yts-roster-internal.h
+++ b/ytstenut/yts-roster-internal.h
@@ -28,7 +28,7 @@
#include <ytstenut/yts-roster.h>
YtsRoster *
-yts_roster_new (YtsClient *client);
+yts_roster_new (void);
void
yts_roster_add_contact (YtsRoster *roster,
diff --git a/ytstenut/yts-roster.c b/ytstenut/yts-roster.c
index 8e34d78..27c234a 100644
--- a/ytstenut/yts-roster.c
+++ b/ytstenut/yts-roster.c
@@ -21,9 +21,9 @@
#include <telepathy-ytstenut-glib/telepathy-ytstenut-glib.h>
-#include "yts-client-internal.h"
#include "yts-contact-internal.h"
#include "yts-marshal.h"
+#include "yts-metadata.h"
#include "yts-roster-internal.h"
#include "yts-service-factory.h"
#include "config.h"
@@ -46,14 +46,15 @@ G_DEFINE_TYPE (YtsRoster, yts_roster, G_TYPE_OBJECT);
*/
enum {
- PROP_0,
- PROP_CLIENT
+ PROP_0
};
enum {
SIG_CONTACT_ADDED,
SIG_CONTACT_REMOVED,
+ SIG_SEND_MESSAGE,
+
SIG_SERVICE_ADDED,
SIG_SERVICE_REMOVED,
@@ -63,7 +64,6 @@ enum {
typedef struct {
GHashTable *contacts; /* hash of YtsContact this roster holds */
- YtsClient *client; /* back-reference to the client object that owns us */
} YtsRosterPrivate;
@@ -76,12 +76,9 @@ _contact_send_message (YtsContact *contact,
YtsRoster *self)
{
YtsRosterPrivate *priv = GET_PRIVATE (self);
- char const *service_id = yts_service_get_service_id (service);
- yts_client_send_message (priv->client,
- contact,
- service_id,
- message);
+ g_signal_emit (self, _signals[SIG_SEND_MESSAGE], 0,
+ contact, service, message);
}
static void
@@ -105,9 +102,6 @@ _set_property (GObject *object,
YtsRosterPrivate *priv = GET_PRIVATE (object);
switch (property_id) {
- case PROP_CLIENT:
- priv->client = g_value_get_object (value);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -132,19 +126,12 @@ _dispose (GObject *object)
g_signal_handlers_disconnect_by_func (contact,
_contact_send_message,
object);
-
- yts_client_cleanup_contact (priv->client, contact);
}
g_hash_table_destroy (priv->contacts);
priv->contacts = NULL;
}
- if (priv->client) {
- /* no ownership */
- priv->client = NULL;
- }
-
G_OBJECT_CLASS (yts_roster_parent_class)->dispose (object);
}
@@ -161,16 +148,6 @@ yts_roster_class_init (YtsRosterClass *klass)
object_class->dispose = _dispose;
/**
- * YtsRoster:client:
- *
- * #YtsClient this roster represents.
- */
- pspec = g_param_spec_object ("client", "", "",
- YTS_TYPE_CLIENT,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
- g_object_class_install_property (object_class, PROP_CLIENT, pspec);
-
- /**
* YtsRoster::contact-added:
* @self: object which emitted the signal.
* @contact: #YtsContact that was added.
@@ -207,6 +184,22 @@ yts_roster_class_init (YtsRosterClass *klass)
YTS_TYPE_CONTACT);
/**
+ * YtsContact::send-message:
+ *
+ * <note>Internal signal, should not be considered by users at this time.
+ * Maybe in the future when we allow for custom contact subclasses.</note>
+ */
+ _signals[SIG_SEND_MESSAGE] = g_signal_new ("send-message",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ yts_marshal_VOID__OBJECT_OBJECT_OBJECT,
+ G_TYPE_NONE, 3,
+ YTS_TYPE_CONTACT,
+ YTS_TYPE_SERVICE,
+ YTS_TYPE_METADATA);
+
+ /**
* YtsRoster::service-added:
* @self: object which emitted the signal.
* @service: #YtsService that was added.
@@ -261,8 +254,6 @@ yts_roster_init (YtsRoster *self)
* @service_id: the service UID.
*
* Removes service from a roster and emits YtsRoster::service-removed signal.
- *
- * For use by #YtsClient.
*/
void
yts_roster_remove_service_by_id (YtsRoster *self,
@@ -288,7 +279,6 @@ yts_roster_remove_service_by_id (YtsRoster *self,
g_signal_handlers_disconnect_by_func (contact,
_contact_send_message,
self);
- yts_client_cleanup_contact (priv->client, contact);
g_object_ref (contact);
g_hash_table_remove (priv->contacts, contact_id);
g_signal_emit (self, _signals[SIG_CONTACT_REMOVED], 0, contact);
@@ -382,8 +372,6 @@ yts_roster_clear (YtsRoster *self)
_contact_send_message,
self);
- yts_client_cleanup_contact (priv->client, contact);
-
g_object_ref (contact);
g_hash_table_iter_remove (&iter);
@@ -396,11 +384,9 @@ yts_roster_clear (YtsRoster *self)
}
YtsRoster *
-yts_roster_new (YtsClient *client)
+yts_roster_new (void)
{
- return g_object_new (YTS_TYPE_ROSTER,
- "client", client,
- NULL);
+ return g_object_new (YTS_TYPE_ROSTER, NULL);
}
static void
diff --git a/ytstenut/yts-roster.h b/ytstenut/yts-roster.h
index 2075562..77977dd 100644
--- a/ytstenut/yts-roster.h
+++ b/ytstenut/yts-roster.h
@@ -16,6 +16,7 @@
* <http://www.gnu.org/licenses/>.
*
* Authored by: Tomas Frydrych <tf@linux.intel.com>
+ * Rob Staudinger <robsta@linux.intel.com>
*/
#ifndef YTS_ROSTER_H
@@ -69,7 +70,7 @@ yts_roster_find_contact_by_id (YtsRoster const *self,
* @self: object owning @service.
* @contact_id: contact JID.
* @contact: contact object.
- * @user_data: data passed to yts_client_foreach_service().
+ * @user_data: data passed to yts_roster_foreach_contact().
*
* Callback signature for iterating a an #YtsRoster's published services.
*