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
6c28adbc
Commit
6c28adbc
authored
Feb 20, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/Plugin: use std::unique_ptr<> to manage Database pointers
parent
2125e3ed
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
93 additions
and
73 deletions
+93
-73
Main.cxx
src/Main.cxx
+1
-1
Configured.cxx
src/db/Configured.cxx
+3
-2
Configured.hxx
src/db/Configured.hxx
+4
-3
DatabaseGlue.cxx
src/db/DatabaseGlue.cxx
+3
-2
DatabaseGlue.hxx
src/db/DatabaseGlue.hxx
+3
-4
DatabasePlugin.hxx
src/db/DatabasePlugin.hxx
+7
-6
Ptr.hxx
src/db/Ptr.hxx
+29
-0
ProxyDatabasePlugin.cxx
src/db/plugins/ProxyDatabasePlugin.cxx
+6
-6
Directory.cxx
src/db/plugins/simple/Directory.cxx
+0
-2
Directory.hxx
src/db/plugins/simple/Directory.hxx
+2
-2
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+13
-21
SimpleDatabasePlugin.hxx
src/db/plugins/simple/SimpleDatabasePlugin.hxx
+9
-9
UpnpDatabasePlugin.cxx
src/db/plugins/upnp/UpnpDatabasePlugin.cxx
+7
-7
Service.cxx
src/db/update/Service.cxx
+2
-2
DumpDatabase.cxx
test/DumpDatabase.cxx
+4
-6
No files found.
src/Main.cxx
View file @
6c28adbc
...
...
@@ -188,7 +188,7 @@ glue_db_init_and_load(const ConfigData &config)
instance
->
database
=
CreateConfiguredDatabase
(
config
,
instance
->
event_loop
,
instance
->
io_thread
.
GetEventLoop
(),
*
instance
);
*
instance
)
.
release
()
;
if
(
instance
->
database
==
nullptr
)
return
true
;
...
...
src/db/Configured.cxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -19,6 +19,7 @@
#include "Configured.hxx"
#include "DatabaseGlue.hxx"
#include "Interface.hxx"
#include "config/Data.hxx"
#include "config/Param.hxx"
#include "config/Block.hxx"
...
...
@@ -26,7 +27,7 @@
#include "fs/StandardDirectory.hxx"
#include "util/RuntimeError.hxx"
Database
*
Database
Ptr
CreateConfiguredDatabase
(
const
ConfigData
&
config
,
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
)
...
...
src/db/Configured.hxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -20,10 +20,11 @@
#ifndef MPD_DB_CONFIG_HXX
#define MPD_DB_CONFIG_HXX
#include "Ptr.hxx"
struct
ConfigData
;
class
EventLoop
;
class
DatabaseListener
;
class
Database
;
/**
* Read database configuration settings and create a #Database
...
...
@@ -32,7 +33,7 @@ class Database;
*
* Throws #std::runtime_error on error.
*/
Database
*
Database
Ptr
CreateConfiguredDatabase
(
const
ConfigData
&
config
,
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
);
...
...
src/db/DatabaseGlue.cxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -18,13 +18,14 @@
*/
#include "DatabaseGlue.hxx"
#include "Interface.hxx"
#include "Registry.hxx"
#include "DatabaseError.hxx"
#include "util/RuntimeError.hxx"
#include "config/Block.hxx"
#include "DatabasePlugin.hxx"
Database
*
Database
Ptr
DatabaseGlobalInit
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
...
...
src/db/DatabaseGlue.hxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -20,12 +20,11 @@
#ifndef MPD_DATABASE_GLUE_HXX
#define MPD_DATABASE_GLUE_HXX
#include "
util/Compiler.h
"
#include "
Ptr.hxx
"
struct
ConfigBlock
;
class
EventLoop
;
class
DatabaseListener
;
class
Database
;
/**
* Initialize the database library.
...
...
@@ -34,7 +33,7 @@ class Database;
*
* @param block the database configuration block
*/
Database
*
Database
Ptr
DatabaseGlobalInit
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
...
...
src/db/DatabasePlugin.hxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -26,10 +26,11 @@
#ifndef MPD_DATABASE_PLUGIN_HXX
#define MPD_DATABASE_PLUGIN_HXX
#include "Ptr.hxx"
struct
ConfigBlock
;
class
EventLoop
;
class
DatabaseListener
;
class
Database
;
struct
DatabasePlugin
{
/**
...
...
@@ -52,10 +53,10 @@ struct DatabasePlugin {
* @param io_event_loop the #EventLoop running on the
* #EventThread, i.e. the one used for background I/O
*/
Database
*
(
*
create
)(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
);
Database
Ptr
(
*
create
)(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
);
constexpr
bool
RequireStorage
()
const
{
return
flags
&
FLAG_REQUIRE_STORAGE
;
...
...
src/db/Ptr.hxx
0 → 100644
View file @
6c28adbc
/*
* Copyright 2003-2019 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_DATABASE_PTR_HXX
#define MPD_DATABASE_PTR_HXX
#include <memory>
class
Database
;
typedef
std
::
unique_ptr
<
Database
>
DatabasePtr
;
#endif
src/db/plugins/ProxyDatabasePlugin.cxx
View file @
6c28adbc
...
...
@@ -112,10 +112,10 @@ public:
ProxyDatabase
(
EventLoop
&
_loop
,
DatabaseListener
&
_listener
,
const
ConfigBlock
&
block
);
static
Database
*
Create
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
);
static
Database
Ptr
Create
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
);
void
Open
()
override
;
void
Close
()
noexcept
override
;
...
...
@@ -440,12 +440,12 @@ ProxyDatabase::ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
{
}
Database
*
Database
Ptr
ProxyDatabase
::
Create
(
EventLoop
&
loop
,
EventLoop
&
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
)
{
return
new
ProxyDatabase
(
loop
,
listener
,
block
);
return
std
::
make_unique
<
ProxyDatabase
>
(
loop
,
listener
,
block
);
}
void
...
...
src/db/plugins/simple/Directory.cxx
View file @
6c28adbc
...
...
@@ -45,8 +45,6 @@ Directory::Directory(std::string &&_path_utf8, Directory *_parent) noexcept
Directory
::~
Directory
()
noexcept
{
delete
mounted_database
;
songs
.
clear_and_dispose
(
Song
::
Disposer
());
children
.
clear_and_dispose
(
DeleteDisposer
());
}
...
...
src/db/plugins/simple/Directory.hxx
View file @
6c28adbc
...
...
@@ -23,6 +23,7 @@
#include "util/Compiler.h"
#include "db/Visitor.hxx"
#include "db/PlaylistVector.hxx"
#include "db/Ptr.hxx"
#include "Song.hxx"
#include <boost/intrusive/list.hpp>
...
...
@@ -43,7 +44,6 @@ static constexpr unsigned DEVICE_INARCHIVE = -1;
static
constexpr
unsigned
DEVICE_CONTAINER
=
-
2
;
class
SongFilter
;
class
Database
;
struct
Directory
{
static
constexpr
auto
link_mode
=
boost
::
intrusive
::
normal_link
;
...
...
@@ -96,7 +96,7 @@ struct Directory {
* If this is not nullptr, then this directory does not really
* exist, but is a mount point for another #Database.
*/
Database
*
mounted_database
=
nullptr
;
Database
Ptr
mounted_database
;
public
:
Directory
(
std
::
string
&&
_path_utf8
,
Directory
*
_parent
)
noexcept
;
...
...
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -84,12 +84,12 @@ inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
prefixed_light_song
(
nullptr
)
{
}
Database
*
Database
Ptr
SimpleDatabase
::
Create
(
EventLoop
&
,
EventLoop
&
,
gcc_unused
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
)
{
return
new
SimpleDatabase
(
block
);
return
std
::
make_unique
<
SimpleDatabase
>
(
block
);
}
void
...
...
@@ -390,13 +390,13 @@ SimpleDatabase::Save()
}
void
SimpleDatabase
::
Mount
(
const
char
*
uri
,
Database
*
db
)
SimpleDatabase
::
Mount
(
const
char
*
uri
,
Database
Ptr
db
)
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
assert
(
uri
!=
nullptr
);
assert
(
db
!=
nullptr
);
#endif
assert
(
db
!=
nullptr
);
assert
(
*
uri
!=
0
);
ScopeDatabaseLock
protect
;
...
...
@@ -411,7 +411,7 @@ SimpleDatabase::Mount(const char *uri, Database *db)
"Parent not found"
);
Directory
*
mnt
=
r
.
directory
->
CreateChild
(
r
.
uri
);
mnt
->
mounted_database
=
db
;
mnt
->
mounted_database
=
std
::
move
(
db
)
;
}
static
constexpr
bool
...
...
@@ -441,27 +441,21 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri)
#ifndef ENABLE_ZLIB
constexpr
bool
compress
=
false
;
#endif
auto
db
=
new
SimpleDatabase
(
cache_path
/
name_fs
,
compress
);
try
{
db
->
Open
();
}
catch
(...)
{
delete
db
;
throw
;
}
auto
db
=
std
::
make_unique
<
SimpleDatabase
>
(
cache_path
/
name_fs
,
compress
);
db
->
Open
();
// TODO: update the new database instance?
try
{
Mount
(
local_uri
,
db
);
Mount
(
local_uri
,
std
::
move
(
db
)
);
}
catch
(...)
{
db
->
Close
();
delete
db
;
throw
;
}
}
inline
Database
*
inline
Database
Ptr
SimpleDatabase
::
LockUmountSteal
(
const
char
*
uri
)
noexcept
{
ScopeDatabaseLock
protect
;
...
...
@@ -470,8 +464,7 @@ SimpleDatabase::LockUmountSteal(const char *uri) noexcept
if
(
r
.
uri
!=
nullptr
||
!
r
.
directory
->
IsMount
())
return
nullptr
;
Database
*
db
=
r
.
directory
->
mounted_database
;
r
.
directory
->
mounted_database
=
nullptr
;
auto
db
=
std
::
move
(
r
.
directory
->
mounted_database
);
r
.
directory
->
Delete
();
return
db
;
...
...
@@ -480,12 +473,11 @@ SimpleDatabase::LockUmountSteal(const char *uri) noexcept
bool
SimpleDatabase
::
Unmount
(
const
char
*
uri
)
noexcept
{
Database
*
db
=
LockUmountSteal
(
uri
);
auto
db
=
LockUmountSteal
(
uri
);
if
(
db
==
nullptr
)
return
false
;
db
->
Close
();
delete
db
;
return
true
;
}
...
...
src/db/plugins/simple/SimpleDatabasePlugin.hxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -21,6 +21,7 @@
#define MPD_SIMPLE_DATABASE_PLUGIN_HXX
#include "db/Interface.hxx"
#include "db/Ptr.hxx"
#include "fs/AllocatedPath.hxx"
#include "song/LightSong.hxx"
#include "util/Manual.hxx"
...
...
@@ -68,15 +69,14 @@ class SimpleDatabase : public Database {
mutable
unsigned
borrowed_song_count
;
#endif
public
:
SimpleDatabase
(
const
ConfigBlock
&
block
);
SimpleDatabase
(
AllocatedPath
&&
_path
,
bool
_compress
)
noexcept
;
public
:
static
Database
*
Create
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
);
static
DatabasePtr
Create
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
);
gcc_pure
Directory
&
GetRoot
()
noexcept
{
...
...
@@ -99,7 +99,7 @@ public:
* success, this object gains ownership of the given #Database
*/
gcc_nonnull_all
void
Mount
(
const
char
*
uri
,
Database
*
db
);
void
Mount
(
const
char
*
uri
,
Database
Ptr
db
);
/**
* Throws #std::runtime_error on error.
...
...
@@ -142,7 +142,7 @@ private:
*/
void
Load
();
Database
*
LockUmountSteal
(
const
char
*
uri
)
noexcept
;
Database
Ptr
LockUmountSteal
(
const
char
*
uri
)
noexcept
;
};
extern
const
DatabasePlugin
simple_db_plugin
;
...
...
src/db/plugins/upnp/UpnpDatabasePlugin.cxx
View file @
6c28adbc
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -82,10 +82,10 @@ public:
:
Database
(
upnp_db_plugin
),
event_loop
(
_event_loop
)
{}
static
Database
*
Create
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
)
noexcept
;
static
Database
Ptr
Create
(
EventLoop
&
main_event_loop
,
EventLoop
&
io_event_loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
)
noexcept
;
void
Open
()
override
;
void
Close
()
noexcept
override
;
...
...
@@ -146,12 +146,12 @@ private:
const
UPnPDirObject
&
dirent
)
const
;
};
Database
*
Database
Ptr
UpnpDatabase
::
Create
(
EventLoop
&
,
EventLoop
&
io_event_loop
,
gcc_unused
DatabaseListener
&
listener
,
const
ConfigBlock
&
)
noexcept
{
return
new
UpnpDatabase
(
io_event_loop
);
return
std
::
make_unique
<
UpnpDatabase
>
(
io_event_loop
);
}
void
...
...
src/db/update/Service.cxx
View file @
6c28adbc
...
...
@@ -94,7 +94,7 @@ UpdateService::CancelMount(const char *uri)
cancel_current
=
next
.
IsDefined
()
&&
next
.
storage
==
storage2
;
}
if
(
auto
*
db2
=
dynamic_cast
<
SimpleDatabase
*>
(
lr
.
directory
->
mounted_database
))
{
if
(
auto
*
db2
=
dynamic_cast
<
SimpleDatabase
*>
(
lr
.
directory
->
mounted_database
.
get
()
))
{
queue
.
Erase
(
*
db2
);
cancel_current
|=
next
.
IsDefined
()
&&
next
.
db
==
db2
;
}
...
...
@@ -188,7 +188,7 @@ UpdateService::Enqueue(const char *path, bool discard)
/* follow the mountpoint, update the mounted
database */
db2
=
dynamic_cast
<
SimpleDatabase
*>
(
lr
.
directory
->
mounted_database
);
db2
=
dynamic_cast
<
SimpleDatabase
*>
(
lr
.
directory
->
mounted_database
.
get
()
);
if
(
db2
==
nullptr
)
throw
std
::
runtime_error
(
"Cannot update this type of database"
);
...
...
test/DumpDatabase.cxx
View file @
6c28adbc
...
...
@@ -133,15 +133,13 @@ try {
if
(
path
!=
nullptr
)
block
.
AddBlockParam
(
"path"
,
path
->
value
,
path
->
line
);
Database
*
db
=
plugin
->
create
(
init
.
GetEventLoop
(),
init
.
GetEventLoop
(),
database_listener
,
block
);
AtScopeExit
(
db
)
{
delete
db
;
};
auto
db
=
plugin
->
create
(
init
.
GetEventLoop
(),
init
.
GetEventLoop
(),
database_listener
,
block
);
db
->
Open
();
AtScopeExit
(
db
)
{
db
->
Close
();
};
AtScopeExit
(
&
db
)
{
db
->
Close
();
};
const
DatabaseSelection
selection
(
""
,
true
);
...
...
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