VRS
A file format for sensor data.
Loading...
Searching...
No Matches
RecordManager.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 <list>
20#include <memory>
21#include <mutex>
22
23#include <vrs/ForwardDefinitions.h>
24#include <vrs/Record.h>
25#include <vrs/VrsExport.h>
26
27namespace vrs {
28
29using std::list;
30
31class DataLayout;
32
39class VRS_API RecordManager {
40 friend class Record;
41
42 public:
44 RecordManager(const RecordManager&) = delete;
45 RecordManager(RecordManager&&) = delete;
47
48 void operator=(const RecordManager&) = delete;
49 void operator=(RecordManager&&) = delete;
50
59 Record*
60 createRecord(double timestamp, Record::Type type, uint32_t formatVersion, const DataSource& data);
61
72 Record* createUncompressedRecord(
73 double timestamp,
74 Record::Type type,
75 uint32_t formatVersion,
76 const DataSource& data,
77 std::unique_ptr<DirectWriteRecordData>&& directWriteData);
78
83 uint32_t purgeOldRecords(double oldestTimestamp, bool recycleBuffers = true);
84
86 void purgeCache();
87
92 void collectOldRecords(double maxAge, list<Record*>& outCollectedRecords);
93
97 return compression_;
98 }
99
104 compression_ = compression;
105 }
106
110 void setMaxCacheSize(size_t max) {
111 maxCacheSize_ = max;
112 }
113
117 size_t getCurrentCacheSize() const {
118 return cache_.size();
119 }
120
121 private:
122 static size_t getAcceptableOverCapacity(size_t capacity);
123 void recycle(Record* record);
124
125 std::mutex mutex_;
126 list<Record*> activeRecords_; // Records ready to be written
127 list<Record*> cache_; // Written/recycled records available for reuse
128
129 CompressionPreset compression_;
130 size_t maxCacheSize_;
131 uint64_t creationOrder_;
132};
133
134} // namespace vrs
A class referencing data to be captured in a record at creation.
Definition DataSource.h:153
Essential VRS class holding a record's details and payload in memory during creation.
Definition Record.h:82
Type
Definition Record.h:91
VRS internal class to manage the records of a specific Recordable after their creation.
Definition RecordManager.h:39
CompressionPreset getCompression() const
Definition RecordManager.h:96
void setCompression(CompressionPreset compression)
Definition RecordManager.h:103
size_t getCurrentCacheSize() const
Definition RecordManager.h:117
void setMaxCacheSize(size_t max)
Definition RecordManager.h:110
Definition Compressor.cpp:113
CompressionPreset
VRS Compression setting.
Definition Compressor.h:39