diff --git a/src/lib3270++/Makefile.in b/src/lib3270++/Makefile.in index f2f55d0..b87c8bd 100644 --- a/src/lib3270++/Makefile.in +++ b/src/lib3270++/Makefile.in @@ -278,16 +278,6 @@ install-dev: #---[ Misc Targets ]--------------------------------------------------------------------- -$(BASEDIR)/.tmp/$(LIBNAME)/fallbacks.c: \ - X3270.xad \ - $(wildcard mkfb/*.c) - - @$(MKDIR) `dirname $@` - @$(MKDIR) $(BINDIR) - @echo $< ... - @$(HOST_CC) -g -o $(BINDIR)/mkfb@EXEEXT@ $(wildcard mkfb/*.c) - @$(BINDIR)/mkfb@EXEEXT@ -c X3270.xad $@ - $(POTDIR)/$(LIBNAME).pot: \ $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(LIBNAME)/$(SRC).pot) diff --git a/src/lib3270++/ipc/session.cc b/src/lib3270++/ipc/session.cc index 3a1f9a4..b6d53fe 100644 --- a/src/lib3270++/ipc/session.cc +++ b/src/lib3270++/ipc/session.cc @@ -43,70 +43,8 @@ /*---[ Implement ]----------------------------------------------------------------------------------*/ -#ifndef _WIN32 - - static void throws_if_error(DBusError &err) { - - if(dbus_error_is_set(&err)) { - string message = err.message; - dbus_error_free(&err); - throw std::runtime_error(message.c_str()); - } - - return; - - } - -#endif // _WIN32 - namespace TN3270 { - IPC::Session::Session(const char *id) : Abstract::Session() { - -#ifdef _WIN32 - -#else - // Create D-Bus session. - DBusError err; - - dbus_error_init(&err); - this->conn = dbus_bus_get(DBUS_BUS_SESSION, &err); - - debug("dbus_bus_get conn=",conn); - - throws_if_error(err); - - if(!conn) - throw std::runtime_error("DBUS Connection failed"); - - auto sep = strchr(id,':'); - if(!sep) { - throw std::system_error(EINVAL, std::system_category()); - } - - this->name = "br.com.bb."; - this->name += string(id,(sep - id)); - this->name += "."; - this->name += (sep+1); - this->path = "/br/com/bb/tn3270/session"; - this->interface = "br.com.bb.tn3270.session"; - - debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\""); - -#endif // _WIN32 - - } - - IPC::Session::~Session() { - -#ifdef _WIN32 - -#else - -#endif // _WIN32 - - } - /* void IPC::Session::wait(time_t timeout) { diff --git a/src/lib3270++/lib3270++.cbp b/src/lib3270++/lib3270++.cbp index 484a4a0..ae11564 100644 --- a/src/lib3270++/lib3270++.cbp +++ b/src/lib3270++/lib3270++.cbp @@ -52,12 +52,14 @@ + + diff --git a/src/lib3270++/linux/session.cc b/src/lib3270++/linux/session.cc new file mode 100644 index 0000000..2197ec8 --- /dev/null +++ b/src/lib3270++/linux/session.cc @@ -0,0 +1,98 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/ipc/linux/session.cc + * + * @brief Implements Linux session create/destroy session. + * + * @author perry.werneck@gmail.com + * + */ + + #include "../private.h" + #include + #include + + using std::string; + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + static void throws_if_error(DBusError &err) { + + if(dbus_error_is_set(&err)) { + string message = err.message; + dbus_error_free(&err); + throw std::runtime_error(message.c_str()); + } + + return; + + } + + namespace TN3270 { + + IPC::Session::Session(const char *id) : Abstract::Session() { + + // Create D-Bus session. + DBusError err; + + dbus_error_init(&err); + this->conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + + debug("dbus_bus_get conn=",conn); + + throws_if_error(err); + + if(!conn) + throw std::runtime_error("DBUS Connection failed"); + + auto sep = strchr(id,':'); + if(!sep) { + throw std::system_error(EINVAL, std::system_category()); + } + + this->name = "br.com.bb."; + this->name += string(id,(sep - id)); + this->name += "."; + this->name += (sep+1); + this->path = "/br/com/bb/tn3270/session"; + this->interface = "br.com.bb.tn3270.session"; + + debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\""); + + } + + IPC::Session::~Session() { + + } + + } + + diff --git a/src/lib3270++/private.h b/src/lib3270++/private.h index c8c57ba..955a086 100644 --- a/src/lib3270++/private.h +++ b/src/lib3270++/private.h @@ -223,6 +223,9 @@ private: #ifdef _WIN32 + /// @brief Pipe Handle. + HANDLE hPipe; + /// @brief IPC Data type. enum Type : uint8_t { String = 's', @@ -238,14 +241,14 @@ }; struct { - size_t length; - size_t used; + DWORD length; + DWORD used; uint8_t * block; } in; struct { - size_t length; - size_t used; + DWORD length; + DWORD used; uint8_t * block; } out; diff --git a/src/lib3270++/testprogram/testprogram.cc b/src/lib3270++/testprogram/testprogram.cc index 9e728ea..d4f5a7a 100644 --- a/src/lib3270++/testprogram/testprogram.cc +++ b/src/lib3270++/testprogram/testprogram.cc @@ -45,7 +45,7 @@ int main(int argc, const char *argv[]) { - TN3270::Host host; //{"pw3270:a"}; + TN3270::Host host{"pw3270:a"}; cout << "Version: " << host.getVersion() diff --git a/src/lib3270++/windows/request.cc b/src/lib3270++/windows/request.cc index 7be6200..0721429 100644 --- a/src/lib3270++/windows/request.cc +++ b/src/lib3270++/windows/request.cc @@ -48,13 +48,15 @@ IPC::Request::Request(const Session &session) { + this->hPipe = session.hPipe; + in.length = PIPE_BUFFER_LENGTH; in.used = 0; in.block = new uint8_t[in.length]; out.length = PIPE_BUFFER_LENGTH; out.used = 0; - out.block = new uint8_t[in.length]; + out.block = new uint8_t[out.length]; } @@ -105,10 +107,6 @@ } - IPC::Request & IPC::Request::call() { - return *this; - } - IPC::Request & IPC::Request::push(const char *arg) { pushBlock(arg, strlen(arg)+1)->type = IPC::Request::String; return *this; diff --git a/src/lib3270++/windows/session.cc b/src/lib3270++/windows/session.cc new file mode 100644 index 0000000..f2986a2 --- /dev/null +++ b/src/lib3270++/windows/session.cc @@ -0,0 +1,123 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/ipc/windows/session.cc + * + * @brief Implements Windows session create/destroy session. + * + * @author perry.werneck@gmail.com + * + */ + + #include "../private.h" + #include + #include + + using std::string; + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + namespace TN3270 { + + IPC::Session::Session(const char *id) : Abstract::Session() { + + char *ptr = strchr(id,':'); + + if(!ptr) + throw std::system_error(EINVAL, std::system_category()); + + string pipename{"\\\\.\\pipe\\"}; + + pipename += string(id,ptr - id); + pipename += "\\"; + pipename += (ptr+1); + + debug("pipename: \"%s\"",pipename.c_str()); + + this->hPipe = CreateFile( + TEXT(pipename.c_str()), // pipe name + GENERIC_READ | // read and write access + GENERIC_WRITE, + 0, // no sharing + NULL, // default security attributes + OPEN_EXISTING, // opens existing pipe + 0, // default attributes + NULL // no template file + ); + + if (hPipe == INVALID_HANDLE_VALUE) { + throw std::runtime_error("Can't open IPC Channel"); + } + + // The pipe connected; change to message-read mode. + DWORD dwMode = PIPE_READMODE_MESSAGE; + if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) { + throw std::runtime_error("Can't set IPC Channel mode"); + } + + } + + IPC::Session::~Session() { + CloseHandle(this->hPipe); + } + + + IPC::Request & IPC::Request::call() { + +#ifdef DEBUG + lib3270_trace_data(NULL,"Request block",(const char *) this->out.block, this->out.used); +#endif // DEBUG + + if(!TransactNamedPipe( + this->hPipe, + this->out.block, + this->out.used, + this->in.block, + this->in.length, + &this->in.used, + NULL) + ) { + + throw std::runtime_error("Can't transact on IPC Channel"); + + } + +#ifdef DEBUG + lib3270_trace_data(NULL,"Response block",(const char *) this->in.block, this->in.used); +#endif // DEBUG + + return *this; + } + + + + } + + -- libgit2 0.21.2