Open Lighting Architecture  Latest Git
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 acn {
41 class E133Header;
42 class E133Inflator;
43 class E133StatusInflator;
44 class IncomingUDPTransport;
45 class RDMInflator;
46 class RootInflator;
47 class TransportHeader;
48 } // namespace acn
49 
50 namespace e133 {
51 
52 class E133Message {
53  public:
54  E133Message(const IPV4Address &ip,
55  uint16_t endpoint,
56  uint32_t sequence_number)
57  : ip(ip),
58  endpoint(endpoint),
59  sequence_number(sequence_number) {
60  }
61  virtual ~E133Message() {}
62 
63  IPV4Address ip;
64  uint16_t endpoint;
65  uint32_t sequence_number;
66 };
67 
68 
73  public:
75  uint16_t endpoint,
76  uint32_t sequence_number,
77  uint16_t status_code,
78  string status_message)
79  : E133Message(ip, endpoint, sequence_number),
80  status_code(status_code),
81  status_message(status_message) {
82  }
83 
84  uint16_t status_code;
85  string status_message;
86 };
87 
88 
93 class E133RDMMessage : public E133Message {
94  public:
95  E133RDMMessage(const IPV4Address &ip,
96  uint16_t endpoint,
97  uint32_t sequence_number,
98  ola::rdm::RDMStatusCode status_code,
99  const ola::rdm::RDMResponse *response)
100  : E133Message(ip, endpoint, sequence_number),
101  status_code(status_code),
102  response(response) {
103  }
104 
105  ola::rdm::RDMStatusCode status_code;
106  const ola::rdm::RDMResponse *response;
107 };
108 
109 
114  public:
117 
118  explicit E133Receiver(ola::network::UDPSocket *socket,
119  StatusCallback *status_callback,
120  RDMCallback *rdm_callback);
121  ~E133Receiver();
122 
123  private:
124  ola::network::UDPSocket *m_udp_socket;
125  StatusCallback *m_status_callback;
126  RDMCallback *m_rdm_callback;
127 
128  auto_ptr<ola::acn::RootInflator> m_root_inflator;
129  auto_ptr<ola::acn::E133Inflator> m_e133_inflator;
130  auto_ptr<ola::acn::RDMInflator> m_rdm_inflator;
131  auto_ptr<ola::acn::E133StatusInflator> m_e133_status_inflator;
132  auto_ptr<ola::acn::IncomingUDPTransport> m_incoming_udp_transport;
133 
134  void HandleStatusMessage(
135  const ola::acn::TransportHeader *transport_header,
136  const ola::acn::E133Header *e133_header,
137  uint16_t status_code,
138  const string &description);
139 
140  void HandlePacket(
141  const ola::acn::TransportHeader *transport_header,
142  const ola::acn::E133Header *e133_header,
143  const std::string &raw_response);
144 
146 };
147 } // namespace e133
148 } // namespace ola
149 #endif // INCLUDE_OLA_E133_E133RECEIVER_H_
Definition: TransportHeader.h:35
RDMStatusCode
RDM Status Codes.
Definition: RDMResponseCodes.h:45
An RDM Command that represents responses (GET, SET or DISCOVER).
Definition: RDMCommand.h:457
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
Definition: Socket.h:238
SingleUseCallback3< void, const Result &, const RDMMetadata &, const ola::rdm::RDMResponse * > RDMCallback
Called when a RDM request completes. Used with OlaClient::RDMGet() and OlaClient::RDMSet().
Definition: CallbackTypes.h:154
Represents a IPv4 Address.
Definition: IPV4Address.h:55
Definition: E133Receiver.h:72
Definition: E133Header.h:35
Definition: E133Receiver.h:93
Represents an IPv4 Address.
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: E133Receiver.h:113
Definition: E133Receiver.h:52
A 1 argument callback which can be called multiple times.
Definition: Callback.h:992
Classes that represent RDM commands.