Open Lighting Architecture: plugins/openpixelcontrol/OPCClient.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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"
31#include "ola/network/SocketAddress.h"
32#include "ola/network/TCPSocket.h"
33#include "ola/util/Backoff.h"
34
35namespace ola {
36
37namespace io {
38class NonBlockingSender;
39} // namespace io
40
41namespace plugin {
42namespace openpixelcontrol {
43
49 class OPCClient {
50 public:
54 typedef ola::Callback1<void, bool> SocketEventCallback;
55
61 OPCClient(ola::io::SelectServerInterface *ss,
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:
90 ola::io::SelectServerInterface *m_ss;
91 const ola::network::IPV4SocketAddress m_target;
92
93 ola::ExponentialBackoffPolicy m_backoff;
94 ola::io::MemoryBlockPool m_pool;
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 OPCClient(const OPCClient &) = delete;
106 const OPCClient &operator=(const OPCClient &) = delete;
107};
108} // namespace openpixelcontrol
109} // namespace plugin
110} // namespace ola
111#endif // PLUGINS_OPENPIXELCONTROL_OPCCLIENT_H_
DmxBuffer.h
A class used to hold a single universe of DMX data.
SocketAddress.h
Represents Socket Addresses.
ola::Callback1
A 1 argument callback which can be called multiple times.
Definition Callback.h:992
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::ExponentialBackoffPolicy
Definition Backoff.h:98
ola::io::MemoryBlockPool
MemoryBlockPool. This class is not thread safe.
Definition MemoryBlockPool.h:35
ola::io::NonBlockingSender
Write data to ConnectedDescriptors without blocking or losing data.
Definition NonBlockingSender.h:57
ola::io::SelectServerInterface
The interface for the SelectServer.
Definition SelectServerInterface.h:42
ola::network::AdvancedTCPConnector
Attempts to open a TCP connection until a failure limit is reached.
Definition AdvancedTCPConnector.h:48
ola::network::IPV4SocketAddress
An IPv4 SocketAddress.
Definition SocketAddress.h:78
ola::network::TCPSocket
Definition TCPSocket.h:43
ola::plugin::openpixelcontrol::OPCClient
An Open Pixel Control client.
Definition OPCClient.h:49
ola::plugin::openpixelcontrol::OPCClient::SendDmx
bool SendDmx(uint8_t channel, const DmxBuffer &buffer)
Send a DMX frame.
Definition OPCClient.cpp:58
ola::plugin::openpixelcontrol::OPCClient::GetRemoteAddress
std::string GetRemoteAddress() const
Return the remote address for this Client.
Definition OPCClient.h:73
ola::plugin::openpixelcontrol::OPCClient::~OPCClient
~OPCClient()
Destructor.
Definition OPCClient.cpp:51
ola::plugin::openpixelcontrol::OPCClient::SocketEventCallback
ola::Callback1< void, bool > SocketEventCallback
Called when the socket changes state.
Definition OPCClient.h:54
ola::plugin::openpixelcontrol::OPCClient::SetSocketCallback
void SetSocketCallback(SocketEventCallback *callback)
Set the callback to be run when the socket state changes.
Definition OPCClient.cpp:72
ola::plugin::openpixelcontrol::OPCClient::OPCClient
OPCClient(ola::io::SelectServerInterface *ss, const ola::network::IPV4SocketAddress &target)
Create a new OPCClient.
Definition OPCClient.cpp:40
ola::io
Classes for general I/O and event handling.
Definition Descriptor.cpp:49
ola::plugin::openpixelcontrol
The Open Pixel Control (OPC) plugin.
ola::plugin
Code for supported devices and protocols.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44