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 "ForwardDefinitions.h"
24#include "Record.h"
25
26namespace vrs {
27
28using std::list;
29
30class DataLayout;
31
39 friend class Record;
40
41 public:
43 RecordManager(const RecordManager&) = delete;
44 RecordManager(RecordManager&&) = delete;
46
47 void operator=(const RecordManager&) = delete;
48 void operator=(RecordManager&&) = delete;
49
58 Record*
59 createRecord(double timestamp, Record::Type type, uint32_t formatVersion, const DataSource& data);
60
72 double timestamp,
73 Record::Type type,
74 uint32_t formatVersion,
75 const DataSource& data,
76 std::unique_ptr<DirectWriteRecordData>&& directWriteData);
77
82 uint32_t purgeOldRecords(double oldestTimestamp, bool recycleBuffers = true);
83
85 void purgeCache();
86
91 void collectOldRecords(double maxAge, list<Record*>& outCollectedRecords);
92
96 return compression_;
97 }
98
103 compression_ = compression;
104 }
105
109 void setMaxCacheSize(size_t max) {
110 maxCacheSize_ = max;
111 }
112
116 size_t getCurrentCacheSize() const {
117 return cache_.size();
118 }
119
120 private:
121 static size_t getAcceptableOverCapacity(size_t capacity);
122 void recycle(Record* record);
123
124 std::mutex mutex_;
125 list<Record*> activeRecords_; // Records ready to be written
126 list<Record*> cache_; // Written/recycled records available for reuse
127
128 CompressionPreset compression_;
129 size_t maxCacheSize_;
130 uint64_t creationOrder_;
131};
132
133} // 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:79
Type
Definition Record.h:88
VRS internal class to manage the records of a specific Recordable after their creation.
Definition RecordManager.h:38
CompressionPreset getCompression() const
Definition RecordManager.h:95
void setCompression(CompressionPreset compression)
Definition RecordManager.h:102
uint32_t purgeOldRecords(double oldestTimestamp, bool recycleBuffers=true)
Definition RecordManager.cpp:127
void collectOldRecords(double maxAge, list< Record * > &outCollectedRecords)
Definition RecordManager.cpp:181
Record * createUncompressedRecord(double timestamp, Record::Type type, uint32_t formatVersion, const DataSource &data, std::unique_ptr< DirectWriteRecordData > &&directWriteData)
Definition RecordManager.cpp:116
Record * createRecord(double timestamp, Record::Type type, uint32_t formatVersion, const DataSource &data)
Definition RecordManager.cpp:55
size_t getCurrentCacheSize() const
Definition RecordManager.h:116
void setMaxCacheSize(size_t max)
Definition RecordManager.h:109
void purgeCache()
Release as much memory as possible, by deleting all the records in the cache.
Definition RecordManager.cpp:173
Definition Compressor.cpp:113
CompressionPreset
VRS Compression setting.
Definition Compressor.h:38