diff options
author | Denis Kenzior <denkenz@gmail.com> | 2009-11-16 11:15:31 -0600 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-11-16 11:15:31 -0600 |
commit | 957fc90d37ba305a64ab299930d53b6e9ec65f40 (patch) | |
tree | b54afa8b973ea8c953120aade4288340fff8a187 | |
parent | 5e1067b8a286ad6c734d33de1db57f1256142f12 (diff) | |
download | ofono-957fc90d37ba305a64ab299930d53b6e9ec65f40.tar.bz2 |
Refactor: Move repeated code to a function
-rw-r--r-- | drivers/hfpmodem/voicecall.c | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/drivers/hfpmodem/voicecall.c b/drivers/hfpmodem/voicecall.c index bc65d649..91a18444 100644 --- a/drivers/hfpmodem/voicecall.c +++ b/drivers/hfpmodem/voicecall.c @@ -76,6 +76,21 @@ struct change_state_req { int affected_types; }; +static GSList *find_dialing(GSList *calls) +{ + GSList *c; + + c = g_slist_find_custom(calls, GINT_TO_POINTER(CALL_STATUS_DIALING), + at_util_call_compare_by_status); + + if (!c) + c = g_slist_find_custom(calls, + GINT_TO_POINTER(CALL_STATUS_ALERTING), + at_util_call_compare_by_status); + + return c; +} + static struct ofono_call *create_call(struct voicecall_data *d, int type, int direction, int status, const char *num, int num_type, int clip) @@ -690,24 +705,12 @@ static void sync_dialing_cb(gboolean ok, GAtResult *result, gpointer user_data) return; /* Look for dialing or alerting calls on the new list */ - n = g_slist_find_custom(calls, GINT_TO_POINTER(CALL_STATUS_DIALING), - at_util_call_compare_by_status); - - if (!n) - n = g_slist_find_custom(calls, - GINT_TO_POINTER(CALL_STATUS_ALERTING), - at_util_call_compare_by_status); + n = find_dialing(calls); /* Let us find if we have done the dial from HF by looking for * existing dialing or alerting calls */ - o = g_slist_find_custom(vd->calls, GINT_TO_POINTER(CALL_STATUS_DIALING), - at_util_call_compare_by_status); - - if (!o) - o = g_slist_find_custom(vd->calls, - GINT_TO_POINTER(CALL_STATUS_ALERTING), - at_util_call_compare_by_status); + o = find_dialing(vd->calls); if (!n && o) { oc = o->data; @@ -742,14 +745,7 @@ static void ciev_callsetup_notify(struct ofono_voicecall *vc, GSList *dialing; GSList *waiting; - dialing = g_slist_find_custom(vd->calls, - GINT_TO_POINTER(CALL_STATUS_DIALING), - at_util_call_compare_by_status); - - if (!dialing) - dialing = g_slist_find_custom(vd->calls, - GINT_TO_POINTER(CALL_STATUS_ALERTING), - at_util_call_compare_by_status); + dialing = find_dialing(vd->calls); waiting = g_slist_find_custom(vd->calls, GINT_TO_POINTER(CALL_STATUS_WAITING), @@ -776,8 +772,9 @@ static void ciev_callsetup_notify(struct ofono_voicecall *vc, goto out; } - /* If call=1 and no call is waiting or dialing, the call - * is active. */ + /* If call=1 and no call is waiting or dialing, the call is + * active and we moved it to active state when call=1 arrived + */ if (waiting == NULL && dialing == NULL) goto out; |