summaryrefslogtreecommitdiffstats
path: root/src/module-protocol-stub.c
blob: 97bf5ef3cb383ebe8ba57a9aaeb755538f42778a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <assert.h>
#include <arpa/inet.h>

#include "module.h"
#include "socket-server.h"

#ifdef USE_PROTOCOL_SIMPLE
  #include "protocol-simple.h"
  #define protocol_free protocol_simple_free
  #define IPV4_PORT 4711
  #define UNIX_SOCKET "/tmp/polypaudio_simple"
#else
  #ifdef USE_PROTOCOL_CLI
    #include "protocol-cli.h" 
    #define protocol_new protocol_cli_new
    #define protocol_free protocol_cli_free
    #define IPV4_PORT 4712
    #define UNIX_SOCKET "/tmp/polypaudio_cli"
  #else
    #ifdef USE_PROTOCOL_NATIVE
      #include "protocol-native.h"
      #define protocol_new protocol_native_new
      #define protocol_free protocol_native_free
      #define IPV4_PORT 4713
      #define UNIX_SOCKET "/tmp/polypaudio_native"
    #else
      #error "Broken build system"
    #endif
  #endif
#endif

int module_init(struct core *c, struct module*m) {
    struct socket_server *s;
    assert(c && m);

#ifdef USE_TCP_SOCKETS
    if (!(s = socket_server_new_ipv4(c->mainloop, INADDR_LOOPBACK, IPV4_PORT)))
        return -1;
#else
    if (!(s = socket_server_new_unix(c->mainloop, UNIX_SOCKET)))
        return -1;
#endif

#ifdef USE_PROTOCOL_SIMPLE
    m->userdata = protocol_simple_new(c, s, PROTOCOL_SIMPLE_PLAYBACK);
#else
    m->userdata = protocol_new(c, s);
#endif
    
    assert(m->userdata);
    return 0;
}

void module_done(struct core *c, struct module*m) {
    assert(c && m);

    protocol_free(m->userdata);
}