2 * @file forb_contract.h
3 * @author Michal Sojka <sojkam1@fel.cvut.cz>
5 * @brief Public interface to forb-based contracts.
9 #ifndef FORB_CONTRACT_H
10 #define FORB_CONTRACT_H
13 #include <forb/basic_types.h>
14 #include <frsh_cpp_macros.h>
15 #include <fosa_types.h>
16 #include <frsh_core_types.h>
17 #include <forb_contract_idl.h>
19 /*============================================================================*/
22 * Data type for represenataion of contracts (imcomplete declaration).
28 * Identification of different types of contract parameters.
30 * All contract parameters should define their ID here. This is the
31 * only place, where the different parameters (e.g. for different
32 * kinds of resources) share a common source file. The declaration of
33 * params struture can occur at any place (.h or better .idl).
36 enum forb_contract_params_type {
37 FORB_CONTRACT_PARAMS_BASIC,
38 FORB_CONTRACT_PARAMS_TIMING_REQS,
39 FORB_CONTRACT_PARAMS_SPARE_CAPACITY,
40 _FORB_CONTRACT_NUM_PARAMS
43 struct forb_contract_params_desc {
45 CORBA_boolean (*serialize)(CDR_Codec *codec, const void *params);
46 CORBA_boolean (*deserialize)(CDR_Codec *codec, void **params);
50 * Allocates memory for a new contract.
54 struct forb_contract *
55 forb_contract_new(void);
58 * Deallocates all memory occupied by a contract.
63 forb_contract_destroy(struct forb_contract *contract);
66 * Adds parameters of a specific type to a contract.
68 * @param contract Contract to which add the parameters.
69 * @param type Which type of parameters is being added.
70 * @param params Values of parameters to add (in most cases pointer to
71 * a structure defined in IDL).
73 * @return Zero on success, FRSH_ERR_BAD_ARGUMENT if the contract
74 * already contains this @a type of parameters.
77 forb_contract_add_params(struct forb_contract *contract,
78 enum forb_contract_params_type type,
81 * Removes specific parameters from a contract and frees all memory
82 * occupied by these parameters.
85 * @param type Which type of parameters to remove.
90 forb_contract_del_params(struct forb_contract *contract,
91 enum forb_contract_params_type type);
94 * Return a specific type of contract parameters.
97 * @param type Which parameters to return.
99 * @return Pointer to the requested parameters of NULL if the
100 * parameters was not added to the contract.
103 forb_contract_get_params(struct forb_contract *contract,
104 enum forb_contract_params_type type);
107 forb_contract_serialize(CDR_Codec *codec, const struct forb_contract *contract);
110 forb_contract_deserialize(CDR_Codec *codec, struct forb_contract **contract);
112 #define FORB_CONTRACT_ACCESSOR(TYPE, type) \
114 forb_contract_add_params_##type(struct forb_contract *contract, \
115 forb_contract_params_##type *params) \
117 return forb_contract_add_params(contract, \
118 FORB_CONTRACT_PARAMS_##TYPE, \
121 static inline forb_contract_params_##type * \
122 forb_contract_get_params_##type(struct forb_contract *contract) \
124 return forb_contract_get_params(contract, \
125 FORB_CONTRACT_PARAMS_##TYPE); \
128 forb_contract_del_params_##type(struct forb_contract *contract) \
130 return forb_contract_del_params(contract, \
131 FORB_CONTRACT_PARAMS_##TYPE); \
134 FORB_CONTRACT_ACCESSOR(BASIC, basic);
135 FORB_CONTRACT_ACCESSOR(TIMING_REQS, timing_reqs);
136 FORB_CONTRACT_ACCESSOR(SPARE_CAPACITY, spare_capacity);