~aleteoryx/muditaos

ref: b9661350f8dd5180b5f8fe7c758e5ae16452f7cf muditaos/module-vfs/src/deprecated/vfsNotifier.cpp -rw-r--r-- 1.3 KiB
b9661350 — Piotr Tański [EGD-5697] Framework for phone modes introduced 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "vfsNotifier.hpp"
#include <vfs.hpp>
#include <cstring>

namespace vfsn::utility
{

    auto vfsNotifier::onFileOpen(std::string_view filename, const char *mode, const FILE *file) noexcept -> void
    {
        if (file && std::strpbrk(mode, "+wa")) {
            cpp_freertos::LockGuard _lock(mMutex);
            mOpenedMap.emplace(file, vfs.getAbsolutePath(filename));
        }
    }
    auto vfsNotifier::onFileClose(const FILE *file) noexcept -> void
    {
        cpp_freertos::LockGuard _lock(mMutex);
        const auto item = mOpenedMap.find(file);
        if (item != mOpenedMap.end()) {
            const auto path = item->second;
            mOpenedMap.erase(item);
            notify(path, FsEvent::modified);
        }
    }

    auto vfsNotifier::onFileRemove(std::string_view filename) noexcept -> void
    {
        notify(vfs.getAbsolutePath(filename), FsEvent::deleted);
    }

    auto vfsNotifier::onFileRename(std::string_view new_file, std::string_view old_file) noexcept -> void
    {
        notify(vfs.getAbsolutePath(new_file), FsEvent::renamed, vfs.getAbsolutePath(old_file));
    }
} // namespace vfsn::utility