5bca604f0c06d7d3c0c8d746e2aabefb53d2bb43
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

1) /*
2)  * EtherPix simulator
3)  *
4)  * Copyright 2017 Stefan Schuermans <stefan schuermans info>
5)  *
6)  * This program is free software: you can redistribute it and/or modify
7)  * it under the terms of the GNU General Public License as published by
8)  * the Free Software Foundation, version 3 of the License.
9)  *
10)  *
11)  * This program is distributed in the hope that it will be useful,
12)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14)  * GNU General Public License for more details.
15)  *
16)  * You should have received a copy of the GNU Lesser General Public License
17)  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18)  */
19) 
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

20) #include <arpa/inet.h>
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

21) #include <gtkmm.h>
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

22) #include <map>
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

23) #include <sstream>
24) #include <stdexcept>
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

25) #include <vector>
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

26) 
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

27) #include "bbox.h"
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

28) #include "distri.h"
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

29) #include "mapping.h"
30) #include "pixel.h"
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

31) #include "transform.h"
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

32) 
33) /// constructor
34) Distri::Distri():
35)   m_distno(0),
36)   m_outputs(0),
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

37)   m_pixels(0),
38)   m_mappings(),
39)   m_outputMap()
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

40) {
41) }
42) 
43) /**
44)  * @brief initialize
45)  * @param[in] distno distributor number
46)  * @param[in] outputs number of outputs
47)  * @param[in] pixels number of pixels per output
48)  */
49) void Distri::init(unsigned long distno, unsigned long outputs,
50)                   unsigned long pixels)
51) {
52)   m_distno = distno;
53)   m_outputs = outputs;
54)   m_pixels = pixels;
55) }
56) 
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

57) /**
58)  * @brief set network address
59)  * @param[in] addr IPv4/port network address (UDP)
60)  */
61) void Distri::setAddr(struct sockaddr_in const &addr)
62) {
63)   m_addr = addr;
64) }
65) 
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

66) /**
67)  * @brief get mapping
68)  * @param[in] chan color channel
69)  * @return mapping mapping object of color channel
70)  * @throws std::exception in case of error
71)  */
72) Mapping const& Distri::getMapping(Mapping::Channel chan) const
73) {
74)   if (chan >= Mapping::ChannelCount) {
75)     std::stringstream msg;
76)     msg << "invalid channel: " << chan;
77)     throw std::runtime_error(msg.str());
78)   }
79)   return m_mappings[chan];
80) }
81) 
82) /**
83)  * @brief set mapping
84)  * @param[in] chan color channel
85)  * @param[in] mapping new mapping object for color channel
86)  * @throws std::exception in case of error
87)  */
88) void Distri::setMapping(Mapping::Channel chan, Mapping const &mapping)
89) {
90)   if (chan >= Mapping::ChannelCount) {
91)     std::stringstream msg;
92)     msg << "invalid channel: " << chan;
93)     throw std::runtime_error(msg.str());
94)   }
95)   m_mappings[chan] = mapping;
96) }
97) 
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

98) /**
99)  * @brief add output to distributor
100)  * @param[in] outno number of output
101)  * @throws std::exception in case of error
102)  */
103) void Distri::addOutput(unsigned long outno)
104) {
105)   if (outno >= m_outputs) {
106)     std::stringstream msg;
107)     msg << "invalid output number " << outno << ": only " << m_outputs
108)         << " outputs supported";
109)     throw std::runtime_error(msg.str());
110)   }
111) 
112)   if (m_outputMap.find(outno) != m_outputMap.end()) {
113)     std::stringstream msg;
114)     msg << "output " << outno << " already exists";
115)     throw std::runtime_error(msg.str());
116)   }
117) 
118)   m_outputMap[outno];
119) }
120) 
121) /**
122)  * @brief add pixel to output of distributor
123)  * @param[in] outno number of output
124)  * @param[in] pixel pixel object to add
125)  * @throws std::exception in case of error
126)  */
127) void Distri::addPixel(unsigned long outno, Pixel const &pixel)
128) {
129)   if (m_outputMap.find(outno) == m_outputMap.end()) {
130)     std::stringstream msg;
131)     msg << "output " << outno << " does not exist";
132)     throw std::runtime_error(msg.str());
133)   }
134) 
135)   Output &output = m_outputMap[outno];
136) 
137)   if (output.m_pixels.size() >= m_pixels) {
138)     std::stringstream msg;
139)     msg << "cannot add pixel to output " << outno << ": already " << m_pixels
140)         << " pixels at this output (this is the maximum)";
141)     throw std::runtime_error(msg.str());
142)   }
143) 
144)   output.m_pixels.push_back(pixel);
145) }
146)