From 29f80e1fc8fd0b8d58645047709a5a488e7c7995 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 24 Feb 2020 17:12:56 +0900 Subject: [PATCH] Change log format in sticker-receiver Change-Id: Id5730c2353be61cfc35804e6e519269224e594b2 Signed-off-by: Jihoon Kim --- receiver/inc/log.h | 6 ++- receiver/inc/main.h | 2 - receiver/inc/sticker_info.h | 2 - receiver/src/ft.cpp | 87 ++++++++++++++++++++++--------------------- receiver/src/main.cpp | 3 +- receiver/src/sticker_info.cpp | 23 ++++++------ 6 files changed, 62 insertions(+), 61 deletions(-) diff --git a/receiver/inc/log.h b/receiver/inc/log.h index df3f0b2..3749cad 100644 --- a/receiver/inc/log.h +++ b/receiver/inc/log.h @@ -3,6 +3,9 @@ #include +#undef LOG_TAG +#define LOG_TAG "STICKER_RECEIVER" + #ifndef _LOG #define _LOG(logLevel, fmt, ...) do { \ dlog_print(logLevel, LOG_TAG, "%s : %s(%d) > " fmt, rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ @@ -29,5 +32,4 @@ #define LOGF(format, arg...) _LOG(DLOG_FATAL, format, ##arg) #endif -#endif /* __debug_H__ */ - +#endif /* __debug_H__ */ \ No newline at end of file diff --git a/receiver/inc/main.h b/receiver/inc/main.h index 473ac68..b6fac02 100644 --- a/receiver/inc/main.h +++ b/receiver/inc/main.h @@ -5,8 +5,6 @@ #ifndef __MAIN_H__ #define __MAIN_H__ -#define TAG "STICKER_RECEIVER" - #if !defined(PACKAGE) #define PACKAGE "org.tizen.sticker-receiver" #endif diff --git a/receiver/inc/sticker_info.h b/receiver/inc/sticker_info.h index 27f2206..7cf88fe 100644 --- a/receiver/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -1,8 +1,6 @@ #ifndef __STICKER_INFO_H__ #define __STICKER_INFO_H__ -#define TAG "STICKER_RECEIVER" - void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc); int create_sticker_provider_handle(void); void destroy_sticker_provider_handle(void); diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 133f673..a67c6d6 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -29,10 +29,11 @@ #include #include -#define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" - +#include "log.h" #include "sticker_info.h" +#define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" + using namespace std; struct priv { @@ -53,7 +54,7 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, { char error_message[100]; - dlog_print(DLOG_INFO, TAG, "# transfer completed"); + LOGI("# transfer completed"); if (priv_data.socket) { sap_file_transfer_destroy(file_transaction); @@ -62,68 +63,68 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, if (result == SAP_FT_TRANSFER_SUCCESS) { sprintf(error_message, "Transfer Completed"); - dlog_print(DLOG_INFO, TAG, "Transfer Completed"); + LOGI("Transfer Completed"); if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { - dlog_print(DLOG_ERROR, TAG, "Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); + LOGE("Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); } else { - dlog_print(DLOG_INFO, TAG, "Succeed to change permission : %s", recv_filepath.c_str()); + 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) - dlog_print(DLOG_ERROR, TAG, "Failed to remove sticker file"); + LOGE("Failed to remove sticker file"); } } } else { switch (result) { case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { sprintf(error_message, "Channel IO Error."); - dlog_print(DLOG_WARN, TAG, "Channel IO Error."); + LOGW("Channel IO Error."); break; } case (SAP_FT_TRANSFER_FAIL_FILE_IO): { sprintf(error_message, "File IO Error."); - dlog_print(DLOG_WARN, TAG, "File IO Error."); + LOGW("File IO Error."); break; } case (SAP_FT_TRANSFER_FAIL_CMD_DROPPED): { sprintf(error_message, "Transfer dropped."); - dlog_print(DLOG_WARN, TAG, "Transfer dropped."); + LOGW("Transfer dropped."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_UNRESPONSIVE): { sprintf(error_message, "Peer Un Responsive."); - dlog_print(DLOG_WARN, TAG, "Peer Un Responsive."); + LOGW("Peer Un Responsive."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_CONN_LOST): { sprintf(error_message, "Connection Lost."); - dlog_print(DLOG_WARN, TAG, "Connection Lost."); + LOGW("Connection Lost."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_CANCELLED): { sprintf(error_message, "Peer Cancelled."); - dlog_print(DLOG_WARN, TAG, "Peer Cancelled."); + LOGW("Peer Cancelled."); break; } case (SAP_FT_TRANSFER_FAIL_SPACE_NOT_AVAILABLE): { sprintf(error_message, "No Space."); - dlog_print(DLOG_WARN, TAG, "No Space."); + LOGW("No Space."); break; } default: sprintf(error_message, "Unknown Error"); - dlog_print(DLOG_WARN, TAG, "Unknown Error"); + LOGW("Unknown Error"); } } @@ -134,12 +135,12 @@ static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction unsigned short int percentage_progress, void *user_data) { - dlog_print(DLOG_INFO, TAG, "# progress %d", percentage_progress); + LOGI("# progress %d", percentage_progress); } static void __set_file_transfer_cb(sap_file_transaction_h file_socket) { - dlog_print(DLOG_INFO, TAG, "# set callbacks"); + 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); @@ -152,22 +153,22 @@ void accept_file() char *data_path = NULL; data_path = app_get_shared_data_path(); - dlog_print(DLOG_INFO, TAG, "Path : %s", data_path); + LOGI("Path : %s", data_path); sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str()); - dlog_print(DLOG_INFO, TAG, "Receive filepath : %s", file_path); + 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: - dlog_print(DLOG_WARN, TAG, "permission denied"); + LOGW("permission denied"); break; case SAP_RESULT_FAILURE: - dlog_print(DLOG_WARN, TAG, "Fail"); + LOGW("Fail"); break; case SAP_RESULT_SUCCESS: - dlog_print(DLOG_INFO, TAG, "Success"); + LOGI("Success"); break; } @@ -182,7 +183,7 @@ void sap_file_transfer_get_receive_filepath(char **filepath) void reject_file() { int ret = sap_file_transfer_reject(priv_data.socket); - dlog_print(DLOG_INFO, TAG, "ret : %d", ret); + LOGI("ret : %d", ret); file_on_progress = 0; } @@ -194,14 +195,14 @@ static void _on_receive_file_cb(sap_peer_agent_h peer_agent_h, { file_on_progress = 1; priv_data.socket = socket; - dlog_print(DLOG_INFO, TAG, "# incoming file request."); + 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); - dlog_print(DLOG_INFO, TAG, "# 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(); } @@ -211,14 +212,14 @@ void conn_terminated(sap_peer_agent_h peer_agent, sap_service_connection_terminated_reason_e result, void *user_data) { - dlog_print(DLOG_INFO, TAG, "connection terminated"); + LOGI("connection terminated"); } 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) */ { - dlog_print(DLOG_INFO, TAG, "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, @@ -239,7 +240,7 @@ static void on_agent_initialized(sap_agent_h agent, switch (result) { case SAP_AGENT_INITIALIZED_RESULT_SUCCESS: - dlog_print(DLOG_DEBUG, TAG, "agent is initialized"); + LOGD("agent is initialized"); priv_data.agent = agent; @@ -249,22 +250,22 @@ static void on_agent_initialized(sap_agent_h agent, break; case SAP_AGENT_INITIALIZED_RESULT_DUPLICATED: - dlog_print(DLOG_ERROR, TAG, "duplicate registration"); + LOGE("duplicate registration"); break; case SAP_AGENT_INITIALIZED_RESULT_INVALID_ARGUMENTS: - dlog_print(DLOG_ERROR, TAG, "invalid arguments"); + LOGE("invalid arguments"); break; case SAP_AGENT_INITIALIZED_RESULT_INTERNAL_ERROR: - dlog_print(DLOG_ERROR, TAG, "internal sap error"); + LOGE("internal sap error"); break; default: - dlog_print(DLOG_ERROR, TAG, "unknown status (%d)", result); + LOGE("unknown status (%d)", result); break; } @@ -274,45 +275,45 @@ static void _on_device_status_changed(sap_device_status_e status, sap_transport_type_e transport_type, void *user_data) { - dlog_print(DLOG_DEBUG, TAG, "%s, status :%d", __func__, status); + LOGD("%s, status :%d", __func__, status); switch (transport_type) { case SAP_TRANSPORT_TYPE_BT: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): bt", transport_type); + LOGD("transport_type (%d): bt", transport_type); break; case SAP_TRANSPORT_TYPE_BLE: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): ble", transport_type); + LOGD("transport_type (%d): ble", transport_type); break; case SAP_TRANSPORT_TYPE_TCP: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): tcp/ip", transport_type); + LOGD("transport_type (%d): tcp/ip", transport_type); break; case SAP_TRANSPORT_TYPE_USB: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): usb", transport_type); + LOGD("transport_type (%d): usb", transport_type); break; case SAP_TRANSPORT_TYPE_MOBILE: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): mobile", transport_type); + LOGD("transport_type (%d): mobile", transport_type); break; default: - dlog_print(DLOG_ERROR, TAG, "unknown transport_type (%d)", transport_type); + LOGE("unknown transport_type (%d)", transport_type); break; } switch (status) { case SAP_DEVICE_STATUS_DETACHED: - dlog_print(DLOG_DEBUG, TAG, "device is not connected."); + LOGD("device is not connected."); break; case SAP_DEVICE_STATUS_ATTACHED: - dlog_print(DLOG_DEBUG, TAG, "Attached calling find peer now"); + LOGD("Attached calling find peer now"); break; default: - dlog_print(DLOG_ERROR, TAG, "unknown status (%d)", status); + LOGE("unknown status (%d)", status); break; } } @@ -325,7 +326,7 @@ gboolean agent_initialize() result = sap_agent_initialize(priv_data.agent, ACCESSORY_SERVICE_PROFILE_ID, SAP_AGENT_ROLE_CONSUMER, on_agent_initialized, NULL); - dlog_print(DLOG_DEBUG, TAG, "SAP >>> getRegisteredServiceAgent() >>> %d", result); + LOGD("SAP >>> getRegisteredServiceAgent() >>> %d", result); } while (result != SAP_RESULT_SUCCESS); return TRUE; diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 3192e42..d99158b 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -1,5 +1,6 @@ #include "main.h" #include "ft.h" +#include "log.h" #include #include @@ -38,7 +39,7 @@ int main(int argc, char *argv[]) ret = service_app_main(argc, argv, &event_callback, NULL); if (ret != APP_ERROR_NONE) { - dlog_print(DLOG_ERROR, TAG, "app_main() is failed. err = %d", ret); + 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 0282163..37f11e8 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -1,10 +1,11 @@ #include "sticker_info.h" #include -#include #include #include #include +#include "log.h" + static sticker_provider_h sticker_provider = NULL; sticker_data_h @@ -19,14 +20,14 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_create(&sticker_data); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to create sticker data"); + LOGE("Failed to create sticker data"); } /* Sets the URI and URI type of the sticker */ ret = sticker_data_set_uri(sticker_data, type, uri); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set uri"); + LOGE("Failed to set uri"); } //for (int i = 0; i < len; i++) @@ -35,7 +36,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_add_keyword(sticker_data, keyword); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to add keyword"); + LOGE("Failed to add keyword"); } } @@ -43,7 +44,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_set_group_name(sticker_data, group); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set group name"); + LOGE("Failed to set group name"); } /* Sets the thumbnail local path of the sticker */ @@ -51,7 +52,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_set_thumbnail(sticker_data, thumbnail); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set thumbnail"); + LOGE("Failed to set thumbnail"); } } @@ -59,7 +60,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_set_description(sticker_data, description); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set description"); + LOGE("Failed to set description"); } return sticker_data; @@ -75,17 +76,17 @@ insert_sticker_data(const char *filepath, const char *keyword, const char *group ret = sticker_provider_insert_data(sticker_provider, data_handle); if (ret != STICKER_ERROR_NONE) { - dlog_print(DLOG_ERROR, TAG, "Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret)); + LOGE("Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret)); } else { - dlog_print(DLOG_INFO, TAG, "Succeeded to insert data"); + LOGI("Succeeded to insert data"); } /* Destroys a sticker data handle */ ret = sticker_data_destroy(data_handle); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to destroy sticker data"); + LOGE("Failed to destroy sticker data"); } } @@ -95,7 +96,7 @@ int create_sticker_provider_handle(void) ret = sticker_provider_create(&sticker_provider); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to create sticker provider"); + LOGE("Failed to create sticker provider"); } return ret; -- 2.7.4