Commit b9f0d78eeed5c1df18aa6bedb984cfa6df46e212

Authored by perry.werneck@gmail.com
1 parent ef0594fa

Atualizando classe de referência

src/classlib/Makefile
@@ -57,7 +57,7 @@ DEBUG_CFLAGS=-DDEBUG=1 -g -Wall @@ -57,7 +57,7 @@ DEBUG_CFLAGS=-DDEBUG=1 -g -Wall
57 CXX=g++ 57 CXX=g++
58 LD=g++ 58 LD=g++
59 59
60 -DEPENDS=*.h ../include/*.h ../include/lib3270/*.h Makefile 60 +DEPENDS=../include/*.h ../include/lib3270/*.h ../include/pw3270/*.h Makefile
61 61
62 $(OBJDBG)/%.o: %.cc $(DEPENDS) 62 $(OBJDBG)/%.o: %.cc $(DEPENDS)
63 @echo " CC `basename $@`" 63 @echo " CC `basename $@`"
src/classlib/exception.cc
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 #include <stdarg.h> 30 #include <stdarg.h>
31 #include <stdio.h> 31 #include <stdio.h>
32 32
33 - #include "pw3270class.h" 33 + #include <pw3270/class.h>
34 34
35 /*--[ Implement ]--------------------------------------------------------------------------------------------------*/ 35 /*--[ Implement ]--------------------------------------------------------------------------------------------------*/
36 36
src/classlib/local.cc
@@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
46 46
47 #endif 47 #endif
48 48
49 -#include "pw3270class.h" 49 +#include <pw3270/class.h>
50 #include <lib3270/log.h> 50 #include <lib3270/log.h>
51 #include <lib3270/popup.h> 51 #include <lib3270/popup.h>
52 #include <string.h> 52 #include <string.h>
@@ -466,6 +466,20 @@ @@ -466,6 +466,20 @@
466 return new string(""); 466 return new string("");
467 } 467 }
468 468
  469 + int set_cursor_position(int row, int col)
  470 + {
  471 + return _set_cursor_position(hSession,row,col);
  472 + }
  473 +
  474 + int set_cursor_addr(int addr)
  475 + {
  476 + return _set_cursor_addr(hSession,addr);
  477 + }
  478 +
  479 + int get_cursor_addr(void)
  480 + {
  481 + return _get_cursor_addr(hSession);
  482 + }
