Implemented PeekConsoleInputA().

svn path=/trunk/; revision=3672
This commit is contained in:
Marty Dill 2002-10-29 03:49:32 +00:00
parent 644b07f2e1
commit da8792228d
5 changed files with 149 additions and 11 deletions

View file

@ -299,6 +299,17 @@ typedef struct
DWORD Flags;
} CSRSS_SHUTDOWN_PARAMETERS, *PCSRSS_SHUTDOWN_PARAMETERS;
typedef struct
{
HANDLE ConsoleHandle;
DWORD Length;
INPUT_RECORD* InputRecord;
} CSRSS_PEEK_CONSOLE_INPUT_REQUEST, *PCSRSS_PEEK_CONSOLE_INPUT_REQUEST;
typedef struct
{
DWORD Length;
} CSRSS_PEEK_CONSOLE_INPUT_REPLY, *PCSRSS_PEEK_CONSOLE_INPUT_REPLY;
#define CSRSS_MAX_WRITE_CONSOLE_REQUEST \
@ -352,6 +363,7 @@ typedef struct
#define CSRSS_EXIT_REACTOS (0x1E)
#define CSRSS_GET_SHUTDOWN_PARAMETERS (0x1F)
#define CSRSS_SET_SHUTDOWN_PARAMETERS (0x20)
#define CSRSS_PEEK_CONSOLE_INPUT (0x21)
/* Keep in sync with definition below. */
@ -393,6 +405,7 @@ typedef struct
CSRSS_REGISTER_SERVICES_PROCESS_REQUEST RegisterServicesProcessRequest;
CSRSS_EXIT_REACTOS_REQUEST ExitReactosRequest;
CSRSS_SHUTDOWN_PARAMETERS SetShutdownParametersRequest;
CSRSS_PEEK_CONSOLE_INPUT_REQUEST PeekConsoleInputRequest;
} Data;
} CSRSS_API_REQUEST, *PCSRSS_API_REQUEST;
@ -420,6 +433,7 @@ typedef struct
CSRSS_READ_CONSOLE_OUTPUT_ATTRIB_REPLY ReadConsoleOutputAttribReply;
CSRSS_GET_NUM_INPUT_EVENTS_REPLY GetNumInputEventsReply;
CSRSS_SHUTDOWN_PARAMETERS GetShutdownParametersReply;
CSRSS_PEEK_CONSOLE_INPUT_REPLY PeekConsoleInputReply;
} Data;
} CSRSS_API_REPLY, *PCSRSS_API_REPLY;

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.45 2002/10/20 11:55:59 chorns Exp $
/* $Id: console.c,v 1.46 2002/10/29 03:49:31 mdill Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -579,9 +579,9 @@ GetStdHandle(DWORD nStdHandle)
Ppb = NtCurrentPeb()->ProcessParameters;
switch (nStdHandle)
{
case STD_INPUT_HANDLE: return Ppb->hStdInput;
case STD_OUTPUT_HANDLE: return Ppb->hStdOutput;
case STD_ERROR_HANDLE: return Ppb->hStdError;
case STD_INPUT_HANDLE: return Ppb->hStdInput;
case STD_OUTPUT_HANDLE: return Ppb->hStdOutput;
case STD_ERROR_HANDLE: return Ppb->hStdError;
}
SetLastError (ERROR_INVALID_PARAMETER);
return INVALID_HANDLE_VALUE;
@ -614,13 +614,13 @@ SetStdHandle(DWORD nStdHandle,
switch (nStdHandle)
{
case STD_INPUT_HANDLE:
Ppb->hStdInput = hHandle;
Ppb->hStdInput = hHandle;
return TRUE;
case STD_OUTPUT_HANDLE:
Ppb->hStdOutput = hHandle;
Ppb->hStdOutput = hHandle;
return TRUE;
case STD_ERROR_HANDLE:
Ppb->hStdError = hHandle;
Ppb->hStdError = hHandle;
return TRUE;
}
SetLastError (ERROR_INVALID_PARAMETER);
@ -937,8 +937,59 @@ PeekConsoleInputA(
LPDWORD lpNumberOfEventsRead
)
{
/* TO DO */
return FALSE;
PCSRSS_API_REQUEST Request;
CSRSS_API_REPLY Reply;
NTSTATUS Status;
PVOID BufferBase;
PVOID BufferTargetBase;
DWORD Size;
if(lpBuffer == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
Size = nLength * sizeof(INPUT_RECORD);
Status = CsrCaptureParameterBuffer((PVOID)lpBuffer, Size, &BufferBase, &BufferTargetBase);
if(!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FALSE;
}
Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REQUEST));
if(Request == NULL)
{
CsrReleaseParameterBuffer(BufferBase);
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
Request->Type = CSRSS_PEEK_CONSOLE_INPUT;
Request->Data.PeekConsoleInputRequest.ConsoleHandle = hConsoleInput;
Request->Data.PeekConsoleInputRequest.Length = nLength;
Request->Data.PeekConsoleInputRequest.InputRecord = (INPUT_RECORD*)BufferTargetBase;
Status = CsrClientCallServer(Request, &Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY));
if(!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
{
RtlFreeHeap(GetProcessHeap(), 0, Request);
CsrReleaseParameterBuffer(BufferBase);
return FALSE;
}
memcpy(lpBuffer, BufferBase, sizeof(INPUT_RECORD) * Reply.Data.PeekConsoleInputReply.Length);
if(lpNumberOfEventsRead != NULL)
*lpNumberOfEventsRead = Reply.Data.PeekConsoleInputReply.Length;
RtlFreeHeap(GetProcessHeap(), 0, Request);
CsrReleaseParameterBuffer(BufferBase);
return TRUE;
}

