YARP
Yet Another Robot Platform
TypedReaderThread-inl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 template <class T>
12  reader(nullptr),
13  callback(nullptr)
14 {
15 }
16 
17 template <class T>
19  TypedReaderCallback<T>& callback)
20 {
21  this->reader = &reader;
22  this->callback = &callback;
23  start(); // automatically starts running
24 }
25 
26 template <class T>
28 {
29  if (reader != nullptr && callback != nullptr) {
30  while (!isStopping() && !reader->isClosed()) {
31  if (reader->read()) {
32  callback->onRead(*(reader->lastRead()), *reader);
33  }
34  }
35  }
36 }
37 
38 template <class T>
40 {
41  if (reader != nullptr) {
42  reader->interrupt();
43  }
44 }
yarp::os::TypedReader
A base class for sources of typed data.
Definition: TypedReader.h:26
yarp::os::TypedReaderThread::TypedReaderThread
TypedReaderThread()
Definition: TypedReaderThread-inl.h:11
yarp::os::TypedReaderCallback
A callback for typed data from a port.
Definition: TypedReaderCallback.h:31
yarp::os::TypedReaderThread::onStop
void onStop() override
Call-back, called while halting the thread (before join).
Definition: TypedReaderThread-inl.h:39
yarp::os::TypedReaderThread::run
void run() override
Main body of the new thread.
Definition: TypedReaderThread-inl.h:27