From 0fe8634c60cc6cac589951c0b8b8d802f40efbdd Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Thu, 11 Jul 2013 12:08:13 +0000 Subject: [PATCH] Atualizando plugin rexx para usar a biblioteca de classes --- src/classlib/session.cc | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/include/pw3270/class.h | 9 ++++++++- src/plugins/rx3270/Makefile.in | 12 ++++-------- src/plugins/rx3270/rexx_methods.cc | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------ 4 files changed, 202 insertions(+), 123 deletions(-) diff --git a/src/classlib/session.cc b/src/classlib/session.cc index 6b2bf8f..7fd37ff 100644 --- a/src/classlib/session.cc +++ b/src/classlib/session.cc @@ -284,6 +284,102 @@ return str; } + string * session::get_string_at(int row, int col, size_t sz) + { + string *str = this->get_text_at(row,col,sz); + + if(str) + return this->get_local_text(str); + + return 0; + } + + int session::set_string_at(int row, int col, const char *str) + { + if(!str) + return -1; + +#ifdef HAVE_ICONV + if(conv2Host != (iconv_t)(-1)) + { + size_t in = strlen(str); + size_t out = (in << 1); + char * ptr; + char * outBuffer = (char *) malloc(out); + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; + + memset(ptr=outBuffer,0,out); + + iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state + + if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) + { + int rc = this->set_text_at(row,col,outBuffer); + free(outBuffer); + return rc; + } + + free(outBuffer); + } +#endif // HAVE_ICONV + + return this->set_text_at(row,col,str); + + } + + int session::input_string(const char *str) + { + if(!str) + return -1; + +#ifdef HAVE_ICONV + if(conv2Host != (iconv_t)(-1)) + { + size_t in = strlen(str); + size_t out = (in << 1); + char * ptr; + char * outBuffer = (char *) malloc(out); + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; + + memset(ptr=outBuffer,0,out); + + iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state + + if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) + { + int rc = this->emulate_input(outBuffer); + free(outBuffer); + return rc; + } + + free(outBuffer); + } +#endif // HAVE_ICONV + + return this->emulate_input(str); + + } + + int session::cmp_string_at(int row, int col, const char *text) + { + string * str = get_3270_text(new string(text)); + int rc = cmp_text_at(row,col,str->c_str()); + delete str; + return rc; + } + + int session::wait_for_string_at(int row, int col, const char *key, int timeout) + { + string * str = get_3270_text(new string(key)); + int rc = wait_for_text_at(row,col,str->c_str(),timeout); + delete str; + return rc; + } + + string * session::get_string(int baddr, size_t len) + { + return get_local_text(get_text(baddr,len)); + } } diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index 1042f8e..fe193b9 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -112,12 +112,18 @@ virtual int wait(int seconds) = 0; virtual int iterate(bool wait = true) = 0; + virtual string * get_text(int baddr, size_t len) = 0; virtual string * get_text_at(int row, int col, size_t sz) = 0; virtual int set_text_at(int row, int col, const char *str) = 0; - virtual string * get_text(int baddr, size_t len) = 0; virtual int cmp_text_at(int row, int col, const char *text) = 0; virtual int wait_for_text_at(int row, int col, const char *key, int timeout); + string * get_string(int baddr, size_t len); + string * get_string_at(int row, int col, size_t sz); + int set_string_at(int row, int col, const char *str); + int cmp_string_at(int row, int col, const char *text); + int wait_for_string_at(int row, int col, const char *key, int timeout); + virtual int set_cursor_position(int row, int col) = 0; virtual int set_cursor_addr(int addr) = 0; virtual int get_cursor_addr(void) = 0; @@ -129,6 +135,7 @@ virtual int pakey(int key) = 0; virtual int emulate_input(const char *str) = 0; + int input_string(const char *str); virtual int get_field_start(int baddr = -1) = 0; virtual int get_field_len(int baddr = -1) = 0; diff --git a/src/plugins/rx3270/Makefile.in b/src/plugins/rx3270/Makefile.in index 6203532..d077969 100644 --- a/src/plugins/rx3270/Makefile.in +++ b/src/plugins/rx3270/Makefile.in @@ -56,10 +56,10 @@ $(BINDBG)/$(PLUGIN_NAME): $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$( @$(MKDIR) `dirname $@` @$(CXX) $(DLL_FLAGS) @LDSOFLAGS@ @DBGRPATH@ $(LDFLAGS) -o $@ $^ $(LIBS) $(LIB3270_LIBS) $(GTK_LIBS) $(GLIB_LIBS) $(PW3270_LIBS) -$(BINDBG)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC) $(CLASS_SRC)), $(OBJDBG)/$(SRC)@OBJEXT@) +$(BINDBG)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC)), $(OBJDBG)/$(SRC)@OBJEXT@) $(CLASS_DEBUG_OBJECTS) @echo " CCLD `basename $@`" @$(MKDIR) `dirname $@` - @$(CXX) $(DLL_FLAGS) $(LDFLAGS) @LDSOFLAGS@ @DBGRPATH@ -o $@ $^ $(LIBS) $(LIB3270_LIBS) + @$(CXX) $(DLL_FLAGS) $(LDFLAGS) @LDSOFLAGS@ @DBGRPATH@ -o $@ $^ $(LIBS) $(LIB3270_LIBS) $(CLASS_LIBS) #---[ Release Targets ]-------------------------------------------------------- @@ -68,10 +68,10 @@ $(BINRLS)/$(PLUGIN_NAME): $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJRLS)/$( @$(MKDIR) `dirname $@` $(CXX) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @RLS_LDFLAGS@ -o $@ $^ $(LIBS) $(LIB3270_LIBS) $(GTK_LIBS) $(GLIB_LIBS) $(PW3270_LIBS) -$(BINRLS)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC)), $(OBJRLS)/$(SRC).o) +$(BINRLS)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC)), $(OBJRLS)/$(SRC).o) $(CLASS_RELEASE_OBJECTS) @echo " CCLD `basename $@`" @$(MKDIR) `dirname $@` - $(CXX) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @RLS_LDFLAGS@ -o $@ $^ $(LIBS) $(LIB3270_LIBS) + $(CXX) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @RLS_LDFLAGS@ -o $@ $^ $(LIBS) $(LIB3270_LIBS) $(CLASS_LIBS) install: @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugin @@ -84,7 +84,3 @@ install: @$(MKDIR) $(DESTDIR)$(REXX_HOME) @$(INSTALL_DATA) rx3270.cls $(DESTDIR)$(REXX_HOME) -$(DEBDIR)/$(MODULE_NAME).install: Makefile - @$(MKDIR) `dirname $@` - @rm -f $@ - @echo $(libdir)/$(PACKAGE_NAME)-plugins/$(MODULE_NAME).so > $@ diff --git a/src/plugins/rx3270/rexx_methods.cc b/src/plugins/rx3270/rexx_methods.cc index 61d198f..b656594 100644 --- a/src/plugins/rx3270/rexx_methods.cc +++ b/src/plugins/rx3270/rexx_methods.cc @@ -126,7 +126,7 @@ RexxMethod1(logical_t, rx3270_method_is_connected, CSELF, sessionPtr) return false; return hSession->is_connected(); } - catch(std::exception e) + catch(std::exception &e) { context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); } @@ -200,84 +200,71 @@ RexxMethod2(int, rx3270_method_pakey, CSELF, sessionPtr, int, key) RexxMethod4(RexxStringObject, rx3270_method_get_text_at, CSELF, sessionPtr, int, row, int, col, int, sz) { - #warning Reimplementar -/* - session * hSession = (session *) sessionPtr; - if(hSession) + try { - char * str = session->get_text_at(row,col,sz); + session * hSession = (session *) sessionPtr; + string * str = hSession->get_string_at(row,col,sz); if(str) { - char * text = session->get_local_string(str); - RexxStringObject ret = context->String((CSTRING) text); - free(str); - free(text); + RexxStringObject ret = context->String((CSTRING) str->c_str()); + delete str; return ret; } + } -*/ + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } + return context->String(""); } RexxMethod4(int, rx3270_method_set_text_at, CSELF, sessionPtr, int, row, int, col, CSTRING, text) { - #warning Reimplementar -/* - rx3270 * session = (rx3270 *) sessionPtr; - - if(session) + try { - char * str = session->get_3270_string(text); - int rc; - rc = session->set_text_at(row,col,str); - free(str); - return rc; + session * hSession = (session *) sessionPtr; + return hSession->set_string_at(row,col,text); } -*/ + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } + return -1; } RexxMethod2(int, rx3270_method_input_text, CSELF, sessionPtr, CSTRING, text) { -#warning Reimplementar -/* - rx3270 * session = (rx3270 *) sessionPtr; - - if(session) + try + { + session * hSession = (session *) sessionPtr; + return hSession->input_string(text); + } + catch(std::exception &e) { - char * str = session->get_3270_string(text); - int rc = session->emulate_input(str); - free(str); - return rc; + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); } -*/ + return -1; + } RexxMethod4(int, rx3270_method_cmp_text_at, CSELF, sessionPtr, int, row, int, col, CSTRING, key) { - #warning Reimplementar -/* - int rc = 0; - rx3270 * session = (rx3270 *) sessionPtr; - - if(session) + try { - char * str = session->get_text_at(row,col,strlen(key)); - if(str) - { - char * text = session->get_3270_string(key); - rc = strcasecmp(str,text); - free(text); - } - free(str); + session * hSession = (session *) sessionPtr; + return hSession->cmp_string_at(row,col,key); + } + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); } - return rc; -*/ - return -1; } @@ -363,64 +350,67 @@ RexxMethod3(int, rx3270_method_set_option, CSELF, sessionPtr, CSTRING, name, int RexxMethod4(logical_t, rx3270_method_test, CSELF, sessionPtr, CSTRING, key, int, row, int, col) { - #warning Reimplementar -/* - session * hSession = (session *) sessionPtr; - - if(!hSession) - return false; + try + { + session * hSession = (session *) sessionPtr; - if(!hSession->is_ready()) - hSession->iterate(false); + if(!hSession->is_ready()) + hSession->iterate(false); - if(hSession->is_ready()) - { - bool rc = false; - char * str = hSession->get_text_at(row,col,strlen(key)); - if(str) + if(hSession->is_ready()) { - char * text = hSession->get_3270_string(key); - rc = (strcasecmp(str,text) == 0); - free(text); + bool rc = false; + string * str = hSession->get_string_at(row,col,strlen(key)); + if(str) + rc = (strcasecmp(str->c_str(),key) == 0); + delete str; + return rc; } - free(str); - return rc; + + } + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); } -*/ + return false; } RexxMethod5(int, rx3270_method_wait_for_text_at, CSELF, sessionPtr, int, row, int, col, CSTRING, key, int, timeout) { - #warning Reimplementar -/* - rx3270 * hSession = (rx3270 *) sessionPtr; + try + { + session * hSession = (session *) sessionPtr; + return hSession->wait_for_string_at(row,col,key,timeout); + + } + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } - if(hSession) - return hSession->wait_for_text_at(row,col,key,timeout); -*/ return -1; } RexxMethod3(RexxStringObject, rx3270_method_get_text, CSELF, sessionPtr, OPTIONAL_int, baddr, OPTIONAL_int, sz) { - #warning Reimplementar -/* - rx3270 * hSession = (rx3270 *) sessionPtr; - - if(hSession) + try { - char *str = hSession->get_text(baddr,sz > 0 ? sz : -1); + session * hSession = (session *) sessionPtr; + string * str = hSession->get_string(baddr,sz > 0 ? sz : -1); + if(str) { - char * text = hSession->get_local_string(str); - RexxStringObject ret = context->String((CSTRING) text); - free(str); - free(text); + RexxStringObject ret = context->String((CSTRING) str->c_str()); + delete str; return ret; } } -*/ + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } + return context->String(""); } @@ -456,41 +446,37 @@ RexxMethod2(int, rx3270_method_get_next_unprotected, CSELF, sessionPtr, OPTIONAL RexxMethod1(RexxStringObject, rx3270_method_get_selection, CSELF, sessionPtr) { - #warning Reimplementar -/* - session * hSession = (session *) sessionPtr; - - if(hSession) + try { - char *str = hSession->get_copy(); + string *str = ((session *) sessionPtr)->get_copy(); + if(str) { - char * text = hSession->get_local_string(str); - RexxStringObject ret = context->String((CSTRING) text); - free(str); - free(text); + RexxStringObject ret = context->String((CSTRING) str->c_str()); + delete str; return ret; } + } -*/ + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } + return context->String(""); } RexxMethod2(int, rx3270_method_set_selection, CSELF, sessionPtr, CSTRING, text) { - #warning Reimplementar -/* - rx3270 * session = (rx3270 *) sessionPtr; - - if(session) + try { - char * str = session->get_3270_string(text); - int rc; - rc = session->set_copy(str); - free(str); - return rc; + return ((session *) sessionPtr)->set_copy(text); } -*/ + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } + return -1; } @@ -516,15 +502,9 @@ RexxMethod1(RexxStringObject, rx3270_method_get_clipboard, CSELF, sessionPtr) RexxMethod2(int, rx3270_method_set_clipboard, CSELF, sessionPtr, CSTRING, text) { - session * hSession = (session *) sessionPtr; - - if(hSession) - return hSession->set_clipboard(text); - - return -1; + return ((session *) sessionPtr)->set_clipboard(text); } - RexxMethod5(int, rx3270_method_popup, CSELF, sessionPtr, CSTRING, s_id, CSTRING, title, CSTRING, message, OPTIONAL_CSTRING, det) { LIB3270_NOTIFY id = LIB3270_NOTIFY_INFO; -- libgit2 0.21.2