]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/fwp_fna.c
29e9d09f921f0a69449eac812e051216a5613beb
[frescor/fwp.git] / fwp / lib / fwp_fna.c
1 #include "fna.h"
2 #include "fwp_vres.h"
3 #include "fwp_msg.h"
4 #include "fwp_ctable.h"
5
6 int fwp_fna_init(const frsh_resource_id_t resource_id);
7 {
8         fwp_init();
9 }
10
11 /** FNA negotiate routine */
12
13 int fwp_fna_contract_negotiate
14         (const frsh_resource_id_t resource_id,
15         const frsh_contract_t *contract,
16         fna_vres_id_t *vres)
17 {
18         struct fwp_contract cnt;
19         int res;
20
21         /* copy to fwp_contract */
22         cnt.period_usec = contract->period;
23         cnt.budget = contract->budget;
24         
25         res = fwp_negotiate(&cnt);
26         if (res < 0) 
27                 return -1;
28
29         *vres = res;
30         return 0;
31 }
32
33
34 /** FNA send routine */
35
36 int fwp_fna_send(const fna_endpoint_data_t *endpoint,const void *msg,
37                    const size_t size, int flags)
38 {
39         struct sockaddr_in to_addr;
40
41         to_addr.sin_family = AF_INET;
42         to_addr.sin_addr.s_addr = inet_addr(endpoint->destination);
43         to_addr.sin_port = htons(endpoint->stream_id);
44         
45         fwp_send(endpoint->vres, msg, size, flags, to_addr,
46                       sizeof(to_addr));
47 }
48
49 int fwp_fna_send_sync(const fna_endpoint_data_t *endpoint,const void *msg,
50                    const size_t size)
51 {
52         return fwp_fna_send(endpoint, msg, size, 0)
53 {
54
55
56 int fwp_fna_send_async(const fna_endpoint_data_t *endpoint,const void *msg,
57                    const size_t size)
58 {
59         return fwp_fna_send(endpoint, msg, size, MSG_DONTWAIT)
60 {
61
62 /** FNA receive routines */
63
64 int fwp_fna_receive(const fna_endpoint_data_t *endpoint, void *buffer, 
65                          const size_t buffer_size, size_t *received_bytes, 
66                          frsh_network_address_t *from, int flags)
67
68 {
69         struct  sockaddr_in from_addr;
70         socklen_t fromlen = sizeof(from_in);
71
72         len = fwp_receive(endpoint->stream_id, buffer, buffer_size, flags, 
73                           &from_addr, &fromlen);
74         if (!len) 
75                 return FNA_ERR_INTERNAL_ERR;
76         
77         *received_bytes = len;
78         *from = from_addr.sin_addr.s_addr;
79         
80         return 0;
81 }
82
83 int fwp_fna_receive_sync(const fna_endpoint_data_t *endpoint, void *buffer, 
84                          const size_t buffer_size, size_t *received_bytes, 
85                          frsh_network_address_t *from)
86 {
87
88         return fwp_fna_receive(endpoint, buffer, buffer_size, received_bytes,
89                                from, 0);
90 }
91
92 int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer, 
93                          const size_t buffer_size, size_t *received_bytes, 
94                          frsh_network_address_t *from)
95 {
96         return fwp_fna_receive(endpoint, buffer, buffer_size, received_bytes,
97                                from, MSG_DONTWAIT);
98 }
99
100 int fwp_fna_receive_endpoint_created (void)
101 {
102         INADDR_ANY
103         fwp_receive_endpoint_create(fwp_configuration.my_node_id,..);
104
105 }
106
107
108 int fwp_fna_vres_destroy(const frsh_resource_id_t resource_id,
109                      const fna_vres_id_t vres)
110 {
111         return fwp_vres_close(vres);    
112 }
113
114 /*fna_operations_t fwp_fna_operations = {
115     .fna_init = fwp_fna_init,
116     .fna_contract_negotiate = NULL,
117     .fna_contract_renegotiate_sync = NULL,
118     .fna_contract_renegotiate_async = NULL,
119     .fna_vres_get_renegotiation_status = NULL,
120     .fna_vres_destroy = fwp_fna_vres_destroy,
121     .fna_vres_get_contract = NULL,
122     .fna_vres_get_usage = NULL,
123     .fna_vres_get_remaining_budget = NULL,
124     .fna_vres_get_budget_and_period = NULL,
125     .fna_resource_get_capacity = NULL,
126     .fna_resource_get_total_weight = NULL,
127     .fna_vres_decrease_capacity = NULL,
128     .fna_send_sync = NULL,
129     .fna_send_async = fwp_fna_send_async,
130     .fna_receive_sync = fwp_fna_receive_sync,
131     .fna_receive_async = fwp_fna_receive_async,
132     .fna_send_endpoint_get_status = NULL,
133     .fna_receive_endpoint_created = NULL,
134     .fna_receive_endpoint_get_status = NULL,
135     .fna_network_get_max_message_size = NULL,
136     .fna_network_bytes_to_budget = NULL,
137     .fna_network_budget_to_bytes = NULL,
138     .fna_network_get_min_eff_budget = NULL
139 }*/