1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
5 /* Universidad de Cantabria, SPAIN */
6 /* University of York, UK */
7 /* Scuola Superiore Sant'Anna, ITALY */
8 /* Kaiserslautern University, GERMANY */
9 /* Univ. Politécnica Valencia, SPAIN */
10 /* Czech Technical University in Prague, CZECH REPUBLIC */
12 /* Thales Communication S.A. FRANCE */
13 /* Visual Tools S.A. SPAIN */
14 /* Rapita Systems Ltd UK */
17 /* See http://www.frescor.org for a link to partners' websites */
19 /* FRESCOR project (FP6/2005/IST/5-034026) is funded */
20 /* in part by the European Union Sixth Framework Programme */
21 /* The European Union is not liable of any use that may be */
22 /* made of this code. */
25 /* This file is part of FRSH (FRescor ScHeduler) */
27 /* FRSH is free software; you can redistribute it and/or modify it */
28 /* under terms of the GNU General Public License as published by the */
29 /* Free Software Foundation; either version 2, or (at your option) any */
30 /* later version. FRSH is distributed in the hope that it will be */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
33 /* General Public License for more details. You should have received a */
34 /* copy of the GNU General Public License along with FRSH; see file */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
36 /* Cambridge, MA 02139, USA. */
38 /* As a special exception, including FRSH header files in a file, */
39 /* instantiating FRSH generics or templates, or linking other files */
40 /* with FRSH objects to produce an executable application, does not */
41 /* by itself cause the resulting executable application to be covered */
42 /* by the GNU General Public License. This exception does not */
43 /* however invalidate any other reasons why the executable file might be */
44 /* covered by the GNU Public License. */
45 /**************************************************************************/
48 * @file fres_contract.h
49 * @author Michal Sojka <sojkam1@fel.cvut.cz>
50 * @date Sun Nov 9 22:15:09 2008
52 * @brief Declaration of contract type and functions
56 #ifndef FRES_CONTRACT_H
57 #define FRES_CONTRACT_H
59 #include <fres_blocks.h>
60 #include <fres_container.h>
62 #include <fres_contract_type.h>
63 #include <fres_contract_idl.h>
64 #include <forb/server_id.h>
74 struct fres_contract {
75 fres_contract_id_t id; /**< Global contract ID */
76 struct fres_container *container; /**< Pointer to the block container (opaque type). */
79 static inline int fres_contract_id_cmp(const fres_contract_id_t *a,
80 const fres_contract_id_t *b)
82 return forb_server_id_cmp((forb_server_id*)a,
86 static inline bool fres_contract_id_is_empty(const fres_contract_id_t *id)
91 for (i=0; i<sizeof(id->byte); i++) {
92 if (id->byte[i] != 0) {
100 static inline char *fres_contract_id_to_string(char *dest,
101 const fres_contract_id_t *id,
104 return forb_server_id_to_string(dest, (forb_server_id*)id, n);
107 struct fres_contract *fres_contract_new(void);
108 void fres_contract_destroy(struct fres_contract *contract);
110 /** Destructor for easy use in forb_sequence_free() */
111 static inline void fres_contract_ptr_destroy(struct fres_contract **p)
113 fres_contract_destroy(*p);
117 struct fres_contract *fres_contract_duplicate(struct fres_contract *src);
120 * Adds a block of the given type to the contract.
122 * This function uses fres_container_add_block() to do its job.
124 * @param contract Where to add the @a block.
125 * @param type Type of contract being added.
126 * @param block Pointer to the malloced block of given @a type.
128 * @return Zero on success, -1 on error and errno is set appropriately.
131 fres_contract_add_block(struct fres_contract *contract,
132 enum fres_block_type type, void *block)
134 return fres_container_add_block(contract->container, type, block);
137 * Deletes a block from the contract and frees it from memory.
139 * This function uses fres_container_del_block() to do its job.
141 * @param contract Where to delete the block.
142 * @param type Type of contract to delete.
145 fres_contract_del_block(struct fres_contract *contract,
146 enum fres_block_type type)
148 fres_container_del_block(contract->container, type);
152 * Returns pointer to a contract block of a particular @a type.
154 * This function uses fres_container_get_block() to do its job.
157 * @param type Type of the block to be returned.
159 * @return Pointer to the block or NULL if the block is not present or
160 * deserialized. The memory area pointed by this pointer is owned by
161 * the contract. If the user needs to store the block, it must be
165 fres_contract_get_block(struct fres_contract *contract,
166 enum fres_block_type type)
168 return fres_container_get_block(contract->container, type);
172 fres_contract_to_string(char *dest, size_t size, const struct fres_contract *c);
174 /* #define FRES_C2S_FL_FMT_ONELINE */
175 /* #define FRES_C2S_FL_FMT_BLOCKPERLINE */
177 fres_contract_to_string2(char *dest, size_t size, const struct fres_contract *c, int indent, uint32_t flags);
180 fres_contract_get_deadline(const frsh_contract_t *contract,
181 frsh_rel_time_t *deadline);
183 fres_contract_get_budget(const frsh_contract_t *contract,
184 frsh_rel_time_t *budget);
186 fres_contract_get_period(const frsh_contract_t *contract,
187 frsh_rel_time_t *period);
189 fres_contract_get_type(const frsh_contract_t *contract);
192 fres_contract_print(char *prefix, const struct fres_contract *c);
195 fres_contract_get_num_blocks(const struct fres_contract *c)
197 return fres_container_get_num_blocks(c->container);
201 fres_contract_merge(struct fres_contract *dest,
202 const struct fres_contract *src)
204 return fres_container_merge(dest->container, src->container);
209 * Macro which defines type-safe contract "accessor" functions for
212 * This macro declares the following inline functions:
213 * - fres_contract_add_<type>
214 * - fres_contract_get_<type>
215 * - fres_contract_del_<type>
217 * The defined functions simply use the container "accessor" functions
218 * (usually defined) by #FRES_CONTAINER_ACCESSOR and are equivalent to
219 * fres_contract_add_block(), fres_contract_del_block() and
220 * fres_contract_get_block() with appropriate parameters.
222 #define FRES_CONTRACT_ACCESSOR(type) \
224 fres_contract_add_##type(struct fres_contract *contract, \
225 fres_block_##type *block) \
227 return fres_container_add_##type(contract->container, \
230 static inline fres_block_##type * \
231 fres_contract_get_##type(const struct fres_contract *contract) \
233 return fres_container_get_##type(contract->container); \
236 fres_contract_del_##type(struct fres_contract *contract) \
238 fres_container_del_##type(contract->container); \
241 FRES_CONTRACT_ACCESSOR(label)
242 FRES_CONTRACT_ACCESSOR(resource)
243 FRES_CONTRACT_ACCESSOR(basic)
244 FRES_CONTRACT_ACCESSOR(timing_reqs)
245 FRES_CONTRACT_ACCESSOR(csects)
246 FRES_CONTRACT_ACCESSOR(spare_capacity)
247 FRES_CONTRACT_ACCESSOR(power_management)