Commit fe4a5aff05acab023646331ebfd0349678f42f9f
1 parent
b42878cf
Exists in
master
and in
5 other branches
Implementando interface DBUS no modulo rexx
Showing
9 changed files
with
169 additions
and
51 deletions
Show diff stats
src/plugins/rx3270/Makefile.in
| ... | ... | @@ -38,7 +38,7 @@ LN_S=@LN_S@ |
| 38 | 38 | |
| 39 | 39 | #---[ Include plugin rules ]--------------------------------------------------- |
| 40 | 40 | |
| 41 | -LIBS=@REXX_LIBS@ @LIBICONV@ | |
| 41 | +LIBS=@REXX_LIBS@ @LIBICONV@ @DBUS_LIBS@ | |
| 42 | 42 | CFLAGS=@REXX_CFLAGS@ @DBUS_CFLAGS@ |
| 43 | 43 | REXX_HOME=@REXX_HOME@ |
| 44 | 44 | REXXLIBDIR=$(libdir)/ooRexx | ... | ... |
src/plugins/rx3270/local.cc
| ... | ... | @@ -60,7 +60,7 @@ |
| 60 | 60 | dynamic(); |
| 61 | 61 | ~dynamic(); |
| 62 | 62 | |
| 63 | - const char * get_version(void); | |
| 63 | + char * get_version(void); | |
| 64 | 64 | LIB3270_CSTATE get_cstate(void); |
| 65 | 65 | int disconnect(void); |
| 66 | 66 | int connect(const char *uri, bool wait = true); |
| ... | ... | @@ -154,6 +154,15 @@ rx3270 * rx3270::create(const char *name) |
| 154 | 154 | return new dynamic(); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | +char * rx3270::get_version(void) | |
| 158 | +{ | |
| 159 | + return strdup(PACKAGE_VERSION); | |
| 160 | +} | |
| 161 | + | |
| 162 | +char * rx3270::get_revision(void) | |
| 163 | +{ | |
| 164 | + return strdup(PACKAGE_REVISION); | |
| 165 | +} | |
| 157 | 166 | |
| 158 | 167 | rx3270 * rx3270::get_default(void) |
| 159 | 168 | { |
| ... | ... | @@ -424,11 +433,11 @@ dynamic::~dynamic() |
| 424 | 433 | |
| 425 | 434 | } |
| 426 | 435 | |
| 427 | -const char * dynamic::get_version(void) | |
| 436 | +char * dynamic::get_version(void) | |
| 428 | 437 | { |
| 429 | 438 | if(!hModule) |
| 430 | 439 | return NULL; |
| 431 | - return _get_version(); | |
| 440 | + return strdup(_get_version()); | |
| 432 | 441 | } |
| 433 | 442 | |
| 434 | 443 | LIB3270_CSTATE dynamic::get_cstate(void) | ... | ... |
src/plugins/rx3270/pluginmain.cc
| ... | ... | @@ -28,6 +28,7 @@ |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | #include "rx3270.h" |
| 31 | + #include <string.h> | |
| 31 | 32 | #include <pw3270/plugin.h> |
| 32 | 33 | #include <lib3270/actions.h> |
| 33 | 34 | |
| ... | ... | @@ -38,7 +39,7 @@ |
| 38 | 39 | public: |
| 39 | 40 | plugin(H3270 *hSession); |
| 40 | 41 | |
| 41 | - const char * get_version(void); | |
| 42 | + char * get_version(void); | |
| 42 | 43 | LIB3270_CSTATE get_cstate(void); |
| 43 | 44 | int disconnect(void); |
| 44 | 45 | int connect(const char *uri, bool wait = true); |
| ... | ... | @@ -93,9 +94,9 @@ |
| 93 | 94 | this->hSession = hSession; |
| 94 | 95 | } |
| 95 | 96 | |
| 96 | - const char * plugin::get_version(void) | |
| 97 | + char * plugin::get_version(void) | |
| 97 | 98 | { |
| 98 | - return lib3270_get_version(); | |
| 99 | + return strdup(lib3270_get_version()); | |
| 99 | 100 | } |
| 100 | 101 | |
| 101 | 102 | LIB3270_CSTATE plugin::get_cstate(void) | ... | ... |
src/plugins/rx3270/remote.cc
| ... | ... | @@ -44,7 +44,7 @@ |
| 44 | 44 | remote(const char *session); |
| 45 | 45 | ~remote(); |
| 46 | 46 | |
| 47 | - const char * get_version(void); | |
| 47 | + char * get_revision(void); | |
| 48 | 48 | LIB3270_CSTATE get_cstate(void); |
| 49 | 49 | int disconnect(void); |
| 50 | 50 | int connect(const char *uri, bool wait = true); |
| ... | ... | @@ -72,10 +72,12 @@ |
| 72 | 72 | |
| 73 | 73 | #elif defined(HAVE_DBUS) |
| 74 | 74 | DBusConnection * conn; |
| 75 | - char * service_name; | |
| 76 | - char * interface_name; | |
| 75 | + char * dest; | |
| 76 | + char * path; | |
| 77 | + char * intf; | |
| 77 | 78 | DBusMessage * create_message(const char *method); |
| 78 | - | |
| 79 | + DBusMessage * call(DBusMessage *msg); | |
| 80 | + char * query_string(const char *method); | |
| 79 | 81 | #endif |
| 80 | 82 | |
| 81 | 83 | |
| ... | ... | @@ -84,8 +86,8 @@ |
| 84 | 86 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
| 85 | 87 | |
| 86 | 88 | #if defined(HAVE_DBUS) |
| 87 | - static const char * prefix = "br.com.bb."; | |
| 88 | - static const char * object = "br/com/bb/" PACKAGE_NAME; | |
| 89 | + static const char * prefix_dest = "br.com.bb."; | |
| 90 | + static const char * prefix_path = "/br/com/bb/"; | |
| 89 | 91 | #else |
| 90 | 92 | #error AQUI |
| 91 | 93 | #endif // HAVE_DBUS |
| ... | ... | @@ -95,10 +97,10 @@ |
| 95 | 97 | #if defined(HAVE_DBUS) |
| 96 | 98 | DBusMessage * remote::create_message(const char *method) |
| 97 | 99 | { |
| 98 | - DBusMessage * msg = dbus_message_new_method_call( service_name, | |
| 99 | - object, | |
| 100 | - interface_name, | |
| 101 | - method); | |
| 100 | + DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
| 101 | + this->path, // Path | |
| 102 | + this->intf, // Interface | |
| 103 | + method); // method | |
| 102 | 104 | |
| 103 | 105 | if (!msg) |
| 104 | 106 | fprintf(stderr, "Error creating message for method %s\n",method); |
| ... | ... | @@ -130,40 +132,35 @@ remote::remote(const char *name) |
| 130 | 132 | |
| 131 | 133 | *(ptr++) = 0; |
| 132 | 134 | |
| 133 | - sz = strlen(ptr)+strlen(name)+strlen(prefix)+2; | |
| 135 | + // Build destination | |
| 136 | + sz = strlen(ptr)+strlen(str)+strlen(prefix_dest)+2; | |
| 137 | + dest = (char *) malloc(sz+1); | |
| 138 | + strncpy(dest,prefix_dest,sz); | |
| 139 | + strncat(dest,str,sz); | |
| 140 | + strncat(dest,".",sz); | |
| 141 | + strncat(dest,ptr,sz); | |
| 142 | + | |
| 143 | + // Build path | |
| 144 | + sz = strlen(str)+strlen(prefix_path); | |
| 145 | + path = (char *) malloc(sz+1); | |
| 146 | + strncpy(path,prefix_path,sz); | |
| 147 | + strncat(path,str,sz); | |
| 148 | + | |
| 149 | + // Build intf | |
| 150 | + sz = strlen(str)+strlen(prefix_dest)+1; | |
| 151 | + intf = (char *) malloc(sz+1); | |
| 152 | + strncpy(intf,prefix_dest,sz); | |
| 153 | + strncat(intf,str,sz); | |
| 134 | 154 | |
| 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 | 155 | |
| 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 | 156 | } |
| 148 | 157 | else |
| 149 | 158 | { |
| 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); | |
| 159 | + exit(-1); | |
| 162 | 160 | |
| 163 | 161 | } |
| 164 | 162 | |
| 165 | - trace("service_name: [%s]", service_name); | |
| 166 | - trace("interface_name: [%s]", interface_name); | |
| 163 | + trace("DBUS:\nDestination:\t[%s]\nPath:\t\t[%s]\nInterface:\t[%s]",dest,path,intf); | |
| 167 | 164 | |
| 168 | 165 | free(str); |
| 169 | 166 | |
| ... | ... | @@ -213,28 +210,85 @@ remote::~remote() |
| 213 | 210 | |
| 214 | 211 | #elif defined(HAVE_DBUS) |
| 215 | 212 | |
| 216 | - if(conn) | |
| 217 | - dbus_connection_close(conn); | |
| 218 | - | |
| 219 | - free(service_name); | |
| 220 | - free(interface_name); | |
| 213 | + free(dest); | |
| 214 | + free(path); | |
| 215 | + free(intf); | |
| 221 | 216 | |
| 222 | 217 | #else |
| 223 | 218 | |
| 224 | 219 | #endif |
| 225 | 220 | } |
| 226 | 221 | |
| 227 | -const char * remote::get_version(void) | |
| 222 | +#if defined(HAVE_DBUS) | |
| 223 | +DBusMessage * remote::call(DBusMessage *msg) | |
| 224 | +{ | |
| 225 | + DBusMessage * reply; | |
| 226 | + DBusError error; | |
| 227 | + | |
| 228 | + dbus_error_init(&error); | |
| 229 | + reply = dbus_connection_send_with_reply_and_block(conn,msg,10000,&error); | |
| 230 | + dbus_message_unref(msg); | |
| 231 | + | |
| 232 | + if(reply) | |
| 233 | + return reply; | |
| 234 | + | |
| 235 | + fprintf(stderr,"%s\n",error.message); | |
| 236 | + dbus_error_free(&error); | |
| 237 | + | |
| 238 | + return NULL; | |
| 239 | + | |
| 240 | +} | |
| 241 | + | |
| 242 | +char * remote::query_string(const char *method) | |
| 243 | +{ | |
| 244 | + char *rc = NULL; | |
| 245 | + | |
| 246 | + if(conn) | |
| 247 | + { | |
| 248 | + DBusMessage * msg = call(create_message(method)); | |
| 249 | + if(msg) | |
| 250 | + { | |
| 251 | + DBusMessageIter iter; | |
| 252 | + | |
| 253 | + if(dbus_message_iter_init(msg, &iter)) | |
| 254 | + { | |
| 255 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) | |
| 256 | + { | |
| 257 | + const char * str; | |
| 258 | + dbus_message_iter_get_basic(&iter, &str); | |
| 259 | + rc = strdup(str); | |
| 260 | + } | |
| 261 | + } | |
| 262 | + | |
| 263 | + dbus_message_unref(msg); | |
| 264 | + } | |
| 265 | + } | |
| 266 | + | |
| 267 | + return rc; | |
| 268 | +} | |
| 269 | + | |
| 270 | +#endif // HAVE_DBUS | |
| 271 | + | |
| 272 | +char * remote::get_revision(void) | |
| 228 | 273 | { |
| 229 | 274 | #if defined(WIN32) |
| 230 | 275 | |
| 276 | + return NULL; | |
| 277 | + | |
| 278 | + | |
| 231 | 279 | #elif defined(HAVE_DBUS) |
| 232 | 280 | |
| 233 | -#endif | |
| 281 | + return query_string("getRevision"); | |
| 282 | + | |
| 283 | +#else | |
| 234 | 284 | |
| 235 | 285 | return NULL; |
| 286 | + | |
| 287 | +#endif | |
| 288 | + | |
| 236 | 289 | } |
| 237 | 290 | |
| 291 | + | |
| 238 | 292 | LIB3270_CSTATE remote::get_cstate(void) |
| 239 | 293 | { |
| 240 | 294 | #if defined(WIN32) |
| ... | ... | @@ -297,6 +351,9 @@ int remote::iterate(bool wait) |
| 297 | 351 | |
| 298 | 352 | #elif defined(HAVE_DBUS) |
| 299 | 353 | |
| 354 | + if(wait) | |
| 355 | + this->wait(1); | |
| 356 | + | |
| 300 | 357 | #endif |
| 301 | 358 | |
| 302 | 359 | return -1; |
| ... | ... | @@ -308,6 +365,8 @@ int remote::wait(int seconds) |
| 308 | 365 | |
| 309 | 366 | #elif defined(HAVE_DBUS) |
| 310 | 367 | |
| 368 | + sleep(seconds); | |
| 369 | + | |
| 311 | 370 | #endif |
| 312 | 371 | |
| 313 | 372 | return -1; | ... | ... |
src/plugins/rx3270/rexx_methods.cc
| ... | ... | @@ -54,6 +54,36 @@ RexxMethod1(int, rx3270_method_uninit, CSELF, sessionPtr) |
| 54 | 54 | return 0; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | +RexxMethod1(RexxStringObject, rx3270_method_version, CSELF, sessionPtr) | |
| 58 | +{ | |
| 59 | + rx3270 * session = (rx3270 *) sessionPtr; | |
| 60 | + | |
| 61 | + if(session) | |
| 62 | + { | |
| 63 | + char * version = session->get_version(); | |
| 64 | + RexxStringObject ret = context->String((CSTRING) (version ? version : "ERROR:")); | |
| 65 | + free(version); | |
| 66 | + return ret; | |
| 67 | + } | |
| 68 | + | |
| 69 | + return context->String((CSTRING) PACKAGE_VERSION); | |
| 70 | +} | |
| 71 | + | |
| 72 | +RexxMethod1(RexxStringObject, rx3270_method_revision, CSELF, sessionPtr) | |
| 73 | +{ | |
| 74 | + rx3270 * session = (rx3270 *) sessionPtr; | |
| 75 | + | |
| 76 | + if(session) | |
| 77 | + { | |
| 78 | + char * version = session->get_revision(); | |
| 79 | + RexxStringObject ret = context->String((CSTRING) (version ? version : PACKAGE_REVISION)); | |
| 80 | + free(version); | |
| 81 | + return ret; | |
| 82 | + } | |
| 83 | + | |
| 84 | + return context->String((CSTRING) PACKAGE_REVISION); | |
| 85 | +} | |
| 86 | + | |
| 57 | 87 | RexxMethod3(int, rx3270_method_connect, CSELF, sessionPtr, CSTRING, uri, OPTIONAL_int, wait) |
| 58 | 88 | { |
| 59 | 89 | rx3270 *hSession = (rx3270 *) sessionPtr; | ... | ... |
src/plugins/rx3270/rx3270.cls
| ... | ... | @@ -37,6 +37,9 @@ |
| 37 | 37 | ::METHOD INIT EXTERNAL "LIBRARY rx3270 rx3270_method_init" |
| 38 | 38 | ::METHOD UNINIT EXTERNAL "LIBRARY rx3270 rx3270_method_uninit" |
| 39 | 39 | |
| 40 | +::METHOD VERSION EXTERNAL "LIBRARY rx3270 rx3270_method_version" | |
| 41 | +::METHOD REVISION EXTERNAL "LIBRARY rx3270 rx3270_method_revision" | |
| 42 | + | |
| 40 | 43 | ::METHOD CONNECT EXTERNAL "LIBRARY rx3270 rx3270_method_connect" |
| 41 | 44 | ::METHOD DISCONNECT EXTERNAL "LIBRARY rx3270 rx3270_method_disconnect" |
| 42 | 45 | ... | ... |
src/plugins/rx3270/rx3270.h
| ... | ... | @@ -74,6 +74,8 @@ |
| 74 | 74 | REXX_TYPED_ROUTINE_PROTOTYPE(rx3270queryStringAt); |
| 75 | 75 | REXX_TYPED_ROUTINE_PROTOTYPE(rx3270SetStringAt); |
| 76 | 76 | |
| 77 | + REXX_METHOD_PROTOTYPE(rx3270_method_version); | |
| 78 | + REXX_METHOD_PROTOTYPE(rx3270_method_revision); | |
| 77 | 79 | REXX_METHOD_PROTOTYPE(rx3270_method_init); |
| 78 | 80 | REXX_METHOD_PROTOTYPE(rx3270_method_uninit); |
| 79 | 81 | REXX_METHOD_PROTOTYPE(rx3270_method_connect); |
| ... | ... | @@ -128,7 +130,8 @@ |
| 128 | 130 | char * get_3270_string(const char *str); |
| 129 | 131 | char * get_local_string(const char *str); |
| 130 | 132 | |
| 131 | - virtual const char * get_version(void) = 0; | |
| 133 | + virtual char * get_version(void); | |
| 134 | + virtual char * get_revision(void); | |
| 132 | 135 | virtual LIB3270_CSTATE get_cstate(void) = 0; |
| 133 | 136 | |
| 134 | 137 | virtual int connect(const char *uri, bool wait = true) = 0; | ... | ... |
src/plugins/rx3270/rxapimain.cc
| ... | ... | @@ -111,6 +111,8 @@ RexxRoutineEntry rx3270_functions[] = |
| 111 | 111 | |
| 112 | 112 | RexxMethodEntry rx3270_methods[] = |
| 113 | 113 | { |
| 114 | + REXX_METHOD(rx3270_method_version, rx3270_method_version ), | |
| 115 | + REXX_METHOD(rx3270_method_revision, rx3270_method_revision ), | |
| 114 | 116 | REXX_METHOD(rx3270_method_init, rx3270_method_init ), |
| 115 | 117 | REXX_METHOD(rx3270_method_uninit, rx3270_method_uninit ), |
| 116 | 118 | REXX_METHOD(rx3270_method_connect, rx3270_method_connect ), | ... | ... |