All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] Extend sim-ready watch with card insert/eject events.
@ 2010-04-09  6:48 Andrzej Zaborowski
  2010-04-15 21:17 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Andrzej Zaborowski @ 2010-04-09  6:48 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 7830 bytes --]

---
 include/sim.h |   17 ++++++++++++-----
 src/cbs.c     |    2 +-
 src/modem.c   |   11 ++++++-----
 src/sim.c     |   49 +++++++++++++++++++++++++------------------------
 4 files changed, 44 insertions(+), 35 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 6ff29f7..23b1905 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -71,6 +71,12 @@ enum ofono_sim_cphs_phase {
 	OFONO_SIM_CPHS_PHASE_2G,
 };
 
+enum ofono_sim_state {
+	OFONO_SIM_STATE_NOT_PRESENT,
+	OFONO_SIM_STATE_INSERTED,
+	OFONO_SIM_STATE_READY,
+};
+
 typedef void (*ofono_sim_file_info_cb_t)(const struct ofono_error *error,
 					int filelength,
 					enum ofono_sim_file_structure structure,
@@ -88,7 +94,8 @@ typedef void (*ofono_sim_write_cb_t)(const struct ofono_error *error,
 typedef void (*ofono_sim_imsi_cb_t)(const struct ofono_error *error,
 					const char *imsi, void *data);
 
-typedef void (*ofono_sim_ready_notify_cb_t)(void *data);
+typedef void (*ofono_sim_state_event_notify_cb_t)(void *data,
+					enum ofono_sim_state new_state);
 
 typedef void (*ofono_sim_file_read_cb_t)(int ok, int total_length, int record,
 					const unsigned char *data,
@@ -173,13 +180,13 @@ enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
 const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim);
 
-unsigned int ofono_sim_add_ready_watch(struct ofono_sim *sim,
-				ofono_sim_ready_notify_cb_t cb,
+unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
+				ofono_sim_state_event_notify_cb_t cb,
 				void *data, ofono_destroy_func destroy);
 
-void ofono_sim_remove_ready_watch(struct ofono_sim *sim, unsigned int id);
+void ofono_sim_remove_state_watch(struct ofono_sim *sim, unsigned int id);
 
-int ofono_sim_get_ready(struct ofono_sim *sim);
+enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim);
 void ofono_sim_set_ready(struct ofono_sim *sim);
 
 /* This will queue an operation to read all available records with id from the
diff --git a/src/cbs.c b/src/cbs.c
index d04404e..2fa33c1 100644
--- a/src/cbs.c
+++ b/src/cbs.c
@@ -1046,7 +1046,7 @@ void ofono_cbs_register(struct ofono_cbs *cbs)
 	if (sim_atom) {
 		cbs->sim = __ofono_atom_get_data(sim_atom);
 
-		if (ofono_sim_get_ready(cbs->sim) == TRUE)
+		if (ofono_sim_get_state(cbs->sim) == OFONO_SIM_STATE_READY)
 			cbs_got_imsi(cbs);
 	}
 
diff --git a/src/modem.c b/src/modem.c
index b935328..df74be3 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -1117,10 +1117,13 @@ static void emit_modems()
 	g_free(modems);
 }
 
-static void modem_sim_ready(void *user)
+static void modem_sim_ready(void *user, enum ofono_sim_state new_state)
 {
 	struct ofono_modem *modem = user;
 
+	if (new_state != OFONO_SIM_STATE_READY)
+		return;
+
 	if (modem->driver->post_sim)
 		modem->driver->post_sim(modem);
 
@@ -1138,12 +1141,10 @@ static void sim_watch(struct ofono_atom *atom,
 	}
 
 	modem->sim = __ofono_atom_get_data(atom);
-	modem->sim_ready_watch = ofono_sim_add_ready_watch(modem->sim,
+	modem->sim_ready_watch = ofono_sim_add_state_watch(modem->sim,
 							modem_sim_ready,
 							modem, NULL);
-
-	if (ofono_sim_get_ready(modem->sim))
-		modem_sim_ready(modem);
+	modem_sim_ready(modem, ofono_sim_get_state(modem->sim));
 }
 
 int ofono_modem_register(struct ofono_modem *modem)
diff --git a/src/sim.c b/src/sim.c
index f64c7d4..58de191 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -77,7 +77,7 @@ struct ofono_sim {
 	GSList *new_numbers;
 	GSList *service_numbers;
 	gboolean sdn_ready;
-	gboolean ready;
+	enum ofono_sim_state state;
 	enum ofono_sim_password_type pin_type;
 	gboolean locked_pins[OFONO_SIM_PASSWORD_INVALID];
 	char **language_prefs;
@@ -89,7 +89,7 @@ struct ofono_sim {
 	unsigned char efli_length;
 	enum ofono_sim_cphs_phase cphs_phase;
 	unsigned char cphs_service_table[2];
-	struct ofono_watchlist *ready_watches;
+	struct ofono_watchlist *state_watches;
 	const struct ofono_sim_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
@@ -968,10 +968,13 @@ static void sim_own_numbers_update(struct ofono_sim *sim)
 			sim_msisdn_read_cb, sim);
 }
 
-static void sim_ready(void *user)
+static void sim_ready(void *user, enum ofono_sim_state new_state)
 {
 	struct ofono_sim *sim = user;
 
+	if (new_state != OFONO_SIM_STATE_READY)
+		return;
+
 	sim_own_numbers_update(sim);
 
 	ofono_sim_read(sim, SIM_EFAD_FILEID,
@@ -1775,8 +1778,8 @@ const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim)
 	return sim->cphs_service_table;
 }
 
-unsigned int ofono_sim_add_ready_watch(struct ofono_sim *sim,
-				ofono_sim_ready_notify_cb_t notify,
+unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
+				ofono_sim_state_event_notify_cb_t notify,
 				void *data, ofono_destroy_func destroy)
 {
 	struct ofono_watchlist_item *item;
@@ -1795,43 +1798,40 @@ unsigned int ofono_sim_add_ready_watch(struct ofono_sim *sim,
 	item->destroy = destroy;
 	item->notify_data = data;
 
-	return __ofono_watchlist_add_item(sim->ready_watches, item);
+	return __ofono_watchlist_add_item(sim->state_watches, item);
 }
 
-void ofono_sim_remove_ready_watch(struct ofono_sim *sim, unsigned int id)
+void ofono_sim_remove_state_watch(struct ofono_sim *sim, unsigned int id)
 {
-	__ofono_watchlist_remove_item(sim->ready_watches, id);
+	__ofono_watchlist_remove_item(sim->state_watches, id);
 }
 
-int ofono_sim_get_ready(struct ofono_sim *sim)
+enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim)
 {
 	if (sim == NULL)
-		return 0;
+		return OFONO_SIM_STATE_NOT_PRESENT;
 
-	if (sim->ready == TRUE)
-		return 1;
-
-	return 0;
+	return sim->state;
 }
 
 void ofono_sim_set_ready(struct ofono_sim *sim)
 {
 	GSList *l;
-	ofono_sim_ready_notify_cb_t notify;
+	ofono_sim_state_event_notify_cb_t notify;
 
 	if (sim == NULL)
 		return;
 
-	if (sim->ready == TRUE)
+	if (sim->state != OFONO_SIM_STATE_INSERTED)
 		return;
 
-	sim->ready = TRUE;
+	sim->state = OFONO_SIM_STATE_READY;
 
-	for (l = sim->ready_watches->items; l; l = l->next) {
+	for (l = sim->state_watches->items; l; l = l->next) {
 		struct ofono_watchlist_item *item = l->data;
 		notify = item->notify;
 
-		notify(item->notify_data);
+		notify(item->notify_data, sim->state);
 	}
 }
 
@@ -1851,7 +1851,7 @@ void __ofono_cbs_sim_download(struct ofono_sim *sim,
 {
 	guint8 tlv[pdu_len + 8];
 
-	if (sim->ready != TRUE)
+	if (sim->state != OFONO_SIM_STATE_READY)
 		return;
 
 	if (sim->driver->envelope == NULL)
@@ -1897,8 +1897,8 @@ static void sim_unregister(struct ofono_atom *atom)
 	const char *path = __ofono_atom_get_path(atom);
 	struct ofono_sim *sim = __ofono_atom_get_data(atom);
 
-	__ofono_watchlist_free(sim->ready_watches);
-	sim->ready_watches = NULL;
+	__ofono_watchlist_free(sim->state_watches);
+	sim->state_watches = NULL;
 
 	g_dbus_unregister_interface(conn, path, OFONO_SIM_MANAGER_INTERFACE);
 	ofono_modem_remove_interface(modem, OFONO_SIM_MANAGER_INTERFACE);
@@ -2012,11 +2012,12 @@ void ofono_sim_register(struct ofono_sim *sim)
 	}
 
 	ofono_modem_add_interface(modem, OFONO_SIM_MANAGER_INTERFACE);
-	sim->ready_watches = __ofono_watchlist_new(g_free);
+	sim->state_watches = __ofono_watchlist_new(g_free);
+	sim->state = OFONO_SIM_STATE_INSERTED;
 
 	__ofono_atom_register(sim->atom, sim_unregister);
 
-	ofono_sim_add_ready_watch(sim, sim_ready, sim, NULL);
+	ofono_sim_add_state_watch(sim, sim_ready, sim, NULL);
 
 	/* Perform SIM initialization according to 3GPP 31.102 Section 5.1.1.2
 	 * The assumption here is that if sim manager is being initialized,
-- 
1.6.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-04-15 21:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-09  6:48 [PATCH 1/8] Extend sim-ready watch with card insert/eject events Andrzej Zaborowski
2010-04-15 21:17 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.