BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
5c70d9d
Branches
Tags
master
libetherpix
simulator
distri.h
implement receiving packets
Stefan Schuermans
commited
5c70d9d
at 2017-06-11 15:48:14
distri.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 DISTRI_H #define DISTRI_H #include <arpa/inet.h> #include <gtkmm.h> #include <map> #include <stdint.h> #include <vector> #include "bbox.h" #include "mapping.h" #include "pixel.h" #include "transform.h" /// distributor class Distri { public: /// constructor Distri(); /// destructor ~Distri(); /** * @brief initialize * @param[in] distno distributor number * @param[in] outputs number of outputs * @param[in] pixels number of pixels per output */ void init(unsigned long distno, unsigned long outputs, unsigned long pixels); /// get distributor number unsigned long getNo() const { return m_distno; } /// get number of outputs unsigned long getOutputs() const { return m_outputs; } /// get number of pixels at each output unsigned long getPixels() const { return m_pixels; } /** * @brief set network address * @param[in] addr IPv4/port network address (UDP) */ void setAddr(struct sockaddr_in const &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& getMapping(Mapping::Channel chan) const; /** * @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 setMapping(Mapping::Channel chan, Mapping const &mapping); /** * @brief add output to distributor * @param[in] outno number of output * @throws std::exception in case of error */ void addOutput(unsigned long 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 addPixel(unsigned long outno, Pixel const &pixel); /** * @brief add all pixels of this distributor to the bounding box * @param[in,out] bb bounding box */ void updateBBox(BBox &bb) const; /** * @brief create socket and listen for incoming packets * @throws std::exception in case of error */ void start(); /** * @brief stop listening for incoming packets and close socket */ void stop(); /// get and reset packet conter unsigned long getPacketCounterAndReset(); /** * @brief draw pixels of this distributor * @param[in] cairo cairo context for drawing * @param[in] tf coordinate transformation */ void draw(Cairo::RefPtr<Cairo::Context> &cairo, Transform const &tf) const; protected: /** * @brief callback on packet input on socket */ bool on_packet(Glib::IOCondition condition); /** * @brief process pixel data * @param[in] outputs number of outputs in pixel data * @param[in] pixels number of pixels per output in pixel data * @param[in] data pixel data */ void procPixelData(unsigned long outputs, unsigned long pixels, uint8_t const *data); protected: /// output data struct Output { std::vector<Pixel> m_pixels; ///< pixels at this output }; /// map out outputs: output number -> output data typedef std::map<unsigned long, Output> OutputMap; protected: /// distributor number unsigned long m_distno; /// number of outputs unsigned long m_outputs; /// number of pixels per output unsigned long m_pixels; /// network address struct sockaddr_in m_addr; /// mappings of color channels Mapping m_mappings[Mapping::ChannelCount]; /// outputs OutputMap m_outputMap; /// IPv4/UDP socket int m_sock; /// Glib connection for notification of input on m_sock sigc::connection m_conn; /// received packets since last reset unsigned long m_packets; }; #endif // #ifndef DISTRI_H