Commit 800fd1f696ade4e573285ed15e3c143449b57704

Authored by Perry Werneck
1 parent a016be86

Incluindo suporte para serviço pw3270 via D-Bus.

@@ -99,58 +99,10 @@ @@ -99,58 +99,10 @@
99 <Option target="Debug" /> 99 <Option target="Debug" />
100 <Option target="Release" /> 100 <Option target="Release" />
101 </Unit> 101 </Unit>
102 - <Unit filename="src/java/actions.cc">  
103 - <Option target="Debug" />  
104 - <Option target="Release" />  
105 - </Unit>  
106 - <Unit filename="src/java/call.cc">  
107 - <Option target="Debug" />  
108 - <Option target="Release" />  
109 - </Unit>  
110 - <Unit filename="src/java/clipboard.cc">  
111 - <Option target="Debug" />  
112 - <Option target="Release" />  
113 - </Unit>  
114 - <Unit filename="src/java/connect.cc">  
115 - <Option target="Debug" />  
116 - <Option target="Release" />  
117 - </Unit>  
118 - <Unit filename="src/java/cursor.cc">  
119 - <Option target="Debug" />  
120 - <Option target="Release" />  
121 - </Unit>  
122 - <Unit filename="src/java/dialog.cc">  
123 - <Option target="Debug" />  
124 - <Option target="Release" />  
125 - </Unit>  
126 - <Unit filename="src/java/field.cc">  
127 - <Option target="Debug" />  
128 - <Option target="Release" />  
129 - </Unit>  
130 - <Unit filename="src/java/getset.cc">  
131 - <Option target="Debug" />  
132 - <Option target="Release" />  
133 - </Unit>  
134 - <Unit filename="src/java/info.cc">  
135 - <Option target="Debug" />  
136 - <Option target="Release" />  
137 - </Unit>  
138 <Unit filename="src/java/jni3270.h"> 102 <Unit filename="src/java/jni3270.h">
139 <Option target="Debug" /> 103 <Option target="Debug" />
140 <Option target="Release" /> 104 <Option target="Release" />
141 </Unit> 105 </Unit>
142 - <Unit filename="src/java/keyboard.cc">  
143 - <Option target="Debug" />  
144 - <Option target="Release" />  
145 - </Unit>  
146 - <Unit filename="src/java/main.cc">  
147 - <Option target="Debug" />  
148 - <Option target="Release" />  
149 - </Unit>  
150 - <Unit filename="src/java/plugin.cc">  
151 - <Option target="Debug" />  
152 - <Option target="Release" />  
153 - </Unit>  
154 <Unit filename="src/java/private.h"> 106 <Unit filename="src/java/private.h">
155 <Option target="Debug" /> 107 <Option target="Debug" />
156 <Option target="Release" /> 108 <Option target="Release" />
@@ -167,10 +119,6 @@ @@ -167,10 +119,6 @@
167 <Option target="Debug" /> 119 <Option target="Debug" />
168 <Option target="Release" /> 120 <Option target="Release" />
169 </Unit> 121 </Unit>
170 - <Unit filename="src/java/startstop.cc">  
171 - <Option target="Debug" />  
172 - <Option target="Release" />  
173 - </Unit>  
174 <Unit filename="src/java/terminal.java"> 122 <Unit filename="src/java/terminal.java">
175 <Option target="Debug" /> 123 <Option target="Debug" />
176 <Option target="Release" /> 124 <Option target="Release" />
src/libpw3270cpp/Makefile.in
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 26
27 MODULE_NAME=libpw3270cpp 27 MODULE_NAME=libpw3270cpp
28 28
29 -SOURCES=session.cc exception.cc local.cc remote.cc module.cc 29 +SOURCES=session.cc exception.cc local.cc remote.cc service.cc module.cc
30 30
31 #---[ Configuration values ]------------------------------------------------------------- 31 #---[ Configuration values ]-------------------------------------------------------------
32 32
@@ -148,7 +148,7 @@ $(SRCDIR): \ @@ -148,7 +148,7 @@ $(SRCDIR): \
148 #---[ Debug Targets ]-------------------------------------------------------------------- 148 #---[ Debug Targets ]--------------------------------------------------------------------
149 149
150 Debug: \ 150 Debug: \
151 - $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a 151 + .bin/Debug/$(MODULE_NAME)@EXEEXT@
152 152
153 $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a: \ 153 $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a: \
154 $(foreach SRC, $(basename $(SOURCES)), $(OBJDBG)/$(SRC).o) 154 $(foreach SRC, $(basename $(SOURCES)), $(OBJDBG)/$(SRC).o)
@@ -157,14 +157,15 @@ $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a: \ @@ -157,14 +157,15 @@ $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a: \
157 @$(MKDIR) `dirname $@` 157 @$(MKDIR) `dirname $@`
158 @$(AR) rcs $@ $^ 158 @$(AR) rcs $@ $^
159 159
160 -$(BASEDIR)/.obj/Debug/$(MODULE_NAME)@EXEEXT@: \ 160 +.bin/Debug/$(MODULE_NAME)@EXEEXT@: \
161 $(OBJDBG)/testprogram.o \ 161 $(OBJDBG)/testprogram.o \
162 $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a 162 $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a
163 163
  164 + @$(MKDIR) `dirname $@`
