Commit 12e3bf678ac462e5d1f209ebbcc1fd001f532a66

Authored by perry.werneck@gmail.com
1 parent 93ef46b2

Melhorando objeto dbus

src/classlib/remote.cc
... ... @@ -229,9 +229,28 @@
229 229  
230 230 int query_intval(const char *method)
231 231 {
232   - if(conn)
233   - return get_intval(call(create_message(method)));
234   - return -1;
  232 + return get_intval(call(create_message(method)));
  233 + }
  234 +
  235 + int query_intval(const char *method, int first_arg_type, ...)
  236 + {
  237 + va_list var_args;
  238 + DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination
  239 + this->path, // Path
  240 + this->intf, // Interface
  241 + method); // method
  242 +
  243 + if (!msg)
  244 + {
  245 + throw exception("Error creating DBUS message for method %s",method);
  246 + return -1;
  247 + }
  248 +
  249 + va_start(var_args, first_arg_type);
  250 + dbus_message_append_args_valist(msg,first_arg_type,var_args);
  251 + va_end(var_args);
  252 +
  253 + return get_intval(call(msg));
235 254 }
236 255  
237 256 #else
... ... @@ -412,15 +431,10 @@
412 431  
413 432 trace("%s: Using DBUS name %s",__FUNCTION__,busname);
414 433  
415   - DBusMessage * msg = create_message("setScript");
  434 + const char * id = "r";
  435 + static const dbus_int32_t flag = 1;
  436 + query_intval("setScript", DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID);
