Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
3c5e4e27
Commit
3c5e4e27
authored
Jan 02, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/Plugin: return std::unique_ptr<Storage>
parent
3f4f7b0a
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
46 additions
and
32 deletions
+46
-32
Main.cxx
src/Main.cxx
+2
-2
StorageCommands.cxx
src/command/StorageCommands.cxx
+2
-2
Configured.cxx
src/storage/Configured.cxx
+5
-4
Configured.hxx
src/storage/Configured.hxx
+3
-1
Registry.cxx
src/storage/Registry.cxx
+3
-2
Registry.hxx
src/storage/Registry.hxx
+4
-2
StoragePlugin.hxx
src/storage/StoragePlugin.hxx
+4
-1
StorageState.cxx
src/storage/StorageState.cxx
+3
-3
CurlStorage.cxx
src/storage/plugins/CurlStorage.cxx
+2
-2
LocalStorage.cxx
src/storage/plugins/LocalStorage.cxx
+2
-2
LocalStorage.hxx
src/storage/plugins/LocalStorage.hxx
+4
-2
NfsStorage.cxx
src/storage/plugins/NfsStorage.cxx
+3
-2
SmbclientStorage.cxx
src/storage/plugins/SmbclientStorage.cxx
+2
-2
run_storage.cxx
test/run_storage.cxx
+4
-4
test_translate_song.cxx
test/test_translate_song.cxx
+3
-1
No files found.
src/Main.cxx
View file @
3c5e4e27
...
...
@@ -175,13 +175,13 @@ glue_mapper_init()
static
void
InitStorage
(
EventLoop
&
event_loop
)
{
Storage
*
storage
=
CreateConfiguredStorage
(
event_loop
);
auto
storage
=
CreateConfiguredStorage
(
event_loop
);
if
(
storage
==
nullptr
)
return
;
CompositeStorage
*
composite
=
new
CompositeStorage
();
instance
->
storage
=
composite
;
composite
->
Mount
(
""
,
storage
);
composite
->
Mount
(
""
,
storage
.
release
()
);
}
/**
...
...
src/command/StorageCommands.cxx
View file @
3c5e4e27
...
...
@@ -199,13 +199,13 @@ handle_mount(Client &client, Request args, Response &r)
}
auto
&
event_loop
=
instance
.
io_thread
.
GetEventLoop
();
Storage
*
storage
=
CreateStorageURI
(
event_loop
,
remote_uri
);
auto
storage
=
CreateStorageURI
(
event_loop
,
remote_uri
);
if
(
storage
==
nullptr
)
{
r
.
Error
(
ACK_ERROR_ARG
,
"Unrecognized storage URI"
);
return
CommandResult
::
ERROR
;
}
composite
.
Mount
(
local_uri
,
storage
);
composite
.
Mount
(
local_uri
,
storage
.
release
()
);
instance
.
EmitIdle
(
IDLE_MOUNT
);
#ifdef ENABLE_DATABASE
...
...
src/storage/Configured.cxx
View file @
3c5e4e27
...
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "Configured.hxx"
#include "Registry.hxx"
#include "StorageInterface.hxx"
#include "plugins/LocalStorage.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigError.hxx"
...
...
@@ -30,10 +31,10 @@
#include <assert.h>
static
Storage
*
static
std
::
unique_ptr
<
Storage
>
CreateConfiguredStorageUri
(
EventLoop
&
event_loop
,
const
char
*
uri
)
{
Storage
*
storage
=
CreateStorageURI
(
event_loop
,
uri
);
auto
storage
=
CreateStorageURI
(
event_loop
,
uri
);
if
(
storage
==
nullptr
)
throw
FormatRuntimeError
(
"Unrecognized storage URI: %s"
,
uri
);
...
...
@@ -50,7 +51,7 @@ GetConfiguredMusicDirectory()
return
path
;
}
static
Storage
*
static
std
::
unique_ptr
<
Storage
>
CreateConfiguredStorageLocal
()
{
AllocatedPath
path
=
GetConfiguredMusicDirectory
();
...
...
@@ -62,7 +63,7 @@ CreateConfiguredStorageLocal()
return
CreateLocalStorage
(
path
);
}
Storage
*
std
::
unique_ptr
<
Storage
>
CreateConfiguredStorage
(
EventLoop
&
event_loop
)
{
auto
uri
=
config_get_string
(
ConfigOption
::
MUSIC_DIR
);
...
...
src/storage/Configured.hxx
View file @
3c5e4e27
...
...
@@ -23,6 +23,8 @@
#include "check.h"
#include "Compiler.h"
#include <memory>
class
Storage
;
class
EventLoop
;
...
...
@@ -32,7 +34,7 @@ class EventLoop;
*
* Throws #std::runtime_error on error.
*/
Storage
*
std
::
unique_ptr
<
Storage
>
CreateConfiguredStorage
(
EventLoop
&
event_loop
);
/**
...
...
src/storage/Registry.cxx
View file @
3c5e4e27
...
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "Registry.hxx"
#include "StoragePlugin.hxx"
#include "StorageInterface.hxx"
#include "plugins/LocalStorage.hxx"
#include "plugins/SmbclientStorage.hxx"
#include "plugins/NfsStorage.hxx"
...
...
@@ -54,7 +55,7 @@ GetStoragePluginByName(const char *name) noexcept
return
nullptr
;
}
Storage
*
std
::
unique_ptr
<
Storage
>
CreateStorageURI
(
EventLoop
&
event_loop
,
const
char
*
uri
)
{
for
(
auto
i
=
storage_plugins
;
*
i
!=
nullptr
;
++
i
)
{
...
...
@@ -63,7 +64,7 @@ CreateStorageURI(EventLoop &event_loop, const char *uri)
if
(
plugin
.
create_uri
==
nullptr
)
continue
;
Storage
*
storage
=
plugin
.
create_uri
(
event_loop
,
uri
);
auto
storage
=
plugin
.
create_uri
(
event_loop
,
uri
);
if
(
storage
!=
nullptr
)
return
storage
;
}
...
...
src/storage/Registry.hxx
View file @
3c5e4e27
...
...
@@ -23,6 +23,8 @@
#include "check.h"
#include "Compiler.h"
#include <memory>
struct
StoragePlugin
;
class
Storage
;
class
EventLoop
;
...
...
@@ -37,8 +39,8 @@ gcc_nonnull_all gcc_pure
const
StoragePlugin
*
GetStoragePluginByName
(
const
char
*
name
)
noexcept
;
gcc_nonnull_all
gcc_malloc
Storage
*
gcc_nonnull_all
std
::
unique_ptr
<
Storage
>
CreateStorageURI
(
EventLoop
&
event_loop
,
const
char
*
uri
);
#endif
src/storage/StoragePlugin.hxx
View file @
3c5e4e27
...
...
@@ -22,6 +22,8 @@
#include "check.h"
#include <memory>
class
Storage
;
class
EventLoop
;
...
...
@@ -31,7 +33,8 @@ struct StoragePlugin {
/**
* Throws #std::runtime_error on error.
*/
Storage
*
(
*
create_uri
)(
EventLoop
&
event_loop
,
const
char
*
uri
);
std
::
unique_ptr
<
Storage
>
(
*
create_uri
)(
EventLoop
&
event_loop
,
const
char
*
uri
);
};
#endif
src/storage/StorageState.cxx
View file @
3c5e4e27
...
...
@@ -101,7 +101,7 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
FormatDebug
(
storage_domain
,
"Restoring mount %s => %s"
,
uri
.
c_str
(),
url
.
c_str
());
auto
&
event_loop
=
instance
.
io_thread
.
GetEventLoop
();
Storage
*
storage
=
CreateStorageURI
(
event_loop
,
url
.
c_str
());
auto
storage
=
CreateStorageURI
(
event_loop
,
url
.
c_str
());
if
(
storage
==
nullptr
)
{
FormatError
(
storage_domain
,
"Unrecognized storage URI: %s"
,
url
.
c_str
());
return
true
;
...
...
@@ -112,7 +112,6 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
try
{
((
SimpleDatabase
*
)
db
)
->
Mount
(
uri
.
c_str
(),
url
.
c_str
());
}
catch
(...)
{
delete
storage
;
FormatError
(
std
::
current_exception
(),
"Failed to restore mount to %s"
,
url
.
c_str
());
...
...
@@ -120,7 +119,8 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
}
}
((
CompositeStorage
*
)
instance
.
storage
)
->
Mount
(
uri
.
c_str
(),
storage
);
((
CompositeStorage
*
)
instance
.
storage
)
->
Mount
(
uri
.
c_str
(),
storage
.
release
());
return
true
;
}
...
...
src/storage/plugins/CurlStorage.cxx
View file @
3c5e4e27
...
...
@@ -549,14 +549,14 @@ CurlStorage::OpenDirectory(const char *uri_utf8)
return
HttpListDirectoryOperation
(
*
curl
,
uri
.
c_str
()).
Perform
();
}
static
Storage
*
static
std
::
unique_ptr
<
Storage
>
CreateCurlStorageURI
(
EventLoop
&
event_loop
,
const
char
*
uri
)
{
if
(
strncmp
(
uri
,
"http://"
,
7
)
!=
0
&&
strncmp
(
uri
,
"https://"
,
8
)
!=
0
)
return
nullptr
;
return
new
CurlStorage
(
event_loop
,
uri
);
return
std
::
make_unique
<
CurlStorage
>
(
event_loop
,
uri
);
}
const
StoragePlugin
curl_storage_plugin
=
{
...
...
src/storage/plugins/LocalStorage.cxx
View file @
3c5e4e27
...
...
@@ -179,10 +179,10 @@ LocalDirectoryReader::GetInfo(bool follow)
return
Stat
(
AllocatedPath
::
Build
(
base_fs
,
reader
.
GetEntry
()),
follow
);
}
Storage
*
std
::
unique_ptr
<
Storage
>
CreateLocalStorage
(
Path
base_fs
)
{
return
new
LocalStorage
(
base_fs
);
return
std
::
make_unique
<
LocalStorage
>
(
base_fs
);
}
const
StoragePlugin
local_storage_plugin
=
{
...
...
src/storage/plugins/LocalStorage.hxx
View file @
3c5e4e27
...
...
@@ -23,14 +23,16 @@
#include "check.h"
#include "Compiler.h"
#include <memory>
struct
StoragePlugin
;
class
Storage
;
class
Path
;
extern
const
StoragePlugin
local_storage_plugin
;
gcc_
malloc
gcc_
nonnull_all
Storage
*
gcc_nonnull_all
std
::
unique_ptr
<
Storage
>
CreateLocalStorage
(
Path
base_fs
);
#endif
src/storage/plugins/NfsStorage.cxx
View file @
3c5e4e27
...
...
@@ -390,7 +390,7 @@ NfsStorage::OpenDirectory(const char *uri_utf8)
return
operation
.
ToReader
();
}
static
Storage
*
static
std
::
unique_ptr
<
Storage
>
CreateNfsStorageURI
(
EventLoop
&
event_loop
,
const
char
*
base
)
{
if
(
strncmp
(
base
,
"nfs://"
,
6
)
!=
0
)
...
...
@@ -406,7 +406,8 @@ CreateNfsStorageURI(EventLoop &event_loop, const char *base)
nfs_set_base
(
server
.
c_str
(),
mount
);
return
new
NfsStorage
(
event_loop
,
base
,
server
.
c_str
(),
mount
);
return
std
::
make_unique
<
NfsStorage
>
(
event_loop
,
base
,
server
.
c_str
(),
mount
);
}
const
StoragePlugin
nfs_storage_plugin
=
{
...
...
src/storage/plugins/SmbclientStorage.cxx
View file @
3c5e4e27
...
...
@@ -179,7 +179,7 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow)
return
::
GetInfo
(
path
.
c_str
());
}
static
Storage
*
static
std
::
unique_ptr
<
Storage
>
CreateSmbclientStorageURI
(
gcc_unused
EventLoop
&
event_loop
,
const
char
*
base
)
{
if
(
strncmp
(
base
,
"smb://"
,
6
)
!=
0
)
...
...
@@ -198,7 +198,7 @@ CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base)
throw
MakeErrno
(
"smbc_new_context() failed"
);
}
return
new
SmbclientStorage
(
base
,
ctx2
);
return
std
::
make_unique
<
SmbclientStorage
>
(
base
,
ctx2
);
}
const
StoragePlugin
smbclient_storage_plugin
=
{
...
...
test/run_storage.cxx
View file @
3c5e4e27
...
...
@@ -34,10 +34,10 @@
#include <string.h>
#include <time.h>
static
Storage
*
static
std
::
unique_ptr
<
Storage
>
MakeStorage
(
EventLoop
&
event_loop
,
const
char
*
uri
)
{
Storage
*
storage
=
CreateStorageURI
(
event_loop
,
uri
);
auto
storage
=
CreateStorageURI
(
event_loop
,
uri
);
if
(
storage
==
nullptr
)
throw
std
::
runtime_error
(
"Unrecognized storage URI"
);
...
...
@@ -108,8 +108,8 @@ try {
const
char
*
const
path
=
argv
[
3
];
std
::
unique_ptr
<
Storage
>
storage
(
MakeStorage
(
io_thread
.
GetEventLoop
(),
storage_uri
)
);
auto
storage
=
MakeStorage
(
io_thread
.
GetEventLoop
(),
storage_uri
);
return
Ls
(
*
storage
,
path
);
}
else
{
...
...
test/test_translate_song.cxx
View file @
3c5e4e27
...
...
@@ -14,6 +14,7 @@
#include "ls.hxx"
#include "Log.hxx"
#include "db/DatabaseSong.hxx"
#include "storage/StorageInterface.hxx"
#include "storage/plugins/LocalStorage.hxx"
#include "Mapper.hxx"
#include "util/ChronoUtil.hxx"
...
...
@@ -309,7 +310,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(TranslateSongTest);
int
main
(
gcc_unused
int
argc
,
gcc_unused
char
**
argv
)
{
storage
=
CreateLocalStorage
(
Path
::
FromFS
(
music_directory
));
auto
_storage
=
CreateLocalStorage
(
Path
::
FromFS
(
music_directory
));
storage
=
_storage
.
get
();
CppUnit
::
TextUi
::
TestRunner
runner
;
auto
&
registry
=
CppUnit
::
TestFactoryRegistry
::
getRegistry
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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