2 * @file fres_contract.h
3 * @author Michal Sojka <sojkam1@fel.cvut.cz>
4 * @date Sun Nov 9 22:15:09 2008
6 * @brief Declaration of contract type and functions
10 #ifndef FRES_CONTRACT_H
11 #define FRES_CONTRACT_H
13 #include <fres_blocks.h>
14 #include <fres_container.h>
16 #include <fres_contract_type.h>
17 #include <fres_contract_idl.h>
18 #include <forb/server_id.h>
24 struct fres_contract {
25 fres_contract_id_t id; /**< Global contract ID */
26 struct fres_container *container; /**< Pointer to the block container (opaque type). */
29 static inline int fres_contract_id_cmp(const fres_contract_id_t *a,
30 const fres_contract_id_t *b)
32 return forb_server_id_cmp((forb_server_id*)a,
36 static inline char *fres_contract_id_to_string(char *dest,
37 const fres_contract_id_t *id,
40 return forb_server_id_to_string(dest, (forb_server_id*)id, n);
43 struct fres_contract *fres_contract_new(void);
44 void fres_contract_destroy(struct fres_contract *contract);
45 struct fres_contract *fres_contract_duplicate(struct fres_contract *src);
48 fres_contract_add_block(struct fres_contract *contract,
49 enum fres_block_type type, void *block)
51 return fres_container_add_block(contract->container, type, block);
54 fres_contract_del_block(struct fres_contract *contract,
55 enum fres_block_type type)
57 fres_container_del_block(contract->container, type);
61 fres_contract_get_block(struct fres_contract *contract,
62 enum fres_block_type type)
64 return fres_container_get_block(contract->container, type);
68 fres_contract_to_string(char *dest, size_t size, const struct fres_contract *c);
71 fres_contract_get_deadline(const frsh_contract_t *contract,
72 frsh_rel_time_t *deadline);
74 fres_contract_print(char *prefix, const struct fres_contract *c);
76 #define FRES_CONTRACT_ACCESSOR(type) \
78 fres_contract_add_##type(struct fres_contract *contract, \
79 fres_block_##type *block) \
81 return fres_container_add_##type(contract->container, \
84 static inline fres_block_##type * \
85 fres_contract_get_##type(struct fres_contract *contract) \
87 return fres_container_get_##type(contract->container); \
90 fres_contract_del_##type(struct fres_contract *contract) \
92 fres_container_del_##type(contract->container); \
95 FRES_CONTRACT_ACCESSOR(label)
96 FRES_CONTRACT_ACCESSOR(resource)
97 FRES_CONTRACT_ACCESSOR(basic)
98 FRES_CONTRACT_ACCESSOR(timing_reqs)
99 FRES_CONTRACT_ACCESSOR(spare_capacity)