Author: hbelusca
Date: Sun Nov 10 20:20:57 2013
New Revision: 60920

URL: http://svn.reactos.org/svn/reactos?rev=60920&view=rev
Log:
[KERNEL32][CONSRV]
Implement ReadConsoleInputExA/W, which are a generalization of 
ReadConsoleInputA/W and PeekConsoleInputA/W. They allow you to read console 
input events by either waiting (or not) for their presence, and to remove them 
from the console input list (or not).
Those functions are the read-equivalent of WriteConsoleInputVDMA/W.
Used in Windows' NTVDM (guess why ;) ).

Modified:
    trunk/reactos/dll/win32/kernel32/client/console/readwrite.c
    trunk/reactos/include/psdk/wincon.h
    trunk/reactos/include/reactos/subsys/win/conmsg.h
    trunk/reactos/win32ss/user/winsrv/consrv/condrv/coninput.c
    trunk/reactos/win32ss/user/winsrv/consrv/coninput.c
    trunk/reactos/win32ss/user/winsrv/consrv/conoutput.c

Modified: trunk/reactos/dll/win32/kernel32/client/console/readwrite.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/console/readwrite.c?rev=60920&r1=60919&r2=60920&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/console/readwrite.c [iso-8859-1] 
(original)
+++ trunk/reactos/dll/win32/kernel32/client/console/readwrite.c [iso-8859-1] 
Sun Nov 10 20:20:57 2013
@@ -120,11 +120,11 @@
 static
 BOOL
 IntGetConsoleInput(HANDLE hConsoleInput,
-                   BOOL bRead,
                    PINPUT_RECORD lpBuffer,
                    DWORD nLength,
                    LPDWORD lpNumberOfEventsRead,
-                   BOOL bUnicode)
+                   WORD wFlags,
+                   BOOLEAN bUnicode)
 {
     NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
@@ -158,10 +158,10 @@
 
     /* Set up the data to send to the Console Server */
     GetInputRequest->InputHandle = hConsoleInput;
-    GetInputRequest->Unicode = bUnicode;
-    GetInputRequest->bRead = bRead;
     GetInputRequest->InputsRead = 0;
     GetInputRequest->Length = nLength;
+    GetInputRequest->wFlags = wFlags;
+    GetInputRequest->Unicode = bUnicode;
 
     /* Call the server */
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@@ -825,10 +825,10 @@
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              FALSE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              CONSOLE_READ_KEEPEVENT | CONSOLE_READ_CONTINUE,
                               TRUE);
 }
 
@@ -846,10 +846,10 @@
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              FALSE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              CONSOLE_READ_KEEPEVENT | CONSOLE_READ_CONTINUE,
                               FALSE);
 }
 
@@ -867,10 +867,10 @@
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              TRUE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              0,
                               TRUE);
 }
 
@@ -888,29 +888,55 @@
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              TRUE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              0,
                               FALSE);
 }
 
 
