Commit 56a70bc7c3bbdaf0088bb99407a9e31e8aa845b7
1 parent
8568180d
Exists in
master
and in
5 other branches
Iniciando tratamento de excessões no padrão ooRexx
Showing
6 changed files
with
126 additions
and
6 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -283,6 +283,7 @@ |
| 283 | 283 | <Option compilerVar="CC" /> |
| 284 | 284 | </Unit> |
| 285 | 285 | <Unit filename="src/plugins/rx3270/Makefile.in" /> |
| 286 | + <Unit filename="src/plugins/rx3270/exception.cc" /> | |
| 286 | 287 | <Unit filename="src/plugins/rx3270/local.cc" /> |
| 287 | 288 | <Unit filename="src/plugins/rx3270/pluginmain.cc" /> |
| 288 | 289 | <Unit filename="src/plugins/rx3270/remote.cc" /> | ... | ... |
src/plugins/rx3270/Makefile.in
| ... | ... | @@ -29,7 +29,7 @@ |
| 29 | 29 | MODULE_NAME=rx3270 |
| 30 | 30 | DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile |
| 31 | 31 | PLUGIN_SRC=pluginmain.cc |
| 32 | -EXTAPI_SRC=rxapimain.cc text.cc typed_routines.cc local.cc remote.cc rexx_methods.cc rx3270.cc | |
| 32 | +EXTAPI_SRC=rxapimain.cc text.cc typed_routines.cc local.cc remote.cc rexx_methods.cc rx3270.cc exception.cc | |
| 33 | 33 | |
| 34 | 34 | #---[ Tools ]------------------------------------------------------------------ |
| 35 | 35 | ... | ... |
| ... | ... | @@ -0,0 +1,86 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
| 19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como exception.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include "rx3270.h" | |
| 31 | + | |
| 32 | +#ifdef HAVE_SYSLOG | |
| 33 | + #include <syslog.h> | |
| 34 | +#endif // HAVE_SYSLOG | |
| 35 | + | |
| 36 | + #include <string.h> | |
| 37 | + | |
| 38 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 39 | + | |
| 40 | +rx3270::exception::exception(const char *fmt, ...) | |
| 41 | +{ | |
| 42 | + char buffer[4096]; | |
| 43 | + va_list arg_ptr; | |
| 44 | + | |
| 45 | + va_start(arg_ptr, fmt); | |
| 46 | + vsnprintf(buffer,4095,fmt,arg_ptr); | |
| 47 | + va_end(arg_ptr); | |
| 48 | + | |
| 49 | + msg = strdup(buffer); | |
| 50 | +} | |
| 51 | + | |
| 52 | +extern "C" { | |
| 53 | + static void memfree(void *ptr) | |
| 54 | + { | |
| 55 | + free(ptr); | |
| 56 | + } | |
| 57 | +} | |
| 58 | + | |
| 59 | +rx3270::exception::~exception() | |
| 60 | +{ | |
| 61 | + memfree(msg); | |
| 62 | +} | |
| 63 | + | |
| 64 | +const char * rx3270::exception::getMessage(void) | |
| 65 | +{ | |
| 66 | + return this->msg; | |
| 67 | +} | |
| 68 | + | |
| 69 | +void rx3270::exception::logMessage(void) | |
| 70 | +{ | |
| 71 | +#ifdef HAVE_SYSLOG | |
| 72 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 73 | + syslog(LOG_INFO,"%s",this->getMessage()); | |
| 74 | + closelog(); | |
| 75 | +#else | |
| 76 | + fprintf(stderr,"%s",this->getMessage()); | |
| 77 | +#endif | |
| 78 | +} | |
| 79 | + | |
| 80 | +void rx3270::exception::RaiseException(RexxMethodContext *context) | |
| 81 | +{ | |
| 82 | + // TODO: Raise rexx exception | |
| 83 | + trace("%s: %s",__FUNCTION__,this->getMessage()); | |
| 84 | + logMessage(); | |
| 85 | +} | |
| 86 | + | ... | ... |
src/plugins/rx3270/rexx_methods.cc
| ... | ... | @@ -43,8 +43,16 @@ |
| 43 | 43 | RexxMethod1(int, rx3270_method_init, CSTRING, type) |
| 44 | 44 | { |
| 45 | 45 | // Set session class in rexx object |
| 46 | - RexxPointerObject sessionPtr = context->NewPointer(rx3270::create(type)); | |
| 47 | - context->SetObjectVariable("CSELF", sessionPtr); | |
| 46 | + try | |
| 47 | + { | |
| 48 | + RexxPointerObject sessionPtr = context->NewPointer(rx3270::create(type)); | |
| 49 | + context->SetObjectVariable("CSELF", sessionPtr); | |
| 50 | + } | |
| 51 | + catch(rx3270::exception e) | |
| 52 | + { | |
| 53 | + e.RaiseException(context); | |
| 54 | + } | |
| 55 | + | |
| 48 | 56 | return 0; |
| 49 | 57 | } |
| 50 | 58 | ... | ... |
src/plugins/rx3270/rx3270.cc
| ... | ... | @@ -118,9 +118,18 @@ char * rx3270::get_revision(void) |
| 118 | 118 | |
| 119 | 119 | rx3270 * rx3270::get_default() |
| 120 | 120 | { |
| 121 | - if(defSession) | |
| 122 | - return defSession; | |
| 123 | - return create_local(); | |
| 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; | |
| 124 | 133 | } |
| 125 | 134 | |
| 126 | 135 | void rx3270::log(const char *fmt, ...) | ... | ... |
src/plugins/rx3270/rx3270.h
| ... | ... | @@ -144,6 +144,22 @@ |
| 144 | 144 | |
| 145 | 145 | public: |
| 146 | 146 | |
| 147 | + class exception | |
| 148 | + { | |
| 149 | + public: | |
| 150 | + exception(const char *fmt, ...); | |
| 151 | + ~exception(); | |
| 152 | + | |
| 153 | + const char * getMessage(void); | |
| 154 | + void logMessage(void); | |
| 155 | + | |
| 156 | + void RaiseException(RexxMethodContext *context); | |
| 157 | + | |
| 158 | + private: | |
| 159 | + char *msg; | |
| 160 | + | |
| 161 | + }; | |
| 162 | + | |
| 147 | 163 | rx3270(const char *local = REXX_DEFAULT_CHARSET, const char *remote = "ISO-8859-1"); |
| 148 | 164 | |
| 149 | 165 | virtual ~rx3270(); | ... | ... |