17# include <sys/eventfd.h>
18# include <sys/inotify.h>
19#elif defined __APPLE__
20# include <sys/event.h>
26 constexpr static std::uintptr_t USER_IDENT = 0x13acab2142;
34 using ptr = std::shared_ptr<DomainWatcherRecord>;
43 std::shared_ptr<SharedMemoryInstance<Flow>>
flowData;
48 return (
id == other.id) && (
fw == other.fw);
61 using ptr = std::shared_ptr<DomainWatcher>;
68 explicit DomainWatcher(std::filesystem::path
const& in_domain);
80 void addFlow(FlowWriter*
writer, uuids::uuid
id);
88 void removeFlow(FlowWriter*
writer, uuids::uuid
id);
99 auto value = ::eventfd_t{1};
100 if (::write(_eventFd, &value,
sizeof(::eventfd_t)) < 0)
102 auto const error = errno;
103 MXL_ERROR(
"Failed to signal DomainWatcher stop request: {}", ::strerror(error));
105#elif defined __APPLE__
107 EV_SET(&kev, USER_IDENT, EVFILT_USER, 0, NOTE_TRIGGER, 0,
nullptr);
108 if (::kevent(_kq, &kev, 1,
nullptr, 0,
nullptr) < 0)
110 auto const error = errno;
111 MXL_WARN(
"Failed so signal DomainWatcher stop request: {}", std::strerror(error));
122 std::size_t
count(uuids::uuid
id)
const noexcept;
127 std::size_t
size() const noexcept;
135 void processEventBuffer(struct ::inotify_event
const*
buffer, std::size_t
count);
136#elif defined __APPLE__
138 void processPendingEvents(
int numEvents);
146 std::vector<struct ::kevent> _eventsToMonitor;
147 std::vector<struct ::kevent> _eventData;
148#elif defined __linux__
158 std::unordered_multimap<int, DomainWatcherRecord>
_watches;
Internal shared-memory headers for discrete grains and event slots.
std::filesystem::path _domain
The monitored domain.
std::size_t size() const noexcept
Returns the total number of writers that are registered in the DomainWatcher.
DomainWatcher(std::filesystem::path const &in_domain)
std::unordered_multimap< int, DomainWatcherRecord > _watches
Map of watch descriptors to file records. Multiple records could use the same watchfd.
std::atomic< bool > _running
Controls the event processing thread.
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
std::mutex _mutex
Prodect maps.
std::thread _watchThread
Event processing thread.
Entry stored in the unordered_maps.
FlowWriter * fw
Non-owning event or discrete writer registered with the watcher.
std::string fileName
file being watched
std::shared_ptr< DomainWatcherRecord > ptr
Shared ownership of a watch record.
bool operator==(DomainWatcherRecord const &other) const noexcept
std::shared_ptr< SharedMemoryInstance< Flow > > flowData
Shared mapping used to update the flow's last-read time.
uint8_t * buffer
Set a mark at the beginning and the end of the grain payload.