iCub-main
ethMonitorPresence.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2017 iCub Facility - Istituto Italiano di Tecnologia
5  * Author: Marco Accame
6  * email: marco.accame@iit.it
7  * website: www.robotcub.org
8  * Permission is granted to copy, distribute, and/or modify this program
9  * under the terms of the GNU General Public License, version 2 or any
10  * later version published by the Free Software Foundation.
11  *
12  * A copy of the license can be found at
13  * http://www.robotcub.org/icub/license/gpl.txt
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18  * Public License for more details
19 */
20 
21 // - include guard ----------------------------------------------------------------------------------------------------
22 
23 #ifndef _ETHMONITORPRESENCE_H_
24 #define _ETHMONITORPRESENCE_H_
25 
26 
27 #include <string>
28 
29 
30 namespace eth {
31 
33  {
34  public:
35 
36  struct Config
37  {
38  bool enabled;
39  double timeout; // in seconds
40  double periodmissingreport; // in seconds
41  std::string name;
42  Config() : enabled(true), timeout(0.020), periodmissingreport(30.0), name("generic") {}
43  Config(bool en, double t, double p, const std::string& na) : enabled(en), timeout(t), periodmissingreport(p), name(na) {}
44  };
45 
48 
49  void config(const Config &cfg);
50  void enable(bool en);
51  bool isenabled();
52 
53  void tick();
54  bool check(); // returns true if ok, false if missing
55 
56  private:
57 
58  Config configuration;
59 
60  double lastTickTime;
61  double lastMissingReportTime;
62  double lastHeardTime;
63  bool reportedMissing;
64  };
65 
66 
67 } // namespace eth
68 
69 
70 #endif // include-guard
71 
72 
73 // - end-of-file (leave a blank line after)----------------------------------------------------------------------------
74 
75 
76 
77 
78 
79 
80 
void config(const Config &cfg)
Config(bool en, double t, double p, const std::string &na)