Rework DECLARE_FAILURE to be a bit nicer

This commit is contained in:
Denis Kenzior 2009-09-11 12:36:35 -05:00
parent 32fc30fa02
commit cbb36acee8
14 changed files with 87 additions and 273 deletions

View File

@ -48,3 +48,12 @@ static inline struct cb_data *cb_data_new(void *cb, void *data)
e.type = OFONO_ERROR_TYPE_FAILURE; \
e.error = 0 \
#define CALLBACK_WITH_FAILURE(cb, args...) \
do { \
struct ofono_error cb_e; \
cb_e.type = OFONO_ERROR_TYPE_FAILURE; \
cb_e.error = 0; \
\
cb(&cb_e, ##args); \
} while (0) \

View File

@ -101,10 +101,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
callback(&error, 0, data);
}
CALLBACK_WITH_FAILURE(callback, 0, data);
}
static void clck_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -149,10 +146,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
callback(&error, data);
}
CALLBACK_WITH_FAILURE(callback, data);
}
static void cpwd_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -191,10 +185,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
callback(&error, data);
}
CALLBACK_WITH_FAILURE(callback, data);
}
static gboolean at_call_barring_register(gpointer user)

View File

@ -147,10 +147,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, 0, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, 0, NULL, data);
}
static void ccfc_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -182,10 +179,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_ccfc_erasure(struct ofono_call_forwarding *cf,

View File

@ -67,18 +67,14 @@ static void caoc_cacm_camm_query_cb(gboolean ok,
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, cbd->user)) {
DECLARE_FAILURE(e);
cb(&e, -1, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
return;
}
g_at_result_iter_next_string(&iter, &meter_hex);
meter = strtol(meter_hex, &end, 16);
if (*end) {
DECLARE_FAILURE(e);
cb(&e, -1, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
return;
}
@ -129,10 +125,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, data);
}
static void at_cacm_query(struct ofono_call_meter *cm,
@ -154,10 +147,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, data);
}
static void generic_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -192,10 +182,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_camm_query(struct ofono_call_meter *cm,
@ -217,10 +204,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, data);
}
static void at_camm_set(struct ofono_call_meter *cm,
@ -244,10 +228,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void cpuc_query_cb(gboolean ok,
@ -272,9 +253,7 @@ static void cpuc_query_cb(gboolean ok,
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, cbd->user)) {
DECLARE_FAILURE(e);
cb(&e, 0, 0, cbd->data);
CALLBACK_WITH_FAILURE(cb, 0, 0, cbd->data);
return;
}
@ -305,10 +284,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, 0, 0, data);
}
CALLBACK_WITH_FAILURE(cb, 0, 0, data);
}
static void at_cpuc_set(struct ofono_call_meter *cm, const char *currency,
@ -333,10 +309,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void ccwv_notify(GAtResult *result, gpointer user_data)

View File

@ -102,10 +102,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, 0, data);
}
CALLBACK_WITH_FAILURE(cb, 0, data);
}
static void ccwa_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -140,10 +137,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
@ -166,9 +160,7 @@ static void clip_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CLIP:")) {
DECLARE_FAILURE(e);
cb(&e, -1, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
return;
}
@ -198,10 +190,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, data);
}
static void colp_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -223,9 +212,7 @@ static void colp_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+COLP:")) {
DECLARE_FAILURE(e);
cb(&e, -1, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
return;
}
@ -255,10 +242,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, data);
}
static void clir_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -280,9 +264,7 @@ static void clir_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CLIR:")) {
DECLARE_FAILURE(e);
cb(&e, -1, -1, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, -1, cbd->data);
return;
}
@ -312,10 +294,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, -1, data);
}
static void clir_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -350,10 +329,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static gboolean at_call_settings_register(gpointer user)

View File

@ -118,10 +118,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, user_data);
}
CALLBACK_WITH_FAILURE(cb, user_data);
}
static void at_cbs_clear_topics(struct ofono_cbs *cbs,
@ -141,10 +138,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, user_data);
}
CALLBACK_WITH_FAILURE(cb, user_data);
}
static void at_cbs_register(gboolean ok, GAtResult *result, gpointer user)

View File

