diff options
author | Max Kellermann <max@duempel.org> | 2008-09-07 13:50:16 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-09-09 01:12:25 -0700 |
commit | 288c051c55e741bbf9387579ea7f066ab6f754f0 (patch) | |
tree | 2ef315138272fe1245325fe151ecaa72c6464b75 /src | |
parent | 2210ddee97bd16424e218a3894fcaca52a4ee080 (diff) | |
download | mpd-288c051c55e741bbf9387579ea7f066ab6f754f0.tar.gz mpd-288c051c55e741bbf9387579ea7f066ab6f754f0.tar.xz mpd-288c051c55e741bbf9387579ea7f066ab6f754f0.zip |
volume: don't pass "fd" to changeVolumeLevel()
The "volume" library shouldn't talk to the client. Move error
handling to command.c.
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 20 | ||||
-rw-r--r-- | src/volume.c | 25 | ||||
-rw-r--r-- | src/volume.h | 2 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/command.c b/src/command.c index e24c93d59..dc62481ff 100644 --- a/src/command.c +++ b/src/command.c @@ -871,21 +871,33 @@ static int handleListAll(int fd, mpd_unused int *permission, static int handleVolume(int fd, mpd_unused int *permission, mpd_unused int argc, char *argv[]) { - int change; + int change, ret; if (check_int(fd, &change, argv[1], need_integer) < 0) return -1; - return changeVolumeLevel(fd, change, 1); + + ret = changeVolumeLevel(change, 1); + if (ret == -1) + commandError(fd, ACK_ERROR_SYSTEM, + "problems setting volume"); + + return ret; } static int handleSetVol(int fd, mpd_unused int *permission, mpd_unused int argc, char *argv[]) { - int level; + int level, ret; if (check_int(fd, &level, argv[1], need_integer) < 0) return -1; - return changeVolumeLevel(fd, level, 0); + + ret = changeVolumeLevel(level, 0); + if (ret == -1) + commandError(fd, ACK_ERROR_SYSTEM, + "problems setting volume"); + + return ret; } static int handleRepeat(int fd, mpd_unused int *permission, diff --git a/src/volume.c b/src/volume.c index cf2b8eff8..428c3b8a1 100644 --- a/src/volume.c +++ b/src/volume.c @@ -17,12 +17,10 @@ */ #include "volume.h" -#include "command.h" #include "conf.h" #include "log.h" #include "gcc.h" #include "utils.h" -#include "ack.h" #include "os_compat.h" #include "outputBuffer.h" @@ -169,18 +167,15 @@ static int getOssVolumeLevel(void) return left; } -static int changeOssVolumeLevel(int fd, int change, int rel) +static int changeOssVolumeLevel(int change, int rel) { int current; int new; int level; if (rel) { - if ((current = getOssVolumeLevel()) < 0) { - commandError(fd, ACK_ERROR_SYSTEM, - "problem getting current volume"); + if ((current = getOssVolumeLevel()) < 0) return -1; - } new = current + change; } else { @@ -198,7 +193,6 @@ static int changeOssVolumeLevel(int fd, int change, int rel) if (ioctl(volume_ossFd, MIXER_WRITE(volume_ossControl), &level) < 0) { closeOssMixer(); - commandError(fd, ACK_ERROR_SYSTEM, "problems setting volume"); return -1; } @@ -328,7 +322,7 @@ static int getAlsaVolumeLevel(void) return ret; } -static int changeAlsaVolumeLevel(int fd, int change, int rel) +static int changeAlsaVolumeLevel(int change, int rel) { float vol; long level; @@ -361,7 +355,6 @@ static int changeAlsaVolumeLevel(int fd, int change, int rel) if ((err = snd_mixer_selem_set_playback_volume_all(volume_alsaElem, level)) < 0) { - commandError(fd, ACK_ERROR_SYSTEM, "problems setting volume"); WARNING("problems setting alsa volume: %s\n", snd_strerror(err)); closeAlsaMixer(); @@ -469,7 +462,7 @@ int getVolumeLevel(void) } } -static int changeSoftwareVolume(mpd_unused int fd, int change, int rel) +static int changeSoftwareVolume(int change, int rel) { int new = change; @@ -497,19 +490,19 @@ static int changeSoftwareVolume(mpd_unused int fd, int change, int rel) return 0; } -int changeVolumeLevel(int fd, int change, int rel) +int changeVolumeLevel(int change, int rel) { switch (volume_mixerType) { #ifdef HAVE_ALSA case VOLUME_MIXER_TYPE_ALSA: - return changeAlsaVolumeLevel(fd, change, rel); + return changeAlsaVolumeLevel(change, rel); #endif #ifdef HAVE_OSS case VOLUME_MIXER_TYPE_OSS: - return changeOssVolumeLevel(fd, change, rel); + return changeOssVolumeLevel(change, rel); #endif case VOLUME_MIXER_TYPE_SOFTWARE: - return changeSoftwareVolume(fd, change, rel); + return changeSoftwareVolume(change, rel); default: return 0; } @@ -531,7 +524,7 @@ void read_sw_volume_state(FILE *fp) continue; sv = strtol(buf + len, &end, 10); if (mpd_likely(!*end)) - changeSoftwareVolume(STDERR_FILENO, sv, 0); + changeSoftwareVolume(sv, 0); else ERROR("Can't parse software volume: %s\n", buf); return; diff --git a/src/volume.h b/src/volume.h index 85a9eefa8..a92cdd8bb 100644 --- a/src/volume.h +++ b/src/volume.h @@ -33,7 +33,7 @@ void finishVolume(void); int getVolumeLevel(void); -int changeVolumeLevel(int fd, int change, int rel); +int changeVolumeLevel(int change, int rel); void read_sw_volume_state(FILE *fp); |