~aleteoryx/muditaos

muditaos/module-sys/SystemManager/DeviceManager.cpp -rw-r--r-- 1.4 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
// 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 <SystemManager/DeviceManager.hpp>
#include <algorithm>
#include <log/log.hpp>

namespace sys
{

    void DeviceManager::RegisterNewDevice(std::shared_ptr<devices::Device> newDevice)
    {
        if (newDevice) {
            devices.push_back(newDevice);
        }
    }

    void DeviceManager::PrintAllDevices() const noexcept
    {
        std::for_each(std::begin(devices), std::end(devices), PrintName);
    }

    void DeviceManager::DisableAllDevices() const noexcept
    {
        std::for_each(std::begin(devices), std::end(devices), DisableDevice);
    }

    void DeviceManager::PrintName(const DevicePointer &element)
    {
        if (!element.expired()) {
            std::shared_ptr<devices::Device> sharedResource = element.lock();
            LOG_INFO("Device %s", sharedResource->GetName().c_str());
        }
    }

    void DeviceManager::DisableDevice(const DevicePointer &element)
    {
        if (!element.expired()) {
            std::shared_ptr<devices::Device> sharedResource = element.lock();
            if (sharedResource->IsEnabled()) {
                sharedResource->Disable();
                LOG_DEBUG("Device %s has been disabled", sharedResource->GetName().c_str());
            }
        }
    }

} // namespace sys