diff --git a/client/src/core/host.cc b/client/src/core/host.cc index bc6f3ec..aa0e296 100644 --- a/client/src/core/host.cc +++ b/client/src/core/host.cc @@ -211,20 +211,11 @@ throw std::system_error(ENOTSUP, std::system_category()); } - void Host::input(const char *text, size_t sz) { - -#ifdef DEBUG - { - string str = string(text,sz); - clog << __FUNCTION__ << "(\"" << str << "\")" << endl; - } -#endif // DEBUG - + Host & Host::input(const char *text, size_t sz) { this->session->input(text, sz); - + return *this; } - Host & Host::input(const char *text, const char control_char) { for(const char * ptr = strchr(text,control_char); ptr; ptr = strchr(text,control_char)) { diff --git a/client/src/core/session.cc b/client/src/core/session.cc index b9a2b0c..31277bb 100644 --- a/client/src/core/session.cc +++ b/client/src/core/session.cc @@ -74,6 +74,24 @@ } + Session & Session::push(const PFKey key) { + return pfkey( ((unsigned short) key) + 1); + } + + Session & Session::push(const PAKey key) { + return pakey( ((unsigned short) key) + 1); + } + + Session & Session::push(int row, int col, const std::string &text) { + return push(row,col,text.c_str(),text.size()); + } + + Session & Session::push(int baddr, const std::string &text) { + return push(baddr,text.c_str(),text.size()); + } + + + } diff --git a/client/src/include/ipc-client-internals.h b/client/src/include/ipc-client-internals.h index fbc6444..745d330 100644 --- a/client/src/include/ipc-client-internals.h +++ b/client/src/include/ipc-client-internals.h @@ -204,10 +204,9 @@ /// @brief Set field at current posicion, jumps to next writable field. TN3270::Session & push(const char *text) override; - TN3270::Session & push(int baddr, const std::string &text) override; - TN3270::Session & push(int row, int col, const std::string &text) override; - TN3270::Session & push(const PFKey key) override; - TN3270::Session & push(const PAKey key) override; + TN3270::Session & push(int baddr, const char *text, int length = -1) override; + TN3270::Session & push(int row, int col, const char *text, int length = -1) override; + TN3270::Session & push(const Action action) override; // Get contents. @@ -374,10 +373,9 @@ /// @brief Set field at current posicion, jumps to next writable field. TN3270::Session & push(const char *text) override; - TN3270::Session & push(int baddr, const std::string &text) override; - TN3270::Session & push(int row, int col, const std::string &text) override; - TN3270::Session & push(const PFKey key) override; - TN3270::Session & push(const PAKey key) override; + TN3270::Session & push(int baddr, const char *text, int length = -1) override; + TN3270::Session & push(int row, int col, const char *text, int length = -1) override; + TN3270::Session & push(const Action action) override; // Get contents. diff --git a/client/src/session/local/session.cc b/client/src/session/local/session.cc index fc143bb..732c5c7 100644 --- a/client/src/session/local/session.cc +++ b/client/src/session/local/session.cc @@ -252,10 +252,10 @@ return *this; } - TN3270::Session & Local::Session::push(int baddr, const std::string &text) { + TN3270::Session & Local::Session::push(int baddr, const char * text, int length) { std::lock_guard lock(sync); - string converted = convertToHost(text.c_str(),text.size()); + string converted = convertToHost(text, length); if(lib3270_set_string_at_address(this->hSession,baddr,(unsigned char *) converted.c_str(),converted.length()) < 0) { throw std::system_error(errno, std::system_category()); @@ -264,10 +264,10 @@ return *this; } - TN3270::Session & Local::Session::push(int row, int col, const std::string &text) { + TN3270::Session & Local::Session::push(int row, int col, const char *text, int length) { std::lock_guard lock(sync); - string converted = convertToHost(text.c_str(),text.size()); + string converted = convertToHost(text,length); if(lib3270_set_string_at(this->hSession,row,col,(unsigned char *) converted.c_str())) { throw std::system_error(errno, std::system_category()); @@ -276,18 +276,6 @@ return *this; } - TN3270::Session & Local::Session::push(const PFKey key) { - std::lock_guard lock(sync); - lib3270_pfkey(hSession,(int) key); - return *this; - } - - TN3270::Session & Local::Session::push(const PAKey key) { - std::lock_guard lock(sync); - lib3270_pakey(hSession,(int) key); - return *this; - } - TN3270::Session & Local::Session::push(const Action action) { typedef int (*ActionCallback)(H3270 *); diff --git a/client/src/session/remote/session.cc b/client/src/session/remote/session.cc index d58a48d..1d404c2 100644 --- a/client/src/session/remote/session.cc +++ b/client/src/session/remote/session.cc @@ -127,6 +127,8 @@ TN3270::Session & IPC::Session::input(const char *text, size_t length) { + throw std::system_error(ENOTSUP, std::system_category()); + return *this; } @@ -148,13 +150,17 @@ } - TN3270::Session & IPC::Session::push(int baddr, const std::string &text) { + TN3270::Session & IPC::Session::push(int baddr, const char *text, int length) { int rc; + if(length < 0) + length = strlen(text); + Request(*this,"setStringAtAddress") .push((uint32_t) baddr) - .push(text.c_str()) + .push(text) + .push((uint32_t) length) .call() .pop(rc); @@ -166,48 +172,18 @@ } - TN3270::Session & IPC::Session::push(int row, int col, const std::string &text) { + TN3270::Session & IPC::Session::push(int row, int col, const char *text, int length) { int32_t rc; + if(length < 0) + length = strlen(text); + Request(*this,"setStringAt") .push((uint32_t) row) .push((uint32_t) col) - .push(text.c_str()) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } - - return *this; - - } - - TN3270::Session & IPC::Session::push(const PFKey key) { - - int32_t rc; - - Request(*this,"pfkey") - .push((uint32_t) key) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } - - return *this; - - } - - TN3270::Session & IPC::Session::push(const PAKey key) { - - int32_t rc; - - Request(*this,"pakey") - .push((uint32_t) key) + .push(text) + .push((uint32_t) length) .call() .pop(rc); diff --git a/common/src/include/lib3270/ipc.h b/common/src/include/lib3270/ipc.h index 85808c6..87ee96b 100644 --- a/common/src/include/lib3270/ipc.h +++ b/common/src/include/lib3270/ipc.h @@ -294,10 +294,15 @@ /// @brief Send PA. virtual Session & pakey(unsigned short value) = 0; - virtual Session & push(int baddr, const std::string &text) = 0; - virtual Session & push(int row, int col, const std::string &text) = 0; - virtual Session & push(const PFKey key) = 0; - virtual Session & push(const PAKey key) = 0; + virtual Session & push(int baddr, const char *text, int length) = 0; + virtual Session & push(int row, int col, const char *text, int length) = 0; + + Session & push(int row, int col, const std::string &text); + Session & push(int baddr, const std::string &text); + + Session & push(const PFKey key); + Session & push(const PAKey key); + virtual Session & push(const Action action) = 0; // Get contents. @@ -342,8 +347,6 @@ /// @brief Write error to log file. void error(const char *fmt, ...) const; - void input(const char *text, size_t sz); - public: Host(const char *id = nullptr, const char *url = nullptr, time_t timeout = DEFAULT_TIMEOUT); ~Host(); @@ -435,6 +438,8 @@ /// @param control_char Control character used to identify commands. Host & input(const char *text, const char control_char = '@'); + Host & input(const char *text, size_t sz); + /// @brief Set field at current posicion, jumps to next writable field. inline Host & push(const char *text) { session->push(text); @@ -452,11 +457,21 @@ return *this; } + inline Host & push(int baddr, const char *text, int length = -1) { + session->push(baddr,text,length); + return *this; + } + inline Host & push(int row, int col, const std::string &text) { session->push(row,col,text); return *this; } + inline Host & push(int row, int col, const char *text, int length = -1) { + session->push(row,col,text,length); + return *this; + } + inline Host & push(const PFKey key) { session->push(key); return *this; -- libgit2 0.21.2