summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitreview5
-rw-r--r--CMakeLists.txt43
-rw-r--r--LICENSE54
-rw-r--r--README.md6
-rw-r--r--include/CMakeLists.txt19
-rw-r--r--include/hmi-debug.h82
-rw-r--r--include/libcloudproxy.h74
-rw-r--r--libcloudproxy.pc.in12
-rwxr-xr-xsample/README.md98
-rwxr-xr-xsample/telemetry-cloud-app/app/TelemetryWorker.cpp116
-rwxr-xr-xsample/telemetry-cloud-app/app/TelemetryWorker.h48
-rwxr-xr-xsample/telemetry-cloud-app/app/app.pri3
-rwxr-xr-xsample/telemetry-cloud-app/app/app.pro32
-rwxr-xr-xsample/telemetry-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.pngbin0 -> 698586 bytes
-rwxr-xr-xsample/telemetry-cloud-app/app/images/images.qrc5
-rwxr-xr-xsample/telemetry-cloud-app/app/main.cpp92
-rwxr-xr-xsample/telemetry-cloud-app/app/mainwindow.cpp100
-rwxr-xr-xsample/telemetry-cloud-app/app/mainwindow.h52
-rwxr-xr-xsample/telemetry-cloud-app/app/ui_mainwindow.h86
-rwxr-xr-xsample/telemetry-cloud-app/autobuild/agl/autobuild110
-rwxr-xr-xsample/telemetry-cloud-app/autobuild/linux/autobuild110
-rwxr-xr-xsample/telemetry-cloud-app/package/config.xml17
-rwxr-xr-xsample/telemetry-cloud-app/package/icon.svg266
-rwxr-xr-xsample/telemetry-cloud-app/package/package.pro28
-rwxr-xr-xsample/telemetry-cloud-app/telemetrycloudapp.pro3
-rwxr-xr-xsample/test-cloud-app/app/app.pri3
-rwxr-xr-xsample/test-cloud-app/app/app.pro31
-rwxr-xr-xsample/test-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.pngbin0 -> 698586 bytes
-rwxr-xr-xsample/test-cloud-app/app/images/images.qrc5
-rwxr-xr-xsample/test-cloud-app/app/main.cpp119
-rwxr-xr-xsample/test-cloud-app/app/main.cpp.save148
-rwxr-xr-xsample/test-cloud-app/app/mainwindow.cpp83
-rwxr-xr-xsample/test-cloud-app/app/mainwindow.h55
-rwxr-xr-xsample/test-cloud-app/app/ui_mainwindow.h94
-rwxr-xr-xsample/test-cloud-app/autobuild/agl/autobuild110
-rwxr-xr-xsample/test-cloud-app/autobuild/linux/autobuild110
-rwxr-xr-xsample/test-cloud-app/package/config.xml17
-rwxr-xr-xsample/test-cloud-app/package/icon.svg266
-rwxr-xr-xsample/test-cloud-app/package/package.pro28
-rwxr-xr-xsample/test-cloud-app/testcloudapp.pro3
-rw-r--r--src/CMakeLists.txt50
-rw-r--r--src/libcloudproxy.cpp261
42 files changed, 2844 insertions, 0 deletions
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..3161e9a
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=gerrit.automotivelinux.org
+port=29418
+project=src/libcloudproxy
+defaultbranch=master
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..09ae60a
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,43 @@
+#
+# Copyright (C) 2020 Orion Innovation, formerly MERA
+#
+# 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(libcloudproxy C CXX)
+
+cmake_minimum_required(VERSION 2.8)
+
+set(PROJECT_NAME "LIBCLOUDPROXY")
+set(PROJECT_VERSION "1.0")
+set(PROJECT_PRETTY_NAME "LIBCLOUDPROXY")
+set(PROJECT_DESCRIPTION "Library for accessing agl cloud proxy service with C/C++")
+set(PROJECT_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
+set(PROJECT_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
+set(LIBCLOUDPROXY_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)
+add_subdirectory(include)
+
+#generate configure file
+configure_file(libcloudproxy.pc.in libcloudproxy.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcloudproxy.pc
+ DESTINATION
+ ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..31c692a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,54 @@
+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/README.md b/README.md
new file mode 100644
index 0000000..c97e96e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+This project contains:
+
+libcloudproxy: Cloud Proxy Client API C++ shared library
+
+AGL repo for source code:
+https://gerrit.automotivelinux.org/gerrit/src/libcloudproxy.git
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644
index 0000000..45244f5
--- /dev/null
+++ b/include/CMakeLists.txt
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2020 Orion Innovation, formerly MERA
+#
+# 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 libcloudproxy.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+endif(DEFINED CMAKE_INSTALL_INCLUDEDIR)
diff --git a/include/hmi-debug.h b/include/hmi-debug.h
new file mode 100644
index 0000000..c8e8638
--- /dev/null
+++ b/include/hmi-debug.h
@@ -0,0 +1,82 @@
+/*
+ * 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 __HMI_DEBUG_H__
+#define __HMI_DEBUG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <time.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <sys/types.h> // gettid()
+#include <unistd.h>
+#include <sys/syscall.h>
+
+ enum LOG_LEVEL{
+ LOG_LEVEL_NONE = 0,
+ LOG_LEVEL_ERROR,
+ LOG_LEVEL_WARNING,
+ LOG_LEVEL_NOTICE,
+ LOG_LEVEL_INFO,
+ LOG_LEVEL_DEBUG,
+ LOG_LEVEL_MAX = LOG_LEVEL_DEBUG
+ };
+
+#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define HMI_ERROR(prefix, args,...) _HMI_LOG(LOG_LEVEL_ERROR, __FILENAME__, __FUNCTION__, __LINE__, prefix, args, ##__VA_ARGS__)
+#define HMI_WARNING(prefix, args,...) _HMI_LOG(LOG_LEVEL_WARNING, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__)
+#define HMI_NOTICE(prefix, args,...) _HMI_LOG(LOG_LEVEL_NOTICE, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__)
+#define HMI_INFO(prefix, args,...) _HMI_LOG(LOG_LEVEL_INFO, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__)
+#define HMI_DEBUG(prefix, args,...) _HMI_LOG(LOG_LEVEL_DEBUG, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__)
+
+ static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};
+
+ static void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* prefix, const char* log, ...)
+ {
+ //SA: WARN: const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
+ const int log_level = LOG_LEVEL_MAX;
+ if(log_level < level)
+ {
+ return;
+ }
+
+ char *message;
+ struct timespec tp;
+ unsigned int time;
+
+ clock_gettime(CLOCK_REALTIME, &tp);
+ time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
+
+ va_list args;
+ va_start(args, log);
+ if (log == NULL || vasprintf(&message, log, args) < 0)
+ message = NULL;
+ fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] [thread %llx]>>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, (unsigned long long)syscall(__NR_gettid), message);
+ va_end(args);
+ free(message);
+ }
+
+#ifdef __cplusplus
+}
+#endif
+#endif //__HMI_DEBUG_H__
diff --git a/include/libcloudproxy.h b/include/libcloudproxy.h
new file mode 100644
index 0000000..b333a14
--- /dev/null
+++ b/include/libcloudproxy.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <vector>
+#include <map>
+#include <string>
+#include <functional>
+#include <json-c/json.h>
+#include <systemd/sd-event.h>
+
+extern "C"
+{
+#include <afb/afb-wsj1.h>
+#include <afb/afb-ws-client.h>
+}
+
+class CloudProxyClient
+{
+public:
+ using handler_func = std::function<void(json_object*)>;
+
+ enum EventType {
+ Event_Min,
+ Event_SendMessageConfirmation = 1,
+ Event_ReceivedMessage,
+ Event_Max
+ };
+
+
+ CloudProxyClient();
+ ~CloudProxyClient();
+
+ CloudProxyClient(const CloudProxyClient &) = delete;
+ CloudProxyClient &operator=(const CloudProxyClient &) = delete;
+
+ int init(const int port, const std::string& token);
+
+ int sendMessage(const std::string& data);
+
+ void set_event_handler(enum EventType et, handler_func f);
+
+ void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
+
+ int subscribe(const std::string& event_name);
+ int unsubscribe(const std::string& event_name);
+
+private:
+ int call(const std::string& verb, struct json_object* arg);
+
+private:
+ static const std::vector<std::string> m_api_list;
+ static const std::vector<std::string> m_event_list;
+
+ std::map<EventType, handler_func> handlers;
+ struct afb_wsj1_itf m_itf;
+ struct afb_wsj1* m_websock{nullptr};
+ sd_event* m_loop{nullptr};
+ std::string m_uri;
+};
diff --git a/libcloudproxy.pc.in b/libcloudproxy.pc.in
new file mode 100644
index 0000000..9e1481c
--- /dev/null
+++ b/libcloudproxy.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} -lcloudproxy
diff --git a/sample/README.md b/sample/README.md
new file mode 100755
index 0000000..8edaddd
--- /dev/null
+++ b/sample/README.md
@@ -0,0 +1,98 @@
+# Test cloud applications #
+
+## Description
+
+The test-cloud-app and telemetry-cloud-app are examples of an agl-cloudproxy-service client.
+They are used to demonstrate the possibilities of the cloudproxy service.
+
+## Applications
+
+* test-cloud-app: Simple application demonstrating the following possibilities:
+ * Sending the messages to cloud over cloud proxy server
+ * Receiving confirmations from cloud on the sent messages
+ * Receiving messages from cloud
+
+
+* telemetry-cloud-app: Application which sends the GPS coordinates to the cloud
+ * Sending of the messages with telemetry to the cloud
+ * Receiving of the messages from the cloud
+
+Applications use CloudProxy client as high level interface for the messages sending and receiving
+
+## CloudProxy client
+
+CloudProxy client hides the communication with CloudProxy server. It incupsulates the following actions
+
+* Connection to **cloudporxy** over wsj1 websocket
+* Subscription to the event
+* Event loop handling
+
+**Note:** At the moment only two event types are supported
+1. Event_SendMessageConfirmation
+2. Event_ReceivedMessage
+
+### Usage of a Cloudproxy client:
+
+* Include the appropriate header to appliciation
+
+ ```
+ #include "cloudproxy-client/cloudproxyclient.h"
+ ```
+
+* Initialization of the CloudProxy client inside the application:
+
+```
+CloudProxyClient* g_cloudproxyclient{nullptr};
+
+g_cloudproxyclient = new CloudProxyClient();
+g_cloudproxyclient->init(port, token.c_str());
+
+```
+
+### Message handling from/to the CloudProxy server:
+
+
+* Subsription to the Event_SendMessageConfirmation
+
+
+
+```
+g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_SendMessageConfirmation, [](json_object* object){
+ json_object *j_result;
+ if(!json_object_object_get_ex(object, "result", &j_result))
+ {
+ qDebug("Can't read confirmation result");
+ return;
+ }
+
+ qDebug("Confirmation result %d", (int)json_object_get_boolean(j_result));
+ });
+
+ ```
+
+
+
+* Subsription to the Event_SendMessageConfirmation
+
+```
+g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_ReceivedMessage, [](json_object* object)
+ json_object *event_data;
+ const char* data_str{nullptr};
+ if(!json_object_object_get_ex(object, "data", &event_data) ||
+ data_str = json_object_get_string(event_data)) == nullptr)
+ {
+ qDebug("Can't read event data");
+ return;
+ }
+
+ qDebug("Received data: %s", data_str);
+ });
+ ```
+
+
+* Message sending:
+
+
+```
+qDebug() << "sendMessage result: " << g_cloudproxyclient->sendMessage("{\"app_key\": \"app_value1111\"}");
+``` \ No newline at end of file
diff --git a/sample/telemetry-cloud-app/app/TelemetryWorker.cpp b/sample/telemetry-cloud-app/app/TelemetryWorker.cpp
new file mode 100755
index 0000000..c277d2b
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/TelemetryWorker.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 "TelemetryWorker.h"
+#include <QDebug>
+#include <nlohmann/json.hpp>
+#include <time.h>
+#include <stdlib.h>
+
+#include <libcloudproxy.h>
+
+/*
+left up: 56.327 43.981
+right up: 56.327 44.03
+right bottom: 56.3 44.03
+left bottom: 56.3 43.981
+
+start: 56.321674 44.006383
+top: 56.329702 44.021352
+
+diff -0.008028 -0.014969
+coeff lon/lat = 1,8646
+
+
+https://gps-coordinates.org/distance-between-coordinates.php
+*/
+
+
+static double drand(double min, double max)
+{
+ double f = (double)rand() / RAND_MAX;
+ return min + f * (max - min);
+}
+
+
+void TelemetryWorker::send()
+{
+ const double lat_top{56.329702};
+ const double lon_lat_coef{1.8646};
+ const double lat_step{0.001}, lon_step{lat_step*lon_lat_coef};
+
+ if (direction == 0 && lat >= lat_top)
+ {
+ direction = 1;
+ qDebug() << "Change direction to " << direction;
+ }
+ else if (direction == 1 && lat <= init_lat)
+ {
+ direction = 2;
+ qDebug() << "Change direction to " << direction;
+ }
+ else if (direction == 2 && lat <= (init_lat - (lat_top - init_lat)))
+ {
+ direction = 3;
+ qDebug() << "Change direction to " << direction;
+ }
+ else if (direction == 3 && lat >= init_lat)
+ {
+ direction = 0;
+ qDebug() << "Change direction to " << direction;
+ }
+
+
+ if (direction == 0)
+ {
+ lat += lat_step;
+ lon += lon_step;
+ }
+ else if (direction == 1)
+ {
+ lat -= lat_step;
+ lon += lon_step;
+ }
+ else if (direction == 2)
+ {
+ lat -= lat_step;
+ lon -= lon_step;
+ }
+ else if (direction == 3)
+ {
+ lat += lat_step;
+ lon -= lon_step;
+ }
+
+ nlohmann::json jmsg{
+ {"tele_ver", "1.0"},
+ {"lat", lat},
+ {"lon", lon},
+ {"alt", (size_t)(alt + drand(0, 10))},
+ {"speed", (size_t)(speed + drand(20, 30))},
+ {"ts", time(nullptr)}
+ };
+
+ {
+ //WARN: remove
+ const auto& msg{jmsg.dump()};
+ qDebug() << "TelemetryWorker: " << msg.c_str();
+ }
+
+ if (cloudproxyclient)
+ qDebug() << "TelemetryWorker: cloud sendMessage result: " << cloudproxyclient->sendMessage(jmsg.dump());
+
+}
diff --git a/sample/telemetry-cloud-app/app/TelemetryWorker.h b/sample/telemetry-cloud-app/app/TelemetryWorker.h
new file mode 100755
index 0000000..11210cb
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/TelemetryWorker.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <QTimer>
+
+class CloudProxyClient;
+
+class TelemetryWorker : public QTimer
+{
+ Q_OBJECT
+public:
+ TelemetryWorker(CloudProxyClient* cloudproxy, QObject* parent = nullptr)
+ : QTimer(parent),
+ cloudproxyclient{cloudproxy}
+ {
+ }
+
+public slots:
+ void send();
+
+private:
+ CloudProxyClient* cloudproxyclient{nullptr};
+
+ int direction{0};
+ const double init_lat{56.306};
+ const double init_lon{44.070};
+ double lat{init_lat};
+ double lon{init_lon};
+ double alt{300.0};
+ double speed{500.0};
+ uint32_t engine_rpm{3000};
+ int32_t engine_temp{97};
+};
diff --git a/sample/telemetry-cloud-app/app/app.pri b/sample/telemetry-cloud-app/app/app.pri
new file mode 100755
index 0000000..6d710e4
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/app.pri
@@ -0,0 +1,3 @@
+TEMPLATE = app
+QMAKE_LFLAGS += "-Wl,--hash-style=gnu -Wl,--as-needed"
+DESTDIR = $${OUT_PWD}/../package/root/bin
diff --git a/sample/telemetry-cloud-app/app/app.pro b/sample/telemetry-cloud-app/app/app.pro
new file mode 100755
index 0000000..798fa82
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/app.pro
@@ -0,0 +1,32 @@
+TARGET = telemetrycloudapp
+QT += core gui gui-private
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+DEFINES += QT_DEPRECATED_WARNINGS
+
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ TelemetryWorker.cpp
+
+HEADERS += mainwindow.h \
+ ui_mainwindow.h \
+ TelemetryWorker.h
+
+CONFIG += link_pkgconfig
+PKGCONFIG += libhomescreen qtappfw-core libcloudproxy
+
+CONFIG(release, debug|release) {
+ QMAKE_POST_LINK = $(STRIP) --strip-unneeded $(TARGET)
+}
+
+LIBS += -ljson-c -lafbwsc -lsystemd
+
+RESOURCES += \
+ images/images.qrc
+
+include(app.pri)
+
+DISTFILES += \
+ images/AGL_HMI_Blue_Background_NoCar-01.png
+
diff --git a/sample/telemetry-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.png b/sample/telemetry-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.png
new file mode 100755
index 0000000..a76b140
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.png
Binary files differ
diff --git a/sample/telemetry-cloud-app/app/images/images.qrc b/sample/telemetry-cloud-app/app/images/images.qrc
new file mode 100755
index 0000000..78d9b77
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/images/images.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/images">
+ <file>AGL_HMI_Blue_Background_NoCar-01.png</file>
+ </qresource>
+</RCC>
diff --git a/sample/telemetry-cloud-app/app/main.cpp b/sample/telemetry-cloud-app/app/main.cpp
new file mode 100755
index 0000000..ca053ad
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/main.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 <QtCore/QUrlQuery>
+#include <QtGui/QGuiApplication>
+#include <QtCore/QCommandLineParser>
+#include <QScopedPointer>
+
+#include "mainwindow.h"
+#include <QApplication>
+#include <QDebug>
+
+#include <libcloudproxy.h>
+
+
+CloudProxyClient* g_cloudproxyclient{nullptr};
+
+
+int main(int argc, char *argv[])
+{
+ QString graphic_role = QString("telemetrycloud");
+
+ QApplication app(argc, argv);
+ app.setDesktopFileName(graphic_role);
+ QScopedPointer<MainWindow> window;
+
+ QCommandLineParser parser;
+ parser.addPositionalArgument("port", app.translate("main", "port for binding"));
+ parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.process(app);
+ QStringList positionalArguments = parser.positionalArguments();
+
+ if (positionalArguments.length() == 2)
+ {
+ int port = positionalArguments.takeFirst().toInt();
+ QString secret = positionalArguments.takeFirst();
+ QUrl bindingAddress;
+ bindingAddress.setScheme(QStringLiteral("ws"));
+ bindingAddress.setHost(QStringLiteral("localhost"));
+ bindingAddress.setPort(port);
+ bindingAddress.setPath(QStringLiteral("/api"));
+ QUrlQuery query;
+ query.addQueryItem(QStringLiteral("token"), secret);
+ bindingAddress.setQuery(query);
+
+ std::string token = secret.toStdString();
+ window.reset(new MainWindow(1));
+
+ g_cloudproxyclient = new CloudProxyClient();
+ g_cloudproxyclient->init(port, token.c_str());
+
+ g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_ReceivedMessage, [&window](json_object* object){
+ qDebug("CloudProxyClient::Event_ReceivedMessage: object ptr %p", object);
+
+ const char* str = object ? json_object_to_json_string_ext(object, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY) : "<obj_null>";
+ if (!str)
+ str = "<empty>";
+ qDebug("Event_SendMessageConfirmation: %s", str);
+
+ json_object *event_data;
+ const char* data_str{nullptr};
+ if(!json_object_object_get_ex(object, "data", &event_data) ||
+ (data_str = json_object_get_string(event_data)) == nullptr)
+ {
+ qDebug("Can't read event data");
+ return;
+ }
+
+ window->updateState(QString(data_str));
+ qDebug("Application received data: %s", data_str);
+ });
+
+ window->show();
+ }
+
+ return app.exec();
+}
diff --git a/sample/telemetry-cloud-app/app/mainwindow.cpp b/sample/telemetry-cloud-app/app/mainwindow.cpp
new file mode 100755
index 0000000..2e8796c
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/mainwindow.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 "mainwindow.h"
+#include "ui_mainwindow.h"
+#include <QDebug>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <nlohmann/json.hpp>
+
+
+#include <libcloudproxy.h>
+extern CloudProxyClient* g_cloudproxyclient;
+
+
+MainWindow::MainWindow(double scale_factor, QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(scale_factor, this);
+
+ //AGL style
+ setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
+ this->setStyleSheet(
+ "background-image:url(:/images/AGL_HMI_Blue_Background_NoCar-01.png) 0 0 0 0 stretch stretch; background: transparent;" );
+}
+
+void MainWindow::updateState(QVariant recvMsg)
+{
+ if (!recvMsg.isValid())
+ return;
+
+ // expected format: {"message": "bla-bla"}
+ std::string cloud_msg;
+ try
+ {
+ const std::string& msg = recvMsg.toString().toStdString();
+ if (msg.empty())
+ {
+ qDebug() << "Received message is empty";
+ }
+ else
+ {
+ const nlohmann::json& jmsg = nlohmann::json::parse(msg);
+ cloud_msg = jmsg["message"].get<std::string>();
+ }
+ }
+ catch (std::exception& ex)
+ {
+ qDebug() << "Can't parse incomming message: " << ex.what();
+ }
+
+ QString str = QString::asprintf("Cloud info: %s", cloud_msg.c_str());
+ ui->stateLabel->setText(str);
+}
+
+void MainWindow::startMsgButtonClick()
+{
+ qDebug() << "MainWindow::startMsgButtonClick()";
+
+ if (started)
+ ui->startMsgButton->setText("Start");
+ else
+ ui->startMsgButton->setText("Stop");
+ started = !started;
+
+ if (worker)
+ {
+ worker->stop();
+ worker.reset();
+ qDebug() << "Worker destroyed";
+ }
+
+ if (started)
+ {
+ worker.reset(new TelemetryWorker(g_cloudproxyclient, this));
+ connect(worker.get(), SIGNAL(timeout()), worker.get(), SLOT(send()));
+ worker->start(1001);
+ }
+}
+
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
diff --git a/sample/telemetry-cloud-app/app/mainwindow.h b/sample/telemetry-cloud-app/app/mainwindow.h
new file mode 100755
index 0000000..ce21845
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/mainwindow.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QVariant>
+#include <QScopedPointer>
+#include <memory>
+
+#include "TelemetryWorker.h"
+
+
+namespace Ui {
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(double scale_factor, QWidget *parent = 0);
+ ~MainWindow();
+
+public slots:
+ void updateState(QVariant recvMsg);
+
+private slots:
+ void startMsgButtonClick();
+
+private:
+ Ui::MainWindow *ui;
+ bool started{false};
+ QScopedPointer<TelemetryWorker> worker;
+};
+
+#endif // MAINWINDOW_H
diff --git a/sample/telemetry-cloud-app/app/ui_mainwindow.h b/sample/telemetry-cloud-app/app/ui_mainwindow.h
new file mode 100755
index 0000000..5dbcbd5
--- /dev/null
+++ b/sample/telemetry-cloud-app/app/ui_mainwindow.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 UI_MAINWINDOW_H
+#define UI_MAINWINDOW_H
+
+#include <QtCore/QVariant>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QLabel>
+#include <QtWidgets/QMainWindow>
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QLineEdit>
+#include <QtWidgets/QWidget>
+#include <QtWidgets/QFrame>
+#include <QtWidgets/QGroupBox>
+#include <QtWidgets/QRadioButton>
+#include <QtWidgets/QComboBox>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QWidget *centralWidget{nullptr};
+ QPushButton *startMsgButton{nullptr};
+ QLabel *stateLabel{nullptr};
+
+ void setupUi(double scale_factor, QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
+ MainWindow->resize(1080*scale_factor, 1400*scale_factor);
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
+
+ //QString style("color: white; font-size: 24px");
+ QString style("color: white");
+
+ startMsgButton = new QPushButton(centralWidget);
+ startMsgButton->setObjectName(QString::fromUtf8("startMsgButton"));
+ startMsgButton->setGeometry(QRect((540-242/2)*scale_factor, 20*scale_factor, 242*scale_factor, 64*scale_factor));
+ startMsgButton->setStyleSheet(style);
+
+ stateLabel = new QLabel(centralWidget);
+ stateLabel->setObjectName(QString::fromUtf8("label"));
+ stateLabel->setGeometry(QRect(40*scale_factor, 180*scale_factor, 1000*scale_factor, 420*scale_factor));
+ stateLabel->setWordWrap(true);
+ stateLabel->setAlignment(Qt::AlignTop);
+ stateLabel->setStyleSheet(style);
+
+ MainWindow->setCentralWidget(centralWidget);
+
+ QObject::connect(startMsgButton, SIGNAL(clicked()), MainWindow, SLOT(startMsgButtonClick()));
+
+ retranslateUi(MainWindow);
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
+ startMsgButton->setText(QApplication::translate("MainWindow", "Start", nullptr));
+ } // retranslateUi
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_MAINWINDOW_H
diff --git a/sample/telemetry-cloud-app/autobuild/agl/autobuild b/sample/telemetry-cloud-app/autobuild/agl/autobuild
new file mode 100755
index 0000000..bbbc13e
--- /dev/null
+++ b/sample/telemetry-cloud-app/autobuild/agl/autobuild
@@ -0,0 +1,110 @@
+#!/usr/bin/make -f
+# Copyright (C) 2015 - 2018 "IoT.bzh"
+# Copyright (C) 2020 Konsulko Group
+# Author "Romain Forlot" <romain.forlot@iot.bzh>
+#
+# 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.
+
+THISFILE := $(lastword $(MAKEFILE_LIST))
+ROOT_DIR := $(abspath $(dir $(THISFILE))/../..)
+
+# Build directories
+# Note that the debug directory is defined in relation to the release
+# directory (BUILD_DIR), this needs to be kept in mind if over-riding
+# it and building that widget types, the specific widget type variable
+# (e.g. BUILD_DIR_DEBUG) may also need to be specified to yield the
+# desired output hierarchy.
+BUILD_DIR = $(ROOT_DIR)/build
+BUILD_DIR_DEBUG = $(abspath $(BUILD_DIR)/../build-debug)
+
+# Output directory variable for use in pattern rules.
+# This is intended for internal use only, hence the explicit override
+# definition.
+override OUTPUT_DIR = $(BUILD_DIR)
+
+# Final install directory for widgets
+DEST = $(OUTPUT_DIR)
+
+# Default build type for release builds
+BUILD_TYPE = release
+
+.PHONY: all help update install distclean
+.PHONY: clean clean-release clean-debug clean-all
+.PHONY: configure configure-release configure-debug
+.PHONY: build build-release build-debug build-all
+.PHONY: package package-release package-debug package-all
+
+help:
+ @echo "List of targets available:"
+ @echo ""
+ @echo "- all"
+ @echo "- help"
+ @echo "- clean"
+ @echo "- distclean"
+ @echo "- configure"
+ @echo "- build: compilation, link and prepare files for package into a widget"
+ @echo "- package: output a widget file '*.wgt'"
+ @echo "- install: install in $(DEST) directory"
+ @echo ""
+ @echo "Usage: ./autobuild/agl/autobuild package DEST=${HOME}/opt"
+ @echo "Don't use your build dir as DEST as wgt file is generated at this location"
+
+all: package-all
+
+# Target specific variable over-rides so static pattern rules can be
+# used for the various type-specific targets.
+
+configure-debug build-debug package-debug clean-debug: OUTPUT_DIR = $(BUILD_DIR_DEBUG)
+configure-debug build-debug package-debug: BUILD_TYPE = debug
+
+clean-release clean-debug:
+ @if [ -d $(OUTPUT_DIR) ]; then \
+ $(MAKE) -C $(OUTPUT_DIR) $(CLEAN_ARGS) clean; \
+ else \
+ echo Nothing to clean; \
+ fi
+
+clean: clean-release
+
+clean-all: clean-release clean-debug
+
+distclean: clean-all
+
+configure-release configure-debug:
+ @mkdir -p $(OUTPUT_DIR)
+ @if [ ! -f $(OUTPUT_DIR)/Makefile ]; then \
+ (cd $(OUTPUT_DIR) && qmake CONFIG+=$(BUILD_TYPE) $(CONFIGURE_ARGS) $(ROOT_DIR)); \
+ fi
+
+configure: configure-release
+
+build-release build-debug: build-%: configure-%
+ @$(MAKE) -C $(OUTPUT_DIR) $(BUILD_ARGS) all
+
+build: build-release
+
+build-all: build-release build-debug
+
+package-release package-debug: package-%: build-%
+ @cp $(OUTPUT_DIR)/package/*.wgt $(OUTPUT_DIR)/
+ @if [ "$(abspath $(DEST))" != "$(abspath $(OUTPUT_DIR))" ]; then \
+ mkdir -p $(DEST) && cp $(OUTPUT_DIR)/*.wgt $(DEST); \
+ fi
+
+
+package: package-release
+
+package-all: package-release package-debug
+
+install: build
+ @$(MAKE) -C $(BUILD_DIR) $(INSTALL_ARGS) install
diff --git a/sample/telemetry-cloud-app/autobuild/linux/autobuild b/sample/telemetry-cloud-app/autobuild/linux/autobuild
new file mode 100755
index 0000000..bbbc13e
--- /dev/null
+++ b/sample/telemetry-cloud-app/autobuild/linux/autobuild
@@ -0,0 +1,110 @@
+#!/usr/bin/make -f
+# Copyright (C) 2015 - 2018 "IoT.bzh"
+# Copyright (C) 2020 Konsulko Group
+# Author "Romain Forlot" <romain.forlot@iot.bzh>
+#
+# 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.
+
+THISFILE := $(lastword $(MAKEFILE_LIST))
+ROOT_DIR := $(abspath $(dir $(THISFILE))/../..)
+
+# Build directories
+# Note that the debug directory is defined in relation to the release
+# directory (BUILD_DIR), this needs to be kept in mind if over-riding
+# it and building that widget types, the specific widget type variable
+# (e.g. BUILD_DIR_DEBUG) may also need to be specified to yield the
+# desired output hierarchy.
+BUILD_DIR = $(ROOT_DIR)/build
+BUILD_DIR_DEBUG = $(abspath $(BUILD_DIR)/../build-debug)
+
+# Output directory variable for use in pattern rules.
+# This is intended for internal use only, hence the explicit override
+# definition.
+override OUTPUT_DIR = $(BUILD_DIR)
+
+# Final install directory for widgets
+DEST = $(OUTPUT_DIR)
+
+# Default build type for release builds
+BUILD_TYPE = release
+
+.PHONY: all help update install distclean
+.PHONY: clean clean-release clean-debug clean-all
+.PHONY: configure configure-release configure-debug
+.PHONY: build build-release build-debug build-all
+.PHONY: package package-release package-debug package-all
+
+help:
+ @echo "List of targets available:"
+ @echo ""
+ @echo "- all"
+ @echo "- help"
+ @echo "- clean"
+ @echo "- distclean"
+ @echo "- configure"
+ @echo "- build: compilation, link and prepare files for package into a widget"
+ @echo "- package: output a widget file '*.wgt'"
+ @echo "- install: install in $(DEST) directory"
+ @echo ""
+ @echo "Usage: ./autobuild/agl/autobuild package DEST=${HOME}/opt"
+ @echo "Don't use your build dir as DEST as wgt file is generated at this location"
+
+all: package-all
+
+# Target specific variable over-rides so static pattern rules can be
+# used for the various type-specific targets.
+
+configure-debug build-debug package-debug clean-debug: OUTPUT_DIR = $(BUILD_DIR_DEBUG)
+configure-debug build-debug package-debug: BUILD_TYPE = debug
+
+clean-release clean-debug:
+ @if [ -d $(OUTPUT_DIR) ]; then \
+ $(MAKE) -C $(OUTPUT_DIR) $(CLEAN_ARGS) clean; \
+ else \
+ echo Nothing to clean; \
+ fi
+
+clean: clean-release
+
+clean-all: clean-release clean-debug
+
+distclean: clean-all
+
+configure-release configure-debug:
+ @mkdir -p $(OUTPUT_DIR)
+ @if [ ! -f $(OUTPUT_DIR)/Makefile ]; then \
+ (cd $(OUTPUT_DIR) && qmake CONFIG+=$(BUILD_TYPE) $(CONFIGURE_ARGS) $(ROOT_DIR)); \
+ fi
+
+configure: configure-release
+
+build-release build-debug: build-%: configure-%
+ @$(MAKE) -C $(OUTPUT_DIR) $(BUILD_ARGS) all
+
+build: build-release
+
+build-all: build-release build-debug
+
+package-release package-debug: package-%: build-%
+ @cp $(OUTPUT_DIR)/package/*.wgt $(OUTPUT_DIR)/
+ @if [ "$(abspath $(DEST))" != "$(abspath $(OUTPUT_DIR))" ]; then \
+ mkdir -p $(DEST) && cp $(OUTPUT_DIR)/*.wgt $(DEST); \
+ fi
+
+
+package: package-release
+
+package-all: package-release package-debug
+
+install: build
+ @$(MAKE) -C $(BUILD_DIR) $(INSTALL_ARGS) install
diff --git a/sample/telemetry-cloud-app/package/config.xml b/sample/telemetry-cloud-app/package/config.xml
new file mode 100755
index 0000000..d1300ab
--- /dev/null
+++ b/sample/telemetry-cloud-app/package/config.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widget xmlns="http://www.w3.org/ns/widgets" id="telemetrycloudapp" version="0.1">
+ <name>CloudTelemetry</name>
+ <icon src="icon.svg"/>
+ <content src="bin/telemetrycloudapp" type="application/vnd.agl.native"/>
+ <description>Test Cloud App</description>
+ <author>Mera</author>
+ <license>APL 2.0</license>
+ <feature name="urn:AGL:widget:required-api">
+ <param name="homescreen" value="ws"/>
+ <param name="cloudproxy" value="ws"/>
+ </feature>
+ <feature name="urn:AGL:widget:required-permission">
+ <param name="urn:AGL:permission::public:no-htdocs" value="required"/>
+ <param name="urn:AGL:permission::public:display" value="required" />
+ </feature>
+</widget>
diff --git a/sample/telemetry-cloud-app/package/icon.svg b/sample/telemetry-cloud-app/package/icon.svg
new file mode 100755
index 0000000..b9b8e67
--- /dev/null
+++ b/sample/telemetry-cloud-app/package/icon.svg
@@ -0,0 +1,266 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Generator: Adobe Illustrator 21.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+
+<svg
+ xmlns:i="&amp;#38;ns_ai;"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.1"
+ x="0px"
+ y="0px"
+ viewBox="0 0 320 320"
+ style="enable-background:new 0 0 320 320;"
+ xml:space="preserve"
+ id="svg2"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="icon.svg"><metadata
+ id="metadata1292"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
+ id="defs1290" /><sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="2560"
+ inkscape:window-height="1464"
+ id="namedview1288"
+ showgrid="false"
+ inkscape:zoom="4.17193"
+ inkscape:cx="183.76952"
+ inkscape:cy="191.17869"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg2" /><style
+ type="text/css"
+ id="style4">
+ .st0{display:none;}
+ .st1{display:inline;}
+ .st2{opacity:0.4;fill:url(#SVGID_1_);}
+ .st3{fill:url(#SVGID_2_);}
+ .st4{fill:#FFFFFF;}
+ .st5{font-family:'Roboto-Regular';}
+ .st6{font-size:25px;}
+ .st7{letter-spacing:6;}
+ .st8{fill:url(#SVGID_3_);}
+ .st9{fill:url(#SVGID_4_);}
+ .st10{fill:url(#SVGID_5_);}
+ .st11{fill:url(#SVGID_6_);}
+ .st12{fill:url(#SVGID_7_);}
+ .st13{fill:url(#SVGID_8_);}
+ .st14{fill:url(#SVGID_9_);}
+ .st15{fill:url(#SVGID_10_);}
+ .st16{fill:url(#SVGID_11_);}
+ .st17{fill:url(#SVGID_12_);}
+ .st18{fill:url(#SVGID_13_);}
+ .st19{fill:url(#SVGID_14_);}
+ .st20{fill:url(#SVGID_15_);}
+ .st21{fill:url(#SVGID_16_);}
+ .st22{fill:url(#SVGID_17_);}
+ .st23{fill:url(#SVGID_18_);}
+ .st24{opacity:0.29;}
+ .st25{fill:url(#SVGID_19_);}
+ .st26{fill:url(#SVGID_20_);}
+ .st27{fill:url(#SVGID_21_);}
+ .st28{fill:url(#SVGID_22_);}
+ .st29{fill:url(#SVGID_23_);}
+ .st30{fill:url(#SVGID_24_);}
+ .st31{fill:url(#SVGID_25_);}
+ .st32{fill:url(#SVGID_26_);}
+ .st33{fill:url(#SVGID_27_);}
+ .st34{fill:url(#SVGID_28_);}
+ .st35{fill:url(#SVGID_29_);}
+ .st36{fill:url(#SVGID_30_);}
+ .st37{fill:url(#SVGID_31_);}
+ .st38{fill:url(#SVGID_32_);}
+ .st39{fill:url(#SVGID_33_);}
+ .st40{fill:url(#SVGID_34_);}
+ .st41{fill:url(#SVGID_35_);}
+ .st42{fill:url(#SVGID_36_);}
+ .st43{opacity:0.4;fill:url(#SVGID_37_);}
+ .st44{fill:url(#SVGID_38_);}
+ .st45{fill:url(#SVGID_39_);}
+ .st46{fill:url(#SVGID_40_);}
+ .st47{fill:url(#SVGID_41_);}
+ .st48{fill:url(#SVGID_42_);}
+ .st49{fill:url(#SVGID_43_);}
+ .st50{fill:url(#SVGID_44_);}
+ .st51{display:inline;opacity:0.29;}
+ .st52{display:inline;fill:url(#SVGID_45_);}
+ .st53{display:inline;fill:url(#SVGID_46_);}
+ .st54{display:inline;fill:#FFFFFF;}
+ .st55{display:inline;fill:url(#SVGID_47_);}
+ .st56{display:inline;fill:url(#SVGID_48_);}
+ .st57{display:inline;fill:url(#SVGID_49_);}
+ .st58{display:inline;fill:url(#SVGID_50_);}
+ .st59{display:inline;fill:url(#SVGID_51_);}
+ .st60{display:inline;fill:url(#SVGID_52_);}
+ .st61{opacity:0.4;fill:url(#SVGID_53_);}
+ .st62{fill:url(#SVGID_54_);}
+ .st63{fill:url(#SVGID_55_);}
+ .st64{fill:url(#SVGID_56_);}
+ .st65{fill:url(#SVGID_57_);}
+ .st66{fill:url(#SVGID_58_);}
+ .st67{opacity:0.4;fill:url(#SVGID_59_);}
+ .st68{fill:url(#SVGID_60_);}
+ .st69{fill:url(#SVGID_61_);}
+ .st70{fill:url(#SVGID_62_);}
+ .st71{fill:url(#SVGID_63_);}
+ .st72{fill:url(#SVGID_64_);}
+ .st73{fill:url(#SVGID_65_);}
+ .st74{fill:url(#SVGID_66_);}
+ .st75{fill:url(#SVGID_67_);}
+ .st76{fill:url(#SVGID_68_);}
+ .st77{fill:url(#SVGID_69_);}
+ .st78{fill:url(#SVGID_70_);}
+ .st79{fill:url(#SVGID_71_);}
+ .st80{fill:url(#SVGID_72_);}
+ .st81{fill:url(#SVGID_73_);}
+ .st82{fill:url(#SVGID_74_);}
+ .st83{fill:url(#SVGID_75_);}
+ .st84{fill:url(#SVGID_76_);}
+ .st85{fill:url(#SVGID_77_);}
+ .st86{fill:url(#SVGID_78_);}
+ .st87{fill:url(#SVGID_79_);}
+ .st88{fill:url(#SVGID_80_);}
+ .st89{fill:url(#SVGID_81_);}
+ .st90{fill:url(#SVGID_82_);}
+ .st91{fill:url(#SVGID_83_);}
+ .st92{fill:url(#SVGID_84_);}
+ .st93{fill:url(#SVGID_85_);}
+ .st94{fill:url(#SVGID_86_);}
+ .st95{opacity:0.4;fill:url(#SVGID_87_);}
+ .st96{fill:url(#SVGID_88_);}
+ .st97{fill:url(#SVGID_89_);}
+ .st98{fill:url(#SVGID_90_);}
+ .st99{fill:url(#SVGID_91_);}
+ .st100{fill:url(#SVGID_92_);}
+ .st101{fill:url(#SVGID_93_);}
+ .st102{fill:url(#SVGID_94_);}
+ .st103{opacity:0.4;fill:url(#SVGID_95_);}
+ .st104{fill:url(#SVGID_96_);}
+ .st105{fill:url(#SVGID_97_);}
+ .st106{fill:url(#SVGID_98_);}
+ .st107{fill:url(#SVGID_99_);}
+ .st108{fill:url(#SVGID_100_);}
+ .st109{fill:url(#SVGID_101_);}
+ .st110{display:inline;fill:url(#SVGID_102_);}
+ .st111{display:inline;fill:url(#SVGID_103_);}
+ .st112{fill:url(#SVGID_104_);}
+ .st113{fill:url(#SVGID_105_);}
+ .st114{fill:url(#SVGID_106_);}
+ .st115{fill:url(#SVGID_107_);}
+ .st116{fill:url(#SVGID_108_);}
+ .st117{opacity:0.4;fill:url(#SVGID_109_);}
+ .st118{fill:url(#SVGID_110_);}
+ .st119{fill:url(#SVGID_111_);}
+ .st120{fill:url(#SVGID_112_);}
+ .st121{fill:url(#SVGID_113_);}
+ .st122{fill:url(#SVGID_114_);}
+ .st123{opacity:0.4;fill:url(#SVGID_115_);}
+ .st124{fill:url(#SVGID_116_);}
+ .st125{fill:url(#SVGID_117_);}
+ .st126{fill:url(#SVGID_118_);}
+ .st127{display:inline;fill:url(#SVGID_119_);}
+ .st128{display:inline;fill:url(#SVGID_120_);}
+ .st129{fill:url(#SVGID_121_);}
+ .st130{fill:url(#SVGID_122_);}
+</style><switch
+ id="switch6"><g
+ i:extraneous="self"
+ id="g8"><g
+ id="Multimedia_Inactive_copy"><circle
+ class="st24"
+ cx="159.7"
+ cy="133.4"
+ r="101.9"
+ id="circle884" /><linearGradient
+ id="SVGID_91_"
+ gradientUnits="userSpaceOnUse"
+ x1="115.9317"
+ y1="254.1836"
+ x2="256.3852"
+ y2="-133.5267"><stop
+ offset="0"
+ style="stop-color:#8BC53F"
+ id="stop887" /><stop
+ offset="2.015080e-02"
+ style="stop-color:#7CCB56;stop-opacity:0.9678"
+ id="stop889" /><stop
+ offset="6.089833e-02"
+ style="stop-color:#62D67D;stop-opacity:0.9028"
+ id="stop891" /><stop
+ offset="0.1057"
+ style="stop-color:#4BDFA0;stop-opacity:0.8312"
+ id="stop893" /><stop
+ offset="0.1543"
+ style="stop-color:#38E7BE;stop-opacity:0.7537"
+ id="stop895" /><stop
+ offset="0.2077"
+ style="stop-color:#28EED6;stop-opacity:0.6684"
+ id="stop897" /><stop
+ offset="0.2681"
+ style="stop-color:#1CF3E8;stop-opacity:0.572"
+ id="stop899" /><stop
+ offset="0.3394"
+ style="stop-color:#13F6F5;stop-opacity:0.4581"
+ id="stop901" /><stop
+ offset="0.4323"
+ style="stop-color:#0EF8FD;stop-opacity:0.3098"
+ id="stop903" /><stop
+ offset="0.6264"
+ style="stop-color:#0DF9FF;stop-opacity:0"
+ id="stop905" /></linearGradient><circle
+ class="st99"
+ cx="159.7"
+ cy="133.4"
+ r="101.9"
+ id="circle907" /><linearGradient
+ id="SVGID_92_"
+ gradientUnits="userSpaceOnUse"
+ x1="4.0481"
+ y1="287.9492"
+ x2="320.4859"
+ y2="-15.4029"
+ gradientTransform="matrix(1 5.464556e-03 -5.464556e-03 1 -2.0192 -3.0212)"><stop
+ offset="0"
+ style="stop-color:#59FF7F"
+ id="stop910" /><stop
+ offset="1"
+ style="stop-color:#6BFBFF"
+ id="stop912" /></linearGradient><path
+ class="st100"
+ d="M160,238.8c-0.2,0-0.4,0-0.6,0c-58-0.3-104.9-47.7-104.6-105.7C55.2,75.3,102.3,28.5,160,28.5 c0.2,0,0.4,0,0.6,0c58,0.3,104.9,47.7,104.6,105.7l0,0C264.8,192,217.7,238.8,160,238.8z M160,32.2 c-55.7,0-101.2,45.2-101.5,100.9c-0.3,55.9,45,101.7,100.9,102c0.2,0,0.4,0,0.6,0c55.7,0,101.2-45.2,101.5-100.9 c0.3-55.9-45-101.7-100.9-102C160.4,32.2,160.2,32.2,160,32.2z"
+ id="path914" /><g
+ id="g916"><text
+ transform="matrix(1 0 0 1 53.5841 284.7119)"
+ class="st4 st5 st6 st7"
+ id="text918">VIDEOPLAYER
+</text>
+<linearGradient
+ id="SVGID_94_"
+ gradientUnits="userSpaceOnUse"
+ x1="145.3286"
+ y1="203.8951"
+ x2="191.6285"
+ y2="70.3637"><stop
+ offset="0"
+ style="stop-color:#59FF7F"
+ id="stop928" /><stop
+ offset="1"
+ style="stop-color:#6BFBFF"
+ id="stop930" /></linearGradient><polygon
+ class="st102"
+ points="125,75 125,200 225,137.5 "
+ id="polygon932"
+ style="fill:url(#SVGID_94_)" /></g></g></g></switch></svg> \ No newline at end of file
diff --git a/sample/telemetry-cloud-app/package/package.pro b/sample/telemetry-cloud-app/package/package.pro
new file mode 100755
index 0000000..7a138a3
--- /dev/null
+++ b/sample/telemetry-cloud-app/package/package.pro
@@ -0,0 +1,28 @@
+
+DISTFILES = icon.svg config.xml
+
+copy_icon.target = $$OUT_PWD/root/icon.svg
+copy_icon.depends = $$_PRO_FILE_PWD_/icon.svg
+copy_icon.commands = $(COPY_FILE) \"$$replace(copy_icon.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_icon.target, /, $$QMAKE_DIR_SEP)\"
+QMAKE_EXTRA_TARGETS += copy_icon
+PRE_TARGETDEPS += $$copy_icon.target
+
+copy_config.target = $$OUT_PWD/root/config.xml
+copy_config.depends = $$_PRO_FILE_PWD_/config.xml
+copy_config.commands = $(COPY_FILE) \"$$replace(copy_config.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_config.target, /, $$QMAKE_DIR_SEP)\"
+QMAKE_EXTRA_TARGETS += copy_config
+PRE_TARGETDEPS += $$copy_config.target
+
+WGT_TYPE =
+CONFIG(debug, debug|release) {
+ WGT_TYPE = -debug
+}
+
+wgt.target = package
+wgt.commands = wgtpkg-pack -f -o telemetrycloudapp$${WGT_TYPE}.wgt root
+
+QMAKE_EXTRA_TARGETS += wgt
+
+deploy.files = telemetrycloudapp.wgt
+deploy.path = /usr/AGL/apps/autoinstall
+INSTALLS += deploy
diff --git a/sample/telemetry-cloud-app/telemetrycloudapp.pro b/sample/telemetry-cloud-app/telemetrycloudapp.pro
new file mode 100755
index 0000000..579a952
--- /dev/null
+++ b/sample/telemetry-cloud-app/telemetrycloudapp.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = app package
+package.depends += app
diff --git a/sample/test-cloud-app/app/app.pri b/sample/test-cloud-app/app/app.pri
new file mode 100755
index 0000000..6d710e4
--- /dev/null
+++ b/sample/test-cloud-app/app/app.pri
@@ -0,0 +1,3 @@
+TEMPLATE = app
+QMAKE_LFLAGS += "-Wl,--hash-style=gnu -Wl,--as-needed"
+DESTDIR = $${OUT_PWD}/../package/root/bin
diff --git a/sample/test-cloud-app/app/app.pro b/sample/test-cloud-app/app/app.pro
new file mode 100755
index 0000000..9b72850
--- /dev/null
+++ b/sample/test-cloud-app/app/app.pro
@@ -0,0 +1,31 @@
+TARGET = testcloudapp
+QT += core gui gui-private
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+DEFINES += QT_DEPRECATED_WARNINGS
+DEFINES += APP_INSTANCE_NUM='\\"1\\"'
+
+SOURCES = main.cpp \
+ mainwindow.cpp \
+
+HEADERS += mainwindow.h \
+ ui_mainwindow.h \
+
+CONFIG += link_pkgconfig
+PKGCONFIG += libcloudproxy qtappfw-core
+
+CONFIG(release, debug|release) {
+ QMAKE_POST_LINK = $(STRIP) --strip-unneeded $(TARGET)
+}
+
+LIBS += -ljson-c -lafbwsc -lsystemd
+
+RESOURCES += \
+ images/images.qrc
+
+include(app.pri)
+
+DISTFILES += \
+ images/AGL_HMI_Blue_Background_NoCar-01.png
+
diff --git a/sample/test-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.png b/sample/test-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.png
new file mode 100755
index 0000000..a76b140
--- /dev/null
+++ b/sample/test-cloud-app/app/images/AGL_HMI_Blue_Background_NoCar-01.png
Binary files differ
diff --git a/sample/test-cloud-app/app/images/images.qrc b/sample/test-cloud-app/app/images/images.qrc
new file mode 100755
index 0000000..78d9b77
--- /dev/null
+++ b/sample/test-cloud-app/app/images/images.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/images">
+ <file>AGL_HMI_Blue_Background_NoCar-01.png</file>
+ </qresource>
+</RCC>
diff --git a/sample/test-cloud-app/app/main.cpp b/sample/test-cloud-app/app/main.cpp
new file mode 100755
index 0000000..6918e97
--- /dev/null
+++ b/sample/test-cloud-app/app/main.cpp
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 <QtCore/QUrlQuery>
+#include <QtGui/QGuiApplication>
+#include <QtCore/QCommandLineParser>
+#include <QScopedPointer>
+
+#include "mainwindow.h"
+#include <QApplication>
+#include <QDebug>
+
+#include "libcloudproxy.h"
+
+CloudProxyClient* g_cloudproxyclient{nullptr};
+
+
+int main(int argc, char *argv[])
+{
+ QString graphic_role = QString("cloudapp") + QString(APP_INSTANCE_NUM);
+
+ QApplication app(argc, argv);
+ app.setDesktopFileName(graphic_role);
+ QScopedPointer<MainWindow> window;
+
+ QCommandLineParser parser;
+ parser.addPositionalArgument("port", app.translate("main", "port for binding"));
+ parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.process(app);
+ QStringList positionalArguments = parser.positionalArguments();
+
+ if (positionalArguments.length() == 2)
+ {
+ int port = positionalArguments.takeFirst().toInt();
+ QString secret = positionalArguments.takeFirst();
+ QUrl bindingAddress;
+ bindingAddress.setScheme(QStringLiteral("ws"));
+ bindingAddress.setHost(QStringLiteral("localhost"));
+ bindingAddress.setPort(port);
+ bindingAddress.setPath(QStringLiteral("/api"));
+ QUrlQuery query;
+ query.addQueryItem(QStringLiteral("token"), secret);
+ bindingAddress.setQuery(query);
+
+ std::string token = secret.toStdString();
+ window.reset(new MainWindow(1));
+
+ g_cloudproxyclient = new CloudProxyClient();
+ g_cloudproxyclient->init(port, token.c_str());
+
+ static int i_confirm_good{0}, i_confirm_bad{0}, i_recv{0};
+ g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_SendMessageConfirmation, [&window](json_object* object){
+ qDebug("CloudProxyClient::Event_SendMessageConfirmation: object ptr %p", object);
+
+ const char* str = object ? json_object_to_json_string_ext(object, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY) : "<obj_null>";
+ if (!str)
+ str = "<empty>";
+ qDebug("Event_SendMessageConfirmation: %s", str);
+
+ json_object *j_result;
+ if(!json_object_object_get_ex(object, "result", &j_result))
+ {
+ qDebug("Can't read confirmation result");
+ return;
+ }
+
+ int result = (int)json_object_get_boolean(j_result);
+
+ if (result)
+ ++i_confirm_good;
+ else
+ ++i_confirm_bad;
+
+ window->updateStat(i_confirm_good, i_confirm_bad, i_recv, QVariant());
+ qDebug("Application received confirmation result [good: %d, bad: %d]: %d", i_confirm_good, i_confirm_bad, result);
+ });
+ g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_ReceivedMessage, [&window](json_object* object){
+ qDebug("CloudProxyClient::Event_ReceivedMessage: object ptr %p", object);
+
+ const char* str = object ? json_object_to_json_string_ext(object, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY) : "<obj_null>";
+ if (!str)
+ str = "<empty>";
+ qDebug("Event_SendMessageConfirmation: %s", str);
+
+ json_object *event_data;
+ const char* data_str{nullptr};
+ if(!json_object_object_get_ex(object, "data", &event_data) ||
+ (data_str = json_object_get_string(event_data)) == nullptr)
+ {
+ qDebug("Can't read event data");
+ return;
+ }
+
+ ++i_recv;
+ window->updateStat(i_confirm_good, i_confirm_bad, i_recv, QString(data_str));
+ qDebug("Application received data [count: %d, good: %d, bad %d]: %s", i_recv, i_confirm_good, i_confirm_bad, data_str);
+ });
+
+
+ window->show();
+ }
+
+ return app.exec();
+}
diff --git a/sample/test-cloud-app/app/main.cpp.save b/sample/test-cloud-app/app/main.cpp.save
new file mode 100755
index 0000000..8236ada
--- /dev/null
+++ b/sample/test-cloud-app/app/main.cpp.save
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 <QtCore/QUrlQuery>
+#include <QtGui/QGuiApplication>
+#include <QtCore/QCommandLineParser>
+#include <QScopedPointer>
+
+#include "mainwindow.h"
+#include <QApplication>
+#include <QDebug>
+
+#include "cloudproxy-client/cloudproxyclient.h"
+
+
+CloudProxyClient* g_cloudproxyclient{nullptr};
+
+
+int main(int argc, char *argv[])
+{
+ QString graphic_role = QString("cloudapp") + QString(APP_INSTANCE_NUM);
+
+ QApplication app(argc, argv);
+ app.setDesktopFileName(graphic_role);
+ QScopedPointer<MainWindow> window;
+
+ QCommandLineParser parser;
+ parser.addPositionalArgument("port", app.translate("main", "port for binding"));
+ parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.process(app);
+ QStringList positionalArguments = parser.positionalArguments();
+
+ if (positionalArguments.length() == 2)
+ {
+ int port = positionalArguments.takeFirst().toInt();
+ QString secret = positionalArguments.takeFirst();
+ QUrl bindingAddress;
+ bindingAddress.setScheme(QStringLiteral("ws"));
+ bindingAddress.setHost(QStringLiteral("localhost"));
+ bindingAddress.setPort(port);
+ bindingAddress.setPath(QStringLiteral("/api"));
+ QUrlQuery query;
+ query.addQueryItem(QStringLiteral("token"), secret);
+ bindingAddress.setQuery(query);
+ std::string token = secret.toStdString();
+ LibHomeScreen* hs = new LibHomeScreen();
+ QLibWindowmanager* qwm = new QLibWindowmanager();
+
+ // WindowManager
+ if(qwm->init(port,secret) != 0){
+ exit(EXIT_FAILURE);
+ }
+ AGLScreenInfo screenInfo(qwm->get_scale_factor());
+ window.reset(new MainWindow(screenInfo.scale_factor()));
+
+ // Request a surface as described in layers.json windowmanager’s file
+ if (qwm->requestSurface(graphic_role) != 0) {
+ exit(EXIT_FAILURE);
+ }
+ // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs
+ qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, &graphic_role](json_object *object) {
+ (void)object;
+ qDebug() << "Surface got syncDraw!";
+ qwm->endDraw(graphic_role);
+ });
+
+ // HomeScreen
+ hs->init(port, token.c_str());
+ // Set the event handler for Event_ShowWindow which will activate the surface for windowmanager
+ hs->set_event_handler(LibHomeScreen::Event_ShowWindow, [qwm, &graphic_role](json_object *object){
+ (void)object;
+ qDebug("Surface %s got showWindow\n", graphic_role.toStdString().c_str());
+ qwm->activateWindow(graphic_role);
+ });
+
+ g_cloudproxyclient = new CloudProxyClient();
+ g_cloudproxyclient->init(port, token.c_str());
+
+ static int i_confirm_good{0}, i_confirm_bad{0}, i_recv{0};
+ g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_SendMessageConfirmation, [&window](json_object* object){
+ qDebug("CloudProxyClient::Event_SendMessageConfirmation: object ptr %p", object);
+
+ const char* str = object ? json_object_to_json_string_ext(object, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY) : "<obj_null>";
+ if (!str)
+ str = "<empty>";
+ qDebug("Event_SendMessageConfirmation: %s", str);
+
+ json_object *j_result;
+ if(!json_object_object_get_ex(object, "result", &j_result))
+ {
+ qDebug("Can't read confirmation result");
+ return;
+ }
+
+ int result = (int)json_object_get_boolean(j_result);
+
+ if (result)
+ ++i_confirm_good;
+ else
+ ++i_confirm_bad;
+
+ window->updateStat(i_confirm_good, i_confirm_bad, i_recv, QVariant());
+ qDebug("Application received confirmation result [good: %d, bad: %d]: %d", i_confirm_good, i_confirm_bad, result);
+ });
+ g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_ReceivedMessage, [&window](json_object* object){
+ qDebug("CloudProxyClient::Event_ReceivedMessage: object ptr %p", object);
+
+ const char* str = object ? json_object_to_json_string_ext(object, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY) : "<obj_null>";
+ if (!str)
+ str = "<empty>";
+ qDebug("Event_SendMessageConfirmation: %s", str);
+
+ json_object *event_data;
+ const char* data_str{nullptr};
+ if(!json_object_object_get_ex(object, "data", &event_data) ||
+ (data_str = json_object_get_string(event_data)) == nullptr)
+ {
+ qDebug("Can't read event data");
+ return;
+ }
+
+ ++i_recv;
+ window->updateStat(i_confirm_good, i_confirm_bad, i_recv, QString(data_str));
+ qDebug("Application received data [count: %d, good: %d, bad %d]: %s", i_recv, i_confirm_good, i_confirm_bad, data_str);
+ });
+
+
+ window->show();
+ qwm->slotActivateWindow();
+ }
+
+ return app.exec();
+}
diff --git a/sample/test-cloud-app/app/mainwindow.cpp b/sample/test-cloud-app/app/mainwindow.cpp
new file mode 100755
index 0000000..355847c
--- /dev/null
+++ b/sample/test-cloud-app/app/mainwindow.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 "mainwindow.h"
+#include "ui_mainwindow.h"
+#include <QDebug>
+
+#include <unistd.h>
+#include <sys/stat.h>
+
+
+#include "libcloudproxy.h"
+extern CloudProxyClient* g_cloudproxyclient;
+
+MainWindow::MainWindow(double scale_factor, QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(scale_factor, this);
+
+ //AGL style
+ setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
+ this->setStyleSheet(
+ "background-image:url(:/images/AGL_HMI_Blue_Background_NoCar-01.png) 0 0 0 0 stretch stretch; background: transparent;" );
+}
+
+void MainWindow::updateStat(int confirm_good, int confirm_bad, int received, QVariant recvMsg)
+{
+ confirmGood = confirm_good;
+ confirmBad = confirm_bad;
+ receivedCount = received;
+
+ if (recvMsg.isValid())
+ lastReceivedMsg = recvMsg.toString();
+
+ updateStat();
+}
+
+void MainWindow::updateStat()
+{
+ QString str = QString::asprintf("Sent: OK=%d, NOK=%d\nConfirmed: OK=%d, NOK=%d\nReceived=%d\n\n",
+ sendCount, sendErrorCount, confirmGood, confirmBad, receivedCount);
+ str.append("Last sent message:\n");
+ str.append(lastSentMsg);
+ str.append("\n\nLast received message:\n");
+ str.append(lastReceivedMsg);
+ ui->statLabel->setText(str);
+ //QApplication::processEvents();
+}
+
+void MainWindow::sendMsgButtonClick()
+{
+ qDebug() << "MainWindow::sendMegButtonClick()";
+
+ std::string msg = std::string{"{\"app_key\": \"app_value_"} + std::to_string(sendCount + sendErrorCount) + "\"}";
+ int res = g_cloudproxyclient->sendMessage(msg);
+ if (res == 0)
+ ++sendCount;
+ else
+ ++sendErrorCount;
+
+ lastSentMsg = msg.c_str();
+ qDebug() << "cloud sendMessage result: " << res;
+}
+
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
diff --git a/sample/test-cloud-app/app/mainwindow.h b/sample/test-cloud-app/app/mainwindow.h
new file mode 100755
index 0000000..ae66729
--- /dev/null
+++ b/sample/test-cloud-app/app/mainwindow.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QVariant>
+#include <memory>
+
+
+namespace Ui {
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(double scale_factor, QWidget *parent = 0);
+ ~MainWindow();
+
+public slots:
+ void updateStat(int confirm_good, int confirm_bad, int received, QVariant recvMsg);
+
+private slots:
+ void sendMsgButtonClick();
+ void updateStat();
+
+private:
+ Ui::MainWindow *ui;
+ int sendCount{0};
+ int sendErrorCount{0};
+ int confirmGood{0};
+ int confirmBad{0};
+ int receivedCount{0};
+ QString lastSentMsg;
+ QString lastReceivedMsg;
+};
+
+#endif // MAINWINDOW_H
diff --git a/sample/test-cloud-app/app/ui_mainwindow.h b/sample/test-cloud-app/app/ui_mainwindow.h
new file mode 100755
index 0000000..3dac77e
--- /dev/null
+++ b/sample/test-cloud-app/app/ui_mainwindow.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 UI_MAINWINDOW_H
+#define UI_MAINWINDOW_H
+
+#include <QtCore/QVariant>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QLabel>
+#include <QtWidgets/QMainWindow>
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QLineEdit>
+#include <QtWidgets/QWidget>
+#include <QtWidgets/QFrame>
+#include <QtWidgets/QGroupBox>
+#include <QtWidgets/QRadioButton>
+#include <QtWidgets/QComboBox>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QWidget *centralWidget{nullptr};
+ QPushButton *sendMsgButton{nullptr};
+ QLabel *appNameLabel{nullptr};
+ QLabel *statLabel{nullptr};
+
+ void setupUi(double scale_factor, QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
+ MainWindow->resize(1080*scale_factor, 1400*scale_factor);
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
+
+ //QString style("color: white; font-size: 24px");
+ QString style("color: white");
+
+ sendMsgButton = new QPushButton(centralWidget);
+ sendMsgButton->setObjectName(QString::fromUtf8("sendMsgButton"));
+ sendMsgButton->setGeometry(QRect((540-242/2)*scale_factor, 100*scale_factor, 242*scale_factor, 64*scale_factor));
+ sendMsgButton->setStyleSheet(style);
+
+ appNameLabel = new QLabel(centralWidget);
+ appNameLabel->setObjectName(QString::fromUtf8("label"));
+ appNameLabel->setGeometry(QRect(40*scale_factor, 20*scale_factor, 1000*scale_factor, 32*scale_factor));
+ appNameLabel->setStyleSheet(style);
+
+ statLabel = new QLabel(centralWidget);
+ statLabel->setObjectName(QString::fromUtf8("label"));
+ statLabel->setGeometry(QRect(40*scale_factor, 180*scale_factor, 1000*scale_factor, 420*scale_factor));
+ statLabel->setWordWrap(true);
+ statLabel->setAlignment(Qt::AlignTop);
+ statLabel->setStyleSheet(style);
+
+ MainWindow->setCentralWidget(centralWidget);
+
+ QObject::connect(sendMsgButton, SIGNAL(clicked()), MainWindow, SLOT(sendMsgButtonClick()));
+
+ retranslateUi(MainWindow);
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
+ sendMsgButton->setText(QApplication::translate("MainWindow", "Send message", nullptr));
+ QString name = QString("Test application ") + APP_INSTANCE_NUM;
+ appNameLabel->setText(QApplication::translate("MainWindow", name.toUtf8().constData(), nullptr));
+ } // retranslateUi
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_MAINWINDOW_H
diff --git a/sample/test-cloud-app/autobuild/agl/autobuild b/sample/test-cloud-app/autobuild/agl/autobuild
new file mode 100755
index 0000000..bbbc13e
--- /dev/null
+++ b/sample/test-cloud-app/autobuild/agl/autobuild
@@ -0,0 +1,110 @@
+#!/usr/bin/make -f
+# Copyright (C) 2015 - 2018 "IoT.bzh"
+# Copyright (C) 2020 Konsulko Group
+# Author "Romain Forlot" <romain.forlot@iot.bzh>
+#
+# 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.
+
+THISFILE := $(lastword $(MAKEFILE_LIST))
+ROOT_DIR := $(abspath $(dir $(THISFILE))/../..)
+
+# Build directories
+# Note that the debug directory is defined in relation to the release
+# directory (BUILD_DIR), this needs to be kept in mind if over-riding
+# it and building that widget types, the specific widget type variable
+# (e.g. BUILD_DIR_DEBUG) may also need to be specified to yield the
+# desired output hierarchy.
+BUILD_DIR = $(ROOT_DIR)/build
+BUILD_DIR_DEBUG = $(abspath $(BUILD_DIR)/../build-debug)
+
+# Output directory variable for use in pattern rules.
+# This is intended for internal use only, hence the explicit override
+# definition.
+override OUTPUT_DIR = $(BUILD_DIR)
+
+# Final install directory for widgets
+DEST = $(OUTPUT_DIR)
+
+# Default build type for release builds
+BUILD_TYPE = release
+
+.PHONY: all help update install distclean
+.PHONY: clean clean-release clean-debug clean-all
+.PHONY: configure configure-release configure-debug
+.PHONY: build build-release build-debug build-all
+.PHONY: package package-release package-debug package-all
+
+help:
+ @echo "List of targets available:"
+ @echo ""
+ @echo "- all"
+ @echo "- help"
+ @echo "- clean"
+ @echo "- distclean"
+ @echo "- configure"
+ @echo "- build: compilation, link and prepare files for package into a widget"
+ @echo "- package: output a widget file '*.wgt'"
+ @echo "- install: install in $(DEST) directory"
+ @echo ""
+ @echo "Usage: ./autobuild/agl/autobuild package DEST=${HOME}/opt"
+ @echo "Don't use your build dir as DEST as wgt file is generated at this location"
+
+all: package-all
+
+# Target specific variable over-rides so static pattern rules can be
+# used for the various type-specific targets.
+
+configure-debug build-debug package-debug clean-debug: OUTPUT_DIR = $(BUILD_DIR_DEBUG)
+configure-debug build-debug package-debug: BUILD_TYPE = debug
+
+clean-release clean-debug:
+ @if [ -d $(OUTPUT_DIR) ]; then \
+ $(MAKE) -C $(OUTPUT_DIR) $(CLEAN_ARGS) clean; \
+ else \
+ echo Nothing to clean; \
+ fi
+
+clean: clean-release
+
+clean-all: clean-release clean-debug
+
+distclean: clean-all
+
+configure-release configure-debug:
+ @mkdir -p $(OUTPUT_DIR)
+ @if [ ! -f $(OUTPUT_DIR)/Makefile ]; then \
+ (cd $(OUTPUT_DIR) && qmake CONFIG+=$(BUILD_TYPE) $(CONFIGURE_ARGS) $(ROOT_DIR)); \
+ fi
+
+configure: configure-release
+
+build-release build-debug: build-%: configure-%
+ @$(MAKE) -C $(OUTPUT_DIR) $(BUILD_ARGS) all
+
+build: build-release
+
+build-all: build-release build-debug
+
+package-release package-debug: package-%: build-%
+ @cp $(OUTPUT_DIR)/package/*.wgt $(OUTPUT_DIR)/
+ @if [ "$(abspath $(DEST))" != "$(abspath $(OUTPUT_DIR))" ]; then \
+ mkdir -p $(DEST) && cp $(OUTPUT_DIR)/*.wgt $(DEST); \
+ fi
+
+
+package: package-release
+
+package-all: package-release package-debug
+
+install: build
+ @$(MAKE) -C $(BUILD_DIR) $(INSTALL_ARGS) install
diff --git a/sample/test-cloud-app/autobuild/linux/autobuild b/sample/test-cloud-app/autobuild/linux/autobuild
new file mode 100755
index 0000000..bbbc13e
--- /dev/null
+++ b/sample/test-cloud-app/autobuild/linux/autobuild
@@ -0,0 +1,110 @@
+#!/usr/bin/make -f
+# Copyright (C) 2015 - 2018 "IoT.bzh"
+# Copyright (C) 2020 Konsulko Group
+# Author "Romain Forlot" <romain.forlot@iot.bzh>
+#
+# 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.
+
+THISFILE := $(lastword $(MAKEFILE_LIST))
+ROOT_DIR := $(abspath $(dir $(THISFILE))/../..)
+
+# Build directories
+# Note that the debug directory is defined in relation to the release
+# directory (BUILD_DIR), this needs to be kept in mind if over-riding
+# it and building that widget types, the specific widget type variable
+# (e.g. BUILD_DIR_DEBUG) may also need to be specified to yield the
+# desired output hierarchy.
+BUILD_DIR = $(ROOT_DIR)/build
+BUILD_DIR_DEBUG = $(abspath $(BUILD_DIR)/../build-debug)
+
+# Output directory variable for use in pattern rules.
+# This is intended for internal use only, hence the explicit override
+# definition.
+override OUTPUT_DIR = $(BUILD_DIR)
+
+# Final install directory for widgets
+DEST = $(OUTPUT_DIR)
+
+# Default build type for release builds
+BUILD_TYPE = release
+
+.PHONY: all help update install distclean
+.PHONY: clean clean-release clean-debug clean-all
+.PHONY: configure configure-release configure-debug
+.PHONY: build build-release build-debug build-all
+.PHONY: package package-release package-debug package-all
+
+help:
+ @echo "List of targets available:"
+ @echo ""
+ @echo "- all"
+ @echo "- help"
+ @echo "- clean"
+ @echo "- distclean"
+ @echo "- configure"
+ @echo "- build: compilation, link and prepare files for package into a widget"
+ @echo "- package: output a widget file '*.wgt'"
+ @echo "- install: install in $(DEST) directory"
+ @echo ""
+ @echo "Usage: ./autobuild/agl/autobuild package DEST=${HOME}/opt"
+ @echo "Don't use your build dir as DEST as wgt file is generated at this location"
+
+all: package-all
+
+# Target specific variable over-rides so static pattern rules can be
+# used for the various type-specific targets.
+
+configure-debug build-debug package-debug clean-debug: OUTPUT_DIR = $(BUILD_DIR_DEBUG)
+configure-debug build-debug package-debug: BUILD_TYPE = debug
+
+clean-release clean-debug:
+ @if [ -d $(OUTPUT_DIR) ]; then \
+ $(MAKE) -C $(OUTPUT_DIR) $(CLEAN_ARGS) clean; \
+ else \
+ echo Nothing to clean; \
+ fi
+
+clean: clean-release
+
+clean-all: clean-release clean-debug
+
+distclean: clean-all
+
+configure-release configure-debug:
+ @mkdir -p $(OUTPUT_DIR)
+ @if [ ! -f $(OUTPUT_DIR)/Makefile ]; then \
+ (cd $(OUTPUT_DIR) && qmake CONFIG+=$(BUILD_TYPE) $(CONFIGURE_ARGS) $(ROOT_DIR)); \
+ fi
+
+configure: configure-release
+
+build-release build-debug: build-%: configure-%
+ @$(MAKE) -C $(OUTPUT_DIR) $(BUILD_ARGS) all
+
+build: build-release
+
+build-all: build-release build-debug
+
+package-release package-debug: package-%: build-%
+ @cp $(OUTPUT_DIR)/package/*.wgt $(OUTPUT_DIR)/
+ @if [ "$(abspath $(DEST))" != "$(abspath $(OUTPUT_DIR))" ]; then \
+ mkdir -p $(DEST) && cp $(OUTPUT_DIR)/*.wgt $(DEST); \
+ fi
+
+
+package: package-release
+
+package-all: package-release package-debug
+
+install: build
+ @$(MAKE) -C $(BUILD_DIR) $(INSTALL_ARGS) install
diff --git a/sample/test-cloud-app/package/config.xml b/sample/test-cloud-app/package/config.xml
new file mode 100755
index 0000000..7d82afc
--- /dev/null
+++ b/sample/test-cloud-app/package/config.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widget xmlns="http://www.w3.org/ns/widgets" id="testcloudapp1" version="0.1">
+ <name>CloudApp1</name>
+ <icon src="icon.svg"/>
+ <content src="bin/testcloudapp" type="application/vnd.agl.native"/>
+ <description>Test Cloud App</description>
+ <author>Mera</author>
+ <license>APL 2.0</license>
+ <feature name="urn:AGL:widget:required-api">
+ <param name="homescreen" value="ws"/>
+ <param name="cloudproxy" value="ws"/>
+ </feature>
+ <feature name="urn:AGL:widget:required-permission">
+ <param name="urn:AGL:permission::public:no-htdocs" value="required"/>
+ <param name="urn:AGL:permission::public:display" value="required" />
+ </feature>
+</widget>
diff --git a/sample/test-cloud-app/package/icon.svg b/sample/test-cloud-app/package/icon.svg
new file mode 100755
index 0000000..b9b8e67
--- /dev/null
+++ b/sample/test-cloud-app/package/icon.svg
@@ -0,0 +1,266 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Generator: Adobe Illustrator 21.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+
+<svg
+ xmlns:i="&amp;#38;ns_ai;"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.1"
+ x="0px"
+ y="0px"
+ viewBox="0 0 320 320"
+ style="enable-background:new 0 0 320 320;"
+ xml:space="preserve"
+ id="svg2"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="icon.svg"><metadata
+ id="metadata1292"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
+ id="defs1290" /><sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="2560"
+ inkscape:window-height="1464"
+ id="namedview1288"
+ showgrid="false"
+ inkscape:zoom="4.17193"
+ inkscape:cx="183.76952"
+ inkscape:cy="191.17869"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg2" /><style
+ type="text/css"
+ id="style4">
+ .st0{display:none;}
+ .st1{display:inline;}
+ .st2{opacity:0.4;fill:url(#SVGID_1_);}
+ .st3{fill:url(#SVGID_2_);}
+ .st4{fill:#FFFFFF;}
+ .st5{font-family:'Roboto-Regular';}
+ .st6{font-size:25px;}
+ .st7{letter-spacing:6;}
+ .st8{fill:url(#SVGID_3_);}
+ .st9{fill:url(#SVGID_4_);}
+ .st10{fill:url(#SVGID_5_);}
+ .st11{fill:url(#SVGID_6_);}
+ .st12{fill:url(#SVGID_7_);}
+ .st13{fill:url(#SVGID_8_);}
+ .st14{fill:url(#SVGID_9_);}
+ .st15{fill:url(#SVGID_10_);}
+ .st16{fill:url(#SVGID_11_);}
+ .st17{fill:url(#SVGID_12_);}
+ .st18{fill:url(#SVGID_13_);}
+ .st19{fill:url(#SVGID_14_);}
+ .st20{fill:url(#SVGID_15_);}
+ .st21{fill:url(#SVGID_16_);}
+ .st22{fill:url(#SVGID_17_);}
+ .st23{fill:url(#SVGID_18_);}
+ .st24{opacity:0.29;}
+ .st25{fill:url(#SVGID_19_);}
+ .st26{fill:url(#SVGID_20_);}
+ .st27{fill:url(#SVGID_21_);}
+ .st28{fill:url(#SVGID_22_);}
+ .st29{fill:url(#SVGID_23_);}
+ .st30{fill:url(#SVGID_24_);}
+ .st31{fill:url(#SVGID_25_);}
+ .st32{fill:url(#SVGID_26_);}
+ .st33{fill:url(#SVGID_27_);}
+ .st34{fill:url(#SVGID_28_);}
+ .st35{fill:url(#SVGID_29_);}
+ .st36{fill:url(#SVGID_30_);}
+ .st37{fill:url(#SVGID_31_);}
+ .st38{fill:url(#SVGID_32_);}
+ .st39{fill:url(#SVGID_33_);}
+ .st40{fill:url(#SVGID_34_);}
+ .st41{fill:url(#SVGID_35_);}
+ .st42{fill:url(#SVGID_36_);}
+ .st43{opacity:0.4;fill:url(#SVGID_37_);}
+ .st44{fill:url(#SVGID_38_);}
+ .st45{fill:url(#SVGID_39_);}
+ .st46{fill:url(#SVGID_40_);}
+ .st47{fill:url(#SVGID_41_);}
+ .st48{fill:url(#SVGID_42_);}
+ .st49{fill:url(#SVGID_43_);}
+ .st50{fill:url(#SVGID_44_);}
+ .st51{display:inline;opacity:0.29;}
+ .st52{display:inline;fill:url(#SVGID_45_);}
+ .st53{display:inline;fill:url(#SVGID_46_);}
+ .st54{display:inline;fill:#FFFFFF;}
+ .st55{display:inline;fill:url(#SVGID_47_);}
+ .st56{display:inline;fill:url(#SVGID_48_);}
+ .st57{display:inline;fill:url(#SVGID_49_);}
+ .st58{display:inline;fill:url(#SVGID_50_);}
+ .st59{display:inline;fill:url(#SVGID_51_);}
+ .st60{display:inline;fill:url(#SVGID_52_);}
+ .st61{opacity:0.4;fill:url(#SVGID_53_);}
+ .st62{fill:url(#SVGID_54_);}
+ .st63{fill:url(#SVGID_55_);}
+ .st64{fill:url(#SVGID_56_);}
+ .st65{fill:url(#SVGID_57_);}
+ .st66{fill:url(#SVGID_58_);}
+ .st67{opacity:0.4;fill:url(#SVGID_59_);}
+ .st68{fill:url(#SVGID_60_);}
+ .st69{fill:url(#SVGID_61_);}
+ .st70{fill:url(#SVGID_62_);}
+ .st71{fill:url(#SVGID_63_);}
+ .st72{fill:url(#SVGID_64_);}
+ .st73{fill:url(#SVGID_65_);}
+ .st74{fill:url(#SVGID_66_);}
+ .st75{fill:url(#SVGID_67_);}
+ .st76{fill:url(#SVGID_68_);}
+ .st77{fill:url(#SVGID_69_);}
+ .st78{fill:url(#SVGID_70_);}
+ .st79{fill:url(#SVGID_71_);}
+ .st80{fill:url(#SVGID_72_);}
+ .st81{fill:url(#SVGID_73_);}
+ .st82{fill:url(#SVGID_74_);}
+ .st83{fill:url(#SVGID_75_);}
+ .st84{fill:url(#SVGID_76_);}
+ .st85{fill:url(#SVGID_77_);}
+ .st86{fill:url(#SVGID_78_);}
+ .st87{fill:url(#SVGID_79_);}
+ .st88{fill:url(#SVGID_80_);}
+ .st89{fill:url(#SVGID_81_);}
+ .st90{fill:url(#SVGID_82_);}
+ .st91{fill:url(#SVGID_83_);}
+ .st92{fill:url(#SVGID_84_);}
+ .st93{fill:url(#SVGID_85_);}
+ .st94{fill:url(#SVGID_86_);}
+ .st95{opacity:0.4;fill:url(#SVGID_87_);}
+ .st96{fill:url(#SVGID_88_);}
+ .st97{fill:url(#SVGID_89_);}
+ .st98{fill:url(#SVGID_90_);}
+ .st99{fill:url(#SVGID_91_);}
+ .st100{fill:url(#SVGID_92_);}
+ .st101{fill:url(#SVGID_93_);}
+ .st102{fill:url(#SVGID_94_);}
+ .st103{opacity:0.4;fill:url(#SVGID_95_);}
+ .st104{fill:url(#SVGID_96_);}
+ .st105{fill:url(#SVGID_97_);}
+ .st106{fill:url(#SVGID_98_);}
+ .st107{fill:url(#SVGID_99_);}
+ .st108{fill:url(#SVGID_100_);}
+ .st109{fill:url(#SVGID_101_);}
+ .st110{display:inline;fill:url(#SVGID_102_);}
+ .st111{display:inline;fill:url(#SVGID_103_);}
+ .st112{fill:url(#SVGID_104_);}
+ .st113{fill:url(#SVGID_105_);}
+ .st114{fill:url(#SVGID_106_);}
+ .st115{fill:url(#SVGID_107_);}
+ .st116{fill:url(#SVGID_108_);}
+ .st117{opacity:0.4;fill:url(#SVGID_109_);}
+ .st118{fill:url(#SVGID_110_);}
+ .st119{fill:url(#SVGID_111_);}
+ .st120{fill:url(#SVGID_112_);}
+ .st121{fill:url(#SVGID_113_);}
+ .st122{fill:url(#SVGID_114_);}
+ .st123{opacity:0.4;fill:url(#SVGID_115_);}
+ .st124{fill:url(#SVGID_116_);}
+ .st125{fill:url(#SVGID_117_);}
+ .st126{fill:url(#SVGID_118_);}
+ .st127{display:inline;fill:url(#SVGID_119_);}
+ .st128{display:inline;fill:url(#SVGID_120_);}
+ .st129{fill:url(#SVGID_121_);}
+ .st130{fill:url(#SVGID_122_);}
+</style><switch
+ id="switch6"><g
+ i:extraneous="self"
+ id="g8"><g
+ id="Multimedia_Inactive_copy"><circle
+ class="st24"
+ cx="159.7"
+ cy="133.4"
+ r="101.9"
+ id="circle884" /><linearGradient
+ id="SVGID_91_"
+ gradientUnits="userSpaceOnUse"
+ x1="115.9317"
+ y1="254.1836"
+ x2="256.3852"
+ y2="-133.5267"><stop
+ offset="0"
+ style="stop-color:#8BC53F"
+ id="stop887" /><stop
+ offset="2.015080e-02"
+ style="stop-color:#7CCB56;stop-opacity:0.9678"
+ id="stop889" /><stop
+ offset="6.089833e-02"
+ style="stop-color:#62D67D;stop-opacity:0.9028"
+ id="stop891" /><stop
+ offset="0.1057"
+ style="stop-color:#4BDFA0;stop-opacity:0.8312"
+ id="stop893" /><stop
+ offset="0.1543"
+ style="stop-color:#38E7BE;stop-opacity:0.7537"
+ id="stop895" /><stop
+ offset="0.2077"
+ style="stop-color:#28EED6;stop-opacity:0.6684"
+ id="stop897" /><stop
+ offset="0.2681"
+ style="stop-color:#1CF3E8;stop-opacity:0.572"
+ id="stop899" /><stop
+ offset="0.3394"
+ style="stop-color:#13F6F5;stop-opacity:0.4581"
+ id="stop901" /><stop
+ offset="0.4323"
+ style="stop-color:#0EF8FD;stop-opacity:0.3098"
+ id="stop903" /><stop
+ offset="0.6264"
+ style="stop-color:#0DF9FF;stop-opacity:0"
+ id="stop905" /></linearGradient><circle
+ class="st99"
+ cx="159.7"
+ cy="133.4"
+ r="101.9"
+ id="circle907" /><linearGradient
+ id="SVGID_92_"
+ gradientUnits="userSpaceOnUse"
+ x1="4.0481"
+ y1="287.9492"
+ x2="320.4859"
+ y2="-15.4029"
+ gradientTransform="matrix(1 5.464556e-03 -5.464556e-03 1 -2.0192 -3.0212)"><stop
+ offset="0"
+ style="stop-color:#59FF7F"
+ id="stop910" /><stop
+ offset="1"
+ style="stop-color:#6BFBFF"
+ id="stop912" /></linearGradient><path
+ class="st100"
+ d="M160,238.8c-0.2,0-0.4,0-0.6,0c-58-0.3-104.9-47.7-104.6-105.7C55.2,75.3,102.3,28.5,160,28.5 c0.2,0,0.4,0,0.6,0c58,0.3,104.9,47.7,104.6,105.7l0,0C264.8,192,217.7,238.8,160,238.8z M160,32.2 c-55.7,0-101.2,45.2-101.5,100.9c-0.3,55.9,45,101.7,100.9,102c0.2,0,0.4,0,0.6,0c55.7,0,101.2-45.2,101.5-100.9 c0.3-55.9-45-101.7-100.9-102C160.4,32.2,160.2,32.2,160,32.2z"
+ id="path914" /><g
+ id="g916"><text
+ transform="matrix(1 0 0 1 53.5841 284.7119)"
+ class="st4 st5 st6 st7"
+ id="text918">VIDEOPLAYER
+</text>
+<linearGradient
+ id="SVGID_94_"
+ gradientUnits="userSpaceOnUse"
+ x1="145.3286"
+ y1="203.8951"
+ x2="191.6285"
+ y2="70.3637"><stop
+ offset="0"
+ style="stop-color:#59FF7F"
+ id="stop928" /><stop
+ offset="1"
+ style="stop-color:#6BFBFF"
+ id="stop930" /></linearGradient><polygon
+ class="st102"
+ points="125,75 125,200 225,137.5 "
+ id="polygon932"
+ style="fill:url(#SVGID_94_)" /></g></g></g></switch></svg> \ No newline at end of file
diff --git a/sample/test-cloud-app/package/package.pro b/sample/test-cloud-app/package/package.pro
new file mode 100755
index 0000000..c8af452
--- /dev/null
+++ b/sample/test-cloud-app/package/package.pro
@@ -0,0 +1,28 @@
+
+DISTFILES = icon.svg config.xml
+
+copy_icon.target = $$OUT_PWD/root/icon.svg
+copy_icon.depends = $$_PRO_FILE_PWD_/icon.svg
+copy_icon.commands = $(COPY_FILE) \"$$replace(copy_icon.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_icon.target, /, $$QMAKE_DIR_SEP)\"
+QMAKE_EXTRA_TARGETS += copy_icon
+PRE_TARGETDEPS += $$copy_icon.target
+
+copy_config.target = $$OUT_PWD/root/config.xml
+copy_config.depends = $$_PRO_FILE_PWD_/config.xml
+copy_config.commands = $(COPY_FILE) \"$$replace(copy_config.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_config.target, /, $$QMAKE_DIR_SEP)\"
+QMAKE_EXTRA_TARGETS += copy_config
+PRE_TARGETDEPS += $$copy_config.target
+
+WGT_TYPE =
+CONFIG(debug, debug|release) {
+ WGT_TYPE = -debug
+}
+
+wgt.target = package
+wgt.commands = wgtpkg-pack -f -o testcloudapp$${WGT_TYPE}.wgt root
+
+QMAKE_EXTRA_TARGETS += wgt
+
+deploy.files = testcloudapp.wgt
+deploy.path = /usr/AGL/apps/autoinstall
+INSTALLS += deploy
diff --git a/sample/test-cloud-app/testcloudapp.pro b/sample/test-cloud-app/testcloudapp.pro
new file mode 100755
index 0000000..579a952
--- /dev/null
+++ b/sample/test-cloud-app/testcloudapp.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = app package
+package.depends += app
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..f90c1c9
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,50 @@
+#
+# Copyright (C) 2020 Orion Innovation, formerly MERA
+#
+# 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_LIBCLOUDPROXY cloudproxy)
+add_definitions("-std=c++11")
+
+
+pkg_check_modules(libcloudproxy_depends json-c libafbwsc libsystemd)
+#pkg_check_modules(json-c libafbwsc libsystemd)
+set(libcloudproxy_sources libcloudproxy.cpp)
+
+include_directories(${LIBCLOUDPROXY_INCLUDE_DIR})
+link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
+
+add_library(${TARGET_LIBCLOUDPROXY} SHARED ${libcloudproxy_sources})
+target_compile_options(${TARGET_LIBCLOUDPROXY} PUBLIC ${libcloudproxy_depends_CFLAGS})
+
+if(DEFINED DEBUGMODE)
+ target_compile_options(${TARGET_LIBCLOUDPROXY} PRIVATE -g -O0)
+else(DEFINED DEBUGMODE)
+ target_compile_options(${TARGET_LIBCLOUDPROXY} PRIVATE -g -O2)
+endif(DEFINED DEBUGMODE)
+
+include_directories(${TARGET_LIBCLOUDPROXY} ${libcloudproxy_depends_INCLUDE_DIRS})
+target_link_libraries(${TARGET_LIBCLOUDPROXY} afbwsc -lpthread ${link_libraries} ${libcloudproxy_depends_LIBRARIES})
+set_target_properties(${TARGET_LIBCLOUDPROXY}
+ PROPERTIES
+ VERSION 0.1
+)
+
+if(DEFINED CMAKE_INSTALL_LIBDIR)
+ INSTALL(TARGETS ${TARGET_LIBCLOUDPROXY}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif(DEFINED CMAKE_INSTALL_LIBDIR)
diff --git a/src/libcloudproxy.cpp b/src/libcloudproxy.cpp
new file mode 100644
index 0000000..7b0f605
--- /dev/null
+++ b/src/libcloudproxy.cpp
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2020 MERA
+ *
+ * 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 <thread>
+#include <algorithm>
+
+#include "libcloudproxy.h"
+#include "hmi-debug.h"
+
+
+static const char API_name[] = "cloudproxy";
+
+const std::vector<std::string> CloudProxyClient::m_api_list {
+ std::string("ping"),
+ std::string("createConnection"),
+ std::string("sendMessage"),
+ std::string("destroyConnection")
+ };
+
+const std::vector<std::string> CloudProxyClient::m_event_list {
+ std::string("sendMessageConfirmation"),
+ std::string("receivedMessage")
+ };
+
+static void event_loop_run(sd_event* loop)
+{
+ sd_event_loop(loop);
+ sd_event_unref(loop);
+}
+
+static void on_hangup(void *closure, afb_wsj1 *wsj)
+{
+ HMI_DEBUG("cloudproxyclient", "called");
+ (void)closure;
+ (void)wsj;
+}
+
+static void on_call(void *closure, const char *api, const char *verb, afb_wsj1_msg *msg)
+{
+ HMI_ERROR("cloudproxyclient", "this method should not be called");
+ (void)closure;
+ (void)api;
+ (void)verb;
+ (void)msg;
+}
+
+static void on_event(void* closure, const char* event, afb_wsj1_msg *msg)
+{
+ HMI_DEBUG("cloudproxyclient", "event [%s]", (event ? event: ""));
+ (void)closure;
+
+ static_cast<CloudProxyClient*>(closure)->on_event(nullptr, event, msg);
+}
+
+static void on_reply(void *closure, afb_wsj1_msg *msg)
+{
+ HMI_DEBUG("cloudproxyclient", "called");
+ (void)closure;
+ (void)msg;
+}
+
+
+CloudProxyClient::CloudProxyClient()
+{
+}
+
+CloudProxyClient::~CloudProxyClient()
+{
+ if(m_websock)
+ {
+ afb_wsj1_unref(m_websock);
+ }
+ if(m_loop)
+ {
+ sd_event_exit(m_loop, 0);
+ }
+}
+
+int CloudProxyClient::init(const int port, const std::string& token)
+{
+ int ret = 0;
+ if(port <= 0 && token.size() == 0)
+ {
+ HMI_ERROR("cloudproxyclient","port and token should be > 0, Initial port and token uses.");
+ return -1;
+ }
+
+ {
+ m_loop = nullptr;
+ int ret = sd_event_new(&m_loop);
+ if(ret < 0)
+ {
+ HMI_ERROR("cloudproxyclient","Failed to create event loop");
+ return -1;
+ }
+
+ {
+ // enforce context to avoid initialization/goto error
+ std::thread th(event_loop_run, m_loop);
+ th.detach();
+ }
+
+ /* Initialize interface from websocket */
+ m_itf.on_hangup = ::on_hangup;
+ m_itf.on_call = ::on_call;
+ m_itf.on_event = ::on_event;
+
+ m_uri += "ws://localhost:" + std::to_string(port) + "/api?token=" + token;
+
+ m_websock = afb_ws_client_connect_wsj1(m_loop, m_uri.c_str(), &m_itf, this);
+ if(!m_websock)
+ {
+ HMI_ERROR("cloudproxyclient","Failed to create websocket connection");
+ return -1;
+ }
+ }
+
+ HMI_DEBUG("cloudproxyclient", "Initialized");
+
+ return ret;
+}
+
+
+int CloudProxyClient::call(const std::string& verb, json_object* arg)
+{
+ int ret;
+ if(!m_websock)
+ {
+ return -1;
+ }
+
+ if (verb.empty() || m_api_list.end() == std::find(m_api_list.begin(), m_api_list.end(), verb))
+ {
+ HMI_ERROR("cloudproxyclient","verb [%s] doesn't exit", verb.c_str());
+ return -1;
+ }
+
+ ret = afb_wsj1_call_j(m_websock, API_name, verb.c_str(), arg, ::on_reply, this);
+ if (ret < 0)
+ {
+ HMI_ERROR("cloudproxyclient", "Failed to call verb:%s", verb.c_str());
+ }
+
+ return ret;
+}
+
+
+int CloudProxyClient::sendMessage(const std::string& data)
+{
+ if(!m_websock)
+ return -1;
+
+ json_object* j_obj = json_object_new_object();
+ json_object_object_add(j_obj, "data", json_object_new_string(data.c_str()));
+
+ return this->call("sendMessage", j_obj);
+}
+
+void CloudProxyClient::set_event_handler(enum EventType et, handler_func f)
+{
+ if (et > Event_Min && et < Event_Max)
+ {
+ switch (et)
+ {
+ case Event_SendMessageConfirmation:
+ this->subscribe(CloudProxyClient::m_event_list[0]);
+ break;
+ case Event_ReceivedMessage:
+ this->subscribe(CloudProxyClient::m_event_list[1]);
+ break;
+ default:
+ break;
+ }
+
+ this->handlers[et] = std::move(f);
+ }
+}
+
+int CloudProxyClient::subscribe(const std::string& event_name)
+{
+ if(!m_websock)
+ return -1;
+
+ 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(m_websock, API_name, "subscribe", j_obj, ::on_reply, this);
+ if (ret < 0)
+ HMI_ERROR("cloudproxyclient", "subscribe filed for '%s'", event_name.c_str());
+
+ return ret;
+}
+
+int CloudProxyClient::unsubscribe(const std::string& event_name)
+{
+ if(!m_websock)
+ return -1;
+
+ 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(m_websock, API_name, "unsubscribe", j_obj, ::on_reply, this);
+ if (ret < 0)
+ HMI_ERROR("cloudproxyclient", "unsubscribe filed for '%s'", event_name.c_str());
+
+ return ret;
+}
+
+void CloudProxyClient::on_event(void *closure, const char *event, afb_wsj1_msg *msg)
+{
+ HMI_DEBUG("cloudproxyclient", "event: (%s) msg: (%s).", event, afb_wsj1_msg_object_s(msg));
+ (void) closure;
+
+ if (strstr(event, API_name) == nullptr)
+ return;
+
+
+ json_object* ev_contents = afb_wsj1_msg_object_j(msg);
+ json_object *json_data;
+ if(!json_object_object_get_ex(ev_contents, "data", &json_data))
+ {
+ HMI_ERROR("cloudproxyclient", "got ev_contents error.");
+ return;
+ }
+
+ const char* event_type = nullptr;
+ json_object *json_event_type;
+ if(!json_object_object_get_ex(json_data, "type", &json_event_type) ||
+ (event_type = json_object_get_string(json_event_type)) == nullptr)
+ {
+ HMI_ERROR("cloudproxyclient", "event_type is null.");
+ return;
+ }
+
+ const std::string et{event_type};
+ if (CloudProxyClient::m_event_list[0] == et)
+ {
+ auto i = this->handlers.find(Event_SendMessageConfirmation);
+ if (i != this->handlers.end())
+ i->second(json_data);
+ }
+ else if (CloudProxyClient::m_event_list[1] == et)
+ {
+ auto i = this->handlers.find(Event_ReceivedMessage);
+ if (i != this->handlers.end())
+ i->second(json_data);
+ }
+}