idmap_put(gprs->cid_map, id);
}
+static gboolean assign_context(struct pri_context *ctx)
+{
+ struct idmap *cidmap = ctx->gprs->cid_map;
+ unsigned int cid_min;
+ GSList *l;
+
+ if (cidmap == NULL)
+ return FALSE;
+
+ cid_min = idmap_get_min(cidmap);
+
+ ctx->context.cid = gprs_cid_alloc(ctx->gprs);
+ if (ctx->context.cid == 0)
+ return FALSE;
+
+ for (l = ctx->gprs->context_drivers; l; l = l->next) {
+ struct ofono_gprs_context *gc = l->data;
+
+ if (gc->inuse == TRUE)
+ continue;
+
+ if (gc->type == OFONO_GPRS_CONTEXT_TYPE_ANY ||
+ gc->type == ctx->type) {
+ ctx->context_driver = gc;
+ ctx->context_driver->inuse = TRUE;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static void release_context(struct pri_context *ctx)
+{
+ if (ctx == NULL || ctx->gprs == NULL || ctx->context_driver == NULL)
+ return;
+
+ gprs_cid_release(ctx->gprs, ctx->context.cid);
+ ctx->context.cid = 0;
+ ctx->context_driver->inuse = FALSE;
+ ctx->context_driver = NULL;
+}
+
static struct pri_context *gprs_context_by_path(struct ofono_gprs *gprs,
const char *ctx_path)
{
telephony_error_to_str(error));
__ofono_dbus_pending_reply(&ctx->pending,
__ofono_error_failed(ctx->pending));
-
- gprs_cid_release(ctx->gprs, ctx->context.cid);
- ctx->context.cid = 0;
- ctx->context_driver->inuse = FALSE;
- ctx->context_driver = NULL;
-
+ release_context(ctx);
return;
}
return;
}
- gprs_cid_release(ctx->gprs, ctx->context.cid);
- ctx->context.cid = 0;
+ release_context(ctx);
ctx->active = FALSE;
- ctx->context_driver->inuse = FALSE;
- ctx->context_driver = NULL;
__ofono_dbus_pending_reply(&ctx->pending,
dbus_message_new_method_return(ctx->pending));
return NULL;
}
-static gboolean assign_context(struct pri_context *ctx)
-{
- struct idmap *cidmap = ctx->gprs->cid_map;
- unsigned int cid_min;
- GSList *l;
-
- if (cidmap == NULL)
- return FALSE;
-
- cid_min = idmap_get_min(cidmap);
-
- ctx->context.cid = gprs_cid_alloc(ctx->gprs);
- if (ctx->context.cid == 0)
- return FALSE;
-
- for (l = ctx->gprs->context_drivers; l; l = l->next) {
- struct ofono_gprs_context *gc = l->data;
-
- if (gc->inuse == TRUE)
- continue;
-
- if (gc->type == OFONO_GPRS_CONTEXT_TYPE_ANY ||
- gc->type == ctx->type) {
- ctx->context_driver = gc;
- ctx->context_driver->inuse = TRUE;
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
static DBusMessage *pri_set_property(DBusConnection *conn,
DBusMessage *msg, void *data)
{
if (ctx->active == FALSE)
continue;
- gprs_cid_release(gprs, ctx->context.cid);
- ctx->context.cid = 0;
+ release_context(ctx);
ctx->active = FALSE;
- ctx->context_driver->inuse = FALSE;
- ctx->context_driver = NULL;
-
pri_reset_context_settings(ctx);
-
value = FALSE;
ofono_dbus_signal_property_changed(conn, ctx->path,
OFONO_CONNECTION_CONTEXT_INTERFACE,
return;
}
- gprs_cid_release(gprs, ctx->context.cid);
- ctx->context.cid = 0;
- ctx->context_driver->inuse = FALSE;
- ctx->context_driver = NULL;
+ release_context(ctx);
if (gprs->settings) {
g_key_file_remove_group(gprs->settings, ctx->key, NULL);
return;
}
- gprs_cid_release(gprs, ctx->context.cid);
- ctx->active = FALSE;
- ctx->context.cid = 0;
- ctx->context_driver->inuse = FALSE;
- ctx->context_driver = NULL;
+ release_context(ctx);
+ ctx->active = FALSE;
pri_reset_context_settings(ctx);
value = ctx->active;
if (ctx->active == FALSE)
break;
- gprs_cid_release(ctx->gprs, ctx->context.cid);
- ctx->context.cid = 0;
+ release_context(ctx);
ctx->active = FALSE;
- ctx->context_driver->inuse = FALSE;
- ctx->context_driver = NULL;
pri_reset_context_settings(ctx);