]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - fres/contract/fres_container.h
Added FRES_BLOCK_FWP_SCHED
[frescor/frsh.git] / fres / contract / fres_container.h
1 /**
2  * @file   fres_container.h
3  * @author Michal Sojka <sojkam1@fel.cvut.cz>
4  * 
5  * @brief  Container for managing contract blocks.
6  * 
7  * 
8  */
9 #ifndef FRES_CONTAINER_H
10 #define FRES_CONTAINER_H
11
12
13 #include <fres_container_type.h>
14 #include <fres_blocks.h>
15 #include <forb/basic_types.h>
16 #include <forb/cdr_codec.h>
17 #include <fosa_types.h>
18
19 /*============================================================================*/
20
21 /**
22  * Identification of different contract blocks.
23  *
24  * All contract blocks should define their ID here. This is the
25  * only place, where the different parameters (e.g. for different
26  * kinds of resources) share a common source file. The declaration of
27  * block struture can occur at any place (.h or better .idl).
28  * 
29  */
30 enum fres_block_type {
31         FRES_BLOCK_LABEL,
32         FRES_BLOCK_RESOURCE,
33         FRES_BLOCK_BASIC,
34         FRES_BLOCK_TIMING_REQS,
35         FRES_BLOCK_SPARE_CAPACITY,
36         FRES_BLOCK_DUMMY_SCHED, /**< See resources/dummy/res_dummy_idl.idl */
37         FRES_BLOCK_CLUSTER_TREE_TRAFFIC, /**< resources/cluster_tree/cluster_tree_idl.idl */
38         FRES_BLOCK_FWP_SCHED,
39         FRES_NUM_BLOCKS
40 };
41
42 typedef CORBA_boolean (fres_block_serialize_fnc_t)(CDR_Codec *codec, const void *block_data);
43 typedef CORBA_boolean (fres_block_deserialize_fnc_t)(CDR_Codec *codec, void **block_data);
44                                              
45 struct fres_block_desc {
46         size_t size;            /**< Size of the block (used by fres_block_duplicate_default() and fres_container_ptr_deserialize()) */
47         fres_block_serialize_fnc_t *serialize;
48         fres_block_deserialize_fnc_t *deserialize;
49         void *(*duplicate)(enum fres_block_type type, const void *block_data);
50 };
51
52 struct fres_container *
53 fres_container_new(void);
54
55 void
56 fres_container_destroy(struct fres_container *container);
57
58 struct fres_container *
59 fres_container_duplicate(const struct fres_container *source);
60
61 int
62 fres_container_add_block(struct fres_container *container,
63                        enum fres_block_type type,
64                        void *block);
65
66 void
67 fres_container_del_block(struct fres_container *container,
68                        enum fres_block_type type);
69
70 void *
71 fres_container_get_block(struct fres_container *container,
72                        enum fres_block_type type);
73
74 #define FRES_CONTAINER_ACCESSOR(TYPE, type)                             \
75         static inline int                                               \
76         fres_container_add_##type(struct fres_container *container,             \
77                                 fres_block_##type *block)                       \
78         {                                                               \
79                 return fres_container_add_block(                                \
80                         container, FRES_BLOCK_##TYPE, block);           \
81         }                                                               \
82         static inline fres_block_##type *                                       \
83         fres_container_get_##type(struct fres_container *container)             \
84         {                                                               \
85                 return fres_container_get_block(                                \
86                         container, FRES_BLOCK_##TYPE);                  \
87         }                                                               \
88         static inline void                                              \
89         fres_container_del_##type(struct fres_container *container)             \
90         {                                                               \
91                 fres_container_del_block(container, FRES_BLOCK_##TYPE); \
92         }
93
94 FRES_CONTAINER_ACCESSOR(LABEL,          label)
95 FRES_CONTAINER_ACCESSOR(RESOURCE,       resource)
96 FRES_CONTAINER_ACCESSOR(BASIC,          basic)
97 FRES_CONTAINER_ACCESSOR(TIMING_REQS,    timing_reqs)
98 FRES_CONTAINER_ACCESSOR(SPARE_CAPACITY, spare_capacity)
99
100 int
101 fres_block_register(enum fres_block_type, const struct fres_block_desc *desc);
102
103 void *
104 fres_block_duplicate_default(enum fres_block_type type, const void *block_data);
105
106 #endif