call-forwarding: Refactoring of is_cfu_enabled()

This also removes the need for uninitialized_var() macro.
This commit is contained in:
Oleg Zhurakivskyy 2012-02-06 14:33:55 +02:00 committed by Denis Kenzior
parent 07adce67e0
commit 12076487aa
1 changed files with 17 additions and 19 deletions

View File

@ -36,14 +36,17 @@
#include "common.h" #include "common.h"
#include "simutil.h" #include "simutil.h"
#define uninitialized_var(x) x = x
#define CALL_FORWARDING_FLAG_CACHED 0x1 #define CALL_FORWARDING_FLAG_CACHED 0x1
#define CALL_FORWARDING_FLAG_CPHS_CFF 0x2 #define CALL_FORWARDING_FLAG_CPHS_CFF 0x2
/* According to 27.007 Spec */ /* According to 27.007 Spec */
#define DEFAULT_NO_REPLY_TIMEOUT 20 #define DEFAULT_NO_REPLY_TIMEOUT 20
#define is_cfu_enabled(_cf) \
({ \
cf_find_unconditional(_cf) ? TRUE : FALSE; \
})
enum call_forwarding_type { enum call_forwarding_type {
CALL_FORWARDING_TYPE_UNCONDITIONAL = 0, CALL_FORWARDING_TYPE_UNCONDITIONAL = 0,
CALL_FORWARDING_TYPE_BUSY = 1, CALL_FORWARDING_TYPE_BUSY = 1,
@ -221,8 +224,8 @@ static void sim_cphs_cff_update_cb(int ok, void *data)
ofono_info("Failed to update EFcphs-cff"); ofono_info("Failed to update EFcphs-cff");
} }
static gboolean is_cfu_enabled(struct ofono_call_forwarding *cf, static struct ofono_call_forwarding_condition *cf_find_unconditional(
struct ofono_call_forwarding_condition **out) struct ofono_call_forwarding *cf)
{ {
GSList *l = cf->cf_conditions[CALL_FORWARDING_TYPE_UNCONDITIONAL]; GSList *l = cf->cf_conditions[CALL_FORWARDING_TYPE_UNCONDITIONAL];
struct ofono_call_forwarding_condition *cond; struct ofono_call_forwarding_condition *cond;
@ -237,21 +240,16 @@ static gboolean is_cfu_enabled(struct ofono_call_forwarding *cf,
if (cond->cls > BEARER_CLASS_VOICE) if (cond->cls > BEARER_CLASS_VOICE)
continue; continue;
if (out) return cond;
*out = cond;
return TRUE;
} }
return FALSE; return NULL;
} }
static void sim_set_cf_indicator(struct ofono_call_forwarding *cf) static void sim_set_cf_indicator(struct ofono_call_forwarding *cf)
{ {
gboolean cfu_voice; struct ofono_call_forwarding_condition *cfu_voice =
struct ofono_call_forwarding_condition *uninitialized_var(cond); cf_find_unconditional(cf);
cfu_voice = is_cfu_enabled(cf, &cond);
if (cf->cfis_record_id) { if (cf->cfis_record_id) {
unsigned char data[16]; unsigned char data[16];
@ -263,15 +261,15 @@ static void sim_set_cf_indicator(struct ofono_call_forwarding *cf)
data[0] = 0x01; data[0] = 0x01;
if (cfu_voice) { if (cfu_voice) {
number_len = strlen(cond->phone_number.number); number_len = strlen(cfu_voice->phone_number.number);
/* CFU indicator Status - Voice */ /* CFU indicator Status - Voice */
data[1] = 0x01; data[1] = 0x01;
number_len = (number_len + 1) / 2; number_len = (number_len + 1) / 2;
data[2] = number_len + 1; data[2] = number_len + 1;
data[3] = cond->phone_number.type; data[3] = cfu_voice->phone_number.type;
sim_encode_bcd_number(cond->phone_number.number, sim_encode_bcd_number(cfu_voice->phone_number.number,
data + 4); data + 4);
} else { } else {
data[1] = 0x00; data[1] = 0x00;
@ -317,7 +315,7 @@ static void set_new_cond_list(struct ofono_call_forwarding *cf,
if ((cf->flags & CALL_FORWARDING_FLAG_CPHS_CFF) || if ((cf->flags & CALL_FORWARDING_FLAG_CPHS_CFF) ||
cf->cfis_record_id > 0) cf->cfis_record_id > 0)
old_cfu = is_cfu_enabled(cf, NULL); old_cfu = is_cfu_enabled(cf);
else else
old_cfu = FALSE; old_cfu = FALSE;
@ -432,7 +430,7 @@ static void set_new_cond_list(struct ofono_call_forwarding *cf,
if ((cf->flags & CALL_FORWARDING_FLAG_CPHS_CFF) || if ((cf->flags & CALL_FORWARDING_FLAG_CPHS_CFF) ||
cf->cfis_record_id > 0) cf->cfis_record_id > 0)
new_cfu = is_cfu_enabled(cf, NULL); new_cfu = is_cfu_enabled(cf);
else else
new_cfu = FALSE; new_cfu = FALSE;
@ -523,7 +521,7 @@ static DBusMessage *cf_get_properties_reply(DBusMessage *msg,
if ((cf->flags & CALL_FORWARDING_FLAG_CPHS_CFF) || if ((cf->flags & CALL_FORWARDING_FLAG_CPHS_CFF) ||
cf->cfis_record_id > 0) cf->cfis_record_id > 0)
status = is_cfu_enabled(cf, NULL); status = is_cfu_enabled(cf);
else else
status = FALSE; status = FALSE;