Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
E133Receiver.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * E133Receiver.h
17  * Handles E1.33 UDP packets and executes RDM and Status message callbacks.
18  * Copyright (C) 2013 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_E133_E133RECEIVER_H_
22 #define INCLUDE_OLA_E133_E133RECEIVER_H_
23 
24 #include <ola/Callback.h>
25 #include <ola/base/Macro.h>
27 #include <ola/network/Socket.h>
28 #include <ola/rdm/RDMCommand.h>
29 
30 #include <memory>
31 #include <string>
32 
33 using std::string;
34 using std::auto_ptr;
36 
37 namespace ola {
38 // We don't want to suck in all the ACN headers, so we forward declare these
39 // and allocate the members on the heap.
40 namespace plugin {
41 namespace e131 {
42 class E133Header;
43 class E133Inflator;
44 class E133StatusInflator;
45 class IncomingUDPTransport;
46 class RDMInflator;
47 class RootInflator;
48 class TransportHeader;
49 } // namespace e131
50 } // namespace plugin
51 
52 namespace e133 {
53 
54 class E133Message {
55  public:
56  E133Message(const IPV4Address &ip,
57  uint16_t endpoint,
58  uint32_t sequence_number)
59  : ip(ip),
60  endpoint(endpoint),
61  sequence_number(sequence_number) {
62  }
63  virtual ~E133Message() {}
64 
65  IPV4Address ip;
66  uint16_t endpoint;
67  uint32_t sequence_number;
68 };
69 
70 
75  public:
77  uint16_t endpoint,
78  uint32_t sequence_number,
79  uint16_t status_code,
80  string status_message)
81  : E133Message(ip, endpoint, sequence_number),
82  status_code(status_code),
83  status_message(status_message) {
84  }
85 
86  uint16_t status_code;
87  string status_message;
88 };
89 
90 
95 class E133RDMMessage : public E133Message {
96  public:
97  E133RDMMessage(const IPV4Address &ip,
98  uint16_t endpoint,
99  uint32_t sequence_number,
100  ola::rdm::rdm_response_code response_code,
101  const ola::rdm::RDMResponse *response)
102  : E133Message(ip, endpoint, sequence_number),
103  response_code(response_code),
104  response(response) {
105  }
106 
107  ola::rdm::rdm_response_code response_code;
108  const ola::rdm::RDMResponse *response;
109 };
110 
111 
116  public:
119 
120  explicit E133Receiver(ola::network::UDPSocket *socket,
121  StatusCallback *status_callback,
122  RDMCallback *rdm_callback);
123  ~E133Receiver();
124 
125  private:
126  ola::network::UDPSocket *m_udp_socket;
127  StatusCallback *m_status_callback;
128  RDMCallback *m_rdm_callback;
129 
130  auto_ptr<ola::plugin::e131::RootInflator> m_root_inflator;
131  auto_ptr<ola::plugin::e131::E133Inflator> m_e133_inflator;
132  auto_ptr<ola::plugin::e131::RDMInflator> m_rdm_inflator;
133  auto_ptr<ola::plugin::e131::E133StatusInflator> m_e133_status_inflator;
134  auto_ptr<ola::plugin::e131::IncomingUDPTransport> m_incoming_udp_transport;
135 
136  void HandleStatusMessage(
137  const ola::plugin::e131::TransportHeader *transport_header,
138  const ola::plugin::e131::E133Header *e133_header,
139  uint16_t status_code,
140  const string &description);
141 
142  void HandlePacket(
143  const ola::plugin::e131::TransportHeader *transport_header,
144  const ola::plugin::e131::E133Header *e133_header,
145  const std::string &raw_response);
146 
147  DISALLOW_COPY_AND_ASSIGN(E133Receiver);
148 };
149 } // namespace e133
150 } // namespace ola
151 #endif // INCLUDE_OLA_E133_E133RECEIVER_H_