Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
Device.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 * Device.h
17 * Header file for the Device class
18 * Copyright (C) 2005 Simon Newton
19 */
20
21#ifndef INCLUDE_OLAD_DEVICE_H_
22#define INCLUDE_OLAD_DEVICE_H_
23
24#include <ola/base/Macro.h>
25#include <olad/Port.h>
26#include <stdint.h>
27#include <map>
28#include <string>
29#include <vector>
30
31namespace ola {
32namespace rpc {
33class RpcController;
34}
35}
36
37namespace ola {
38
39class AbstractPlugin;
40
41/*
42 * The interface for a Device
43 */
45 public:
47
49 virtual ~AbstractDevice() {}
50
51 // return the name of this device
52 virtual const std::string Name() const = 0;
53 // return the plugin that owns this device
54 virtual AbstractPlugin *Owner() const = 0;
55
56 // return the a unique id of this device, this is guaranteed to be unique
57 // and persist across restarts.
58 virtual std::string UniqueId() const = 0;
59
60 // stop the device
61 virtual bool Stop() = 0;
62
63 // allow input and output ports to be patched to the same univese
64 virtual bool AllowLooping() const = 0;
65
66 // allow multiple ports of the same type to be patched to the same
67 // universe.
68 virtual bool AllowMultiPortPatching() const = 0;
69
70 // Fetch a list of all ports in this device
71 virtual void InputPorts(std::vector<InputPort*> *ports) const = 0;
72 virtual void OutputPorts(std::vector<OutputPort*> *ports) const = 0;
73
74 // Lookup a particular port in this device
75 virtual InputPort *GetInputPort(unsigned int port_id) const = 0;
76 virtual OutputPort *GetOutputPort(unsigned int port_id) const = 0;
77
78 // configure this device
79 virtual void Configure(ola::rpc::RpcController *controller,
80 const std::string &request,
81 std::string *response,
82 ConfigureCallback *done) = 0;
83};
84
85
86/*
87 * A partial implementation of a Device.
88 */
89class Device: public AbstractDevice {
90 public:
91 Device(AbstractPlugin *owner, const std::string &name);
92 virtual ~Device();
93
94 const std::string Name() const { return m_name; }
95 void SetName(const std::string &name) { m_name = name; }
96
97 AbstractPlugin *Owner() const { return m_owner; }
98 std::string UniqueId() const;
99
104 virtual std::string DeviceId() const = 0;
105
106 bool IsEnabled() const { return m_enabled; }
107
108 bool Start();
109 bool Stop();
110
111 // sane defaults
112 bool AllowLooping() const { return false; }
113 bool AllowMultiPortPatching() const { return false; }
114
115 bool AddPort(InputPort *port);
116 bool AddPort(OutputPort *port);
117 void InputPorts(std::vector<InputPort*> *ports) const;
118 void OutputPorts(std::vector<OutputPort*> *ports) const;
119
120 InputPort *GetInputPort(unsigned int port_id) const;
121 OutputPort *GetOutputPort(unsigned int port_id) const;
122
123 // Free all ports
124 void DeleteAllPorts();
125
126 // Handle a Configure request
127 virtual void Configure(ola::rpc::RpcController *controller,
128 const std::string &request,
129 std::string *response,
130 ConfigureCallback *done);
131
132 protected:
138 virtual bool StartHook() { return true; }
139 virtual void PrePortStop() {}
140 virtual void PostPortStop() {}
141
142 private:
143 typedef std::map<unsigned int, InputPort*> input_port_map;
144 typedef std::map<unsigned int, OutputPort*> output_port_map;
145
146 bool m_enabled;
147 AbstractPlugin *m_owner; // which plugin owns this device
148 std::string m_name; // device name
149 mutable std::string m_unique_id; // device id
150 input_port_map m_input_ports;
151 output_port_map m_output_ports;
152
153 template<class PortClass>
154 bool GenericAddPort(PortClass *port,
155 std::map<unsigned int, PortClass*> *ports);
156
157 template <class PortClass>
158 void GenericDeletePort(PortClass *p);
159
160 Device(const Device &) = delete;
161 const Device &operator=(const Device &) = delete;
162};
163} // namespace ola
164#endif // INCLUDE_OLAD_DEVICE_H_
Helper macros.
Definition Device.h:44
Definition Plugin.h:38
The base class for all 0 argument callbacks.
Definition Callback.h:119
Definition Device.h:89
virtual std::string DeviceId() const =0
The device ID.
virtual bool StartHook()
Called during Start().
Definition Device.h:138
A port that receives DMX512 data.
Definition Port.h:137
A port that sends DMX512 data.
Definition Port.h:163
A RpcController object is passed every time an RPC is invoked and is used to indicate the success or ...
Definition RpcController.h:42
The namespace containing all OLA symbols.
Definition Credentials.cpp:44