YARP
Yet Another Robot Platform
TypedReaderThread-inl.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 template <class T>
9  reader(nullptr),
10  callback(nullptr)
11 {
12 }
13 
14 template <class T>
16  TypedReaderCallback<T>& callback)
17 {
18  this->reader = &reader;
19  this->callback = &callback;
20  start(); // automatically starts running
21 }
22 
23 template <class T>
25 {
26  if (reader != nullptr && callback != nullptr) {
27  while (!isStopping() && !reader->isClosed()) {
28  if (reader->read()) {
29  callback->onRead(*(reader->lastRead()), *reader);
30  }
31  }
32  }
33 }
34 
35 template <class T>
37 {
38  if (reader != nullptr) {
39  reader->interrupt();
40  }
41 }
A callback for typed data from a port.
void onStop() override
Call-back, called while halting the thread (before join).
void run() override
Main body of the new thread.
A base class for sources of typed data.
Definition: TypedReader.h:23