Skip to content

Commit 563c03e

Browse files
committed
FileSystemWatcher: Remove dependency from Async and File libraries
1 parent 07e100e commit 563c03e

File tree

19 files changed

+845
-497
lines changed

19 files changed

+845
-497
lines changed

Documentation/Doxygen/Doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ INPUT = ../../Documentation/Pages \
2929
../../Libraries/FileSystem \
3030
../../Libraries/FileSystemIterator \
3131
../../Libraries/FileSystemWatcher \
32+
../../Libraries/FileSystemWatcherAsync \
3233
../../Libraries/Foundation \
3334
../../Libraries/Hashing \
3435
../../Libraries/Http \

Documentation/Libraries/FileSystemWatcher.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
SC::FileSystemWatcher allows watching directories for changes that happen to them.
88

99
# Dependencies
10-
- Direct dependencies: [Async](@ref library_async), [Foundation](@ref library_foundation), [Threading](@ref library_threading)
11-
- All dependencies: [Async](@ref library_async), [File](@ref library_file), [FileSystem](@ref library_file_system), [Foundation](@ref library_foundation), [Socket](@ref library_socket), [Threading](@ref library_threading), [Time](@ref library_time)
10+
- Direct dependencies: [Foundation](@ref library_foundation), [Threading](@ref library_threading)
11+
- All dependencies: [Foundation](@ref library_foundation), [Threading](@ref library_threading)
1212

1313
# Statistics
14-
- Lines of code (excluding comments): 1227
15-
- Lines of code (including comments): 1570
14+
- Lines of code (excluding comments): 1319
15+
- Lines of code (including comments): 1668
1616

1717
# Features
1818
- Get notified about modified files or directories
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@page library_file_system_watcher_async File System Watcher Async
2+
3+
@brief 🟩 [Async](@ref library_async) backend for [FileSystemWatcher](@ref library_file_system_watcher)
4+
5+
[TOC]
6+
7+
SC::FileSystemWatcherAsync is an implementation of SC::FileSystemWatcher that uses SC::Async to deliver notifications.
8+
9+
# Dependencies
10+
- Direct dependencies: [Async](@ref library_async), [FileSystemWatcher](@ref library_file_system_watcher), [Foundation](@ref library_foundation)
11+
- All dependencies: [Async](@ref library_async), [File](@ref library_file), [FileSystem](@ref library_file_system), [FileSystemWatcher](@ref library_file_system_watcher), [Foundation](@ref library_foundation), [Socket](@ref library_socket), [Threading](@ref library_threading), [Time](@ref library_time)
12+
13+
# Statistics
14+
- Lines of code (excluding comments): 113
15+
- Lines of code (including comments): 166
16+
17+
# Features
18+
- Implement SC::FileSystemWatcher::EventLoopRunner for macOS, Windows and Linux
19+
20+
# Status
21+
🟩 Usable
22+
Library does have basic capabilities and it can be used just fine.
23+
24+
# Roadmap
25+
26+
🟦 Complete Features:
27+
- Not sure what else could be useful here
28+
29+
💡 Unplanned Features:
30+
- Not sure what else could be useful here

Documentation/Pages/Dependencies.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ This file describes what each library depends on. It also lists the number of li
5050
- Lines of code (including comments): 541
5151

5252
# [FileSystemWatcher](@ref library_file_system_watcher)
53-
- Direct dependencies: [Async](@ref library_async), [Foundation](@ref library_foundation), [Threading](@ref library_threading)
54-
- All dependencies: [Async](@ref library_async), [File](@ref library_file), [FileSystem](@ref library_file_system), [Foundation](@ref library_foundation), [Socket](@ref library_socket), [Threading](@ref library_threading), [Time](@ref library_time)
55-
- Lines of code (excluding comments): 1227
56-
- Lines of code (including comments): 1570
53+
- Direct dependencies: [Foundation](@ref library_foundation), [Threading](@ref library_threading)
54+
- All dependencies: [Foundation](@ref library_foundation), [Threading](@ref library_threading)
55+
- Lines of code (excluding comments): 1319
56+
- Lines of code (including comments): 1668
57+
58+
# [FileSystemWatcherAsync](@ref library_file_system_watcher_async)
59+
- Direct dependencies: [Async](@ref library_async), [FileSystemWatcher](@ref library_file_system_watcher), [Foundation](@ref library_foundation)
60+
- All dependencies: [Async](@ref library_async), [File](@ref library_file), [FileSystem](@ref library_file_system), [FileSystemWatcher](@ref library_file_system_watcher), [Foundation](@ref library_foundation), [Socket](@ref library_socket), [Threading](@ref library_threading), [Time](@ref library_time)
61+
- Lines of code (excluding comments): 113
62+
- Lines of code (including comments): 166
5763

5864
# [Foundation](@ref library_foundation)
5965
- Direct dependencies: *(none)*
@@ -141,6 +147,6 @@ This file describes what each library depends on. It also lists the number of li
141147

