Open Lighting Architecture
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * DeviceManager.h
17  * Interface to the DeviceManager class
18  * Copyright (C) 2005-2009 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/timecode/TimeCode.h"
38 #include "olad/Device.h"
39 #include "olad/Preferences.h"
40 
41 namespace ola {
42 
43 using std::map;
44 using std::string;
45 
46 
47 // pair a device with it's alias
48 typedef struct {
49  unsigned int alias;
50  AbstractDevice *device;
52 
53 bool operator <(const device_alias_pair& left, const device_alias_pair &right);
54 
56  public:
57  DeviceManager(PreferencesFactory *prefs_factory,
58  class PortManager *port_manager);
59  ~DeviceManager();
60 
61  bool RegisterDevice(AbstractDevice *device);
62  bool UnregisterDevice(const string &device_id);
63  bool UnregisterDevice(const AbstractDevice *device);
64  unsigned int DeviceCount() const;
65  vector<device_alias_pair> Devices() const;
66  AbstractDevice *GetDevice(unsigned int alias) const;
67  device_alias_pair GetDevice(const string &unique_id) const;
68  void UnregisterAllDevices();
69 
70  void SendTimeCode(const ola::timecode::TimeCode &timecode);
71 
72  static const unsigned int MISSING_DEVICE_ALIAS;
73  static const char PRIORITY_VALUE_SUFFIX[];
74  static const char PRIORITY_MODE_SUFFIX[];
75 
76  private:
77  Preferences *m_port_preferences;
78  class PortManager *m_port_manager;
79  map<string, device_alias_pair> m_devices; // map device_ids to devices
80  map<unsigned int, AbstractDevice*> m_alias_map; // map alias to devices
81  unsigned int m_next_device_alias;
82  std::set<class OutputPort*> m_timecode_ports;
83 
85  DeviceManager& operator=(const DeviceManager&);
86  void ReleaseDevice(const AbstractDevice *device);
87  void RestoreDevicePortSettings(AbstractDevice *device);
88 
89  template <class PortClass>
90  void SavePortPatchings(const vector<PortClass*> &ports) const;
91 
92  void SavePortPriority(const Port &port) const;
93  void RestorePortPriority(Port *port) const;
94 
95  template <class PortClass>
96  void RestorePortSettings(const vector<PortClass*> &ports) const;
97 
98  static const char PORT_PREFERENCES[];
99  static const unsigned int FIRST_DEVICE_ALIAS = 1;
100 };
101 } // namespace ola
102 #endif // OLAD_DEVICEMANAGER_H_