From 1210883bae3580bd60107d3a746b6b557d002d33 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 23 Oct 2017 14:42:50 +0900 Subject: Removed thread loop This is redundant thread, it works without thread. So removed thread loop like libsoundmanager. Relative Commit: https://gerrit.automotivelinux.org/gerrit/#/c/11403/ Change-Id: I32d65efcf32f3395719837339659ff94b3e64889 Signed-off-by: zheng_wenlong --- include/libhomescreen.hpp | 31 +++++++++++++++---------------- sample/template/main.cpp | 5 ----- src/libhomescreen.cpp | 45 --------------------------------------------- 3 files changed, 15 insertions(+), 66 deletions(-) diff --git a/include/libhomescreen.hpp b/include/libhomescreen.hpp index 06e9ad8..5720368 100644 --- a/include/libhomescreen.hpp +++ b/include/libhomescreen.hpp @@ -35,26 +35,26 @@ public: LibHomeScreen(); ~LibHomeScreen(); - LibHomeScreen(const LibHomeScreen &) = delete; - LibHomeScreen &operator=(const LibHomeScreen &) = delete; + LibHomeScreen(const LibHomeScreen &) = delete; + LibHomeScreen &operator=(const LibHomeScreen &) = delete; - using handler_func = std::function; + using handler_func = std::function; - enum EventType { - Event_TapShortcut = 1, - Event_OnScreenMessage - }; + enum EventType { + Event_TapShortcut = 1, + Event_OnScreenMessage + }; - static const std::vector api_list; - static const std::vector event_list; + static const std::vector api_list; + static const std::vector event_list; /* Method */ - int init(const int port, const std::string& token); + int init(const int port, const std::string& token); - int tapShortcut(const char* application_name); - int onScreenMessage(const char* display_message); + int tapShortcut(const char* application_name); + int onScreenMessage(const char* display_message); - void set_event_handler(enum EventType et, handler_func f); + void set_event_handler(enum EventType et, handler_func f); void registerCallback( void (*event_cb)(const std::string& event, struct json_object* event_contents), @@ -68,8 +68,7 @@ public: private: int initialize_websocket(); - int runEventloop(); - + void (*onEvent)(const std::string& event, struct json_object* event_contents); void (*onReply)(struct json_object* reply); void (*onHangup)(void); @@ -82,7 +81,7 @@ private: int mport = 2000; std::string mtoken = "hs"; - std::map handlers; + std::map handlers; public: /* Don't use/ Internal only */ diff --git a/sample/template/main.cpp b/sample/template/main.cpp index ccbe935..589d314 100644 --- a/sample/template/main.cpp +++ b/sample/template/main.cpp @@ -135,10 +135,6 @@ int main(int argc, char *argv[]) } }); - // Run event loop for HomeScreen - hs->runEventloop(); - - /* * Set SoundManager */ @@ -148,7 +144,6 @@ int main(int argc, char *argv[]) smw->subscribe(QString("removedMainConnection")); smw->subscribe(QString("asyncSetSourceState")); smw->subscribe(QString("asyncConnect")); - smw->run_eventloop(); // Set context property for SoundManager context->setContextProperty("smw", smw); diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp index 90ecec2..42ab8b1 100644 --- a/src/libhomescreen.cpp +++ b/src/libhomescreen.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -80,7 +79,6 @@ static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg) */ LibHomeScreen::LibHomeScreen() { - } /** @@ -134,8 +132,6 @@ int LibHomeScreen::init(const int port, const string& token) HMI_DEBUG("libhomescreen","Initialized"); } - this->runEventloop(); - return ret; } @@ -199,47 +195,6 @@ END: return -1; } -static void *event_loop_run(void *args) -{ - struct sd_event* loop = (struct sd_event*)(args); - HMI_DEBUG("libhomescreen","start eventloop"); - for(;;) - sd_event_run(loop, 30000000); -} - -/** - * This function start receiving the reply/event message from home screen - * - * #### Parameters - * Nothing - * - * #### Return - * - Returns thread_id on success or -1 in case of error. - * - * #### Note - * - */ -int LibHomeScreen::runEventloop() -{ - if(mploop && sp_websock) - { - pthread_t thread_id; - int ret = pthread_create(&thread_id, NULL, event_loop_run, mploop); - if(ret != 0) - { - HMI_ERROR("libhomescreen","Cannot run eventloop due to error:%d", errno); - return -1; - } - else - return thread_id; - } - else - { - HMI_ERROR("libhomescreen","Connecting is not established yet"); - return -1; - } -} - /** * Sending ShortCut Icon tapped event * -- cgit 1.2.3-korg