]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_contract.c
Split to multiple directories
[frescor/frsh.git] / frsh_api / frsh_contract.c
1 /**
2  * @file   frsh_contract.c
3  * @author Michal Sojka <sojkam1@fel.cvut.cz>
4  * 
5  * @brief  Implementation of FRSH contract API on top of forb-based contracts.
6  * 
7  * 
8  */
9 #include <forb_contract.h>
10 #include "forb_contract_internal.h"
11 #include <forb_contract_idl.h>
12 #include <frsh_core.h>
13 #include <frsh_error.h>
14
15
16 /**********************************/
17 /* -----===== FRSH API =====----- */
18 /**********************************/
19
20 int
21 frsh_contract_init(frsh_contract_t *contract)
22 {
23         struct forb_contract *c;
24
25         if (!contract) {
26                 return FRSH_ERR_BAD_ARGUMENT;
27         }
28         c = forb_contract_new();
29         *contract = c;
30         if (!c) {
31                 return FOSA_ENOMEM;
32         }
33         
34         
35         return 0;
36 }
37
38 int frsh_contract_set_basic_params
39   (frsh_contract_t *contract,
40    const frsh_rel_time_t      *budget_min,
41    const frsh_rel_time_t      *period_max,
42    const frsh_workload_t      workload,
43    const frsh_contract_type_t contract_type)
44 {
45         forb_contract_params_basic *b;
46         if (!contract ||
47             !*contract ||
48             !budget_min ||
49             !period_max) {
50                 return FRSH_ERR_BAD_ARGUMENT;
51         }
52
53         b = malloc(sizeof(*b));
54         if (!b) {
55                 /* We should return something else, but the FRSH API
56                  * allows only this error. errno is set correctly. */
57                 return FRSH_ERR_BAD_ARGUMENT;
58         }
59
60         b->budget = *budget_min;
61         b->period = *period_max;
62         b->workload = workload; /* FIXME: Handle type range */
63         b->contract_type = contract_type; /* FIXME: Handle type range */
64         return forb_contract_add_params_basic(*contract, b);
65 }
66
67 int frsh_contract_set_resource_and_label
68   (frsh_contract_t *contract,
69    const frsh_resource_type_t resource_type,
70    const frsh_resource_id_t resource_id,
71    const char *contract_label)
72 {
73         struct forb_contract *c;
74         if (!contract || !*contract)
75                 return FRSH_ERR_BAD_ARGUMENT;
76         c = *contract;
77
78         c->resource_type = resource_type;
79         c->resource_id = resource_id;
80         /* contract_label is currently ignored */
81         return 0;
82 }
83
84 int frsh_contract_set_timing_reqs
85   (frsh_contract_t *contract,
86    const bool                   d_equals_t,
87    const frsh_rel_time_t        *deadline,
88    const frsh_signal_t          budget_overrun_signal,
89    const frsh_signal_info_t     budget_overrun_siginfo,
90    const frsh_signal_t          deadline_miss_signal,
91    const frsh_signal_info_t     deadline_miss_siginfo)
92 {
93         forb_contract_params_timing_reqs *p;
94
95         if (!contract || !*contract)
96                 return FRSH_ERR_BAD_ARGUMENT;
97
98         p = malloc(sizeof(*p));
99         if (!p) {
100                 /* We should return something else, but the FRSH API
101                  * allows only this error. errno is set correctly. */
102                 return FRSH_ERR_BAD_ARGUMENT;
103         }
104         p->d_equals_t = d_equals_t;
105         if (!d_equals_t) {
106                 if (deadline) {
107                         p->deadline = *deadline;
108                 } else {
109                         return FRSH_ERR_BAD_ARGUMENT;
110                 }
111         }
112         return forb_contract_add_params_timing_reqs(*contract, p);
113 }