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 <romain.forlot@iot.bzh>
return socket_.socket() != INVALID_SOCKET;
}
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_;
int low_can_subscription_t::get_index() const
{
return index_;
+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;
void low_can_subscription_t::set_frequency(float freq)
{
event_filter_.frequency = freq;
///
///*******************************************************************************/
///
///*******************************************************************************/
-static int make_subscription_unsubscription(struct afb_req request, std::shared_ptr<low_can_subscription_t>& can_subscription, std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& s, bool subscribe)
+static int make_subscription_unsubscription(struct afb_req request, std::shared_ptr<low_can_subscription_t>& can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s, bool subscribe)
{
/* Make the subscription or unsubscription to the event */
{
/* 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;
{
ERROR(binder_interface, "%s: Operation goes wrong for signal: %s", __FUNCTION__, can_subscription->get_name().c_str());
return -1;
-static int create_event_handle(std::shared_ptr<low_can_subscription_t>& can_subscription, std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& s)
+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();
{
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;
{
ERROR(binder_interface, "%s: Can't create an event for %s, something goes wrong.", __FUNCTION__, can_subscription->get_name().c_str());
return -1;
utils::signals_manager_t& sm = utils::signals_manager_t::instance();
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
utils::signals_manager_t& sm = utils::signals_manager_t::instance();
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
- std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& s = sm.get_subscribed_signals();
+ std::map<int, std::shared_ptr<low_can_subscription_t> >& s = sm.get_subscribed_signals();
if (can_subscription && s.find(sub_index) != s.end())
{
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;
{
NOTICE(binder_interface, "%s: Event isn't valid, no need to unsubscribed.", __FUNCTION__);
ret = -1;
else
{
/* Event doesn't exist , so let's create it */
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);
}
ret = create_event_handle(can_subscription, s);
}
+ struct afb_event event_;
/// Signal part
std::shared_ptr<can_signal_t> can_signal_;
/// Signal part
std::shared_ptr<can_signal_t> can_signal_;
explicit operator bool() const;
int get_index() const;
explicit operator bool() const;
int get_index() const;
+ struct afb_event& get_event();
const std::shared_ptr<can_signal_t> get_can_signal() const;
const std::string get_name() const;
float get_frequency() const;
const std::shared_ptr<can_signal_t> get_can_signal() const;
const std::string get_name() const;
float get_frequency() const;
float get_max() const;
utils::socketcan_bcm_t& get_socket();
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);
void set_frequency(float freq);
void set_min(float min);
void set_max(float max);
{
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
{
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
- std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& s = sm.get_subscribed_signals();
+ std::map<int, std::shared_ptr<low_can_subscription_t> >& s = sm.get_subscribed_signals();
// First we have to found which can_signal_t it is
// First we have to found which can_signal_t it is
- std::shared_ptr<low_can_subscription_t> sig = s[subscription_id].first;
+ std::shared_ptr<low_can_subscription_t> sig = s[subscription_id];
- if( s.find(subscription_id) != s.end() && afb_event_is_valid(s[subscription_id].second))
+ if( s.find(subscription_id) != s.end() && afb_event_is_valid(s[subscription_id]->get_event()))
{
bool send = true;
decoded_message = decoder_t::translateSignal(*sig->get_can_signal(), can_message, conf.get_all_can_signals(), &send);
{
bool send = true;
decoded_message = decoder_t::translateSignal(*sig->get_can_signal(), can_message, conf.get_all_can_signals(), &send);
{
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
{
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
- std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& s = sm.get_subscribed_signals();
+ std::map<int, std::shared_ptr<low_can_subscription_t> >& s = sm.get_subscribed_signals();
openxc_VehicleMessage vehicle_message = manager.find_and_decode_adr(can_message);
if( (vehicle_message.has_simple_message && vehicle_message.simple_message.has_name) &&
openxc_VehicleMessage vehicle_message = manager.find_and_decode_adr(can_message);
if( (vehicle_message.has_simple_message && vehicle_message.simple_message.has_name) &&
- s.find(subscription_id) != s.end() && afb_event_is_valid(s[subscription_id].second))
+ s.find(subscription_id) != s.end() && afb_event_is_valid(s[subscription_id]->get_event()))
- if (apply_filter(vehicle_message, s[subscription_id].first))
+ if (apply_filter(vehicle_message, s[subscription_id]))
{
std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex_);
push_new_vehicle_message(subscription_id, vehicle_message);
{
std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex_);
push_new_vehicle_message(subscription_id, vehicle_message);
- DEBUG(binder_interface, "%s: %s CAN signals processed.", __FUNCTION__, s[subscription_id].first->get_name().c_str());
+ DEBUG(binder_interface, "%s: %s CAN signals processed.", __FUNCTION__, s[subscription_id]->get_name().c_str());
s_message = get_simple_message(v_message.second);
{
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
s_message = get_simple_message(v_message.second);
{
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
- std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& s = sm.get_subscribed_signals();
- if(s.find(v_message.first) != s.end() && afb_event_is_valid(s[v_message.first].second))
+ std::map<int, std::shared_ptr<low_can_subscription_t> >& s = sm.get_subscribed_signals();
+ if(s.find(v_message.first) != s.end() && afb_event_is_valid(s[v_message.first]->get_event()))
{
jo = json_object_new_object();
jsonify_simple(s_message, jo);
{
jo = json_object_new_object();
jsonify_simple(s_message, jo);
- if(afb_event_push(s[v_message.first].second, jo) == 0)
+ if(afb_event_push(s[v_message.first]->get_event(), jo) == 0)
on_no_clients(std::string(s_message.name));
}
}
on_no_clients(std::string(s_message.name));
}
}
/// @brief return the subscribed_signals map.
///
/// @return Map of subscribed signals.
/// @brief return the subscribed_signals map.
///
/// @return Map of subscribed signals.
- std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& signals_manager_t::get_subscribed_signals()
+ std::map<int, std::shared_ptr<low_can_subscription_t> >& signals_manager_t::get_subscribed_signals()
{
return subscribed_signals_;
}
{
return subscribed_signals_;
}
{
private:
std::mutex subscribed_signals_mutex_;
{
private:
std::mutex subscribed_signals_mutex_;
- std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> > subscribed_signals_;
+ std::map<int, std::shared_ptr<low_can_subscription_t> > subscribed_signals_;
signals_manager_t(); ///< Private constructor to make singleton class.
signals_manager_t(); ///< Private constructor to make singleton class.
static signals_manager_t& instance();
std::mutex& get_subscribed_signals_mutex();
static signals_manager_t& instance();
std::mutex& get_subscribed_signals_mutex();
- std::map<int, std::pair<std::shared_ptr<low_can_subscription_t>, struct afb_event> >& get_subscribed_signals();
+ std::map<int, std::shared_ptr<low_can_subscription_t> >& get_subscribed_signals();
struct signals_found find_signals(const openxc_DynamicField &key);
void find_diagnostic_messages(const openxc_DynamicField &key, std::vector<std::shared_ptr<diagnostic_message_t> >& found_signals);
struct signals_found find_signals(const openxc_DynamicField &key);
void find_diagnostic_messages(const openxc_DynamicField &key, std::vector<std::shared_ptr<diagnostic_message_t> >& found_signals);