aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQball Cow <qball@qballcow.nl>2005-08-23 12:01:37 +0000
committerQball Cow <qball@qballcow.nl>2005-08-23 12:01:37 +0000
commit2aba0437a6ab9097ea61f658337fcf470fca73af (patch)
tree82d0d31a532dc02ac9bf250eb9dd596616e3d72a /src
parent1b65ae02d4303050bc33754f4ee467010b416a4d (diff)
downloadmpd-2aba0437a6ab9097ea61f658337fcf470fca73af.tar.gz
mpd-2aba0437a6ab9097ea61f658337fcf470fca73af.tar.xz
mpd-2aba0437a6ab9097ea61f658337fcf470fca73af.zip
Saving state of output-device in state-file. (This is a temporary solution, rewrite of state-file is planned for 0.13)
git-svn-id: https://svn.musicpd.org/mpd/trunk@3449 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/audio.c131
-rw-r--r--src/audio.h4
-rw-r--r--src/main.c7
3 files changed, 142 insertions, 0 deletions
diff --git a/src/audio.c b/src/audio.c
index 277ab6cf0..8f7200d46 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -23,11 +23,29 @@
#include "sig_handlers.h"
#include "command.h"
#include "playerData.h"
+#include "utils.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <errno.h>
+#include <unistd.h>
+
+
+/* crappy code by qball */
+#define AUDIO_STATE_FILE_DEVICE_START "audio_device_start"
+#define AUDIO_STATE_FILE_DEVICE_ID "audio_device_id: "
+#define AUDIO_STATE_FILE_DEVICE_ENABLED "audio_device_enabled: "
+#define AUDIO_STATE_FILE_DEVICE_NAME "audio_device_name: "
+#define AUDIO_STATE_FILE_DEVICE_END "audio_device_end"
+
+#define AUDIO_BUFFER_SIZE 2*MAXPATHLEN
+/* /crappy code */
+
+
static AudioFormat audio_format;
@@ -396,3 +414,116 @@ void printAudioDevices(FILE * fp) {
(int)pdAudioDevicesEnabled[i]);
}
}
+
+
+/* more qball crappy code */
+
+static char * getStateFile() {
+ ConfigParam * param = parseConfigFilePath(CONF_STATE_FILE, 0);
+
+ if(!param) return NULL;
+
+ return param->value;
+}
+
+
+
+void saveAudioDevicesState() {
+ int i;
+ char * stateFile = getStateFile();
+
+ if(stateFile) {
+ FILE * fp;
+
+ while(!(fp = fopen(stateFile,"a")) && errno==EINTR);
+ if(!fp) {
+ ERROR("problems opening state file \"%s\" for "
+ "writing: %s\n", stateFile,
+ strerror(errno));
+ return;
+ }
+ for(i = 0; i < audioOutputArraySize; i++) {
+ myfprintf(fp, "%s\n", AUDIO_STATE_FILE_DEVICE_START);
+ myfprintf(fp, "%s%i\n", AUDIO_STATE_FILE_DEVICE_ID, i);
+ myfprintf(fp, "%s%s\n", AUDIO_STATE_FILE_DEVICE_NAME, audioOutputArray[i]->name);
+ myfprintf(fp, "%s%i\n", AUDIO_STATE_FILE_DEVICE_ENABLED,(int)pdAudioDevicesEnabled[i]);
+ myfprintf(fp, "%s\n", AUDIO_STATE_FILE_DEVICE_END);
+ }
+ while(fclose(fp) && errno==EINTR);
+ }
+}
+
+void readAudioDevicesState() {
+ char * stateFile = getStateFile();
+ FILE *fp;
+ struct stat st;
+ if(stateFile) {
+ char buffer[AUDIO_BUFFER_SIZE];
+
+
+
+
+ if(stat(stateFile,&st)<0) {
+ DEBUG("failed to stat state file\n");
+ return;
+ }
+ if(!S_ISREG(st.st_mode)) {
+ ERROR("state file \"%s\" is not a regular "
+ "file\n",stateFile);
+ exit(EXIT_FAILURE);
+ }
+
+ fp = fopen(stateFile,"r");
+ if(!fp) {
+ ERROR("problems opening state file \"%s\" for "
+ "reading: %s\n", stateFile,
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ while(myFgets(buffer,AUDIO_BUFFER_SIZE,fp)) {
+ if(strncmp(buffer,AUDIO_STATE_FILE_DEVICE_START, strlen(AUDIO_STATE_FILE_DEVICE_START))==0) {
+ char *name = NULL;
+ int id = -1;
+ int enabled = 1;
+ if(!myFgets(buffer,AUDIO_BUFFER_SIZE,fp)) {
+ ERROR("error parsing state file \"%s\"\n", stateFile);
+ exit(EXIT_FAILURE);
+ }
+ while(strcmp(buffer,AUDIO_STATE_FILE_DEVICE_END)) {
+ if(strncmp(buffer,AUDIO_STATE_FILE_DEVICE_ID, strlen(AUDIO_STATE_FILE_DEVICE_ID)) == 0 ) {
+ if(strlen(buffer) > strlen(AUDIO_STATE_FILE_DEVICE_ID))
+ {
+ id = atoi(&buffer[strlen(AUDIO_STATE_FILE_DEVICE_ID)]);
+ }
+ }
+ if(strncmp(buffer,AUDIO_STATE_FILE_DEVICE_ENABLED, strlen(AUDIO_STATE_FILE_DEVICE_ENABLED)) == 0 ) {
+ if(strlen(buffer) > strlen(AUDIO_STATE_FILE_DEVICE_ENABLED))
+ {
+ enabled = atoi(&buffer[strlen(AUDIO_STATE_FILE_DEVICE_ENABLED)]);
+ }
+ }
+ if(!myFgets(buffer,AUDIO_BUFFER_SIZE,fp)) {
+ ERROR("error parsing state file \"%s\"\n", stateFile);
+ exit(EXIT_FAILURE);
+ }
+ }
+ if(id != -1)
+ {
+ /* search for same name here, can we trust id? */
+ if(id < audioOutputArraySize)
+ {
+ pdAudioDevicesEnabled[id] = enabled;
+ }
+ }
+ if(name != NULL)
+ {
+ free(name);
+ }
+ }
+ }
+
+ fclose(fp);
+ }
+}
+
diff --git a/src/audio.h b/src/audio.h
index 87c265568..f1a63ee69 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -75,4 +75,8 @@ int disableAudioDevice(FILE * fp, int device);
void printAudioDevices(FILE * fp);
+/* qball's crappy code */
+void readAudioDevicesState();
+void saveAudioDevicesState();
+
#endif
diff --git a/src/main.c b/src/main.c
index cda6d1077..67c76a981 100644
--- a/src/main.c
+++ b/src/main.c
@@ -491,6 +491,9 @@ int main(int argc, char * argv[]) {
initSigHandlers();
readPlaylistState();
+ /* qball crappy code */
+ readAudioDevicesState();
+
while(COMMAND_RETURN_KILL!=doIOForInterfaces()) {
if(COMMAND_RETURN_KILL==handlePendingSignals()) break;
syncPlayerAndPlaylist();
@@ -499,6 +502,10 @@ int main(int argc, char * argv[]) {
}
savePlaylistState();
+ /* qball crappy code */
+ saveAudioDevicesState();
+
+
playerKill();
freeAllInterfaces();