Commit b3612fa63da0419d9931021949512ae2886814d6

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

Working on new C++ API.

events.cc 0 → 100644
... ... @@ -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 +
... ...
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" />
... ...
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  
... ...
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();
... ...
session.cc
... ... @@ -63,6 +63,15 @@
63 63  
64 64 }
65 65  
  66 + void Session::insert(Event::Type type, std::function <void(const Event &event)> listener) {
  67 + }
  68 +
  69 + /// @brief Fire event.
  70 + void Session::fire(const Event &event) {
  71 +
  72 +
  73 + }
  74 +
66 75 }
67 76  
68 77  
... ...
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 }
... ...