Pigweed
 
Loading...
Searching...
No Matches
server2.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <cstdint>
17
18#include "pw_async2/dispatcher.h"
19#include "pw_async2/once_sender.h"
20#include "pw_bluetooth/gatt/error.h"
21#include "pw_bluetooth/gatt/types.h"
22#include "pw_bluetooth/internal/raii_ptr.h"
23#include "pw_bluetooth/types.h"
24#include "pw_multibuf/multibuf.h"
25#include "pw_result/expected.h"
26#include "pw_span/span.h"
27
28namespace pw::bluetooth::gatt {
29
33 public:
34 virtual ~LocalServiceDelegate2() = default;
35
41 virtual void OnError(Error error) = 0;
42
63 virtual void CharacteristicConfiguration(PeerId peer_id,
64 Handle handle,
65 bool notify,
66 bool indicate) = 0;
67
78 ReadValue(PeerId peer_id, Handle handle, uint32_t offset) = 0;
79
93 PeerId peer_id,
94 Handle handle,
95 uint32_t offset,
96 multibuf::MultiBuf&& value) = 0;
97
105 virtual void MtuUpdate(PeerId peer_id, uint16_t mtu) = 0;
106};
107
112 public:
120 pw::span<const PeerId> peer_ids;
122 Handle handle;
125 };
126
130 using ValueChangedResult = pw::expected<void, Error>;
131
132 virtual ~LocalService2() = default;
133
158 ValueChangedParameters&& parameters) = 0;
159
188 ValueChangedParameters&& parameters) = 0;
189
190 private:
194 virtual void UnpublishService() = 0;
195
196 public:
199 using Ptr =
200 internal::RaiiPtr<LocalService2, &LocalService2::UnpublishService>;
201};
202
204class Server2 {
205 public:
207 kInternalError = 0,
208
210 kInvalidHandle = 1,
211
213 kInvalidUuid = 2,
214
217
220 };
221
225 ServiceHandle handle;
226
229
232 Uuid type;
233
235 span<const Characteristic2> characteristics;
236
239 span<const ServiceHandle> includes;
240 };
241
244 pw::expected<LocalService2::Ptr, PublishServiceError>;
245
246 virtual ~Server2() = default;
247
260 const LocalServiceInfo& info, LocalServiceDelegate2& delegate) = 0;
261};
262
263} // namespace pw::bluetooth::gatt
Definition: once_sender.h:41
Definition: server2.h:111
virtual async2::OnceReceiver< ValueChangedResult > NotifyValue(ValueChangedParameters &&parameters)=0
pw::expected< void, Error > ValueChangedResult
Definition: server2.h:130
internal::RaiiPtr< LocalService2, &LocalService2::UnpublishService > Ptr
Definition: server2.h:200
virtual async2::OnceReceiver< ValueChangedResult > IndicateValue(ValueChangedParameters &&parameters)=0
virtual async2::OnceReceiver< pw::expected< void, Error > > WriteValue(PeerId peer_id, Handle handle, uint32_t offset, multibuf::MultiBuf &&value)=0
virtual async2::OnceReceiver< pw::expected< multibuf::MultiBuf, Error > > ReadValue(PeerId peer_id, Handle handle, uint32_t offset)=0
virtual void MtuUpdate(PeerId peer_id, uint16_t mtu)=0
virtual void CharacteristicConfiguration(PeerId peer_id, Handle handle, bool notify, bool indicate)=0
virtual void OnError(Error error)=0
Interface for a GATT server that serves many GATT services.
Definition: server2.h:204
PublishServiceError
Definition: server2.h:206
@ kInvalidIncludes
Invalid service includes provided.
@ kInvalidCharacteristics
Invalid service characteristics provided.
@ kInvalidHandle
The service handle provided was not unique.
@ kInvalidUuid
Invalid service UUID provided.
pw::expected< LocalService2::Ptr, PublishServiceError > PublishServiceResult
The Result passed by PublishService.
Definition: server2.h:244
virtual async2::OnceReceiver< PublishServiceResult > PublishService(const LocalServiceInfo &info, LocalServiceDelegate2 &delegate)=0
Definition: multibuf.h:245
Handle handle
The handle of the characteristic value being signaled.
Definition: server2.h:122
multibuf::MultiBuf value
The new value for the descriptor/characteristic.
Definition: server2.h:124
pw::span< const PeerId > peer_ids
Definition: server2.h:120
Parameters for registering a local GATT service.
Definition: server2.h:223
bool primary
Indicates whether this is a primary or secondary service.
Definition: server2.h:228
ServiceHandle handle
A unique (within a Server) handle identifying this service.
Definition: server2.h:225
span< const Characteristic2 > characteristics
The characteristics of this service.
Definition: server2.h:235
span< const ServiceHandle > includes
Definition: server2.h:239