DUDS
Distributed Update of Data from Something
MeasurementSignalQueue.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
12 #include <utility>
13 
14 namespace duds { namespace hardware {
15 
40 template <
41  class SVT,
42  class SQT,
43  class TVT,
44  class TQT,
45  template <typename, typename ...> class IS = std::shared_ptr,
46  typename... ISArgs
47 >
49  public GenericMeasurementSignalSink<SVT, SQT, TVT, TQT>
50 {
51 public:
54  enum EventType {
57  };
61  struct SignalData {
65  IS<Instrument, ISArgs ...> insturment;
69  std::shared_ptr<const Measurement> measurement;
74  SignalData() = default;
76  const IS<Instrument> &i,
77  const std::shared_ptr<const Measurement> &m,
78  EventType e
79  ) : insturment(i), measurement(m), type(e) { }
80  };
84  typedef std::list<SignalData> EventList;
85 private:
89  EventList events;
95 protected:
100  const std::shared_ptr<Instrument> &i,
101  const std::shared_ptr<const Measurement> &m
102  ) {
103  std::lock_guard<duds::general::Spinlock> lock(block);
104  events.emplace_back(i, m, NewMeasurement);
105  }
110  const std::shared_ptr<Instrument> &i,
111  const std::shared_ptr<const Measurement> &m
112  ) {
113  std::lock_guard<duds::general::Spinlock> lock(block);
114  events.emplace_back(i, m, OldMeasurement);
115  }
116 public:
117  GenericMeasurementSignalQueue() = default;
119  std::lock_guard<duds::general::Spinlock> lock(sq.block);
120  events = sq.events;
121  }
123  std::lock_guard<duds::general::Spinlock> lock(sq.block);
124  events = std::move(sq.events);
125  }
128  ) {
129  std::unique_lock<duds::general::Spinlock> lock0(block, std::defer_lock);
130  std::unique_lock<duds::general::Spinlock> lock1(sq.block, std::defer_lock);
131  std::lock(lock0, lock1);
132  events = sq.events;
133  }
136  ) {
137  std::unique_lock<duds::general::Spinlock> lock0(block, std::defer_lock);
138  std::unique_lock<duds::general::Spinlock> lock1(sq.block, std::defer_lock);
139  std::lock(lock0, lock1);
140  events = std::move(sq.events);
141  }
147  std::unique_lock<duds::general::Spinlock> lock0(block, std::defer_lock);
148  std::unique_lock<duds::general::Spinlock> lock1(sq.block, std::defer_lock);
149  std::lock(lock0, lock1);
150  events.swap(sq.events);
151  }
155  EventList copy() const {
156  EventList copy;
157  {
158  std::lock_guard<duds::general::Spinlock> lock(block);
159  copy = events;
160  }
161  return copy;
162  }
167  void copy(EventList &copy) const {
168  std::lock_guard<duds::general::Spinlock> lock(block);
169  copy = events;
170  }
175  EventList move() {
176  EventList copy;
177  {
178  std::lock_guard<duds::general::Spinlock> lock(block);
179  copy = std::move(events);
180  }
181  return copy;
182  }
187  void move(EventList &copy) {
188  std::lock_guard<duds::general::Spinlock> lock(block);
189  copy = std::move(events);
190  }
195  void pushBack(const SignalData &sd) {
196  std::lock_guard<duds::general::Spinlock> lock(block);
197  events.push_back(sd);
198  }
203  void pushFront(const SignalData &sd) {
204  std::lock_guard<duds::general::Spinlock> lock(block);
205  events.push_front(sd);
206  }
212  SignalData sd;
213  {
214  std::lock_guard<duds::general::Spinlock> lock(block);
215  sd = std::move(events.back());
216  events.pop_back();
217  }
218  return sd;
219  }
225  SignalData sd;
226  {
227  std::lock_guard<duds::general::Spinlock> lock(block);
228  sd = std::move(events.front());
229  events.pop_front();
230  }
231  return sd;
232  }
236  void clear() {
237  std::lock_guard<duds::general::Spinlock> lock(block);
238  events.clear();
239  }
240 };
241 
261 template <
262  class SVT,
263  class SQT,
264  class TVT,
265  class TQT,
266  template <typename> class IS,
267  typename ... ISArgs
268 >
269 void swap(
272 ) {
273  sq0.swap(sq1);
274 }
275 
278  double,
280  float
282 
283 } }
boost::variant< std::string, duds::general::LanguageTaggedString, std::array< std::int32_t, 4 >, std::array< std::int64_t, 2 >, duds::data::int128_w, std::array< float, 4 >, std::array< double, 2 >, double, duds::data::Quantity, boost::recursive_wrapper< duds::data::QuantityNddArray >, duds::time::interstellar::Femtoseconds, duds::time::interstellar::Nanoseconds, duds::time::interstellar::FemtoTime, duds::time::interstellar::NanoTime, boost::uuids::uuid, boost::recursive_wrapper< duds::data::GenericValueTable >, std::shared_ptr< std::vector< char > >> GenericValue
A general value of a type can be serialized for transmission over a network and can be used with a re...
GenericMeasurementSignalQueue & operator=(const GenericMeasurementSignalQueue &sq)
EventList move()
Returns a move-constructed list of the signal events stored internally.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
GenericMeasurementSignalQueue< duds::data::GenericValue, double, duds::time::interstellar::NanoTime, float > MeasurementSignalQueue
std::shared_ptr< const Measurement > measurement
The measurement taken by the instrument.
GenericMeasurementSignalQueue(const GenericMeasurementSignalQueue &sq)
void pushFront(const SignalData &sd)
Push signal data onto the front (oldest side) of the internal list.
SignalData(const IS< Instrument > &i, const std::shared_ptr< const Measurement > &m, EventType e)
A base class for receiving measurement signals from multiple Instruments.
SignalData popBack()
Pop signal data from the end (newest side) of the internal list and return that data.
IS< Instrument, ISArgs ... > insturment
The originating instrument.
void pushBack(const SignalData &sd)
Push signal data onto the end (newest side) of the internal list.
std::list< SignalData > EventList
The list type used to store information from incoming signals.
void copy(EventList &copy) const
Creates a copy of the ignal events stored internally.
SignalData popFront()
Pop signal data from the front (oldest side) of the internal list and return that data...
void swap(GenericMeasurementSignalQueue &sq)
Swaps the internal signal data list with another GenericMeasurementSignalQueue object.
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
Definition: Spinlock.hpp:52
void handleOldMeasure(const std::shared_ptr< Instrument > &i, const std::shared_ptr< const Measurement > &m)
Receives an old measurement signal and queues its information.
GenericMeasurementSignalQueue(GenericMeasurementSignalQueue &&sq)
Stores the information from a new or old measurement signal.
void move(EventList &copy)
Move-assigns to a given list the signal events stored internally.
void handleNewMeasure(const std::shared_ptr< Instrument > &i, const std::shared_ptr< const Measurement > &m)
Receives a new measurement signal and queues its information.
duds::data::GenericMeasurement< SVT, SQT, TVT, TQT > Measurement
Stores a sample of something along with a timestamp stored as a sample from a clock.
Definition: Measurement.hpp:24
Queues mesurement signals for later processing.
EventList copy() const
Returns a copy of the signal events stored internally.
GenericInstrument< SVT, SQT, TVT, TQT > Instrument
EventType type
Denotes either a new or old measurement.
duds::general::Spinlock block
Used to allow only one thread access to events.
void clear()
Clear the signal data stored internally.
NanoClock::time_point NanoTime
A point in time in Interstellar Time stored in Nanoseconds.