Open Lighting Architecture: include/ola/rdm/QueueingRDMController.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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
32#include <ola/rdm/RDMControllerInterface.h>
33#include <queue>
34#include <string>
35#include <utility>
36#include <vector>
37
38namespace ola {
39namespace 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 */
45 class QueueingRDMController: public RDMControllerInterface {
46 public:
47 QueueingRDMController(RDMControllerInterface *controller,
48 unsigned int max_queue_size);
49 ~QueueingRDMController();
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;
61 } outstanding_rdm_request;
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
88 class DiscoverableQueueingRDMController: public QueueingRDMController {
89 public:
90 DiscoverableQueueingRDMController(
91 DiscoverableRDMControllerInterface *controller,
92 unsigned int max_queue_size);
93
94 ~DiscoverableQueueingRDMController() {}
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();
110 bool CheckForBlockingCondition();
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_
RDMControllerInterface.h
Definitions and Interfaces to implement an RDMController that sends a single message at a time.
ola::rdm::DiscoverableQueueingRDMController::RunIncrementalDiscovery
void RunIncrementalDiscovery(RDMDiscoveryCallback *callback)
Definition QueueingRDMController.cpp:261
ola::rdm::DiscoverableQueueingRDMController::DiscoverableQueueingRDMController
DiscoverableQueueingRDMController(DiscoverableRDMControllerInterface *controller, unsigned int max_queue_size)
Definition QueueingRDMController.cpp:239
ola::rdm::DiscoverableQueueingRDMController::RunFullDiscovery
void RunFullDiscovery(RDMDiscoveryCallback *callback)
Definition QueueingRDMController.cpp:251
ola::rdm::DiscoverableRDMControllerInterface
The interface that can send RDM commands, as well as perform discovery operations.
Definition RDMControllerInterface.h:104
ola::rdm::QueueingRDMController::Resume
void Resume()
Definition QueueingRDMController.cpp:87
ola::rdm::QueueingRDMController::TakeNextAction
virtual void TakeNextAction()
Definition QueueingRDMController.cpp:118
ola::rdm::QueueingRDMController::SendRDMRequest
void SendRDMRequest(RDMRequest *request, RDMCallback *on_complete)
Definition QueueingRDMController.cpp:96
ola::rdm::QueueingRDMController::CheckForBlockingCondition
virtual bool CheckForBlockingCondition()
Definition QueueingRDMController.cpp:132
ola::rdm::QueueingRDMController::Pause
void Pause()
Definition QueueingRDMController.cpp:79
ola::rdm::RDMControllerInterface
The interface that can send RDMRequest.
Definition RDMControllerInterface.h:73
ola::rdm::RDMRequest
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition RDMCommand.h:234
ola::rdm::UIDSet
Represents a set of RDM UIDs.
Definition UIDSet.h:48
ola::rdm
PLASA E1.20 Remote Device Management.
Definition AckTimerResponder.cpp:38
ola::rdm::RDMCallback
ola::BaseCallback1< void, RDMReply * > RDMCallback
The callback run when a RDM request completes.
Definition RDMControllerInterface.h:52
ola::rdm::RDMDiscoveryCallback
ola::BaseCallback1< void, const ola::rdm::UIDSet & > RDMDiscoveryCallback
The callback run when a discovery operation completes.
Definition RDMControllerInterface.h:68
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::rdm::QueueingRDMController::outstanding_rdm_request
Definition QueueingRDMController.h:58
ola::rdm::RDMReply
Holds the final state of an RDM request.
Definition RDMReply.h:43