142148
---
143149
# Project Total
144-
- Total lines of code (excluding comments): 31037
145-
- Total lines of code (including comments): 41148
150+
- Total lines of code (excluding comments): 31242
151+
- Total lines of code (including comments): 41412
146152

Documentation/Pages/Libraries.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,32 @@
22

33
This is the list of all libraries, whose internal dependencies are documented at [Dependencies](@ref page_dependencies):
44

5-
Library | Description | LOC
6-
:-------------------------------------------|:------------------------------------------|---------------
7-
@subpage library_algorithms | @copybrief library_algorithms | 102
8-
@subpage library_async | @copybrief library_async | 5661
9-
@subpage library_async_streams | @copybrief library_async_streams | 2013
10-
@subpage library_build | @copybrief library_build | 4094
11-
@subpage library_containers | @copybrief library_containers | 801
12-
@subpage library_file | @copybrief library_file | 700
13-
@subpage library_file_system | @copybrief library_file_system | 1323
14-
@subpage library_file_system_iterator | @copybrief library_file_system_iterator | 417
15-
@subpage library_file_system_watcher | @copybrief library_file_system_watcher | 1227
16-
@subpage library_foundation | @copybrief library_foundation | 1215
17-
@subpage library_hashing | @copybrief library_hashing | 359
18-
@subpage library_http | @copybrief library_http | 1299
19-
@subpage library_memory | @copybrief library_memory | 1257
20-
@subpage library_plugin | @copybrief library_plugin | 1464
21-
@subpage library_process | @copybrief library_process | 1318
22-
@subpage library_reflection | @copybrief library_reflection | 700
23-
@subpage library_serialization_binary | @copybrief library_serialization_binary | 594
24-
@subpage library_serialization_text | @copybrief library_serialization_text | 661
25-
@subpage library_socket | @copybrief library_socket | 858
26-
@subpage library_strings | @copybrief library_strings | 3387
27-
@subpage library_testing | @copybrief library_testing | 343
28-
@subpage library_threading | @copybrief library_threading | 895
29-
@subpage library_time | @copybrief library_time | 349
5+
Library | Description | LOC
6+
:-------------------------------------------|:----------------------------------------------|---------------
7+
@subpage library_algorithms | @copybrief library_algorithms | 102
8+
@subpage library_async | @copybrief library_async | 5661
9+
@subpage library_async_streams | @copybrief library_async_streams | 2013
10+
@subpage library_build | @copybrief library_build | 4094
11+
@subpage library_containers | @copybrief library_containers | 801
12+
@subpage library_file | @copybrief library_file | 700
13+
@subpage library_file_system | @copybrief library_file_system | 1323
14+
@subpage library_file_system_iterator | @copybrief library_file_system_iterator | 417
15+
@subpage library_file_system_watcher | @copybrief library_file_system_watcher | 1319
16+
@subpage library_file_system_watcher_async | @copybrief library_file_system_watcher_async | 113
17+
@subpage library_foundation | @copybrief library_foundation | 1215
18+
@subpage library_hashing | @copybrief library_hashing | 359
19+
@subpage library_http | @copybrief library_http | 1299
20+
@subpage library_memory | @copybrief library_memory | 1257
21+
@subpage library_plugin | @copybrief library_plugin | 1464
22+
@subpage library_process | @copybrief library_process | 1318
23+
@subpage library_reflection | @copybrief library_reflection | 700
24+
@subpage library_serialization_binary | @copybrief library_serialization_binary | 594
25+
@subpage library_serialization_text | @copybrief library_serialization_text | 661
26+
@subpage library_socket | @copybrief library_socket | 858
27+
@subpage library_strings | @copybrief library_strings | 3387
28+
@subpage library_testing | @copybrief library_testing | 343
29+
@subpage library_threading | @copybrief library_threading | 895
30+
@subpage library_time | @copybrief library_time | 349
3031

3132

3233
Some libraries have [C Bindings](@ref group_c_bindings):

Examples/SCExample/HotReloadSystem.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44
#include "Libraries/FileSystem/FileSystem.h"
55
#include "Libraries/FileSystemWatcher/FileSystemWatcher.h"
6+
#include "Libraries/FileSystemWatcherAsync/FileSystemWatcherAsync.h"
67
#include "Libraries/Plugin/Plugin.h"
78
#include "Libraries/Strings/Path.h"
89

@@ -54,7 +55,8 @@ struct HotReloadSystem
5455
SC_TRY(compiler.includePaths.push_back(state.imguiPath.view()));
5556

5657
// Setup File System Watcher
57-
SC_TRY(fileSystemWatcher.init(fileSystemWatcherRunner, *eventLoop));
58+
fileSystemWatcherRunner.init(*eventLoop);
59+
SC_TRY(fileSystemWatcher.init(fileSystemWatcherRunner));
5860
folderWatcher.notifyCallback.bind<HotReloadSystem, &HotReloadSystem::onFileChange>(*this);
5961
SC_TRY(fileSystemWatcher.watch(folderWatcher, state.pluginsPath.view()));
6062
return Result(true);
@@ -122,10 +124,10 @@ struct HotReloadSystem
122124
PluginCompiler compiler;
123125
PluginSysroot sysroot;
124126

