2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
24 #include "openxc.pb.h"
25 #include "../binding/application.hpp"
26 #include "../can/can-signals.hpp"
27 #include "../diagnostic/diagnostic-message.hpp"
29 #include "../binding/low-can-hat.hpp"
30 #include "../binding/low-can-subscription.hpp"
36 std::vector<std::shared_ptr<can_signal_t> > can_signals;
37 std::vector<std::shared_ptr<diagnostic_message_t> > diagnostic_messages;
40 /// @brief Signal manager singleton hold subscription object with attached afb_event and its mutex
41 /// to read and write it safely.
42 /// It can be used to browse CAN signals and Diagnostic messages vectors and find a particular signal to
44 class signals_manager_t
47 std::mutex subscribed_signals_mutex_;
48 std::map<int, std::shared_ptr<low_can_subscription_t> > subscribed_signals_; ///< Map containing all subscribed signals, key is the socket int value.
50 signals_manager_t(); ///< Private constructor to make singleton class.
53 static signals_manager_t& instance();
55 std::mutex& get_subscribed_signals_mutex();
56 std::map<int, std::shared_ptr<low_can_subscription_t> >& get_subscribed_signals();
58 struct signals_found find_signals(const openxc_DynamicField &key);
59 void find_diagnostic_messages(const openxc_DynamicField &key, std::vector<std::shared_ptr<diagnostic_message_t> >& found_signals);
60 void find_can_signals(const openxc_DynamicField &key, std::vector<std::shared_ptr<can_signal_t> >& found_signals);
63 void lookup_signals_by_name(const std::string& key, std::vector<std::shared_ptr<T> > signals, std::vector<std::shared_ptr<T> >& found_signals)
65 for(std::shared_ptr<T> s : signals)
67 if(::fnmatch(key.c_str(), s->get_generic_name().c_str(), FNM_CASEFOLD) == 0)
68 found_signals.push_back(s);
69 else if(::fnmatch(key.c_str(), s->get_name().c_str(), FNM_CASEFOLD) == 0)
70 found_signals.push_back(s);
75 void lookup_signals_by_id(const double key, std::vector<std::shared_ptr<T> > signals, std::vector<std::shared_ptr<T> >& found_signals)
77 for(std::shared_ptr<T> s : signals)
79 if(application_t::instance().get_signal_id(*s) == key)
81 found_signals.push_back(s);