Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DeviceManager.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  * DeviceManager.h
17  * Interface to the DeviceManager class
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef OLAD_DEVICEMANAGER_H_
22 #define OLAD_DEVICEMANAGER_H_
23 
24 #include <map>
25 #include <set>
26 #include <string>
27 #include <vector>
28 #include "ola/base/Macro.h"
29 #include "ola/timecode/TimeCode.h"
30 #include "olad/Device.h"
31 #include "olad/Preferences.h"
32 
33 namespace ola {
34 
35 // pair a device with it's alias
37  public:
38  unsigned int alias;
39  AbstractDevice *device;
40 
41  device_alias_pair(unsigned int alias, AbstractDevice *device)
42  : alias(alias), device(device) {}
43 };
44 
45 bool operator <(const device_alias_pair& left, const device_alias_pair &right);
46 
62  public:
69  DeviceManager(PreferencesFactory *prefs_factory,
70  class PortManager *port_manager);
71 
76 
84  bool RegisterDevice(AbstractDevice *device);
85 
91  bool UnregisterDevice(const std::string &device_id);
92 
98  bool UnregisterDevice(const AbstractDevice *device);
99 
104  unsigned int DeviceCount() const;
105 
110  std::vector<device_alias_pair> Devices() const;
111 
116  AbstractDevice *GetDevice(unsigned int alias) const;
117 
124  device_alias_pair GetDevice(const std::string &unique_id) const;
125 
129  void UnregisterAllDevices();
130 
131 
136  void SendTimeCode(const ola::timecode::TimeCode &timecode);
137 
138  static const unsigned int MISSING_DEVICE_ALIAS;
139 
140  private:
141  typedef std::map<std::string, device_alias_pair> DeviceIdMap;
142  typedef std::map<unsigned int, AbstractDevice*> DeviceAliasMap;
143 
144  Preferences *m_port_preferences;
145  class PortManager *m_port_manager;
146 
147  DeviceIdMap m_devices;
148  DeviceAliasMap m_alias_map;
149 
150  unsigned int m_next_device_alias;
151  std::set<class OutputPort*> m_timecode_ports;
152 
153  void ReleaseDevice(const AbstractDevice *device);
154  void RestoreDevicePortSettings(AbstractDevice *device);
155 
156  template <class PortClass>
157  void SavePortPatchings(const std::vector<PortClass*> &ports) const;
158 
159  void SavePortPriority(const Port &port) const;
160  void RestorePortPriority(Port *port) const;
161 
162  template <class PortClass>
163  void RestorePortSettings(const std::vector<PortClass*> &ports) const;
164 
165  static const char PORT_PREFERENCES[];
166  static const unsigned int FIRST_DEVICE_ALIAS = 1;
167  static const char PRIORITY_VALUE_SUFFIX[];
168  static const char PRIORITY_MODE_SUFFIX[];
169 
171 };
172 } // namespace ola
173 #endif // OLAD_DEVICEMANAGER_H_