Open Lighting Architecture
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * UDPTransport.h
17  * Interface for the UDPTransport class
18  * Copyright (C) 2007-2009 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"
25 #include "ola/network/IPV4Address.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 
36 
37 /*
38  * The OutgoingUDPTransport is a small shim that provides the options to
39  * UDPTransportImpl.
40  */
42  public:
44  const IPV4Address &destination,
45  uint16_t port = ola::acn::ACN_PORT)
46  : m_impl(impl),
47  m_destination(destination),
48  m_port(port) {
49  }
51 
52  bool Send(const PDUBlock<PDU> &pdu_block);
53 
54  private:
55  class OutgoingUDPTransportImpl *m_impl;
56  IPV4Address m_destination;
57  uint16_t m_port;
58 
60  OutgoingUDPTransport& operator=(const OutgoingUDPTransport&);
61 };
62 
63 
68  public:
70  PreamblePacker *packer = NULL)
71  : m_socket(socket),
72  m_packer(packer),
73  m_free_packer(false) {
74  if (!m_packer) {
75  m_packer = new PreamblePacker();
76  m_free_packer = true;
77  }
78  }
80  if (m_free_packer)
81  delete m_packer;
82  }
83 
84  bool Send(const PDUBlock<PDU> &pdu_block,
85  const IPV4Address &destination,
86  uint16_t port);
87 
88  private:
89  ola::network::UDPSocket *m_socket;
90  PreamblePacker *m_packer;
91  bool m_free_packer;
92 };
93 
94 
101  public:
103  class BaseInflator *inflator);
105  if (m_recv_buffer)
106  delete[] m_recv_buffer;
107  }
108 
109  void Receive();
110 
111  private:
112  ola::network::UDPSocket *m_socket;
113  class BaseInflator *m_inflator;
114  uint8_t *m_recv_buffer;
115 };
116 } // namespace e131
117 } // namespace plugin
118 } // namespace ola
119 #endif // PLUGINS_E131_E131_UDPTRANSPORT_H_