GammaLib 2.0.0
Loading...
Searching...
No Matches
GDaemon.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GDaemon.hpp - Daemon class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2022 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GDaemon.hpp
23 * @brief Daemon class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GDAEMON_HPP
28#define GDAEMON_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GBase.hpp"
33#include "GTools.hpp"
34#include "GFilename.hpp"
35#include "GLog.hpp"
36
37/* __ Forward declarations _______________________________________________ */
38class GCsv;
39class GXml;
40
41/* __ Constants __________________________________________________________ */
42
43
44/***********************************************************************//**
45 * @class GDaemon
46 *
47 * @brief Daemon class
48 *
49 * @todo Add class description.
50 ***************************************************************************/
51class GDaemon : public GBase {
52
53public:
54 // Constructors and destructors
55 GDaemon(void);
56 GDaemon(const GDaemon& daemon);
57 virtual ~GDaemon(void);
58
59 // Operators
60 GDaemon& operator=(const GDaemon& daemon);
61
62 // Implemented pure virtual base class methods
63 virtual void clear(void);
64 virtual GDaemon* clone(void) const;
65 virtual std::string classname(void) const;
66 virtual std::string print(const GChatter& chatter = NORMAL) const;
67
68 // Other methods
69 void start(void);
70 bool alive(void) const;
71
72protected:
73 // Protected methods
74 void init_members(void);
75 void copy_members(const GDaemon& daemon);
76 void free_members(void);
77 void create_lock_file(void);
78 void delete_lock_file(void);
79 void write_heartbeat(void);
80 GFilename lock_filename(void) const;
81 GFilename heartbeat_filename(void) const;
83 pid_t lock_pid(void) const;
84 void update_statistics(void);
85 void update_host_country(void);
86 void recover_valid_xml(void);
87 void create_xml(const GFilename& filename);
88 void update_dates(GXml& xml, const GCsv& statistics);
89 void update_countries_header(GXml& xml, const GCsv& statistics);
90 void update_countries_data(GXml& xml, const GCsv& statistics);
91 void update_versions_data(GXml& xml, const GCsv& statistics);
92 void update_daily(GXml& xml, const GCsv& statistics);
93
94 // Protected members
95 pid_t m_pid; //!< Process ID
96 int m_period; //!< Wake-up period in seconds
97 int m_heartbeat; //!< Heartbeat period in seconds
98 GLog m_log; //!< Logger
99 GChatter m_chatter; //!< Chattiness of logger
100};
101
102
103/***********************************************************************//**
104 * @brief Return class name
105 *
106 * @return String containing the class name ("GDaemon").
107 ***************************************************************************/
108inline
109std::string GDaemon::classname(void) const
110{
111 return ("GDaemon");
112}
113
114
115/***********************************************************************//**
116 * @brief Returns name of daemon lock file
117 *
118 * @return Daemon lock filename.
119 ***************************************************************************/
120inline
122{
123 return (gammalib::gamma_filename("daemon.lock"));
124}
125
126
127/***********************************************************************//**
128 * @brief Returns name of daemon heartbeat file
129 *
130 * @return Daemon heartbeat filename.
131 ***************************************************************************/
132inline
134{
135 return (gammalib::gamma_filename("daemon.heartbeat"));
136}
137
138#endif /* GDAEMON_HPP */
Definition of interface for all GammaLib classes.
Filename class interface definition.
Information logger class definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Comma-separated values table class.
Definition GCsv.hpp:57
Daemon class.
Definition GDaemon.hpp:51
void create_xml(const GFilename &filename)
Create high-level statistics XML file.
Definition GDaemon.cpp:866
pid_t m_pid
Process ID.
Definition GDaemon.hpp:95
void update_statistics(void)
Update application statistics.
Definition GDaemon.cpp:584
void copy_members(const GDaemon &daemon)
Copy class members.
Definition GDaemon.cpp:418
virtual ~GDaemon(void)
Destructor.
Definition GDaemon.cpp:96
GFilename lock_filename(void) const
Returns name of daemon lock file.
Definition GDaemon.hpp:121
void update_host_country(void)
Update host country.
Definition GDaemon.cpp:690
GChatter m_chatter
Chattiness of logger.
Definition GDaemon.hpp:99
void update_daily(GXml &xml, const GCsv &statistics)
Update daily statistics.
Definition GDaemon.cpp:1197
void start(void)
Starts the daemon.
Definition GDaemon.cpp:177
pid_t lock_pid(void) const
Returns process ID in lock file.
Definition GDaemon.cpp:546
void write_heartbeat(void)
Write heartbeat file.
Definition GDaemon.cpp:512
GDaemon & operator=(const GDaemon &daemon)
Assignment operator.
Definition GDaemon.cpp:118
void update_versions_data(GXml &xml, const GCsv &statistics)
Update versions in high-level statistics data.
Definition GDaemon.cpp:1116
int m_heartbeat
Heartbeat period in seconds.
Definition GDaemon.hpp:97
bool alive(void) const
Check if daemon is alive.
Definition GDaemon.cpp:282
void update_countries_data(GXml &xml, const GCsv &statistics)
Update countries in high-level statistics data.
Definition GDaemon.cpp:1035
void create_lock_file(void)
Create the lock file.
Definition GDaemon.cpp:450
int m_period
Wake-up period in seconds.
Definition GDaemon.hpp:96
virtual std::string print(const GChatter &chatter=NORMAL) const
Print Daemon.
Definition GDaemon.cpp:362
void update_countries_header(GXml &xml, const GCsv &statistics)
Update countries in high-level statistics header.
Definition GDaemon.cpp:978
GFilename statistics_filename(void) const
void recover_valid_xml(void)
Recovers a valid XML file.
Definition GDaemon.cpp:746
virtual std::string classname(void) const
Return class name.
Definition GDaemon.hpp:109
virtual void clear(void)
Clear Daemon.
Definition GDaemon.cpp:148
void update_dates(GXml &xml, const GCsv &statistics)
Update dates in high-level statistics header.
Definition GDaemon.cpp:918
void free_members(void)
Delete class members.
Definition GDaemon.cpp:435
GFilename heartbeat_filename(void) const
Returns name of daemon heartbeat file.
Definition GDaemon.hpp:133
GDaemon(void)
Void constructor.
Definition GDaemon.cpp:65
GLog m_log
Logger.
Definition GDaemon.hpp:98
void init_members(void)
Initialise class members.
Definition GDaemon.cpp:399
virtual GDaemon * clone(void) const
Clone Daemon.
Definition GDaemon.cpp:166
void delete_lock_file(void)
Delete daemon lock file.
Definition GDaemon.cpp:483
Filename class.
Definition GFilename.hpp:62
Information logger interface definition.
Definition GLog.hpp:62
XML class.
Definition GXml.hpp:172
GFilename gamma_filename(const std::string &name)
Returns filename in .gamma directory.
Definition GTools.cpp:2484