Commit 0d3245a825a4d2144893e369ee0c977da74011e5

Authored by Perry Werneck
1 parent 828f2c8c
Exists in master and in 1 other branch develop

Adding action object required for the python extension.

client/ipcclient.cbp
... ... @@ -68,6 +68,7 @@
68 68 <Unit filename="src/host/string.cc" />
69 69 <Unit filename="src/include/ipc-client-internals.h" />
70 70 <Unit filename="src/include/lib3270/ipc.h" />
  71 + <Unit filename="src/include/lib3270/ipc/action.h" />
71 72 <Unit filename="src/include/lib3270/ipc/request.h" />
72 73 <Unit filename="src/session/get.cc" />
73 74 <Unit filename="src/session/local/actions.cc" />
... ...
client/src/core/constants.cc
... ... @@ -50,7 +50,7 @@ TN3270_PUBLIC const char * getRevision() {
50 50 return LIB3270_STRINGIZE_VALUE_OF(PACKAGE_RELEASE);
51 51 }
52 52  
53   -TN3270_PUBLIC const char * toCharString(const TN3270::Action action) {
  53 +TN3270_PUBLIC const char * toCharString(const TN3270::KeyboardAction action) {
54 54  
55 55 static const char * actions[] = {
56 56 "enter",
... ...
client/src/core/session.cc
... ... @@ -439,6 +439,11 @@
439 439 value = getAttribute(name).getBoolean();
440 440 }
441 441  
  442 + /// @brief Create an action object
  443 + Action * Session::getAction(const LIB3270_ACTION *descriptor) {
  444 + throw std::system_error(ENOTSUP, std::system_category());
  445 + }
  446 +
442 447  
443 448 }
444 449  
... ...
client/src/include/lib3270/ipc.h
... ... @@ -68,6 +68,7 @@
68 68  
69 69 class Host;
70 70 class Controller;
  71 + class Action;
71 72  
72 73 #define DEFAULT_TIMEOUT 5
73 74  
... ... @@ -222,8 +223,8 @@
222 223 PA_3
223 224 };
224 225  
225   - /// @brief LIB3270 Action.
226   - enum Action : uint8_t {
  226 + /// @brief Keyboard Actions.
  227 + enum KeyboardAction : uint8_t {
227 228 ENTER, ///< @brief Enter key
228 229 ERASE,
229 230 ERASE_EOF,
... ... @@ -436,7 +437,7 @@
436 437  
437 438 void push(const PFKey key);
438 439 void push(const PAKey key);
439   - virtual void push(const Action action) = 0;
  440 + virtual void push(const KeyboardAction action) = 0;
440 441  
441 442 /// @brief Get contents of field ad address.
442 443 virtual void pop(int baddr, std::string &text) = 0;
... ... @@ -541,8 +542,6 @@
541 542 /// @brief Set local charset.
542 543 virtual void setCharSet(const char *charset = NULL) = 0;
543 544  
544   - // Actions
545   -
546 545 /// @brief Execute action by name.
547 546 virtual void action(const char *action_name) = 0;
548 547  
... ... @@ -583,7 +582,8 @@
583 582 /// @brief Insert event listener.
584 583 // void insert(Event::Type type, std::function <void(const Event &event)> listener);
585 584  
586   - // Misc
  585 + /// @brief Create an action object
  586 + virtual Action * getAction(const LIB3270_ACTION *descriptor);
587 587  
588 588 /// @brief Search
589 589 size_t find(const char * str, size_t pos = 0) const;
... ... @@ -899,7 +899,7 @@
899 899 /// @param The action code.
900 900 ///
901 901 /// @return The action description.
902   - TN3270_PUBLIC const char * toCharString(const TN3270::Action action);
  902 + TN3270_PUBLIC const char * toCharString(const TN3270::KeyboardAction action);
903 903  
904 904 template <typename T>
905 905 inline TN3270_PUBLIC TN3270::Session & operator<<(TN3270::Session& session, const T value) {
... ...
client/src/include/lib3270/ipc/action.h 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +/**
  31 + * @file lib3270/ipc/action.h
  32 + *
  33 + * @brief Declares the TN3270 IPC Action object.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 +#ifndef IPC3270_ACTION_H_INCLUDED
  40 +
  41 + #define IPC3270_ACTION_H_INCLUDED
  42 +
  43 + #include <lib3270/ipc.h>
  44 +
  45 + namespace TN3270 {
  46 +
  47 + /// @brief TN3270 Action
  48 + class TN3270_PUBLIC Action {
  49 + public:
  50 + virtual bool activatable() const noexcept = 0;
  51 + virtual void activate() = 0;
  52 +
  53 + inline operator bool() const noexcept {
  54 + return activatable();
  55 + }
  56 +
  57 + };
  58 +
  59 + }
  60 +
  61 +#endif // IPC3270_ACTION_H_INCLUDED
... ...
client/src/include/lib3270/ipc/request.h
... ... @@ -40,7 +40,7 @@
40 40  
41 41 #define IPC3270_REQUEST_H_INCLUDED
42 42  
43   - #include <config.h>
  43 + #include <lib3270/ipc.h>
44 44  
45 45 #ifdef _WIN32
46 46 #include <winsock2.h>
... ...
client/src/session/local/actions.cc
... ... @@ -38,11 +38,32 @@
38 38  
39 39 #include "private.h"
40 40 #include <lib3270/actions.h>
  41 + #include <lib3270/ipc/action.h>
41 42  
42 43 /*---[ Implement ]----------------------------------------------------------------------------------*/
43 44  
44 45 namespace TN3270 {
45 46  
  47 + Local::Action::Action(Session *session, const LIB3270_ACTION *descriptor) {
  48 + this->session = session;
  49 + this->descriptor = descriptor;
  50 + }
  51 +
  52 + bool Local::Action::activatable() const noexcept {
  53 + std::lock_guard<std::mutex> lock(this->session->sync);
  54 + return lib3270_action_is_activatable(this->descriptor,this->session->hSession);
  55 + }
  56 +
  57 + void Local::Action::activate() {
  58 + std::lock_guard<std::mutex> lock(this->session->sync);
  59 + chkResponse(lib3270_action_activate(this->descriptor,this->session->hSession));
  60 + }
  61 +
  62 + TN3270::Action * Local::Session::getAction(const LIB3270_ACTION *descriptor) {
  63 + std::lock_guard<std::mutex> lock(sync);
  64 + return new Local::Action(this, descriptor);
  65 + }
  66 +
46 67 void Local::Session::action(const char *action_name) {
47 68 std::lock_guard<std::mutex> lock(sync);
48 69 chkResponse(lib3270_action_activate_by_name(action_name,hSession));
... ... @@ -74,7 +95,7 @@
74 95  
75 96 }
76 97  
77   - void Local::Session::push(const Action action) {
  98 + void Local::Session::push(const KeyboardAction action) {
78 99  
79 100 typedef int (*ActionCallback)(H3270 *);
80 101  
... ...
client/src/session/local/private.h
... ... @@ -42,6 +42,7 @@
42 42  
43 43 #include <config.h>
44 44 #include <ipc-client-internals.h>
  45 + #include <lib3270/ipc/action.h>
45 46 #include <string>
46 47 #include <lib3270.h>
47 48 #include <stdexcept>
... ... @@ -53,9 +54,25 @@
53 54  
54 55 namespace Local {
55 56  
  57 + class Session;
  58 +
  59 + class Action : public TN3270::Action {
  60 + private:
  61 + Session *session;
  62 + const LIB3270_ACTION *descriptor;
  63 +
  64 + public:
  65 + Action(Session *hSession, const LIB3270_ACTION *descriptor);
  66 + bool activatable() const noexcept override;
  67 + void activate() override;
  68 +
  69 + };
  70 +
56 71 class TN3270_PRIVATE Session : public TN3270::Abstract::Session {
57 72 private:
58 73  
  74 + friend class Action;
  75 +
59 76 /// @brief Handle of the related instance of lib3270
60 77 H3270 * hSession;
61 78  
... ... @@ -89,12 +106,14 @@
89 106 virtual ~Session();
90 107  
91 108 // Actions
  109 + TN3270::Action * getAction(const LIB3270_ACTION *descriptor) override;
  110 +
92 111 void action(const char *action_name) override;
93 112 void connect(const char *url, int seconds) override;
94 113 void disconnect() override;
95 114 void pfkey(unsigned short value) override;
96 115 void pakey(unsigned short value) override;
97   - void push(const Action action) override;
  116 + void push(const KeyboardAction action) override;
98 117 void print(LIB3270_CONTENT_OPTION option = LIB3270_CONTENT_ALL) override;
99 118  
100 119 void wait(time_t seconds) const override;
... ...
client/src/session/remote/actions.cc
... ... @@ -113,7 +113,7 @@
113 113  
114 114 }
115 115  
116   - void IPC::Session::push(const Action action) {
  116 + void IPC::Session::push(const KeyboardAction action) {
117 117 this->action(toCharString(action));
118 118 }
119 119  
... ...
client/src/session/remote/private.h
... ... @@ -95,7 +95,7 @@
95 95 void disconnect() override;
96 96 void pfkey(unsigned short value) override;
97 97 void pakey(unsigned short value) override;
98   - void push(const Action action) override;
  98 + void push(const KeyboardAction action) override;
99 99 void print(LIB3270_CONTENT_OPTION option = LIB3270_CONTENT_ALL) override;
100 100  
101 101 void wait(time_t seconds) const override;
... ...