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
84de45af
Commit
84de45af
authored
Jan 18, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
state_file: added state_file_init() and state_file_finish()
The constructor/destructor interface should hide the functions read_state_file() and write_state_file().
parent
1482b223
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
24 deletions
+40
-24
main.c
src/main.c
+3
-2
state_file.c
src/state_file.c
+31
-21
state_file.h
src/state_file.h
+6
-1
No files found.
src/main.c
View file @
84de45af
...
@@ -262,7 +262,8 @@ int main(int argc, char *argv[])
...
@@ -262,7 +262,8 @@ int main(int argc, char *argv[])
decoder_thread_start
();
decoder_thread_start
();
player_create
();
player_create
();
read_state_file
();
state_file_init
(
config_get_path
(
CONF_STATE_FILE
));
save_state_timer
=
g_timer_new
();
save_state_timer
=
g_timer_new
();
...
@@ -280,7 +281,7 @@ int main(int argc, char *argv[])
...
@@ -280,7 +281,7 @@ int main(int argc, char *argv[])
g_source_remove
(
save_state_source_id
);
g_source_remove
(
save_state_source_id
);
g_timer_destroy
(
save_state_timer
);
g_timer_destroy
(
save_state_timer
);
write_state_file
();
state_file_finish
();
playerKill
();
playerKill
();
finishZeroconf
();
finishZeroconf
();
client_manager_deinit
();
client_manager_deinit
();
...
...
src/state_file.c
View file @
84de45af
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
*/
*/
#include "state_file.h"
#include "state_file.h"
#include "conf.h"
#include "audio.h"
#include "audio.h"
#include "playlist.h"
#include "playlist.h"
#include "volume.h"
#include "volume.h"
...
@@ -38,29 +37,20 @@ static struct _sf_cb {
...
@@ -38,29 +37,20 @@ static struct _sf_cb {
{
readPlaylistState
,
savePlaylistState
},
{
readPlaylistState
,
savePlaylistState
},
};
};
static
const
char
*
sfpath
;
static
char
*
state_file_path
;
static
void
get_state_file_path
(
void
)
{
struct
config_param
*
param
;
if
(
sfpath
)
return
;
param
=
parseConfigFilePath
(
CONF_STATE_FILE
,
0
);
if
(
param
)
sfpath
=
(
const
char
*
)
param
->
value
;
}
void
write_state_file
(
void
)
void
write_state_file
(
void
)
{
{
unsigned
int
i
;
unsigned
int
i
;
FILE
*
fp
;
FILE
*
fp
;
if
(
!
sfpath
)
if
(
state_file_path
==
NULL
)
return
;
return
;
fp
=
fopen
(
sfpath
,
"w"
);
fp
=
fopen
(
state_file_path
,
"w"
);
if
(
G_UNLIKELY
(
!
fp
))
{
if
(
G_UNLIKELY
(
!
fp
))
{
g_warning
(
"failed to create %s: %s"
,
g_warning
(
"failed to create %s: %s"
,
s
f
path
,
strerror
(
errno
));
s
tate_file_
path
,
strerror
(
errno
));
return
;
return
;
}
}
...
@@ -70,19 +60,18 @@ void write_state_file(void)
...
@@ -70,19 +60,18 @@ void write_state_file(void)
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
/* nothing */
;
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
/* nothing */
;
}
}
void
read_state_file
(
void
)
static
void
state_file_read
(
void
)
{
{
unsigned
int
i
;
unsigned
int
i
;
FILE
*
fp
;
FILE
*
fp
;
get_state_file_path
();
assert
(
state_file_path
!=
NULL
);
if
(
!
sfpath
)
return
;
while
(
!
(
fp
=
fopen
(
sfpath
,
"r"
))
&&
errno
==
EINTR
);
fp
=
fopen
(
state_file_path
,
"r"
);
if
(
G_UNLIKELY
(
!
fp
))
{
if
(
G_UNLIKELY
(
!
fp
))
{
g_warning
(
"failed to open %s: %s"
,
g_warning
(
"failed to open %s: %s"
,
s
f
path
,
strerror
(
errno
));
s
tate_file_
path
,
strerror
(
errno
));
return
;
return
;
}
}
for
(
i
=
0
;
i
<
G_N_ELEMENTS
(
sf_callbacks
);
i
++
)
{
for
(
i
=
0
;
i
<
G_N_ELEMENTS
(
sf_callbacks
);
i
++
)
{
...
@@ -92,3 +81,24 @@ void read_state_file(void)
...
@@ -92,3 +81,24 @@ void read_state_file(void)
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
/* nothing */
;
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
/* nothing */
;
}
}
void
state_file_init
(
const
char
*
path
)
{
assert
(
state_file_path
==
NULL
);
if
(
path
==
NULL
)
return
;
state_file_path
=
g_strdup
(
path
);
state_file_read
();
}
void
state_file_finish
(
void
)
{
if
(
state_file_path
!=
NULL
)
write_state_file
();
g_free
(
state_file_path
);
}
src/state_file.h
View file @
84de45af
...
@@ -19,7 +19,12 @@
...
@@ -19,7 +19,12 @@
#ifndef MPD_STATE_FILE_H
#ifndef MPD_STATE_FILE_H
#define MPD_STATE_FILE_H
#define MPD_STATE_FILE_H
void
state_file_init
(
const
char
*
path
);
void
state_file_finish
(
void
);
void
write_state_file
(
void
);
void
write_state_file
(
void
);
void
read_state_file
(
void
);
#endif
/* STATE_FILE_H */
#endif
/* STATE_FILE_H */
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