sim: Unify sim_read and sim_read_bytes
authorDenis Kenzior <denkenz@gmail.com>
Tue, 31 Aug 2010 22:55:17 +0000 (17:55 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Thu, 9 Sep 2010 13:50:28 +0000 (08:50 -0500)
src/sim.c

index 99b5090..58f3f64 100644 (file)
--- a/src/sim.c
+++ b/src/sim.c
@@ -2120,9 +2120,10 @@ static gboolean sim_op_next(gpointer user_data)
        return FALSE;
 }
 
-int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
-                       unsigned short offset, int num_bytes,
-                       ofono_sim_file_read_cb_t cb, void *data)
+static int sim_read_common(struct ofono_sim *sim, int id,
+                               enum ofono_sim_file_structure expected_type,
+                               unsigned short offset, int num_bytes,
+                               ofono_sim_file_read_cb_t cb, void *data)
 {
        struct sim_file_op *op;
 
@@ -2148,7 +2149,7 @@ int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
        op = g_new0(struct sim_file_op, 1);
 
        op->id = id;
-       op->structure = OFONO_SIM_FILE_STRUCTURE_TRANSPARENT;
+       op->structure = expected_type;
        op->cb = cb;
        op->userdata = data;
        op->is_read = TRUE;
@@ -2163,46 +2164,19 @@ int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
        return 0;
 }
 
+int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
+                       unsigned short offset, int num_bytes,
+                       ofono_sim_file_read_cb_t cb, void *data)
+{
+       return sim_read_common(sim, id, OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+                               offset, num_bytes, cb, data);
+}
+
 int ofono_sim_read(struct ofono_sim *sim, int id,
                        enum ofono_sim_file_structure expected_type,
                        ofono_sim_file_read_cb_t cb, void *data)
 {
-       struct sim_file_op *op;
-
-       if (!cb)
-               return -1;
-
-       if (sim == NULL)
-               return -1;
-
-       if (!sim->driver)
-               return -1;
-
-       if (!sim->driver->read_file_info)
-               return -1;
-
-       /* TODO: We must first check the EFust table to see whether
-        * this file can be read at all
-        */
-
-       if (!sim->simop_q)
-               sim->simop_q = g_queue_new();
-
-       op = g_new0(struct sim_file_op, 1);
-
-       op->id = id;
-       op->structure = expected_type;
-       op->cb = cb;
-       op->userdata = data;
-       op->is_read = TRUE;
-       op->num_bytes = -1;
-
-       g_queue_push_tail(sim->simop_q, op);
-
-       if (g_queue_get_length(sim->simop_q) == 1)
-               sim->simop_source = g_timeout_add(0, sim_op_next, sim);
-
-       return 0;
+       return sim_read_common(sim, id, expected_type, 0, -1, cb, data);
 }
 
 int ofono_sim_write(struct ofono_sim *sim, int id,