Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
31 namespace ola {
32 namespace rpc {
33 class RpcController;
34 }
35 }
36 
37 namespace ola {
38 
39 class AbstractPlugin;
40 
45  public:
47 
48  AbstractDevice() {}
49  virtual ~AbstractDevice() {}
50 
52  virtual const std::string Name() const = 0;
53 
55  virtual AbstractPlugin *Owner() const = 0;
56 
61  virtual std::string UniqueId() const = 0;
62 
64  virtual bool Stop() = 0;
65 
67  virtual bool AllowLooping() const = 0;
68 
73  virtual bool AllowMultiPortPatching() const = 0;
74 
76  virtual void InputPorts(std::vector<InputPort*> *ports) const = 0;
77  virtual void OutputPorts(std::vector<OutputPort*> *ports) const = 0;
78 
80  virtual InputPort *GetInputPort(unsigned int port_id) const = 0;
82  virtual OutputPort *GetOutputPort(unsigned int port_id) const = 0;
83 
85  virtual void Configure(ola::rpc::RpcController *controller,
86  const std::string &request,
87  std::string *response,
88  ConfigureCallback *done) = 0;
89 };
90 
91 
95 class Device: public AbstractDevice {
96  public:
97  Device(AbstractPlugin *owner, const std::string &name);
98  virtual ~Device();
99 
100  const std::string Name() const { return m_name; }
101 
103  void SetName(const std::string &name) { m_name = name; }
104 
105  AbstractPlugin *Owner() const { return m_owner; }
106  std::string UniqueId() const;
107 
112  virtual std::string DeviceId() const = 0;
113 
114  bool IsEnabled() const { return m_enabled; }
115 
117  bool Start();
118  bool Stop();
119 
120  // sane defaults
121  bool AllowLooping() const { return false; }
122  bool AllowMultiPortPatching() const { return false; }
123 
124  bool AddPort(InputPort *port);
125  bool AddPort(OutputPort *port);
126  void InputPorts(std::vector<InputPort*> *ports) const;
127  void OutputPorts(std::vector<OutputPort*> *ports) const;
128 
129  InputPort *GetInputPort(unsigned int port_id) const;
130  OutputPort *GetOutputPort(unsigned int port_id) const;
131 
133  void DeleteAllPorts();
134 
135  // Handle a Configure request
136  virtual void Configure(ola::rpc::RpcController *controller,
137  const std::string &request,
138  std::string *response,
139  ConfigureCallback *done);
140 
141  protected:
147  virtual bool StartHook() { return true; }
148  virtual void PrePortStop() {}
149  virtual void PostPortStop() {}
150 
151  private:
152  typedef std::map<unsigned int, InputPort*> input_port_map;
153  typedef std::map<unsigned int, OutputPort*> output_port_map;
154 
155  bool m_enabled;
156  AbstractPlugin *m_owner; // which plugin owns this device
157  std::string m_name; // device name
158  mutable std::string m_unique_id; // device id
159  input_port_map m_input_ports;
160  output_port_map m_output_ports;
161 
162  template<class PortClass>
163  bool GenericAddPort(PortClass *port,
164  std::map<unsigned int, PortClass*> *ports);
165 
166  template <class PortClass>
167  void GenericDeletePort(PortClass *p);
168 
169  DISALLOW_COPY_AND_ASSIGN(Device);
170 };
171 } // namespace ola
172 #endif // INCLUDE_OLAD_DEVICE_H_
virtual const std::string Name() const =0
The name of this Device.
virtual std::string UniqueId() const =0
The unique id of this Device.
bool AllowMultiPortPatching() const
Allow multiple ports of the same type to be patched to the same universe.
Definition: Device.h:122
virtual InputPort * GetInputPort(unsigned int port_id) const =0
Lookup a particular InputPort in this Device.
A port that receives DMX512 data.
Definition: Port.h:137
virtual OutputPort * GetOutputPort(unsigned int port_id) const =0
Lookup a particular OutputPort in this Device.
bool AllowLooping() const
Allow input and output ports to be patched to the same universe.
Definition: Device.h:121
virtual bool Stop()=0
Stop the Device.
Definition: Device.h:95
virtual bool AllowLooping() const =0
Allow input and output ports to be patched to the same universe.
OutputPort * GetOutputPort(unsigned int port_id) const
Lookup a particular OutputPort in this Device.
Definition: Device.cpp:138
A port that sends DMX512 data.
Definition: Port.h:163
virtual bool StartHook()
Called during Start().
Definition: Device.h:147
The interface for a Device.
Definition: Device.h:44
virtual AbstractPlugin * Owner() const =0
The Plugin that owns this Device.
void InputPorts(std::vector< InputPort * > *ports) const
Fetch a list of all ports in this Device.
Definition: Device.cpp:118
virtual void Configure(ola::rpc::RpcController *controller, const std::string &request, std::string *response, ConfigureCallback *done)
Configure this Device.
Definition: Device.cpp:182
virtual void Configure(ola::rpc::RpcController *controller, const std::string &request, std::string *response, ConfigureCallback *done)=0
Configure this Device.
const std::string Name() const
The name of this Device.
Definition: Device.h:100
virtual std::string DeviceId() const =0
The device ID.
InputPort * GetInputPort(unsigned int port_id) const
Lookup a particular InputPort in this Device.
Definition: Device.cpp:130
bool Stop()
Stop the Device.
Definition: Device.cpp:86
Helper macros.
bool Start()
Start the Device.
Definition: Device.cpp:72
virtual void InputPorts(std::vector< InputPort * > *ports) const =0
Fetch a list of all ports in this Device.
void DeleteAllPorts()
Free all ports.
Definition: Device.cpp:146
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
A RpcController object is passed every time an RPC is invoked and is used to indicate the success or ...
Definition: RpcController.h:42
std::string UniqueId() const
The unique id of this Device.
Definition: Device.cpp:165
virtual bool AllowMultiPortPatching() const =0
Allow multiple ports of the same type to be patched to the same universe.
Definition: Plugin.h:38
AbstractPlugin * Owner() const
The Plugin that owns this Device.
Definition: Device.h:105
void SetName(const std::string &name)
Sets the name of this Device.
Definition: Device.h:103