From b0d241b74dd8d56b32fd38b5373a91b23c6b0783 Mon Sep 17 00:00:00 2001 From: Georges Berenger Date: Wed, 18 Dec 2024 11:09:44 -0800 Subject: [PATCH] Isolate method to create a WriteFileHandler Summary: This diff isolates a few lines of code that can be useful to create a WriteFileHandler from a name using the FileHandlerFactory. This will be used down the stack. Reviewed By: hanghu Differential Revision: D67329236 fbshipit-source-id: 8b1b4b59ccc980d008fc72b09a79e0ba2e9a058f --- vrs/FileHandlerFactory.cpp | 6 ++++++ vrs/RecordFileWriter.cpp | 3 +-- vrs/WriteFileHandler.h | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/vrs/FileHandlerFactory.cpp b/vrs/FileHandlerFactory.cpp index 24406153..46d7c0e8 100644 --- a/vrs/FileHandlerFactory.cpp +++ b/vrs/FileHandlerFactory.cpp @@ -193,4 +193,10 @@ FileDelegator* FileHandlerFactory::getFileDelegator(const string& name) { return (delegator == fileDelegatorMap_.end()) ? nullptr : delegator->second.get(); } +unique_ptr WriteFileHandler::make(const string& fileHandlerName) { + unique_ptr file{dynamic_cast( + FileHandlerFactory::getInstance().getFileHandler(fileHandlerName).release())}; + return file; +} + } // namespace vrs diff --git a/vrs/RecordFileWriter.cpp b/vrs/RecordFileWriter.cpp index 1a6809a6..71eefe3e 100644 --- a/vrs/RecordFileWriter.cpp +++ b/vrs/RecordFileWriter.cpp @@ -808,8 +808,7 @@ int RecordFileWriter::createFile(const string& filePath, bool splitHead) { if (file_->getFileHandlerName() == DiskFile::staticName() && spec.fileHandlerName != DiskFile::staticName()) { - unique_ptr writeFile{dynamic_cast( - FileHandlerFactory::getInstance().getFileHandler(spec.fileHandlerName).release())}; + unique_ptr writeFile = WriteFileHandler::make(spec.fileHandlerName); if (!writeFile) { XR_LOGE("Found no WriteFileHandler named {}.", spec.fileHandlerName); return INVALID_FILE_SPEC; diff --git a/vrs/WriteFileHandler.h b/vrs/WriteFileHandler.h index 652f9d41..4ce01e57 100644 --- a/vrs/WriteFileHandler.h +++ b/vrs/WriteFileHandler.h @@ -44,6 +44,9 @@ class WriteFileHandler : public FileHandler { public: WriteFileHandler() = default; + /// Create a new WriteFileHandler from a name. + static unique_ptr make(const string& fileHandlerName); + /// Create a new file for writing, using a spec. /// The path of the file to create is expected to be in the first chunk. /// Optional URI parameters might be provided in the spec' extras.