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
0dd2dfff
Commit
0dd2dfff
authored
Jan 18, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
main: moved the save_state timer to state_file.c
The state_file library should manage its own regular saves.
parent
84de45af
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
20 deletions
+26
-20
main.c
src/main.c
+0
-18
state_file.c
src/state_file.c
+26
-2
No files found.
src/main.c
View file @
0dd2dfff
...
...
@@ -165,14 +165,6 @@ initialize_decoder_and_player(void)
dc_init
();
}
static
gboolean
timer_save_state_file
(
G_GNUC_UNUSED
gpointer
data
)
{
g_debug
(
"Saving state file"
);
write_state_file
();
return
true
;
}
/**
* event_pipe callback function for PIPE_EVENT_IDLE
*/
...
...
@@ -190,8 +182,6 @@ int main(int argc, char *argv[])
{
Options
options
;
clock_t
start
;
GTimer
*
save_state_timer
;
guint
save_state_source_id
;
daemonize_close_stdin
();
...
...
@@ -265,11 +255,6 @@ int main(int argc, char *argv[])
state_file_init
(
config_get_path
(
CONF_STATE_FILE
));
save_state_timer
=
g_timer_new
();
save_state_source_id
=
g_timeout_add
(
5
*
60
*
1000
,
timer_save_state_file
,
NULL
);
/* run the main loop */
g_main_loop_run
(
main_loop
);
...
...
@@ -278,9 +263,6 @@ int main(int argc, char *argv[])
g_main_loop_unref
(
main_loop
);
g_source_remove
(
save_state_source_id
);
g_timer_destroy
(
save_state_timer
);
state_file_finish
();
playerKill
();
finishZeroconf
();
...
...
src/state_file.c
View file @
0dd2dfff
...
...
@@ -22,6 +22,7 @@
#include "volume.h"
#include <glib.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
...
...
@@ -39,7 +40,11 @@ static struct _sf_cb {
static
char
*
state_file_path
;
void
write_state_file
(
void
)
/** the GLib source id for the save timer */
static
guint
save_state_source_id
;
static
void
state_file_write
(
void
)
{
unsigned
int
i
;
FILE
*
fp
;
...
...
@@ -68,6 +73,8 @@ state_file_read(void)
assert
(
state_file_path
!=
NULL
);
g_debug
(
"Saving state file"
);
fp
=
fopen
(
state_file_path
,
"r"
);
if
(
G_UNLIKELY
(
!
fp
))
{
g_warning
(
"failed to open %s: %s"
,
...
...
@@ -82,6 +89,17 @@ state_file_read(void)
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
/* nothing */
;
}
/**
* This function is called every 5 minutes by the GLib main loop, and
* saves the state file.
*/
static
gboolean
timer_save_state_file
(
G_GNUC_UNUSED
gpointer
data
)
{
state_file_write
();
return
true
;
}
void
state_file_init
(
const
char
*
path
)
{
...
...
@@ -92,13 +110,19 @@ state_file_init(const char *path)
state_file_path
=
g_strdup
(
path
);
state_file_read
();
save_state_source_id
=
g_timeout_add
(
5
*
60
*
1000
,
timer_save_state_file
,
NULL
);
}
void
state_file_finish
(
void
)
{
if
(
save_state_source_id
!=
0
)
g_source_remove
(
save_state_source_id
);
if
(
state_file_path
!=
NULL
)
write_state_fil
e
();
state_file_writ
e
();
g_free
(
state_file_path
);
}
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