469 483
470 }; 484 };
471 485
src/classlib/pw3270class.h
@@ -1,164 +0,0 @@ @@ -1,164 +0,0 @@
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., 59 Temple  
19 - * Place, Suite 330, Boston, MA, 02111-1307, USA  
20 - *  
21 - * Este programa está nomeado como pw3270class.c 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 -#ifndef PW3270_CLASS_H_INCLUDED  
31 -  
32 - #define PW3270_CLASS_H_INCLUDED 1  
33 -  
34 - #ifdef WIN32  
35 - #define SYSTEM_CHARSET "CP1252"  
36 - #else  
37 - #define SYSTEM_CHARSET "UTF-8"  
38 - #endif // WIN32  
39 -  
40 - #include <exception>  
41 - #include <lib3270/config.h>  
42 - #include <lib3270.h>  
43 -  
44 - #ifdef HAVE_ICONV  
45 - #include <iconv.h>  
46 - #endif // HAVE_ICONV  
47 -  
48 - #include <string>  
49 - #include <stdarg.h>  
50 - #include <lib3270.h>  
51 -  
52 - namespace pw3270  
53 - {  
54 - using namespace std;  
55 -  
56 - class exception : public std::exception  
57 - {  
58 - public:  
59 - exception(int code, const char *fmt, ...);  
60 - exception(const char *fmt, ...);  
61 -  
62 - virtual const char * what() const throw();  
63 -  
64 - private:  
65 - int code;  
66 - char msg[4096];  
67 -  
68 - };  
69 -  
70 - class session  
71 - {  
72 - public:  
73 -  
74 - session();  
75 - virtual ~session();  
76 -  
77 - // Factory methods and settings  
78 - static session * create(const char *name = 0);  
79 - static session * start(const char *name = 0);  
80 - static session * get_default(void);  
81 - static void set_plugin(session * (*factory)(const char *name));  
82 -  
83 - // Object settings  
84 - void set_charset(const char *charset);  
85 -  
86 - // Log management  
87 - void log(const char *fmt, ...);  
88 - void logva(const char *fmt, va_list args);  
89 -  
90 - // 3270 methods  
91 - virtual string get_version(void);  
92 - virtual string get_revision(void);  
93 -  
94 - virtual bool is_connected(void) = 0;  
95 - virtual bool is_ready(void) = 0;  
96 -  
97 - virtual LIB3270_CSTATE get_cstate(void) = 0;  
98 -  
99 - virtual int connect(const char *uri, bool wait = true) = 0;  
100 - virtual int disconnect(void) = 0;  
101 -  
102 - virtual int wait_for_ready(int seconds) = 0;  
103 - virtual int wait(int seconds) = 0;  
104 - virtual int iterate(bool wait = true) = 0;  
105 -  
106 - virtual string * get_text_at(int row, int col, size_t sz) = 0;  
107 - virtual int set_text_at(int row, int col, const char *str) = 0;  
108 - virtual string * get_text(int baddr, size_t len) = 0;  
109 - virtual int cmp_text_at(int row, int col, const char *text) = 0;  
110 - virtual int wait_for_text_at(int row, int col, const char *key, int timeout);  
111 -  
112 -// virtual int set_cursor_position(int row, int col) = 0;  
113 -// virtual int set_cursor_addr(int addr) = 0;  
114 -// virtual int get_cursor_addr(void) = 0;  
115 -  
116 -// virtual int set_toggle(LIB3270_TOGGLE ix, bool value) = 0;  
117 -  
118 -// virtual int enter(void) = 0;  
119 -// virtual int pfkey(int key) = 0;  
120 -// virtual int pakey(int key) = 0;  
121 -  
122 -// virtual int emulate_input(const char *str) = 0;  
123 -  
124 -// virtual int get_field_start(int baddr = -1) = 0;  
125 -// virtual int get_field_len(int baddr = -1) = 0;  
126 -// virtual int get_next_unprotected(int baddr = -1) = 0;  
127 -  
128 -// virtual int set_copy(const char *text);  
129 -// virtual char * get_copy(void);  
130 -  
131 -// virtual char * get_clipboard(void);  
132 -// virtual int set_clipboard(const char *text);  
133 -  
134 -// virtual int quit(void) = 0;  
135 -  
136 - // Dialogs  
137 -// virtual int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...);  
138 -// virtual char * file_chooser_dialog(GtkFileChooserAction action, const char *title, const char *extension, const char *filename);  
139 -  
140 - private:  
141 -  
142 - session * prev;  
143 - session * next;  
144 -  
145 - static session * first;  
146 - static session * last;  
147 -  
148 - static session * (*factory)(const char *name);  
149 -  
150 - static session * create_remote(const char *name);  
151 - static session * create_local(void);  
152 -  
153 -#ifdef HAVE_ICONV  
154 - iconv_t conv2Local;  
155 - iconv_t conv2Host;  
156 -#endif  
157 -  
158 - };  
159 -  
160 -  
161 - }  
162 -  
163 -  
164 -#endif // PW3270_CLASS_H_INCLUDED  
src/classlib/remote.cc
@@ -43,7 +43,7 @@ @@ -43,7 +43,7 @@
43 #include <pw3270/ipcpackets.h> 43 #include <pw3270/ipcpackets.h>
44 #endif // WIN32 44 #endif // WIN32
45 45
46 - #include "pw3270class.h" 46 + #include <pw3270/class.h>
47 #include <lib3270/log.h> 47 #include <lib3270/log.h>
48 48
49 #if defined(HAVE_DBUS) 49 #if defined(HAVE_DBUS)
@@ -63,6 +63,17 @@ @@ -63,6 +63,17 @@
63 63
64 HANDLE hPipe; 64 HANDLE hPipe;
65 65
  66 + int query_intval(HLLAPI_PACKET id)
  67 + {
  68 + struct hllapi_packet_query query = { id };
  69 + struct hllapi_packet_result response;
  70 + DWORD cbSize = sizeof(query);
  71 + if(TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL))
  72 + return response.rc;
  73 +
  74 + throw exception("Error %d in TransactNamedPipe",GetLastError());
  75 + }
  76 +
