Commit 9eeebba190c25d75f286af0874b872f9f36f8e9b

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

Adding header file from original lib3270 ipc module.

client/lib3270++.cbp
... ... @@ -40,6 +40,7 @@
40 40 <Linker>
41 41 <Add option="`pkg-config --libs lib3270`" />
42 42 </Linker>
  43 + <Unit filename="../common/src/include/lib3270/ipc.h" />
43 44 <Unit filename="../include/config.h.in" />
44 45 <Unit filename="src/core/abstract.cc" />
45 46 <Unit filename="src/core/events.cc" />
... ...
client/src/include/ipc-client-internals.h
... ... @@ -52,7 +52,7 @@
52 52  
53 53 #include <iostream>
54 54 #include <mutex>
55   - #include <lib3270++.h>
  55 + #include <lib3270/ipc.h>
56 56 #include <lib3270/popup.h>
57 57 #include <system_error>
58 58 #include <stdexcept>
... ...
client/src/testprogram/testprogram.cc
... ... @@ -38,7 +38,7 @@
38 38  
39 39 #include <getopt.h>
40 40 #include <cstdlib>
41   - #include <lib3270++.h>
  41 + #include <lib3270/ipc.h>
42 42  
43 43 using namespace std;
44 44  
... ...
common/src/include/lib3270/ipc.h 0 → 100644
... ... @@ -0,0 +1,437 @@
  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 +#ifndef LIB3270_IPC_H_INCLUDED
  31 +
  32 + #define LIB3270_IPC_H_INCLUDED 1
  33 +
  34 + #include <iostream>
  35 + #include <cstdarg>
  36 + #include <vector>
  37 + #include <functional>
  38 + #include <lib3270.h>
  39 +
  40 + #if defined(_WIN32)
  41 +
  42 + #define TN3270_PUBLIC __declspec (dllexport)
  43 + #define TN3270_PRIVATE
  44 +
  45 + #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
  46 +
  47 + #define TN3270_PUBLIC
  48 + #define TN3270_PRIVATE
  49 +
  50 + #elif defined(__GNUC__)
  51 +
  52 + #define TN3270_PUBLIC __attribute__((visibility("default")))
  53 + #define TN3270_PRIVATE __attribute__((visibility("hidden")))
  54 +
  55 + #else
  56 +
  57 + #error Unable to set visibility attribute
  58 +
  59 + #endif
  60 +
  61 +#ifdef __cplusplus
  62 +
  63 + #include <string>
  64 +
  65 + namespace TN3270 {
  66 +
  67 + class Host;
  68 + class Controller;
  69 +
  70 + #define DEFAULT_TIMEOUT 5
  71 +
  72 + class TN3270_PUBLIC Event {
  73 + public:
  74 + enum Type : uint8_t {
  75 + All, ///< @brief All events (undefined).
  76 + Popup, ///< @brief Popup message.
  77 + Trace, ///< @brief Trace message.
  78 + Message, ///< @brief Generic message.
  79 + Connection ///< @brief Connect/Disconnect event.
  80 + };
  81 +
  82 + private:
  83 + Type type;
  84 +
  85 + protected:
  86 + Event(enum Type type);
  87 +
  88 + public:
  89 + virtual ~Event();
  90 +
  91 + /// @brief Check event type
  92 + inline bool is(Event::Type type) const noexcept {
  93 + return this->type == type;
  94 + }
  95 +
  96 + /// @brief Check event type
  97 + inline bool operator==(Event::Type type) const noexcept {
  98 + return this->type == type;
  99 + }
  100 +
  101 + inline operator Event::Type() const noexcept {
  102 + return this->type;
  103 + }
  104 +
  105 + /// @brief Get event description.
  106 + virtual std::string toString() const = 0;
  107 +
  108 + };
  109 +
  110 + enum ProgramMessage : uint8_t {
  111 + MESSAGE_NONE = LIB3270_MESSAGE_NONE, ///< @brief No message
  112 + MESSAGE_SYSWAIT = LIB3270_MESSAGE_SYSWAIT, ///< @brief --
  113 + MESSAGE_TWAIT = LIB3270_MESSAGE_TWAIT, ///< @brief --
  114 + MESSAGE_CONNECTED = LIB3270_MESSAGE_CONNECTED, ///< @brief Connected
  115 + MESSAGE_DISCONNECTED = LIB3270_MESSAGE_DISCONNECTED, ///< @brief Disconnected from host
  116 + MESSAGE_AWAITING_FIRST = LIB3270_MESSAGE_AWAITING_FIRST, ///< @brief --
  117 + MESSAGE_MINUS = LIB3270_MESSAGE_MINUS, ///< @brief --
  118 + MESSAGE_PROTECTED = LIB3270_MESSAGE_PROTECTED, ///< @brief --
  119 + MESSAGE_NUMERIC = LIB3270_MESSAGE_NUMERIC, ///< @brief --
  120 + MESSAGE_OVERFLOW = LIB3270_MESSAGE_OVERFLOW, ///< @brief --
  121 + MESSAGE_INHIBIT = LIB3270_MESSAGE_INHIBIT, ///< @brief --
  122 + MESSAGE_KYBDLOCK = LIB3270_MESSAGE_KYBDLOCK, ///< @brief Keyboard is locked
  123 +
  124 + MESSAGE_X = LIB3270_MESSAGE_X, ///< @brief --
  125 + MESSAGE_RESOLVING = LIB3270_MESSAGE_RESOLVING, ///< @brief Resolving hostname (running DNS query)
  126 + MESSAGE_CONNECTING = LIB3270_MESSAGE_CONNECTING ///< @brief Connecting to host
  127 +
  128 + };
  129 +
  130 + /// @brief connection state.
  131 + enum ConnectionState : uint8_t {
  132 + DISCONNECTED = LIB3270_NOT_CONNECTED, ///< @brief disconnected
  133 + RESOLVING = LIB3270_RESOLVING, ///< @brief resolving hostname
  134 + PENDING = LIB3270_PENDING, ///< @brief connection pending
  135 + CONNECTED_INITIAL = LIB3270_CONNECTED_INITIAL, ///< @brief connected, no mode yet
  136 + CONNECTED_ANSI = LIB3270_CONNECTED_ANSI, ///< @brief connected in NVT ANSI mode
  137 + CONNECTED_3270 = LIB3270_CONNECTED_3270, ///< @brief connected in old-style 3270 mode
  138 + CONNECTED_INITIAL_E = LIB3270_CONNECTED_INITIAL_E, ///< @brief connected in TN3270E mode, unnegotiated
  139 + CONNECTED_NVT = LIB3270_CONNECTED_NVT, ///< @brief connected in TN3270E mode, NVT mode
  140 + CONNECTED_SSCP = LIB3270_CONNECTED_SSCP, ///< @brief connected in TN3270E mode, SSCP-LU mode
  141 + CONNECTED_TN3270E = LIB3270_CONNECTED_TN3270E, ///< @brief connected in TN3270E mode, 3270 mode
  142 + };
  143 +
  144 + /// @brief PF Keys
  145 + enum PFKey : uint8_t {
  146 + PF_1,
  147 + PF_2,
  148 + PF_3,
  149 + PF_4,
  150 + PF_5,
  151 + PF_6,
  152 + PF_7,
  153 + PF_8,
  154 + PF_9,
  155 + PF_10,
  156 + PF_11,
  157 + PF_12
  158 + };
  159 +
  160 + /// @brief PF Keys
  161 + enum PAKey : uint8_t {
  162 + PA_1,
  163 + PA_2,
  164 + PA_3
  165 + };
  166 +
  167 + /// @brief Actions keys
  168 + enum Action : uint8_t {
  169 + ENTER, ///< Enter key
  170 + ERASE,
  171 + ERASE_EOF,
  172 + ERASE_EOL,
  173 + ERASE_INPUT
  174 + };
  175 +
  176 + /// @brief TN3270 Session.
  177 + class TN3270_PUBLIC Session {
  178 + protected:
  179 + Session();
  180 +
  181 + /// @brief Write information to log file.
  182 + void info(const char *fmt, ...) const;
  183 +
  184 + /// @brief Write warning to log file.
  185 + void warning(const char *fmt, ...) const;
  186 +
  187 + /// @brief Write error to log file.
  188 + void error(const char *fmt, ...) const;
  189 +
  190 + /// @brief Fire event.
  191 + void fire(const Event &event);
  192 +
  193 + public:
  194 +
  195 + /// @brief Create a tn3270 session.
  196 + static Session * create(const char *id = nullptr);
  197 +
  198 + virtual ~Session();
  199 +
  200 + // Connect/disconnect
  201 + virtual void connect(const char *url) = 0;
  202 + virtual void disconnect() = 0;
  203 +
  204 + // Wait for session state.
  205 + virtual void waitForReady(time_t timeout = DEFAULT_TIMEOUT) = 0;
  206 +
  207 + // Gets
  208 + virtual std::string toString(int baddr = 0, size_t len = -1, char lf = '\n') const = 0;
  209 + virtual std::string toString(int row, int col, size_t sz, char lf = '\n') const = 0;
  210 +
  211 + inline operator std::string() const {
  212 + return toString();
  213 + }
  214 +
  215 + // Get properties.
  216 + virtual void getProperty(const char *name, int &value) const = 0;
  217 + virtual void getProperty(const char *name, std::string &value) const = 0;
  218 + virtual void getProperty(const char *name, bool &value) const = 0;
  219 +
  220 + virtual std::string getVersion() const = 0;
  221 + virtual std::string getRevision() const = 0;
  222 +
  223 + virtual ProgramMessage getProgramMessage() const = 0;
  224 + inline operator ProgramMessage() const {
  225 + return getProgramMessage();
  226 + }
  227 +
  228 + virtual ConnectionState getConnectionState() const = 0;
  229 + inline operator ConnectionState() const {
  230 + return getConnectionState();
  231 + }
  232 +
  233 + inline bool operator==(ConnectionState state) const noexcept {
  234 + return this->getConnectionState() == state;
  235 + }
  236 +
  237 + // Set contents.
  238 +
  239 + /// @brief Set field at current posicion, jumps to next writable field.
  240 + virtual Session & push(const char *text) = 0;
  241 + inline Session & push(const std::string &text) {
  242 + return push(text.c_str());
  243 + }
  244 +
  245 + /// @brief Set cursor address.
  246 + virtual TN3270::Session & setCursorPosition(unsigned short addr) = 0;
  247 +
  248 + /// @brief Set cursor position.
  249 + virtual TN3270::Session & setCursorPosition(unsigned short row, unsigned short col) = 0;
  250 +
  251 + virtual Session & push(int baddr, const std::string &text) = 0;
  252 + virtual Session & push(int row, int col, const std::string &text) = 0;
  253 + virtual Session & push(const PFKey key) = 0;
  254 + virtual Session & push(const PAKey key) = 0;
  255 + virtual Session & push(const Action action) = 0;
  256 +
  257 + // Get contents.
  258 + virtual Session & pop(int baddr, std::string &text) = 0;
  259 + virtual Session & pop(int row, int col, std::string &text) = 0;
  260 + virtual Session & pop(std::string &text) = 0;
  261 +
  262 + /// @brief Insert event listener.
  263 + void insert(Event::Type type, std::function <void(const Event &event)> listener);
  264 +
  265 + // Misc
  266 +
  267 + /// @brief Execute action by name.
  268 + virtual Session & action(const char *action_name) = 0;
  269 +
  270 + };
  271 +
  272 + /// @brief TN3270 Host
  273 + class TN3270_PUBLIC Host : public std::basic_streambuf<char, std::char_traits<char> > {
  274 + private:
  275 +
  276 + /// @brief Connection with the host
  277 + Session *session;
  278 +
  279 + /// @brief How much seconds we wait for the terminal to be ready?
  280 + time_t timeout;
  281 +
  282 + protected:
  283 +
  284 + /// @brief Writes characters to the associated file from the put area
  285 + int sync() override;
  286 +
  287 + /// @brief Writes characters to the associated output sequence from the put area.
  288 + int overflow(int c) override;
  289 +
  290 + /// @brief Write information to log file.
  291 + void info(const char *fmt, ...) const;
  292 +
  293 + /// @brief Write warning to log file.
  294 + void warning(const char *fmt, ...) const;
  295 +
  296 + /// @brief Write error to log file.
  297 + void error(const char *fmt, ...) const;
  298 +
  299 + public:
  300 + Host(const char *id = nullptr, const char *url = nullptr, time_t timeout = DEFAULT_TIMEOUT);
  301 + ~Host();
  302 +
  303 + inline bool operator==(ConnectionState state) const noexcept {
  304 + return session->getConnectionState() == state;
  305 + }
  306 +
  307 + void connect(const char *url, bool sync = true);
  308 +
  309 + inline ProgramMessage getProgramMessage() const {
  310 + return session->getProgramMessage();
  311 + }
  312 +
  313 + inline operator bool() const {
  314 + return isReady();
  315 + }
  316 +
  317 + inline operator ProgramMessage() const {
  318 + return getProgramMessage();
  319 + }
  320 +
  321 + inline ConnectionState getConnectionState() const {
  322 + return session->getConnectionState();
  323 + }
  324 +
  325 + bool isReady() const;
  326 + bool isConnected() const;
  327 +
  328 + inline operator ConnectionState() const {
  329 + return getConnectionState();
  330 + }
  331 +
  332 + /// @brief Set cursor address.
  333 + inline void setCursorPosition(unsigned short addr) {
  334 + session->setCursorPosition(addr);
  335 + }
  336 +
  337 + /// @brief Set cursor position.
  338 + inline void setCursorPosition(unsigned short row, unsigned short col) {
  339 + session->setCursorPosition(row,col);
  340 + }
  341 +
  342 + // Get properties
  343 +
  344 + /// @brief Get lib3270 version.
  345 + inline std::string getVersion() const {
  346 + return session->getVersion();
  347 + }
  348 +
  349 + /// @brief Get lib3270 revision.
  350 + std::string getRevision() const {
  351 + return session->getRevision();
  352 + }
  353 +
  354 + // Set contents.
  355 +
  356 + /// @brief Set field at current posicion, jumps to next writable field.
  357 + inline Host & push(const char *text) {
  358 + session->push(text);
  359 + return *this;
  360 + };
  361 +
  362 + inline Host & push(const std::string &text) {
  363 + session->push(text);
  364 + return *this;
  365 +
  366 + }
  367 +
  368 + inline Host & push(int baddr, const std::string &text) {
  369 + session->push(baddr,text);
  370 + return *this;
  371 + }
  372 +
  373 + inline Host & push(int row, int col, const std::string &text) {
  374 + session->push(row,col,text);
  375 + return *this;
  376 + }
  377 +
  378 + inline Host & push(const PFKey key) {
  379 + session->push(key);
  380 + return *this;
  381 + }
  382 +
  383 + inline Host & push(const PAKey key) {
  384 + session->push(key);
  385 + return *this;
  386 + }
  387 +
  388 + Host & push(const Action action);
  389 +
  390 + // Get contents.
  391 +
  392 + Host & pop(int baddr, std::string &text);
  393 + Host & pop(int row, int col, std::string &text);
  394 + Host & pop(std::string &text);
  395 +
  396 + std::string toString() const;
  397 + std::string toString(int baddr, size_t len = -1, char lf = '\n') const;
  398 + std::string toString(int row, int col, size_t sz, char lf = '\n') const;
  399 +
  400 + // Event listeners
  401 + inline Host & insert(Event::Type type, std::function <void(const Event &event)> listener) noexcept {
  402 + session->insert(type, listener);
  403 + return *this;
  404 + }
  405 +
  406 +
  407 + };
  408 +
  409 + }
  410 +
  411 + TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMessage) noexcept;
  412 + TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState) noexcept;
  413 +
  414 + template <typename T>
  415 + inline TN3270_PUBLIC TN3270::Session & operator<<(TN3270::Session& session, const T value) {
  416 + return session.push(value);
  417 + }
  418 +
  419 + template <typename T>
  420 + inline TN3270_PUBLIC TN3270::Session & operator>>(TN3270::Session& session, const T value) {
  421 + return session.pop(value);
  422 + }
  423 +
  424 + template <typename T>
  425 + inline TN3270_PUBLIC TN3270::Host & operator<<(TN3270::Host& host, const T value) {
  426 + return host.push(value);
  427 + }
  428 +
  429 + inline std::ostream & operator<<(std::ostream &stream, const TN3270::Host& host) {
  430 + stream << host.toString();
  431 + return stream;
  432 + }
  433 +
  434 +
  435 +#endif
  436 +
  437 +#endif // LIB3270_H_INCLUDED
... ...