From e9b00c3af0c469726e32755715a69395ad1d3718 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 1 Jun 2017 13:46:10 +0200 Subject: Simplify processing event Set afb_event into subscription object then there is no more std::pair used t access it, better use a method from low_can_subscription_t class Change-Id: Ic0772d97c18ca8899821cf3ce175166bbe0be660 Signed-off-by: Romain Forlot --- CAN-binder/low-can-binding/binding/low-can-cb.cpp | 30 +++++++++++++++-------- CAN-binder/low-can-binding/binding/low-can-cb.hpp | 3 +++ 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'CAN-binder/low-can-binding/binding') 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 5f24546..6504acf 100644 --- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp +++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp @@ -80,6 +80,11 @@ low_can_subscription_t::operator bool() const return socket_.socket() != INVALID_SOCKET; } +struct afb_event& low_can_subscription_t::get_event() +{ + return event_; +} + int low_can_subscription_t::get_index() const { return index_; @@ -120,6 +125,11 @@ utils::socketcan_bcm_t& low_can_subscription_t::get_socket() return socket_; } +void low_can_subscription_t::set_event(struct afb_event event) +{ + event_ = event; +} + void low_can_subscription_t::set_frequency(float freq) { event_filter_.frequency = freq; @@ -266,10 +276,10 @@ int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata) /// ///*******************************************************************************/ -static int make_subscription_unsubscription(struct afb_req request, std::shared_ptr& can_subscription, std::map, struct afb_event> >& s, bool subscribe) +static int make_subscription_unsubscription(struct afb_req request, std::shared_ptr& can_subscription, std::map >& s, bool subscribe) { /* Make the subscription or unsubscription to the event */ - if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s[can_subscription->get_index()].second)) < 0) + 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()); return -1; @@ -277,12 +287,12 @@ static int make_subscription_unsubscription(struct afb_req request, std::shared_ return 0; } -static int create_event_handle(std::shared_ptr& can_subscription, std::map, struct afb_event> >& s) +static int create_event_handle(std::shared_ptr& can_subscription, std::map >& s) { int sub_index = can_subscription->get_index(); - struct afb_event event = afb_daemon_make_event(binder_interface->daemon, can_subscription->get_name().c_str()); - s[sub_index] = std::make_pair(can_subscription, event); - if (!afb_event_is_valid(s[sub_index].second)) + can_subscription->set_event(afb_daemon_make_event(binder_interface->daemon, 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()); return -1; @@ -300,10 +310,10 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe, utils::signals_manager_t& sm = utils::signals_manager_t::instance(); std::lock_guard subscribed_signals_lock(sm.get_subscribed_signals_mutex()); - std::map, struct afb_event> >& s = sm.get_subscribed_signals(); + std::map >& s = sm.get_subscribed_signals(); if (can_subscription && s.find(sub_index) != s.end()) { - if (!afb_event_is_valid(s[sub_index].second) && !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__); ret = -1; @@ -317,8 +327,8 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe, else { /* Event doesn't exist , so let's create it */ - struct afb_event empty_event = {nullptr, nullptr}; - s[sub_index] = std::make_pair(can_subscription, empty_event); + can_subscription->set_event({nullptr, nullptr}); + s[sub_index] = can_subscription; ret = create_event_handle(can_subscription, s); } diff --git a/CAN-binder/low-can-binding/binding/low-can-cb.hpp b/CAN-binder/low-can-binding/binding/low-can-cb.hpp index 0f276fb..ad3f74f 100644 --- a/CAN-binder/low-can-binding/binding/low-can-cb.hpp +++ b/CAN-binder/low-can-binding/binding/low-can-cb.hpp @@ -37,6 +37,7 @@ class low_can_subscription_t { private: int index_; + struct afb_event event_; /// Signal part std::shared_ptr can_signal_; @@ -57,6 +58,7 @@ public: explicit operator bool() const; int get_index() const; + struct afb_event& get_event(); const std::shared_ptr get_can_signal() const; const std::string get_name() const; float get_frequency() const; @@ -64,6 +66,7 @@ public: float get_max() const; utils::socketcan_bcm_t& get_socket(); + void set_event(struct afb_event event); void set_frequency(float freq); void set_min(float min); void set_max(float max); -- cgit 1.2.3-korg