annotate audacious/controlsocket.c @ 1267:d5361c48bb18 trunk

[svn] - more fun
author nenolod
date Thu, 15 Jun 2006 22:13:55 -0700
parents bcd1ebd0a7c1
children 2f714bee0645
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "controlsocket.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include <errno.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #include <sys/time.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include <sys/types.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include <sys/socket.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <sys/un.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #include "main.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #include "equalizer.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 #include "mainwin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 #include "input.h"
538
e4e897d20791 [svn] remove libaudcore, we never did anything with it
nenolod
parents: 383
diff changeset
39 #include "playback.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 #include "playlist.h"
383
5c457dac866a [svn] - Rename playlistwin stuff to ui_playlist.*
nenolod
parents: 377
diff changeset
41 #include "ui_playlist.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 #include "prefswin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 #include "skin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 #include "libaudacious/beepctrl.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 #define CTRLSOCKET_BACKLOG 100
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 #define CTRLSOCKET_TIMEOUT 100000
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 static gint session_id = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 static gint ctrl_fd = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 static gchar *socket_name = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 static gpointer ctrlsocket_func(gpointer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 static GThread *ctrlsocket_thread;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 static GList *packet_list = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 static GMutex *packet_list_mutex = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 static gboolean started = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 static gboolean going = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 static GCond *start_cond = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 static GMutex *status_mutex = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 ctrlsocket_start_thread(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 start_cond = g_cond_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 status_mutex = g_mutex_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 packet_list_mutex = g_mutex_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 ctrlsocket_thread = g_thread_create(ctrlsocket_func, NULL, TRUE, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 ctrlsocket_setup(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 struct sockaddr_un saddr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 gint fd;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 g_critical("ctrlsocket_setup(): Failed to open socket: %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 strerror(errno));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 for (i = 0;; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 saddr.sun_family = AF_UNIX;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 "%s/%s_%s.%d", g_get_tmp_dir(),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 CTRLSOCKET_NAME, g_get_user_name(), i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 if (xmms_remote_is_running(i)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 if (cfg.allow_multiple_instances)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 if ((unlink(saddr.sun_path) == -1) && errno != ENOENT) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 g_critical
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 ("ctrlsocket_setup(): Failed to unlink %s (Error: %s)",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 saddr.sun_path, strerror(errno));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 if (bind(fd, (struct sockaddr *) &saddr, sizeof(saddr)) == -1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 g_critical
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 ("ctrlsocket_setup(): Failed to assign %s to a socket (Error: %s)",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 saddr.sun_path, strerror(errno));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 listen(fd, CTRLSOCKET_BACKLOG);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 socket_name = g_strdup(saddr.sun_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 ctrl_fd = fd;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 session_id = i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 going = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 ctrlsocket_start_thread();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 close(fd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 ctrlsocket_get_session_id(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 return session_id;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 ctrlsocket_cleanup(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 if (ctrl_fd) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 g_mutex_lock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 going = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 g_cond_signal(start_cond);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 g_mutex_unlock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 /* wait for ctrlsocket_thread to terminate */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 g_thread_join(ctrlsocket_thread);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 /* close and remove socket */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 close(ctrl_fd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 ctrl_fd = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 unlink(socket_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 g_free(socket_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 g_cond_free(start_cond);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 g_mutex_free(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 g_mutex_free(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 ctrlsocket_start(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 /* tell control socket thread to go 'live' i.e. start handling
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 * packets */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 g_mutex_lock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 started = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 g_cond_signal(start_cond);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 g_mutex_unlock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 write_all(gint fd, gconstpointer buf, size_t count)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 size_t left = count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 GTimer *timer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 gulong usec;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 gint written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 timer = g_timer_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 do {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 if ((written = write(fd, buf, left)) < 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 count = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 left -= written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 buf = (gchar *) buf + written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 g_timer_elapsed(timer, &usec);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 g_timer_destroy(timer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 return count - left;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 ctrl_write_packet(gint fd, gpointer data, gint length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 ServerPktHeader pkthdr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 pkthdr.version = XMMS_PROTOCOL_VERSION;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 pkthdr.data_length = length;
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
207 if ((size_t)write_all(fd, &pkthdr, sizeof(ServerPktHeader)) < sizeof(pkthdr))
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 if (data && length > 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 write_all(fd, data, length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 ctrl_write_gint(gint fd, gint val)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 ctrl_write_packet(fd, &val, sizeof(gint));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 ctrl_write_gfloat(gint fd, gfloat val)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 ctrl_write_packet(fd, &val, sizeof(gfloat));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 ctrl_write_gboolean(gint fd, gboolean bool)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 ctrl_write_packet(fd, &bool, sizeof(gboolean));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 ctrl_write_string(gint fd, gchar * string)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 ctrl_write_packet(fd, string, string ? strlen(string) + 1 : 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 ctrl_ack_packet(PacketNode * pkt)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 ctrl_write_packet(pkt->fd, NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 close(pkt->fd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 if (pkt->data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 g_free(pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 g_free(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 static gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 read_all(gint fd, gpointer buf, size_t count)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 size_t left = count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 GTimer *timer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 gulong usec;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 gint r;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 timer = g_timer_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 do {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 if ((r = read(fd, buf, left)) < 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 count = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 left -= r;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 buf = (gchar *) buf + r;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 g_timer_elapsed(timer, &usec);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 g_timer_destroy(timer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 return count - left;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 ctrlsocket_is_going(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 gboolean result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 g_mutex_lock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 result = going;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 g_mutex_unlock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 return result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 static gpointer
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 ctrlsocket_func(gpointer arg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 fd_set set;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 struct timeval tv;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 struct sockaddr_un saddr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 gint fd, b, i;
377
4e1d41a93cb3 [svn] Start caring about pointer signedness.
chainsaw
parents: 284
diff changeset
291 gint info[3];
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 gint32 v[2];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 PacketNode *pkt;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 socklen_t len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 gfloat fval[11];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 g_mutex_lock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 while (!started && going)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 g_cond_wait(start_cond, status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 g_mutex_unlock(status_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 while (ctrlsocket_is_going()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 FD_ZERO(&set);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 FD_SET(ctrl_fd, &set);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 tv.tv_sec = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 tv.tv_usec = CTRLSOCKET_TIMEOUT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 len = sizeof(saddr);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 if (select(ctrl_fd + 1, &set, NULL, NULL, &tv) <= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 if ((fd = accept(ctrl_fd, (struct sockaddr *) &saddr, &len)) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 pkt = g_new0(PacketNode, 1);
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
314 if ((size_t)read_all(fd, &pkt->hdr, sizeof(ClientPktHeader))
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 < sizeof(ClientPktHeader)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 g_free(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 if (pkt->hdr.data_length) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 size_t data_length = pkt->hdr.data_length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 pkt->data = g_malloc0(data_length);
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
323 if ((size_t)read_all(fd, pkt->data, data_length) < data_length) {
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 g_free(pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 g_free(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 g_warning("ctrlsocket_func(): Incomplete data packet dropped");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 pkt->fd = fd;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 switch (pkt->hdr.command) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 case CMD_GET_VERSION:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 ctrl_write_gint(pkt->fd, 0x09a3);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 case CMD_IS_PLAYING:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 ctrl_write_gboolean(pkt->fd, bmp_playback_get_playing());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 case CMD_IS_PAUSED:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 ctrl_write_gboolean(pkt->fd, bmp_playback_get_paused());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 case CMD_GET_PLAYLIST_POS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 ctrl_write_gint(pkt->fd, playlist_get_position());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 case CMD_GET_PLAYLIST_LENGTH:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 ctrl_write_gint(pkt->fd, playlist_get_length());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 case CMD_GET_PLAYQUEUE_LENGTH:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 ctrl_write_gint(pkt->fd, playlist_queue_get_length());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 break;
984
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
357 case CMD_PLAYQUEUE_IS_QUEUED:
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
358 ctrl_write_gboolean(pkt->fd,
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
359 playlist_is_position_queued(*((guint32 *) pkt->data)));
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
360 ctrl_ack_packet(pkt);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
361 break;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
362 case CMD_PLAYQUEUE_GET_POS:
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
363 if (pkt->data)
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
364 ctrl_write_gint(pkt->fd,
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
365 playlist_get_queue_position_number(*
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
366 ((guint32 *) pkt->
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
367 data)));
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
368 else
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
369 ctrl_write_gint(pkt->fd, 0);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
370
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
371 ctrl_ack_packet(pkt);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
372 break;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
373 case CMD_PLAYQUEUE_GET_QPOS:
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
374 if (pkt->data)
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
375 ctrl_write_gint(pkt->fd,
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
376 playlist_get_queue_qposition_number(*
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
377 ((guint32 *) pkt->
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
378 data)));
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
379 else
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
380 ctrl_write_gint(pkt->fd, 0);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
381
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
382 ctrl_ack_packet(pkt);
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
383 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 case CMD_GET_OUTPUT_TIME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 if (bmp_playback_get_playing())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 ctrl_write_gint(pkt->fd, bmp_playback_get_time());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 ctrl_write_gint(pkt->fd, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 case CMD_GET_VOLUME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 input_get_volume(&v[0], &v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 ctrl_write_packet(pkt->fd, v, sizeof(v));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 case CMD_GET_BALANCE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 input_get_volume(&v[0], &v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 if (v[0] < 0 || v[1] < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 b = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 else if (v[0] > v[1])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 b = -100 + ((v[1] * 100) / v[0]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 else if (v[1] > v[0])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 b = 100 - ((v[0] * 100) / v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 b = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 ctrl_write_gint(pkt->fd, b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 case CMD_GET_SKIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 ctrl_write_string(pkt->fd, bmp_active_skin->path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 case CMD_GET_PLAYLIST_FILE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416 filename = playlist_get_filename(*((guint32 *) pkt->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 ctrl_write_string(pkt->fd, filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 ctrl_write_string(pkt->fd, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424 case CMD_GET_PLAYLIST_TITLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 gchar *title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 title = playlist_get_songtitle(*((guint32 *) pkt->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 ctrl_write_string(pkt->fd, title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 g_free(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 ctrl_write_string(pkt->fd, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 case CMD_GET_PLAYLIST_TIME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 if (pkt->data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 ctrl_write_gint(pkt->fd,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 playlist_get_songtime(*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 ((guint32 *) pkt->
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 data)));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 ctrl_write_gint(pkt->fd, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 case CMD_GET_INFO:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447 playback_get_sample_params(&info[0], &info[1], &info[2]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 ctrl_write_packet(pkt->fd, info, 3 * sizeof(gint));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 case CMD_GET_EQ_DATA:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 case CMD_SET_EQ_DATA:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453 /* obsolete */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456 case CMD_PING:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459 case CMD_PLAYLIST_ADD:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461 guint32 *dataptr = pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 while ((len = *dataptr) > 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 dataptr++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 filename = g_malloc0(len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 memcpy(filename, dataptr, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 playlist_add_url(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 dataptr += (len + 3) / 4;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 case CMD_PLAYLIST_ADD_URL_STRING:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 playlist_add_url(pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 case CMD_PLAYLIST_INS_URL_STRING:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 gint pos = *(gint *) pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 gchar *ptr = pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 ptr += sizeof(gint);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 playlist_ins_url(ptr, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 case CMD_PLAYLIST_DELETE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 playlist_delete_index(*((guint32 *) pkt->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 case CMD_PLAYLIST_CLEAR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503 playlist_clear();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509 case CMD_IS_MAIN_WIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 ctrl_write_gboolean(pkt->fd, cfg.player_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513 case CMD_IS_PL_WIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 ctrl_write_gboolean(pkt->fd, cfg.playlist_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517 case CMD_IS_EQ_WIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 ctrl_write_gboolean(pkt->fd, cfg.equalizer_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 case CMD_IS_REPEAT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522 ctrl_write_gboolean(pkt->fd, cfg.repeat);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525 case CMD_IS_SHUFFLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 ctrl_write_gboolean(pkt->fd, cfg.shuffle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 case CMD_IS_ADVANCE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 ctrl_write_gboolean(pkt->fd, !cfg.no_playlist_advance);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 case CMD_GET_EQ:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 fval[0] = equalizerwin_get_preamp();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 for (i = 0; i < 10; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 fval[i + 1] = equalizerwin_get_band(i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 ctrl_write_packet(pkt->fd, fval, 11 * sizeof(gfloat));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540 case CMD_GET_EQ_PREAMP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 ctrl_write_gfloat(pkt->fd, equalizerwin_get_preamp());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 case CMD_GET_EQ_BAND:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 i = *((guint32 *) pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 ctrl_write_gfloat(pkt->fd, equalizerwin_get_band(i));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 g_mutex_lock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 packet_list = g_list_append(packet_list, pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552 ctrl_write_packet(pkt->fd, NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553 close(pkt->fd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 g_mutex_unlock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 g_thread_exit(NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 /* Used to suppress GCC warnings. Sometimes you'd wish C has
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 native threading support :p */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566 ctrlsocket_check(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 GList *pkt_list, *next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569 PacketNode *pkt;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570 gpointer data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 guint32 v[2], i, num;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 gboolean tbool;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 gfloat *fval, f;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575 g_mutex_lock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576 for (pkt_list = packet_list; pkt_list; pkt_list = next) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577 pkt = pkt_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578 data = pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580 switch (pkt->hdr.command) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581 case CMD_PLAY:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582 if (bmp_playback_get_paused())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583 bmp_playback_pause();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584 else if (playlist_get_length())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587 mainwin_eject_pushed();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589 case CMD_PAUSE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590 bmp_playback_pause();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592 case CMD_STOP:
906
704c0b2e5f6b [svn] - this should be it for now
nhjm449
parents: 680
diff changeset
593 ip_data.stop = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594 bmp_playback_stop();
906
704c0b2e5f6b [svn] - this should be it for now
nhjm449
parents: 680
diff changeset
595 ip_data.stop = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598 case CMD_PLAY_PAUSE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599 if (bmp_playback_get_playing())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600 bmp_playback_pause();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604 case CMD_PLAYQUEUE_ADD:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605 num = *((guint32 *) data);
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
606 if (num < (guint)playlist_get_length())
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607 playlist_queue_position(num);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 case CMD_PLAYQUEUE_REMOVE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
610 num = *((guint32 *) data);
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
611 if (num < (guint)playlist_get_length())
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
612 playlist_queue_remove(num);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 break;
984
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
614 case CMD_PLAYQUEUE_CLEAR:
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
615 playlist_clear_queue();
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
616 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617 case CMD_SET_PLAYLIST_POS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
618 num = *((guint32 *) data);
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
619 if (num < (guint)playlist_get_length())
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
620 playlist_set_position(num);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 case CMD_JUMP_TO_TIME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623 num = *((guint32 *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624 if (playlist_get_current_length() > 0 &&
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
625 num < (guint)playlist_get_current_length())
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 bmp_playback_seek(num / 1000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628 case CMD_SET_VOLUME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629 v[0] = ((guint32 *) data)[0];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630 v[1] = ((guint32 *) data)[1];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631 for (i = 0; i < 2; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632 if (v[i] > 100)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633 v[i] = 100;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635 input_set_volume(v[0], v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637 case CMD_SET_SKIN:
680
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
638 if (has_x11_connection == TRUE)
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
639 bmp_active_skin_load(data);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641 case CMD_PL_WIN_TOGGLE:
680
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
642 if (has_x11_connection != TRUE)
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
643 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645 if (tbool)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646 playlistwin_show();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 playlistwin_hide();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 case CMD_EQ_WIN_TOGGLE:
680
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
651 if (has_x11_connection != TRUE)
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
652 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
653 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
654 equalizerwin_show(!!tbool);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
655 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
656 case CMD_SHOW_PREFS_BOX:
680
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
657 if (has_x11_connection != TRUE)
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
658 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
659 show_prefs_window();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660 break;
984
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
661 case CMD_SHOW_JTF_BOX:
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
662 if (has_x11_connection != TRUE)
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
663 break;
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
664 mainwin_jump_to_file();
bcd1ebd0a7c1 [svn] - jumptofile and queue support fun
nhjm449
parents: 906
diff changeset
665 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 case CMD_TOGGLE_AOT:
680
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
667 if (has_x11_connection != TRUE)
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
668 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670 mainwin_set_always_on_top(tbool);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672 case CMD_SHOW_ABOUT_BOX:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674 case CMD_EJECT:
680
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
675 if (has_x11_connection != TRUE)
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
676 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677 mainwin_eject_pushed();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679 case CMD_PLAYLIST_PREV:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680 playlist_prev();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682 case CMD_PLAYLIST_NEXT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 playlist_next();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685 case CMD_TOGGLE_REPEAT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
686 mainwin_repeat_pushed(!cfg.repeat);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688 case CMD_TOGGLE_SHUFFLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689 mainwin_shuffle_pushed(!cfg.shuffle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
691 case CMD_TOGGLE_ADVANCE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
692 /* FIXME: to be implemented */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
694 case CMD_MAIN_WIN_TOGGLE:
680
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
695 if (has_x11_connection != TRUE)
8282b365f6cb [svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents: 625
diff changeset
696 break;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
697 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
698 mainwin_show(!!tbool);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
699 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
700 case CMD_SET_EQ:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
701 if (pkt->hdr.data_length >= 11 * sizeof(gfloat)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
702 fval = (gfloat *) data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
703 equalizerwin_set_preamp(fval[0]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
704 for (i = 0; i < 10; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
705 equalizerwin_set_band(i, fval[i + 1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
706 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
707 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
708 case CMD_SET_EQ_PREAMP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
709 f = *((gfloat *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
710 equalizerwin_set_preamp(f);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
711 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
712 case CMD_SET_EQ_BAND:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
713 if (pkt->hdr.data_length >= sizeof(gint) + sizeof(gfloat)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
714 i = *((gint *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
715 f = *((gfloat *) ((gchar *) data + sizeof(gint)));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
716 equalizerwin_set_band(i, f);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
717 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
718 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
719 case CMD_QUIT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
720 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
721 * We unlock the packet_list_mutex to
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
722 * avoid that cleanup_ctrlsocket() can
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
723 * deadlock, mainwin_quit_cb() will
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
724 * never return anyway, so this will
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
725 * work ok.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
726 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
727 g_mutex_unlock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
728 mainwin_quit_cb();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
729 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
730 case CMD_ACTIVATE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
731 gtk_window_present(GTK_WINDOW(mainwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
732 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
733 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
734 g_message("Unknown socket command received");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
735 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
736 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
737 next = g_list_next(pkt_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
738 packet_list = g_list_remove_link(packet_list, pkt_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
739 g_list_free_1(pkt_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
740 if (pkt->data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
741 g_free(pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
742 g_free(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
743 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
744 g_mutex_unlock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
745 }