]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - frsh_error.h
Passing FRSH_TRACE as a standard (non-inlined) function in order for -O1 to
[frescor/frsh-include.git] / frsh_error.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 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 API
35 //
36 //  FRSH API is free software; you can  redistribute it and/or  modify
37 //  it under the terms of  the GNU General Public License as published by
38 //  the Free Software Foundation;  either  version 2, or (at  your option)
39 //  any later version.
40 //
41 //  FRSH API  is distributed  in  the hope  that  it  will  be useful,  but
42 //  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
43 //  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
44 //  General Public License for more details.
45 //
46 //  You should have  received a  copy of  the  GNU  General Public License
47 //  distributed  with  FRSH API;  see file COPYING.   If not,  write to the
48 //  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
49 //  02111-1307, USA.
50 //
51 //  As a special exception, if you include this header file into source
52 //  files to be compiled, this header file does not by itself cause
53 //  the resulting executable to be covered by the GNU General Public
54 //  License.  This exception does not however invalidate any other
55 //  reasons why the executable file might be covered by the GNU General
56 //  Public License.
57 // -----------------------------------------------------------------------
58 //frsh_error.h
59 //==============================================
60 //  ******** *******    ********  **      **
61 //  **///// /**////**  **//////  /**     /**
62 //  **      /**   /** /**        /**     /**
63 //  ******* /*******  /********* /**********
64 //  **////  /**///**  ////////** /**//////**
65 //  **      /**  //**        /** /**     /**
66 //  **      /**   //** ********  /**     /**
67 //  //       //     // ////////   //      // 
68 //
69 // FRSH(FRescor ScHeduler), pronounced "fresh"
70 //==============================================
71
72 #ifndef         FRSH_ERROR_H_
73 #define         FRSH_ERROR_H_
74
75 /**
76  * @file frsh_error.h
77  **/
78
79 /**
80  * addtogroup core
81  *
82  * @{
83  **/
84
85 /* Error codes */
86 #define FRSH_NO_ERROR                            0
87
88 #define FRSH_ERR_BASE_VALUE                      0x02004000
89
90 #define FRSH_ERR_TOO_MANY_TASKS                  0x02004001
91 #define FRSH_ERR_BAD_ARGUMENT                    0x02004002
92 #define FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE        0x02004003
93 #define FRSH_ERR_NO_RENEGOTIATION_REQUESTED      0x02004004
94 #define FRSH_ERR_CONTRACT_REJECTED               0x02004005
95 #define FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD    0x02004006
96 #define FRSH_ERR_NOT_BOUND                       0x02004007
97 #define FRSH_ERR_UNKNOWN_SCHEDULED_THREAD        0x02004008
98 #define FRSH_ERR_NOT_CONTRACTED_VRES             0x02004009
99 #define FRSH_ERR_NOT_SCHEDULED_THREAD            0x0200400A
100 #define FRSH_ERR_TOO_MANY_SERVICE_JOBS           0x0200400B
101 #define FRSH_ERR_TOO_MANY_SYNCH_OBJS             0x0200400C
102 #define FRSH_ERR_TOO_MANY_VRES_IN_SYNCH_OBJ      0x0200400D
103 #define FRSH_ERR_TOO_MANY_EVENTS_IN_SYNCH_OBJ    0x0200400E
104 #define FRSH_ERR_INTERNAL_ERROR                  0x0200400F
105 #define FRSH_ERR_TOO_MANY_VRES                   0x02004010
106 #define FRSH_ERR_INVALID_SCHEDULER_REPLY         0x02004011
107 #define FRSH_ERR_TOO_MANY_PENDING_REPLENISHMENTS 0x02004012
108 #define FRSH_ERR_SYSTEM_ALREADY_INITIALIZED      0x02004013
109 #define FRSH_ERR_SHARED_OBJ_ALREADY_INITIALIZED  0x02004014
110 #define FRSH_ERR_SHARED_OBJ_NOT_INITIALIZED      0x02004015
111 #define FRSH_ERR_SCHED_POLICY_NOT_COMPATIBLE     0x02004016
112 #define FRSH_ERR_VRES_WORKLOAD_NOT_COMPATIBLE    0x02004017
113 #define FRSH_ERR_ALREADY_BOUND                   0x02004018
114 #define FRSH_ERR_RESOURCE_ID_INVALID             0x02004019
115 #define FRSH_ERR_TOO_LARGE                       0x0200401A
116 #define FRSH_ERR_BUFFER_FULL                     0x0200401B
117 #define FRSH_ERR_NO_SPACE                        0x0200401C
118 #define FRSH_ERR_NO_MESSAGES                     0x0200401D
119 #define FRSH_WRN_MODULE_NOT_SUPPORTED            0x0200401E
120 #define FRSH_ERR_NOT_INITIALIZED                 0x0200401F
121 #define FRSH_ERR_TOO_MANY_SHARED_OBJS            0x02004020
122 #define FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS   0x02004021
123 #define FRSH_ERR_BUDGET_EXPIRED                  0x02004022
124 #define FRSH_ERR_SHARED_OBJECT_NOT_PROTECTED     0x02004023
125 #define FRSH_ERR_NOT_IMPLEMENTED                 0x02004024
126 #define FRSH_ERR_CONTRACT_TYPE_NOT_COMPATIBLE    0x02004025
127 #define FRSH_ERR_CAPACITY_NOT_DECREASING         0x02004026
128 #define FRSH_ERR_CONTRACT_LABEL_UNKNOWN          0x02004027
129
130 #define FRSH_ERR_LAST_VALUE                      0x02004028
131
132 #define ERROR(nn,ss) do {if(nn>FRSH_ERR_BASE_VALUE) my_frsh_strerror(nn, ss); else perror(ss); exit (nn);} while (0)
133
134
135
136
137 int frsh_strerror (int error, char *message, size_t size);
138 void my_frsh_strerror(int error, char *sss);
139
140
141 /**
142  * This str_helper is needed to ensure argument expansion,
143  * see http://www.iar.com/p180591/p180591_eng.php
144  **/
145 #define STR_HELPER(x) #x
146
147 /**
148  * PERROR_FRESCOR
149  *
150  * This macro checks the given error number and composes a messages accordingly.
151  *
152  * @param nn  Error number
153  * @param ss  Error string (to be appended to FRSH or system error string)
154  **/
155 #define PERROR_FRESCOR(_nn_,_ss_) do {          \
156  \
157         char error_string[1024]; \
158  \
159         sprintf(error_string,  "File: %s, in function %s at line %d, error %d: %s\n", __FILE__, __FUNCTION__, __LINE__, (_nn_), _ss_); \
160  \
161                 if( (_nn_)>FRSH_ERR_BASE_VALUE ) {      \
162                         my_frsh_strerror( (_nn_), error_string);        \
163                 } else {                                \
164                         perror(error_string);                   \
165                 }                                       \
166 } while(0) 
167
168
169
170 /**
171  * PERROR_AND_RETURN
172  *
173  * Macro that displays an error code and message and then returns from
174  * the current function
175  *
176  * @param nn  Error number
177  * @param ss  Error string (to be appended to FRSH or system error string)
178  **/
179 #define PERROR_AND_RETURN(nn,ss) do {                   \
180         PERROR_FRESCOR(nn, ss); \
181                 return (nn);                            \
182         } while (0)
183
184
185
186
187 /**
188  * PERROR_AND_EXIT
189  *
190  * Macro that displays an error code and message and then aborts the
191  * program.
192  *
193  * @param nn  Error number
194  * @param ss  Error string (to be appended to FRSH or system error string)
195  **/
196 #define PERROR_AND_EXIT(nn,ss) do {     \
197                 PERROR_FRESCOR(nn,ss);          \
198                 exit(nn);               \
199         } while (0)
200
201
202 /**
203  * PRW:  Perror and Return Wrapper
204  *
205  * Function that calls funccall and checks the result != 0.
206  * In case of error it displays the error code with the function call
207  * as extra error string and returns from the function.
208  *
209  * terror (int) needs to be visible in the point of call.
210  *
211  * @param funccall Code to execute that should return 0 in a non error
212  *                 case. 
213  **/
214 #define PRW(funccall)  do { \
215   if ( (terror = funccall ) != 0) \
216   { \
217      PERROR_AND_RETURN( terror, STR_HELPER(funccall) ); \
218   } \
219 } while(0)
220
221
222
223 /**
224  * PXW:  Perror and eXit Wrapper
225  *
226  * Function that calls funccall and checks the result != 0.
227  * In case of error it displays the error code with the function call
228  * as extra error string and ABORTS the program.
229  *
230  * terror (int) needs to be visible in the point of call.
231  *
232  * @param funccall Code to execute that should return 0 in a non error
233  *                 case. 
234  **/
235 #define PXW(funccall)  do { \
236   if ( (terror = funccall ) != 0) \
237   { \
238      PERROR_AND_EXIT( terror, STR_HELPER(funccall) ); \
239   } \
240 } while(0)
241
242
243
244 /**
245  * PERROR_KERN_AND_EXIT
246  *
247  * Function that displays an error code and message and then aborts the
248  * program.
249  *
250  * @param nn  Error number
251  * @param ss  Error string (to be appended to FRSH or system error string)
252  **/
253 #define PERROR_KERN_AND_EXIT(nn, ss) do {               \
254                 errno = errno ? errno : (nn);           \
255                 kern_printf(ss);                        \
256                 exit(nn);                               \
257         } while (0)
258
259
260
261
262 /*}*/
263
264 #endif      /* !FRSH_ERROR_H_ */