Open Lighting Architecture
 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 using std::pair;
42 using std::vector;
43 
44 /*
45  * A RDM controller that only sends a single request at a time. This also
46  * handles timing out messages that we don't get a response for.
47  */
49  public:
51  unsigned int max_queue_size);
53 
54  void Pause();
55  void Resume();
56 
57  // This can be called multiple times and the requests will be queued.
58  void SendRDMRequest(const RDMRequest *request, RDMCallback *on_complete);
59 
60  protected:
61  typedef struct {
62  const RDMRequest *request;
63  RDMCallback *on_complete;
65 
66  RDMControllerInterface *m_controller;
67  unsigned int m_max_queue_size;
68  std::queue<outstanding_rdm_request> m_pending_requests;
69  bool m_rdm_request_pending; // true if a request is in progress
70  bool m_active; // true if the controller is active
71  RDMCallback *m_callback;
72  const ola::rdm::RDMResponse *m_response;
73  vector<std::string> m_packets;
74 
75  virtual void TakeNextAction();
76  virtual bool CheckForBlockingCondition();
77  void MaybeSendRDMRequest();
78  void DispatchNextRequest();
79 
80  void HandleRDMResponse(rdm_response_code status,
81  const ola::rdm::RDMResponse *response,
82  const vector<std::string> &packets);
83 };
84 
85 
93  public:
96  unsigned int max_queue_size);
97 
99 
100  // These can be called multiple times and the requests will be queued
101  void RunFullDiscovery(RDMDiscoveryCallback *callback);
103 
104  private:
105  typedef vector<RDMDiscoveryCallback*> DiscoveryCallbacks;
106  typedef vector<pair<bool, RDMDiscoveryCallback*> >
107  PendingDiscoveryCallbacks;
108 
109  DiscoverableRDMControllerInterface *m_discoverable_controller;
110  DiscoveryCallbacks m_discovery_callbacks;
111  PendingDiscoveryCallbacks m_pending_discovery_callbacks;
112 
113  void TakeNextAction();
114  bool CheckForBlockingCondition();
115  void GenericDiscovery(RDMDiscoveryCallback *callback, bool full);
116  void StartRDMDiscovery();
117  void DiscoveryComplete(const ola::rdm::UIDSet &uids);
118 };
119 } // namespace rdm
120 } // namespace ola
121 #endif // INCLUDE_OLA_RDM_QUEUEINGRDMCONTROLLER_H_