~aleteoryx/muditaos

ref: 0e8b4c848e3f87f3bbb1f64ef7460cf56017b87f muditaos/module-sys/Service/include/Service/ServiceManifest.hpp -rw-r--r-- 1.6 KiB
0e8b4c84 — Lefucjusz [BH-2108] Fix misaligned charging symbol 3 months 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <chrono>
#include <string>
#include <vector>

namespace sys
{
    class Service; // Forward declaration

    struct ServiceManifest
    {
        using ServiceName                    = std::string;
        using Timeout                        = std::chrono::milliseconds;
        static constexpr auto DefaultTimeout = Timeout{5000};

        std::vector<ServiceName> dependencies;
        ServiceName name;
        Timeout timeout = DefaultTimeout;
    };

    /// Type traits pattern used to enforce user-defined types to implement "GetManifest" function.
    template <class T>
    struct ManifestTraits;

    template <class, class = void>
    struct HasManifest : std::false_type
    {};

    /// Checks whether T implements "GetManifest" static method.
    /// Provides the member constant "value" that is equal to true if T implements "GetManifest" static method.
    /// Otherwise, "value" is equal to false.
    template <class T>
    struct HasManifest<T, std::void_t<decltype(&ManifestTraits<T>::GetManifest)>>
        : std::is_same<ServiceManifest, decltype(ManifestTraits<T>::GetManifest())>
    {};

    /// Retrieves the manifest of T, if T implements ManifestTraits.
    /// Otherwise, reports an error during compile time.
    template <class T, std::enable_if_t<HasManifest<T>::value, int> = 0>
    auto ManifestOf() -> ServiceManifest
    {
        return ManifestTraits<T>::GetManifest();
    }
} // namespace sys