Commit 79de44538306fba990d69dce8fb7b23e18e8e273

Authored by Perry Werneck
1 parent da64c0f2

Working on IPC client module.

configure.ac
... ... @@ -427,6 +427,14 @@ AC_SUBST(LIBSSL_LIBS)
427 427 AC_SUBST(LIBSSL_CFLAGS)
428 428  
429 429 dnl ---------------------------------------------------------------------------
  430 +dnl Check for D-Bus
  431 +dnl ---------------------------------------------------------------------------
  432 +
  433 +PKG_CHECK_MODULES( [DBUS], [dbus-1], AC_DEFINE(HAVE_DBUS), AC_MSG_NOTICE([ No DBUS support.]) )
  434 +AC_SUBST(DBUS_LIBS)
  435 +AC_SUBST(DBUS_CFLAGS)
  436 +
  437 +dnl ---------------------------------------------------------------------------
430 438 dnl Check for LDAP
431 439 dnl ---------------------------------------------------------------------------
432 440  
... ...
src/include/config.h.in
... ... @@ -2,18 +2,18 @@
2 2 * Software pw3270, desenvolvido com base nos códigos fontes do C3270 e X3270
3 3 * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4 4 * aplicativos mainframe. Registro no INPI sob o nome G3270.
5   - *
  5 + *
6 6 * Copyright (C) <2008> <Banco do Brasil S.A.>
7   - *
  7 + *
8 8 * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
9 9 * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
10 10 * Free Software Foundation.
11   - *
  11 + *
12 12 * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
13 13 * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
14 14 * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
15 15 * obter mais detalhes.
16   - *
  16 + *
17 17 * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
18 18 * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
19 19 * Place, Suite 330, Boston, MA, 02111-1307, USA
... ... @@ -41,6 +41,7 @@
41 41 #undef HAVE_GETADDRINFO
42 42 #undef HAVE_VASPRINTF
43 43 #undef HAVE_INET_NTOP
  44 + #undef HAVE_DBUS
