aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt42
-rw-r--r--LICENSE (renamed from interfaces/LICENSE)0
-rw-r--r--README.md30
-rw-r--r--include/CMakeLists.txt (renamed from libhomescreen.pro)15
-rw-r--r--include/libhomescreen.hpp95
-rw-r--r--interfaces/README.md11
-rw-r--r--interfaces/homescreen.xml106
-rw-r--r--libhomescreen.pc.in12
-rw-r--r--libhomescreen/LICENSE54
-rw-r--r--libhomescreen/include/libhomescreen.hpp36
-rw-r--r--libhomescreen/libhomescreen.pro47
-rw-r--r--libhomescreen/src/libhomescreen.cpp160
-rw-r--r--samplehomescreeninterfaceapp/samplehomescreeninterfaceapp.pro13
-rw-r--r--samplehomescreeninterfaceapp/src/main.cpp31
-rw-r--r--samplehomescreeninterfaceapp/src/sampleclass.cpp42
-rw-r--r--samplehomescreeninterfaceapp/src/sampleclass.hpp24
-rw-r--r--src/CMakeLists.txt48
-rw-r--r--src/libhomescreen.cpp566
18 files changed, 779 insertions, 553 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..d6fba10
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+
+project(libhomescreen C CXX)
+
+cmake_minimum_required(VERSION 2.8)
+
+set(PROJECT_NAME "LIBHOMESCREEN")
+set(PROJECT_VERSION "1.0")
+set(PROJECT_PRETTY_NAME "LIBHOMESCREEN")
+set(PROJECT_DESCRIPTION "Library for accessing agl service homescreen 2017 with C/C++")
+set(PROJECT_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
+set(PROJECT_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
+set(LIBHOMESCREEN_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
+
+# get pkgconfig
+INCLUDE(FindPkgConfig)
+link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
+
+set(CMAKE_BUILD_TYPE Debug)
+set(USE_HMI_DEBUG FALSE)
+
+add_subdirectory(src)
+
+#generate configure file
+configure_file(libhomescreen.pc.in libhomescreen.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libhomescreen.pc
+ DESTINATION
+ ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
diff --git a/interfaces/LICENSE b/LICENSE
index 31c692a..31c692a 100644
--- a/interfaces/LICENSE
+++ b/LICENSE
diff --git a/README.md b/README.md
index 8d1290a..24e5e56 100644
--- a/README.md
+++ b/README.md
@@ -3,13 +3,10 @@ This project contains:
libhomescreen: HomeScreen API C++ shared library
AGL repo for source code:
-https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2FHomeScreen.git
+https://gerrit.automotivelinux.org/gerrit/p/src/libhomescreen.git
AGL repo for bitbake recipe:
-https://gerrit.automotivelinux.org/gerrit/gitweb?p=AGL/meta-agl-demo.git;a=blob;f=recipes-demo-hmi/homescreen/homescreen_git.bb
-
-
-
+https://gerrit.automotivelinux.org/gerrit/gitweb?p=AGL/meta-agl-devel.git;a=blob;f=recipes-demo-hmi/libhomescreen/libhomescreen_git.bb
Quickstart:
@@ -17,23 +14,16 @@ Instructions for building libhomescreen
---------------------------------------
The libhomescreen is part of the
-packagegroup-agl-demo-platform
+packagegroup-hmi-framework
packagegroup.
This also includes the following apps:
-- HomeScreenAppFrameworkBinderAGL
-- InputEventManager
-- SampleAppTimeDate
-- SampleHomeScreenInterfaceApp
-- WindowManager
-
-
-
-
+- agl-service-windowmanager-2017
+- agl-service-soundmanager-2017
+- agl-service-homescreen-2017
+- homescreen-2017
+- onscreenapp-2017
To build all the above, follow the instrucions on the AGL
-documentation website:
-http://docs.automotivelinux.org/docs/getting_started/en/dev/reference/source-code.html#features-supported-by-aglsetup
-
-Please activate the "agl-demo" feature when running the aglsetup script:
-http://docs.automotivelinux.org/docs/getting_started/en/dev/reference/source-code.html#features-supported-by-aglsetup
+source meta-agl/scripts/aglsetup.sh -m m3ulcb agl-demo agl-devel agl-appfw-smack agl-hmi-framework
+bitbake agl-demo-platform
diff --git a/libhomescreen.pro b/include/CMakeLists.txt
index 1139864..bb37242 100644
--- a/libhomescreen.pro
+++ b/include/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
+#
+# 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.
@@ -11,12 +12,8 @@
# 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.
+#
-TEMPLATE = subdirs
-
-load(configure)
-
-SUBDIRS = libhomescreen \
- samplehomescreeninterfaceapp
-
-samplehomescreeninterfaceapp.depends = libhomescreen
+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
new file mode 100644
index 0000000..06e9ad8
--- /dev/null
+++ b/include/libhomescreen.hpp
@@ -0,0 +1,95 @@
+/*
+ * 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/interfaces/README.md b/interfaces/README.md
deleted file mode 100644
index 15dfaa9..0000000
--- a/interfaces/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-AGL Home Screen reference implementation
-This lib provides the needed D-Bus interfaces
-
-Build with QtCreator 3.0.1
-
-AGL repo for source code:
-https://gerrit.automotivelinux.org/gerrit/#/admin/projects/staging/HomeScreen
-
-AGL repo for bitbake recipe:
-https://gerrit.automotivelinux.org/gerrit/#/admin/projects/AGL/meta-agl-demo/recipes-demo-hmi/HomeScreen/HomeScreen_?.bb
-
diff --git a/interfaces/homescreen.xml b/interfaces/homescreen.xml
deleted file mode 100644
index 378ff54..0000000
--- a/interfaces/homescreen.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<!-- Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
-
- 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. -->
-<node>
-<!--
- org.agl.homescreen:
- @short_description: A generic interface for the HomeScreen app.
-
- This interface is a collection of methods from different functional areas to control the HomeScreen app.
--->
- <interface name="org.agl.homescreen">
- <!--
- hardKeyPressed:
- @key: The key that was pressed using the inputevent.hpp InputEvent::HardKey type.
-
- This is used to inject hard keys into the HomeScreen app.
- -->
- <method name="hardKeyPressed">
- <arg name="key" type="i" direction="in"/>
- </method>
- <!--
- getSurfaceStatus:
- @surfaceId: The given surface.
- @status: The status can be unknown (-1), visible (0), invisible (1)
-
- A surface can have three states. It can be visible, then it is shown on the screen.
- It can be invisible, then it is not shown on the screen. Or the state is unknown.
- -->
- <method name="getSurfaceStatus">
- <arg name="surfaceId" type="i" direction="in"/>
- <arg name="status" type="i" direction="out"/>
- </method>
- <!--
- requestSurfaceIdToFullScreen:
- @surfaceId: The surface that request to be shown fullscreen.
-
- This allows an application to set a surface to full screen.
- -->
- <method name="requestSurfaceIdToFullScreen">
- <arg name="surfaceId" type="i" direction="in"/>
- </method>
- <!--
- getAllSurfacesOfProcess:
- @pid: The PID of the process.
- @surfaceIds: A list of surfaces that were created by the process.
-
- The surface IDs can for example be used to assign them to a layout render area.
- -->
- <method name="getAllSurfacesOfProcess">
- <arg name="pid" type="i" direction="in"/>
- <arg name="surfaceIds" type="ai" direction="out"/>
- <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList&lt;int&gt;"/>
- </method>
- <!--
- renderAppToAreaAllowed:
- @appCategory: The application category that is requested. Use enum AppCategory for this!
- @layoutArea: The layout area where the application shall be rendered. Find the layoutArea ids in the layout definition!
- @allowed: Returns true, if the application is allowed to be rendered in the area
-
- This function can be used to request, if it is allowed to render an application of a specific category
- in a layout area. The idea is to decide from an application point of view to allocate recources or not.
- Example: an application will decide to render video based on this call. This call will not change anything, it is only a request.
- -->
- <method name="renderAppToAreaAllowed">
- <arg name="appCategory" type="i" direction="in"/>
- <arg name="layoutArea" type="i" direction="in"/>
- <arg name="allowed" type="b" direction="out"/>
- </method>
- <!--
- renderSurfaceToArea:
- @surfaceId: The surface that is requested.
- @layoutArea: The layout area where the surface shall be rendered. Find the layoutArea ids in the layout definition!
-
- This is a special case. In the normal use case, one layout area is always filled completely
- with the first surface, that the process creates (more precise: the surface with the lowest id).
- By using this function, an app can request to position a different surface in the layout area.
- -->
- <method name="renderSurfaceToArea">
- <arg name="surfaceId" type="i" direction="in"/>
- <arg name="layoutArea" type="i" direction="in"/>
- </method>
- <!--
- surfaceVisibilityChanged:
- @surfaceId: The surface that changed.
- @visible: True, if the surface is visible.
-
- This is emitted when the visible property of the surfaces changes.
- -->
- <signal name="surfaceVisibilityChanged">
- <arg name="surfaceId" type="i"/>
- <arg name="visible" type="b"/>
- </signal>
- </interface>
-</node>
-
diff --git a/libhomescreen.pc.in b/libhomescreen.pc.in
new file mode 100644
index 0000000..809abbd
--- /dev/null
+++ b/libhomescreen.pc.in
@@ -0,0 +1,12 @@
+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/libhomescreen/LICENSE b/libhomescreen/LICENSE
deleted file mode 100644
index 31c692a..0000000
--- a/libhomescreen/LICENSE
+++ /dev/null
@@ -1,54 +0,0 @@
-Apache License
-
-Version 2.0, January 2004
-
-http://www.apache.org/licenses/
-
-TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-1. Definitions.
-
-"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
-
-"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
-
-"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
-
-"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
-
-"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
-
-"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
-
-"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
-
-"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
-
-"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
-
-"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
-
-2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
-
-3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
-
-4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
-
- You must give any other recipients of the Work or Derivative Works a copy of this License; and
- You must cause any modified files to carry prominent notices stating that You changed the files; and
- You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
- If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
-
- You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
-
-5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
-
-6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
-
-7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
-
-8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
-
-9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
-
-END OF TERMS AND CONDITIONS
diff --git a/libhomescreen/include/libhomescreen.hpp b/libhomescreen/include/libhomescreen.hpp
deleted file mode 100644
index 6baa805..0000000
--- a/libhomescreen/include/libhomescreen.hpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef LIBHOMESCREEN_HPP
-#define LIBHOMESCREEN_HPP
-
-#include <vector>
-
-// forward declarations
-struct _LibHomeScreenHomescreen;
-typedef struct _LibHomeScreenHomescreen LibHomeScreenHomescreen;
-
-typedef struct
-{
- int x;
- int y;
- int width;
- int height;
-} sRectangle;
-
-class LibHomeScreen
-{
-public:
- LibHomeScreen();
- ~LibHomeScreen();
-
- // these are representing the D-Bus methods:
- std::vector<int> getAllSurfacesOfProcess(int pid);
- int getSurfaceStatus(int surfaceId);
- void hardKeyPressed(int key);
- void renderSurfaceToArea(int surfaceId, int layoutArea);
- bool renderAppToAreaAllowed(int appCategory, int layoutArea);
- void requestSurfaceIdToFullScreen(int surfaceId);
-private:
- LibHomeScreenHomescreen *mp_libHomeScreenHomescreen_Proxy;
-};
-
-#endif // LIBHOMESCREEN_HPP
-
diff --git a/libhomescreen/libhomescreen.pro b/libhomescreen/libhomescreen.pro
deleted file mode 100644
index f7cae8e..0000000
--- a/libhomescreen/libhomescreen.pro
+++ /dev/null
@@ -1,47 +0,0 @@
-TEMPLATE = lib
-TARGET = homescreen
-CONFIG -= qt
-
-SOURCES += \
- src/libhomescreen.cpp
-
-HEADERS += \
- include/libhomescreen.hpp
-
-CONFIG += link_pkgconfig
-PKGCONFIG += glib-2.0 gio-unix-2.0
-
-XMLSOURCES = \
- ../interfaces/homescreen.xml
-
-gen_proxy_skeleton_h.input = XMLSOURCES
-gen_proxy_skeleton_h.commands = \
- gdbus-codegen --generate-c-code ${QMAKE_FILE_IN_BASE} --c-namespace LibHomeScreen --interface-prefix org.agl. ${QMAKE_FILE_IN}
-gen_proxy_skeleton_h.output = ${QMAKE_FILE_IN_BASE}.h
-gen_proxy_skeleton_h.variable_out = HEADERS
-gen_proxy_skeleton_h.clean = ${QMAKE_FILE_IN_BASE}.h
-
-gen_proxy_skeleton_c.input = XMLSOURCES
-gen_proxy_skeleton_c.commands = \
- gdbus-codegen --generate-c-code ${QMAKE_FILE_IN_BASE} --c-namespace LibHomeScreen --interface-prefix org.agl. ${QMAKE_FILE_IN}
-gen_proxy_skeleton_c.output = ${QMAKE_FILE_IN_BASE}.c
-gen_proxy_skeleton_c.variable_out = SOURCES
-gen_proxy_skeleton_c.clean = ${QMAKE_FILE_IN_BASE}.c
-
-QMAKE_EXTRA_COMPILERS += gen_proxy_skeleton_h gen_proxy_skeleton_c
-
-
-gen_docbook.target = doc
-gen_docbook.commands = \
- gdbus-codegen --generate-docbook doc $$PWD/../interfaces/homescreen.xml
-
-QMAKE_EXTRA_TARGETS += gen_docbook
-PRE_TARGETDEPS += doc
-
-CONFIG += create_pc create_prl
-QMAKE_PKGCONFIG_NAME = libhomescreen
-QMAKE_PKGCONFIG_DESCRIPTION = A generic interface for the HomeScreen app
-QMAKE_PKGCONFIG_LIBDIR = /usr/lib64
-QMAKE_PKGCONFIG_INCDIR = /usr/include
-QMAKE_PKGCONFIG_REQUIRES = glib-2.0 gio-unix-2.0
-QMAKE_PKGCONFIG_DESTDIR = pkgconfig
diff --git a/libhomescreen/src/libhomescreen.cpp b/libhomescreen/src/libhomescreen.cpp
deleted file mode 100644
index ae8f563..0000000
--- a/libhomescreen/src/libhomescreen.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-extern "C" {
-#include "homescreen.h" // generated from xml
-}
-#include "include/libhomescreen.hpp"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-LibHomeScreen::LibHomeScreen()
-{
- GError *err = NULL;
-
- mp_libHomeScreenHomescreen_Proxy = lib_home_screen_homescreen_proxy_new_for_bus_sync(
- G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.agl.homescreen",
- "/HomeScreen",
- NULL,
- &err);
-
- if (NULL != err)
- {
- fprintf(stderr, "Unable to create proxy: %s\n", err->message);
- }
-}
-
-LibHomeScreen::~LibHomeScreen()
-{
- g_object_unref(mp_libHomeScreenHomescreen_Proxy);
-}
-
-std::vector<int> LibHomeScreen::getAllSurfacesOfProcess(int pid)
-{
- std::vector<int> result;
-
- GError *err = NULL;
-
- GVariant *out_surfaceIds;
-
- lib_home_screen_homescreen_call_get_all_surfaces_of_process_sync(
- mp_libHomeScreenHomescreen_Proxy,
- pid,
- &out_surfaceIds,
- NULL,
- &err);
-
- if (NULL != err)
- {
- fprintf(stderr, "Unable to call getAllSurfacesOfProcess: %s\n", err->message);
- }
-
-
- GVariant *element;
- GVariantIter iter;
- int i;
-
- if (g_variant_iter_init(&iter, out_surfaceIds))
- {
- while ((element = g_variant_iter_next_value(&iter)) != NULL)
- {
- g_variant_get(element, "i", &i);
- result.push_back(i);
- g_variant_unref(element);
- }
- }
-
- return result;
-}
-
-int LibHomeScreen::getSurfaceStatus(int surfaceId)
-{
- int result;
- GError *err = NULL;
-
- GVariant *out_renderArea;
-
- lib_home_screen_homescreen_call_get_surface_status_sync(
- mp_libHomeScreenHomescreen_Proxy,
- surfaceId,
- &result,
- NULL,
- &err);
-
- if (NULL != err)
- {
- fprintf(stderr, "Unable to call getSurfaceStatus: %s\n", err->message);
- }
-
- return result;
-}
-
-void LibHomeScreen::hardKeyPressed(int key)
-{
- GError *err = NULL;
-
- lib_home_screen_homescreen_call_hard_key_pressed_sync(
- mp_libHomeScreenHomescreen_Proxy,
- key,
- NULL,
- &err);
-
- if (NULL != err)
- {
- fprintf(stderr, "Unable to call hardKeyPressed: %s\n", err->message);
- }
-}
-
-void LibHomeScreen::renderSurfaceToArea(int surfaceId, int layoutArea)
-{
- GError *err = NULL;
-
- lib_home_screen_homescreen_call_render_surface_to_area_sync(
- mp_libHomeScreenHomescreen_Proxy,
- surfaceId,
- layoutArea,
- NULL,
- &err);
-
- if (NULL != err)
- {
- fprintf(stderr, "Unable to call renderSurfaceToArea: %s\n", err->message);
- }
-}
-
-bool LibHomeScreen::renderAppToAreaAllowed(int appCategory, int layoutArea)
-{
- gboolean result = true;
- GError *err = NULL;
-
- lib_home_screen_homescreen_call_render_app_to_area_allowed_sync(
- mp_libHomeScreenHomescreen_Proxy,
- appCategory,
- layoutArea,
- &result,
- NULL,
- &err);
-
- if (NULL != err)
- {
- fprintf(stderr, "Unable to call renderAppToAreaAllowed: %s\n", err->message);
- }
-
- return result;
-}
-
-void LibHomeScreen::requestSurfaceIdToFullScreen(int surfaceId)
-{
- GError *err = NULL;
-
- lib_home_screen_homescreen_call_request_surface_id_to_full_screen_sync(
- mp_libHomeScreenHomescreen_Proxy,
- surfaceId,
- NULL,
- &err);
-
- if (NULL != err)
- {
- fprintf(stderr, "Unable to call requestSurfaceIdToFullScreen: %s\n", err->message);
- }
-}
diff --git a/samplehomescreeninterfaceapp/samplehomescreeninterfaceapp.pro b/samplehomescreeninterfaceapp/samplehomescreeninterfaceapp.pro
deleted file mode 100644
index 92268a0..0000000
--- a/samplehomescreeninterfaceapp/samplehomescreeninterfaceapp.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-TEMPLATE = app
-TARGET = SampleHomeScreenInterfaceApp
-CONFIG -= qt
-
-SOURCES += src/main.cpp \
- src/sampleclass.cpp
-
-HEADERS += \
- src/sampleclass.hpp
-
-INCLUDEPATH += $$PWD/../libhomescreen/include/
-
-LIBS += -L$$OUT_PWD/../libhomescreen -lhomescreen
diff --git a/samplehomescreeninterfaceapp/src/main.cpp b/samplehomescreeninterfaceapp/src/main.cpp
deleted file mode 100644
index 5b48855..0000000
--- a/samplehomescreeninterfaceapp/src/main.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <iostream>
-#include "sampleclass.hpp"
-
-using namespace std;
-
-int main()
-{
- cout << "SampleHomeScreenInterfaceApp" << endl;
- cout << "v0.6.0" << endl;
-
- SampleClass *sampleClass = new SampleClass();
-
- //sRectangle test = sampleClass->getLayoutRenderAreaForSurfaceId(1);
-
- sampleClass->hardKeyPressed(100);
- sampleClass->hardKeyPressed(101);
- sampleClass->hardKeyPressed(102);
-
- /*sRectangle renderArea;
- renderArea.x = 0;
- renderArea.y = 1;
- renderArea.width = 12;
- renderArea.height = 13;
- sampleClass->renderSurfaceToArea(1, renderArea);*/
-
- //sampleClass->requestSurfaceIdToFullScreen(1);
-
- delete sampleClass;
-
- return 0;
-}
diff --git a/samplehomescreeninterfaceapp/src/sampleclass.cpp b/samplehomescreeninterfaceapp/src/sampleclass.cpp
deleted file mode 100644
index a5e1fac..0000000
--- a/samplehomescreeninterfaceapp/src/sampleclass.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-#include "sampleclass.hpp"
-
-SampleClass::SampleClass() :
- mp_libHomeScreen(0)
-{
- mp_libHomeScreen = new LibHomeScreen();
-}
-
-SampleClass::~SampleClass()
-{
- delete mp_libHomeScreen;
-}
-
-std::vector<int> SampleClass::getAllSurfacesOfProcess(int pid)
-{
- return mp_libHomeScreen->getAllSurfacesOfProcess(pid);
-}
-
-void SampleClass::hardKeyPressed(int key)
-{
- mp_libHomeScreen->hardKeyPressed(key);
-}
-
-int SampleClass::getSurfaceStatus(int surfaceId)
-{
- return mp_libHomeScreen->getSurfaceStatus(surfaceId);
-}
-
-void SampleClass::renderSurfaceToArea(int surfaceId, int layoutArea)
-{
- mp_libHomeScreen->renderSurfaceToArea(surfaceId, layoutArea);
-}
-
-bool SampleClass::renderAppToAreaAllowed(int appCategory, int layoutArea)
-{
- return mp_libHomeScreen->renderAppToAreaAllowed(appCategory, layoutArea);
-}
-
-void SampleClass::requestSurfaceIdToFullScreen(int surfaceId)
-{
- mp_libHomeScreen->requestSurfaceIdToFullScreen(surfaceId);
-}
diff --git a/samplehomescreeninterfaceapp/src/sampleclass.hpp b/samplehomescreeninterfaceapp/src/sampleclass.hpp
deleted file mode 100644
index fd00afe..0000000
--- a/samplehomescreeninterfaceapp/src/sampleclass.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef SAMPLECLASS_HPP
-#define SAMPLECLASS_HPP
-
-#include "libhomescreen.hpp"
-#include <vector>
-
-class SampleClass
-{
-public:
- SampleClass();
- ~SampleClass();
-
- std::vector<int> getAllSurfacesOfProcess(int pid);
- int getSurfaceStatus(int surfaceId);
- void hardKeyPressed(int key);
- void renderSurfaceToArea(int surfaceId, int layoutArea);
- bool renderAppToAreaAllowed(int appCategory, int layoutArea);
- void requestSurfaceIdToFullScreen(int surfaceId);
-
-private:
- LibHomeScreen *mp_libHomeScreen;
-};
-
-#endif // SAMPLECLASS_HPP
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..babf49d
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,48 @@
+#
+# 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_LIBHOMESCREEN homescreen)
+add_definitions("-std=c++11")
+
+pkg_check_modules(libhomescreen_depends json-c libafbwsc libsystemd)
+set(libhomescreen_sources libhomescreen.cpp)
+
+include_directories(${LIBHOMESCREEN_INCLUDE_DIR})
+link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
+
+add_library(${TARGET_LIBHOMESCREEN} SHARED ${libhomescreen_sources})
+target_compile_options(${TARGET_LIBHOMESCREEN} PUBLIC ${libhomescreen_depends_CFLAGS})
+
+if(DEFINED DEBUGMODE)
+ target_compile_options(${TARGET_LIBHOMESCREEN} PRIVATE -g -O0)
+else(DEFINED DEBUGMODE)
+ target_compile_options(${TARGET_LIBHOMESCREEN} PRIVATE -g -O2)
+endif(DEFINED DEBUGMODE)
+
+include_directories(${TARGET_LIBHOMESCREEN} ${libhomescreen_depends_INCLUDE_DIRS})
+target_link_libraries(${TARGET_LIBHOMESCREEN} afbwsc -lpthread ${link_libraries} ${libhomescreen_depends_LIBRARIES})
+set_target_properties(${TARGET_LIBHOMESCREEN}
+ PROPERTIES
+ VERSION 0.1
+)
+
+if(DEFINED CMAKE_INSTALL_LIBDIR)
+ INSTALL(TARGETS ${TARGET_LIBHOMESCREEN}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif(DEFINED CMAKE_INSTALL_LIBDIR)
diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp
new file mode 100644
index 0000000..ef73cbc
--- /dev/null
+++ b/src/libhomescreen.cpp
@@ -0,0 +1,566 @@
+/*
+ * 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;
+ }
+}
+
+/**
+ * ショートカットアイコンがタップされたイベントの発行
+ *
+ * HomeScreenアプリケーションにて各アプリアイコンがタップされたときにイベントを発行する
+ *
+ * #### Parameters
+ * - application_name [in] : タップされたアプリケーションの名前(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;
+}