~aleteoryx/muditaos

ref: 395e99e16239630263d5892e2462f1333236ae99 muditaos/module-sys/SystemManager/DependencyGraph.hpp -rw-r--r-- 1.1 KiB
395e99e1 — Marek Niepieklo [CP-583] Update failure due to version.json on the phone 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
// 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/ServiceCreator.hpp"

#include <memory>
#include <vector>

namespace sys
{
    class BaseServiceCreator; // Forward declaration

    namespace graph
    {
        using Node  = std::reference_wrapper<BaseServiceCreator>;
        using Nodes = std::vector<Node>;

        Nodes nodesFrom(const std::vector<std::unique_ptr<BaseServiceCreator>> &services);
    } // namespace graph

    class DependencySortingStrategy
    {
      public:
        virtual ~DependencySortingStrategy() noexcept = default;

        [[nodiscard]] virtual auto sort(const graph::Nodes &nodes) -> graph::Nodes = 0;
    };

    class DependencyGraph
    {
      public:
        DependencyGraph(graph::Nodes nodes, std::unique_ptr<DependencySortingStrategy> &&strategy);

        [[nodiscard]] auto sort() const -> graph::Nodes;

      private:
        graph::Nodes nodes;
        std::unique_ptr<DependencySortingStrategy> strategy;
    };
} // namespace sys