Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClientBroker.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  * ClientBroker.h
17  * The client broker exists to handle the case where a client may disconnect
18  * while a RDM call is in flight. When the call completes, the client broker
19  * will detect that the client 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 OLAD_CLIENTBROKER_H_
25 #define OLAD_CLIENTBROKER_H_
26 
27 #include <set>
28 #include <string>
29 #include <vector>
30 #include "ola/rdm/RDMCommand.h"
32 #include "ola/Callback.h"
33 #include "olad/Universe.h"
34 #include "olad/Client.h"
35 
36 namespace ola {
37 
38 class ClientBroker {
39  public:
40  ClientBroker() {}
41  ~ClientBroker() {}
42 
43  void AddClient(const Client *client);
44  void RemoveClient(const Client *client);
45 
46  void SendRDMRequest(const Client *client,
47  Universe *universe,
48  const ola::rdm::RDMRequest *request,
49  ola::rdm::RDMCallback *callback);
50 
51  private:
52  ClientBroker(const ClientBroker&);
53  ClientBroker& operator=(const ClientBroker&);
54 
55  void RequestComplete(const Client *key,
56  ola::rdm::RDMCallback *callback,
57  ola::rdm::rdm_response_code code,
58  const ola::rdm::RDMResponse *response,
59  const std::vector<std::string> &packets);
60 
61  typedef std::set<const Client*> client_set;
62  client_set m_clients;
63 };
64 } // namespace ola
65 #endif // OLAD_CLIENTBROKER_H_