From a64df62919504e06c45a8fd58dc2c34cdacf34ee Mon Sep 17 00:00:00 2001 From: Zhenhua Zhang Date: Wed, 28 Oct 2009 17:41:07 +0800 Subject: [PATCH 2/3] Move and rename alloc_next_id and release_id into atutil.c So that they could be shared by atmodem and hfpmodem drivers. --- drivers/atmodem/atutil.c | 20 ++++++++++++++++++++ drivers/atmodem/atutil.h | 2 ++ 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 465d258..847a4ee 100644 --- a/drivers/atmodem/atutil.c +++ b/drivers/atmodem/atutil.c @@ -82,3 +82,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 & (0x1 << i)) + continue; + + *id_list |= (0x1 << i); + return i; + } + + return 0; +} + +inline void at_util_release_id(unsigned int *id_list, unsigned int id) +{ + *id_list &= ~(0x1 << id); +} + diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h index ab9db05..0444561 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 f0c8d93..0733607 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))) { -- 1.6.2.5