164 @$(LD) $(APP_LDFLAGS) -o $@ $^ $(LIBS) 165 @$(LD) $(APP_LDFLAGS) -o $@ $^ $(LIBS)
165 166
166 run: \ 167 run: \
167 - $(BASEDIR)/.obj/Debug/$(MODULE_NAME)@EXEEXT@ 168 + .bin/Debug/$(MODULE_NAME)@EXEEXT@
168 169
169 ifeq ($(VALGRIND),no) 170 ifeq ($(VALGRIND),no)
170 $(BASEDIR)/.obj/Debug/$(MODULE_NAME)@EXEEXT@ 171 $(BASEDIR)/.obj/Debug/$(MODULE_NAME)@EXEEXT@
@@ -185,6 +186,7 @@ cleanDebug: @@ -185,6 +186,7 @@ cleanDebug:
185 186
186 @rm -fr $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a \ 187 @rm -fr $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a \
187 $(OBJDBG) 188 $(OBJDBG)
  189 + @rm -fr .bin
188 190
189 cleanRelease: 191 cleanRelease:
190 192
src/libpw3270cpp/classlib.cbp
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 <Option compiler="gcc" /> 8 <Option compiler="gcc" />
9 <Build> 9 <Build>
10 <Target title="Debug"> 10 <Target title="Debug">
11 - <Option output=".bin/Debug/testprogram" prefix_auto="1" extension_auto="1" /> 11 + <Option output=".bin/Debug/libpw3270cpp" prefix_auto="1" extension_auto="1" />
12 <Option object_output=".obj/Debug/" /> 12 <Option object_output=".obj/Debug/" />
13 <Option type="1" /> 13 <Option type="1" />
14 <Option compiler="gcc" /> 14 <Option compiler="gcc" />
@@ -40,6 +40,7 @@ @@ -40,6 +40,7 @@
40 <Unit filename="module.cc" /> 40 <Unit filename="module.cc" />
41 <Unit filename="private.h" /> 41 <Unit filename="private.h" />
42 <Unit filename="remote.cc" /> 42 <Unit filename="remote.cc" />
  43 + <Unit filename="service.cc" />
43 <Unit filename="session.cc" /> 44 <Unit filename="session.cc" />
44 <Unit filename="testprogram.cc" /> 45 <Unit filename="testprogram.cc" />
45 <Extensions> 46 <Extensions>
src/libpw3270cpp/private.h
@@ -107,7 +107,12 @@ @@ -107,7 +107,12 @@
107 107
108 #endif // !c11 108 #endif // !c11
109 109
  110 + namespace PW3270_NAMESPACE
  111 + {
110 112
  113 + session * create_service_client(const char *session) throw (std::exception);
  114 +
  115 + }
