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
aeb2baa4
Commit
aeb2baa4
authored
Dec 29, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InputStream: add static method OpenReady()
Merge some duplicate code.
parent
ea9aff1d
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
47 additions
and
62 deletions
+47
-62
InputStream.cxx
src/InputStream.cxx
+22
-0
InputStream.hxx
src/InputStream.hxx
+9
-0
PlaylistAny.cxx
src/PlaylistAny.cxx
+1
-1
PlaylistRegistry.cxx
src/PlaylistRegistry.cxx
+3
-7
TagFile.cxx
src/TagFile.cxx
+3
-3
Bzip2ArchivePlugin.cxx
src/archive/Bzip2ArchivePlugin.cxx
+1
-1
SoundCloudPlaylistPlugin.cxx
src/playlist/SoundCloudPlaylistPlugin.cxx
+2
-3
dump_playlist.cxx
test/dump_playlist.cxx
+1
-3
dump_text_file.cxx
test/dump_text_file.cxx
+2
-18
read_tags.cxx
test/read_tags.cxx
+2
-15
run_input.cxx
test/run_input.cxx
+1
-11
No files found.
src/InputStream.cxx
View file @
aeb2baa4
...
...
@@ -57,6 +57,28 @@ InputStream::Open(const char *url,
return
nullptr
;
}
InputStream
*
InputStream
::
OpenReady
(
const
char
*
uri
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
{
InputStream
*
is
=
Open
(
uri
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
return
nullptr
;
mutex
.
lock
();
is
->
WaitReady
();
bool
success
=
is
->
Check
(
error
);
mutex
.
unlock
();
if
(
!
success
)
{
is
->
Close
();
is
=
nullptr
;
}
return
is
;
}
bool
InputStream
::
Check
(
Error
&
error
)
{
...
...
src/InputStream.hxx
View file @
aeb2baa4
...
...
@@ -119,6 +119,15 @@ struct InputStream {
Error
&
error
);
/**
* Just like Open(), but waits for the stream to become ready.
* It is a wrapper for Open(), WaitReady() and Check().
*/
gcc_malloc
gcc_nonnull_all
static
InputStream
*
OpenReady
(
const
char
*
uri
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
);
/**
* Close the input stream and free resources.
*
* The caller must not lock the mutex.
...
...
src/PlaylistAny.cxx
View file @
aeb2baa4
...
...
@@ -41,7 +41,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond,
}
Error
error
;
InputStream
*
is
=
InputStream
::
Open
(
uri
,
mutex
,
cond
,
error
);
InputStream
*
is
=
InputStream
::
Open
Ready
(
uri
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
{
if
(
error
.
IsDefined
())
FormatError
(
error
,
"Failed to open %s"
,
uri
);
...
...
src/PlaylistRegistry.cxx
View file @
aeb2baa4
...
...
@@ -269,9 +269,7 @@ playlist_list_open_stream_suffix(InputStream &is, const char *suffix)
SongEnumerator
*
playlist_list_open_stream
(
InputStream
&
is
,
const
char
*
uri
)
{
const
char
*
suffix
;
is
.
LockWaitReady
();
assert
(
is
.
ready
);
const
char
*
const
mime
=
is
.
GetMimeType
();
if
(
mime
!=
nullptr
)
{
...
...
@@ -280,7 +278,7 @@ playlist_list_open_stream(InputStream &is, const char *uri)
return
playlist
;
}
suffix
=
uri
!=
nullptr
?
uri_get_suffix
(
uri
)
:
nullptr
;
const
char
*
suffix
=
uri
!=
nullptr
?
uri_get_suffix
(
uri
)
:
nullptr
;
if
(
suffix
!=
nullptr
)
{
auto
playlist
=
playlist_list_open_stream_suffix
(
is
,
suffix
);
if
(
playlist
!=
nullptr
)
...
...
@@ -317,7 +315,7 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
return
nullptr
;
Error
error
;
InputStream
*
is
=
InputStream
::
Open
(
path_fs
,
mutex
,
cond
,
error
);
InputStream
*
is
=
InputStream
::
Open
Ready
(
path_fs
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
{
if
(
error
.
IsDefined
())
LogError
(
error
);
...
...
@@ -325,8 +323,6 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
return
nullptr
;
}
is
->
LockWaitReady
();
auto
playlist
=
playlist_list_open_stream_suffix
(
*
is
,
suffix
);
if
(
playlist
!=
nullptr
)
*
is_r
=
is
;
...
...
src/TagFile.cxx
View file @
aeb2baa4
...
...
@@ -62,9 +62,9 @@ public:
/* open the InputStream (if not already open) */
if
(
is
==
nullptr
)
{
is
=
InputStream
::
Open
(
path_fs
.
c_str
(),
mutex
,
cond
,
IgnoreError
());
is
=
InputStream
::
Open
Ready
(
path_fs
.
c_str
(),
mutex
,
cond
,
IgnoreError
());
if
(
is
==
nullptr
)
return
false
;
}
else
...
...
src/archive/Bzip2ArchivePlugin.cxx
View file @
aeb2baa4
...
...
@@ -146,7 +146,7 @@ bz2_open(const char *pathname, Error &error)
{
static
Mutex
mutex
;
static
Cond
cond
;
InputStream
*
is
=
InputStream
::
Open
(
pathname
,
mutex
,
cond
,
error
);
InputStream
*
is
=
InputStream
::
Open
Ready
(
pathname
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
return
nullptr
;
...
...
src/playlist/SoundCloudPlaylistPlugin.cxx
View file @
aeb2baa4
...
...
@@ -254,8 +254,8 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
Mutex
&
mutex
,
Cond
&
cond
)
{
Error
error
;
InputStream
*
input_stream
=
InputStream
::
Open
(
url
,
mutex
,
cond
,
error
);
InputStream
*
input_stream
=
InputStream
::
Open
Ready
(
url
,
mutex
,
cond
,
error
);
if
(
input_stream
==
nullptr
)
{
if
(
error
.
IsDefined
())
LogError
(
error
);
...
...
@@ -263,7 +263,6 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
}
mutex
.
lock
();
input_stream
->
WaitReady
();
yajl_status
stat
;
int
done
=
0
;
...
...
test/dump_playlist.cxx
View file @
aeb2baa4
...
...
@@ -92,7 +92,7 @@ int main(int argc, char **argv)
if
(
playlist
==
NULL
)
{
/* open the stream and wait until it becomes ready */
is
=
InputStream
::
Open
(
uri
,
mutex
,
cond
,
error
);
is
=
InputStream
::
Open
Ready
(
uri
,
mutex
,
cond
,
error
);
if
(
is
==
NULL
)
{
if
(
error
.
IsDefined
())
LogError
(
error
);
...
...
@@ -102,8 +102,6 @@ int main(int argc, char **argv)
return
2
;
}
is
->
LockWaitReady
();
/* open the playlist */
playlist
=
playlist_list_open_stream
(
*
is
,
uri
);
...
...
test/dump_text_file.cxx
View file @
aeb2baa4
...
...
@@ -49,23 +49,6 @@ dump_text_file(TextInputStream &is)
static
int
dump_input_stream
(
InputStream
&
is
)
{
Error
error
;
is
.
Lock
();
/* wait until the stream becomes ready */
is
.
WaitReady
();
if
(
!
is
.
Check
(
error
))
{
LogError
(
error
);
is
.
Unlock
();
return
EXIT_FAILURE
;
}
/* read data and tags from the stream */
is
.
Unlock
();
{
TextInputStream
tis
(
is
);
dump_text_file
(
tis
);
...
...
@@ -73,6 +56,7 @@ dump_input_stream(InputStream &is)
is
.
Lock
();
Error
error
;
if
(
!
is
.
Check
(
error
))
{
LogError
(
error
);
is
.
Unlock
();
...
...
@@ -121,7 +105,7 @@ int main(int argc, char **argv)
Mutex
mutex
;
Cond
cond
;
InputStream
*
is
=
InputStream
::
Open
(
argv
[
1
],
mutex
,
cond
,
error
);
InputStream
*
is
=
InputStream
::
Open
Ready
(
argv
[
1
],
mutex
,
cond
,
error
);
if
(
is
!=
NULL
)
{
ret
=
dump_input_stream
(
*
is
);
is
->
Close
();
...
...
test/read_tags.cxx
View file @
aeb2baa4
...
...
@@ -113,26 +113,13 @@ int main(int argc, char **argv)
Mutex
mutex
;
Cond
cond
;
InputStream
*
is
=
InputStream
::
Open
(
path
,
mutex
,
cond
,
error
);
InputStream
*
is
=
InputStream
::
Open
Ready
(
path
,
mutex
,
cond
,
error
);
if
(
is
==
NULL
)
{
FormatError
(
error
,
"Failed to open %s"
,
path
);
return
EXIT_FAILURE
;
}
mutex
.
lock
();
is
->
WaitReady
();
if
(
!
is
->
Check
(
error
))
{
mutex
.
unlock
();
FormatError
(
error
,
"Failed to read %s"
,
path
);
return
EXIT_FAILURE
;
}
mutex
.
unlock
();
success
=
plugin
->
ScanStream
(
*
is
,
print_handler
,
nullptr
);
is
->
Close
();
}
...
...
test/run_input.cxx
View file @
aeb2baa4
...
...
@@ -50,16 +50,6 @@ dump_input_stream(InputStream *is)
is
->
Lock
();
/* wait until the stream becomes ready */
is
->
WaitReady
();
if
(
!
is
->
Check
(
error
))
{
LogError
(
error
);
is
->
Unlock
();
return
EXIT_FAILURE
;
}
/* print meta data */
if
(
!
is
->
mime
.
empty
())
...
...
@@ -139,7 +129,7 @@ int main(int argc, char **argv)
Mutex
mutex
;
Cond
cond
;
is
=
InputStream
::
Open
(
argv
[
1
],
mutex
,
cond
,
error
);
is
=
InputStream
::
Open
Ready
(
argv
[
1
],
mutex
,
cond
,
error
);
if
(
is
!=
NULL
)
{
ret
=
dump_input_stream
(
is
);
is
->
Close
();
...
...
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