]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/frsh_fwp/fwp_fna.c
8f32ca3358cba6602beb9b4b8382fa6c13597ca5
[frescor/fwp.git] / fwp / lib / frsh_fwp / fwp_fna.c
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
5 /*   Universidad de Cantabria,              SPAIN                         */
6 /*   University of York,                    UK                            */
7 /*   Scuola Superiore Sant'Anna,            ITALY                         */
8 /*   Kaiserslautern University,             GERMANY                       */
9 /*   Univ. Politécnica  Valencia,           SPAIN                        */
10 /*   Czech Technical University in Prague,  CZECH REPUBLIC                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
19 /*          FRESCOR project (FP6/2005/IST/5-034026) is funded             */
20 /*       in part by the European Union Sixth Framework Programme          */
21 /*       The European Union is not liable of any use that may be          */
22 /*       made of this code.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FWP (Frescor WLAN Protocol)                      */
26 /*                                                                        */
27 /* FWP is free software; you can redistribute it and/or modify it         */
28 /* under terms of the GNU General Public License as published by the      */
29 /* Free Software Foundation; either version 2, or (at your option) any    */
30 /* later version.  FWP is distributed in the hope that it will be         */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
33 /* General Public License for more details. You should have received a    */
34 /* copy of the GNU General Public License along with FWP; see file        */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
36 /* Cambridge, MA 02139, USA.                                              */
37 /*                                                                        */
38 /* As a special exception, including FWP header files in a file,          */
39 /* instantiating FWP generics or templates, or linking other files        */
40 /* with FWP objects to produce an executable application, does not        */
41 /* by itself cause the resulting executable application to be covered     */
42 /* by the GNU General Public License. This exception does not             */
43 /* however invalidate any other reasons why the executable file might be  */
44 /* covered by the GNU Public License.                                     */
45 /**************************************************************************/
46 #include <fna.h>
47 #include <fres_vres.h>
48 #include <frsh_forb.h>
49 #include "fwp_endpoint.h"
50 #include "fwp_vres.h"
51 #include "fwp.h"
52 #include "fwp_res.h"
53
54 int fwp_fna_init(const frsh_resource_id_t resource_id)
55 {
56         int rv;
57
58         if ((rv = fwp_init()))
59                 return rv;
60
61         return fra_fwp_init();
62 }
63
64 int fwp_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id,
65                         const frsh_rel_time_t *budget, size_t *nbytes)
66 {
67         *nbytes = budget->tv_nsec;
68         return 0;       
69 }
70
71 int fwp_fna_network_bytes_to_budget(const frsh_resource_id_t resource_id,
72                         const size_t nbytes, frsh_rel_time_t *budget)
73 {
74         budget->tv_nsec = nbytes;
75         budget->tv_sec = 0;
76         return 0;
77 }
78
79 int fwp_fna_send_endpoint_created(fna_endpoint_data_t  *endpoint)
80 {
81         unsigned int node, port;
82         fwp_endpoint_attr_t *attr;
83         fwp_endpoint_t *fwp_epoint;
84         int rv;
85
86         node = (unsigned int) endpoint->destination;
87         port = (unsigned int) endpoint->stream_id;
88         attr = (fwp_endpoint_attr_t*) endpoint->endpoint_protocol_info.send.body; 
89         rv = fwp_send_endpoint_create(node, port, attr, &fwp_epoint);
90         endpoint->protocol_info.body = fwp_epoint;
91         return rv;
92 }
93
94 int fwp_fna_receive_endpoint_created(fna_endpoint_data_t  *endpoint)
95 {
96         unsigned int node,port;
97         fwp_endpoint_attr_t *attr;
98         fwp_endpoint_t *fwp_epoint;
99         int rv;
100
101         node = (unsigned int) endpoint->destination;
102         port = (unsigned int) endpoint->stream_id;
103         attr = (fwp_endpoint_attr_t*) endpoint->protocol_info.body; 
104         rv = fwp_receive_endpoint_create(port, attr, &fwp_epoint);
105         if (rv)
106                 return rv;
107         
108         endpoint->protocol_info.body = fwp_epoint;
109         fwp_endpoint_get_params(fwp_epoint, &node, &port, attr);
110         endpoint->stream_id = port;
111         FWP_DEBUG("PORT= %d\n", port);
112
113         return 0;
114 }
115
116 int fwp_fna_send_endpoint_bind(fna_endpoint_data_t *endpoint, fna_vres_id_t vres)
117 {
118         return fwp_send_endpoint_bind(endpoint->protocol_info.body, 
119                                         (fwp_vres_d_t) vres->priv);
120 }
121
122 int fwp_fna_send_endpoint_unbind(fna_endpoint_data_t *endpoint)
123 {
124         return fwp_send_endpoint_unbind(endpoint->protocol_info.body);
125 }
126
127 int fwp_fna_endpoint_destroy(fna_endpoint_data_t  *endpoint)
128 {       
129         return fwp_endpoint_destroy(endpoint->endpoint_protocol_info.send.body);
130 }
131
132 /** FNA send routine */
133 int fwp_fna_send(const fna_endpoint_data_t *endpoint, const void *msg, 
134                         const size_t size)
135 {
136         fwp_endpoint_t *fwp_epoint;
137         int flags = 0;
138
139         fwp_epoint = endpoint->protocol_info.body;
140         return fwp_send(fwp_epoint, msg, size, flags);
141 }
142
143 int fwp_fna_send_sync(const fna_endpoint_data_t *endpoint, const void *msg, 
144                         const size_t size)
145 {
146         fwp_endpoint_t *fwp_epoint;
147         int flags = 0;
148
149         fwp_epoint = endpoint->protocol_info.body;
150         return fwp_send(fwp_epoint, msg, size, flags);
151 }
152
153 int fwp_fna_send_async(const fna_endpoint_data_t *endpoint,const void *msg,
154                    const size_t size)
155 {
156         fwp_endpoint_t *fwp_epoint;
157
158         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
159         return fwp_send(fwp_epoint, msg, size, MSG_DONTWAIT);
160 }
161
162 /** FNA receive routines */
163 int fwp_fna_receive(const fna_endpoint_data_t *endpoint,
164                         void *buffer, const size_t buffer_size,
165                         size_t *received_bytes, frsh_network_address_t *from)
166 {
167         unsigned int from_addr;
168         size_t len;
169         fwp_endpoint_t *fwp_epoint;
170         int flags = 0;
171         
172         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
173         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
174         if (len < 0) 
175                 return len;
176         
177         *received_bytes = len;
178         *from = from_addr;
179         
180         return 0;
181 }
182
183 int fwp_fna_receive_sync(const fna_endpoint_data_t *endpoint, void *buffer, 
184                          const size_t buffer_size, size_t *received_bytes, 
185                          frsh_network_address_t *from)
186 {
187         unsigned int from_addr;
188         size_t len;
189         fwp_endpoint_t *fwp_epoint;
190         int flags = 0;
191         
192         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
193         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
194         if (len < 0) 
195                 return len;
196         
197         *received_bytes = len;
198         *from = from_addr;
199         
200         return 0;
201 }
202
203 int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer, 
204                          const size_t buffer_size, size_t *received_bytes, 
205                          frsh_network_address_t *from)
206 {
207         unsigned int from_addr;
208         size_t len;
209         fwp_endpoint_t *fwp_epoint;
210         int flags = 0;
211         
212         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
213         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
214         if (len < 0) 
215                 return len;
216         
217         *received_bytes = len;
218         *from = from_addr;
219         
220         return 0;
221 }
222
223 int fwp_fna_vres_destroy(const frsh_resource_id_t resource_id,
224                      const fna_vres_id_t vres)
225 {
226 //      return fwp_vres_close(vres);    
227         return 0;
228 }
229
230 fna_operations_t fwp_fna_operations = {
231     .fna_init = fwp_fna_init,
232     .fna_contract_negotiate = NULL,
233     .fna_contract_renegotiate_sync = NULL,
234     .fna_contract_renegotiate_async = NULL,
235     .fna_vres_get_renegotiation_status = NULL,
236     .fna_vres_destroy = fwp_fna_vres_destroy,
237     .fna_vres_get_contract = NULL,
238     .fna_vres_get_usage = NULL,
239     .fna_vres_get_remaining_budget = NULL,
240     .fna_vres_get_budget_and_period = NULL,
241     .fna_resource_get_capacity = NULL,
242     .fna_resource_get_total_weight = NULL,
243     .fna_vres_decrease_capacity = NULL,
244     .fna_send_sync = NULL,
245     .fna_send_async = fwp_fna_send_async,
246     .fna_receive_sync = fwp_fna_receive_sync,
247     .fna_receive_async = fwp_fna_receive_async,
248     .fna_send_endpoint_get_status = NULL,
249     .fna_endpoint_destroy = fwp_fna_endpoint_destroy,
250     .fna_send_endpoint_created = fwp_fna_send_endpoint_created,
251     .fna_send_endpoint_bind = fwp_fna_send_endpoint_bind,
252     .fna_send_endpoint_unbind = fwp_fna_send_endpoint_unbind,
253     .fna_receive_endpoint_created = fwp_fna_receive_endpoint_created,
254     .fna_receive_endpoint_get_status = NULL,
255     .fna_network_get_max_message_size = NULL,
256     .fna_network_bytes_to_budget = fwp_fna_network_bytes_to_budget,
257     .fna_network_budget_to_bytes = fwp_fna_network_budget_to_bytes,
258     .fna_network_get_min_eff_budget = NULL
259 };
260