66 #elif defined(HAVE_DBUS) 77 #elif defined(HAVE_DBUS)
67 78
68 DBusConnection * conn; 79 DBusConnection * conn;
@@ -390,11 +401,7 @@ @@ -390,11 +401,7 @@
390 { 401 {
391 #if defined(WIN32) 402 #if defined(WIN32)
392 403
393 - static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED };  
394 - struct hllapi_packet_result response;  
395 - DWORD cbSize = sizeof(query);  
396 - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);  
397 - return response.rc != 0; 404 + return query_intval(HLLAPI_PACKET_IS_CONNECTED) != 0;
398 405
399 #elif defined(HAVE_DBUS) 406 #elif defined(HAVE_DBUS)
400 407
@@ -409,11 +416,7 @@ @@ -409,11 +416,7 @@
409 { 416 {
410 #if defined(WIN32) 417 #if defined(WIN32)
411 418
412 - static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CSTATE };  
413 - struct hllapi_packet_result response;  
414 - DWORD cbSize = sizeof(query);  
415 - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);  
416 - return (LIB3270_CSTATE) response.rc; 419 + return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE);
417 420
418 #elif defined(HAVE_DBUS) 421 #elif defined(HAVE_DBUS)
419 422
@@ -531,11 +534,7 @@ @@ -531,11 +534,7 @@
531 { 534 {
532 #if defined(WIN32) 535 #if defined(WIN32)
533 536
534 - static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_READY };  
535 - struct hllapi_packet_result response;  
536 - DWORD cbSize = sizeof(query);  
537 - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);  
538 - return response.rc != 0; 537 + return query_intval(HLLAPI_PACKET_IS_READY) != 0;
539 538
540 #elif defined(HAVE_DBUS) 539 #elif defined(HAVE_DBUS)
541 540
@@ -551,11 +550,7 @@ @@ -551,11 +550,7 @@
551 { 550 {
552 #if defined(WIN32) 551 #if defined(WIN32)
553 552
554 - static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT };  
555 - struct hllapi_packet_result response;  
556 - DWORD cbSize = sizeof(query);  
557 - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);  
558 - return 0; 553 + return query_intval(HLLAPI_PACKET_DISCONNECT);
559 554
560 #elif defined(HAVE_DBUS) 555 #elif defined(HAVE_DBUS)
561 556
@@ -776,6 +771,77 @@ @@ -776,6 +771,77 @@
776 } 771 }
777 772
778 773
  774 + int set_cursor_position(int row, int col)
  775 + {
  776 +#if defined(WIN32)
  777 +
  778 + struct hllapi_packet_cursor query = { HLLAPI_PACKET_SET_CURSOR_POSITION, (unsigned short) row, (unsigned short) col };
  779 + struct hllapi_packet_result response;
  780 + DWORD cbSize = sizeof(query);
  781 + TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  782 + return response.rc != 0;
  783 +
  784 +#elif defined(HAVE_DBUS)
  785 +
  786 + dbus_int32_t r = (dbus_int32_t) row;
  787 + dbus_int32_t c = (dbus_int32_t) col;
  788 +
  789 + DBusMessage * msg = create_message("setCursorAt");
  790 + if(msg)
  791 + {
  792 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID);
  793 + return get_intval(call(msg));
  794 + }
  795 +
  796 +#endif
  797 +
  798 + return -1;
  799 + }
  800 +
  801 + int set_cursor_addr(int addr)
  802 + {
  803 +#if defined(WIN32)
  804 +
  805 + struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, (unsigned short) addr };
  806 + struct hllapi_packet_result response;
  807 + DWORD cbSize = sizeof(query);
  808 + TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  809 + return response.rc;
  810 +
  811 +#elif defined(HAVE_DBUS)
  812 +
  813 + dbus_int32_t k = (dbus_int32_t) addr;
  814 +
  815 + DBusMessage * msg = create_message("setCursorAddress");
  816 + if(msg)
  817 + {
  818 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
  819 + return get_intval(call(msg));
  820 + }
  821 +
  822 +#endif
  823 +
  824 + return -1;
  825 + }
  826 +
  827 + int get_cursor_addr(void)
  828 + {
  829 +#if defined(WIN32)
  830 +
  831 + return query_intval(HLLAPI_PACKET_GET_CURSOR);
  832 +
  833 +#elif defined(HAVE_DBUS)
  834 +
  835 + return query_intval("getCursorAddress");
  836 +
  837 +#else
  838 +
  839 + return -1;
  840 +
  841 +#endif
  842 + }
  843 +
  844 +
