diff options
author | Zhenhua Zhang <zhenhua.zhang@intel.com> | 2009-10-29 01:42:39 +0800 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-10-28 17:31:44 -0500 |
commit | 57aaf9813f9a865ab31314e0cf9ad2b068e67592 (patch) | |
tree | af4507023887378f536ada3d3ddeb24cd6c5927c | |
parent | 17903940c5d356cb0bfb44d26bce422ec2ec06f6 (diff) | |
download | ofono-57aaf9813f9a865ab31314e0cf9ad2b068e67592.tar.bz2 |
Refactor: Move alloc/release id to atutil.c
-rw-r--r-- | drivers/atmodem/atutil.c | 20 | ||||
-rw-r--r-- | drivers/atmodem/atutil.h | 2 | ||||
-rw-r--r-- | drivers/atmodem/voicecall.c | 24 |
3 files changed, 24 insertions, 22 deletions
diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c index 578522f6..26d0c259 100644 --- a/drivers/atmodem/atutil.c +++ b/drivers/atmodem/atutil.c @@ -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); +} + diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h index ab9db053..0444561a 100644 --- a/drivers/atmodem/atutil.h +++ b/drivers/atmodem/atutil.h @@ -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; diff --git a/drivers/atmodem/voicecall.c b/drivers/atmodem/voicecall.c index f0c8d93f..07336078 100644 --- a/drivers/atmodem/voicecall.c +++ b/drivers/atmodem/voicecall.c @@ -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))) { |