Debian Codegraph @

olad/plugin_api/PortManager.h

raw
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_PLUGIN_API_PORTMANAGER_H_
22 #define OLAD_PLUGIN_API_PORTMANAGER_H_
23
24 #include <vector>
25 #include "olad/Device.h"
26 #include "olad/PortBroker.h"
27 #include "olad/plugin_api/DeviceManager.h"
28 #include "olad/plugin_api/UniverseStore.h"
29 #include "ola/base/Macro.h"
30
31
32 namespace ola {
33
34 /**
35 * @brief Responsible for performing Port operations.
36 */
37 class PortManager {
38 public:
39 /**
40 * @brief Create a new PortManager.
41 * @param universe_store the UniverseStore used to lookup / create Universes.
42 * @param broker the PortBroker to update when Ports are added / removed.
43 */
44 PortManager(UniverseStore *universe_store,
45 PortBroker *broker)
46 : m_universe_store(universe_store),
47 m_broker(broker) {
48 }
49
50 /**
51 * @brief Destructor.
52 */
53 ~PortManager() {}
54
55 /**
56 * @brief Patch an InputPort to a universe.
57 * @param port the port to patch
58 * @param universe the universe-id to patch to.
59 * @returns true is successful, false otherwise
60 */
61 bool PatchPort(InputPort *port, unsigned int universe);
62
63 /**
64 * @brief Patch an OutputPort to a universe.
65 * @param port the port to patch
66 * @param universe the universe-id to patch to.
67 * @returns true is successful, false otherwise
68 */
69 bool PatchPort(OutputPort *port, unsigned int universe);
70
71 /**
72 * @brief UnPatch an InputPort.
73 * @param port the port to unpatch
74 * @returns true is successful, false otherwise
75 */
76 bool UnPatchPort(InputPort *port);
77
78 /**
79 * @brief UnPatch an OutputPort.
80 * @param port the port to unpatch
81 * @returns true is successful, false otherwise
82 */
83 bool UnPatchPort(OutputPort *port);
84
85 /**
86 * @brief Set a port to 'inherit' priority mode.
87 * @param port the port to configure
88 */
89 bool SetPriorityInherit(Port *port);
90
91 /**
92 * @brief Set a port to 'override' priority mode.
93 * @param port the port to configure
94 * @param value the new priority
95 */
96 bool SetPriorityStatic(Port *port, uint8_t value);
97
98 private:
99 template<class PortClass>
100 bool GenericPatchPort(PortClass *port,
101 unsigned int new_universe_id);
102
103 template<class PortClass>
104 bool GenericUnPatchPort(PortClass *port);
105
106 template<class PortClass>
107 bool CheckLooping(const AbstractDevice *device,
108 unsigned int new_universe_id) const;
109
110 template<class PortClass>
111 bool CheckMultiPort(const AbstractDevice *device,
112 unsigned int new_universe_id) const;
113
114 /**
115 * Check if any input ports in this device are bound to the universe.
116 * @returns true if there is a match, false otherwise.
117 */
118 bool CheckInputPortsForUniverse(const AbstractDevice *device,
119 unsigned int universe_id) const;
120
121 /**
122 * Check if any output ports in this device are bound to the universe.
123 * @returns true if there is a match, false otherwise.
124 */
125 bool CheckOutputPortsForUniverse(const AbstractDevice *device,
126 unsigned int universe_id) const;
127
128 /**
129 * Check for any port in a list that's bound to this universe.
130 * @returns true if there is a match, false otherwise.
131 */
132 template<class PortClass>
133 bool CheckForPortMatchingUniverse(const std::vector<PortClass*> &ports,
134 unsigned int universe_id) const;
135
136 UniverseStore * const m_universe_store;
137 PortBroker *m_broker;
138
139 DISALLOW_COPY_AND_ASSIGN(PortManager);
140 };
141 } // namespace ola
142 #endif // OLAD_PLUGIN_API_PORTMANAGER_H_