Refactor: Move alloc/release id to atutil.c
authorZhenhua Zhang <zhenhua.zhang@intel.com>
Wed, 28 Oct 2009 17:42:39 +0000 (01:42 +0800)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 28 Oct 2009 22:31:44 +0000 (17:31 -0500)
drivers/atmodem/atutil.c
drivers/atmodem/atutil.h
drivers/atmodem/voicecall.c

index 578522f..26d0c25 100644 (file)
@@ -81,3 +81,23 @@ gint at_util_call_compare(gconstpointer a, gconstpointer b)
        return 0;
 }
 
+unsigned int at_util_alloc_next_id(unsigned int *id_list)
+{
+       unsigned int i;
+
+       for (i = 1; i < sizeof(unsigned int) * 8; i++) {
+               if (*id_list & (1 << i))
+                       continue;
+
+               *id_list |= (1 << i);
+               return i;
+       }
+
+       return 0;
+}
+
+void at_util_release_id(unsigned int *id_list, unsigned int id)
+{
+       *id_list &= ~(1 << id);
+}
+
index ab9db05..0444561 100644 (file)
@@ -23,6 +23,8 @@ void decode_at_error(struct ofono_error *error, const char *final);
 void dump_response(const char *func, gboolean ok, GAtResult *result);
 gint at_util_call_compare_by_status(gconstpointer a, gconstpointer b);
 gint at_util_call_compare(gconstpointer a, gconstpointer b);
+unsigned int at_util_alloc_next_id(unsigned int *id_list);
+void at_util_release_id(unsigned int *id_list, unsigned int id);
 
 struct cb_data {
        void *cb;
index f0c8d93..0733607 100644 (file)
@@ -89,26 +89,6 @@ static int class_to_call_type(int cls)
        }
 }
 
-static unsigned int alloc_next_id(struct voicecall_data *d)
-{
-       unsigned int i;
-
-       for (i = 1; i < sizeof(d->id_list) * 8; i++) {
-               if (d->id_list & (0x1 << i))
-                       continue;
-
-               d->id_list |= (0x1 << i);
-               return i;
-       }
-
-       return 0;
-}
-
-static void release_id(struct voicecall_data *d, unsigned int id)
-{
-       d->id_list &= ~(0x1 << id);
-}
-
 static struct ofono_call *create_call(struct voicecall_data *d, int type,
                                        int direction, int status,
                                        const char *num, int num_type, int clip)
@@ -121,7 +101,7 @@ static struct ofono_call *create_call(struct voicecall_data *d, int type,
        if (!call)
                return NULL;
 
-       call->id = alloc_next_id(d);
+       call->id = at_util_alloc_next_id(&d->id_list);
        call->type = type;
        call->direction = direction;
        call->status = status;
@@ -235,7 +215,7 @@ static void clcc_poll_cb(gboolean ok, GAtResult *result, gpointer user_data)
                                ofono_voicecall_disconnected(vc, oc->id,
                                                                reason, NULL);
 
-                       release_id(vd, oc->id);
+                       at_util_release_id(&vd->id_list, oc->id);
 
                        o = o->next;
                } else if (nc && (!oc || (nc->id < oc->id))) {