]> code.delx.au - pulseaudio/blob - src/module-protocol-stub.c
esound protocol
[pulseaudio] / src / module-protocol-stub.c
1 #include <stdio.h>
2 #include <assert.h>
3 #include <arpa/inet.h>
4 #include <unistd.h>
5
6 #include "module.h"
7 #include "socket-server.h"
8 #include "util.h"
9
10 #ifdef USE_PROTOCOL_SIMPLE
11 #include "protocol-simple.h"
12 #define protocol_free protocol_simple_free
13 #define IPV4_PORT 4711
14 #define UNIX_SOCKET_DIR "/tmp/polypaudio"
15 #define UNIX_SOCKET "/tmp/polypaudio/simple"
16 #else
17 #ifdef USE_PROTOCOL_CLI
18 #include "protocol-cli.h"
19 #define protocol_new protocol_cli_new
20 #define protocol_free protocol_cli_free
21 #define IPV4_PORT 4712
22 #define UNIX_SOCKET_DIR "/tmp/polypaudio"
23 #define UNIX_SOCKET "/tmp/polypaudio/cli"
24 #else
25 #ifdef USE_PROTOCOL_NATIVE
26 #include "protocol-native.h"
27 #define protocol_new protocol_native_new
28 #define protocol_free protocol_native_free
29 #define IPV4_PORT 4713
30 #define UNIX_SOCKET_DIR "/tmp/polypaudio"
31 #define UNIX_SOCKET "/tmp/polypaudio/native"
32 #else
33 #ifdef USE_PROTOCOL_ESOUND
34 #include "protocol-esound.h"
35 #include "esound-spec.h"
36 #define protocol_new protocol_esound_new
37 #define protocol_free protocol_esound_free
38 #define IPV4_PORT ESD_DEFAULT_PORT
39 #define UNIX_SOCKET_DIR ESD_UNIX_SOCKET_DIR
40 #define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
41 #else
42 #error "Broken build system"
43 #endif
44 #endif
45 #endif
46 #endif
47
48 int module_init(struct core *c, struct module*m) {
49 struct socket_server *s;
50 assert(c && m);
51
52 #ifdef USE_TCP_SOCKETS
53 if (!(s = socket_server_new_ipv4(c->mainloop, INADDR_LOOPBACK, IPV4_PORT)))
54 return -1;
55 #else
56 if (make_secure_dir(UNIX_SOCKET_DIR) < 0) {
57 fprintf(stderr, "Failed to create secure socket directory.\n");
58 return -1;
59 }
60
61 if (!(s = socket_server_new_unix(c->mainloop, UNIX_SOCKET))) {
62 rmdir(UNIX_SOCKET_DIR);
63 return -1;
64 }
65 #endif
66
67 #ifdef USE_PROTOCOL_SIMPLE
68 m->userdata = protocol_simple_new(c, s, PROTOCOL_SIMPLE_PLAYBACK);
69 #else
70 m->userdata = protocol_new(c, s);
71 #endif
72
73 assert(m->userdata);
74 return 0;
75 }
76
77 void module_done(struct core *c, struct module*m) {
78 assert(c && m);
79
80 protocol_free(m->userdata);
81
82 #ifndef USE_TCP_SOCKETS
83 rmdir(UNIX_SOCKET_DIR);
84 #endif
85 }