Commit 0459733be8f48961414e04761af4d3dfc5c6d419
1 parent
fe4a5aff
Exists in
master
and in
5 other branches
Implementando chamadas remotas na API rexx
Showing
9 changed files
with
109 additions
and
12 deletions
Show diff stats
pw3270.cbp
@@ -292,6 +292,7 @@ | @@ -292,6 +292,7 @@ | ||
292 | <Unit filename="src/plugins/rx3270/rx3270.h" /> | 292 | <Unit filename="src/plugins/rx3270/rx3270.h" /> |
293 | <Unit filename="src/plugins/rx3270/rxapimain.cc" /> | 293 | <Unit filename="src/plugins/rx3270/rxapimain.cc" /> |
294 | <Unit filename="src/plugins/rx3270/sample/object.rex" /> | 294 | <Unit filename="src/plugins/rx3270/sample/object.rex" /> |
295 | + <Unit filename="src/plugins/rx3270/sample/remote.rex" /> | ||
295 | <Unit filename="src/plugins/rx3270/text.cc" /> | 296 | <Unit filename="src/plugins/rx3270/text.cc" /> |
296 | <Unit filename="src/plugins/rx3270/typed_routines.cc" /> | 297 | <Unit filename="src/plugins/rx3270/typed_routines.cc" /> |
297 | <Unit filename="src/pw3270/Makefile.in" /> | 298 | <Unit filename="src/pw3270/Makefile.in" /> |
src/plugins/dbus3270/gobject.c
@@ -103,6 +103,13 @@ void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *conte | @@ -103,6 +103,13 @@ void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *conte | ||
103 | dbus_g_method_return(context,lib3270_get_program_message(pw3270_dbus_get_session_handle(object))); | 103 | dbus_g_method_return(context,lib3270_get_program_message(pw3270_dbus_get_session_handle(object))); |
104 | } | 104 | } |
105 | 105 | ||
106 | +void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context) | ||
107 | +{ | ||
108 | + trace("%s object=%p context=%p",__FUNCTION__,object,context); | ||
109 | + dbus_g_method_return(context,lib3270_get_connection_state(pw3270_dbus_get_session_handle(object))); | ||
110 | +} | ||
111 | + | ||
112 | + | ||
106 | GError * pw3270_dbus_get_error_from_errno(int code) | 113 | GError * pw3270_dbus_get_error_from_errno(int code) |
107 | { | 114 | { |
108 | return g_error_new(ERROR_DOMAIN,code,"%s",g_strerror(code)); | 115 | return g_error_new(ERROR_DOMAIN,code,"%s",g_strerror(code)); |
src/plugins/dbus3270/pw3270dbus.xml
@@ -22,6 +22,10 @@ | @@ -22,6 +22,10 @@ | ||
22 | <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> | 22 | <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> |
23 | <arg type="i" name="status" direction="out" /> | 23 | <arg type="i" name="status" direction="out" /> |
24 | </method> | 24 | </method> |
25 | + <method name="getConnectionState"> | ||
26 | + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> | ||
27 | + <arg type="i" name="status" direction="out" /> | ||
28 | + </method> | ||
25 | <method name="getScreenContents"> | 29 | <method name="getScreenContents"> |
26 | <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> | 30 | <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> |
27 | <arg type="s" name="contents" direction="out" /> | 31 | <arg type="s" name="contents" direction="out" /> |
src/plugins/dbus3270/service.h
@@ -68,6 +68,7 @@ | @@ -68,6 +68,7 @@ | ||
68 | void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); | 68 | void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); |
69 | void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); | 69 | void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); |
70 | void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); | 70 | void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); |
71 | + void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); | ||
71 | void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context); | 72 | void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context); |
72 | H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); | 73 | H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); |
73 | GError * pw3270_dbus_get_error_from_errno(int code); | 74 | GError * pw3270_dbus_get_error_from_errno(int code); |
src/plugins/rx3270/pluginmain.cc
@@ -31,6 +31,7 @@ | @@ -31,6 +31,7 @@ | ||
31 | #include <string.h> | 31 | #include <string.h> |
32 | #include <pw3270/plugin.h> | 32 | #include <pw3270/plugin.h> |
33 | #include <lib3270/actions.h> | 33 | #include <lib3270/actions.h> |
34 | + #include <lib3270/log.h> | ||
34 | 35 | ||
35 | /*--[ Plugin session object ]--------------------------------------------------------------------------------*/ | 36 | /*--[ Plugin session object ]--------------------------------------------------------------------------------*/ |
36 | 37 | ||
@@ -46,6 +47,8 @@ | @@ -46,6 +47,8 @@ | ||
46 | bool is_connected(void); | 47 | bool is_connected(void); |
47 | bool is_ready(void); | 48 | bool is_ready(void); |
48 | 49 | ||
50 | + void logva(const char *fmt, va_list args); | ||
51 | + | ||
49 | int iterate(bool wait); | 52 | int iterate(bool wait); |
50 | int wait(int seconds); | 53 | int wait(int seconds); |
51 | int wait_for_ready(int seconds); | 54 | int wait_for_ready(int seconds); |
@@ -184,3 +187,8 @@ | @@ -184,3 +187,8 @@ | ||
184 | { | 187 | { |
185 | lib3270_set_toggle(hSession,ix,(int) value); | 188 | lib3270_set_toggle(hSession,ix,(int) value); |
186 | } | 189 | } |
190 | + | ||
191 | + void plugin::logva(const char *fmt, va_list args) | ||
192 | + { | ||
193 | + lib3270_write_va_log(hSession,"REXX",fmt,args); | ||
194 | + } |
src/plugins/rx3270/remote.cc
@@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
18 | * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple |
19 | * Place, Suite 330, Boston, MA, 02111-1307, USA | 19 | * Place, Suite 330, Boston, MA, 02111-1307, USA |
20 | * | 20 | * |
21 | - * Este programa está nomeado como local.cc e possui - linhas de código. | 21 | + * Este programa está nomeado como remote.cc e possui - linhas de código. |
22 | * | 22 | * |
23 | * Contatos: | 23 | * Contatos: |
24 | * | 24 | * |
@@ -78,6 +78,7 @@ | @@ -78,6 +78,7 @@ | ||
78 | DBusMessage * create_message(const char *method); | 78 | DBusMessage * create_message(const char *method); |
79 | DBusMessage * call(DBusMessage *msg); | 79 | DBusMessage * call(DBusMessage *msg); |
80 | char * query_string(const char *method); | 80 | char * query_string(const char *method); |
81 | + int query_intval(const char *method); | ||
81 | #endif | 82 | #endif |
82 | 83 | ||
83 | 84 | ||
@@ -103,7 +104,7 @@ DBusMessage * remote::create_message(const char *method) | @@ -103,7 +104,7 @@ DBusMessage * remote::create_message(const char *method) | ||
103 | method); // method | 104 | method); // method |
104 | 105 | ||
105 | if (!msg) | 106 | if (!msg) |
106 | - fprintf(stderr, "Error creating message for method %s\n",method); | 107 | + log("Error creating message for method %s",method); |
107 | 108 | ||
108 | return msg; | 109 | return msg; |
109 | } | 110 | } |
@@ -170,13 +171,13 @@ remote::remote(const char *name) | @@ -170,13 +171,13 @@ remote::remote(const char *name) | ||
170 | 171 | ||
171 | if (dbus_error_is_set(&err)) | 172 | if (dbus_error_is_set(&err)) |
172 | { | 173 | { |
173 | - fprintf(stderr, "DBUS Connection Error (%s)\n", err.message); | 174 | + log("DBUS Connection Error (%s)", err.message); |
174 | dbus_error_free(&err); | 175 | dbus_error_free(&err); |
175 | } | 176 | } |
176 | 177 | ||
177 | if(!conn) | 178 | if(!conn) |
178 | { | 179 | { |
179 | - fprintf(stderr, "%s\n", "DBUS Connection failed"); | 180 | + log("%s", "DBUS Connection failed"); |
180 | dbus_connection_close(conn); | 181 | dbus_connection_close(conn); |
181 | conn = NULL; | 182 | conn = NULL; |
182 | return; | 183 | return; |
@@ -186,13 +187,13 @@ remote::remote(const char *name) | @@ -186,13 +187,13 @@ remote::remote(const char *name) | ||
186 | 187 | ||
187 | if (dbus_error_is_set(&err)) | 188 | if (dbus_error_is_set(&err)) |
188 | { | 189 | { |
189 | - fprintf(stderr, "Name Error (%s)\n", err.message); | 190 | + log("Name Error (%s)", err.message); |
190 | dbus_error_free(&err); | 191 | dbus_error_free(&err); |
191 | } | 192 | } |
192 | 193 | ||
193 | if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | 194 | if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) |
194 | { | 195 | { |
195 | - fprintf(stderr, "%s\n", "DBUS request name failed"); | 196 | + log("%s", "DBUS request name failed"); |
196 | dbus_connection_close(conn); | 197 | dbus_connection_close(conn); |
197 | conn = NULL; | 198 | conn = NULL; |
198 | return; | 199 | return; |
@@ -232,7 +233,7 @@ DBusMessage * remote::call(DBusMessage *msg) | @@ -232,7 +233,7 @@ DBusMessage * remote::call(DBusMessage *msg) | ||
232 | if(reply) | 233 | if(reply) |
233 | return reply; | 234 | return reply; |
234 | 235 | ||
235 | - fprintf(stderr,"%s\n",error.message); | 236 | + log("%s",error.message); |
236 | dbus_error_free(&error); | 237 | dbus_error_free(&error); |
237 | 238 | ||
238 | return NULL; | 239 | return NULL; |
@@ -267,6 +268,35 @@ char * remote::query_string(const char *method) | @@ -267,6 +268,35 @@ char * remote::query_string(const char *method) | ||
267 | return rc; | 268 | return rc; |
268 | } | 269 | } |
269 | 270 | ||
271 | +int remote::query_intval(const char *method) | ||
272 | +{ | ||
273 | + int rc = -1; | ||
274 | + | ||
275 | + if(conn) | ||
276 | + { | ||
277 | + DBusMessage * msg = call(create_message(method)); | ||
278 | + if(msg) | ||
279 | + { | ||
280 | + DBusMessageIter iter; | ||
281 | + | ||
282 | + if(dbus_message_iter_init(msg, &iter)) | ||
283 | + { | ||
284 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) | ||
285 | + { | ||
286 | + dbus_int32_t iSigned; | ||
287 | + dbus_message_iter_get_basic(&iter, &iSigned); | ||
288 | + rc = (int) iSigned; | ||
289 | + } | ||
290 | + } | ||
291 | + | ||
292 | + dbus_message_unref(msg); | ||
293 | + } | ||
294 | + } | ||
295 | + | ||
296 | + return rc; | ||
297 | +} | ||
298 | + | ||
299 | + | ||
270 | #endif // HAVE_DBUS | 300 | #endif // HAVE_DBUS |
271 | 301 | ||
272 | char * remote::get_revision(void) | 302 | char * remote::get_revision(void) |
@@ -293,12 +323,18 @@ LIB3270_CSTATE remote::get_cstate(void) | @@ -293,12 +323,18 @@ LIB3270_CSTATE remote::get_cstate(void) | ||
293 | { | 323 | { |
294 | #if defined(WIN32) | 324 | #if defined(WIN32) |
295 | 325 | ||
326 | + return (LIB3270_CSTATE) -1; | ||
327 | + | ||
296 | #elif defined(HAVE_DBUS) | 328 | #elif defined(HAVE_DBUS) |
297 | 329 | ||
298 | -#endif | 330 | + return (LIB3270_CSTATE) query_intval("getConnectionState"); |
331 | + | ||
332 | +#else | ||
299 | 333 | ||
300 | return (LIB3270_CSTATE) -1; | 334 | return (LIB3270_CSTATE) -1; |
301 | 335 | ||
336 | +#endif | ||
337 | + | ||
302 | } | 338 | } |
303 | 339 | ||
304 | int remote::disconnect(void) | 340 | int remote::disconnect(void) |
@@ -307,9 +343,14 @@ int remote::disconnect(void) | @@ -307,9 +343,14 @@ int remote::disconnect(void) | ||
307 | 343 | ||
308 | #elif defined(HAVE_DBUS) | 344 | #elif defined(HAVE_DBUS) |
309 | 345 | ||
310 | -#endif | 346 | + return query_intval("disconnect"); |
347 | + | ||
348 | +#else | ||
311 | 349 | ||
312 | return -1; | 350 | return -1; |
351 | + | ||
352 | +#endif | ||
353 | + | ||
313 | } | 354 | } |
314 | 355 | ||
315 | int remote::connect(const char *uri, bool wait) | 356 | int remote::connect(const char *uri, bool wait) |
@@ -351,8 +392,7 @@ int remote::iterate(bool wait) | @@ -351,8 +392,7 @@ int remote::iterate(bool wait) | ||
351 | 392 | ||
352 | #elif defined(HAVE_DBUS) | 393 | #elif defined(HAVE_DBUS) |
353 | 394 | ||
354 | - if(wait) | ||
355 | - this->wait(1); | 395 | + return 0; |
356 | 396 | ||
357 | #endif | 397 | #endif |
358 | 398 | ||
@@ -366,6 +406,7 @@ int remote::wait(int seconds) | @@ -366,6 +406,7 @@ int remote::wait(int seconds) | ||
366 | #elif defined(HAVE_DBUS) | 406 | #elif defined(HAVE_DBUS) |
367 | 407 | ||
368 | sleep(seconds); | 408 | sleep(seconds); |
409 | + return 0; | ||
369 | 410 | ||
370 | #endif | 411 | #endif |
371 | 412 | ||
@@ -431,11 +472,18 @@ int remote::enter(void) | @@ -431,11 +472,18 @@ int remote::enter(void) | ||
431 | { | 472 | { |
432 | #if defined(WIN32) | 473 | #if defined(WIN32) |
433 | 474 | ||
475 | + return -1; | ||
476 | + | ||
434 | #elif defined(HAVE_DBUS) | 477 | #elif defined(HAVE_DBUS) |
435 | 478 | ||
436 | -#endif | 479 | + return query_intval("enter"); |
480 | + | ||
481 | +#else | ||
437 | 482 | ||
438 | return -1; | 483 | return -1; |
484 | + | ||
485 | +#endif | ||
486 | + | ||
439 | } | 487 | } |
440 | 488 | ||
441 | int remote::pfkey(int key) | 489 | int remote::pfkey(int key) |
src/plugins/rx3270/rx3270.h
@@ -46,6 +46,7 @@ | @@ -46,6 +46,7 @@ | ||
46 | #include <stdio.h> | 46 | #include <stdio.h> |
47 | #include <lib3270.h> | 47 | #include <lib3270.h> |
48 | #include <lib3270/log.h> | 48 | #include <lib3270/log.h> |
49 | + #include <stdarg.h> | ||
49 | 50 | ||
50 | #ifndef ETIMEDOUT | 51 | #ifndef ETIMEDOUT |
51 | #define ETIMEDOUT -1 | 52 | #define ETIMEDOUT -1 |
@@ -130,10 +131,14 @@ | @@ -130,10 +131,14 @@ | ||
130 | char * get_3270_string(const char *str); | 131 | char * get_3270_string(const char *str); |
131 | char * get_local_string(const char *str); | 132 | char * get_local_string(const char *str); |
132 | 133 | ||
134 | + void log(const char *fmt, ...); | ||
135 | + virtual void logva(const char *fmt, va_list arg); | ||
136 | + | ||
133 | virtual char * get_version(void); | 137 | virtual char * get_version(void); |
134 | virtual char * get_revision(void); | 138 | virtual char * get_revision(void); |
135 | virtual LIB3270_CSTATE get_cstate(void) = 0; | 139 | virtual LIB3270_CSTATE get_cstate(void) = 0; |
136 | 140 | ||
141 | + | ||
137 | virtual int connect(const char *uri, bool wait = true) = 0; | 142 | virtual int connect(const char *uri, bool wait = true) = 0; |
138 | virtual int disconnect(void) = 0; | 143 | virtual int disconnect(void) = 0; |
139 | virtual bool is_connected(void) = 0; | 144 | virtual bool is_connected(void) = 0; |
src/plugins/rx3270/rxapimain.cc
@@ -38,6 +38,10 @@ | @@ -38,6 +38,10 @@ | ||
38 | #include "rx3270.h" | 38 | #include "rx3270.h" |
39 | #include <lib3270/actions.h> | 39 | #include <lib3270/actions.h> |
40 | 40 | ||
41 | +#ifdef HAVE_SYSLOG | ||
42 | + #include <syslog.h> | ||
43 | +#endif // HAVE_SYSLOG | ||
44 | + | ||
41 | #include <string.h> | 45 | #include <string.h> |
42 | 46 | ||
43 | #if defined WIN32 | 47 | #if defined WIN32 |
@@ -162,3 +166,21 @@ LIB3270_EXPORT RexxPackageEntry * RexxEntry RexxGetPackage(void) | @@ -162,3 +166,21 @@ LIB3270_EXPORT RexxPackageEntry * RexxEntry RexxGetPackage(void) | ||
162 | END_EXTERN_C() | 166 | END_EXTERN_C() |
163 | 167 | ||
164 | 168 | ||
169 | +void rx3270::log(const char *fmt, ...) | ||
170 | +{ | ||
171 | + va_list arg_ptr; | ||
172 | + va_start(arg_ptr, fmt); | ||
173 | + this->logva(fmt,arg_ptr); | ||
174 | + va_end(arg_ptr); | ||
175 | +} | ||
176 | + | ||
177 | +void rx3270::logva(const char *fmt, va_list args) | ||
178 | +{ | ||
179 | +#ifdef HAVE_SYSLOG | ||
180 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | ||
181 | + vsyslog(LOG_INFO,fmt,args); | ||
182 | + closelog(); | ||
183 | +#else | ||
184 | + vfprintf(stderr,fmt,args); | ||
185 | +#endif | ||
186 | +} |
src/plugins/rx3270/sample/remote.rex