Open Lighting Architecture  0.9.0
 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"
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),
46  m_port(port) {
47  }
49 
50  bool Send(const PDUBlock<PDU> &pdu_block);
51 
52  private:
53  class OutgoingUDPTransportImpl *m_impl;
54  ola::network::IPV4Address m_destination;
55  uint16_t m_port;
56 
58  OutgoingUDPTransport& operator=(const OutgoingUDPTransport&);
59 };
60 
61 
66  public:
68  PreamblePacker *packer = NULL)
69  : m_socket(socket),
70  m_packer(packer),
71  m_free_packer(false) {
72  if (!m_packer) {
73  m_packer = new PreamblePacker();
74  m_free_packer = true;
75  }
76  }
78  if (m_free_packer)
79  delete m_packer;
80  }
81 
82  bool Send(const PDUBlock<PDU> &pdu_block,
83  const ola::network::IPV4Address &destination,
84  uint16_t port);
85 
86  private:
87  ola::network::UDPSocket *m_socket;
88  PreamblePacker *m_packer;
89  bool m_free_packer;
90 };
91 
92 
99  public:
101  class BaseInflator *inflator);
103  if (m_recv_buffer)
104  delete[] m_recv_buffer;
105  }
106 
107  void Receive();
108 
109  private:
110  ola::network::UDPSocket *m_socket;
111  class BaseInflator *m_inflator;
112  uint8_t *m_recv_buffer;
113 };
114 } // namespace e131
115 } // namespace plugin
116 } // namespace ola
117 #endif // PLUGINS_E131_E131_UDPTRANSPORT_H_