]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - resources/item/tests/test_item.c
Finished integration of ITEM
[frescor/frsh.git] / resources / item / tests / test_item.c
1 #include <frsh.h>
2 #include <error.h>
3 #include <item.h>
4 #include <fres_contract.h>
5
6 #define N 3
7
8 int contract_deadline_sec[N] = { 8, 8, 4 };
9 int contract_nodes[N] = { 0x01, 0x03, 0x02 };
10
11 int main(int argc, char *argv[])
12 {
13         int ret;
14         frsh_contract_t contract[N];
15         frsh_vres_id_t vres[N];
16         int i;
17
18         ret = frsh_init();
19         if (ret) PERROR_AND_EXIT(ret, "frsh_init");
20
21         /* Negotiate N contracts */
22         for (i=0; i<N; i++) {
23                 frsh_rel_time_t deadline;
24                 frsh_signal_info_t si;
25                 fres_block_item_nodes *nodes;
26                 ret = frsh_contract_init(&contract[i]);
27                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
28
29                 /* Set nodes we want to receive data from */
30                 nodes = malloc(sizeof(*nodes));
31                 if (!nodes) PERROR_AND_EXIT(errno, "malloc");
32                 nodes->mask = contract_nodes[i];
33                 ret = fres_contract_add_block(contract[i], FRES_BLOCK_ITEM_NODES,
34                                               nodes);
35                 if (ret) PERROR_AND_EXIT(ret, "Cannot add item_nodes block\n");
36
37                 /* Set deadline */
38                 deadline = fosa_msec_to_rel_time(contract_deadline_sec[i]*1000);
39                 ret = frsh_contract_set_timing_reqs(&contract[i],
40                                                     false, &deadline,
41                                             0, si, 0, si);
42                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_timing_reqs");
43
44                 /* Negotiate the contract */
45                 ret = frsh_contract_negotiate(&contract[i], &vres[i]);
46                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
47         }
48         printf("Contracts negotiated\n");
49
50         for (i=0; i<10; i++) {
51                 int j;
52                 printf("Reading data\n");
53                 for (j=0; j<N; j++) {
54                         unsigned *data;
55                         ret = frs_item_receive(vres[j], &data);
56                         if (ret == -1) PERROR_AND_EXIT(errno, "frs_item_receive");
57                         
58                         /* TODO: Do something with the received data */
59
60                         forb_free(data);
61                 }
62                 sleep(1);
63         }
64
65 /*      for (i=0; i<N; i++) { */
66 /*              frsh_cancel_contract(vres[i]); */
67 /*      }        */
68         return 0;
69 }