Open Lighting Architecture
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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/network/Socket.h>
26 #include <ola/network/IPV4Address.h>
27 #include <ola/rdm/RDMCommand.h>
28 
29 #include <memory>
30 #include <string>
31 
32 using std::string;
33 using std::auto_ptr;
35 
36 namespace ola {
37 // We don't want to suck in all the ACN headers, so we forward declare these
38 // and allocate the members on the heap.
39 namespace plugin {
40 namespace e131 {
41  class E133Header;
42  class E133Inflator;
43  class E133StatusInflator;
44  class IncomingUDPTransport;
45  class RDMInflator;
46  class RootInflator;
47  class TransportHeader;
48 } // namespace e131
49 } // namespace plugin
50 
51 namespace e133 {
52 
53 class E133Message {
54  public:
55  E133Message(const IPV4Address &ip,
56  uint16_t endpoint,
57  uint32_t sequence_number)
58  : ip(ip),
59  endpoint(endpoint),
60  sequence_number(sequence_number) {
61  }
62  virtual ~E133Message() {}
63 
64  IPV4Address ip;
65  uint16_t endpoint;
66  uint32_t sequence_number;
67 };
68 
69 
74  public:
76  uint16_t endpoint,
77  uint32_t sequence_number,
78  uint16_t status_code,
79  string status_message)
80  : E133Message(ip, endpoint, sequence_number),
81  status_code(status_code),
82  status_message(status_message) {
83  }
84 
85  uint16_t status_code;
86  string status_message;
87 };
88 
89 
94 class E133RDMMessage : public E133Message {
95  public:
96  E133RDMMessage(const IPV4Address &ip,
97  uint16_t endpoint,
98  uint32_t sequence_number,
99  ola::rdm::rdm_response_code response_code,
100  const ola::rdm::RDMResponse *response)
101  : E133Message(ip, endpoint, sequence_number),
102  response_code(response_code),
103  response(response) {
104  }
105 
106  ola::rdm::rdm_response_code response_code;
107  const ola::rdm::RDMResponse *response;
108 };
109 
110 
115  public:
118 
119  explicit E133Receiver(ola::network::UDPSocket *socket,
120  StatusCallback *status_callback,
121  RDMCallback *rdm_callback);
122  ~E133Receiver();
123 
124  private:
125  ola::network::UDPSocket *m_udp_socket;
126  StatusCallback *m_status_callback;
127  RDMCallback *m_rdm_callback;
128 
129  auto_ptr<ola::plugin::e131::RootInflator> m_root_inflator;
130  auto_ptr<ola::plugin::e131::E133Inflator> m_e133_inflator;
131  auto_ptr<ola::plugin::e131::RDMInflator> m_rdm_inflator;
132  auto_ptr<ola::plugin::e131::E133StatusInflator> m_e133_status_inflator;
133  auto_ptr<ola::plugin::e131::IncomingUDPTransport> m_incoming_udp_transport;
134 
135  void HandleStatusMessage(
136  const ola::plugin::e131::TransportHeader *transport_header,
137  const ola::plugin::e131::E133Header *e133_header,
138  uint16_t status_code,
139  const string &description);
140 
141  void HandlePacket(
142  const ola::plugin::e131::TransportHeader *transport_header,
143  const ola::plugin::e131::E133Header *e133_header,
144  const std::string &raw_response);
145 };
146 } // namespace e133
147 } // namespace ola
148 #endif // INCLUDE_OLA_E133_E133RECEIVER_H_