111 116
112 117
113 #endif // PRIVATE_H_INCLUDED 118 #endif // PRIVATE_H_INCLUDED
src/libpw3270cpp/remote.cc
@@ -77,6 +77,8 @@ @@ -77,6 +77,8 @@
77 #include <pw3270cpp.h> 77 #include <pw3270cpp.h>
78 #include <lib3270/log.h> 78 #include <lib3270/log.h>
79 79
  80 + #include "private.h"
  81 +
80 #if defined(HAVE_DBUS) 82 #if defined(HAVE_DBUS)
81 static const char * prefix_dest = "br.com.bb."; 83 static const char * prefix_dest = "br.com.bb.";
82 static const char * prefix_path = "/br/com/bb/"; 84 static const char * prefix_path = "/br/com/bb/";
@@ -1617,7 +1619,18 @@ @@ -1617,7 +1619,18 @@
1617 1619
1618 session * session::create_remote(const char *session) throw (std::exception) 1620 session * session::create_remote(const char *session) throw (std::exception)
1619 { 1621 {
1620 - return new remote(session); 1622 + debug("create(%s)",session);
  1623 +
  1624 + if(strncasecmp(session,"service://",10)) {
  1625 + return new remote(session);
  1626 + }
  1627 +
  1628 +#ifdef HAVE_DBUS
  1629 + return create_service_client(session+10);
  1630 +#else
  1631 + throw exception("Can't create session \"%s\"",session);
  1632 +#endif // HAVE_DBUS
  1633 +
1621 } 1634 }
1622 1635
1623 } 1636 }
src/libpw3270cpp/service.cc 0 → 100644
@@ -0,0 +1,409 @@ @@ -0,0 +1,409 @@
  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 service.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 + #include <lib3270/config.h>
  30 +
  31 + #include <iostream>
  32 + #include <stdio.h>
  33 + #include <dbus/dbus.h>
  34 + #include <string.h>
  35 + #include <malloc.h>
  36 + #include <sys/types.h>
  37 + #include <unistd.h>
  38 + #include <limits.h>
  39 +
  40 + #ifndef DBUS_TIMEOUT_INFINITE
  41 + #define DBUS_TIMEOUT_INFINITE ((int) 0x7fffffff)
  42 + #endif // !DBUS_TIMEOUT_INFINITE
  43 +
  44 + #include <pw3270cpp.h>
  45 + #include <lib3270/log.h>
  46 +
  47 +/*--[ Implement ]--------------------------------------------------------------------------------------------------*/
  48 +
  49 + #ifdef HAVE_DBUS
  50 + namespace PW3270_NAMESPACE
  51 + {
  52 + DBusConnection * conn;
  53 +
  54 + class client : public session
  55 + {
  56 + private:
  57 + DBusConnection * conn;
  58 + string id;
  59 +
  60 + DBusMessage * createMessage(const char *method)
  61 + {
  62 + DBusMessage * msg = dbus_message_new_method_call( "br.com.bb.pw3270.service", // Destination
  63 + "/br/com/bb/pw3270/service", // Path
  64 + "br.com.bb.pw3270.service", // Interface
  65 + method); // method
  66 +
  67 + if (!msg)
  68 + throw exception("Error creating DBUS message for method %s",method);
  69 +
  70 + return msg;
  71 +
  72 + }
  73 +
  74 + DBusMessage * call(DBusMessage *msg)
  75 + {
  76 + DBusMessage * reply;
  77 + DBusError error;
  78 +
  79 + dbus_error_init(&error);
  80 + reply = dbus_connection_send_with_reply_and_block(conn,msg,10000,&error);
  81 + dbus_message_unref(msg);
  82 +
  83 + if(dbus_error_is_set(&error))
  84 + {
  85 + exception e = exception("%s",error.message);
  86 + dbus_error_free(&error);
  87 + throw e;
  88 + }
  89 +
  90 + if(!reply)
  91 + {
  92 + exception e = exception("No reply for %s message","DBUS");
  93 + throw e;
  94 + }
  95 +
  96 + return reply;
  97 + }
  98 +
  99 + string getString(DBusMessage *msg)
  100 + {
  101 + string rc;
  102 +
  103 + if(msg)
  104 + {
  105 + DBusMessageIter iter;
  106 +
  107 + if(dbus_message_iter_init(msg, &iter))
  108 + {
  109 + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
  110 + {
  111 + const char * str;
  112 + dbus_message_iter_get_basic(&iter, &str);
  113 + trace("Response: [%s]",str);
  114 + rc.assign(str);
  115 + dbus_message_unref(msg);
  116 + return rc;
  117 + }
  118 +
  119 + exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32);
  120 + dbus_message_unref(msg);
  121 +
  122 + throw e;
  123 +
  124 + }
  125 +
  126 + }
  127 +
  128 + return rc;
  129 +
  130 + }
  131 +
  132 + string getString(const char *method)
  133 + {
  134 + return getString(call(createMessage(method)));
  135 + }
  136 +
  137 + protected:
  138 +
  139 + virtual string get_text(int baddr = 0, size_t len = 1)
  140 + {
  141 +
  142 + }
  143 +
  144 + virtual string get_text_at(int row, int col, size_t sz)
  145 + {
  146 +
  147 + }
  148 +
  149 + virtual int set_text_at(int row, int col, const char *str)
  150 + {
  151 +
  152 + }
  153 +
  154 + virtual int cmp_text_at(int row, int col, const char *text)
  155 + {
  156 +
  157 + }
  158 +
  159 + virtual int emulate_input(const char *str)
  160 + {
  161 +
  162 + }
  163 +
  164 + public:
  165 + client(const char *session) throw (std::exception)
  166 + {
  167 + DBusError err;
  168 +
  169 + dbus_error_init(&err);
  170 + conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
  171 +
  172 + if(dbus_error_is_set(&err))
  173 + {
  174 + exception e = exception("DBUS Connection Error (%s)", err.message);
  175 + dbus_error_free(&err);
  176 + throw e;
  177 + }
  178 +
  179 + if(!conn)
  180 + {
  181 + throw exception("%s", "DBUS Connection failed");
  182 + }
  183 +
  184 + if(*session != '?')
  185 + {
  186 + // Já tem sessão definida, usa.
  187 + this->id = session;
  188 + }
  189 + else
  190 + {
  191 + // Obter um ID de sessão no serviço
  192 + this->id = getString("createSession");
  193 + }
  194 +
  195 + trace("Session=%s",this->id.c_str());
  196 +
  197 + }
  198 +
  199 + virtual ~client()
  200 + {
  201 +
  202 + }
  203 +
  204 + virtual bool is_connected(void)
  205 + {
  206 +
  207 + }
  208 +
  209 + virtual bool is_ready(void)
  210 + {
  211 +
  212 + }
  213 +
  214 + virtual LIB3270_CSTATE get_cstate(void)
  215 + {
  216 +
  217 + }
  218 +
  219 + virtual LIB3270_MESSAGE get_program_message(void)
  220 + {
  221 +
  222 + }
  223 +
  224 + virtual LIB3270_SSL_STATE get_secure(void)
  225 + {
  226 +
  227 + }
  228 +
  229 + virtual int get_width(void)
  230 + {
  231 +
  232 + }
  233 +
  234 + virtual int get_height(void)
  235 + {
  236 +
  237 + }
  238 +
  239 + virtual int get_length(void)
  240 + {
  241 +
  242 + }
  243 +
  244 + virtual void set_unlock_delay(unsigned short ms)
  245 + {
  246 +
  247 + }
  248 +
  249 + virtual int set_host_charset(const char *charset)
  250 + {
  251 +
  252 + }
  253 +
  254 + virtual string get_host_charset(void)
  255 + {
  256 +
  257 + }
  258 +
  259 + virtual int connect(void)
  260 + {
  261 +
  262 + }
  263 +
  264 + virtual int set_url(const char *hostname)
  265 + {
  266 +
  267 + }
  268 +
  269 + virtual string get_url()
  270 + {
  271 +
  272 + }
  273 +
  274 + virtual int disconnect(void)
  275 + {
  276 +
  277 + }
  278 +
  279 + virtual int wait_for_ready(int seconds)
  280 + {
  281 +
  282 + }
  283 +
  284 + virtual int wait(int seconds)
  285 + {
  286 +
  287 + }
  288 +
  289 + virtual int iterate(bool wait = true)
  290 + {
  291 +
  292 + }
  293 +
  294 + virtual const char * asc2ebc(unsigned char *str, int sz = -1)
  295 + {
  296 +
  297 + }
  298 +
  299 + virtual const char * ebc2asc(unsigned char *str, int sz = -1)
  300 + {
  301 +
  302 + }
  303 +
  304 + virtual int set_cursor_position(int row, int col)
  305 + {
  306 +
  307 + }
  308 +
  309 + virtual int set_cursor_addr(int addr)
  310 + {
  311 +
  312 + }
  313 +
  314 + virtual int get_cursor_addr(void)
  315 + {
  316 +
  317 + }
  318 +
  319 + virtual int set_toggle(LIB3270_TOGGLE ix, bool value)
  320 + {
  321 +
  322 + }
  323 +
  324 + virtual int enter(void)
  325 + {
  326 +
  327 + }
  328 +
  329 + virtual int pfkey(int key)
  330 + {
  331 +
  332 + }
  333 +
  334 + virtual int pakey(int key)
  335 + {
  336 +
  337 + }
  338 +
  339 + virtual int quit(void)
  340 + {
  341 +
  342 + }
  343 +
  344 + virtual int action(const char *name)
  345 + {
  346 +
  347 + }
  348 +
  349 + virtual int erase(void)
  350 + {
  351 +
  352 + }
  353 +
  354 + virtual int erase_eof(void)
  355 + {
  356 +
  357 + }
  358 +
  359 + virtual int erase_eol(void)
  360 + {
  361 +
  362 + }
  363 +
  364 + virtual int erase_input(void)
  365 + {
  366 +
  367 + }
  368 +
  369 + virtual int print(void)
  370 + {
  371 +
  372 + }
  373 +
  374 + virtual int get_field_start(int baddr = -1)
  375 + {
  376 +
  377 + }
  378 +
  379 + virtual int get_field_len(int baddr = -1)
  380 + {
  381 +
  382 + }
  383 +
  384 + virtual int get_next_unprotected(int baddr = -1)
  385 + {
  386 +
  387 + }
  388 +
  389 + virtual int get_is_protected(int baddr = -1)
  390 + {
  391 +
  392 + }
  393 +
  394 + virtual int get_is_protected_at(int row, int col)
  395 + {
  396 +
  397 + }
  398 +
  399 +
  400 + };
  401 +
  402 + session * create_service_client(const char *session) throw (std::exception)
  403 + {
  404 + return new client(session);
  405 + }
  406 +
  407 +
  408 + }
  409 + #endif // HAVE_DBUS
