BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
8e0a57f
Branches
Tags
master
libetherpix
simulator
distri.cpp
complete implementation of config file parsing
Stefan Schuermans
commited
8e0a57f
at 2017-06-10 21:21:50
distri.cpp
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/>. */ #include <arpa/inet.h> #include <map> #include <sstream> #include <stdexcept> #include <vector> #include "distri.h" #include "mapping.h" #include "pixel.h" /// constructor Distri::Distri(): m_distno(0), m_outputs(0), m_pixels(0), m_mappings(), m_outputMap() { } /** * @brief initialize * @param[in] distno distributor number * @param[in] outputs number of outputs * @param[in] pixels number of pixels per output */ void Distri::init(unsigned long distno, unsigned long outputs, unsigned long pixels) { m_distno = distno; m_outputs = outputs; m_pixels = pixels; } /** * @brief set network address * @param[in] addr IPv4/port network address (UDP) */ void Distri::setAddr(struct sockaddr_in const &addr) { m_addr = addr; } /** * @brief get mapping * @param[in] chan color channel * @return mapping mapping object of color channel * @throws std::exception in case of error */ Mapping const& Distri::getMapping(Mapping::Channel chan) const { if (chan >= Mapping::ChannelCount) { std::stringstream msg; msg << "invalid channel: " << chan; throw std::runtime_error(msg.str()); } return m_mappings[chan]; } /** * @brief set mapping * @param[in] chan color channel * @param[in] mapping new mapping object for color channel * @throws std::exception in case of error */ void Distri::setMapping(Mapping::Channel chan, Mapping const &mapping) { if (chan >= Mapping::ChannelCount) { std::stringstream msg; msg << "invalid channel: " << chan; throw std::runtime_error(msg.str()); } m_mappings[chan] = mapping; } /** * @brief add output to distributor * @param[in] outno number of output * @throws std::exception in case of error */ void Distri::addOutput(unsigned long outno) { if (outno >= m_outputs) { std::stringstream msg; msg << "invalid output number " << outno << ": only " << m_outputs << " outputs supported"; throw std::runtime_error(msg.str()); } if (m_outputMap.find(outno) != m_outputMap.end()) { std::stringstream msg; msg << "output " << outno << " already exists"; throw std::runtime_error(msg.str()); } m_outputMap[outno]; } /** * @brief add pixel to output of distributor * @param[in] outno number of output * @param[in] pixel pixel object to add * @throws std::exception in case of error */ void Distri::addPixel(unsigned long outno, Pixel const &pixel) { if (m_outputMap.find(outno) == m_outputMap.end()) { std::stringstream msg; msg << "output " << outno << " does not exist"; throw std::runtime_error(msg.str()); } Output &output = m_outputMap[outno]; if (output.m_pixels.size() >= m_pixels) { std::stringstream msg; msg << "cannot add pixel to output " << outno << ": already " << m_pixels << " pixels at this output (this is the maximum)"; throw std::runtime_error(msg.str()); } output.m_pixels.push_back(pixel); }