]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - fres/contract/fres_container.h
Added license headers and authorship info
[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_SPARE_CAPACITY,
86         FRES_BLOCK_DUMMY_SCHED, /**< See resources/dummy/res_dummy_idl.idl */
87         FRES_BLOCK_CLUSTER_TREE_TRAFFIC, /**< resources/cluster_tree/cluster_tree_idl.idl */
88         FRES_BLOCK_FWP_SCHED,
89         FRES_BLOCK_ITEM_NODES, /**< resources/item/item_idl.idl */
90         FRES_BLOCK_FPGA,       /**< resources/fpga/res_fpga_idl.idl */
91         FRES_NUM_BLOCKS
92 };
93
94 typedef CORBA_boolean (fres_block_serialize_fnc_t)(FORB_CDR_Codec *codec, const void *block_data);
95 typedef CORBA_boolean (fres_block_deserialize_fnc_t)(FORB_CDR_Codec *codec, void **block_data);
96
97 /**
98  * Description of contract blocks.
99  */
100 struct fres_block_desc {
101         const char *name;       /**< Name of the block for use fres_container_to_string() */
102         size_t size;            /**< Size of the block (used by fres_block_duplicate_default() and fres_container_ptr_deserialize()) */
103         fres_block_serialize_fnc_t *serialize;
104         fres_block_deserialize_fnc_t *deserialize;
105         void *(*duplicate)(enum fres_block_type type, const void *block_data);
106         int (*to_string)(char *dest, size_t size, enum fres_block_type type, const void *block_data);
107 };
108
109 struct fres_container *
110 fres_container_new(void);
111
112 void
113 fres_container_destroy(struct fres_container *container);
114
115 struct fres_container *
116 fres_container_duplicate(const struct fres_container *source);
117
118 int
119 fres_container_add_block(struct fres_container *container,
120                        enum fres_block_type type,
121                        void *block);
122
123 void
124 fres_container_del_block(struct fres_container *container,
125                        enum fres_block_type type);
126
127 void *
128 fres_container_get_block(const struct fres_container *container,
129                          enum fres_block_type type);
130
131 /**
132  * Macro which defines type-safe container "accessor" functions for
133  * various blocks.
134  *
135  * This macro declares the following inline functions:
136  * - fres_container_add_<type>
137  * - fres_container_get_<type>
138  * - fres_container_del_<type>
139  *
140  * These functions are equivalent to fres_container_add_block(),
141  * fres_container_del_block() and fres_container_get_block() with
142  * appropriate parameters.
143  */
144 #define FRES_CONTAINER_ACCESSOR(TYPE, type)                             \
145         static inline int                                               \
146         fres_container_add_##type(struct fres_container *container,             \
147                                 fres_block_##type *block)                       \
148         {                                                               \
149                 return fres_container_add_block(                                \
150                         container, FRES_BLOCK_##TYPE, block);           \
151         }                                                               \
152         static inline fres_block_##type *                                       \
153         fres_container_get_##type(const struct fres_container *container) \
154         {                                                               \
155                 return (fres_block_##type *)fres_container_get_block(   \
156                         container, FRES_BLOCK_##TYPE);                  \
157         }                                                               \
158         static inline void                                              \
159         fres_container_del_##type(struct fres_container *container)             \
160         {                                                               \
161                 fres_container_del_block(container, FRES_BLOCK_##TYPE); \
162         }
163
164 FRES_CONTAINER_ACCESSOR(LABEL,          label)
165 FRES_CONTAINER_ACCESSOR(RESOURCE,       resource)
166 FRES_CONTAINER_ACCESSOR(BASIC,          basic)
167 FRES_CONTAINER_ACCESSOR(TIMING_REQS,    timing_reqs)
168 FRES_CONTAINER_ACCESSOR(SPARE_CAPACITY, spare_capacity)
169
170 int
171 fres_block_register(enum fres_block_type, const struct fres_block_desc *desc);
172
173 void *
174 fres_block_duplicate_default(enum fres_block_type type, const void *block_data);
175
176 int
177 fres_container_to_string(char *dest, size_t size, const struct fres_container *c);
178
179 #ifdef __cplusplus
180 } /* extern "C"*/
181 #endif
182
183 #endif