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 "WriteFileHandler.h"
20
21namespace vrs {
22
28 public:
29 virtual ~NewChunkHandler() = default;
39 virtual void newChunk(const string& path, size_t index, bool isLastChunk) = 0;
40};
41
48 public:
49 NewChunkNotifier(WriteFileHandler& file, const std::unique_ptr<NewChunkHandler>& chunkHandler)
50 : chunkHandler_{chunkHandler.get()} {
51 if (chunkHandler_ != nullptr) {
52 file.getCurrentChunk(path_, index_);
53 }
54 }
55 void notify(size_t indexOffset = 0, bool isLastChunk = false) {
56 if (chunkHandler_ != nullptr) {
57 chunkHandler_->newChunk(path_, index_ + indexOffset, isLastChunk);
58 }
59 }
60
61 private:
62 NewChunkHandler* chunkHandler_;
63 string path_;
64 size_t index_{};
65};
66
67} // namespace vrs
Listener to be notified when a new file chunk is finalized.
Definition NewChunkHandler.h:27
virtual void newChunk(const string &path, size_t index, bool isLastChunk)=0
Helper to make new chunks notifications simpler and safer.
Definition NewChunkHandler.h:47
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:45
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 AsyncDiskFileChunk.hpp:49