]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - fres/contract/fres_container.h
Merge branch 'master' of rtime.felk.cvut.cz:/var/git/frescor/frsh_forb.git
[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_BLOCK_ITEM_NODES, /**< resources/item/item_idl.idl */
40         FRES_NUM_BLOCKS
41 };
42
43 typedef CORBA_boolean (fres_block_serialize_fnc_t)(CDR_Codec *codec, const void *block_data);
44 typedef CORBA_boolean (fres_block_deserialize_fnc_t)(CDR_Codec *codec, void **block_data);
45
46 /**
47  * Description of contract blocks.
48  */
49 struct fres_block_desc {
50         const char *name;       /**< Name of the block for use fres_container_to_string() */
51         size_t size;            /**< Size of the block (used by fres_block_duplicate_default() and fres_container_ptr_deserialize()) */
52         fres_block_serialize_fnc_t *serialize;
53         fres_block_deserialize_fnc_t *deserialize;
54         void *(*duplicate)(enum fres_block_type type, const void *block_data);
55 };
56
57 struct fres_container *
58 fres_container_new(void);
59
60 void
61 fres_container_destroy(struct fres_container *container);
62
63 struct fres_container *
64 fres_container_duplicate(const struct fres_container *source);
65
66 int
67 fres_container_add_block(struct fres_container *container,
68                        enum fres_block_type type,
69                        void *block);
70
71 void
72 fres_container_del_block(struct fres_container *container,
73                        enum fres_block_type type);
74
75 void *
76 fres_container_get_block(struct fres_container *container,
77                        enum fres_block_type type);
78
79 #define FRES_CONTAINER_ACCESSOR(TYPE, type)                             \
80         static inline int                                               \
81         fres_container_add_##type(struct fres_container *container,             \
82                                 fres_block_##type *block)                       \
83         {                                                               \
84                 return fres_container_add_block(                                \
85                         container, FRES_BLOCK_##TYPE, block);           \
86         }                                                               \
87         static inline fres_block_##type *                                       \
88         fres_container_get_##type(struct fres_container *container)             \
89         {                                                               \
90                 return fres_container_get_block(                                \
91                         container, FRES_BLOCK_##TYPE);                  \
92         }                                                               \
93         static inline void                                              \
94         fres_container_del_##type(struct fres_container *container)             \
95         {                                                               \
96                 fres_container_del_block(container, FRES_BLOCK_##TYPE); \
97         }
98
99 FRES_CONTAINER_ACCESSOR(LABEL,          label)
100 FRES_CONTAINER_ACCESSOR(RESOURCE,       resource)
101 FRES_CONTAINER_ACCESSOR(BASIC,          basic)
102 FRES_CONTAINER_ACCESSOR(TIMING_REQS,    timing_reqs)
103 FRES_CONTAINER_ACCESSOR(SPARE_CAPACITY, spare_capacity)
104
105 int
106 fres_block_register(enum fres_block_type, const struct fres_block_desc *desc);
107
108 void *
109 fres_block_duplicate_default(enum fres_block_type type, const void *block_data);
110
111 int
112 fres_container_to_string(char *dest, size_t size, const struct fres_container *c);
113
114 #endif