Commit baa7265264616ec0d8de727f6be924f7fca57ca7
1 parent
01b59a4d
Exists in
master
and in
1 other branch
Implementing action factory by name.
Showing
7 changed files
with
95 additions
and
3 deletions
Show diff stats
client/ipcclient.cbp
| ... | ... | @@ -70,6 +70,7 @@ |
| 70 | 70 | <Unit filename="src/include/lib3270/ipc.h" /> |
| 71 | 71 | <Unit filename="src/include/lib3270/ipc/action.h" /> |
| 72 | 72 | <Unit filename="src/include/lib3270/ipc/request.h" /> |
| 73 | + <Unit filename="src/session/action.cc" /> | |
| 73 | 74 | <Unit filename="src/session/get.cc" /> |
| 74 | 75 | <Unit filename="src/session/local/actions.cc" /> |
| 75 | 76 | <Unit filename="src/session/local/attribute.cc" /> | ... | ... |
client/src/core/actions.cc
| ... | ... | @@ -52,13 +52,15 @@ |
| 52 | 52 | TN3270::Action::~Action() { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | + const char * TN3270::Action::getName() const noexcept { | |
| 56 | + return ((const LIB3270_PROPERTY *) this->descriptor)->name; | |
| 57 | + } | |
| 58 | + | |
| 55 | 59 | const char * TN3270::Action::getDescription() const noexcept { |
| 56 | - debug(__FUNCTION__,"(",(void *) descriptor,")"); | |
| 57 | 60 | return lib3270_property_get_description((const LIB3270_PROPERTY *) this->descriptor); |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | 63 | const char * TN3270::Action::getSummary() const noexcept { |
| 61 | - debug(__FUNCTION__,"(",(void *) descriptor,")"); | |
| 62 | 64 | return lib3270_property_get_summary((const LIB3270_PROPERTY *) this->descriptor); |
| 63 | 65 | } |
| 64 | 66 | ... | ... |
client/src/core/session.cc
| ... | ... | @@ -460,6 +460,20 @@ |
| 460 | 460 | throw std::system_error(ENOTSUP, std::system_category()); |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | + Action * Session::getAction(const char *name) { | |
| 464 | + | |
| 465 | + for(auto action : getActions()) { | |
| 466 | + | |
| 467 | + if(strcasecmp(action->name,name) == 0) { | |
| 468 | + return getAction(action); | |
| 469 | + } | |
| 470 | + | |
| 471 | + } | |
| 472 | + | |
| 473 | + throw std::system_error(EINVAL, std::system_category()); | |
| 474 | + | |
| 475 | + } | |
| 476 | + | |
| 463 | 477 | |
| 464 | 478 | } |
| 465 | 479 | ... | ... |
client/src/include/lib3270/ipc.h
| ... | ... | @@ -583,9 +583,12 @@ |
| 583 | 583 | /// @brief Insert event listener. |
| 584 | 584 | // void insert(Event::Type type, std::function <void(const Event &event)> listener); |
| 585 | 585 | |
| 586 | - /// @brief Create an action object | |
| 586 | + /// @brief Create an action object. | |
| 587 | 587 | virtual Action * getAction(const LIB3270_ACTION *descriptor); |
| 588 | 588 | |
| 589 | + /// @brief Create an action object. | |
| 590 | + Action * getAction(const char *name); | |
| 591 | + | |
| 589 | 592 | /// @brief Checks if the terminal contains the string. |
| 590 | 593 | size_t find(const char * str, size_t pos = 0) const; |
| 591 | 594 | |
| ... | ... | @@ -814,6 +817,15 @@ |
| 814 | 817 | return session->getAction(descriptor); |
| 815 | 818 | } |
| 816 | 819 | |
| 820 | + /// @brief Create new action object. | |
| 821 | + /// | |
| 822 | + /// Alocate a new action object associated with the session, delete it | |
| 823 | + /// when no longer necessary. | |
| 824 | + /// | |
| 825 | + inline TN3270::Action * getAction(const char *name) { | |
| 826 | + return session->getAction(name); | |
| 827 | + } | |
| 828 | + | |
| 817 | 829 | /// @brief Send PF. |
| 818 | 830 | inline Host & pfkey(unsigned short value) { |
| 819 | 831 | session->pfkey(value); | ... | ... |
client/src/include/lib3270/ipc/action.h
| ... | ... | @@ -0,0 +1,49 @@ |
| 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 | |
| 32 | + * | |
| 33 | + * @brief | |
| 34 | + * | |
| 35 | + * @author perry.werneck@gmail.com | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + | |
| 39 | +#include <ipc-client-internals.h> | |
| 40 | + | |
| 41 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 42 | + | |
| 43 | + namespace TN3270 { | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + } | |
| 48 | + | |
| 49 | + | ... | ... |
client/src/testprogram/testprogram.cc
| ... | ... | @@ -41,6 +41,7 @@ |
| 41 | 41 | #include <cstdlib> |
| 42 | 42 | #include <lib3270.h> |
| 43 | 43 | #include <lib3270/ipc.h> |
| 44 | + #include <lib3270/ipc/action.h> | |
| 44 | 45 | |
| 45 | 46 | using namespace std; |
| 46 | 47 | |
| ... | ... | @@ -196,6 +197,7 @@ |
| 196 | 197 | //testHost(session); |
| 197 | 198 | //testAttributes(session); |
| 198 | 199 | |
| 200 | + /* | |
| 199 | 201 | { |
| 200 | 202 | TN3270::Host host{":a",nullptr,10}; |
| 201 | 203 | |
| ... | ... | @@ -205,6 +207,17 @@ |
| 205 | 207 | |
| 206 | 208 | cout << "post: " << host["url"] << endl; |
| 207 | 209 | } |
| 210 | + */ | |
| 211 | + | |
| 212 | + { | |
| 213 | + TN3270::Host host{":a",nullptr,10}; | |
| 214 | + | |
| 215 | + TN3270::Action * action = host.getAction("reconnect"); | |
| 216 | + | |
| 217 | + action->activatable(); | |
| 218 | + | |
| 219 | + delete action; | |
| 220 | + } | |
| 208 | 221 | |
| 209 | 222 | |
| 210 | 223 | /* | ... | ... |