summaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-06-08 15:25:27 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-06-09 11:43:31 +0200
commit32fb0e5b1949ef115e92de9457cb4e83854e51f2 (patch)
treebb9444fb67783eda6a187acf17bcdffcdea4f8ec /CAN-binder/low-can-binding/binding
parentce2bd1c557ae2cb44db1794909f129e82286c305 (diff)
Migration to AFB Binding V2
No more binder interface needed to use logging macros and others stuff like make_event or any other calls Change-Id: Iaee60697373bc8a0e67518e924b36b5389533e68 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/binding')
-rw-r--r--CAN-binder/low-can-binding/binding/low-can-cb.cpp22
-rw-r--r--CAN-binder/low-can-binding/binding/low-can-hat.cpp38
-rw-r--r--CAN-binder/low-can-binding/binding/low-can-hat.hpp6
3 files changed, 28 insertions, 38 deletions
diff --git a/CAN-binder/low-can-binding/binding/low-can-cb.cpp b/CAN-binder/low-can-binding/binding/low-can-cb.cpp
index e352101..97b6d20 100644
--- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp
+++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp
@@ -105,7 +105,7 @@ static int make_subscription_unsubscription(struct afb_req request, std::shared_
/* Make the subscription or unsubscription to the event */
if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s[can_subscription->get_index()]->get_event())) < 0)
{
- ERROR(binder_interface, "%s: Operation goes wrong for signal: %s", __FUNCTION__, can_subscription->get_name().c_str());
+ ERROR("Operation goes wrong for signal: %s", can_subscription->get_name().c_str());
return -1;
}
return 0;
@@ -114,11 +114,11 @@ static int make_subscription_unsubscription(struct afb_req request, std::shared_
static int create_event_handle(std::shared_ptr<low_can_subscription_t>& can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s)
{
int sub_index = can_subscription->get_index();
- can_subscription->set_event(afb_daemon_make_event(binder_interface->daemon, can_subscription->get_name().c_str()));
+ can_subscription->set_event(afb_daemon_make_event(can_subscription->get_name().c_str()));
s[sub_index] = can_subscription;
if (!afb_event_is_valid(s[sub_index]->get_event()))
{
- ERROR(binder_interface, "%s: Can't create an event for %s, something goes wrong.", __FUNCTION__, can_subscription->get_name().c_str());
+ ERROR("Can't create an event for %s, something goes wrong.", can_subscription->get_name().c_str());
return -1;
}
return 0;
@@ -136,7 +136,7 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
{
if (!afb_event_is_valid(s[sub_index]->get_event()) && !subscribe)
{
- NOTICE(binder_interface, "%s: Event isn't valid, no need to unsubscribed.", __FUNCTION__);
+ NOTICE("Event isn't valid, no need to unsubscribed.");
ret = -1;
}
ret = 0;
@@ -159,7 +159,7 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
static int add_to_event_loop(std::shared_ptr<low_can_subscription_t>& can_subscription)
{
struct sd_event_source* event_source = nullptr;
- return ( sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon),
+ return ( sd_event_add_io(afb_daemon_get_event_loop(),
&event_source,
can_subscription->get_socket().socket(),
EPOLLIN,
@@ -192,22 +192,22 @@ static int subscribe_unsubscribe_diagnostic_messages(struct afb_req request, boo
diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), event_filter.frequency);
if(can_subscription->create_rx_filter(sig) < 0)
{return -1;}
- DEBUG(binder_interface, "%s: Signal: %s subscribed", __FUNCTION__, sig->get_name().c_str());
+ DEBUG("Signal: %s subscribed", sig->get_name().c_str());
if(it == s.end() && add_to_event_loop(can_subscription) < 0)
{
diag_m.cleanup_request(
diag_m.find_recurring_request(*diag_req), true);
- WARNING(binder_interface, "%s: signal: %s isn't supported. Canceling operation.", __FUNCTION__, sig->get_name().c_str());
+ WARNING("signal: %s isn't supported. Canceling operation.", sig->get_name().c_str());
return -1;
}
}
else
{
if(sig->get_supported())
- {DEBUG(binder_interface, "%s: %s cancelled due to unsubscribe", __FUNCTION__, sig->get_name().c_str());}
+ {DEBUG("%s cancelled due to unsubscribe", sig->get_name().c_str());}
else
{
- WARNING(binder_interface, "%s: signal: %s isn't supported. Canceling operation.", __FUNCTION__, sig->get_name().c_str());
+ WARNING("signal: %s isn't supported. Canceling operation.", sig->get_name().c_str());
return -1;
}
}
@@ -245,7 +245,7 @@ static int subscribe_unsubscribe_can_signals(struct afb_req request, bool subscr
{return -1;}
rets++;
- DEBUG(binder_interface, "%s: signal: %s subscribed", __FUNCTION__, sig->get_name().c_str());
+ DEBUG("signal: %s subscribed", sig->get_name().c_str());
}
return rets;
}
@@ -307,7 +307,7 @@ static int one_subscribe_unsubscribe(struct afb_req request, bool subscribe, con
openxc_DynamicField search_key = build_DynamicField(tag);
sf = utils::signals_manager_t::instance().find_signals(search_key);
if (sf.can_signals.empty() && sf.diagnostic_messages.empty())
- NOTICE(binder_interface, "%s: No signal(s) found for %s.", __FUNCTION__, tag.c_str());
+ NOTICE("No signal(s) found for %s.", tag.c_str());
else
ret = subscribe_unsubscribe_signals(request, subscribe, sf, event_filter);
diff --git a/CAN-binder/low-can-binding/binding/low-can-hat.cpp b/CAN-binder/low-can-binding/binding/low-can-hat.cpp
index e8e5629..7113b69 100644
--- a/CAN-binder/low-can-binding/binding/low-can-hat.cpp
+++ b/CAN-binder/low-can-binding/binding/low-can-hat.cpp
@@ -28,39 +28,33 @@
#include "application.hpp"
#include "../can/can-bus.hpp"
-// Interface between the daemon and the binding
-const struct afb_binding_interface *binder_interface;
-
extern "C"
{
- static const struct afb_verb_desc_v1 verbs[]=
+ static int initv2();
+
+ static const struct afb_verb_v2 verbs[]=
{
- { .name= "subscribe", .session= AFB_SESSION_NONE, .callback= subscribe, .info= "subscribe to notification of CAN bus messages." },
- { .name= "unsubscribe", .session= AFB_SESSION_NONE, .callback= unsubscribe, .info= "unsubscribe a previous subscription." }
+ { .verb= "subscribe", .callback= subscribe, .auth= NULL, .session= AFB_SESSION_NONE},
+ { .verb= "unsubscribe", .callback= unsubscribe, .auth= NULL, .session= AFB_SESSION_NONE},
+ { .verb= NULL, .callback= NULL, .auth= NULL, .session= 0}
};
- static const struct afb_binding binding_desc {
- AFB_BINDING_VERSION_1,
- {
- "Low level CAN bus service",
- "low-can",
- verbs
- }
+ const struct afb_binding_v2 afbBindingV2 {
+ .api = "low-can",
+ .specification = NULL,
+ .verbs = verbs,
+ .preinit = NULL,
+ .init = initv2,
+ .onevent = NULL,
+ .noconcurrency = 0
};
- const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *itf)
- {
- binder_interface = itf;
-
- return &binding_desc;
- }
-
/// @brief Initialize the binding.
///
/// @param[in] service Structure which represent the Application Framework Binder.
///
/// @return Exit code, zero if success.
- int afbBindingV1ServiceInit(struct afb_service service)
+ static int initv2()
{
can_bus_t& can_bus_manager = application_t::instance().get_can_bus_manager();
@@ -73,7 +67,7 @@ extern "C"
if(application_t::instance().get_diagnostic_manager().initialize())
return 0;
- ERROR(binder_interface, "%s: There was something wrong with CAN device Initialization.", __FUNCTION__);
+ ERROR("There was something wrong with CAN device Initialization.");
return 1;
}
};
diff --git a/CAN-binder/low-can-binding/binding/low-can-hat.hpp b/CAN-binder/low-can-binding/binding/low-can-hat.hpp
index 34dd80b..cf3d999 100644
--- a/CAN-binder/low-can-binding/binding/low-can-hat.hpp
+++ b/CAN-binder/low-can-binding/binding/low-can-hat.hpp
@@ -26,14 +26,10 @@
extern "C"
{
- #define AFB_BINDING_VERSION 1
+ #define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
};
-extern "C" struct afb_binding_interface;
-
-extern const struct afb_binding_interface *binder_interface;
-
class low_can_subscription_t;
void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s);