Open Lighting Architecture  Latest Git
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 
106 };
107 } // namespace openpixelcontrol
108 } // namespace plugin
109 } // namespace ola
110 #endif // PLUGINS_OPENPIXELCONTROL_OPCCLIENT_H_
Represents Socket Addresses.
Definition: TCPSocketFactory.h:46
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
Attempts to open a TCP connection until a failure limit is reached.
Definition: AdvancedTCPConnector.h:48
std::string GetRemoteAddress() const
Return the remote address for this Client.
Definition: OPCClient.h:73
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A class used to hold a single universe of DMX data.
The interface for the SelectServer.
Definition: SelectServerInterface.h:42
Definition: TCPSocket.h:43
Definition: Backoff.h:98
An Open Pixel Control client.
Definition: OPCClient.h:49
ola::Callback1< void, bool > SocketEventCallback
Called when the socket changes state.
Definition: OPCClient.h:54
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
An IPv4 SocketAddress.
Definition: SocketAddress.h:78
MemoryBlockPool. This class is not thread safe.
Definition: MemoryBlockPool.h:35
A 1 argument callback which can be called multiple times.
Definition: Callback.h:992