Commit 9077bc4c71ca4e48408ea226500481b14ecf5a4e
1 parent
be11789b
Exists in
master
and in
1 other branch
Debugging action methods and properties.
Showing
11 changed files
with
102 additions
and
26 deletions
Show diff stats
client/src/core/session.cc
| @@ -378,11 +378,25 @@ | @@ -378,11 +378,25 @@ | ||
| 378 | return rc; | 378 | return rc; |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | - /// @brief Search | 381 | + /// @brief Checks if the terminal contains the string. |
| 382 | size_t Session::find(const char * str, size_t pos) const { | 382 | size_t Session::find(const char * str, size_t pos) const { |
| 383 | return toString((int) 0,(int) -1, '\0').find(str,pos); | 383 | return toString((int) 0,(int) -1, '\0').find(str,pos); |
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | + /// @brief Get the number of occurrences of a string in the terminal. | ||
| 387 | + size_t Session::count(const char * str, size_t pos) const { | ||
| 388 | + | ||
| 389 | + std::string contents = toString((int) 0,(int) -1, '\0'); | ||
| 390 | + size_t rc = 0; | ||
| 391 | + | ||
| 392 | + while( (pos = contents.find(str,pos)) != std::string::npos) { | ||
| 393 | + rc++; | ||
| 394 | + } | ||
| 395 | + | ||
| 396 | + return rc; | ||
| 397 | + | ||
| 398 | + } | ||
| 399 | + | ||
| 386 | /// @brief Compare contents. | 400 | /// @brief Compare contents. |
| 387 | int Session::compare(int baddr, const char* s, int len) const { | 401 | int Session::compare(int baddr, const char* s, int len) const { |
| 388 | 402 |
client/src/host/string.cc
| @@ -60,7 +60,7 @@ std::string TN3270::Host::toString(unsigned short row, unsigned short col, int l | @@ -60,7 +60,7 @@ std::string TN3270::Host::toString(unsigned short row, unsigned short col, int l | ||
| 60 | 60 | ||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | -/// @brief Search | 63 | +/// @brief Checks if the terminal contains the string. |
| 64 | size_t TN3270::Host::find(const char * str, size_t pos) const { | 64 | size_t TN3270::Host::find(const char * str, size_t pos) const { |
| 65 | 65 | ||
| 66 | this->session->waitForReady(this->timeout); | 66 | this->session->waitForReady(this->timeout); |
| @@ -68,6 +68,14 @@ size_t TN3270::Host::find(const char * str, size_t pos) const { | @@ -68,6 +68,14 @@ size_t TN3270::Host::find(const char * str, size_t pos) const { | ||
| 68 | 68 | ||
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | +/// @brief Get the number of occurrences of a string in the terminal. | ||
| 72 | +size_t TN3270::Host::count(const char * str, size_t pos) const { | ||
| 73 | + | ||
| 74 | + this->session->waitForReady(this->timeout); | ||
| 75 | + return this->session->count(str,pos); | ||
| 76 | + | ||
| 77 | +} | ||
| 78 | + | ||
| 71 | /// @brief Compare contents. | 79 | /// @brief Compare contents. |
| 72 | int TN3270::Host::compare(int baddr, const char* s, int len) const { | 80 | int TN3270::Host::compare(int baddr, const char* s, int len) const { |
| 73 | 81 |
client/src/include/lib3270/ipc.h
| @@ -585,9 +585,12 @@ | @@ -585,9 +585,12 @@ | ||
| 585 | /// @brief Create an action object | 585 | /// @brief Create an action object |
| 586 | virtual Action * getAction(const LIB3270_ACTION *descriptor); | 586 | virtual Action * getAction(const LIB3270_ACTION *descriptor); |
| 587 | 587 | ||
| 588 | - /// @brief Search | 588 | + /// @brief Checks if the terminal contains the string. |
| 589 | size_t find(const char * str, size_t pos = 0) const; | 589 | size_t find(const char * str, size_t pos = 0) const; |
| 590 | 590 | ||
| 591 | + /// @brief Get the number of occurrences of a string in the terminal. | ||
| 592 | + size_t count(const char * str, size_t pos = 0) const; | ||
| 593 | + | ||
| 591 | /// @brief Compare contents. | 594 | /// @brief Compare contents. |
| 592 | int compare(int baddr, const char* s, int len = -1) const; | 595 | int compare(int baddr, const char* s, int len = -1) const; |
| 593 | int compare(unsigned short row, unsigned short col, const char* s, int len = -1) const; | 596 | int compare(unsigned short row, unsigned short col, const char* s, int len = -1) const; |
| @@ -863,9 +866,12 @@ | @@ -863,9 +866,12 @@ | ||
| 863 | return session->wait(addr,text,timeout); | 866 | return session->wait(addr,text,timeout); |
| 864 | } | 867 | } |
| 865 | 868 | ||
| 866 | - /// @brief Search | 869 | + /// @brief Checks if the terminal contains the string. |
| 867 | size_t find(const char * str, size_t pos = 0) const; | 870 | size_t find(const char * str, size_t pos = 0) const; |
| 868 | 871 | ||
| 872 | + /// @brief Get the number of occurrences of a string in the terminal. | ||
| 873 | + size_t count(const char * str, size_t pos = 0) const; | ||
| 874 | + | ||
| 869 | /// @brief Compare contents. | 875 | /// @brief Compare contents. |
| 870 | int compare(int baddr, const char* s, int len = -1) const; | 876 | int compare(int baddr, const char* s, int len = -1) const; |
| 871 | int compare(unsigned short row, unsigned short col, const char* s, int len = -1) const; | 877 | int compare(unsigned short row, unsigned short col, const char* s, int len = -1) const; |
client/src/include/lib3270/ipc/action.h
| @@ -53,12 +53,12 @@ | @@ -53,12 +53,12 @@ | ||
| 53 | Action(const LIB3270_ACTION *descriptor); | 53 | Action(const LIB3270_ACTION *descriptor); |
| 54 | 54 | ||
| 55 | public: | 55 | public: |
| 56 | - virtual bool activatable() const noexcept = 0; | 56 | + virtual bool activatable() const = 0; |
| 57 | virtual void activate() = 0; | 57 | virtual void activate() = 0; |
| 58 | virtual void wait(time_t seconds = 0) = 0; | 58 | virtual void wait(time_t seconds = 0) = 0; |
| 59 | virtual ~Action(); | 59 | virtual ~Action(); |
| 60 | 60 | ||
| 61 | - inline operator bool() const noexcept { | 61 | + inline operator bool() const { |
| 62 | return activatable(); | 62 | return activatable(); |
| 63 | } | 63 | } |
| 64 | 64 |
client/src/session/remote/actions.cc
| @@ -47,6 +47,30 @@ | @@ -47,6 +47,30 @@ | ||
| 47 | 47 | ||
| 48 | namespace TN3270 { | 48 | namespace TN3270 { |
| 49 | 49 | ||
| 50 | + IPC::Action::Action(Session *session, const LIB3270_ACTION *descriptor) : TN3270::Action(descriptor) { | ||
| 51 | + this->session = session; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + bool IPC::Action::activatable() const { | ||
| 55 | + | ||
| 56 | + bool rc; | ||
| 57 | + | ||
| 58 | + Request(*session,"activatable") | ||
| 59 | + .push(descriptor->name) | ||
| 60 | + .call() | ||
| 61 | + .pop(rc); | ||
| 62 | + | ||
| 63 | + return rc; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + void IPC::Action::activate() { | ||
| 67 | + session->action(descriptor->name); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + void IPC::Action::wait(time_t seconds) { | ||
| 71 | + session->waitForReady(seconds); | ||
| 72 | + } | ||
| 73 | + | ||
| 50 | void IPC::Session::action(const char *action_name) { | 74 | void IPC::Session::action(const char *action_name) { |
| 51 | 75 | ||
| 52 | int32_t rc; | 76 | int32_t rc; |
client/src/session/remote/private.h
| @@ -42,6 +42,7 @@ | @@ -42,6 +42,7 @@ | ||
| 42 | 42 | ||
| 43 | #include <config.h> | 43 | #include <config.h> |
| 44 | #include <ipc-client-internals.h> | 44 | #include <ipc-client-internals.h> |
| 45 | + #include <lib3270/ipc/action.h> | ||
| 45 | #include <string> | 46 | #include <string> |
| 46 | #include <lib3270.h> | 47 | #include <lib3270.h> |
| 47 | #include <stdexcept> | 48 | #include <stdexcept> |
| @@ -53,6 +54,20 @@ | @@ -53,6 +54,20 @@ | ||
| 53 | 54 | ||
| 54 | namespace IPC { | 55 | namespace IPC { |
| 55 | 56 | ||
| 57 | + class Session; | ||
| 58 | + | ||
| 59 | + class Action : public TN3270::Action { | ||
| 60 | + private: | ||
| 61 | + Session *session; | ||
| 62 | + | ||
| 63 | + public: | ||
| 64 | + Action(Session *session, const LIB3270_ACTION *descriptor); | ||
| 65 | + bool activatable() const override; | ||
| 66 | + void activate() override; | ||
| 67 | + void wait(time_t seconds) override; | ||
| 68 | + | ||
| 69 | + }; | ||
| 70 | + | ||
| 56 | class TN3270_PRIVATE Session : public TN3270::Abstract::Session { | 71 | class TN3270_PRIVATE Session : public TN3270::Abstract::Session { |
| 57 | private: | 72 | private: |
| 58 | 73 |
server/src/core/getproperties.c
| @@ -65,7 +65,7 @@ GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GEr | @@ -65,7 +65,7 @@ GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GEr | ||
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | // Erro! | 67 | // Erro! |
| 68 | - ipc3270_set_error(object,ENOENT,error); | 68 | + ipc3270_set_error(object,errno,error); |
| 69 | return NULL; | 69 | return NULL; |
| 70 | 70 | ||
| 71 | } | 71 | } |
server/src/core/linux/gobject.c
| @@ -112,6 +112,10 @@ void ipc3270_add_terminal_introspection(GString *introspection) { | @@ -112,6 +112,10 @@ void ipc3270_add_terminal_introspection(GString *introspection) { | ||
| 112 | " <arg type='s' name='name' direction='in' />" \ | 112 | " <arg type='s' name='name' direction='in' />" \ |
| 113 | " <arg type='i' name='result' direction='out' />" \ | 113 | " <arg type='i' name='result' direction='out' />" \ |
| 114 | " </method>" | 114 | " </method>" |
| 115 | + " <method name='activatable'>" | ||
| 116 | + " <arg type='s' name='name' direction='in' />" \ | ||
| 117 | + " <arg type='b' name='result' direction='out' />" \ | ||
| 118 | + " </method>" | ||
| 115 | " <method name='pfkey'>" \ | 119 | " <method name='pfkey'>" \ |
| 116 | " <arg type='i' name='keycode' direction='in'/>" \ | 120 | " <arg type='i' name='keycode' direction='in'/>" \ |
| 117 | " <arg type='i' name='result' direction='out' />" \ | 121 | " <arg type='i' name='result' direction='out' />" \ |
server/src/core/methods/action.c
| @@ -46,3 +46,24 @@ int ipc3270_method_action(GObject *session, GVariant *request, GObject *response | @@ -46,3 +46,24 @@ int ipc3270_method_action(GObject *session, GVariant *request, GObject *response | ||
| 46 | return 0; | 46 | return 0; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | +int ipc3270_method_activatable(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) { | ||
| 50 | + | ||
| 51 | + if(g_variant_n_children(request) != 1) { | ||
| 52 | + g_message("activatable was called with %u arguments.",(unsigned int) g_variant_n_children(request)); | ||
| 53 | + ipc3270_response_append_int32(response, EINVAL); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + GVariant *value = g_variant_get_child_value(request,0); | ||
| 57 | + | ||
| 58 | + LIB3270_ACTION * action = lib3270_action_get_by_name(g_variant_get_string(value,NULL)); | ||
| 59 | + | ||
| 60 | + if(action) { | ||
| 61 | + ipc3270_response_append_int32(response, lib3270_action_is_activatable(action, ipc3270_get_session(session))); | ||
| 62 | + } else { | ||
| 63 | + ipc3270_response_append_int32(response, ENOENT); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + g_variant_unref(value); | ||
| 67 | + | ||
| 68 | + return 0; | ||
| 69 | +} |
server/src/core/methods/methods.c
| @@ -72,6 +72,7 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req | @@ -72,6 +72,7 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req | ||
| 72 | { "setCursorPosition", ipc3270_method_set_cursor }, | 72 | { "setCursorPosition", ipc3270_method_set_cursor }, |
| 73 | 73 | ||
| 74 | { "action", ipc3270_method_action }, | 74 | { "action", ipc3270_method_action }, |
| 75 | + { "activatable", ipc3270_method_activatable }, | ||
| 75 | 76 | ||
| 76 | }; | 77 | }; |
| 77 | 78 | ||
| @@ -98,31 +99,13 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req | @@ -98,31 +99,13 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req | ||
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | // Check actions table. | 101 | // Check actions table. |
| 101 | - const LIB3270_ACTION * action = lib3270_get_action(method_name); | 102 | + const LIB3270_ACTION * action = lib3270_action_get_by_name(method_name); |
| 102 | if(action) { | 103 | if(action) { |
| 103 | if(lib3270_action_activate(action,hSession)) { | 104 | if(lib3270_action_activate(action,hSession)) { |
| 104 | ipc3270_set_error(object,errno,error); | 105 | ipc3270_set_error(object,errno,error); |
| 105 | } | 106 | } |
| 106 | return 0; | 107 | return 0; |
| 107 | } | 108 | } |
| 108 | - /* | ||
| 109 | - const LIB3270_ACTION * actions = lib3270_get_actions(); | ||
| 110 | - for(ix = 0; actions[ix].name; ix++) { | ||
| 111 | - | ||
| 112 | - if(!g_ascii_strcasecmp(actions[ix].name,method_name)) { | ||
| 113 | - | ||
| 114 | - if(!actions[ix].enabled(hSession)) | ||
| 115 | - ipc3270_set_error(object,EPERM,error); | ||
| 116 | - else if(actions[ix].activate(hSession)) | ||
| 117 | - ipc3270_set_error(object,errno,error); | ||
| 118 | - else | ||
| 119 | - ipc3270_response_append_int32(response, 0); | ||
| 120 | - | ||
| 121 | - return 0; | ||
| 122 | - | ||
| 123 | - } | ||
| 124 | - } | ||
| 125 | - */ | ||
| 126 | 109 | ||
| 127 | // Check lib3270 internal methods | 110 | // Check lib3270 internal methods |
| 128 | const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods(); | 111 | const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods(); |
server/src/core/methods/private.h
| @@ -58,6 +58,7 @@ | @@ -58,6 +58,7 @@ | ||
| 58 | G_GNUC_INTERNAL int ipc3270_method_set_cursor(GObject *session, GVariant *request, GObject *response, GError **error); | 58 | G_GNUC_INTERNAL int ipc3270_method_set_cursor(GObject *session, GVariant *request, GObject *response, GError **error); |
| 59 | 59 | ||
| 60 | G_GNUC_INTERNAL int ipc3270_method_action(GObject *session, GVariant *request, GObject *response, GError **error); | 60 | G_GNUC_INTERNAL int ipc3270_method_action(GObject *session, GVariant *request, GObject *response, GError **error); |
| 61 | + G_GNUC_INTERNAL int ipc3270_method_activatable(GObject *session, GVariant *request, GObject *response, GError **error); | ||
| 61 | 62 | ||
| 62 | G_GNUC_INTERNAL int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError **error); | 63 | G_GNUC_INTERNAL int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError **error); |
| 63 | 64 |