125-
FileSystemWatcher fileSystemWatcher;
127+
FileSystemWatcher fileSystemWatcher;
128+
FileSystemWatcherAsync fileSystemWatcherRunner;
126129

127-
FileSystemWatcher::FolderWatcher folderWatcher;
128-
FileSystemWatcher::EventLoopRunner fileSystemWatcherRunner;
130+
FileSystemWatcher::FolderWatcher folderWatcher;
129131

130132
void onFileChange(const FileSystemWatcher::Notification& notification)
131133
{

Libraries/FileSystemWatcher/FileSystemWatcher.cpp

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Stefano Cristiano
22
// SPDX-License-Identifier: MIT
3-
#include "../Async/Internal/IntrusiveDoubleLinkedList.inl" // IWYU pragma: keep
4-
3+
#include "../FileSystemWatcher/FileSystemWatcher.h"
4+
#include "../Foundation/Assert.h"
55
#if SC_PLATFORM_WINDOWS
66
#include "Internal/FileSystemWatcherWindows.inl"
77
#elif SC_PLATFORM_APPLE
@@ -19,11 +19,7 @@ SC::FileSystemWatcher::FolderWatcher::FolderWatcher(Span<char> buffer)
1919
#endif
2020
}
2121

22-
SC::Result SC::FileSystemWatcher::init(EventLoopRunner& runner, AsyncEventLoop& eventLoop)
23-
{
24-
runner.eventLoop = &eventLoop;
25-
return internal.get().init(*this, runner);
26-
}
22+
SC::Result SC::FileSystemWatcher::init(EventLoopRunner& runner) { return internal.get().init(*this, runner); }
2723

2824
SC::Result SC::FileSystemWatcher::init(ThreadRunner& runner) { return internal.get().init(*this, runner); }
2925

@@ -44,13 +40,7 @@ SC::Result SC::FileSystemWatcher::FolderWatcher::stopWatching()
4440
return parent->internal.get().stopWatching(*this);
4541
}
4642

47-
void SC::FileSystemWatcher::FolderWatcher::setDebugName(const char* debugName)
48-
{
49-
(void)debugName;
50-
#if SC_PLATFORM_WINDOWS
51-
return Internal::setDebugName(*this, debugName);
52-
#endif
53-
}
43+
void SC::FileSystemWatcher::FolderWatcher::setDebugName(const char* debugName) { (void)debugName; }
5444

5545
//! [OpaqueDefinition2Snippet]
5646
template <>
@@ -85,3 +75,73 @@ void SC::OpaqueObject<SC::FileSystemWatcher::FolderWatcherSizes>::destruct(Objec
8575
{
8676
obj.~Object();
8777
}
78+
79+
void SC::FileSystemWatcher::EventLoopRunner::internalInit(FileSystemWatcher& pself, int handle)
80+
{
81+
fileSystemWatcher = &pself;
82+
(void)handle;
83+
#if SC_PLATFORM_LINUX
84+
notifyFd = handle;
85+
#endif
86+
}
87+
88+
void SC::FileSystemWatcher::WatcherLinkedList::queueBack(FolderWatcher& item)
89+
{
90+
SC_ASSERT_DEBUG(item.next == nullptr and item.prev == nullptr);
91+
if (back)
92+
{
93+
back->next = &item;
94+
item.prev = back;
95+
}
96+
else
97+
{
98+
SC_ASSERT_DEBUG(front == nullptr);
99+
front = &item;
100+
}
101+
back = &item;
102+
SC_ASSERT_DEBUG(back->next == nullptr);
103+
SC_ASSERT_DEBUG(front->prev == nullptr);
104+
}
105+
106+
void SC::FileSystemWatcher::WatcherLinkedList::remove(FolderWatcher& item)
107+
{
108+
using T = FolderWatcher;
109+
#if SC_CONFIGURATION_DEBUG
110+
bool found = false;
111+
auto it = front;
112+
while (it)
113+
{
114+
if (it == &item)
115+
{
116+
found = true;
117+
break;
118+
}
119+
it = static_cast<T*>(it->next);
120+
}
121+
SC_ASSERT_DEBUG(found);
122+
#endif
123+
if (&item == front)
124+
{
125+
front = static_cast<T*>(front->next);
126+
}
127+
if (&item == back)
128+
{
129+
back = static_cast<T*>(back->prev);
130+
}
131+
132+
T* next = static_cast<T*>(item.next);
133+
T* prev = static_cast<T*>(item.prev);
134+
135+
if (prev)
136+
{
137+
prev->next = next;
138+
}
139+
140+
if (next)
141+
{
142+
next->prev = prev;
143+
}
144+
145+
item.next = nullptr;
146+
item.prev = nullptr;
147+
}

0 commit comments

Comments
 (0)