libfreerdp-core/fastpath: add FastPath Input, enabled by default.
authorVic Lee <llyzs@163.com>
Tue, 16 Aug 2011 06:37:11 +0000 (14:37 +0800)
committerVic Lee <llyzs@163.com>
Tue, 16 Aug 2011 06:37:11 +0000 (14:37 +0800)
include/freerdp/input.h
libfreerdp-core/fastpath.c
libfreerdp-core/fastpath.h
libfreerdp-core/input.c
libfreerdp-core/input.h
libfreerdp-core/settings.c
libfreerdp-utils/args.c

index ec28db0..469cd16 100644 (file)
 #ifndef __INPUT_API_H
 #define __INPUT_API_H
 
-/* Input Events */
-#define INPUT_EVENT_SYNC               0x0000
-#define INPUT_EVENT_SCANCODE           0x0004
-#define INPUT_EVENT_UNICODE            0x0005
-#define INPUT_EVENT_MOUSE              0x8001
-#define INPUT_EVENT_MOUSEX             0x8002
-
 /* keyboard Flags */
 #define KBD_FLAGS_EXTENDED             0x0100
 #define KBD_FLAGS_DOWN                 0x4000
index 31d8f3f..0dfa1f5 100644 (file)
@@ -254,6 +254,34 @@ void fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s)
        IFCALL(update->EndPaint, update);
 }
 
+STREAM* fastpath_pdu_init(rdpFastPath* fastpath)
+{
+       STREAM* s;
+       s = transport_send_stream_init(fastpath->rdp->transport, 127);
+       stream_seek(s, 2); /* fpInputHeader and length1 */
+       /* length2 is not necessary since input PDU should not exceed 127 bytes */
+       return s;
+}
+
+void fastpath_send_pdu(rdpFastPath* fastpath, STREAM* s, uint8 numberEvents)
+{
+       int length;
+
+       length = stream_get_length(s);
+       if (length > 127)
+       {
+               printf("Maximum FastPath PDU length is 127\n");
+               return;
+       }
+
+       stream_set_pos(s, 0);
+       stream_write_uint8(s, (numberEvents << 2));
+       stream_write_uint8(s, length);
+
+       stream_set_pos(s, length);
+       transport_write(fastpath->rdp->transport, s);
+}
+
 rdpFastPath* fastpath_new(rdpRdp* rdp)
 {
        rdpFastPath* fastpath;
index 20111e4..c1df080 100644 (file)
@@ -82,6 +82,9 @@ struct rdp_fastpath
 uint16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s);
 void fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s);
 
+STREAM* fastpath_pdu_init(rdpFastPath* fastpath);
+void fastpath_send_pdu(rdpFastPath* fastpath, STREAM* s, uint8 numberEvents);
+
 rdpFastPath* fastpath_new(rdpRdp* rdp);
 void fastpath_free(rdpFastPath* fastpath);
 
index 72f6dae..fca754f 100644 (file)
@@ -119,6 +119,62 @@ void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, ui
        rdp_send_client_input_pdu(input->rdp, s);
 }
 
