Commit 46b42c1569baea6b3d0cc2acabdcb950a5d232ef

Authored by Perry Werneck
1 parent cea915fb

Working on windows IPC client module.

src/lib3270++/Makefile.in
... ... @@ -278,16 +278,6 @@ install-dev:
278 278  
279 279 #---[ Misc Targets ]---------------------------------------------------------------------
280 280  
281   -$(BASEDIR)/.tmp/$(LIBNAME)/fallbacks.c: \
282   - X3270.xad \
283   - $(wildcard mkfb/*.c)
284   -
285   - @$(MKDIR) `dirname $@`
286   - @$(MKDIR) $(BINDIR)
287   - @echo $< ...
288   - @$(HOST_CC) -g -o $(BINDIR)/mkfb@EXEEXT@ $(wildcard mkfb/*.c)
289   - @$(BINDIR)/mkfb@EXEEXT@ -c X3270.xad $@
290   -
291 281 $(POTDIR)/$(LIBNAME).pot: \
292 282 $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(LIBNAME)/$(SRC).pot)
293 283  
... ...
src/lib3270++/ipc/session.cc
... ... @@ -43,70 +43,8 @@
43 43  
44 44 /*---[ Implement ]----------------------------------------------------------------------------------*/
45 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 46 namespace TN3270 {
63 47  
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   - this->interface = "br.com.bb.tn3270.session";
93   -
94   - debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\"");
95   -
96   -#endif // _WIN32
97   -
98   - }
99   -
100   - IPC::Session::~Session() {
101   -
102   -#ifdef _WIN32
103   -
104   -#else
105   -
106   -#endif // _WIN32
107   -
108   - }
109   -
110 48 /*
111 49 void IPC::Session::wait(time_t timeout) {
112 50  
... ...
src/lib3270++/lib3270++.cbp
... ... @@ -52,12 +52,14 @@
52 52 <Unit filename="host.cc" />
53 53 <Unit filename="ipc/session.cc" />
54 54 <Unit filename="linux/request.cc" />
  55 + <Unit filename="linux/session.cc" />
55 56 <Unit filename="local/events.cc" />
56 57 <Unit filename="local/session.cc" />
57 58 <Unit filename="private.h" />
58 59 <Unit filename="session.cc" />
59 60 <Unit filename="testprogram/testprogram.cc" />
60 61 <Unit filename="windows/request.cc" />
  62 + <Unit filename="windows/session.cc" />
61 63 <Extensions>
62 64 <code_completion />
63 65 <envvars />
... ...
src/lib3270++/linux/session.cc 0 → 100644
... ... @@ -0,0 +1,98 @@
  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/linux/session.cc
  32 + *
  33 + * @brief Implements Linux session create/destroy session.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 + #include <cstring>
  41 + #include <lib3270/trace.h>
  42 +
  43 + using std::string;
  44 +
  45 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  46 +
  47 + static void throws_if_error(DBusError &err) {
  48 +
  49 + if(dbus_error_is_set(&err)) {
  50 + string message = err.message;
  51 + dbus_error_free(&err);
  52 + throw std::runtime_error(message.c_str());
  53 + }
  54 +
  55 + return;
  56 +
  57 + }
  58 +
  59 + namespace TN3270 {
  60 +
  61 + IPC::Session::Session(const char *id) : Abstract::Session() {
  62 +
  63 + // Create D-Bus session.
  64 + DBusError err;
  65 +
  66 + dbus_error_init(&err);
  67 + this->conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
  68 +
  69 + debug("dbus_bus_get conn=",conn);
  70 +
  71 + throws_if_error(err);
  72 +
  73 + if(!conn)
  74 + throw std::runtime_error("DBUS Connection failed");
  75 +
  76 + auto sep = strchr(id,':');
  77 + if(!sep) {
  78 + throw std::system_error(EINVAL, std::system_category());
  79 + }
  80 +
  81 + this->name = "br.com.bb.";
  82 + this->name += string(id,(sep - id));
  83 + this->name += ".";
  84 + this->name += (sep+1);
  85 + this->path = "/br/com/bb/tn3270/session";
  86 + this->interface = "br.com.bb.tn3270.session";
  87 +
  88 + debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\"");
  89 +
  90 + }
  91 +
  92 + IPC::Session::~Session() {
  93 +
  94 + }
  95 +
  96 + }
  97 +
  98 +
... ...
src/lib3270++/private.h
... ... @@ -223,6 +223,9 @@
223 223 private:
224 224  
225 225 #ifdef _WIN32
  226 + /// @brief Pipe Handle.
  227 + HANDLE hPipe;
  228 +
226 229 /// @brief IPC Data type.
227 230 enum Type : uint8_t {
228 231 String = 's',
... ... @@ -238,14 +241,14 @@
238 241 };
239 242  
240 243 struct {
241   - size_t length;
242   - size_t used;
  244 + DWORD length;
  245 + DWORD used;
243 246 uint8_t * block;
244 247 } in;
245 248  
246 249 struct {
247   - size_t length;
248   - size_t used;
  250 + DWORD length;
  251 + DWORD used;
249 252 uint8_t * block;
250 253 } out;
251 254  
... ...
src/lib3270++/testprogram/testprogram.cc
... ... @@ -45,7 +45,7 @@
45 45  
46 46 int main(int argc, const char *argv[]) {
47 47  
48   - TN3270::Host host; //{"pw3270:a"};
  48 + TN3270::Host host{"pw3270:a"};
49 49  
50 50 cout
51 51 << "Version: " << host.getVersion()
... ...
src/lib3270++/windows/request.cc
... ... @@ -48,13 +48,15 @@
48 48  
49 49 IPC::Request::Request(const Session &session) {
50 50  
  51 + this->hPipe = session.hPipe;
  52 +
51 53 in.length = PIPE_BUFFER_LENGTH;
52 54 in.used = 0;
53 55 in.block = new uint8_t[in.length];
54 56  
55 57 out.length = PIPE_BUFFER_LENGTH;
56 58 out.used = 0;
57   - out.block = new uint8_t[in.length];
  59 + out.block = new uint8_t[out.length];
58 60  
59 61 }
60 62  
... ... @@ -105,10 +107,6 @@
105 107  
106 108 }
107 109  
108   - IPC::Request & IPC::Request::call() {
109   - return *this;
110   - }
111   -
112 110 IPC::Request & IPC::Request::push(const char *arg) {
113 111 pushBlock(arg, strlen(arg)+1)->type = IPC::Request::String;
114 112 return *this;
... ...
src/lib3270++/windows/session.cc 0 → 100644
... ... @@ -0,0 +1,123 @@
  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/windows/session.cc
  32 + *
  33 + * @brief Implements Windows session create/destroy session.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 + #include <cstring>
  41 + #include <lib3270/trace.h>
  42 +
  43 + using std::string;
  44 +
  45 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  46 +
  47 + namespace TN3270 {
  48 +
  49 + IPC::Session::Session(const char *id) : Abstract::Session() {
  50 +
  51 + char *ptr = strchr(id,':');
  52 +
  53 + if(!ptr)
  54 + throw std::system_error(EINVAL, std::system_category());
  55 +
  56 + string pipename{"\\\\.\\pipe\\"};
  57 +
  58 + pipename += string(id,ptr - id);
  59 + pipename += "\\";
  60 + pipename += (ptr+1);
  61 +
  62 + debug("pipename: \"%s\"",pipename.c_str());
  63 +
  64 + this->hPipe = CreateFile(
  65 + TEXT(pipename.c_str()), // pipe name
  66 + GENERIC_READ | // read and write access
  67 + GENERIC_WRITE,
  68 + 0, // no sharing
  69 + NULL, // default security attributes
  70 + OPEN_EXISTING, // opens existing pipe
  71 + 0, // default attributes
  72 + NULL // no template file
  73 + );
  74 +
  75 + if (hPipe == INVALID_HANDLE_VALUE) {
  76 + throw std::runtime_error("Can't open IPC Channel");
  77 + }
  78 +
  79 + // The pipe connected; change to message-read mode.
  80 + DWORD dwMode = PIPE_READMODE_MESSAGE;
  81 + if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) {
  82 + throw std::runtime_error("Can't set IPC Channel mode");
  83 + }
  84 +
  85 + }
  86 +
  87 + IPC::Session::~Session() {
  88 + CloseHandle(this->hPipe);
  89 + }
  90 +
  91 +
  92 + IPC::Request & IPC::Request::call() {
  93 +
  94 +#ifdef DEBUG
  95 + lib3270_trace_data(NULL,"Request block",(const char *) this->out.block, this->out.used);
  96 +#endif // DEBUG
  97 +
  98 + if(!TransactNamedPipe(
  99 + this->hPipe,
  100 + this->out.block,
  101 + this->out.used,
  102 + this->in.block,
  103 + this->in.length,
  104 + &this->in.used,
  105 + NULL)
  106 + ) {
  107 +
  108 + throw std::runtime_error("Can't transact on IPC Channel");
  109 +
  110 + }
  111 +
  112 +#ifdef DEBUG
  113 + lib3270_trace_data(NULL,"Response block",(const char *) this->in.block, this->in.used);
  114 +#endif // DEBUG
  115 +
  116 + return *this;
  117 + }
  118 +
  119 +
  120 +
  121 + }
  122 +
  123 +
... ...