1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
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 */
12 /* Thales Communication S.A. FRANCE */
13 /* Visual Tools S.A. SPAIN */
14 /* Rapita Systems Ltd UK */
17 /* See http://www.frescor.org for a link to partners' websites */
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. */
25 /* This file is part of FWP (Frescor WLAN Protocol) */
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. */
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 /**************************************************************************/
47 #include <fres_vres.h>
48 #include <frsh_forb.h>
49 #include "fwp_endpoint.h"
54 int fwp_fna_init(const frsh_resource_id_t resource_id)
58 if ((rv = fwp_init()))
61 return fra_fwp_init(frsh_forb_global.orb, frsh_forb_global.fcb,
62 &frsh_forb_global.alloc_executor);
65 int fwp_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id,
66 const frsh_rel_time_t *budget, size_t *nbytes)
68 *nbytes = budget->tv_nsec;
72 int fwp_fna_network_bytes_to_budget(const frsh_resource_id_t resource_id,
73 const size_t nbytes, frsh_rel_time_t *budget)
75 budget->tv_nsec = nbytes;
80 int fwp_fna_send_endpoint_created(fna_endpoint_data_t *endpoint)
82 unsigned int node, port;
83 fwp_endpoint_attr_t *attr;
84 fwp_endpoint_t *fwp_epoint;
87 node = (unsigned int) endpoint->destination;
88 port = (unsigned int) endpoint->stream_id;
89 attr = (fwp_endpoint_attr_t*) endpoint->endpoint_protocol_info.send.body;
90 rv = fwp_send_endpoint_create(node, port, attr, &fwp_epoint);
93 endpoint->protocol_info.body = fwp_epoint;
97 int fwp_fna_receive_endpoint_created(fna_endpoint_data_t *endpoint)
99 unsigned int node,port;
100 fwp_endpoint_attr_t *attr;
101 fwp_endpoint_t *fwp_epoint;
104 node = (unsigned int) endpoint->destination;
105 port = (unsigned int) endpoint->stream_id;
106 attr = (fwp_endpoint_attr_t*) endpoint->protocol_info.body;
107 rv = fwp_receive_endpoint_create(port, attr, &fwp_epoint);
111 endpoint->protocol_info.body = fwp_epoint;
112 fwp_endpoint_get_params(fwp_epoint, &node, &port, attr);
113 endpoint->stream_id = fwp_epoint->port;
118 int fwp_fna_send_endpoint_bind(fna_endpoint_data_t *endpoint, fna_vres_id_t vres)
120 return fwp_send_endpoint_bind(endpoint->protocol_info.body,
121 (fwp_vres_d_t) vres->priv);
124 int fwp_fna_send_endpoint_unbind(fna_endpoint_data_t *endpoint)
126 return fwp_send_endpoint_unbind(endpoint->protocol_info.body);
129 int fwp_fna_endpoint_destroy(fna_endpoint_data_t *endpoint)
131 return fwp_endpoint_destroy(endpoint->endpoint_protocol_info.send.body);
134 /** FNA send routine */
135 int fwp_fna_send(const fna_endpoint_data_t *endpoint, const void *msg,
138 fwp_endpoint_t *fwp_epoint;
141 fwp_epoint = endpoint->protocol_info.body;
142 return fwp_send(fwp_epoint, msg, size, flags);
145 int fwp_fna_send_sync(const fna_endpoint_data_t *endpoint, const void *msg,
148 fwp_endpoint_t *fwp_epoint;
151 fwp_epoint = endpoint->protocol_info.body;
152 return fwp_send(fwp_epoint, msg, size, flags);
155 int fwp_fna_send_async(const fna_endpoint_data_t *endpoint,const void *msg,
158 fwp_endpoint_t *fwp_epoint;
160 fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
161 return fwp_send(fwp_epoint, msg, size, MSG_DONTWAIT);
164 /** FNA receive routines */
165 int fwp_fna_receive(const fna_endpoint_data_t *endpoint,
166 void *buffer, const size_t buffer_size,
167 size_t *received_bytes, frsh_network_address_t *from)
169 unsigned int from_addr;
171 fwp_endpoint_t *fwp_epoint;
174 fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
175 len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
179 *received_bytes = len;
185 int fwp_fna_receive_sync(const fna_endpoint_data_t *endpoint, void *buffer,
186 const size_t buffer_size, size_t *received_bytes,
187 frsh_network_address_t *from)
189 unsigned int from_addr;
191 fwp_endpoint_t *fwp_epoint;
194 fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
195 len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
199 *received_bytes = len;
205 int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer,
206 const size_t buffer_size, size_t *received_bytes,
207 frsh_network_address_t *from)
209 unsigned int from_addr;
211 fwp_endpoint_t *fwp_epoint;
214 fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
215 len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
219 *received_bytes = len;
225 int fwp_fna_vres_destroy(const frsh_resource_id_t resource_id,
226 const fna_vres_id_t vres)
228 // return fwp_vres_close(vres);
232 fna_operations_t fwp_fna_operations = {
233 .fna_init = fwp_fna_init,
234 .fna_contract_negotiate = NULL,
235 .fna_contract_renegotiate_sync = NULL,
236 .fna_contract_renegotiate_async = NULL,
237 .fna_vres_get_renegotiation_status = NULL,
238 .fna_vres_destroy = fwp_fna_vres_destroy,
239 .fna_vres_get_contract = NULL,
240 .fna_vres_get_usage = NULL,
241 .fna_vres_get_remaining_budget = NULL,
242 .fna_vres_get_budget_and_period = NULL,
243 .fna_resource_get_capacity = NULL,
244 .fna_resource_get_total_weight = NULL,
245 .fna_vres_decrease_capacity = NULL,
246 .fna_send_sync = NULL,
247 .fna_send_async = fwp_fna_send_async,
248 .fna_receive_sync = fwp_fna_receive_sync,
249 .fna_receive_async = fwp_fna_receive_async,
250 .fna_send_endpoint_get_status = NULL,
251 .fna_endpoint_destroy = fwp_fna_endpoint_destroy,
252 .fna_send_endpoint_created = fwp_fna_send_endpoint_created,
253 .fna_send_endpoint_bind = fwp_fna_send_endpoint_bind,
254 .fna_send_endpoint_unbind = fwp_fna_send_endpoint_unbind,
255 .fna_receive_endpoint_created = fwp_fna_receive_endpoint_created,
256 .fna_receive_endpoint_get_status = NULL,
257 .fna_network_get_max_message_size = NULL,
258 .fna_network_bytes_to_budget = fwp_fna_network_bytes_to_budget,
259 .fna_network_budget_to_bytes = fwp_fna_network_budget_to_bytes,
260 .fna_network_get_min_eff_budget = NULL