BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
5c70d9d
Branches
Tags
master
libetherpix
simulator
config.h
implement receiving packets
Stefan Schuermans
commited
5c70d9d
at 2017-06-11 15:48:14
config.h
Blame
History
Raw
/* * EtherPix simulator * * Copyright 2017 Stefan Schuermans <stefan schuermans info> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef CONFIG_H #define CONFIG_H #include <arpa/inet.h> #include <gtkmm.h> #include <map> #include <string> #include <vector> #include "bbox.h" #include "distri.h" #include "transform.h" /// config file class Config { public: /** * @brief constructor * @param[in] configFile name of config file */ Config(std::string const &configFile); /// get bounding box BBox const &getBBox() const { return m_bb; } /** * @brief create sockets and listen for incoming packets * @throws std::exception in case of error */ void start(); /** * @brief stop listening for incoming packets and close sockets */ void stop(); /// get and reset packet counter of all distributors unsigned long getPacketCounterAndReset(); /** * @brief draw pixels of all distributors * @param[in] cairo cairo context for drawing * @param[in] tf coordinate transformation */ void draw(Cairo::RefPtr<Cairo::Context> &cairo, Transform const &tf) const; protected: /// distributor map: distributor number -> distributor object typedef std::map<unsigned long, Distri> DistriMap; protected: /** * @brief remove whitespace at beging and end of string * @param[in,out] str string to process */ static void trim(std::string &str); /** * @brief split string at sequences of whitespace * @param[in] str string to split * @param[out] fields fields of string */ static void split(std::string const &str, std::vector<std::string> &fields); /** * @brief split string at specific character * @param[in] str string to split * @param[in] delim delimiter character * @param[out] fields fields of string */ static void split_chr(std::string const &str, char delim, std::vector<std::string> &fields); /** * @brief convert string to unsigned long * @param[in] str string to convert * @return unsigned long parsed from string * @throws std::exception in case of error */ static unsigned long str2ul(std::string const &str); /** * @brief convert string to two unsigned longs * @param[in] str string containing two comma-separated unsigned integers * @param[out] ul1 first unsigned long parsed from string * @param[out] ul2 second unsigned long parsed from string * @throws std::exception in case of error */ static void str2ul2(std::string const &str, unsigned long &ul1, unsigned long &ul2); /** * @brief convert string to double (using the decimal dot for any locale) * @param[in] str string to convert * @return double parsed from string * @throws std::exception in case of error */ static double str2d(std::string const &str); /** * @brief convert string to three doubles (decimal dot for any locale) * @param[in] str string containing three comma-separated doubles * @param[out] d1 first double parsed from string * @param[out] d2 second double parsed from string * @param[out] d3 third double parsed from string * @throws std::exception in case of error */ static void str2d3(std::string const &str, double &d1, double &d2, double &d3); /** * @brief convert string to IPv4/port address * @param[in] str string containing IPv4/port address * @throws std::exception in case of error */ static void str2addr(std::string const &str, struct sockaddr_in &addr); /** * @brief read config file * @param[in] configFile name of config file * @throws std::exception in case of error */ void readFile(std::string const &configFile); /** * @brief process line from config file * @param[in] line line to process * @throws std::exception in case of error */ void procLine(std::string line); /** * @brief process setting from config file * @param[in] setting name of the setting * @param[in] value value for setting * @throws std::exception in case of error */ void procSetting(std::string const &setting, std::string const &value); /** * @brief process distributor line from config file * @param[in] setFields fields of the setting parts * @param[in] valFields fields of the value part * @throws std::exception in case of error */ void proc_distributor(std::vector<std::string> const &setFields, std::vector<std::string> const &valFields); /** * @brief process distributorAddr line from config file * @param[in] setFields fields of the setting parts * @param[in] valFields fields of the value part * @throws std::exception in case of error */ void proc_distributorAddr(std::vector<std::string> const &setFields, std::vector<std::string> const &valFields); /** * @brief process mapping line from config file * @param[in] setFields fields of the setting parts * @param[in] valFields fields of the value part * @throws std::exception in case of error */ void proc_mapping(std::vector<std::string> const &setFields, std::vector<std::string> const &valFields); /** * @brief process output line from config file * @param[in] setFields fields of the setting parts * @param[in] valFields fields of the value part * @throws std::exception in case of error */ void proc_output(std::vector<std::string> const &setFields, std::vector<std::string> const &valFields); /** * @brief get distributor * @param[in] strDistno distributor number as string * @return reference to distributor object in map * @throws std::exception in case of error */ Distri & getDistri(std::string const &strDistno); /** * @brief get distributor * @param[in] distno distributor number * @return reference to distributor object in map * @throws std::exception in case of error */ Distri & getDistri(unsigned long distno); /// update internal data void update(); protected: /// distributors DistriMap m_distriMap; /// bounding box of all pixels BBox m_bb; }; #endif // #ifndef CONFIG_H