Permalink
Browse files

command: moved send utility functions to send.c/isend.h

  • Loading branch information...
1 parent 3b54517 commit 75ec0cf35a8057325310bc599673a2d4af65944c @MaxKellermann MaxKellermann committed Sep 10, 2009
Showing with 112 additions and 52 deletions.
  1. +1 −1 Makefile.am
  2. +1 −43 src/command.c
  3. +0 −8 src/internal.h
  4. +58 −0 src/isend.h
  5. +1 −0 src/list.c
  6. +51 −0 src/send.c
View
2 Makefile.am
@@ -56,7 +56,7 @@ src_libmpdclient_la_SOURCES = \
src/response.c \
src/run.c \
src/search.c \
- src/send.c \
+ src/send.c src/isend.h \
src/socket.c src/socket.h \
src/song.c \
src/status.c \
View
44 src/command.c
@@ -28,6 +28,7 @@
#include <mpd/command.h>
#include <mpd/send.h>
+#include "isend.h"
#include <limits.h>
#include <stdio.h>
@@ -38,49 +39,6 @@ enum {
LONGLONGLEN = (sizeof(long long) * CHAR_BIT + 1) / 3 + 1,
};
-static bool
-mpd_send_int_command(struct mpd_connection *connection, const char *command,
- int arg)
-{
- char arg_string[INTLEN];
-
- snprintf(arg_string, sizeof(arg_string), "%i", arg);
- return mpd_send_command(connection, command, arg_string, NULL);
-}
-
-static bool
-mpd_send_int2_command(struct mpd_connection *connection, const char *command,
- int arg1, int arg2)
-{
- char arg1_string[INTLEN], arg2_string[INTLEN];
-
- snprintf(arg1_string, sizeof(arg1_string), "%i", arg1);
- snprintf(arg2_string, sizeof(arg2_string), "%i", arg2);
- return mpd_send_command(connection, command,
- arg1_string, arg2_string, NULL);
-}
-
-static bool
-mpd_send_range_command(struct mpd_connection *connection, const char *command,
- unsigned arg1, unsigned arg2)
-{
- char arg_string[INTLEN*2+1];
-
- snprintf(arg_string, sizeof arg_string, "%u:%u", arg1, arg2);
- return mpd_send_command(connection, command, arg_string, NULL);
-}
-
-static bool
-mpd_send_ll_command(struct mpd_connection *connection, const char *command,
- long long arg)
-{
- char arg_string[LONGLONGLEN];
-
- snprintf(arg_string, sizeof(arg_string), "%lld", arg);
- return mpd_send_command(connection, command, arg_string, NULL);
-}
-
-
/*
* Status commands
*
View
8 src/internal.h
@@ -150,14 +150,6 @@ void
mpd_connection_sync_error(struct mpd_connection *connection);
/**
- * Sends a command without arguments to the server, but does not
- * update the "receiving" flag nor the "listOks" counter. This is
- * used internally by the command_list functions.
- */
-bool
-mpd_send_command2(struct mpd_connection *connection, const char *command);
-
-/**
* Check if it's possible to run a single command via mpd_run_X().
* This is not possible if the connection is currently sending a
* command list.
View
58 src/isend.h
@@ -0,0 +1,58 @@
+/* libmpdclient
+ (c) 2003-2009 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.
+
+ 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_ISEND_H
+#define MPD_ISEND_H
+
+struct mpd_connection;
+
+/**
+ * Sends a command without arguments to the server, but does not
+ * update the "receiving" flag nor the "listOks" counter. This is
+ * used internally by the command_list functions.
+ */
+bool
+mpd_send_command2(struct mpd_connection *connection, const char *command);
+
+bool
+mpd_send_int_command(struct mpd_connection *connection, const char *command,
+ int arg);
+
+bool
+mpd_send_int2_command(struct mpd_connection *connection, const char *command,
+ int arg1, int arg2);
+
+bool
+mpd_send_range_command(struct mpd_connection *connection, const char *command,
+ unsigned arg1, unsigned arg2);
+
+bool
+mpd_send_ll_command(struct mpd_connection *connection, const char *command,
+ long long arg);
+
+#endif
View
1 src/list.c
@@ -33,6 +33,7 @@
#include <mpd/list.h>
#include <mpd/send.h>
#include "internal.h"
+#include "isend.h"
#include <assert.h>
View
51 src/send.c
@@ -28,10 +28,19 @@
#include <mpd/send.h>
+#include "isend.h"
#include "internal.h"
#include "sync.h"
#include <stdarg.h>
+#include <limits.h>
+#include <stdio.h>
+
+/* (bits+1)/3 (plus the sign character) */
+enum {
+ INTLEN = (sizeof(int) * CHAR_BIT + 1) / 3 + 1,
+ LONGLONGLEN = (sizeof(long long) * CHAR_BIT + 1) / 3 + 1,
+};
/**
* Checks whether it is possible to send a command now.
@@ -103,3 +112,45 @@ mpd_send_command2(struct mpd_connection *connection, const char *command)
return true;
}
+
+bool
+mpd_send_int_command(struct mpd_connection *connection, const char *command,
+ int arg)
+{
+ char arg_string[INTLEN];
+
+ snprintf(arg_string, sizeof(arg_string), "%i", arg);
+ return mpd_send_command(connection, command, arg_string, NULL);
+}
+
+bool
+mpd_send_int2_command(struct mpd_connection *connection, const char *command,
+ int arg1, int arg2)
+{
+ char arg1_string[INTLEN], arg2_string[INTLEN];
+
+ snprintf(arg1_string, sizeof(arg1_string), "%i", arg1);
+ snprintf(arg2_string, sizeof(arg2_string), "%i", arg2);
+ return mpd_send_command(connection, command,
+ arg1_string, arg2_string, NULL);
+}
+
+bool
+mpd_send_range_command(struct mpd_connection *connection, const char *command,
+ unsigned arg1, unsigned arg2)
+{
+ char arg_string[INTLEN*2+1];
+
+ snprintf(arg_string, sizeof arg_string, "%u:%u", arg1, arg2);
+ return mpd_send_command(connection, command, arg_string, NULL);
+}
+
+bool
+mpd_send_ll_command(struct mpd_connection *connection, const char *command,
+ long long arg)
+{
+ char arg_string[LONGLONGLEN];
+
+ snprintf(arg_string, sizeof(arg_string), "%lld", arg);
+ return mpd_send_command(connection, command, arg_string, NULL);
+}

0 comments on commit 75ec0cf

Please sign in to comment.