diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-01-17 15:41:06 +0100 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-12 12:30:41 +0200 |
commit | 3d9c255172a9641fd7df32a71fbeeac0642ee08d (patch) | |
tree | e95f00fda7305051ca327705e884abf9f1df67f9 | |
parent | a24526a08c468cac853d26615cf66fed3137ccc2 (diff) |
add TpProxyFeature.can_retry
-rw-r--r-- | telepathy-glib/proxy-internal.h | 2 | ||||
-rw-r--r-- | telepathy-glib/proxy.c | 5 | ||||
-rw-r--r-- | tests/dbus/proxy-preparation.c | 32 | ||||
-rw-r--r-- | tests/lib/my-conn-proxy.c | 34 | ||||
-rw-r--r-- | tests/lib/my-conn-proxy.h | 7 |
5 files changed, 79 insertions, 1 deletions
diff --git a/telepathy-glib/proxy-internal.h b/telepathy-glib/proxy-internal.h index 35a9073b..ade38d26 100644 --- a/telepathy-glib/proxy-internal.h +++ b/telepathy-glib/proxy-internal.h @@ -45,6 +45,8 @@ struct _TpProxyFeature { /* Features we depend on */ const GQuark *depends_on; + gboolean can_retry; + /*<private>*/ GCallback _reserved[4]; TpProxyFeaturePrivate *priv; diff --git a/telepathy-glib/proxy.c b/telepathy-glib/proxy.c index 90fd2c10..f315abb7 100644 --- a/telepathy-glib/proxy.c +++ b/telepathy-glib/proxy.c @@ -1776,13 +1776,16 @@ tp_proxy_prepare_async (gpointer self, for (i = 0; features[i] != 0; i++) { FeatureState state = tp_proxy_get_feature_state (self, features[i]); + const TpProxyFeature *feature = tp_proxy_subclass_get_feature ( + G_OBJECT_TYPE (self), features[i]); /* We just skip unknown features, which have state FEATURE_STATE_INVALID * (this doesn't seem ideal, but is * consistent with TpAccountManager's existing behaviour) */ if (state == FEATURE_STATE_INVALID) continue; - else if (state == FEATURE_STATE_UNWANTED) + else if (state == FEATURE_STATE_UNWANTED || + (state == FEATURE_STATE_FAILED && feature->can_retry)) { gboolean failed; diff --git a/tests/dbus/proxy-preparation.c b/tests/dbus/proxy-preparation.c index c52a0c37..fa9b088a 100644 --- a/tests/dbus/proxy-preparation.c +++ b/tests/dbus/proxy-preparation.c @@ -218,6 +218,36 @@ test_fail_dep (Test *test, TP_TESTS_MY_CONN_PROXY_FEATURE_FAIL_DEP)); } +static void +test_retry (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + /* We have the prepare the feature twice */ + GQuark features[] = { TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY, 0 }; + + tp_proxy_prepare_async (test->my_conn, features, prepare_cb, test); + + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + g_assert (tp_proxy_is_prepared (test->my_conn, + TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); + g_assert (!tp_proxy_is_prepared (test->my_conn, + TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY)); + + /* second attempt */ + test->my_conn->retry_feature_success = TRUE; + tp_proxy_prepare_async (test->my_conn, features, prepare_cb, test); + + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + g_assert (tp_proxy_is_prepared (test->my_conn, + TP_TESTS_MY_CONN_PROXY_FEATURE_CORE)); + g_assert (tp_proxy_is_prepared (test->my_conn, + TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY)); +} + int main (int argc, char **argv) @@ -243,6 +273,8 @@ main (int argc, test_fail, teardown); g_test_add ("/proxy-preparation/fail-dep", Test, NULL, setup, test_fail_dep, teardown); + g_test_add ("/proxy-preparation/retry", Test, NULL, setup, + test_retry, teardown); return g_test_run (); } diff --git a/tests/lib/my-conn-proxy.c b/tests/lib/my-conn-proxy.c index d68e660a..26a32a83 100644 --- a/tests/lib/my-conn-proxy.c +++ b/tests/lib/my-conn-proxy.c @@ -29,6 +29,7 @@ enum { FEAT_BAD_DEP, FEAT_FAIL, FEAT_FAIL_DEP, + FEAT_RETRY, N_FEAT }; @@ -112,6 +113,29 @@ prepare_fail_async (TpProxy *proxy, g_object_unref (result); } +static void +prepare_retry_async (TpProxy *proxy, + const TpProxyFeature *feature, + GAsyncReadyCallback callback, + gpointer user_data) +{ + TpTestsMyConnProxy *self = (TpTestsMyConnProxy *) proxy; + GSimpleAsyncResult *result; + + result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, + prepare_retry_async); + + if (!self->retry_feature_success) + { + /* Fail the first time we try to prepare the feature */ + g_simple_async_result_set_error (result, TP_ERRORS, + TP_ERROR_NOT_YET, "Nah"); + } + + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); +} + static const TpProxyFeature * list_features (TpProxyClass *cls G_GNUC_UNUSED) { @@ -158,6 +182,10 @@ list_features (TpProxyClass *cls G_GNUC_UNUSED) need_fail[0] = TP_TESTS_MY_CONN_PROXY_FEATURE_FAIL; features[FEAT_FAIL_DEP].depends_on = need_fail; + features[FEAT_RETRY].name = TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY; + features[FEAT_RETRY].prepare_async = prepare_retry_async; + features[FEAT_RETRY].can_retry = TRUE; + return features; } @@ -210,3 +238,9 @@ tp_tests_my_conn_proxy_get_feature_quark_fail_dep (void) { return g_quark_from_static_string ("tp-my-conn-proxy-feature-fail-dep"); } + +GQuark +tp_tests_my_conn_proxy_get_feature_quark_retry (void) +{ + return g_quark_from_static_string ("tp-my-conn-proxy-feature-retry"); +} diff --git a/tests/lib/my-conn-proxy.h b/tests/lib/my-conn-proxy.h index 5861bd44..8dae142a 100644 --- a/tests/lib/my-conn-proxy.h +++ b/tests/lib/my-conn-proxy.h @@ -27,6 +27,8 @@ struct _TpTestsMyConnProxyClass { struct _TpTestsMyConnProxy { TpConnection parent; + + gboolean retry_feature_success; }; GType tp_tests_my_conn_proxy_get_type (void); @@ -83,6 +85,11 @@ GQuark tp_tests_my_conn_proxy_get_feature_quark_fail (void) G_GNUC_CONST; (tp_tests_my_conn_proxy_get_feature_quark_fail_dep ()) GQuark tp_tests_my_conn_proxy_get_feature_quark_fail_dep (void) G_GNUC_CONST; +/* Fail at first attempt but succeed after */ +#define TP_TESTS_MY_CONN_PROXY_FEATURE_RETRY \ + (tp_tests_my_conn_proxy_get_feature_quark_retry ()) +GQuark tp_tests_my_conn_proxy_get_feature_quark_retry (void) G_GNUC_CONST; + G_END_DECLS #endif /* #ifndef __TP_TESTS_MY_CONN_PROXY_H__ */ |