-BOOL
-WINAPI
-ReadConsoleInputExW(HANDLE hConsole, LPVOID lpBuffer, DWORD dwLen, LPDWORD 
Unknown1, DWORD Unknown2)
-{
-    STUB;
-    return FALSE;
-}
-
-
-BOOL
-WINAPI
-ReadConsoleInputExA(HANDLE hConsole, LPVOID lpBuffer, DWORD dwLen, LPDWORD 
Unknown1, DWORD Unknown2)
-{
-    STUB;
-    return FALSE;
+/*--------------------------------------------------------------
+ *     ReadConsoleInputExW
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+ReadConsoleInputExW(HANDLE hConsoleInput,
+                    PINPUT_RECORD lpBuffer,
+                    DWORD nLength,
+                    LPDWORD lpNumberOfEventsRead,
+                    WORD wFlags)
+{
+    return IntGetConsoleInput(hConsoleInput,
+                              lpBuffer,
+                              nLength,
+                              lpNumberOfEventsRead,
+                              wFlags,
+                              TRUE);
+}
+
+
+/*--------------------------------------------------------------
+ *     ReadConsoleInputExA
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+ReadConsoleInputExA(HANDLE hConsoleInput,
+                    PINPUT_RECORD lpBuffer,
+                    DWORD nLength,
+                    LPDWORD lpNumberOfEventsRead,
+                    WORD wFlags)
+{
+    return IntGetConsoleInput(hConsoleInput,
+                              lpBuffer,
+                              nLength,
+                              lpNumberOfEventsRead,
+                              wFlags,
+                              FALSE);
 }
 
 

Modified: trunk/reactos/include/psdk/wincon.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/wincon.h?rev=60920&r1=60919&r2=60920&view=diff
==============================================================================
--- trunk/reactos/include/psdk/wincon.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/wincon.h [iso-8859-1] Sun Nov 10 20:20:57 2013
@@ -107,6 +107,12 @@
 #if (_WIN32_WINNT >= 0x0600)
 #define HISTORY_NO_DUP_FLAG             0x0001
 #endif
+
+/*
+ * Read input flags
+ */
+#define CONSOLE_READ_KEEPEVENT          0x0001
+#define CONSOLE_READ_CONTINUE           0x0002
 
 /*
  * Event types
@@ -436,6 +442,7 @@
 BOOL WINAPI GetNumberOfConsoleInputEvents(_In_ HANDLE, _Out_ PDWORD);
 BOOL WINAPI GetNumberOfConsoleMouseButtons(_Out_ PDWORD);
 
+_Success_(return != 0)
 BOOL
 WINAPI PeekConsoleInputA(
   _In_ HANDLE hConsoleInput,
@@ -443,6 +450,7 @@
   _In_ DWORD nLength,
   _Out_ LPDWORD lpNumberOfEventsRead);
 
+_Success_(return != 0)
 BOOL
 WINAPI
 PeekConsoleInputW(
@@ -488,6 +496,26 @@
   _Out_writes_to_(nLength, *lpNumberOfEventsRead) PINPUT_RECORD lpBuffer,
   _In_ DWORD nLength,
   _Out_ _Deref_out_range_(<= , nLength) LPDWORD lpNumberOfEventsRead);
+
+_Success_(return != 0)
+BOOL
+WINAPI
+ReadConsoleInputExA(
+  _In_ HANDLE hConsoleInput,
+  _Out_writes_to_(nLength, *lpNumberOfEventsRead) PINPUT_RECORD lpBuffer,
+  _In_ DWORD nLength,
+  _Out_ _Deref_out_range_(<= , nLength) LPDWORD lpNumberOfEventsRead,
+  _In_ WORD wFlags);
+
+_Success_(return != 0)
+BOOL
+WINAPI
+ReadConsoleInputExW(
+  _In_ HANDLE hConsoleInput,
+  _Out_writes_to_(nLength, *lpNumberOfEventsRead) PINPUT_RECORD lpBuffer,
+  _In_ DWORD nLength,
+  _Out_ _Deref_out_range_(<= , nLength) LPDWORD lpNumberOfEventsRead,
+  _In_ WORD wFlags);
 
 BOOL
 WINAPI

Modified: trunk/reactos/include/reactos/subsys/win/conmsg.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/subsys/win/conmsg.h?rev=60920&r1=60919&r2=60920&view=diff
==============================================================================
--- trunk/reactos/include/reactos/subsys/win/conmsg.h   [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/subsys/win/conmsg.h   [iso-8859-1] Sun Nov 10 
20:20:57 2013
@@ -469,13 +469,11 @@
 typedef struct
 {
     HANDLE InputHandle;
-    BOOL Unicode;
-    BOOL bRead; // TRUE --> Read ; FALSE --> Peek
-
     ULONG InputsRead;
-
+    PINPUT_RECORD InputRecord;
     ULONG Length;
-    PINPUT_RECORD InputRecord;
+    WORD wFlags;
+    BOOLEAN Unicode;
 } CONSOLE_GETINPUT, *PCONSOLE_GETINPUT;
 
 typedef struct

Modified: trunk/reactos/win32ss/user/winsrv/consrv/condrv/coninput.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv/condrv/coninput.c?rev=60920&r1=60919&r2=60920&view=diff
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/condrv/coninput.c  [iso-8859-1] 
(original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/condrv/coninput.c  [iso-8859-1] 
Sun Nov 10 20:20:57 2013
@@ -376,6 +376,7 @@
 NTSTATUS NTAPI
 ConDrvGetConsoleInput(IN PCONSOLE Console,
                       IN PCONSOLE_INPUT_BUFFER InputBuffer,
+                      IN BOOLEAN KeepEvents,
                       IN BOOLEAN WaitForMoreEvents,
                       IN BOOLEAN Unicode,
                       OUT PINPUT_RECORD InputRecord,
@@ -425,7 +426,8 @@
         ++i;
         CurrentInput = CurrentInput->Flink;
 
-        if (WaitForMoreEvents) // TRUE --> Read, we remove inputs from the 
buffer ; FALSE --> Peek, we keep inputs.
+        /* Remove the events from the queue if needed */
+        if (!KeepEvents)
         {
             RemoveEntryList(&Input->ListEntry);
             ConsoleFreeHeap(Input);

Modified: trunk/reactos/win32ss/user/winsrv/consrv/coninput.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv/coninput.c?rev=60920&r1=60919&r2=60920&view=diff
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/coninput.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/coninput.c [iso-8859-1] Sun Nov 10 
20:20:57 2013
@@ -45,7 +45,7 @@
 WaitBeforeReading(IN PGET_INPUT_INFO InputInfo,
                   IN PCSR_API_MESSAGE ApiMessage,
                   IN CSR_WAIT_FUNCTION WaitFunction OPTIONAL,
-                  IN BOOL CreateWaitBlock OPTIONAL)
+                  IN BOOLEAN CreateWaitBlock OPTIONAL)
 {
     if (CreateWaitBlock)
     {
@@ -74,7 +74,7 @@
 static NTSTATUS
 ReadChars(IN PGET_INPUT_INFO InputInfo,
           IN PCSR_API_MESSAGE ApiMessage,
-          IN BOOL CreateWaitBlock OPTIONAL);
+          IN BOOLEAN CreateWaitBlock OPTIONAL);
 
 // Wait function CSR_WAIT_FUNCTION
 static BOOLEAN
@@ -123,9 +123,7 @@
      * If we go there, that means we are notified for some new input.
      * The console is therefore already locked.
      */
-    Status = ReadChars(InputInfo,
-                       WaitApiMessage,
-                       FALSE);
+    Status = ReadChars(InputInfo, WaitApiMessage, FALSE);
 
 Quit:
     if (Status != STATUS_PENDING)
@@ -148,7 +146,7 @@
 static NTSTATUS
 ReadChars(IN PGET_INPUT_INFO InputInfo,
           IN PCSR_API_MESSAGE ApiMessage,
-          IN BOOL CreateWaitBlock OPTIONAL)
+          IN BOOLEAN CreateWaitBlock OPTIONAL)
 {
     NTSTATUS Status;
     PCONSOLE_READCONSOLE ReadConsoleRequest = 
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ReadConsoleRequest;
@@ -188,9 +186,8 @@
 
 static NTSTATUS
 ReadInputBuffer(IN PGET_INPUT_INFO InputInfo,
-                IN BOOL Wait,
                 IN PCSR_API_MESSAGE ApiMessage,
-                IN BOOL CreateWaitBlock OPTIONAL);
+                IN BOOLEAN CreateWaitBlock OPTIONAL);
 
 // Wait function CSR_WAIT_FUNCTION
 static BOOLEAN
@@ -204,7 +201,6 @@
                       IN ULONG WaitFlags)
 {
     NTSTATUS Status;
-    PCONSOLE_GETINPUT GetInputRequest = 
&((PCONSOLE_API_MESSAGE)WaitApiMessage)->Data.GetInputRequest;
     PGET_INPUT_INFO InputInfo = (PGET_INPUT_INFO)WaitContext;
 
     PVOID InputHandle = WaitArgument2;
@@ -240,10 +236,7 @@
      * If we go there, that means we are notified for some new input.
      * The console is therefore already locked.
      */
-    Status = ReadInputBuffer(InputInfo,
-                             GetInputRequest->bRead,
-                             WaitApiMessage,
-                             FALSE);
+    Status = ReadInputBuffer(InputInfo, WaitApiMessage, FALSE);
 
 Quit:
     if (Status != STATUS_PENDING)
@@ -258,16 +251,16 @@
 NTSTATUS NTAPI
 ConDrvGetConsoleInput(IN PCONSOLE Console,
                       IN PCONSOLE_INPUT_BUFFER InputBuffer,
+                      IN BOOLEAN KeepEvents,
                       IN BOOLEAN WaitForMoreEvents,
                       IN BOOLEAN Unicode,
                       OUT PINPUT_RECORD InputRecord,
                       IN ULONG NumEventsToRead,
-                      OUT PULONG NumEventsRead);
+                      OUT PULONG NumEventsRead OPTIONAL);
 static NTSTATUS
 ReadInputBuffer(IN PGET_INPUT_INFO InputInfo,
-                IN BOOL Wait,   // TRUE --> Read ; FALSE --> Peek
                 IN PCSR_API_MESSAGE ApiMessage,
-                IN BOOL CreateWaitBlock OPTIONAL)
+                IN BOOLEAN CreateWaitBlock OPTIONAL)
 {
     NTSTATUS Status;
     PCONSOLE_GETINPUT GetInputRequest = 
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetInputRequest;
@@ -277,7 +270,8 @@
 
     Status = ConDrvGetConsoleInput(InputBuffer->Header.Console,
                                    InputBuffer,
-                                   Wait,
+                                   (GetInputRequest->wFlags & 
CONSOLE_READ_KEEPEVENT) != 0,
+                                   (GetInputRequest->wFlags & 
CONSOLE_READ_CONTINUE ) == 0,
                                    GetInputRequest->Unicode,
                                    GetInputRequest->InputRecord,
                                    GetInputRequest->Length,
@@ -336,9 +330,7 @@
     InputInfo.HandleEntry   = HandleEntry;
     InputInfo.InputBuffer   = InputBuffer;
 
-    Status = ReadChars(&InputInfo,
-                       ApiMessage,
-                       TRUE);
+    Status = ReadChars(&InputInfo, ApiMessage, TRUE);
 
     ConSrvReleaseInputBuffer(InputBuffer, TRUE);
 
@@ -358,6 +350,9 @@
 
     DPRINT("SrvGetConsoleInput\n");
 
+    if (GetInputRequest->wFlags & ~(CONSOLE_READ_KEEPEVENT | 
CONSOLE_READ_CONTINUE))
+        return STATUS_INVALID_PARAMETER;
+
     if (!CsrValidateMessageBuffer(ApiMessage,
                                   (PVOID*)&GetInputRequest->InputRecord,
                                   GetInputRequest->Length,
@@ -375,10 +370,7 @@
     InputInfo.HandleEntry   = HandleEntry;
     InputInfo.InputBuffer   = InputBuffer;
 
-    Status = ReadInputBuffer(&InputInfo,
-                             GetInputRequest->bRead,
-                             ApiMessage,
-                             TRUE);
+    Status = ReadInputBuffer(&InputInfo, ApiMessage, TRUE);
 
     ConSrvReleaseInputBuffer(InputBuffer, TRUE);
 

Modified: trunk/reactos/win32ss/user/winsrv/consrv/conoutput.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv/conoutput.c?rev=60920&r1=60919&r2=60920&view=diff
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/conoutput.c        [iso-8859-1] 
(original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/conoutput.c        [iso-8859-1] 
Sun Nov 10 20:20:57 2013
@@ -323,7 +323,7 @@
 static NTSTATUS
 DoWriteConsole(IN PCSR_API_MESSAGE ApiMessage,
                IN PCSR_THREAD ClientThread,
-               IN BOOL CreateWaitBlock OPTIONAL);
+               IN BOOLEAN CreateWaitBlock OPTIONAL);
 
 // Wait function CSR_WAIT_FUNCTION
 static BOOLEAN
@@ -351,9 +351,7 @@
         goto Quit;
     }
 
-    Status = DoWriteConsole(WaitApiMessage,
-                            WaitThread,
-                            FALSE);
+    Status = DoWriteConsole(WaitApiMessage, WaitThread, FALSE);
 
 Quit:
     if (Status != STATUS_PENDING)
@@ -374,7 +372,7 @@
 static NTSTATUS
 DoWriteConsole(IN PCSR_API_MESSAGE ApiMessage,
                IN PCSR_THREAD ClientThread,
-               IN BOOL CreateWaitBlock OPTIONAL)
+               IN BOOLEAN CreateWaitBlock OPTIONAL)
 {
     NTSTATUS Status;
     PCONSOLE_WRITECONSOLE WriteConsoleRequest = 
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleRequest;
@@ -517,9 +515,7 @@
         return STATUS_INVALID_PARAMETER;
     }
 
-    Status = DoWriteConsole(ApiMessage,
-                            CsrGetClientThread(),
-                            TRUE);
+    Status = DoWriteConsole(ApiMessage, CsrGetClientThread(), TRUE);
 
     if (Status == STATUS_PENDING) *ReplyCode = CsrReplyPending;
 


Reply via email to