Open Lighting Architecture  0.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PortManager.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  * PortManager.h
17  * Provides a unified interface for controlling port patchings & priorities.
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef OLAD_PORTMANAGER_H_
22 #define OLAD_PORTMANAGER_H_
23 
24 #include <vector>
25 #include "olad/Device.h"
26 #include "olad/DeviceManager.h"
27 #include "olad/PortBroker.h"
28 #include "olad/UniverseStore.h"
29 #include "ola/base/Macro.h"
30 
31 
32 namespace ola {
33 
34 class PortManager {
35  public:
36  explicit PortManager(UniverseStore *universe_store,
37  PortBroker *broker)
38  : m_universe_store(universe_store),
39  m_broker(broker) {
40  }
41  ~PortManager() {}
42 
43  bool PatchPort(InputPort *port, unsigned int universe);
44  bool PatchPort(OutputPort *port, unsigned int universe);
45  bool UnPatchPort(InputPort *port);
46  bool UnPatchPort(OutputPort *port);
47 
48  bool SetPriorityInherit(Port *port);
49  bool SetPriorityStatic(Port *port, uint8_t value);
50 
51  private:
52  template<class PortClass>
53  bool GenericPatchPort(PortClass *port,
54  unsigned int new_universe_id);
55 
56  template<class PortClass>
57  bool GenericUnPatchPort(PortClass *port);
58 
59  template<class PortClass>
60  bool CheckLooping(const AbstractDevice *device,
61  unsigned int new_universe_id) const;
62 
63  template<class PortClass>
64  bool CheckMultiPort(const AbstractDevice *device,
65  unsigned int new_universe_id) const;
66 
67  bool CheckInputPortsForUniverse(const AbstractDevice *device,
68  unsigned int universe_id) const;
69  bool CheckOutputPortsForUniverse(const AbstractDevice *device,
70  unsigned int universe_id) const;
71 
72  template<class PortClass>
73  bool CheckForPortMatchingUniverse(const std::vector<PortClass*> &ports,
74  unsigned int universe_id) const;
75 
76  UniverseStore * const m_universe_store;
77  PortBroker *m_broker;
78 
79  DISALLOW_COPY_AND_ASSIGN(PortManager);
80 };
81 } // namespace ola
82 #endif // OLAD_PORTMANAGER_H_