Commit a20a64aaf0c47c7d573fcefbd40627e5b0e63ab4
1 parent
56a70bc7
Exists in
master
and in
5 other branches
Implementando tratamento de excessões em rexx
Showing
6 changed files
with
87 additions
and
51 deletions
Show diff stats
src/plugins/rx3270/exception.cc
| @@ -34,33 +34,34 @@ | @@ -34,33 +34,34 @@ | ||
| 34 | #endif // HAVE_SYSLOG | 34 | #endif // HAVE_SYSLOG |
| 35 | 35 | ||
| 36 | #include <string.h> | 36 | #include <string.h> |
| 37 | + #include <oorexxerrors.h> | ||
| 37 | 38 | ||
| 38 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 39 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 39 | 40 | ||
| 40 | rx3270::exception::exception(const char *fmt, ...) | 41 | rx3270::exception::exception(const char *fmt, ...) |
| 41 | { | 42 | { |
| 42 | - char buffer[4096]; | ||
| 43 | va_list arg_ptr; | 43 | va_list arg_ptr; |
| 44 | 44 | ||
| 45 | va_start(arg_ptr, fmt); | 45 | va_start(arg_ptr, fmt); |
| 46 | - vsnprintf(buffer,4095,fmt,arg_ptr); | 46 | + vsnprintf(this->msg,4095,fmt,arg_ptr); |
| 47 | va_end(arg_ptr); | 47 | va_end(arg_ptr); |
| 48 | 48 | ||
| 49 | - msg = strdup(buffer); | 49 | + this->code = Rexx_Error_Application_error; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -extern "C" { | ||
| 53 | - static void memfree(void *ptr) | ||
| 54 | - { | ||
| 55 | - free(ptr); | ||
| 56 | - } | ||
| 57 | -} | ||
| 58 | - | ||
| 59 | -rx3270::exception::~exception() | 52 | +rx3270::exception::exception(int code, const char *fmt, ...) |
| 60 | { | 53 | { |
| 61 | - memfree(msg); | 54 | + va_list arg_ptr; |
| 55 | + | ||
| 56 | + va_start(arg_ptr, fmt); | ||
| 57 | + vsnprintf(this->msg,4095,fmt,arg_ptr); | ||
| 58 | + va_end(arg_ptr); | ||
| 59 | + | ||
| 60 | + this->code = code; | ||
| 61 | + | ||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | + | ||
| 64 | const char * rx3270::exception::getMessage(void) | 65 | const char * rx3270::exception::getMessage(void) |
| 65 | { | 66 | { |
| 66 | return this->msg; | 67 | return this->msg; |
| @@ -79,8 +80,21 @@ void rx3270::exception::logMessage(void) | @@ -79,8 +80,21 @@ void rx3270::exception::logMessage(void) | ||
| 79 | 80 | ||
| 80 | void rx3270::exception::RaiseException(RexxMethodContext *context) | 81 | void rx3270::exception::RaiseException(RexxMethodContext *context) |
| 81 | { | 82 | { |
| 82 | - // TODO: Raise rexx exception | ||
| 83 | trace("%s: %s",__FUNCTION__,this->getMessage()); | 83 | trace("%s: %s",__FUNCTION__,this->getMessage()); |
| 84 | logMessage(); | 84 | logMessage(); |
| 85 | + | ||
| 86 | + context->RaiseException1( this->code, | ||
| 87 | + context->NewStringFromAsciiz(this->msg) | ||
| 88 | + ); | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +void rx3270::exception::RaiseException(RexxCallContext *context) | ||
| 92 | +{ | ||
| 93 | + trace("%s: %s",__FUNCTION__,this->getMessage()); | ||
| 94 | + logMessage(); | ||
| 95 | + | ||
| 96 | + context->RaiseException1( this->code, | ||
| 97 | + context->NewStringFromAsciiz(this->msg) | ||
| 98 | + ); | ||
| 85 | } | 99 | } |
| 86 | 100 |
src/plugins/rx3270/remote.cc
| @@ -104,6 +104,9 @@ | @@ -104,6 +104,9 @@ | ||
| 104 | char * query_string(const char *method); | 104 | char * query_string(const char *method); |
| 105 | int query_intval(const char *method); | 105 | int query_intval(const char *method); |
| 106 | 106 | ||
| 107 | + char * get_string(DBusMessage * msg); | ||
| 108 | + int get_intval(DBusMessage * msg); | ||
| 109 | + | ||
| 107 | #endif | 110 | #endif |
| 108 | 111 | ||
| 109 | 112 | ||
| @@ -127,7 +130,7 @@ DBusMessage * remote::create_message(const char *method) | @@ -127,7 +130,7 @@ DBusMessage * remote::create_message(const char *method) | ||
| 127 | method); // method | 130 | method); // method |
| 128 | 131 | ||
| 129 | if (!msg) | 132 | if (!msg) |
| 130 | - log("Error creating message for method %s",method); | 133 | + throw exception("Error creating message for method %s",method); |
| 131 | 134 | ||
| 132 | return msg; | 135 | return msg; |
| 133 | } | 136 | } |
| @@ -167,7 +170,7 @@ remote::remote(const char *name) | @@ -167,7 +170,7 @@ remote::remote(const char *name) | ||
| 167 | 170 | ||
| 168 | if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT)) | 171 | if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT)) |
| 169 | { | 172 | { |
| 170 | - log("%s","Invalid service instance"); | 173 | + throw exception("%s","Invalid service instance"); |
| 171 | return; | 174 | return; |
| 172 | } | 175 | } |
| 173 | 176 | ||
| @@ -175,13 +178,13 @@ remote::remote(const char *name) | @@ -175,13 +178,13 @@ remote::remote(const char *name) | ||
| 175 | 178 | ||
| 176 | if(hPipe == INVALID_HANDLE_VALUE) | 179 | if(hPipe == INVALID_HANDLE_VALUE) |
| 177 | { | 180 | { |
| 178 | - log("%s","Can´t create service pipe"); | 181 | + throw exception("%s","Can´t create service pipe"); |
| 179 | return; | 182 | return; |
| 180 | } | 183 | } |
| 181 | 184 | ||
| 182 | if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) | 185 | if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) |
| 183 | { | 186 | { |
| 184 | - log("%s","Can´t set pipe state"); | 187 | + throw exception("%s","Can´t set pipe state"); |
| 185 | CloseHandle(hPipe); | 188 | CloseHandle(hPipe); |
| 186 | hPipe = INVALID_HANDLE_VALUE; | 189 | hPipe = INVALID_HANDLE_VALUE; |
| 187 | return; | 190 | return; |
| @@ -267,13 +270,13 @@ remote::remote(const char *name) | @@ -267,13 +270,13 @@ remote::remote(const char *name) | ||
| 267 | 270 | ||
| 268 | if (dbus_error_is_set(&err)) | 271 | if (dbus_error_is_set(&err)) |
| 269 | { | 272 | { |
| 270 | - log("DBUS Connection Error (%s)", err.message); | 273 | + throw exception("DBUS Connection Error (%s)", err.message); |
| 271 | dbus_error_free(&err); | 274 | dbus_error_free(&err); |
| 272 | } | 275 | } |
| 273 | 276 | ||
| 274 | if(!conn) | 277 | if(!conn) |
| 275 | { | 278 | { |
| 276 | - log("%s", "DBUS Connection failed"); | 279 | + throw exception("%s", "DBUS Connection failed"); |
| 277 | return; | 280 | return; |
| 278 | } | 281 | } |
| 279 | 282 | ||
| @@ -293,7 +296,7 @@ remote::remote(const char *name) | @@ -293,7 +296,7 @@ remote::remote(const char *name) | ||
| 293 | 296 | ||
| 294 | if (dbus_error_is_set(&err)) | 297 | if (dbus_error_is_set(&err)) |
| 295 | { | 298 | { |
| 296 | - log("Name Error (%s)", err.message); | 299 | + throw exception("Name Error (%s)", err.message); |
| 297 | dbus_error_free(&err); | 300 | dbus_error_free(&err); |
| 298 | conn = NULL; | 301 | conn = NULL; |
| 299 | return; | 302 | return; |
| @@ -302,7 +305,7 @@ remote::remote(const char *name) | @@ -302,7 +305,7 @@ remote::remote(const char *name) | ||
| 302 | if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | 305 | if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) |
| 303 | { | 306 | { |
| 304 | trace("%s: DBUS request for name %s failed",__FUNCTION__, busname); | 307 | trace("%s: DBUS request for name %s failed",__FUNCTION__, busname); |
| 305 | - log("DBUS for \"%s\" failed",name); | 308 | + throw exception("DBUS request for \"%s\" failed",name); |
| 306 | conn = NULL; | 309 | conn = NULL; |
| 307 | return; | 310 | return; |
| 308 | } | 311 | } |
| @@ -345,7 +348,7 @@ DBusMessage * remote::call(DBusMessage *msg) | @@ -345,7 +348,7 @@ DBusMessage * remote::call(DBusMessage *msg) | ||
| 345 | 348 | ||
| 346 | if(!reply) | 349 | if(!reply) |
| 347 | { | 350 | { |
| 348 | - log("%s",error.message); | 351 | + throw exception("%s",error.message); |
| 349 | dbus_error_free(&error); | 352 | dbus_error_free(&error); |
| 350 | } | 353 | } |
| 351 | 354 | ||
| @@ -353,7 +356,7 @@ DBusMessage * remote::call(DBusMessage *msg) | @@ -353,7 +356,7 @@ DBusMessage * remote::call(DBusMessage *msg) | ||
| 353 | 356 | ||
| 354 | } | 357 | } |
| 355 | 358 | ||
| 356 | -char * get_string(DBusMessage * msg) | 359 | +char * remote::get_string(DBusMessage * msg) |
| 357 | { | 360 | { |
| 358 | char *rc = NULL; | 361 | char *rc = NULL; |
| 359 | if(msg) | 362 | if(msg) |
| @@ -369,12 +372,12 @@ char * get_string(DBusMessage * msg) | @@ -369,12 +372,12 @@ char * get_string(DBusMessage * msg) | ||
| 369 | trace("Response: [%s]",str); | 372 | trace("Response: [%s]",str); |
| 370 | rc = strdup(str); | 373 | rc = strdup(str); |
| 371 | } | 374 | } |
| 372 | -#ifdef DEBUG | ||
| 373 | else | 375 | else |
| 374 | { | 376 | { |
| 375 | - trace("Return type is %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_STRING); | 377 | + dbus_message_unref(msg); |
| 378 | + throw exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | ||
| 379 | + return NULL; | ||
| 376 | } | 380 | } |
| 377 | -#endif | ||
| 378 | } | 381 | } |
| 379 | 382 | ||
| 380 | dbus_message_unref(msg); | 383 | dbus_message_unref(msg); |
| @@ -389,7 +392,7 @@ char * remote::query_string(const char *method) | @@ -389,7 +392,7 @@ char * remote::query_string(const char *method) | ||
| 389 | return NULL; | 392 | return NULL; |
| 390 | } | 393 | } |
| 391 | 394 | ||
| 392 | -int get_intval(DBusMessage * msg) | 395 | +int remote::get_intval(DBusMessage * msg) |
| 393 | { | 396 | { |
| 394 | int rc = -1; | 397 | int rc = -1; |
| 395 | 398 | ||
| @@ -405,12 +408,12 @@ int get_intval(DBusMessage * msg) | @@ -405,12 +408,12 @@ int get_intval(DBusMessage * msg) | ||
| 405 | dbus_message_iter_get_basic(&iter, &iSigned); | 408 | dbus_message_iter_get_basic(&iter, &iSigned); |
| 406 | rc = (int) iSigned; | 409 | rc = (int) iSigned; |
| 407 | } | 410 | } |
| 408 | -#ifdef DEBUG | ||
| 409 | else | 411 | else |
| 410 | { | 412 | { |
| 411 | - trace("Return type is %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | 413 | + dbus_message_unref(msg); |
| 414 | + throw exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | ||
| 415 | + return -1; | ||
| 412 | } | 416 | } |
| 413 | -#endif | ||
| 414 | } | 417 | } |
| 415 | 418 | ||
| 416 | dbus_message_unref(msg); | 419 | dbus_message_unref(msg); |
| @@ -447,7 +450,6 @@ char * remote::get_revision(void) | @@ -447,7 +450,6 @@ char * remote::get_revision(void) | ||
| 447 | 450 | ||
| 448 | } | 451 | } |
| 449 | 452 | ||
| 450 | - | ||
| 451 | LIB3270_CSTATE remote::get_cstate(void) | 453 | LIB3270_CSTATE remote::get_cstate(void) |
| 452 | { | 454 | { |
| 453 | #if defined(WIN32) | 455 | #if defined(WIN32) |
src/plugins/rx3270/rexx_methods.cc
| @@ -125,10 +125,19 @@ RexxMethod2(int, rx3270_method_sleep, CSELF, sessionPtr, int, seconds) | @@ -125,10 +125,19 @@ RexxMethod2(int, rx3270_method_sleep, CSELF, sessionPtr, int, seconds) | ||
| 125 | 125 | ||
| 126 | RexxMethod1(logical_t, rx3270_method_is_connected, CSELF, sessionPtr) | 126 | RexxMethod1(logical_t, rx3270_method_is_connected, CSELF, sessionPtr) |
| 127 | { | 127 | { |
| 128 | - rx3270 *hSession = (rx3270 *) sessionPtr; | ||
| 129 | - if(!hSession) | ||
| 130 | - return false; | ||
| 131 | - return hSession->is_connected(); | 128 | + try |
| 129 | + { | ||
| 130 | + rx3270 *hSession = (rx3270 *) sessionPtr; | ||
| 131 | + if(!hSession) | ||
| 132 | + return false; | ||
| 133 | + return hSession->is_connected(); | ||
| 134 | + } | ||
| 135 | + catch(rx3270::exception e) | ||
| 136 | + { | ||
| 137 | + e.RaiseException(context); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + return 0; | ||
| 132 | } | 141 | } |
| 133 | 142 | ||
| 134 | RexxMethod1(logical_t, rx3270_method_is_ready, CSELF, sessionPtr) | 143 | RexxMethod1(logical_t, rx3270_method_is_ready, CSELF, sessionPtr) |
src/plugins/rx3270/rx3270.cc
| @@ -118,18 +118,9 @@ char * rx3270::get_revision(void) | @@ -118,18 +118,9 @@ char * rx3270::get_revision(void) | ||
| 118 | 118 | ||
| 119 | rx3270 * rx3270::get_default() | 119 | rx3270 * rx3270::get_default() |
| 120 | { | 120 | { |
| 121 | - try | ||
| 122 | - { | ||
| 123 | - if(defSession) | ||
| 124 | - return defSession; | ||
| 125 | - return create_local(); | ||
| 126 | - } | ||
| 127 | - catch(exception e) | ||
| 128 | - { | ||
| 129 | - e.logMessage(); | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - return NULL; | 121 | + if(defSession) |
| 122 | + return defSession; | ||
| 123 | + return create_local(); | ||
| 133 | } | 124 | } |
| 134 | 125 | ||
| 135 | void rx3270::log(const char *fmt, ...) | 126 | void rx3270::log(const char *fmt, ...) |
src/plugins/rx3270/rx3270.h
| @@ -147,16 +147,18 @@ | @@ -147,16 +147,18 @@ | ||
| 147 | class exception | 147 | class exception |
| 148 | { | 148 | { |
| 149 | public: | 149 | public: |
| 150 | + exception(int code, const char *fmt, ...); | ||
| 150 | exception(const char *fmt, ...); | 151 | exception(const char *fmt, ...); |
| 151 | - ~exception(); | ||
| 152 | 152 | ||
| 153 | const char * getMessage(void); | 153 | const char * getMessage(void); |
| 154 | void logMessage(void); | 154 | void logMessage(void); |
| 155 | 155 | ||
| 156 | void RaiseException(RexxMethodContext *context); | 156 | void RaiseException(RexxMethodContext *context); |
| 157 | + void RaiseException(RexxCallContext *context); | ||
| 157 | 158 | ||
| 158 | private: | 159 | private: |
| 159 | - char *msg; | 160 | + int code; |
| 161 | + char msg[4096]; | ||
| 160 | 162 | ||
| 161 | }; | 163 | }; |
| 162 | 164 |
src/plugins/rx3270/typed_routines.cc
| @@ -35,7 +35,16 @@ | @@ -35,7 +35,16 @@ | ||
| 35 | 35 | ||
| 36 | RexxRoutine0(CSTRING, rx3270version) | 36 | RexxRoutine0(CSTRING, rx3270version) |
| 37 | { | 37 | { |
| 38 | - return rx3270::get_default()->get_version(); | 38 | + try |
| 39 | + { | ||
| 40 | + return rx3270::get_default()->get_version(); | ||
| 41 | + } | ||
| 42 | + catch(rx3270::exception e) | ||
| 43 | + { | ||
| 44 | + e.RaiseException(context); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + return NULL; | ||
| 39 | } | 48 | } |
| 40 | 49 | ||
| 41 | RexxRoutine0(CSTRING, rx3270QueryCState) | 50 | RexxRoutine0(CSTRING, rx3270QueryCState) |
| @@ -184,7 +193,16 @@ RexxRoutine3(int, rx3270queryStringAt, int, row, int, col, CSTRING, key) | @@ -184,7 +193,16 @@ RexxRoutine3(int, rx3270queryStringAt, int, row, int, col, CSTRING, key) | ||
| 184 | 193 | ||
| 185 | RexxRoutine2(int, rx3270SetCursorPosition, int, row, int, col) | 194 | RexxRoutine2(int, rx3270SetCursorPosition, int, row, int, col) |
| 186 | { | 195 | { |
| 187 | - return rx3270::get_default()->set_cursor_position(row,col); | 196 | + try |
| 197 | + { | ||
| 198 | + return rx3270::get_default()->set_cursor_position(row,col); | ||
| 199 | + } | ||
| 200 | + catch(rx3270::exception e) | ||
| 201 | + { | ||
| 202 | + e.RaiseException(context); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + return -1; | ||
| 188 | } | 206 | } |
| 189 | 207 | ||
| 190 | RexxRoutine3(int, rx3270SetStringAt, int, row, int, col, CSTRING, text) | 208 | RexxRoutine3(int, rx3270SetStringAt, int, row, int, col, CSTRING, text) |