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
871063da
Commit
871063da
authored
Sep 05, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
neighbor/Plugin: migrate from class Error to C++ exceptions
parent
135662d6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
67 deletions
+40
-67
Main.cxx
src/Main.cxx
+3
-7
Explorer.hxx
src/neighbor/Explorer.hxx
+3
-2
Glue.cxx
src/neighbor/Glue.cxx
+16
-30
Glue.hxx
src/neighbor/Glue.hxx
+5
-3
NeighborPlugin.hxx
src/neighbor/NeighborPlugin.hxx
+1
-3
SmbclientNeighborPlugin.cxx
src/neighbor/plugins/SmbclientNeighborPlugin.cxx
+4
-6
UpnpNeighborPlugin.cxx
src/neighbor/plugins/UpnpNeighborPlugin.cxx
+4
-7
run_neighbor_explorer.cxx
test/run_neighbor_explorer.cxx
+4
-9
No files found.
src/Main.cxx
View file @
871063da
...
...
@@ -461,10 +461,7 @@ int mpd_main(int argc, char *argv[])
#ifdef ENABLE_NEIGHBOR_PLUGINS
instance
->
neighbors
=
new
NeighborGlue
();
if
(
!
instance
->
neighbors
->
Init
(
io_thread_get
(),
*
instance
,
error
))
{
LogError
(
error
);
return
EXIT_FAILURE
;
}
instance
->
neighbors
->
Init
(
io_thread_get
(),
*
instance
);
if
(
instance
->
neighbors
->
IsEmpty
())
{
delete
instance
->
neighbors
;
...
...
@@ -563,9 +560,8 @@ try {
io_thread_start
();
#ifdef ENABLE_NEIGHBOR_PLUGINS
if
(
instance
->
neighbors
!=
nullptr
&&
!
instance
->
neighbors
->
Open
(
error
))
FatalError
(
error
);
if
(
instance
->
neighbors
!=
nullptr
)
instance
->
neighbors
->
Open
();
#endif
ZeroconfInit
(
instance
->
event_loop
);
...
...
src/neighbor/Explorer.hxx
View file @
871063da
...
...
@@ -22,7 +22,6 @@
#include <forward_list>
class
Error
;
class
NeighborListener
;
struct
NeighborInfo
;
...
...
@@ -54,8 +53,10 @@ public:
/**
* Start exploring the neighborhood.
*
* Throws std::runtime_error on error.
*/
virtual
bool
Open
(
Error
&
error
)
=
0
;
virtual
void
Open
(
)
=
0
;
/**
* Stop exploring.
...
...
src/neighbor/Glue.cxx
View file @
871063da
...
...
@@ -26,7 +26,6 @@
#include "config/ConfigGlobal.hxx"
#include "config/ConfigError.hxx"
#include "config/Block.hxx"
#include "util/Error.hxx"
#include "util/RuntimeError.hxx"
#include <stdexcept>
...
...
@@ -40,63 +39,50 @@ NeighborGlue::~NeighborGlue() {}
static
NeighborExplorer
*
CreateNeighborExplorer
(
EventLoop
&
loop
,
NeighborListener
&
listener
,
const
ConfigBlock
&
block
,
Error
&
error
)
const
ConfigBlock
&
block
)
{
const
char
*
plugin_name
=
block
.
GetBlockValue
(
"plugin"
);
if
(
plugin_name
==
nullptr
)
{
error
.
Set
(
config_domain
,
"Missing
\"
plugin
\"
configuration"
);
return
nullptr
;
}
if
(
plugin_name
==
nullptr
)
throw
std
::
runtime_error
(
"Missing
\"
plugin
\"
configuration"
);
const
NeighborPlugin
*
plugin
=
GetNeighborPluginByName
(
plugin_name
);
if
(
plugin
==
nullptr
)
{
error
.
Format
(
config_domain
,
"No such neighbor plugin: %s"
,
plugin_name
);
return
nullptr
;
}
if
(
plugin
==
nullptr
)
throw
FormatRuntimeError
(
"No such neighbor plugin: %s"
,
plugin_name
);
return
plugin
->
create
(
loop
,
listener
,
block
,
error
);
return
plugin
->
create
(
loop
,
listener
,
block
);
}
bool
NeighborGlue
::
Init
(
EventLoop
&
loop
,
NeighborListener
&
listener
,
Error
&
error
)
void
NeighborGlue
::
Init
(
EventLoop
&
loop
,
NeighborListener
&
listener
)
{
for
(
const
auto
*
block
=
config_get_block
(
ConfigBlockOption
::
NEIGHBORS
);
block
!=
nullptr
;
block
=
block
->
next
)
{
try
{
auto
*
explorer
=
CreateNeighborExplorer
(
loop
,
listener
,
*
block
,
error
);
if
(
explorer
==
nullptr
)
{
error
.
FormatPrefix
(
"Line %i: "
,
block
->
line
);
return
false
;
}
CreateNeighborExplorer
(
loop
,
listener
,
*
block
);
explorers
.
emplace_front
(
explorer
);
}
catch
(...)
{
std
::
throw_with_nested
(
FormatRuntimeError
(
"Line %i: "
,
block
->
line
));
}
}
return
true
;
}
bool
NeighborGlue
::
Open
(
Error
&
error
)
void
NeighborGlue
::
Open
()
{
for
(
auto
i
=
explorers
.
begin
(),
end
=
explorers
.
end
();
i
!=
end
;
++
i
)
{
if
(
!
i
->
explorer
->
Open
(
error
))
{
try
{
i
->
explorer
->
Open
();
}
catch
(...)
{
/* roll back */
for
(
auto
k
=
explorers
.
begin
();
k
!=
i
;
++
k
)
k
->
explorer
->
Close
();
return
false
;
throw
;
}
}
return
true
;
}
void
...
...
src/neighbor/Glue.hxx
View file @
871063da
...
...
@@ -27,7 +27,6 @@
#include <forward_list>
struct
config_param
;
class
Error
;
class
EventLoop
;
class
NeighborExplorer
;
class
NeighborListener
;
...
...
@@ -60,9 +59,12 @@ public:
return
explorers
.
empty
();
}
bool
Init
(
EventLoop
&
loop
,
NeighborListener
&
listener
,
Error
&
error
);
/**
* Throws std::runtime_error on error.
*/
void
Init
(
EventLoop
&
loop
,
NeighborListener
&
listener
);
bool
Open
(
Error
&
error
);
void
Open
(
);
void
Close
();
/**
...
...
src/neighbor/NeighborPlugin.hxx
View file @
871063da
...
...
@@ -21,7 +21,6 @@
#define MPD_NEIGHBOR_PLUGIN_HXX
struct
ConfigBlock
;
class
Error
;
class
EventLoop
;
class
NeighborListener
;
class
NeighborExplorer
;
...
...
@@ -33,8 +32,7 @@ struct NeighborPlugin {
* Allocates and configures a #NeighborExplorer instance.
*/
NeighborExplorer
*
(
*
create
)(
EventLoop
&
loop
,
NeighborListener
&
listener
,
const
ConfigBlock
&
block
,
Error
&
error
);
const
ConfigBlock
&
block
);
};
#endif
src/neighbor/plugins/SmbclientNeighborPlugin.cxx
View file @
871063da
...
...
@@ -72,7 +72,7 @@ public:
:
NeighborExplorer
(
_listener
)
{}
/* virtual methods from class NeighborExplorer */
v
irtual
bool
Open
(
Error
&
error
)
override
;
v
oid
Open
(
)
override
;
virtual
void
Close
()
override
;
virtual
List
GetList
()
const
override
;
...
...
@@ -82,12 +82,11 @@ private:
static
void
ThreadFunc
(
void
*
ctx
);
};
bool
SmbclientNeighborExplorer
::
Open
(
gcc_unused
Error
&
error
)
void
SmbclientNeighborExplorer
::
Open
()
{
quit
=
false
;
thread
.
Start
(
ThreadFunc
,
this
);
return
true
;
}
void
...
...
@@ -270,8 +269,7 @@ SmbclientNeighborExplorer::ThreadFunc(void *ctx)
static
NeighborExplorer
*
smbclient_neighbor_create
(
gcc_unused
EventLoop
&
loop
,
NeighborListener
&
listener
,
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
gcc_unused
const
ConfigBlock
&
block
)
{
SmbclientInit
();
...
...
src/neighbor/plugins/UpnpNeighborPlugin.cxx
View file @
871063da
...
...
@@ -60,7 +60,7 @@ public:
:
NeighborExplorer
(
_listener
)
{}
/* virtual methods from class NeighborExplorer */
v
irtual
bool
Open
(
Error
&
error
)
override
;
v
oid
Open
(
)
override
;
virtual
void
Close
()
override
;
virtual
List
GetList
()
const
override
;
...
...
@@ -70,8 +70,8 @@ private:
virtual
void
LostUPnP
(
const
ContentDirectoryService
&
service
)
override
;
};
bool
UpnpNeighborExplorer
::
Open
(
gcc_unused
Error
&
error
)
void
UpnpNeighborExplorer
::
Open
()
{
UpnpClient_Handle
handle
;
UpnpClientGlobalInit
(
handle
);
...
...
@@ -85,8 +85,6 @@ UpnpNeighborExplorer::Open(gcc_unused Error &error)
UpnpClientGlobalFinish
();
throw
;
}
return
true
;
}
void
...
...
@@ -130,8 +128,7 @@ UpnpNeighborExplorer::LostUPnP(const ContentDirectoryService &service)
static
NeighborExplorer
*
upnp_neighbor_create
(
gcc_unused
EventLoop
&
loop
,
NeighborListener
&
listener
,
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
UpnpNeighborExplorer
(
listener
);
}
...
...
test/run_neighbor_explorer.cxx
View file @
871063da
...
...
@@ -24,7 +24,6 @@
#include "neighbor/Glue.hxx"
#include "fs/Path.hxx"
#include "event/Loop.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <stdio.h>
...
...
@@ -56,8 +55,6 @@ try {
/* read configuration file (mpd.conf) */
Error
error
;
config_global_init
();
ReadConfigFile
(
config_path
);
...
...
@@ -69,17 +66,15 @@ try {
MyNeighborListener
listener
;
NeighborGlue
neighbor
;
if
(
!
neighbor
.
Init
(
loop
,
listener
,
error
)
||
!
neighbor
.
Open
(
error
))
{
LogError
(
error
);
return
EXIT_FAILURE
;
}
neighbor
.
Init
(
loop
,
listener
);
neighbor
.
Open
();
/* run */
loop
.
Run
();
neighbor
.
Close
();
return
EXIT_SUCCESS
;
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
return
EXIT_FAILURE
;
}
}
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