]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - frsh_error.h
38b0a1fcac48f1641adb420d5be56355ce6314ad
[frescor/frsh-include.git] / frsh_error.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
3 //
4 //    Universidad de Cantabria,              SPAIN
5 //    University of York,                    UK
6 //    Scuola Superiore Sant'Anna,            ITALY
7 //    Kaiserslautern University,             GERMANY
8 //    Univ. Politécnica  Valencia,           SPAIN
9 //    Czech Technical University in Prague,  CZECH REPUBLIC
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //
16 //    See http://www.frescor.org for a link to partners' websites
17 //
18 //           FRESCOR project (FP6/2005/IST/5-034026) is funded
19 //        in part by the European Union Sixth Framework Programme
20 //        The European Union is not liable of any use that may be
21 //        made of this code.
22 //
23 //
24 //  based on previous work (FSF) done in the FIRST project
25 //
26 //   Copyright (C) 2005  Mälardalen University, SWEDEN
27 //                       Scuola Superiore S.Anna, ITALY
28 //                       Universidad de Cantabria, SPAIN
29 //                       University of York, UK
30 //
31 //   FSF API web pages: http://marte.unican.es/fsf/docs
32 //                      http://shark.sssup.it/contrib/first/docs/
33 //
34 //   This file is part of FRSH (FRescor ScHeduler)
35 //
36 //  FRSH is free software; you can redistribute it and/or modify it
37 //  under terms of the GNU General Public License as published by the
38 //  Free Software Foundation; either version 2, or (at your option) any
39 //  later version.  FRSH is distributed in the hope that it will be
40 //  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
41 //  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 //  General Public License for more details. You should have received a
43 //  copy of the GNU General Public License along with FRSH; see file
44 //  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
45 //  Cambridge, MA 02139, USA.
46 //
47 //  As a special exception, including FRSH header files in a file,
48 //  instantiating FRSH generics or templates, or linking other files
49 //  with FRSH objects to produce an executable application, does not
50 //  by itself cause the resulting executable application to be covered
51 //  by the GNU General Public License. This exception does not
52 //  however invalidate any other reasons why the executable file might be
53 //  covered by the GNU Public License.
54 //  As a special exception, if you include this header file into source
55 //  files to be compiled, this header file does not by itself cause
56 //  the resulting executable to be covered by the GNU General Public
57 //  License.  This exception does not however invalidate any other
58 //  reasons why the executable file might be covered by the GNU General
59 //  Public License.
60 // -----------------------------------------------------------------------
61 //frsh_error.h
62 //==============================================
63 //  ******** *******    ********  **      **
64 //  **///// /**////**  **//////  /**     /**
65 //  **      /**   /** /**        /**     /**
66 //  ******* /*******  /********* /**********
67 //  **////  /**///**  ////////** /**//////**
68 //  **      /**  //**        /** /**     /**
69 //  **      /**   //** ********  /**     /**
70 //  //       //     // ////////   //      // 
71 //
72 // FRSH(FRescor ScHeduler), pronounced "fresh"
73 //==============================================
74
75 #ifndef         FRSH_ERROR_H_
76 #define         FRSH_ERROR_H_
77
78 /**
79  * @file frsh_error.h
80  **/
81
82 /**
83  * addtogroup core
84  *
85  * @{
86  **/
87
88 /* Error codes */
89 #define FRSH_NO_ERROR                            0
90
91 #define FRSH_ERR_BASE_VALUE                      0x02004000
92
93 #define FRSH_ERR_TOO_MANY_TASKS                  0x02004001
94 #define FRSH_ERR_BAD_ARGUMENT                    0x02004002
95 #define FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE        0x02004003
96 #define FRSH_ERR_NO_RENEGOTIATION_REQUESTED      0x02004004
97 #define FRSH_ERR_CONTRACT_REJECTED               0x02004005
98 #define FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD    0x02004006
99 #define FRSH_ERR_NOT_BOUND                       0x02004007
100 #define FRSH_ERR_UNKNOWN_SCHEDULED_THREAD        0x02004008
101 #define FRSH_ERR_NOT_CONTRACTED_VRES             0x02004009
102 #define FRSH_ERR_NOT_SCHEDULED_THREAD            0x0200400A
103 #define FRSH_ERR_TOO_MANY_SERVICE_JOBS           0x0200400B
104 #define FRSH_ERR_TOO_MANY_SYNCH_OBJS             0x0200400C
105 #define FRSH_ERR_TOO_MANY_VRES_IN_SYNCH_OBJ      0x0200400D
106 #define FRSH_ERR_TOO_MANY_EVENTS_IN_SYNCH_OBJ    0x0200400E
107 #define FRSH_ERR_INTERNAL_ERROR                  0x0200400F
108 #define FRSH_ERR_TOO_MANY_VRES                   0x02004010
109 #define FRSH_ERR_INVALID_SCHEDULER_REPLY         0x02004011
110 #define FRSH_ERR_TOO_MANY_PENDING_REPLENISHMENTS 0x02004012
111 #define FRSH_ERR_SYSTEM_ALREADY_INITIALIZED      0x02004013
112 #define FRSH_ERR_SHARED_OBJ_ALREADY_INITIALIZED  0x02004014
113 #define FRSH_ERR_SHARED_OBJ_NOT_INITIALIZED      0x02004015
114 #define FRSH_ERR_SCHED_POLICY_NOT_COMPATIBLE     0x02004016
115 #define FRSH_ERR_VRES_WORKLOAD_NOT_COMPATIBLE    0x02004017
116 #define FRSH_ERR_ALREADY_BOUND                   0x02004018
117 #define FRSH_ERR_RESOURCE_ID_INVALID             0x02004019
118 #define FRSH_ERR_TOO_LARGE                       0x0200401A
119 #define FRSH_ERR_BUFFER_FULL                     0x0200401B
120 #define FRSH_ERR_NO_SPACE                        0x0200401C
121 #define FRSH_ERR_NO_MESSAGES                     0x0200401D
122 #define FRSH_WRN_MODULE_NOT_SUPPORTED            0x0200401E
123 #define FRSH_ERR_NOT_INITIALIZED                 0x0200401F
124 #define FRSH_ERR_TOO_MANY_SHARED_OBJS            0x02004020
125 #define FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS   0x02004021
126 #define FRSH_ERR_BUDGET_EXPIRED                  0x02004022
127 #define FRSH_ERR_SHARED_OBJECT_NOT_PROTECTED     0x02004023
128 #define FRSH_ERR_NOT_IMPLEMENTED                 0x02004024
129 #define FRSH_ERR_CONTRACT_TYPE_NOT_COMPATIBLE    0x02004025
130 #define FRSH_ERR_CAPACITY_NOT_DECREASING         0x02004026
131 #define FRSH_ERR_CONTRACT_LABEL_UNKNOWN          0x02004027
132
133 #define FRSH_ERR_LAST_VALUE                      0x02004028
134
135 #define ERROR(nn,ss) do {if(nn>FRSH_ERR_BASE_VALUE) my_frsh_strerror(nn, ss); else perror(ss); exit (nn);} while (0)
136
137
138
139
140 int frsh_strerror (int error, char *message, size_t size);
141 void my_frsh_strerror(int error, char *sss);
142
143
144 /**
145  * This str_helper is needed to ensure argument expansion,
146  * see http://www.iar.com/p180591/p180591_eng.php
147  **/
148 #define STR_HELPER(x) #x
149
150 /**
151  * PERROR_FRESCOR
152  *
153  * This macro checks the given error number and composes a messages accordingly.
154  *
155  * @param nn  Error number
156  * @param ss  Error string (to be appended to FRSH or system error string)
157  **/
158 #define PERROR_FRESCOR(_nn_,_ss_) do {          \
159  \
160         char error_string[1024]; \
161  \
162         sprintf(error_string,  "File: %s, in function %s at line %d, error %d: %s\n", __FILE__, __FUNCTION__, __LINE__, (_nn_), _ss_); \
163  \
164                 if( (_nn_)>FRSH_ERR_BASE_VALUE ) {      \
165                         my_frsh_strerror( (_nn_), error_string);        \
166                 } else {                                \
167                         perror(error_string);                   \
168                 }                                       \
169 } while(0) 
170
171
172
173 /**
174  * PERROR_AND_RETURN
175  *
176  * Macro that displays an error code and message and then returns from
177  * the current function
178  *
179  * @param nn  Error number
180  * @param ss  Error string (to be appended to FRSH or system error string)
181  **/
182 #define PERROR_AND_RETURN(nn,ss) do {                   \
183         PERROR_FRESCOR(nn, ss); \
184                 return (nn);                            \
185         } while (0)
186
187
188
189
190 /**
191  * PERROR_AND_EXIT
192  *
193  * Macro that displays an error code and message and then aborts the
194  * program.
195  *
196  * @param nn  Error number
197  * @param ss  Error string (to be appended to FRSH or system error string)
198  **/
199 #define PERROR_AND_EXIT(nn,ss) do {     \
200                 PERROR_FRESCOR(nn,ss);          \
201                 exit(nn);               \
202         } while (0)
203
204
205 /**
206  * PRW:  Perror and Return Wrapper
207  *
208  * Function that calls funccall and checks the result != 0.
209  * In case of error it displays the error code with the function call
210  * as extra error string and returns from the function.
211  *
212  * terror (int) needs to be visible in the point of call.
213  *
214  * @param funccall Code to execute that should return 0 in a non error
215  *                 case. 
216  **/
217 #define PRW(funccall)  do { \
218   if ( (terror = funccall ) != 0) \
219   { \
220      PERROR_AND_RETURN( terror, STR_HELPER(funccall) ); \
221   } \
222 } while(0)
223
224
225
226 /**
227  * PXW:  Perror and eXit Wrapper
228  *
229  * Function that calls funccall and checks the result != 0.
230  * In case of error it displays the error code with the function call
231  * as extra error string and ABORTS the program.
232  *
233  * terror (int) needs to be visible in the point of call.
234  *
235  * @param funccall Code to execute that should return 0 in a non error
236  *                 case. 
237  **/
238 #define PXW(funccall)  do { \
239   if ( (terror = funccall ) != 0) \
240   { \
241      PERROR_AND_EXIT( terror, STR_HELPER(funccall) ); \
242   } \
243 } while(0)
244
245
246
247 /**
248  * PERROR_KERN_AND_EXIT
249  *
250  * Function that displays an error code and message and then aborts the
251  * program.
252  *
253  * @param nn  Error number
254  * @param ss  Error string (to be appended to FRSH or system error string)
255  **/
256 #define PERROR_KERN_AND_EXIT(nn, ss) do {               \
257                 errno = errno ? errno : (nn);           \
258                 kern_printf(ss);                        \
259                 exit(nn);                               \
260         } while (0)
261
262
263
264
265 /*}*/
266
267 #endif      /* !FRSH_ERROR_H_ */