summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore8
-rw-r--r--CMakeLists.txt3
-rw-r--r--LICENSE21
-rw-r--r--README.md163
-rwxr-xr-xautobuild/agl/autobuild79
-rwxr-xr-xautobuild/linux/autobuild79
-rw-r--r--conf.d/cmake/config.cmake183
-rw-r--r--conf.d/packaging/agl-helloworld-service.dsc18
-rw-r--r--conf.d/packaging/agl-helloworld-service.spec66
-rw-r--r--conf.d/packaging/debian.agl-helloworld-service.install2
-rw-r--r--conf.d/packaging/debian.changelog5
-rw-r--r--conf.d/packaging/debian.compat1
-rw-r--r--conf.d/packaging/debian.control19
-rw-r--r--conf.d/packaging/debian.rules87
-rw-r--r--conf.d/wgt/config.xml.in15
-rw-r--r--helloworld-skeleton/CMakeLists.txt27
-rw-r--r--helloworld-skeleton/helloworld-service-binding.c92
-rw-r--r--helloworld-subscribe-event/CMakeLists.txt28
-rw-r--r--helloworld-subscribe-event/helloworld-service-binding.c133
-rw-r--r--htdocs/AFB-websock.js177
-rw-r--r--htdocs/CMakeLists.txt33
-rw-r--r--htdocs/assets/background_iot_bzh_light.jpgbin0 -> 40718 bytes
-rw-r--r--htdocs/assets/favicon.icobin0 -> 1150 bytes
-rw-r--r--htdocs/assets/iot-bzh-logo-small.pngbin0 -> 14449 bytes
-rw-r--r--htdocs/index.html49
-rw-r--r--htdocs/iotbzh-Binding.css59
-rw-r--r--htdocs/iotbzh-Binding.js104
-rw-r--r--test/CMakeLists.txt27
-rw-r--r--test/etc/CMakeLists.txt31
-rw-r--r--test/etc/aft-agl-helloworld.json22
-rw-r--r--test/tests/CMakeLists.txt31
-rw-r--r--test/tests/helloworld.lua38
32 files changed, 1600 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..21745cb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+build*
+package
+nbproject/
+.stfolder
+.*.sw*
+*.tar.gz
+.vscode
+__*
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..dbaaf34
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,3 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.6)
+
+include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..1b67277
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017-2019 IoT.bzh
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..29d52db
--- /dev/null
+++ b/README.md
@@ -0,0 +1,163 @@
+# helloworld-service
+
+A binding example for AGL
+
+## Pre-requisites
+
+Please follow [this guide](http://docs.automotivelinux.org/master/docs/devguides/en/dev/reference/host-configuration/docs/1_Prerequisites.html)
+to add the AGL-Master repository to your distribution. In order to load these files into the current shell script, use the following command :
+
+* **Debian/Ubuntu**
+
+```bash
+source /etc/profile.d/agl-app-framework-binder.sh
+```
+
+Then install the cmake module using your distribution package manager.
+
+* **Debian/Ubuntu**
+
+```bash
+sudo apt-get install agl-cmake-apps-module-bin
+```
+
+* **openSUSE**
+
+```bash
+sudo zypper install agl-cmake-apps-module
+```
+
+* **Fedora**
+
+```bash
+sudo dnf install agl-cmake-apps-module
+```
+Because the helloworld-service binding uses json, the following package has to be installed.
+
+* **Debian/Ubuntu**
+
+```bash
+sudo apt-get install libjson-c-dev
+```
+
+* **openSUSE**
+
+```bash
+sudo zypper install libjson-c-dev
+```
+
+* **Fedora**
+
+```bash
+sudo dnf install libjson-c-dev
+```
+
+Binder and client communicate through HTTP protocol :
+
+* **Debian/Ubuntu**
+
+```bash
+sudo apt-get install agl-libmicrohttpd-dev
+```
+
+* **openSUSE**
+
+```bash
+sudo zypper install agl-libmicrohttpd-dev
+```
+
+* **Fedora**
+
+```bash
+sudo dnf install agl-libmicrohttpd-dev
+```
+
+## Setup
+
+```bash
+git clone https://gerrit.automotivelinux.org/gerrit/admin/repos/apps/agl-service-helloworld
+cd agl-service-helloworld
+```
+
+## Build for AGL
+
+```bash
+#setup your build environement
+. /xdt/sdk/environment-setup-aarch64-agl-linux
+#build your application
+./conf.d/autobuild/agl/autobuild package
+```
+
+## Build for 'native' Linux distros (Fedora, openSUSE, Debian, Ubuntu, ...)
+
+```bash
+./conf.d/autobuild/linux/autobuild package
+```
+
+You can also use binary package from OBS: [opensuse.org/LinuxAutomotive][opensuse.org/LinuxAutomotive]
+
+## Deploy
+
+### AGL
+
+```bash
+export YOUR_BOARD_IP=192.168.1.X
+export APP_NAME=helloworld-service
+scp build/${APP_NAME}.wgt root@${YOUR_BOARD_IP}:/tmp
+ssh root@${YOUR_BOARD_IP} afm-util install /tmp/${APP_NAME}.wgt
+APP_VERSION=$(ssh root@${YOUR_BOARD_IP} afm-util list | grep ${APP_NAME}@ | cut -d"\"" -f4| cut -d"@" -f2)
+ssh root@${YOUR_BOARD_IP} afm-util start ${APP_NAME}@${APP_VERSION}
+```
+
+## TEST
+
+### AGL
+
+```bash
+export YOUR_BOARD_IP=192.168.1.X
+export PORT=8000
+ssh root@${YOUR_BOARD_IP} afb-daemon --ws-client=unix:/run/user/0/apis/ws/helloworld --port=${PORT} --token='x' -v
+
+#On an other terminal
+ssh root@${YOUR_BOARD_IP} afb-client-demo -H 127.0.0.1:${PORT}/api?token=x helloworld ping true
+#or
+curl http://${YOUR_BOARD_IP}:${PORT}/api/helloworld/ping?token=x
+#For a nice display
+curl http://${YOUR_BOARD_IP}:${PORT}/api/helloworld/ping?token=x 2>/dev/null | python -m json.tool
+```
+
+### Native Linux
+
+For native build you need to have tools **afb-daemon**.
+You can build it by your self [app-framework-binder][app-framework-binder], or use binary package from OBS: [opensuse.org/LinuxAutomotive][opensuse.org/LinuxAutomotive]
+
+```bash
+export PORT=8000
+afb-daemon --port=${PORT} --ldpaths=/opt/AGL/helloworld-service/lib/
+
+curl http://localhost:${PORT}/api/helloworld/ping
+#For a nice display
+curl http://localhost:${PORT}/api/helloworld/ping 2>/dev/null | python -m json.tool
+
+```
+
+# Activate authentification security
+
+To test auth just switch the line:
+
+```diff
+ static const struct afb_verb_v2 verbs[]= {
+ /*Without security*/
+- { .verb = "ping" , .session = AFB_SESSION_NONE, .callback = pingSample , .auth = NULL},
++ /*{ .verb = "ping" , .session = AFB_SESSION_NONE, .callback = pingSample , .auth = NULL},*/
+ /*With security "urn:AGL:permission:monitor:public:get"*/
+- /*{ .verb = "ping" , .session = AFB_SESSION_NONE, .callback = pingSample , .auth = &_afb_auths_v2_monitor[1]},*/
++ { .verb = "ping" , .session = AFB_SESSION_NONE, .callback = pingSample , .auth = &_afb_auths_v2_monitor[1]},
+ {NULL}
+ };
+```
+
+And rebuild your application
+
+[opensuse.org/LinuxAutomotive]:https://en.opensuse.org/LinuxAutomotive
+[app-framework-binder]:https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/app-framework-binder
diff --git a/autobuild/agl/autobuild b/autobuild/agl/autobuild
new file mode 100755
index 0000000..db00c1a
--- /dev/null
+++ b/autobuild/agl/autobuild
@@ -0,0 +1,79 @@
+#!/usr/bin/make -f
+# Copyright (C) 2015 - 2018 "IoT.bzh"
+# 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))
+BUILD_DIR := $(abspath $(dir $(THISFILE))/../../build)
+DEST := ${BUILD_DIR}
+
+.PHONY: all clean distclean configure build package help update
+
+all: help
+
+help:
+ @echo "List of targets available:"
+ @echo ""
+ @echo "- all"
+ @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 your ${CMAKE_INSTALL_DIR} 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"
+
+update: configure
+ @cmake --build ${BUILD_DIR} --target autobuild
+
+clean:
+ @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} ${CLEAN_ARGS} clean) || echo Nothing to clean
+
+distclean:
+ @rm -rf ${BUILD_DIR}
+
+configure:
+ @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}
+ @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..)
+
+build: configure
+ @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all
+
+package: build
+ @mkdir -p ${BUILD_DIR}/$@/bin
+ @mkdir -p ${BUILD_DIR}/$@/etc
+ @mkdir -p ${BUILD_DIR}/$@/lib
+ @mkdir -p ${BUILD_DIR}/$@/htdocs
+ @mkdir -p ${BUILD_DIR}/$@/var
+ @cmake --build ${BUILD_DIR} ${PACKAGE_ARGS} --target widget
+ @if [ "${DEST}" != "${BUILD_DIR}" ]; then \
+ mkdir -p ${DEST} && cp ${BUILD_DIR}/*.wgt ${DEST}; \
+ fi
+
+package-test: build
+ @mkdir -p ${BUILD_DIR}/$@/bin
+ @mkdir -p ${BUILD_DIR}/$@/etc
+ @mkdir -p ${BUILD_DIR}/$@/lib
+ @mkdir -p ${BUILD_DIR}/$@/htdocs
+ @mkdir -p ${BUILD_DIR}/$@/var
+ @cmake --build ${BUILD_DIR} ${PACKAGE_ARGS} --target widget
+ @cmake --build ${BUILD_DIR} ${PACKAGE_ARGS} --target test_widget
+ @if [ "${DEST}" != "${BUILD_DIR}" ]; then \
+ mkdir -p ${DEST} && cp ${BUILD_DIR}/*.wgt ${DEST}; \
+ fi
+
+install: build
+ @cmake --build ${BUILD_DIR} ${INSTALL_ARGS} --target install
diff --git a/autobuild/linux/autobuild b/autobuild/linux/autobuild
new file mode 100755
index 0000000..db00c1a
--- /dev/null
+++ b/autobuild/linux/autobuild
@@ -0,0 +1,79 @@
+#!/usr/bin/make -f
+# Copyright (C) 2015 - 2018 "IoT.bzh"
+# 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))
+BUILD_DIR := $(abspath $(dir $(THISFILE))/../../build)
+DEST := ${BUILD_DIR}
+
+.PHONY: all clean distclean configure build package help update
+
+all: help
+
+help:
+ @echo "List of targets available:"
+ @echo ""
+ @echo "- all"
+ @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 your ${CMAKE_INSTALL_DIR} 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"
+
+update: configure
+ @cmake --build ${BUILD_DIR} --target autobuild
+
+clean:
+ @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} ${CLEAN_ARGS} clean) || echo Nothing to clean
+
+distclean:
+ @rm -rf ${BUILD_DIR}
+
+configure:
+ @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}
+ @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..)
+
+build: configure
+ @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all
+
+package: build
+ @mkdir -p ${BUILD_DIR}/$@/bin
+ @mkdir -p ${BUILD_DIR}/$@/etc
+ @mkdir -p ${BUILD_DIR}/$@/lib
+ @mkdir -p ${BUILD_DIR}/$@/htdocs
+ @mkdir -p ${BUILD_DIR}/$@/var
+ @cmake --build ${BUILD_DIR} ${PACKAGE_ARGS} --target widget
+ @if [ "${DEST}" != "${BUILD_DIR}" ]; then \
+ mkdir -p ${DEST} && cp ${BUILD_DIR}/*.wgt ${DEST}; \
+ fi
+
+package-test: build
+ @mkdir -p ${BUILD_DIR}/$@/bin
+ @mkdir -p ${BUILD_DIR}/$@/etc
+ @mkdir -p ${BUILD_DIR}/$@/lib
+ @mkdir -p ${BUILD_DIR}/$@/htdocs
+ @mkdir -p ${BUILD_DIR}/$@/var
+ @cmake --build ${BUILD_DIR} ${PACKAGE_ARGS} --target widget
+ @cmake --build ${BUILD_DIR} ${PACKAGE_ARGS} --target test_widget
+ @if [ "${DEST}" != "${BUILD_DIR}" ]; then \
+ mkdir -p ${DEST} && cp ${BUILD_DIR}/*.wgt ${DEST}; \
+ fi
+
+install: build
+ @cmake --build ${BUILD_DIR} ${INSTALL_ARGS} --target install
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
new file mode 100644
index 0000000..44690c5
--- /dev/null
+++ b/conf.d/cmake/config.cmake
@@ -0,0 +1,183 @@
+###########################################################################
+# Copyright 2015-2019 IoT.bzh
+#
+# author: Fulup Ar Foll <fulup@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.
+###########################################################################
+
+# Project Info
+# ------------------
+set(PROJECT_NAME agl-service-helloworld)
+set(PROJECT_VERSION "1.0")
+set(PROJECT_PRETTY_NAME "Helloworld for AGL")
+set(PROJECT_DESCRIPTION "Provide an AGL Helloworld Binding")
+set(PROJECT_URL "https://gerrit.automotivelinux.org/gerrit/admin/repos/apps/agl-service-helloworld")
+set(PROJECT_ICON "icon.png")
+set(PROJECT_AUTHOR "Iot-Team")
+set(PROJECT_AUTHOR_MAIL "frederic.marec@iot.bzh")
+set(PROJECT_LICENSE "APL2.0")
+set(PROJECT_LANGUAGES,"C")
+set(API_NAME "helloworld")
+
+# Where are stored default templates files from submodule or subtree app-templates in your project tree
+# relative to the root project directory
+set(PROJECT_CMAKE_CONF_DIR "conf.d/cmake")
+
+# Where are stored your external libraries for your project. This is 3rd party library that you don't maintain
+# but used and must be built and linked.
+# set(PROJECT_LIBDIR "libs")
+
+# Where are stored data for your application. Pictures, static resources must be placed in that folder.
+# set(PROJECT_RESOURCES "data")
+
+# Which directories inspect to find CMakeLists.txt target files
+# set(PROJECT_SRC_DIR_PATTERN "*")
+
+# Compilation Mode (DEBUG, RELEASE)
+# ----------------------------------
+set(BUILD_TYPE "RELEASE")
+
+# Kernel selection if needed. You can choose between a
+# mandatory version to impose a minimal version.
+# Or check Kernel minimal version and just print a Warning
+# about missing features and define a preprocessor variable
+# to be used as preprocessor condition in code to disable
+# incompatibles features. Preprocessor define is named
+# KERNEL_MINIMAL_VERSION_OK.
+#
+# NOTE*** FOR NOW IT CHECKS KERNEL Yocto environment and
+# Yocto SDK Kernel version.
+# -----------------------------------------------
+#set (kernel_mandatory_version 4.8)
+#set (kernel_minimal_version 4.8)
+
+# Compiler selection if needed. Impose a minimal version.
+# -----------------------------------------------
+set (gcc_minimal_version 4.9)
+
+# PKG_CONFIG required packages
+# -----------------------------
+set (PKG_REQUIRED_LIST
+ json-c
+ afb-daemon
+)
+
+
+# Print a helper message when every thing is finished
+# ----------------------------------------------------
+if(IS_DIRECTORY $ENV{HOME}/opt/afb-monitoring)
+set(MONITORING_ALIAS "--alias=/monitoring:$ENV{HOME}/opt/afb-monitoring")
+endif()
+set(CLOSING_MESSAGE "Debug from afb-daemon --port=1234 ${MONITORING_ALIAS} --ldpaths=package --workdir=. --roothttp=../htdocs --token= --verbose ")
+set(PACKAGE_MESSAGE "Install widget file using in the target : afm-util install ${PROJECT_NAME}.wgt")
+
+# Customize link option
+# -----------------------------
+#list(APPEND link_libraries -an-option)
+
+# Compilation options definition
+# Use CMake generator expressions to specify only for a specific language
+# Values are prefilled with default options that is currently used.
+# Either separate options with ";", or each options must be quoted separately
+# DO NOT PUT ALL OPTION QUOTED AT ONCE , COMPILATION COULD FAILED !
+# ----------------------------------------------------------------------------
+#set(COMPILE_OPTIONS "-Wall" "-Wextra" "-Wconversion" "-Wno-unused-parameter" "-Wno-sign-compare" "-Wno-sign-conversion" "-Werror=maybe-uninitialized" "-Werror=implicit-function-declaration" "-ffunction-sections" "-fdata-sections" "-fPIC" CACHE STRING "Compilation flags")
+#set(C_COMPILE_OPTIONS "" CACHE STRING "Compilation flags for C language.")
+#set(CXX_COMPILE_OPTIONS "" CACHE STRING "Compilation flags for C++ language.")
+#set(PROFILING_COMPILE_OPTIONS "-g" "-O0" "-pg" "-Wp,-U_FORTIFY_SOURCE" CACHE STRING "Compilation flags for PROFILING build type.")
+#set(DEBUG_COMPILE_OPTIONS "-g" "-ggdb" "-Wp,-U_FORTIFY_SOURCE" CACHE STRING "Compilation flags for DEBUG build type.")
+#set(CCOV_COMPILE_OPTIONS "-g" "-O2" "--coverage" CACHE STRING "Compilation flags for CCOV build type.")
+#set(RELEASE_COMPILE_OPTIONS "-g" "-O2" CACHE STRING "Compilation flags for RELEASE build type.")
+
+# Print a helper message when every thing is finished
+# ----------------------------------------------------
+#set(CLOSING_MESSAGE "")
+#set(PACKAGE_MESSAGE "Install widget file using in the target : afm-util install ${PROJECT_NAME}.wgt")
+
+# (BUG!!!) as PKG_CONFIG_PATH does not work [should be an env variable]
+# ---------------------------------------------------------------------
+set(INSTALL_PREFIX $ENV{HOME}/opt)
+set(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}/lib64/pkgconfig ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
+set(LD_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib64 ${CMAKE_INSTALL_PREFIX}/lib)
+
+# Optional location for config.xml.in
+# -----------------------------------
+set(WIDGET_ICON ${PROJECT_APP_TEMPLATES_DIR}/wgt/${PROJECT_ICON})
+set(WIDGET_CONFIG_TEMPLATE ${CMAKE_SOURCE_DIR}/conf.d/wgt/config.xml.in CACHE PATH "Path to widget config file template (config.xml.in)")
+
+# Mandatory widget Mimetype specification of the main unit
+# --------------------------------------------------------------------------
+# Choose between :
+#- text/html : HTML application,
+# content.src designates the home page of the application
+#
+#- application/vnd.agl.native : AGL compatible native,
+# content.src designates the relative path of the binary.
+#
+# - application/vnd.agl.service: AGL service, content.src is not used.
+#
+#- ***application/x-executable***: Native application,
+# content.src designates the relative path of the binary.
+# For such application, only security setup is made.
+#
+set(WIDGET_TYPE application/vnd.agl.service)
+
+# Mandatory Widget entry point file of the main unit
+# --------------------------------------------------------------
+# This is the file that will be executed, loaded,
+# at launch time by the application framework.
+#
+set(WIDGET_ENTRY_POINT config.xml)
+
+# Optional dependencies order
+# ---------------------------
+#set(EXTRA_DEPENDENCIES_ORDER)
+
+# Optional Extra global include path
+# -----------------------------------
+#set(EXTRA_INCLUDE_DIRS)
+
+# Optional extra libraries
+# -------------------------
+#set(EXTRA_LINK_LIBRARIES)
+
+# Optional force binding installation
+# ------------------------------------
+# set(BINDINGS_INSTALL_PREFIX PrefixPath )
+
+# Optional force binding Linking flag
+# ------------------------------------
+# set(BINDINGS_LINK_FLAG LinkOptions )
+
+# Optional force package prefix generation, like widget
+# -----------------------------------------------------
+# set(PKG_PREFIX DestinationPath)
+
+# Optional Application Framework security token
+# and port use for remote debugging.
+#------------------------------------------------------------
+#set(AFB_TOKEN "" CACHE PATH "Default AFB_TOKEN")
+#set(AFB_REMPORT "1234" CACHE PATH "Default AFB_TOKEN")
+
+# Optional schema validator about now only XML, LUA and JSON
+# are supported
+#------------------------------------------------------------
+#set(LUA_CHECKER "luac" CACHE STRING "LUA compiler")
+#set(XML_CHECKER "xmllint" CACHE STRING "XML linter")
+#set(JSON_CHECKER "json_verify" CACHE STRING "JSON linter")
+
+# This include is mandatory and MUST happens at the end
+# of this file, else you expose you to unexpected behavior
+# -----------------------------------------------------------
+include(CMakeAfbTemplates)
diff --git a/conf.d/packaging/agl-helloworld-service.dsc b/conf.d/packaging/agl-helloworld-service.dsc
new file mode 100644
index 0000000..d883851
--- /dev/null
+++ b/conf.d/packaging/agl-helloworld-service.dsc
@@ -0,0 +1,18 @@
+Format: 1.0
+Source: agl-helloworld-service
+Binary: agl-helloworld-service-bin
+Architecture: any
+Version: 2.0-0
+Maintainer: Iot-Team <secretaria@iot.bzh>
+Standards-Version: 3.8.2
+Homepage: https://github.com/iotbzh/helloworld-service
+Build-Depends: debhelper (>= 5),
+ pkg-config,
+ cmake,
+ gcc,
+ g++,
+ libjson-c-dev ,
+ libsystemd-dev (>= 222),
+ agl-app-framework-binder-dev ,
+ agl-libmicrohttpd-dev (>= 0.9.55)
+Debtransform-Tar: agl-helloworld-service_1.0.orig.tar.gz
diff --git a/conf.d/packaging/agl-helloworld-service.spec b/conf.d/packaging/agl-helloworld-service.spec
new file mode 100644
index 0000000..d495571
--- /dev/null
+++ b/conf.d/packaging/agl-helloworld-service.spec
@@ -0,0 +1,66 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 IoT.bzh
+#
+# author: Iot-Team <secretaria@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.
+###########################################################################
+
+
+Name: agl-helloworld-service
+Version: 1.0
+Release: 1
+Group: AGL
+License: APL2.0
+Summary: Provide an AGL Helloworld Binding
+Url: https://github.com/iotbzh/helloworld-service
+Source0: %{name}_%{version}.orig.tar.gz
+
+BuildRequires: cmake
+BuildRequires: gcc gcc-c++
+BuildRequires: pkgconfig(json-c)
+BuildRequires: pkgconfig(libsystemd) >= 222
+BuildRequires: pkgconfig(afb-daemon)
+BuildRequires: pkgconfig(libmicrohttpd) >= 0.9.55
+
+
+BuildRoot: %{_tmppath}/%{name}-%{version}-build
+
+%define _prefix /opt/AGL/helloworld-service
+%define __cmake cmake
+
+%description
+Provide an AGL Helloworld Binding
+
+%prep
+%setup -q
+
+%build
+%cmake -DCMAKE_INSTALL_PREFIX:PATH=%{_libdir}
+make %{?_smp_mflags}
+
+%install
+CURDIR=$(pwd)
+[ -d build ] && cd build
+make populate
+mkdir -p %{?buildroot}%{_prefix}
+cp -r package/* %{?buildroot}%{_prefix}
+
+cd $CURDIR
+find %{?buildroot}%{_prefix} -type d -exec echo "%dir {}" \;>> pkg_file
+find %{?buildroot}%{_prefix} -type f -exec echo "{}" \;>> pkg_file
+sed -i 's@%{?buildroot}@@g' pkg_file
+
+
+%files -f pkg_file
+%defattr(-,root,root)
diff --git a/conf.d/packaging/debian.agl-helloworld-service.install b/conf.d/packaging/debian.agl-helloworld-service.install
new file mode 100644
index 0000000..5858efd
--- /dev/null
+++ b/conf.d/packaging/debian.agl-helloworld-service.install
@@ -0,0 +1,2 @@
+/opt/AGL/*
+/etc/profile.d/*
diff --git a/conf.d/packaging/debian.changelog b/conf.d/packaging/debian.changelog
new file mode 100644
index 0000000..d668686
--- /dev/null
+++ b/conf.d/packaging/debian.changelog
@@ -0,0 +1,5 @@
+agl-helloworld-service (1.0-0) UNRELEASED; urgency=low
+
+ * init build
+
+ -- Iot-Team <secretaria@iot.bzh> Mon, 25 Dec 2007 10:50:38 +0100
diff --git a/conf.d/packaging/debian.compat b/conf.d/packaging/debian.compat
new file mode 100644
index 0000000..45a4fb7
--- /dev/null
+++ b/conf.d/packaging/debian.compat
@@ -0,0 +1 @@
+8
diff --git a/conf.d/packaging/debian.control b/conf.d/packaging/debian.control
new file mode 100644
index 0000000..31461d6
--- /dev/null
+++ b/conf.d/packaging/debian.control
@@ -0,0 +1,19 @@
+Priority: optional
+Maintainer: Iot-Team <secretaria@iot.bzh>
+Source: agl-helloworld-service
+Build-Depends: debhelper (>= 5),
+ pkg-config,
+ cmake,
+ gcc,
+ g++,
+ libjson-c-dev ,
+ libsystemd-dev (>= 222),
+ agl-app-framework-binder-dev ,
+ agl-libmicrohttpd-dev (>= 0.9.55)
+Standards-Version: 3.8.2
+Homepage: https://github.com/iotbzh/helloworld-service
+
+Package: agl-helloworld-service
+Section: libs
+Architecture: any
+Description: Provide an AGL Helloworld Binding
diff --git a/conf.d/packaging/debian.rules b/conf.d/packaging/debian.rules
new file mode 100644
index 0000000..fd8a335
--- /dev/null
+++ b/conf.d/packaging/debian.rules
@@ -0,0 +1,87 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Uncomment this to turn on verbose mode.
+export DH_VERBOSE=1
+
+# These are used for cross-compiling and for saving the configure script
+# from having to guess our platform (since we know it already)
+DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+ INSTALL_PROGRAM += -s
+endif
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ #
+ touch configure-stamp
+
+build: build-stamp
+build-stamp: configure-stamp
+ dh_testdir
+ mkdir -p build
+ cd build;cmake ../ -DCMAKE_INSTALL_PREFIX:PATH=/opt/AGL/helloworld-service -DCMAKE_INSTALL_LIBDIR:PATH=lib/$(DEB_HOST_MULTIARCH);$(MAKE)
+ #
+ touch build-stamp
+
+clean:
+ #dh_testdir
+ dh_testroot
+ rm -f configure-stamp build-stamp
+ [ ! -f Makefile ] || $(MAKE) distclean
+ #dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_prep
+ dh_installdirs
+ # Add here commands to install the package into debian/tmp
+ mkdir -p debian/tmp/opt/AGL/helloworld-service;cd build;make populate;cp -r package/* ../debian/tmp/opt/AGL/helloworld-service/
+ mkdir -p debian/tmp/etc/profile.d
+ echo '#---------- AGL helloworld-service options Start ---------" ' > debian/tmp/etc/profile.d/AGL_helloworld-service.sh
+ echo '# Object: AGL cmake option for binder/bindings' >> debian/tmp/etc/profile.d/AGL_helloworld-service.sh
+ echo 'export LD_LIBRARY_PATH=/opt/AGL/helloworld-service/lib/$(DEB_HOST_MULTIARCH):$$LD_LIBRARY_PATH' >> debian/tmp/etc/profile.d/AGL_helloworld-service.sh
+ echo 'export LIBRARY_PATH=/opt/AGL/helloworld-service/lib/$(DEB_HOST_MULTIARCH):$$LIBRARY_PATH' >> debian/tmp/etc/profile.d/AGL_helloworld-service.sh
+ echo 'export PATH=/opt/AGL/helloworld-service/bin:$$PATH' >> debian/tmp/etc/profile.d/AGL_helloworld-service.sh
+ echo '#---------- AGL options End ---------' >> debian/tmp/etc/profile.d/AGL_helloworld-service.sh
+ # Move all files in their corresponding package
+ dh_install --list-missing -s --sourcedir=debian/tmp
+ # empty dependency_libs in .la files
+ #sed -i "/dependency_libs/ s/'.*'/''/" `find debian/ -name '*.la'`
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_installman
+ dh_link
+ dh_strip
+ dh_compress
+ dh_fixperms
+ dh_makeshlibs -V
+ dh_installdeb
+ dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in
new file mode 100644
index 0000000..fc31b9b
--- /dev/null
+++ b/conf.d/wgt/config.xml.in
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widget xmlns="http://www.w3.org/ns/widgets" id="@PROJECT_NAME@" version="@PROJECT_VERSION@">
+ <name>@PROJECT_NAME@</name>
+ <icon src="@PROJECT_ICON@"/>
+ <content src="@WIDGET_ENTRY_POINT@" type="@WIDGET_TYPE@"/>
+ <description>@PROJECT_DESCRIPTION@</description>
+ <author>@PROJECT_AUTHOR@ &lt;@PROJECT_AUTHOR_MAIL@&gt;</author>
+ <license>@PROJECT_LICENSE@</license>
+ <feature name="urn:AGL:widget:provided-api">
+ <param name="helloworld" value="ws" />
+ </feature>
+ <feature name="urn:AGL:widget:required-api">
+ <param name="lib/afb-helloworld-skeleton.so" value="local" />
+ </feature>
+</widget>
diff --git a/helloworld-skeleton/CMakeLists.txt b/helloworld-skeleton/CMakeLists.txt
new file mode 100644
index 0000000..9736e50
--- /dev/null
+++ b/helloworld-skeleton/CMakeLists.txt
@@ -0,0 +1,27 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 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.
+###########################################################################
+
+# Add target to project dependency list
+PROJECT_TARGET_ADD(helloworld-skeleton)
+ # Define project Targets
+ ADD_LIBRARY(${TARGET_NAME} MODULE helloworld-service-binding.c)
+
+ # Binder exposes a unique public entry point
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ PREFIX "afb-"
+ LABELS "BINDING"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
diff --git a/helloworld-skeleton/helloworld-service-binding.c b/helloworld-skeleton/helloworld-service-binding.c
new file mode 100644
index 0000000..a39da57
--- /dev/null
+++ b/helloworld-skeleton/helloworld-service-binding.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2016-2018 "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.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <json-c/json.h>
+
+#define AFB_BINDING_VERSION 3
+#include <afb/afb-binding.h>
+
+static void pingSample(afb_req_t request)
+{
+ static int pingcount = 0;
+
+ afb_req_success_f(request, json_object_new_int(pingcount), "Ping count = %d", pingcount);
+
+ AFB_API_NOTICE(afbBindingV3root, "Verbosity macro at level notice invoked at ping invocation count = %d", pingcount);
+
+ pingcount++;
+}
+
+// testArgsSample - return success only if argument is set to {"cezam": "open"}
+static void testArgsSample(afb_req_t request)
+{
+ json_object *tmpJ;
+ json_object *res = json_object_new_object();
+ json_object *queryJ = afb_req_json(request);
+
+ json_bool success = json_object_object_get_ex(queryJ, "cezam", &tmpJ);
+ if (!success) {
+ afb_req_fail_f(request, "ERROR", "key cezam not found in '%s'", json_object_get_string(queryJ));
+ return;
+ }
+
+ if (json_object_get_type(tmpJ) != json_type_string) {
+ afb_req_fail(request, "ERROR", "key cezam not a string");
+ return;
+ }
+
+ if (strncmp(json_object_get_string(tmpJ), "open", 4) == 0) {
+ json_object_object_add(res, "code", json_object_new_int(123456789));
+ afb_req_success(request, res, NULL);
+ return;
+ }
+
+ afb_req_fail_f(request, "ERROR", "value of cezam (%s) is not the expected one.",
+ json_object_get_string(queryJ));
+}
+
+static const struct afb_auth _afb_auths_v2_monitor[] = {
+ {.type = afb_auth_Permission, .text = "urn:AGL:permission:monitor:public:set"},
+ {.type = afb_auth_Permission, .text = "urn:AGL:permission:monitor:public:get"},
+ {.type = afb_auth_Or, .first = &_afb_auths_v2_monitor[1], .next = &_afb_auths_v2_monitor[0]}
+};
+
+static const afb_verb_t verbs[] = {
+ /*Without security*/
+ {.verb = "ping", .session = AFB_SESSION_NONE, .callback = pingSample, .auth = NULL},
+
+ /*With security "urn:AGL:permission:monitor:public:get"*/
+ /*{ .verb = "ping" , .session = AFB_SESSION_NONE, .callback = pingSample , .auth = &_afb_auths_v2_monitor[1]},*/
+
+ {.verb = "testargs", .session = AFB_SESSION_NONE, .callback = testArgsSample, .auth = NULL},
+ {NULL}
+};
+
+const afb_binding_t afbBindingExport = {
+ .api = "helloworld",
+ .specification = NULL,
+ .verbs = verbs,
+ .preinit = NULL,
+ .init = NULL,
+ .onevent = NULL,
+ .userdata = NULL,
+ .provide_class = NULL,
+ .require_class = NULL,
+ .require_api = NULL,
+ .noconcurrency = 0
+};
diff --git a/helloworld-subscribe-event/CMakeLists.txt b/helloworld-subscribe-event/CMakeLists.txt
new file mode 100644
index 0000000..131e8d4
--- /dev/null
+++ b/helloworld-subscribe-event/CMakeLists.txt
@@ -0,0 +1,28 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 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.
+###########################################################################
+
+# Add target to project dependency list
+PROJECT_TARGET_ADD(helloworld-subscribe-event)
+ # Define project Targets
+ ADD_LIBRARY(${TARGET_NAME} MODULE helloworld-service-binding.c)
+
+ # Binder exposes a unique public entry point
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ PREFIX "afb-"
+ LABELS "BINDING"
+ LINK_FLAGS ${BINDINGS_LINK_FLAG}
+ OUTPUT_NAME ${TARGET_NAME}
+ )
diff --git a/helloworld-subscribe-event/helloworld-service-binding.c b/helloworld-subscribe-event/helloworld-service-binding.c
new file mode 100644
index 0000000..ce525e7
--- /dev/null
+++ b/helloworld-subscribe-event/helloworld-service-binding.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2016-2018 "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.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <json-c/json.h>
+
+#define AFB_BINDING_VERSION 3
+#include <afb/afb-binding.h>
+
+static afb_event_t event;
+
+static void pingSample(afb_req_t request)
+{
+ static int pingcount = 0;
+ int listeners = 0;
+
+ if(afb_event_is_valid(event))
+ listeners = afb_event_push(event, json_object_new_int(pingcount));
+
+ afb_req_success_f(request, json_object_new_int(pingcount), "Ping count = %d, Event listeners = %d", pingcount, listeners);
+
+ AFB_API_NOTICE(afbBindingV3root, "Verbosity macro at level notice invoked at ping invocation, count = %d, event listeners = %d", pingcount, listeners);
+
+ pingcount++;
+}
+
+static void subscribeSample(afb_req_t request)
+{
+ // Event not valid ? then creating one.
+ if(! afb_event_is_valid(event))
+ event = afb_api_make_event(request->api, "PingCount");
+
+
+ if(afb_req_subscribe(request, event) < 0) {
+ afb_req_fail(request, "Error", "Subscription operation failed");
+ return;
+ }
+
+ afb_req_success(request, NULL, NULL);
+
+ AFB_API_NOTICE(request->api, "Verbosity macro at level notice invoked at subscribe invocation");
+}
+
+static void unsubscribeSample(afb_req_t request)
+{
+ if(! afb_event_is_valid(event)) {
+ afb_req_fail(request, "Invalid", "Event not valid");
+ return;
+ }
+
+ if(afb_req_unsubscribe(request, event) < 0) {
+ afb_req_fail(request, "Error", "Unsubscription operation failed");
+ return;
+ }
+
+ afb_req_success(request, NULL, NULL);
+ AFB_API_NOTICE(request->api, "Verbosity macro at level notice invoked at unsubscribe invocation");
+}
+
+// testArgsSample - return success only if argument is set to {"cezam": "open"}
+static void testArgsSample(afb_req_t request)
+{
+ json_object *tmpJ;
+ json_object *res = json_object_new_object();
+ json_object *queryJ = afb_req_json(request);
+
+ json_bool success = json_object_object_get_ex(queryJ, "cezam", &tmpJ);
+ if (!success) {
+ afb_req_fail_f(request, "ERROR", "key cezam not found in '%s'", json_object_get_string(queryJ));
+ return;
+ }
+
+ if (json_object_get_type(tmpJ) != json_type_string) {
+ afb_req_fail(request, "ERROR", "key cezam not a string");
+ return;
+ }
+
+ if (strncmp(json_object_get_string(tmpJ), "open", 4) == 0) {
+ json_object_object_add(res, "code", json_object_new_int(123456789));
+ afb_req_success(request, res, NULL);
+ return;
+ }
+
+ afb_req_fail_f(request, "ERROR", "value of cezam (%s) is not the expected one.",
+ json_object_get_string(queryJ));
+}
+
+static const struct afb_auth _afb_auths_monitor[] = {
+ {.type = afb_auth_Permission, .text = "urn:AGL:permission:monitor:public:set"},
+ {.type = afb_auth_Permission, .text = "urn:AGL:permission:monitor:public:get"},
+ {.type = afb_auth_Or, .first = &_afb_auths_monitor[1], .next = &_afb_auths_monitor[0]}
+};
+
+static const afb_verb_t verbs[] = {
+ /*Without security*/
+ {.verb = "ping", .session = AFB_SESSION_NONE, .callback = pingSample, .auth = NULL},
+
+ /*With security "urn:AGL:permission:monitor:public:get"*/
+ /*{ .verb = "ping" , .session = AFB_SESSION_NONE, .callback = pingSample , .auth = &_afb_auths_monitor[1]},*/
+
+ {.verb = "subscribe", .session = AFB_SESSION_NONE, .callback = subscribeSample, .auth = NULL},
+ {.verb = "unsubscribe", .session = AFB_SESSION_NONE, .callback = unsubscribeSample, .auth = NULL},
+ {.verb = "testargs", .session = AFB_SESSION_NONE, .callback = testArgsSample, .auth = NULL},
+ {NULL}
+};
+
+const afb_binding_t afbBindingExport = {
+ .api = "helloworld-event",
+ .specification = NULL,
+ .verbs = verbs,
+ .preinit = NULL,
+ .init = NULL,
+ .onevent = NULL,
+ .userdata = NULL,
+ .provide_class = NULL,
+ .require_class = NULL,
+ .require_api = NULL,
+ .noconcurrency = 0
+};
diff --git a/htdocs/AFB-websock.js b/htdocs/AFB-websock.js
new file mode 100644
index 0000000..99ab3b8
--- /dev/null
+++ b/htdocs/AFB-websock.js
@@ -0,0 +1,177 @@
+var urlws;
+var urlhttp;
+
+AFB = function(base, initialtoken){
+
+urlws = "ws://"+window.location.host+"/"+base;
+urlhttp = "http://"+window.location.host+"/"+base;
+
+/*********************************************/
+/**** ****/
+/**** AFB_context ****/
+/**** ****/
+/*********************************************/
+var AFB_context;
+{
+ var UUID = undefined;
+ var TOKEN = initialtoken;
+
+ var context = function(token, uuid) {
+ this.token = token;
+ this.uuid = uuid;
+ }
+
+ context.prototype = {
+ get token() {return TOKEN;},
+ set token(tok) {if(tok) TOKEN=tok;},
+ get uuid() {return UUID;},
+ set uuid(id) {if(id) UUID=id;}
+ };
+
+ AFB_context = new context();
+}
+/*********************************************/
+/**** ****/
+/**** AFB_websocket ****/
+/**** ****/
+/*********************************************/
+var AFB_websocket;
+{
+ var CALL = 2;
+ var RETOK = 3;
+ var RETERR = 4;
+ var EVENT = 5;
+
+ var PROTO1 = "x-afb-ws-json1";
+
+ AFB_websocket = function(onopen, onabort) {
+ var u = urlws;
+ if (AFB_context.token) {
+ u = u + '?x-afb-token=' + AFB_context.token;
+ if (AFB_context.uuid)
+ u = u + '&x-afb-uuid=' + AFB_context.uuid;
+ }
+ this.ws = new WebSocket(u, [ PROTO1 ]);
+ this.pendings = {};
+ this.awaitens = {};
+ this.counter = 0;
+ this.ws.onopen = onopen.bind(this);
+ this.ws.onerror = onerror.bind(this);
+ this.ws.onclose = onclose.bind(this);
+ this.ws.onmessage = onmessage.bind(this);
+ this.onopen = onopen;
+ this.onabort = onabort;
+ this.onclose = onabort;
+ }
+
+ function onerror(event) {
+ var f = this.onabort;
+ if (f) {
+ delete this.onopen;
+ delete this.onabort;
+ f && f(this);
+ }
+ this.onerror && this.onerror(this);
+ }
+
+ function onopen(event) {
+ var f = this.onopen;
+ delete this.onopen;
+ delete this.onabort;
+ f && f(this);
+ }
+
+ function onclose(event) {
+ for (var id in this.pendings) {
+ var ferr = this.pendings[id].onerror;
+ ferr && ferr(null, this);
+ }
+ this.pendings = {};
+ this.onclose && this.onclose();
+ }
+
+ function fire(awaitens, name, data) {
+ var a = awaitens[name];
+ if (a)
+ a.forEach(function(handler){handler(data);});
+ var i = name.indexOf("/");
+ if (i >= 0) {
+ a = awaitens[name.substring(0,i)];
+ if (a)
+ a.forEach(function(handler){handler(data);});
+ }
+ a = awaitens["*"];
+ if (a)
+ a.forEach(function(handler){handler(data);});
+ }
+
+ function reply(pendings, id, ans, offset) {
+ if (id in pendings) {
+ var p = pendings[id];
+ delete pendings[id];
+ var f = p[offset];
+ f(ans);
+ }
+ }
+
+ function onmessage(event) {
+ var obj = JSON.parse(event.data);
+ var code = obj[0];
+ var id = obj[1];
+ var ans = obj[2];
+ AFB_context.token = obj[3];
+ switch (code) {
+ case RETOK:
+ reply(this.pendings, id, ans, 0);
+ break;
+ case RETERR:
+ reply(this.pendings, id, ans, 1);
+ break;
+ case EVENT:
+ default:
+ fire(this.awaitens, id, ans);
+ break;
+ }
+ }
+
+ function close() {
+ this.ws.close();
+ this.onabort();
+ }
+
+ function call(method, request) {
+ return new Promise((function(resolve, reject){
+ var id, arr;
+ do {
+ id = String(this.counter = 4095 & (this.counter + 1));
+ } while (id in this.pendings);
+ this.pendings[id] = [ resolve, reject ];
+ arr = [CALL, id, method, request ];
+ if (AFB_context.token) arr.push(AFB_context.token);
+ this.ws.send(JSON.stringify(arr));
+ }).bind(this));
+ }
+
+ function onevent(name, handler) {
+ var id = name;
+ var list = this.awaitens[id] || (this.awaitens[id] = []);
+ list.push(handler);
+ }
+
+ AFB_websocket.prototype = {
+ close: close,
+ call: call,
+ onevent: onevent
+ };
+}
+/*********************************************/
+/**** ****/
+/**** ****/
+/**** ****/
+/*********************************************/
+return {
+ context: AFB_context,
+ ws: AFB_websocket
+};
+};
+
diff --git a/htdocs/CMakeLists.txt b/htdocs/CMakeLists.txt
new file mode 100644
index 0000000..7aa0ce1
--- /dev/null
+++ b/htdocs/CMakeLists.txt
@@ -0,0 +1,33 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 IoT.bzh
+#
+# author: Fulup Ar Foll <fulup@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.
+###########################################################################
+
+
+
+##################################################
+# HTML Testing Files
+##################################################
+PROJECT_TARGET_ADD(htdocs)
+
+ file(GLOB SOURCE_FILES "*.html" "*.js" "*.jpg" "*.css" "assets")
+
+ add_input_files("${SOURCE_FILES}")
+
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ LABELS "HTDOCS"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
diff --git a/htdocs/assets/background_iot_bzh_light.jpg b/htdocs/assets/background_iot_bzh_light.jpg
new file mode 100644
index 0000000..f47d2ee
--- /dev/null
+++ b/htdocs/assets/background_iot_bzh_light.jpg
Binary files differ
diff --git a/htdocs/assets/favicon.ico b/htdocs/assets/favicon.ico
new file mode 100644
index 0000000..eeb7ab7
--- /dev/null
+++ b/htdocs/assets/favicon.ico
Binary files differ
diff --git a/htdocs/assets/iot-bzh-logo-small.png b/htdocs/assets/iot-bzh-logo-small.png
new file mode 100644
index 0000000..2c3b2ae
--- /dev/null
+++ b/htdocs/assets/iot-bzh-logo-small.png
Binary files differ
diff --git a/htdocs/index.html b/htdocs/index.html
new file mode 100644
index 0000000..ffefe20
--- /dev/null
+++ b/htdocs/index.html
@@ -0,0 +1,49 @@
+<html>
+
+<head>
+ <title>Simple Helloworld binding Test</title>
+ <link rel="stylesheet" href="iotbzh-Binding.css">
+ <link rel="icon" type="image/x-icon" href="assets/favicon.ico">
+ <script type="text/javascript" src="AFB-websock.js"></script>
+ <script type="text/javascript" src="iotbzh-Binding.js"></script>
+</head>
+
+<body class="page-content" onload="init()">
+
+ <img src="assets/iot-bzh-logo-small.png">
+
+ <h1>Simple Helloworld binding Test</h1>
+
+ <button id="connected" onclick="init()">Binder WS Fail</button>
+ <button id="mnitoring" onclick="window.open('/monitoring/monitor.html','_monitor_ctl')">Debug/Monitoring</a></button>
+
+ <br><br>
+
+ <div>
+ <button onclick="callbinder('helloworld','ping' ,{args:{'var1':1234, 'var2':'Test ping'}});">Send ping</button></li>
+
+ <button onclick="callbinder('helloworld','testargs' ,{'cezam': 'open'});">Send testargs OK</button></li>
+
+ <button onclick="callbinder('helloworld','testargs' ,{'foo':'toto'});">Send testargs Error</button></li>
+
+ <button onclick="callbinder('unknown_api','ping' ,{});">Send unknown Api</button></li>
+
+ <button onclick="callbinder('helloworld','unknown_verb', {});">Send unknown verb</button></li>
+ </div>
+
+ <br>
+
+ <div id="main" style="visibility:hidden">
+ <ol>
+ <li>Question
+ <pre id="question"></pre>
+ </li>
+ <li>Response
+ <pre id="output"></pre>
+ </li>
+ <li>Events:
+ <pre id="outevt"></pre>
+ </li>
+ </ol>
+ </div>
+</body>
diff --git a/htdocs/iotbzh-Binding.css b/htdocs/iotbzh-Binding.css
new file mode 100644
index 0000000..96a04cc
--- /dev/null
+++ b/htdocs/iotbzh-Binding.css
@@ -0,0 +1,59 @@
+body.page-content {
+ height: 100%;
+ width: auto;
+ margin-top: 20px;
+ background: url("assets/background_iot_bzh_light.jpg") 0 0 no-repeat;
+ background-size: cover;
+ background-position: center;
+}
+
+img {
+ float: right;
+}
+
+#question,
+#output,
+#outevt {
+ white-space: pre-wrap;
+}
+
+button {
+ margin-right: 10px;
+ padding: 6px 8px;
+ font-size: large;
+}
+
+pre {
+ outline: 1px solid #ccc;
+ padding: 5px;
+ margin: 5px;
+ background-color: white;
+ opacity: 0.85;
+ min-height: 5pc;
+ max-height: 10pc;
+ overflow: auto;
+}
+
+pre#output {
+ max-height: 30pc;
+}
+
+.string {
+ color: green;
+}
+
+.number {
+ color: darkorange;
+}
+
+.boolean {
+ color: blue;
+}
+
+.null {
+ color: magenta;
+}
+
+.key {
+ color: red;
+}
diff --git a/htdocs/iotbzh-Binding.js b/htdocs/iotbzh-Binding.js
new file mode 100644
index 0000000..d2d870c
--- /dev/null
+++ b/htdocs/iotbzh-Binding.js
@@ -0,0 +1,104 @@
+var afb = new AFB("api", "mysecret");
+var ws;
+var evtidx = 0;
+var count = 0;
+
+
+//**********************************************
+// Logger
+//**********************************************
+var log = {
+ command: function (api, verb, query) {
+ console.log("subscribe api=" + api + " verb=" + verb + " query=", query);
+ var question = urlws + "/" + api + "/" + verb + "?query=" + JSON.stringify(query);
+ log._write("question", count + ": " + log.syntaxHighlight(question));
+ },
+
+ event: function (obj) {
+ console.log("gotevent:" + JSON.stringify(obj));
+ log._write("outevt", (evtidx++) + ": " + JSON.stringify(obj));
+ },
+
+ reply: function (obj) {
+ console.log("replyok:" + JSON.stringify(obj));
+ log._write("output", count + ": OK: " + log.syntaxHighlight(obj));
+ },
+
+ error: function (obj) {
+ console.log("replyerr:" + JSON.stringify(obj));
+ log._write("output", count + ": ERROR: " + log.syntaxHighlight(obj));
+ },
+
+ _write: function (element, msg) {
+ var el = document.getElementById(element);
+ el.innerHTML += msg + '\n';
+
+ // auto scroll down
+ setTimeout(function () {
+ el.scrollTop = el.scrollHeight;
+ }, 100);
+ },
+
+ syntaxHighlight: function (json) {
+ if (typeof json !== 'string') {
+ json = JSON.stringify(json, undefined, 2);
+ }
+ json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
+ var cls = 'number';
+ if (/^"/.test(match)) {
+ if (/:$/.test(match)) {
+ cls = 'key';
+ } else {
+ cls = 'string';
+ }
+ } else if (/true|false/.test(match)) {
+ cls = 'boolean';
+ } else if (/null/.test(match)) {
+ cls = 'null';
+ }
+ return '<span class="' + cls + '">' + match + '</span>';
+ });
+ },
+};
+
+//**********************************************
+// Generic function to call binder
+//***********************************************
+function callbinder(api, verb, query) {
+ log.command(api, verb, query);
+
+ // ws.call return a Promise
+ return ws.call(api + "/" + verb, query)
+ .then(function (res) {
+ log.reply(res);
+ count++;
+ return res;
+ })
+ .catch(function (err) {
+ log.reply(err);
+ count++;
+ throw err;
+ });
+}
+
+//**********************************************
+// Init - establish Websocket connection
+//**********************************************
+function init(elemid, api, verb, query) {
+
+ function onopen() {
+ document.getElementById("main").style.visibility = "visible";
+ document.getElementById("connected").innerHTML = "Binder WS Active";
+ document.getElementById("connected").style.background = "lightgreen";
+ ws.onevent("*", log.event);
+ }
+
+ function onabort() {
+ document.getElementById("main").style.visibility = "hidden";
+ document.getElementById("connected").innerHTML = "Connected Closed";
+ document.getElementById("connected").style.background = "red";
+ }
+
+ ws = new afb.ws(onopen, onabort);
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..d75b1c9
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,27 @@
+###########################################################################
+# Copyright 2015 - 2018 IoT.bzh
+#
+# 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.
+###########################################################################
+
+
+# Include any directory not starting with _
+# -----------------------------------------------------
+PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN})
+
+ADD_TEST(NAME AFB-TEST_TESTS
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ COMMAND afm-test "${CMAKE_BINARY_DIR}/package" "${CMAKE_BINARY_DIR}/package-test" SERVICE
+)
diff --git a/test/etc/CMakeLists.txt b/test/etc/CMakeLists.txt
new file mode 100644
index 0000000..f1f095e
--- /dev/null
+++ b/test/etc/CMakeLists.txt
@@ -0,0 +1,31 @@
+###########################################################################
+# Copyright 2015 - 2018 IoT.bzh
+#
+# 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.
+###########################################################################
+
+##################################################
+# Helloworld test configuration files
+##################################################
+PROJECT_TARGET_ADD(helloworld-config)
+
+ file(GLOB CONF_FILES "*.json")
+
+ add_input_files("${CONF_FILES}")
+
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ LABELS "TEST-CONFIG"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
diff --git a/test/etc/aft-agl-helloworld.json b/test/etc/aft-agl-helloworld.json
new file mode 100644
index 0000000..2f51b2a
--- /dev/null
+++ b/test/etc/aft-agl-helloworld.json
@@ -0,0 +1,22 @@
+{
+ "id": "http://iot.bzh/download/public/schema/json/ctl-schema.json#",
+ "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json#",
+ "metadata": {
+ "uid": "Hello_Test",
+ "version": "1.0",
+ "api": "aft-agl-helloworld",
+ "info": "Test part of Helloworld service binding",
+ "require": [
+ "helloworld"
+ ]
+ },
+ "testVerb": {
+ "uid": "testing-hello",
+ "info": "Launch the tests against hello api",
+ "action": "lua://AFT#_launch_test",
+ "args": {
+ "trace": "hello",
+ "files": ["helloworld.lua"]
+ }
+ }
+} \ No newline at end of file
diff --git a/test/tests/CMakeLists.txt b/test/tests/CMakeLists.txt
new file mode 100644
index 0000000..f9278ac
--- /dev/null
+++ b/test/tests/CMakeLists.txt
@@ -0,0 +1,31 @@
+###########################################################################
+# Copyright 2015 - 2018 IoT.bzh
+#
+# 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.
+###########################################################################
+
+
+##################################################
+# Hellowolrd Lua Scripts
+##################################################
+PROJECT_TARGET_ADD(test-files)
+
+ file(GLOB LUA_FILES "*.lua")
+ add_input_files("${LUA_FILES}")
+
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ LABELS "TEST-DATA"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
diff --git a/test/tests/helloworld.lua b/test/tests/helloworld.lua
new file mode 100644
index 0000000..556cb8b
--- /dev/null
+++ b/test/tests/helloworld.lua
@@ -0,0 +1,38 @@
+--[[
+ Copyright (C) 2018 "IoT.bzh"
+ 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.
+
+
+ NOTE: strict mode: every global variables should be prefixed by '_'
+--]]
+
+function _callback(responseJ)
+ _AFT.assertStrContains(responseJ.request.status, "success")
+end
+
+function _callbackError(responseJ)
+ _AFT.assertStrContains(responseJ.request.info, "verb pingfail unknown within api helloworld")
+end
+
+_AFT.testVerbStatusSuccess('testPingSuccess','helloworld', 'ping', {})
+_AFT.setBefore("testPingSuccess",function() print("~~~~~ Begin testPingSuccess ~~~~~") end)
+_AFT.setAfter("testPingSuccess",function() print("~~~~~ End testPingSuccess ~~~~~") end)
+
+_AFT.testVerbResponseEquals('testPingSuccessAndResponse','helloworld', 'ping', {}, "Ping count = %d")
+_AFT.testVerbCb('testPingSuccessCallback','helloworld', 'ping', {}, _callback)
+
+_AFT.testVerbStatusError('testPingError', 'helloworld', 'pingfail', {})
+_AFT.testVerbResponseEqualsError('testPingErrorAndResponse', 'helloworld', 'pingfail', {}, "Ping Binder Daemon succeeds")
+_AFT.testVerbCbError('testPingErrorCallback', 'helloworld', 'pingfail', {}, _callbackError) \ No newline at end of file