Skip to content
Browse files

moved code to output.c, output.h

Moved code which operates on MPD's audio output devices to output.c,
public header mpd/output.h.
  • Loading branch information...
1 parent c0bb7c6 commit 18edaeb91ff6a980c563e3b915e7122ecdd465ee @MaxKellermann MaxKellermann committed Nov 27, 2008
Showing with 180 additions and 89 deletions.
  1. +2 −0 Makefile.am
  2. +0 −16 include/mpd/client.h
  3. +59 −0 include/mpd/output.h
  4. +0 −73 src/libmpdclient.c
  5. +119 −0 src/output.c
View
2 Makefile.am
@@ -8,6 +8,7 @@ mpdinclude_HEADERS = \
include/mpd/client.h \
include/mpd/connection.h \
include/mpd/idle.h \
+ include/mpd/output.h \
include/mpd/return_element.h \
include/mpd/song.h
@@ -19,6 +20,7 @@ src_libmpdclient_la_SOURCES = \
src/str_pool.c src/str_pool.h \
src/resolver.c src/resolver.h \
src/connection.c \
+ src/output.c \
src/return_element.c \
src/idle.c \
src/song.c \
View
16 include/mpd/client.h
@@ -395,22 +395,6 @@ void mpd_sendCommandListEnd(struct mpd_connection *connection);
* returns -1 if it advanced to an OK or ACK */
int mpd_nextListOkCommand(struct mpd_connection *connection);
-typedef struct _mpd_OutputEntity {
- int id;
- char * name;
- int enabled;
-} mpd_OutputEntity;
-
-void mpd_sendOutputsCommand(struct mpd_connection *connection);
-
-mpd_OutputEntity * mpd_getNextOutput(struct mpd_connection *connection);
-
-void mpd_sendEnableOutputCommand(struct mpd_connection *connection, int outputId);
-
-void mpd_sendDisableOutputCommand(struct mpd_connection *connection, int outputId);
-
-void mpd_freeOutputElement(mpd_OutputEntity * output);
-
/**
* @param connection a #mpd_Connection
*
View
59 include/mpd/output.h
@@ -0,0 +1,59 @@
+/* libmpdclient
+ (c) 2003-2008 The Music Player Daemon Project
+ This project's homepage is: http://www.musicpd.org
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of the Music Player Daemon nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef MPD_OUTPUT_H
+#define MPD_OUTPUT_H
+
+struct mpd_connection;
+
+typedef struct _mpd_OutputEntity {
+ int id;
+ char *name;
+ int enabled;
+} mpd_OutputEntity;
+
+void
+mpd_sendOutputsCommand(struct mpd_connection *connection);
+
+mpd_OutputEntity *
+mpd_getNextOutput(struct mpd_connection *connection);
+
+void
+mpd_freeOutputElement(mpd_OutputEntity * output);
+
+void
+mpd_sendEnableOutputCommand(struct mpd_connection *connection, int outputId);
+
+void
+mpd_sendDisableOutputCommand(struct mpd_connection *connection, int outputId);
+
+#endif
View
73 src/libmpdclient.c
@@ -1111,79 +1111,6 @@ void mpd_sendCommandListEnd(struct mpd_connection *connection)
mpd_executeCommand(connection,"command_list_end\n");
}
-void mpd_sendOutputsCommand(struct mpd_connection *connection)
-{
- mpd_executeCommand(connection,"outputs\n");
-}
-
-mpd_OutputEntity * mpd_getNextOutput(struct mpd_connection *connection)
-{
- mpd_OutputEntity * output = NULL;
-
- if(connection->doneProcessing || (connection->listOks &&
- connection->doneListOk))
- {
- return NULL;
- }
-
- if(connection->error) return NULL;
-
- output = malloc(sizeof(mpd_OutputEntity));
- output->id = -10;
- output->name = NULL;
- output->enabled = 0;
-
- if(!connection->returnElement) mpd_getNextReturnElement(connection);
-
- while(connection->returnElement) {
- struct mpd_return_element *re = connection->returnElement;
- if(strcmp(re->name,"outputid")==0) {
- if(output!=NULL && output->id>=0) return output;
- output->id = atoi(re->value);
- }
- else if(strcmp(re->name,"outputname")==0) {
- output->name = strdup(re->value);
- }
- else if(strcmp(re->name,"outputenabled")==0) {
- output->enabled = atoi(re->value);
- }
-
- mpd_getNextReturnElement(connection);
- if(connection->error) {
- free(output);
- return NULL;
- }
-
- }
-
- return output;
-}
-
-void
-mpd_sendEnableOutputCommand(struct mpd_connection *connection, int outputId)
-{
- int len = strlen("enableoutput")+2+INTLEN+3;
- char *string = malloc(len);
- snprintf(string, len, "enableoutput \"%i\"\n", outputId);
- mpd_executeCommand(connection,string);
- free(string);
-}
-
-void
-mpd_sendDisableOutputCommand(struct mpd_connection *connection, int outputId)
-{
- int len = strlen("disableoutput")+2+INTLEN+3;
- char *string = malloc(len);
- snprintf(string, len, "disableoutput \"%i\"\n", outputId);
- mpd_executeCommand(connection,string);
- free(string);
-}
-
-void mpd_freeOutputElement(mpd_OutputEntity * output) {
- free(output->name);
- free(output);
-}
-
/**
* mpd_sendNotCommandsCommand
* odd naming, but it gets the not allowed commands
View
119 src/output.c
@@ -0,0 +1,119 @@
+/* libmpdclient
+ (c) 2003-2008 The Music Player Daemon Project
+ This project's homepage is: http://www.musicpd.org
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of the Music Player Daemon nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <mpd/output.h>
+#include <mpd/connection.h>
+
+#include <limits.h>
+#include <string.h>
+#include <stdio.h>
+
+enum {
+ INTLEN = ((sizeof(int) * CHAR_BIT + 1) / 3 + 1),
+};
+
+void
+mpd_sendOutputsCommand(struct mpd_connection *connection)
+{
+ mpd_executeCommand(connection,"outputs\n");
+}
+
+mpd_OutputEntity *
+mpd_getNextOutput(struct mpd_connection *connection)
+{
+ mpd_OutputEntity * output = NULL;
+
+ if(connection->doneProcessing || (connection->listOks &&
+ connection->doneListOk))
+ {
+ return NULL;
+ }
+
+ if(connection->error) return NULL;
+
+ output = malloc(sizeof(mpd_OutputEntity));
+ output->id = -10;
+ output->name = NULL;
+ output->enabled = 0;
+
+ if(!connection->returnElement) mpd_getNextReturnElement(connection);
+
+ while(connection->returnElement) {
+ struct mpd_return_element *re = connection->returnElement;
+ if(strcmp(re->name,"outputid")==0) {
+ if(output!=NULL && output->id>=0) return output;
+ output->id = atoi(re->value);
+ }
+ else if(strcmp(re->name,"outputname")==0) {
+ output->name = strdup(re->value);
+ }
+ else if(strcmp(re->name,"outputenabled")==0) {
+ output->enabled = atoi(re->value);
+ }
+
+ mpd_getNextReturnElement(connection);
+ if(connection->error) {
+ free(output);
+ return NULL;
+ }
+
+ }
+
+ return output;
+}
+
+void
+mpd_freeOutputElement(mpd_OutputEntity * output)
+{
+ free(output->name);
+ free(output);
+}
+
+void
+mpd_sendEnableOutputCommand(struct mpd_connection *connection, int outputId)
+{
+ int len = strlen("enableoutput")+2+INTLEN+3;
+ char *string = malloc(len);
+ snprintf(string, len, "enableoutput \"%i\"\n", outputId);
+ mpd_executeCommand(connection,string);
+ free(string);
+}
+
+void
+mpd_sendDisableOutputCommand(struct mpd_connection *connection, int outputId)
+{
+ int len = strlen("disableoutput")+2+INTLEN+3;
+ char *string = malloc(len);
+ snprintf(string, len, "disableoutput \"%i\"\n", outputId);
+ mpd_executeCommand(connection,string);
+ free(string);
+}

0 comments on commit 18edaeb

Please sign in to comment.
Something went wrong with that request. Please try again.