Open Lighting Architecture  Latest Git
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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(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  std::auto_ptr<RDMCallback> m_callback;
69  std::auto_ptr<ola::rdm::RDMResponse> m_response;
70  std::vector<RDMFrame> m_frames;
71 
72  virtual void TakeNextAction();
73  virtual bool CheckForBlockingCondition();
74  void MaybeSendRDMRequest();
75  void DispatchNextRequest();
76 
77  void HandleRDMResponse(RDMReply *reply);
78  void RunCallback(RDMReply *reply);
79 };
80 
81 
89  public:
92  unsigned int max_queue_size);
93 
95 
96  // These can be called multiple times and the requests will be queued
97  void RunFullDiscovery(RDMDiscoveryCallback *callback);
98  void RunIncrementalDiscovery(RDMDiscoveryCallback *callback);
99 
100  private:
101  typedef std::vector<RDMDiscoveryCallback*> DiscoveryCallbacks;
102  typedef std::vector<std::pair<bool, RDMDiscoveryCallback*> >
103  PendingDiscoveryCallbacks;
104 
105  DiscoverableRDMControllerInterface *m_discoverable_controller;
106  DiscoveryCallbacks m_discovery_callbacks;
107  PendingDiscoveryCallbacks m_pending_discovery_callbacks;
108 
109  void TakeNextAction();
111  void GenericDiscovery(RDMDiscoveryCallback *callback, bool full);
112  void StartRDMDiscovery();
113  void DiscoveryComplete(const ola::rdm::UIDSet &uids);
114 };
115 } // namespace rdm
116 } // namespace ola
117 #endif // INCLUDE_OLA_RDM_QUEUEINGRDMCONTROLLER_H_
Represents a set of RDM UIDs.
Definition: UIDSet.h:48
Definitions and Interfaces to implement an RDMController that sends a single message at a time...
void Resume()
Definition: QueueingRDMController.cpp:87
void SendRDMRequest(RDMRequest *request, RDMCallback *on_complete)
Definition: QueueingRDMController.cpp:96
The interface that can send RDM commands, as well as perform discovery operations.
Definition: RDMControllerInterface.h:104
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:234
virtual bool CheckForBlockingCondition()
Definition: QueueingRDMController.cpp:132
void Pause()
Definition: QueueingRDMController.cpp:79
The base class for all 1 argument callbacks.
Definition: Callback.h:982
Holds the final state of an RDM request.
Definition: RDMReply.h:43
Definition: QueueingRDMController.h:88
The interface that can send RDMRequest.
Definition: RDMControllerInterface.h:73
Definition: QueueingRDMController.h:58
virtual void TakeNextAction()
Definition: QueueingRDMController.cpp:118
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: QueueingRDMController.h:45