From: Zhenhua Zhang <[email protected]>

Remove duplicated code in gprs_deactivate_for_remove and
gprs_remove_context. So they could share the same remove_context method.
---
 src/gprs.c |   59 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 830e143..05e1c70 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -1652,26 +1652,14 @@ static DBusMessage *gprs_add_context(DBusConnection 
*conn,
        return NULL;
 }
 
-static void gprs_deactivate_for_remove(const struct ofono_error *error,
-                                               void *data)
+static void remove_context(struct pri_context *ctx)
 {
-       struct pri_context *ctx = data;
        struct ofono_gprs *gprs = ctx->gprs;
        DBusConnection *conn;
        char *path;
        const char *atompath;
 
-       if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
-               DBG("Removing context failed with error: %s",
-                               telephony_error_to_str(error));
-
-               __ofono_dbus_pending_reply(&gprs->pending,
-                                       __ofono_error_failed(gprs->pending));
-               return;
-       }
-
-       gprs_cid_release(gprs, ctx->context.cid);
-       ctx->context.cid = 0;
+       DBG("%s", ctx->path);
 
        if (gprs->settings) {
                g_key_file_remove_group(gprs->settings, ctx->key, NULL);
@@ -1684,9 +1672,6 @@ static void gprs_deactivate_for_remove(const struct 
ofono_error *error,
        context_dbus_unregister(ctx);
        gprs->contexts = g_slist_remove(gprs->contexts, ctx);
 
-       __ofono_dbus_pending_reply(&gprs->pending,
-                               dbus_message_new_method_return(gprs->pending));
-
        atompath = __ofono_atom_get_path(gprs->atom);
        conn = ofono_dbus_get_connection();
        g_dbus_emit_signal(conn, atompath, OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -1695,13 +1680,38 @@ static void gprs_deactivate_for_remove(const struct 
ofono_error *error,
        g_free(path);
 }
 
+
+static void gprs_deactivate_for_remove(const struct ofono_error *error,
+                                               void *data)
+{
+       struct pri_context *ctx = data;
+       struct ofono_gprs *gprs = ctx->gprs;
+
+       if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+               DBG("Removing context failed with error: %s",
+                               telephony_error_to_str(error));
+
+               __ofono_dbus_pending_reply(&gprs->pending,
+                                       __ofono_error_failed(gprs->pending));
+               return;
+       }
+
+       gprs_cid_release(gprs, ctx->context.cid);
+       ctx->context.cid = 0;
+
+       remove_context(ctx);
+
+       if (gprs->pending)
+               __ofono_dbus_pending_reply(&gprs->pending,
+                               dbus_message_new_method_return(gprs->pending));
+}
+
 static DBusMessage *gprs_remove_context(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
        struct ofono_gprs *gprs = data;
        struct pri_context *ctx;
        const char *path;
-       const char *atompath;
 
        if (gprs->pending)
                return __ofono_error_busy(msg);
@@ -1730,22 +1740,11 @@ static DBusMessage *gprs_remove_context(DBusConnection 
*conn,
                return NULL;
        }
 
-       if (gprs->settings) {
-               g_key_file_remove_group(gprs->settings, ctx->key, NULL);
-               storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
-       }
-
        DBG("Unregistering context: %s", ctx->path);
-       context_dbus_unregister(ctx);
-       gprs->contexts = g_slist_remove(gprs->contexts, ctx);
+       remove_context(ctx);
 
        g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);
 
-       atompath = __ofono_atom_get_path(gprs->atom);
-       g_dbus_emit_signal(conn, atompath, OFONO_CONNECTION_MANAGER_INTERFACE,
-                               "ContextRemoved", DBUS_TYPE_OBJECT_PATH, &path,
-                               DBUS_TYPE_INVALID);
-
        return NULL;
 }
 
-- 
1.7.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to