aboutsummaryrefslogtreecommitdiff
path: root/sandbox_ui.lv2/sandbox_master.c
blob: c61e1d05607672206d2373009b8172882acded3f (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (c) 2015-2016 Hanspeter Portner (dev@open-music-kontrollers.ch)
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the Artistic License 2.0 as published by
 * The Perl Foundation.
 *
 * This source is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Artistic License 2.0 for more details.
 *
 * You should have received a copy of the Artistic License 2.0
 * along the source as a COPYING file. If not, obtain it from
 * http://www.perlfoundation.org/artistic_license_2_0.
 */

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sandbox_master.h>
#include <sandbox_io.h>

#include <lv2/lv2plug.in/ns/ext/log/log.h>
#include <lv2/lv2plug.in/ns/ext/options/options.h>
#include <lv2/lv2plug.in/ns/extensions/ui/ui.h>

struct _sandbox_master_t {
	sandbox_io_t io;

	sandbox_master_driver_t *driver;
	void *data;
};

sandbox_master_t *
sandbox_master_new(sandbox_master_driver_t *driver, void *data)
{
	sandbox_master_t *sb = calloc(1, sizeof(sandbox_master_t));
	if(!sb)
		goto fail;

	sb->driver = driver;
	sb->data = data;

	if(_sandbox_io_init(&sb->io, driver->map, driver->unmap, driver->socket_path, true))
		goto fail;

	return sb;

fail:
	sandbox_master_free(sb);
	return NULL;
}

void
sandbox_master_free(sandbox_master_t *sb)
{
	if(sb)
	{
		_sandbox_io_deinit(&sb->io);
		free(sb);
	}
}

void
sandbox_master_recv(sandbox_master_t *sb)
{
	if(sb)
		_sandbox_io_recv(&sb->io, sb->driver->recv_cb, sb->driver->subscribe_cb, sb->data);
}

bool
sandbox_master_send(sandbox_master_t *sb, uint32_t index, uint32_t size,
	uint32_t format, const void *buf)
{
	if(sb)
		return _sandbox_io_send(&sb->io, index, size, format, buf);

	return false;
}

bool
sandbox_master_flush(sandbox_master_t *sb)
{
	if(sb)
		return _sandbox_io_flush(&sb->io);

	return false;
}

void
sandbox_master_fd_get(sandbox_master_t *sb, int *fd)
{
	if(sb && fd)
		*fd = _sandbox_io_fd_get(&sb->io);
	else if(fd)
		*fd = -1;
}