mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +00:00
LibCore: Move FileWatcher implementations into separate files
Rather than one big file with (eventually) all implementations for each OS, let's keep OS-specific implementations in their own files.
This commit is contained in:
parent
204257526c
commit
5bfc9daba1
3 changed files with 49 additions and 30 deletions
|
@ -10,7 +10,6 @@ set(SOURCES
|
||||||
Event.cpp
|
Event.cpp
|
||||||
EventLoop.cpp
|
EventLoop.cpp
|
||||||
File.cpp
|
File.cpp
|
||||||
FileWatcher.cpp
|
|
||||||
IODevice.cpp
|
IODevice.cpp
|
||||||
LockFile.cpp
|
LockFile.cpp
|
||||||
MappedFile.cpp
|
MappedFile.cpp
|
||||||
|
@ -45,5 +44,12 @@ if (NOT ANDROID AND NOT WIN32 AND NOT EMSCRIPTEN)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# FIXME: Implement Core::FileWatcher for Linux, macOS, *BSD, and Windows.
|
||||||
|
if (SERENITYOS)
|
||||||
|
list(APPEND SOURCES FileWatcherSerenity.cpp)
|
||||||
|
else()
|
||||||
|
list(APPEND SOURCES FileWatcherUnimplemented.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
serenity_lib(LibCore core)
|
serenity_lib(LibCore core)
|
||||||
target_link_libraries(LibCore PRIVATE LibCrypt LibSystem)
|
target_link_libraries(LibCore PRIVATE LibCrypt LibSystem)
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace Core {
|
#if !defined(AK_OS_SERENITY)
|
||||||
|
static_assert(false, "This file must only be used for SerenityOS");
|
||||||
|
#endif
|
||||||
|
|
||||||
// Only supported in serenity mode because we use InodeWatcher syscalls
|
namespace Core {
|
||||||
#ifdef AK_OS_SERENITY
|
|
||||||
|
|
||||||
static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, DeprecatedString> const& wd_to_path)
|
static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, DeprecatedString> const& wd_to_path)
|
||||||
{
|
{
|
||||||
|
@ -206,30 +207,4 @@ FileWatcher::~FileWatcher()
|
||||||
dbgln_if(FILE_WATCHER_DEBUG, "Stopped watcher at fd {}", m_notifier->fd());
|
dbgln_if(FILE_WATCHER_DEBUG, "Stopped watcher at fd {}", m_notifier->fd());
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
// FIXME: Implement Core::FileWatcher for linux, macOS, and *BSD
|
|
||||||
FileWatcher::~FileWatcher() { }
|
|
||||||
FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
|
|
||||||
: FileWatcherBase(watcher_fd)
|
|
||||||
, m_notifier(move(notifier))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<FileWatcher>> FileWatcher::create(InodeWatcherFlags)
|
|
||||||
{
|
|
||||||
return Error::from_errno(ENOTSUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString, FileWatcherEvent::Type)
|
|
||||||
{
|
|
||||||
return Error::from_errno(ENOTSUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<bool> FileWatcherBase::remove_watch(DeprecatedString)
|
|
||||||
{
|
|
||||||
return Error::from_errno(ENOTSUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
38
Userland/Libraries/LibCore/FileWatcherUnimplemented.cpp
Normal file
38
Userland/Libraries/LibCore/FileWatcherUnimplemented.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
||||||
|
* Copyright (c) 2021, the SerenityOS developers.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FileWatcher.h"
|
||||||
|
#include <Kernel/API/InodeWatcherFlags.h>
|
||||||
|
#include <LibCore/Notifier.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
|
||||||
|
ErrorOr<NonnullRefPtr<FileWatcher>> FileWatcher::create(InodeWatcherFlags)
|
||||||
|
{
|
||||||
|
return Error::from_errno(ENOTSUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
|
||||||
|
: FileWatcherBase(watcher_fd)
|
||||||
|
, m_notifier(move(notifier))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FileWatcher::~FileWatcher() = default;
|
||||||
|
|
||||||
|
ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString, FileWatcherEvent::Type)
|
||||||
|
{
|
||||||
|
return Error::from_errno(ENOTSUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<bool> FileWatcherBase::remove_watch(DeprecatedString)
|
||||||
|
{
|
||||||
|
return Error::from_errno(ENOTSUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue