Commit 09f7edb3def3e459c58886c5962acd5e9d2614d6
1 parent
833d8b5c
Exists in
master
and in
3 other branches
Working on new C++ API.
Showing
7 changed files
with
117 additions
and
12 deletions
Show diff stats
src/include/lib3270++.h
... | ... | @@ -33,6 +33,8 @@ |
33 | 33 | |
34 | 34 | #include <iostream> |
35 | 35 | #include <cstdarg> |
36 | + #include <vector> | |
37 | + #include <functional> | |
36 | 38 | #include <lib3270.h> |
37 | 39 | |
38 | 40 | #if defined(_WIN32) |
... | ... | @@ -63,8 +65,9 @@ |
63 | 65 | namespace TN3270 { |
64 | 66 | |
65 | 67 | class Host; |
68 | + class Controller; | |
66 | 69 | |
67 | - class Event { | |
70 | + class TN3270_PUBLIC Event { | |
68 | 71 | public: |
69 | 72 | enum Type : uint8_t { |
70 | 73 | All, ///< @brief All events (undefined). |
... | ... | @@ -77,9 +80,7 @@ |
77 | 80 | Type type; |
78 | 81 | |
79 | 82 | protected: |
80 | - Event(enum Type type) { | |
81 | - this->type = type; | |
82 | - } | |
83 | + Event(enum Type type); | |
83 | 84 | |
84 | 85 | public: |
85 | 86 | virtual ~Event(); |
... | ... | @@ -89,6 +90,15 @@ |
89 | 90 | return this->type == type; |
90 | 91 | } |
91 | 92 | |
93 | + /// @brief Check event type | |
94 | + inline bool operator==(Event::Type type) const noexcept { | |
95 | + return this->type == type; | |
96 | + } | |
97 | + | |
98 | + inline operator Event::Type() const noexcept { | |
99 | + return this->type; | |
100 | + } | |
101 | + | |
92 | 102 | /// @brief Get event description. |
93 | 103 | virtual std::string toString() const = 0; |
94 | 104 | |
... | ... | @@ -174,6 +184,7 @@ |
174 | 184 | /// @brief Write error to log file. |
175 | 185 | void error(const char *fmt, ...) const; |
176 | 186 | |
187 | + /// @brief Fire event. | |
177 | 188 | void fire(const Event &event); |
178 | 189 | |
179 | 190 | public: |
... | ... | @@ -228,6 +239,9 @@ |
228 | 239 | virtual Session & pop(int row, int col, std::string &text) = 0; |
229 | 240 | virtual Session & pop(std::string &text) = 0; |
230 | 241 | |
242 | + /// @brief Insert event listener. | |
243 | + void insert(Event::Type type, std::function <void(const Event &event)> listener); | |
244 | + | |
231 | 245 | }; |
232 | 246 | |
233 | 247 | /// @brief TN3270 Host |
... | ... | @@ -334,6 +348,13 @@ |
334 | 348 | return *this; |
335 | 349 | } |
336 | 350 | |
351 | + // Event listeners | |
352 | + inline Host & insert(Event::Type type, std::function <void(const Event &event)> listener) noexcept { | |
353 | + session->insert(type, listener); | |
354 | + return *this; | |
355 | + } | |
356 | + | |
357 | + | |
337 | 358 | }; |
338 | 359 | |
339 | 360 | } | ... | ... |
... | ... | @@ -0,0 +1,56 @@ |
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 lib3270++.h 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 src/lib3270++/events.cc | |
32 | + * | |
33 | + * @brief | |
34 | + * | |
35 | + * @author perry.werneck@gmail.com | |
36 | + * | |
37 | + */ | |
38 | + | |
39 | + #include "private.h" | |
40 | + | |
41 | + | |
42 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
43 | + | |
44 | + namespace TN3270 { | |
45 | + | |
46 | + Event::Event(enum Event::Type type) { | |
47 | + this->type = type; | |
48 | + } | |
49 | + | |
50 | + Event::~Event() { | |
51 | + } | |
52 | + | |
53 | + } | |
54 | + | |
55 | + | |
56 | + | ... | ... |
src/lib3270++/lib3270++.cbp
... | ... | @@ -44,6 +44,7 @@ |
44 | 44 | <Unit filename="../include/lib3270/popup.h" /> |
45 | 45 | <Unit filename="../include/lib3270/session.h" /> |
46 | 46 | <Unit filename="abstract.cc" /> |
47 | + <Unit filename="events.cc" /> | |
47 | 48 | <Unit filename="host.cc" /> |
48 | 49 | <Unit filename="local.cc" /> |
49 | 50 | <Unit filename="private.h" /> | ... | ... |
src/lib3270++/local.cc
... | ... | @@ -86,6 +86,13 @@ |
86 | 86 | free(buffer); |
87 | 87 | } |
88 | 88 | |
89 | +#ifdef DEBUG | |
90 | + std::cerr << "Popup:" << std::endl | |
91 | + << "\t" << title << std::endl | |
92 | + << "\t" << msg << std::endl | |
93 | + << "\t" << description << std::endl; | |
94 | +#endif // DEBUG | |
95 | + | |
89 | 96 | } |
90 | 97 | |
91 | 98 | virtual ~PopupEvent() { |
... | ... | @@ -113,14 +120,26 @@ |
113 | 120 | this->hSession = nullptr; |
114 | 121 | } |
115 | 122 | |
123 | + void LocalSession::wait(time_t timeout) { | |
124 | + | |
125 | + int rc = lib3270_wait_for_ready(this->hSession, timeout); | |
126 | + | |
127 | + if(rc) { | |
128 | + throw std::system_error(rc, std::system_category()); | |
129 | + } | |
130 | + | |
131 | + } | |
132 | + | |
116 | 133 | void LocalSession::connect(const char *url) { |
117 | 134 | std::lock_guard<std::mutex> lock(sync); |
118 | 135 | int rc = lib3270_connect_url(hSession,url,0); |
119 | 136 | |
120 | - if(!rc) { | |
137 | + if(rc) { | |
121 | 138 | throw std::system_error(rc, std::system_category()); |
122 | 139 | } |
123 | 140 | |
141 | + wait(); | |
142 | + | |
124 | 143 | } |
125 | 144 | |
126 | 145 | void LocalSession::disconnect() { |
... | ... | @@ -132,12 +151,7 @@ |
132 | 151 | void LocalSession::waitForReady(time_t timeout) throw() { |
133 | 152 | |
134 | 153 | std::lock_guard<std::mutex> lock(sync); |
135 | - | |
136 | - int rc = lib3270_wait_for_ready(this->hSession, timeout); | |
137 | - | |
138 | - if(rc) { | |
139 | - throw std::system_error(rc, std::system_category()); | |
140 | - } | |
154 | + wait(timeout); | |
141 | 155 | |
142 | 156 | } |
143 | 157 | ... | ... |
src/lib3270++/private.h
... | ... | @@ -112,6 +112,9 @@ |
112 | 112 | /// @brief Popup Handler. |
113 | 113 | static int popupHandler(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg); |
114 | 114 | |
115 | + /// @brief Wait for network events | |
116 | + void wait(time_t timeout = 5); | |
117 | + | |
115 | 118 | public: |
116 | 119 | LocalSession(); |
117 | 120 | virtual ~LocalSession(); | ... | ... |
src/lib3270++/session.cc
src/lib3270++/testprogram/testprogram.cc
... | ... | @@ -36,6 +36,7 @@ |
36 | 36 | * |
37 | 37 | */ |
38 | 38 | |
39 | + #include <cstdlib> | |
39 | 40 | #include <lib3270++.h> |
40 | 41 | |
41 | 42 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
... | ... | @@ -44,7 +45,7 @@ |
44 | 45 | |
45 | 46 | TN3270::Host host; |
46 | 47 | |
47 | - host.connect(nullptr); | |
48 | + host.connect(getenv("TN3270URL")); | |
48 | 49 | |
49 | 50 | return 0; |
50 | 51 | } | ... | ... |