reactos/win32ss/user/winsrv/consrv/frontendctl.c
Katayama Hirofumi MZ f84963b0d5
[WIN32SS][WINSRV] Add CSR API_NUMBER info comments (#2192)
Add comments to improve human-readability and referencing of CSR API. CORE-12451
2019-12-31 09:21:42 +09:00

496 lines
16 KiB
C

/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/winsrv/consrv/frontendctl.c
* PURPOSE: Terminal Front-Ends Control
* PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
*/
/* INCLUDES *******************************************************************/
#include "consrv.h"
#define NDEBUG
#include <debug.h>
/* PUBLIC SERVER APIS *********************************************************/
/**********************************************************************
* HardwareStateProperty
*
* DESCRIPTION
* Set/Get the value of the HardwareState and switch
* between direct video buffer ouput and GDI windowed
* output.
* ARGUMENTS
* Client hands us a CONSOLE_GETSETHWSTATE object.
* We use the same object to Request.
* NOTE
* ConsoleHwState has the correct size to be compatible
* with NT's, but values are not.
*/
#if 0
static NTSTATUS
SetConsoleHardwareState(PCONSRV_CONSOLE Console, ULONG ConsoleHwState)
{
DPRINT1("Console Hardware State: %d\n", ConsoleHwState);
if ((CONSOLE_HARDWARE_STATE_GDI_MANAGED == ConsoleHwState)
||(CONSOLE_HARDWARE_STATE_DIRECT == ConsoleHwState))
{
if (Console->HardwareState != ConsoleHwState)
{
/* TODO: implement switching from full screen to windowed mode */
/* TODO: or back; now simply store the hardware state */
Console->HardwareState = ConsoleHwState;
}
return STATUS_SUCCESS;
}
return STATUS_INVALID_PARAMETER_3; /* Client: (handle, set_get, [mode]) */
}
#endif
/* API_NUMBER: ConsolepGetHardwareState */
CSR_API(SrvGetConsoleHardwareState)
{
#if 0
NTSTATUS Status;
PCONSOLE_GETSETHWSTATE HardwareStateRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HardwareStateRequest;
PCONSOLE_SCREEN_BUFFER Buff;
PCONSRV_CONSOLE Console;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to get console handle in SrvGetConsoleHardwareState\n");
return Status;
}
Console = Buff->Header.Console;
HardwareStateRequest->State = Console->HardwareState;
ConSrvReleaseScreenBuffer(Buff, TRUE);
return Status;
#else
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
#endif
}
/* API_NUMBER: ConsolepSetHardwareState */
CSR_API(SrvSetConsoleHardwareState)
{
#if 0
NTSTATUS Status;
PCONSOLE_GETSETHWSTATE HardwareStateRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HardwareStateRequest;
PCONSOLE_SCREEN_BUFFER Buff;
PCONSRV_CONSOLE Console;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to get console handle in SrvSetConsoleHardwareState\n");
return Status;
}
DPRINT("Setting console hardware state.\n");
Console = Buff->Header.Console;
Status = SetConsoleHardwareState(Console, HardwareStateRequest->State);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return Status;
#else
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
#endif
}
/* API_NUMBER: ConsolepGetDisplayMode */
CSR_API(SrvGetConsoleDisplayMode)
{
NTSTATUS Status;
PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetDisplayModeRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
GetDisplayModeRequest->DisplayMode = TermGetDisplayMode(Console);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetDisplayMode */
CSR_API(SrvSetConsoleDisplayMode)
{
NTSTATUS Status;
PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetDisplayModeRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
SetDisplayModeRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
if (TermSetDisplayMode(Console, SetDisplayModeRequest->DisplayMode))
{
SetDisplayModeRequest->NewSBDim = Buff->ScreenBufferSize;
Status = STATUS_SUCCESS;
}
else
{
Status = STATUS_INVALID_PARAMETER;
}
ConSrvReleaseScreenBuffer(Buff, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetLargestWindowSize */
CSR_API(SrvGetLargestConsoleWindowSize)
{
NTSTATUS Status;
PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetLargestWindowSizeRequest;
PCONSOLE /*PCONSRV_CONSOLE*/ Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
GetLargestWindowSizeRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console = Buff->Header.Console;
/*
* Retrieve the largest possible console window size, without
* taking into account the size of the console screen buffer
* (thus differs from ConDrvGetConsoleScreenBufferInfo).
*/
TermGetLargestConsoleWindowSize(Console, &GetLargestWindowSizeRequest->Size);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepShowCursor */
CSR_API(SrvShowConsoleCursor)
{
NTSTATUS Status;
PCONSOLE_SHOWCURSOR ShowCursorRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ShowCursorRequest;
PCONSOLE /*PCONSRV_CONSOLE*/ Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
ShowCursorRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console = Buff->Header.Console;
ShowCursorRequest->RefCount = TermShowMouseCursor(Console, ShowCursorRequest->Show);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetCursor */
CSR_API(SrvSetConsoleCursor)
{
NTSTATUS Status;
BOOL Success;
PCONSOLE_SETCURSOR SetCursorRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetCursorRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
// NOTE: Tests show that this function is used only for graphics screen buffers
// and otherwise it returns FALSE and sets last error to ERROR_INVALID_HANDLE.
// I find that behaviour is ridiculous but ok, let's accept it at the moment...
Status = ConSrvGetGraphicsBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
SetCursorRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
Success = TermSetMouseCursor(Console, SetCursorRequest->CursorHandle);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return (Success ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
}
/* API_NUMBER: ConsolepMenuControl */
CSR_API(SrvConsoleMenuControl)
{
NTSTATUS Status;
PCONSOLE_MENUCONTROL MenuControlRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.MenuControlRequest;
PCONSRV_CONSOLE Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
MenuControlRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console = (PCONSRV_CONSOLE)Buff->Header.Console;
MenuControlRequest->MenuHandle = TermMenuControl(Console,
MenuControlRequest->CmdIdLow,
MenuControlRequest->CmdIdHigh);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetMenuClose */
CSR_API(SrvSetConsoleMenuClose)
{
NTSTATUS Status;
BOOL Success;
PCONSOLE_SETMENUCLOSE SetMenuCloseRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetMenuCloseRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Success = TermSetMenuClose(Console, SetMenuCloseRequest->Enable);
ConSrvReleaseConsole(Console, TRUE);
return (Success ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
}
/* Used by USERSRV!SrvGetThreadConsoleDesktop() */
NTSTATUS
NTAPI
GetThreadConsoleDesktop(
IN ULONG_PTR ThreadId,
OUT HDESK* ConsoleDesktop)
{
NTSTATUS Status;
PCSR_THREAD CsrThread;
PCONSRV_CONSOLE Console;
/* No console desktop handle by default */
*ConsoleDesktop = NULL;
/* Retrieve and lock the thread */
Status = CsrLockThreadByClientId(ULongToHandle(ThreadId), &CsrThread);
if (!NT_SUCCESS(Status))
return Status;
ASSERT(CsrThread->Process);
/* Retrieve the console to which the process is attached, and unlock the thread */
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrThread->Process),
&Console, TRUE);
CsrUnlockThread(CsrThread);
if (!NT_SUCCESS(Status))
return Status;
/* Retrieve the console desktop handle, and release the console */
*ConsoleDesktop = TermGetThreadConsoleDesktop(Console);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetConsoleWindow */
CSR_API(SrvGetConsoleWindow)
{
NTSTATUS Status;
PCONSOLE_GETWINDOW GetWindowRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetWindowRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
GetWindowRequest->WindowHandle = TermGetConsoleWindowHandle(Console);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetIcon */
CSR_API(SrvSetConsoleIcon)
{
NTSTATUS Status;
PCONSOLE_SETICON SetIconRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetIconRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = (TermChangeIcon(Console, SetIconRequest->IconHandle)
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetSelectionInfo */
CSR_API(SrvGetConsoleSelectionInfo)
{
NTSTATUS Status;
PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetSelectionInfoRequest;
PCONSRV_CONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
Status = (TermGetSelectionInfo(Console, &GetSelectionInfoRequest->Info)
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}
/* API_NUMBER: ConsolepGetNumberOfFonts */
CSR_API(SrvGetConsoleNumberOfFonts)
{
NTSTATUS Status;
PCONSOLE_GETNUMFONTS GetNumFontsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetNumFontsRequest;
PCONSOLE /*PCONSRV_CONSOLE*/ Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
&Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
// FIXME!
// TermGetNumberOfFonts(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
GetNumFontsRequest->NumFonts = 0;
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetFontInfo */
CSR_API(SrvGetConsoleFontInfo)
{
NTSTATUS Status;
PCONSOLE_GETFONTINFO GetFontInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetFontInfoRequest;
// PCONSOLE /*PCONSRV_CONSOLE*/ Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
GetFontInfoRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
// FIXME!
// Console = Buff->Header.Console;
// TermGetFontInfo(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
GetFontInfoRequest->NumFonts = 0;
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetFontSize */
CSR_API(SrvGetConsoleFontSize)
{
NTSTATUS Status;
PCONSOLE_GETFONTSIZE GetFontSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetFontSizeRequest;
// PCONSOLE /*PCONSRV_CONSOLE*/ Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
GetFontSizeRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
// FIXME!
// Console = Buff->Header.Console;
// TermGetFontSize(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepGetCurrentFont */
CSR_API(SrvGetConsoleCurrentFont)
{
NTSTATUS Status;
PCONSOLE_GETCURRENTFONT GetCurrentFontRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCurrentFontRequest;
// PCONSOLE /*PCONSRV_CONSOLE*/ Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
GetCurrentFontRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
// FIXME!
// Console = Buff->Header.Console;
// TermGetCurrentFont(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
GetCurrentFontRequest->FontIndex = 0;
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
/* API_NUMBER: ConsolepSetFont */
CSR_API(SrvSetConsoleFont)
{
NTSTATUS Status;
PCONSOLE_SETFONT SetFontRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetFontRequest;
// PCONSOLE /*PCONSRV_CONSOLE*/ Console;
PCONSOLE_SCREEN_BUFFER Buff;
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
SetFontRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
// FIXME!
// Console = Buff->Header.Console;
// TermSetFont(Console, ...);
DPRINT1("%s not yet implemented\n", __FUNCTION__);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
/* EOF */