src/libpw3270cpp/testprogram.cc
@@ -39,12 +39,15 @@ @@ -39,12 +39,15 @@
39 int main(int numpar, char *param[]) 39 int main(int numpar, char *param[])
40 { 40 {
41 41
  42 + try
42 { 43 {
43 string s; 44 string s;
44 - session *session = session::start("pw3270:a"); 45 + session *session = session::start("service://?");
45 // session *session = session::start(""); 46 // session *session = session::start("");
46 // session *session = session::start("new"); 47 // session *session = session::start("new");
47 48
  49 + return 0;
  50 +
48 cout << "pw3270 version: " << session->get_version() << endl; 51 cout << "pw3270 version: " << session->get_version() << endl;
49 cout << "pw3270 revision: " << session->get_revision() << endl << endl; 52 cout << "pw3270 revision: " << session->get_revision() << endl << endl;
50 53
@@ -74,6 +77,11 @@ @@ -74,6 +77,11 @@
74 session->disconnect(); 77 session->disconnect();
75 delete session; 78 delete session;
76 } 79 }
  80 + catch(std::exception &e) {
  81 +
  82 + cerr << e.what() << endl;
  83 + return -1;
  84 + }
77 85
78 // Waits 86 // Waits
79 sleep(2); 87 sleep(2);