Robot Raconteur Core C++ Library
BroadcastDownsampler.h
Go to the documentation of this file.
1 
24 #pragma once
25 
27 #include <boost/unordered_map.hpp>
28 
29 namespace RobotRaconteur
30 {
31 class ROBOTRACONTEUR_CORE_API ServerContext;
32 class ROBOTRACONTEUR_CORE_API PipeBroadcasterBase;
33 class ROBOTRACONTEUR_CORE_API WireBroadcasterBase;
34 
63 class ROBOTRACONTEUR_CORE_API BroadcastDownsampler : public RR_ENABLE_SHARED_FROM_THIS<BroadcastDownsampler>
64 {
65  public:
75 
82  void Init(const RR_SHARED_PTR<ServerContext>& context, uint32_t default_downsample = 0);
83 
90  uint32_t GetClientDownsample(uint32_t ep);
91 
98  void SetClientDownsample(uint32_t ep, uint32_t downsample);
99 
106  void BeginStep();
107 
114  void EndStep();
115 
123  void AddPipeBroadcaster(const RR_SHARED_PTR<PipeBroadcasterBase>& broadcaster);
124 
132  void AddWireBroadcaster(const RR_SHARED_PTR<WireBroadcasterBase>& broadcaster);
133 
134  protected:
135  RR_WEAK_PTR<ServerContext> context;
136 
137  uint32_t default_downsample;
138  uint64_t step_count;
139  RR_UNORDERED_MAP<uint32_t, uint32_t> client_downsamples;
140 
141  boost::mutex this_lock;
142 
143  static bool wire_predicate(RR_WEAK_PTR<BroadcastDownsampler> this_, const RR_SHARED_PTR<WireBroadcasterBase>& wire,
144  uint32_t ep);
145  static bool pipe_predicate(RR_WEAK_PTR<BroadcastDownsampler> this_, const RR_SHARED_PTR<PipeBroadcasterBase>& wire,
146  uint32_t ep, uint32_t index);
147 
148  static void server_event(RR_WEAK_PTR<BroadcastDownsampler> this_, const RR_SHARED_PTR<ServerContext>& ctx,
149  ServerServiceListenerEventType evt, const RR_SHARED_PTR<void>& p);
150 };
151 
160 class ROBOTRACONTEUR_CORE_API BroadcastDownsamplerStep
161 {
162  RR_SHARED_PTR<BroadcastDownsampler>& _downsampler;
163 
164  public:
174  BroadcastDownsamplerStep(RR_SHARED_PTR<BroadcastDownsampler>& downsampler);
176 };
177 
178 #ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
180 using BroadcastDownsamplerPtr = RR_SHARED_PTR<BroadcastDownsampler>;
181 #endif
182 } // namespace RobotRaconteur
boost::shared_ptr< BroadcastDownsampler > BroadcastDownsamplerPtr
Convenience alias for BroadcastDownsampler shared_ptr.
Definition: BroadcastDownsampler.h:180
ServerServiceListenerEventType
Enum of service listener events.
Definition: RobotRaconteurConstants.h:518
Downsampler to manage rate of packets sent to client.
Definition: BroadcastDownsampler.h:64
BroadcastDownsampler()
Construct a new BroadcastDownsampler.
void SetClientDownsample(uint32_t ep, uint32_t downsample)
Set the downsample for the specified client.
void AddPipeBroadcaster(const boost::shared_ptr< PipeBroadcasterBase > &broadcaster)
Add a PipeBroadcaster to the downsampler.
uint32_t GetClientDownsample(uint32_t ep)
Get the downsample for the specified client.
void BeginStep()
Begin the update loop step.
void EndStep()
End the update loop step.
void AddWireBroadcaster(const boost::shared_ptr< WireBroadcasterBase > &broadcaster)
Add a WireBroadcaster to the downsampler.
void Init(const boost::shared_ptr< ServerContext > &context, uint32_t default_downsample=0)
Initialize the BroadcastDownsampler.
Class for automatic broadcast downsampler stepping.
Definition: BroadcastDownsampler.h:161
BroadcastDownsamplerStep(boost::shared_ptr< BroadcastDownsampler > &downsampler)
Construct a BroadcastDownsampler.