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

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

struct core* core_new(struct pa_mainloop_api *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;
    c->namereg = 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);

    namereg_free(c);
    
    free(c);    
};