]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - fres/contract/fres_contract.h
Generic allocator: unify terminology (scheduler/allocator)
[frescor/frsh.git] / fres / contract / fres_contract.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_contract.h
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * @date   Sun Nov  9 22:15:09 2008
51  * 
52  * @brief  Declaration of contract type and functions
53  * 
54  * 
55  */
56 #ifndef FRES_CONTRACT_H
57 #define FRES_CONTRACT_H
58
59 #include <fres_blocks.h>
60 #include <fres_container.h>
61 #include <ul_gavl.h>
62 #include <fres_contract_type.h>
63 #include <fres_contract_idl.h>
64 #include <forb/server_id.h>
65
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69
70 /**
71  * Contract data type.
72  * 
73  */
74 struct fres_contract {
75         fres_contract_id_t id;  /**< Global contract ID */
76         struct fres_container *container;       /**< Pointer to the block container (opaque type). */
77 };
78
79 static inline int fres_contract_id_cmp(const fres_contract_id_t *a,
80                                        const fres_contract_id_t *b)
81 {
82         return forb_server_id_cmp((forb_server_id*)a,
83                                   (forb_server_id*)b);
84 }
85
86 static inline char *fres_contract_id_to_string(char *dest,
87                                                const fres_contract_id_t *id,
88                                                size_t n)
89 {
90         return forb_server_id_to_string(dest, (forb_server_id*)id, n);
91 }
92
93 struct fres_contract *fres_contract_new(void);
94 void fres_contract_destroy(struct fres_contract *contract);
95 struct fres_contract *fres_contract_duplicate(struct fres_contract *src);
96
97 /** 
98  * Adds a block of the given type to the contract.
99  *
100  * This function uses fres_container_add_block() to do its job.
101  * 
102  * @param contract Where to add the @a block.
103  * @param type Type of contract being added.
104  * @param block Pointer to the malloced block of given @a type.
105  * 
106  * @return Zero on success, -1 on error and errno is set appropriately.
107  */
108 static inline int
109 fres_contract_add_block(struct fres_contract *contract,
110                         enum fres_block_type type, void *block)
111 {
112         return fres_container_add_block(contract->container, type, block);
113 }
114 /** 
115  * Deletes a block from the contract and frees it from memory.
116  *
117  * This function uses fres_container_del_block() to do its job.
118  * 
119  * @param contract Where to delete the block.
120  * @param type Type of contract to delete.
121  */
122 static inline void
123 fres_contract_del_block(struct fres_contract *contract,
124                         enum fres_block_type type)
125 {
126         fres_container_del_block(contract->container, type);
127 }
128
129 /** 
130  * Returns pointer to a contract block of a particular @a type.
131  * 
132  * This function uses fres_container_get_block() to do its job.
133  * 
134  * @param contract
135  * @param type Type of the block to be returned.
136  * 
137  * @return Pointer to the block or NULL if the block is not present or
138  * deserialized. The memory area pointed by this pointer is owned by
139  * the contract. If the user needs to store the block, it must be
140  * duplicated.
141  */
142 static inline void *
143 fres_contract_get_block(struct fres_contract *contract,
144                         enum fres_block_type type)
145 {
146         return fres_container_get_block(contract->container, type);
147 }
148
149 int
150 fres_contract_to_string(char *dest, size_t size, const struct fres_contract *c);
151
152 bool
153 fres_contract_get_deadline(const frsh_contract_t *contract,
154                            frsh_rel_time_t       *deadline);
155 void
156 fres_contract_print(char *prefix, const struct fres_contract *c);
157
158 static inline int
159 fres_contract_get_num_blocks(const struct fres_contract *c)
160 {
161         return fres_container_get_num_blocks(c->container);
162 }
163
164 static inline int
165 fres_contract_merge(struct fres_contract *dest,
166                      const struct fres_contract *src)
167 {
168         return fres_container_merge(dest->container, src->container);
169 }
170
171
172 /**
173  * Macro which defines type-safe contract "accessor" functions for
174  * various blocks.
175  *
176  * This macro declares the following inline functions:
177  * - fres_contract_add_<type>
178  * - fres_contract_get_<type>
179  * - fres_contract_del_<type>
180  *
181  * The defined functions simply use the container "accessor" functions
182  * (usually defined) by #FRES_CONTAINER_ACCESSOR and are equivalent to
183  * fres_contract_add_block(), fres_contract_del_block() and
184  * fres_contract_get_block() with appropriate parameters.
185  */
186 #define FRES_CONTRACT_ACCESSOR(type)                                    \
187         static inline int                                               \
188         fres_contract_add_##type(struct fres_contract *contract,        \
189                                  fres_block_##type *block)              \
190         {                                                               \
191                 return fres_container_add_##type(contract->container,   \
192                                                  block);                \
193         }                                                               \
194         static inline fres_block_##type *                               \
195         fres_contract_get_##type(const struct fres_contract *contract)  \
196         {                                                               \
197                 return fres_container_get_##type(contract->container);  \
198         }                                                               \
199         static inline void                                              \
200         fres_contract_del_##type(struct fres_contract *contract)        \
201         {                                                               \
202                 fres_container_del_##type(contract->container);         \
203         }
204
205 FRES_CONTRACT_ACCESSOR(label)
206 FRES_CONTRACT_ACCESSOR(resource)
207 FRES_CONTRACT_ACCESSOR(basic)
208 FRES_CONTRACT_ACCESSOR(timing_reqs)
209 FRES_CONTRACT_ACCESSOR(csects)
210 FRES_CONTRACT_ACCESSOR(spare_capacity)
211
212 #ifdef __cplusplus
213 } /* extern "C"*/
214 #endif
215
216 #endif