C/C++ API Reference
Loading...
Searching...
No Matches
atomic_file_transfer_handler.h
1// Copyright 2022 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 <filesystem>
17#include <string>
18#include <string_view>
19#include <variant>
20
21#include "pw_status/status.h"
22#include "pw_stream/std_file_stream.h"
23#include "pw_transfer/handler.h"
24
25namespace pw::transfer {
26
28
33class AtomicFileTransferHandler : public ReadWriteHandler {
34 public:
38 AtomicFileTransferHandler(uint32_t resource_id, std::string_view file_path)
39 : ReadWriteHandler(resource_id), path_(file_path) {}
40
43 delete;
44 ~AtomicFileTransferHandler() override = default;
45
58 Status PrepareRead() override;
66 void FinalizeRead(Status) override;
79 Status PrepareWrite() override;
92
93 private:
94 std::string path_;
95 std::variant<std::monostate, stream::StdFileReader, stream::StdFileWriter>
96 stream_{};
97};
98
99} // namespace pw::transfer
Definition: status.h:109
Definition: atomic_file_transfer_handler.h:33
Status FinalizeWrite(Status) override
AtomicFileTransferHandler(uint32_t resource_id, std::string_view file_path)
Definition: atomic_file_transfer_handler.h:38