44 45  
45 46 #undef HAVE_ICONV
46 47 #undef ICONV_CONST
... ...
src/lib3270++/Makefile.in
... ... @@ -31,6 +31,7 @@ LIBNAME=lib@LIB3270_NAME@++
31 31 SOURCES= \
32 32 $(wildcard *.cc) \
33 33 $(wildcard local/*.cc) \
  34 + $(wildcard ipc/*.cc) \
34 35 $(wildcard @OSNAME@/*.c) \
35 36 $(wildcard @OSNAME@/*.rc)
36 37  
... ... @@ -90,14 +91,16 @@ DEPENDS= \
90 91 CFLAGS= \
91 92 @CFLAGS@ \
92 93 -g \
93   - -I../include
94   - -DBUILD_DATE=`date +%Y%m%d`
  94 + -I../include \
  95 + -DBUILD_DATE=`date +%Y%m%d` \
  96 + @DBUS_CFLAGS@
95 97  
96 98 LIBS= \
97 99 @LIBS@ \
98 100 @LIBSSL_LIBS@ \
99 101 @LIBICONV@ \
100   - @INTL_LIBS@
  102 + @INTL_LIBS@ \
  103 + @DBUS_LIBS@
101 104  
102 105  
103 106 #---[ Debug Rules ]----------------------------------------------------------------------
... ...
src/lib3270++/ipc/session.cc 0 → 100644
... ... @@ -0,0 +1,216 @@
  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 src/lib3270++/ipc/session.cc
  32 + *
  33 + * @brief Implements lib3270 access using IPC calls.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 + #include <cstring>
  41 +
  42 + using std::string;
  43 +
  44 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  45 +
  46 +#ifndef _WIN32
  47 +
  48 + static void throws_if_error(DBusError &err) {
  49 +
  50 + if(dbus_error_is_set(&err)) {
  51 + string message = err.message;
  52 + dbus_error_free(&err);
  53 + throw std::runtime_error(message.c_str());
  54 + }
  55 +
  56 + return;
  57 +
  58 + }
  59 +
  60 +#endif // _WIN32
  61 +
  62 + namespace TN3270 {
  63 +
  64 + IPC::Session::Session(const char *id) : Abstract::Session() {
  65 +
  66 +#ifdef _WIN32
  67 +
  68 +#else
  69 + // Create D-Bus session.
  70 + DBusError err;
  71 +
  72 + dbus_error_init(&err);
  73 + this->conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
  74 +
  75 + debug("dbus_bus_get conn=",conn);
  76 +
  77 + throws_if_error(err);
  78 +
  79 + if(!conn)
  80 + throw std::runtime_error("DBUS Connection failed");
  81 +
  82 + auto sep = strchr(id,':');
  83 + if(!sep) {
  84 + throw std::system_error(EINVAL, std::system_category());
  85 + }
  86 +
  87 + this->name = "br.com.bb.";
  88 + this->name += string(id,(sep - id));
  89 + this->name += ".";
  90 + this->name += (sep+1);
  91 + this->path = "/br/com/bb/tn3270/session";
  92 +
  93 + debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\"");
  94 +
  95 +#endif // _WIN32
  96 +
  97 + }
  98 +
  99 + IPC::Session::~Session() {
  100 +
  101 +#ifdef _WIN32
  102 +
  103 +#else
  104 +
  105 +#endif // _WIN32
  106 +
  107 + }
  108 +
  109 + /*
  110 + void IPC::Session::wait(time_t timeout) {
  111 +
  112 +
  113 + }
  114 + */
  115 +
  116 + void IPC::Session::connect(const char *url) {
  117 + Request request(*this,"connect");
  118 + request.push(url).call();
  119 + }
  120 +
  121 + void IPC::Session::disconnect() {
  122 + Request request(*this,"disconnect");
  123 + request.call();
  124 + }
  125 +
  126 + // Wait for session state.
  127 + void IPC::Session::waitForReady(time_t timeout) throw() {
  128 + throw std::system_error(EINVAL, std::system_category());
  129 + }
  130 +
  131 + std::string IPC::Session::toString(int baddr, size_t len, char lf) const {
  132 + throw std::system_error(EINVAL, std::system_category());
  133 + }
  134 +
  135 + std::string IPC::Session::toString(int row, int col, size_t sz, char lf) const {
  136 + throw std::system_error(EINVAL, std::system_category());
  137 + }
  138 +
  139 + ProgramMessage IPC::Session::getProgramMessage() const {
  140 + throw std::system_error(EINVAL, std::system_category());
  141 + }
  142 +
  143 + ConnectionState IPC::Session::getConnectionState() const {
  144 + throw std::system_error(EINVAL, std::system_category());
  145 + }
  146 +
  147 + /// @brief Set field at current position, jumps to next writable field.
  148 + TN3270::Session & IPC::Session::push(const char *text) {
  149 + throw std::system_error(EINVAL, std::system_category());
  150 + }
  151 +
  152 + TN3270::Session & IPC::Session::push(int baddr, const std::string &text) {
  153 +
  154 +
  155 + return *this;
  156 + }
  157 +
  158 + TN3270::Session & IPC::Session::push(int row, int col, const std::string &text) {
  159 +
  160 +
  161 + return *this;
  162 + }
  163 +
  164 + TN3270::Session & IPC::Session::push(const PFKey key) {
  165 +
  166 +
  167 + return *this;
  168 + }
  169 +
  170 + TN3270::Session & IPC::Session::push(const PAKey key) {
  171 +
  172 +
  173 + return *this;
  174 + }
  175 +
  176 + TN3270::Session & IPC::Session::push(const Action action) {
  177 +
  178 + return *this;
  179 + }
  180 +
  181 + TN3270::Session & IPC::Session::pop(int baddr, std::string &text) {
  182 +
  183 +
  184 + return *this;
  185 + }
  186 +
  187 + TN3270::Session & IPC::Session::pop(int row, int col, std::string &text) {
  188 +
  189 + return *this;
  190 + }
  191 +
  192 + TN3270::Session & IPC::Session::pop(std::string &text) {
  193 +
  194 + return *this;
  195 + }
  196 +
  197 + /// @brief Set cursor address.
  198 + ///
  199 + /// @param addr Cursor address.
  200 + void IPC::Session::setCursorPosition(unsigned short addr) {
  201 +
  202 +
  203 + }
  204 +
  205 + /// @brief Set cursor position.
  206 + ///
  207 + /// @param row New cursor row.
  208 + /// @param col New cursor column.
  209 + void IPC::Session::setCursorPosition(unsigned short row, unsigned short col) {
  210 +
  211 +
  212 + }
  213 +
  214 + }
  215 +
  216 +
... ...
src/lib3270++/lib3270++.cbp
... ... @@ -50,6 +50,7 @@
50 50 <Unit filename="abstract.cc" />
51 51 <Unit filename="events.cc" />
52 52 <Unit filename="host.cc" />
  53 + <Unit filename="ipc/session.cc" />
