Commit 57ededa09263451bbe964fbfedfa81b02c3a1324
1 parent
d737223e
Exists in
master
and in
5 other branches
Iniciando migração do objeto rexx para a classe referência
Showing
17 changed files
with
212 additions
and
2141 deletions
Show diff stats
pw3270.cbp
... | ... | @@ -61,6 +61,13 @@ |
61 | 61 | <Unit filename="pw3270-x86_64.nsi.in" /> |
62 | 62 | <Unit filename="pw3270.nsi.in" /> |
63 | 63 | <Unit filename="pw3270.spec.in" /> |
64 | + <Unit filename="src/classlib/Makefile.in" /> | |
65 | + <Unit filename="src/classlib/class.mak.in" /> | |
66 | + <Unit filename="src/classlib/exception.cc" /> | |
67 | + <Unit filename="src/classlib/local.cc" /> | |
68 | + <Unit filename="src/classlib/remote.cc" /> | |
69 | + <Unit filename="src/classlib/session.cc" /> | |
70 | + <Unit filename="src/classlib/testprogram.cc" /> | |
64 | 71 | <Unit filename="src/include/lib3270.h" /> |
65 | 72 | <Unit filename="src/include/lib3270/action_table.h" /> |
66 | 73 | <Unit filename="src/include/lib3270/actions.h" /> |
... | ... | @@ -76,6 +83,7 @@ |
76 | 83 | <Unit filename="src/include/lib3270/trace.h" /> |
77 | 84 | <Unit filename="src/include/plugin.mak.in" /> |
78 | 85 | <Unit filename="src/include/pw3270.h" /> |
86 | + <Unit filename="src/include/pw3270/class.h" /> | |
79 | 87 | <Unit filename="src/include/pw3270/hllapi.h" /> |
80 | 88 | <Unit filename="src/include/pw3270/ipcpackets.h" /> |
81 | 89 | <Unit filename="src/include/pw3270/plugin.h" /> | ... | ... |
src/classlib/classlib.cbp
src/classlib/exception.cc
src/classlib/local.cc
src/classlib/remote.cc
src/classlib/session.cc
... | ... | @@ -40,7 +40,7 @@ |
40 | 40 | |
41 | 41 | /*--[ Implement ]--------------------------------------------------------------------------------------------------*/ |
42 | 42 | |
43 | - namespace pw3270 | |
43 | + namespace PW3270_NAMESPACE | |
44 | 44 | { |
45 | 45 | session * session::first = 0; |
46 | 46 | session * session::last = 0; | ... | ... |
src/classlib/testprogram.cc
src/include/pw3270/class.h
src/plugins/rx3270/Makefile.in
... | ... | @@ -29,7 +29,8 @@ |
29 | 29 | MODULE_NAME=rx3270 |
30 | 30 | DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile |
31 | 31 | PLUGIN_SRC=pluginmain.cc |
32 | -EXTAPI_SRC=rxapimain.cc text.cc typed_routines.cc local.cc remote.cc rexx_methods.cc rx3270.cc exception.cc | |
32 | +# EXTAPI_SRC=rxapimain.cc text.cc typed_routines.cc local.cc remote.cc rexx_methods.cc rx3270.cc exception.cc | |
33 | +EXTAPI_SRC=rxapimain.cc typed_routines.cc rexx_methods.cc | |
33 | 34 | |
34 | 35 | #---[ Tools ]------------------------------------------------------------------ |
35 | 36 | |
... | ... | @@ -43,7 +44,10 @@ CFLAGS=@REXX_CFLAGS@ @DBUS_CFLAGS@ |
43 | 44 | REXX_HOME=@REXX_HOME@ |
44 | 45 | REXXLIBDIR=$(libdir)/ooRexx |
45 | 46 | |
47 | +CLASSLIBDIR=../../classlib | |
48 | + | |
46 | 49 | include ../../include/plugin.mak |
50 | +include $(CLASSLIBDIR)/class.mak | |
47 | 51 | |
48 | 52 | #---[ Debug Targets ]---------------------------------------------------------- |
49 | 53 | |
... | ... | @@ -52,7 +56,7 @@ $(BINDBG)/$(PLUGIN_NAME): $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$( |
52 | 56 | @$(MKDIR) `dirname $@` |
53 | 57 | @$(CXX) $(DLL_FLAGS) @LDSOFLAGS@ @DBGRPATH@ $(LDFLAGS) -o $@ $^ $(LIBS) $(LIB3270_LIBS) $(GTK_LIBS) $(GLIB_LIBS) $(PW3270_LIBS) |
54 | 58 | |
55 | -$(BINDBG)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC)), $(OBJDBG)/$(SRC)@OBJEXT@) | |
59 | +$(BINDBG)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC) $(CLASS_SRC)), $(OBJDBG)/$(SRC)@OBJEXT@) | |
56 | 60 | @echo " CCLD `basename $@`" |
57 | 61 | @$(MKDIR) `dirname $@` |
58 | 62 | @$(CXX) $(DLL_FLAGS) $(LDFLAGS) @LDSOFLAGS@ @DBGRPATH@ -o $@ $^ $(LIBS) $(LIB3270_LIBS) | ... | ... |
src/plugins/rx3270/exception.cc
... | ... | @@ -1,104 +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 exception.cc 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 | - #include "rx3270.h" | |
31 | - | |
32 | -#ifdef HAVE_SYSLOG | |
33 | - #include <syslog.h> | |
34 | -#endif // HAVE_SYSLOG | |
35 | - | |
36 | - #include <string.h> | |
37 | - #include <oorexxerrors.h> | |
38 | - | |
39 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
40 | - | |
41 | -rx3270::exception::exception(const char *fmt, ...) | |
42 | -{ | |
43 | - va_list arg_ptr; | |
44 | - | |
45 | - va_start(arg_ptr, fmt); | |
46 | - vsnprintf(this->msg,4095,fmt,arg_ptr); | |
47 | - va_end(arg_ptr); | |
48 | - | |
49 | - this->code = Rexx_Error_Application_error; | |
50 | -} | |
51 | - | |
52 | -rx3270::exception::exception(int code, const char *fmt, ...) | |
53 | -{ | |
54 | - va_list arg_ptr; | |
55 | - | |
56 | - va_start(arg_ptr, fmt); | |
57 | - vsnprintf(this->msg,4095,fmt,arg_ptr); | |
58 | - va_end(arg_ptr); | |
59 | - | |
60 | - this->code = code; | |
61 | - | |
62 | -} | |
63 | - | |
64 | - | |
65 | -const char * rx3270::exception::getMessage(void) | |
66 | -{ | |
67 | - return this->msg; | |
68 | -} | |
69 | - | |
70 | -void rx3270::exception::logMessage(void) | |
71 | -{ | |
72 | -#ifdef HAVE_SYSLOG | |
73 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
74 | - syslog(LOG_INFO,"%s",this->getMessage()); | |
75 | - closelog(); | |
76 | -#else | |
77 | - fprintf(stderr,"%s",this->getMessage()); | |
78 | -#endif | |
79 | -} | |
80 | - | |
81 | -void rx3270::exception::RaiseException(RexxMethodContext *context) | |
82 | -{ | |
83 | - trace("%s: %s",__FUNCTION__,this->getMessage()); | |
84 | - logMessage(); | |
85 | - | |
86 | - context->RaiseException1( this->code, | |
87 | - context->NewStringFromAsciiz(this->msg) | |
88 | - ); | |
89 | -} | |
90 | - | |
91 | -void rx3270::exception::RaiseException(RexxCallContext *context) | |
92 | -{ | |
93 | - trace("%s: %s",__FUNCTION__,this->getMessage()); | |
94 | - logMessage(); | |
95 | - | |
96 | - context->RaiseException1( this->code, | |
97 | - context->NewStringFromAsciiz(this->msg) | |
98 | - ); | |
99 | -} | |
100 | - | |
101 | -const char * rx3270::exception::what() const throw() | |
102 | -{ | |
103 | - return this->msg; | |
104 | -} |
src/plugins/rx3270/local.cc
... | ... | @@ -1,596 +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 local.cc 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 | - #include "rx3270.h" | |
31 | - #include <string.h> | |
32 | - | |
33 | -#if !defined WIN32 | |
34 | - #include <dlfcn.h> | |
35 | - #include <stdio.h> | |
36 | -#endif | |
37 | - | |
38 | -#ifdef HAVE_SYSLOG | |
39 | - #include <syslog.h> | |
40 | - #include <stdarg.h> | |
41 | -#endif // HAVE_SYSLOG | |
42 | - | |
43 | -// http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx | |
44 | -#ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
45 | - #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 | |
46 | -#endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
47 | - | |
48 | -#ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
49 | - #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 | |
50 | -#endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
51 | - | |
52 | -/*--[ Class definition ]-----------------------------------------------------------------------------*/ | |
53 | - | |
54 | - class dynamic : public rx3270 | |
55 | - { | |
56 | - public: | |
57 | - dynamic(); | |
58 | - ~dynamic(); | |
59 | - | |
60 | - char * get_version(void); | |
61 | - LIB3270_CSTATE get_cstate(void); | |
62 | - int disconnect(void); | |
63 | - int connect(const char *uri, bool wait = true); | |
64 | - bool is_connected(void); | |
65 | - bool is_ready(void); | |
66 | - | |
67 | - int iterate(bool wait); | |
68 | - int wait(int seconds); | |
69 | - int wait_for_ready(int seconds); | |
70 | - | |
71 | - char * get_text(int baddr, size_t len); | |
72 | - char * get_text_at(int row, int col, size_t sz); | |
73 | - int cmp_text_at(int row, int col, const char *text); | |
74 | - int set_text_at(int row, int col, const char *str); | |
75 | - int emulate_input(const char *str); | |
76 | - | |
77 | - int set_cursor_position(int row, int col); | |
78 | - int set_cursor_addr(int addr); | |
79 | - int get_cursor_addr(void); | |
80 | - | |
81 | - int set_toggle(LIB3270_TOGGLE ix, bool value); | |
82 | - | |
83 | - int enter(void); | |
84 | - int pfkey(int key); | |
85 | - int pakey(int key); | |
86 | - | |
87 | - int get_field_start(int baddr = -1); | |
88 | - int get_field_len(int baddr = -1); | |
89 | - int get_next_unprotected(int baddr = -1); | |
90 | - | |
91 | - int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...); | |
92 | - | |
93 | - int quit(void); | |
94 | - | |
95 | - private: | |
96 | - | |
97 | - const char * (*_get_version)(void); | |
98 | - LIB3270_CSTATE (*_get_connection_state)(H3270 *h); | |
99 | - int (*_disconnect)(H3270 *h); | |
100 | - int (*_connect)(H3270 *h,const char *n, int wait); | |
101 | - int (*_is_connected)(H3270 *h); | |
102 | - void (*_main_iterate)(H3270 *h, int wait); | |
103 | - int (*_wait)(H3270 *hSession, int seconds); | |
104 | - int (*_enter)(H3270 *hSession); | |
105 | - int (*_pfkey)(H3270 *hSession, int key); | |
106 | - int (*_pakey)(H3270 *hSession, int key); | |
107 | - int (*_wait_for_ready)(H3270 *hSession, int seconds); | |
108 | - char * (*_get_text)(H3270 *h, int offset, int len); | |
109 | - char * (*_get_text_at)(H3270 *h, int row, int col, int len); | |
110 | - int (*_cmp_text_at)(H3270 *h, int row, int col, const char *text); | |
111 | - int (*_set_text_at)(H3270 *h, int row, int col, const unsigned char *str); | |
112 | - int (*_is_ready)(H3270 *h); | |
113 | - int (*_set_cursor_position)(H3270 *h, int row, int col); | |
114 | - int (*_set_toggle)(H3270 *h, LIB3270_TOGGLE ix, int value); | |
115 | - int (*_get_field_start)(H3270 *h, int baddr); | |
116 | - int (*_get_field_len)(H3270 *h, int baddr); | |
117 | - int (*_set_cursor_addr)(H3270 *h, int addr); | |
118 | - int (*_get_cursor_addr)(H3270 *h); | |
119 | - int (*_emulate_input)(H3270 *session, const char *s, int len, int pasting); | |
120 | - int (*_get_next_unprotected)(H3270 *hSession, int baddr0); | |
121 | - void (*_popup_va)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, va_list); | |
122 | - | |
123 | -#ifdef WIN32 | |
124 | - HMODULE hModule; | |
125 | -#else | |
126 | - void * hModule; | |
127 | -#endif // WIN32 | |
128 | - | |
129 | - H3270 * hSession; | |
130 | - | |
131 | - }; | |
132 | - | |
133 | -/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
134 | - | |
135 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
136 | - | |
137 | -rx3270 * rx3270::create_local(void) | |
138 | -{ | |
139 | - trace("%s",__FUNCTION__); | |
140 | - return new dynamic(); | |
141 | -} | |
142 | - | |
143 | -#ifdef WIN32 | |
144 | -static int get_datadir(LPSTR datadir) | |
145 | -{ | |
146 | - HKEY hKey = 0; | |
147 | - unsigned long datalen = strlen(datadir); | |
148 | - | |
149 | - *datadir = 0; | |
150 | - | |
151 | - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) | |
152 | - { | |
153 | - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
154 | - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) | |
155 | - *datadir = 0; | |
156 | - RegCloseKey(hKey); | |
157 | - } | |
158 | - | |
159 | - return *datadir; | |
160 | -} | |
161 | -#endif // WIN32 | |
162 | - | |
163 | -extern "C" | |
164 | -{ | |
165 | - | |
166 | -static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) | |
167 | -{ | |
168 | -#ifdef HAVE_SYSLOG | |
169 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
170 | - vsyslog(LOG_INFO,fmt,args); | |
171 | - closelog(); | |
172 | -#endif // HAVE_SYSLOG | |
173 | -} | |
174 | - | |
175 | -static void tracehandler(H3270 *session, const char *fmt, va_list args) | |
176 | -{ | |
177 | -#ifdef HAVE_SYSLOG | |
178 | - | |
179 | - #define MAX_LOG_LENGTH 200 | |
180 | - | |
181 | - static char line[MAX_LOG_LENGTH+1]; | |
182 | - char temp[MAX_LOG_LENGTH]; | |
183 | - char * ptr; | |
184 | - size_t len = strlen(line); | |
185 | - | |
186 | - vsnprintf(temp,MAX_LOG_LENGTH-len,fmt,args); | |
187 | - | |
188 | - ptr = strchr(temp,'\n'); | |
189 | - if(!ptr) | |
190 | - { | |
191 | - strncat(line,temp,MAX_LOG_LENGTH); | |
192 | - if(strlen(line) >= MAX_LOG_LENGTH) | |
193 | - { | |
194 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
195 | - syslog(LOG_INFO,line); | |
196 | - closelog(); | |
197 | - *line = 0; | |
198 | - } | |
199 | - return; | |
200 | - } | |
201 | - | |
202 | - *ptr = 0; | |
203 | - strncat(line,temp,MAX_LOG_LENGTH); | |
204 | - | |
205 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
206 | - syslog(LOG_DEBUG,line); | |
207 | - closelog(); | |
208 | - | |
209 | - strncpy(line,ptr+1,MAX_LOG_LENGTH); | |
210 | - | |
211 | -#endif // HAVE_SYSLOG | |
212 | -} | |
213 | - | |
214 | -} | |
215 | - | |
216 | -dynamic::dynamic() | |
217 | -{ | |
218 | - H3270 * (*lib3270_new)(const char *); | |
219 | - void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); | |
220 | - void (*set_trace_handler)( void (*handler)(H3270 *session, const char *fmt, va_list args) ); | |
221 | - | |
222 | - struct _call | |
223 | - { | |
224 | - void **entry; | |
225 | - const char * name; | |
226 | - } call[] = | |
227 | - { | |
228 | - { (void **) & lib3270_new, "lib3270_session_new" }, | |
229 | - { (void **) & set_log_handler, "lib3270_set_log_handler" }, | |
230 | - { (void **) & set_trace_handler, "lib3270_set_trace_handler" }, | |
231 | - { (void **) & _get_version, "lib3270_get_version" }, | |
232 | - { (void **) & _get_connection_state, "lib3270_get_connection_state" }, | |
233 | - { (void **) & _disconnect, "lib3270_disconnect" }, | |
234 | - { (void **) & _connect, "lib3270_connect" }, | |
235 | - { (void **) & _is_connected, "lib3270_in_tn3270e" }, | |
236 | - { (void **) & _main_iterate, "lib3270_main_iterate" }, | |
237 | - { (void **) & _wait, "lib3270_wait" }, | |
238 | - { (void **) & _enter, "lib3270_enter" }, | |
239 | - { (void **) & _pfkey, "lib3270_pfkey" }, | |
240 | - { (void **) & _pakey, "lib3270_pakey" }, | |
241 | - { (void **) & _wait_for_ready, "lib3270_wait_for_ready" }, | |
242 | - { (void **) & _get_text, "lib3270_get_text" }, | |
243 | - { (void **) & _get_text_at, "lib3270_get_text_at" }, | |
244 | - { (void **) & _cmp_text_at, "lib3270_cmp_text_at" }, | |
245 | - { (void **) & _set_text_at, "lib3270_set_string_at" }, | |
246 | - { (void **) & _is_ready, "lib3270_is_ready" }, | |
247 | - { (void **) & _set_cursor_position, "lib3270_set_cursor_position" }, | |
248 | - { (void **) & _set_toggle, "lib3270_set_toggle" }, | |
249 | - { (void **) & _get_field_start, "lib3270_get_field_start" }, | |
250 | - { (void **) & _get_field_len, "lib3270_get_field_len" }, | |
251 | - { (void **) & _set_cursor_addr, "lib3270_set_cursor_address" }, | |
252 | - { (void **) & _get_cursor_addr, "lib3270_get_cursor_address" }, | |
253 | - { (void **) & _emulate_input, "lib3270_emulate_input" }, | |
254 | - { (void **) & _get_next_unprotected, "lib3270_get_next_unprotected" }, | |
255 | - { (void **) & _popup_va, "lib3270_popup_va" }, | |
256 | - }; | |
257 | - | |
258 | -// Load lib3270.dll | |
259 | -#ifdef WIN32 | |
260 | - static const char *dllname = "lib3270.dll." PACKAGE_VERSION; | |
261 | - | |
262 | - HMODULE kernel; | |
263 | - HANDLE cookie = NULL; | |
264 | - DWORD rc; | |
265 | - HANDLE WINAPI (*AddDllDirectory)(PCWSTR NewDirectory); | |
266 | - BOOL WINAPI (*RemoveDllDirectory)(HANDLE Cookie); | |
267 | - UINT errorMode; | |
268 | - char datadir[4096]; | |
269 | - char buffer[4096]; | |
270 | - | |
271 | - kernel = LoadLibrary("kernel32.dll"); | |
272 | - AddDllDirectory = (HANDLE WINAPI (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); | |
273 | - RemoveDllDirectory = (BOOL WINAPI (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); | |
274 | - | |
275 | - // Notify user in case of error loading protocol DLL | |
276 | - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx | |
277 | - errorMode = SetErrorMode(1); | |
278 | - | |
279 | - memset(datadir,' ',4095); | |
280 | - datadir[4095] = 0; | |
281 | - | |
282 | - if(get_datadir(datadir)) | |
283 | - { | |
284 | - trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory); | |
285 | - | |
286 | - if(AddDllDirectory) | |
287 | - { | |
288 | - wchar_t *path = (wchar_t *) malloc(4096*sizeof(wchar_t)); | |
289 | - mbstowcs(path, datadir, 4095); | |
290 | - cookie = AddDllDirectory(path); | |
291 | - free(path); | |
292 | - } | |
293 | - | |
294 | -#ifdef DEBUG | |
295 | - snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname); | |
296 | -#else | |
297 | - snprintf(buffer,4096,"%s\\%s",datadir,dllname); | |
298 | -#endif // DEBUG | |
299 | - | |
300 | - trace("Loading [%s] [%s]",buffer,datadir); | |
301 | - hModule = LoadLibrary(buffer); | |
302 | - | |
303 | - trace("Module=%p rc=%d",hModule,(int) GetLastError()); | |
304 | - | |
305 | - if(hModule == NULL) | |
306 | - { | |
307 | - // Enable DLL error popup and try again with full path | |
308 | - SetErrorMode(0); | |
309 | - hModule = LoadLibraryEx(buffer,NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); | |
310 | - } | |
311 | - | |
312 | - rc = GetLastError(); | |
313 | - | |
314 | - trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc); | |
315 | - } | |
316 | - else | |
317 | - { | |
318 | - hModule = LoadLibrary(dllname); | |
319 | - rc = GetLastError(); | |
320 | - } | |
321 | - | |
322 | - SetErrorMode(errorMode); | |
323 | - | |
324 | - trace("%s hModule=%p rc=%d",dllname,hModule,(int) rc); | |
325 | - | |
326 | - if(cookie && RemoveDllDirectory) | |
327 | - RemoveDllDirectory(cookie); | |
328 | - | |
329 | - if(kernel) | |
330 | - FreeLibrary(kernel); | |
331 | - | |
332 | - if(!hModule) | |
333 | - throw exception("Can't load %s",dllname); | |
334 | - | |
335 | - | |
336 | -#else | |
337 | - dlerror(); | |
338 | - | |
339 | - hModule = dlopen("lib3270.so." PACKAGE_VERSION, RTLD_NOW); | |
340 | - if(!hModule) | |
341 | - { | |
342 | - throw exception("Can't load lib3270: %s",dlerror()); | |
343 | - return; | |
344 | - } | |
345 | - | |
346 | -#endif // WIN32 | |
347 | - | |
348 | - // Load entry points | |
349 | - for(unsigned int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++) | |
350 | - { | |
351 | -#ifdef WIN32 | |
352 | - *call[f].entry = (void *) GetProcAddress(hModule,call[f].name); | |
353 | -#else | |
354 | - *call[f].entry = dlsym(hModule,call[f].name); | |
355 | -#endif // WIN32 | |
356 | - | |
357 | - if(!*call[f].entry) | |
358 | - { | |
359 | -#ifndef WIN32 | |
360 | - throw exception("Error \"%s\" loading lib3270::%s",dlerror(),call[f].name); | |
361 | - dlclose(hModule); | |
362 | -#else | |
363 | - throw exception("Error loading lib3270::%s",call[f].name); | |
364 | - FreeLibrary(hModule); | |
365 | -#endif // !WIN32 | |
366 | - hModule = NULL; | |
367 | - return; | |
368 | - } | |
369 | - } | |
370 | - | |
371 | - // Get Session handle, setup base callbacks | |
372 | - set_log_handler(loghandler); | |
373 | - set_trace_handler(tracehandler); | |
374 | - this->hSession = lib3270_new(""); | |
375 | - | |
376 | -} | |
377 | - | |
378 | -dynamic::~dynamic() | |
379 | -{ | |
380 | - static void (*session_free)(void *h); | |
381 | - | |
382 | - trace("%s",__FUNCTION__); | |
383 | - | |
384 | - if(!hModule) | |
385 | - return; | |
386 | - | |
387 | -#ifdef WIN32 | |
388 | - | |
389 | - session_free = (void (*)(void *h)) GetProcAddress(hModule,"lib3270_session_free"); | |
390 | - | |
391 | - if(session_free) | |
392 | - session_free(hSession); | |
393 | - | |
394 | - FreeLibrary(hModule); | |
395 | - | |
396 | -#else | |
397 | - | |
398 | - session_free = (void (*)(void *h)) dlsym(hModule,"lib3270_session_free"); | |
399 | - | |
400 | - if(session_free) | |
401 | - session_free(hSession); | |
402 | - | |
403 | - dlclose(hModule); | |
404 | - | |
405 | -#endif // WIN32 | |
406 | - | |
407 | -} | |
408 | - | |
409 | -char * dynamic::get_version(void) | |
410 | -{ | |
411 | - if(!hModule) | |
412 | - return NULL; | |
413 | - return strdup(_get_version()); | |
414 | -} | |
415 | - | |
416 | -LIB3270_CSTATE dynamic::get_cstate(void) | |
417 | -{ | |
418 | - if(!hModule) | |
419 | - return (LIB3270_CSTATE) -1; | |
420 | - return _get_connection_state(hSession); | |
421 | -} | |
422 | - | |
423 | -int dynamic::disconnect(void) | |
424 | -{ | |
425 | - if(!hModule) | |
426 | - return -1; | |
427 | - return _disconnect(hSession); | |
428 | -} | |
429 | - | |
430 | -int dynamic::connect(const char *uri, bool wait) | |
431 | -{ | |
432 | - if(!hModule) | |
433 | - return -1; | |
434 | - return _connect(hSession,uri,(int) wait); | |
435 | -} | |
436 | - | |
437 | -bool dynamic::is_connected(void) | |
438 | -{ | |
439 | - if(!hModule) | |
440 | - return -1; | |
441 | - return _is_connected(hSession) != 0; | |
442 | -} | |
443 | - | |
444 | -bool dynamic::is_ready(void) | |
445 | -{ | |
446 | - if(!hModule) | |
447 | - return -1; | |
448 | - return _is_ready(hSession) != 0; | |
449 | -} | |
450 | - | |
451 | -int dynamic::iterate(bool wait) | |
452 | -{ | |
453 | - if(!hModule) | |
454 | - return -1; | |
455 | - | |
456 | - _main_iterate(hSession,wait); | |
457 | - | |
458 | - return 0; | |
459 | -} | |
460 | - | |
461 | -int dynamic::wait(int seconds) | |
462 | -{ | |
463 | - if(!hModule) | |
464 | - return -1; | |
465 | - return _wait(hSession,seconds); | |
466 | -} | |
467 | - | |
468 | -int dynamic::wait_for_ready(int seconds) | |
469 | -{ | |
470 | - if(!hModule) | |
471 | - return -1; | |
472 | - return _wait_for_ready(hSession,seconds); | |
473 | -} | |
474 | - | |
475 | -char * dynamic::get_text(int offset, size_t len) | |
476 | -{ | |
477 | - if(!hModule) | |
478 | - return NULL; | |
479 | - return _get_text(hSession,offset,len); | |
480 | -} | |
481 | - | |
482 | -char * dynamic::get_text_at(int row, int col, size_t sz) | |
483 | -{ | |
484 | - if(!hModule) | |
485 | - return NULL; | |
486 | - return _get_text_at(hSession,row,col,sz); | |
487 | -} | |
488 | - | |
489 | -int dynamic::cmp_text_at(int row, int col, const char *text) | |
490 | -{ | |
491 | - if(!hModule) | |
492 | - return 0; | |
493 | - return _cmp_text_at(hSession,row,col,text); | |
494 | -} | |
495 | - | |
496 | -int dynamic::set_text_at(int row, int col, const char *str) | |
497 | -{ | |
498 | - if(!hModule) | |
499 | - return -1; | |
500 | - return _set_text_at(hSession,row,col,(const unsigned char *) str); | |
501 | -} | |
502 | - | |
503 | -int dynamic::set_cursor_position(int row, int col) | |
504 | -{ | |
505 | - if(!hModule) | |
506 | - return -1; | |
507 | - return _set_cursor_position(hSession,row,col); | |
508 | -} | |
509 | - | |
510 | -int dynamic::enter(void) | |
511 | -{ | |
512 | - if(!hModule) | |
513 | - return -1; | |
514 | - return _enter(hSession); | |
515 | -} | |
516 | - | |
517 | -int dynamic::pfkey(int key) | |
518 | -{ | |
519 | - if(!hModule) | |
520 | - return -1; | |
521 | - return _pfkey(hSession,key); | |
522 | -} | |
523 | - | |
524 | -int dynamic::pakey(int key) | |
525 | -{ | |
526 | - if(!hModule) | |
527 | - return -1; | |
528 | - return _pakey(hSession,key); | |
529 | -} | |
530 | - | |
531 | -int dynamic::set_toggle(LIB3270_TOGGLE ix, bool value) | |
532 | -{ | |
533 | - if(hModule) | |
534 | - return _set_toggle(hSession,ix,(int) value); | |
535 | - return -1; | |
536 | -} | |
537 | - | |
538 | -int dynamic::get_field_start(int baddr) | |
539 | -{ | |
540 | - if(hModule) | |
541 | - return _get_field_start(hSession,baddr); | |
542 | - return -1; | |
543 | -} | |
544 | - | |
545 | -int dynamic::get_field_len(int baddr) | |
546 | -{ | |
547 | - if(hModule) | |
548 | - return _get_field_len(hSession,baddr); | |
549 | - return -1; | |
550 | -} | |
551 | - | |
552 | -int dynamic::set_cursor_addr(int addr) | |
553 | -{ | |
554 | - if(hModule) | |
555 | - return _set_cursor_addr(hSession,addr); | |
556 | - return -1; | |
557 | -} | |
558 | - | |
559 | -int dynamic::get_cursor_addr(void) | |
560 | -{ | |
561 | - if(hModule) | |
562 | - return _get_cursor_addr(hSession); | |
563 | - return -1; | |
564 | -} | |
565 | - | |
566 | -int dynamic::emulate_input(const char *str) | |
567 | -{ | |
568 | - if(hModule) | |
569 | - return _emulate_input(hSession,str,-1,1); | |
570 | - return -1; | |
571 | -} | |
572 | - | |
573 | -int dynamic::get_next_unprotected(int baddr) | |
574 | -{ | |
575 | - if(hModule) | |
576 | - return _get_next_unprotected(hSession,baddr); | |
577 | - return -1; | |
578 | -} | |
579 | - | |
580 | -int dynamic::popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
581 | -{ | |
582 | - if(hModule) | |
583 | - { | |
584 | - va_list args; | |
585 | - va_start(args, fmt); | |
586 | - _popup_va(hSession, id, title, message, fmt, args); | |
587 | - va_end(args); | |
588 | - return 0; | |
589 | - } | |
590 | - return -1; | |
591 | -} | |
592 | - | |
593 | -int dynamic::quit(void) | |
594 | -{ | |
595 | - return EINVAL; | |
596 | -} |
src/plugins/rx3270/pluginmain.cc
... | ... | @@ -47,6 +47,7 @@ |
47 | 47 | #include <pw3270/v3270.h> |
48 | 48 | #include <lib3270/actions.h> |
49 | 49 | #include <lib3270/log.h> |
50 | + #include <pw3270/class.h> | |
50 | 51 | |
51 | 52 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
52 | 53 | |
... | ... | @@ -69,7 +70,10 @@ |
69 | 70 | |
70 | 71 | /*--[ Plugin session object ]--------------------------------------------------------------------------------*/ |
71 | 72 | |
72 | - class plugin : public rx3270 | |
73 | + using namespace std; | |
74 | + using namespace PW3270_NAMESPACE; | |
75 | + | |
76 | + class plugin : public session | |
73 | 77 | { |
74 | 78 | public: |
75 | 79 | plugin(H3270 *hSession); |
... | ... | @@ -77,7 +81,7 @@ |
77 | 81 | |
78 | 82 | void free(void *ptr); |
79 | 83 | |
80 | - char * get_version(void); | |
84 | + string get_version(void); | |
81 | 85 | LIB3270_CSTATE get_cstate(void); |
82 | 86 | int disconnect(void); |
83 | 87 | int connect(const char *uri, bool wait = true); |
... | ... | @@ -90,8 +94,8 @@ |
90 | 94 | int wait(int seconds); |
91 | 95 | int wait_for_ready(int seconds); |
92 | 96 | |
93 | - char * get_text(int baddr, size_t len); | |
94 | - char * get_text_at(int row, int col, size_t sz); | |
97 | + string * get_text(int baddr, size_t len); | |
98 | + string * get_text_at(int row, int col, size_t sz); | |
95 | 99 | int cmp_text_at(int row, int col, const char *text); |
96 | 100 | int set_text_at(int row, int col, const char *str); |
97 | 101 | |
... | ... | @@ -111,13 +115,13 @@ |
111 | 115 | int get_next_unprotected(int baddr = -1); |
112 | 116 | |
113 | 117 | int set_copy(const char *text); |
114 | - char * get_copy(void); | |
118 | + string * get_copy(void); | |
115 | 119 | |
116 | - char * get_clipboard(void); | |
120 | + string * get_clipboard(void); | |
117 | 121 | int set_clipboard(const char *text); |
118 | 122 | |
119 | 123 | int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...); |
120 | - char * file_chooser_dialog(GtkFileChooserAction action, const char *title, const char *extension, const char *filename); | |
124 | + string * file_chooser_dialog(GtkFileChooserAction action, const char *title, const char *extension, const char *filename); | |
121 | 125 | |
122 | 126 | int quit(void); |
123 | 127 | |
... | ... | @@ -365,7 +369,7 @@ extern "C" |
365 | 369 | |
366 | 370 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
367 | 371 | |
368 | - static rx3270 * factory(const char *name) | |
372 | + static session * factory(const char *name) | |
369 | 373 | { |
370 | 374 | return new plugin(lib3270_get_default_session_handle()); |
371 | 375 | } |
... | ... | @@ -376,7 +380,7 @@ extern "C" |
376 | 380 | #if GTK_CHECK_VERSION(2,32,0) |
377 | 381 | g_mutex_init(&mutex); |
378 | 382 | #endif // GTK_CHECK_VERSION |
379 | - rx3270::set_plugin(factory); | |
383 | + session::set_plugin(factory); | |
380 | 384 | return 0; |
381 | 385 | } |
382 | 386 | |
... | ... | @@ -389,7 +393,7 @@ extern "C" |
389 | 393 | return 0; |
390 | 394 | } |
391 | 395 | |
392 | - plugin::plugin(H3270 *hSession) : rx3270() | |
396 | + plugin::plugin(H3270 *hSession) : session() | |
393 | 397 | { |
394 | 398 | this->hSession = hSession; |
395 | 399 | } |
... | ... | @@ -400,9 +404,9 @@ extern "C" |
400 | 404 | } |
401 | 405 | |
402 | 406 | |
403 | - char * plugin::get_version(void) | |
407 | + string plugin::get_version(void) | |
404 | 408 | { |
405 | - return strdup(lib3270_get_version()); | |
409 | + return string(lib3270_get_version()); | |
406 | 410 | } |
407 | 411 | |
408 | 412 | LIB3270_CSTATE plugin::get_cstate(void) |
... | ... | @@ -461,9 +465,18 @@ extern "C" |
461 | 465 | return lib3270_wait_for_ready(hSession,seconds); |
462 | 466 | } |
463 | 467 | |
464 | - char * plugin::get_text_at(int row, int col, size_t sz) | |
468 | + string * plugin::get_text_at(int row, int col, size_t sz) | |
465 | 469 | { |
466 | - return lib3270_get_text_at(hSession,row,col,(int) sz); | |
470 | + char * ptr = lib3270_get_text_at(hSession,row,col,(int) sz); | |
471 | + | |
472 | + if(ptr) | |
473 | + { | |
474 | + string *s = new string(ptr); | |
475 | + lib3270_free(ptr); | |
476 | + return s; | |
477 | + } | |
478 | + | |
479 | + return new string(""); | |
467 | 480 | } |
468 | 481 | |
469 | 482 | int plugin::cmp_text_at(int row, int col, const char *text) |
... | ... | @@ -496,9 +509,17 @@ extern "C" |
496 | 509 | lib3270_write_va_log(hSession,"REXX",fmt,args); |
497 | 510 | } |
498 | 511 | |
499 | - char * plugin::get_text(int baddr, size_t len) | |
512 | + string * plugin::get_text(int baddr, size_t len) | |
500 | 513 | { |
501 | - return lib3270_get_text(hSession,baddr,len); | |
514 | + char *ptr = lib3270_get_text(hSession,baddr,len); | |
515 | + if(ptr) | |
516 | + { | |
517 | + string *s = new string(ptr); | |
518 | + lib3270_free(ptr); | |
519 | + return s; | |
520 | + } | |
521 | + | |
522 | + return new string(""); | |
502 | 523 | } |
503 | 524 | |
504 | 525 | int plugin::get_field_start(int baddr) |
... | ... | @@ -517,15 +538,32 @@ extern "C" |
517 | 538 | return 0; |
518 | 539 | } |
519 | 540 | |
520 | - char * plugin::get_copy(void) | |
541 | + string * plugin::get_copy(void) | |
521 | 542 | { |
522 | - return v3270_get_copy(GTK_WIDGET(lib3270_get_widget(hSession))); | |
543 | + gchar *ptr = v3270_get_copy(GTK_WIDGET(lib3270_get_widget(hSession))); | |
544 | + | |
545 | + if(ptr) | |
546 | + { | |
547 | + string *ret = new string((char *) ptr); | |
548 | + g_free(ptr); | |
549 | + return ret; | |
550 | + } | |
551 | + | |
552 | + return NULL; | |
523 | 553 | } |
524 | 554 | |
525 | - char * plugin::get_clipboard(void) | |
555 | + string * plugin::get_clipboard(void) | |
526 | 556 | { |
527 | - trace("%s toplevel=%p",__FUNCTION__,pw3270_get_toplevel()); | |
528 | - return gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD)); | |
557 | + gchar *ptr = gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD)); | |
558 | + | |
559 | + if(ptr) | |
560 | + { | |
561 | + string *ret = new string((char *) ptr); | |
562 | + g_free(ptr); | |
563 | + return ret; | |
564 | + } | |
565 | + | |
566 | + return NULL; | |
529 | 567 | } |
530 | 568 | |
531 | 569 | int plugin::set_clipboard(const char *text) |
... | ... | @@ -568,9 +606,18 @@ int plugin::popup_dialog(LIB3270_NOTIFY id , const char *title, const char *mess |
568 | 606 | return 0; |
569 | 607 | } |
570 | 608 | |
571 | -char * plugin::file_chooser_dialog(GtkFileChooserAction action, const char *title, const char *extension, const char *filename) | |
609 | +string * plugin::file_chooser_dialog(GtkFileChooserAction action, const char *title, const char *extension, const char *filename) | |
572 | 610 | { |
573 | - return pw3270_file_chooser(action, script_name ? script_name : "rexx", title, filename, extension); | |
611 | + gchar *ptr = pw3270_file_chooser(action, script_name ? script_name : "rexx", title, filename, extension); | |
612 | + | |
613 | + if(ptr) | |
614 | + { | |
615 | + string *s = new string((char *) ptr); | |
616 | + g_free(ptr); | |
617 | + return s; | |
618 | + } | |
619 | + | |
620 | + return NULL; | |
574 | 621 | } |
575 | 622 | |
576 | 623 | int plugin::quit(void) | ... | ... |
src/plugins/rx3270/remote.cc
... | ... | @@ -1,1270 +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 remote.cc 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 | - #include "rx3270.h" | |
31 | - | |
32 | -#if defined(HAVE_DBUS) | |
33 | - #include <stdio.h> | |
34 | - #include <dbus/dbus.h> | |
35 | -#endif // HAVE_DBUS | |
36 | - | |
37 | -#if defined(WIN32) | |
38 | - #include <pw3270/ipcpackets.h> | |
39 | -#endif // WIN32 | |
40 | - | |
41 | - #include <time.h> | |
42 | - #include <string.h> | |
43 | - #include <ctype.h> | |
44 | - | |
45 | -/*--[ Class definition ]-----------------------------------------------------------------------------*/ | |
46 | - | |
47 | - class remote : public rx3270 | |
48 | - { | |
49 | - public: | |
50 | - remote(const char *session); | |
51 | - ~remote(); | |
52 | - | |
53 | - char * get_revision(void); | |
54 | - LIB3270_CSTATE get_cstate(void); | |
55 | - int disconnect(void); | |
56 | - int connect(const char *uri, bool wait = true); | |
57 | - bool is_connected(void); | |
58 | - bool is_ready(void); | |
59 | - | |
60 | - int iterate(bool wait); | |
61 | - int wait(int seconds); | |
62 | - int wait_for_ready(int seconds); | |
63 | - | |
64 | - char * get_text(int baddr, size_t len); | |
65 | - char * get_text_at(int row, int col, size_t sz); | |
66 | - int cmp_text_at(int row, int col, const char *text); | |
67 | - int set_text_at(int row, int col, const char *str); | |
68 | - int emulate_input(const char *str); | |
69 | - | |
70 | - int wait_for_text_at(int row, int col, const char *key, int timeout); | |
71 | - | |
72 | - int set_cursor_position(int row, int col); | |
73 | - int set_cursor_addr(int addr); | |
74 | - int get_cursor_addr(void); | |
75 | - | |
76 | - int set_toggle(LIB3270_TOGGLE ix, bool value); | |
77 | - | |
78 | - int enter(void); | |
79 | - int pfkey(int key); | |
80 | - int pakey(int key); | |
81 | - | |
82 | - int get_field_start(int baddr = -1); | |
83 | - int get_field_len(int baddr = -1); | |
84 | - int get_next_unprotected(int baddr = -1); | |
85 | - | |
86 | - char * get_clipboard(void); | |
87 | - int set_clipboard(const char *text); | |
88 | - | |
89 | - int quit(void); | |
90 | - | |
91 | - private: | |
92 | -#if defined(WIN32) | |
93 | - | |
94 | - HANDLE hPipe; | |
95 | - | |
96 | -#elif defined(HAVE_DBUS) | |
97 | - | |
98 | - DBusConnection * conn; | |
99 | - char * dest; | |
100 | - char * path; | |
101 | - char * intf; | |
102 | - DBusMessage * create_message(const char *method); | |
103 | - DBusMessage * call(DBusMessage *msg); | |
104 | - char * query_string(const char *method); | |
105 | - int query_intval(const char *method); | |
106 | - | |
107 | - char * get_string(DBusMessage * msg); | |
108 | - int get_intval(DBusMessage * msg); | |
109 | - | |
110 | -#endif | |
111 | - | |
112 | - | |
113 | - }; | |
114 | - | |
115 | -/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
116 | - | |
117 | -#if defined(HAVE_DBUS) | |
118 | - static const char * prefix_dest = "br.com.bb."; | |
119 | - static const char * prefix_path = "/br/com/bb/"; | |
120 | -#endif // HAVE_DBUS | |
121 | - | |
122 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
123 | - | |
124 | -#if defined(HAVE_DBUS) | |
125 | -DBusMessage * remote::create_message(const char *method) | |
126 | -{ | |
127 | - DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
128 | - this->path, // Path | |
129 | - this->intf, // Interface | |
130 | - method); // method | |
131 | - | |
132 | - if (!msg) | |
133 | - throw exception("Error creating message for method %s",method); | |
134 | - | |
135 | - return msg; | |
136 | -} | |
137 | -#endif // HAVE_DBUS | |
138 | - | |
139 | -rx3270 * rx3270::create_remote(const char *name) | |
140 | -{ | |
141 | - return new remote(name); | |
142 | -} | |
143 | - | |
144 | - | |
145 | -#if defined(HAVE_DBUS) | |
146 | -remote::remote(const char *name) : rx3270(REXX_DEFAULT_CHARSET,"UTF-8") | |
147 | -#else | |
148 | -remote::remote(const char *name) | |
149 | -#endif // HAVE_DBUS | |
150 | -{ | |
151 | -#if defined(WIN32) | |
152 | - static DWORD dwMode = PIPE_READMODE_MESSAGE; | |
153 | - char buffer[4096]; | |
154 | - char * str = strdup(name); | |
155 | - char * ptr; | |
156 | - | |
157 | - hPipe = INVALID_HANDLE_VALUE; | |
158 | - | |
159 | - for(ptr=str;*ptr;ptr++) | |
160 | - { | |
161 | - if(*ptr == ':') | |
162 | - *ptr = '_'; | |
163 | - else | |
164 | - *ptr = tolower(*ptr); | |
165 | - } | |
166 | - | |
167 | - snprintf(buffer,4095,"\\\\.\\pipe\\%s",str); | |
168 | - | |
169 | - free(str); | |
170 | - | |
171 | - if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT)) | |
172 | - { | |
173 | - throw exception("Invalid service instance: %s",name); | |
174 | - return; | |
175 | - } | |
176 | - | |
177 | - hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); | |
178 | - | |
179 | - if(hPipe == INVALID_HANDLE_VALUE) | |
180 | - { | |
181 | - throw exception("Can´t create service pipe %s",buffer); | |
182 | - return; | |
183 | - } | |
184 | - | |
185 | - if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) | |
186 | - { | |
187 | - throw exception("%s","Can´t set pipe state"); | |
188 | - CloseHandle(hPipe); | |
189 | - hPipe = INVALID_HANDLE_VALUE; | |
190 | - return; | |
191 | - } | |
192 | - | |
193 | - // Connected | |
194 | - | |
195 | -#elif defined(HAVE_DBUS) | |
196 | - DBusError err; | |
197 | - int rc; | |
198 | - char * str = strdup(name); | |
199 | - char * ptr; | |
200 | - char busname[4096]; | |
201 | - char pidname[10]; | |
202 | - int pid = (int) getpid(); | |
203 | - | |
204 | - trace("%s str=%p",__FUNCTION__,str); | |
205 | - | |
206 | - for(ptr=str;*ptr;ptr++) | |
207 | - *ptr = tolower(*ptr); | |
208 | - | |
209 | - ptr = strchr(str,':'); | |
210 | - | |
211 | - if(ptr) | |
212 | - { | |
213 | - size_t sz; | |
214 | - | |
215 | - *(ptr++) = 0; | |
216 | - | |
217 | - // Build destination | |
218 | - sz = strlen(ptr)+strlen(str)+strlen(prefix_dest)+2; | |
219 | - dest = (char *) malloc(sz+1); | |
220 | - strncpy(dest,prefix_dest,sz); | |
221 | - strncat(dest,str,sz); | |
222 | - strncat(dest,".",sz); | |
223 | - strncat(dest,ptr,sz); | |
224 | - | |
225 | - // Build path | |
226 | - sz = strlen(str)+strlen(prefix_path); | |
227 | - path = (char *) malloc(sz+1); | |
228 | - strncpy(path,prefix_path,sz); | |
229 | - strncat(path,str,sz); | |
230 | - | |
231 | - // Build intf | |
232 | - sz = strlen(str)+strlen(prefix_dest)+1; | |
233 | - intf = (char *) malloc(sz+1); | |
234 | - strncpy(intf,prefix_dest,sz); | |
235 | - strncat(intf,str,sz); | |
236 | - | |
237 | - } | |
238 | - else | |
239 | - { | |
240 | - size_t sz; | |
241 | - | |
242 | - // Build destination | |
243 | - sz = strlen(str)+strlen(prefix_dest)+2; | |
244 | - dest = (char *) malloc(sz+1); | |
245 | - strncpy(dest,prefix_dest,sz); | |
246 | - strncat(dest,str,sz); | |
247 | - | |
248 | - // Build path | |
249 | - sz = strlen(str)+strlen(prefix_path); | |
250 | - path = (char *) malloc(sz+1); | |
251 | - strncpy(path,prefix_path,sz); | |
252 | - strncat(path,str,sz); | |
253 | - | |
254 | - // Build intf | |
255 | - sz = strlen(str)+strlen(prefix_dest)+1; | |
256 | - intf = (char *) malloc(sz+1); | |
257 | - strncpy(intf,prefix_dest,sz); | |
258 | - strncat(intf,str,sz); | |
259 | - | |
260 | - } | |
261 | - | |
262 | - trace("DBUS:\nDestination:\t[%s]\nPath:\t\t[%s]\nInterface:\t[%s]",dest,path,intf); | |
263 | - | |
264 | - free(str); | |
265 | - | |
266 | - dbus_error_init(&err); | |
267 | - | |
268 | - conn = dbus_bus_get(DBUS_BUS_SESSION, &err); | |
269 | - trace("dbus_bus_get conn=%p",conn); | |
270 | - | |
271 | - if (dbus_error_is_set(&err)) | |
272 | - { | |
273 | - throw exception("DBUS Connection Error (%s)", err.message); | |
274 | - dbus_error_free(&err); | |
275 | - } | |
276 | - | |
277 | - if(!conn) | |
278 | - { | |
279 | - throw exception("%s", "DBUS Connection failed"); | |
280 | - return; | |
281 | - } | |
282 | - | |
283 | - memset(pidname,0,10); | |
284 | - for(int f = 0; f < 9 && pid > 0;f++) | |
285 | - { | |
286 | - pidname[f] = 'a'+(pid % 25); | |
287 | - pid /= 25; | |
288 | - } | |
289 | - | |
290 | - snprintf(busname, 4095, "%s.rx3270.br.com.bb",pidname); | |
291 | - | |
292 | - trace("Busname: [%s]",busname); | |
293 | - | |
294 | - rc = dbus_bus_request_name(conn, busname, DBUS_NAME_FLAG_REPLACE_EXISTING , &err); | |
295 | - trace("dbus_bus_request_name rc=%d",rc); | |
296 | - | |
297 | - if (dbus_error_is_set(&err)) | |
298 | - { | |
299 | - throw exception("Name Error (%s)", err.message); | |
300 | - dbus_error_free(&err); | |
301 | - conn = NULL; | |
302 | - return; | |
303 | - } | |
304 | - | |
305 | - if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | |
306 | - { | |
307 | - trace("%s: DBUS request for name %s failed",__FUNCTION__, busname); | |
308 | - throw exception("DBUS request for \"%s\" failed",name); | |
309 | - conn = NULL; | |
310 | - return; | |
311 | - } | |
312 | - | |
313 | - trace("%s: Using DBUS name %s",__FUNCTION__,busname); | |
314 | - | |
315 | - DBusMessage * msg = create_message("setScript"); | |
316 | - | |
317 | - if(msg) | |
318 | - { | |
319 | - const char * id = "r"; | |
320 | - static const dbus_int32_t flag = 1; | |
321 | - dbus_message_append_args(msg, DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID); | |
322 | - get_intval(call(msg)); | |
323 | - } | |
324 | - | |
325 | -#else | |
326 | - | |
327 | -#endif | |
328 | -} | |
329 | - | |
330 | -remote::~remote() | |
331 | -{ | |
332 | -#if defined(WIN32) | |
333 | - | |
334 | - if(hPipe != INVALID_HANDLE_VALUE) | |
335 | - CloseHandle(hPipe); | |
336 | - | |
337 | -#elif defined(HAVE_DBUS) | |
338 | - | |
339 | - try | |
340 | - { | |
341 | - DBusMessage * msg = create_message("setScript"); | |
342 | - if(msg) | |
343 | - { | |
344 | - const char * id = "r"; | |
345 | - static const dbus_int32_t flag = 0; | |
346 | - dbus_message_append_args(msg, DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID); | |
347 | - get_intval(call(msg)); | |
348 | - } | |
349 | - } | |
350 | - catch(rx3270::exception e) | |
351 | - { | |
352 | - } | |
353 | - | |
354 | - free(dest); | |
355 | - free(path); | |
356 | - free(intf); | |
357 | - | |
358 | -#else | |
359 | - | |
360 | -#endif | |
361 | -} | |
362 | - | |
363 | -#if defined(HAVE_DBUS) | |
364 | -DBusMessage * remote::call(DBusMessage *msg) | |
365 | -{ | |
366 | - DBusMessage * reply; | |
367 | - DBusError error; | |
368 | - | |
369 | - dbus_error_init(&error); | |
370 | - reply = dbus_connection_send_with_reply_and_block(conn,msg,10000,&error); | |
371 | - dbus_message_unref(msg); | |
372 | - | |
373 | - if(!reply) | |
374 | - { | |
375 | - throw exception("%s",error.message); | |
376 | - dbus_error_free(&error); | |
377 | - } | |
378 | - | |
379 | - return reply; | |
380 | - | |
381 | -} | |
382 | - | |
383 | -char * remote::get_string(DBusMessage * msg) | |
384 | -{ | |
385 | - char *rc = NULL; | |
386 | - if(msg) | |
387 | - { | |
388 | - DBusMessageIter iter; | |
389 | - | |
390 | - if(dbus_message_iter_init(msg, &iter)) | |
391 | - { | |
392 | - if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) | |
393 | - { | |
394 | - const char * str; | |
395 | - dbus_message_iter_get_basic(&iter, &str); | |
396 | - trace("Response: [%s]",str); | |
397 | - rc = strdup(str); | |
398 | - } | |
399 | - else | |
400 | - { | |
401 | - dbus_message_unref(msg); | |
402 | - throw exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
403 | - return NULL; | |
404 | - } | |
405 | - } | |
406 | - | |
407 | - dbus_message_unref(msg); | |
408 | - } | |
409 | - return rc; | |
410 | -} | |
411 | - | |
412 | -char * remote::query_string(const char *method) | |
413 | -{ | |
414 | - if(conn) | |
415 | - return get_string(call(create_message(method))); | |
416 | - return NULL; | |
417 | -} | |
418 | - | |
419 | -int remote::get_intval(DBusMessage * msg) | |
420 | -{ | |
421 | - int rc = -1; | |
422 | - | |
423 | - if(msg) | |
424 | - { | |
425 | - DBusMessageIter iter; | |
426 | - | |
427 | - if(dbus_message_iter_init(msg, &iter)) | |
428 | - { | |
429 | - if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) | |
430 | - { | |
431 | - dbus_int32_t iSigned; | |
432 | - dbus_message_iter_get_basic(&iter, &iSigned); | |
433 | - rc = (int) iSigned; | |
434 | - } | |
435 | - else | |
436 | - { | |
437 | - dbus_message_unref(msg); | |
438 | - throw exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
439 | - return -1; | |
440 | - } | |
441 | - } | |
442 | - | |
443 | - dbus_message_unref(msg); | |
444 | - } | |
445 | - | |
446 | - return rc; | |
447 | -} | |
448 | - | |
449 | -int remote::query_intval(const char *method) | |
450 | -{ | |
451 | - if(conn) | |
452 | - return get_intval(call(create_message(method))); | |
453 | - return -1; | |
454 | -} | |
455 | - | |
456 | - | |
457 | -#endif // HAVE_DBUS | |
458 | - | |
459 | -char * remote::get_revision(void) | |
460 | -{ | |
461 | -#if defined(WIN32) | |
462 | - | |
463 | - return strdup(PACKAGE_REVISION); | |
464 | - | |
465 | -#elif defined(HAVE_DBUS) | |
466 | - | |
467 | - return query_string("getRevision"); | |
468 | - | |
469 | -#else | |
470 | - | |
471 | - return NULL; | |
472 | - | |
473 | -#endif | |
474 | - | |
475 | -} | |
476 | - | |
477 | -LIB3270_CSTATE remote::get_cstate(void) | |
478 | -{ | |
479 | -#if defined(WIN32) | |
480 | - | |
481 | - if(hPipe != INVALID_HANDLE_VALUE) | |
482 | - { | |
483 | - static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CSTATE }; | |
484 | - struct hllapi_packet_result response; | |
485 | - DWORD cbSize = sizeof(query); | |
486 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
487 | - return (LIB3270_CSTATE) response.rc; | |
488 | - } | |
489 | - | |
490 | - return (LIB3270_CSTATE) -1; | |
491 | - | |
492 | -#elif defined(HAVE_DBUS) | |
493 | - | |
494 | - return (LIB3270_CSTATE) query_intval("getConnectionState"); | |
495 | - | |
496 | -#else | |
497 | - | |
498 | - return (LIB3270_CSTATE) -1; | |
499 | - | |
500 | -#endif | |
501 | - | |
502 | -} | |
503 | - | |
504 | -int remote::disconnect(void) | |
505 | -{ | |
506 | -#if defined(WIN32) | |
507 | - | |
508 | - if(hPipe != INVALID_HANDLE_VALUE) | |
509 | - { | |
510 | - static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT }; | |
511 | - struct hllapi_packet_result response; | |
512 | - DWORD cbSize = sizeof(query); | |
513 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
514 | - return 0; | |
515 | - } | |
516 | - return -1; | |
517 | - | |
518 | -#elif defined(HAVE_DBUS) | |
519 | - | |
520 | - return query_intval("disconnect"); | |
521 | - | |
522 | -#else | |
523 | - | |
524 | - return -1; | |
525 | - | |
526 | -#endif | |
527 | - | |
528 | -} | |
529 | - | |
530 | -int remote::connect(const char *uri, bool wait) | |
531 | -{ | |
532 | -#if defined(WIN32) | |
533 | - if(hPipe != INVALID_HANDLE_VALUE) | |
534 | - { | |
535 | - struct hllapi_packet_connect * pkt; | |
536 | - struct hllapi_packet_result response; | |
537 | - DWORD cbSize; | |
538 | - | |
539 | - cbSize = sizeof(struct hllapi_packet_connect)+strlen(uri); | |
540 | - pkt = (struct hllapi_packet_connect *) malloc(cbSize); | |
541 | - | |
542 | - pkt->packet_id = HLLAPI_PACKET_CONNECT; | |
543 | - pkt->wait = (unsigned char) wait; | |
544 | - strcpy(pkt->hostname,uri); | |
545 | - | |
546 | - trace("Sending %s",pkt->hostname); | |
547 | - | |
548 | - if(!TransactNamedPipe(hPipe,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL)) | |
549 | - { | |
550 | - errno = GetLastError(); | |
551 | - response.rc = -1; | |
552 | - } | |
553 | - | |
554 | - free(pkt); | |
555 | - | |
556 | - return response.rc; | |
557 | - | |
558 | - } | |
559 | - | |
560 | -#elif defined(HAVE_DBUS) | |
561 | - | |
562 | - int rc; | |
563 | - DBusMessage * msg = create_message("connect"); | |
564 | - if(!msg) | |
565 | - return -1; | |
566 | - | |
567 | - dbus_message_append_args(msg, DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID); | |
568 | - | |
569 | - rc = get_intval(call(msg)); | |
570 | - | |
571 | - if(!rc && wait) | |
572 | - return wait_for_ready(120); | |
573 | - | |
574 | - return rc; | |
575 | - | |
576 | -#endif | |
577 | - | |
578 | - return -1; | |
579 | -} | |
580 | - | |
581 | -bool remote::is_connected(void) | |
582 | -{ | |
583 | -#if defined(WIN32) | |
584 | - | |
585 | - if(hPipe != INVALID_HANDLE_VALUE) | |
586 | - { | |
587 | - static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED }; | |
588 | - struct hllapi_packet_result response; | |
589 | - DWORD cbSize = sizeof(query); | |
590 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
591 | - return response.rc != 0; | |
592 | - } | |
593 | - | |
594 | -#elif defined(HAVE_DBUS) | |
595 | - | |
596 | - return query_intval("isConnected") != 0; | |
597 | - | |
598 | -#endif | |
599 | - | |
600 | - return false; | |
601 | -} | |
602 | - | |
603 | -bool remote::is_ready(void) | |
604 | -{ | |
605 | -#if defined(WIN32) | |
606 | - | |
607 | - if(hPipe != INVALID_HANDLE_VALUE) | |
608 | - { | |
609 | - static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_READY }; | |
610 | - struct hllapi_packet_result response; | |
611 | - DWORD cbSize = sizeof(query); | |
612 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
613 | - return response.rc != 0; | |
614 | - } | |
615 | - | |
616 | -#elif defined(HAVE_DBUS) | |
617 | - | |
618 | - return query_intval("isReady") != 0; | |
619 | - | |
620 | -#endif | |
621 | - | |
622 | - return false; | |
623 | -} | |
624 | - | |
625 | -int remote::iterate(bool wait) | |
626 | -{ | |
627 | -#if defined(WIN32) | |
628 | - | |
629 | - return 0; | |
630 | - | |
631 | -#elif defined(HAVE_DBUS) | |
632 | - | |
633 | - return 0; | |
634 | - | |
635 | -#endif | |
636 | - | |
637 | - return -1; | |
638 | -} | |
639 | - | |
640 | -int remote::wait(int seconds) | |
641 | -{ | |
642 | -#if defined(WIN32) | |
643 | - | |
644 | - time_t end = time(0)+seconds; | |
645 | - | |
646 | - while(time(0) < end) | |
647 | - { | |
648 | - if(!is_connected()) | |
649 | - return ENOTCONN; | |
650 | - Sleep(500); | |
651 | - } | |
652 | - | |
653 | - return 0; | |
654 | - | |
655 | -#elif defined(HAVE_DBUS) | |
656 | - | |
657 | - time_t end = time(0)+seconds; | |
658 | - | |
659 | - while(time(0) < end) | |
660 | - { | |
661 | - if(!is_connected()) | |
662 | - return ENOTCONN; | |
663 | - usleep(500); | |
664 | - } | |
665 | - | |
666 | - return 0; | |
667 | - | |
668 | -#endif | |
669 | - | |
670 | - return -1; | |
671 | -} | |
672 | - | |
673 | -int remote::wait_for_ready(int seconds) | |
674 | -{ | |
675 | -#if defined(WIN32) | |
676 | - | |
677 | - if(hPipe != INVALID_HANDLE_VALUE) | |
678 | - { | |
679 | - time_t end = time(0)+seconds; | |
680 | - | |
681 | - while(time(0) < end) | |
682 | - { | |
683 | - if(!is_connected()) | |
684 | - return ENOTCONN; | |
685 | - | |
686 | - if(is_ready()) | |
687 | - return 0; | |
688 | - | |
689 | - Sleep(250); | |
690 | - } | |
691 | - | |
692 | - return ETIMEDOUT; | |
693 | - | |
694 | - } | |
695 | - | |
696 | - return -1; | |
697 | - | |
698 | -#elif defined(HAVE_DBUS) | |
699 | - | |
700 | - time_t end = time(0)+seconds; | |
701 | - | |
702 | - while(time(0) < end) | |
703 | - { | |
704 | - static const dbus_int32_t delay = 2; | |
705 | - | |
706 | - DBusMessage * msg = create_message("waitForReady"); | |
707 | - int rc; | |
708 | - | |
709 | - if(!msg) | |
710 | - return -1; | |
711 | - | |
712 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &delay, DBUS_TYPE_INVALID); | |
713 | - | |
714 | - rc = get_intval(call(msg)); | |
715 | - trace("waitForReady exits with rc=%d",rc); | |
716 | - if(rc != ETIMEDOUT) | |
717 | - return rc; | |
718 | - } | |
719 | - | |
720 | - return ETIMEDOUT; | |
721 | - | |
722 | -#else | |
723 | - | |
724 | - return -1; | |
725 | - | |
726 | -#endif | |
727 | - | |
728 | -} | |
729 | - | |
730 | -char * remote::get_text_at(int row, int col, size_t sz) | |
731 | -{ | |
732 | -#if defined(WIN32) | |
733 | - | |
734 | - if(hPipe != INVALID_HANDLE_VALUE) | |
735 | - { | |
736 | - struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, (unsigned short) row, (unsigned short) col, (unsigned short) sz }; | |
737 | - struct hllapi_packet_text * response; | |
738 | - DWORD cbSize = sizeof(struct hllapi_packet_text)+sz; | |
739 | - char * text = NULL; | |
740 | - | |
741 | - response = (struct hllapi_packet_text *) malloc(cbSize+2); | |
742 | - memset(response,0,cbSize+2); | |
743 | - | |
744 | - if(!TransactNamedPipe(hPipe,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL)) | |
745 | - return NULL; | |
746 | - | |
747 | - if(response->packet_id) | |
748 | - errno = response->packet_id; | |
749 | - else | |
750 | - text = strdup(response->text); | |
751 | - | |
752 | - free(response); | |
753 | - return text; | |
754 | - | |
755 | - } | |
756 | - | |
757 | -#elif defined(HAVE_DBUS) | |
758 | - | |
759 | - dbus_int32_t r = (dbus_int32_t) row; | |
760 | - dbus_int32_t c = (dbus_int32_t) col; | |
761 | - dbus_int32_t l = (dbus_int32_t) sz; | |
762 | - | |
763 | - DBusMessage * msg = create_message("getTextAt"); | |
764 | - if(!msg) | |
765 | - return NULL; | |
766 | - | |
767 | - trace("%s(%d,%d,%d)",__FUNCTION__,r,c,l); | |
768 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INT32, &l, DBUS_TYPE_INVALID); | |
769 | - | |
770 | - return get_string(call(msg)); | |
771 | - | |
772 | -#endif | |
773 | - | |
774 | - return NULL; | |
775 | -} | |
776 | - | |
777 | -int remote::cmp_text_at(int row, int col, const char *text) | |
778 | -{ | |
779 | -#if defined(WIN32) | |
780 | - | |
781 | - if(hPipe != INVALID_HANDLE_VALUE) | |
782 | - { | |
783 | - struct hllapi_packet_text_at * query; | |
784 | - struct hllapi_packet_result response; | |
785 | - DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text); | |
786 | - | |
787 | - query = (struct hllapi_packet_text_at *) malloc(cbSize); | |
788 | - query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT; | |
789 | - query->row = row; | |
790 | - query->col = col; | |
791 | - strcpy(query->text,text); | |
792 | - | |
793 | - TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
794 | - | |
795 | - free(query); | |
796 | - | |
797 | - return response.rc; | |
798 | - } | |
799 | - | |
800 | - | |
801 | -#elif defined(HAVE_DBUS) | |
802 | - | |
803 | - dbus_int32_t r = (dbus_int32_t) row; | |
804 | - dbus_int32_t c = (dbus_int32_t) col; | |
805 | - | |
806 | - DBusMessage * msg = create_message("cmpTextAt"); | |
807 | - if(msg) | |
808 | - { | |
809 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); | |
810 | - return get_intval(call(msg)); | |
811 | - } | |
812 | - | |
813 | -#endif | |
814 | - | |
815 | - return 0; | |
816 | -} | |
817 | - | |
818 | -int remote::set_text_at(int row, int col, const char *str) | |
819 | -{ | |
820 | -#if defined(WIN32) | |
821 | - | |
822 | - if(hPipe != INVALID_HANDLE_VALUE) | |
823 | - { | |
824 | - struct hllapi_packet_text_at * query; | |
825 | - struct hllapi_packet_result response; | |
826 | - DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str); | |
827 | - | |
828 | - query = (struct hllapi_packet_text_at *) malloc(cbSize); | |
829 | - query->packet_id = HLLAPI_PACKET_SET_TEXT_AT; | |
830 | - query->row = row; | |
831 | - query->col = col; | |
832 | - strcpy(query->text,(const char *) str); | |
833 | - | |
834 | - TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
835 | - | |
836 | - free(query); | |
837 | - | |
838 | - return response.rc; | |
839 | - } | |
840 | - | |
841 | -#elif defined(HAVE_DBUS) | |
842 | - | |
843 | - dbus_int32_t r = (dbus_int32_t) row; | |
844 | - dbus_int32_t c = (dbus_int32_t) col; | |
845 | - | |
846 | - DBusMessage * msg = create_message("setTextAt"); | |
847 | - if(msg) | |
848 | - { | |
849 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
850 | - return get_intval(call(msg)); | |
851 | - } | |
852 | - | |
853 | -#endif | |
854 | - | |
855 | - return -1; | |
856 | -} | |
857 | - | |
858 | -int remote::emulate_input(const char *str) | |
859 | -{ | |
860 | -#if defined(WIN32) | |
861 | - | |
862 | - if(hPipe != INVALID_HANDLE_VALUE) | |
863 | - { | |
864 | - size_t len = strlen(str); | |
865 | - struct hllapi_packet_emulate_input * query; | |
866 | - struct hllapi_packet_result response; | |
867 | - DWORD cbSize = sizeof(struct hllapi_packet_emulate_input)+len; | |
868 | - | |
869 | - query = (struct hllapi_packet_emulate_input *) malloc(cbSize); | |
870 | - query->packet_id = HLLAPI_PACKET_EMULATE_INPUT; | |
871 | - query->len = len; | |
872 | - query->pasting = 1; | |
873 | - strcpy(query->text,str); | |
874 | - | |
875 | - TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
876 | - | |
877 | - free(query); | |
878 | - | |
879 | - return response.rc; | |
880 | - } | |
881 | - | |
882 | -#elif defined(HAVE_DBUS) | |
883 | - | |
884 | - DBusMessage * msg = create_message("input"); | |
885 | - if(msg) | |
886 | - { | |
887 | - dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
888 | - return get_intval(call(msg)); | |
889 | - } | |
890 | - | |
891 | -#endif | |
892 | - | |
893 | - return -1; | |
894 | -} | |
895 | - | |
896 | -int remote::set_cursor_position(int row, int col) | |
897 | -{ | |
898 | -#if defined(WIN32) | |
899 | - | |
900 | - if(hPipe != INVALID_HANDLE_VALUE) | |
901 | - { | |
902 | - struct hllapi_packet_cursor query = { HLLAPI_PACKET_SET_CURSOR_POSITION, (unsigned short) row, (unsigned short) col }; | |
903 | - struct hllapi_packet_result response; | |
904 | - DWORD cbSize = sizeof(query); | |
905 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
906 | - return response.rc != 0; | |
907 | - } | |
908 | - | |
909 | -#elif defined(HAVE_DBUS) | |
910 | - | |
911 | - dbus_int32_t r = (dbus_int32_t) row; | |
912 | - dbus_int32_t c = (dbus_int32_t) col; | |
913 | - | |
914 | - DBusMessage * msg = create_message("setCursorAt"); | |
915 | - if(msg) | |
916 | - { | |
917 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID); | |
918 | - return get_intval(call(msg)); | |
919 | - } | |
920 | - | |
921 | -#endif | |
922 | - | |
923 | - return -1; | |
924 | -} | |
925 | - | |
926 | -int remote::enter(void) | |
927 | -{ | |
928 | -#if defined(WIN32) | |
929 | - | |
930 | - if(hPipe != INVALID_HANDLE_VALUE) | |
931 | - { | |
932 | - static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER }; | |
933 | - struct hllapi_packet_result response; | |
934 | - DWORD cbSize = sizeof(query); | |
935 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
936 | - return response.rc; | |
937 | - } | |
938 | - | |
939 | - return -1; | |
940 | - | |
941 | -#elif defined(HAVE_DBUS) | |
942 | - | |
943 | - return query_intval("enter"); | |
944 | - | |
945 | -#else | |
946 | - | |
947 | - return -1; | |
948 | - | |
949 | -#endif | |
950 | - | |
951 | -} | |
952 | - | |
953 | -int remote::pfkey(int key) | |
954 | -{ | |
955 | -#if defined(WIN32) | |
956 | - | |
957 | - if(hPipe != INVALID_HANDLE_VALUE) | |
958 | - { | |
959 | - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, (unsigned short) key }; | |
960 | - struct hllapi_packet_result response; | |
961 | - DWORD cbSize = sizeof(query); | |
962 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
963 | - return response.rc; | |
964 | - } | |
965 | - | |
966 | -#elif defined(HAVE_DBUS) | |
967 | - | |
968 | - dbus_int32_t k = (dbus_int32_t) key; | |
969 | - | |
970 | - DBusMessage * msg = create_message("pfKey"); | |
971 | - if(msg) | |
972 | - { | |
973 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
974 | - return get_intval(call(msg)); | |
975 | - } | |
976 | - | |
977 | -#endif | |
978 | - | |
979 | - return -1; | |
980 | -} | |
981 | - | |
982 | -int remote::pakey(int key) | |
983 | -{ | |
984 | -#if defined(WIN32) | |
985 | - | |
986 | - if(hPipe != INVALID_HANDLE_VALUE) | |
987 | - { | |
988 | - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, (unsigned short) key }; | |
989 | - struct hllapi_packet_result response; | |
990 | - DWORD cbSize = sizeof(query); | |
991 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
992 | - return response.rc; | |
993 | - } | |
994 | - | |
995 | -#elif defined(HAVE_DBUS) | |
996 | - | |
997 | - dbus_int32_t k = (dbus_int32_t) key; | |
998 | - | |
999 | - DBusMessage * msg = create_message("paKey"); | |
1000 | - if(msg) | |
1001 | - { | |
1002 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
1003 | - return get_intval(call(msg)); | |
1004 | - } | |
1005 | - | |
1006 | -#endif | |
1007 | - | |
1008 | - return -1; | |
1009 | -} | |
1010 | - | |
1011 | -int remote::get_field_start(int baddr) | |
1012 | -{ | |
1013 | -#if defined(WIN32) | |
1014 | - | |
1015 | - if(hPipe != INVALID_HANDLE_VALUE) | |
1016 | - { | |
1017 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_START, (unsigned short) baddr }; | |
1018 | - struct hllapi_packet_result response; | |
1019 | - DWORD cbSize = sizeof(query); | |
1020 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
1021 | - return response.rc; | |
1022 | - } | |
1023 | - | |
1024 | -#elif defined(HAVE_DBUS) | |
1025 | - | |
1026 | - dbus_int32_t k = (dbus_int32_t) baddr; | |
1027 | - | |
1028 | - DBusMessage * msg = create_message("getFieldStart"); | |
1029 | - if(msg) | |
1030 | - { | |
1031 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
1032 | - return get_intval(call(msg)); | |
1033 | - } | |
1034 | - | |
1035 | -#endif | |
1036 | - | |
1037 | - return -1; | |
1038 | -} | |
1039 | - | |
1040 | -int remote::get_field_len(int baddr) | |
1041 | -{ | |
1042 | -#if defined(WIN32) | |
1043 | - | |
1044 | - if(hPipe != INVALID_HANDLE_VALUE) | |
1045 | - { | |
1046 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_LEN, (unsigned short) baddr }; | |
1047 | - struct hllapi_packet_result response; | |
1048 | - DWORD cbSize = sizeof(query); | |
1049 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
1050 | - return response.rc; | |
1051 | - } | |
1052 | - | |
1053 | -#elif defined(HAVE_DBUS) | |
1054 | - | |
1055 | - dbus_int32_t k = (dbus_int32_t) baddr; | |
1056 | - | |
1057 | - DBusMessage * msg = create_message("getFieldLength"); | |
1058 | - if(msg) | |
1059 | - { | |
1060 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
1061 | - return get_intval(call(msg)); | |
1062 | - } | |
1063 | - | |
1064 | -#endif | |
1065 | - | |
1066 | - return -1; | |
1067 | -} | |
1068 | - | |
1069 | - | |
1070 | - | |
1071 | -int remote::set_toggle(LIB3270_TOGGLE ix, bool value) | |
1072 | -{ | |
1073 | -#if defined(WIN32) | |
1074 | - | |
1075 | - if(hPipe != INVALID_HANDLE_VALUE) | |
1076 | - { | |
1077 | - struct hllapi_packet_set query = { HLLAPI_PACKET_SET_TOGGLE, (unsigned short) ix, (unsigned short) value }; | |
1078 | - struct hllapi_packet_result response; | |
1079 | - DWORD cbSize = sizeof(query); | |
1080 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
1081 | - return response.rc; | |
1082 | - } | |
1083 | - | |
1084 | -#elif defined(HAVE_DBUS) | |
1085 | - | |
1086 | - dbus_int32_t i = (dbus_int32_t) ix; | |
1087 | - dbus_int32_t v = (dbus_int32_t) value; | |
1088 | - | |
1089 | - DBusMessage * msg = create_message("setToggle"); | |
1090 | - if(msg) | |
1091 | - { | |
1092 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &i, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID); | |
1093 | - return get_intval(call(msg)); | |
1094 | - } | |
1095 | - | |
1096 | -#endif | |
1097 | - | |
1098 | - return -1; | |
1099 | -} | |
1100 | - | |
1101 | -int remote::wait_for_text_at(int row, int col, const char *key, int timeout) | |
1102 | -{ | |
1103 | - time_t end = time(0)+timeout; | |
1104 | - | |
1105 | - while(time(0) < end) | |
1106 | - { | |
1107 | - if(!is_connected()) | |
1108 | - return ENOTCONN; | |
1109 | - | |
1110 | - if(!cmp_text_at(row,col,key)) | |
1111 | - return 0; | |
1112 | - | |
1113 | -#ifdef WIN32 | |
1114 | - Sleep(500); | |
1115 | -#else | |
1116 | - usleep(500); | |
1117 | -#endif | |
1118 | - } | |
1119 | - | |
1120 | - return ETIMEDOUT; | |
1121 | -} | |
1122 | - | |
1123 | -char * remote::get_text(int baddr, size_t len) | |
1124 | -{ | |
1125 | - #warning IMPLEMENTAR | |
1126 | - return NULL; | |
1127 | -} | |
1128 | - | |
1129 | -int remote::set_cursor_addr(int addr) | |
1130 | -{ | |
1131 | -#if defined(WIN32) | |
1132 | - | |
1133 | - if(hPipe != INVALID_HANDLE_VALUE) | |
1134 | - { | |
1135 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, (unsigned short) addr }; | |
1136 | - struct hllapi_packet_result response; | |
1137 | - DWORD cbSize = sizeof(query); | |
1138 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
1139 | - return response.rc; | |
1140 | - } | |
1141 | - | |
1142 | -#elif defined(HAVE_DBUS) | |
1143 | - | |
1144 | - dbus_int32_t k = (dbus_int32_t) addr; | |
1145 | - | |
1146 | - DBusMessage * msg = create_message("setCursorAddress"); | |
1147 | - if(msg) | |
1148 | - { | |
1149 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
1150 | - return get_intval(call(msg)); | |
1151 | - } | |
1152 | - | |
1153 | -#endif | |
1154 | - | |
1155 | - return -1; | |
1156 | -} | |
1157 | - | |
1158 | -int remote::get_cursor_addr(void) | |
1159 | -{ | |
1160 | -#if defined(WIN32) | |
1161 | - | |
1162 | - if(hPipe != INVALID_HANDLE_VALUE) | |
1163 | - { | |
1164 | - struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CURSOR }; | |
1165 | - struct hllapi_packet_result response; | |
1166 | - DWORD cbSize = sizeof(query); | |
1167 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
1168 | - return response.rc; | |
1169 | - } | |
1170 | - | |
1171 | -#elif defined(HAVE_DBUS) | |
1172 | - | |
1173 | - return query_intval("getCursorAddress"); | |
1174 | - | |
1175 | -#else | |
1176 | - | |
1177 | - return -1; | |
1178 | - | |
1179 | -#endif | |
1180 | -} | |
1181 | - | |
1182 | -int remote::get_next_unprotected(int baddr) | |
1183 | -{ | |
1184 | -#if defined(WIN32) | |
1185 | - | |
1186 | - if(hPipe != INVALID_HANDLE_VALUE) | |
1187 | - { | |
1188 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_NEXT_UNPROTECTED, (unsigned short) baddr }; | |
1189 | - struct hllapi_packet_result response; | |
1190 | - DWORD cbSize = sizeof(query); | |
1191 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
1192 | - return response.rc; | |
1193 | - } | |
1194 | - | |
1195 | -#elif defined(HAVE_DBUS) | |
1196 | - | |
1197 | - dbus_int32_t k = (dbus_int32_t) baddr; | |
1198 | - | |
1199 | - DBusMessage * msg = create_message("getNextUnprotected"); | |
1200 | - if(msg) | |
1201 | - { | |
1202 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
1203 | - return get_intval(call(msg)); | |
1204 | - } | |
1205 | - | |
1206 | -#endif | |
1207 | - | |
1208 | - return -1; | |
1209 | -} | |
1210 | - | |
1211 | -int remote::set_clipboard(const char *text) | |
1212 | -{ | |
1213 | -#if defined(WIN32) | |
1214 | - | |
1215 | - return -1; | |
1216 | - | |
1217 | -#elif defined(HAVE_DBUS) | |
1218 | - | |
1219 | - DBusMessage * msg = create_message("setClipboard"); | |
1220 | - if(msg) | |
1221 | - { | |
1222 | - dbus_message_append_args(msg, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); | |
1223 | - return get_intval(call(msg)); | |
1224 | - } | |
1225 | - | |
1226 | -#endif | |
1227 | - | |
1228 | - return -1; | |
1229 | -} | |
1230 | - | |
1231 | -char * remote::get_clipboard(void) | |
1232 | -{ | |
1233 | -#if defined(WIN32) | |
1234 | - | |
1235 | - return NULL; | |
1236 | - | |
1237 | -#elif defined(HAVE_DBUS) | |
1238 | - | |
1239 | - trace("%s",__FUNCTION__); | |
1240 | - return query_string("getClipboard"); | |
1241 | - | |
1242 | -#endif | |
1243 | - | |
1244 | - return NULL; | |
1245 | -} | |
1246 | - | |
1247 | -int remote::quit(void) | |
1248 | -{ | |
1249 | -#if defined(WIN32) | |
1250 | - | |
1251 | - if(hPipe != INVALID_HANDLE_VALUE) | |
1252 | - { | |
1253 | - static const struct hllapi_packet_query query = { HLLAPI_PACKET_QUIT }; | |
1254 | - struct hllapi_packet_result response; | |
1255 | - DWORD cbSize = sizeof(query); | |
1256 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
1257 | - return (int) response.rc; | |
1258 | - } | |
1259 | - | |
1260 | - return (int) -1; | |
1261 | - | |
1262 | -#elif defined(HAVE_DBUS) | |
1263 | - | |
1264 | - return query_intval("quit"); | |
1265 | - | |
1266 | -#endif | |
1267 | - | |
1268 | - return -1; | |
1269 | - | |
1270 | -} |
src/plugins/rx3270/rexx_methods.cc
... | ... | @@ -37,6 +37,10 @@ |
37 | 37 | #include <time.h> |
38 | 38 | #include <string.h> |
39 | 39 | #include <ctype.h> |
40 | + #include <pw3270/class.h> | |
41 | + | |
42 | + using namespace std; | |
43 | + using namespace PW3270_NAMESPACE; | |
40 | 44 | |
41 | 45 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
42 | 46 | |
... | ... | @@ -45,12 +49,12 @@ RexxMethod1(int, rx3270_method_init, CSTRING, type) |
45 | 49 | // Set session class in rexx object |
46 | 50 | try |
47 | 51 | { |
48 | - RexxPointerObject sessionPtr = context->NewPointer(rx3270::create(type)); | |
52 | + RexxPointerObject sessionPtr = context->NewPointer(session::create(type)); | |
49 | 53 | context->SetObjectVariable("CSELF", sessionPtr); |
50 | 54 | } |
51 | - catch(rx3270::exception e) | |
55 | + catch(std::exception &e) | |
52 | 56 | { |
53 | - e.RaiseException(context); | |
57 | + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); | |
54 | 58 | } |
55 | 59 | |
56 | 60 | return 0; |
... | ... | @@ -58,7 +62,7 @@ RexxMethod1(int, rx3270_method_init, CSTRING, type) |
58 | 62 | |
59 | 63 | RexxMethod1(int, rx3270_method_uninit, CSELF, sessionPtr) |
60 | 64 | { |
61 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
65 | + session *hSession = (session *) sessionPtr; | |
62 | 66 | |
63 | 67 | trace("rx3270_method_uninit hSession=%p",hSession); |
64 | 68 | |
... | ... | @@ -71,37 +75,27 @@ RexxMethod1(int, rx3270_method_uninit, CSELF, sessionPtr) |
71 | 75 | |
72 | 76 | RexxMethod1(RexxStringObject, rx3270_method_version, CSELF, sessionPtr) |
73 | 77 | { |
74 | - rx3270 * session = (rx3270 *) sessionPtr; | |
78 | + session * hSession = (session *) sessionPtr; | |
75 | 79 | |
76 | - if(session) | |
77 | - { | |
78 | - char * version = session->get_version(); | |
79 | - RexxStringObject ret = context->String((CSTRING) (version ? version : "ERROR:")); | |
80 | - free(version); | |
81 | - return ret; | |
82 | - } | |
80 | + if(hSession) | |
81 | + return context->String((CSTRING) hSession->get_version().c_str()); | |
83 | 82 | |
84 | 83 | return context->String((CSTRING) PACKAGE_VERSION); |
85 | 84 | } |
86 | 85 | |
87 | 86 | RexxMethod1(RexxStringObject, rx3270_method_revision, CSELF, sessionPtr) |
88 | 87 | { |
89 | - rx3270 * session = (rx3270 *) sessionPtr; | |
88 | + session * hSession = (session *) sessionPtr; | |
90 | 89 | |
91 | - if(session) | |
92 | - { | |
93 | - char * version = session->get_revision(); | |
94 | - RexxStringObject ret = context->String((CSTRING) (version ? version : PACKAGE_REVISION)); | |
95 | - free(version); | |
96 | - return ret; | |
97 | - } | |
90 | + if(hSession) | |
91 | + return context->String((CSTRING) hSession->get_revision().c_str()); | |
98 | 92 | |
99 | 93 | return context->String((CSTRING) PACKAGE_REVISION); |
100 | 94 | } |
101 | 95 | |
102 | 96 | RexxMethod3(int, rx3270_method_connect, CSELF, sessionPtr, CSTRING, uri, OPTIONAL_int, wait) |
103 | 97 | { |
104 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
98 | + session *hSession = (session *) sessionPtr; | |
105 | 99 | if(!hSession) |
106 | 100 | return -1; |
107 | 101 | return hSession->connect(uri,wait != 0); |
... | ... | @@ -109,7 +103,7 @@ RexxMethod3(int, rx3270_method_connect, CSELF, sessionPtr, CSTRING, uri, OPTIONA |
109 | 103 | |
110 | 104 | RexxMethod1(int, rx3270_method_disconnect, CSELF, sessionPtr) |
111 | 105 | { |
112 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
106 | + session *hSession = (session *) sessionPtr; | |
113 | 107 | if(!hSession) |
114 | 108 | return -1; |
115 | 109 | return hSession->disconnect(); |
... | ... | @@ -117,7 +111,7 @@ RexxMethod1(int, rx3270_method_disconnect, CSELF, sessionPtr) |
117 | 111 | |
118 | 112 | RexxMethod2(int, rx3270_method_sleep, CSELF, sessionPtr, int, seconds) |
119 | 113 | { |
120 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
114 | + session *hSession = (session *) sessionPtr; | |
121 | 115 | if(!hSession) |
122 | 116 | return -1; |
123 | 117 | return hSession->wait(seconds); |
... | ... | @@ -127,14 +121,14 @@ RexxMethod1(logical_t, rx3270_method_is_connected, CSELF, sessionPtr) |
127 | 121 | { |
128 | 122 | try |
129 | 123 | { |
130 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
124 | + session *hSession = (session *) sessionPtr; | |
131 | 125 | if(!hSession) |
132 | 126 | return false; |
133 | 127 | return hSession->is_connected(); |
134 | 128 | } |
135 | - catch(rx3270::exception e) | |
129 | + catch(std::exception e) | |
136 | 130 | { |
137 | - e.RaiseException(context); | |
131 | + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); | |
138 | 132 | } |
139 | 133 | |
140 | 134 | return 0; |
... | ... | @@ -142,7 +136,7 @@ RexxMethod1(logical_t, rx3270_method_is_connected, CSELF, sessionPtr) |
142 | 136 | |
143 | 137 | RexxMethod1(logical_t, rx3270_method_is_ready, CSELF, sessionPtr) |
144 | 138 | { |
145 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
139 | + session *hSession = (session *) sessionPtr; | |
146 | 140 | if(!hSession) |
147 | 141 | return false; |
148 | 142 | return hSession->is_ready(); |
... | ... | @@ -150,7 +144,7 @@ RexxMethod1(logical_t, rx3270_method_is_ready, CSELF, sessionPtr) |
150 | 144 | |
151 | 145 | RexxMethod2(int, rx3270_method_wait_for_ready, CSELF, sessionPtr, OPTIONAL_int, seconds) |
152 | 146 | { |
153 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
147 | + session *hSession = (session *) sessionPtr; | |
154 | 148 | if(!hSession) |
155 | 149 | return -1; |
156 | 150 | return hSession->wait_for_ready(seconds > 0 ? seconds : 60); |
... | ... | @@ -158,7 +152,7 @@ RexxMethod2(int, rx3270_method_wait_for_ready, CSELF, sessionPtr, OPTIONAL_int, |
158 | 152 | |
159 | 153 | RexxMethod3(int, rx3270_method_set_cursor, CSELF, sessionPtr, int, row, int, col) |
160 | 154 | { |
161 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
155 | + session *hSession = (session *) sessionPtr; | |
162 | 156 | if(!hSession) |
163 | 157 | return -1; |
164 | 158 | return hSession->set_cursor_position(row,col); |
... | ... | @@ -166,7 +160,7 @@ RexxMethod3(int, rx3270_method_set_cursor, CSELF, sessionPtr, int, row, int, col |
166 | 160 | |
167 | 161 | RexxMethod1(int, rx3270_method_get_cursor_addr, CSELF, sessionPtr) |
168 | 162 | { |
169 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
163 | + session *hSession = (session *) sessionPtr; | |
170 | 164 | if(!hSession) |
171 | 165 | return -1; |
172 | 166 | return hSession->get_cursor_addr(); |
... | ... | @@ -174,7 +168,7 @@ RexxMethod1(int, rx3270_method_get_cursor_addr, CSELF, sessionPtr) |
174 | 168 | |
175 | 169 | RexxMethod2(int, rx3270_method_set_cursor_addr, CSELF, sessionPtr, int, addr) |
176 | 170 | { |
177 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
171 | + session *hSession = (session *) sessionPtr; | |
178 | 172 | if(!hSession) |
179 | 173 | return -1; |
180 | 174 | return hSession->set_cursor_addr(addr); |
... | ... | @@ -182,7 +176,7 @@ RexxMethod2(int, rx3270_method_set_cursor_addr, CSELF, sessionPtr, int, addr) |
182 | 176 | |
183 | 177 | RexxMethod1(int, rx3270_method_enter, CSELF, sessionPtr) |
184 | 178 | { |
185 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
179 | + session *hSession = (session *) sessionPtr; | |
186 | 180 | if(!hSession) |
187 | 181 | return -1; |
188 | 182 | return hSession->enter(); |
... | ... | @@ -190,7 +184,7 @@ RexxMethod1(int, rx3270_method_enter, CSELF, sessionPtr) |
190 | 184 | |
191 | 185 | RexxMethod2(int, rx3270_method_pfkey, CSELF, sessionPtr, int, key) |
192 | 186 | { |
193 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
187 | + session *hSession = (session *) sessionPtr; | |
194 | 188 | if(!hSession) |
195 | 189 | return -1; |
196 | 190 | return hSession->pfkey(key); |
... | ... | @@ -198,7 +192,7 @@ RexxMethod2(int, rx3270_method_pfkey, CSELF, sessionPtr, int, key) |
198 | 192 | |
199 | 193 | RexxMethod2(int, rx3270_method_pakey, CSELF, sessionPtr, int, key) |
200 | 194 | { |
201 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
195 | + session *hSession = (session *) sessionPtr; | |
202 | 196 | if(!hSession) |
203 | 197 | return -1; |
204 | 198 | return hSession->pakey(key); |
... | ... | @@ -206,9 +200,11 @@ RexxMethod2(int, rx3270_method_pakey, CSELF, sessionPtr, int, key) |
206 | 200 | |
207 | 201 | RexxMethod4(RexxStringObject, rx3270_method_get_text_at, CSELF, sessionPtr, int, row, int, col, int, sz) |
208 | 202 | { |
209 | - rx3270 * session = (rx3270 *) sessionPtr; | |
203 | + #warning Reimplementar | |
204 | +/* | |
205 | + session * hSession = (session *) sessionPtr; | |
210 | 206 | |
211 | - if(session) | |
207 | + if(hSession) | |
212 | 208 | { |
213 | 209 | char * str = session->get_text_at(row,col,sz); |
214 | 210 | |
... | ... | @@ -221,13 +217,15 @@ RexxMethod4(RexxStringObject, rx3270_method_get_text_at, CSELF, sessionPtr, int, |
221 | 217 | return ret; |
222 | 218 | } |
223 | 219 | } |
224 | - | |
220 | +*/ | |
225 | 221 | return context->String(""); |
226 | 222 | } |
227 | 223 | |
228 | 224 | |
229 | 225 | RexxMethod4(int, rx3270_method_set_text_at, CSELF, sessionPtr, int, row, int, col, CSTRING, text) |
230 | 226 | { |
227 | + #warning Reimplementar | |
228 | +/* | |
231 | 229 | rx3270 * session = (rx3270 *) sessionPtr; |
232 | 230 | |
233 | 231 | if(session) |
... | ... | @@ -238,11 +236,14 @@ RexxMethod4(int, rx3270_method_set_text_at, CSELF, sessionPtr, int, row, int, co |
238 | 236 | free(str); |
239 | 237 | return rc; |
240 | 238 | } |
239 | +*/ | |
241 | 240 | return -1; |
242 | 241 | } |
243 | 242 | |
244 | 243 | RexxMethod2(int, rx3270_method_input_text, CSELF, sessionPtr, CSTRING, text) |
245 | 244 | { |
245 | +#warning Reimplementar | |
246 | +/* | |
246 | 247 | rx3270 * session = (rx3270 *) sessionPtr; |
247 | 248 | |
248 | 249 | if(session) |
... | ... | @@ -252,12 +253,14 @@ RexxMethod2(int, rx3270_method_input_text, CSELF, sessionPtr, CSTRING, text) |
252 | 253 | free(str); |
253 | 254 | return rc; |
254 | 255 | } |
255 | - | |
256 | +*/ | |
256 | 257 | return -1; |
257 | 258 | } |
258 | 259 | |
259 | 260 | RexxMethod4(int, rx3270_method_cmp_text_at, CSELF, sessionPtr, int, row, int, col, CSTRING, key) |
260 | 261 | { |
262 | + #warning Reimplementar | |
263 | +/* | |
261 | 264 | int rc = 0; |
262 | 265 | rx3270 * session = (rx3270 *) sessionPtr; |
263 | 266 | |
... | ... | @@ -272,13 +275,15 @@ RexxMethod4(int, rx3270_method_cmp_text_at, CSELF, sessionPtr, int, row, int, co |
272 | 275 | } |
273 | 276 | free(str); |
274 | 277 | } |
275 | - | |
276 | 278 | return rc; |
279 | +*/ | |
280 | + | |
281 | + return -1; | |
277 | 282 | } |
278 | 283 | |
279 | 284 | RexxMethod2(int, rx3270_method_event_trace, CSELF, sessionPtr, int, flag) |
280 | 285 | { |
281 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
286 | + session *hSession = (session *) sessionPtr; | |
282 | 287 | if(!hSession) |
283 | 288 | return -1; |
284 | 289 | hSession->set_toggle(LIB3270_TOGGLE_EVENT_TRACE,flag); |
... | ... | @@ -287,7 +292,7 @@ RexxMethod2(int, rx3270_method_event_trace, CSELF, sessionPtr, int, flag) |
287 | 292 | |
288 | 293 | RexxMethod2(int, rx3270_method_screen_trace, CSELF, sessionPtr, int, flag) |
289 | 294 | { |
290 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
295 | + session *hSession = (session *) sessionPtr; | |
291 | 296 | if(!hSession) |
292 | 297 | return -1; |
293 | 298 | hSession->set_toggle(LIB3270_TOGGLE_SCREEN_TRACE,flag); |
... | ... | @@ -297,7 +302,7 @@ RexxMethod2(int, rx3270_method_screen_trace, CSELF, sessionPtr, int, flag) |
297 | 302 | |
298 | 303 | RexxMethod2(int, rx3270_method_ds_trace, CSELF, sessionPtr, int, flag) |
299 | 304 | { |
300 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
305 | + session *hSession = (session *) sessionPtr; | |
301 | 306 | if(!hSession) |
302 | 307 | return -1; |
303 | 308 | hSession->set_toggle(LIB3270_TOGGLE_DS_TRACE,flag); |
... | ... | @@ -339,7 +344,7 @@ RexxMethod3(int, rx3270_method_set_option, CSELF, sessionPtr, CSTRING, name, int |
339 | 344 | { "altscreen", LIB3270_TOGGLE_ALTSCREEN } |
340 | 345 | }; |
341 | 346 | |
342 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
347 | + session *hSession = (session *) sessionPtr; | |
343 | 348 | if(hSession) |
344 | 349 | { |
345 | 350 | for(int f = 0; f < LIB3270_TOGGLE_COUNT; f++) |
... | ... | @@ -358,7 +363,9 @@ RexxMethod3(int, rx3270_method_set_option, CSELF, sessionPtr, CSTRING, name, int |
358 | 363 | |
359 | 364 | RexxMethod4(logical_t, rx3270_method_test, CSELF, sessionPtr, CSTRING, key, int, row, int, col) |
360 | 365 | { |
361 | - rx3270 * hSession = (rx3270 *) sessionPtr; | |
366 | + #warning Reimplementar | |
367 | +/* | |
368 | + session * hSession = (session *) sessionPtr; | |
362 | 369 | |
363 | 370 | if(!hSession) |
364 | 371 | return false; |
... | ... | @@ -379,22 +386,26 @@ RexxMethod4(logical_t, rx3270_method_test, CSELF, sessionPtr, CSTRING, key, int, |
379 | 386 | free(str); |
380 | 387 | return rc; |
381 | 388 | } |
382 | - | |
389 | +*/ | |
383 | 390 | return false; |
384 | 391 | } |
385 | 392 | |
386 | 393 | RexxMethod5(int, rx3270_method_wait_for_text_at, CSELF, sessionPtr, int, row, int, col, CSTRING, key, int, timeout) |
387 | 394 | { |
395 | + #warning Reimplementar | |
396 | +/* | |
388 | 397 | rx3270 * hSession = (rx3270 *) sessionPtr; |
389 | 398 | |
390 | 399 | if(hSession) |
391 | 400 | return hSession->wait_for_text_at(row,col,key,timeout); |
392 | - | |
401 | +*/ | |
393 | 402 | return -1; |
394 | 403 | } |
395 | 404 | |
396 | 405 | RexxMethod3(RexxStringObject, rx3270_method_get_text, CSELF, sessionPtr, OPTIONAL_int, baddr, OPTIONAL_int, sz) |
397 | 406 | { |
407 | + #warning Reimplementar | |
408 | +/* | |
398 | 409 | rx3270 * hSession = (rx3270 *) sessionPtr; |
399 | 410 | |
400 | 411 | if(hSession) |
... | ... | @@ -409,14 +420,14 @@ RexxMethod3(RexxStringObject, rx3270_method_get_text, CSELF, sessionPtr, OPTIONA |
409 | 420 | return ret; |
410 | 421 | } |
411 | 422 | } |
412 | - | |
423 | +*/ | |
413 | 424 | return context->String(""); |
414 | 425 | } |
415 | 426 | |
416 | 427 | |
417 | 428 | RexxMethod2(int, rx3270_method_get_field_len, CSELF, sessionPtr, OPTIONAL_int, baddr) |
418 | 429 | { |
419 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
430 | + session *hSession = (session *) sessionPtr; | |
420 | 431 | if(!hSession) |
421 | 432 | return -1; |
422 | 433 | return hSession->get_field_len(baddr); |
... | ... | @@ -424,7 +435,7 @@ RexxMethod2(int, rx3270_method_get_field_len, CSELF, sessionPtr, OPTIONAL_int, b |
424 | 435 | |
425 | 436 | RexxMethod2(int, rx3270_method_get_field_start, CSELF, sessionPtr, OPTIONAL_int, baddr) |
426 | 437 | { |
427 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
438 | + session *hSession = (session *) sessionPtr; | |
428 | 439 | if(!hSession) |
429 | 440 | return -1; |
430 | 441 | return hSession->get_field_start(baddr)+1; |
... | ... | @@ -432,7 +443,7 @@ RexxMethod2(int, rx3270_method_get_field_start, CSELF, sessionPtr, OPTIONAL_int, |
432 | 443 | |
433 | 444 | RexxMethod2(int, rx3270_method_get_next_unprotected, CSELF, sessionPtr, OPTIONAL_int, baddr) |
434 | 445 | { |
435 | - rx3270 *hSession = (rx3270 *) sessionPtr; | |
446 | + session *hSession = (session *) sessionPtr; | |
436 | 447 | if(!hSession) |
437 | 448 | return -1; |
438 | 449 | |
... | ... | @@ -445,7 +456,9 @@ RexxMethod2(int, rx3270_method_get_next_unprotected, CSELF, sessionPtr, OPTIONAL |
445 | 456 | |
446 | 457 | RexxMethod1(RexxStringObject, rx3270_method_get_selection, CSELF, sessionPtr) |
447 | 458 | { |
448 | - rx3270 * hSession = (rx3270 *) sessionPtr; | |
459 | + #warning Reimplementar | |
460 | +/* | |
461 | + session * hSession = (session *) sessionPtr; | |
449 | 462 | |
450 | 463 | if(hSession) |
451 | 464 | { |
... | ... | @@ -459,12 +472,14 @@ RexxMethod1(RexxStringObject, rx3270_method_get_selection, CSELF, sessionPtr) |
459 | 472 | return ret; |
460 | 473 | } |
461 | 474 | } |
462 | - | |
475 | +*/ | |
463 | 476 | return context->String(""); |
464 | 477 | } |
465 | 478 | |
466 | 479 | RexxMethod2(int, rx3270_method_set_selection, CSELF, sessionPtr, CSTRING, text) |
467 | 480 | { |
481 | + #warning Reimplementar | |
482 | +/* | |
468 | 483 | rx3270 * session = (rx3270 *) sessionPtr; |
469 | 484 | |
470 | 485 | if(session) |
... | ... | @@ -475,23 +490,22 @@ RexxMethod2(int, rx3270_method_set_selection, CSELF, sessionPtr, CSTRING, text) |
475 | 490 | free(str); |
476 | 491 | return rc; |
477 | 492 | } |
493 | +*/ | |
478 | 494 | return -1; |
479 | 495 | } |
480 | 496 | |
481 | 497 | RexxMethod1(RexxStringObject, rx3270_method_get_clipboard, CSELF, sessionPtr) |
482 | 498 | { |
483 | - rx3270 * hSession = (rx3270 *) sessionPtr; | |
499 | + session * hSession = (session *) sessionPtr; | |
484 | 500 | |
485 | 501 | if(hSession) |
486 | 502 | { |
487 | - char *str = hSession->get_clipboard(); | |
488 | - | |
489 | - trace("str=%p (%s)",str,str); | |
503 | + string *str = hSession->get_clipboard(); | |
490 | 504 | |
491 | 505 | if(str) |
492 | 506 | { |
493 | - RexxStringObject ret = context->String((CSTRING) str); | |
494 | - hSession->free(str); | |
507 | + RexxStringObject ret = context->String((CSTRING) str->c_str()); | |
508 | + delete str; | |
495 | 509 | return ret; |
496 | 510 | } |
497 | 511 | } |
... | ... | @@ -502,7 +516,7 @@ RexxMethod1(RexxStringObject, rx3270_method_get_clipboard, CSELF, sessionPtr) |
502 | 516 | |
503 | 517 | RexxMethod2(int, rx3270_method_set_clipboard, CSELF, sessionPtr, CSTRING, text) |
504 | 518 | { |
505 | - rx3270 * hSession = (rx3270 *) sessionPtr; | |
519 | + session * hSession = (session *) sessionPtr; | |
506 | 520 | |
507 | 521 | if(hSession) |
508 | 522 | return hSession->set_clipboard(text); |
... | ... | @@ -513,8 +527,8 @@ RexxMethod2(int, rx3270_method_set_clipboard, CSELF, sessionPtr, CSTRING, text) |
513 | 527 | |
514 | 528 | RexxMethod5(int, rx3270_method_popup, CSELF, sessionPtr, CSTRING, s_id, CSTRING, title, CSTRING, message, OPTIONAL_CSTRING, det) |
515 | 529 | { |
516 | - LIB3270_NOTIFY id = LIB3270_NOTIFY_INFO; | |
517 | - rx3270 * hSession = (rx3270 *) sessionPtr; | |
530 | + LIB3270_NOTIFY id = LIB3270_NOTIFY_INFO; | |
531 | + session * hSession = (session *) sessionPtr; | |
518 | 532 | |
519 | 533 | if(!hSession) |
520 | 534 | return -1; |
... | ... | @@ -562,7 +576,7 @@ RexxMethod5(RexxStringObject, rx3270_method_get_filename, CSELF, sessionPtr, CST |
562 | 576 | }; |
563 | 577 | |
564 | 578 | GtkFileChooserAction id = GTK_FILE_CHOOSER_ACTION_OPEN; |
565 | - char * ret; | |
579 | + string * ret; | |
566 | 580 | |
567 | 581 | for(int f=0;f<5;f++) |
568 | 582 | { |
... | ... | @@ -573,11 +587,11 @@ RexxMethod5(RexxStringObject, rx3270_method_get_filename, CSELF, sessionPtr, CST |
573 | 587 | } |
574 | 588 | } |
575 | 589 | |
576 | - ret = ((rx3270 *) sessionPtr)->file_chooser_dialog(id, title, extension,filename); | |
590 | + ret = ((session *) sessionPtr)->file_chooser_dialog(id, title, extension,filename); | |
577 | 591 | if(ret) |
578 | 592 | { |
579 | - RexxStringObject obj = context->String(ret); | |
580 | - ((rx3270 *) sessionPtr)->free(ret); | |
593 | + RexxStringObject obj = context->String(ret->c_str()); | |
594 | + delete ret; | |
581 | 595 | return obj; |
582 | 596 | } |
583 | 597 | ... | ... |
src/plugins/rx3270/rx3270.h
... | ... | @@ -64,7 +64,7 @@ |
64 | 64 | #define REXX_DEFAULT_CHARSET "UTF-8" |
65 | 65 | #endif // WIN32 |
66 | 66 | |
67 | -#include <exception> | |
67 | +// #include <exception> | |
68 | 68 | |
69 | 69 | /*---[ Rexx entry points ]-----------------------------------------------------------------------------------*/ |
70 | 70 | |
... | ... | @@ -128,6 +128,7 @@ |
128 | 128 | |
129 | 129 | /*--[ 3270 Session ]-----------------------------------------------------------------------------------------*/ |
130 | 130 | |
131 | +/* | |
131 | 132 | #if defined (HAVE_GNUC_VISIBILITY) |
132 | 133 | class __attribute__((visibility("default"))) rx3270 |
133 | 134 | #elif defined(WIN32) |
... | ... | @@ -232,6 +233,7 @@ |
232 | 233 | }; |
233 | 234 | |
234 | 235 | rx3270 * create_lib3270_instance(void); |
236 | +*/ | |
235 | 237 | |
236 | 238 | #ifdef __cplusplus |
237 | 239 | extern "C" { | ... | ... |
src/plugins/rx3270/session.cc
... | ... | @@ -1,52 +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 session.cc 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 | - #include <time.h> | |
31 | - #include <string.h> | |
32 | - | |
33 | - #include "rx3270.h" | |
34 | - #include <lib3270/actions.h> | |
35 | - | |
36 | - | |
37 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
38 | - | |
39 | -session::session() | |
40 | -{ | |
41 | - this->hSession = lib3270_get_default_session_handle(); | |
42 | -} | |
43 | - | |
44 | -session::~session() | |
45 | -{ | |
46 | - | |
47 | -} | |
48 | - | |
49 | -const char * session::getVersion(void) | |
50 | -{ | |
51 | - return lib3270_get_version(); | |
52 | -} |
src/plugins/rx3270/typed_routines.cc
... | ... | @@ -30,6 +30,11 @@ |
30 | 30 | #include "rx3270.h" |
31 | 31 | #include <time.h> |
32 | 32 | #include <string.h> |
33 | + #include <exception> | |
34 | + #include <pw3270/class.h> | |
35 | + | |
36 | + using namespace std; | |
37 | + using namespace PW3270_NAMESPACE; | |
33 | 38 | |
34 | 39 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
35 | 40 | |
... | ... | @@ -37,11 +42,11 @@ RexxRoutine0(CSTRING, rx3270version) |
37 | 42 | { |
38 | 43 | try |
39 | 44 | { |
40 | - return rx3270::get_default()->get_version(); | |
45 | + return session::get_default()->get_version().c_str(); | |
41 | 46 | } |
42 | - catch(rx3270::exception e) | |
47 | + catch(std::exception& e) | |
43 | 48 | { |
44 | - e.RaiseException(context); | |
49 | + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); | |
45 | 50 | } |
46 | 51 | |
47 | 52 | return NULL; |
... | ... | @@ -70,7 +75,7 @@ RexxRoutine0(CSTRING, rx3270QueryCState) |
70 | 75 | }; |
71 | 76 | |
72 | 77 | size_t f; |
73 | - LIB3270_CSTATE state = rx3270::get_default()->get_cstate(); | |
78 | + LIB3270_CSTATE state = session::get_default()->get_cstate(); | |
74 | 79 | |
75 | 80 | for(f=0;f < (sizeof(xlat_state)/sizeof(struct _xlat_state)); f++) |
76 | 81 | { |
... | ... | @@ -83,52 +88,54 @@ RexxRoutine0(CSTRING, rx3270QueryCState) |
83 | 88 | |
84 | 89 | RexxRoutine0(int, rx3270Disconnect) |
85 | 90 | { |
86 | - return rx3270::get_default()->disconnect(); | |
91 | + return session::get_default()->disconnect(); | |
87 | 92 | } |
88 | 93 | |
89 | 94 | RexxRoutine2(int, rx3270Connect, CSTRING, hostname, int, wait) |
90 | 95 | { |
91 | - return rx3270::get_default()->connect(hostname,wait); | |
96 | + return session::get_default()->connect(hostname,wait); | |
92 | 97 | } |
93 | 98 | |
94 | 99 | RexxRoutine0(int, rx3270isConnected) |
95 | 100 | { |
96 | - return rx3270::get_default()->is_connected(); | |
101 | + return session::get_default()->is_connected(); | |
97 | 102 | } |
98 | 103 | |
99 | 104 | RexxRoutine0(int, rx3270WaitForEvents) |
100 | 105 | { |
101 | - return rx3270::get_default()->iterate(); | |
106 | + return session::get_default()->iterate(); | |
102 | 107 | } |
103 | 108 | |
104 | 109 | RexxRoutine1(int, rx3270Sleep, int, seconds) |
105 | 110 | { |
106 | - return rx3270::get_default()->wait(seconds); | |
111 | + return session::get_default()->wait(seconds); | |
107 | 112 | } |
108 | 113 | |
109 | 114 | RexxRoutine0(int, rx3270SendENTERKey) |
110 | 115 | { |
111 | - return rx3270::get_default()->enter(); | |
116 | + return session::get_default()->enter(); | |
112 | 117 | } |
113 | 118 | |
114 | 119 | RexxRoutine1(int, rx3270SendPFKey, int, key) |
115 | 120 | { |
116 | - return rx3270::get_default()->pfkey(key); | |
121 | + return session::get_default()->pfkey(key); | |
117 | 122 | } |
118 | 123 | |
119 | 124 | RexxRoutine1(int, rx3270SendPAKey, int, key) |
120 | 125 | { |
121 | - return rx3270::get_default()->pakey(key); | |
126 | + return session::get_default()->pakey(key); | |
122 | 127 | } |
123 | 128 | |
124 | 129 | RexxRoutine1(int, rx3270WaitForTerminalReady, int, seconds) |
125 | 130 | { |
126 | - return rx3270::get_default()->wait_for_ready(seconds); | |
131 | + return session::get_default()->wait_for_ready(seconds); | |
127 | 132 | } |
128 | 133 | |
129 | 134 | RexxRoutine4(int, rx3270WaitForStringAt, int, row, int, col, CSTRING, key, int, timeout) |
130 | 135 | { |
131 | - rx3270 * session = rx3270::get_default(); | |
136 | + #warning REIMPLEMENTAR | |
137 | +/* | |
138 | + session * session = session::get_default(); | |
132 | 139 | time_t end = time(0) + timeout; |
133 | 140 | char * text = session->get_3270_string(key); |
134 | 141 | |
... | ... | @@ -146,13 +153,15 @@ RexxRoutine4(int, rx3270WaitForStringAt, int, row, int, col, CSTRING, key, int, |
146 | 153 | } |
147 | 154 | |
148 | 155 | free(text); |
149 | - | |
156 | +*/ | |
150 | 157 | return ETIMEDOUT; |
151 | 158 | |
152 | 159 | } |
153 | 160 | |
154 | 161 | RexxRoutine3(RexxStringObject, rx3270GetStringAt, int, row, int, col, int, sz) |
155 | 162 | { |
163 | + #warning REIMPLEMENTAR | |
164 | +/* | |
156 | 165 | rx3270 * session = rx3270::get_default(); |
157 | 166 | char * str = session->get_text_at(row,col,sz); |
158 | 167 | |
... | ... | @@ -164,17 +173,19 @@ RexxRoutine3(RexxStringObject, rx3270GetStringAt, int, row, int, col, int, sz) |
164 | 173 | free(text); |
165 | 174 | return ret; |
166 | 175 | } |
167 | - | |
176 | +*/ | |
168 | 177 | return context->String(""); |
169 | 178 | } |
170 | 179 | |
171 | 180 | RexxRoutine0(int, rx3270IsTerminalReady) |
172 | 181 | { |
173 | - return rx3270::get_default()->is_ready(); | |
182 | + return session::get_default()->is_ready(); | |
174 | 183 | } |
175 | 184 | |
176 | 185 | RexxRoutine3(int, rx3270queryStringAt, int, row, int, col, CSTRING, key) |
177 | 186 | { |
187 | + #warning Reimplementar | |
188 | +/* | |
178 | 189 | int rc = 0; |
179 | 190 | rx3270 * session = rx3270::get_default(); |
180 | 191 | char * str = session->get_text_at(row,col,strlen(key)); |
... | ... | @@ -189,17 +200,19 @@ RexxRoutine3(int, rx3270queryStringAt, int, row, int, col, CSTRING, key) |
189 | 200 | free(str); |
190 | 201 | |
191 | 202 | return rc; |
203 | +*/ | |
204 | + return -1; | |
192 | 205 | } |
193 | 206 | |
194 | 207 | RexxRoutine2(int, rx3270SetCursorPosition, int, row, int, col) |
195 | 208 | { |
196 | 209 | try |
197 | 210 | { |
198 | - return rx3270::get_default()->set_cursor_position(row,col); | |
211 | + return session::get_default()->set_cursor_position(row,col); | |
199 | 212 | } |
200 | - catch(rx3270::exception e) | |
213 | + catch(std::exception &e) | |
201 | 214 | { |
202 | - e.RaiseException(context); | |
215 | + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); | |
203 | 216 | } |
204 | 217 | |
205 | 218 | return -1; |
... | ... | @@ -207,6 +220,8 @@ RexxRoutine2(int, rx3270SetCursorPosition, int, row, int, col) |
207 | 220 | |
208 | 221 | RexxRoutine3(int, rx3270SetStringAt, int, row, int, col, CSTRING, text) |
209 | 222 | { |
223 | + #warning Reimplementar | |
224 | +/* | |
210 | 225 | rx3270 * session = rx3270::get_default(); |
211 | 226 | char * str = session->get_3270_string(text); |
212 | 227 | int rc; |
... | ... | @@ -216,10 +231,12 @@ RexxRoutine3(int, rx3270SetStringAt, int, row, int, col, CSTRING, text) |
216 | 231 | free(str); |
217 | 232 | |
218 | 233 | return rc; |
234 | +*/ | |
235 | + return -1; | |
219 | 236 | } |
220 | 237 | |
221 | 238 | RexxRoutine0(int, rx3270CloseApplication) |
222 | 239 | { |
223 | - rx3270 * session = rx3270::get_default(); | |
240 | + session * session = session::get_default(); | |
224 | 241 | return session->quit(); |
225 | 242 | } | ... | ... |