]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/fwp_fna.c
Fna ops mapped to fwp ops inluding new fna ops like bind, unbind, cretae , destroy...
[frescor/fwp.git] / fwp / lib / fwp_fna.c
1 #include <fna.h>
2 #include "fwp_endpoint.h"
3 #include "fwp_vres.h"
4 #include "fwp.h"
5
6 int fwp_fna_init(const frsh_resource_id_t resource_id)
7 {
8         return fwp_init();
9 }
10
11 int fwp_fna_send_endpoint_created(fna_endpoint_data_t  *endpoint)
12 {
13         unsigned int node, port;
14         fwp_endpoint_attr_t *attr;
15         fwp_endpoint_t *fwp_epoint;
16         int rv;
17
18         node = (unsigned int) endpoint->destination;
19         port = (unsigned int) endpoint->stream_id;
20         attr = (fwp_endpoint_attr_t*) endpoint->protocol_info.body; 
21         rv = fwp_send_endpoint_create(node, port, attr, &fwp_epoint);
22         if (rv)
23                 return rv;
24         endpoint->protocol_info.body = fwp_epoint;
25         return 0;
26 }
27
28 int fwp_fna_receive_endpoint_created(fna_endpoint_data_t  *endpoint)
29 {
30         unsigned int node,port;
31         fwp_endpoint_attr_t *attr;
32         fwp_endpoint_t *fwp_epoint;
33         int rv;
34
35         node = (unsigned int) endpoint->destination;
36         port = (unsigned int) endpoint->stream_id;
37         attr = (fwp_endpoint_attr_t*) endpoint->protocol_info.body; 
38         rv = fwp_receive_endpoint_create(port, attr, &fwp_epoint);
39         if (rv)
40                 return rv;
41         
42         endpoint->protocol_info.body = fwp_epoint;
43         return 0;
44 }
45
46 int fwp_fna_send_endpoint_bind(fna_endpoint_data_t *endpoint, fna_vres_id_t vres)
47 {
48         return fwp_send_endpoint_bind(endpoint->protocol_info.body, 
49                                         (fwp_vres_t*) vres);
50 }
51
52 int fwp_fna_send_endpoint_unbind(fna_endpoint_data_t *endpoint)
53 {
54         return fwp_send_endpoint_unbind(endpoint->protocol_info.body);
55 }
56
57 int fwp_fna_endpoint_destroy(fna_endpoint_data_t  *endpoint)
58 {       
59         return fwp_endpoint_destroy(endpoint->endpoint_protocol_info.send.body);
60 }
61
62 /** FNA send routine */
63 int fwp_fna_send(const fna_endpoint_data_t *endpoint, const void *msg, 
64                         const size_t size)
65 {
66         fwp_endpoint_t *fwp_epoint;
67         int flags = 0;
68
69         fwp_epoint = endpoint->protocol_info.body;
70         return fwp_send(fwp_epoint, msg, size, flags);
71 }
72
73 int fwp_fna_send_sync(const fna_endpoint_data_t *endpoint, const void *msg, 
74                         const size_t size)
75 {
76         fwp_endpoint_t *fwp_epoint;
77         int flags = 0;
78
79         fwp_epoint = endpoint->protocol_info.body;
80         return fwp_send(fwp_epoint, msg, size, flags);
81 }
82
83 int fwp_fna_send_async(const fna_endpoint_data_t *endpoint,const void *msg,
84                    const size_t size)
85 {
86         fwp_endpoint_t *fwp_epoint;
87
88         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
89         return fwp_send(fwp_epoint, msg, size, MSG_DONTWAIT);
90 }
91
92 /** FNA receive routines */
93 int fwp_fna_receive(const fna_endpoint_data_t *endpoint,
94                         void *buffer, const size_t buffer_size,
95                         size_t *received_bytes, frsh_network_address_t *from)
96 {
97         unsigned int from_addr;
98         size_t len;
99         fwp_endpoint_t *fwp_epoint;
100         int flags = 0;
101         
102         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
103         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
104         if (len < 0) 
105                 return len;
106         
107         *received_bytes = len;
108         *from = from_addr;
109         
110         return 0;
111 }
112
113 int fwp_fna_receive_sync(const fna_endpoint_data_t *endpoint, void *buffer, 
114                          const size_t buffer_size, size_t *received_bytes, 
115                          frsh_network_address_t *from)
116 {
117         unsigned int from_addr;
118         size_t len;
119         fwp_endpoint_t *fwp_epoint;
120         int flags = 0;
121         
122         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
123         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
124         if (len < 0) 
125                 return len;
126         
127         *received_bytes = len;
128         *from = from_addr;
129         
130         return 0;
131 }
132
133 int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer, 
134                          const size_t buffer_size, size_t *received_bytes, 
135                          frsh_network_address_t *from)
136 {
137         unsigned int from_addr;
138         size_t len;
139         fwp_endpoint_t *fwp_epoint;
140         int flags = 0;
141         
142         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
143         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
144         if (len < 0) 
145                 return len;
146         
147         *received_bytes = len;
148         *from = from_addr;
149         
150         return 0;
151 }
152
153 int fwp_fna_vres_destroy(const frsh_resource_id_t resource_id,
154                      const fna_vres_id_t vres)
155 {
156 //      return fwp_vres_close(vres);    
157         return 0;
158 }
159
160 fna_operations_t fwp_fna_operations = {
161     .fna_init = fwp_fna_init,
162     .fna_contract_negotiate = NULL,
163     .fna_contract_renegotiate_sync = NULL,
164     .fna_contract_renegotiate_async = NULL,
165     .fna_vres_get_renegotiation_status = NULL,
166     .fna_vres_destroy = fwp_fna_vres_destroy,
167     .fna_vres_get_contract = NULL,
168     .fna_vres_get_usage = NULL,
169     .fna_vres_get_remaining_budget = NULL,
170     .fna_vres_get_budget_and_period = NULL,
171     .fna_resource_get_capacity = NULL,
172     .fna_resource_get_total_weight = NULL,
173     .fna_vres_decrease_capacity = NULL,
174     .fna_send_sync = NULL,
175     .fna_send_async = fwp_fna_send_async,
176     .fna_receive_sync = fwp_fna_receive_sync,
177     .fna_receive_async = fwp_fna_receive_async,
178     .fna_send_endpoint_get_status = NULL,
179     .fna_endpoint_destroy = fwp_fna_endpoint_destroy,
180     .fna_send_endpoint_created = fwp_fna_send_endpoint_created,
181     .fna_send_endpoint_bind = fwp_fna_send_endpoint_bind,
182     .fna_send_endpoint_unbind = fwp_fna_send_endpoint_unbind,
183     .fna_receive_endpoint_created = fwp_fna_receive_endpoint_created,
184     .fna_receive_endpoint_get_status = NULL,
185     .fna_network_get_max_message_size = NULL,
186     .fna_network_bytes_to_budget = NULL,
187     .fna_network_budget_to_bytes = NULL,
188     .fna_network_get_min_eff_budget = NULL
189 };
190