]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - fres/contract/fres_container.h
Added ID of the new FWP contract block
[frescor/frsh.git] / fres / contract / fres_container.h
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
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                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
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.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FRSH (FRescor ScHeduler)                         */
26 /*                                                                        */
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.                                              */
37 /*                                                                        */
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 /**************************************************************************/
46
47 /**
48  * @file   fres_container.h
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * 
51  * @brief  Container for managing contract blocks.
52  * 
53  * 
54  */
55 #ifndef FRES_CONTAINER_H
56 #define FRES_CONTAINER_H
57
58
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>
64
65 /*============================================================================*/
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 /**
72  * Identification of different contract blocks.
73  *
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).
78  * 
79  */
80 enum fres_block_type {
81         FRES_BLOCK_LABEL,
82         FRES_BLOCK_RESOURCE,
83         FRES_BLOCK_BASIC,
84         FRES_BLOCK_TIMING_REQS,
85         FRES_BLOCK_CSECTS,
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 */
91         FRES_BLOCK_FWP_SCHED,
92         FRES_BLOCK_ITEM_NODES, /**< resources/item/item_idl.idl */
93         FRES_BLOCK_FPGA,       /**< resources/fpga/res_fpga_idl.idl */
94         FRES_NUM_BLOCKS,
95         FRES_BLOCK_FWP,
96 };
97
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);
100
101 /**
102  * Description of contract blocks.
103  */
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);
111 };
112
113 struct fres_container *
114 fres_container_new(void);
115
116 void
117 fres_container_destroy(struct fres_container *container);
118
119 struct fres_container *
120 fres_container_duplicate(const struct fres_container *source);
121
122 int
123 fres_container_add_block(struct fres_container *container,
124                        enum fres_block_type type,
125                        void *block);
126
127 void
128 fres_container_del_block(struct fres_container *container,
129                        enum fres_block_type type);
130
131 void *
132 fres_container_get_block(const struct fres_container *container,
133                          enum fres_block_type type);
134
135 /**
136  * Macro which defines type-safe container "accessor" functions for
137  * various blocks.
138  *
139  * This macro declares the following inline functions:
140  * - fres_container_add_<type>
141  * - fres_container_get_<type>
142  * - fres_container_del_<type>
143  *
144  * These functions are equivalent to fres_container_add_block(),
145  * fres_container_del_block() and fres_container_get_block() with
146  * appropriate parameters.
147  */
148 #define FRES_CONTAINER_ACCESSOR(TYPE, type)                             \
149         static inline int                                               \
150         fres_container_add_##type(struct fres_container *container,             \
151                                 fres_block_##type *block)                       \
152         {                                                               \
153                 return fres_container_add_block(                                \
154                         container, FRES_BLOCK_##TYPE, block);           \
155         }                                                               \
156         static inline fres_block_##type *                                       \
157         fres_container_get_##type(const struct fres_container *container) \
158         {                                                               \
159                 return (fres_block_##type *)fres_container_get_block(   \
160                         container, FRES_BLOCK_##TYPE);                  \
161         }                                                               \
162         static inline void                                              \
163         fres_container_del_##type(struct fres_container *container)             \
164         {                                                               \
165                 fres_container_del_block(container, FRES_BLOCK_##TYPE); \
166         }
167
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)
175
176 int
177 fres_block_register(enum fres_block_type, const struct fres_block_desc *desc);
178
179 void *
180 fres_block_duplicate_default(enum fres_block_type type, const void *block_data);
181
182 int
183 fres_container_to_string(char *dest, size_t size, const struct fres_container *c);
184
185 int
186 fres_container_get_num_blocks(const struct fres_container *c);
187
188 int fres_container_merge(struct fres_container *dest,
189                          const struct fres_container *src);
190
191 int fres_container_copy(struct fres_container *dest,
192                         const struct fres_container *src);
193
194 #ifdef __cplusplus
195 } /* extern "C"*/
196 #endif
197
198 #endif