From 7154cff7a5604ea7a8e2096361ee55fa038652e0 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 19 Feb 2019 14:41:50 -0300 Subject: [PATCH] Implementing IPC calls. --- src/include/lib3270++.h | 4 ++-- src/lib3270++/ipc/session.cc | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/lib3270++/local/session.cc | 7 +++++-- src/lib3270++/private.h | 8 ++++---- 4 files changed, 137 insertions(+), 11 deletions(-) diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h index 3aada0e..e42a384 100644 --- a/src/include/lib3270++.h +++ b/src/include/lib3270++.h @@ -243,10 +243,10 @@ } /// @brief Set cursor address. - virtual void setCursorPosition(unsigned short addr) = 0; + virtual TN3270::Session & setCursorPosition(unsigned short addr) = 0; /// @brief Set cursor position. - virtual void setCursorPosition(unsigned short row, unsigned short col) = 0; + virtual TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) = 0; virtual Session & push(int baddr, const std::string &text) = 0; virtual Session & push(int row, int col, const std::string &text) = 0; diff --git a/src/lib3270++/ipc/session.cc b/src/lib3270++/ipc/session.cc index 9dbef59..1b74f11 100644 --- a/src/lib3270++/ipc/session.cc +++ b/src/lib3270++/ipc/session.cc @@ -127,59 +127,169 @@ /// @brief Set field at current position, jumps to next writable field. TN3270::Session & IPC::Session::push(const char *text) { - throw std::system_error(EINVAL, std::system_category()); + + int rc; + + Request(*this,"setString") + .push(text) + .call() + .pop(rc); + + if(rc) { + throw std::system_error((int) rc, std::system_category()); + } + + return *this; + } TN3270::Session & IPC::Session::push(int baddr, const std::string &text) { + int rc; + + Request(*this,"setStringAtAddress") + .push((uint32_t) baddr) + .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(int row, int col, const std::string &text) { + int32_t rc; + + 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) + .call() + .pop(rc); + + if(rc) { + throw std::system_error((int) rc, std::system_category()); + } return *this; + } TN3270::Session & IPC::Session::push(const Action action) { + const char * actions[] = { + "enter", + "erase", + "eraseeof", + "eraseeol", + "eraseinput" + }; + + int32_t rc; + + if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) { + throw std::system_error(EINVAL, std::system_category()); + } + + Request(*this,actions[(size_t) action]) + .call() + .pop(rc); + + if(rc) { + throw std::system_error((int) rc, std::system_category()); + } + return *this; + } TN3270::Session & IPC::Session::pop(int baddr, std::string &text) { + Request(*this,"getFieldAtAddress") + .push((uint32_t) baddr) + .call() + .pop(text); return *this; } TN3270::Session & IPC::Session::pop(int row, int col, std::string &text) { + Request(*this,"getFieldAt") + .push((uint32_t) row) + .push((uint32_t) col) + .call() + .pop(text); + return *this; } TN3270::Session & IPC::Session::pop(std::string &text) { + Request(*this,"getFieldAtCursor") + .call() + .pop(text); + return *this; + } /// @brief Set cursor address. /// /// @param addr Cursor address. - void IPC::Session::setCursorPosition(unsigned short addr) { + TN3270::Session & IPC::Session::setCursorPosition(unsigned short addr) { + + int32_t rc; + Request(*this,"setCursorAddress") + .push((uint32_t) addr) + .call() + .pop(rc); + + if(rc) { + throw std::system_error((int) rc, std::system_category()); + } + + return *this; } @@ -187,8 +297,21 @@ /// /// @param row New cursor row. /// @param col New cursor column. - void IPC::Session::setCursorPosition(unsigned short row, unsigned short col) { + TN3270::Session & IPC::Session::setCursorPosition(unsigned short row, unsigned short col) { + int32_t rc; + + Request(*this,"setCursorPosition") + .push((uint32_t) row) + .push((uint32_t) col) + .call() + .pop(rc); + + if(rc) { + throw std::system_error((int) rc, std::system_category()); + } + + return *this; } diff --git a/src/lib3270++/local/session.cc b/src/lib3270++/local/session.cc index c2c4e14..df3ad1b 100644 --- a/src/lib3270++/local/session.cc +++ b/src/lib3270++/local/session.cc @@ -344,24 +344,27 @@ /// @brief Set cursor address. /// /// @param addr Cursor address. - void Local::Session::setCursorPosition(unsigned short addr) { + TN3270::Session & Local::Session::setCursorPosition(unsigned short addr) { if(lib3270_set_cursor_address(hSession,addr) < 0) { throw std::system_error(errno, std::system_category()); } + return *this; } /// @brief Set cursor position. /// /// @param row New cursor row. /// @param col New cursor column. - void Local::Session::setCursorPosition(unsigned short row, unsigned short col) { + TN3270::Session & Local::Session::setCursorPosition(unsigned short row, unsigned short col) { if(lib3270_set_cursor_position(hSession,row,col)) { throw std::system_error(errno, std::system_category()); } + return *this; + } // Get properties. diff --git a/src/lib3270++/private.h b/src/lib3270++/private.h index c970893..69d87c5 100644 --- a/src/lib3270++/private.h +++ b/src/lib3270++/private.h @@ -192,8 +192,8 @@ ConnectionState getConnectionState() const override; - void setCursorPosition(unsigned short addr); - void setCursorPosition(unsigned short row, unsigned short col); + TN3270::Session & setCursorPosition(unsigned short addr) override; + TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) override; /// @brief Set field at current posicion, jumps to next writable field. TN3270::Session & push(const char *text) override; @@ -353,8 +353,8 @@ ConnectionState getConnectionState() const override; - void setCursorPosition(unsigned short addr); - void setCursorPosition(unsigned short row, unsigned short col); + TN3270::Session & setCursorPosition(unsigned short addr) override; + TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) override; /// @brief Set field at current posicion, jumps to next writable field. TN3270::Session & push(const char *text) override; -- libgit2 0.21.2