diff options
author | 2017-08-31 12:19:23 +0200 | |
---|---|---|
committer | 2017-09-02 12:18:23 +0200 | |
commit | a27e152d46e2635b4f30a06647af6041c8b383a2 (patch) | |
tree | 8f4859f3d1ee57395a752a2bd9c4a4260c75195c | |
parent | ce14a49fad2d058c438632995869dab3429efbb2 (diff) |
Renaming high-can to high-viwi more generic.
Change-Id: Id543f9f5724321f8c12c2d386340a3cc1ff0dc81
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | high-can-binding/high-can-binding-hat.cpp | 37 | ||||
-rw-r--r-- | high-viwi-binding/CMakeLists.txt (renamed from high-can-binding/CMakeLists.txt) | 13 | ||||
-rw-r--r-- | high-viwi-binding/high-viwi-apidef.h | 94 | ||||
-rw-r--r-- | high-viwi-binding/high-viwi-apidef.json | 148 | ||||
-rw-r--r-- | high-viwi-binding/high-viwi-binding.cpp (renamed from high-can-binding/high-can-binding.cpp) | 15 | ||||
-rw-r--r-- | high-viwi-binding/high-viwi-binding.hpp (renamed from high-can-binding/high-can-binding-hat.hpp) | 6 | ||||
-rw-r--r-- | high-viwi-binding/high.cpp (renamed from high-can-binding/high.cpp) | 24 | ||||
-rw-r--r-- | high-viwi-binding/high.hpp (renamed from high-can-binding/high.hpp) | 2 |
8 files changed, 277 insertions, 62 deletions
diff --git a/high-can-binding/high-can-binding-hat.cpp b/high-can-binding/high-can-binding-hat.cpp deleted file mode 100644 index 8c747d1..0000000 --- a/high-can-binding/high-can-binding-hat.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "high-can-binding-hat.hpp" -#include <cstddef> -/// Interface between the daemon and the binding - -static int init_service(); - -static const struct afb_verb_v2 verbs[]= -{ - { .verb= "subscribe", .callback= subscribe, .auth = NULL, .info = "subscribe to an ViWi object", .session = 0 }, - { .verb= "unsubscribe", .callback= unsubscribe, .auth = NULL, .info = "unsubscribe to a ViWi object", .session = 0 }, - { .verb= "load", .callback= load, .auth = NULL, .info = "Load Viwi service Configuration", .session = 0 }, - { .verb= "get", .callback= get, .auth = NULL, .info = "Get informations about a resource or element", .session = 0 }, - { .verb= NULL, .callback=NULL, .auth = NULL, .info = NULL, .session = 0 } -}; - -const struct afb_binding_v2 afbBindingV2 = { - .api = "high-can", - .specification = "", - .info = "High CAN ViWi API connected to low-can AGL service", - .verbs = verbs, - .preinit = NULL, - .init = init_service, - .onevent = onEvent, - .noconcurrency = 1 -}; - -/// @brief Initialize the binding. -/// -/// @return Exit code, zero if success. -int init_service() -{ - AFB_NOTICE("high level binding is initializing"); - afb_daemon_require_api("low-can", 1); - initHigh(); - AFB_NOTICE("high level binding is initialized and running"); - return 0; -} diff --git a/high-can-binding/CMakeLists.txt b/high-viwi-binding/CMakeLists.txt index a380eb8..18a4e79 100644 --- a/high-can-binding/CMakeLists.txt +++ b/high-viwi-binding/CMakeLists.txt @@ -18,20 +18,21 @@ ########################################################################### # Add target to project dependency list -PROJECT_TARGET_ADD(high-can) +PROJECT_TARGET_ADD(high-viwi) # Define project Targets - add_library(${TARGET_NAME} MODULE ${TARGET_NAME}-binding.cpp high-can-binding-hat.cpp high.cpp) + add_library(${TARGET_NAME} MODULE ${TARGET_NAME}-binding.cpp high.cpp) # 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} + PREFIX "afb-" + LABELS "BINDINGV2" + LINK_FLAGS ${BINDINGS_LINK_FLAG} + OUTPUT_NAME ${TARGET_NAME} ) # Library dependencies (include updates automatically) TARGET_LINK_LIBRARIES(${TARGET_NAME} + afb-utilities ${link_libraries} ) diff --git a/high-viwi-binding/high-viwi-apidef.h b/high-viwi-binding/high-viwi-apidef.h new file mode 100644 index 0000000..fec9d26 --- /dev/null +++ b/high-viwi-binding/high-viwi-apidef.h @@ -0,0 +1,94 @@ + +static const char _afb_description_v2_high_viwi[] = + "{\"openapi\":\"3.0.0\",\"$schema\":\"http:iot.bzh/download/openapi/schem" + "a-3.0/default-schema.json\",\"info\":{\"description\":\"\",\"title\":\"h" + "igh-level-viwi-service\",\"version\":\"4.0\",\"x-binding-c-generator\":{" + "\"api\":\"high-viwi\",\"version\":2,\"prefix\":\"\",\"postfix\":\"\",\"s" + "tart\":null,\"onevent\":\"onEvent\",\"init\":\"init_service\",\"scope\":" + "\"\",\"private\":false}},\"servers\":[{\"url\":\"ws://{host}:{port}/api/" + "monitor\",\"description\":\"High ViWi API connected to low level AGL ser" + "vices\",\"variables\":{\"host\":{\"default\":\"localhost\"},\"port\":{\"" + "default\":\"1234\"}},\"x-afb-events\":[{\"$ref\":\"#/components/schemas/" + "afb-event\"}]}],\"components\":{\"schemas\":{\"afb-reply\":{\"$ref\":\"#" + "/components/schemas/afb-reply-v2\"},\"afb-event\":{\"$ref\":\"#/componen" + "ts/schemas/afb-event-v2\"},\"afb-reply-v2\":{\"title\":\"Generic respons" + "e.\",\"type\":\"object\",\"required\":[\"jtype\",\"request\"],\"properti" + "es\":{\"jtype\":{\"type\":\"string\",\"const\":\"afb-reply\"},\"request\"" + ":{\"type\":\"object\",\"required\":[\"status\"],\"properties\":{\"status" + "\":{\"type\":\"string\"},\"info\":{\"type\":\"string\"},\"token\":{\"typ" + "e\":\"string\"},\"uuid\":{\"type\":\"string\"},\"reqid\":{\"type\":\"str" + "ing\"}}},\"response\":{\"type\":\"object\"}}},\"afb-event-v2\":{\"type\"" + ":\"object\",\"required\":[\"jtype\",\"event\"],\"properties\":{\"jtype\"" + ":{\"type\":\"string\",\"const\":\"afb-event\"},\"event\":{\"type\":\"str" + "ing\"},\"data\":{\"type\":\"object\"}}}},\"x-permissions\":{},\"response" + "s\":{\"200\":{\"description\":\"A complex object array response\",\"cont" + "ent\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas" + "/afb-reply\"}}}}}},\"paths\":{\"/subscribe\":{\"description\":\"Subscrib" + "e to a ViWi object\",\"parameters\":[{\"in\":\"query\",\"name\":\"event\"" + ",\"required\":false,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"" + "200\":{\"$ref\":\"#/components/responses/200\"}}},\"/unsubscribe\":{\"de" + "scription\":\"Unsubscribe previously suscribed ViWi objects.\",\"paramet" + "ers\":[{\"in\":\"query\",\"name\":\"event\",\"required\":false,\"schema\"" + ":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components" + "/responses/200\"}}},\"/get\":{\"description\":\"Get informations about a" + " resource or element\",\"responses\":{\"200\":{\"$ref\":\"#/components/r" + "esponses/200\"}}},\"/load\":{\"description\":\"Load config file in direc" + "tory passed as argument\",\"parameters\":[{\"in\":\"query\",\"name\":\"p" + "ath\",\"required\":true,\"schema\":{\"type\":\"string\"}}],\"responses\"" + ":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}}}" +; + + void subscribe(struct afb_req req); + void unsubscribe(struct afb_req req); + void get(struct afb_req req); + void load(struct afb_req req); + +static const struct afb_verb_v2 _afb_verbs_v2_high_viwi[] = { + { + .verb = "subscribe", + .callback = subscribe, + .auth = NULL, + .info = "Subscribe to a ViWi object", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "unsubscribe", + .callback = unsubscribe, + .auth = NULL, + .info = "Unsubscribe previously suscribed ViWi objects.", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "get", + .callback = get, + .auth = NULL, + .info = "Get informations about a resource or element", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "load", + .callback = load, + .auth = NULL, + .info = "Load config file in directory passed as argument", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = NULL, + .callback = NULL, + .auth = NULL, + .info = NULL, + .session = 0 + } +}; + +const struct afb_binding_v2 afbBindingV2 = { + .api = "high-viwi", + .specification = _afb_description_v2_high_viwi, + .info = "", + .verbs = _afb_verbs_v2_high_viwi, + .preinit = NULL, + .init = init_service, + .onevent = onEvent, + .noconcurrency = 0 +}; + diff --git a/high-viwi-binding/high-viwi-apidef.json b/high-viwi-binding/high-viwi-apidef.json new file mode 100644 index 0000000..16c2d0b --- /dev/null +++ b/high-viwi-binding/high-viwi-apidef.json @@ -0,0 +1,148 @@ +{ + "openapi": "3.0.0", + "$schema": "http:iot.bzh/download/openapi/schema-3.0/default-schema.json", + "info": { + "description": "", + "title": "high-level-viwi-service", + "version": "4.0", + "x-binding-c-generator": { + "api": "high-viwi", + "version": 2, + "prefix": "", + "postfix": "", + "start": null , + "onevent": "onEvent", + "init": "init_service", + "scope": "", + "private": false + } + }, + "servers": [ + { + "url": "ws://{host}:{port}/api/monitor", + "description": "High ViWi API connected to low level AGL services", + "variables": { + "host": { + "default": "localhost" + }, + "port": { + "default": "1234" + } + }, + "x-afb-events": [ + { + "$ref": "#/components/schemas/afb-event" + } + ] + } + ], + "components": { + "schemas": { + "afb-reply": { + "$ref": "#/components/schemas/afb-reply-v2" + }, + "afb-event": { + "$ref": "#/components/schemas/afb-event-v2" + }, + "afb-reply-v2": { + "title": "Generic response.", + "type": "object", + "required": [ "jtype", "request" ], + "properties": { + "jtype": { + "type": "string", + "const": "afb-reply" + }, + "request": { + "type": "object", + "required": [ "status" ], + "properties": { + "status": { "type": "string" }, + "info": { "type": "string" }, + "token": { "type": "string" }, + "uuid": { "type": "string" }, + "reqid": { "type": "string" } + } + }, + "response": { "type": "object" } + } + }, + "afb-event-v2": { + "type": "object", + "required": [ "jtype", "event" ], + "properties": { + "jtype": { + "type": "string", + "const": "afb-event" + }, + "event": { "type": "string" }, + "data": { "type": "object" } + } + } + }, + "x-permissions": { + }, + "responses": { + "200": { + "description": "A complex object array response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/afb-reply" + } + } + } + } + } + }, + "paths": { + "/subscribe": { + "description": "Subscribe to a ViWi object", + "parameters": [ + { + "in": "query", + "name": "event", + "required": false, + "schema": { "type": "string" } + } + ], + "responses": { + "200": {"$ref": "#/components/responses/200"} + } + }, + "/unsubscribe": { + "description": "Unsubscribe previously suscribed ViWi objects.", + "parameters": [ + { + "in": "query", + "name": "event", + "required": false, + "schema": { "type": "string" } + } + ], + "responses": { + "200": {"$ref": "#/components/responses/200"} + } + }, + "/get": { + "description": "Get informations about a resource or element", + "responses": { + "200": {"$ref": "#/components/responses/200"} + } + }, + "/load": { + "description": "Load config file in directory passed as argument", + "parameters": [ + { + "in": "query", + "name": "path", + "required": true, + "schema": { "type": "string"} + } + ], + "responses": { + "200": {"$ref": "#/components/responses/200"} + } + } + } +} diff --git a/high-can-binding/high-can-binding.cpp b/high-viwi-binding/high-viwi-binding.cpp index 27a49f2..f86fc67 100644 --- a/high-can-binding/high-can-binding.cpp +++ b/high-viwi-binding/high-viwi-binding.cpp @@ -16,9 +16,13 @@ * limitations under the License. */ -#include "high-can-binding-hat.hpp" #include <json-c/json.h> + +#include "high-viwi-binding.hpp" +#include "high-viwi-apidef.h" +#include "wrap-json.h" #include "high.hpp" + High high; /// @brief callback for receiving message from low binding. Treatment itself is made in High class. @@ -76,9 +80,10 @@ int ticked(sd_event_source *source, uint64_t t, void* data) /// @brief Initialize the binding. /// -/// @param[in] service Structure which represent the Application Framework Binder. -void initHigh() +/// @return Exit code, zero if success. +int init_service() { + AFB_DEBUG("High level binding is initializing"); + AFB_NOTICE("High level binding is initialized and running"); + return 0; } - - diff --git a/high-can-binding/high-can-binding-hat.hpp b/high-viwi-binding/high-viwi-binding.hpp index bb912c1..711e531 100644 --- a/high-can-binding/high-can-binding-hat.hpp +++ b/high-viwi-binding/high-viwi-binding.hpp @@ -8,9 +8,5 @@ extern "C" }; void onEvent(const char *event, struct json_object *object); - void subscribe(afb_req request); - void unsubscribe(afb_req request); - void load(afb_req request); - void get(afb_req request); - void initHigh(); + int init_service(); int ticked(sd_event_source *source, uint64_t t, void *data); diff --git a/high-can-binding/high.cpp b/high-viwi-binding/high.cpp index ff252c0..a7c00cc 100644 --- a/high-can-binding/high.cpp +++ b/high-viwi-binding/high.cpp @@ -13,12 +13,16 @@ high-can unsubscribe {"name":"/car/doors/","interval":5000} */ #include <json-c/json.h> -#include <algorithm> -#include "high.hpp" -#include "high-can-binding-hat.hpp" #include <time.h> +#include <algorithm> #include <sstream> #include <iterator> + +#include "filescan-utils.h" +#include "wrap-json.h" +#include "high.hpp" +#include "high-viwi-binding.hpp" + /// @brief Split a std::string in several string, based on a delimeter /// /// @param[in] string: the string to be splitted, delim: the delimeter to use for splitting. @@ -53,15 +57,17 @@ High::High() /// /// @param[in] confd - path to configuration directory which holds the binding configuration to load /// -void High::parseConfigAndSubscribe(const std::string* confd) +void High::parseConfigAndSubscribe(const std::string& confd) { - char *filename; - char*fullpath; + char* filename; + char* fullpath; std::vector<std::string> conf_files_path; - struct json_object* conf_filesJ = ScanForConfig(confd, CTL_SCAN_FLAT, "viwi", "json"); + + // Grab all config files with 'viwi' in their names in the path provided + struct json_object* conf_filesJ = ScanForConfig(confd.c_str(), CTL_SCAN_FLAT, "viwi", "json"); if (!conf_filesJ || json_object_array_length(conf_filesJ) == 0) { - AFB_ERROR("No JSON config files found in %s", confd); + AFB_ERROR("No JSON config files found in %s", confd.c_str()); return; } @@ -69,7 +75,7 @@ void High::parseConfigAndSubscribe(const std::string* confd) { json_object *entryJ=json_object_array_get_idx(conf_filesJ, i); - err= wrap_json_unpack (entryJ, "{s:s, s:s !}", "fullpath", &fullpath,"filename", &filename); + int err = wrap_json_unpack (entryJ, "{s:s, s:s !}", "fullpath", &fullpath,"filename", &filename); if (err) { AFB_ERROR ("OOOPs invalid config file path = %s", json_object_get_string(entryJ)); return; diff --git a/high-can-binding/high.hpp b/high-viwi-binding/high.hpp index 7ccc87d..525f9f9 100644 --- a/high-can-binding/high.hpp +++ b/high-viwi-binding/high.hpp @@ -46,6 +46,8 @@ public: void startTimer(const int &t); ~High(); void parseConfigAndSubscribe(const std::string& confd); + void loadDefinition(const json_object* definitionsJ); + void loadResources(const json_object* resourcesJ); static bool startsWith(const std::string &s, const std::string &val); static void callBackFromSubscribe(void *handle, int iserror, json_object *result); private: |