Open Lighting Architecture  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueueingRDMController.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  * QueueingRDMController.h
17  * A RDM Controller that sends a single message at a time.
18  * Copyright (C) 2010 Simon Newton
19  */
20 
29 #ifndef INCLUDE_OLA_RDM_QUEUEINGRDMCONTROLLER_H_
30 #define INCLUDE_OLA_RDM_QUEUEINGRDMCONTROLLER_H_
31 
33 #include <queue>
34 #include <string>
35 #include <utility>
36 #include <vector>
37 
38 namespace ola {
39 namespace rdm {
40 
41 /*
42  * A RDM controller that only sends a single request at a time. This also
43  * handles timing out messages that we don't get a response for.
44  */
46  public:
48  unsigned int max_queue_size);
50 
51  void Pause();
52  void Resume();
53 
54  // This can be called multiple times and the requests will be queued.
55  void SendRDMRequest(const RDMRequest *request, RDMCallback *on_complete);
56 
57  protected:
58  typedef struct {
59  const RDMRequest *request;
60  RDMCallback *on_complete;
62 
63  RDMControllerInterface *m_controller;
64  unsigned int m_max_queue_size;
65  std::queue<outstanding_rdm_request> m_pending_requests;
66  bool m_rdm_request_pending; // true if a request is in progress
67  bool m_active; // true if the controller is active
68  RDMCallback *m_callback;
69  const ola::rdm::RDMResponse *m_response;
70  std::vector<std::string> m_packets;
71 
72  virtual void TakeNextAction();
73  virtual bool CheckForBlockingCondition();
74  void MaybeSendRDMRequest();
75  void DispatchNextRequest();
76 
77  void HandleRDMResponse(rdm_response_code status,
78  const ola::rdm::RDMResponse *response,
79  const std::vector<std::string> &packets);
80 };
81 
82 
90  public:
93  unsigned int max_queue_size);
94 
96 
97  // These can be called multiple times and the requests will be queued
98  void RunFullDiscovery(RDMDiscoveryCallback *callback);
100 
101  private:
102  typedef std::vector<RDMDiscoveryCallback*> DiscoveryCallbacks;
103  typedef std::vector<std::pair<bool, RDMDiscoveryCallback*> >
104  PendingDiscoveryCallbacks;
105 
106  DiscoverableRDMControllerInterface *m_discoverable_controller;
107  DiscoveryCallbacks m_discovery_callbacks;
108  PendingDiscoveryCallbacks m_pending_discovery_callbacks;
109 
110  void TakeNextAction();
111  bool CheckForBlockingCondition();
112  void GenericDiscovery(RDMDiscoveryCallback *callback, bool full);
113  void StartRDMDiscovery();
114  void DiscoveryComplete(const ola::rdm::UIDSet &uids);
115 };
116 } // namespace rdm
117 } // namespace ola
118 #endif // INCLUDE_OLA_RDM_QUEUEINGRDMCONTROLLER_H_