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
d2046de1
Commit
d2046de1
authored
Jan 03, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/run_input, ...: RAII-style global initialization
parent
4397fe3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
73 deletions
+75
-73
dump_text_file.cxx
test/dump_text_file.cxx
+26
-29
run_input.cxx
test/run_input.cxx
+26
-28
visit_archive.cxx
test/visit_archive.cxx
+23
-16
No files found.
test/dump_text_file.cxx
View file @
d2046de1
...
@@ -36,6 +36,27 @@
...
@@ -36,6 +36,27 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
class
GlobalInit
{
const
ScopeIOThread
io_thread
;
public
:
GlobalInit
()
{
config_global_init
();
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all
();
#endif
input_stream_global_init
();
}
~
GlobalInit
()
{
input_stream_global_finish
();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all
();
#endif
config_global_finish
();
}
};
static
void
static
void
dump_text_file
(
TextInputStream
&
is
)
dump_text_file
(
TextInputStream
&
is
)
{
{
...
@@ -60,8 +81,6 @@ dump_input_stream(InputStreamPtr &&is)
...
@@ -60,8 +81,6 @@ dump_input_stream(InputStreamPtr &&is)
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
try
{
try
{
int
ret
;
if
(
argc
!=
2
)
{
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"Usage: run_input URI
\n
"
);
fprintf
(
stderr
,
"Usage: run_input URI
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
@@ -69,37 +88,15 @@ try {
...
@@ -69,37 +88,15 @@ try {
/* initialize MPD */
/* initialize MPD */
config_global_init
();
const
GlobalInit
init
;
const
ScopeIOThread
io_thread
;
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all
();
#endif
input_stream_global_init
();
/* open the stream and dump it */
/* open the stream and dump it */
{
Mutex
mutex
;
Mutex
mutex
;
Cond
cond
;
Cond
cond
;
auto
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
);
ret
=
dump_input_stream
(
std
::
move
(
is
));
}
/* deinitialize everything */
input_stream_global_finish
();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all
();
#endif
config_global_finish
();
return
ret
;
auto
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
);
return
dump_input_stream
(
std
::
move
(
is
));
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
LogError
(
e
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
...
test/run_input.cxx
View file @
d2046de1
...
@@ -38,6 +38,27 @@
...
@@ -38,6 +38,27 @@
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
class
GlobalInit
{
const
ScopeIOThread
io_thread
;
public
:
GlobalInit
()
{
config_global_init
();
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all
();
#endif
input_stream_global_init
();
}
~
GlobalInit
()
{
input_stream_global_finish
();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all
();
#endif
config_global_finish
();
}
};
static
void
static
void
tag_save
(
FILE
*
file
,
const
Tag
&
tag
)
tag_save
(
FILE
*
file
,
const
Tag
&
tag
)
{
{
...
@@ -91,37 +112,14 @@ try {
...
@@ -91,37 +112,14 @@ try {
/* initialize MPD */
/* initialize MPD */
config_global_init
();
const
GlobalInit
init
;
const
ScopeIOThread
io_thread
;
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all
();
#endif
input_stream_global_init
();
/* open the stream and dump it */
/* open the stream and dump it */
int
ret
;
Mutex
mutex
;
{
Cond
cond
;
Mutex
mutex
;
auto
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
);
Cond
cond
;
return
dump_input_stream
(
is
.
get
());
auto
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
);
ret
=
dump_input_stream
(
is
.
get
());
}
/* deinitialize everything */
input_stream_global_finish
();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all
();
#endif
config_global_finish
();
return
ret
;
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
LogError
(
e
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
...
test/visit_archive.cxx
View file @
d2046de1
...
@@ -35,8 +35,29 @@
...
@@ -35,8 +35,29 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
class
GlobalInit
{
const
ScopeIOThread
io_thread
;
public
:
GlobalInit
()
{
config_global_init
();
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all
();
#endif
input_stream_global_init
();
}
~
GlobalInit
()
{
input_stream_global_finish
();
#ifdef ENABLE_ARCHIVE
archive_plugin_deinit_all
();
#endif
config_global_finish
();
}
};
class
MyArchiveVisitor
final
:
public
ArchiveVisitor
{
class
MyArchiveVisitor
final
:
public
ArchiveVisitor
{
public
:
public
:
virtual
void
VisitArchiveEntry
(
const
char
*
path_utf8
)
override
{
virtual
void
VisitArchiveEntry
(
const
char
*
path_utf8
)
override
{
printf
(
"%s
\n
"
,
path_utf8
);
printf
(
"%s
\n
"
,
path_utf8
);
}
}
...
@@ -55,13 +76,7 @@ try {
...
@@ -55,13 +76,7 @@ try {
/* initialize MPD */
/* initialize MPD */
config_global_init
();
const
GlobalInit
init
;
const
ScopeIOThread
io_thread
;
archive_plugin_init_all
();
input_stream_global_init
();
/* open the archive and dump it */
/* open the archive and dump it */
...
@@ -79,14 +94,6 @@ try {
...
@@ -79,14 +94,6 @@ try {
file
->
Visit
(
visitor
);
file
->
Visit
(
visitor
);
file
->
Close
();
file
->
Close
();
/* deinitialize everything */
input_stream_global_finish
();
archive_plugin_deinit_all
();
config_global_finish
();
return
result
;
return
result
;
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
LogError
(
e
);
...
...
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