embox

Форк
0
/
node.c 
87 строк · 1.6 Кб
1
/**
2
 * @file
3
 * @brief Network node manager
4
 *
5
 * @date 19.10.2011
6
 * @author Anton Kozlov
7
 */
8

9
#include <stddef.h>
10
#include <assert.h>
11
#include <string.h>
12

13
#include <mem/objalloc.h>
14

15
#include <pnet/core/types.h>
16
#include <pnet/core/core.h>
17

18
#include <framework/mod/options.h>
19

20
#define CONFIG_PNET_NODES_QUANTITY OPTION_GET(NUMBER,pnet_nodes_quantity)
21

22
OBJALLOC_DEF(net_nodes, struct net_node, CONFIG_PNET_NODES_QUANTITY);
23

24
net_node_t pnet_node_init(net_node_t node, pnet_proto_t proto) {
25
	assert(node);
26
	node->proto = proto;
27

28
	INIT_LIST_HEAD(&node->gr_link);
29

30
	node->rx_dfault = node->tx_dfault = NULL;
31
	node->graph = NULL;
32

33
	return node;
34
}
35

36
net_node_t pnet_node_alloc(net_addr_t addr, pnet_proto_t proto) {
37
	net_node_t node;
38
	if (NULL == proto || NULL == proto->actions.alloc) {
39
		node = (net_node_t) objalloc(&net_nodes);
40
	} else {
41
		node = proto->actions.alloc();
42
	}
43

44
	pnet_node_init(node, proto);
45

46
	return node;
47

48
}
49

50
int pnet_node_free(net_node_t node) {
51
	assert(node);
52
	if ((NULL != node->proto) && (NULL != node->proto->actions.free)) {
53
		if (node->proto->actions.free(node) == 0) {
54
			return 0;
55
		}
56
	}
57
	objfree(&net_nodes, node);
58
	return 0;
59
}
60

61
int pnet_node_attach(net_node_t node, net_id_t id, net_node_t other) {
62
	if (node == NULL) {
63
		return -1;
64
	}
65

66
	switch (id) {
67
		case NET_RX_DFAULT:
68
			node->rx_dfault = other;
69
			break;
70
		case NET_TX_DFAULT:
71
			node->tx_dfault = other;
72
			break;
73
	}
74

75
	return 0;
76
}
77

78
net_node_t pnet_node_get(net_node_t node, net_id_t id) {
79
	switch (id) {
80
		case NET_RX_DFAULT:
81
			return node->rx_dfault;
82
		case NET_TX_DFAULT:
83
			return node->tx_dfault;
84
	}
85

86
	return NULL;
87
}
88

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.