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
3ecf5fd4
Commit
3ecf5fd4
authored
Jan 26, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/run_input: add frontend for InputPlugin::scan_tags()
parent
3e9c3c8a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
run_input.cxx
test/run_input.cxx
+72
-0
No files found.
test/run_input.cxx
View file @
3ecf5fd4
...
...
@@ -23,6 +23,9 @@
#include "config/ConfigGlobal.hxx"
#include "input/InputStream.hxx"
#include "input/Init.hxx"
#include "input/Registry.hxx"
#include "input/InputPlugin.hxx"
#include "input/RemoteTagScanner.hxx"
#include "event/Thread.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
...
...
@@ -49,16 +52,20 @@ struct CommandLine {
Path
config_path
=
nullptr
;
bool
verbose
=
false
;
bool
scan
=
false
;
};
enum
Option
{
OPTION_CONFIG
,
OPTION_VERBOSE
,
OPTION_SCAN
,
};
static
constexpr
OptionDef
option_defs
[]
=
{
{
"config"
,
0
,
true
,
"Load a MPD configuration file"
},
{
"verbose"
,
'v'
,
false
,
"Verbose logging"
},
{
"scan"
,
0
,
false
,
"Scan tags instead of reading raw data"
},
};
static
CommandLine
...
...
@@ -76,6 +83,10 @@ ParseCommandLine(int argc, char **argv)
case
OPTION_VERBOSE
:
c
.
verbose
=
true
;
break
;
case
OPTION_SCAN
:
c
.
scan
=
true
;
break
;
}
}
...
...
@@ -160,6 +171,64 @@ dump_input_stream(InputStream *is)
return
0
;
}
class
DumpRemoteTagHandler
final
:
public
RemoteTagHandler
{
Mutex
mutex
;
Cond
cond
;
Tag
tag
;
std
::
exception_ptr
error
;
bool
done
=
false
;
public
:
Tag
Wait
()
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
while
(
!
done
)
cond
.
wait
(
mutex
);
if
(
error
)
std
::
rethrow_exception
(
error
);
return
std
::
move
(
tag
);
}
/* virtual methods from RemoteTagHandler */
void
OnRemoteTag
(
Tag
&&
_tag
)
noexcept
override
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
tag
=
std
::
move
(
_tag
);
done
=
true
;
cond
.
broadcast
();
}
void
OnRemoteTagError
(
std
::
exception_ptr
e
)
noexcept
override
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
error
=
std
::
move
(
e
);
done
=
true
;
cond
.
broadcast
();
}
};
static
int
Scan
(
const
char
*
uri
)
{
DumpRemoteTagHandler
handler
;
input_plugins_for_each_enabled
(
plugin
)
{
if
(
plugin
->
scan_tags
==
nullptr
)
continue
;
auto
scanner
=
plugin
->
scan_tags
(
uri
,
handler
);
if
(
scanner
)
{
scanner
->
Start
();
tag_save
(
stdout
,
handler
.
Wait
());
return
EXIT_SUCCESS
;
}
}
fprintf
(
stderr
,
"Unsupported URI
\n
"
);
return
EXIT_FAILURE
;
}
int
main
(
int
argc
,
char
**
argv
)
try
{
const
auto
c
=
ParseCommandLine
(
argc
,
argv
);
...
...
@@ -168,6 +237,9 @@ try {
const
GlobalInit
init
(
c
.
config_path
,
c
.
verbose
);
if
(
c
.
scan
)
return
Scan
(
c
.
uri
);
/* open the stream and dump it */
Mutex
mutex
;
...
...
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