-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify_events.c
62 lines (49 loc) · 1.32 KB
/
spotify_events.c
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
59
60
61
#include <signal.h>
#include <assert.h>
/* We need access to events and spotify_stop */
#include "spotify_events_int.h"
#include "spotify_int.h"
static void
stop_event_cb(evutil_socket_t fd, short event_flags, void *arg)
{
spotify_t *spotify = arg;
assert(spotify);
spotify_stop(spotify);
}
static void
process_event_cb(evutil_socket_t fd, short event_flags, void *arg)
{
spotify_t *spotify = arg;
spotify_events_t *events;
int next_timeout = 0;
struct timeval timeout;
assert(spotify);
do {
spotify_process_events(spotify, &next_timeout);
} while (next_timeout == 0);
timeout.tv_sec = next_timeout/1000;
timeout.tv_usec = (next_timeout%1000)*1000;
events = spotify_get_events(spotify);
event_add(events->process_event, &timeout);
}
int
spotify_events_init(spotify_t *spotify, spotify_events_t *events, struct event_base *event_base)
{
events->stop_event = event_new(event_base, SIGINT, EV_SIGNAL, stop_event_cb, spotify);
event_add(events->stop_event, NULL);
events->process_event = event_new(event_base, -1, 0, process_event_cb, spotify);
event_add(events->process_event, NULL);
return 0;
}
void
spotify_events_destroy(spotify_events_t *events)
{
event_free(events->stop_event);
event_free(events->process_event);
events->stop_event = NULL;
events->process_event = NULL;
}
void
spotify_events_register()
{
}