YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
StatsMonitor.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_PORTMONITOR_STATSMONITOR_H
7#define YARP_PORTMONITOR_STATSMONITOR_H
8
10
11#include <yarp/os/Port.h>
13
14#include <string>
15#include <mutex>
16#include <memory>
17
19{
20private:
21 std::mutex m_mutex;
22 double m_datasize_sum=0;
23 double m_period = 1.0;
24 int m_datasize_count=0;
25 std::string m_source;
26 std::string m_destination;
27 std::string m_carrier;
28 std::string m_stats_port_name = "/testport";
29 yarp::os::Port m_stats_port;
30 bool m_isForward = true;
31
32public:
33 StatsThread() = delete;;
34 StatsThread(const StatsThread&) = delete;
35 StatsThread(double period, std::string src, std::string dest, std::string carrier, bool fw) : PeriodicThread(period)
36 {
37 m_period = period;
38 m_source =src;
39 m_destination=dest;
40 m_stats_port_name = "/stats_monitor" + m_source + m_destination + "/stats:o";
41 m_isForward = fw;
42 m_carrier = carrier;
43 }
44 virtual ~StatsThread() = default;
45
46 void setData(size_t datasize);
47 void run() override;
48 bool threadInit() override;
49 void threadRelease() override;
50};
51
64{
65public:
66 bool create(const yarp::os::Property& options) override;
69
70private:
71 bool m_isSender;
72 std::string m_source;
73 std::string m_destination;
74 std::string m_carrier;
75 std::unique_ptr<StatsThread> m_stats_thread_forward;
76 std::unique_ptr<StatsThread> m_stats_thread_backward;
77};
78
79#endif // YARP_PORTMONITOR_STATSMONITOR_H
stats_monitor: When this port monitor is attached to the sender side of a connection,...
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
yarp::os::Things & updateReply(yarp::os::Things &thing) override
The updateReply makes it possible to modify a reply from a port when the portmonitor object is attach...
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
void run() override
Loop function.
StatsThread()=delete
bool threadInit() override
Initialization method.
void setData(size_t datasize)
StatsThread(const StatsThread &)=delete
StatsThread(double period, std::string src, std::string dest, std::string carrier, bool fw)
void threadRelease() override
Release method.
virtual ~StatsThread()=default
An abstraction for a periodic thread.
PeriodicThread(double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No, PeriodicThreadClock clockAccuracy=PeriodicThreadClock::Relative)
Constructor.
A mini-server for network communication.
Definition Port.h:46
A class for storing options and configuration information.
Definition Property.h:33
Base class for generic things.
Definition Things.h:18