Adding OSAL inotify - #379
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
665abfc to
8ca1037
Compare
8ca1037 to
79cbe77
Compare
ff44720 to
371082b
Compare
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
|
|
||
| #ifndef INOTIFY_RANGE_HPP_ |
There was a problem hiding this comment.
OSAL_INOTIFY_RANGE_HPP_INCLUDED
There was a problem hiding this comment.
Just a suggestion, shall we also include namespace in the #def?
SCORE_MW_LIFECYCLE_OSAL_INOTIFY_RANGE_HPP
paulquiring
left a comment
There was a problem hiding this comment.
Some findings nothing major.
| class INotifyRange | ||
| { | ||
| public: | ||
| explicit INotifyRange(std::unique_ptr<score::os::InotifyInstance> instance) noexcept |
There was a problem hiding this comment.
I am not sure I completely understand how this would be used.
It looks like you would still need to interact with the InotifyInstance to setup the file notification first.
And then later to call Close() but the pointer has already been moved to the INotifyRange
E.g. within some kind of FileWatchReadyCondition class:
std::unique_ptr<InotifyInstance> inotify = std::make_unique<InotifyInstanceImpl>();
// init
bool init() {
if(!inotify->IsValid) {
// ready condition failed
return false;
}
if(!inotify->AddWatch(path, event_mask)) {
// ready condition failed
return false;
}
}
// at runtime
score::cpp::expected_blank<Error> WaitForReadyCondition(stop_token) {
INotifyRange range(std::move(inotify);
while(!ready_timeout_over) {
for(events : range) { // does this block? How to interrupt this on timeout?
// if the expected event occured -> return Success
// else continue until timeout
}
}
}
// at destruction
// want to call inotify->Close() but its already moved outThere was a problem hiding this comment.
I will add this to a FileHandler class that will work like OsHandler (seperate thread).
I will add a stop() method I think then this would be the code
FileHandler::run(){
auto instance = std::make_unique<score::os::InotifyInstanceImpl>();
instance.AddWatch("/tmp", score::os::Inotify::EventMask::kInCreate);
range_ = INotifyRange{std::move(instance)}
for (const score::os::InotifyEvent& event : range_)
{
std::cout << event.GetName() << std::endl;
};
}
FileHandler::stop()
{
range_.stop();
}| return true; | ||
| } | ||
|
|
||
| auto result = instance_->Read(); |
There was a problem hiding this comment.
As far as I understood, this Read() call blocks until there is an event.
How to interrupt this when the ready timeout is over?
Or the startup needs to be aborted?
There was a problem hiding this comment.
InotifyInstance.Close() aborts this
Adding a small wrapper around
score::os::InotifyInstanceto get iterator syntax.Usage: