Commit dd4059a1b55e7bfbc563dc30906e196d69898c80
1 parent
d1524662
Exists in
master
and in
1 other branch
Updating IPC module.
Showing
6 changed files
with
120 additions
and
39 deletions
Show diff stats
client/src/core/constants.cc
@@ -80,6 +80,54 @@ TN3270_PUBLIC const char * toCharString(const TN3270::Action action) { | @@ -80,6 +80,54 @@ TN3270_PUBLIC const char * toCharString(const TN3270::Action action) { | ||
80 | return actions[action]; | 80 | return actions[action]; |
81 | } | 81 | } |
82 | 82 | ||
83 | +TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMessage) { | ||
84 | + | ||
85 | + static const char *messages[] = { | ||
86 | + "", | ||
87 | + "X System", | ||
88 | + "X Wait", | ||
89 | + "Connected" | ||
90 | + "X Not Connected", | ||
91 | + "Awaiting first", | ||
92 | + "X -f", | ||
93 | + "X Protected", | ||
94 | + "X Numeric", | ||
95 | + "X Overflow", | ||
96 | + "X Inhibit", | ||
97 | + "KybdLock", | ||
98 | + "X", | ||
99 | + "X Resolving", | ||
100 | + "X Connecting", | ||
101 | + }; | ||
102 | + | ||
103 | + if( ((size_t) programMessage) > (sizeof(messages)/sizeof(messages[0]))) { | ||
104 | + throw std::system_error(EINVAL, std::system_category()); | ||
105 | + } | ||
106 | + | ||
107 | + return messages[programMessage]; | ||
108 | +} | ||
109 | + | ||
110 | +TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState) { | ||
111 | + | ||
112 | + static const char *states[] = { | ||
113 | + "Disconnected", | ||
114 | + "Resolving hostname", | ||
115 | + "Pending", | ||
116 | + "Connected, no mode yet", | ||
117 | + "Connected in NVT ANSI mode", | ||
118 | + "Connected in old-style 3270 mode", | ||
119 | + "Connected in TN3270E mode, unnegotiated", | ||
120 | + "Connected in TN3270E mode, NVT mode", | ||
121 | + "Connected in TN3270E mode, SSCP-LU mode", | ||
122 | + "Connected in TN3270E mode, 3270 mode", | ||
123 | + }; | ||
124 | + | ||
125 | + if( ((size_t) connectionState) > (sizeof(states)/sizeof(states[0]))) { | ||
126 | + throw std::system_error(EINVAL, std::system_category()); | ||
127 | + } | ||
128 | + | ||
129 | + return states[connectionState]; | ||
130 | +} | ||
83 | 131 | ||
84 | 132 | ||
85 | 133 |
client/src/include/ipc-client-internals.h
@@ -186,6 +186,7 @@ | @@ -186,6 +186,7 @@ | ||
186 | 186 | ||
187 | std::string getVersion() const override; | 187 | std::string getVersion() const override; |
188 | std::string getRevision() const override; | 188 | std::string getRevision() const override; |
189 | + std::string getLUName() const override; | ||
189 | 190 | ||
190 | // Gets | 191 | // Gets |
191 | std::string toString(int baddr, size_t len, char lf) const override; | 192 | std::string toString(int baddr, size_t len, char lf) const override; |
@@ -195,9 +196,9 @@ | @@ -195,9 +196,9 @@ | ||
195 | 196 | ||
196 | ConnectionState getConnectionState() const override; | 197 | ConnectionState getConnectionState() const override; |
197 | 198 | ||
198 | - TN3270::Session & setCursorPosition(unsigned short addr) override; | ||
199 | - TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) override; | ||
200 | - unsigned short getCursorPosition() override; | 199 | + TN3270::Session & setCursor(unsigned short addr) override; |
200 | + TN3270::Session & setCursor(unsigned short row, unsigned short col) override; | ||
201 | + unsigned short getCursorAddress() override; | ||
201 | 202 | ||
202 | TN3270::Session & pfkey(unsigned short value); | 203 | TN3270::Session & pfkey(unsigned short value); |
203 | TN3270::Session & pakey(unsigned short value); | 204 | TN3270::Session & pakey(unsigned short value); |
@@ -361,8 +362,10 @@ | @@ -361,8 +362,10 @@ | ||
361 | 362 | ||
362 | std::string getVersion() const override; | 363 | std::string getVersion() const override; |
363 | std::string getRevision() const override; | 364 | std::string getRevision() const override; |
365 | + std::string getLUName() const override; | ||
364 | 366 | ||
365 | // Set properties. | 367 | // Set properties. |
368 | + void setProperty(const char *name, const int value) const; | ||
366 | void setUnlockDelay(unsigned short delay = 350) override; | 369 | void setUnlockDelay(unsigned short delay = 350) override; |
367 | 370 | ||
368 | // Gets | 371 | // Gets |
@@ -373,9 +376,9 @@ | @@ -373,9 +376,9 @@ | ||
373 | 376 | ||
374 | ConnectionState getConnectionState() const override; | 377 | ConnectionState getConnectionState() const override; |
375 | 378 | ||
376 | - TN3270::Session & setCursorPosition(unsigned short addr) override; | ||
377 | - TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) override; | ||
378 | - unsigned short getCursorPosition() override; | 379 | + TN3270::Session & setCursor(unsigned short addr) override; |
380 | + TN3270::Session & setCursor(unsigned short row, unsigned short col) override; | ||
381 | + unsigned short getCursorAddress() override; | ||
379 | 382 | ||
380 | TN3270::Session & pfkey(unsigned short value); | 383 | TN3270::Session & pfkey(unsigned short value); |
381 | TN3270::Session & pakey(unsigned short value); | 384 | TN3270::Session & pakey(unsigned short value); |
client/src/session/local/session.cc
@@ -413,7 +413,7 @@ | @@ -413,7 +413,7 @@ | ||
413 | /// @brief Set cursor address. | 413 | /// @brief Set cursor address. |
414 | /// | 414 | /// |
415 | /// @param addr Cursor address. | 415 | /// @param addr Cursor address. |
416 | - TN3270::Session & Local::Session::setCursorPosition(unsigned short addr) { | 416 | + TN3270::Session & Local::Session::setCursor(unsigned short addr) { |
417 | 417 | ||
418 | if(lib3270_set_cursor_address(hSession,addr) < 0) { | 418 | if(lib3270_set_cursor_address(hSession,addr) < 0) { |
419 | throw std::system_error(errno, std::system_category()); | 419 | throw std::system_error(errno, std::system_category()); |
@@ -425,7 +425,7 @@ | @@ -425,7 +425,7 @@ | ||
425 | /// @brief Get cursor address. | 425 | /// @brief Get cursor address. |
426 | /// | 426 | /// |
427 | /// @return | 427 | /// @return |
428 | - unsigned short Local::Session::getCursorPosition() { | 428 | + unsigned short Local::Session::getCursorAddress() { |
429 | 429 | ||
430 | unsigned int position = lib3270_get_cursor_address(hSession); | 430 | unsigned int position = lib3270_get_cursor_address(hSession); |
431 | 431 | ||
@@ -440,7 +440,7 @@ | @@ -440,7 +440,7 @@ | ||
440 | /// | 440 | /// |
441 | /// @param row New cursor row. | 441 | /// @param row New cursor row. |
442 | /// @param col New cursor column. | 442 | /// @param col New cursor column. |
443 | - TN3270::Session & Local::Session::setCursorPosition(unsigned short row, unsigned short col) { | 443 | + TN3270::Session & Local::Session::setCursor(unsigned short row, unsigned short col) { |
444 | 444 | ||
445 | if(lib3270_set_cursor_position(hSession,row,col)) { | 445 | if(lib3270_set_cursor_position(hSession,row,col)) { |
446 | throw std::system_error(errno, std::system_category()); | 446 | throw std::system_error(errno, std::system_category()); |
@@ -459,6 +459,13 @@ | @@ -459,6 +459,13 @@ | ||
459 | return lib3270_get_revision(); | 459 | return lib3270_get_revision(); |
460 | } | 460 | } |
461 | 461 | ||
462 | + std::string Local::Session::getLUName() const { | ||
463 | + const char * luname = lib3270_get_luname(hSession); | ||
464 | + if(luname) | ||
465 | + return luname; | ||
466 | + return ""; | ||
467 | + } | ||
468 | + | ||
462 | /// @brief Execute action by name. | 469 | /// @brief Execute action by name. |
463 | TN3270::Session & Local::Session::action(const char *action_name) { | 470 | TN3270::Session & Local::Session::action(const char *action_name) { |
464 | 471 |
client/src/session/remote/session.cc
@@ -266,27 +266,18 @@ | @@ -266,27 +266,18 @@ | ||
266 | /// @brief Set cursor address. | 266 | /// @brief Set cursor address. |
267 | /// | 267 | /// |
268 | /// @param addr Cursor address. | 268 | /// @param addr Cursor address. |
269 | - TN3270::Session & IPC::Session::setCursorPosition(unsigned short addr) { | ||
270 | - | ||
271 | - int32_t rc; | ||
272 | - | ||
273 | - Request(*this,"setCursorAddress") | ||
274 | - .push((uint32_t) addr) | ||
275 | - .call() | ||
276 | - .pop(rc); | ||
277 | - | ||
278 | - if(rc) { | ||
279 | - throw std::system_error((int) rc, std::system_category()); | ||
280 | - } | 269 | + TN3270::Session & IPC::Session::setCursor(unsigned short addr) { |
281 | 270 | ||
271 | + setProperty("setCursorAddress", (uint32_t) addr); | ||
282 | return *this; | 272 | return *this; |
283 | 273 | ||
284 | } | 274 | } |
285 | 275 | ||
286 | - unsigned short IPC::Session::getCursorPosition() { | 276 | + unsigned short IPC::Session::getCursorAddress() { |
287 | 277 | ||
288 | - // TODO: Implement it. | ||
289 | - throw std::system_error((int) ENOTSUP, std::system_category()); | 278 | + int32_t address; |
279 | + getProperty("cursor_address",address); | ||
280 | + return (unsigned short) address; | ||
290 | 281 | ||
291 | } | 282 | } |
292 | 283 | ||
@@ -294,7 +285,7 @@ | @@ -294,7 +285,7 @@ | ||
294 | /// | 285 | /// |
295 | /// @param row New cursor row. | 286 | /// @param row New cursor row. |
296 | /// @param col New cursor column. | 287 | /// @param col New cursor column. |
297 | - TN3270::Session & IPC::Session::setCursorPosition(unsigned short row, unsigned short col) { | 288 | + TN3270::Session & IPC::Session::setCursor(unsigned short row, unsigned short col) { |
298 | 289 | ||
299 | int32_t rc; | 290 | int32_t rc; |
300 | 291 | ||
@@ -320,6 +311,21 @@ | @@ -320,6 +311,21 @@ | ||
320 | 311 | ||
321 | } | 312 | } |
322 | 313 | ||
314 | + void IPC::Session::setProperty(const char *name, const int value) const { | ||
315 | + | ||
316 | + int32_t rc; | ||
317 | + | ||
318 | + Request(*this,true,name) | ||
319 | + .push(value) | ||
320 | + .call() | ||
321 | + .pop(rc); | ||
322 | + | ||
323 | + if(rc) { | ||
324 | + throw std::system_error((int) rc, std::system_category()); | ||
325 | + } | ||
326 | + | ||
327 | + } | ||
328 | + | ||
323 | void IPC::Session::getProperty(const char *name, std::string &value) const { | 329 | void IPC::Session::getProperty(const char *name, std::string &value) const { |
324 | 330 | ||
325 | Request(*this,false,name) | 331 | Request(*this,false,name) |
@@ -350,6 +356,14 @@ | @@ -350,6 +356,14 @@ | ||
350 | 356 | ||
351 | } | 357 | } |
352 | 358 | ||
359 | + std::string IPC::Session::getLUName() const { | ||
360 | + | ||
361 | + string rc; | ||
362 | + getProperty("luname",rc); | ||
363 | + return rc; | ||
364 | + | ||
365 | + } | ||
366 | + | ||
353 | /// @brief Execute action by name. | 367 | /// @brief Execute action by name. |
354 | TN3270::Session & IPC::Session::action(const char *action_name) { | 368 | TN3270::Session & IPC::Session::action(const char *action_name) { |
355 | 369 | ||
@@ -381,6 +395,8 @@ | @@ -381,6 +395,8 @@ | ||
381 | 395 | ||
382 | void IPC::Session::setUnlockDelay(unsigned short delay) { | 396 | void IPC::Session::setUnlockDelay(unsigned short delay) { |
383 | 397 | ||
398 | + setProperty("unlock_delay", (uint32_t) delay); | ||
399 | + | ||
384 | } | 400 | } |
385 | 401 | ||
386 | } | 402 | } |
client/src/testprogram/testprogram.cc
@@ -46,7 +46,7 @@ | @@ -46,7 +46,7 @@ | ||
46 | 46 | ||
47 | int main(int argc, char **argv) { | 47 | int main(int argc, char **argv) { |
48 | 48 | ||
49 | - const char * session = ""; // "pw3270:a"; | 49 | + const char * session = "pw3270:a"; |
50 | 50 | ||
51 | #pragma GCC diagnostic push | 51 | #pragma GCC diagnostic push |
52 | #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" | 52 | #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" |
@@ -82,8 +82,9 @@ | @@ -82,8 +82,9 @@ | ||
82 | << std::endl; | 82 | << std::endl; |
83 | 83 | ||
84 | cout | 84 | cout |
85 | - << "Connection state is " << host.getConnectionState() | ||
86 | - << "\tProgram message is " << host.getProgramMessage() | 85 | + << "Connection state is " << toCharString(host.getConnectionState()) << std::endl |
86 | + << "Program message is " << toCharString(host.getProgramMessage()) << std::endl | ||
87 | + << "Luname is " << host.getLUName() << std::endl | ||
87 | << std::endl; | 88 | << std::endl; |
88 | 89 | ||
89 | 90 |
common/src/include/lib3270/ipc.h
@@ -253,6 +253,7 @@ | @@ -253,6 +253,7 @@ | ||
253 | 253 | ||
254 | virtual std::string getVersion() const = 0; | 254 | virtual std::string getVersion() const = 0; |
255 | virtual std::string getRevision() const = 0; | 255 | virtual std::string getRevision() const = 0; |
256 | + virtual std::string getLUName() const = 0; | ||
256 | 257 | ||
257 | virtual ProgramMessage getProgramMessage() const = 0; | 258 | virtual ProgramMessage getProgramMessage() const = 0; |
258 | inline operator ProgramMessage() const { | 259 | inline operator ProgramMessage() const { |
@@ -284,13 +285,13 @@ | @@ -284,13 +285,13 @@ | ||
284 | virtual Session & input(const char *text, size_t length) = 0; | 285 | virtual Session & input(const char *text, size_t length) = 0; |
285 | 286 | ||
286 | /// @brief Set cursor address. | 287 | /// @brief Set cursor address. |
287 | - virtual TN3270::Session & setCursorPosition(unsigned short addr) = 0; | 288 | + virtual TN3270::Session & setCursor(unsigned short addr) = 0; |
288 | 289 | ||
289 | /// @brief Set cursor position. | 290 | /// @brief Set cursor position. |
290 | - virtual TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) = 0; | 291 | + virtual TN3270::Session & setCursor(unsigned short row, unsigned short col) = 0; |
291 | 292 | ||
292 | /// @brief Get cursor address | 293 | /// @brief Get cursor address |
293 | - virtual unsigned short getCursorPosition() = 0; | 294 | + virtual unsigned short getCursorAddress() = 0; |
294 | 295 | ||
295 | /// @brief Send PF. | 296 | /// @brief Send PF. |
296 | virtual Session & pfkey(unsigned short value) = 0; | 297 | virtual Session & pfkey(unsigned short value) = 0; |
@@ -400,18 +401,18 @@ | @@ -400,18 +401,18 @@ | ||
400 | } | 401 | } |
401 | 402 | ||
402 | /// @brief Set cursor address. | 403 | /// @brief Set cursor address. |
403 | - inline void setCursorPosition(unsigned short addr) { | ||
404 | - session->setCursorPosition(addr); | 404 | + inline void setCursor(unsigned short addr) { |
405 | + session->setCursor(addr); | ||
405 | } | 406 | } |
406 | 407 | ||
407 | /// @brief Set cursor position. | 408 | /// @brief Set cursor position. |
408 | - inline void setCursorPosition(unsigned short row, unsigned short col) { | ||
409 | - session->setCursorPosition(row,col); | 409 | + inline void setCursor(unsigned short row, unsigned short col) { |
410 | + session->setCursor(row,col); | ||
410 | } | 411 | } |
411 | 412 | ||
412 | /// @brief Get cursor address | 413 | /// @brief Get cursor address |
413 | - inline unsigned short getCursorPosition() { | ||
414 | - return session->getCursorPosition(); | 414 | + inline unsigned short getCursorAddress() { |
415 | + return session->getCursorAddress(); | ||
415 | } | 416 | } |
416 | 417 | ||
417 | // Get properties | 418 | // Get properties |
@@ -426,6 +427,11 @@ | @@ -426,6 +427,11 @@ | ||
426 | return session->getRevision(); | 427 | return session->getRevision(); |
427 | } | 428 | } |
428 | 429 | ||
430 | + /// @brief Get LU Name. | ||
431 | + std::string getLUName() const { | ||
432 | + return session->getLUName(); | ||
433 | + } | ||
434 | + | ||
429 | // Actions | 435 | // Actions |
430 | 436 | ||
431 | /// @brief Send PF. | 437 | /// @brief Send PF. |
@@ -515,8 +521,8 @@ | @@ -515,8 +521,8 @@ | ||
515 | 521 | ||
516 | } | 522 | } |
517 | 523 | ||
518 | - TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMessage) noexcept; | ||
519 | - TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState) noexcept; | 524 | + TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMessage); |
525 | + TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState); | ||
520 | TN3270_PUBLIC const char * toCharString(const TN3270::Action action); | 526 | TN3270_PUBLIC const char * toCharString(const TN3270::Action action); |
521 | 527 | ||
522 | template <typename T> | 528 | template <typename T> |