Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowNetNode.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  * ShowNetNode.h
17  * Header file for the ShowNetNode class
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef PLUGINS_SHOWNET_SHOWNETNODE_H_
22 #define PLUGINS_SHOWNET_SHOWNETNODE_H_
23 
24 #include <string>
25 #include <map>
26 #include "ola/Callback.h"
27 #include "ola/DmxBuffer.h"
28 #include "ola/base/Macro.h"
30 #include "ola/network/InterfacePicker.h"
31 #include "ola/network/Socket.h"
32 #include "plugins/shownet/ShowNetPackets.h"
33 
34 namespace ola {
35 namespace plugin {
36 namespace shownet {
37 
38 class ShowNetNode {
39  public:
40  explicit ShowNetNode(const std::string &ip_address);
41  virtual ~ShowNetNode();
42 
43  bool Start();
44  bool Stop();
45  void SetName(const std::string &name);
46 
47  bool SendDMX(unsigned int universe, const ola::DmxBuffer &buffer);
48  bool SetHandler(unsigned int universe,
49  DmxBuffer *buffer,
50  ola::Callback0<void> *handler);
51  bool RemoveHandler(unsigned int universe);
52 
53  const ola::network::Interface &GetInterface() const {
54  return m_interface;
55  }
56 
57  ola::network::UDPSocket* GetSocket() { return m_socket; }
58  void SocketReady();
59 
60  static const uint16_t SHOWNET_MAX_UNIVERSES = 8;
61 
62  friend class ShowNetNodeTest;
63 
64  private:
65  typedef struct {
66  DmxBuffer *buffer;
67  Callback0<void> *closure;
68  } universe_handler;
69 
70  bool m_running;
71  uint16_t m_packet_count;
72  std::string m_node_name;
73  std::string m_preferred_ip;
74  std::map<unsigned int, universe_handler> m_handlers;
75  ola::network::Interface m_interface;
77  ola::network::UDPSocket *m_socket;
78 
79  bool HandlePacket(const shownet_packet *packet, unsigned int size);
80  bool HandleCompressedPacket(const shownet_compressed_dmx *packet,
81  unsigned int packet_size);
82  unsigned int BuildCompressedPacket(shownet_packet *packet,
83  unsigned int universe,
84  const DmxBuffer &buffer);
85  bool InitNetwork();
86 
87  static const uint16_t SHOWNET_PORT = 2501;
88  // In the shownet spec, the pass(2) and name(9) fields are combined with the
89  // compressed data. This means the indicies referenced in indexBlocks are
90  // off by 11.
91  static const int MAGIC_INDEX_OFFSET = 11;
92 
93  DISALLOW_COPY_AND_ASSIGN(ShowNetNode);
94 };
95 } // namespace shownet
96 } // namespace plugin
97 } // namespace ola
98 #endif // PLUGINS_SHOWNET_SHOWNETNODE_H_