VRS
A file format for sensor data.
Loading...
Searching...
No Matches
FileHandlerFactory.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 <map>
20#include <memory>
21#include <mutex>
22#include <string>
23
24#include "ForwardDefinitions.h"
25
26namespace vrs {
27
28using std::map;
29using std::mutex;
30using std::string;
31using std::unique_ptr;
32
36 public:
37 static FileHandlerFactory& getInstance();
38
40 void registerFileDelegator(const string& name, unique_ptr<FileDelegator>&& delegator);
41 void unregisterFileDelegator(const string& name);
42
46 const string& extraName,
47 const string& extraValue,
48 unique_ptr<FileDelegator>&& delegator);
49 void unregisterExtraDelegator(const string& extraName, const string& extraValue);
50 FileDelegator* getExtraDelegator(const FileSpec& fileSpec);
51 FileDelegator* getExtraDelegator(const string& extraName, const string& extraValue);
52
54 void registerFileHandler(unique_ptr<FileHandler>&& fileHandler);
55 void unregisterFileHandler(const string& fileHandlerName);
56 unique_ptr<FileHandler> getFileHandler(const string& name);
57 FileDelegator* getFileDelegator(const string& name);
58
80 virtual int delegateOpen(const string& path, unique_ptr<FileHandler>& outNewDelegate);
81 virtual int delegateOpen(const FileSpec& fileSpec, unique_ptr<FileHandler>& outNewDelegate);
82
86 virtual int parseUri(FileSpec& inOutFileSpec, size_t colonIndex);
87
88 protected:
90 virtual ~FileHandlerFactory() = default;
91
92 private:
93 mutex mutex_;
94 map<string, unique_ptr<FileDelegator>> fileDelegatorMap_;
95 map<string, unique_ptr<FileHandler>> fileHandlerMap_;
96 map<string, map<string, unique_ptr<FileDelegator>>> extraDelegatorMap_;
97};
98
99} // namespace vrs
Class to abstract the delegate file open operation for VRS file.
Definition FileDelegator.h:32
A factory system for FileHandlers, allowing the runtime registration & usage of custom FileHandler im...
Definition FileHandlerFactory.h:35
void registerExtraDelegator(const string &extraName, const string &extraValue, unique_ptr< FileDelegator > &&delegator)
Definition FileHandlerFactory.cpp:139
virtual int delegateOpen(const string &path, unique_ptr< FileHandler > &outNewDelegate)
Definition FileHandlerFactory.cpp:42
void registerFileDelegator(const string &name, unique_ptr< FileDelegator > &&delegator)
Delegators operating on FileSpec.fileHandlerName.
Definition FileHandlerFactory.cpp:127
void registerFileHandler(unique_ptr< FileHandler > &&fileHandler)
Delegators operating on FileSpec.fileHandlerName.
Definition FileHandlerFactory.cpp:105
virtual int parseUri(FileSpec &inOutFileSpec, size_t colonIndex)
Definition FileHandlerFactory.cpp:86
Definition AsyncDiskFileChunk.hpp:49
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:37