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 <string>
20#include <vector>
21
22#include <vrs/VrsExport.h>
23#include <vrs/WriteFileHandler.h>
24#include <vrs/os/CompilerAttributes.h>
25
26namespace vrs {
27
32class VRS_API NewChunkHandler {
33 public:
34 virtual ~NewChunkHandler() = default;
44 virtual void newChunk(const string& path, size_t index, bool isLastChunk) = 0;
57 virtual void recordingFailed(
58 MAYBE_UNUSED int error,
59 MAYBE_UNUSED const std::vector<std::string>& unnotifiedChunks) {}
60};
61
67class VRS_API NewChunkNotifier {
68 public:
69 NewChunkNotifier(WriteFileHandler& file, const std::unique_ptr<NewChunkHandler>& chunkHandler)
70 : chunkHandler_{chunkHandler.get()} {
71 if (chunkHandler_ != nullptr) {
72 file.getCurrentChunk(path_, index_);
73 }
74 }
75 void notify(size_t indexOffset = 0, bool isLastChunk = false) {
76 if (chunkHandler_ != nullptr) {
77 chunkHandler_->newChunk(path_, index_ + indexOffset, isLastChunk);
78 }
79 }
80
81 private:
82 NewChunkHandler* chunkHandler_;
83 string path_;
84 size_t index_{};
85};
86
87} // namespace vrs
Listener to be notified when a new file chunk is finalized.
Definition NewChunkHandler.h:32
virtual void recordingFailed(MAYBE_UNUSED int error, MAYBE_UNUSED const std::vector< std::string > &unnotifiedChunks)
Definition NewChunkHandler.h:57
virtual void newChunk(const string &path, size_t index, bool isLastChunk)=0
Helper to make new chunks notifications simpler and safer.
Definition NewChunkHandler.h:67
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:128