annotate audacious/controlsocket.c @ 179:15c2210499ea trunk

[svn] Use GThread instead of pthread.
author chainsaw
date Sun, 13 Nov 2005 13:02:22 -0800
parents cb178e5ad177
children 763afa52f416
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"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 #include "playback.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 #include "playlist.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 #include "playlistwin.h"
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;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 if (write_all(fd, &pkthdr, sizeof(ServerPktHeader)) < sizeof(pkthdr))
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;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 guint32 info[3];
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);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 if (read_all(fd, &pkt->hdr, sizeof(ClientPktHeader))
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);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 if (read_all(fd, pkt->data, data_length) < data_length) {
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;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 case CMD_GET_OUTPUT_TIME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 if (bmp_playback_get_playing())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 ctrl_write_gint(pkt->fd, bmp_playback_get_time());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 ctrl_write_gint(pkt->fd, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 case CMD_GET_VOLUME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 input_get_volume(&v[0], &v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 ctrl_write_packet(pkt->fd, v, sizeof(v));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 case CMD_GET_BALANCE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 input_get_volume(&v[0], &v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 if (v[0] < 0 || v[1] < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 b = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 else if (v[0] > v[1])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 b = -100 + ((v[1] * 100) / v[0]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 else if (v[1] > v[0])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 b = 100 - ((v[0] * 100) / v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 b = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 ctrl_write_gint(pkt->fd, b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 case CMD_GET_SKIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 ctrl_write_string(pkt->fd, bmp_active_skin->path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 case CMD_GET_PLAYLIST_FILE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 filename = playlist_get_filename(*((guint32 *) pkt->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 ctrl_write_string(pkt->fd, filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 ctrl_write_string(pkt->fd, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 case CMD_GET_PLAYLIST_TITLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 gchar *title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 title = playlist_get_songtitle(*((guint32 *) pkt->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 ctrl_write_string(pkt->fd, title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 g_free(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 ctrl_write_string(pkt->fd, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 case CMD_GET_PLAYLIST_TIME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 if (pkt->data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 ctrl_write_gint(pkt->fd,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 playlist_get_songtime(*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 ((guint32 *) pkt->
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 data)));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 ctrl_write_gint(pkt->fd, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 case CMD_GET_INFO:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 playback_get_sample_params(&info[0], &info[1], &info[2]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 ctrl_write_packet(pkt->fd, info, 3 * sizeof(gint));
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_EQ_DATA:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 case CMD_SET_EQ_DATA:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 /* obsolete */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 case CMD_PING:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 case CMD_PLAYLIST_ADD:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 guint32 *dataptr = pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 while ((len = *dataptr) > 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 gchar *filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 dataptr++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 filename = g_malloc0(len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 memcpy(filename, dataptr, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443 playlist_add_url(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 g_free(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447 dataptr += (len + 3) / 4;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 case CMD_PLAYLIST_ADD_URL_STRING:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454 playlist_add_url(pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456
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_INS_URL_STRING:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 if (pkt->data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461 gint pos = *(gint *) pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 gchar *ptr = pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 ptr += sizeof(gint);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464 playlist_ins_url(ptr, pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 case CMD_PLAYLIST_DELETE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 playlist_delete_index(*((guint32 *) pkt->data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 case CMD_PLAYLIST_CLEAR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 playlist_clear();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 mainwin_set_info_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 case CMD_IS_MAIN_WIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 ctrl_write_gboolean(pkt->fd, cfg.player_visible);
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_IS_PL_WIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 ctrl_write_gboolean(pkt->fd, cfg.playlist_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 case CMD_IS_EQ_WIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 ctrl_write_gboolean(pkt->fd, cfg.equalizer_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 case CMD_IS_REPEAT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 ctrl_write_gboolean(pkt->fd, cfg.repeat);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 case CMD_IS_SHUFFLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 ctrl_write_gboolean(pkt->fd, cfg.shuffle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 case CMD_IS_ADVANCE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503 ctrl_write_gboolean(pkt->fd, !cfg.no_playlist_advance);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 case CMD_GET_EQ:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 fval[0] = equalizerwin_get_preamp();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 for (i = 0; i < 10; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509 fval[i + 1] = equalizerwin_get_band(i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 ctrl_write_packet(pkt->fd, fval, 11 * sizeof(gfloat));
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_GET_EQ_PREAMP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 ctrl_write_gfloat(pkt->fd, equalizerwin_get_preamp());
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_GET_EQ_BAND:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 i = *((guint32 *) pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 ctrl_write_gfloat(pkt->fd, equalizerwin_get_band(i));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 ctrl_ack_packet(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 g_mutex_lock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 packet_list = g_list_append(packet_list, pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525 ctrl_write_packet(pkt->fd, NULL, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 close(pkt->fd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 g_mutex_unlock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 g_thread_exit(NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 /* Used to suppress GCC warnings. Sometimes you'd wish C has
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 native threading support :p */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 ctrlsocket_check(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 GList *pkt_list, *next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 PacketNode *pkt;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 gpointer data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 guint32 v[2], i, num;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 gboolean tbool;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 gfloat *fval, f;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548 g_mutex_lock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 for (pkt_list = packet_list; pkt_list; pkt_list = next) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 pkt = pkt_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 data = pkt->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553 switch (pkt->hdr.command) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 case CMD_PLAY:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 if (bmp_playback_get_paused())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 bmp_playback_pause();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 else if (playlist_get_length())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 mainwin_eject_pushed();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 case CMD_PAUSE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 bmp_playback_pause();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 case CMD_STOP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566 bmp_playback_stop();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 mainwin_clear_song_info();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569 case CMD_PLAY_PAUSE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570 if (bmp_playback_get_playing())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 bmp_playback_pause();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575 case CMD_PLAYQUEUE_ADD:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576 num = *((guint32 *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577 if (num < playlist_get_length())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578 playlist_queue_position(num);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580 case CMD_PLAYQUEUE_REMOVE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581 num = *((guint32 *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582 if (num < playlist_get_length())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583 playlist_queue_remove(num);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 case CMD_SET_PLAYLIST_POS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 num = *((guint32 *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587 if (num < playlist_get_length())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588 playlist_set_position(num);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590 case CMD_JUMP_TO_TIME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591 num = *((guint32 *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592 if (playlist_get_current_length() > 0 &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
593 num < playlist_get_current_length())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594 bmp_playback_seek(num / 1000);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
595 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596 case CMD_SET_VOLUME:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597 v[0] = ((guint32 *) data)[0];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598 v[1] = ((guint32 *) data)[1];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599 for (i = 0; i < 2; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600 if (v[i] > 100)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601 v[i] = 100;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603 input_set_volume(v[0], v[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605 case CMD_SET_SKIN:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
606 bmp_active_skin_load(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608 case CMD_PL_WIN_TOGGLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
610 if (tbool)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
611 playlistwin_show();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
612 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 playlistwin_hide();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
614 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
615 case CMD_EQ_WIN_TOGGLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
616 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617 equalizerwin_show(!!tbool);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
618 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
619 case CMD_SHOW_PREFS_BOX:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
620 show_prefs_window();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 case CMD_TOGGLE_AOT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624 mainwin_set_always_on_top(tbool);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
625 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 case CMD_SHOW_ABOUT_BOX:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628 case CMD_EJECT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629 mainwin_eject_pushed();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631 case CMD_PLAYLIST_PREV:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632 playlist_prev();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634 case CMD_PLAYLIST_NEXT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635 playlist_next();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637 case CMD_TOGGLE_REPEAT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
638 mainwin_repeat_pushed(!cfg.repeat);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
639 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 case CMD_TOGGLE_SHUFFLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641 mainwin_shuffle_pushed(!cfg.shuffle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
642 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
643 case CMD_TOGGLE_ADVANCE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644 /* FIXME: to be implemented */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646 case CMD_MAIN_WIN_TOGGLE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647 tbool = *((gboolean *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 mainwin_show(!!tbool);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 case CMD_SET_EQ:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
651 if (pkt->hdr.data_length >= 11 * sizeof(gfloat)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
652 fval = (gfloat *) data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
653 equalizerwin_set_preamp(fval[0]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
654 for (i = 0; i < 10; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
655 equalizerwin_set_band(i, fval[i + 1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
656 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
657 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
658 case CMD_SET_EQ_PREAMP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
659 f = *((gfloat *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660 equalizerwin_set_preamp(f);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
661 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
662 case CMD_SET_EQ_BAND:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
663 if (pkt->hdr.data_length >= sizeof(gint) + sizeof(gfloat)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
664 i = *((gint *) data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
665 f = *((gfloat *) ((gchar *) data + sizeof(gint)));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 equalizerwin_set_band(i, f);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
667 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
668 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669 case CMD_QUIT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671 * We unlock the packet_list_mutex to
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672 * avoid that cleanup_ctrlsocket() can
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673 * deadlock, mainwin_quit_cb() will
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674 * never return anyway, so this will
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
675 * work ok.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
676 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677 g_mutex_unlock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678 mainwin_quit_cb();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680 case CMD_ACTIVATE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681 gtk_window_present(GTK_WINDOW(mainwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 g_message("Unknown socket command received");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
686 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 next = g_list_next(pkt_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688 packet_list = g_list_remove_link(packet_list, pkt_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689 g_list_free_1(pkt_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 if (pkt->data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
691 g_free(pkt->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
692 g_free(pkt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
694 g_mutex_unlock(packet_list_mutex);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
695 }