1 // Copyright 2023 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 
15 #pragma once
16 #include <queue>
17 
18 #include "pw_bluetooth_sapphire/internal/host/att/att.h"
19 #include "pw_bluetooth_sapphire/internal/host/common/byte_buffer.h"
20 #include "pw_bluetooth_sapphire/internal/host/common/macros.h"
21 
22 namespace bt::att {
23 
24 // Represents a singe write operation queued for atomic submission by an ATT
25 // protocol write method
26 class QueuedWrite {
27  public:
28   QueuedWrite() = default;
29   ~QueuedWrite() = default;
30 
31   // Constructs a write request by copying the contents of |value|.
32   QueuedWrite(Handle handle, uint16_t offset, const ByteBuffer& value);
33 
34   // Allow move operations.
35   QueuedWrite(QueuedWrite&&) = default;
36   QueuedWrite& operator=(QueuedWrite&&) = default;
37 
handle()38   Handle handle() const { return handle_; }
offset()39   uint16_t offset() const { return offset_; }
value()40   const ByteBuffer& value() const { return value_; }
41 
42  private:
43   Handle handle_;
44   uint16_t offset_;
45   DynamicByteBuffer value_;
46 };
47 
48 // Represents a prepare queue used to handle the ATT Prepare Write and Execute
49 // Write requests.
50 using PrepareWriteQueue = std::queue<QueuedWrite>;
51 
52 }  // namespace bt::att
53