~aleteoryx/muditaos

ref: 64cfe81ec546ed75b7be1cffaef781aa3b893236 muditaos/module-services/service-fileindexer/StartupIndexer.hpp -rw-r--r-- 1.5 KiB
64cfe81e — Marek Niepieklo [CP-427] Set Mudita USB VID as default 4 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <Service/Service.hpp>
#include <module-sys/Timers/TimerHandle.hpp>

#include <list>

namespace service::msg
{
    class FileChangeMessage;
}
namespace service::detail
{
    // RFC6838 IANA MIME types
    enum class mimeType
    {
        _none_,
        application,
        audio,
        example,
        font,
        image,
        text,
        video
    };
    class StartupIndexer
    {
        static constexpr auto timer_indexing_time = 100U;

      public:
        StartupIndexer()                       = default;
        ~StartupIndexer()                      = default;
        StartupIndexer(const StartupIndexer &) = delete;
        StartupIndexer &operator=(StartupIndexer) = delete;
        auto start(std::shared_ptr<sys::Service> svc, std::string_view svc_name) -> void
        {
            collectStartupFiles();
            setupTimers(svc, svc_name);
        }
        static auto getFileType(std::string_view path) -> mimeType;

      private:
        // Collect startup files when service starts
        auto collectStartupFiles() -> void;
        // Setup timers for notification
        auto setupTimers(std::shared_ptr<sys::Service> svc, std::string_view svc_name) -> void;

      private:
        std::list<std::shared_ptr<msg::FileChangeMessage>> mMsgs;
        sys::TimerHandle mIdxTimer;
    };
} // namespace service::detail