Open Lighting Architecture  0.9.1
 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  * The DeviceManager assigns an unsigned int as an alias to each device which
21  * remains consistent throughout the lifetime of the DeviceManager. These are
22  * used in the user facing portion as '1' is easier to understand/type
23  * than 5-02050016. If a device is registered, then unregistered, then
24  * registered again, it'll have the same device alias.
25  *
26  * The DeviceManager is also responsible for restoring the port patchings when
27  * devices are registered.
28  */
29 
30 #ifndef OLAD_DEVICEMANAGER_H_
31 #define OLAD_DEVICEMANAGER_H_
32 
33 #include <map>
34 #include <set>
35 #include <string>
36 #include <vector>
37 #include "ola/base/Macro.h"
38 #include "ola/timecode/TimeCode.h"
39 #include "olad/Device.h"
40 #include "olad/Preferences.h"
41 
42 namespace ola {
43 
44 // pair a device with it's alias
45 typedef struct {
46  unsigned int alias;
47  AbstractDevice *device;
49 
50 bool operator <(const device_alias_pair& left, const device_alias_pair &right);
51 
53  public:
54  DeviceManager(PreferencesFactory *prefs_factory,
55  class PortManager *port_manager);
56  ~DeviceManager();
57 
58  bool RegisterDevice(AbstractDevice *device);
59  bool UnregisterDevice(const std::string &device_id);
60  bool UnregisterDevice(const AbstractDevice *device);
61  unsigned int DeviceCount() const;
62  std::vector<device_alias_pair> Devices() const;
63  AbstractDevice *GetDevice(unsigned int alias) const;
64  device_alias_pair GetDevice(const std::string &unique_id) const;
65  void UnregisterAllDevices();
66 
67  void SendTimeCode(const ola::timecode::TimeCode &timecode);
68 
69  static const unsigned int MISSING_DEVICE_ALIAS;
70  static const char PRIORITY_VALUE_SUFFIX[];
71  static const char PRIORITY_MODE_SUFFIX[];
72 
73  private:
74  Preferences *m_port_preferences;
75  class PortManager *m_port_manager;
76  // map device_ids to devices
77  std::map<std::string, device_alias_pair> m_devices;
78  // map alias to devices
79  std::map<unsigned int, AbstractDevice*> m_alias_map;
80  unsigned int m_next_device_alias;
81  std::set<class OutputPort*> m_timecode_ports;
82 
83  void ReleaseDevice(const AbstractDevice *device);
84  void RestoreDevicePortSettings(AbstractDevice *device);
85 
86  template <class PortClass>
87  void SavePortPatchings(const std::vector<PortClass*> &ports) const;
88 
89  void SavePortPriority(const Port &port) const;
90  void RestorePortPriority(Port *port) const;
91 
92  template <class PortClass>
93  void RestorePortSettings(const std::vector<PortClass*> &ports) const;
94 
95  static const char PORT_PREFERENCES[];
96  static const unsigned int FIRST_DEVICE_ALIAS = 1;
97 
99 };
100 } // namespace ola
101 #endif // OLAD_DEVICEMANAGER_H_