Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
e998a5f2
Commit
e998a5f2
authored
Apr 14, 2015
by
Hugo Beauzée-Luyssen
Browse files
Add a FileSystem classes factory, to ease up FS mocking
parent
4832f1e1
Changes
8
Hide whitespace changes
Inline
Side-by-side
include/IMediaLibrary.h
View file @
e998a5f2
...
...
@@ -5,6 +5,7 @@
#include
<string>
#include
"Types.h"
#include
"factory/IFileSystem.h"
class
IParserCb
{
...
...
@@ -31,7 +32,14 @@ class IMediaLibrary
{
public:
virtual
~
IMediaLibrary
()
{}
virtual
bool
initialize
(
const
std
::
string
&
dbPath
)
=
0
;
///
/// \brief initialize Initializes the media library.
/// \param dbPath Path to the database
/// \param fsFactory An instance to a filesystem factory.
/// In case this is a nullptr, a default factory will be used
/// \return true in case of success, false otherwise
///
virtual
bool
initialize
(
const
std
::
string
&
dbPath
,
std
::
unique_ptr
<
factory
::
IFileSystem
>
fsFactory
=
nullptr
)
=
0
;
/// Adds a stand alone file
virtual
FilePtr
addFile
(
const
std
::
string
&
path
)
=
0
;
virtual
FilePtr
file
(
const
std
::
string
&
path
)
=
0
;
...
...
include/factory/IFileSystem.h
0 → 100644
View file @
e998a5f2
#pragma once
#include
<memory>
namespace
fs
{
class
IDirectory
;
}
namespace
factory
{
class
IFileSystem
{
public:
virtual
~
IFileSystem
()
=
default
;
virtual
std
::
unique_ptr
<
fs
::
IDirectory
>
createDirectory
(
const
std
::
string
&
path
)
=
0
;
};
}
src/CMakeLists.txt
View file @
e998a5f2
...
...
@@ -23,6 +23,8 @@ list(APPEND HEADERS_LIST
${
CMAKE_SOURCE_DIR
}
/include/IVideoTrack.h
${
CMAKE_SOURCE_DIR
}
/include/IMovie.h
${
CMAKE_SOURCE_DIR
}
/include/factory/IFileSystem.h
Cache.h
SqliteTools.h
...
...
@@ -31,6 +33,8 @@ list(APPEND HEADERS_LIST
filesystem/
${
ARCH_FOLDER
}
/Directory.h
filesystem/
${
ARCH_FOLDER
}
/File.h
factory/FileSystem.h
)
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/include"
)
...
...
@@ -53,7 +57,7 @@ list(APPEND SRC_LIST ${HEADERS_LIST}
metadata_services/VLCMetadataService.cpp
file
s
ystem
/Factory
.cpp
f
actory/F
ile
S
ystem.cpp
filesystem/
${
ARCH_FOLDER
}
/Directory.cpp
filesystem/
${
ARCH_FOLDER
}
/File.cpp
)
...
...
src/MediaLibrary.cpp
View file @
e998a5f2
...
...
@@ -19,6 +19,8 @@
#include
"filesystem/IDirectory.h"
#include
"filesystem/IFile.h"
#include
"factory/FileSystem.h"
MediaLibrary
::
MediaLibrary
()
:
m_parser
(
new
Parser
)
{
...
...
@@ -38,8 +40,13 @@ MediaLibrary::~MediaLibrary()
AudioTrack
::
clear
();
}
bool
MediaLibrary
::
initialize
(
const
std
::
string
&
dbPath
)
bool
MediaLibrary
::
initialize
(
const
std
::
string
&
dbPath
,
std
::
unique_ptr
<
factory
::
IFileSystem
>
fsFactory
)
{
if
(
fsFactory
!=
nullptr
)
m_fsFactory
=
std
::
move
(
fsFactory
);
else
m_fsFactory
.
reset
(
new
factory
::
FileSystemDefaultFactory
);
sqlite3
*
dbConnection
;
int
res
=
sqlite3_open
(
dbPath
.
c_str
(),
&
dbConnection
);
if
(
res
!=
SQLITE_OK
)
...
...
@@ -84,7 +91,7 @@ FolderPtr MediaLibrary::addFolder( const std::string& path )
try
{
dir
=
fs
::
createDirectory
(
path
);
dir
=
m_fsFactory
->
createDirectory
(
path
);
}
catch
(
std
::
runtime_error
&
)
{
...
...
src/MediaLibrary.h
View file @
e998a5f2
...
...
@@ -12,7 +12,7 @@ class MediaLibrary : public IMediaLibrary
public:
MediaLibrary
();
~
MediaLibrary
();
virtual
bool
initialize
(
const
std
::
string
&
dbPath
);
virtual
bool
initialize
(
const
std
::
string
&
dbPath
,
std
::
unique_ptr
<
factory
::
IFileSystem
>
fsFactory
);
virtual
std
::
vector
<
FilePtr
>
files
();
virtual
FilePtr
file
(
const
std
::
string
&
path
);
...
...
@@ -43,5 +43,6 @@ class MediaLibrary : public IMediaLibrary
private:
std
::
shared_ptr
<
sqlite3
>
m_dbConnection
;
std
::
unique_ptr
<
Parser
>
m_parser
;
std
::
unique_ptr
<
factory
::
IFileSystem
>
m_fsFactory
;
};
#endif // MEDIALIBRARY_H
src/file
s
ystem
/Factory
.cpp
→
src/f
actory/F
ile
S
ystem.cpp
View file @
e998a5f2
#include
"IDirectory.h"
#include
"factory/FileSystem.h"
#include
"filesystem/IDirectory.h"
#if defined(__linux__) || defined(__APPLE__)
# include "unix/Directory.h"
# include "
filesystem/
unix/Directory.h"
#else
# error No filesystem implementation for this architecture
#endif
std
::
unique_ptr
<
fs
::
IDirectory
>
fs
::
createDirectory
(
const
std
::
string
&
path
)
namespace
factory
{
std
::
unique_ptr
<
fs
::
IDirectory
>
FileSystemDefaultFactory
::
createDirectory
(
const
std
::
string
&
path
)
{
return
std
::
unique_ptr
<
fs
::
IDirectory
>
(
new
fs
::
Directory
(
path
)
);
}
}
src/factory/FileSystem.h
0 → 100644
View file @
e998a5f2
#pragma once
#include
"factory/IFileSystem.h"
namespace
factory
{
class
FileSystemDefaultFactory
:
public
IFileSystem
{
public:
virtual
std
::
unique_ptr
<
fs
::
IDirectory
>
createDirectory
(
const
std
::
string
&
path
)
override
;
};
}
src/filesystem/IDirectory.h
View file @
e998a5f2
...
...
@@ -15,6 +15,4 @@ namespace fs
virtual
const
std
::
string
&
path
()
const
=
0
;
virtual
std
::
vector
<
std
::
unique_ptr
<
IFile
>>
files
()
const
=
0
;
};
std
::
unique_ptr
<
IDirectory
>
createDirectory
(
const
std
::
string
&
path
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment