Refactor isidevinfo

Remove storing of pending request objects to linked list;
g_isi_client_destroy() will clear those properly. Fix naming of enums,
and use DECLARE_SUCCESS() macro.
This commit is contained in:
Aki Niemi 2009-08-21 10:16:42 +03:00
parent a434d94169
commit a42ec65274
1 changed files with 19 additions and 56 deletions

View File

@ -46,16 +46,15 @@
#define INFO_TIMEOUT 5 #define INFO_TIMEOUT 5
static GIsiClient *client = NULL; static GIsiClient *client = NULL;
static GSList *pending = NULL;
enum return_codes { enum return_code {
INFO_OK = 0x00, INFO_OK = 0x00,
INFO_FAIL = 0x01, INFO_FAIL = 0x01,
INFO_NO_NUMBER = 0x02, INFO_NO_NUMBER = 0x02,
INFO_NOT_SUPPORTED = 0x03 INFO_NOT_SUPPORTED = 0x03
}; };
enum message_ids { enum message_id {
INFO_SERIAL_NUMBER_READ_REQ = 0x00, INFO_SERIAL_NUMBER_READ_REQ = 0x00,
INFO_SERIAL_NUMBER_READ_RESP = 0x01, INFO_SERIAL_NUMBER_READ_RESP = 0x01,
INFO_VERSION_READ_REQ = 0x07, INFO_VERSION_READ_REQ = 0x07,
@ -64,40 +63,30 @@ enum message_ids {
INFO_PRODUCT_INFO_READ_RESP = 0x16 INFO_PRODUCT_INFO_READ_RESP = 0x16
}; };
enum sub_block_ids { enum sub_block_id {
INFO_SB_PRODUCT_INFO_NAME = 0x01, INFO_SB_PRODUCT_INFO_NAME = 0x01,
INFO_SB_PRODUCT_INFO_MANUFACTURER = 0x07, INFO_SB_PRODUCT_INFO_MANUFACTURER = 0x07,
INFO_SB_SN_IMEI_PLAIN = 0x41, INFO_SB_SN_IMEI_PLAIN = 0x41,
INFO_SB_MCUSW_VERSION = 0x48 INFO_SB_MCUSW_VERSION = 0x48
}; };
enum product_info_types { enum product_info_type {
INFO_PRODUCT_NAME = 0x01, INFO_PRODUCT_NAME = 0x01,
INFO_PRODUCT_MANUFACTURER = 0x07 INFO_PRODUCT_MANUFACTURER = 0x07
}; };
enum serial_number_types { enum serial_number_type {
INFO_SN_IMEI_PLAIN = 0x41 INFO_SN_IMEI_PLAIN = 0x41
}; };
enum version_types { enum version_type {
INFO_MCUSW = 0x01 INFO_MCUSW = 0x01
}; };
static void clear_pending_reqs()
{
GSList *l;
for (l = pending; l; l = l->next)
g_isi_request_cancel((GIsiRequest *)l->data);
}
static gboolean decode_sb_and_report(const unsigned char *msg, size_t len, int id, static gboolean decode_sb_and_report(const unsigned char *msg, size_t len, int id,
ofono_devinfo_query_cb_t cb, ofono_devinfo_query_cb_t cb,
void *data) void *data)
{ {
struct ofono_error err;
dump_msg(msg, len); dump_msg(msg, len);
if (msg[1] != INFO_OK) { if (msg[1] != INFO_OK) {
@ -117,11 +106,11 @@ static gboolean decode_sb_and_report(const unsigned char *msg, size_t len, int i
str[msg[6]] = '\0'; str[msg[6]] = '\0';
DBG("<%s>", str); DBG("<%s>", str);
err.type = OFONO_ERROR_TYPE_NO_ERROR; {
err.error = 0; DECLARE_SUCCESS(err);
cb(&err, str, data);
cb(&err, str, data); return true;
return true; }
} }
DBG("Unexpected sub-block: 0x%02x", msg[3]); DBG("Unexpected sub-block: 0x%02x", msg[3]);
@ -170,18 +159,12 @@ static void isi_query_manufacturer(struct ofono_devinfo *info,
INFO_PRODUCT_MANUFACTURER INFO_PRODUCT_MANUFACTURER
}; };
GIsiRequest *req = NULL;
if (!cbd) if (!cbd)
goto error; goto error;
req = g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT, if (g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT,
manufacturer_resp_cb, cbd); manufacturer_resp_cb, cbd))
if (req) {
pending = g_slist_append(pending, req);
return; return;
}
error: error:
if (cbd) if (cbd)
@ -235,18 +218,12 @@ static void isi_query_model(struct ofono_devinfo *info,
INFO_PRODUCT_NAME INFO_PRODUCT_NAME
}; };
GIsiRequest *req = NULL;
if (!cbd) if (!cbd)
goto error; goto error;
req = g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT, if (g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT,
model_resp_cb, cbd); model_resp_cb, cbd))
if (req) {
pending = g_slist_append(pending, req);
return; return;
}
error: error:
if (cbd) if (cbd)
@ -301,18 +278,12 @@ static void isi_query_revision(struct ofono_devinfo *info,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00
}; };
GIsiRequest *req = NULL;
if (!cbd) if (!cbd)
goto error; goto error;
req = g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT, if (g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT,
revision_resp_cb, cbd); revision_resp_cb, cbd))
if (req) {
pending = g_slist_append(pending, req);
return; return;
}
error: error:
if (cbd) if (cbd)
@ -366,18 +337,12 @@ static void isi_query_serial(struct ofono_devinfo *info,
INFO_SN_IMEI_PLAIN INFO_SN_IMEI_PLAIN
}; };
GIsiRequest *req = NULL;
if (!cbd) if (!cbd)
goto error; goto error;
req = g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT, if (g_isi_request_make(client, msg, sizeof(msg), INFO_TIMEOUT,
serial_resp_cb, cbd); serial_resp_cb, cbd))
if (req) {
pending = g_slist_append(pending, req);
return; return;
}
error: error:
if (cbd) if (cbd)
@ -421,8 +386,6 @@ static int isi_devinfo_remove(struct ofono_devinfo *info)
client = NULL; client = NULL;
} }
clear_pending_reqs();
return 0; return 0;
} }