libGulliBLE
service.hpp
Go to the documentation of this file.
1//
2// Created by spak on 10/1/21.
3//
4
5#ifndef LIBGULLIBLE_SERVICE_HPP
6#define LIBGULLIBLE_SERVICE_HPP
7
9
10namespace ble {
11
12 enum struct service_type : std::uint8_t {
13 primary = BLE_GATT_SVC_TYPE_PRIMARY,
14 secondary = BLE_GATT_SVC_TYPE_SECONDARY
15 };
16
17 class service {
20 std::vector<std::shared_ptr<characteristic_base>> _chrs;
21
22 public:
23 class snapshot;
24
25 service(uuid u, service_type type, std::vector<std::shared_ptr<characteristic_base>> chrs = {});
26
27 static constexpr ble_gatt_svc_def void_definition = {
28 .type = 0,
29 .uuid = nullptr,
30 .includes = nullptr,
31 .characteristics = nullptr};
32
33 [[nodiscard]] inline std::vector<std::shared_ptr<characteristic_base>> const &characteristics() const;
34
35 [[nodiscard]] inline std::vector<std::shared_ptr<characteristic_base>> &characteristics();
36
37 [[nodiscard]] inline service_type type() const;
38
39 [[nodiscard]] inline uuid const &svc_uuid() const;
40
41 [[nodiscard]] snapshot take_snapshot() const;
42 };
43
46 std::vector<std::shared_ptr<characteristic_base>> _chrs;
47 std::unique_ptr<ble_uuid_any_t> _nimble_svc_uuid;
48 std::unique_ptr<ble_gatt_chr_def[]> _nimble_chr_defs;
49
50 public:
51 explicit snapshot(service const &svc);
52
53 [[nodiscard]] inline std::vector<std::shared_ptr<characteristic_base>> const &characteristics() const;
54
55 [[nodiscard]] inline service_type type() const;
56
57 [[nodiscard]] inline uuid get_svc_uuid() const;
58
59 [[nodiscard]] ble_gatt_svc_def get_definition() const;
60 };
61
62}// namespace ble
63
64namespace ble {
65
66 uuid const &service::svc_uuid() const {
67 return _uuid;
68 }
69
71 return _type;
72 }
73
75 return _type;
76 }
77
78 std::vector<std::shared_ptr<characteristic_base>> const &service::characteristics() const {
79 return _chrs;
80 }
81
82 std::vector<std::shared_ptr<characteristic_base>> const &service::snapshot::characteristics() const {
83 return _chrs;
84 }
85
86 std::vector<std::shared_ptr<characteristic_base>> &service::characteristics() {
87 return _chrs;
88 }
89
91 return uuid::from_nimble(*_nimble_svc_uuid);
92 }
93
94}// namespace ble
95#endif//LIBGULLIBLE_SERVICE_HPP
Definition: service.hpp:44
snapshot(service const &svc)
Definition: service.cpp:17
uuid get_svc_uuid() const
Definition: service.hpp:90
service_type _type
Definition: service.hpp:45
ble_gatt_svc_def get_definition() const
Definition: service.cpp:27
std::unique_ptr< ble_gatt_chr_def[]> _nimble_chr_defs
Definition: service.hpp:48
service_type type() const
Definition: service.hpp:74
std::vector< std::shared_ptr< characteristic_base > > const & characteristics() const
Definition: service.hpp:82
std::vector< std::shared_ptr< characteristic_base > > _chrs
Definition: service.hpp:46
std::unique_ptr< ble_uuid_any_t > _nimble_svc_uuid
Definition: service.hpp:47
Definition: service.hpp:17
service_type _type
Definition: service.hpp:19
uuid const & svc_uuid() const
Definition: service.hpp:66
std::vector< std::shared_ptr< characteristic_base > > _chrs
Definition: service.hpp:20
service(uuid u, service_type type, std::vector< std::shared_ptr< characteristic_base > > chrs={})
Definition: service.cpp:9
std::vector< std::shared_ptr< characteristic_base > > const & characteristics() const
Definition: service.hpp:78
service_type type() const
Definition: service.hpp:70
snapshot take_snapshot() const
Definition: service.cpp:13
uuid _uuid
Definition: service.hpp:18
static constexpr ble_gatt_svc_def void_definition
Definition: service.hpp:27
Definition: uuid.hpp:72
static uuid from_nimble(ble_uuid_t const &ble_uuid)
Definition: uuid.cpp:123
Definition: characteristic.hpp:14
service_type
Definition: service.hpp:12