2 * Copyright (C) 2015, 2016 ,2017 "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.
18 #include "config-parser.hpp"
20 #include "../binding/low-can-hat.hpp"
24 /// @brief constructor using path to file
25 config_parser_t::config_parser_t(std::string conf_file)
26 : filepath_{conf_file}, config_content_{}
28 config_content_.read_file(conf_file);
31 const std::string& config_parser_t::filepath() const
36 /// @brief read the conf_file_ and parse it into an INIReader object
37 /// to search into later.
38 bool config_parser_t::check_conf()
40 if (config_content_.size() <= 0)
42 AFB_ERROR("Can't load the INI config file: /etc/dev-mapping.conf.");
45 AFB_DEBUG("Configuration file parsed");
49 /// @brief Public method to access devices_name_ vector. If vector size equal 0
50 /// then it will parses the configuration file content to fill it. It could be empty even
51 /// after parsing if content file just don't have a correct "canbus" directive so you
52 /// have to test the returned value.
54 /// @return A const vector with string of linux CAN devices.
55 const std::vector<std::pair<std::string, std::string> > config_parser_t::get_devices_name()
57 std::vector<std::pair<std::string, std::string> > devices_name;
59 std::map<std::string, std::string> bus_mapping = config_content_.get_keys("CANbus-mapping");
60 for(const auto& busIt : bus_mapping )
62 devices_name.push_back(std::make_pair(busIt.first, busIt.second));