annotate libaudacious/beepctrl.c @ 1437:dd2b97f79a20 trunk

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