diff options
author | Caiwen Zhang <caiwen.zhang@intel.com> | 2014-04-09 02:07:52 +0800 |
---|---|---|
committer | Caiwen Zhang <caiwen.zhang@intel.com> | 2014-04-10 01:52:20 +0800 |
commit | d388d974baf77e8da1238ba156ba6dc21d6480d5 (patch) | |
tree | e59f73519fe451ffa409bf2b704f26a8a1563981 | |
parent | 49d5ea62cbf898075e0c4ad48c5909e760c4d83f (diff) | |
download | tel-plugin-vpc-tizen.tar.gz tel-plugin-vpc-tizen.tar.bz2 tel-plugin-vpc-tizen.zip |
Align with refactored telephonytizen
Change-Id: I2e61333abd0d8e49efc2530368fde4fd3ca5e8b8
-rw-r--r-- | src/desc-vpc.c | 143 |
1 files changed, 85 insertions, 58 deletions
diff --git a/src/desc-vpc.c b/src/desc-vpc.c index d758b44..ce0633d 100644 --- a/src/desc-vpc.c +++ b/src/desc-vpc.c @@ -37,29 +37,16 @@ static int registered = FALSE; -static TcorePlugin * find_modem_plugin(Server *s) +static inline int audio_device_converter(int path) { - TcorePlugin *plugin = tcore_server_find_plugin(s, "mfld_blackbay0"); - if (plugin != NULL) - return plugin; - - plugin = tcore_server_find_plugin(s, "clovertrail_geek0"); - - return plugin; -} - -static inline int audio_device_converter(int device) -{ - switch (device) { - case 0: - return DISCONNECT; - case CALL_SOUND_PATH_HANDSET: + switch (path) { + case TEL_SOUND_PATH_HANDSET: return DEVICE_OUT_EARPIECE; - case CALL_SOUND_PATH_SPEAKER: + case TEL_SOUND_PATH_SPK_PHONE: return DEVICE_OUT_SPEAKER; - case CALL_SOUND_PATH_HEADSET: + case TEL_SOUND_PATH_HEADSET: return DEVICE_OUT_WIRED_HEADSET; - case CALL_SOUND_PATH_BLUETOOTH: + case TEL_SOUND_PATH_BLUETOOTH: return DEVICE_OUT_BLUETOOTH; default: err("device Id not recognized, use default device (earpiece)"); @@ -67,13 +54,14 @@ static inline int audio_device_converter(int device) } } -static void prepare_and_send_pending_request (TcorePlugin *plugin, unsigned int plugin_type, +static void prepare_and_send_pending_request (TcorePlugin *plugin, + unsigned int plugin_type, const char *at_cmd, const char *prefix, - enum tcore_at_command_type at_cmd_type, + TcoreAtCommandType at_cmd_type, TcorePendingResponseCallback callback) { - TcoreATRequest *req; + TcoreAtRequest *req; TcoreHal *hal; CoreObject *co; TcorePending *pending ; @@ -101,7 +89,7 @@ static void prepare_and_send_pending_request (TcorePlugin *plugin, unsigned int tcore_pending_set_request_data(pending, 0, req); tcore_pending_set_response_callback(pending, callback, NULL); - tcore_pending_link_user_request(pending, NULL); + tcore_pending_link_request(pending, NULL); tcore_hal_send_request(hal, pending); } @@ -125,25 +113,23 @@ static void on_screen_status_changed(keynode_t *key, void* data) prepare_and_send_pending_request(plugin, CORE_OBJECT_TYPE_NETWORK, "AT+CREG=2;+CGREG=2;+XCSQ=1;+XMER=1;+XFDOR=3;+CREG?;+CGREG?", NULL, - TCORE_AT_NO_RESULT, + TCORE_AT_COMMAND_TYPE_NO_RESULT, NULL); else if (state == VCONFKEY_PM_STATE_LCDOFF) /* screen off, disable URC */ prepare_and_send_pending_request(plugin, CORE_OBJECT_TYPE_NETWORK, "AT+CREG=0;+CGREG=0;+XCSQ=0;+XMER=0;+XFDOR=2", NULL, - TCORE_AT_NO_RESULT, + TCORE_AT_COMMAND_TYPE_NO_RESULT, NULL); } -static enum tcore_hook_return on_hook_call_end(Server *s, - CoreObject *source, - enum tcore_notification_command command, +static TcoreHookReturn on_hook_call_end(TcorePlugin *plugin, + TcoreNotification command, unsigned int data_len, void *data, void *user_data) { - TcorePlugin *plugin = find_modem_plugin(s); if (plugin == NULL) { warn("Warning: can't find modem plugin"); return TCORE_HOOK_RETURN_CONTINUE; @@ -152,66 +138,91 @@ static enum tcore_hook_return on_hook_call_end(Server *s, vpc_disable(); /* amc disable */ -// usleep(1000); /* Time to disable MSIC... */ +// usleep(1000); /* Time to disable MSIC... */ prepare_and_send_pending_request(plugin, CORE_OBJECT_TYPE_CALL, "AT+XDRV=40,3,3", NULL, - TCORE_AT_NO_RESULT, + TCORE_AT_COMMAND_TYPE_NO_RESULT, NULL); /* Disable AMC_I2S1_RX */ prepare_and_send_pending_request(plugin, CORE_OBJECT_TYPE_CALL, "AT+XDRV=40,3,4", NULL, - TCORE_AT_NO_RESULT, + TCORE_AT_COMMAND_TYPE_NO_RESULT, NULL); /* Disable AMC_I2S2_RX */ /* amc route: AMC_RADIO_RX => AMC_PCM_GENERALD */ prepare_and_send_pending_request(plugin, CORE_OBJECT_TYPE_CALL, "AT+XDRV=40,6,0,4", NULL, - TCORE_AT_NO_RESULT, + TCORE_AT_COMMAND_TYPE_NO_RESULT, NULL); -// usleep(80000); /* Time to Disable modem I2S... */ +// usleep(80000); /* Time to Disable modem I2S... */ return TCORE_HOOK_RETURN_CONTINUE; } -static enum tcore_hook_return on_hook_set_sound_path(Server *s, - CoreObject *source, - enum tcore_notification_command command, - unsigned int data_len, void *data, - void *user_data) +static TcoreHookReturn on_hook_resp_set_sound_path(CoreObject *co, + gint result, + TcoreCommand command, + const void *response, + const void *user_data) { - const struct tnoti_call_sound_path *sound_path = data; - int devId = audio_device_converter(sound_path->path); + TelCallSoundPath *sound_path = (TelCallSoundPath *)user_data; + int devId = audio_device_converter(*sound_path); - dbg("sound_path->path <%d> devId <%d>",sound_path->path, devId); + dbg("sound_path->path <%d> devId <%d>",*sound_path, devId); vpc_enable(MODE_IN_CALL, devId); + g_free(sound_path); + + return TCORE_HOOK_RETURN_CONTINUE; +} + +static TcoreHookReturn on_hook_req_set_sound_path(CoreObject *co, + TcoreCommand command, + const void *request, + const void *user_data, + TcoreObjectResponseCallback cb, + const void *cb_data) +{ + TelCallSoundPath *sound_path; + TelCallSoundPathInfo *path_info = (TelCallSoundPathInfo*)request; + + /* Make sure there is no duplicated hook */ + tcore_object_remove_response_hook(co, command, on_hook_resp_set_sound_path); + + sound_path = g_malloc0(sizeof(TelCallSoundPath)); + *sound_path = path_info->path; + tcore_object_add_response_hook(co, command, request, + on_hook_resp_set_sound_path, sound_path); return TCORE_HOOK_RETURN_CONTINUE; } -static enum tcore_hook_return on_hook_register_notification(Server *s, - CoreObject *source, - enum tcore_notification_command command, +static TcoreHookReturn on_hook_register_notification(TcorePlugin *plugin, + TcoreNotification command, unsigned int data_len, void *data, void *user_data) { + CoreObject *co_call; /* avoid the hooks are registered repeatedly */ - TcorePlugin *plugin = find_modem_plugin(s); if (plugin == NULL) return TCORE_HOOK_RETURN_CONTINUE; if (registered == TRUE) return TCORE_HOOK_RETURN_CONTINUE; - tcore_server_add_notification_hook(s, TNOTI_CALL_SOUND_PATH, - on_hook_set_sound_path, NULL); + co_call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL); - tcore_server_add_notification_hook(s, TNOTI_CALL_STATUS_IDLE, - on_hook_call_end, NULL); + tcore_object_add_request_hook(co_call, + TCORE_COMMAND_MODEM_SET_FLIGHTMODE, + on_hook_req_set_sound_path, NULL); + + tcore_object_add_notification_hook(co_call, + TCORE_NOTIFICATION_CALL_STATUS_IDLE, + on_hook_call_end, NULL); vconf_notify_key_changed(VCONFKEY_PM_STATE, on_screen_status_changed, plugin); @@ -230,16 +241,16 @@ static gboolean on_load() static gboolean on_init(TcorePlugin *p) { - Server *s; + CoreObject *co; if (p == NULL) return FALSE; vpc_init(); - s = tcore_plugin_ref_server(p); - tcore_server_add_notification_hook(s, TNOTI_MODEM_POWER, - on_hook_register_notification, NULL); + co = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_MODEM); + tcore_object_add_notification_hook(co, TCORE_NOTIFICATION_MODEM_POWER, + on_hook_register_notification, NULL); dbg("i'm init!"); @@ -248,15 +259,31 @@ static gboolean on_init(TcorePlugin *p) static void on_unload(TcorePlugin *p) { - Server *s; + CoreObject *co_call; + CoreObject *co_modem; if (p == NULL) return; - s = tcore_plugin_ref_server(p); + co_call = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_CALL); + co_modem = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_MODEM); + + tcore_object_remove_notification_hook(co_modem, + TCORE_NOTIFICATION_MODEM_POWER, + on_hook_register_notification); + + tcore_object_remove_request_hook(co_call, + TCORE_COMMAND_MODEM_SET_FLIGHTMODE, + on_hook_req_set_sound_path); + + tcore_object_remove_response_hook(co_call, + TCORE_COMMAND_MODEM_SET_FLIGHTMODE, + on_hook_resp_set_sound_path); + + tcore_object_remove_notification_hook(co_call, + TCORE_NOTIFICATION_CALL_STATUS_IDLE, + on_hook_call_end); - tcore_server_remove_notification_hook(s, on_hook_set_sound_path); - tcore_server_remove_notification_hook(s, on_hook_call_end); vconf_ignore_key_changed(VCONFKEY_PM_STATE, on_screen_status_changed); registered = FALSE; |