The Pedigree Project 0.1
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
17using FileEventMask = uint32_t;
18
19namespace FileEvents {
20enum 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
35struct 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;
46 bool targetIsDirectory;
47 uint32_t producerPid;
48};
49
50class FileEventState;
51class FileEventTarget;
52
53class EXPORTED_PUBLIC FileEventObserver {
54 public:
55 virtual ~FileEventObserver() = default;
56
62 virtual void fileEvent(const FileEvent& event) = 0;
63};
64
69class EXPORTED_PUBLIC FileEventSubscription {
70 public:
74
75 FileEventSubscription& operator=(FileEventSubscription&& other) noexcept;
76
77 explicit operator bool() const;
78 void reset();
79
80 private:
81 friend class FileEventSource;
82
84 FileEventSubscription& operator=(const FileEventSubscription&) = delete;
85
89};
90
92class EXPORTED_PUBLIC FileEventSource {
93 public:
95 virtual ~FileEventSource();
96
97 MUST_USE_RESULT bool subscribeFileEvents(FileEventMask interest,
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
122class EXPORTED_PUBLIC InodeEventSource : public FileEventSource {
123 public:
124 void publish(const FileEvent& event);
125 void beginRetirement();
127 void finishRetirement();
128};
129
130#endif
Definition Event.h:49
virtual void fileEvent(const FileEvent &event)=0
StringView name
Definition FileEvent.h:45