Commit 9192562c738d09dd91b26296dc72aea360d2b667

Authored by Perry Werneck
1 parent 6e995388
Exists in master and in 1 other branch develop

Adding IPC method to wait for connection state.

client/src/include/lib3270/ipc.h
... ... @@ -600,6 +600,9 @@
600 600 /// @brief Wait until session state changes to "ready".
601 601 virtual void waitForReady(time_t timeout = DEFAULT_TIMEOUT) const = 0;
602 602  
  603 + /// @brief Wait for connection state.
  604 + virtual void waitForConnectionState(ConnectionState state, time_t timeout = DEFAULT_TIMEOUT) const = 0;
  605 +
603 606 /// @brief Wait for screen changes.
604 607 virtual void waitForChange(time_t seconds = DEFAULT_TIMEOUT) const = 0;
605 608  
... ... @@ -663,17 +666,6 @@
663 666 /// @brief Writes characters to the associated output sequence from the put area.
664 667 int overflow(int c) override;
665 668  
666   - /*
667   - /// @brief Write information to log file.
668   - void info(const char *fmt, ...) const;
669   -
670   - /// @brief Write warning to log file.
671   - void warning(const char *fmt, ...) const;
672   -
673   - /// @brief Write error to log file.
674   - void error(const char *fmt, ...) const;
675   - */
676   -
677 669 public:
678 670 Host(const char *id, const char *charset = nullptr);
679 671  
... ... @@ -733,6 +725,15 @@
733 725 return this->session->waitForKeyboardUnlock(timeout);
734 726 }
735 727  
  728 + /// @brief Wait for connection state.
  729 + inline void waitForConnectionState(ConnectionState state, time_t timeout = DEFAULT_TIMEOUT) {
  730 + return this->session->waitForConnectionState(state,timeout);
  731 + }
  732 +
  733 + inline void wait(ConnectionState state, time_t timeout = DEFAULT_TIMEOUT) {
  734 + return this->session->waitForConnectionState(state,timeout);
  735 + }
  736 +
736 737 /// @brief Execute action by name.
737 738 inline Host & action(const char *action_name) {
738 739 session->action(action_name);
... ...
client/src/session/local/private.h
... ... @@ -122,6 +122,7 @@
122 122  
123 123 void wait(time_t seconds) const override;
124 124 void waitForReady(time_t timeout) const override;
  125 + void waitForConnectionState(ConnectionState state, time_t timeout) const override;
125 126 void waitForChange(time_t timeout) const override;
126 127  
127 128 LIB3270_KEYBOARD_LOCK_STATE waitForKeyboardUnlock(time_t seconds) const override;
... ...
client/src/session/local/wait.cc
... ... @@ -56,6 +56,12 @@
56 56 chkResponse(lib3270_wait_for_ready(this->hSession, timeout));
57 57 }
58 58  
  59 + void Local::Session::waitForConnectionState(ConnectionState state, time_t timeout) const {
  60 +
  61 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  62 + chkResponse(lib3270_wait_for_cstate(this->hSession, (LIB3270_CSTATE) state, timeout));
  63 + }
  64 +
59 65 LIB3270_KEYBOARD_LOCK_STATE Local::Session::waitForKeyboardUnlock(time_t timeout) const {
60 66  
61 67 std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
... ...
client/src/session/remote/private.h
... ... @@ -121,6 +121,7 @@
121 121  
122 122 void wait(time_t seconds) const override;
123 123 void waitForReady(time_t timeout) const override;
  124 + void waitForConnectionState(ConnectionState state, time_t timeout) const override;
124 125 void waitForChange(time_t timeout) const override;
125 126  
126 127 LIB3270_KEYBOARD_LOCK_STATE waitForKeyboardUnlock(time_t seconds) const override;
... ...
client/src/session/remote/wait.cc
... ... @@ -113,6 +113,30 @@
113 113  
114 114 }
115 115  
  116 + void IPC::Session::waitForConnectionState(ConnectionState state, time_t timeout) const {
  117 +
  118 + debug(__FUNCTION__,"(",timeout,")");
  119 +
  120 + wait(timeout, [this,state]() {
  121 +
  122 + int rc;
  123 +
  124 + debug("Running waitForConnectionState request...");
  125 +
  126 + Request(*this,"waitForConnectionState")
  127 + .push((uint32_t) state)
  128 + .push((uint32_t) 1)
  129 + .call()
  130 + .pop(rc);
  131 +
  132 + debug("Wait for connection state returned ",rc);
  133 +
  134 + return rc;
  135 +
  136 + });
  137 +
  138 + }
  139 +
116 140 LIB3270_KEYBOARD_LOCK_STATE IPC::Session::waitForKeyboardUnlock(time_t timeout) const {
117 141  
118 142 int rc;
... ...
client/src/testprogram/testprogram.cc
... ... @@ -171,6 +171,7 @@
171 171 TN3270::Host host{session};
172 172  
173 173 host.connect();
  174 + host.wait(TN3270::CONNECTED_TN3270E);
174 175  
175 176 {
176 177 auto start = time(nullptr);
... ...
server/src/core/linux/gobject.c
... ... @@ -171,6 +171,11 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
171 171 " <arg type='u' name='seconds' direction='in' />" \
172 172 " <arg type='i' name='result' direction='out' />" \
173 173 " </method>" \
  174 + " <method name= 'waitForConnectionState'>" \
  175 + " <arg type='u' name='cstate' direction='in' />" \
  176 + " <arg type='u' name='seconds' direction='in' />" \
  177 + " <arg type='i' name='result' direction='out' />" \
  178 + " </method>" \
174 179 " <method name= 'waitForKeyboardUnlock'>" \
175 180 " <arg type='u' name='seconds' direction='in' />" \
176 181 " <arg type='i' name='result' direction='out' />" \
... ...
server/src/core/methods/methods.c
... ... @@ -48,6 +48,7 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req
48 48  
49 49 { "wait", ipc3270_method_wait },
50 50 { "waitforready", ipc3270_method_wait_for_ready },
  51 + { "waitForConnectionState", ipc3270_method_wait_for_cstate },
51 52 { "waitforupdate", ipc3270_method_wait_for_update },
52 53 { "waitforkeyboardunlock", ipc3270_method_wait_for_keyboard_unlock },
53 54  
... ...
server/src/core/methods/private.h
... ... @@ -52,6 +52,7 @@
52 52  
53 53 G_GNUC_INTERNAL int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response, GError **error);
54 54 G_GNUC_INTERNAL int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *response, GError **error);
  55 + G_GNUC_INTERNAL int ipc3270_method_wait_for_cstate(GObject *session, GVariant *request, GObject *response, GError **error);
55 56 G_GNUC_INTERNAL int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject *response, GError **error);
56 57 G_GNUC_INTERNAL int ipc3270_method_wait_for_keyboard_unlock(GObject *session, GVariant *request, GObject *response, GError **error);
57 58  
... ...
server/src/core/methods/wait.c
... ... @@ -116,6 +116,14 @@ int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *
116 116 return 0;
117 117 }
118 118  
  119 +int ipc3270_method_wait_for_cstate(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) {
  120 + guint seconds = 1;
  121 + guint cstate = 0;
  122 + g_variant_get(request, "(uu)", &seconds);
  123 + ipc3270_response_append_int32(response,lib3270_wait_for_cstate(ipc3270_get_session(session),(LIB3270_CSTATE) cstate, seconds));
  124 + return 0;
  125 +}
  126 +
119 127 int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) {
120 128 guint seconds = 1;
121 129 g_variant_get(request, "(u)", &seconds);
... ...