Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PortBroker.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  * PortBroker.h
17  * The port broker exists to handle the case where a port may be removed
18  * while a RDM call is in flight. When the call completes, the port broker
19  * will detect that the port has disconnected and not run the callback (which
20  * would now point to an invalid memory location).
21  * Copyright (C) 2010 Simon Newton
22  */
23 
24 #ifndef INCLUDE_OLAD_PORTBROKER_H_
25 #define INCLUDE_OLAD_PORTBROKER_H_
26 
27 #include <ola/base/Macro.h>
28 #include <ola/rdm/RDMCommand.h>
30 #include <ola/Callback.h>
31 #include <olad/Universe.h>
32 #include <olad/Port.h>
33 #include <set>
34 #include <string>
35 #include <utility>
36 #include <vector>
37 
38 namespace ola {
39 
41  public:
43  virtual ~PortBrokerInterface() {}
44 
45  virtual void SendRDMRequest(
46  const Port *port,
47  Universe *universe,
48  const ola::rdm::RDMRequest *request,
49  ola::rdm::RDMCallback *callback) = 0;
50 };
51 
52 
54  public:
55  PortBroker() {}
56  ~PortBroker() {}
57 
58  void AddPort(const Port *port);
59  void RemovePort(const Port *port);
60 
61  void SendRDMRequest(const Port *port,
62  Universe *universe,
63  const ola::rdm::RDMRequest *request,
64  ola::rdm::RDMCallback *callback);
65 
66  private:
67  typedef std::pair<std::string, const Port*> port_key;
68 
69  void RequestComplete(port_key key,
70  ola::rdm::RDMCallback *callback,
71  ola::rdm::rdm_response_code code,
72  const ola::rdm::RDMResponse *response,
73  const std::vector<std::string> &packets);
74 
75  std::set<port_key> m_ports;
76 
77  DISALLOW_COPY_AND_ASSIGN(PortBroker);
78 };
79 } // namespace ola
80 #endif // INCLUDE_OLAD_PORTBROKER_H_