~aleteoryx/muditaos

muditaos/module-services/service-fileindexer/ServiceFileIndexer.cpp -rw-r--r-- 2.0 KiB
a405cad6Aleteoryx trim readme 6 days 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
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include <service-fileindexer/ServiceFileIndexer.hpp>
#include <service-fileindexer/ServiceFileIndexerName.hpp>

#include <log/log.hpp>
#include <purefs/filesystem_paths.hpp>

namespace
{
    constexpr auto fileIndexerServiceStackSize = 1024 * 5;
} // namespace

namespace service
{
    ServiceFileIndexer::ServiceFileIndexer(const std::vector<std::string> &paths)
        : sys::Service{service::name::file_indexer, "", fileIndexerServiceStackSize}, mStartupIndexer{paths}
    {
    }

    ServiceFileIndexer::~ServiceFileIndexer()
    {
    }

    sys::MessagePointer ServiceFileIndexer::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
    {
        return sys::msgNotHandled();
    }

    // Initialize data notification handler
    sys::ReturnCodes ServiceFileIndexer::InitHandler()
    {
        if (mInotifyHandler.init(shared_from_this())) {
            mInotifyHandler.addWatch(purefs::dir::getUserMediaPath().c_str());

            // Start the initial indexer
            mStartupIndexer.start(shared_from_this(), service::name::file_indexer);
            return sys::ReturnCodes::Success;
        }

        LOG_INFO("Initialized");
        return sys::ReturnCodes::Failure;
    }

    sys::ReturnCodes ServiceFileIndexer::DeinitHandler()
    {
        LOG_INFO("Deinitialized");
        return sys::ReturnCodes::Success;
    }

    sys::ReturnCodes ServiceFileIndexer::SwitchPowerModeHandler(const sys::ServicePowerMode mode)
    {
        LOG_DEBUG("Switch to power Mode %s", c_str(mode));
        return sys::ReturnCodes::Success;
    }

    void ServiceFileIndexer::ProcessCloseReason(sys::CloseReason closeReason)
    {
        if (closeReason == sys::CloseReason::FactoryReset) {
            mStartupIndexer.reset();
        }
        else {
            mStartupIndexer.stop();
        }
    }
} // namespace service