summaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 79d50ab0d7c662e0ab2f4fe73b42f216a544296d (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
#include "data.h"
#include "log.h"
#include "mpris.h"
#include "player.h"
#include "tui.h"

#include <curses.h>
#include <locale.h>

static void stop(int sig);
static void init(void);
static void cleanup(int code, void *arg);

void
stop(int sig)
{
	if (player.loaded) {
		player_stop();
	} else {
		exit(0);
	}
}

void
init(void)
{
	setlocale(LC_ALL, "");
	srand(time(NULL));

	log_init();

	data_load();

	player_init();

	tui_init();

	dbus_init();

	on_exit(cleanup, NULL);
	signal(SIGINT, stop);
	signal(SIGTERM, exit);
}

void
cleanup(int exitcode, void* arg)
{
	tui_restore();

	player_deinit();

	data_save();
	data_free();

	dbus_deinit();

	tui_deinit();

	log_deinit();
}

int
main(int argc, const char **argv)
{
	init();

	do {
		dbus_update();
		player_update();
	} while (tui_update());
}