aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nbproject/configurations.xml17
-rw-r--r--ucs2-afb/CMakeLists.txt28
-rw-r--r--ucs2-afb/ucs_apidef.h86
-rw-r--r--ucs2-afb/ucs_apidef.json39
-rw-r--r--ucs2-afb/ucs_apihat.c21
5 files changed, 158 insertions, 33 deletions
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 4ff307d..5d4dfd9 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -35,7 +35,6 @@
<in>libmostvolume.cpp</in>
</df>
<df name="ucs2-afb">
- <in>ucs_apihat.c</in>
<in>ucs_binding.c</in>
<in>ucs_binding.new.c</in>
</df>
@@ -283,13 +282,6 @@
</preprocessorList>
</ccTool>
</folder>
- <item path="ucs2-afb/ucs_apihat.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
- <preprocessorList>
- <Elem>ucs2_EXPORTS</Elem>
- </preprocessorList>
- </cTool>
- </item>
<item path="ucs2-afb/ucs_binding.c" ex="false" tool="0" flavor2="3">
<cTool flags="1">
<preprocessorList>
@@ -675,15 +667,6 @@
</preprocessorList>
</ccTool>
</folder>
- <item path="ucs2-afb/ucs_apihat.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
- <incDir>
- <pElem>ucs2-afb</pElem>
- <pElem>../../../opt/include/afb</pElem>
- <pElem>build/ucs2-afb</pElem>
- </incDir>
- </cTool>
- </item>
<item path="ucs2-afb/ucs_binding.c" ex="false" tool="0" flavor2="3">
<cTool flags="1">
<incDir>
diff --git a/ucs2-afb/CMakeLists.txt b/ucs2-afb/CMakeLists.txt
index ee5099e..9bac628 100644
--- a/ucs2-afb/CMakeLists.txt
+++ b/ucs2-afb/CMakeLists.txt
@@ -16,28 +16,44 @@
# limitations under the License.
###########################################################################
+
+# Generate API-v2 hat from OpenAPI json definition
+macro(SET_TARGET_GENSKEL TARGET_NAME API_DEF_NAME)
+ add_custom_command(OUTPUT ${API_DEF_NAME}.h
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${API_DEF_NAME}.json
+ COMMAND afb-genskel ${API_DEF_NAME}.json >${API_DEF_NAME}.h
+ )
+ add_custom_target(${API_DEF_NAME}_OPENAPI DEPENDS ${API_DEF_NAME}.h)
+ add_dependencies(${TARGET_NAME} ${API_DEF_NAME}_OPENAPI)
+
+endmacro(SET_TARGET_GENSKEL)
+
# Add target to project dependency list
-PROJECT_TARGET_ADD(ucs2)
+PROJECT_TARGET_ADD(ucs2-afb)
# Define project Targets
- ADD_LIBRARY(ucs2 MODULE ucs_binding.c ucs_apihat.c)
+ ADD_LIBRARY(${TARGET_NAME} MODULE ucs_apihat.c ucs_binding.c )
+
+ # Generate API-v2 hat from OpenAPI json definition
+ SET_TARGET_GENSKEL(${TARGET_NAME} ucs_apidef)
# Binder exposes a unique public entry point
- SET_TARGET_PROPERTIES(ucs2 PROPERTIES
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
PREFIX "afb-"
LABELS "BINDING"
LINK_FLAGS ${BINDINGS_LINK_FLAG}
- OUTPUT_NAME ${TARGET_NAME}
+ OUTPUT_NAME ucs2
)
# Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(ucs2
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
ucs2-inter
${link_libraries}
)
# installation directory
- INSTALL(TARGETS ucs2
+ INSTALL(TARGETS ${TARGET_NAME}
LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR})
diff --git a/ucs2-afb/ucs_apidef.h b/ucs2-afb/ucs_apidef.h
new file mode 100644
index 0000000..8e1ab13
--- /dev/null
+++ b/ucs2-afb/ucs_apidef.h
@@ -0,0 +1,86 @@
+
+static const char _afb_description_v2_UNICENS[] =
+ "{\"openapi\":\"3.0.0\",\"$schema\":\"http:iot.bzh/download/openapi/schem"
+ "a-3.0/default-schema.json\",\"info\":{\"description\":\"\",\"title\":\"u"
+ "cs2\",\"version\":\"1.0\",\"x-binding-c-generator\":{\"api\":\"UNICENS\""
+ ",\"version\":2,\"prefix\":\"Ucs2\",\"postfix\":\"API\",\"start\":null,\""
+ "onevent\":null,\"init\":null,\"scope\":\"\",\"private\":false}},\"server"
+ "s\":[{\"url\":\"ws://{host}:{port}/api/monitor\",\"description\":\"Unice"
+ "ns2 API.\",\"variables\":{\"host\":{\"default\":\"localhost\"},\"port\":"
+ "{\"default\":\"1234\"}},\"x-afb-events\":[{\"$ref\":\"#/components/schem"
+ "as/afb-event\"}]}],\"components\":{\"schemas\":{\"afb-reply\":{\"$ref\":"
+ "\"#/components/schemas/afb-reply-v2\"},\"afb-event\":{\"$ref\":\"#/compo"
+ "nents/schemas/afb-event-v2\"},\"afb-reply-v2\":{\"title\":\"Generic resp"
+ "onse.\",\"type\":\"object\",\"required\":[\"jtype\",\"request\"],\"prope"
+ "rties\":{\"jtype\":{\"type\":\"string\",\"const\":\"afb-reply\"},\"reque"
+ "st\":{\"type\":\"object\",\"required\":[\"status\"],\"properties\":{\"st"
+ "atus\":{\"type\":\"string\"},\"info\":{\"type\":\"string\"},\"token\":{\""
+ "type\":\"string\"},\"uuid\":{\"type\":\"string\"},\"reqid\":{\"type\":\""
+ "string\"}}},\"response\":{\"type\":\"object\"}}},\"afb-event-v2\":{\"typ"
+ "e\":\"object\",\"required\":[\"jtype\",\"event\"],\"properties\":{\"jtyp"
+ "e\":{\"type\":\"string\",\"const\":\"afb-event\"},\"event\":{\"type\":\""
+ "string\"},\"data\":{\"type\":\"object\"}}}},\"x-permissions\":{\"config\""
+ ":{\"permission\":\"urn:AGL:permission:UNICENS:public:initialise\"},\"mon"
+ "itor\":{\"permission\":\"urn:AGL:permission:UNICENS:public:monitor\"}},\""
+ "responses\":{\"200\":{\"description\":\"A complex object array response\""
+ ",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/"
+ "schemas/afb-reply\"}}}}}},\"paths\":{\"/initialise\":{\"description\":\""
+ "Initialise Unicens2 lib from NetworkConfig.XML.\",\"get\":{\"x-permissio"
+ "ns\":{\"$ref\":\"#/components/x-permissions/config\"},\"parameters\":[{\""
+ "in\":\"query\",\"name\":\"filename\",\"required\":true,\"schema\":{\"typ"
+ "e\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components/respon"
+ "ses/200\"}}}},\"/volume\":{\"description\":\"Set Master Volume.\",\"get\""
+ ":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/monitor\"},\""
+ "parameters\":[{\"in\":\"query\",\"name\":\"value\",\"required\":true,\"s"
+ "chema\":{\"type\":\"integer\"}}],\"responses\":{\"200\":{\"$ref\":\"#/co"
+ "mponents/responses/200\"}}}},\"/monitor\":{\"description\":\"Subscribe t"
+ "o Unicens Event.\",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x"
+ "-permissions/monitor\"},\"responses\":{\"200\":{\"$ref\":\"#/components/"
+ "responses/200\"}}}}}}"
+;
+
+static const struct afb_auth _afb_auths_v2_UNICENS[] = {
+ { .type = afb_auth_Permission, .text = "urn:AGL:permission:UNICENS:public:initialise" },
+ { .type = afb_auth_Permission, .text = "urn:AGL:permission:UNICENS:public:monitor" }
+};
+
+ void Ucs2initialiseAPI(struct afb_req req);
+ void Ucs2volumeAPI(struct afb_req req);
+ void Ucs2monitorAPI(struct afb_req req);
+
+static const struct afb_verb_v2 _afb_verbs_v2_UNICENS[] = {
+ {
+ .verb = "initialise",
+ .callback = Ucs2initialiseAPI,
+ .auth = &_afb_auths_v2_UNICENS[0],
+ .info = NULL,
+ .session = AFB_SESSION_NONE_V2
+ },
+ {
+ .verb = "volume",
+ .callback = Ucs2volumeAPI,
+ .auth = &_afb_auths_v2_UNICENS[1],
+ .info = NULL,
+ .session = AFB_SESSION_NONE_V2
+ },
+ {
+ .verb = "monitor",
+ .callback = Ucs2monitorAPI,
+ .auth = &_afb_auths_v2_UNICENS[1],
+ .info = NULL,
+ .session = AFB_SESSION_NONE_V2
+ },
+ { .verb = NULL }
+};
+
+const struct afb_binding_v2 afbBindingV2 = {
+ .api = "UNICENS",
+ .specification = _afb_description_v2_UNICENS,
+ .info = NULL,
+ .verbs = _afb_verbs_v2_UNICENS,
+ .preinit = NULL,
+ .init = NULL,
+ .onevent = NULL,
+ .noconcurrency = 0
+};
+
diff --git a/ucs2-afb/ucs_apidef.json b/ucs2-afb/ucs_apidef.json
index 5aa33a2..9936004 100644
--- a/ucs2-afb/ucs_apidef.json
+++ b/ucs2-afb/ucs_apidef.json
@@ -1,6 +1,6 @@
{
"openapi": "3.0.0",
- "$schema": "file:///home/fulup/Workspace/AGL-AppFW/unicens2rc-afb/etc/openapi-schema.json",
+ "$schema": "http:iot.bzh/download/openapi/schema-3.0/default-schema.json",
"info": {
"description": "",
"title": "ucs2",
@@ -8,13 +8,13 @@
"x-binding-c-generator": {
"api": "UNICENS",
"version": 2,
- "prefix": "ucs2_",
- "postfix": "",
+ "prefix": "Ucs2",
+ "postfix": "API",
"start": null ,
"onevent": null,
"init": null,
- "scope": "static",
- "private": true
+ "scope": "",
+ "private": false
}
},
"servers": [
@@ -39,12 +39,12 @@
"components": {
"schemas": {
"afb-reply": {
- "$ref": "#/components/schemas/afb-reply-v1"
+ "$ref": "#/components/schemas/afb-reply-v2"
},
"afb-event": {
- "$ref": "#/components/schemas/afb-event-v1"
+ "$ref": "#/components/schemas/afb-event-v2"
},
- "afb-reply-v1": {
+ "afb-reply-v2": {
"title": "Generic response.",
"type": "object",
"required": [ "jtype", "request" ],
@@ -67,7 +67,7 @@
"response": { "type": "object" }
}
},
- "afb-event-v1": {
+ "afb-event-v2": {
"type": "object",
"required": [ "jtype", "event" ],
"properties": {
@@ -121,8 +121,27 @@
}
}
},
+ "/volume": {
+ "description": "Set Master Volume.",
+ "get": {
+ "x-permissions": {
+ "$ref": "#/components/x-permissions/monitor"
+ },
+ "parameters": [
+ {
+ "in": "query",
+ "name": "value",
+ "required": true,
+ "schema": { "type": "integer" }
+ }
+ ],
+ "responses": {
+ "200": {"$ref": "#/components/responses/200"}
+ }
+ }
+ },
"/monitor": {
- "description": "Subscribe to Unicens2 Events.",
+ "description": "Subscribe to Unicens Event.",
"get": {
"x-permissions": {
"$ref": "#/components/x-permissions/monitor"
diff --git a/ucs2-afb/ucs_apihat.c b/ucs2-afb/ucs_apihat.c
new file mode 100644
index 0000000..04bf50f
--- /dev/null
+++ b/ucs2-afb/ucs_apihat.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016 "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.
+ */
+
+#define _GNU_SOURCE
+
+#include "ucs_binding.h"
+#include "ucs_apidef.h"