summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denis.kenzior@intel.com>2009-10-22 19:00:38 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-10-23 17:05:55 -0500
commit08eda615c541363869abe379e1973ca8e519a32a (patch)
tree709713115d87c2beaee57056868befe904c0ac6e
parenta12d252609e61a79a49f38de51fd8e809f526a9b (diff)
downloadofono-08eda615c541363869abe379e1973ca8e519a32a.tar.bz2
Refactor/Implement basic activate logic
Not yet tested
-rw-r--r--include/gprs-context.h3
-rw-r--r--src/gprs.c57
2 files changed, 57 insertions, 3 deletions
diff --git a/include/gprs-context.h b/include/gprs-context.h
index 4a1afe2f..1ceb19bf 100644
--- a/include/gprs-context.h
+++ b/include/gprs-context.h
@@ -54,7 +54,8 @@ struct ofono_gprs_context_driver {
const struct ofono_gprs_primary_context *ctx,
ofono_gprs_context_cb_t cb, void *data);
void (*deactivate_primary)(struct ofono_gprs_context *gc,
- unsigned int id);
+ unsigned int id,
+ ofono_gprs_context_cb_t cb, void *data);
};
void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc, unsigned id);
diff --git a/src/gprs.c b/src/gprs.c
index 3124ea29..9e6f00c7 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -61,6 +61,7 @@ struct ofono_gprs {
int cid_min;
int cid_max;
DBusMessage *pending;
+ struct ofono_gprs_context *context_driver;
const struct ofono_gprs_driver *driver;
void *driver_data;
struct ofono_atom *atom;
@@ -68,12 +69,14 @@ struct ofono_gprs {
struct ofono_gprs_context {
struct ofono_gprs *gprs;
+ DBusMessage *pending;
const struct ofono_gprs_context_driver *driver;
void *driver_data;
};
struct pri_context {
ofono_bool_t active;
+ ofono_bool_t pending_active;
enum gprs_context_type type;
char *name;
char *path;
@@ -158,6 +161,39 @@ static DBusMessage *pri_get_properties(DBusConnection *conn,
return reply;
}
+static void pri_set_active_callback(const struct ofono_error *error,
+ void *data)
+{
+ struct pri_context *ctx = data;
+ struct ofono_gprs_context *gc = ctx->gprs->context_driver;
+ DBusConnection *conn = ofono_dbus_get_connection();
+ DBusMessage *reply;
+ const char *path;
+ dbus_bool_t value;
+
+ if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+ ofono_debug("(De)Activating context failed with error: %s",
+ telephony_error_to_str(error));
+
+ ctx->pending_active = ctx->active;
+
+ __ofono_dbus_pending_reply(&gc->pending,
+ __ofono_error_failed(gc->pending));
+ return;
+ }
+
+ ctx->active = ctx->pending_active;
+
+ __ofono_dbus_pending_reply(&gc->pending,
+ dbus_message_new_method_return(gc->pending));
+
+ value = ctx->active;
+ ofono_dbus_signal_property_changed(conn, ctx->path,
+ DATA_CONTEXT_INTERFACE,
+ "Active", DBUS_TYPE_BOOLEAN,
+ &value);
+}
+
static DBusMessage *pri_set_apn(struct pri_context *ctx, DBusConnection *conn,
DBusMessage *msg, const char *apn)
{
@@ -299,7 +335,9 @@ static DBusMessage *pri_set_property(DBusConnection *conn,
dbus_message_iter_recurse(&iter, &var);
if (g_str_equal(property, "Active")) {
- if (ctx->gprs->pending)
+ struct ofono_gprs_context *gc = ctx->gprs->context_driver;
+
+ if (gc->pending)
return __ofono_error_busy(msg);
if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
@@ -316,7 +354,22 @@ static DBusMessage *pri_set_property(DBusConnection *conn,
if (value && !ctx->gprs->attached)
return __ofono_error_failed(msg);
- return __ofono_error_not_implemented(msg);
+ if (gc == NULL || gc->driver->activate_primary == NULL ||
+ gc->driver->deactivate_primary == NULL)
+ return __ofono_error_not_implemented(msg);
+
+ gc->pending = dbus_message_ref(msg);
+
+ ctx->pending_active = value;
+
+ if (value)
+ gc->driver->activate_primary(gc, &ctx->context,
+ pri_set_active_callback, ctx);
+ else
+ gc->driver->deactivate_primary(gc, ctx->context.cid,
+ pri_set_active_callback, ctx);
+
+ return NULL;
}
/* All other properties are read-only when context is active */