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_container.h
49 * @author Michal Sojka <sojkam1@fel.cvut.cz>
51 * @brief Container for managing contract blocks.
55 #ifndef FRES_CONTAINER_H
56 #define FRES_CONTAINER_H
59 #include <fres_container_type.h>
60 #include <fres_blocks.h>
61 #include <forb/basic_types.h>
62 #include <forb/cdr_codec.h>
63 #include <fosa_types.h>
65 /*============================================================================*/
72 * Identification of different contract blocks.
74 * All contract blocks should define their ID here. This is the
75 * only place, where the different parameters (e.g. for different
76 * kinds of resources) share a common source file. The declaration of
77 * block struture can occur at any place (.h or better .idl).
80 enum fres_block_type {
84 FRES_BLOCK_TIMING_REQS,
86 FRES_BLOCK_SPARE_CAPACITY,
87 FRES_BLOCK_POWER_MANAGEMENT,
88 FRES_BLOCK_DUMMY_SCHED, /**< See resources/dummy/res_dummy_idl.idl */
89 FRES_BLOCK_DISK_SCHED, /** < See resources/disk_bfq/res_disk_idl.idl */
90 FRES_BLOCK_CLUSTER_TREE_TRAFFIC, /**< resources/cluster_tree/cluster_tree_idl.idl */
92 FRES_BLOCK_ITEM_NODES, /**< resources/item/item_idl.idl */
93 FRES_BLOCK_FPGA, /**< resources/fpga/res_fpga_idl.idl */
98 typedef CORBA_boolean (fres_block_serialize_fnc_t)(FORB_CDR_Codec *codec, const void *block_data);
99 typedef CORBA_boolean (fres_block_deserialize_fnc_t)(FORB_CDR_Codec *codec, void **block_data);
102 * Description of contract blocks.
104 struct fres_block_desc {
105 const char *name; /**< Name of the block for use fres_container_to_string() */
106 size_t size; /**< Size of the block (used by fres_block_duplicate_default() and fres_container_ptr_deserialize()) */
107 fres_block_serialize_fnc_t *serialize;
108 fres_block_deserialize_fnc_t *deserialize;
109 void *(*duplicate)(enum fres_block_type type, const void *block_data);
110 int (*to_string)(char *dest, size_t size, enum fres_block_type type, const void *block_data);
113 struct fres_container *
114 fres_container_new(void);
117 fres_container_destroy(struct fres_container *container);
119 struct fres_container *
120 fres_container_duplicate(const struct fres_container *source);
123 fres_container_add_block(struct fres_container *container,
124 enum fres_block_type type,
128 fres_container_del_block(struct fres_container *container,
129 enum fres_block_type type);
132 fres_container_get_block(const struct fres_container *container,
133 enum fres_block_type type);
136 * Macro which defines type-safe container "accessor" functions for
139 * This macro declares the following inline functions:
140 * - fres_container_add_<type>
141 * - fres_container_get_<type>
142 * - fres_container_del_<type>
144 * These functions are equivalent to fres_container_add_block(),
145 * fres_container_del_block() and fres_container_get_block() with
146 * appropriate parameters.
148 #define FRES_CONTAINER_ACCESSOR(TYPE, type) \
150 fres_container_add_##type(struct fres_container *container, \
151 fres_block_##type *block) \
153 return fres_container_add_block( \
154 container, FRES_BLOCK_##TYPE, block); \
156 static inline fres_block_##type * \
157 fres_container_get_##type(const struct fres_container *container) \
159 return (fres_block_##type *)fres_container_get_block( \
160 container, FRES_BLOCK_##TYPE); \
163 fres_container_del_##type(struct fres_container *container) \
165 fres_container_del_block(container, FRES_BLOCK_##TYPE); \
168 FRES_CONTAINER_ACCESSOR(LABEL, label)
169 FRES_CONTAINER_ACCESSOR(RESOURCE, resource)
170 FRES_CONTAINER_ACCESSOR(BASIC, basic)
171 FRES_CONTAINER_ACCESSOR(TIMING_REQS, timing_reqs)
172 FRES_CONTAINER_ACCESSOR(CSECTS, csects)
173 FRES_CONTAINER_ACCESSOR(SPARE_CAPACITY, spare_capacity)
174 FRES_CONTAINER_ACCESSOR(POWER_MANAGEMENT, power_management)
177 fres_block_register(enum fres_block_type, const struct fres_block_desc *desc);
180 fres_block_duplicate_default(enum fres_block_type type, const void *block_data);
183 fres_container_to_string(char *dest, size_t size, const struct fres_container *c);
186 fres_container_get_num_blocks(const struct fres_container *c);
188 int fres_container_merge(struct fres_container *dest,
189 const struct fres_container *src);
191 int fres_container_copy(struct fres_container *dest,
192 const struct fres_container *src);