Pigweed
 
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
31class AtomicFileTransferHandler : public ReadWriteHandler {
32 public:
36 AtomicFileTransferHandler(uint32_t resource_id, std::string_view file_path)
37 : ReadWriteHandler(resource_id), path_(file_path) {}
38
41 delete;
42 ~AtomicFileTransferHandler() override = default;
43
56 Status PrepareRead() override;
64 void FinalizeRead(Status) override;
77 Status PrepareWrite() override;
90
91 private:
92 std::string path_;
93 std::variant<std::monostate, stream::StdFileReader, stream::StdFileWriter>
94 stream_{};
95};
96
97} // namespace pw::transfer
Definition: status.h:85
Definition: atomic_file_transfer_handler.h:31
Status FinalizeWrite(Status) override
AtomicFileTransferHandler(uint32_t resource_id, std::string_view file_path)
Definition: atomic_file_transfer_handler.h:36