]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - cm/forb_contract.h
Split to multiple directories
[frescor/frsh.git] / cm / forb_contract.h
1 /**
2  * @file   forb_contract.h
3  * @author Michal Sojka <sojkam1@fel.cvut.cz>
4  * 
5  * @brief  Public interface to forb-based contracts.
6  * 
7  * 
8  */
9 #ifndef FORB_CONTRACT_H
10 #define FORB_CONTRACT_H
11
12
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>
18
19 /*============================================================================*/
20
21 /**
22  * Data type for represenataion of contracts (imcomplete declaration).
23  */
24 struct forb_contract;
25
26
27 /**
28  * Identification of different types of contract parameters.
29  *
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).
34  * 
35  */
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
41 };
42
43 struct forb_contract_params_desc {
44         size_t size;
45         CORBA_boolean (*serialize)(CDR_Codec *codec, const void *params);
46         CORBA_boolean (*deserialize)(CDR_Codec *codec, void **params);
47 };
48
49 /** 
50  * Allocates memory for a new contract.
51  * 
52  * @return 
53  */
54 struct forb_contract *
55 forb_contract_new(void);
56
57 /** 
58  * Deallocates all memory occupied by a contract.
59  * 
60  * @param contract 
61  */
62 void
63 forb_contract_destroy(struct forb_contract *contract);
64
65 /** 
66  * Adds parameters of a specific type to a contract.
67  * 
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).
72  * 
73  * @return Zero on success, FRSH_ERR_BAD_ARGUMENT if the contract
74  * already contains this @a type of parameters.
75  */
76 int
77 forb_contract_add_params(struct forb_contract *contract,
78                          enum forb_contract_params_type type,
79                          void *params);
80 /** 
81  * Removes specific parameters from a contract and frees all memory
82  * occupied by these parameters.
83  * 
84  * @param contract 
85  * @param type Which type of parameters to remove.
86  * 
87  * @return 
88  */
89 int
90 forb_contract_del_params(struct forb_contract *contract,
91                          enum forb_contract_params_type type);
92
93 /** 
94  * Return a specific type of contract parameters.
95  * 
96  * @param contract 
97  * @param type Which parameters to return.
98  * 
99  * @return Pointer to the requested parameters of NULL if the
100  * parameters was not added to the contract.
101  */
102 void *
103 forb_contract_get_params(struct forb_contract *contract,
104                          enum forb_contract_params_type type);
105
106 CORBA_boolean
107 forb_contract_serialize(CDR_Codec *codec, const struct forb_contract *contract);
108
109 CORBA_boolean
110 forb_contract_deserialize(CDR_Codec *codec, struct forb_contract **contract);
111
112 #define FORB_CONTRACT_ACCESSOR(TYPE, type)                              \
113         static inline int                                               \
114         forb_contract_add_params_##type(struct forb_contract *contract, \
115                                         forb_contract_params_##type *params) \
116         {                                                               \
117                 return forb_contract_add_params(contract,               \
118                                                 FORB_CONTRACT_PARAMS_##TYPE, \
119                                                 params);                \
120         }                                                               \
121         static inline forb_contract_params_##type *                     \
122         forb_contract_get_params_##type(struct forb_contract *contract) \
123         {                                                               \
124                 return forb_contract_get_params(contract,               \
125                                                 FORB_CONTRACT_PARAMS_##TYPE); \
126         }                                                               \
127         static inline int                                               \
128         forb_contract_del_params_##type(struct forb_contract *contract) \
129         {                                                               \
130                 return forb_contract_del_params(contract,               \
131                                                 FORB_CONTRACT_PARAMS_##TYPE); \
132         }
133
134 FORB_CONTRACT_ACCESSOR(BASIC,           basic);
135 FORB_CONTRACT_ACCESSOR(TIMING_REQS,     timing_reqs);
136 FORB_CONTRACT_ACCESSOR(SPARE_CAPACITY,  spare_capacity);
137
138 #endif