View file

@ -128,6 +128,7 @@ CSR_API(CsrRegisterServicesProcess);
CSR_API(CsrExitReactos);
CSR_API(CsrGetShutdownParameters);
CSR_API(CsrSetShutdownParameters);
CSR_API(CsrPeekConsoleInput);
/* print.c */
VOID STDCALL DisplayString(LPCWSTR lpwString);

View file

@ -1,4 +1,4 @@
/* $Id: conio.c,v 1.35 2002/10/20 00:34:40 mdill Exp $
/* $Id: conio.c,v 1.36 2002/10/29 03:49:31 mdill Exp $
*
* reactos/subsys/csrss/api/conio.c
*
@ -2076,4 +2076,75 @@ CSR_API(CsrGetNumberOfConsoleInputEvents)
return Reply->Status;
}
CSR_API(CsrPeekConsoleInput)
{
NTSTATUS Status;
PCSRSS_CONSOLE Console;
DWORD Size;
DWORD Length;
PLIST_ENTRY CurrentItem;
PLIST_ENTRY NextItem;
PINPUT_RECORD InputRecord;
ConsoleInput* Item;
UINT NumItems;
Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - sizeof(LPC_MESSAGE_HEADER);
LOCK;
Status = CsrGetObject(ProcessData, Request->Data.GetNumInputEventsRequest.ConsoleHandle, (Object_t**)&Console);
if(!NT_SUCCESS(Status))
{
Reply->Status = Status;
UNLOCK;
return Reply->Status;
}
if(Console->Header.Type != CSRSS_CONSOLE_MAGIC)
{
Reply->Status = STATUS_INVALID_HANDLE;
UNLOCK;
return Reply->Status;
}
InputRecord = Request->Data.PeekConsoleInputRequest.InputRecord;
Length = Request->Data.PeekConsoleInputRequest.Length;
Size = Length * sizeof(INPUT_RECORD);
if(((PVOID)InputRecord < ProcessData->CsrSectionViewBase)
|| (((PVOID)InputRecord + Size) > (ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize)))
{
UNLOCK;
Reply->Status = STATUS_ACCESS_VIOLATION;
return Reply->Status ;
}
NumItems = 0;
if(!IsListEmpty(&Console->InputEvents))
{
CurrentItem = &Console->InputEvents;
while(NumItems < Length)
{
++NumItems;
Item = CONTAINING_RECORD(CurrentItem, ConsoleInput, ListEntry);
*InputRecord++ = Item->InputEvent;
if(CurrentItem->Flink == &Console->InputEvents)
break;
else
CurrentItem = CurrentItem->Flink;
}
}
UNLOCK;
Reply->Status = STATUS_SUCCESS;
Reply->Data.PeekConsoleInputReply.Length = NumItems;
return Reply->Status;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: wapi.c,v 1.22 2002/10/20 16:40:12 ekohl Exp $
/* $Id: wapi.c,v 1.23 2002/10/29 03:49:32 mdill Exp $
*
* reactos/subsys/csrss/api/wapi.c
*
@ -60,6 +60,7 @@ static const CsrFunc CsrFuncs[] = {
CsrExitReactos,
CsrGetShutdownParameters,
CsrSetShutdownParameters,
CsrPeekConsoleInput,
0 };
static void Thread_Api2(HANDLE ServerPort)