Commit 74df497c29c72c9fff33c2a16013aa704715e48d

Authored by perry.werneck@gmail.com
1 parent 3787e42d

Implementando DBUS no módulo libreoffice para linux

src/oxt/local.cxx
... ... @@ -125,10 +125,20 @@
125 125 hThread = NULL;
126 126 hSession = NULL;
127 127  
128   - trace("%s",__FUNCTION__);
129   - hModule = osl_loadModuleAscii("lib3270.so",SAL_LOADMODULE_NOW);
  128 + hModule = osl_loadModuleAscii("lib3270.so." PACKAGE_VERSION,SAL_LOADMODULE_NOW);
  129 + trace("%s: hModule(lib3270.so." PACKAGE_VERSION ")=%p",__FUNCTION__,hModule);
  130 +
130 131 if(!hModule)
  132 + {
  133 + hModule = osl_loadModuleAscii("lib3270.so." PACKAGE_VERSION,SAL_LOADMODULE_NOW);
  134 + trace("%s: hModule(lib3270.so)=%p",__FUNCTION__,hModule);
  135 + }
  136 +
  137 + if(!hModule)
  138 + {
  139 + log("%s","Error loading lib3270");
131 140 return;
  141 + }
132 142  
133 143 for(int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++)
134 144 {
... ...
src/oxt/remote.cxx
... ... @@ -272,7 +272,13 @@ pw3270::ipc3270_session::~ipc3270_session()
272 272 int pw3270::ipc3270_session::get_revision(void)
273 273 {
274 274 #ifdef HAVE_DBUS
275   -
  275 + char *ptr = query_string("getRevision");
  276 + if(ptr)
  277 + {
  278 + int rc = atoi(ptr);
  279 + free(ptr);
  280 + return rc;
  281 + }
276 282 return -1;
277 283  
278 284 #else
... ... @@ -286,7 +292,7 @@ LIB3270_MESSAGE pw3270::ipc3270_session::get_state(void)
286 292 {
287 293 #ifdef HAVE_DBUS
288 294  
289   - return (LIB3270_MESSAGE) -1;
  295 + return (LIB3270_MESSAGE) query_intval("getMessageID");
290 296  
291 297 #else
292 298  
... ... @@ -299,7 +305,18 @@ char * pw3270::ipc3270_session::get_text_at(int row, int col, int len)
299 305 {
300 306 #ifdef HAVE_DBUS
301 307  
302   - return NULL;
  308 + dbus_int32_t r = (dbus_int32_t) row;
  309 + dbus_int32_t c = (dbus_int32_t) col;
  310 + dbus_int32_t l = (dbus_int32_t) len;
  311 +
  312 + DBusMessage * msg = create_message("getTextAt");
  313 + if(!msg)
  314 + return NULL;
  315 +
  316 + trace("%s(%d,%d,%d)",__FUNCTION__,r,c,l);
  317 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INT32, &l, DBUS_TYPE_INVALID);
  318 +
  319 + return get_string(call(msg));
303 320  
304 321 #else
305 322  
... ... @@ -312,7 +329,15 @@ int pw3270::ipc3270_session::set_text_at(int row, int col, const char *text)
312 329 {
313 330 #ifdef HAVE_DBUS
314 331  
315   - return -1;
  332 + dbus_int32_t r = (dbus_int32_t) row;
  333 + dbus_int32_t c = (dbus_int32_t) col;
  334 +
  335 + DBusMessage * msg = create_message("setTextAt");
  336 + if(msg)
  337 + {
  338 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
  339 + return get_intval(call(msg));
  340 + }
316 341  
317 342 #else
318 343  
... ... @@ -325,7 +350,15 @@ int pw3270::ipc3270_session::cmp_text_at(int row, int col, const char *text)
325 350 {
326 351 #ifdef HAVE_DBUS
327 352  
328   - return -1;
  353 + dbus_int32_t r = (dbus_int32_t) row;
  354 + dbus_int32_t c = (dbus_int32_t) col;
  355 +
  356 + DBusMessage * msg = create_message("cmpTextAt");
  357 + if(msg)
  358 + {
  359 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
  360 + return get_intval(call(msg));
  361 + }
329 362  
330 363 #else
331 364  
... ... @@ -336,13 +369,33 @@ int pw3270::ipc3270_session::cmp_text_at(int row, int col, const char *text)
336 369  
337 370 void pw3270::ipc3270_session::set_toggle(LIB3270_TOGGLE toggle, bool state)
338 371 {
  372 +#ifdef HAVE_DBUS
  373 +
  374 + dbus_int32_t i = (dbus_int32_t) toggle;
  375 + dbus_int32_t v = (dbus_int32_t) state;
  376 +
  377 + DBusMessage * msg = create_message("setToggle");
  378 + if(msg)
  379 + {
  380 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &i, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID);
  381 + get_intval(call(msg));
  382 + }
  383 +
  384 +#endif // HAVE_DBUS
339 385 }
340 386  
341 387 int pw3270::ipc3270_session::connect(const char *uri)
342 388 {
343 389 #ifdef HAVE_DBUS
344 390  
345   - return -1;
  391 + int rc;
  392 + DBusMessage * msg = create_message("connect");
  393 + if(!msg)
  394 + return -1;
  395 +
  396 + dbus_message_append_args(msg, DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID);
  397 +
  398 + return get_intval(call(msg));
346 399  
347 400 #else
348 401  
... ... @@ -355,7 +408,7 @@ int pw3270::ipc3270_session::disconnect(void)
355 408 {
356 409 #ifdef HAVE_DBUS
357 410  
358   - return -1;
  411 + return query_intval("disconnect");
359 412  
360 413 #else
361 414  
... ... @@ -368,7 +421,7 @@ bool pw3270::ipc3270_session::connected(void)
368 421 {
369 422 #ifdef HAVE_DBUS
370 423  
371   - return false;
  424 + return query_intval("isConnected") > 0;
372 425  
373 426 #else
374 427  
... ... @@ -381,7 +434,7 @@ int pw3270::ipc3270_session::enter(void)
381 434 {
382 435 #ifdef HAVE_DBUS
383 436  
384   - return -1;
  437 + return query_intval("enter");
385 438  
386 439 #else
387 440  
... ... @@ -394,33 +447,45 @@ int pw3270::ipc3270_session::pfkey(int key)
394 447 {
395 448 #ifdef HAVE_DBUS
396 449  
397   - return -1;
  450 + dbus_int32_t k = (dbus_int32_t) key;
398 451  
399   -#else
  452 + DBusMessage * msg = create_message("pfKey");
  453 + if(msg)
  454 + {
  455 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
  456 + return get_intval(call(msg));
  457 + }
  458 +
  459 +#endif // HAVE_DBUS
400 460  
401 461 return -1;
402 462  
403   -#endif // HAVE_DBUS
404 463 }
405 464  
406 465 int pw3270::ipc3270_session::pakey(int key)
407 466 {
408 467 #ifdef HAVE_DBUS
409 468  
410   - return -1;
  469 + dbus_int32_t k = (dbus_int32_t) key;
411 470  
412   -#else
  471 + DBusMessage * msg = create_message("paKey");
  472 + if(msg)
  473 + {
  474 + dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
  475 + return get_intval(call(msg));
  476 + }
  477 +
  478 +#endif // HAVE_DBUS
413 479  
414 480 return -1;
415 481  
416   -#endif // HAVE_DBUS
417 482 }
418 483  
419 484 bool pw3270::ipc3270_session::in_tn3270e()
420 485 {
421 486 #ifdef HAVE_DBUS
422 487  
423   - return false;
  488 + return query_intval("inTN3270E") > 0;
424 489  
425 490 #else
426 491  
... ... @@ -433,6 +498,7 @@ void pw3270::ipc3270_session::mem_free(void *ptr)
433 498 {
434 499 #ifdef HAVE_DBUS
435 500  
  501 + free(ptr);
436 502  
437 503 #else
438 504  
... ...
src/oxt/testprogram.cxx
... ... @@ -28,15 +28,15 @@
28 28 * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
29 29 *
30 30 */
31   -
32   -#include <stdio.h>
33   -#ifdef WIN32
34   - #include <windows.h>
35   - #define sleep(x) Sleep(x)
36   -#endif
37   -
38   -#define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr);
39   -
  31 +
  32 +#include <stdio.h>
  33 +#ifdef WIN32
  34 + #include <windows.h>
  35 + #define sleep(x) Sleep(x)
  36 +#endif
  37 +
  38 +#define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr);
  39 +
40 40 #include "globals.hpp"
41 41 #include <cppuhelper/bootstrap.hxx>
42 42 #include <com/sun/star/registry/XSimpleRegistry.hpp>
... ... @@ -51,10 +51,10 @@ using namespace cppu;
51 51  
52 52 int SAL_CALL main(int argc, char **argv)
53 53 {
54   - Reference< XSimpleRegistry > xReg = createSimpleRegistry();
55   -
  54 + Reference< XSimpleRegistry > xReg = createSimpleRegistry();
  55 +
56 56 OSL_ENSURE( xReg.is(), "### cannot get service instance of \"com.sun.star.regiystry.SimpleRegistry\"!" );
57   -
  57 +
58 58 xReg->open(OUString::createFromAscii("pw3270.uno.rdb"), sal_False, sal_False);
59 59  
60 60 OSL_ENSURE( xReg->isValid(), "### cannot open test registry \"pw3270.uno.rdb\"!" );
... ... @@ -75,11 +75,11 @@ int SAL_CALL main(int argc, char **argv)
75 75 OSL_ENSURE( xImplReg.is(), "### cannot get service instance of \"com.sun.star.registry.ImplementationRegistration\"!" );
76 76  
77 77 if (xImplReg.is())
78   - {
  78 + {
79 79 const char *libname = ".bin/Debug/pw3270.uno.so";
80   -
81   - trace("Loading %s",libname);
82   -
  80 +
  81 + trace("Loading %s",libname);
  82 +
83 83 xImplReg->registerImplementation(
84 84 OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), // loader for component
85 85 OUString::createFromAscii(libname), // component location
... ... @@ -92,8 +92,8 @@ int SAL_CALL main(int argc, char **argv)
92 92  
93 93 Reference< XInterface > xx ;
94 94 xx = xMgr->createInstanceWithContext(OUString::createFromAscii(IMPLNAME), xContext);
95   -
96   - printf("Instance: %p\n",&xx);
  95 +
  96 + printf("Instance: %p\n",&xx);
97 97  
98 98 Reference< pw3270intf > srv( xx, UNO_QUERY );
99 99  
... ... @@ -107,6 +107,8 @@ int SAL_CALL main(int argc, char **argv)
107 107 char buffer[4096];
108 108 OString str;
109 109  
  110 + srv->setSession(OUString::createFromAscii("pw3270:a"));
  111 +
110 112 printf("Revision:\t%d\n",srv->getRevision());
111 113  
112 114 srv->dsTrace(true);
... ... @@ -141,20 +143,20 @@ int SAL_CALL main(int argc, char **argv)
141 143 printf("Entire screen:\n%s\n",str.pData->buffer);
142 144  
143 145  
144   - */
  146 + */
145 147  
146 148 printf("Enter to exit...\n");
147 149 fgets(buffer,80,stdin);
148 150  
149   - printf("Disconnect(): %d\n" , srv->Disconnect());
150   -
  151 + printf("Disconnect(): %d\n" , srv->Disconnect());
  152 +
151 153 srv->sleep(5);
152 154  
153 155 }
154 156 }
155 157  
156 158  
157   - Reference< XComponent >::query( xContext )->dispose();
158   -
  159 + Reference< XComponent >::query( xContext )->dispose();
  160 +
159 161 return 0;
160 162 }
... ...
src/plugins/dbus3270/gobject.c
... ... @@ -264,6 +264,12 @@ void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, DBus
264 264 dbus_g_method_return(context,lib3270_is_ready(pw3270_dbus_get_session_handle(object)));
265 265 }
266 266  
  267 + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context)
  268 + {
  269 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  270 + dbus_g_method_return(context,lib3270_in_tn3270e(pw3270_dbus_get_session_handle(object)));
  271 + }
  272 +
267 273 void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context)
268 274 {
269 275 trace("%s object=%p context=%p",__FUNCTION__,object,context);
... ...
src/plugins/dbus3270/pw3270dbus.xml
... ... @@ -65,6 +65,10 @@
65 65 <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
66 66 <arg type="i" name="result" direction="out" />
67 67 </method>
  68 + <method name="inTN3270E">
  69 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  70 + <arg type="i" name="result" direction="out" />
  71 + </method>
68 72 <method name="waitForReady">
69 73 <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
70 74 <arg type="i" name="timeout" direction="in" />
... ...
src/plugins/dbus3270/service.h
... ... @@ -75,7 +75,7 @@
75 75  
76 76 void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context);
77 77 void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context);
78   -
  78 + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context);
79 79 void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context);
80 80 void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context);
81 81  
... ...