Commit b42878cfc9993c5315dea07e22c675a55d899eea
1 parent
1699197d
Exists in
master
and in
5 other branches
Implementando interface para acesso via DBUS no objeto rexx
Showing
8 changed files
with
427 additions
and
15 deletions
Show diff stats
configure.ac
pw3270.cbp
| ... | ... | @@ -286,6 +286,7 @@ |
| 286 | 286 | <Unit filename="src/plugins/rx3270/Makefile.in" /> |
| 287 | 287 | <Unit filename="src/plugins/rx3270/local.cc" /> |
| 288 | 288 | <Unit filename="src/plugins/rx3270/pluginmain.cc" /> |
| 289 | + <Unit filename="src/plugins/rx3270/remote.cc" /> | |
| 289 | 290 | <Unit filename="src/plugins/rx3270/rexx_methods.cc" /> |
| 290 | 291 | <Unit filename="src/plugins/rx3270/rx3270.cls" /> |
| 291 | 292 | <Unit filename="src/plugins/rx3270/rx3270.h" /> | ... | ... |
src/include/lib3270/config.h.in
src/plugins/rx3270/Makefile.in
| ... | ... | @@ -29,23 +29,22 @@ |
| 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 rexx_methods.cc | |
| 32 | +EXTAPI_SRC=rxapimain.cc text.cc typed_routines.cc local.cc remote.cc rexx_methods.cc | |
| 33 | 33 | |
| 34 | 34 | #---[ Tools ]------------------------------------------------------------------ |
| 35 | 35 | |
| 36 | 36 | REXXCONFIG=@REXXCONFIG@ |
| 37 | 37 | LN_S=@LN_S@ |
| 38 | 38 | |
| 39 | -LIBS=@REXX_LIBS@ @LIBICONV@ | |
| 40 | -CFLAGS=@REXX_CFLAGS@ | |
| 41 | - | |
| 42 | 39 | #---[ Include plugin rules ]--------------------------------------------------- |
| 43 | 40 | |
| 44 | -include ../../include/plugin.mak | |
| 45 | - | |
| 41 | +LIBS=@REXX_LIBS@ @LIBICONV@ | |
| 42 | +CFLAGS=@REXX_CFLAGS@ @DBUS_CFLAGS@ | |
| 46 | 43 | REXX_HOME=@REXX_HOME@ |
| 47 | 44 | REXXLIBDIR=$(libdir)/ooRexx |
| 48 | 45 | |
| 46 | +include ../../include/plugin.mak | |
| 47 | + | |
| 49 | 48 | #---[ Debug Targets ]---------------------------------------------------------- |
| 50 | 49 | |
| 51 | 50 | $(BINDBG)/$(PLUGIN_NAME): $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$(SRC).o) $(BINDBG)$(DLL_NAME) | ... | ... |
src/plugins/rx3270/local.cc
| ... | ... | @@ -147,13 +147,10 @@ rx3270::~rx3270() |
| 147 | 147 | defSession = NULL; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | -rx3270 * rx3270::create(const char *type) | |
| 150 | +rx3270 * rx3270::create(const char *name) | |
| 151 | 151 | { |
| 152 | - if(type && *type) | |
| 153 | - { | |
| 154 | - // Create remote session | |
| 155 | - return NULL; | |
| 156 | - } | |
| 152 | + if(name && *name) | |
| 153 | + return create_remote(name); | |
| 157 | 154 | return new dynamic(); |
| 158 | 155 | } |
| 159 | 156 | ... | ... |
| ... | ... | @@ -0,0 +1,411 @@ |
| 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 | + | |
| 32 | +#if defined(HAVE_DBUS) | |
| 33 | + #include <stdio.h> | |
| 34 | + #include <dbus/dbus.h> | |
| 35 | +#endif // HAVE_DBUS | |
| 36 | + | |
| 37 | + #include <string.h> | |
| 38 | + | |
| 39 | +/*--[ Class definition ]-----------------------------------------------------------------------------*/ | |
| 40 | + | |
| 41 | + class remote : public rx3270 | |
| 42 | + { | |
| 43 | + public: | |
| 44 | + remote(const char *session); | |
| 45 | + ~remote(); | |
| 46 | + | |
| 47 | + const char * get_version(void); | |
| 48 | + LIB3270_CSTATE get_cstate(void); | |
| 49 | + int disconnect(void); | |
| 50 | + int connect(const char *uri, bool wait = true); | |
| 51 | + bool is_connected(void); | |
| 52 | + bool is_ready(void); | |
| 53 | + | |
| 54 | + int iterate(bool wait); | |
| 55 | + int wait(int seconds); | |
| 56 | + int wait_for_ready(int seconds); | |
| 57 | + | |
| 58 | + char * get_text_at(int row, int col, size_t sz); | |
| 59 | + int cmp_text_at(int row, int col, const char *text); | |
| 60 | + int set_text_at(int row, int col, const char *str); | |
| 61 | + | |
| 62 | + int set_cursor_position(int row, int col); | |
| 63 | + | |
| 64 | + void set_toggle(LIB3270_TOGGLE ix, bool value); | |
| 65 | + | |
| 66 | + int enter(void); | |
| 67 | + int pfkey(int key); | |
| 68 | + int pakey(int key); | |
| 69 | + | |
| 70 | + private: | |
| 71 | +#if defined(WIN32) | |
| 72 | + | |
| 73 | +#elif defined(HAVE_DBUS) | |
| 74 | + DBusConnection * conn; | |
| 75 | + char * service_name; | |
| 76 | + char * interface_name; | |
| 77 | + DBusMessage * create_message(const char *method); | |
| 78 | + | |
| 79 | +#endif | |
| 80 | + | |
| 81 | + | |
| 82 | + }; | |
| 83 | + | |
| 84 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
| 85 | + | |
| 86 | +#if defined(HAVE_DBUS) | |
| 87 | + static const char * prefix = "br.com.bb."; | |
| 88 | + static const char * object = "br/com/bb/" PACKAGE_NAME; | |
| 89 | +#else | |
| 90 | + #error AQUI | |
| 91 | +#endif // HAVE_DBUS | |
| 92 | + | |
| 93 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 94 | + | |
| 95 | +#if defined(HAVE_DBUS) | |
| 96 | +DBusMessage * remote::create_message(const char *method) | |
| 97 | +{ | |
| 98 | + DBusMessage * msg = dbus_message_new_method_call( service_name, | |
| 99 | + object, | |
| 100 | + interface_name, | |
| 101 | + method); | |
| 102 | + | |
| 103 | + if (!msg) | |
| 104 | + fprintf(stderr, "Error creating message for method %s\n",method); | |
| 105 | + | |
| 106 | + return msg; | |
| 107 | +} | |
| 108 | +#endif // HAVE_DBUS | |
| 109 | + | |
| 110 | + | |
| 111 | +rx3270 * rx3270::create_remote(const char *name) | |
| 112 | +{ | |
| 113 | + return new remote(name); | |
| 114 | +} | |
| 115 | + | |
| 116 | + | |
| 117 | +remote::remote(const char *name) | |
| 118 | +{ | |
| 119 | +#if defined(WIN32) | |
| 120 | + | |
| 121 | +#elif defined(HAVE_DBUS) | |
| 122 | + DBusError err; | |
| 123 | + int rc; | |
| 124 | + char * str = strdup(name); | |
| 125 | + char * ptr = strchr(str,':'); | |
| 126 | + | |
| 127 | + if(ptr) | |
| 128 | + { | |
| 129 | + size_t sz; | |
| 130 | + | |
| 131 | + *(ptr++) = 0; | |
| 132 | + | |
| 133 | + sz = strlen(ptr)+strlen(name)+strlen(prefix)+2; | |
| 134 | + | |
| 135 | + service_name = (char *) malloc(sz+1); | |
| 136 | + strncpy(service_name,prefix,sz); | |
| 137 | + strncat(service_name,".",sz); | |
| 138 | + strncat(service_name,name,sz); | |
| 139 | + strncat(service_name,".",sz); | |
| 140 | + strncat(service_name,ptr,sz); | |
| 141 | + | |
| 142 | + sz = strlen(prefix)+strlen(name)+1; | |
| 143 | + interface_name = (char *) malloc(sz+1); | |
| 144 | + strncpy(interface_name,prefix,sz); | |
| 145 | + strncat(interface_name,".",sz); | |
| 146 | + strncat(interface_name,name,sz); | |
| 147 | + } | |
| 148 | + else | |
| 149 | + { | |
| 150 | + size_t sz = strlen(name)+strlen(prefix)+1; | |
| 151 | + | |
| 152 | + service_name = (char *) malloc(sz+1); | |
| 153 | + strncpy(service_name,prefix,sz); | |
| 154 | + strncat(service_name,".",sz); | |
| 155 | + strncat(service_name,name,sz); | |
| 156 | + | |
| 157 | + sz = strlen(prefix)+strlen(name)+1; | |
| 158 | + interface_name = (char *) malloc(sz+1); | |
| 159 | + strncpy(interface_name,prefix,sz); | |
| 160 | + strncat(interface_name,".",sz); | |
| 161 | + strncat(interface_name,name,sz); | |
| 162 | + | |
| 163 | + } | |
| 164 | + | |
| 165 | + trace("service_name: [%s]", service_name); | |
| 166 | + trace("interface_name: [%s]", interface_name); | |
| 167 | + | |
| 168 | + free(str); | |
| 169 | + | |
| 170 | + dbus_error_init(&err); | |
| 171 | + | |
| 172 | + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); | |
| 173 | + | |
| 174 | + if (dbus_error_is_set(&err)) | |
| 175 | + { | |
| 176 | + fprintf(stderr, "DBUS Connection Error (%s)\n", err.message); | |
| 177 | + dbus_error_free(&err); | |
| 178 | + } | |
| 179 | + | |
| 180 | + if(!conn) | |
| 181 | + { | |
| 182 | + fprintf(stderr, "%s\n", "DBUS Connection failed"); | |
| 183 | + dbus_connection_close(conn); | |
| 184 | + conn = NULL; | |
| 185 | + return; | |
| 186 | + } | |
| 187 | + | |
| 188 | + rc = dbus_bus_request_name(conn, "br.com.bb." PACKAGE_NAME ".rexx", DBUS_NAME_FLAG_REPLACE_EXISTING , &err); | |
| 189 | + | |
| 190 | + if (dbus_error_is_set(&err)) | |
| 191 | + { | |
| 192 | + fprintf(stderr, "Name Error (%s)\n", err.message); | |
| 193 | + dbus_error_free(&err); | |
| 194 | + } | |
| 195 | + | |
| 196 | + if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | |
| 197 | + { | |
| 198 | + fprintf(stderr, "%s\n", "DBUS request name failed"); | |
| 199 | + dbus_connection_close(conn); | |
| 200 | + conn = NULL; | |
| 201 | + return; | |
| 202 | + } | |
| 203 | + | |
| 204 | + | |
| 205 | +#else | |
| 206 | + | |
| 207 | +#endif | |
| 208 | +} | |
| 209 | + | |
| 210 | +remote::~remote() | |
| 211 | +{ | |
| 212 | +#if defined(WIN32) | |
| 213 | + | |
| 214 | +#elif defined(HAVE_DBUS) | |
| 215 | + | |
| 216 | + if(conn) | |
| 217 | + dbus_connection_close(conn); | |
| 218 | + | |
| 219 | + free(service_name); | |
| 220 | + free(interface_name); | |
| 221 | + | |
| 222 | +#else | |
| 223 | + | |
| 224 | +#endif | |
| 225 | +} | |
| 226 | + | |
| 227 | +const char * remote::get_version(void) | |
| 228 | +{ | |
| 229 | +#if defined(WIN32) | |
| 230 | + | |
| 231 | +#elif defined(HAVE_DBUS) | |
| 232 | + | |
| 233 | +#endif | |
| 234 | + | |
| 235 | + return NULL; | |
| 236 | +} | |
| 237 | + | |
| 238 | +LIB3270_CSTATE remote::get_cstate(void) | |
| 239 | +{ | |
| 240 | +#if defined(WIN32) | |
| 241 | + | |
| 242 | +#elif defined(HAVE_DBUS) | |
| 243 | + | |
| 244 | +#endif | |
| 245 | + | |
| 246 | + return (LIB3270_CSTATE) -1; | |
| 247 | + | |
| 248 | +} | |
| 249 | + | |
| 250 | +int remote::disconnect(void) | |
| 251 | +{ | |
| 252 | +#if defined(WIN32) | |
| 253 | + | |
| 254 | +#elif defined(HAVE_DBUS) | |
| 255 | + | |
| 256 | +#endif | |
| 257 | + | |
| 258 | + return -1; | |
| 259 | +} | |
| 260 | + | |
| 261 | +int remote::connect(const char *uri, bool wait) | |
| 262 | +{ | |
| 263 | +#if defined(WIN32) | |
| 264 | + | |
| 265 | +#elif defined(HAVE_DBUS) | |
| 266 | + | |
| 267 | +#endif | |
| 268 | + | |
| 269 | + return -1; | |
| 270 | +} | |
| 271 | + | |
| 272 | +bool remote::is_connected(void) | |
| 273 | +{ | |
| 274 | +#if defined(WIN32) | |
| 275 | + | |
| 276 | +#elif defined(HAVE_DBUS) | |
| 277 | + | |
| 278 | +#endif | |
| 279 | + | |
| 280 | + return false; | |
| 281 | +} | |
| 282 | + | |
| 283 | +bool remote::is_ready(void) | |
| 284 | +{ | |
| 285 | +#if defined(WIN32) | |
| 286 | + | |
| 287 | +#elif defined(HAVE_DBUS) | |
| 288 | + | |
| 289 | +#endif | |
| 290 | + | |
| 291 | + return false; | |
| 292 | +} | |
| 293 | + | |
| 294 | +int remote::iterate(bool wait) | |
| 295 | +{ | |
| 296 | +#if defined(WIN32) | |
| 297 | + | |
| 298 | +#elif defined(HAVE_DBUS) | |
| 299 | + | |
| 300 | +#endif | |
| 301 | + | |
| 302 | + return -1; | |
| 303 | +} | |
| 304 | + | |
| 305 | +int remote::wait(int seconds) | |
| 306 | +{ | |
| 307 | +#if defined(WIN32) | |
| 308 | + | |
| 309 | +#elif defined(HAVE_DBUS) | |
| 310 | + | |
| 311 | +#endif | |
| 312 | + | |
| 313 | + return -1; | |
| 314 | +} | |
| 315 | + | |
| 316 | +int remote::wait_for_ready(int seconds) | |
| 317 | +{ | |
| 318 | +#if defined(WIN32) | |
| 319 | + | |
| 320 | +#elif defined(HAVE_DBUS) | |
| 321 | + | |
| 322 | +#endif | |
| 323 | + | |
| 324 | + return -1; | |
| 325 | +} | |
| 326 | + | |
| 327 | +char * remote::get_text_at(int row, int col, size_t sz) | |
| 328 | +{ | |
| 329 | +#if defined(WIN32) | |
| 330 | + | |
| 331 | +#elif defined(HAVE_DBUS) | |
| 332 | + | |
| 333 | +#endif | |
| 334 | + | |
| 335 | + return NULL; | |
| 336 | +} | |
| 337 | + | |
| 338 | +int remote::cmp_text_at(int row, int col, const char *text) | |
| 339 | +{ | |
| 340 | +#if defined(WIN32) | |
| 341 | + | |
| 342 | +#elif defined(HAVE_DBUS) | |
| 343 | + | |
| 344 | +#endif | |
| 345 | + | |
| 346 | + return 0; | |
| 347 | +} | |
| 348 | + | |
| 349 | +int remote::set_text_at(int row, int col, const char *str) | |
| 350 | +{ | |
| 351 | +#if defined(WIN32) | |
| 352 | + | |
| 353 | +#elif defined(HAVE_DBUS) | |
| 354 | + | |
| 355 | +#endif | |
| 356 | + | |
| 357 | + return -1; | |
| 358 | +} | |
| 359 | + | |
| 360 | +int remote::set_cursor_position(int row, int col) | |
| 361 | +{ | |
| 362 | +#if defined(WIN32) | |
| 363 | + | |
| 364 | +#elif defined(HAVE_DBUS) | |
| 365 | + | |
| 366 | +#endif | |
| 367 | + | |
| 368 | + return -1; | |
| 369 | +} | |
| 370 | + | |
| 371 | +int remote::enter(void) | |
| 372 | +{ | |
| 373 | +#if defined(WIN32) | |
| 374 | + | |
| 375 | +#elif defined(HAVE_DBUS) | |
| 376 | + | |
| 377 | +#endif | |
| 378 | + | |
| 379 | + return -1; | |
| 380 | +} | |
| 381 | + | |
| 382 | +int remote::pfkey(int key) | |
| 383 | +{ | |
| 384 | +#if defined(WIN32) | |
| 385 | + | |
| 386 | +#elif defined(HAVE_DBUS) | |
| 387 | + | |
| 388 | +#endif | |
| 389 | + | |
| 390 | + return -1; | |
| 391 | +} | |
| 392 | + | |
| 393 | +int remote::pakey(int key) | |
| 394 | +{ | |
| 395 | +#if defined(WIN32) | |
| 396 | + | |
| 397 | +#elif defined(HAVE_DBUS) | |
| 398 | + | |
| 399 | +#endif | |
| 400 | + | |
| 401 | + return -1; | |
| 402 | +} | |
| 403 | + | |
| 404 | +void remote::set_toggle(LIB3270_TOGGLE ix, bool value) | |
| 405 | +{ | |
| 406 | +#if defined(WIN32) | |
| 407 | + | |
| 408 | +#elif defined(HAVE_DBUS) | |
| 409 | + | |
| 410 | +#endif | |
| 411 | +} | ... | ... |
src/plugins/rx3270/rexx_methods.cc
| ... | ... | @@ -94,12 +94,12 @@ RexxMethod1(logical_t, rx3270_method_is_ready, CSELF, sessionPtr) |
| 94 | 94 | return hSession->is_ready(); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | -RexxMethod2(int, rx3270_method_wait_for_ready, CSELF, sessionPtr, int, seconds) | |
| 97 | +RexxMethod2(int, rx3270_method_wait_for_ready, CSELF, sessionPtr, OPTIONAL_int, seconds) | |
| 98 | 98 | { |
| 99 | 99 | rx3270 *hSession = (rx3270 *) sessionPtr; |
| 100 | 100 | if(!hSession) |
| 101 | 101 | return -1; |
| 102 | - return hSession->wait_for_ready(seconds); | |
| 102 | + return hSession->wait_for_ready(seconds > 0 ? seconds : 60); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | RexxMethod3(int, rx3270_method_set_cursor, CSELF, sessionPtr, int, row, int, col) | ... | ... |
src/plugins/rx3270/rx3270.h
| ... | ... | @@ -119,8 +119,10 @@ |
| 119 | 119 | rx3270(); |
| 120 | 120 | virtual ~rx3270(); |
| 121 | 121 | |
| 122 | - static rx3270 * create(const char *type = NULL); | |
| 122 | + static rx3270 * create(const char *name = NULL); | |
| 123 | + static rx3270 * create_remote(const char *name); | |
| 123 | 124 | static rx3270 * get_default(void); |
| 125 | + | |
| 124 | 126 | static void set_plugin(void); |
| 125 | 127 | |
| 126 | 128 | char * get_3270_string(const char *str); | ... | ... |