779 }; 845 };
780 846
781 session * session::create_remote(const char *session) 847 session * session::create_remote(const char *session)
src/classlib/session.cc
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 #include <stdarg.h> 30 #include <stdarg.h>
31 #include <stdio.h> 31 #include <stdio.h>
32 32
33 - #include "pw3270class.h" 33 + #include <pw3270/class.h>
34 34
35 #ifdef HAVE_SYSLOG 35 #ifdef HAVE_SYSLOG
36 #include <syslog.h> 36 #include <syslog.h>
src/classlib/testprogram.cc
@@ -27,7 +27,7 @@ @@ -27,7 +27,7 @@
27 * 27 *
28 */ 28 */
29 29
30 - #include "pw3270class.h" 30 + #include <pw3270/class.h>
31 #include <iostream> 31 #include <iostream>
32 32
33 using namespace std; 33 using namespace std;
src/include/pw3270/class.h 0 → 100644
@@ -0,0 +1,164 @@ @@ -0,0 +1,164 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como pw3270class.c 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 +#ifndef PW3270_CLASS_H_INCLUDED
  31 +
  32 + #define PW3270_CLASS_H_INCLUDED 1
  33 +
  34 + #ifdef WIN32
  35 + #define SYSTEM_CHARSET "CP1252"
  36 + #else
  37 + #define SYSTEM_CHARSET "UTF-8"
  38 + #endif // WIN32
  39 +
  40 + #include <exception>
  41 + #include <lib3270/config.h>
  42 + #include <lib3270.h>
  43 +
  44 + #ifdef HAVE_ICONV
  45 + #include <iconv.h>
  46 + #endif // HAVE_ICONV
  47 +
  48 + #include <string>
  49 + #include <stdarg.h>
  50 + #include <lib3270.h>
  51 +
  52 + namespace pw3270
  53 + {
  54 + using namespace std;
  55 +
  56 + class exception : public std::exception
  57 + {
  58 + public:
  59 + exception(int code, const char *fmt, ...);
  60 + exception(const char *fmt, ...);
  61 +
  62 + virtual const char * what() const throw();
  63 +
  64 + private:
  65 + int code;
  66 + char msg[4096];
  67 +
  68 + };
  69 +
  70 + class session
  71 + {
  72 + public:
  73 +
  74 + session();
  75 + virtual ~session();
  76 +
  77 + // Factory methods and settings
  78 + static session * create(const char *name = 0);
  79 + static session * start(const char *name = 0);
  80 + static session * get_default(void);
  81 + static void set_plugin(session * (*factory)(const char *name));
  82 +
  83 + // Object settings
  84 + void set_charset(const char *charset);
  85 +
  86 + // Log management
  87 + void log(const char *fmt, ...);
  88 + void logva(const char *fmt, va_list args);
  89 +
  90 + // 3270 methods
  91 + virtual string get_version(void);
  92 + virtual string get_revision(void);
  93 +
  94 + virtual bool is_connected(void) = 0;
  95 + virtual bool is_ready(void) = 0;
  96 +
  97 + virtual LIB3270_CSTATE get_cstate(void) = 0;
  98 +
  99 + virtual int connect(const char *uri, bool wait = true) = 0;
  100 + virtual int disconnect(void) = 0;
  101 +
  102 + virtual int wait_for_ready(int seconds) = 0;
  103 + virtual int wait(int seconds) = 0;
  104 + virtual int iterate(bool wait = true) = 0;
  105 +
  106 + virtual string * get_text_at(int row, int col, size_t sz) = 0;
  107 + virtual int set_text_at(int row, int col, const char *str) = 0;
  108 + virtual string * get_text(int baddr, size_t len) = 0;
  109 + virtual int cmp_text_at(int row, int col, const char *text) = 0;
  110 + virtual int wait_for_text_at(int row, int col, const char *key, int timeout);
  111 +
  112 + virtual int set_cursor_position(int row, int col) = 0;
  113 + virtual int set_cursor_addr(int addr) = 0;
  114 + virtual int get_cursor_addr(void) = 0;
  115 +
  116 +// virtual int set_toggle(LIB3270_TOGGLE ix, bool value) = 0;
  117 +
  118 +// virtual int enter(void) = 0;
  119 +// virtual int pfkey(int key) = 0;
  120 +// virtual int pakey(int key) = 0;
  121 +
  122 +// virtual int emulate_input(const char *str) = 0;
  123 +
  124 +// virtual int get_field_start(int baddr = -1) = 0;
  125 +// virtual int get_field_len(int baddr = -1) = 0;
  126 +// virtual int get_next_unprotected(int baddr = -1) = 0;
  127 +
  128 +// virtual int set_copy(const char *text);
  129 +// virtual char * get_copy(void);
  130 +
  131 +// virtual char * get_clipboard(void);
  132 +// virtual int set_clipboard(const char *text);
  133 +
  134 +// virtual int quit(void) = 0;
  135 +
  136 + // Dialogs
  137 +// virtual int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...);
  138 +// virtual char * file_chooser_dialog(GtkFileChooserAction action, const char *title, const char *extension, const char *filename);
  139 +
  140 + private:
  141 +
  142 + session * prev;
  143 + session * next;
  144 +
  145 + static session * first;
  146 + static session * last;
  147 +
  148 + static session * (*factory)(const char *name);
  149 +
  150 + static session * create_remote(const char *name);
  151 + static session * create_local(void);
  152 +
  153 +#ifdef HAVE_ICONV
  154 + iconv_t conv2Local;
  155 + iconv_t conv2Host;
  156 +#endif
  157 +
  158 + };
  159 +
  160 +
  161 + }
  162 +
  163 +
  164 +#endif // PW3270_CLASS_H_INCLUDED
src/plugins/rx3270/remote.cc
@@ -1132,7 +1132,7 @@ int remote::set_cursor_addr(int addr) @@ -1132,7 +1132,7 @@ int remote::set_cursor_addr(int addr)
1132 1132
1133 if(hPipe != INVALID_HANDLE_VALUE) 1133 if(hPipe != INVALID_HANDLE_VALUE)
1134 { 1134 {
1135 - struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_LEN, (unsigned short) addr }; 1135 + struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, (unsigned short) addr };
1136 struct hllapi_packet_result response; 1136 struct hllapi_packet_result response;
1137 DWORD cbSize = sizeof(query); 1137 DWORD cbSize = sizeof(query);
1138 TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); 1138 TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);