From abb024ffcbf800a51dc7a7c513611141d82b2a3b Mon Sep 17 00:00:00 2001 From: "Li, Xiaoming" Date: Mon, 22 Jun 2020 11:07:30 +0800 Subject: Fix test folder structure The test folder should rest in the root of a package. Bug-AGL: SPEC-2807 Change-Id: I6e44e68f40aaf58d2c59973e6a2413947dcb4eaf Signed-off-by: Li, Xiaoming --- CMakeLists.txt | 22 +++++ LICENSE | 54 ++++++++++++ autobuild/agl/autobuild | 127 ++++++++++++++++++++++++++++ autobuild/linux/autobuild | 127 ++++++++++++++++++++++++++++ binding/CMakeLists.txt | 20 ++++- binding/LICENSE | 54 ------------ binding/autobuild/agl/autobuild | 127 ---------------------------- binding/autobuild/linux/autobuild | 127 ---------------------------- binding/binding-api.c | 65 ++++++++++++++ binding/binding-api.h | 49 +++++++++++ binding/conf.d/cmake/config.cmake | 153 --------------------------------- binding/conf.d/wgt/config.xml.in | 28 ------- binding/src/CMakeLists.txt | 36 -------- binding/src/binding-api.c | 65 -------------- binding/src/binding-api.h | 49 ----------- binding/src/verbs.cpp | 172 -------------------------------------- binding/verbs.cpp | 172 ++++++++++++++++++++++++++++++++++++++ conf.d/cmake/config.cmake | 153 +++++++++++++++++++++++++++++++++ conf.d/wgt/config.xml.in | 28 +++++++ 19 files changed, 814 insertions(+), 814 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 autobuild/agl/autobuild create mode 100644 autobuild/linux/autobuild delete mode 100644 binding/LICENSE delete mode 100755 binding/autobuild/agl/autobuild delete mode 100755 binding/autobuild/linux/autobuild create mode 100644 binding/binding-api.c create mode 100644 binding/binding-api.h delete mode 100755 binding/conf.d/cmake/config.cmake delete mode 100644 binding/conf.d/wgt/config.xml.in delete mode 100644 binding/src/CMakeLists.txt delete mode 100644 binding/src/binding-api.c delete mode 100644 binding/src/binding-api.h delete mode 100644 binding/src/verbs.cpp create mode 100644 binding/verbs.cpp create mode 100644 conf.d/cmake/config.cmake create mode 100644 conf.d/wgt/config.xml.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..459773a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +########################################################################### +# Copyright 2015, 2016, 2017 IoT.bzh +# +# author: Romain Forlot +# +# 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.3) + +include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake) + 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/autobuild/agl/autobuild b/autobuild/agl/autobuild new file mode 100644 index 0000000..a7c25ae --- /dev/null +++ b/autobuild/agl/autobuild @@ -0,0 +1,127 @@ +#!/usr/bin/make -f +# Copyright (C) 2015 - 2018 "IoT.bzh" +# Author "Romain Forlot" +# +# 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) +BUILD_DIR_TEST := $(abspath $(dir $(THISFILE))/../../build-test) +BUILD_DIR_DEBUG := $(abspath $(dir $(THISFILE))/../../build-debug) +BUILD_DIR_COVERAGE := $(abspath $(dir $(THISFILE))/../../build-coverage) +DEST := ${BUILD_DIR} + +.PHONY: all clean distclean configure build package help configure-debug configure-coverage build-debug build-coverage package-test package-debug package-coverage package-debug package-all + +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" + +clean: + @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} ${CLEAN_ARGS} clean) || echo Nothing to clean + +distclean: + @[ -d ${DEST} ] && find ${DEST} -name "*.wgt" -delete + @rm -rf ${BUILD_DIR} + +configure: + @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} + @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) + +configure-test: + @[ -d ${BUILD_DIR_TEST} ] || mkdir -p ${BUILD_DIR_TEST} + @[ -f ${BUILD_DIR_TEST}/Makefile ] || (cd ${BUILD_DIR_TEST} && cmake ${CONFIGURE_ARGS} ..) + +configure-debug: + @[ -d ${BUILD_DIR_DEBUG} ] || mkdir -p ${BUILD_DIR_DEBUG} + @[ -f ${BUILD_DIR_DEBUG}/Makefile ] || (cd ${BUILD_DIR_DEBUG} && cmake ${CONFIGURE_ARGS} ..) + +configure-coverage: + @[ -d ${BUILD_DIR_COVERAGE} ] || mkdir -p ${BUILD_DIR_COVERAGE} + @[ -f ${BUILD_DIR_COVERAGE}/Makefile ] || (cd ${BUILD_DIR_COVERAGE} && cmake ${CONFIGURE_ARGS} ..) + +build: configure + @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all + +build-test: configure-test + @cmake --build ${BUILD_DIR_TEST} ${BUILD_ARGS} --target all + +build-debug: configure-debug + @cmake --build ${BUILD_DIR_DEBUG} ${BUILD_ARGS} --target all + +build-coverage: configure-coverage + @cmake --build ${BUILD_DIR_COVERAGE} ${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-test + @mkdir -p ${BUILD_DIR_TEST}/package/bin + @mkdir -p ${BUILD_DIR_TEST}/package/etc + @mkdir -p ${BUILD_DIR_TEST}/package/lib + @mkdir -p ${BUILD_DIR_TEST}/package/htdocs + @mkdir -p ${BUILD_DIR_TEST}/package/var + @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target widget + @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target test_widget + @if [ "${DEST}" != "${BUILD_DIR_TEST}" ]; then \ + mkdir -p ${DEST} && cp ${BUILD_DIR_TEST}/*.wgt ${DEST}; \ + fi + +package-test: build-test + @mkdir -p ${BUILD_DIR_DEBUG}/package/bin + @mkdir -p ${BUILD_DIR_DEBUG}/package/etc + @mkdir -p ${BUILD_DIR_DEBUG}/package/lib + @mkdir -p ${BUILD_DIR_DEBUG}/package/htdocs + @mkdir -p ${BUILD_DIR_DEBUG}/package/var + @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target widget + @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target test_widget + @if [ "${DEST}" != "${BUILD_DIR_DEBUG}" ]; then \ + mkdir -p ${DEST} && cp ${BUILD_DIR_DEBUG}/*.wgt ${DEST}; \ + fi + +package-coverage: build-coverage + @mkdir -p ${BUILD_DIR_COVERAGE}/package/bin + @mkdir -p ${BUILD_DIR_COVERAGE}/package/etc + @mkdir -p ${BUILD_DIR_COVERAGE}/package/lib + @mkdir -p ${BUILD_DIR_COVERAGE}/package/htdocs + @mkdir -p ${BUILD_DIR_COVERAGE}/package/var + @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target widget + @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target test_widget + @if [ "${DEST}" != "${BUILD_DIR_COVERAGE}" ]; then \ + mkdir -p ${DEST} && cp ${BUILD_DIR_COVERAGE}/*.wgt ${DEST}; \ + fi + +package-all: package package-test package-coverage package-debug + +install: build + @cmake --build ${BUILD_DIR} ${INSTALL_ARGS} --target install diff --git a/autobuild/linux/autobuild b/autobuild/linux/autobuild new file mode 100644 index 0000000..a7c25ae --- /dev/null +++ b/autobuild/linux/autobuild @@ -0,0 +1,127 @@ +#!/usr/bin/make -f +# Copyright (C) 2015 - 2018 "IoT.bzh" +# Author "Romain Forlot" +# +# 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) +BUILD_DIR_TEST := $(abspath $(dir $(THISFILE))/../../build-test) +BUILD_DIR_DEBUG := $(abspath $(dir $(THISFILE))/../../build-debug) +BUILD_DIR_COVERAGE := $(abspath $(dir $(THISFILE))/../../build-coverage) +DEST := ${BUILD_DIR} + +.PHONY: all clean distclean configure build package help configure-debug configure-coverage build-debug build-coverage package-test package-debug package-coverage package-debug package-all + +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" + +clean: + @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} ${CLEAN_ARGS} clean) || echo Nothing to clean + +distclean: + @[ -d ${DEST} ] && find ${DEST} -name "*.wgt" -delete + @rm -rf ${BUILD_DIR} + +configure: + @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} + @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) + +configure-test: + @[ -d ${BUILD_DIR_TEST} ] || mkdir -p ${BUILD_DIR_TEST} + @[ -f ${BUILD_DIR_TEST}/Makefile ] || (cd ${BUILD_DIR_TEST} && cmake ${CONFIGURE_ARGS} ..) + +configure-debug: + @[ -d ${BUILD_DIR_DEBUG} ] || mkdir -p ${BUILD_DIR_DEBUG} + @[ -f ${BUILD_DIR_DEBUG}/Makefile ] || (cd ${BUILD_DIR_DEBUG} && cmake ${CONFIGURE_ARGS} ..) + +configure-coverage: + @[ -d ${BUILD_DIR_COVERAGE} ] || mkdir -p ${BUILD_DIR_COVERAGE} + @[ -f ${BUILD_DIR_COVERAGE}/Makefile ] || (cd ${BUILD_DIR_COVERAGE} && cmake ${CONFIGURE_ARGS} ..) + +build: configure + @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all + +build-test: configure-test + @cmake --build ${BUILD_DIR_TEST} ${BUILD_ARGS} --target all + +build-debug: configure-debug + @cmake --build ${BUILD_DIR_DEBUG} ${BUILD_ARGS} --target all + +build-coverage: configure-coverage + @cmake --build ${BUILD_DIR_COVERAGE} ${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-test + @mkdir -p ${BUILD_DIR_TEST}/package/bin + @mkdir -p ${BUILD_DIR_TEST}/package/etc + @mkdir -p ${BUILD_DIR_TEST}/package/lib + @mkdir -p ${BUILD_DIR_TEST}/package/htdocs + @mkdir -p ${BUILD_DIR_TEST}/package/var + @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target widget + @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target test_widget + @if [ "${DEST}" != "${BUILD_DIR_TEST}" ]; then \ + mkdir -p ${DEST} && cp ${BUILD_DIR_TEST}/*.wgt ${DEST}; \ + fi + +package-test: build-test + @mkdir -p ${BUILD_DIR_DEBUG}/package/bin + @mkdir -p ${BUILD_DIR_DEBUG}/package/etc + @mkdir -p ${BUILD_DIR_DEBUG}/package/lib + @mkdir -p ${BUILD_DIR_DEBUG}/package/htdocs + @mkdir -p ${BUILD_DIR_DEBUG}/package/var + @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target widget + @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target test_widget + @if [ "${DEST}" != "${BUILD_DIR_DEBUG}" ]; then \ + mkdir -p ${DEST} && cp ${BUILD_DIR_DEBUG}/*.wgt ${DEST}; \ + fi + +package-coverage: build-coverage + @mkdir -p ${BUILD_DIR_COVERAGE}/package/bin + @mkdir -p ${BUILD_DIR_COVERAGE}/package/etc + @mkdir -p ${BUILD_DIR_COVERAGE}/package/lib + @mkdir -p ${BUILD_DIR_COVERAGE}/package/htdocs + @mkdir -p ${BUILD_DIR_COVERAGE}/package/var + @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target widget + @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target test_widget + @if [ "${DEST}" != "${BUILD_DIR_COVERAGE}" ]; then \ + mkdir -p ${DEST} && cp ${BUILD_DIR_COVERAGE}/*.wgt ${DEST}; \ + fi + +package-all: package package-test package-coverage package-debug + +install: build + @cmake --build ${BUILD_DIR} ${INSTALL_ARGS} --target install diff --git a/binding/CMakeLists.txt b/binding/CMakeLists.txt index 459773a..0ac597f 100644 --- a/binding/CMakeLists.txt +++ b/binding/CMakeLists.txt @@ -1,7 +1,8 @@ ########################################################################### # Copyright 2015, 2016, 2017 IoT.bzh # -# author: Romain Forlot +# author: Fulup Ar Foll +# contrib: Romain Forlot # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +17,20 @@ # limitations under the License. ########################################################################### -CMAKE_MINIMUM_REQUIRED(VERSION 3.3) +# Add target to project dependency list +PROJECT_TARGET_ADD(afm-poi-binding) -include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake) + # Define project Targets + add_library(afm-poi-binding MODULE binding-api.h binding-api.c verbs.cpp) + + # Binder exposes a unique public entry point + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + PREFIX "lib" + LABELS "BINDING" + LINK_FLAGS ${BINDINGS_LINK_FLAG} + OUTPUT_NAME ${TARGET_NAME} + ) + + # Library dependencies (include updates automatically) + TARGET_LINK_LIBRARIES(${TARGET_NAME} ${link_libraries}) diff --git a/binding/LICENSE b/binding/LICENSE deleted file mode 100644 index 31c692a..0000000 --- a/binding/LICENSE +++ /dev/null @@ -1,54 +0,0 @@ -Apache License - -Version 2.0, January 2004 - -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - You must give any other recipients of the Work or Derivative Works a copy of this License; and - You must cause any modified files to carry prominent notices stating that You changed the files; and - You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - - You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS diff --git a/binding/autobuild/agl/autobuild b/binding/autobuild/agl/autobuild deleted file mode 100755 index a7c25ae..0000000 --- a/binding/autobuild/agl/autobuild +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/make -f -# Copyright (C) 2015 - 2018 "IoT.bzh" -# Author "Romain Forlot" -# -# 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) -BUILD_DIR_TEST := $(abspath $(dir $(THISFILE))/../../build-test) -BUILD_DIR_DEBUG := $(abspath $(dir $(THISFILE))/../../build-debug) -BUILD_DIR_COVERAGE := $(abspath $(dir $(THISFILE))/../../build-coverage) -DEST := ${BUILD_DIR} - -.PHONY: all clean distclean configure build package help configure-debug configure-coverage build-debug build-coverage package-test package-debug package-coverage package-debug package-all - -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" - -clean: - @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} ${CLEAN_ARGS} clean) || echo Nothing to clean - -distclean: - @[ -d ${DEST} ] && find ${DEST} -name "*.wgt" -delete - @rm -rf ${BUILD_DIR} - -configure: - @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} - @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) - -configure-test: - @[ -d ${BUILD_DIR_TEST} ] || mkdir -p ${BUILD_DIR_TEST} - @[ -f ${BUILD_DIR_TEST}/Makefile ] || (cd ${BUILD_DIR_TEST} && cmake ${CONFIGURE_ARGS} ..) - -configure-debug: - @[ -d ${BUILD_DIR_DEBUG} ] || mkdir -p ${BUILD_DIR_DEBUG} - @[ -f ${BUILD_DIR_DEBUG}/Makefile ] || (cd ${BUILD_DIR_DEBUG} && cmake ${CONFIGURE_ARGS} ..) - -configure-coverage: - @[ -d ${BUILD_DIR_COVERAGE} ] || mkdir -p ${BUILD_DIR_COVERAGE} - @[ -f ${BUILD_DIR_COVERAGE}/Makefile ] || (cd ${BUILD_DIR_COVERAGE} && cmake ${CONFIGURE_ARGS} ..) - -build: configure - @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all - -build-test: configure-test - @cmake --build ${BUILD_DIR_TEST} ${BUILD_ARGS} --target all - -build-debug: configure-debug - @cmake --build ${BUILD_DIR_DEBUG} ${BUILD_ARGS} --target all - -build-coverage: configure-coverage - @cmake --build ${BUILD_DIR_COVERAGE} ${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-test - @mkdir -p ${BUILD_DIR_TEST}/package/bin - @mkdir -p ${BUILD_DIR_TEST}/package/etc - @mkdir -p ${BUILD_DIR_TEST}/package/lib - @mkdir -p ${BUILD_DIR_TEST}/package/htdocs - @mkdir -p ${BUILD_DIR_TEST}/package/var - @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target widget - @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target test_widget - @if [ "${DEST}" != "${BUILD_DIR_TEST}" ]; then \ - mkdir -p ${DEST} && cp ${BUILD_DIR_TEST}/*.wgt ${DEST}; \ - fi - -package-test: build-test - @mkdir -p ${BUILD_DIR_DEBUG}/package/bin - @mkdir -p ${BUILD_DIR_DEBUG}/package/etc - @mkdir -p ${BUILD_DIR_DEBUG}/package/lib - @mkdir -p ${BUILD_DIR_DEBUG}/package/htdocs - @mkdir -p ${BUILD_DIR_DEBUG}/package/var - @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target widget - @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target test_widget - @if [ "${DEST}" != "${BUILD_DIR_DEBUG}" ]; then \ - mkdir -p ${DEST} && cp ${BUILD_DIR_DEBUG}/*.wgt ${DEST}; \ - fi - -package-coverage: build-coverage - @mkdir -p ${BUILD_DIR_COVERAGE}/package/bin - @mkdir -p ${BUILD_DIR_COVERAGE}/package/etc - @mkdir -p ${BUILD_DIR_COVERAGE}/package/lib - @mkdir -p ${BUILD_DIR_COVERAGE}/package/htdocs - @mkdir -p ${BUILD_DIR_COVERAGE}/package/var - @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target widget - @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target test_widget - @if [ "${DEST}" != "${BUILD_DIR_COVERAGE}" ]; then \ - mkdir -p ${DEST} && cp ${BUILD_DIR_COVERAGE}/*.wgt ${DEST}; \ - fi - -package-all: package package-test package-coverage package-debug - -install: build - @cmake --build ${BUILD_DIR} ${INSTALL_ARGS} --target install diff --git a/binding/autobuild/linux/autobuild b/binding/autobuild/linux/autobuild deleted file mode 100755 index a7c25ae..0000000 --- a/binding/autobuild/linux/autobuild +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/make -f -# Copyright (C) 2015 - 2018 "IoT.bzh" -# Author "Romain Forlot" -# -# 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) -BUILD_DIR_TEST := $(abspath $(dir $(THISFILE))/../../build-test) -BUILD_DIR_DEBUG := $(abspath $(dir $(THISFILE))/../../build-debug) -BUILD_DIR_COVERAGE := $(abspath $(dir $(THISFILE))/../../build-coverage) -DEST := ${BUILD_DIR} - -.PHONY: all clean distclean configure build package help configure-debug configure-coverage build-debug build-coverage package-test package-debug package-coverage package-debug package-all - -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" - -clean: - @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} ${CLEAN_ARGS} clean) || echo Nothing to clean - -distclean: - @[ -d ${DEST} ] && find ${DEST} -name "*.wgt" -delete - @rm -rf ${BUILD_DIR} - -configure: - @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} - @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) - -configure-test: - @[ -d ${BUILD_DIR_TEST} ] || mkdir -p ${BUILD_DIR_TEST} - @[ -f ${BUILD_DIR_TEST}/Makefile ] || (cd ${BUILD_DIR_TEST} && cmake ${CONFIGURE_ARGS} ..) - -configure-debug: - @[ -d ${BUILD_DIR_DEBUG} ] || mkdir -p ${BUILD_DIR_DEBUG} - @[ -f ${BUILD_DIR_DEBUG}/Makefile ] || (cd ${BUILD_DIR_DEBUG} && cmake ${CONFIGURE_ARGS} ..) - -configure-coverage: - @[ -d ${BUILD_DIR_COVERAGE} ] || mkdir -p ${BUILD_DIR_COVERAGE} - @[ -f ${BUILD_DIR_COVERAGE}/Makefile ] || (cd ${BUILD_DIR_COVERAGE} && cmake ${CONFIGURE_ARGS} ..) - -build: configure - @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all - -build-test: configure-test - @cmake --build ${BUILD_DIR_TEST} ${BUILD_ARGS} --target all - -build-debug: configure-debug - @cmake --build ${BUILD_DIR_DEBUG} ${BUILD_ARGS} --target all - -build-coverage: configure-coverage - @cmake --build ${BUILD_DIR_COVERAGE} ${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-test - @mkdir -p ${BUILD_DIR_TEST}/package/bin - @mkdir -p ${BUILD_DIR_TEST}/package/etc - @mkdir -p ${BUILD_DIR_TEST}/package/lib - @mkdir -p ${BUILD_DIR_TEST}/package/htdocs - @mkdir -p ${BUILD_DIR_TEST}/package/var - @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target widget - @cmake --build ${BUILD_DIR_TEST} ${PACKAGE_ARGS} --target test_widget - @if [ "${DEST}" != "${BUILD_DIR_TEST}" ]; then \ - mkdir -p ${DEST} && cp ${BUILD_DIR_TEST}/*.wgt ${DEST}; \ - fi - -package-test: build-test - @mkdir -p ${BUILD_DIR_DEBUG}/package/bin - @mkdir -p ${BUILD_DIR_DEBUG}/package/etc - @mkdir -p ${BUILD_DIR_DEBUG}/package/lib - @mkdir -p ${BUILD_DIR_DEBUG}/package/htdocs - @mkdir -p ${BUILD_DIR_DEBUG}/package/var - @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target widget - @cmake --build ${BUILD_DIR_DEBUG} ${PACKAGE_ARGS} --target test_widget - @if [ "${DEST}" != "${BUILD_DIR_DEBUG}" ]; then \ - mkdir -p ${DEST} && cp ${BUILD_DIR_DEBUG}/*.wgt ${DEST}; \ - fi - -package-coverage: build-coverage - @mkdir -p ${BUILD_DIR_COVERAGE}/package/bin - @mkdir -p ${BUILD_DIR_COVERAGE}/package/etc - @mkdir -p ${BUILD_DIR_COVERAGE}/package/lib - @mkdir -p ${BUILD_DIR_COVERAGE}/package/htdocs - @mkdir -p ${BUILD_DIR_COVERAGE}/package/var - @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target widget - @cmake --build ${BUILD_DIR_COVERAGE} ${PACKAGE_ARGS} --target test_widget - @if [ "${DEST}" != "${BUILD_DIR_COVERAGE}" ]; then \ - mkdir -p ${DEST} && cp ${BUILD_DIR_COVERAGE}/*.wgt ${DEST}; \ - fi - -package-all: package package-test package-coverage package-debug - -install: build - @cmake --build ${BUILD_DIR} ${INSTALL_ARGS} --target install diff --git a/binding/binding-api.c b/binding/binding-api.c new file mode 100644 index 0000000..5221cda --- /dev/null +++ b/binding/binding-api.c @@ -0,0 +1,65 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "binding-api.h" + +#include +#include + +const afb_verb_t verbs[] = { + { .verb = POIAPI_BINDING_VERB_SEND_REQUEST, .callback = send_request }, + { .verb = POIAPI_BINDING_VERB_REQUEST_PROCESSED, .callback = request_processed }, + { .verb = POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS, .callback = subscribe_requests }, + { .verb = POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS, .callback = unsubscribe_requests }, + { .verb = POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES, .callback = subscribe_responses }, + { .verb = POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES, .callback = unsubscribe_responses }, + { .verb = NULL } +}; + +afb_event_t gEventRequestReceived; +afb_event_t gEventResponseReceived; + +int init(afb_api_t api) +{ + gEventRequestReceived = afb_api_make_event(api, POIAPI_BINDING_EVENT_REQUEST_RECEIVED); + gEventResponseReceived = afb_api_make_event(api, POIAPI_BINDING_EVENT_RESPONSE_RECEIVED); + if (afb_event_is_valid(gEventRequestReceived) && afb_event_is_valid(gEventResponseReceived)) { + + json_object *args = json_object_new_object(); + // TODO Set Version + json_object *appid = json_object_new_string("poi-service@0.1"); + json_object_object_add(args, "id", appid); + + char *err; + char *info; + json_object *response; + + // Launch poiservice + afb_api_call_sync(api, "afm-main", "start", args, &response, &err, &info); + + if (err) { + AFB_API_ERROR(api, "ERROR %s", err); + free(err); + } + if (info) { + AFB_API_INFO(api, "INFO %s", info); + free(info); + } + + json_object_put(response); + + return 0; + } + else { + AFB_API_ERROR(api, "Can't create events"); + return -1; + } +} + +const afb_binding_t afbBindingExport = { + .api = POIAPI_BINDING_API_NAME, + .verbs = verbs, + .init = init, + .noconcurrency = 0 +}; diff --git a/binding/binding-api.h b/binding/binding-api.h new file mode 100644 index 0000000..e274f9a --- /dev/null +++ b/binding/binding-api.h @@ -0,0 +1,49 @@ +#pragma once + +#ifndef AFB_BINDING_VERSION +#define AFB_BINDING_VERSION 3 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +extern afb_event_t gEventRequestReceived; +extern afb_event_t gEventResponseReceived; + +// Verbs +extern void send_request(afb_req_t req); +extern void request_processed(afb_req_t req); +extern void subscribe_requests(afb_req_t req); +extern void unsubscribe_requests(afb_req_t req); +extern void subscribe_responses(afb_req_t req); +extern void unsubscribe_responses(afb_req_t req); + +#define POIAPI_BINDING_API_NAME "poi" + +#define POIAPI_BINDING_VERB_SEND_REQUEST "send-request" +#define POIAPI_BINDING_VERB_REQUEST_PROCESSED "request-processed" +#define POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS "subscribe-requests" +#define POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS "unsubscribe-requests" +#define POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES "subscribe-responses" +#define POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES "unsubscribe-responses" + +#define POIAPI_BINDING_EVENT_REQUEST_RECEIVED "reqest-received-event" +#define POIAPI_BINDING_EVENT_RESPONSE_RECEIVED "response-received-event" + +// Some definitions is not used in this project + +#define POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID "request-id" +#define POIAPI_BINDING_PARAMETER_KEY_REQUEST_OBJECT "request-object" +#define POIAPI_BINDING_PARAMETER_KEY_RESPONSE_OBJECT "response-object" + +#define POIAPI_BINDING_REQUEST_OBJECT_KEY_REQUEST_TYPE "request-type" +#define POIAPI_BINDING_REQUEST_OBJECT_KEY_REQUEST_PARAMETER "request-parameter" + +#define POIAPI_BINDING_REQUEST_TYPE_EXTERNAL_ONLINE_REQUEST_HTTP_GET_JSON "external-online-request-http-get-json" + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/binding/conf.d/cmake/config.cmake b/binding/conf.d/cmake/config.cmake deleted file mode 100755 index f16f1c3..0000000 --- a/binding/conf.d/cmake/config.cmake +++ /dev/null @@ -1,153 +0,0 @@ -########################################################################### -# Copyright 2015, 2016, 2017 IoT.bzh -# -# author: Fulup Ar Foll -# -# 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-poi) -set(PROJECT_PRETTY_NAME "AFM binding for POI interface") -set(PROJECT_DESCRIPTION "Binding for POI interface") -set(PROJECT_URL "http://micdev14.micware.local/hiramatsu_sh/agl-service-poi") -set(PROJECT_VERSION "0.1") -set(PROJECT_ICON "icon.png") -set(PROJECT_LICENSE "APL2.0") -set(PROJECT_LANGUAGES,"C") -set(API_NAME "poi") - -# Where are stored the project configuration files -# relative to the root project directory -set(PROJECT_CMAKE_CONF_DIR "conf.d") - -# 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) - -# Compiler selection if needed. Impose a minimal version. -# ----------------------------------------------- -set (gcc_minimal_version 4.9) - -# PKG_CONFIG required packages -# ----------------------------- -set (PKG_REQUIRED_LIST - json-c - libsystemd>=222 - afb-daemon -) - -# Customize link option -# ----------------------------- -list (APPEND link_libraries -pthread) - -# (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_CONFIG_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/conf.d/wgt/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 lib/libafm-poi-binding.so) - -# Print a helper message when every thing is finished -# ---------------------------------------------------- -set(CLOSING_MESSAGE "Test with: afb-daemon --rootdir=\$\$(pwd)/package --binding=\$\$(pwd)/package/${WIDGET_ENTRY_POINT} --port=1234 --tracereq=common --token=\"1\" --verbose") -set(PACKAGE_MESSAGE "Install widget file using in the target : afm-util install ${PROJECT_NAME}.wgt") - -# 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") - -# This include is mandatory and MUST happens at the end -# of this file, else you expose you to unexpected behavior -# -# This CMake module could be found at the following url: -# https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/cmake-apps-module -# ----------------------------------------------------------- -include(CMakeAfbTemplates) diff --git a/binding/conf.d/wgt/config.xml.in b/binding/conf.d/wgt/config.xml.in deleted file mode 100644 index 3d649cc..0000000 --- a/binding/conf.d/wgt/config.xml.in +++ /dev/null @@ -1,28 +0,0 @@ - - - poi-binding - - - Demonstration POI Binding - Hiramatsu Shoichi <hiramatsu_sh@micware.co.jp> - MIT - - - - - - - - - - - - - - - - - - - - diff --git a/binding/src/CMakeLists.txt b/binding/src/CMakeLists.txt deleted file mode 100644 index 0ac597f..0000000 --- a/binding/src/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -########################################################################### -# Copyright 2015, 2016, 2017 IoT.bzh -# -# author: Fulup Ar Foll -# contrib: Romain Forlot -# -# 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(afm-poi-binding) - - # Define project Targets - add_library(afm-poi-binding MODULE binding-api.h binding-api.c verbs.cpp) - - # Binder exposes a unique public entry point - SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "lib" - LABELS "BINDING" - LINK_FLAGS ${BINDINGS_LINK_FLAG} - OUTPUT_NAME ${TARGET_NAME} - ) - - # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(${TARGET_NAME} ${link_libraries}) - diff --git a/binding/src/binding-api.c b/binding/src/binding-api.c deleted file mode 100644 index 5221cda..0000000 --- a/binding/src/binding-api.c +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include "binding-api.h" - -#include -#include - -const afb_verb_t verbs[] = { - { .verb = POIAPI_BINDING_VERB_SEND_REQUEST, .callback = send_request }, - { .verb = POIAPI_BINDING_VERB_REQUEST_PROCESSED, .callback = request_processed }, - { .verb = POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS, .callback = subscribe_requests }, - { .verb = POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS, .callback = unsubscribe_requests }, - { .verb = POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES, .callback = subscribe_responses }, - { .verb = POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES, .callback = unsubscribe_responses }, - { .verb = NULL } -}; - -afb_event_t gEventRequestReceived; -afb_event_t gEventResponseReceived; - -int init(afb_api_t api) -{ - gEventRequestReceived = afb_api_make_event(api, POIAPI_BINDING_EVENT_REQUEST_RECEIVED); - gEventResponseReceived = afb_api_make_event(api, POIAPI_BINDING_EVENT_RESPONSE_RECEIVED); - if (afb_event_is_valid(gEventRequestReceived) && afb_event_is_valid(gEventResponseReceived)) { - - json_object *args = json_object_new_object(); - // TODO Set Version - json_object *appid = json_object_new_string("poi-service@0.1"); - json_object_object_add(args, "id", appid); - - char *err; - char *info; - json_object *response; - - // Launch poiservice - afb_api_call_sync(api, "afm-main", "start", args, &response, &err, &info); - - if (err) { - AFB_API_ERROR(api, "ERROR %s", err); - free(err); - } - if (info) { - AFB_API_INFO(api, "INFO %s", info); - free(info); - } - - json_object_put(response); - - return 0; - } - else { - AFB_API_ERROR(api, "Can't create events"); - return -1; - } -} - -const afb_binding_t afbBindingExport = { - .api = POIAPI_BINDING_API_NAME, - .verbs = verbs, - .init = init, - .noconcurrency = 0 -}; diff --git a/binding/src/binding-api.h b/binding/src/binding-api.h deleted file mode 100644 index e274f9a..0000000 --- a/binding/src/binding-api.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#ifndef AFB_BINDING_VERSION -#define AFB_BINDING_VERSION 3 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -extern afb_event_t gEventRequestReceived; -extern afb_event_t gEventResponseReceived; - -// Verbs -extern void send_request(afb_req_t req); -extern void request_processed(afb_req_t req); -extern void subscribe_requests(afb_req_t req); -extern void unsubscribe_requests(afb_req_t req); -extern void subscribe_responses(afb_req_t req); -extern void unsubscribe_responses(afb_req_t req); - -#define POIAPI_BINDING_API_NAME "poi" - -#define POIAPI_BINDING_VERB_SEND_REQUEST "send-request" -#define POIAPI_BINDING_VERB_REQUEST_PROCESSED "request-processed" -#define POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS "subscribe-requests" -#define POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS "unsubscribe-requests" -#define POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES "subscribe-responses" -#define POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES "unsubscribe-responses" - -#define POIAPI_BINDING_EVENT_REQUEST_RECEIVED "reqest-received-event" -#define POIAPI_BINDING_EVENT_RESPONSE_RECEIVED "response-received-event" - -// Some definitions is not used in this project - -#define POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID "request-id" -#define POIAPI_BINDING_PARAMETER_KEY_REQUEST_OBJECT "request-object" -#define POIAPI_BINDING_PARAMETER_KEY_RESPONSE_OBJECT "response-object" - -#define POIAPI_BINDING_REQUEST_OBJECT_KEY_REQUEST_TYPE "request-type" -#define POIAPI_BINDING_REQUEST_OBJECT_KEY_REQUEST_PARAMETER "request-parameter" - -#define POIAPI_BINDING_REQUEST_TYPE_EXTERNAL_ONLINE_REQUEST_HTTP_GET_JSON "external-online-request-http-get-json" - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/binding/src/verbs.cpp b/binding/src/verbs.cpp deleted file mode 100644 index f71698a..0000000 --- a/binding/src/verbs.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include "binding-api.h" - -#include -#include -#include -#include - -extern "C" { -// json-c/json.h -#include -} - -static std::mutex mut; -static int32_t gRequestId = 0; -static std::map gRequests; - -static inline bool pushRequest(json_object *reqJson) { - // Guard `gRequests' and `gRequestId' - std::lock_guard lock(mut); - - gRequestId++; - - json_object *reqToSvc = json_object_new_object(); - json_object_object_add(reqToSvc, POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID, json_object_new_string(std::to_string(gRequestId).c_str())); - - // reqJson(1), reqToSvc(1) - // Associate `reqJson' to `reqToSvc' but the refcount of `reqJson' is not incremented - json_object_object_add(reqToSvc, POIAPI_BINDING_PARAMETER_KEY_REQUEST_OBJECT, reqJson); - - // reqJson(1->2->1), reqToSvc(1->2->1) - // Each refcount of `reqJson' or `reqToSvc' is decrement, and we increment the refcounts before the decrementations - int rc = afb_event_push(gEventRequestReceived, json_object_get(reqToSvc)); - if (rc == -1 || rc == 0) { // Discard the request if the event was not pushed or there are no subscriber - // reqJson(1->2), reqToSvc(1->1) - json_object_get(reqJson); - // reqJson(2->1), reqToSvc(1->0) - // Delete reqToSvc - json_object_put(reqToSvc); - return false; - } - - // reqJson(1->2), reqToSvc(1) - // Increment the refcount of `refJson' to preserve `reqToSvc'. - // The refcount of reqJson will be decremented in afb_req_success - json_object_get(reqJson); - gRequests.emplace(gRequestId, reqToSvc); - - return true; -} - -// Verb: request-processed -void send_request(afb_req_t req) -{ - json_object *reqJson = afb_req_json(req); - if (!pushRequest(reqJson)) { - AFB_REQ_ERROR(req, "Failed to push an event"); - // reqJson(1->0) - afb_req_fail(req, "error", "Failed to push an event"); - return; - } - - json_object *response = json_object_new_object(); - json_object_object_add(response, POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID, json_object_new_string(std::to_string(gRequestId).c_str())); - - // `response' will be released - // The refcount of `reqJson' will be 1; `reqJson' belonges to a element of `gRequests' - afb_req_success(req, response, POIAPI_BINDING_VERB_SEND_REQUEST); -} - -// Verb: request-processed -void request_processed(afb_req_t req) -{ - json_object *resultJson = afb_req_json(req); - json_object *ridj; - json_object_object_get_ex(resultJson, POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID, &ridj); - if (!json_object_is_type(ridj, json_type_string)) { - AFB_REQ_ERROR(req, "Received response was bad formatted: %s", json_object_to_json_string_ext(afb_req_json(req), JSON_C_TO_STRING_PRETTY)); - afb_req_fail(req, "error", "Received response was badly formatted"); - return; - } - - const char *rids = json_object_get_string(ridj); - uint32_t rid; - try { - rid = std::stoi(rids); - } - catch (const std::invalid_argument &e) { - AFB_REQ_ERROR(req, "Received response was bad formatted: %s", json_object_to_json_string_ext(afb_req_json(req), JSON_C_TO_STRING_PRETTY)); - afb_req_fail(req, "error", "Received response was badly formatted"); - return; - } - catch (const std::out_of_range &e) { - AFB_REQ_ERROR(req, "Received response was bad formatted: %s", json_object_to_json_string_ext(afb_req_json(req), JSON_C_TO_STRING_PRETTY)); - afb_req_fail(req, "error", "Received response was badly formatted"); - return; - } - - decltype(gRequests)::iterator it = gRequests.find(rid); - if (it == gRequests.end()) { - AFB_REQ_ERROR(req, "Received an invalid request id: %d", rid); - afb_req_fail_f(req, "error", "Received an invalid request id: %d %s", rid, rids); - return; - } - - // Preserve `resultJson' because afb_req_success use it - if (afb_event_push(gEventResponseReceived, json_object_get(resultJson)) == -1) { - AFB_REQ_ERROR(req, "Failed to push an event"); - afb_req_fail(req, "error", "Failed to push an event"); - return; - } - - afb_req_success(req, nullptr, nullptr); - - // Guard `gRequests' - std::lock_guard lock(mut); - - // Delete the processed request data - json_object *processedReq = it->second; - gRequests.erase(it); - int rc = json_object_put(processedReq); - if (rc != 1) { - AFB_REQ_ERROR(req, "bad-ref-count %d:%s", rc, POIAPI_BINDING_VERB_REQUEST_PROCESSED); - } -} - -// Verb: subscribe-requests -void subscribe_requests(afb_req_t req) -{ - if (afb_req_subscribe(req, gEventRequestReceived) == 0) { - afb_req_success(req, nullptr, nullptr); - } else { - AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS); - afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS); - } -} - -// Verb: unsubscribe-requests -void unsubscribe_requests(afb_req_t req) -{ - if (afb_req_unsubscribe(req, gEventRequestReceived) == 0) { - afb_req_success(req, nullptr, nullptr); - } else { - AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS); - afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS); - } -} - -// Verb: subscribe-responses -void subscribe_responses(afb_req_t req) -{ - if (afb_req_subscribe(req, gEventResponseReceived) == 0) { - afb_req_success(req, nullptr, nullptr); - } else { - AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES); - afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES); - } -} - -// Verb: unsubscribe-responses -void unsubscribe_responses(afb_req_t req) -{ - if (afb_req_unsubscribe(req, gEventResponseReceived) == 0) { - afb_req_success(req, nullptr, nullptr); - } else { - AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES); - afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES); - } -} diff --git a/binding/verbs.cpp b/binding/verbs.cpp new file mode 100644 index 0000000..f71698a --- /dev/null +++ b/binding/verbs.cpp @@ -0,0 +1,172 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "binding-api.h" + +#include +#include +#include +#include + +extern "C" { +// json-c/json.h +#include +} + +static std::mutex mut; +static int32_t gRequestId = 0; +static std::map gRequests; + +static inline bool pushRequest(json_object *reqJson) { + // Guard `gRequests' and `gRequestId' + std::lock_guard lock(mut); + + gRequestId++; + + json_object *reqToSvc = json_object_new_object(); + json_object_object_add(reqToSvc, POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID, json_object_new_string(std::to_string(gRequestId).c_str())); + + // reqJson(1), reqToSvc(1) + // Associate `reqJson' to `reqToSvc' but the refcount of `reqJson' is not incremented + json_object_object_add(reqToSvc, POIAPI_BINDING_PARAMETER_KEY_REQUEST_OBJECT, reqJson); + + // reqJson(1->2->1), reqToSvc(1->2->1) + // Each refcount of `reqJson' or `reqToSvc' is decrement, and we increment the refcounts before the decrementations + int rc = afb_event_push(gEventRequestReceived, json_object_get(reqToSvc)); + if (rc == -1 || rc == 0) { // Discard the request if the event was not pushed or there are no subscriber + // reqJson(1->2), reqToSvc(1->1) + json_object_get(reqJson); + // reqJson(2->1), reqToSvc(1->0) + // Delete reqToSvc + json_object_put(reqToSvc); + return false; + } + + // reqJson(1->2), reqToSvc(1) + // Increment the refcount of `refJson' to preserve `reqToSvc'. + // The refcount of reqJson will be decremented in afb_req_success + json_object_get(reqJson); + gRequests.emplace(gRequestId, reqToSvc); + + return true; +} + +// Verb: request-processed +void send_request(afb_req_t req) +{ + json_object *reqJson = afb_req_json(req); + if (!pushRequest(reqJson)) { + AFB_REQ_ERROR(req, "Failed to push an event"); + // reqJson(1->0) + afb_req_fail(req, "error", "Failed to push an event"); + return; + } + + json_object *response = json_object_new_object(); + json_object_object_add(response, POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID, json_object_new_string(std::to_string(gRequestId).c_str())); + + // `response' will be released + // The refcount of `reqJson' will be 1; `reqJson' belonges to a element of `gRequests' + afb_req_success(req, response, POIAPI_BINDING_VERB_SEND_REQUEST); +} + +// Verb: request-processed +void request_processed(afb_req_t req) +{ + json_object *resultJson = afb_req_json(req); + json_object *ridj; + json_object_object_get_ex(resultJson, POIAPI_BINDING_PARAMETER_KEY_REQUEST_ID, &ridj); + if (!json_object_is_type(ridj, json_type_string)) { + AFB_REQ_ERROR(req, "Received response was bad formatted: %s", json_object_to_json_string_ext(afb_req_json(req), JSON_C_TO_STRING_PRETTY)); + afb_req_fail(req, "error", "Received response was badly formatted"); + return; + } + + const char *rids = json_object_get_string(ridj); + uint32_t rid; + try { + rid = std::stoi(rids); + } + catch (const std::invalid_argument &e) { + AFB_REQ_ERROR(req, "Received response was bad formatted: %s", json_object_to_json_string_ext(afb_req_json(req), JSON_C_TO_STRING_PRETTY)); + afb_req_fail(req, "error", "Received response was badly formatted"); + return; + } + catch (const std::out_of_range &e) { + AFB_REQ_ERROR(req, "Received response was bad formatted: %s", json_object_to_json_string_ext(afb_req_json(req), JSON_C_TO_STRING_PRETTY)); + afb_req_fail(req, "error", "Received response was badly formatted"); + return; + } + + decltype(gRequests)::iterator it = gRequests.find(rid); + if (it == gRequests.end()) { + AFB_REQ_ERROR(req, "Received an invalid request id: %d", rid); + afb_req_fail_f(req, "error", "Received an invalid request id: %d %s", rid, rids); + return; + } + + // Preserve `resultJson' because afb_req_success use it + if (afb_event_push(gEventResponseReceived, json_object_get(resultJson)) == -1) { + AFB_REQ_ERROR(req, "Failed to push an event"); + afb_req_fail(req, "error", "Failed to push an event"); + return; + } + + afb_req_success(req, nullptr, nullptr); + + // Guard `gRequests' + std::lock_guard lock(mut); + + // Delete the processed request data + json_object *processedReq = it->second; + gRequests.erase(it); + int rc = json_object_put(processedReq); + if (rc != 1) { + AFB_REQ_ERROR(req, "bad-ref-count %d:%s", rc, POIAPI_BINDING_VERB_REQUEST_PROCESSED); + } +} + +// Verb: subscribe-requests +void subscribe_requests(afb_req_t req) +{ + if (afb_req_subscribe(req, gEventRequestReceived) == 0) { + afb_req_success(req, nullptr, nullptr); + } else { + AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS); + afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS); + } +} + +// Verb: unsubscribe-requests +void unsubscribe_requests(afb_req_t req) +{ + if (afb_req_unsubscribe(req, gEventRequestReceived) == 0) { + afb_req_success(req, nullptr, nullptr); + } else { + AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS); + afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS); + } +} + +// Verb: subscribe-responses +void subscribe_responses(afb_req_t req) +{ + if (afb_req_subscribe(req, gEventResponseReceived) == 0) { + afb_req_success(req, nullptr, nullptr); + } else { + AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES); + afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES); + } +} + +// Verb: unsubscribe-responses +void unsubscribe_responses(afb_req_t req) +{ + if (afb_req_unsubscribe(req, gEventResponseReceived) == 0) { + afb_req_success(req, nullptr, nullptr); + } else { + AFB_REQ_ERROR(req, "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES); + afb_req_fail_f(req, "error", "Failed to %s", POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES); + } +} diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake new file mode 100644 index 0000000..f16f1c3 --- /dev/null +++ b/conf.d/cmake/config.cmake @@ -0,0 +1,153 @@ +########################################################################### +# Copyright 2015, 2016, 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# 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-poi) +set(PROJECT_PRETTY_NAME "AFM binding for POI interface") +set(PROJECT_DESCRIPTION "Binding for POI interface") +set(PROJECT_URL "http://micdev14.micware.local/hiramatsu_sh/agl-service-poi") +set(PROJECT_VERSION "0.1") +set(PROJECT_ICON "icon.png") +set(PROJECT_LICENSE "APL2.0") +set(PROJECT_LANGUAGES,"C") +set(API_NAME "poi") + +# Where are stored the project configuration files +# relative to the root project directory +set(PROJECT_CMAKE_CONF_DIR "conf.d") + +# 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) + +# Compiler selection if needed. Impose a minimal version. +# ----------------------------------------------- +set (gcc_minimal_version 4.9) + +# PKG_CONFIG required packages +# ----------------------------- +set (PKG_REQUIRED_LIST + json-c + libsystemd>=222 + afb-daemon +) + +# Customize link option +# ----------------------------- +list (APPEND link_libraries -pthread) + +# (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_CONFIG_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/conf.d/wgt/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 lib/libafm-poi-binding.so) + +# Print a helper message when every thing is finished +# ---------------------------------------------------- +set(CLOSING_MESSAGE "Test with: afb-daemon --rootdir=\$\$(pwd)/package --binding=\$\$(pwd)/package/${WIDGET_ENTRY_POINT} --port=1234 --tracereq=common --token=\"1\" --verbose") +set(PACKAGE_MESSAGE "Install widget file using in the target : afm-util install ${PROJECT_NAME}.wgt") + +# 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") + +# This include is mandatory and MUST happens at the end +# of this file, else you expose you to unexpected behavior +# +# This CMake module could be found at the following url: +# https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/cmake-apps-module +# ----------------------------------------------------------- +include(CMakeAfbTemplates) diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in new file mode 100644 index 0000000..3d649cc --- /dev/null +++ b/conf.d/wgt/config.xml.in @@ -0,0 +1,28 @@ + + + poi-binding + + + Demonstration POI Binding + Hiramatsu Shoichi <hiramatsu_sh@micware.co.jp> + MIT + + + + + + + + + + + + + + + + + + + + -- cgit 1.2.3-korg