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
bcc1e510
Commit
bcc1e510
authored
Jul 17, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StateFile: add struct StateFileConfig
parent
e8a7c6ce
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
32 deletions
+102
-32
Makefile.am
Makefile.am
+1
-0
Main.cxx
src/Main.cxx
+4
-18
StateFile.cxx
src/StateFile.cxx
+5
-9
StateFile.hxx
src/StateFile.hxx
+4
-5
StateFileConfig.cxx
src/StateFileConfig.cxx
+44
-0
StateFileConfig.hxx
src/StateFileConfig.hxx
+44
-0
No files found.
Makefile.am
View file @
bcc1e510
...
@@ -175,6 +175,7 @@ libmpd_a_SOURCES = \
...
@@ -175,6 +175,7 @@ libmpd_a_SOURCES = \
src/SongPrint.cxx src/SongPrint.hxx
\
src/SongPrint.cxx src/SongPrint.hxx
\
src/SongSave.cxx src/SongSave.hxx
\
src/SongSave.cxx src/SongSave.hxx
\
src/StateFile.cxx src/StateFile.hxx
\
src/StateFile.cxx src/StateFile.hxx
\
src/StateFileConfig.cxx src/StateFileConfig.hxx
\
src/Stats.cxx src/Stats.hxx
\
src/Stats.cxx src/Stats.hxx
\
src/TagPrint.cxx src/TagPrint.hxx
\
src/TagPrint.cxx src/TagPrint.hxx
\
src/TagSave.cxx src/TagSave.hxx
\
src/TagSave.cxx src/TagSave.hxx
\
...
...
src/Main.cxx
View file @
bcc1e510
...
@@ -93,7 +93,6 @@
...
@@ -93,7 +93,6 @@
#include "java/File.hxx"
#include "java/File.hxx"
#include "android/Environment.hxx"
#include "android/Environment.hxx"
#include "android/Context.hxx"
#include "android/Context.hxx"
#include "fs/StandardDirectory.hxx"
#include "fs/FileSystem.hxx"
#include "fs/FileSystem.hxx"
#include "org_musicpd_Bridge.h"
#include "org_musicpd_Bridge.h"
#endif
#endif
...
@@ -256,26 +255,13 @@ glue_sticker_init(const ConfigData &config)
...
@@ -256,26 +255,13 @@ glue_sticker_init(const ConfigData &config)
}
}
static
void
static
void
glue_state_file_init
(
const
ConfigData
&
config
)
glue_state_file_init
(
const
ConfigData
&
raw_
config
)
{
{
auto
path_fs
=
config
.
GetPath
(
ConfigOption
::
STATE_FILE
);
StateFileConfig
config
(
raw_config
);
if
(
path_fs
.
IsNull
())
{
if
(
!
config
.
IsEnabled
())
#ifdef ANDROID
const
auto
cache_dir
=
GetUserCacheDir
();
if
(
cache_dir
.
IsNull
())
return
;
path_fs
=
cache_dir
/
Path
::
FromFS
(
"state"
);
#else
return
;
return
;
#endif
}
const
auto
interval
=
config
.
GetUnsigned
(
ConfigOption
::
STATE_FILE_INTERVAL
,
StateFile
::
DEFAULT_INTERVAL
);
instance
->
state_file
=
new
StateFile
(
std
::
move
(
path_fs
),
interval
,
instance
->
state_file
=
new
StateFile
(
std
::
move
(
config
)
,
instance
->
partitions
.
front
(),
instance
->
partitions
.
front
(),
instance
->
event_loop
);
instance
->
event_loop
);
instance
->
state_file
->
Read
();
instance
->
state_file
->
Read
();
...
...
src/StateFile.cxx
View file @
bcc1e510
...
@@ -38,13 +38,9 @@
...
@@ -38,13 +38,9 @@
static
constexpr
Domain
state_file_domain
(
"state_file"
);
static
constexpr
Domain
state_file_domain
(
"state_file"
);
constexpr
std
::
chrono
::
steady_clock
::
duration
StateFile
::
DEFAULT_INTERVAL
;
StateFile
::
StateFile
(
StateFileConfig
&&
_config
,
StateFile
::
StateFile
(
AllocatedPath
&&
_path
,
std
::
chrono
::
steady_clock
::
duration
_interval
,
Partition
&
_partition
,
EventLoop
&
_loop
)
Partition
&
_partition
,
EventLoop
&
_loop
)
:
path
(
std
::
move
(
_path
)),
path_utf8
(
path
.
ToUTF8
()),
:
config
(
std
::
move
(
_config
)),
path_utf8
(
config
.
path
.
ToUTF8
()),
interval
(
_interval
),
timer_event
(
_loop
,
BIND_THIS_METHOD
(
OnTimeout
)),
timer_event
(
_loop
,
BIND_THIS_METHOD
(
OnTimeout
)),
partition
(
_partition
)
partition
(
_partition
)
{
{
...
@@ -103,7 +99,7 @@ StateFile::Write()
...
@@ -103,7 +99,7 @@ StateFile::Write()
"Saving state file %s"
,
path_utf8
.
c_str
());
"Saving state file %s"
,
path_utf8
.
c_str
());
try
{
try
{
FileOutputStream
fos
(
path
);
FileOutputStream
fos
(
config
.
path
);
Write
(
fos
);
Write
(
fos
);
fos
.
Commit
();
fos
.
Commit
();
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
...
@@ -120,7 +116,7 @@ try {
...
@@ -120,7 +116,7 @@ try {
FormatDebug
(
state_file_domain
,
"Loading state file %s"
,
path_utf8
.
c_str
());
FormatDebug
(
state_file_domain
,
"Loading state file %s"
,
path_utf8
.
c_str
());
TextFile
file
(
path
);
TextFile
file
(
config
.
path
);
#ifdef ENABLE_DATABASE
#ifdef ENABLE_DATABASE
const
SongLoader
song_loader
(
partition
.
instance
.
database
,
const
SongLoader
song_loader
(
partition
.
instance
.
database
,
...
@@ -155,7 +151,7 @@ void
...
@@ -155,7 +151,7 @@ void
StateFile
::
CheckModified
()
StateFile
::
CheckModified
()
{
{
if
(
!
timer_event
.
IsActive
()
&&
IsModified
())
if
(
!
timer_event
.
IsActive
()
&&
IsModified
())
timer_event
.
Schedule
(
interval
);
timer_event
.
Schedule
(
config
.
interval
);
}
}
void
void
...
...
src/StateFile.hxx
View file @
bcc1e510
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#ifndef MPD_STATE_FILE_HXX
#ifndef MPD_STATE_FILE_HXX
#define MPD_STATE_FILE_HXX
#define MPD_STATE_FILE_HXX
#include "StateFileConfig.hxx"
#include "event/TimerEvent.hxx"
#include "event/TimerEvent.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/AllocatedPath.hxx"
#include "Compiler.h"
#include "Compiler.h"
...
@@ -32,10 +33,10 @@ class OutputStream;
...
@@ -32,10 +33,10 @@ class OutputStream;
class
BufferedOutputStream
;
class
BufferedOutputStream
;
class
StateFile
final
{
class
StateFile
final
{
const
AllocatedPath
path
;
const
StateFileConfig
config
;
const
std
::
string
path_utf8
;
const
std
::
string
path_utf8
;
const
std
::
chrono
::
steady_clock
::
duration
interval
;
TimerEvent
timer_event
;
TimerEvent
timer_event
;
Partition
&
partition
;
Partition
&
partition
;
...
@@ -52,9 +53,7 @@ class StateFile final {
...
@@ -52,9 +53,7 @@ class StateFile final {
#endif
#endif
public
:
public
:
static
constexpr
std
::
chrono
::
steady_clock
::
duration
DEFAULT_INTERVAL
=
std
::
chrono
::
minutes
(
2
);
StateFile
(
StateFileConfig
&&
_config
,
StateFile
(
AllocatedPath
&&
path
,
std
::
chrono
::
steady_clock
::
duration
interval
,
Partition
&
partition
,
EventLoop
&
loop
);
Partition
&
partition
,
EventLoop
&
loop
);
void
Read
();
void
Read
();
...
...
src/StateFileConfig.cxx
0 → 100644
View file @
bcc1e510
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "StateFileConfig.hxx"
#include "config/Data.hxx"
#ifdef ANDROID
#include "fs/StandardDirectory.hxx"
#endif
constexpr
std
::
chrono
::
steady_clock
::
duration
StateFileConfig
::
DEFAULT_INTERVAL
;
StateFileConfig
::
StateFileConfig
(
const
ConfigData
&
config
)
:
path
(
config
.
GetPath
(
ConfigOption
::
STATE_FILE
)),
interval
(
config
.
GetUnsigned
(
ConfigOption
::
STATE_FILE_INTERVAL
,
DEFAULT_INTERVAL
))
{
#ifdef ANDROID
if
(
path
.
IsNull
())
{
const
auto
cache_dir
=
GetUserCacheDir
();
if
(
cache_dir
.
IsNull
())
return
;
path
=
cache_dir
/
Path
::
FromFS
(
"state"
);
}
#endif
}
src/StateFileConfig.hxx
0 → 100644
View file @
bcc1e510
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_STATE_FILE_CONFIG_HXX
#define MPD_STATE_FILE_CONFIG_HXX
#include "check.h"
#include "fs/AllocatedPath.hxx"
#include <chrono>
struct
ConfigData
;
struct
StateFileConfig
{
static
constexpr
std
::
chrono
::
steady_clock
::
duration
DEFAULT_INTERVAL
=
std
::
chrono
::
minutes
(
2
);
AllocatedPath
path
;
std
::
chrono
::
steady_clock
::
duration
interval
;
explicit
StateFileConfig
(
const
ConfigData
&
config
);
bool
IsEnabled
()
const
noexcept
{
return
!
path
.
IsNull
();
}
};
#endif
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