Refactor supplementary service control strings

The registration was done by using the storage in the modem.  Refactored
to use the new atom watch APIs and storing the control entries in the
ussd atom itself
This commit is contained in:
Denis Kenzior 2009-08-17 14:32:06 -05:00
parent 5e957a7e3e
commit d5339edc44
3 changed files with 83 additions and 170 deletions

View File

@ -67,9 +67,6 @@ struct ofono_modem {
void *userdata; void *userdata;
GSList *ss_control_list;
GSList *ss_passwd_list;
GSList *atoms; GSList *atoms;
GSList *atom_watches; GSList *atom_watches;
int next_atom_watch_id; int next_atom_watch_id;
@ -171,6 +168,26 @@ gboolean __ofono_ssn_mt_watch_remove(struct ofono_ssn *ssn, int id);
#include <ofono/ussd.h> #include <ofono/ussd.h>
typedef gboolean (*ofono_ussd_ssc_cb_t)(int type,
const char *sc,
const char *sia, const char *sib,
const char *sic, const char *dn,
DBusMessage *msg, void *data);
typedef gboolean (*ofono_ussd_passwd_cb_t)(const char *sc,
const char *old, const char *new,
DBusMessage *msg, void *data);
gboolean __ofono_ussd_ssc_register(struct ofono_ussd *ussd, const char *sc,
ofono_ussd_ssc_cb_t cb, void *data,
ofono_destroy_func destroy);
void __ofono_ussd_ssc_unregister(struct ofono_ussd *ussd, const char *sc);
gboolean __ofono_ussd_passwd_register(struct ofono_ussd *ussd, const char *sc,
ofono_ussd_passwd_cb_t cb, void *data,
ofono_destroy_func destroy);
void __ofono_ussd_passwd_unregister(struct ofono_ussd *ussd, const char *sc);
#include <ofono/history.h> #include <ofono/history.h>
void __ofono_history_probe_drivers(struct ofono_modem *modem); void __ofono_history_probe_drivers(struct ofono_modem *modem);

View File

@ -34,7 +34,6 @@
#include "ofono.h" #include "ofono.h"
#include "common.h" #include "common.h"
#include "ussd.h"
#define SUPPLEMENTARY_SERVICES_INTERFACE "org.ofono.SupplementaryServices" #define SUPPLEMENTARY_SERVICES_INTERFACE "org.ofono.SupplementaryServices"
@ -52,202 +51,141 @@ struct ofono_ussd {
int state; int state;
DBusMessage *pending; DBusMessage *pending;
int flags; int flags;
GSList *ss_control_list;
GSList *ss_passwd_list;
const struct ofono_ussd_driver *driver; const struct ofono_ussd_driver *driver;
void *driver_data; void *driver_data;
struct ofono_atom *atom; struct ofono_atom *atom;
}; };
struct ss_control_entry { struct ssc_entry {
char *service; char *service;
ss_control_cb_t cb; void *cb;
void *user;
ofono_destroy_func destroy;
}; };
static struct ss_control_entry *ss_control_entry_create(const char *service, static struct ssc_entry *ssc_entry_create(const char *sc, void *cb, void *data,
ss_control_cb_t cb) ofono_destroy_func destroy)
{ {
struct ss_control_entry *r; struct ssc_entry *r;
r = g_try_new0(struct ss_control_entry, 1); r = g_try_new0(struct ssc_entry, 1);
if (!r) if (!r)
return r; return r;
r->service = g_strdup(service); r->service = g_strdup(sc);
r->cb = cb; r->cb = cb;
r->user = data;
r->destroy = destroy;
return r; return r;
} }
static void ss_control_entry_destroy(struct ss_control_entry *ca) static void ssc_entry_destroy(struct ssc_entry *ca)
{ {
if (ca->destroy)
ca->destroy(ca->user);
g_free(ca->service); g_free(ca->service);
g_free(ca); g_free(ca);
} }
static gint ss_control_entry_compare(gconstpointer a, gconstpointer b) static gint ssc_entry_compare(gconstpointer a, gconstpointer b)
{ {
const struct ss_control_entry *ca = a; const struct ssc_entry *ca = a;
const struct ss_control_entry *cb = b; const struct ssc_entry *cb = b;
int ret;
ret = strcmp(ca->service, cb->service); return strcmp(ca->service, cb->service);
if (ret)
return ret;
if (ca->cb < cb->cb)
return -1;
if (ca->cb > cb->cb)
return 1;
return 0;
} }
static gint ss_control_entry_find_by_service(gconstpointer a, gconstpointer b) static gint ssc_entry_find_by_service(gconstpointer a, gconstpointer b)
{ {
const struct ss_control_entry *ca = a; const struct ssc_entry *ca = a;
return strcmp(ca->service, b); return strcmp(ca->service, b);
} }
gboolean ss_control_register(struct ofono_modem *modem, const char *str, gboolean __ofono_ussd_ssc_register(struct ofono_ussd *ussd, const char *sc,
ss_control_cb_t cb) ofono_ussd_ssc_cb_t cb, void *data,
ofono_destroy_func destroy)
{ {
struct ss_control_entry *entry; struct ssc_entry *entry;
if (!modem) if (!ussd)
return FALSE; return FALSE;
entry = ss_control_entry_create(str, cb); entry = ssc_entry_create(sc, cb, data, destroy);
if (!entry) if (!entry)
return FALSE; return FALSE;
modem->ss_control_list = g_slist_prepend(modem->ss_control_list, entry); ussd->ss_control_list = g_slist_prepend(ussd->ss_control_list, entry);
return TRUE; return TRUE;
} }
void ss_control_unregister(struct ofono_modem *modem, const char *str, void __ofono_ussd_ssc_unregister(struct ofono_ussd *ussd, const char *sc)
ss_control_cb_t cb)
{ {
const struct ss_control_entry entry = { (char *)str, cb };
GSList *l; GSList *l;
if (!modem) if (!ussd)
return; return;
l = g_slist_find_custom(modem->ss_control_list, &entry, l = g_slist_find_custom(ussd->ss_control_list, sc,
ss_control_entry_compare); ssc_entry_find_by_service);
if (!l) if (!l)
return; return;
ss_control_entry_destroy(l->data); ssc_entry_destroy(l->data);
modem->ss_control_list = g_slist_remove(modem->ss_control_list, ussd->ss_control_list = g_slist_remove(ussd->ss_control_list, l->data);
l->data);
} }
struct ss_passwd_entry { gboolean __ofono_ussd_passwd_register(struct ofono_ussd *ussd, const char *sc,
char *service; ofono_ussd_passwd_cb_t cb, void *data,
ss_passwd_cb_t cb; ofono_destroy_func destroy)
};
static struct ss_passwd_entry *ss_passwd_entry_create(const char *service,
ss_passwd_cb_t cb)
{ {
struct ss_passwd_entry *r; struct ssc_entry *entry;
r = g_try_new0(struct ss_passwd_entry, 1); if (!ussd)
if (!r)
return r;
r->service = g_strdup(service);
r->cb = cb;
return r;
}
static void ss_passwd_entry_destroy(struct ss_passwd_entry *ca)
{
g_free(ca->service);
g_free(ca);
}
static gint ss_passwd_entry_compare(gconstpointer a, gconstpointer b)
{
const struct ss_passwd_entry *ca = a;
const struct ss_passwd_entry *cb = b;
int ret;
ret = strcmp(ca->service, cb->service);
if (ret)
return ret;
if (ca->cb < cb->cb)
return -1;
if (ca->cb > cb->cb)
return 1;
return 0;
}
static gint ss_passwd_entry_find_by_service(gconstpointer a, gconstpointer b)
{
const struct ss_passwd_entry *ca = a;
return strcmp(ca->service, b);
}
gboolean ss_passwd_register(struct ofono_modem *modem, const char *str,
ss_passwd_cb_t cb)
{
struct ss_passwd_entry *entry;
if (!modem)
return FALSE; return FALSE;
entry = ss_passwd_entry_create(str, cb); entry = ssc_entry_create(sc, cb, data, destroy);
if (!entry) if (!entry)
return FALSE; return FALSE;
modem->ss_passwd_list = g_slist_prepend(modem->ss_passwd_list, entry); ussd->ss_passwd_list = g_slist_prepend(ussd->ss_passwd_list, entry);
return TRUE; return TRUE;
} }
void ss_passwd_unregister(struct ofono_modem *modem, const char *str, void __ofono_ussd_passwd_unregister(struct ofono_ussd *ussd, const char *sc)
ss_passwd_cb_t cb)
{ {
const struct ss_passwd_entry entry = { (char *)str, cb };
GSList *l; GSList *l;
if (!modem) if (!ussd)
return; return;
l = g_slist_find_custom(modem->ss_passwd_list, &entry, l = g_slist_find_custom(ussd->ss_passwd_list, sc,
ss_passwd_entry_compare); ssc_entry_find_by_service);
if (!l) if (!l)
return; return;
ss_passwd_entry_destroy(l->data); ssc_entry_destroy(l->data);
modem->ss_passwd_list = g_slist_remove(modem->ss_passwd_list, ussd->ss_passwd_list = g_slist_remove(ussd->ss_passwd_list, l->data);
l->data);
} }
static gboolean recognized_passwd_change_string(struct ofono_modem *modem, static gboolean recognized_passwd_change_string(struct ofono_ussd *ussd,
int type, char *sc, int type, char *sc,
char *sia, char *sib, char *sia, char *sib,
char *sic, char *sid, char *sic, char *sid,
char *dn, DBusMessage *msg) char *dn, DBusMessage *msg)
{ {
GSList *l = modem->ss_passwd_list; GSList *l = ussd->ss_passwd_list;
switch (type) { switch (type) {
case SS_CONTROL_TYPE_ACTIVATION: case SS_CONTROL_TYPE_ACTIVATION:
@ -270,10 +208,11 @@ static gboolean recognized_passwd_change_string(struct ofono_modem *modem,
} }
while ((l = g_slist_find_custom(l, sia, while ((l = g_slist_find_custom(l, sia,
ss_passwd_entry_find_by_service)) != NULL) { ssc_entry_find_by_service)) != NULL) {
struct ss_passwd_entry *entry = l->data; struct ssc_entry *entry = l->data;
ofono_ussd_passwd_cb_t cb = entry->cb;
if (entry->cb(modem, sia, sib, sic, msg)) if (cb(sia, sib, sic, msg, entry->user))
return TRUE; return TRUE;
l = l->next; l = l->next;
@ -282,7 +221,7 @@ static gboolean recognized_passwd_change_string(struct ofono_modem *modem,
return FALSE; return FALSE;
} }
static gboolean recognized_control_string(struct ofono_modem *modem, static gboolean recognized_control_string(struct ofono_ussd *ussd,
const char *ss_str, const char *ss_str,
DBusMessage *msg) DBusMessage *msg)
{ {
@ -295,7 +234,7 @@ static gboolean recognized_control_string(struct ofono_modem *modem,
if (parse_ss_control_string(str, &type, &sc, if (parse_ss_control_string(str, &type, &sc,
&sia, &sib, &sic, &sid, &dn)) { &sia, &sib, &sic, &sid, &dn)) {
GSList *l = modem->ss_control_list; GSList *l = ussd->ss_control_list;
ofono_debug("Got parse result: %d, %s, %s, %s, %s, %s, %s", ofono_debug("Got parse result: %d, %s, %s, %s, %s, %s, %s",
type, sc, sia, sib, sic, sid, dn); type, sc, sia, sib, sic, sid, dn);
@ -303,7 +242,7 @@ static gboolean recognized_control_string(struct ofono_modem *modem,
/* A password change string needs to be treated separately /* A password change string needs to be treated separately
* because it uses a fourth SI and is thus not a valid * because it uses a fourth SI and is thus not a valid
* control string. */ * control string. */
if (recognized_passwd_change_string(modem, type, sc, if (recognized_passwd_change_string(ussd, type, sc,
sia, sib, sic, sid, dn, msg)) { sia, sib, sic, sid, dn, msg)) {
ret = TRUE; ret = TRUE;
goto out; goto out;
@ -313,10 +252,11 @@ static gboolean recognized_control_string(struct ofono_modem *modem,
goto out; goto out;
while ((l = g_slist_find_custom(l, sc, while ((l = g_slist_find_custom(l, sc,
ss_control_entry_find_by_service)) != NULL) { ssc_entry_find_by_service)) != NULL) {
struct ss_control_entry *entry = l->data; struct ssc_entry *entry = l->data;
ofono_ussd_ssc_cb_t cb = entry->cb;
if (entry->cb(modem, type, sc, sia, sib, sic, dn, msg)) { if (cb(type, sc, sia, sib, sic, dn, msg, entry->user)) {
ret = TRUE; ret = TRUE;
goto out; goto out;
} }
@ -432,7 +372,6 @@ static DBusMessage *ussd_initiate(DBusConnection *conn, DBusMessage *msg,
void *data) void *data)
{ {
struct ofono_ussd *ussd = data; struct ofono_ussd *ussd = data;
struct ofono_modem *modem = __ofono_atom_get_modem(ussd->atom);
const char *str; const char *str;
if (ussd->flags & USSD_FLAG_PENDING) if (ussd->flags & USSD_FLAG_PENDING)
@ -449,7 +388,7 @@ static DBusMessage *ussd_initiate(DBusConnection *conn, DBusMessage *msg,
return __ofono_error_invalid_format(msg); return __ofono_error_invalid_format(msg);
ofono_debug("checking if this is a recognized control string"); ofono_debug("checking if this is a recognized control string");
if (recognized_control_string(modem, str, msg)) if (recognized_control_string(ussd, str, msg))
return NULL; return NULL;
ofono_debug("No.., checking if this is a USSD string"); ofono_debug("No.., checking if this is a USSD string");

View File

@ -1,43 +0,0 @@
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2008-2009 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
typedef gboolean (*ss_control_cb_t)(struct ofono_modem *modem,
enum ss_control_type type,
const char *sc,
const char *sia, const char *sib,
const char *sic, const char *dn,
DBusMessage *msg);
typedef gboolean (*ss_passwd_cb_t)(struct ofono_modem *modem, const char *sc,
const char *old, const char *new,
DBusMessage *msg);
gboolean ss_control_register(struct ofono_modem *modem, const char *str,
ss_control_cb_t cb);
void ss_control_unregister(struct ofono_modem *modem, const char *str,
ss_control_cb_t cb);
gboolean ss_passwd_register(struct ofono_modem *modem, const char *str,
ss_passwd_cb_t cb);
void ss_passwd_unregister(struct ofono_modem *modem, const char *str,
ss_passwd_cb_t cb);