Mercurial > audlegacy
annotate libaudacious/beepctrl.c @ 945:6b3750ab5eab trunk
[svn] - Tiny fix
author | nhjm449 |
---|---|
date | Sun, 16 Apr 2006 17:51:07 -0700 |
parents | 0a73d1faeb4e |
children | bcd1ebd0a7c1 |
rev | line source |
---|---|
0 | 1 /* XMMS - Cross-platform multimedia player |
2 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
3 * Thomas Nilsson and 4Front Technologies | |
4 * Copyright (C) 1999-2003 Haavard Kvaalen | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 */ | |
20 | |
21 #ifdef HAVE_CONFIG_H | |
22 # include "config.h" | |
23 #endif | |
24 | |
25 #include <glib.h> | |
26 #include <sys/types.h> | |
27 #include <sys/stat.h> | |
28 #include <sys/socket.h> | |
29 #include <sys/un.h> | |
30 #include <errno.h> | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 #include <string.h> | |
34 #include "beepctrl.h" | |
35 #include "audacious/controlsocket.h" | |
36 | |
37 | |
38 #ifdef HAVE_UNISTD_H | |
39 #include <unistd.h> | |
40 #endif | |
41 | |
42 static gint | |
43 read_all(gint fd, gpointer buf, size_t count) | |
44 { | |
45 size_t left = count; | |
46 GTimer *timer; | |
47 gulong usec; | |
48 gint r; | |
49 | |
50 timer = g_timer_new(); | |
51 | |
52 do { | |
53 if ((r = read(fd, buf, left)) < 0) { | |
54 count = -1; | |
55 break; | |
56 } | |
57 left -= r; | |
58 buf = (gchar *) buf + r; | |
59 g_timer_elapsed(timer, &usec); | |
60 } | |
61 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC); | |
62 | |
63 g_timer_destroy(timer); | |
64 return count - left; | |
65 } | |
66 | |
67 static gint | |
68 write_all(gint fd, gconstpointer buf, size_t count) | |
69 { | |
70 size_t left = count; | |
71 GTimer *timer; | |
72 gulong usec; | |
73 gint written; | |
74 | |
75 timer = g_timer_new(); | |
76 | |
77 do { | |
78 if ((written = write(fd, buf, left)) < 0) { | |
79 count = -1; | |
80 break; | |
81 } | |
82 left -= written; | |
83 buf = (gchar *) buf + written; | |
84 g_timer_elapsed(timer, &usec); | |
85 } | |
86 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC); | |
87 | |
88 g_timer_destroy(timer); | |
89 return count - left; | |
90 } | |
91 | |
92 static gpointer | |
93 remote_read_packet(gint fd, ServerPktHeader * pkt_hdr) | |
94 { | |
95 gpointer data = NULL; | |
96 | |
97 if (read_all(fd, pkt_hdr, sizeof(ServerPktHeader)) == | |
98 sizeof(ServerPktHeader)) { | |
99 if (pkt_hdr->data_length) { | |
100 size_t data_length = pkt_hdr->data_length; | |
101 data = g_malloc0(data_length); | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
0
diff
changeset
|
102 if ((size_t)read_all(fd, data, data_length) < data_length) { |
0 | 103 g_free(data); |
104 data = NULL; | |
105 } | |
106 } | |
107 } | |
108 return data; | |
109 } | |
110 | |
111 static void | |
112 remote_read_ack(gint fd) | |
113 { | |
114 gpointer data; | |
115 ServerPktHeader pkt_hdr; | |
116 | |
117 data = remote_read_packet(fd, &pkt_hdr); | |
118 if (data) | |
119 g_free(data); | |
120 | |
121 } | |
122 | |
123 static void | |
124 remote_send_packet(gint fd, guint32 command, gpointer data, | |
125 guint32 data_length) | |
126 { | |
127 ClientPktHeader pkt_hdr; | |
128 | |
129 pkt_hdr.version = XMMS_PROTOCOL_VERSION; | |
130 pkt_hdr.command = command; | |
131 pkt_hdr.data_length = data_length; | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
0
diff
changeset
|
132 if ((size_t)write_all(fd, &pkt_hdr, sizeof(ClientPktHeader)) < sizeof(pkt_hdr)) |
0 | 133 return; |
134 if (data_length && data) | |
135 write_all(fd, data, data_length); | |
136 } | |
137 | |
138 static void | |
139 remote_send_guint32(gint session, guint32 cmd, guint32 val) | |
140 { | |
141 gint fd; | |
142 | |
143 if ((fd = xmms_connect_to_session(session)) == -1) | |
144 return; | |
145 remote_send_packet(fd, cmd, &val, sizeof(guint32)); | |
146 remote_read_ack(fd); | |
147 close(fd); | |
148 } | |
149 | |
150 static void | |
151 remote_send_boolean(gint session, guint32 cmd, gboolean val) | |
152 { | |
153 gint fd; | |
154 | |
155 if ((fd = xmms_connect_to_session(session)) == -1) | |
156 return; | |
157 remote_send_packet(fd, cmd, &val, sizeof(gboolean)); | |
158 remote_read_ack(fd); | |
159 close(fd); | |
160 } | |
161 | |
162 static void | |
163 remote_send_gfloat(gint session, guint32 cmd, gfloat value) | |
164 { | |
165 gint fd; | |
166 | |
167 if ((fd = xmms_connect_to_session(session)) == -1) | |
168 return; | |
169 remote_send_packet(fd, cmd, &value, sizeof(gfloat)); | |
170 remote_read_ack(fd); | |
171 close(fd); | |
172 } | |
173 | |
174 static void | |
175 remote_send_string(gint session, guint32 cmd, gchar * string) | |
176 { | |
177 gint fd; | |
178 | |
179 if ((fd = xmms_connect_to_session(session)) == -1) | |
180 return; | |
181 remote_send_packet(fd, cmd, string, string ? strlen(string) + 1 : 0); | |
182 remote_read_ack(fd); | |
183 close(fd); | |
184 } | |
185 | |
186 static gboolean | |
187 remote_cmd(gint session, guint32 cmd) | |
188 { | |
189 gint fd; | |
190 | |
191 if ((fd = xmms_connect_to_session(session)) == -1) | |
192 return FALSE; | |
193 remote_send_packet(fd, cmd, NULL, 0); | |
194 remote_read_ack(fd); | |
195 close(fd); | |
196 | |
197 return TRUE; | |
198 } | |
199 | |
200 static gboolean | |
201 remote_get_gboolean(gint session, gint cmd) | |
202 { | |
203 ServerPktHeader pkt_hdr; | |
204 gboolean ret = FALSE; | |
205 gpointer data; | |
206 gint fd; | |
207 | |
208 if ((fd = xmms_connect_to_session(session)) == -1) | |
209 return ret; | |
210 remote_send_packet(fd, cmd, NULL, 0); | |
211 data = remote_read_packet(fd, &pkt_hdr); | |
212 if (data) { | |
213 ret = *((gboolean *) data); | |
214 g_free(data); | |
215 } | |
216 remote_read_ack(fd); | |
217 close(fd); | |
218 | |
219 return ret; | |
220 } | |
221 | |
222 static guint32 | |
223 remote_get_gint(gint session, gint cmd) | |
224 { | |
225 ServerPktHeader pkt_hdr; | |
226 gpointer data; | |
227 gint fd, ret = 0; | |
228 | |
229 if ((fd = xmms_connect_to_session(session)) == -1) | |
230 return ret; | |
231 remote_send_packet(fd, cmd, NULL, 0); | |
232 data = remote_read_packet(fd, &pkt_hdr); | |
233 if (data) { | |
234 ret = *((gint *) data); | |
235 g_free(data); | |
236 } | |
237 remote_read_ack(fd); | |
238 close(fd); | |
239 return ret; | |
240 } | |
241 | |
242 static gfloat | |
243 remote_get_gfloat(gint session, gint cmd) | |
244 { | |
245 ServerPktHeader pkt_hdr; | |
246 gpointer data; | |
247 gint fd; | |
248 gfloat ret = 0.0; | |
249 | |
250 if ((fd = xmms_connect_to_session(session)) == -1) | |
251 return ret; | |
252 remote_send_packet(fd, cmd, NULL, 0); | |
253 data = remote_read_packet(fd, &pkt_hdr); | |
254 if (data) { | |
255 ret = *((gfloat *) data); | |
256 g_free(data); | |
257 } | |
258 remote_read_ack(fd); | |
259 close(fd); | |
260 return ret; | |
261 } | |
262 | |
263 gchar * | |
264 remote_get_string(gint session, gint cmd) | |
265 { | |
266 ServerPktHeader pkt_hdr; | |
267 gpointer data; | |
268 gint fd; | |
269 | |
270 if ((fd = xmms_connect_to_session(session)) == -1) | |
271 return NULL; | |
272 remote_send_packet(fd, cmd, NULL, 0); | |
273 data = remote_read_packet(fd, &pkt_hdr); | |
274 remote_read_ack(fd); | |
275 close(fd); | |
276 return data; | |
277 } | |
278 | |
279 gchar * | |
280 remote_get_string_pos(gint session, gint cmd, guint32 pos) | |
281 { | |
282 ServerPktHeader pkt_hdr; | |
283 gpointer data; | |
284 gint fd; | |
285 | |
286 if ((fd = xmms_connect_to_session(session)) == -1) | |
287 return NULL; | |
288 remote_send_packet(fd, cmd, &pos, sizeof(guint32)); | |
289 data = remote_read_packet(fd, &pkt_hdr); | |
290 remote_read_ack(fd); | |
291 close(fd); | |
292 return data; | |
293 } | |
294 | |
295 gint | |
296 xmms_connect_to_session(gint session) | |
297 { | |
298 gint fd; | |
299 uid_t stored_uid, euid; | |
300 struct sockaddr_un saddr; | |
301 | |
302 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { | |
303 saddr.sun_family = AF_UNIX; | |
304 stored_uid = getuid(); | |
305 euid = geteuid(); | |
306 setuid(euid); | |
307 g_snprintf(saddr.sun_path, 108, "%s/%s_%s.%d", g_get_tmp_dir(), | |
308 CTRLSOCKET_NAME, g_get_user_name(), session); | |
309 setreuid(stored_uid, euid); | |
310 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) | |
311 return fd; | |
312 } | |
313 close(fd); | |
314 return -1; | |
315 } | |
316 | |
317 void | |
318 xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue) | |
319 { | |
320 gint fd, i; | |
321 gchar *data, *ptr; | |
322 gint data_length; | |
323 guint32 len; | |
324 | |
325 g_return_if_fail(list != NULL); | |
326 g_return_if_fail(num > 0); | |
327 | |
328 if (!enqueue) | |
329 xmms_remote_playlist_clear(session); | |
330 | |
331 if ((fd = xmms_connect_to_session(session)) == -1) | |
332 return; | |
333 | |
334 for (i = 0, data_length = 0; i < num; i++) | |
335 data_length += (((strlen(list[i]) + 1) + 3) / 4) * 4 + 4; | |
336 if (data_length) { | |
337 data_length += 4; | |
338 data = g_malloc(data_length); | |
339 for (i = 0, ptr = data; i < num; i++) { | |
340 len = strlen(list[i]) + 1; | |
341 *((guint32 *) ptr) = len; | |
342 ptr += 4; | |
343 memcpy(ptr, list[i], len); | |
344 ptr += ((len + 3) / 4) * 4; | |
345 } | |
346 *((guint32 *) ptr) = 0; | |
347 remote_send_packet(fd, CMD_PLAYLIST_ADD, data, data_length); | |
348 remote_read_ack(fd); | |
349 close(fd); | |
350 g_free(data); | |
351 } | |
352 | |
353 if (!enqueue) | |
354 xmms_remote_play(session); | |
355 } | |
356 | |
357 gint | |
358 xmms_remote_get_version(gint session) | |
359 { | |
360 return remote_get_gint(session, CMD_GET_VERSION); | |
361 } | |
362 | |
363 void | |
364 xmms_remote_play_files(gint session, GList * list) | |
365 { | |
366 g_return_if_fail(list != NULL); | |
367 | |
368 xmms_remote_playlist_clear(session); | |
369 xmms_remote_add_files(session, list); | |
370 xmms_remote_play(session); | |
371 } | |
372 | |
373 void | |
374 xmms_remote_playlist_add(gint session, GList * list) | |
375 { | |
376 gchar **str_list; | |
377 GList *node; | |
378 gint i, num; | |
379 | |
380 g_return_if_fail(list != NULL); | |
381 | |
382 num = g_list_length(list); | |
383 str_list = g_malloc0(num * sizeof(gchar *)); | |
384 for (i = 0, node = list; i < num && node; i++, node = g_list_next(node)) | |
385 str_list[i] = node->data; | |
386 | |
387 xmms_remote_playlist(session, str_list, num, TRUE); | |
388 g_free(str_list); | |
389 } | |
390 | |
391 void | |
392 xmms_remote_playlist_delete(gint session, gint pos) | |
393 { | |
394 remote_send_guint32(session, CMD_PLAYLIST_DELETE, pos); | |
395 } | |
396 | |
397 void | |
398 xmms_remote_play(gint session) | |
399 { | |
400 remote_cmd(session, CMD_PLAY); | |
401 } | |
402 | |
403 void | |
404 xmms_remote_pause(gint session) | |
405 { | |
406 remote_cmd(session, CMD_PAUSE); | |
407 } | |
408 | |
409 void | |
410 xmms_remote_stop(gint session) | |
411 { | |
412 remote_cmd(session, CMD_STOP); | |
413 } | |
414 | |
415 void | |
416 xmms_remote_play_pause(gint session) | |
417 { | |
418 remote_cmd(session, CMD_PLAY_PAUSE); | |
419 } | |
420 | |
421 gboolean | |
422 xmms_remote_is_playing(gint session) | |
423 { | |
424 return remote_get_gboolean(session, CMD_IS_PLAYING); | |
425 } | |
426 | |
427 gboolean | |
428 xmms_remote_is_paused(gint session) | |
429 { | |
430 return remote_get_gboolean(session, CMD_IS_PAUSED); | |
431 } | |
432 | |
433 gint | |
434 xmms_remote_get_playlist_pos(gint session) | |
435 { | |
436 return remote_get_gint(session, CMD_GET_PLAYLIST_POS); | |
437 } | |
438 | |
439 void | |
440 xmms_remote_set_playlist_pos(gint session, gint pos) | |
441 { | |
442 remote_send_guint32(session, CMD_SET_PLAYLIST_POS, pos); | |
443 } | |
444 | |
445 gint | |
446 xmms_remote_get_playlist_length(gint session) | |
447 { | |
448 return remote_get_gint(session, CMD_GET_PLAYLIST_LENGTH); | |
449 } | |
450 | |
451 void | |
452 xmms_remote_playlist_clear(gint session) | |
453 { | |
454 remote_cmd(session, CMD_PLAYLIST_CLEAR); | |
455 } | |
456 | |
457 gint | |
458 xmms_remote_get_output_time(gint session) | |
459 { | |
460 return remote_get_gint(session, CMD_GET_OUTPUT_TIME); | |
461 } | |
462 | |
463 void | |
464 xmms_remote_jump_to_time(gint session, gint pos) | |
465 { | |
466 remote_send_guint32(session, CMD_JUMP_TO_TIME, pos); | |
467 } | |
468 | |
469 void | |
470 xmms_remote_get_volume(gint session, gint * vl, gint * vr) | |
471 { | |
472 ServerPktHeader pkt_hdr; | |
473 gint fd; | |
474 gpointer data; | |
475 | |
476 if ((fd = xmms_connect_to_session(session)) == -1) | |
477 return; | |
478 | |
479 remote_send_packet(fd, CMD_GET_VOLUME, NULL, 0); | |
480 data = remote_read_packet(fd, &pkt_hdr); | |
481 if (data) { | |
482 *vl = ((guint32 *) data)[0]; | |
483 *vr = ((guint32 *) data)[1]; | |
484 g_free(data); | |
485 } | |
486 remote_read_ack(fd); | |
487 close(fd); | |
488 } | |
489 | |
490 gint | |
491 xmms_remote_get_main_volume(gint session) | |
492 { | |
493 gint vl, vr; | |
494 | |
495 xmms_remote_get_volume(session, &vl, &vr); | |
496 | |
497 return (vl > vr) ? vl : vr; | |
498 } | |
499 | |
500 gint | |
501 xmms_remote_get_balance(gint session) | |
502 { | |
503 return remote_get_gint(session, CMD_GET_BALANCE); | |
504 } | |
505 | |
506 void | |
507 xmms_remote_set_volume(gint session, gint vl, gint vr) | |
508 { | |
509 gint fd; | |
510 guint32 v[2]; | |
511 | |
512 if (vl < 0) | |
513 vl = 0; | |
514 if (vl > 100) | |
515 vl = 100; | |
516 if (vr < 0) | |
517 vr = 0; | |
518 if (vr > 100) | |
519 vr = 100; | |
520 | |
521 if ((fd = xmms_connect_to_session(session)) == -1) | |
522 return; | |
523 v[0] = vl; | |
524 v[1] = vr; | |
525 remote_send_packet(fd, CMD_SET_VOLUME, v, 2 * sizeof(guint32)); | |
526 remote_read_ack(fd); | |
527 close(fd); | |
528 } | |
529 | |
530 void | |
531 xmms_remote_set_main_volume(gint session, gint v) | |
532 { | |
533 gint b, vl, vr; | |
534 | |
535 b = xmms_remote_get_balance(session); | |
536 | |
537 if (b < 0) { | |
538 vl = v; | |
539 vr = (v * (100 - abs(b))) / 100; | |
540 } | |
541 else if (b > 0) { | |
542 vl = (v * (100 - b)) / 100; | |
543 vr = v; | |
544 } | |
545 else | |
546 vl = vr = v; | |
547 xmms_remote_set_volume(session, vl, vr); | |
548 } | |
549 | |
550 void | |
551 xmms_remote_set_balance(gint session, gint b) | |
552 { | |
553 gint v, vl, vr; | |
554 | |
555 if (b < -100) | |
556 b = -100; | |
557 if (b > 100) | |
558 b = 100; | |
559 | |
560 v = xmms_remote_get_main_volume(session); | |
561 | |
562 if (b < 0) { | |
563 vl = v; | |
564 vr = (v * (100 - abs(b))) / 100; | |
565 } | |
566 else if (b > 0) { | |
567 vl = (v * (100 - b)) / 100; | |
568 vr = v; | |
569 } | |
570 else | |
571 vl = vr = v; | |
572 xmms_remote_set_volume(session, vl, vr); | |
573 } | |
574 | |
575 gchar * | |
576 xmms_remote_get_skin(gint session) | |
577 { | |
578 return remote_get_string(session, CMD_GET_SKIN); | |
579 } | |
580 | |
581 void | |
582 xmms_remote_set_skin(gint session, gchar * skinfile) | |
583 { | |
584 remote_send_string(session, CMD_SET_SKIN, skinfile); | |
585 } | |
586 | |
587 gchar * | |
588 xmms_remote_get_playlist_file(gint session, gint pos) | |
589 { | |
590 return remote_get_string_pos(session, CMD_GET_PLAYLIST_FILE, pos); | |
591 } | |
592 | |
593 gchar * | |
594 xmms_remote_get_playlist_title(gint session, gint pos) | |
595 { | |
596 return remote_get_string_pos(session, CMD_GET_PLAYLIST_TITLE, pos); | |
597 } | |
598 | |
599 gint | |
600 xmms_remote_get_playlist_time(gint session, gint pos) | |
601 { | |
602 ServerPktHeader pkt_hdr; | |
603 gpointer data; | |
604 gint fd, ret = 0; | |
605 guint32 p = pos; | |
606 | |
607 if ((fd = xmms_connect_to_session(session)) == -1) | |
608 return ret; | |
609 remote_send_packet(fd, CMD_GET_PLAYLIST_TIME, &p, sizeof(guint32)); | |
610 data = remote_read_packet(fd, &pkt_hdr); | |
611 if (data) { | |
612 ret = *((gint *) data); | |
613 g_free(data); | |
614 } | |
615 remote_read_ack(fd); | |
616 close(fd); | |
617 return ret; | |
618 } | |
619 | |
620 void | |
621 xmms_remote_get_info(gint session, gint * rate, gint * freq, gint * nch) | |
622 { | |
623 ServerPktHeader pkt_hdr; | |
624 gint fd; | |
625 gpointer data; | |
626 | |
627 if ((fd = xmms_connect_to_session(session)) == -1) | |
628 return; | |
629 remote_send_packet(fd, CMD_GET_INFO, NULL, 0); | |
630 data = remote_read_packet(fd, &pkt_hdr); | |
631 if (data) { | |
632 *rate = ((guint32 *) data)[0]; | |
633 *freq = ((guint32 *) data)[1]; | |
634 *nch = ((guint32 *) data)[2]; | |
635 g_free(data); | |
636 } | |
637 remote_read_ack(fd); | |
638 close(fd); | |
639 } | |
640 | |
641 void | |
642 xmms_remote_get_eq_data(gint session) | |
643 { | |
644 /* Obsolete */ | |
645 } | |
646 | |
647 void | |
648 xmms_remote_set_eq_data(gint session) | |
649 { | |
650 /* Obsolete */ | |
651 } | |
652 | |
653 void | |
654 xmms_remote_pl_win_toggle(gint session, gboolean show) | |
655 { | |
656 remote_send_boolean(session, CMD_PL_WIN_TOGGLE, show); | |
657 } | |
658 | |
659 void | |
660 xmms_remote_eq_win_toggle(gint session, gboolean show) | |
661 { | |
662 remote_send_boolean(session, CMD_EQ_WIN_TOGGLE, show); | |
663 } | |
664 | |
665 void | |
666 xmms_remote_main_win_toggle(gint session, gboolean show) | |
667 { | |
668 remote_send_boolean(session, CMD_MAIN_WIN_TOGGLE, show); | |
669 } | |
670 | |
671 gboolean | |
672 xmms_remote_is_main_win(gint session) | |
673 { | |
674 return remote_get_gboolean(session, CMD_IS_MAIN_WIN); | |
675 } | |
676 | |
677 gboolean | |
678 xmms_remote_is_pl_win(gint session) | |
679 { | |
680 return remote_get_gboolean(session, CMD_IS_PL_WIN); | |
681 } | |
682 | |
683 gboolean | |
684 xmms_remote_is_eq_win(gint session) | |
685 { | |
686 return remote_get_gboolean(session, CMD_IS_EQ_WIN); | |
687 } | |
688 | |
689 void | |
690 xmms_remote_show_prefs_box(gint session) | |
691 { | |
692 remote_cmd(session, CMD_SHOW_PREFS_BOX); | |
693 } | |
694 | |
695 void | |
696 xmms_remote_toggle_aot(gint session, gboolean ontop) | |
697 { | |
698 remote_send_boolean(session, CMD_TOGGLE_AOT, ontop); | |
699 } | |
700 | |
701 void | |
702 xmms_remote_show_about_box(gint session) | |
703 { | |
704 remote_cmd(session, CMD_SHOW_ABOUT_BOX); | |
705 } | |
706 | |
707 void | |
708 xmms_remote_eject(gint session) | |
709 { | |
710 remote_cmd(session, CMD_EJECT); | |
711 } | |
712 | |
713 void | |
714 xmms_remote_playlist_prev(gint session) | |
715 { | |
716 remote_cmd(session, CMD_PLAYLIST_PREV); | |
717 } | |
718 | |
719 void | |
720 xmms_remote_playlist_next(gint session) | |
721 { | |
722 remote_cmd(session, CMD_PLAYLIST_NEXT); | |
723 } | |
724 | |
725 void | |
726 xmms_remote_playlist_add_url_string(gint session, gchar * string) | |
727 { | |
728 g_return_if_fail(string != NULL); | |
729 remote_send_string(session, CMD_PLAYLIST_ADD_URL_STRING, string); | |
730 } | |
731 | |
732 void | |
733 xmms_remote_playlist_ins_url_string(gint session, gchar * string, gint pos) | |
734 { | |
735 gint fd, size; | |
736 gchar *packet; | |
737 | |
738 g_return_if_fail(string != NULL); | |
739 | |
740 size = strlen(string) + 1 + sizeof(gint); | |
741 | |
742 if ((fd = xmms_connect_to_session(session)) == -1) | |
743 return; | |
744 | |
745 packet = g_malloc0(size); | |
746 *((gint *) packet) = pos; | |
747 strcpy(packet + sizeof(gint), string); | |
748 remote_send_packet(fd, CMD_PLAYLIST_INS_URL_STRING, packet, size); | |
749 remote_read_ack(fd); | |
750 close(fd); | |
751 g_free(packet); | |
752 } | |
753 | |
754 gboolean | |
755 xmms_remote_is_running(gint session) | |
756 { | |
757 return remote_cmd(session, CMD_PING); | |
758 } | |
759 | |
760 void | |
761 xmms_remote_toggle_repeat(gint session) | |
762 { | |
763 remote_cmd(session, CMD_TOGGLE_REPEAT); | |
764 } | |
765 | |
766 void | |
767 xmms_remote_toggle_shuffle(gint session) | |
768 { | |
769 remote_cmd(session, CMD_TOGGLE_SHUFFLE); | |
770 } | |
771 | |
772 void | |
773 xmms_remote_toggle_advance(int session) | |
774 { | |
775 remote_cmd(session, CMD_TOGGLE_ADVANCE); | |
776 } | |
777 | |
778 gboolean | |
779 xmms_remote_is_repeat(gint session) | |
780 { | |
781 return remote_get_gboolean(session, CMD_IS_REPEAT); | |
782 } | |
783 | |
784 gboolean | |
785 xmms_remote_is_shuffle(gint session) | |
786 { | |
787 return remote_get_gboolean(session, CMD_IS_SHUFFLE); | |
788 } | |
789 | |
790 gboolean | |
791 xmms_remote_is_advance(gint session) | |
792 { | |
793 return remote_get_gboolean(session, CMD_IS_ADVANCE); | |
794 } | |
795 | |
796 void | |
797 xmms_remote_playqueue_add(gint session, gint pos) | |
798 { | |
799 remote_send_guint32(session, CMD_PLAYQUEUE_ADD, pos); | |
800 } | |
801 | |
802 void | |
803 xmms_remote_playqueue_remove(gint session, gint pos) | |
804 { | |
805 remote_send_guint32(session, CMD_PLAYQUEUE_REMOVE, pos); | |
806 } | |
807 | |
808 gint | |
809 xmms_remote_get_playqueue_length(gint session) | |
810 { | |
811 return remote_get_gint(session, CMD_GET_PLAYQUEUE_LENGTH); | |
812 } | |
813 | |
814 void | |
815 xmms_remote_get_eq(gint session, gfloat * preamp, gfloat ** bands) | |
816 { | |
817 ServerPktHeader pkt_hdr; | |
818 gint fd; | |
819 gpointer data; | |
820 | |
821 if (preamp) | |
822 *preamp = 0.0; | |
823 | |
824 if (bands) | |
825 *bands = NULL; | |
826 | |
827 if ((fd = xmms_connect_to_session(session)) == -1) | |
828 return; | |
829 remote_send_packet(fd, CMD_GET_EQ, NULL, 0); | |
830 data = remote_read_packet(fd, &pkt_hdr); | |
831 if (data) { | |
832 if (pkt_hdr.data_length >= 11 * sizeof(gfloat)) { | |
833 if (preamp) | |
834 *preamp = *((gfloat *) data); | |
835 if (bands) | |
836 *bands = | |
837 (gfloat *) g_memdup((gfloat *) data + 1, | |
838 10 * sizeof(gfloat)); | |
839 } | |
840 g_free(data); | |
841 } | |
842 remote_read_ack(fd); | |
843 close(fd); | |
844 } | |
845 | |
846 gfloat | |
847 xmms_remote_get_eq_preamp(gint session) | |
848 { | |
849 return remote_get_gfloat(session, CMD_GET_EQ_PREAMP); | |
850 } | |
851 | |
852 gfloat | |
853 xmms_remote_get_eq_band(gint session, gint band) | |
854 { | |
855 ServerPktHeader pkt_hdr; | |
856 gint fd; | |
857 gpointer data; | |
858 gfloat val = 0.0; | |
859 | |
860 if ((fd = xmms_connect_to_session(session)) == -1) | |
861 return val; | |
862 remote_send_packet(fd, CMD_GET_EQ_BAND, &band, sizeof(band)); | |
863 data = remote_read_packet(fd, &pkt_hdr); | |
864 if (data) { | |
865 val = *((gfloat *) data); | |
866 g_free(data); | |
867 } | |
868 remote_read_ack(fd); | |
869 close(fd); | |
870 return val; | |
871 } | |
872 | |
873 void | |
874 xmms_remote_set_eq(gint session, gfloat preamp, gfloat * bands) | |
875 { | |
876 gint fd, i; | |
877 gfloat data[11]; | |
878 | |
879 g_return_if_fail(bands != NULL); | |
880 | |
881 if ((fd = xmms_connect_to_session(session)) == -1) | |
882 return; | |
883 data[0] = preamp; | |
884 for (i = 0; i < 10; i++) | |
885 data[i + 1] = bands[i]; | |
886 remote_send_packet(fd, CMD_SET_EQ, data, sizeof(data)); | |
887 remote_read_ack(fd); | |
888 close(fd); | |
889 } | |
890 | |
891 void | |
892 xmms_remote_set_eq_preamp(gint session, gfloat preamp) | |
893 { | |
894 remote_send_gfloat(session, CMD_SET_EQ_PREAMP, preamp); | |
895 } | |
896 | |
897 void | |
898 xmms_remote_set_eq_band(gint session, gint band, gfloat value) | |
899 { | |
900 gint fd; | |
901 gchar data[sizeof(gint) + sizeof(gfloat)]; | |
902 | |
903 if ((fd = xmms_connect_to_session(session)) == -1) | |
904 return; | |
905 *((gint *) data) = band; | |
906 *((gfloat *) (data + sizeof(gint))) = value; | |
907 remote_send_packet(fd, CMD_SET_EQ_BAND, data, sizeof(data)); | |
908 remote_read_ack(fd); | |
909 close(fd); | |
910 } | |
911 | |
912 void | |
913 xmms_remote_quit(gint session) | |
914 { | |
915 gint fd; | |
916 | |
917 if ((fd = xmms_connect_to_session(session)) == -1) | |
918 return; | |
919 remote_send_packet(fd, CMD_QUIT, NULL, 0); | |
920 remote_read_ack(fd); | |
921 close(fd); | |
922 } | |
923 | |
924 void | |
925 xmms_remote_activate(gint session) | |
926 { | |
927 gint fd; | |
928 | |
929 if ((fd = xmms_connect_to_session(session)) == -1) | |
930 return; | |
931 remote_send_packet(fd, CMD_ACTIVATE, NULL, 0); | |
932 remote_read_ack(fd); | |
933 close(fd); | |
934 } |