From 0c34cb90e640fce46f745a663eaa199eb81a0b0c Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 19 Feb 2019 14:41:50 -0300 Subject: [PATCH] Implementing IPC calls. --- ipc/session.cc | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- local/session.cc | 7 +++++-- private.h | 8 ++++---- 3 files changed, 135 insertions(+), 9 deletions(-) diff --git a/ipc/session.cc b/ipc/session.cc index 9dbef59..1b74f11 100644 --- a/ipc/session.cc +++ b/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/local/session.cc b/local/session.cc index c2c4e14..df3ad1b 100644 --- a/local/session.cc +++ b/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/private.h b/private.h index c970893..69d87c5 100644 --- a/private.h +++ b/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