YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
7template <class T>
9 reader(nullptr),
10 callback(nullptr)
11{
12}
13
14template <class T>
16 TypedReaderCallback<T>& callback)
17{
18 this->reader = &reader;
19 this->callback = &callback;
20 start(); // automatically starts running
21}
22
23template <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}
35template <class T>
37{
38 if (reader != nullptr) {
39 reader->interrupt();
40 }
41}
A mini-server for performing network communication in the background.
void onRead(T &datum) override
Callback method.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void onStop() override
Call-back, called while halting the thread (before join).
void run() override
Main body of the new thread.