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
90 Record* createRecord(
91 double timestamp,
92 Record::Type type,
93 uint32_t formatVersion,
94 const DataSource& data,
95 std::unique_ptr<BorrowedData>&& borrowedData);
96
101 uint32_t purgeOldRecords(double oldestTimestamp, bool recycleBuffers = true);
102
104 void purgeCache();
105
110 void collectOldRecords(double maxAge, list<Record*>& outCollectedRecords);
111
115 return compression_;
116 }
117
122 compression_ = compression;
123 }
124
128 void setMaxCacheSize(size_t max) {
129 maxCacheSize_ = max;
130 }
131
135 size_t getCurrentCacheSize() const {
136 return cache_.size();
137 }
138
139 private:
140 Record* createRecord(
141 double timestamp,
142 Record::Type type,
143 uint32_t formatVersion,
144 const DataSource& data,
145 std::unique_ptr<DirectWriteRecordData> directWriteData,
146 std::unique_ptr<BorrowedData> borrowedData);
147 static size_t getAcceptableOverCapacity(size_t capacity);
148 void recycle(Record* record);
149
150 std::mutex mutex_;
151 list<Record*> activeRecords_; // Records ready to be written
152 list<Record*> cache_; // Written/recycled records available for reuse
153
154 CompressionPreset compression_;
155 size_t maxCacheSize_;
156 uint64_t creationOrder_;
157};
158
159} // namespace vrs
A class referencing data to be captured in a record at creation.
Definition DataSource.h:154
Essential VRS class holding a record's details and payload in memory during creation.
Definition Record.h:85
Type
Definition Record.h:94
VRS internal class to manage the records of a specific Recordable after their creation.
Definition RecordManager.h:39
CompressionPreset getCompression() const
Definition RecordManager.h:114
void setCompression(CompressionPreset compression)
Definition RecordManager.h:121
size_t getCurrentCacheSize() const
Definition RecordManager.h:135
void setMaxCacheSize(size_t max)
Definition RecordManager.h:128
Definition Compressor.cpp:130
CompressionPreset
VRS Compression setting.
Definition Compressor.h:39