-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinterface.c
74 lines (56 loc) · 1.5 KB
/
interface.c
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
/*
* Greybus Simulator
*
* Copyright 2016 Rui Miguel Silva <[email protected]>
*
* Provided under the three clause BSD license found in the LICENSE file.
*/
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/queue.h>
#include "gbsim.h"
struct gbsim_interface *interface_get_by_hash(struct gbsim_svc *svc,
uint32_t hash)
{
struct gbsim_interface *intf;
TAILQ_FOREACH(intf, &svc->intfs, intf_node)
if (intf->manifest_fname_hash == hash)
return intf;
return NULL;
}
struct gbsim_interface *interface_get_by_id(struct gbsim_svc *svc, uint8_t id)
{
struct gbsim_interface *intf;
TAILQ_FOREACH(intf, &svc->intfs, intf_node)
if (intf->interface_id == id)
return intf;
return NULL;
}
void interface_free(struct gbsim_svc *svc, struct gbsim_interface *intf)
{
struct gbsim_connection *connection;
gbsim_debug("free interface %u\n", intf->interface_id);
TAILQ_FOREACH(connection, &intf->connections, cnode)
free_connection(connection);
TAILQ_REMOVE(&svc->intfs, intf, intf_node);
free(intf->manifest);
free(intf);
}
struct gbsim_interface *interface_alloc(struct gbsim_svc *svc, uint8_t id)
{
struct gbsim_interface *intf;
intf = interface_get_by_id(svc, id);
if (intf) {
gbsim_error("allocated an already existent interface %u\n", id);
return intf;
}
intf = calloc(1, sizeof(*intf));
if (!intf)
return NULL;
TAILQ_INIT(&intf->connections);
intf->interface_id = id;
intf->svc = svc;
TAILQ_INSERT_TAIL(&svc->intfs, intf, intf_node);
return intf;
}