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 #include "pw_system/transfer_handlers.h"
15
16 namespace pw::system {
17
CrashSnapshotBufferTransfer(uint32_t id,CrashSnapshotPersistentBuffer & buffer)18 CrashSnapshotBufferTransfer::CrashSnapshotBufferTransfer(
19 uint32_t id, CrashSnapshotPersistentBuffer& buffer)
20 : transfer::ReadOnlyHandler(id), buffer_(buffer), reader_({}) {
21 set_reader(reader_);
22 }
23
PrepareRead()24 Status CrashSnapshotBufferTransfer::PrepareRead() {
25 if (!buffer_.has_value()) {
26 return Status::Unavailable();
27 }
28
29 // As seeking is not yet supported, reinitialize the reader from the start
30 // of the snapshot buffer.
31 new (&reader_)
32 stream::MemoryReader(pw::ConstByteSpan{buffer_.data(), buffer_.size()});
33
34 return OkStatus();
35 }
36
TraceBufferTransfer(uint32_t id,TracePersistentBuffer & buffer)37 TraceBufferTransfer::TraceBufferTransfer(uint32_t id,
38 TracePersistentBuffer& buffer)
39 : transfer::ReadOnlyHandler(id), buffer_(buffer), reader_({}) {
40 set_reader(reader_);
41 }
42
PrepareRead()43 Status TraceBufferTransfer::PrepareRead() {
44 if (!buffer_.has_value()) {
45 return Status::Unavailable();
46 }
47
48 // As seeking is not yet supported, reinitialize the reader from the start
49 // of the snapshot buffer.
50 new (&reader_)
51 stream::MemoryReader(pw::ConstByteSpan{buffer_.data(), buffer_.size()});
52
53 return OkStatus();
54 }
55
56 } // namespace pw::system
57