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
a0088ccc
Commit
a0088ccc
authored
Feb 05, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: add struct StoragePlugin and a plugin registry
parent
be081929
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
177 additions
and
6 deletions
+177
-6
Makefile.am
Makefile.am
+2
-0
CommandLine.cxx
src/CommandLine.cxx
+8
-0
Registry.cxx
src/storage/Registry.cxx
+67
-0
Registry.hxx
src/storage/Registry.hxx
+44
-0
StoragePlugin.hxx
src/storage/StoragePlugin.hxx
+34
-0
LocalStorage.cxx
src/storage/plugins/LocalStorage.cxx
+6
-0
LocalStorage.hxx
src/storage/plugins/LocalStorage.hxx
+3
-0
SmbclientStorage.cxx
src/storage/plugins/SmbclientStorage.cxx
+11
-2
SmbclientStorage.hxx
src/storage/plugins/SmbclientStorage.hxx
+2
-4
No files found.
Makefile.am
View file @
a0088ccc
...
...
@@ -425,6 +425,8 @@ if ENABLE_DATABASE
noinst_LIBRARIES
+=
libstorage.a
libstorage_a_SOURCES
=
\
src/storage/StoragePlugin.hxx
\
src/storage/Registry.cxx src/storage/Registry.hxx
\
src/storage/StorageInterface.cxx src/storage/StorageInterface.hxx
\
src/storage/plugins/LocalStorage.cxx src/storage/plugins/LocalStorage.hxx
\
src/storage/FileInfo.hxx
...
...
src/CommandLine.cxx
View file @
a0088ccc
...
...
@@ -43,6 +43,8 @@
#ifdef ENABLE_DATABASE
#include "db/Registry.hxx"
#include "db/DatabasePlugin.hxx"
#include "storage/Registry.hxx"
#include "storage/StoragePlugin.hxx"
#endif
#ifdef ENABLE_NEIGHBOR_PLUGINS
...
...
@@ -113,6 +115,12 @@ static void version(void)
for
(
auto
i
=
database_plugins
;
*
i
!=
nullptr
;
++
i
)
printf
(
" %s"
,
(
*
i
)
->
name
);
puts
(
"
\n\n
"
"Storage plugins:"
);
for
(
auto
i
=
storage_plugins
;
*
i
!=
nullptr
;
++
i
)
printf
(
" %s"
,
(
*
i
)
->
name
);
#endif
#ifdef ENABLE_NEIGHBOR_PLUGINS
...
...
src/storage/Registry.cxx
0 → 100644
View file @
a0088ccc
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Registry.hxx"
#include "StoragePlugin.hxx"
#include "plugins/LocalStorage.hxx"
#include "plugins/SmbclientStorage.hxx"
#include "util/Error.hxx"
#include <assert.h>
#include <string.h>
const
StoragePlugin
*
const
storage_plugins
[]
=
{
&
local_storage_plugin
,
#ifdef ENABLE_SMBCLIENT
&
smbclient_storage_plugin
,
#endif
nullptr
};
const
StoragePlugin
*
GetStoragePluginByName
(
const
char
*
name
)
{
for
(
auto
i
=
storage_plugins
;
*
i
!=
nullptr
;
++
i
)
{
const
StoragePlugin
&
plugin
=
**
i
;
if
(
strcmp
(
plugin
.
name
,
name
)
==
0
)
return
*
i
;
}
return
nullptr
;
}
Storage
*
CreateStorageURI
(
const
char
*
uri
,
Error
&
error
)
{
assert
(
!
error
.
IsDefined
());
for
(
auto
i
=
storage_plugins
;
*
i
!=
nullptr
;
++
i
)
{
const
StoragePlugin
&
plugin
=
**
i
;
if
(
plugin
.
create_uri
==
nullptr
)
continue
;
Storage
*
storage
=
plugin
.
create_uri
(
uri
,
error
);
if
(
storage
!=
nullptr
||
error
.
IsDefined
())
return
storage
;
}
return
nullptr
;
}
src/storage/Registry.hxx
0 → 100644
View file @
a0088ccc
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_STORAGE_REGISTRY_HXX
#define MPD_STORAGE_REGISTRY_HXX
#include "check.h"
#include "Compiler.h"
struct
StoragePlugin
;
class
Storage
;
class
Error
;
/**
* nullptr terminated list of all storage plugins which were enabled at
* compile time.
*/
extern
const
StoragePlugin
*
const
storage_plugins
[];
gcc_nonnull_all
gcc_pure
const
StoragePlugin
*
GetStoragePluginByName
(
const
char
*
name
);
gcc_nonnull_all
gcc_malloc
Storage
*
CreateStorageURI
(
const
char
*
uri
,
Error
&
error
);
#endif
src/storage/StoragePlugin.hxx
0 → 100644
View file @
a0088ccc
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_STORAGE_PLUGIN_HXX
#define MPD_STORAGE_PLUGIN_HXX
#include "check.h"
class
Error
;
class
Storage
;
struct
StoragePlugin
{
const
char
*
name
;
Storage
*
(
*
create_uri
)(
const
char
*
uri
,
Error
&
error
);
};
#endif
src/storage/plugins/LocalStorage.cxx
View file @
a0088ccc
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "LocalStorage.hxx"
#include "storage/StoragePlugin.hxx"
#include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx"
#include "util/Error.hxx"
...
...
@@ -210,3 +211,8 @@ CreateLocalStorage(Path base_fs)
{
return
new
LocalStorage
(
base_fs
);
}
const
StoragePlugin
local_storage_plugin
=
{
"local"
,
nullptr
,
};
src/storage/plugins/LocalStorage.hxx
View file @
a0088ccc
...
...
@@ -23,9 +23,12 @@
#include "check.h"
#include "Compiler.h"
struct
StoragePlugin
;
class
Storage
;
class
Path
;
extern
const
StoragePlugin
local_storage_plugin
;
gcc_malloc
gcc_nonnull_all
Storage
*
CreateLocalStorage
(
Path
base_fs
);
...
...
src/storage/plugins/SmbclientStorage.cxx
View file @
a0088ccc
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "SmbclientStorage.hxx"
#include "storage/StoragePlugin.hxx"
#include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx"
#include "lib/smbclient/Init.hxx"
...
...
@@ -178,9 +179,12 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info,
return
::
GetInfo
(
path
.
c_str
(),
info
,
error
);
}
Storage
*
CreateSmbclientStorage
(
const
char
*
base
,
Error
&
error
)
static
Storage
*
CreateSmbclientStorage
URI
(
const
char
*
base
,
Error
&
error
)
{
if
(
memcmp
(
base
,
"smb://"
,
6
)
!=
0
)
return
nullptr
;
if
(
!
SmbclientInit
(
error
))
return
nullptr
;
...
...
@@ -200,3 +204,8 @@ CreateSmbclientStorage(const char *base, Error &error)
return
new
SmbclientStorage
(
base
,
ctx2
);
}
const
StoragePlugin
smbclient_storage_plugin
=
{
"smbclient"
,
CreateSmbclientStorageURI
,
};
src/storage/plugins/SmbclientStorage.hxx
View file @
a0088ccc
...
...
@@ -22,10 +22,8 @@
#include "check.h"
class
Error
;
class
Storage
;
struct
StoragePlugin
;
Storage
*
CreateSmbclientStorage
(
const
char
*
base
,
Error
&
error
);
extern
const
StoragePlugin
smbclient_storage_plugin
;
#endif
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