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
78bf4ef5
Commit
78bf4ef5
authored
Oct 28, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/Configured: migrate from class Error to C++ exceptions
parent
318d0b39
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
35 deletions
+24
-35
Main.cxx
src/Main.cxx
+3
-8
Configured.cxx
src/db/Configured.cxx
+8
-13
Configured.hxx
src/db/Configured.hxx
+5
-5
DatabaseGlue.cxx
src/db/DatabaseGlue.cxx
+5
-7
DatabaseGlue.hxx
src/db/DatabaseGlue.hxx
+3
-2
No files found.
src/Main.cxx
View file @
78bf4ef5
...
...
@@ -183,14 +183,9 @@ glue_db_init_and_load(void)
{
Error
error
;
instance
->
database
=
CreateConfiguredDatabase
(
instance
->
event_loop
,
*
instance
,
error
);
if
(
instance
->
database
==
nullptr
)
{
if
(
error
.
IsDefined
())
FatalError
(
error
);
else
return
true
;
}
CreateConfiguredDatabase
(
instance
->
event_loop
,
*
instance
);
if
(
instance
->
database
==
nullptr
)
return
true
;
if
(
instance
->
database
->
GetPlugin
().
flags
&
DatabasePlugin
::
FLAG_REQUIRE_STORAGE
)
{
InitStorage
();
...
...
src/db/Configured.cxx
View file @
78bf4ef5
...
...
@@ -23,31 +23,26 @@
#include "config/ConfigGlobal.hxx"
#include "config/Param.hxx"
#include "config/Block.hxx"
#include "config/ConfigError.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/StandardDirectory.hxx"
#include "util/Error.hxx"
#include "util/
Runtime
Error.hxx"
Database
*
CreateConfiguredDatabase
(
EventLoop
&
loop
,
DatabaseListener
&
listener
,
Error
&
error
)
CreateConfiguredDatabase
(
EventLoop
&
loop
,
DatabaseListener
&
listener
)
{
const
auto
*
param
=
config_get_block
(
ConfigBlockOption
::
DATABASE
);
const
auto
*
path
=
config_get_param
(
ConfigOption
::
DB_FILE
);
if
(
param
!=
nullptr
&&
path
!=
nullptr
)
{
error
.
Format
(
config_domain
,
"Found both 'database' (line %d) and 'db_file' (line %d) setting"
,
param
->
line
,
path
->
line
);
return
nullptr
;
}
if
(
param
!=
nullptr
&&
path
!=
nullptr
)
throw
FormatRuntimeError
(
"Found both 'database' (line %d) and 'db_file' (line %d) setting"
,
param
->
line
,
path
->
line
);
if
(
param
!=
nullptr
)
return
DatabaseGlobalInit
(
loop
,
listener
,
*
param
,
error
);
return
DatabaseGlobalInit
(
loop
,
listener
,
*
param
);
else
if
(
path
!=
nullptr
)
{
ConfigBlock
block
(
path
->
line
);
block
.
AddBlockParam
(
"path"
,
path
->
value
.
c_str
(),
path
->
line
);
return
DatabaseGlobalInit
(
loop
,
listener
,
block
,
error
);
return
DatabaseGlobalInit
(
loop
,
listener
,
block
);
}
else
{
/* if there is no override, use the cache directory */
...
...
@@ -63,6 +58,6 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
ConfigBlock
block
;
block
.
AddBlockParam
(
"path"
,
db_file_utf8
.
c_str
(),
-
1
);
return
DatabaseGlobalInit
(
loop
,
listener
,
block
,
error
);
return
DatabaseGlobalInit
(
loop
,
listener
,
block
);
}
}
src/db/Configured.hxx
View file @
78bf4ef5
...
...
@@ -25,15 +25,15 @@
class
EventLoop
;
class
DatabaseListener
;
class
Database
;
class
Error
;
/**
* Read database configuration settings and create a #Database
* instance from it, but do not open it. Returns nullptr on error or
* if no database is configured (no #Error set in that case).
* instance from it, but do not open it. Returns nullptr if no
* database is configured.
*
* Throws #std::runtime_error on error.
*/
Database
*
CreateConfiguredDatabase
(
EventLoop
&
loop
,
DatabaseListener
&
listener
,
Error
&
error
);
CreateConfiguredDatabase
(
EventLoop
&
loop
,
DatabaseListener
&
listener
);
#endif
src/db/DatabaseGlue.cxx
View file @
78bf4ef5
...
...
@@ -21,23 +21,21 @@
#include "DatabaseGlue.hxx"
#include "Registry.hxx"
#include "DatabaseError.hxx"
#include "util/Error.hxx"
#include "util/
Runtime
Error.hxx"
#include "config/Block.hxx"
#include "DatabasePlugin.hxx"
Database
*
DatabaseGlobalInit
(
EventLoop
&
loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
,
Error
&
error
)
const
ConfigBlock
&
block
)
{
const
char
*
plugin_name
=
block
.
GetBlockValue
(
"plugin"
,
"simple"
);
const
DatabasePlugin
*
plugin
=
GetDatabasePluginByName
(
plugin_name
);
if
(
plugin
==
nullptr
)
{
error
.
Format
(
db_domain
,
"No such database plugin: %s"
,
plugin_name
);
return
nullptr
;
}
if
(
plugin
==
nullptr
)
throw
FormatRuntimeError
(
"No such database plugin: %s"
,
plugin_name
);
return
plugin
->
create
(
loop
,
listener
,
block
);
}
src/db/DatabaseGlue.hxx
View file @
78bf4ef5
...
...
@@ -26,15 +26,16 @@ struct ConfigBlock;
class
EventLoop
;
class
DatabaseListener
;
class
Database
;
class
Error
;
/**
* Initialize the database library.
*
* Throws #std::runtime_error on error.
*
* @param block the database configuration block
*/
Database
*
DatabaseGlobalInit
(
EventLoop
&
loop
,
DatabaseListener
&
listener
,
const
ConfigBlock
&
block
,
Error
&
error
);
const
ConfigBlock
&
block
);
#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