From 1b3655d85cfb9cc143c9e7f0d3506e6b004f835e Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 11 Oct 2018 12:25:27 +0200 Subject: Migration to binding v3 Change-Id: I0bcccb15200064bd7d83edbf06c1e7202069189a Signed-off-by: Romain Forlot --- conf.d/cmake/config.cmake | 2 +- conf.d/wgt/config.xml.in | 6 +- low-can-binding/CMakeLists.txt | 2 +- low-can-binding/binding/low-can-apidef.json | 2 +- low-can-binding/binding/low-can-cb.cpp | 83 ++++++++++++------------ low-can-binding/binding/low-can-hat.hpp | 1 - low-can-binding/binding/low-can-socket.hpp | 2 +- low-can-binding/binding/low-can-subscription.cpp | 4 +- low-can-binding/binding/low-can-subscription.hpp | 6 +- low-can-binding/utils/signals.hpp | 2 +- low-can-binding/utils/socketcan.hpp | 2 +- 11 files changed, 54 insertions(+), 58 deletions(-) diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake index 924833b3..3fbc3ef6 100644 --- a/conf.d/cmake/config.cmake +++ b/conf.d/cmake/config.cmake @@ -119,7 +119,7 @@ set(CXX_COMPILE_OPTIONS -pthread CACHE STRING "Compilation flags for C++ languag # -D_FORTIFY_SOURCE=2 # CACHE STRING "Compilation flags for RELEASE build type.") -add_definitions(-DAFB_BINDING_VERSION=2) +add_definitions(-DAFB_BINDING_VERSION=3) # Optional location for config.xml.in # ----------------------------------- diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in index 9050690c..0ddccec8 100644 --- a/conf.d/wgt/config.xml.in +++ b/conf.d/wgt/config.xml.in @@ -14,10 +14,10 @@ - + - - + + diff --git a/low-can-binding/CMakeLists.txt b/low-can-binding/CMakeLists.txt index b2892cc1..acbf4f18 100644 --- a/low-can-binding/CMakeLists.txt +++ b/low-can-binding/CMakeLists.txt @@ -50,7 +50,7 @@ PROJECT_TARGET_ADD(low-can) # Binder exposes a unique public entry point SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES PREFIX "afb-" - LABELS "BINDINGV2" + LABELS "BINDINGV3" LINK_FLAGS ${BINDINGS_LINK_FLAG} OUTPUT_NAME ${TARGET_NAME} ) diff --git a/low-can-binding/binding/low-can-apidef.json b/low-can-binding/binding/low-can-apidef.json index 854bdd4a..24eb23be 100644 --- a/low-can-binding/binding/low-can-apidef.json +++ b/low-can-binding/binding/low-can-apidef.json @@ -12,7 +12,7 @@ "postfix": "", "start": null , "onevent": null, - "init": "initv2", + "init": "init_binding", "scope": "", "private": false } diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp index 0f97404c..c5a0138e 100644 --- a/low-can-binding/binding/low-can-cb.cpp +++ b/low-can-binding/binding/low-can-cb.cpp @@ -109,13 +109,13 @@ int read_message(sd_event_source *event_source, int fd, uint32_t revents, void * /// ///*******************************************************************************/ -static int make_subscription_unsubscription(struct afb_req request, - std::shared_ptr& can_subscription, - std::map >& s, - bool subscribe) +static int make_subscription_unsubscription(afb_req_t request, + std::shared_ptr& can_subscription, + std::map >& s, + bool subscribe) { - /* Make the subscription or unsubscription to the event (if request contents are not null) */ - if(request.itf && request.closure && + /* Make the subscription or unsubscription to the event (if request is not null) */ + if(request && ((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s[can_subscription->get_index()]->get_event())) < 0) { AFB_ERROR("Operation goes wrong for signal: %s", can_subscription->get_name().c_str()); @@ -125,7 +125,7 @@ static int make_subscription_unsubscription(struct afb_req request, } static int create_event_handle(std::shared_ptr& can_subscription, - std::map >& s) + std::map >& s) { int sub_index = can_subscription->get_index(); can_subscription->set_event(afb_daemon_make_event(can_subscription->get_name().c_str())); @@ -141,10 +141,10 @@ static int create_event_handle(std::shared_ptr& can_subs /// @brief This will determine if an event handle needs to be created and checks if /// we got a valid afb_event to get subscribe or unsubscribe. After that launch the subscription or unsubscription /// against the application framework using that event handle. -static int subscribe_unsubscribe_signal(struct afb_req request, - bool subscribe, - std::shared_ptr& can_subscription, - std::map >& s) +static int subscribe_unsubscribe_signal(afb_req_t request, + bool subscribe, + std::shared_ptr& can_subscription, + std::map >& s) { int ret = -1; int sub_index = can_subscription->get_index(); @@ -161,7 +161,6 @@ static int subscribe_unsubscribe_signal(struct afb_req request, else { /* Event doesn't exist , so let's create it */ - can_subscription->set_event({nullptr, nullptr}); s[sub_index] = can_subscription; ret = create_event_handle(can_subscription, s); } @@ -184,12 +183,12 @@ static int add_to_event_loop(std::shared_ptr& can_subscr can_subscription.get())); } -static int subscribe_unsubscribe_diagnostic_messages(struct afb_req request, - bool subscribe, - std::vector > diagnostic_messages, - struct event_filter_t& event_filter, - std::map >& s, - bool perm_rec_diag_req) +static int subscribe_unsubscribe_diagnostic_messages(afb_req_t request, + bool subscribe, + std::vector > diagnostic_messages, + struct event_filter_t& event_filter, + std::map >& s, + bool perm_rec_diag_req) { int rets = 0; application_t& app = application_t::instance(); @@ -245,11 +244,11 @@ static int subscribe_unsubscribe_diagnostic_messages(struct afb_req request, return rets; } -static int subscribe_unsubscribe_can_signals(struct afb_req request, - bool subscribe, - std::vector > can_signals, - struct event_filter_t& event_filter, - std::map >& s) +static int subscribe_unsubscribe_can_signals(afb_req_t request, + bool subscribe, + std::vector > can_signals, + struct event_filter_t& event_filter, + std::map >& s) { int rets = 0; for(const auto& sig: can_signals) @@ -287,10 +286,10 @@ static int subscribe_unsubscribe_can_signals(struct afb_req request, /// /// @return Number of correctly subscribed signal /// -static int subscribe_unsubscribe_signals(struct afb_req request, - bool subscribe, - const struct utils::signals_found& signals, - struct event_filter_t& event_filter) +static int subscribe_unsubscribe_signals(afb_req_t request, + bool subscribe, + const struct utils::signals_found& signals, + struct event_filter_t& event_filter) { int rets = 0; utils::signals_manager_t& sm = utils::signals_manager_t::instance(); @@ -304,10 +303,10 @@ static int subscribe_unsubscribe_signals(struct afb_req request, return rets; } -static int one_subscribe_unsubscribe(struct afb_req request, - bool subscribe, - const std::string& tag, - json_object* args) +static int one_subscribe_unsubscribe(afb_req_t request, + bool subscribe, + const std::string& tag, + json_object* args) { int ret = 0; struct event_filter_t event_filter; @@ -341,7 +340,7 @@ static int one_subscribe_unsubscribe(struct afb_req request, return ret; } -static int process_one_subscribe_args(struct afb_req request, bool subscribe, json_object *args) +static int process_one_subscribe_args(afb_req_t request, bool subscribe, json_object *args) { int rc = 0, rc2=0; json_object *x = nullptr, *event = nullptr; @@ -367,7 +366,7 @@ static int process_one_subscribe_args(struct afb_req request, bool subscribe, js return rc; } -static void do_subscribe_unsubscribe(struct afb_req request, bool subscribe) +static void do_subscribe_unsubscribe(afb_req_t request, bool subscribe) { int rc = 0; struct json_object *args, *x; @@ -392,18 +391,18 @@ static void do_subscribe_unsubscribe(struct afb_req request, bool subscribe) afb_req_fail(request, "error", NULL); } -void auth(struct afb_req request) +void auth(afb_req_t request) { afb_req_session_set_LOA(request, 1); afb_req_success(request, NULL, NULL); } -void subscribe(struct afb_req request) +void subscribe(afb_req_t request) { do_subscribe_unsubscribe(request, true); } -void unsubscribe(struct afb_req request) +void unsubscribe(afb_req_t request) { do_subscribe_unsubscribe(request, false); } @@ -484,7 +483,7 @@ static int write_signal(const std::string& name, uint64_t value) return rc; } -void write(struct afb_req request) +void write(afb_req_t request) { int rc = 0; struct json_object* args = nullptr, @@ -561,7 +560,7 @@ static struct json_object *get_signals_value(const std::string& name) return ans; } -void get(struct afb_req request) +void get(afb_req_t request) { int rc = 0; struct json_object* args = nullptr, @@ -619,7 +618,7 @@ static struct json_object *list_can_message(const std::string& name) return ans; } -void list(struct afb_req request) +void list(afb_req_t request) { int rc = 0; json_object *ans = nullptr; @@ -652,7 +651,7 @@ void list(struct afb_req request) /// @param[in] service Structure which represent the Application Framework Binder. /// /// @return Exit code, zero if success. -int initv2() +int init_binding(afb_api_t api) { uint32_t ret = 1; can_bus_t& can_bus_manager = application_t::instance().get_can_bus_manager(); @@ -672,9 +671,7 @@ int initv2() if(sf.can_signals.empty() && sf.diagnostic_messages.size() == 1) { - struct afb_req request; - request.itf = nullptr; - request.closure = nullptr; + afb_req_t request = nullptr; struct event_filter_t event_filter; event_filter.frequency = sf.diagnostic_messages.front()->get_frequency(); diff --git a/low-can-binding/binding/low-can-hat.hpp b/low-can-binding/binding/low-can-hat.hpp index 248b62ce..e21b9cd0 100644 --- a/low-can-binding/binding/low-can-hat.hpp +++ b/low-can-binding/binding/low-can-hat.hpp @@ -28,7 +28,6 @@ class low_can_subscription_t; -int initv2(); void on_no_clients(std::shared_ptr can_subscription, std::map >& s); void on_no_clients(std::shared_ptr can_subscription, uint32_t pid, std::map >& s); int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata); diff --git a/low-can-binding/binding/low-can-socket.hpp b/low-can-binding/binding/low-can-socket.hpp index dee7bd13..00f6825a 100644 --- a/low-can-binding/binding/low-can-socket.hpp +++ b/low-can-binding/binding/low-can-socket.hpp @@ -76,7 +76,7 @@ public: float get_max() const; utils::socketcan_bcm_t& get_socket(); - void set_event(struct afb_event event); + void set_event(afb_event_t event); void set_frequency(float freq); void set_min(float min); void set_max(float max); diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index 20287b88..3f844da3 100644 --- a/low-can-binding/binding/low-can-subscription.cpp +++ b/low-can-binding/binding/low-can-subscription.cpp @@ -20,12 +20,12 @@ #include "application.hpp" #include "canutil/write.h" -struct afb_event& low_can_subscription_t::get_event() +afb_event_t low_can_subscription_t::get_event() { return event_; } -void low_can_subscription_t::set_event(struct afb_event event) +void low_can_subscription_t::set_event(afb_event_t event) { event_ = event; } diff --git a/low-can-binding/binding/low-can-subscription.hpp b/low-can-binding/binding/low-can-subscription.hpp index 2e656b9a..0807feef 100644 --- a/low-can-binding/binding/low-can-subscription.hpp +++ b/low-can-binding/binding/low-can-subscription.hpp @@ -33,11 +33,11 @@ class low_can_subscription_t : public low_can_socket_t { private: - struct afb_event event_; ///< event_ - application framework event used to push on client + afb_event_t event_; ///< event_ - application framework event used to push on client public: using low_can_socket_t::low_can_socket_t; - struct afb_event& get_event(); - void set_event(struct afb_event event); + afb_event_t get_event(); + void set_event(afb_event_t event); }; diff --git a/low-can-binding/utils/signals.hpp b/low-can-binding/utils/signals.hpp index 65316a7d..10cb8ad0 100644 --- a/low-can-binding/utils/signals.hpp +++ b/low-can-binding/utils/signals.hpp @@ -36,7 +36,7 @@ namespace utils std::vector > diagnostic_messages; }; - /// @brief Signal manager singleton hold subscription object with attached afb_event and its mutex + /// @brief Signal manager singleton hold subscription object with attached afb_event_t and its mutex /// to read and write it safely. /// It can be used to browse CAN signals and Diagnostic messages vectors and find a particular signal to /// subscribe to. diff --git a/low-can-binding/utils/socketcan.hpp b/low-can-binding/utils/socketcan.hpp index 40e165bd..a1fdcb58 100644 --- a/low-can-binding/utils/socketcan.hpp +++ b/low-can-binding/utils/socketcan.hpp @@ -65,7 +65,7 @@ namespace utils socketcan_t& operator<<(socketcan_t& s, const T& obj) { if (::sendto(s.socket(), &obj, sizeof(obj), 0, (const struct sockaddr*)&s.get_tx_address(), sizeof(s.get_tx_address())) < 0) - AFB_ERROR("Error sending : %i %s", errno, ::strerror(errno)); + AFB_API_ERROR(afbBindingV3root, "Error sending : %i %s", errno, ::strerror(errno)); return s; } } -- cgit 1.2.3-korg