Commit b9c3bf7296b4a18ee377ff77f8c071fab8446628
1 parent
bce5593a
Exists in
master
and in
5 other branches
Simplificando módulo IPC windows
Showing
1 changed file
with
70 additions
and
155 deletions
Show diff stats
src/classlib/remote.cc
| @@ -100,9 +100,35 @@ | @@ -100,9 +100,35 @@ | ||
| 100 | return s; | 100 | return s; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | + int query_intval(void *pkt, size_t szQuery, bool dynamic = false) | ||
| 104 | + { | ||
| 105 | + struct hllapi_packet_result response; | ||
| 106 | + DWORD cbSize = (DWORD) szQuery; | ||
| 107 | + BOOL status; | ||
| 108 | + | ||
| 109 | + status = TransactNamedPipe(hPipe,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 110 | + | ||
| 111 | + if(dynamic) | ||
| 112 | + free(pkt); | ||
| 113 | + | ||
| 114 | + if(status) | ||
| 115 | + return response.rc; | ||
| 116 | + | ||
| 117 | + throw exception(GetLastError(),"%s","Transaction error"); | ||
| 118 | + | ||
| 119 | + } | ||
| 120 | + | ||
| 103 | 121 | ||
| 104 | #elif defined(HAVE_DBUS) | 122 | #elif defined(HAVE_DBUS) |
| 105 | 123 | ||
| 124 | + #define HLLAPI_PACKET_IS_CONNECTED "isConnected" | ||
| 125 | + #define HLLAPI_PACKET_GET_CSTATE "getConnectionState" | ||
| 126 | + #define HLLAPI_PACKET_IS_READY "isReady" | ||
| 127 | + #define HLLAPI_PACKET_DISCONNECT "disconnect" | ||
| 128 | + #define HLLAPI_PACKET_GET_CURSOR "getCursorAddress" | ||
| 129 | + #define HLLAPI_PACKET_ENTER "enter" | ||
| 130 | + #define HLLAPI_PACKET_QUIT "quit" | ||
| 131 | + | ||
| 106 | DBusConnection * conn; | 132 | DBusConnection * conn; |
| 107 | char * dest; | 133 | char * dest; |
| 108 | char * path; | 134 | char * path; |
| @@ -116,7 +142,7 @@ | @@ -116,7 +142,7 @@ | ||
| 116 | method); // method | 142 | method); // method |
| 117 | 143 | ||
| 118 | if (!msg) | 144 | if (!msg) |
| 119 | - throw exception("Error creating message for method %s",method); | 145 | + throw exception("Error creating DBUS message for method %s",method); |
| 120 | 146 | ||
| 121 | return msg; | 147 | return msg; |
| 122 | 148 | ||
| @@ -163,7 +189,7 @@ | @@ -163,7 +189,7 @@ | ||
| 163 | dbus_message_unref(msg); | 189 | dbus_message_unref(msg); |
| 164 | 190 | ||
| 165 | throw e; | 191 | throw e; |
| 166 | - return NULL; | 192 | + |
| 167 | } | 193 | } |
| 168 | 194 | ||
| 169 | } | 195 | } |
| @@ -208,6 +234,14 @@ | @@ -208,6 +234,14 @@ | ||
| 208 | return -1; | 234 | return -1; |
| 209 | } | 235 | } |
| 210 | 236 | ||
| 237 | +#else | ||
| 238 | + | ||
| 239 | + int query_intval(const char *method) | ||
| 240 | + { | ||
| 241 | + throw exception("Call to unimplemented RPC method \"%s\"",method); | ||
| 242 | + return -1 | ||
| 243 | + } | ||
| 244 | + | ||
| 211 | #endif | 245 | #endif |
| 212 | 246 | ||
| 213 | public: | 247 | public: |
| @@ -388,7 +422,9 @@ | @@ -388,7 +422,9 @@ | ||
| 388 | get_intval(call(msg)); | 422 | get_intval(call(msg)); |
| 389 | } | 423 | } |
| 390 | 424 | ||
| 391 | - #else | 425 | +#else |
| 426 | + | ||
| 427 | + throw exception("%s","RPC support is incomplete."); | ||
| 392 | 428 | ||
| 393 | #endif | 429 | #endif |
| 394 | } | 430 | } |
| @@ -429,46 +465,20 @@ | @@ -429,46 +465,20 @@ | ||
| 429 | 465 | ||
| 430 | bool is_connected(void) | 466 | bool is_connected(void) |
| 431 | { | 467 | { |
| 432 | -#if defined(WIN32) | ||
| 433 | - | ||
| 434 | return query_intval(HLLAPI_PACKET_IS_CONNECTED) != 0; | 468 | return query_intval(HLLAPI_PACKET_IS_CONNECTED) != 0; |
| 435 | - | ||
| 436 | -#elif defined(HAVE_DBUS) | ||
| 437 | - | ||
| 438 | - return query_intval("isConnected") != 0; | ||
| 439 | - | ||
| 440 | -#endif | ||
| 441 | - | ||
| 442 | - return false; | ||
| 443 | } | 469 | } |
| 444 | 470 | ||
| 445 | LIB3270_CSTATE get_cstate(void) | 471 | LIB3270_CSTATE get_cstate(void) |
| 446 | { | 472 | { |
| 447 | -#if defined(WIN32) | ||
| 448 | - | ||
| 449 | return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); | 473 | return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); |
| 450 | - | ||
| 451 | -#elif defined(HAVE_DBUS) | ||
| 452 | - | ||
| 453 | - return (LIB3270_CSTATE) query_intval("getConnectionState"); | ||
| 454 | - | ||
| 455 | -#else | ||
| 456 | - | ||
| 457 | - return (LIB3270_CSTATE) -1; | ||
| 458 | - | ||
| 459 | -#endif | ||
| 460 | - | ||
| 461 | } | 474 | } |
| 462 | 475 | ||
| 463 | int connect(const char *uri, bool wait) | 476 | int connect(const char *uri, bool wait) |
| 464 | { | 477 | { |
| 465 | #if defined(WIN32) | 478 | #if defined(WIN32) |
| 466 | - struct hllapi_packet_connect * pkt; | ||
| 467 | - struct hllapi_packet_result response; | ||
| 468 | - DWORD cbSize; | ||
| 469 | 479 | ||
| 470 | - cbSize = sizeof(struct hllapi_packet_connect)+strlen(uri); | ||
| 471 | - pkt = (struct hllapi_packet_connect *) malloc(cbSize); | 480 | + size_t cbSize = sizeof(struct hllapi_packet_connect)+strlen(uri); |
| 481 | + struct hllapi_packet_connect * pkt = (struct hllapi_packet_connect *) malloc(cbSize); | ||
| 472 | 482 | ||
| 473 | pkt->packet_id = HLLAPI_PACKET_CONNECT; | 483 | pkt->packet_id = HLLAPI_PACKET_CONNECT; |
| 474 | pkt->wait = (unsigned char) wait; | 484 | pkt->wait = (unsigned char) wait; |
| @@ -476,15 +486,7 @@ | @@ -476,15 +486,7 @@ | ||
| 476 | 486 | ||
| 477 | trace("Sending %s",pkt->hostname); | 487 | trace("Sending %s",pkt->hostname); |
| 478 | 488 | ||
| 479 | - if(TransactNamedPipe(hPipe,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL)) | ||
| 480 | - { | ||
| 481 | - free(pkt); | ||
| 482 | - return response.rc; | ||
| 483 | - } | ||
| 484 | - | ||
| 485 | - free(pkt); | ||
| 486 | - | ||
| 487 | - throw exception(GetLastError(),"%s","Transaction error"); | 489 | + return query_intval((void *) pkt,cbSize,true); |
| 488 | 490 | ||
| 489 | #elif defined(HAVE_DBUS) | 491 | #elif defined(HAVE_DBUS) |
| 490 | 492 | ||
| @@ -562,36 +564,13 @@ | @@ -562,36 +564,13 @@ | ||
| 562 | 564 | ||
| 563 | bool is_ready(void) | 565 | bool is_ready(void) |
| 564 | { | 566 | { |
| 565 | -#if defined(WIN32) | ||
| 566 | - | ||
| 567 | return query_intval(HLLAPI_PACKET_IS_READY) != 0; | 567 | return query_intval(HLLAPI_PACKET_IS_READY) != 0; |
| 568 | - | ||
| 569 | -#elif defined(HAVE_DBUS) | ||
| 570 | - | ||
| 571 | - return query_intval("isReady") != 0; | ||
| 572 | - | ||
| 573 | -#endif | ||
| 574 | - | ||
| 575 | - return false; | ||
| 576 | } | 568 | } |
| 577 | 569 | ||
| 578 | 570 | ||
| 579 | int disconnect(void) | 571 | int disconnect(void) |
| 580 | { | 572 | { |
| 581 | -#if defined(WIN32) | ||
| 582 | - | ||
| 583 | return query_intval(HLLAPI_PACKET_DISCONNECT); | 573 | return query_intval(HLLAPI_PACKET_DISCONNECT); |
| 584 | - | ||
| 585 | -#elif defined(HAVE_DBUS) | ||
| 586 | - | ||
| 587 | - return query_intval("disconnect"); | ||
| 588 | - | ||
| 589 | -#else | ||
| 590 | - | ||
| 591 | - return -1; | ||
| 592 | - | ||
| 593 | -#endif | ||
| 594 | - | ||
| 595 | } | 574 | } |
| 596 | 575 | ||
| 597 | 576 | ||
| @@ -720,8 +699,7 @@ | @@ -720,8 +699,7 @@ | ||
| 720 | #if defined(WIN32) | 699 | #if defined(WIN32) |
| 721 | 700 | ||
| 722 | struct hllapi_packet_text_at * query; | 701 | struct hllapi_packet_text_at * query; |
| 723 | - struct hllapi_packet_result response; | ||
| 724 | - DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text); | 702 | + size_t cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text); |
| 725 | 703 | ||
| 726 | query = (struct hllapi_packet_text_at *) malloc(cbSize); | 704 | query = (struct hllapi_packet_text_at *) malloc(cbSize); |
| 727 | query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT; | 705 | query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT; |
| @@ -729,11 +707,7 @@ | @@ -729,11 +707,7 @@ | ||
| 729 | query->col = col; | 707 | query->col = col; |
| 730 | strcpy(query->text,text); | 708 | strcpy(query->text,text); |
| 731 | 709 | ||
| 732 | - TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 733 | - | ||
| 734 | - free(query); | ||
| 735 | - | ||
| 736 | - return response.rc; | 710 | + return query_intval((void *) query, cbSize, true); |
| 737 | 711 | ||
| 738 | #elif defined(HAVE_DBUS) | 712 | #elif defined(HAVE_DBUS) |
| 739 | 713 | ||
| @@ -799,11 +773,9 @@ | @@ -799,11 +773,9 @@ | ||
| 799 | { | 773 | { |
| 800 | #if defined(WIN32) | 774 | #if defined(WIN32) |
| 801 | 775 | ||
| 802 | - struct hllapi_packet_cursor query = { HLLAPI_PACKET_SET_CURSOR_POSITION, (unsigned short) row, (unsigned short) col }; | ||
| 803 | - struct hllapi_packet_result response; | ||
| 804 | - DWORD cbSize = sizeof(query); | ||
| 805 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 806 | - return response.rc != 0; | 776 | + struct hllapi_packet_cursor query = { HLLAPI_PACKET_SET_CURSOR_POSITION, (unsigned short) row, (unsigned short) col }; |
| 777 | + | ||
| 778 | + return query_intval((void *) &query, sizeof(query)); | ||
| 807 | 779 | ||
| 808 | #elif defined(HAVE_DBUS) | 780 | #elif defined(HAVE_DBUS) |
| 809 | 781 | ||
| @@ -826,11 +798,9 @@ | @@ -826,11 +798,9 @@ | ||
| 826 | { | 798 | { |
| 827 | #if defined(WIN32) | 799 | #if defined(WIN32) |
| 828 | 800 | ||
| 829 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, (unsigned short) addr }; | ||
| 830 | - struct hllapi_packet_result response; | ||
| 831 | - DWORD cbSize = sizeof(query); | ||
| 832 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 833 | - return response.rc; | 801 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, (unsigned short) addr }; |
| 802 | + | ||
| 803 | + return query_intval((void *) &query, sizeof(query)); | ||
| 834 | 804 | ||
| 835 | #elif defined(HAVE_DBUS) | 805 | #elif defined(HAVE_DBUS) |
| 836 | 806 | ||
| @@ -850,49 +820,22 @@ | @@ -850,49 +820,22 @@ | ||
| 850 | 820 | ||
| 851 | int get_cursor_addr(void) | 821 | int get_cursor_addr(void) |
| 852 | { | 822 | { |
| 853 | -#if defined(WIN32) | ||
| 854 | - | ||
| 855 | return query_intval(HLLAPI_PACKET_GET_CURSOR); | 823 | return query_intval(HLLAPI_PACKET_GET_CURSOR); |
| 856 | - | ||
| 857 | -#elif defined(HAVE_DBUS) | ||
| 858 | - | ||
| 859 | - return query_intval("getCursorAddress"); | ||
| 860 | - | ||
| 861 | -#else | ||
| 862 | - | ||
| 863 | - return -1; | ||
| 864 | - | ||
| 865 | -#endif | ||
| 866 | } | 824 | } |
| 867 | 825 | ||
| 868 | 826 | ||
| 869 | int enter(void) | 827 | int enter(void) |
| 870 | { | 828 | { |
| 871 | -#if defined(WIN32) | ||
| 872 | - | ||
| 873 | return query_intval(HLLAPI_PACKET_ENTER); | 829 | return query_intval(HLLAPI_PACKET_ENTER); |
| 874 | - | ||
| 875 | -#elif defined(HAVE_DBUS) | ||
| 876 | - | ||
| 877 | - return query_intval("enter"); | ||
| 878 | - | ||
| 879 | -#else | ||
| 880 | - | ||
| 881 | - return -1; | ||
| 882 | - | ||
| 883 | -#endif | ||
| 884 | - | ||
| 885 | } | 830 | } |
| 886 | 831 | ||
| 887 | int pfkey(int key) | 832 | int pfkey(int key) |
| 888 | { | 833 | { |
| 889 | #if defined(WIN32) | 834 | #if defined(WIN32) |
| 890 | 835 | ||
| 891 | - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, (unsigned short) key }; | ||
| 892 | - struct hllapi_packet_result response; | ||
| 893 | - DWORD cbSize = sizeof(query); | ||
| 894 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 895 | - return response.rc; | 836 | + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, (unsigned short) key }; |
| 837 | + | ||
| 838 | + return query_intval((void *) &query, sizeof(query)); | ||
| 896 | 839 | ||
| 897 | #elif defined(HAVE_DBUS) | 840 | #elif defined(HAVE_DBUS) |
| 898 | 841 | ||
| @@ -919,11 +862,9 @@ | @@ -919,11 +862,9 @@ | ||
| 919 | { | 862 | { |
| 920 | #if defined(WIN32) | 863 | #if defined(WIN32) |
| 921 | 864 | ||
| 922 | - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, (unsigned short) key }; | ||
| 923 | - struct hllapi_packet_result response; | ||
| 924 | - DWORD cbSize = sizeof(query); | ||
| 925 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 926 | - return response.rc; | 865 | + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, (unsigned short) key }; |
| 866 | + | ||
| 867 | + return query_intval((void *) &query, sizeof(query)); | ||
| 927 | 868 | ||
| 928 | #elif defined(HAVE_DBUS) | 869 | #elif defined(HAVE_DBUS) |
| 929 | 870 | ||
| @@ -947,31 +888,16 @@ | @@ -947,31 +888,16 @@ | ||
| 947 | 888 | ||
| 948 | int quit(void) | 889 | int quit(void) |
| 949 | { | 890 | { |
| 950 | -#if defined(WIN32) | ||
| 951 | - | ||
| 952 | return query_intval(HLLAPI_PACKET_QUIT); | 891 | return query_intval(HLLAPI_PACKET_QUIT); |
| 953 | - | ||
| 954 | -#elif defined(HAVE_DBUS) | ||
| 955 | - | ||
| 956 | - return query_intval("quit"); | ||
| 957 | - | ||
| 958 | -#else | ||
| 959 | - | ||
| 960 | - return -1; | ||
| 961 | - | ||
| 962 | -#endif | ||
| 963 | - | ||
| 964 | } | 892 | } |
| 965 | 893 | ||
| 966 | int set_toggle(LIB3270_TOGGLE ix, bool value) | 894 | int set_toggle(LIB3270_TOGGLE ix, bool value) |
| 967 | { | 895 | { |
| 968 | #if defined(WIN32) | 896 | #if defined(WIN32) |
| 969 | 897 | ||
| 970 | - struct hllapi_packet_set query = { HLLAPI_PACKET_SET_TOGGLE, (unsigned short) ix, (unsigned short) value }; | ||
| 971 | - struct hllapi_packet_result response; | ||
| 972 | - DWORD cbSize = sizeof(query); | ||
| 973 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 974 | - return response.rc; | 898 | + struct hllapi_packet_set query = { HLLAPI_PACKET_SET_TOGGLE, (unsigned short) ix, (unsigned short) value }; |
| 899 | + | ||
| 900 | + return query_intval((void *) &query, sizeof(query)); | ||
| 975 | 901 | ||
| 976 | #elif defined(HAVE_DBUS) | 902 | #elif defined(HAVE_DBUS) |
| 977 | 903 | ||
| @@ -1000,8 +926,7 @@ | @@ -1000,8 +926,7 @@ | ||
| 1000 | 926 | ||
| 1001 | size_t len = strlen(str); | 927 | size_t len = strlen(str); |
| 1002 | struct hllapi_packet_emulate_input * query; | 928 | struct hllapi_packet_emulate_input * query; |
| 1003 | - struct hllapi_packet_result response; | ||
| 1004 | - DWORD cbSize = sizeof(struct hllapi_packet_emulate_input)+len; | 929 | + size_t cbSize = sizeof(struct hllapi_packet_emulate_input)+len; |
| 1005 | 930 | ||
| 1006 | query = (struct hllapi_packet_emulate_input *) malloc(cbSize); | 931 | query = (struct hllapi_packet_emulate_input *) malloc(cbSize); |
| 1007 | query->packet_id = HLLAPI_PACKET_EMULATE_INPUT; | 932 | query->packet_id = HLLAPI_PACKET_EMULATE_INPUT; |
| @@ -1009,11 +934,7 @@ | @@ -1009,11 +934,7 @@ | ||
| 1009 | query->pasting = 1; | 934 | query->pasting = 1; |
| 1010 | strcpy(query->text,str); | 935 | strcpy(query->text,str); |
| 1011 | 936 | ||
| 1012 | - TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 1013 | - | ||
| 1014 | - free(query); | ||
| 1015 | - | ||
| 1016 | - return response.rc; | 937 | + return query_intval((void *) query, cbSize, true); |
| 1017 | 938 | ||
| 1018 | #elif defined(HAVE_DBUS) | 939 | #elif defined(HAVE_DBUS) |
| 1019 | 940 | ||
| @@ -1037,11 +958,9 @@ | @@ -1037,11 +958,9 @@ | ||
| 1037 | { | 958 | { |
| 1038 | #if defined(WIN32) | 959 | #if defined(WIN32) |
| 1039 | 960 | ||
| 1040 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_START, (unsigned short) baddr }; | ||
| 1041 | - struct hllapi_packet_result response; | ||
| 1042 | - DWORD cbSize = sizeof(query); | ||
| 1043 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 1044 | - return response.rc; | 961 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_START, (unsigned short) baddr }; |
| 962 | + | ||
| 963 | + return query_intval((void *) &query, sizeof(query)); | ||
| 1045 | 964 | ||
| 1046 | #elif defined(HAVE_DBUS) | 965 | #elif defined(HAVE_DBUS) |
| 1047 | 966 | ||
| @@ -1068,11 +987,9 @@ | @@ -1068,11 +987,9 @@ | ||
| 1068 | { | 987 | { |
| 1069 | #if defined(WIN32) | 988 | #if defined(WIN32) |
| 1070 | 989 | ||
| 1071 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_LEN, (unsigned short) baddr }; | ||
| 1072 | - struct hllapi_packet_result response; | ||
| 1073 | - DWORD cbSize = sizeof(query); | ||
| 1074 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 1075 | - return response.rc; | 990 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_LEN, (unsigned short) baddr }; |
| 991 | + | ||
| 992 | + return query_intval((void *) &query, sizeof(query)); | ||
| 1076 | 993 | ||
| 1077 | #elif defined(HAVE_DBUS) | 994 | #elif defined(HAVE_DBUS) |
| 1078 | 995 | ||
| @@ -1098,11 +1015,9 @@ | @@ -1098,11 +1015,9 @@ | ||
| 1098 | { | 1015 | { |
| 1099 | #if defined(WIN32) | 1016 | #if defined(WIN32) |
| 1100 | 1017 | ||
| 1101 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_NEXT_UNPROTECTED, (unsigned short) baddr }; | ||
| 1102 | - struct hllapi_packet_result response; | ||
| 1103 | - DWORD cbSize = sizeof(query); | ||
| 1104 | - TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); | ||
| 1105 | - return response.rc; | 1018 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_NEXT_UNPROTECTED, (unsigned short) baddr }; |
| 1019 | + | ||
| 1020 | + return query_intval((void *) &query, sizeof(query)); | ||
| 1106 | 1021 | ||
| 1107 | #elif defined(HAVE_DBUS) | 1022 | #elif defined(HAVE_DBUS) |
| 1108 | 1023 |