Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SubDeviceDispatcher.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library 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 GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * SubDeviceDispatcher_h
17  * Handles dispatching RDM requests to the correct sub device.
18  * Copyright (C) 2013 Simon Newton
19  */
20 
29 #ifndef INCLUDE_OLA_RDM_SUBDEVICEDISPATCHER_H_
30 #define INCLUDE_OLA_RDM_SUBDEVICEDISPATCHER_H_
31 
33 
34 #include <map>
35 #include <string>
36 #include <vector>
37 
38 namespace ola {
39 namespace rdm {
40 
42  public:
45 
46  void AddSubDevice(uint16_t sub_device_number,
48 
49  void SendRDMRequest(const ola::rdm::RDMRequest *request,
50  ola::rdm::RDMCallback *callback);
51 
52  private:
53  struct FanOutTracker {
54  public:
55  FanOutTracker(uint16_t number_of_subdevices,
56  ola::rdm::RDMCallback *callback);
57 
58  bool IncrementAndCheckIfComplete() {
59  return ++m_responses_so_far == m_number_of_subdevices;
60  }
61 
62  void SetResponse(ola::rdm::rdm_response_code code,
63  const ola::rdm::RDMResponse *response);
64 
65  void RunCallback();
66 
67  uint16_t NumResponses() const {
68  return m_responses_so_far;
69  }
70 
71  private:
72  uint16_t m_number_of_subdevices;
73  uint16_t m_responses_so_far;
74  ola::rdm::RDMCallback *m_callback;
75 
76  ola::rdm::rdm_response_code m_response_code;
77  const ola::rdm::RDMResponse *m_response;
78  };
79 
80  typedef std::map<uint16_t, ola::rdm::RDMControllerInterface*> SubDeviceMap;
81 
82  SubDeviceMap m_subdevices;
83 
84  void FanOutToSubDevices(const ola::rdm::RDMRequest *request,
85  ola::rdm::RDMCallback *callback);
86 
87  void NackIfNotBroadcast(const ola::rdm::RDMRequest *request,
88  ola::rdm::RDMCallback *callback,
89  ola::rdm::rdm_nack_reason nack_reason);
90 
91  void HandleSubDeviceResponse(
92  FanOutTracker *tracker,
93  ola::rdm::rdm_response_code code,
94  const ola::rdm::RDMResponse *response,
95  const std::vector<std::string> &packets);
96 };
97 } // namespace rdm
98 } // namespace ola
99 #endif // INCLUDE_OLA_RDM_SUBDEVICEDISPATCHER_H_