Commit 5e086dbaf749ce0140e4e036344657acf3e38380

Authored by Perry Werneck
1 parent 9b29e43a

Updating C++ API.

src/include/lib3270++.h
@@ -234,6 +234,12 @@ @@ -234,6 +234,12 @@
234 return push(text.c_str()); 234 return push(text.c_str());
235 } 235 }
236 236
  237 + /// @brief Set cursor address.
  238 + virtual void setCursorPosition(unsigned short addr) = 0;
  239 +
  240 + /// @brief Set cursor position.
  241 + virtual void setCursorPosition(unsigned short row, unsigned short col) = 0;
  242 +
237 virtual Session & push(int baddr, const std::string &text) = 0; 243 virtual Session & push(int baddr, const std::string &text) = 0;
238 virtual Session & push(int row, int col, const std::string &text) = 0; 244 virtual Session & push(int row, int col, const std::string &text) = 0;
239 virtual Session & push(const PFKey key) = 0; 245 virtual Session & push(const PFKey key) = 0;
@@ -311,6 +317,16 @@ @@ -311,6 +317,16 @@
311 return getConnectionState(); 317 return getConnectionState();
312 } 318 }
313 319
  320 + /// @brief Set cursor address.
  321 + inline void setCursorPosition(unsigned short addr) {
  322 + session->setCursorPosition(addr);
  323 + }
  324 +
  325 + /// @brief Set cursor position.
  326 + inline void setCursorPosition(unsigned short row, unsigned short col) {
  327 + session->setCursorPosition(row,col);
  328 + }
  329 +
314 // Set contents. 330 // Set contents.
315 331
316 /// @brief Set field at current posicion, jumps to next writable field. 332 /// @brief Set field at current posicion, jumps to next writable field.
src/lib3270++/local/session.cc
@@ -219,10 +219,14 @@ @@ -219,10 +219,14 @@
219 219
220 std::lock_guard<std::mutex> lock(sync); 220 std::lock_guard<std::mutex> lock(sync);
221 221
222 - char *contents = lib3270_get_field_at(hSession, baddr); 222 + if(!lib3270_is_connected(hSession)) {
  223 + throw std::system_error(ENOTCONN, std::system_category());
  224 + }
  225 +
  226 + char *contents = lib3270_get_field_text_at(hSession, baddr);
223 227
224 if(!contents) { 228 if(!contents) {
225 - throw std::runtime_error("Can't get field contents"); 229 + throw std::system_error(errno, std::system_category());
226 } 230 }
227 231
228 text.assign(convertFromHost(contents).c_str()); 232 text.assign(convertFromHost(contents).c_str());
@@ -240,15 +244,19 @@ @@ -240,15 +244,19 @@
240 244
241 std::lock_guard<std::mutex> lock(sync); 245 std::lock_guard<std::mutex> lock(sync);
242 246
  247 + if(!lib3270_is_connected(hSession)) {
  248 + throw std::system_error(ENOTCONN, std::system_category());
  249 + }
  250 +
243 int baddr = lib3270_get_cursor_address(hSession); 251 int baddr = lib3270_get_cursor_address(hSession);
244 if(baddr < 0) { 252 if(baddr < 0) {
245 throw std::system_error(errno, std::system_category()); 253 throw std::system_error(errno, std::system_category());
246 } 254 }
247 255
248 - char *contents = lib3270_get_field_at(hSession, baddr); 256 + char *contents = lib3270_get_field_text_at(hSession, baddr);
249 257
250 if(!contents) { 258 if(!contents) {
251 - throw std::runtime_error("Can't get field contents"); 259 + throw std::system_error(errno, std::system_category());
252 } 260 }
253 261
254 text.assign(convertFromHost(contents).c_str()); 262 text.assign(convertFromHost(contents).c_str());
@@ -265,6 +273,33 @@ @@ -265,6 +273,33 @@
265 return *this; 273 return *this;
266 } 274 }
267 275
  276 + /// @brief Set cursor address.
  277 + ///
  278 + /// @param addr Cursor address.
  279 + void Local::Session::setCursorPosition(unsigned short addr) {
  280 +
  281 + if(!lib3270_is_connected(hSession)) {
  282 + throw std::system_error(ENOTCONN, std::system_category());
  283 + }
  284 +
  285 + lib3270_set_cursor_address(hSession,baddr);
  286 +
  287 + }
  288 +
  289 + /// @brief Set cursor position.
  290 + ///
  291 + /// @param row New cursor row.
  292 + /// @param col New cursor column.
  293 + void Local::Session::setCursorPosition(unsigned short row, unsigned short col) {
  294 +
  295 + if(!lib3270_is_connected(hSession)) {
  296 + throw std::system_error(ENOTCONN, std::system_category());
  297 + }
  298 +
  299 + lib3270_set_cursor_position(hSession,row,col);
  300 + }
  301 +
  302 +
268 } 303 }
269 304
270 305
src/lib3270++/private.h
@@ -156,6 +156,9 @@ @@ -156,6 +156,9 @@
156 156
157 ConnectionState getConnectionState() const override; 157 ConnectionState getConnectionState() const override;
158 158
  159 + void setCursorPosition(unsigned short addr);
  160 + void setCursorPosition(unsigned short row, unsigned short col);
  161 +
159 /// @brief Set field at current posicion, jumps to next writable field. 162 /// @brief Set field at current posicion, jumps to next writable field.
160 TN3270::Session & push(const char *text) override; 163 TN3270::Session & push(const char *text) override;
161 164