@ -99,10 +99,8 @@ static void at_query_manufacturer(struct ofono_devinfo *info,
error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, data);
}
static void at_query_model(struct ofono_devinfo *info,
@ -124,10 +122,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, data);
}
static void at_query_revision(struct ofono_devinfo *info,
@ -149,10 +144,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, data);
}
static void at_query_serial(struct ofono_devinfo *info,
@ -174,10 +166,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, data);
}
static gboolean at_devinfo_register(gpointer user_data)

View File

@ -84,9 +84,7 @@ static void at_creg_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CREG:")) {
DECLARE_FAILURE(e);
cb(&e, -1, -1, -1, -1, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, cbd->data);
return;
}
@ -131,10 +129,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, -1, -1, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, data);
}
static void cops_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -197,11 +192,7 @@ out:
return;
error:
{
DECLARE_FAILURE(e);
cb(&e, NULL, cbd->data);
}
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
g_free(cbd);
}
@ -280,10 +271,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, data);
}
static void cops_list_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -315,8 +303,7 @@ static void cops_list_cb(gboolean ok, GAtResult *result, gpointer user_data)
list = g_try_new0(struct ofono_network_operator, num);
if (!list) {
DECLARE_FAILURE(e);
cb(&e, 0, NULL, cbd->data);
CALLBACK_WITH_FAILURE(cb, 0, NULL, cbd->data);
return;
}
@ -406,10 +393,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, 0, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, 0, NULL, data);
}
static void register_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -441,10 +425,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_register_manual(struct ofono_netreg *netreg,
@ -468,10 +449,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_deregister(struct ofono_netreg *netreg,
@ -491,10 +469,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static inline void report_signal_strength(struct ofono_netreg *netreg,
@ -567,9 +542,7 @@ static void csq_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CSQ:")) {
DECLARE_FAILURE(e);
cb(&e, -1, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
return;
}
@ -602,10 +575,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, data);
}
CALLBACK_WITH_FAILURE(cb, -1, data);
}
static void creg_notify(GAtResult *result, gpointer user_data)

View File

@ -204,10 +204,7 @@ static void export_failed(struct cb_data *cbd)
struct pb_data *pbd = ofono_phonebook_get_data(pb);
ofono_phonebook_cb_t cb = cbd->cb;
{
DECLARE_FAILURE(error);
cb(&error, cbd->data);
}
CALLBACK_WITH_FAILURE(cb, cbd->data);
g_free(cbd);
@ -391,10 +388,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void phonebook_not_supported(struct ofono_phonebook *pb)

View File

