2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-07-22 15:01:11 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Badge.h>
|
|
|
|
|
#include <AK/CircularQueue.h>
|
|
|
|
|
#include <AK/WeakPtr.h>
|
2020-11-07 04:38:48 -03:00
|
|
|
#include <Kernel/API/InodeWatcherEvent.h>
|
2019-07-22 15:01:11 -03:00
|
|
|
#include <Kernel/FileSystem/File.h>
|
2020-07-04 08:36:55 -03:00
|
|
|
#include <Kernel/Lock.h>
|
2019-07-22 15:01:11 -03:00
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2019-07-22 15:01:11 -03:00
|
|
|
class Inode;
|
|
|
|
|
|
|
|
|
|
class InodeWatcher final : public File {
|
|
|
|
|
public:
|
|
|
|
|
static NonnullRefPtr<InodeWatcher> create(Inode&);
|
|
|
|
|
virtual ~InodeWatcher() override;
|
|
|
|
|
|
2020-04-10 06:44:42 -03:00
|
|
|
virtual bool can_read(const FileDescription&, size_t) const override;
|
|
|
|
|
virtual bool can_write(const FileDescription&, size_t) const override;
|
2021-03-17 09:18:51 -03:00
|
|
|
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
|
|
|
|
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
2019-07-22 15:01:11 -03:00
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
|
|
|
|
virtual const char* class_name() const override { return "InodeWatcher"; };
|
|
|
|
|
|
2020-11-07 04:38:48 -03:00
|
|
|
void notify_inode_event(Badge<Inode>, InodeWatcherEvent::Type);
|
2020-09-19 11:39:52 -03:00
|
|
|
void notify_child_added(Badge<Inode>, const InodeIdentifier& child_id);
|
|
|
|
|
void notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id);
|
2019-07-22 15:01:11 -03:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit InodeWatcher(Inode&);
|
|
|
|
|
|
2020-07-04 08:36:55 -03:00
|
|
|
Lock m_lock;
|
2019-07-22 15:01:11 -03:00
|
|
|
WeakPtr<Inode> m_inode;
|
2020-11-07 04:38:48 -03:00
|
|
|
CircularQueue<InodeWatcherEvent, 32> m_queue;
|
2019-07-22 15:01:11 -03:00
|
|
|
};
|
2020-02-15 21:27:42 -03:00
|
|
|
|
|
|
|
|
}
|