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

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
OPCServer.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 * OPCServer.h
17 * The Open Pixel Server.
18 * Copyright (C) 2014 Simon Newton
19 */
20
21#ifndef PLUGINS_OPENPIXELCONTROL_OPCSERVER_H_
22#define PLUGINS_OPENPIXELCONTROL_OPCSERVER_H_
23
24#include <string>
25#include <map>
26#include <memory>
27#include "ola/Constants.h"
28#include "ola/DmxBuffer.h"
29#include "ola/io/SelectServerInterface.h"
30#include "ola/network/SocketAddress.h"
31#include "ola/network/TCPSocket.h"
32#include "ola/network/TCPSocketFactory.h"
33#include "plugins/openpixelcontrol/OPCConstants.h"
34
35namespace ola {
36namespace plugin {
37namespace openpixelcontrol {
38
44 class OPCServer {
45 public:
49 typedef Callback3<void, uint8_t, const uint8_t*, unsigned int>
50 ChannelCallback;
51
57 OPCServer(ola::io::SelectServerInterface *ss,
58 const ola::network::IPV4SocketAddress &listen_addr);
59
63 ~OPCServer();
64
70 bool Init();
71
78 void SetCallback(uint8_t channel, ChannelCallback *callback);
79
85 ola::network::IPV4SocketAddress ListenAddress() const;
86
87 private:
88 struct RxState {
89 public:
90 unsigned int offset;
91 uint16_t expected_size;
92 uint8_t *data;
93 unsigned int buffer_size;
94
95 RxState()
96 : offset(0),
97 expected_size(0) {
98 buffer_size = OPC_FRAME_SIZE,
99 data = new uint8_t[buffer_size];
100 }
101
102 ~RxState() {
103 delete[] data;
104 }
105
106 void CheckSize();
107 };
108
109 typedef std::map<ola::network::TCPSocket*, RxState*> ClientMap;
110
111 ola::io::SelectServerInterface* const m_ss;
112 const ola::network::IPV4SocketAddress m_listen_addr;
113 ola::network::TCPSocketFactory m_tcp_socket_factory;
114
115 std::auto_ptr<ola::network::TCPAcceptingSocket> m_listening_socket;
116 ClientMap m_clients;
117 std::map<uint8_t, ChannelCallback*> m_callbacks;
118
119 void NewTCPConnection(ola::network::TCPSocket *socket);
120 void SocketReady(ola::network::TCPSocket *socket, RxState *rx_state);
121 void SocketClosed(ola::network::TCPSocket *socket);
122
123 OPCServer(const OPCServer &) = delete;
124 const OPCServer &operator=(const OPCServer &) = delete;
125};
126} // namespace openpixelcontrol
127} // namespace plugin
128} // namespace ola
129#endif // PLUGINS_OPENPIXELCONTROL_OPCSERVER_H_
Constants.h
Constants used throughout OLA.
DmxBuffer.h
A class used to hold a single universe of DMX data.
SocketAddress.h
Represents Socket Addresses.
ola::Callback3
A 3 argument callback which can be called multiple times.
Definition Callback.h:2838
ola::io::SelectServerInterface
The interface for the SelectServer.
Definition SelectServerInterface.h:42
ola::network::IPV4SocketAddress
An IPv4 SocketAddress.
Definition SocketAddress.h:78
ola::network::TCPSocket
Definition TCPSocket.h:43
ola::plugin::openpixelcontrol::OPCServer::ListenAddress
ola::network::IPV4SocketAddress ListenAddress() const
The listen address of this server.
Definition OPCServer.cpp:95
ola::plugin::openpixelcontrol::OPCServer::ChannelCallback
Callback3< void, uint8_t, const uint8_t *, unsigned int > ChannelCallback
The callback executed when new OPC data arrives.
Definition OPCServer.h:50
ola::plugin::openpixelcontrol::OPCServer::Init
bool Init()
Initialize the OPCServer.
Definition OPCServer.cpp:84
ola::plugin::openpixelcontrol::OPCServer::SetCallback
void SetCallback(uint8_t channel, ChannelCallback *callback)
Set the callback to be run when channel data arrives.
Definition OPCServer.cpp:105
ola::plugin::openpixelcontrol::OPCServer::OPCServer
OPCServer(ola::io::SelectServerInterface *ss, const ola::network::IPV4SocketAddress &listen_addr)
Create a new OPCServer.
Definition OPCServer.cpp:60
ola::plugin::openpixelcontrol::OPCServer::~OPCServer
~OPCServer()
Destructor.
Definition OPCServer.cpp:68
ola::plugin::openpixelcontrol
The Open Pixel Control (OPC) plugin.
ola::plugin::openpixelcontrol::OPC_FRAME_SIZE
@ OPC_FRAME_SIZE
The size of an OPC frame with DMX512 data.
Definition OPCConstants.h:41
ola::plugin
Code for supported devices and protocols.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44