416 437  
417   - if(msg)
418   - {
419   - const char * id = "r";
420   - static const dbus_int32_t flag = 1;
421   - dbus_message_append_args(msg, DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID);
422   - get_intval(call(msg));
423   - }
424 438  
425 439 #else
426 440  
... ... @@ -440,14 +454,9 @@
440 454  
441 455 try
442 456 {
443   - DBusMessage * msg = create_message("setScript");
444   - if(msg)
445   - {
446   - const char * id = "r";
447   - static const dbus_int32_t flag = 0;
448   - dbus_message_append_args(msg, DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID);
449   - get_intval(call(msg));
450   - }
  457 + const char * id = "r";
  458 + static const dbus_int32_t flag = 0;
  459 + query_intval("setScript", DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID);
451 460 }
452 461 catch(exception e)
453 462 {
... ... @@ -490,14 +499,7 @@
490 499  
491 500 #elif defined(HAVE_DBUS)
492 501  
493   - int rc;
494   - DBusMessage * msg = create_message("connect");
495   - if(!msg)
496   - return -1;
497   -
498   - dbus_message_append_args(msg, DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID);
499   -
500   - rc = get_intval(call(msg));
  502 + int rc = query_intval("connect", DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID);
501 503  
502 504 if(!rc && wait)
503 505 return wait_for_ready(120);
... ... @@ -537,15 +539,8 @@
537 539 {
538 540 static const dbus_int32_t delay = 2;
539 541  
540   - DBusMessage * msg = create_message("waitForReady");
541   - int rc;
542   -
543   - if(!msg)
544   - return -1;
  542 + int rc = query_intval("waitForReady", DBUS_TYPE_INT32, &delay, DBUS_TYPE_INVALID);
545 543  
546   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &delay, DBUS_TYPE_INVALID);
547   -
548   - rc = get_intval(call(msg));
549 544 trace("waitForReady exits with rc=%d",rc);
550 545  
551 546 if(rc != ETIMEDOUT)
... ... @@ -677,14 +672,7 @@
677 672 dbus_int32_t r = (dbus_int32_t) row;
678 673 dbus_int32_t c = (dbus_int32_t) col;
679 674  
680   - DBusMessage * msg = create_message("setTextAt");
681   - if(msg)
682   - {
683   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID);
684   - return get_intval(call(msg));
685   - }
686   -
687   - return -1;
  675 + return query_intval("setTextAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID);
688 676  
689 677 #else
690 678  
... ... @@ -714,12 +702,7 @@
714 702 dbus_int32_t r = (dbus_int32_t) row;
715 703 dbus_int32_t c = (dbus_int32_t) col;
716 704  
717   - DBusMessage * msg = create_message("cmpTextAt");
718   - if(msg)
719   - {
720   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
721   - return get_intval(call(msg));
722   - }
  705 + return query_intval("cmpTextAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
723 706  
724 707 #endif
725 708  
... ... @@ -782,12 +765,7 @@
782 765 dbus_int32_t r = (dbus_int32_t) row;
783 766 dbus_int32_t c = (dbus_int32_t) col;
784 767  
785   - DBusMessage * msg = create_message("setCursorAt");
786   - if(msg)
787   - {
788   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID);
789   - return get_intval(call(msg));
790   - }
  768 + return query_intval("setCursorAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID);
791 769  
792 770 #endif
793 771  
... ... @@ -806,12 +784,7 @@
806 784  
807 785 dbus_int32_t k = (dbus_int32_t) addr;
808 786  
809   - DBusMessage * msg = create_message("setCursorAddress");
810   - if(msg)
811   - {
812   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
813   - return get_intval(call(msg));
814   - }
  787 + return query_intval("setCursorAddress", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
815 788  
816 789 #endif
817 790  
... ... @@ -841,14 +814,7 @@
841 814  
842 815 dbus_int32_t k = (dbus_int32_t) key;
843 816  
844   - DBusMessage * msg = create_message("pfKey");
845   - if(msg)
846   - {
847   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
848   - return get_intval(call(msg));
849   - }
850   -
851   - return -1;
  817 + return query_intval("pfKey", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
852 818  
853 819 #else
854 820  
... ... @@ -870,13 +836,7 @@
870 836  
871 837 dbus_int32_t k = (dbus_int32_t) key;
872 838  
873   - DBusMessage * msg = create_message("paKey");
874   - if(msg)
875   - {
876   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
877   - return get_intval(call(msg));
878   - }
879   - return -1;
  839 + return query_intval("paKey", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
880 840  
881 841 #else
882 842  
... ... @@ -904,14 +864,7 @@
904 864 dbus_int32_t i = (dbus_int32_t) ix;
905 865 dbus_int32_t v = (dbus_int32_t) value;
906 866  
907   - DBusMessage * msg = create_message("setToggle");
908   - if(msg)
909   - {
910   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &i, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID);
911   - return get_intval(call(msg));
912   - }
913   -
914   - return -1;
  867 + return query_intval("setToggle", DBUS_TYPE_INT32, &i, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID);
915 868  
916 869 #else
917 870 return -1;
... ... @@ -938,14 +891,7 @@
938 891  
939 892 #elif defined(HAVE_DBUS)
940 893  
941   - DBusMessage * msg = create_message("input");
942   - if(msg)
943   - {
944   - dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID);
945   - return get_intval(call(msg));
946   - }
947   - return -1;
948   -
  894 + return query_intval("input", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID);
949 895 #else
950 896  
951 897 return -1;
... ... @@ -966,14 +912,7 @@
966 912  
967 913 dbus_int32_t k = (dbus_int32_t) baddr;
968 914  
969   - DBusMessage * msg = create_message("getFieldStart");
970   - if(msg)
971   - {
972   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
973   - return get_intval(call(msg));
974   - }
975   -
976   - return -1;
  915 + return query_intval("getFieldStart", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
977 916  
978 917 #else
979 918  
... ... @@ -995,14 +934,7 @@
995 934  
996 935 dbus_int32_t k = (dbus_int32_t) baddr;
997 936  
998   - DBusMessage * msg = create_message("getFieldLength");
999   - if(msg)
1000   - {
1001   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
1002   - return get_intval(call(msg));
1003   - }
1004   -
1005   - return -1;
  937 + return query_intval("getFieldLength", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID);
1006 938  
1007 939 #else
1008 940  
... ... @@ -1048,14 +980,7 @@
1048 980  
1049 981 int set_clipboard(const char *text)
1050 982 {
1051   - DBusMessage * msg = create_message("setClipboard");
1052   - if(msg)
1053   - {
1054   - dbus_message_append_args(msg, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
1055   - return get_intval(call(msg));
1056   - }
1057   -
1058   - return -1;
  983 + return query_intval("setClipboard", DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
1059 984 }
1060 985 #endif // HAVE_DBUS
1061 986  
... ...
src/plugins/rx3270/sample/remote.rex
1 1  
2 2 use arg uri
3 3  
  4 +trace "?R"
  5 +
4 6 host = .rx3270~new("pw3270:a")
5 7  
6   -say "PW3270 version is "||host~revision()
  8 +say "PW3270 revision is "||host~revision()
7 9 say "Connection state is "||host~connected()
8 10 say "Ready state is "||host~ready()
9 11  
... ...