From 572023336d9573d3d5636d7e61a8dd3ed8878b0d Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 23 Oct 2017 14:35:58 +0900 Subject: Add debug message control by environment variable Add HMI_DEBUG to print debug message, It is controlled by the USE_HMI_DEBUG environment variable. BUG-AGL: SPEC-998 Change-Id: I4b948f3af0d3a1b5e8707518e5b83a1029df3667 Signed-off-by: zheng_wenlong --- src/libhomescreen.cpp | 76 ++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 53 deletions(-) (limited to 'src/libhomescreen.cpp') diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp index ef73cbc..90ecec2 100644 --- a/src/libhomescreen.cpp +++ b/src/libhomescreen.cpp @@ -28,14 +28,10 @@ #include #include - -#define ELOG(args,...) _ELOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__) -#define DLOG(args,...) _DLOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__) +#include "hmi-debug.h" using namespace std; -static void _DLOG(const char* func, const int line, const char* log, ...); -static void _ELOG(const char* func, const int line, const char* log, ...); static bool has_verb(const string& verb); static const char API[] = "homescreen"; @@ -126,16 +122,16 @@ int LibHomeScreen::init(const int port, const string& token) } else { - ELOG("port and token should be > 0, Initial port and token uses."); + HMI_ERROR("libhomescreen","port and token should be > 0, Initial port and token uses."); } ret = initialize_websocket(); if(ret != 0 ) { - ELOG("Failed to initialize websocket"); + HMI_ERROR("libhomescreen","Failed to initialize websocket"); } else{ - DLOG("Initialized"); + HMI_DEBUG("libhomescreen","Initialized"); } this->runEventloop(); @@ -175,7 +171,7 @@ int LibHomeScreen::initialize_websocket() int ret = sd_event_default(&mploop); if(ret < 0) { - ELOG("Failed to create event loop"); + HMI_ERROR("libhomescreen","Failed to create event loop"); goto END; } @@ -187,7 +183,7 @@ int LibHomeScreen::initialize_websocket() sp_websock = afb_ws_client_connect_wsj1(mploop, muri.c_str(), &minterface, this); if(sp_websock == NULL) { - ELOG("Failed to create websocket connection"); + HMI_ERROR("libhomescreen","Failed to create websocket connection"); goto END; } @@ -206,7 +202,7 @@ END: static void *event_loop_run(void *args) { struct sd_event* loop = (struct sd_event*)(args); - DLOG("start eventloop"); + HMI_DEBUG("libhomescreen","start eventloop"); for(;;) sd_event_run(loop, 30000000); } @@ -231,7 +227,7 @@ int LibHomeScreen::runEventloop() int ret = pthread_create(&thread_id, NULL, event_loop_run, mploop); if(ret != 0) { - ELOG("Cannot run eventloop due to error:%d", errno); + HMI_ERROR("libhomescreen","Cannot run eventloop due to error:%d", errno); return -1; } else @@ -239,18 +235,18 @@ int LibHomeScreen::runEventloop() } else { - ELOG("Connecting is not established yet"); + HMI_ERROR("libhomescreen","Connecting is not established yet"); return -1; } } /** - * ショートカットアイコンがタップされたイベントの発行 + * Sending ShortCut Icon tapped event * - * HomeScreenアプリケーションにて各アプリアイコンがタップされたときにイベントを発行する + * When HomeScreen shortcut area is tapped, sending a event * * #### Parameters - * - application_name [in] : タップされたアプリケーションの名前(label) + * - application_name [in] : Tapped application name (label) * * #### Return * - Returns 0 on success or -1 in case of error. @@ -343,12 +339,12 @@ int LibHomeScreen::call(const string& verb, struct json_object* arg) } if (!has_verb(verb)) { - ELOG("verb doesn't exit"); + HMI_ERROR("libhomescreen","verb doesn't exit"); return -1; } ret = afb_wsj1_call_j(sp_websock, API, verb.c_str(), arg, _on_reply_static, this); if (ret < 0) { - ELOG("Failed to call verb:%s",verb.c_str()); + HMI_ERROR("libhomescreen","Failed to call verb:%s",verb.c_str()); } return ret; } @@ -377,12 +373,12 @@ int LibHomeScreen::call(const char* verb, struct json_object* arg) } if (!has_verb(string(verb))) { - ELOG("verb doesn't exit"); + HMI_ERROR("libhomescreen","verb doesn't exit"); return -1; } ret = afb_wsj1_call_j(sp_websock, API, verb, arg, _on_reply_static, this); if (ret < 0) { - ELOG("Failed to call verb:%s",verb); + HMI_ERROR("libhomescreen","Failed to call verb:%s",verb); } return ret; } @@ -411,7 +407,7 @@ int LibHomeScreen::subscribe(const string& event_name) int ret = afb_wsj1_call_j(sp_websock, API, "subscribe", j_obj, _on_reply_static, this); if (ret < 0) { - ELOG("Failed to call verb:%s",__FUNCTION__); + HMI_ERROR("libhomescreen","Failed to call verb"); } return ret; } @@ -440,7 +436,7 @@ int LibHomeScreen::unsubscribe(const string& event_name) int ret = afb_wsj1_call_j(sp_websock, API, "unsubscribe", j_obj, _on_reply_static, this); if (ret < 0) { - ELOG("Failed to call verb:%s",__FUNCTION__); + HMI_ERROR("libhomescreen","Failed to call verb"); } return ret; } @@ -449,7 +445,7 @@ int LibHomeScreen::unsubscribe(const string& event_name) void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj) { - DLOG("%s called", __FUNCTION__); + HMI_DEBUG("libhomescreen","called"); if(onHangup != nullptr) { onHangup(); @@ -468,9 +464,9 @@ void LibHomeScreen::on_call(void *closure, const char *api, const char *verb, st */ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_msg *msg) { - cout << "[libhomescreen on_event]: " << event << " (" << afb_wsj1_msg_object_s(msg) << ")" << endl; + HMI_DEBUG("libhomescreen","event: (%s) msg: (%s).", event, afb_wsj1_msg_object_s(msg)); - if (strstr(event, API) == NULL) { + if (strstr(event, API) == NULL) { return; } @@ -520,7 +516,7 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m */ void LibHomeScreen::on_reply(void *closure, struct afb_wsj1_msg *msg) { - cout << "[libhomescreen on_reply]: " << " (" << afb_wsj1_msg_object_s(msg) << ")" << endl; + HMI_DEBUG("libhomescreen","msg: (%s)", afb_wsj1_msg_object_s(msg)); if(onReply != nullptr) { struct json_object* reply = afb_wsj1_msg_object_j(msg); @@ -530,35 +526,9 @@ void LibHomeScreen::on_reply(void *closure, struct afb_wsj1_msg *msg) } } -/* Internal Function in libhomescreen */ - -static void _ELOG(const char* func, const int line, const char* log, ...) -{ - char *message; - va_list args; - va_start(args, log); - if (log == NULL || vasprintf(&message, log, args) < 0) - message = NULL; - cout << "[libhomescreen ERROR]" << func << "(" << line << "):" << message << endl; - va_end(args); - free(message); -} - -static void _DLOG(const char* func, const int line, const char* log, ...) -{ - char *message; - va_list args; - va_start(args, log); - if (log == NULL || vasprintf(&message, log, args) < 0) - message = NULL; - cout << "[libhomescreen DEBUG]" << func << "(" << line << "):" << message << endl; - va_end(args); - free(message); -} - static bool has_verb(const string& verb) { - DLOG("verb is %s", verb.c_str()); + HMI_DEBUG("libhomescreen","verb is %s", verb.c_str()); if(find(LibHomeScreen::api_list.begin(), LibHomeScreen::api_list.end(), verb) != LibHomeScreen::api_list.end()) return true; else -- cgit 1.2.3-korg