~aleteoryx/muditaos

ref: 00ef5e69b87cf8cc44ff767d8f5fa8c0e2fb4b6e muditaos/module-services/service-fileindexer/StartupIndexer.hpp -rw-r--r-- 1.5 KiB
00ef5e69 — Marcin Smoczyński changelog: fix broken changelog for v0.49.1 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2017-2020, 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 <Service/Timer.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;
        std::unique_ptr<sys::Timer> mIdxTimer;
    };
} // namespace service::detail