Skip to content

Commit

Permalink
Isolate method to create a WriteFileHandler
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Dec 18, 2024
1 parent b490899 commit b0d241b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions vrs/FileHandlerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,10 @@ FileDelegator* FileHandlerFactory::getFileDelegator(const string& name) {
return (delegator == fileDelegatorMap_.end()) ? nullptr : delegator->second.get();
}

unique_ptr<WriteFileHandler> WriteFileHandler::make(const string& fileHandlerName) {
unique_ptr<WriteFileHandler> file{dynamic_cast<WriteFileHandler*>(
FileHandlerFactory::getInstance().getFileHandler(fileHandlerName).release())};
return file;
}

} // namespace vrs
3 changes: 1 addition & 2 deletions vrs/RecordFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,7 @@ int RecordFileWriter::createFile(const string& filePath, bool splitHead) {

if (file_->getFileHandlerName() == DiskFile::staticName() &&
spec.fileHandlerName != DiskFile::staticName()) {
unique_ptr<WriteFileHandler> writeFile{dynamic_cast<WriteFileHandler*>(
FileHandlerFactory::getInstance().getFileHandler(spec.fileHandlerName).release())};
unique_ptr<WriteFileHandler> writeFile = WriteFileHandler::make(spec.fileHandlerName);
if (!writeFile) {
XR_LOGE("Found no WriteFileHandler named {}.", spec.fileHandlerName);
return INVALID_FILE_SPEC;
Expand Down
3 changes: 3 additions & 0 deletions vrs/WriteFileHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class WriteFileHandler : public FileHandler {
public:
WriteFileHandler() = default;

/// Create a new WriteFileHandler from a name.
static unique_ptr<WriteFileHandler> 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.
Expand Down

0 comments on commit b0d241b

Please sign in to comment.