From 57d90c68c33b22271da476dbb90a4943d246aedf Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 24 Feb 2020 18:57:29 +0900 Subject: [PATCH] Change indentation from tab to spaces Change-Id: I4f79da47ef7b6b05d096596230683a5582005cb5 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 500 +++++++++++++++++++++--------------------- receiver/src/main.cpp | 40 ++-- receiver/src/sticker_info.cpp | 3 +- 3 files changed, 266 insertions(+), 277 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index ac09cf5..d03495d 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -38,8 +38,8 @@ using namespace std; struct priv { - sap_agent_h agent; - sap_file_transaction_h socket; + sap_agent_h agent; + sap_file_transaction_h socket; }; static struct priv priv_data = { 0 }; @@ -49,333 +49,323 @@ static string incoming_file_name; static string recv_filepath; static void _on_send_completed(sap_file_transaction_h file_transaction, - sap_ft_transfer_e result, - const char *file_path, - void *user_data) + sap_ft_transfer_e result, + const char *file_path, + void *user_data) { - char error_message[100]; - - LOGI("# transfer completed"); - - if (priv_data.socket) { - sap_file_transfer_destroy(file_transaction); - priv_data.socket = NULL; - } - - if (result == SAP_FT_TRANSFER_SUCCESS) { - sprintf(error_message, "Transfer Completed"); - LOGI("Transfer Completed"); - - if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { - LOGE("Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); - } - else { - LOGI("Succeed to change permission : %s", recv_filepath.c_str()); - if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { - insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); - destroy_sticker_provider_handle(); - - if (unlink(recv_filepath.c_str()) == -1) - LOGE("Failed to remove sticker file"); - } - } - } else { - switch (result) { - case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { - sprintf(error_message, "Channel IO Error."); - LOGW("Channel IO Error."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_FILE_IO): { - sprintf(error_message, "File IO Error."); - LOGW("File IO Error."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_CMD_DROPPED): { - sprintf(error_message, "Transfer dropped."); - LOGW("Transfer dropped."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_PEER_UNRESPONSIVE): { - sprintf(error_message, "Peer Un Responsive."); - LOGW("Peer Un Responsive."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_PEER_CONN_LOST): { - sprintf(error_message, "Connection Lost."); - LOGW("Connection Lost."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_PEER_CANCELLED): { - sprintf(error_message, "Peer Cancelled."); - LOGW("Peer Cancelled."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_SPACE_NOT_AVAILABLE): { - sprintf(error_message, "No Space."); - LOGW("No Space."); - break; - } - - default: - sprintf(error_message, "Unknown Error"); - LOGW("Unknown Error"); - } - } - - file_on_progress = 0; + char error_message[100]; + + LOGI("# transfer completed"); + + if (priv_data.socket) { + sap_file_transfer_destroy(file_transaction); + priv_data.socket = NULL; + } + + if (result == SAP_FT_TRANSFER_SUCCESS) { + sprintf(error_message, "Transfer Completed"); + LOGI("Transfer Completed"); + + if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { + LOGE("Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); + } + else { + LOGI("Succeed to change permission : %s", recv_filepath.c_str()); + if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { + insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); + destroy_sticker_provider_handle(); + + if (unlink(recv_filepath.c_str()) == -1) + LOGE("Failed to remove sticker file"); + } + } + } else { + switch (result) { + case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { + sprintf(error_message, "Channel IO Error."); + LOGW("Channel IO Error."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_FILE_IO): { + sprintf(error_message, "File IO Error."); + LOGW("File IO Error."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_CMD_DROPPED): + { + sprintf(error_message, "Transfer dropped."); + LOGW("Transfer dropped."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_PEER_UNRESPONSIVE): + { + sprintf(error_message, "Peer Un Responsive."); + LOGW("Peer Un Responsive."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_PEER_CONN_LOST): + { + sprintf(error_message, "Connection Lost."); + LOGW("Connection Lost."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_PEER_CANCELLED): + { + sprintf(error_message, "Peer Cancelled."); + LOGW("Peer Cancelled."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_SPACE_NOT_AVAILABLE): + { + sprintf(error_message, "No Space."); + LOGW("No Space."); + break; + } + + default: + sprintf(error_message, "Unknown Error"); + LOGW("Unknown Error"); + break; + } + } + + file_on_progress = 0; } static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction, - unsigned short int percentage_progress, - void *user_data) + unsigned short int percentage_progress, + void *user_data) { - LOGI("# progress %d", percentage_progress); + LOGI("# progress %d", percentage_progress); } static void __set_file_transfer_cb(sap_file_transaction_h file_socket) { - LOGI("# set callbacks"); - sap_file_transfer_set_progress_cb(file_socket, _on_sending_file_in_progress, NULL); + LOGI("# set callbacks"); + sap_file_transfer_set_progress_cb(file_socket, _on_sending_file_in_progress, NULL); - sap_file_transfer_set_done_cb(file_socket, _on_send_completed, NULL); + sap_file_transfer_set_done_cb(file_socket, _on_send_completed, NULL); } void accept_file() { - int ret; - char file_path[PATH_MAX]; - char *data_path = NULL; - - data_path = app_get_shared_data_path(); - LOGI("Path : %s", data_path); - sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str()); - LOGI("Receive filepath : %s", file_path); - recv_filepath = string(file_path); - free(data_path); - - ret = sap_file_transfer_receive(priv_data.socket, file_path); - switch(ret) { - case SAP_RESULT_PERMISSION_DENIED: - LOGW("permission denied"); - break; - case SAP_RESULT_FAILURE: - LOGW("Fail"); - break; - case SAP_RESULT_SUCCESS: - LOGI("Success"); - break; - } - - file_on_progress = 1; + int ret; + char file_path[PATH_MAX]; + char *data_path = NULL; + + data_path = app_get_shared_data_path(); + LOGI("Path : %s", data_path); + sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str()); + LOGI("Receive filepath : %s", file_path); + recv_filepath = string(file_path); + free(data_path); + + ret = sap_file_transfer_receive(priv_data.socket, file_path); + switch(ret) { + case SAP_RESULT_PERMISSION_DENIED: + LOGW("permission denied"); + break; + case SAP_RESULT_FAILURE: + LOGW("Fail"); + break; + case SAP_RESULT_SUCCESS: + LOGI("Success"); + break; + } + + file_on_progress = 1; } void sap_file_transfer_get_receive_filepath(char **filepath) { - *filepath = strdup(recv_filepath.c_str()); + *filepath = strdup(recv_filepath.c_str()); } void reject_file() { - int ret = sap_file_transfer_reject(priv_data.socket); - LOGI("ret : %d", ret); + int ret = sap_file_transfer_reject(priv_data.socket); + LOGI("ret : %d", ret); - file_on_progress = 0; + file_on_progress = 0; } static void _on_receive_file_cb(sap_peer_agent_h peer_agent_h, - sap_file_transaction_h socket, - const char *file_path, - void *user_data) + sap_file_transaction_h socket, + const char *file_path, + void *user_data) { - file_on_progress = 1; - priv_data.socket = socket; - LOGI("# incoming file request."); - __set_file_transfer_cb(priv_data.socket); + file_on_progress = 1; + priv_data.socket = socket; + LOGI("# incoming file request."); + __set_file_transfer_cb(priv_data.socket); - incoming_file_name = file_path; - std::size_t found = incoming_file_name.find_last_of("/"); - incoming_file_name = incoming_file_name.substr(found+1); + incoming_file_name = file_path; + std::size_t found = incoming_file_name.find_last_of("/"); + incoming_file_name = incoming_file_name.substr(found+1); - LOGI("# file path : %s, incoming file name : %s", file_path, incoming_file_name.c_str()); + LOGI("# file path : %s, incoming file name : %s", file_path, incoming_file_name.c_str()); - accept_file(); + accept_file(); } void conn_terminated(sap_peer_agent_h peer_agent, - sap_socket_h socket, - sap_service_connection_terminated_reason_e result, - void *user_data) + sap_socket_h socket, + sap_service_connection_terminated_reason_e result, + void *user_data) { - LOGI("connection terminated"); - service_app_exit(); + LOGI("connection terminated"); + service_app_exit(); } void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, - void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ + void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ { - LOGI("received data: %s, len:%d", (char *)buffer, payload_length); + LOGI("received data: %s, len:%d", (char *)buffer, payload_length); } static void on_conn_req(sap_peer_agent_h peer_agent, - sap_socket_h socket, - sap_service_connection_result_e result, - void *user_data) + sap_socket_h socket, + sap_service_connection_result_e result, + void *user_data) { - sap_peer_agent_accept_service_connection(peer_agent); - sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL); + sap_peer_agent_accept_service_connection(peer_agent); + sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL); - sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); + sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); } static void on_agent_initialized(sap_agent_h agent, - sap_agent_initialized_result_e result, - void *user_data) + sap_agent_initialized_result_e result, + void *user_data) { - switch (result) { - case SAP_AGENT_INITIALIZED_RESULT_SUCCESS: - - LOGD("agent is initialized"); - - priv_data.agent = agent; - - sap_file_transfer_set_incoming_file_cb(agent, _on_receive_file_cb, NULL); - sap_agent_set_service_connection_requested_cb(agent, on_conn_req, NULL); - - break; - - case SAP_AGENT_INITIALIZED_RESULT_DUPLICATED: - LOGE("duplicate registration"); - - break; - - case SAP_AGENT_INITIALIZED_RESULT_INVALID_ARGUMENTS: - LOGE("invalid arguments"); - - break; - - case SAP_AGENT_INITIALIZED_RESULT_INTERNAL_ERROR: - LOGE("internal sap error"); - - break; - - default: - LOGE("unknown status (%d)", result); - - break; - } + switch (result) { + case SAP_AGENT_INITIALIZED_RESULT_SUCCESS: + LOGD("agent is initialized"); + + priv_data.agent = agent; + + sap_file_transfer_set_incoming_file_cb(agent, _on_receive_file_cb, NULL); + sap_agent_set_service_connection_requested_cb(agent, on_conn_req, NULL); + + break; + case SAP_AGENT_INITIALIZED_RESULT_DUPLICATED: + LOGE("duplicate registration"); + break; + case SAP_AGENT_INITIALIZED_RESULT_INVALID_ARGUMENTS: + LOGE("invalid arguments"); + break; + case SAP_AGENT_INITIALIZED_RESULT_INTERNAL_ERROR: + LOGE("internal sap error"); + break; + default: + LOGE("unknown status (%d)", result); + break; + } } static void on_agent_deinitialized(sap_agent_h agent, - sap_agent_deinitialized_result_e result, - void *user_data) + sap_agent_deinitialized_result_e result, + void *user_data) { - LOGD("result of deinitialize : %d", result); + LOGD("result of deinitialize : %d", result); } static void _on_device_status_changed(sap_device_status_e status, - sap_transport_type_e transport_type, - void *user_data) + sap_transport_type_e transport_type, + void *user_data) { - LOGD("%s, status :%d", __func__, status); - - switch (transport_type) { - case SAP_TRANSPORT_TYPE_BT: - LOGD("transport_type (%d): bt", transport_type); - break; - - case SAP_TRANSPORT_TYPE_BLE: - LOGD("transport_type (%d): ble", transport_type); - break; - - case SAP_TRANSPORT_TYPE_TCP: - LOGD("transport_type (%d): tcp/ip", transport_type); - break; - - case SAP_TRANSPORT_TYPE_USB: - LOGD("transport_type (%d): usb", transport_type); - break; - - case SAP_TRANSPORT_TYPE_MOBILE: - LOGD("transport_type (%d): mobile", transport_type); - break; - - default: - LOGE("unknown transport_type (%d)", transport_type); - break; - } - - switch (status) { - case SAP_DEVICE_STATUS_DETACHED: - LOGD("device is not connected."); - break; - - case SAP_DEVICE_STATUS_ATTACHED: - LOGD("Attached calling find peer now"); - break; - - default: - LOGE("unknown status (%d)", status); - break; - } + LOGD("%s, status :%d", __func__, status); + + switch (transport_type) { + case SAP_TRANSPORT_TYPE_BT: + LOGD("transport_type (%d): bt", transport_type); + break; + case SAP_TRANSPORT_TYPE_BLE: + LOGD("transport_type (%d): ble", transport_type); + break; + case SAP_TRANSPORT_TYPE_TCP: + LOGD("transport_type (%d): tcp/ip", transport_type); + break; + case SAP_TRANSPORT_TYPE_USB: + LOGD("transport_type (%d): usb", transport_type); + break; + case SAP_TRANSPORT_TYPE_MOBILE: + LOGD("transport_type (%d): mobile", transport_type); + break; + default: + LOGE("unknown transport_type (%d)", transport_type); + break; + } + + switch (status) { + case SAP_DEVICE_STATUS_DETACHED: + LOGD("device is not connected."); + break; + case SAP_DEVICE_STATUS_ATTACHED: + LOGD("Attached calling find peer now"); + break; + default: + LOGE("unknown status (%d)", status); + break; + } } gboolean agent_initialize() { - int result = 0; + int result = 0; - do { - result = sap_agent_initialize(priv_data.agent, ACCESSORY_SERVICE_PROFILE_ID, SAP_AGENT_ROLE_CONSUMER, - on_agent_initialized, NULL); + do { + result = sap_agent_initialize(priv_data.agent, ACCESSORY_SERVICE_PROFILE_ID, SAP_AGENT_ROLE_CONSUMER, + on_agent_initialized, NULL); - LOGD("SAP >>> getRegisteredServiceAgent() >>> %d", result); - } while (result != SAP_RESULT_SUCCESS); + LOGD("SAP >>> getRegisteredServiceAgent() >>> %d", result); + } while (result != SAP_RESULT_SUCCESS); - return TRUE; + return TRUE; } gboolean initialize_sap(void) { - sap_agent_h agent = NULL; + sap_agent_h agent = NULL; - sap_agent_create(&agent); + sap_agent_create(&agent); - priv_data.agent = agent; + priv_data.agent = agent; - agent_initialize(); + agent_initialize(); - sap_set_device_status_changed_cb(_on_device_status_changed, NULL); + sap_set_device_status_changed_cb(_on_device_status_changed, NULL); - return TRUE; + return TRUE; } void deinitialize_sap(void) { - if (priv_data.agent) { - int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL); - switch (ret) { - case SAP_RESULT_FAILURE: - LOGW("Failed to deinitialize"); - break; - case SAP_RESULT_SUCCESS: - LOGD("Succeed to deinitialize"); - break; - case SAP_RESULT_PERMISSION_DENIED: - LOGW("permission denied: deinitialize "); - break; - default: - LOGD("deinitialize : %d", ret); - break; - } - - sap_agent_destroy(priv_data.agent); - priv_data.agent = NULL; - } + if (priv_data.agent) { + int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL); + switch (ret) { + case SAP_RESULT_FAILURE: + LOGW("Failed to deinitialize"); + break; + case SAP_RESULT_SUCCESS: + LOGD("Succeed to deinitialize"); + break; + case SAP_RESULT_PERMISSION_DENIED: + LOGW("permission denied: deinitialize "); + break; + default: + LOGD("deinitialize : %d", ret); + break; + } + + sap_agent_destroy(priv_data.agent); + priv_data.agent = NULL; + } } diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 6151d90..3bf6300 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -6,41 +6,41 @@ static bool app_create(void *data) { - /* Hook to take necessary actions before main event loop starts - Initialize UI resources and application's data - If this function returns true, the main loop of application starts - If this function returns false, the application is terminated */ + /* Hook to take necessary actions before main event loop starts + Initialize UI resources and application's data + If this function returns true, the main loop of application starts + If this function returns false, the application is terminated */ - initialize_sap(); + initialize_sap(); - return true; + return true; } static void app_control(app_control_h app_control, void *data) { - /* Handle the launch request. */ + /* Handle the launch request. */ } static void app_terminate(void *data) { - /* Release all resources. */ - deinitialize_sap(); + /* Release all resources. */ + deinitialize_sap(); } int main(int argc, char *argv[]) { - int ret = 0; + int ret = 0; - service_app_lifecycle_callback_s event_callback; - memset(&event_callback, 0x0, sizeof(service_app_lifecycle_callback_s)); + service_app_lifecycle_callback_s event_callback; + memset(&event_callback, 0x0, sizeof(service_app_lifecycle_callback_s)); - event_callback.create = (service_app_create_cb)app_create; - event_callback.terminate = (service_app_terminate_cb)app_terminate; - event_callback.app_control = (service_app_control_cb)app_control; + event_callback.create = (service_app_create_cb)app_create; + event_callback.terminate = (service_app_terminate_cb)app_terminate; + event_callback.app_control = (service_app_control_cb)app_control; - ret = service_app_main(argc, argv, &event_callback, NULL); - if (ret != APP_ERROR_NONE) { - LOGE("app_main() is failed. err = %d", ret); - } - return ret; + ret = service_app_main(argc, argv, &event_callback, NULL); + if (ret != APP_ERROR_NONE) { + LOGE("app_main() is failed. err = %d", ret); + } + return ret; } diff --git a/receiver/src/sticker_info.cpp b/receiver/src/sticker_info.cpp index 37f11e8..a391fc2 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -12,7 +12,6 @@ sticker_data_h set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword, int len, const char* group, const char* thumbnail, const char* description) { - sticker_data_h sticker_data; int ret; @@ -106,4 +105,4 @@ void destroy_sticker_provider_handle(void) { sticker_provider_destroy(sticker_provider); sticker_provider = NULL; -} \ No newline at end of file +} -- 2.7.4