summaryrefslogtreecommitdiff
path: root/src/core.c
blob: 50248501a7c571b10fa36a7d576d62fb265bf195 (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
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

#include "core.h"
#include "module.h"
#include "sink.h"
#include "source.h"

struct core* core_new(struct mainloop *m) {
    struct core* c;
    c = malloc(sizeof(struct core));
    assert(c);

    c->mainloop = m;
    c->clients = idxset_new(NULL, NULL);
    c->sinks = idxset_new(NULL, NULL);
    c->sources = idxset_new(NULL, NULL);
    c->source_outputs = idxset_new(NULL, NULL);
    c->sink_inputs = idxset_new(NULL, NULL);

    c->default_source_index = c->default_sink_index = IDXSET_INVALID;

    c->modules = NULL;
    
    return c;
};

void core_free(struct core *c) {
    assert(c);

    module_unload_all(c);
    assert(!c->modules);
    
    assert(idxset_isempty(c->clients));
    idxset_free(c->clients, NULL, NULL);
    
    assert(idxset_isempty(c->sinks));
    idxset_free(c->sinks, NULL, NULL);

    assert(idxset_isempty(c->sources));
    idxset_free(c->sources, NULL, NULL);
    
    assert(idxset_isempty(c->source_outputs));
    idxset_free(c->source_outputs, NULL, NULL);
    
    assert(idxset_isempty(c->sink_inputs));
    idxset_free(c->sink_inputs, NULL, NULL);

    free(c);    
};