Open Lighting Architecture
 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 
32 #include <map>
33 #include <string>
34 #include <vector>
36 
37 namespace ola {
38 namespace rdm {
39 
41  public:
44 
45  void AddSubDevice(uint16_t sub_device_number,
47 
48  void SendRDMRequest(const ola::rdm::RDMRequest *request,
49  ola::rdm::RDMCallback *callback);
50 
51  private:
52  struct FanOutTracker {
53  public:
54  FanOutTracker(uint16_t number_of_subdevices,
55  ola::rdm::RDMCallback *callback);
56 
57  bool IncrementAndCheckIfComplete() {
58  return ++m_responses_so_far == m_number_of_subdevices;
59  }
60 
61  void SetResponse(ola::rdm::rdm_response_code code,
62  const ola::rdm::RDMResponse *response);
63 
64  void RunCallback();
65 
66  uint16_t NumResponses() const {
67  return m_responses_so_far;
68  }
69 
70  private:
71  uint16_t m_number_of_subdevices;
72  uint16_t m_responses_so_far;
73  ola::rdm::RDMCallback *m_callback;
74 
75  ola::rdm::rdm_response_code m_response_code;
76  const ola::rdm::RDMResponse *m_response;
77  };
78 
79  typedef std::map<uint16_t, ola::rdm::RDMControllerInterface*> SubDeviceMap;
80 
81  SubDeviceMap m_subdevices;
82 
83  void FanOutToSubDevices(const ola::rdm::RDMRequest *request,
84  ola::rdm::RDMCallback *callback);
85 
86  void NackIfNotBroadcast(const ola::rdm::RDMRequest *request,
87  ola::rdm::RDMCallback *callback,
88  ola::rdm::rdm_nack_reason nack_reason);
89 
90  void HandleSubDeviceResponse(
91  FanOutTracker *tracker,
92  ola::rdm::rdm_response_code code,
93  const ola::rdm::RDMResponse *response,
94  const std::vector<std::string> &packets);
95 };
96 } // namespace rdm
97 } // namespace ola
98 #endif // INCLUDE_OLA_RDM_SUBDEVICEDISPATCHER_H_