VRS
A file format for sensor data.
Loading...
Searching...
No Matches
NewChunkHandler.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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
17#pragma once
18
19#include <vrs/VrsExport.h>
20#include <vrs/WriteFileHandler.h>
21
22namespace vrs {
23
28class VRS_API NewChunkHandler {
29 public:
30 virtual ~NewChunkHandler() = default;
40 virtual void newChunk(const string& path, size_t index, bool isLastChunk) = 0;
41};
42
48class VRS_API NewChunkNotifier {
49 public:
50 NewChunkNotifier(WriteFileHandler& file, const std::unique_ptr<NewChunkHandler>& chunkHandler)
51 : chunkHandler_{chunkHandler.get()} {
52 if (chunkHandler_ != nullptr) {
53 file.getCurrentChunk(path_, index_);
54 }
55 }
56 void notify(size_t indexOffset = 0, bool isLastChunk = false) {
57 if (chunkHandler_ != nullptr) {
58 chunkHandler_->newChunk(path_, index_ + indexOffset, isLastChunk);
59 }
60 }
61
62 private:
63 NewChunkHandler* chunkHandler_;
64 string path_;
65 size_t index_{};
66};
67
68} // namespace vrs
Listener to be notified when a new file chunk is finalized.
Definition NewChunkHandler.h:28
virtual void newChunk(const string &path, size_t index, bool isLastChunk)=0
Helper to make new chunks notifications simpler and safer.
Definition NewChunkHandler.h:48
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:43
virtual bool getCurrentChunk(string &outChunkPath, size_t &outChunkIndex) const =0
Get the path of the current chunk, or an empty string if no chunk is open.
Definition Compressor.cpp:113