Skip to content

Commit

Permalink
Added mms_connman_default_imsi API
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Feb 19, 2014
1 parent db2304a commit b606e0c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mms-lib/include/mms_connman.h
Expand Up @@ -19,6 +19,7 @@

typedef struct mms_connman_class {
GObjectClass parent;
char* (*fn_default_imsi)(MMSConnMan* cm);
MMSConnection* (*fn_open_connection)(MMSConnMan* cm, const char* imsi,
gboolean user_request);
} MMSConnManClass;
Expand All @@ -35,6 +36,14 @@ void
mms_connman_unref(
MMSConnMan* cm);

/**
* Returns default (first available) IMSI or NULL if SIM is not present
* or not configured. Caller must g_free() the returned string.
*/
char*
mms_connman_default_imsi(
MMSConnMan* cm);

/**
* Creates a new connection or returns the reference to an aready active one.
* The caller must release the reference.
Expand Down
17 changes: 17 additions & 0 deletions mms-lib/src/mms_connman.c
Expand Up @@ -55,6 +55,23 @@ mms_connman_init(
{
}

/**
* Returns default (first available) IMSI or NULL if SIM is not present
* or not configured. Caller must g_free() the returned string.
*/
char*
mms_connman_default_imsi(
MMSConnMan* cm)
{
if (cm) {
MMSConnManClass* klass = MMS_CONNMAN_GET_CLASS(cm);
if (klass->fn_default_imsi) {
return klass->fn_default_imsi(cm);
}
}
return NULL;
}

/**
* Creates a new connection or returns the reference to an aready active one.
* The caller must release the reference.
Expand Down
19 changes: 19 additions & 0 deletions mms-ofono/src/mms_ofono_connman.c
Expand Up @@ -37,6 +37,24 @@ G_DEFINE_TYPE(MMSOfonoConnMan, mms_ofono_connman, MMS_TYPE_CONNMAN);
#define MMS_OFONO_CONNMAN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
MMS_TYPE_OFONO_CONNMAN, MMSOfonoConnMan))

/**
* Returns IMSI of the default SIM
*/
static
char*
mms_ofono_connman_default_imsi(
MMSConnMan* cm)
{
MMSOfonoConnMan* ofono = MMS_OFONO_CONNMAN(cm);
if (ofono->man) {
MMSOfonoModem* modem = mms_ofono_manager_default_modem(ofono->man);
if (modem && modem->imsi) {
return g_strdup(modem->imsi);
}
}
return NULL;
}

/**
* Creates a new connection or returns the reference to an aready active one.
* The caller must release the reference.
Expand Down Expand Up @@ -153,6 +171,7 @@ void
mms_ofono_connman_class_init(
MMSOfonoConnManClass* klass)
{
klass->fn_default_imsi = mms_ofono_connman_default_imsi;
klass->fn_open_connection = mms_ofono_connman_open_connection;
G_OBJECT_CLASS(klass)->dispose = mms_ofono_connman_dispose;
}
Expand Down
15 changes: 15 additions & 0 deletions mms-ofono/src/mms_ofono_manager.c
Expand Up @@ -155,6 +155,21 @@ mms_ofono_manager_modem_imsi_find_cb(
return modem->imsi && !strcmp(modem->imsi, imsi);
}

MMSOfonoModem*
mms_ofono_manager_default_modem(
MMSOfonoManager* ofono)
{
if (g_hash_table_size(ofono->modems) > 0) {
GHashTableIter iter;
gpointer key, value = NULL;
g_hash_table_iter_init(&iter, ofono->modems);
if (g_hash_table_iter_next(&iter, &key, &value)) {
return value;
}
}
return NULL;
}

MMSOfonoModem*
mms_ofono_manager_modem_for_imsi(
MMSOfonoManager* ofono,
Expand Down
4 changes: 4 additions & 0 deletions mms-ofono/src/mms_ofono_manager.h
Expand Up @@ -25,6 +25,10 @@ void
mms_ofono_manager_free(
MMSOfonoManager* ofono);

MMSOfonoModem*
mms_ofono_manager_default_modem(
MMSOfonoManager* ofono);

MMSOfonoModem*
mms_ofono_manager_modem_for_imsi(
MMSOfonoManager* ofono,
Expand Down

0 comments on commit b606e0c

Please sign in to comment.