Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UDPTransport.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  * UDPTransport.h
17  * Interface for the UDPTransport class
18  * Copyright (C) 2007 Simon Newton
19  */
20 
21 #ifndef PLUGINS_E131_E131_UDPTRANSPORT_H_
22 #define PLUGINS_E131_E131_UDPTRANSPORT_H_
23 
24 #include "ola/acn/ACNPort.h"
26 #include "ola/network/Socket.h"
27 #include "plugins/e131/e131/PDU.h"
28 #include "plugins/e131/e131/PreamblePacker.h"
29 #include "plugins/e131/e131/Transport.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace e131 {
34 
35 /*
36  * The OutgoingUDPTransport is a small shim that provides the options to
37  * UDPTransportImpl.
38  */
40  public:
42  const ola::network::IPV4Address &destination,
43  uint16_t port = ola::acn::ACN_PORT)
44  : m_impl(impl),
45  m_destination(destination, port) {
46  }
48 
49  bool Send(const PDUBlock<PDU> &pdu_block);
50 
51  private:
52  class OutgoingUDPTransportImpl *m_impl;
53  ola::network::IPV4SocketAddress m_destination;
54 
56  OutgoingUDPTransport& operator=(const OutgoingUDPTransport&);
57 };
58 
59 
64  public:
66  PreamblePacker *packer = NULL)
67  : m_socket(socket),
68  m_packer(packer),
69  m_free_packer(false) {
70  if (!m_packer) {
71  m_packer = new PreamblePacker();
72  m_free_packer = true;
73  }
74  }
76  if (m_free_packer)
77  delete m_packer;
78  }
79 
80  bool Send(const PDUBlock<PDU> &pdu_block,
81  const ola::network::IPV4SocketAddress &destination);
82 
83  private:
84  ola::network::UDPSocket *m_socket;
85  PreamblePacker *m_packer;
86  bool m_free_packer;
87 };
88 
89 
96  public:
98  class BaseInflator *inflator);
100  if (m_recv_buffer)
101  delete[] m_recv_buffer;
102  }
103 
104  void Receive();
105 
106  private:
107  ola::network::UDPSocket *m_socket;
108  class BaseInflator *m_inflator;
109  uint8_t *m_recv_buffer;
110 };
111 } // namespace e131
112 } // namespace plugin
113 } // namespace ola
114 #endif // PLUGINS_E131_E131_UDPTRANSPORT_H_