Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OPCClient.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  * OPCClient.h
17  * The Open Pixel Control Client.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_OPENPIXELCONTROL_OPCCLIENT_H_
22 #define PLUGINS_OPENPIXELCONTROL_OPCCLIENT_H_
23 
24 #include <memory>
25 #include <string>
26 
27 #include "ola/DmxBuffer.h"
28 #include "ola/io/MemoryBlockPool.h"
29 #include "ola/io/SelectServerInterface.h"
30 #include "ola/network/AdvancedTCPConnector.h"
32 #include "ola/network/TCPSocket.h"
33 #include "ola/util/Backoff.h"
34 
35 namespace ola {
36 
37 namespace io {
38 class NonBlockingSender;
39 } // namespace io
40 
41 namespace plugin {
42 namespace openpixelcontrol {
43 
49 class OPCClient {
50  public:
55 
62  const ola::network::IPV4SocketAddress &target);
63 
67  ~OPCClient();
68 
73  std::string GetRemoteAddress() const { return m_target.ToString(); }
74 
80  bool SendDmx(uint8_t channel, const DmxBuffer &buffer);
81 
87  void SetSocketCallback(SocketEventCallback *callback);
88 
89  private:
91  const ola::network::IPV4SocketAddress m_target;
92 
95  ola::network::TCPSocketFactory m_socket_factory;
96  ola::network::AdvancedTCPConnector m_tcp_connector;
97  std::auto_ptr<ola::network::TCPSocket> m_client_socket;
98  std::auto_ptr<ola::io::NonBlockingSender> m_sender;
99  std::auto_ptr<SocketEventCallback> m_socket_callback;
100 
101  void SocketConnected(ola::network::TCPSocket *socket);
102  void NewData();
103  void SocketClosed();
104 
105  DISALLOW_COPY_AND_ASSIGN(OPCClient);
106 };
107 } // namespace openpixelcontrol
108 } // namespace plugin
109 } // namespace ola
110 #endif // PLUGINS_OPENPIXELCONTROL_OPCCLIENT_H_