Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv gs/ DataDesc/ ; change the prefix of parsing functions from gs_parse to gras_datad...
[simgrid.git] / src / gras / DataDesc / net_driver.c
1 /* gs_net_driver.c */
2
3 #include "DataDesc/gs_private.h"
4
5 //GRAS_LOG_NEW_DEFAULT_CATEGORY(FIXME_net_driver);
6
7 static
8 gras_dict_t *p_net_driver_dict = NULL;
9
10 void
11 gs_net_drivers_init(void) {
12   gras_error_t errcode;
13
14   TRYFAIL(gras_dict_new(&p_net_driver_dict));
15   TRYFAIL(gras_dict_insert(p_net_driver_dict, "fd", gs_fd_net_driver(), NULL));
16 }
17
18
19 struct s_gs_net_driver *
20 gs_net_driver_init(const char *name) {
21
22         struct s_gs_net_driver_ops      *net_driver_ops = NULL;
23         struct s_gs_net_driver          *p_net_driver   = NULL;
24
25         gras_dict_retrieve(p_net_driver_dict, name, (void **)&net_driver_ops);
26         if (!net_driver_ops)
27                 GS_FAILURE("net driver not found");
28
29         p_net_driver                    = calloc(1, sizeof (struct s_gs_net_driver));
30         p_net_driver->net_ops           = net_driver_ops;
31         p_net_driver->connection_ops    = NULL;
32         p_net_driver->specific          = NULL;
33
34         if (net_driver_ops->_init) {
35                 net_driver_ops->_init(p_net_driver);
36         }
37
38         return p_net_driver;
39 }
40
41
42
43 void
44 gs_net_driver_exit(struct s_gs_net_driver       *p_net_driver){
45
46         struct s_gs_net_driver_ops      *net_driver_ops = NULL;
47
48         net_driver_ops = p_net_driver->net_ops;
49         if (net_driver_ops->_exit) {
50                 net_driver_ops->_exit(p_net_driver);
51         }
52
53         p_net_driver->net_ops = NULL;
54
55         if (p_net_driver->specific) {
56                 free(p_net_driver->specific);
57                 p_net_driver->specific = NULL;
58         }
59
60         free(p_net_driver);
61 }
62
63 struct s_gs_connection *
64 gs_net_connection_connect(struct s_gs_net_driver        *p_net_driver,
65                           void                          *arg) {
66
67         struct s_gs_connection_ops      *connection_ops = p_net_driver->connection_ops;
68         struct s_gs_connection          *p_connection   = NULL;
69
70         p_connection = malloc(sizeof (struct s_gs_connection));
71         p_connection->connection_ops    = connection_ops;
72         p_connection->p_net_driver      = p_net_driver;
73         p_connection->direction         = e_gs_connection_direction_outgoing;
74
75         if (connection_ops->_init) {
76                 connection_ops->_init(p_connection, arg);
77         }
78
79         return p_connection;
80 }
81
82 struct s_gs_connection *
83 gs_net_connection_accept(struct s_gs_net_driver *p_net_driver,
84                          void                   *arg) {
85
86         struct s_gs_connection_ops      *connection_ops = p_net_driver->connection_ops;
87         struct s_gs_connection          *p_connection   = NULL;
88
89         p_connection = malloc(sizeof (struct s_gs_connection));
90         p_connection->connection_ops    = connection_ops;
91         p_connection->p_net_driver      = p_net_driver;
92         p_connection->direction         = e_gs_connection_direction_incoming;
93
94         if (connection_ops->_init) {
95                 connection_ops->_init(p_connection, arg);
96         }
97
98         return p_connection;
99 }
100
101 void
102 gs_net_connection_close(struct s_gs_connection  *p_connection) {
103         if (p_connection->connection_ops->_exit) {
104                 p_connection->connection_ops->_exit(p_connection);
105         }
106
107         if (p_connection->specific) {
108                 free(p_connection->specific);
109                 p_connection->specific = NULL;
110         }
111
112         free(p_connection);
113 }