diff options
author | Denis Kenzior <denkenz@gmail.com> | 2010-08-19 15:10:06 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-08-19 15:10:30 -0500 |
commit | 18d8584adbab48319bab7082ccd2232e88095e53 (patch) | |
tree | 564753d2eba1c1e6cdcf49b430d7661875f73b4f /src/gprs.c | |
parent | 86b58a7e43e81522b2c8aad232eb76fa1e9bb89b (diff) | |
download | ofono-18d8584adbab48319bab7082ccd2232e88095e53.tar.bz2 |
gprs: Automatically add a context if none defined
Diffstat (limited to 'src/gprs.c')
-rw-r--r-- | src/gprs.c | 62 |
1 files changed, 39 insertions, 23 deletions
@@ -1150,25 +1150,12 @@ static void write_context_settings(struct ofono_gprs *gprs, gprs_proto_to_string(context->context.proto)); } -static DBusMessage *gprs_add_context(DBusConnection *conn, - DBusMessage *msg, void *data) +static struct pri_context *add_context(struct ofono_gprs *gprs, + const char *name, + enum gprs_context_type type) { - struct ofono_gprs *gprs = data; - struct pri_context *context; - const char *typestr; - const char *path; - enum gprs_context_type type; unsigned int id; - DBusMessage *signal; - - if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr, - DBUS_TYPE_INVALID)) - return __ofono_error_invalid_args(msg); - - type = gprs_context_string_to_type(typestr); - - if (type == GPRS_CONTEXT_TYPE_INVALID) - return __ofono_error_invalid_format(msg); + struct pri_context *context; if (gprs->last_context_id) id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id); @@ -1176,21 +1163,21 @@ static DBusMessage *gprs_add_context(DBusConnection *conn, id = idmap_alloc(gprs->pid_map); if (id > idmap_get_max(gprs->pid_map)) - return __ofono_error_not_supported(msg); - - context = pri_context_create(gprs, typestr, type); - context->id = id; + return NULL; + context = pri_context_create(gprs, name, type); if (!context) { ofono_error("Unable to allocate context struct"); - return __ofono_error_failed(msg); + return NULL; } + context->id = id; + DBG("Registering new context"); if (!context_dbus_register(context)) { ofono_error("Unable to register primary context"); - return __ofono_error_failed(msg); + return NULL; } gprs->last_context_id = id; @@ -1202,6 +1189,32 @@ static DBusMessage *gprs_add_context(DBusConnection *conn, gprs->contexts = g_slist_append(gprs->contexts, context); + return context; +} + +static DBusMessage *gprs_add_context(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct ofono_gprs *gprs = data; + struct pri_context *context; + const char *typestr; + const char *path; + enum gprs_context_type type; + DBusMessage *signal; + + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr, + DBUS_TYPE_INVALID)) + return __ofono_error_invalid_args(msg); + + type = gprs_context_string_to_type(typestr); + + if (type == GPRS_CONTEXT_TYPE_INVALID) + return __ofono_error_invalid_format(msg); + + context = add_context(gprs, typestr, type); + if (context == NULL) + return __ofono_error_failed(msg); + path = context->path; g_dbus_send_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &path, @@ -1953,6 +1966,9 @@ void ofono_gprs_register(struct ofono_gprs *gprs) gprs_load_settings(gprs, imsi); } + if (gprs->contexts == NULL) + add_context(gprs, "internet", GPRS_CONTEXT_TYPE_INTERNET); + gprs->netreg_watch = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_NETREG, netreg_watch, gprs, NULL); |