fswatch 1.20.1
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2026 Enrico M. Crisostomo
3 *
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 3, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 * details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
25
26#ifndef FSW_EVENT_H
27# define FSW_EVENT_H
28
29# include <string>
30# include <ctime>
31# include <vector>
32# include <iostream>
33# include <optional>
34# include "../c/cevent.h"
35
36namespace fsw
37{
38 enum class process_id_kind
39 {
40 none = 0,
41 pid,
42 tid
43 };
44
46 {
47 process_id_kind kind = process_id_kind::none;
48 long long id = 0;
49 int pidfd = -1;
50 bool has_pidfd = false;
51 };
52
64 class event
65 {
66 public:
74 event(std::string path, time_t evt_time, std::vector<fsw_event_flag> flags);
75
84 event(std::string path, time_t evt_time, std::vector<fsw_event_flag> flags, unsigned long correlation_id);
85
95 event(std::string path,
96 time_t evt_time,
97 std::vector<fsw_event_flag> flags,
98 unsigned long correlation_id,
99 process_metadata process);
100
106 virtual ~event();
107
113 std::string get_path() const;
114
120 time_t get_time() const;
121
127 std::vector<fsw_event_flag> get_flags() const;
128
133 unsigned long get_correlation_id() const;
134
138 bool has_process_id() const;
139
145 long long get_process_id() const;
146
150 process_id_kind get_process_id_kind() const;
151
155 bool has_process_pidfd() const;
156
164 int get_process_pidfd() const;
165
169 static std::string get_process_id_kind_name(process_id_kind kind);
170
178 static fsw_event_flag get_event_flag_by_name(const std::string& name);
179
187 static std::string get_event_flag_name(const fsw_event_flag& flag);
188
189 private:
190 std::string path;
191 time_t evt_time;
192 std::vector<fsw_event_flag> evt_flags;
193 unsigned long correlation_id = 0;
194 process_metadata process;
195 };
196
204 std::ostream& operator<<(std::ostream& out, const fsw_event_flag flag);
205}
206
207#endif /* FSW_EVENT_H */
Event type manipulation.
fsw_event_flag
Backend-agnostic change flags.
Definition cevent.h:66
event(std::string path, time_t evt_time, std::vector< fsw_event_flag > flags, unsigned long correlation_id, process_metadata process)
Constructs an event with optional process metadata.
time_t get_time() const
Returns the time of the event.
Definition event.cpp:55
int get_process_pidfd() const
Returns the process file descriptor associated with this event.
Definition event.cpp:90
bool has_process_pidfd() const
Returns true if the event has a process file descriptor.
Definition event.cpp:85
event(std::string path, time_t evt_time, std::vector< fsw_event_flag > flags)
Constructs an event.
event(std::string path, time_t evt_time, std::vector< fsw_event_flag > flags, unsigned long correlation_id)
Constructs an event.
unsigned long get_correlation_id() const
Returns the correlation_id of the file of the event.
Definition event.cpp:65
long long get_process_id() const
Returns the process or thread identifier associated with this event.
Definition event.cpp:75
static std::string get_event_flag_name(const fsw_event_flag &flag)
Get the name of an event flag.
Definition event.cpp:141
std::string get_path() const
Returns the path of the event.
Definition event.cpp:50
process_id_kind get_process_id_kind() const
Returns the process identifier kind.
Definition event.cpp:80
std::vector< fsw_event_flag > get_flags() const
Returns the flags of the event.
Definition event.cpp:60
static std::string get_process_id_kind_name(process_id_kind kind)
Get the display name of a process identifier kind.
Definition event.cpp:95
bool has_process_id() const
Returns true if the event has process attribution metadata.
Definition event.cpp:70
virtual ~event()
Destructs an event.
static fsw_event_flag get_event_flag_by_name(const std::string &name)
Get event flag by name.
Definition event.cpp:110
Main namespace of libfswatch.
Definition event.cpp:24
Definition event.hpp:46