From b73c6cf5a94e1c7f9be38917f26da37e13fe452e Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Thu, 27 Jun 2013 12:58:30 +0200 Subject: Rework handlers and ipc functions for better consistency Detailed list of the changes introduced by this commit: * Rename ipc_client_bootstrap_modem to ipc_client_bootstrap * Rename ipc_client_new/free to ipc_client_create/destroy * Rename log_handler to log_callback and change arguments order * Remove handlers common data and fd mechanisms * Set transport, power and gprs common data for handlers * Add data_create and data_destroy handlers * Rework arguments order for handlers * Add poll transport handler * Remove functions types typedefs * Remove dumb ipc_client_send_* functions * Remove ipc_client_gprs_handlers_available * Adapt device files for the new API changes * Adapt modemctrl for the new API changes Change-Id: Ia9ba1045dbbf9f5e31a201aa8629b49019158972 Signed-off-by: Paul Kocialkowski --- tools/modemctrl.c | 59 +++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'tools') diff --git a/tools/modemctrl.c b/tools/modemctrl.c index f266dd3..22e91d6 100644 --- a/tools/modemctrl.c +++ b/tools/modemctrl.c @@ -42,7 +42,6 @@ #define DEF_CALL_NUMBER "950" #define DEF_SIM_PIN "1234" -int client_fd = -1; int state = MODEM_STATE_LPM; int seq = 0; int in_call = 0; @@ -369,47 +368,38 @@ void modem_response_handle(struct ipc_client *client, struct ipc_message_info *r } } + int modem_read_loop(struct ipc_client *client) { struct ipc_message_info resp; - int fd = client_fd; int rc; - fd_set fds; - - if(fd < 0) { - return -1; - } memset(&resp, 0, sizeof(resp)); - FD_ZERO(&fds); - FD_SET(fd, &fds); - while(1) { usleep(3000); - select(fd + 1, &fds, NULL, NULL, NULL); - - if(FD_ISSET(fd, &fds)) - { - rc = ipc_client_recv(client, &resp); + rc = ipc_client_poll(client, NULL); + if (rc < 0) { + continue; + } - if(rc < 0) { - printf("[E] Can't RECV from modem: please run this again\n"); - break; - } + rc = ipc_client_recv(client, &resp); + if(rc < 0) { + printf("[E] Can't RECV from modem: please run this again\n"); + break; + } - modem_response_handle(client, &resp); + modem_response_handle(client, &resp); - if(resp.data != NULL) - free(resp.data); - } + if(resp.data != NULL) + free(resp.data); } return 0; } -void modem_log_handler(const char *msg, void *user_data) +void modem_log_handler(void *user_data, const char *msg) { int i, l; char *message; @@ -433,7 +423,7 @@ void modem_log_handler(const char *msg, void *user_data) free(message); } -void modem_log_handler_quiet(const char *message, void *user_data) +void modem_log_handler_quiet(void *user_data, const char *msg) { return; } @@ -442,10 +432,8 @@ int modem_start(struct ipc_client *client) { int rc = -1; -// ipc_client_set_handlers(client, &ipc_default_handlers); - ipc_client_create_handlers_common_data(client); - - ipc_client_bootstrap_modem(client); + ipc_client_data_create(client); + ipc_client_bootstrap(client); usleep(300); @@ -453,8 +441,6 @@ int modem_start(struct ipc_client *client) if(rc < 0) return -1; - client_fd = ipc_client_get_handlers_common_data_fd(client); - rc = ipc_client_power_on(client); if(rc < 0) return -1; @@ -531,7 +517,7 @@ int main(int argc, char *argv[]) } } - client_fmt = ipc_client_new(IPC_CLIENT_TYPE_FMT); + client_fmt = ipc_client_create(IPC_CLIENT_TYPE_FMT); if (client_fmt == 0) { printf("[E] Could not create IPC client; aborting ...\n"); @@ -539,8 +525,8 @@ int main(int argc, char *argv[]) } if (debug == 0) - ipc_client_set_log_handler(client_fmt, modem_log_handler_quiet, NULL); - else ipc_client_set_log_handler(client_fmt, modem_log_handler, NULL); + ipc_client_set_log_callback(client_fmt, modem_log_handler_quiet, NULL); + else ipc_client_set_log_callback(client_fmt, modem_log_handler, NULL); while(opt_i < argc) { if(strncmp(argv[optind], "power-on", 8) == 0) { @@ -552,8 +538,7 @@ int main(int argc, char *argv[]) printf("[E] Something went wrong while powering modem off\n"); goto modem_quit; } else if (strncmp(argv[optind], "bootstrap", 9) == 0) { - ipc_client_create_handlers_common_data(client_fmt); - ipc_client_bootstrap_modem(client_fmt); + ipc_client_bootstrap(client_fmt); } else if(strncmp(argv[optind], "start", 5) == 0) { printf("[0] Starting modem on FMT client\n"); rc = modem_start(client_fmt); @@ -578,7 +563,7 @@ int main(int argc, char *argv[]) modem_quit: if (client_fmt != 0) - ipc_client_free(client_fmt); + ipc_client_destroy(client_fmt); return 0; } -- cgit v1.1