diff --git a/hllapi.cbp b/hllapi.cbp index cd113a5..492008f 100644 --- a/hllapi.cbp +++ b/hllapi.cbp @@ -35,6 +35,8 @@ + + diff --git a/src/core/actions.cc b/src/core/actions.cc index c6ad06d..b356e3f 100644 --- a/src/core/actions.cc +++ b/src/core/actions.cc @@ -74,25 +74,30 @@ return action(TN3270::ERASE_INPUT); } -/* - - HLLAPI_API_CALL hllapi_reset(void) - { - return HLLAPI_STATUS_SUCCESS; + HLLAPI_API_CALL hllapi_kybdreset(void) { + return action(TN3270::KYBD_RESET); } - HLLAPI_API_CALL hllapi_action(LPSTR buffer) { - try - { - session::get_default()->action((const char *) buffer); - } - catch(std::exception &e) - { - return HLLAPI_STATUS_SYSTEM_ERROR; + HLLAPI_API_CALL hllapi_action(LPSTR action_name) { + + try { + + getSession().action((const char *) action_name); + + return HLLAPI_STATUS_SUCCESS; + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + } - return HLLAPI_STATUS_SUCCESS; + + return HLLAPI_STATUS_SYSTEM_ERROR; + } +/* + HLLAPI_API_CALL hllapi_print(void) { return session::get_default()->print(); diff --git a/src/core/calls.cc b/src/core/calls.cc index c6264c2..e137d4a 100644 --- a/src/core/calls.cc +++ b/src/core/calls.cc @@ -237,29 +237,6 @@ return hllapi_get_state(); } - HLLAPI_API_CALL hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - if(!(buffer && *buffer)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - try - { - size_t sz = strlen(buffer); - string str = session::get_default()->get_string_at(row,col,sz); - strncpy(buffer,str.c_str(),sz); - } - catch(std::exception &e) - { - return HLLAPI_STATUS_SYSTEM_ERROR; - } - - return HLLAPI_STATUS_SUCCESS; - } - - HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text) { if(!hllapi_is_connected()) @@ -347,88 +324,6 @@ return *datadir; } - HLLAPI_API_CALL hllapi_setcursor(WORD pos) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - session::get_default()->set_cursor_addr(pos-1); - - return HLLAPI_STATUS_SUCCESS; - - } - - HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - session::get_default()->set_cursor_addr(pos-1); - - return HLLAPI_STATUS_SUCCESS; - - } - - HLLAPI_API_CALL hllapi_get_cursor_address() - { - return session::get_default()->get_cursor_addr()+1; - } - - HLLAPI_API_CALL hllapi_getcursor() - { - return session::get_default()->get_cursor_addr()+1; - } - - HLLAPI_API_CALL hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - int rc = HLLAPI_STATUS_SYSTEM_ERROR; - - if(offset < 1) - { - return HLLAPI_STATUS_BAD_PARAMETER; - } - - offset--; - - if(!session::has_default()) - { - return HLLAPI_STATUS_DISCONNECTED; - } - - if(!(buffer && *buffer)) { - return HLLAPI_STATUS_BAD_PARAMETER; - } - - try - { - size_t szBuffer; - - if(len > 0) - { - szBuffer = (size_t) len; - } - else - { - return HLLAPI_STATUS_BAD_PARAMETER; - } - - memset(buffer,' ',szBuffer); - - string str = session::get_default()->get_string(offset,szBuffer,false); - strncpy(buffer,str.c_str(),szBuffer); - rc = HLLAPI_STATUS_SUCCESS; - } - catch(std::exception &e) - { - rc = HLLAPI_STATUS_SYSTEM_ERROR; - } - - return rc; - } - HLLAPI_API_CALL hllapi_emulate_input(const LPSTR buffer, WORD len, WORD pasting) { if(!hllapi_is_connected()) diff --git a/src/core/cursor.cc b/src/core/cursor.cc new file mode 100644 index 0000000..84f0990 --- /dev/null +++ b/src/core/cursor.cc @@ -0,0 +1,85 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "private.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return HLLAPI_STATUS_DISCONNECTED; + + host.setCursorPosition((unsigned short) pos -1); + + return 0; + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + + } + + return HLLAPI_STATUS_SYSTEM_ERROR; + + } + + HLLAPI_API_CALL hllapi_setcursor(WORD pos) { + return hllapi_set_cursor_address(pos); + } + + HLLAPI_API_CALL hllapi_get_cursor_address() { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return 0; + + return (DWORD) (host.getCursorPosition()+1); + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + return -1; + + } + + return -1; + } + + HLLAPI_API_CALL hllapi_getcursor() { + return hllapi_get_cursor_address(); + } + diff --git a/src/core/get.cc b/src/core/get.cc new file mode 100644 index 0000000..70532ef --- /dev/null +++ b/src/core/get.cc @@ -0,0 +1,92 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "private.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + HLLAPI_API_CALL hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return HLLAPI_STATUS_DISCONNECTED; + + if(!(buffer && *buffer)) + return HLLAPI_STATUS_BAD_PARAMETER; + + size_t length = strlen(buffer); + string contents = host.toString( (int) row, (int) col, length); + + strncpy((char *) buffer, contents.c_str(), std::min(length,contents.size())); + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + return HLLAPI_STATUS_SYSTEM_ERROR; + + } + + return HLLAPI_STATUS_SUCCESS; + + } + + HLLAPI_API_CALL hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return HLLAPI_STATUS_DISCONNECTED; + + if(!(buffer && *buffer)) + return HLLAPI_STATUS_BAD_PARAMETER; + + if(len == 0) + return HLLAPI_STATUS_BAD_PARAMETER; + + string contents = host.toString((int) offset, (size_t) len); + + memset(buffer,' ',len); + strncpy((char *) buffer, contents.c_str(), std::min((size_t) len,contents.size())); + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + return HLLAPI_STATUS_SYSTEM_ERROR; + + } + + return HLLAPI_STATUS_SUCCESS; + + } + diff --git a/src/core/private.h b/src/core/private.h index d34be79..49d0956 100644 --- a/src/core/private.h +++ b/src/core/private.h @@ -43,6 +43,7 @@ using std::runtime_error; using std::string; using TN3270::Host; + using std::exception; extern string hllapi_lasterror; diff --git a/src/include/lib3270/hllapi.h b/src/include/lib3270/hllapi.h index 3db9c7c..e15dab6 100644 --- a/src/include/lib3270/hllapi.h +++ b/src/include/lib3270/hllapi.h @@ -170,7 +170,7 @@ HLLAPI_API_CALL hllapi_deinit(void); HLLAPI_API_CALL hllapi_get_revision(void); - HLLAPI_API_CALL hllapi_reset(void); + HLLAPI_API_CALL hllapi_kybdreset(void); /** * @brief Connect to host. @@ -211,7 +211,7 @@ HLLAPI_API_CALL hllapi_erase_eol(void); HLLAPI_API_CALL hllapi_erase_input(void); - HLLAPI_API_CALL hllapi_action(LPSTR buffer); + HLLAPI_API_CALL hllapi_action(LPSTR action_name); HLLAPI_API_CALL hllapi_print(void); diff --git a/src/testprogram/testprogram.cc b/src/testprogram/testprogram.cc index b568433..0a9632e 100644 --- a/src/testprogram/testprogram.cc +++ b/src/testprogram/testprogram.cc @@ -82,6 +82,20 @@ return rc; } + rc = hllapi_wait_for_ready(10); + if(rc) { + cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + return rc; + } + + cout << "Host is " << (hllapi_is_connected() ? "connected" : "not connected") << endl; + + rc = hllapi_disconnect(); + if(rc) { + cout << "hllapi_disconnect returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + return rc; + } + cout << "HLLAPI Last error was \"" << hllapi_get_last_error() << "\"" << endl; /* -- libgit2 0.21.2