Sese Framework
x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
FileNotifier.h
浏览该文件的文档.
1
// Copyright 2024 libsese
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
20
21
#pragma once
22
23
#include "
sese/Config.h
"
24
#include "
sese/util/Result.h
"
25
26
#include <atomic>
27
#ifdef __APPLE__
28
#include <tuple>
29
#else
30
#include "
sese/thread/Thread.h
"
31
#endif
32
33
namespace
sese::system
{
34
36
struct
FileNotifyOption
{
37
virtual
~FileNotifyOption
() =
default
;
38
40
virtual
void
onCreate
(std::string_view name) = 0;
41
43
virtual
void
onMove
(std::string_view src_name, std::string_view dst_name) = 0;
44
46
virtual
void
onModify
(std::string_view name) = 0;
47
49
virtual
void
onDelete
(std::string_view name) = 0;
50
};
51
55
class
FileNotifier
{
56
public
:
57
using
Ptr
= std::unique_ptr<FileNotifier>;
58
63
static
FileNotifier::Ptr
create
(
const
std::string &path,
FileNotifyOption
*option)
noexcept
;
64
65
static
Result<Ptr>
createEx
(
const
std::string &path,
FileNotifyOption
*option)
noexcept
;
66
67
virtual
~FileNotifier
() noexcept;
68
70
void
loopNonblocking
() noexcept;
71
73
void
shutdown
() noexcept;
74
75
private:
76
FileNotifier
() = default;
77
78
#ifdef WIN32
79
void
*file_handle =
nullptr
;
80
void
*overlapped =
nullptr
;
81
std::atomic_bool is_shutdown =
false
;
82
FileNotifyOption
*option =
nullptr
;
83
Thread::Ptr
th =
nullptr
;
84
#elif __linux__
85
int
inotify_fd = -1;
86
int
watch_fd = -1;
87
std::atomic_bool is_shutdown =
false
;
88
FileNotifyOption
*option =
nullptr
;
89
Thread::Ptr
th =
nullptr
;
90
#elif __APPLE__
91
void
*stream =
nullptr
;
92
void
*queue =
nullptr
;
93
#endif
94
};
95
}
// namespace sese::system
sese
system
FileNotifier.h
生成于 2024年 十一月 4日 星期一 09:58:02 , 为 Sese Framework使用
1.11.0