aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt13
-rw-r--r--cmake/modules/Findgtest.cmake38
-rw-r--r--homescreen.pc.in12
-rw-r--r--include/CMakeLists.txt19
-rw-r--r--include/libhomescreen.hpp95
-rw-r--r--libhomescreen/CMakeLists.txt58
-rw-r--r--libhomescreen/libhomescreen.cpp566
-rw-r--r--libhomescreen/test.cpp179
8 files changed, 2 insertions, 978 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 57f56b1..a854b43 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,15 +18,14 @@ project(HomeScreenService C CXX)
cmake_minimum_required(VERSION 3.0)
-set(PROJECT_NAME "HomeScreen Service and client library")
+set(PROJECT_NAME "HomeScreen Service 2017")
set(PROJECT_VERSION "1.0")
set(PROJECT_PRETTY_NAME "HM")
-set(PROJECT_DESCRIPTION "HomeScreen Service and client library")
+set(PROJECT_DESCRIPTION "HomeScreen Service 2017")
set(PROJECT_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(PROJECT_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
set(binding_install_dir ${PREFIX}/lib/homescreen)
set(PROJECT_BINDINGDIR ${binding_install_dir})
-set(LIBSM_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
# get pkgconfig
INCLUDE(FindPkgConfig)
@@ -37,11 +36,3 @@ set(DEBUGMODE "1")
add_definitions(-DDEBUGMODE)
add_subdirectory(src)
-add_subdirectory(libhomescreen)
-add_subdirectory(include)
-
-#generate configure file
-configure_file(homescreen.pc.in homescreen.pc @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/homescreen.pc
- DESTINATION
- ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
diff --git a/cmake/modules/Findgtest.cmake b/cmake/modules/Findgtest.cmake
deleted file mode 100644
index 8ea850f..0000000
--- a/cmake/modules/Findgtest.cmake
+++ /dev/null
@@ -1,38 +0,0 @@
-SET(MODULE_NAME gtest)
-
-SET(${MODULE_NAME}_FOUND FALSE)
-
-FIND_PATH(${MODULE_NAME}_INCLUDE_DIRS
- NAMES gtest/gtest.h
- PATHS /usr/include /usr/local/include
-)
-
-FIND_LIBRARY(LIB_GTEST
- NAMES gtest
- PATHS /usr/lib
- /usr/lib64
- /usr/local/lib
- /usr/local/lib64
-)
-
-FIND_LIBRARY(LIB_GTEST_MAIN
- NAMES gtest_main
- PATHS /usr/lib
- /usr/lib64
- /usr/local/lib
- /usr/local/lib64
-)
-
-IF(LIB_GTEST AND LIB_GTEST_MAIN)
- SET(${MODULE_NAME}_FOUND TRUE)
- SET(${MODULE_NAME}_LIBRARIES ${LIB_GTEST} ${LIB_GTEST_MAIN})
-ENDIF()
-
-MARK_AS_ADVANCED(
- ${MODULE_NAME}_FOUND
- ${MODULE_NAME}_INCLUDE_DIRS
- ${MODULE_NAME}_LIBRARIES
-)
-
-MESSAGE(STATUS "${MODULE_NAME}_INCLUDE_DIRS: ${${MODULE_NAME}_INCLUDE_DIRS}")
-MESSAGE(STATUS "${MODULE_NAME}_LIBRARIES: ${${MODULE_NAME}_LIBRARIES}")
diff --git a/homescreen.pc.in b/homescreen.pc.in
deleted file mode 100644
index 809abbd..0000000
--- a/homescreen.pc.in
+++ /dev/null
@@ -1,12 +0,0 @@
-includedir=@PROJECT_INCLUDEDIR@
-libdir=@PROJECT_LIBDIR@
-binding_install_dir=@binding_install_dir@
-
-Name: @PROJECT_PRETTY_NAME@
-Description: @PROJECT_DESCRIPTION@
-Version: @PROJECT_VERSION@
-URL: @PROJECT_URL@
-
-Requires: json-c afb-daemon
-Cflags: -I${includedir}
-Libs: -L${libdir} -lhomescreen
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
deleted file mode 100644
index bb37242..0000000
--- a/include/CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Copyright (c) 2017 TOYOTA MOTOR CORPORATION
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-if(DEFINED CMAKE_INSTALL_INCLUDEDIR)
- INSTALL(FILES libhomescreen.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
-endif(DEFINED CMAKE_INSTALL_INCLUDEDIR)
diff --git a/include/libhomescreen.hpp b/include/libhomescreen.hpp
deleted file mode 100644
index 06e9ad8..0000000
--- a/include/libhomescreen.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef LIBHOMESCREEN_H
-#define LIBHOMESCREEN_H
-#include <vector>
-#include <map>
-#include <string>
-#include <functional>
-#include <json-c/json.h>
-#include <systemd/sd-event.h>
-extern "C"
-{
-#include <afb/afb-binding.h>
-#include <afb/afb-wsj1.h>
-#include <afb/afb-ws-client.h>
-}
-
-class LibHomeScreen
-{
-public:
- LibHomeScreen();
- ~LibHomeScreen();
-
- LibHomeScreen(const LibHomeScreen &) = delete;
- LibHomeScreen &operator=(const LibHomeScreen &) = delete;
-
- using handler_func = std::function<void(const char*)>;
-
- enum EventType {
- Event_TapShortcut = 1,
- Event_OnScreenMessage
- };
-
- static const std::vector<std::string> api_list;
- static const std::vector<std::string> event_list;
-
- /* Method */
- int init(const int port, const std::string& token);
-
- int tapShortcut(const char* application_name);
- int onScreenMessage(const char* display_message);
-
- void set_event_handler(enum EventType et, handler_func f);
-
- void registerCallback(
- void (*event_cb)(const std::string& event, struct json_object* event_contents),
- void (*reply_cb)(struct json_object* reply_contents),
- void (*hangup_cb)(void) = nullptr);
-
- int call(const std::string& verb, struct json_object* arg);
- int call(const char* verb, struct json_object* arg);
- int subscribe(const std::string& event_name);
- int unsubscribe(const std::string& event_name);
-
-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);
-
- struct afb_wsj1* sp_websock;
- struct afb_wsj1_itf minterface;
- sd_event* mploop;
- std::string muri;
-
- int mport = 2000;
- std::string mtoken = "hs";
-
- std::map<EventType, handler_func> handlers;
-
-public:
- /* Don't use/ Internal only */
- void on_hangup(void *closure, struct afb_wsj1 *wsj);
- void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
- void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
- void on_reply(void *closure, struct afb_wsj1_msg *msg);
-};
-
-#endif /* LIBHOMESCREEN_H */
diff --git a/libhomescreen/CMakeLists.txt b/libhomescreen/CMakeLists.txt
deleted file mode 100644
index b9dc94b..0000000
--- a/libhomescreen/CMakeLists.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# Copyright (c) 2017 TOYOTA MOTOR CORPORATION
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-
-cmake_minimum_required(VERSION 3.0)
-
-set(TARGET_LIBHS homescreen)
-add_definitions("-std=c++11")
-
-pkg_check_modules(libhs_depends json-c libafbwsc libsystemd)
-set(libhs_sources libhomescreen.cpp)
-
-include_directories(${LIBSM_INCLUDE_DIR})
-link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
-
-add_library(${TARGET_LIBHS} SHARED ${libhs_sources})
-target_compile_options(${TARGET_LIBHS} PUBLIC ${libhs_depends_CFLAGS})
-
-if(DEFINED DEBUGMODE)
- target_compile_options(${TARGET_LIBHS} PRIVATE -g -O0)
-else(DEFINED DEBUGMODE)
- target_compile_options(${TARGET_LIBHS} PRIVATE -g -O2)
-endif(DEFINED DEBUGMODE)
-
-include_directories(${TARGET_LIBHS} ${libhs_depends_INCLUDE_DIRS})
-target_link_libraries(${TARGET_LIBHS} afbwsc -lpthread ${link_libraries} ${libhs_depends_LIBRARIES})
-
-if(DEFINED CMAKE_INSTALL_LIBDIR)
- INSTALL(TARGETS ${TARGET_LIBHS}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
-endif(DEFINED CMAKE_INSTALL_LIBDIR)
-
-#####################
-pkg_check_modules(test_depends glib-2.0 gio-2.0 gio-unix-2.0)
-add_executable(libhomescreen-demo test.cpp)
-include_directories(libhomescreen-demo ${test_depends_INCLUDE_DIRS})
-TARGET_LINK_LIBRARIES(libhomescreen-demo
- homescreen
- ${link_libraries}
- -lpthread
- ${test_depends_LIBRARIES}
- ${libhs_depends_LIBRARIES}
-)
-#####################
-#add_subdirectory(test)
diff --git a/libhomescreen/libhomescreen.cpp b/libhomescreen/libhomescreen.cpp
deleted file mode 100644
index 6c6076e..0000000
--- a/libhomescreen/libhomescreen.cpp
+++ /dev/null
@@ -1,566 +0,0 @@
-/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdarg.h>
-#include <sys/socket.h>
-#include <iostream>
-#include <algorithm>
-#include <thread>
-#include <errno.h>
-#include <cassert>
-#include <cctype>
-#include <cerrno>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-
-#include <libhomescreen.hpp>
-
-#define ELOG(args,...) _ELOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
-#define DLOG(args,...) _DLOG(__FUNCTION__,__LINE__,args,##__VA_ARGS__)
-
-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";
-
-const std::vector<std::string> LibHomeScreen::api_list {
- std::string("ping"), // debug do not use
- std::string("tap_shortcut"), // HomeScreen Application only
- std::string("on_screen_message"),
- std::string("subscribe"),
- std::string("unsubscribe")
-};
-
-const std::vector<std::string> LibHomeScreen::event_list {
- std::string("tap_shortcut"),
- std::string("on_screen_message"),
- std::string("none")
-};
-
-
-/**
- * websocket
- */
-
-static void _on_hangup_static(void *closure, struct afb_wsj1 *wsj)
-{
- static_cast<LibHomeScreen*>(closure)->on_hangup(NULL,wsj);
-}
-
-static void _on_call_static(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
-{
- /* LibHomeScreen is not called from other process */
-}
-
-static void _on_event_static(void* closure, const char* event, struct afb_wsj1_msg *msg)
-{
- static_cast<LibHomeScreen*>(closure)->on_event(NULL,event,msg);
-}
-
-static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
-{
- static_cast<LibHomeScreen*>(closure)->on_reply(NULL,msg);
-}
-
-
-/**
- * constructor
- */
-LibHomeScreen::LibHomeScreen()
-{
-
-}
-
-/**
- * destructor
- */
-LibHomeScreen::~LibHomeScreen()
-{
- if(mploop)
- {
- sd_event_unref(mploop);
- }
- if(sp_websock != NULL)
- {
- afb_wsj1_unref(sp_websock);
- }
-}
-
-/**
- * This function is initializer
- *
- * #### Parameters
- * - port [in] : This argument should be specified to the port number to be used for websocket
- * - token [in] : This argument should be specified to the token to be used for websocket
- *
- * #### Return
- * Nothing
- *
- * #### Note
- * Use this constructor
- *
- */
-int LibHomeScreen::init(const int port, const string& token)
-{
- int ret = 0;
- if(port > 0 && token.size() > 0)
- {
- mport = port;
- mtoken = token;
- }
- else
- {
- ELOG("port and token should be > 0, Initial port and token uses.");
- }
-
- ret = initialize_websocket();
- if(ret != 0 )
- {
- ELOG("Failed to initialize websocket");
- }
- else{
- DLOG("Initialized");
- }
-
- this->runEventloop();
-
- return ret;
-}
-
-/**
- * This function register callback function for reply/event message from home screen
- *
- * #### Parameters
- * - event_cb [in] : This argument should be specified to the callback for subscribed event
- * - reply_cb [in] : This argument should be specified to the reply callback for call function
- *
- * #### Return
- * Nothing
- *
- * #### Note
- * Event callback is invoked by home screen for event you subscribed.
- * If you would like to get event, please call subscribe function before/after this function
- */
-void LibHomeScreen::registerCallback(
- void (*event_cb)(const std::string& event, struct json_object* event_contents),
- void (*reply_cb)(struct json_object* reply_contents),
- void (*hangup_cb)(void))
-{
- onEvent = event_cb;
- onReply = reply_cb;
- onHangup = hangup_cb;
-}
-
-int LibHomeScreen::initialize_websocket()
-{
- mploop = NULL;
- onEvent = nullptr;
- onReply = nullptr;
- int ret = sd_event_default(&mploop);
- if(ret < 0)
- {
- ELOG("Failed to create event loop");
- goto END;
- }
-
- /* Initialize interface from websocket */
- minterface.on_hangup = _on_hangup_static;
- minterface.on_call = _on_call_static; /* Is this necessary? */
- minterface.on_event = _on_event_static;
- muri += "ws://localhost:" + to_string(mport) + "/api?token=" + mtoken; /*To be modified*/
- sp_websock = afb_ws_client_connect_wsj1(mploop, muri.c_str(), &minterface, this);
- if(sp_websock == NULL)
- {
- ELOG("Failed to create websocket connection");
- goto END;
- }
-
- /* creates the evsrc */
- //ret = sd_event_add_io(mploop,&mevent_src, sp_websock->fd, EPOLLIN, event_callback, NULL);
-
- return 0;
-END:
- if(mploop)
- {
- sd_event_unref(mploop);
- }
- return -1;
-}
-
-static void *event_loop_run(void *args)
-{
- struct sd_event* loop = (struct sd_event*)(args);
- DLOG("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)
- {
- ELOG("Cannot run eventloop due to error:%d", errno);
- return -1;
- }
- else
- return thread_id;
- }
- else
- {
- ELOG("Connecting is not established yet");
- return -1;
- }
-}
-
-/**
- * Sending ShortCut Icon tapped event
- *
- * When HomeScreen shortcut area is tapped, sending a event
- *
- * #### Parameters
- * - application_name [in] : Tapped application name (label)
- *
- * #### Return
- * - Returns 0 on success or -1 in case of error.
- */
-int LibHomeScreen::tapShortcut(const char* application_name)
-{
- if(!sp_websock)
- {
- return -1;
- }
-
- struct json_object* j_obj = json_object_new_object();
- struct json_object* val = json_object_new_string(application_name);
- json_object_object_add(j_obj, "application_name", val);
- return this->call("tap_shortcut", j_obj);
-}
-
-/**
- * Sending onScreen message event
- *
- * Sending OnScreen message event to HomeScreen from applications
- *
- * #### Parameters
- * - display_message [in] : message for display
- *
- * #### Return
- * - Returns 0 on success or -1 in case of error.
- */
-int LibHomeScreen::onScreenMessage(const char* display_message)
-{
- if(!sp_websock)
- {
- return -1;
- }
-
- struct json_object* j_obj = json_object_new_object();
- struct json_object* val = json_object_new_string(display_message);
- json_object_object_add(j_obj, "display_message", val);
- return this->call("on_screen_message", j_obj);
-}
-
-/**
- * Setting Event Handler
- *
- * Setting event handler for Homescreen
- *
- * #### Parameters
- * - et [in] : event name
- * - f [in] : event handler
- *
- * #### Return
- * Nothing
- */
-void LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
-{
- if (et >= 1 && et <= 2) {
- switch (et) {
- case Event_TapShortcut:
- this->subscribe(LibHomeScreen::event_list[0]);
- break;
- case Event_OnScreenMessage:
- this->subscribe(LibHomeScreen::event_list[1]);
- break;
- }
-
- this->handlers[et] = std::move(f);
- }
-}
-
-/**
- * This function calls the API of HomeScreen via WebSocket
- *
- * #### Parameters
- * - verb [in] : This argument should be specified to the API name (e.g. "tap_shortcut")
- * - arg [in] : This argument should be specified to the argument of API. And this argument expects JSON object
- *
- * #### Return
- * - Returns 0 on success or -1 in case of error.
- *
- * #### Note
- * To call HomeScreen's APIs, the application should set its function name, arguments to JSON format.
- *
- */
-int LibHomeScreen::call(const string& verb, struct json_object* arg)
-{
- int ret;
- if(!sp_websock)
- {
- return -1;
- }
- if (!has_verb(verb))
- {
- ELOG("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());
- }
- return ret;
-}
-
-/**
- * This function calls the API of HomeScreen via WebSocket
- * This function is overload function of "call"
- *
- * #### Parameters
- * - verb [in] : This argument should be specified to the API name (e.g. "tap_shortcut")
- * - arg [in] : This argument should be specified to the argument of API. And this argument expects JSON object
- *
- * #### Return
- * - Returns 0 on success or -1 in case of error.
- *
- * #### Note
- * To call HomeScreen's APIs, the application should set its function name, arguments to JSON format.
- *
- */
-int LibHomeScreen::call(const char* verb, struct json_object* arg)
-{
- int ret;
- if(!sp_websock)
- {
- return -1;
- }
- if (!has_verb(string(verb)))
- {
- ELOG("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);
- }
- return ret;
-}
-
-/**
- * Register callback function for each event
- *
- * #### Parameters
- * - event_name [in] : This argument should be specified to the event name
- *
- * #### Return
- * - Returns 0 on success or -1 in case of error.
- *
- * #### Note
- * This function enables to get an event to your callback function.
- *
- */
-int LibHomeScreen::subscribe(const string& event_name)
-{
- if(!sp_websock)
- {
- return -1;
- }
- struct json_object* j_obj = json_object_new_object();
- json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
-
- 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__);
- }
- return ret;
-}
-
-/**
- * Unregister callback function for each event
- *
- * #### Parameters
- * - event_name [in] : This argument should be specified to the event name
- *
- * #### Return
- * - Returns 0 on success or -1 in case of error.
- *
- * #### Note
- * This function disables to get an event to your callback function.
- *
- */
-int LibHomeScreen::unsubscribe(const string& event_name)
-{
- if(!sp_websock)
- {
- return -1;
- }
- struct json_object* j_obj = json_object_new_object();
- json_object_object_add(j_obj, "event", json_object_new_string(event_name.c_str()));
-
- 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__);
- }
- return ret;
-}
-
-/************* Callback Function *************/
-
-void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj)
-{
- DLOG("%s called", __FUNCTION__);
- if(onHangup != nullptr)
- {
- onHangup();
- }
-}
-
-void LibHomeScreen::on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
-{
-}
-
-/*
-* event is like "homescreen/tap_shortcut"
-* msg is like {"event":"homescreen\/tap_shortcut","data":{"application_name":"hoge"},"jtype":"afb-event"}
-* so you can get
- event name : struct json_object obj = json_object_object_get(msg,"event")
-*/
-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;
-
- if (strstr(event, API) == NULL) {
- return;
- }
-
- struct json_object* ev_contents = afb_wsj1_msg_object_j(msg);
- struct json_object *json_data = json_object_object_get(ev_contents, "data");
-
- if(onEvent != nullptr)
- {
- const string ev(event);
- onEvent(ev, ev_contents);
- }
-
- const char* event_only = strchr(event, '/');
- if (event_only != nullptr) {
- event_only = event_only + 1;
- }
-
- if (strcasecmp(event_only, LibHomeScreen::event_list[0].c_str()) == 0) {
- auto i = this->handlers.find(Event_TapShortcut);
-
- struct json_object *json_application_name = json_object_object_get(json_data, "application_name");
- const char* application_name = json_object_get_string(json_application_name);
-
- if ( i != this->handlers.end() ) {
- i->second(application_name);
- }
- }
- else if (strcasecmp(event_only, LibHomeScreen::event_list[1].c_str()) == 0) {
-
- auto i = this->handlers.find(Event_OnScreenMessage);
-
- struct json_object *json_display_message = json_object_object_get(json_data, "display_message");
- const char* display_message = json_object_get_string(json_display_message);
-
- if ( i != this->handlers.end() ) {
- i->second(display_message);
- }
-
- }
-
- json_object_put(ev_contents);
-}
-
-/**
- * msg is like ({"response":{"verb":"subscribe","error":0},"jtype":"afb-reply","request":{"status":"success","info":"homescreen binder subscribe event name [on_screen_message]"}})
- * msg is like ({"response":{"verb":"tap_shortcut","error":0},"jtype":"afb-reply","request":{"status":"success","info":"afb_event_push event [tap_shortcut]"}})
- */
-void LibHomeScreen::on_reply(void *closure, struct afb_wsj1_msg *msg)
-{
- cout << "[libhomescreen on_reply]: " << " (" << afb_wsj1_msg_object_s(msg) << ")" << endl;
- if(onReply != nullptr)
- {
- struct json_object* reply = afb_wsj1_msg_object_j(msg);
- onReply(reply);
-
- json_object_put(reply);
- }
-}
-
-/* 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());
- if(find(LibHomeScreen::api_list.begin(), LibHomeScreen::api_list.end(), verb) != LibHomeScreen::api_list.end())
- return true;
- else
- return false;
-}
diff --git a/libhomescreen/test.cpp b/libhomescreen/test.cpp
deleted file mode 100644
index 1a61616..0000000
--- a/libhomescreen/test.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <libhomescreen.hpp>
-#include <iostream>
-#include <glib-2.0/glib.h>
-#include <fcntl.h>
-#include <string>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <thread>
-#include <exception>
-#include <vector>
-#include <sstream>
-#include <functional>
-
-using namespace std;
-
-static vector<string> split(const string& str, char sep);
-LibHomeScreen* hs;
-
-static void usage()
-{
- cout << "verb "<< "key:arg" << endl;
- cout << "example:" << endl;
- cout << "ping" << endl;
- cout << "------- -------- --- " << endl;
- cout << " verb key value" << endl;
- cout << "verb list:" << endl;
- for(auto itr = LibHomeScreen::api_list.begin(); itr != LibHomeScreen::api_list.end(); ++itr)
- {
- cout << " " << *itr << endl;
- }
- // Todo output api list
- exit(0);
-}
-
-static void call_test()
-{
- string command;
-
- cout << "input verb and argments" << endl;
-
- /* read the buffer */
- for(;;){
- char line[1023];
- cin.getline(line, sizeof(line));
- command = line;
- if(command.empty()){
- continue;
- }
-
- vector<string> v_command = split(command, ' ');
- /*for(auto itr = v_command.begin(); itr != v_command.end(); ++itr)
- {
- cout << *itr <<endl;
- }*/
- size_t num = v_command.size();
- if(num % 2 == 0){
- cout << "If command contains args, please input <key,value> in argument part" << endl;
- continue;
- }
- /* create json object */
- struct json_object* j_obj = json_object_new_object();
- for(int i = 1;i < (v_command.size()) ;++i){
- struct json_object* val = json_object_new_string(v_command[i+1].c_str());
- json_object_object_add(j_obj, v_command[i].c_str(), val);
- ++i;
- }
- /* call verb via LibHomeScreen */
- hs->call(v_command[0], j_obj);
- /* free vector */
- vector<string>().swap(v_command);
- string().swap(command);
- }
-}
-
-static void onRep(struct json_object* reply_contents)
-{
- const char* str = json_object_to_json_string(reply_contents);
- cout << "test.cpp [CB onRep]: " << str << endl;
- //json_object_put(reply_contents); do not release!!!
-}
-
-static void onEv(const string& event, struct json_object* event_contents)
-{
- const char* str = json_object_to_json_string(event_contents);
- cout << "test.cpp [CB onEvent]: event: " << event.c_str() << " contents: " << str << endl;
- //json_object_put(event_contents); do not release!!!
-}
-
-static vector<string> split(const string& str, char sep)
-{
- vector<string> v;
- stringstream ss(str);
- string buffer;
- while( getline(ss, buffer, sep) ) {
- if(!buffer.empty())
- v.push_back(buffer);
- }
- return v;
-}
-
-int main(int argc, char **argv)
-{
- int ret;
- if(argc == 1)
- {
- printf("Please input port num in first argument, and token in second argument");
- usage();
- return 0;
- }
- if(argc == 2)
- {
- string av(argv[1]);
- if( (av == "-h") || (av == "--help"))
- {
- usage();
- return 0;
- }
- }
-
- string port_string(argv[1]);
- string token(argv[2]);
- char* endptr;
- long port = strtol(port_string.c_str(),&endptr,10);
-
- /* error check of range */
- if( (port > 20000) || (port < 0) )
- {
- printf("input under 20000(temporary number)");
- return 0;
- }
- if(*endptr != '\0')
- {
- printf("not number");
- return 0;
- }
-
- cout << "Call test for LibHomeScreen" << endl;
- hs = new LibHomeScreen();
- hs->init(port, token);
-
- // hs->registerCallback(&onEv, &onRep);
- //
- // hs->subscribe(event_list[0]); // tap_shortcut event subscribe
- // hs->subscribe(event_list[1]);
-
- hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](const char* application_name){
- cout << "set_event_handler Event_TapShortcut application_name = " << application_name << endl;
- });
-
- hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [](const char* display_message){
- cout << "set_event_handler Event_OnScreenMessage display_message = " << display_message << endl;
- });
-
-
- if (ret < 0) {
- printf("failed to create event loop");
- return -1;
- }
-
- call_test();
-
- return 0;
-}