+STREAM* rdp_client_fastpath_input_pdu_init(rdpRdp* rdp, uint8 flags, uint8 code)
+{
+       STREAM* s;
+       s = fastpath_pdu_init(rdp->fastpath);
+       stream_write_uint8(s, flags | (code << 5)); /* eventHeader */
+       return s;
+}
+
+void rdp_send_client_fastpath_input_pdu(rdpRdp* rdp, STREAM* s)
+{
+       fastpath_send_pdu(rdp->fastpath, s, 1);
+}
+
+void input_send_fastpath_synchronize_event(rdpInput* input, uint32 flags)
+{
+       STREAM* s;
+       /* The FastPath Synchronization eventFlags has identical values as SlowPath */
+       s = rdp_client_fastpath_input_pdu_init(input->rdp, (uint8)flags, FASTPATH_INPUT_EVENT_SYNC);
+       rdp_send_client_fastpath_input_pdu(input->rdp, s);
+}
+
+void input_send_fastpath_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
+{
+       STREAM* s;
+       uint8 eventFlags = 0;
+       eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0;
+       eventFlags |= (flags & KBD_FLAGS_EXTENDED) ? FASTPATH_INPUT_KBDFLAGS_EXTENDED : 0;
+       s = rdp_client_fastpath_input_pdu_init(input->rdp, eventFlags, FASTPATH_INPUT_EVENT_SCANCODE);
+       stream_write_uint8(s, code); /* keyCode (1 byte) */
+       rdp_send_client_fastpath_input_pdu(input->rdp, s);
+}
+
+void input_send_fastpath_unicode_keyboard_event(rdpInput* input, uint16 code)
+{
+       STREAM* s;
+       s = rdp_client_fastpath_input_pdu_init(input->rdp, 0, FASTPATH_INPUT_EVENT_UNICODE);
+       stream_write_uint16(s, code); /* unicodeCode (2 bytes) */
+       rdp_send_client_fastpath_input_pdu(input->rdp, s);
+}
+
+void input_send_fastpath_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
+{
+       STREAM* s;
+       s = rdp_client_fastpath_input_pdu_init(input->rdp, 0, FASTPATH_INPUT_EVENT_MOUSE);
+       input_write_mouse_event(s, flags, x, y);
+       rdp_send_client_fastpath_input_pdu(input->rdp, s);
+}
+
+void input_send_fastpath_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
+{
+       STREAM* s;
+       s = rdp_client_fastpath_input_pdu_init(input->rdp, 0, FASTPATH_INPUT_EVENT_MOUSEX);
+       input_write_extended_mouse_event(s, flags, x, y);
+       rdp_send_client_fastpath_input_pdu(input->rdp, s);
+}
+
 rdpInput* input_new(rdpRdp* rdp)
 {
        rdpInput* input;
@@ -128,11 +184,22 @@ rdpInput* input_new(rdpRdp* rdp)
        if (input != NULL)
        {
                input->rdp = rdp;
-               input->SynchronizeEvent = input_send_synchronize_event;
-               input->KeyboardEvent = input_send_keyboard_event;
-               input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event;
-               input->MouseEvent = input_send_mouse_event;
-               input->ExtendedMouseEvent = input_send_extended_mouse_event;
+               if (rdp->settings->fastpath_input)
+               {
+                       input->SynchronizeEvent = input_send_fastpath_synchronize_event;
+                       input->KeyboardEvent = input_send_fastpath_keyboard_event;
+                       input->UnicodeKeyboardEvent = input_send_fastpath_unicode_keyboard_event;
+                       input->MouseEvent = input_send_fastpath_mouse_event;
+                       input->ExtendedMouseEvent = input_send_fastpath_extended_mouse_event;
+               }
+               else
+               {
+                       input->SynchronizeEvent = input_send_synchronize_event;
+                       input->KeyboardEvent = input_send_keyboard_event;
+                       input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event;
+                       input->MouseEvent = input_send_mouse_event;
+                       input->ExtendedMouseEvent = input_send_extended_mouse_event;
+               }
        }
 
        return input;
index da042f0..a61b068 100644 (file)
 #define __INPUT_H
 
 #include "rdp.h"
+#include "fastpath.h"
 
 #include <freerdp/input.h>
 #include <freerdp/freerdp.h>
 #include <freerdp/utils/stream.h>
 #include <freerdp/utils/memory.h>
 
+/* Input Events */
+#define INPUT_EVENT_SYNC               0x0000
+#define INPUT_EVENT_SCANCODE           0x0004
+#define INPUT_EVENT_UNICODE            0x0005
+#define INPUT_EVENT_MOUSE              0x8001
+#define INPUT_EVENT_MOUSEX             0x8002
+
+/* FastPath Input Events */
+#define FASTPATH_INPUT_EVENT_SCANCODE  0x0
+#define FASTPATH_INPUT_EVENT_MOUSE     0x1
+#define FASTPATH_INPUT_EVENT_MOUSEX    0x2
+#define FASTPATH_INPUT_EVENT_SYNC      0x3
+#define FASTPATH_INPUT_EVENT_UNICODE   0x4
+
+/* FastPath Keyboard Event Flags */
+#define FASTPATH_INPUT_KBDFLAGS_RELEASE                0x01
+#define FASTPATH_INPUT_KBDFLAGS_EXTENDED       0x02
+
 #define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH     4
 
 void input_send_synchronize_event(rdpInput* input, uint32 flags);
@@ -35,6 +54,12 @@ void input_send_unicode_keyboard_event(rdpInput* input, uint16 code);
 void input_send_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
 void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
 
+void input_send_fastpath_synchronize_event(rdpInput* input, uint32 flags);
+void input_send_fastpath_keyboard_event(rdpInput* input, uint16 flags, uint16 code);
+void input_send_fastpath_unicode_keyboard_event(rdpInput* input, uint16 code);
+void input_send_fastpath_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
+void input_send_fastpath_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
+
 rdpInput* input_new(rdpRdp* rdp);
 void input_free(rdpInput* input);
 
index f77d596..27d653b 100644 (file)
@@ -109,6 +109,8 @@ rdpSettings* settings_new()
                settings->num_icon_caches = 3;
                settings->num_icon_cache_entries = 12;
 
+               settings->fastpath_input = True;
+
                settings->uniconv = freerdp_uniconv_new();
                gethostname(settings->client_hostname, sizeof(settings->client_hostname) - 1);
        }
index 0f71930..935499f 100644 (file)
@@ -174,10 +174,10 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
                {
                        settings->offscreen_bitmap_cache = 0;
                }
-               else if (strcmp("-fastpath", argv[index]) == 0)
+               else if (strcmp("--no-fastpath", argv[index]) == 0)
                {
-                       settings->fastpath_input = True;
-                       settings->fastpath_output = True;
+                       settings->fastpath_input = False;
+                       settings->fastpath_output = False;
                }
                else if (strcmp("--rfx", argv[index]) == 0)
                {