summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2014-01-30 15:14:52 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-02-03 16:29:25 +0000
commit4c539c002bb7c50aee24774edceb14495bdcc78e (patch)
treea01c617fd20593f08c2e4dcd27721eb2b5d1fc57
parentd0c0da1d87363a6e823ec8749272d1746c0e2f16 (diff)
Squash mcd-account-connection.c into mcd-account.c
There's hardly anything there any more anyway. Take the opportunity to replace _mcd_account_set_connection_context and _mcd_account_get_connection_context with simple access to the priv struct. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71093 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--src/Makefile.am1
-rw-r--r--src/mcd-account-connection.c115
-rw-r--r--src/mcd-account-priv.h13
-rw-r--r--src/mcd-account.c141
4 files changed, 118 insertions, 152 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7f209d3c..17c22f22 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,7 +52,6 @@ libmcd_convenience_la_SOURCES = \
mcd-account.c \
mcd-account-addressing.h \
mcd-account-config.h \
- mcd-account-connection.c \
mcd-account-requests.c \
mcd-account-addressing.c \
mcd-account-manager.c \
diff --git a/src/mcd-account-connection.c b/src/mcd-account-connection.c
index 09b3a219..a532f351 100644
--- a/src/mcd-account-connection.c
+++ b/src/mcd-account-connection.c
@@ -36,118 +36,3 @@
#include "mcd-account-priv.h"
#include "mcd-account-manager.h"
#include "mcd-connection-priv.h"
-
-struct _McdAccountConnectionContext {
- GHashTable *params;
- gboolean user_initiated;
-};
-
-void
-_mcd_account_connection_context_free (McdAccountConnectionContext *c)
-{
- g_hash_table_unref (c->params);
- g_free (c);
-}
-
-void
-_mcd_account_connection_begin (McdAccount *account,
- gboolean user_initiated)
-{
- McdAccountConnectionContext *ctx;
-
- /* check whether a connection process is already ongoing */
- if (_mcd_account_get_connection_context (account) != NULL)
- {
- DEBUG ("already trying to connect");
- return;
- }
-
- /* get account params */
- /* create dynamic params HT */
- /* run the handlers */
- ctx = g_malloc (sizeof (McdAccountConnectionContext));
- ctx->user_initiated = user_initiated;
-
- /* If we get this far, the account should be valid, so getting the
- * parameters should succeed.
- */
- ctx->params = _mcd_account_dup_parameters (account);
- g_assert (ctx->params != NULL);
-
- _mcd_account_set_connection_status (account,
- TP_CONNECTION_STATUS_CONNECTING,
- TP_CONNECTION_STATUS_REASON_REQUESTED,
- NULL, NULL, NULL);
- _mcd_account_set_connection_context (account, ctx);
- mcd_account_connection_proceed (account, TRUE);
-}
-
-void
-mcd_account_connection_proceed_with_reason (McdAccount *account,
- gboolean success,
- TpConnectionStatusReason reason)
-{
- McdAccountConnectionContext *ctx;
- gboolean delayed;
-
- /* call next handler, or terminate the chain (emitting proper signal).
- * if everything is fine, call mcd_manager_create_connection() and
- * _mcd_connection_connect () with the dynamic parameters. Remove that call
- * from mcd_manager_create_connection() */
- ctx = _mcd_account_get_connection_context (account);
- g_return_if_fail (ctx != NULL);
- g_return_if_fail (ctx->params != NULL);
-
- if (success)
- {
- if (mcd_connectivity_monitor_is_online (
- mcd_account_get_connectivity_monitor (account)))
- {
- DEBUG ("%s wants to connect and we're online - go for it",
- mcd_account_get_unique_name (account));
- delayed = FALSE;
- }
- else if (!mcd_account_get_waiting_for_connectivity (account))
- {
- DEBUG ("%s wants to connect, but we're offline; queuing it up",
- mcd_account_get_unique_name (account));
- delayed = TRUE;
- mcd_account_set_waiting_for_connectivity (account, TRUE);
- }
- else
- {
- DEBUG ("%s wants to connect, but is already waiting for "
- "connectivity?", mcd_account_get_unique_name (account));
- delayed = TRUE;
- }
- }
- else
- {
- DEBUG ("%s failed to connect: reason code %d",
- mcd_account_get_unique_name (account), reason);
- delayed = FALSE;
- }
-
- if (!delayed)
- {
- /* end of the chain */
- if (success)
- {
- _mcd_account_connect (account, ctx->params);
- }
- else
- {
- _mcd_account_set_connection_status
- (account, TP_CONNECTION_STATUS_DISCONNECTED, reason, NULL,
- TP_ERROR_STR_DISCONNECTED, NULL);
- }
- _mcd_account_set_connection_context (account, NULL);
- }
-}
-
-void
-mcd_account_connection_proceed (McdAccount *account, gboolean success)
-{
- mcd_account_connection_proceed_with_reason
- (account, success, TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED);
-}
diff --git a/src/mcd-account-priv.h b/src/mcd-account-priv.h
index 269feb62..c4991325 100644
--- a/src/mcd-account-priv.h
+++ b/src/mcd-account-priv.h
@@ -123,19 +123,6 @@ G_GNUC_INTERNAL McdChannel *_mcd_account_create_request (
gboolean use_existing,
McdRequest **request_out, GError **error);
-typedef struct _McdAccountConnectionContext McdAccountConnectionContext;
-
-G_GNUC_INTERNAL
-McdAccountConnectionContext *_mcd_account_get_connection_context
- (McdAccount *self);
-
-G_GNUC_INTERNAL
-void _mcd_account_set_connection_context (McdAccount *self,
- McdAccountConnectionContext *c);
-
-G_GNUC_INTERNAL void _mcd_account_connection_context_free
- (McdAccountConnectionContext *c);
-
typedef void (*McdAccountDupParametersCb) (McdAccount *account,
GHashTable *params,
gpointer user_data);
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 6af1741d..77ef5dfe 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -88,6 +88,11 @@ typedef struct {
gpointer user_data;
} McdOnlineRequestData;
+typedef struct {
+ GHashTable *params;
+ gboolean user_initiated;
+} McdAccountConnectionContext;
+
struct _McdAccountPrivate
{
gchar *unique_name;
@@ -179,6 +184,13 @@ enum
LAST_SIGNAL
};
+static void
+_mcd_account_connection_context_free (McdAccountConnectionContext *c)
+{
+ g_hash_table_unref (c->params);
+ g_free (c);
+}
+
static guint _mcd_account_signals[LAST_SIGNAL] = { 0 };
static GQuark account_ready_quark = 0;
@@ -3260,7 +3272,8 @@ _mcd_account_dispose (GObject *object)
tp_clear_object (&priv->self_contact);
tp_clear_object (&priv->connectivity);
- _mcd_account_set_connection_context (self, NULL);
+ tp_clear_pointer (&self->priv->connection_context,
+ _mcd_account_connection_context_free);
_mcd_account_set_connection (self, NULL);
G_OBJECT_CLASS (mcd_account_parent_class)->dispose (object);
@@ -4871,28 +4884,6 @@ _mcd_account_set_has_been_online (McdAccount *account)
}
}
-McdAccountConnectionContext *
-_mcd_account_get_connection_context (McdAccount *self)
-{
- g_return_val_if_fail (MCD_IS_ACCOUNT (self), NULL);
-
- return self->priv->connection_context;
-}
-
-void
-_mcd_account_set_connection_context (McdAccount *self,
- McdAccountConnectionContext *c)
-{
- g_return_if_fail (MCD_IS_ACCOUNT (self));
-
- if (self->priv->connection_context != NULL)
- {
- _mcd_account_connection_context_free (self->priv->connection_context);
- }
-
- self->priv->connection_context = c;
-}
-
gboolean
_mcd_account_needs_dispatch (McdAccount *self)
{
@@ -4960,3 +4951,107 @@ mcd_account_set_waiting_for_connectivity (McdAccount *self,
{
self->priv->waiting_for_connectivity = waiting;
}
+
+void
+_mcd_account_connection_begin (McdAccount *account,
+ gboolean user_initiated)
+{
+ McdAccountConnectionContext *ctx;
+
+ /* check whether a connection process is already ongoing */
+ if (account->priv->connection_context != NULL)
+ {
+ DEBUG ("already trying to connect");
+ return;
+ }
+
+ /* get account params */
+ /* create dynamic params HT */
+ /* run the handlers */
+ ctx = g_malloc (sizeof (McdAccountConnectionContext));
+ ctx->user_initiated = user_initiated;
+
+ /* If we get this far, the account should be valid, so getting the
+ * parameters should succeed.
+ */
+ ctx->params = _mcd_account_dup_parameters (account);
+ g_assert (ctx->params != NULL);
+
+ _mcd_account_set_connection_status (account,
+ TP_CONNECTION_STATUS_CONNECTING,
+ TP_CONNECTION_STATUS_REASON_REQUESTED,
+ NULL, NULL, NULL);
+ account->priv->connection_context = ctx;
+ mcd_account_connection_proceed (account, TRUE);
+}
+
+void
+mcd_account_connection_proceed_with_reason (McdAccount *account,
+ gboolean success,
+ TpConnectionStatusReason reason)
+{
+ McdAccountConnectionContext *ctx;
+ gboolean delayed;
+
+ /* call next handler, or terminate the chain (emitting proper signal).
+ * if everything is fine, call mcd_manager_create_connection() and
+ * _mcd_connection_connect () with the dynamic parameters. Remove that call
+ * from mcd_manager_create_connection() */
+ ctx = account->priv->connection_context;
+ g_return_if_fail (ctx != NULL);
+ g_return_if_fail (ctx->params != NULL);
+
+ if (success)
+ {
+ if (mcd_connectivity_monitor_is_online (
+ mcd_account_get_connectivity_monitor (account)))
+ {
+ DEBUG ("%s wants to connect and we're online - go for it",
+ mcd_account_get_unique_name (account));
+ delayed = FALSE;
+ }
+ else if (!mcd_account_get_waiting_for_connectivity (account))
+ {
+ DEBUG ("%s wants to connect, but we're offline; queuing it up",
+ mcd_account_get_unique_name (account));
+ delayed = TRUE;
+ mcd_account_set_waiting_for_connectivity (account, TRUE);
+ }
+ else
+ {
+ DEBUG ("%s wants to connect, but is already waiting for "
+ "connectivity?", mcd_account_get_unique_name (account));
+ delayed = TRUE;
+ }
+ }
+ else
+ {
+ DEBUG ("%s failed to connect: reason code %d",
+ mcd_account_get_unique_name (account), reason);
+ delayed = FALSE;
+ }
+
+ if (!delayed)
+ {
+ /* end of the chain */
+ if (success)
+ {
+ _mcd_account_connect (account, ctx->params);
+ }
+ else
+ {
+ _mcd_account_set_connection_status
+ (account, TP_CONNECTION_STATUS_DISCONNECTED, reason, NULL,
+ TP_ERROR_STR_DISCONNECTED, NULL);
+ }
+ tp_clear_pointer (&account->priv->connection_context,
+ _mcd_account_connection_context_free);
+ }
+}
+
+void
+mcd_account_connection_proceed (McdAccount *account, gboolean success)
+{
+ mcd_account_connection_proceed_with_reason
+ (account, success, TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED);
+}