The Pedigree Project
0.1
src
modules
system
vfs
FileEvent.h
1
/*
2
* Copyright (c) 2026, Pedigree Developers
3
*
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
7
*/
8
9
#ifndef PEDIGREE_VFS_FILEEVENT_H
10
#define PEDIGREE_VFS_FILEEVENT_H
11
12
#include "pedigree/kernel/compiler.h"
13
#include "pedigree/kernel/processor/types.h"
14
#include "pedigree/kernel/utilities/SharedPointer.h"
15
#include "pedigree/kernel/utilities/StringView.h"
16
17
using
FileEventMask = uint32_t;
18
19
namespace
FileEvents {
20
enum
Event
: FileEventMask {
21
None = 0,
22
Access = 1U << 0,
23
Modify = 1U << 1,
24
Attributes = 1U << 2,
25
CloseWrite = 1U << 3,
26
CloseNoWrite = 1U << 4,
27
Open = 1U << 5,
28
Created = 1U << 6,
29
Removed = 1U << 7,
30
DeletedSelf = 1U << 8,
31
SourceRetired = 1U << 9,
32
};
33
}
// namespace FileEvents
34
35
struct
FileEvent
{
36
FileEvent
(FileEventMask eventMask,
const
StringView
& eventName,
bool
eventTargetIsDirectory,
37
uint32_t producer = 0)
38
: mask(eventMask),
39
name
(eventName),
40
targetIsDirectory(eventTargetIsDirectory),
41
producerPid(producer) {}
42
43
FileEventMask mask;
45
StringView
name
;
46
bool
targetIsDirectory;
47
uint32_t producerPid;
48
};
49
50
class
FileEventState
;
51
class
FileEventTarget
;
52
53
class
EXPORTED_PUBLIC
FileEventObserver
{
54
public
:
55
virtual
~FileEventObserver
() =
default
;
56
62
virtual
void
fileEvent
(
const
FileEvent
& event) = 0;
63
};
64
69
class
EXPORTED_PUBLIC
FileEventSubscription
{
70
public
:
71
FileEventSubscription
();
72
FileEventSubscription
(
FileEventSubscription
&& other)
noexcept
;
73
~FileEventSubscription
();
74
75
FileEventSubscription
& operator=(
FileEventSubscription
&& other)
noexcept
;
76
77
explicit
operator
bool()
const
;
78
void
reset();
79
80
private
:
81
friend
class
FileEventSource
;
82
83
FileEventSubscription
(
const
FileEventSubscription
&) =
delete
;
84
FileEventSubscription
& operator=(
const
FileEventSubscription
&) =
delete
;
85
86
SharedPointer<FileEventState>
m_State;
87
SharedPointer<FileEventTarget>
m_Target;
88
SharedPointer<FileEventObserver>
m_Observer;
89
};
90
92
class
EXPORTED_PUBLIC
FileEventSource
{
93
public
:
94
FileEventSource
();
95
virtual
~FileEventSource
();
96
97
MUST_USE_RESULT
bool
subscribeFileEvents(FileEventMask interest,
98
const
SharedPointer<FileEventObserver>
& observer,
99
FileEventSubscription
& subscription);
100
101
protected
:
103
static
bool
anyFileEventObservers();
104
bool
hasFileEventObservers(FileEventMask mask)
const
;
106
void
notifyFileEvent(
const
FileEvent
& event);
108
void
notifyFinalFileEvent(
const
FileEvent
& event);
110
void
beginFinalFileEvent(
const
FileEvent
& event);
111
void
drainFileEvents();
112
void
closeFileEvents();
113
114
private
:
115
FileEventSource
(
const
FileEventSource
&) =
delete
;
116
FileEventSource
& operator=(
const
FileEventSource
&) =
delete
;
117
118
SharedPointer<FileEventState>
m_FileEventState;
119
};
120
122
class
EXPORTED_PUBLIC
InodeEventSource
:
public
FileEventSource
{
123
public
:
124
void
publish(
const
FileEvent
& event);
125
void
beginRetirement();
127
void
finishRetirement();
128
};
129
130
#endif
Event
Definition
Event.h:49
FileEventObserver
Definition
FileEvent.h:53
FileEventObserver::fileEvent
virtual void fileEvent(const FileEvent &event)=0
FileEventSource
Definition
FileEvent.h:92
FileEventState
Definition
FileEvent.cc:67
FileEventSubscription
Definition
FileEvent.h:69
FileEventTarget
Definition
FileEvent.cc:23
InodeEventSource
Definition
FileEvent.h:122
SharedPointer
Definition
SharedPointer.h:31
StringView
Definition
StringView.h:34
MUST_USE_RESULT
#define MUST_USE_RESULT
Definition
system/include/pedigree/kernel/compiler.h:70
FileEvent
Definition
FileEvent.h:35
FileEvent::name
StringView name
Definition
FileEvent.h:45
Generated on Tue Sep 22 2026 06:05:49 for The Pedigree Project by
1.9.8