53 54 <Unit filename="local/events.cc" />
54 55 <Unit filename="local/session.cc" />
55 56 <Unit filename="private.h" />
... ...
src/lib3270++/private.h
... ... @@ -46,8 +46,11 @@
46 46 #include <winsock2.h>
47 47 #include <windows.h>
48 48 #include <ws2tcpip.h>
  49 + #else
  50 + #include <dbus/dbus.h>
49 51 #endif // WIN32
50 52  
  53 + #include <iostream>
51 54 #include <mutex>
52 55 #include <lib3270++.h>
53 56 #include <lib3270/popup.h>
... ... @@ -73,6 +76,31 @@
73 76 #define SYSTEM_CHARSET "UTF-8"
74 77 #endif // WIN32
75 78  
  79 +#ifdef DEBUG
  80 +
  81 + inline void console(std::ostream &out) {
  82 + out << std::endl;
  83 + }
  84 +
  85 + template<typename T, typename... Targs>
  86 + void console(std::ostream &out, T value, Targs... Fargs) {
  87 + out << value;
  88 + console(out, Fargs...);
  89 + }
  90 +
  91 + template<typename T, typename... Targs>
  92 + void log(T value, Targs... Fargs) {
  93 + console(std::clog,value,Fargs...);
  94 + }
  95 +
  96 + #define debug(...) log(__FILE__, "(", __LINE__, ") ", __VA_ARGS__);
  97 +
  98 +#else
  99 +
  100 + #define debug(...) /* __VA_ARGS__ */
  101 +
  102 +#endif
  103 +
76 104 namespace TN3270 {
77 105  
78 106 namespace Abstract {
... ... @@ -180,6 +208,8 @@
180 208 /// @brief IPC Based acess (Access and active instance of pw3270 or pw3270d)
181 209 namespace IPC {
182 210  
  211 + class Session;
  212 +
183 213 /// @brief PW3270 IPC Request/Response.
184 214 class Request {
185 215 private:
... ... @@ -203,22 +233,37 @@
203 233 static DWORD pack(std::vector<DataBlock *> &args, uint8_t * outBuffer, size_t szBuffer);
204 234 #else
205 235  
  236 + DBusMessage * msg;
  237 + DBusConnection * conn;
  238 +
206 239 #endif // _WIN32
207 240  
208 241 public:
209   - Request(const char *name);
  242 + Request(Session &session, const char *method);
  243 +
  244 + Request & call();
  245 + Request & push(const char *arg);
210 246  
211 247 };
212 248  
213 249 class TN3270_PRIVATE Session : public TN3270::Abstract::Session {
214 250 private:
  251 +
  252 + friend class Request;
  253 +
215 254 #ifdef _WIN32
216 255 /// @brief Pipe Handle.
217 256 HANDLE hPipe;
218 257 #else
219 258  
  259 + DBusConnection * conn;
  260 + std::string name; ///< @brief D-Bus Object name.
  261 + std::string path; ///< @brief D-Bus Object path.
  262 +
220 263 #endif // _WIN32
221 264  
  265 + void call(Request &request);
  266 +
222 267 public:
223 268  
224 269 Session(const char *id);
... ... @@ -255,7 +300,8 @@
255 300 TN3270::Session & pop(int baddr, std::string &text) override;
256 301 TN3270::Session & pop(int row, int col, std::string &text) override;
257 302 TN3270::Session & pop(std::string &text) override;
258   - }
  303 +
  304 + };
259 305  
260 306 }
261 307  
... ...
src/lib3270++/session.cc
... ... @@ -50,7 +50,7 @@
50 50 return new Local::Session();
51 51 }
52 52  
53   - throw std::system_error(EINVAL, std::system_category());
  53 + return new IPC::Session(id);
54 54  
55 55 }
56 56  
... ...
src/lib3270++/testprogram/testprogram.cc
... ... @@ -45,14 +45,16 @@
45 45  
46 46 int main(int argc, const char *argv[]) {
47 47  
48   - TN3270::Host host;
  48 + TN3270::Host host("pw3270:a");
49 49  
  50 + /*
50 51 host.connect(getenv("LIB3270_DEFAULT_HOST"));
51 52 cout << host << endl;
52 53  
53 54 host << TN3270::ENTER;
54 55  
55 56 cout << host << endl;
  57 + */
56 58  
57 59 return 0;
58 60 }
... ...