~aleteoryx/muditaos

ref: 76c924fd5ee9b3d99ba61d40bd5fa932e40715c0 muditaos/module-bluetooth/Bluetooth/interface/profiles/GAP/Devices.cpp -rw-r--r-- 1.6 KiB
76c924fd — Adam Dobrowolski [EGD-8002] Added SSP, fixed some minor issues, removed obsolete code 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Devices.hpp"
#include <btstack_util.h>

namespace bluetooth::gap
{
    auto Devices::getList() -> std::vector<Devicei>
    {
        return {devices.begin(), devices.end()};
    }

    Devices::iter Devices::find(bd_addr_t &addr)
    {
        return std::find_if(std::begin(devices), std::end(devices), [addr](const Devicei &device) {
            return bd_addr_cmp(addr, device.address) == 0;
        });
    }

    Devices::iter Devices::find(DEVICE_STATE st)
    {
        return std::find_if(
            std::begin(devices), std::end(devices), [st](const Devicei &device) { return st == device.state; });
    }

    void Devices::for_each(const std::function<void(Devicei &)> &f)
    {
        if (not f) {
            return;
        }
        for (auto &el : devices) {
            f(el);
        }
    }

    Devices::iter Devices::end()
    {
        return std::end(devices);
    }

    Devices::iter Devices::put(Devicei &&dev)
    {
        if (const auto &it = find(dev.address); it != end()) {
            devices.erase(it);
        }
        devices.emplace_back(dev);
        return std::prev(devices.end());
    }

    Devices::iter Devices::put(bd_addr_t &addr)
    {
        if (const auto &it = find(addr); it != end()) {
            devices.erase(it);
        }
        devices.emplace_back(Devicei(addr));
        return std::prev(devices.end());
    }

    void Devices::clear()
    {
        devices.clear();
    }
} // namespace bluetooth::gap