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>
67 # define __STDC_FORMAT_MACROS
78 struct fres_contract {
79 fres_contract_id_t id; /**< Global contract ID */
80 struct fres_container *container; /**< Pointer to the block container (opaque type). */
83 static inline int fres_contract_id_cmp(const fres_contract_id_t *a,
84 const fres_contract_id_t *b)
86 return forb_server_id_cmp((forb_server_id*)a,
90 static inline bool fres_contract_id_is_empty(const fres_contract_id_t *id)
92 /* bool empty = true; */
95 /* for (i=0; i<sizeof(id->byte); i++) { */
96 /* if (id->byte[i] != 0) { */
105 static inline char *fres_contract_id_to_string(char *dest,
106 const fres_contract_id_t *id,
109 snprintf(dest, n, "%"PRIx64, *id);
110 /* return forb_server_id_to_string(dest, (forb_server_id*)id, n); */
114 struct fres_contract *fres_contract_new(void);
115 void fres_contract_destroy(struct fres_contract *contract);
117 /** Destructor for easy use in forb_sequence_free() */
118 static inline void fres_contract_ptr_destroy(struct fres_contract **p)
120 fres_contract_destroy(*p);
124 struct fres_contract *fres_contract_duplicate(struct fres_contract *src);
127 * Adds a block of the given type to the contract.
129 * This function uses fres_container_add_block() to do its job.
131 * @param contract Where to add the @a block.
132 * @param type Type of contract being added.
133 * @param block Pointer to the malloced block of given @a type.
135 * @return Zero on success, -1 on error and errno is set appropriately.
138 fres_contract_add_block(struct fres_contract *contract,
139 enum fres_block_type type, void *block)
141 return fres_container_add_block(contract->container, type, block);
144 * Deletes a block from the contract and frees it from memory.
146 * This function uses fres_container_del_block() to do its job.
148 * @param contract Where to delete the block.
149 * @param type Type of contract to delete.
152 fres_contract_del_block(struct fres_contract *contract,
153 enum fres_block_type type)
155 fres_container_del_block(contract->container, type);
159 * Returns pointer to a contract block of a particular @a type.
161 * This function uses fres_container_get_block() to do its job.
164 * @param type Type of the block to be returned.
166 * @return Pointer to the block or NULL if the block is not present or
167 * deserialized. The memory area pointed by this pointer is owned by
168 * the contract. If the user needs to store the block, it must be
172 fres_contract_get_block(struct fres_contract *contract,
173 enum fres_block_type type)
175 return fres_container_get_block(contract->container, type);
179 fres_contract_to_string(char *dest, size_t size, const struct fres_contract *c);
181 /* #define FRES_C2S_FL_FMT_ONELINE */
182 /* #define FRES_C2S_FL_FMT_BLOCKPERLINE */
184 fres_contract_to_string2(char *dest, size_t size, const struct fres_contract *c, int indent, uint32_t flags);
187 fres_contract_get_deadline(const frsh_contract_t *contract,
188 frsh_rel_time_t *deadline);
190 fres_contract_get_budget(const frsh_contract_t *contract,
191 frsh_rel_time_t *budget);
193 fres_contract_get_period(const frsh_contract_t *contract,
194 frsh_rel_time_t *period);
196 fres_contract_get_type(const frsh_contract_t *contract);
199 fres_contract_print(char *prefix, const struct fres_contract *c);
202 fres_contract_get_num_blocks(const struct fres_contract *c)
204 return fres_container_get_num_blocks(c->container);
208 fres_contract_merge(struct fres_contract *dest,
209 const struct fres_contract *src)
211 return fres_container_merge(dest->container, src->container);
216 * Macro which defines type-safe contract "accessor" functions for
219 * This macro declares the following inline functions:
220 * - fres_contract_add_<type>
221 * - fres_contract_get_<type>
222 * - fres_contract_del_<type>
224 * The defined functions simply use the container "accessor" functions
225 * (usually defined) by #FRES_CONTAINER_ACCESSOR and are equivalent to
226 * fres_contract_add_block(), fres_contract_del_block() and
227 * fres_contract_get_block() with appropriate parameters.
229 #define FRES_CONTRACT_ACCESSOR(type) \
231 fres_contract_add_##type(struct fres_contract *contract, \
232 fres_block_##type *block) \
234 return fres_container_add_##type(contract->container, \
237 static inline fres_block_##type * \
238 fres_contract_get_##type(const struct fres_contract *contract) \
240 return fres_container_get_##type(contract->container); \
243 fres_contract_del_##type(struct fres_contract *contract) \
245 fres_container_del_##type(contract->container); \
248 FRES_CONTRACT_ACCESSOR(label)
249 FRES_CONTRACT_ACCESSOR(resource)
250 FRES_CONTRACT_ACCESSOR(basic)
251 FRES_CONTRACT_ACCESSOR(timing_reqs)
252 FRES_CONTRACT_ACCESSOR(csects)
253 FRES_CONTRACT_ACCESSOR(spare_capacity)
254 FRES_CONTRACT_ACCESSOR(power_management)