Commit f2b6e6f03d8b3c69b3d959901a610155884c259f
1 parent
b0b00222
Exists in
master
and in
3 other branches
Designing a new C++ API.
Showing
2 changed files
with
198 additions
and
0 deletions
Show diff stats
lib3270.cbp
... | ... | @@ -64,6 +64,7 @@ |
64 | 64 | <Unit filename="src/include/icmdc.h" /> |
65 | 65 | <Unit filename="src/include/keypadc.h" /> |
66 | 66 | <Unit filename="src/include/kybdc.h" /> |
67 | + <Unit filename="src/include/lib3270++.h" /> | |
67 | 68 | <Unit filename="src/include/lib3270.h" /> |
68 | 69 | <Unit filename="src/include/lib3270/X11keysym.h" /> |
69 | 70 | <Unit filename="src/include/lib3270/action_table.h" /> | ... | ... |
... | ... | @@ -0,0 +1,197 @@ |
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 | + * licinio@bb.com.br (Licínio Luis Branco) | |
28 | + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
29 | + * | |
30 | + */ | |
31 | + | |
32 | +#ifndef LIB3270_HPP_INCLUDED | |
33 | + | |
34 | + #define LIB3270_HPP_INCLUDED 1 | |
35 | + | |
36 | + #include <lib3270.h> | |
37 | + | |
38 | + #if defined(_WIN32) | |
39 | + | |
40 | + #define TN3270_PUBLIC __declspec (dllexport) | |
41 | + #define TN3270_PRIVATE | |
42 | + | |
43 | + #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) | |
44 | + | |
45 | + #define TN3270_PUBLIC | |
46 | + #define TN3270_PRIVATE | |
47 | + | |
48 | + #elif defined(__GNUC__) | |
49 | + | |
50 | + #define TN3270_PUBLIC __attribute__((visibility("default"))) | |
51 | + #define TN3270_PRIVATE __attribute__((visibility("hidden"))) | |
52 | + | |
53 | + #else | |
54 | + | |
55 | + #error Unable to set visibility attribute | |
56 | + | |
57 | + #endif | |
58 | + | |
59 | +#ifdef __cplusplus | |
60 | + | |
61 | + #include <string> | |
62 | + | |
63 | + namespace TN3270 { | |
64 | + | |
65 | + enum ProgramMessage : uint8_t { | |
66 | + MESSAGE_NONE = LIB3270_MESSAGE_NONE, ///< @brief No message | |
67 | + MESSAGE_SYSWAIT = LIB3270_MESSAGE_SYSWAIT, ///< @brief -- | |
68 | + MESSAGE_TWAIT = LIB3270_MESSAGE_TWAIT, ///< @brief -- | |
69 | + MESSAGE_CONNECTED = LIB3270_MESSAGE_CONNECTED, ///< @brief Connected | |
70 | + MESSAGE_DISCONNECTED = LIB3270_MESSAGE_DISCONNECTED, ///< @brief Disconnected from host | |
71 | + MESSAGE_AWAITING_FIRST = LIB3270_MESSAGE_AWAITING_FIRST, ///< @brief -- | |
72 | + MESSAGE_MINUS = LIB3270_MESSAGE_MINUS, ///< @brief -- | |
73 | + MESSAGE_PROTECTED = LIB3270_MESSAGE_PROTECTED, ///< @brief -- | |
74 | + MESSAGE_NUMERIC = LIB3270_MESSAGE_NUMERIC, ///< @brief -- | |
75 | + MESSAGE_OVERFLOW = LIB3270_MESSAGE_OVERFLOW, ///< @brief -- | |
76 | + MESSAGE_INHIBIT = LIB3270_MESSAGE_INHIBIT, ///< @brief -- | |
77 | + MESSAGE_KYBDLOCK = LIB3270_MESSAGE_KYBDLOCK, ///< @brief Keyboard is locked | |
78 | + | |
79 | + MESSAGE_X = LIB3270_MESSAGE_X, ///< @brief -- | |
80 | + MESSAGE_RESOLVING = LIB3270_MESSAGE_RESOLVING, ///< @brief Resolving hostname (running DNS query) | |
81 | + MESSAGE_CONNECTING, = LIB3270_MESSAGE_CONNECTING ///< @brief Connecting to host | |
82 | + | |
83 | + }; | |
84 | + | |
85 | + /// @brief connection state. | |
86 | + enum ConnectionState : uint8_t { | |
87 | + DISCONNECTED = LIB3270_NOT_CONNECTED, ///< @brief disconnected | |
88 | + RESOLVING = LIB3270_RESOLVING, ///< @brief resolving hostname | |
89 | + PENDING = LIB3270_PENDING, ///< @brief connection pending | |
90 | + CONNECTED_INITIAL = LIB3270_CONNECTED_INITIAL, ///< @brief connected, no mode yet | |
91 | + CONNECTED_ANSI = LIB3270_CONNECTED_ANSI, ///< @brief connected in NVT ANSI mode | |
92 | + CONNECTED_3270 = LIB3270_CONNECTED_3270, ///< @brief connected in old-style 3270 mode | |
93 | + CONNECTED_INITIAL_E = LIB3270_CONNECTED_INITIAL_E, ///< @brief connected in TN3270E mode, unnegotiated | |
94 | + CONNECTED_NVT = LIB3270_CONNECTED_NVT, ///< @brief connected in TN3270E mode, NVT mode | |
95 | + CONNECTED_SSCP = LIB3270_CONNECTED_SSCP, ///< @brief connected in TN3270E mode, SSCP-LU mode | |
96 | + CONNECTED_TN3270E = LIB3270_CONNECTED_TN3270E, ///< @brief connected in TN3270E mode, 3270 mode | |
97 | + }; | |
98 | + | |
99 | + /// @brief PF Keys | |
100 | + enum PFKey : uint8_t { | |
101 | + PF_1, | |
102 | + PF_2, | |
103 | + PF_3, | |
104 | + PF_4, | |
105 | + PF_5, | |
106 | + PF_6, | |
107 | + PF_7, | |
108 | + PF_8, | |
109 | + PF_9, | |
110 | + PF_10, | |
111 | + PF_11, | |
112 | + PF_12 | |
113 | + }; | |
114 | + | |
115 | + /// @brief PF Keys | |
116 | + enum PAKey : uint8_t { | |
117 | + PA_1, | |
118 | + PA_2, | |
119 | + PA_3 | |
120 | + }; | |
121 | + | |
122 | + /// @brief Actions keys | |
123 | + enum Action : uint8_t { | |
124 | + ENTER ///< Enter key | |
125 | + }; | |
126 | + | |
127 | + /// @brief TN3270 Session. | |
128 | + class TN3270_PUBLIC Session { | |
129 | + protected: | |
130 | + Session(); | |
131 | + | |
132 | + public: | |
133 | + | |
134 | + /// @brief Create a tn3270 session. | |
135 | + static Session * create(const char *id = nullptr); | |
136 | + | |
137 | + virtual ~Session(); | |
138 | + | |
139 | + // Connect/disconnect | |
140 | + virtual void connect(const char *url) = 0; | |
141 | + virtual void disconnect(const char *url); | |
142 | + | |
143 | + // Gets | |
144 | + virtual std::string toString(int baddr = 0, size_t len = -1, bool lf = false) = 0; | |
145 | + virtual std::string toString(int row, int col, size_t sz, bool lf = false) = 0; | |
146 | + | |
147 | + /// @brief Get field at current position, update to next one. | |
148 | + virtual Session & pop(std::string &value) = 0; | |
149 | + | |
150 | + inline operator std::string() const { | |
151 | + return toString(); | |
152 | + } | |
153 | + | |
154 | + virtual ProgramMessage getProgramMessage() const = 0; | |
155 | + inline operator ProgramMessage() const { | |
156 | + return getProgramMessage(); | |
157 | + } | |
158 | + | |
159 | + virtual ConnectionState getConnectionState() const = 0; | |
160 | + inline operator ConnectionState() const { | |
161 | + return getConnectionState(); | |
162 | + } | |
163 | + | |
164 | + // Sets | |
165 | + | |
166 | + /// @brief Set field at current posicion, jumps to next writable field. | |
167 | + virtual Session & push(const char *text) = 0; | |
168 | + inline Session & push(const std::string &text) { | |
169 | + return push(text.c_str()); | |
170 | + } | |
171 | + | |
172 | + virtual Session & push(int baddr = 0, const std::string &text) = 0; | |
173 | + virtual Session & push(int row, int col, const std::string &text) = 0; | |
174 | + virtual Session & push(const PFKey key) = 0; | |
175 | + virtual Session & push(const PAKey key) = 0; | |
176 | + virtual Session & push(const Action action) = 0; | |
177 | + | |
178 | + }; | |
179 | + | |
180 | + } | |
181 | + | |
182 | + TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMessage) noexcept; | |
183 | + TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState) noexcept; | |
184 | + | |
185 | + template <typename T> | |
186 | + inline TN3270_PUBLIC TN3270::Session & operator<<(TN3270::Session& session, const T value) { | |
187 | + return session.push(value); | |
188 | + } | |
189 | + | |
190 | + template <typename T> | |
191 | + inline TN3270_PUBLIC TN3270::Session & operator>>(TN3270::Session& session, const T value) { | |
192 | + return session.pop(value); | |
193 | + } | |
194 | + | |
195 | +#endif | |
196 | + | |
197 | +#endif // LIB3270_H_INCLUDED | ... | ... |