@ -64,9 +64,7 @@ static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CRSM:")) {
DECLARE_FAILURE(e);
cb(&e, -1, -1, -1, NULL, cbd->data);
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL, cbd->data);
return;
}
@ -74,13 +72,11 @@ static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_result_iter_next_number(&iter, &sw2);
if (!g_at_result_iter_next_hexstring(&iter, &response, &len) ||
(sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92) ||
(sw1 == 0x90 && sw2 != 0x00) ||
len < 14 || response[6] != 0x04 ||
(response[13] == 0x01 && len < 15)) {
DECLARE_FAILURE(e);
cb(&e, -1, -1, -1, NULL, cbd->data);
(sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92) ||
(sw1 == 0x90 && sw2 != 0x00) ||
len < 14 || response[6] != 0x04 ||
(response[13] == 0x01 && len < 15)) {
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL, cbd->data);
return;
}
@ -122,10 +118,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, -1, -1, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL, data);
}
static void at_crsm_read_cb(gboolean ok, GAtResult *result,
@ -149,9 +142,7 @@ static void at_crsm_read_cb(gboolean ok, GAtResult *result,
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CRSM:")) {
DECLARE_FAILURE(e);
cb(&e, NULL, 0, cbd->data);
CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
return;
}
@ -161,9 +152,7 @@ static void at_crsm_read_cb(gboolean ok, GAtResult *result,
if (!g_at_result_iter_next_hexstring(&iter, &response, &len) ||
(sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
(sw1 == 0x90 && sw2 != 0x00)) {
DECLARE_FAILURE(e);
cb(&e, NULL, 0, cbd->data);
CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
return;
}
@ -194,10 +183,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, 0, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
}
static void at_sim_read_record(struct ofono_sim *sim, int fileid,
@ -222,10 +208,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, 0, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
}
static void at_crsm_update_cb(gboolean ok, GAtResult *result,
@ -248,9 +231,7 @@ static void at_crsm_update_cb(gboolean ok, GAtResult *result,
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CRSM:")) {
DECLARE_FAILURE(e);
cb(&e, cbd->data);
CALLBACK_WITH_FAILURE(cb, cbd->data);
return;
}
@ -258,10 +239,8 @@ static void at_crsm_update_cb(gboolean ok, GAtResult *result,
g_at_result_iter_next_number(&iter, &sw2);
if ((sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
(sw1 == 0x90 && sw2 != 0x00)) {
DECLARE_FAILURE(e);
cb(&e, cbd->data);
(sw1 == 0x90 && sw2 != 0x00)) {
CALLBACK_WITH_FAILURE(cb, cbd->data);
return;
}
@ -301,10 +280,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_sim_update_record(struct ofono_sim *sim, int fileid,
@ -338,10 +314,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_sim_update_cyclic(struct ofono_sim *sim, int fileid,
@ -373,10 +346,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_cimi_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -425,10 +395,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, NULL, data);
}
static gboolean at_sim_register(gpointer user)

View File

@ -118,10 +118,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, user_data);
}
CALLBACK_WITH_FAILURE(cb, user_data);
}
static void at_csca_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -167,10 +164,7 @@ static void at_csca_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
return;
err:
{
DECLARE_FAILURE(error);
cb(&error, NULL, cbd->data);
}
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
}
static void at_csca_query(struct ofono_sms *sms, ofono_sms_sca_query_cb_t cb,
@ -190,10 +184,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, NULL, user_data);
}
CALLBACK_WITH_FAILURE(cb, NULL, user_data);
}
static void at_cmgs_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -226,10 +217,7 @@ static void at_cmgs_cb(gboolean ok, GAtResult *result, gpointer user_data)
return;
err:
{
DECLARE_FAILURE(error);
cb(&error, -1, cbd->data);
}
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
}
static void at_cmgs(struct ofono_sms *sms, unsigned char *pdu, int pdu_len,
@ -261,10 +249,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, -1, user_data);
}
CALLBACK_WITH_FAILURE(cb, -1, user_data);
}
static void at_cnma_cb(gboolean ok, GAtResult *result, gpointer user_data)

View File

@ -93,10 +93,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void cusd_cancel_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -128,10 +125,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static gboolean at_ussd_register(gpointer user)

View File

@ -467,10 +467,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_template(const char *cmd, struct ofono_voicecall *vc,
@ -496,10 +493,7 @@ error:
if (req)
g_free(req);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_answer(struct ofono_voicecall *vc,
@ -536,16 +530,14 @@ static void clcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
calls = parse_clcc(result);
if (calls == NULL) {
DECLARE_FAILURE(e);
cb(&e, 0, NULL, cbd->data);
CALLBACK_WITH_FAILURE(cb, 0, NULL, cbd->data);
goto out;
}
list = g_try_new0(struct ofono_call, g_slist_length(calls));
if (!list) {
DECLARE_FAILURE(e);
cb(&e, 0, NULL, cbd->data);
CALLBACK_WITH_FAILURE(cb, 0, NULL, cbd->data);
goto out;
}
@ -578,11 +570,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, 0, NULL, data);
}
CALLBACK_WITH_FAILURE(cb, 0, NULL, data);
}
static void at_hold_all_active(struct ofono_voicecall *vc,
@ -637,10 +625,7 @@ error:
if (req)
g_free(req);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void at_private_chat(struct ofono_voicecall *vc, int id,
@ -731,10 +716,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void ring_notify(GAtResult *result, gpointer user_data)

View File

@ -75,10 +75,7 @@ error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, data);
}
CALLBACK_WITH_FAILURE(cb, data);
}
static void calypso_dial(struct ofono_voicecall *vc,
@ -206,8 +203,7 @@ static void calypso_send_dtmf(struct ofono_voicecall *vc, const char *dtmf,
buf = g_try_new(char, len * 9 + 3);
if (!buf) {
DECLARE_FAILURE(error);
cb(&error, data);
CALLBACK_WITH_FAILURE(cb, data);
return;
}