Open Lighting Architecture
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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/rdm/RDMCommand.h>
29 #include <ola/Callback.h>
30 #include <olad/Universe.h>
31 #include <olad/Port.h>
32 #include <set>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 
37 namespace ola {
38 
40  public:
42  virtual ~PortBrokerInterface() {}
43 
44  virtual void SendRDMRequest(
45  const Port *port,
46  Universe *universe,
47  const ola::rdm::RDMRequest *request,
48  ola::rdm::RDMCallback *callback) = 0;
49 };
50 
51 
53  public:
54  PortBroker() {}
55  ~PortBroker() {}
56 
57  void AddPort(const Port *port);
58  void RemovePort(const Port *port);
59 
60  void SendRDMRequest(const Port *port,
61  Universe *universe,
62  const ola::rdm::RDMRequest *request,
63  ola::rdm::RDMCallback *callback);
64 
65  private:
66  PortBroker(const PortBroker&);
67  PortBroker& operator=(const PortBroker&);
68 
69  typedef std::pair<string, const Port*> port_key;
70 
71  void RequestComplete(port_key key,
72  ola::rdm::RDMCallback *callback,
73  ola::rdm::rdm_response_code code,
74  const ola::rdm::RDMResponse *response,
75  const std::vector<std::string> &packets);
76 
77  std::set<port_key> m_ports;
78 };
79 } // namespace ola
80 #endif // INCLUDE_OLAD_PORTBROKER_H_