]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - frsh_error.h
Update transaction API
[frescor/frsh-include.git] / frsh_error.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2009 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 // -----------------------------------------------------------------------
55 //frsh_error.h
56 //==============================================
57 //  ******** *******    ********  **      **
58 //  **///// /**////**  **//////  /**     /**
59 //  **      /**   /** /**        /**     /**
60 //  ******* /*******  /********* /**********
61 //  **////  /**///**  ////////** /**//////**
62 //  **      /**  //**        /** /**     /**
63 //  **      /**   //** ********  /**     /**
64 //  //       //     // ////////   //      //
65 //
66 // FRSH(FRescor ScHeduler), pronounced "fresh"
67 //==============================================
68
69 #ifndef         FRSH_ERROR_H_
70 #define         FRSH_ERROR_H_
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
76 /**
77  * @file frsh_error.h
78  **/
79
80 /**
81  * addtogroup core
82  *
83  * @{
84  **/
85
86 /* Error codes */
87 #define FRSH_NO_ERROR                            0
88
89 #define FRSH_ERR_BASE_VALUE                      0x02004000
90
91 #define FRSH_ERR_TOO_MANY_TASKS                  0x02004001
92 #define FRSH_ERR_BAD_ARGUMENT                    0x02004002
93 #define FRSH_ERR_INVALID_SYNCH_OBJ_HANDLE        0x02004003
94 #define FRSH_ERR_NO_RENEGOTIATION_REQUESTED      0x02004004
95 #define FRSH_ERR_CONTRACT_REJECTED               0x02004005
96 #define FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD    0x02004006
97 #define FRSH_ERR_NOT_BOUND                       0x02004007
98 #define FRSH_ERR_UNKNOWN_SCHEDULED_THREAD        0x02004008
99 #define FRSH_ERR_NOT_CONTRACTED_VRES             0x02004009
100 #define FRSH_ERR_NOT_SCHEDULED_THREAD            0x0200400A
101 #define FRSH_ERR_TOO_MANY_SERVICE_JOBS           0x0200400B
102 #define FRSH_ERR_TOO_MANY_SYNCH_OBJS             0x0200400C
103 #define FRSH_ERR_TOO_MANY_VRES_IN_SYNCH_OBJ      0x0200400D
104 #define FRSH_ERR_TOO_MANY_EVENTS_IN_SYNCH_OBJ    0x0200400E
105 #define FRSH_ERR_INTERNAL_ERROR                  0x0200400F
106 #define FRSH_ERR_TOO_MANY_VRES                   0x02004010
107 #define FRSH_ERR_INVALID_SCHEDULER_REPLY         0x02004011
108 #define FRSH_ERR_TOO_MANY_PENDING_REPLENISHMENTS 0x02004012
109 #define FRSH_ERR_SYSTEM_ALREADY_INITIALIZED      0x02004013
110 #define FRSH_ERR_SHARED_OBJ_ALREADY_INITIALIZED  0x02004014
111 #define FRSH_ERR_SHARED_OBJ_NOT_INITIALIZED      0x02004015
112 #define FRSH_ERR_SCHED_POLICY_NOT_COMPATIBLE     0x02004016
113 #define FRSH_ERR_VRES_WORKLOAD_NOT_COMPATIBLE    0x02004017
114 #define FRSH_ERR_ALREADY_BOUND                   0x02004018
115 #define FRSH_ERR_RESOURCE_ID_INVALID             0x02004019
116 #define FRSH_ERR_TOO_LARGE                       0x0200401A
117 #define FRSH_ERR_BUFFER_FULL                     0x0200401B
118 #define FRSH_ERR_NO_SPACE                        0x0200401C
119 #define FRSH_ERR_NO_MESSAGES                     0x0200401D
120 #define FRSH_WRN_MODULE_NOT_SUPPORTED            0x0200401E
121 #define FRSH_ERR_NOT_INITIALIZED                 0x0200401F
122 #define FRSH_ERR_TOO_MANY_SHARED_OBJS            0x02004020
123 #define FRSH_ERR_CONTRACT_LABEL_ALREADY_EXISTS   0x02004021
124 #define FRSH_ERR_BUDGET_EXPIRED                  0x02004022
125 #define FRSH_ERR_SHARED_OBJECT_NOT_PROTECTED     0x02004023
126 #define FRSH_ERR_NOT_IMPLEMENTED                 0x02004024
127 #define FRSH_ERR_CONTRACT_TYPE_NOT_COMPATIBLE    0x02004025
128 #define FRSH_ERR_CAPACITY_NOT_DECREASING         0x02004026
129 #define FRSH_ERR_CONTRACT_LABEL_UNKNOWN          0x02004027
130 #define FRSH_ERR_OUT_OF_BUDGET                           0x02004028
131 #define FRSH_ERR_ALREADY_IN_FRSH                         0x02004029
132
133 #define FRSH_ERR_LAST_VALUE                      0x02004030
134
135
136
137 #ifdef AQuoSA
138 #define my_frsh_perror(nn,ss) do { errno = nn; perror(ss); } while(0)
139 #else
140 #define my_frsh_perror(nn,ss) do { perror(ss); } while(0)
141 #endif
142
143 #define ERROR(nn,ss) do {if(nn>FRSH_ERR_BASE_VALUE) my_frsh_strerror(nn, ss); else { my_frsh_perror(nn, ss); } exit (nn);} while (0)
144
145
146 int frsh_strerror (int error, char *message, size_t size);
147 void my_frsh_strerror(int error, char *sss);
148
149 /**
150  * This str_helper is needed to ensure argument expansion,
151  * see http://www.iar.com/p180591/p180591_eng.php
152  **/
153 #define STR_HELPER(x) #x
154
155 /**
156  * PERROR_FRESCOR
157  *
158  * This macro checks the given error number and composes a messages accordingly.
159  *
160  * @param nn  Error number
161  * @param ss  Error string (to be appended to FRSH or system error string)
162  **/
163 #define PERROR_FRESCOR(_nn_,_ss_) do {          \
164  \
165         char error_string[1024]; \
166  \
167         sprintf(error_string,  "File: %s, in function %s at line %d, error %d: %s\n", __FILE__, __FUNCTION__, __LINE__, (_nn_), _ss_); \
168  \
169                 if( (_nn_)>FRSH_ERR_BASE_VALUE ) {      \
170                         my_frsh_strerror( (_nn_), error_string);        \
171                 } else {                                \
172                         my_frsh_perror(_nn_, error_string);    \
173                 }                                       \
174 } while(0)
175
176
177
178 /**
179  * PERROR_AND_RETURN
180  *
181  * Macro that displays an error code and message and then returns from
182  * the current function
183  *
184  * @param nn  Error number
185  * @param ss  Error string (to be appended to FRSH or system error string)
186  **/
187 #define PERROR_AND_RETURN(nn,ss) do {                   \
188         PERROR_FRESCOR(nn, ss); \
189                 return (nn);                            \
190         } while (0)
191
192
193
194
195 /**
196  * PERROR_AND_EXIT
197  *
198  * Macro that displays an error code and message and then aborts the
199  * program.
200  *
201  * @param nn  Error number
202  * @param ss  Error string (to be appended to FRSH or system error string)
203  **/
204 #define PERROR_AND_EXIT(nn,ss) do {     \
205                 PERROR_FRESCOR(nn,ss);          \
206                 exit(nn);               \
207         } while (0)
208
209
210 /**
211  * PRW:  Perror and Return Wrapper
212  *
213  * Function that calls funccall and checks the result != 0.
214  * In case of error it displays the error code with the function call
215  * as extra error string and returns from the function.
216  *
217  * terror (int) needs to be visible in the point of call.
218  *
219  * @param funccall Code to execute that should return 0 in a non error
220  *                 case.
221  **/
222 #define PRW(funccall)  do { \
223   if ( (terror = funccall ) != 0) \
224   { \
225      PERROR_AND_RETURN( terror, STR_HELPER(funccall) ); \
226   } \
227 } while(0)
228
229
230
231 /**
232  * PXW:  Perror and eXit Wrapper
233  *
234  * Function that calls funccall and checks the result != 0.
235  * In case of error it displays the error code with the function call
236  * as extra error string and ABORTS the program.
237  *
238  * terror (int) needs to be visible in the point of call.
239  *
240  * @param funccall Code to execute that should return 0 in a non error
241  *                 case.
242  **/
243 #define PXW(funccall)  do { \
244   if ( (terror = funccall ) != 0) \
245   { \
246      PERROR_AND_EXIT( terror, STR_HELPER(funccall) ); \
247   } \
248 } while(0)
249
250
251
252 /**
253  * PERROR_KERN_AND_EXIT
254  *
255  * Function that displays an error code and message and then aborts the
256  * program.
257  *
258  * @param nn  Error number
259  * @param ss  Error string (to be appended to FRSH or system error string)
260  **/
261 #define PERROR_KERN_AND_EXIT(nn, ss) do {               \
262                 errno = errno ? errno : (nn);           \
263                 kern_printf(ss);                        \
264                 exit(nn);                               \
265         } while (0)
266
267
268
269
270 /*}*/
271
272 #ifdef __cplusplus
273 }
274 #endif
275
276
277 #endif      /* !FRSH_ERROR_H_ */