Hash :
63b45f3b
Author :
tokyovania
Date :
2022-08-12T14:38:49
switch from bits to bytes
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
/*
* Copyright 2020-2021 Thomas de Grivel <thoxdg@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <assert.h>
#include "../librtbuf/data.h"
#include "rtbuf_gtk3.h"
s_data_type g_rtbuf_gtk_connection_type = {
sizeof(s_rtbuf_gtk_connection),
DATA_TYPE_BYTES
};
s_data_alloc g_rtbuf_gtk_connection_alloc;
void rtbuf_gtk_connection_init ()
{
data_alloc_init(&g_rtbuf_gtk_connection_alloc,
&g_rtbuf_gtk_connection_type,
RTBUF_MAX * 10, NULL, NULL);
}
s_rtbuf_gtk_connection * rtbuf_gtk_connection_new ()
{
s_rtbuf_gtk_connection *connection = data_new(&g_rtbuf_gtk_connection_alloc);
return connection;
}
void rtbuf_gtk_connection_delete (s_rtbuf_gtk_connection *connection)
{
data_delete(&g_rtbuf_gtk_connection_alloc, connection);
}
void rtbuf_gtk_connection_push (s_rtbuf_gtk_connection **head,
s_rtbuf_gtk_connection *item)
{
assert(!item->next);
item->next = *head;
*head = item;
}
int rtbuf_gtk_connection_remove_one (s_rtbuf_gtk_connection **head,
s_rtbuf_gtk_connection *item)
{
s_rtbuf_gtk_connection **next = head;
while (*next && *next != item)
next = &(*next)->next;
if (*next == item) {
*next = item->next;
return 1;
}
return 0;
}
s_rtbuf_gtk_connection * rtbuf_gtk_connection_find
(s_rtbuf_gtk_connection *c,
RtbufOutputWidget *output_widget,
RtbufInputWidget *input_widget)
{
while (c && (c->output_widget != output_widget ||
c->input_widget != input_widget))
c = c->next;
return c;
}
void rtbuf_gtk_connection_remove_rtbuf (s_rtbuf_gtk_connection **conn,
s_rtbuf *rtbuf)
{
while (*conn) {
s_rtbuf *output_rtbuf;
output_rtbuf = rtbuf_output_widget_get_rtbuf((*conn)->output_widget);
if (output_rtbuf != rtbuf) {
s_rtbuf *input_rtbuf;
input_rtbuf = rtbuf_input_widget_get_rtbuf((*conn)->input_widget);
if (input_rtbuf != rtbuf) {
conn = &(*conn)->next;
continue;
}
}
*conn = (*conn)->next;
}
}