Android-cuttlefish cvd tool
readable_source.h
Go to the documentation of this file.
1//
2// Copyright (C) 2025 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <stddef.h>
19#include <stdint.h>
20
21#include <memory>
22#include <mutex>
23
24#include "zip.h"
25
29#include "cuttlefish/io/io.h"
31
32namespace cuttlefish {
33
34int64_t HandleCallback(ReadableZipSourceCallback& callbacks, zip_error_t* error,
35 void* data, uint64_t len, zip_source_cmd_t cmd);
36
38 public:
39 friend class ReadableZip;
40 friend class WritableZip;
41 friend class ZipSourceReader;
43 friend class ZipSourceWriter;
44
46 std::unique_ptr<ReadableZipSourceCallback>);
47
48 // Can be safely called with a subclass type.
51 // Can be safely called with a subclass type.
53
55
56 /* Returns a RAII instance that puts this instance in an "open for reading"
57 * state. Can fail. Should not outlive this instance. */
59
60 protected:
62
64};
65
66/* A `ReadableZipSource` in an "open for reading" state. */
67class ZipSourceReader : public Reader {
68 public:
69 friend class ReadableZipSource;
71
73 virtual ~ZipSourceReader();
75
76 /* Returns a failed Result on error, or a successful result with bytes read or
77 * 0 on EOF. */
78 Result<uint64_t> Read(void* data, uint64_t length) override;
79
80 protected:
81 std::recursive_mutex mutex_;
82
83 private:
85
87};
88
89} // namespace cuttlefish
Definition: readable_source.h:37
Result< class ZipSourceReader > Reader()
Definition: readable_source.cc:174
ManagedZipSource raw_
Definition: readable_source.h:61
static Result< ReadableZipSource > FromCallbacks(std::unique_ptr< ReadableZipSourceCallback >)
Definition: readable_source.cc:124
ReadableZipSource(ReadableZipSource &&)
Result< ZipStat > Stat()
Definition: readable_source.cc:146
ReadableZipSource & operator=(ReadableZipSource &&)
Definition: archive.h:35
Definition: io.h:29
Definition: seekable_source.h:52
Definition: archive.h:70
Definition: readable_source.h:67
Result< uint64_t > Read(void *data, uint64_t length) override
Definition: readable_source.cc:204
ReadableZipSource * source_
Definition: readable_source.h:86
ZipSourceReader(ZipSourceReader &&)
Definition: readable_source.cc:187
std::recursive_mutex mutex_
Definition: readable_source.h:81
virtual ~ZipSourceReader()
Definition: readable_source.cc:198
ZipSourceReader & operator=(ZipSourceReader &&)
Definition: readable_source.cc:192
Definition: writable_source.h:54
#define data
Definition: dict.c:56
#define error(format, args...)
Definition: fec_private.h:201
Definition: alloc_driver.h:20
std::unique_ptr< zip_source_t, ZipDeleter > ManagedZipSource
Definition: managed.h:37
int64_t HandleCallback(ReadableZipSourceCallback &callbacks, zip_error_t *error, void *data, uint64_t len, zip_source_cmd_t cmd)
Definition: readable_source.cc:81
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30