ReactOS  0.4.15-dev-1187-g119f102
console.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NTSTATUS NTAPI ConDrvInitConsole (IN OUT PCONSOLE Console, IN PCONSOLE_INFO ConsoleInfo)
 
NTSTATUS NTAPI ConDrvAttachTerminal (IN PCONSOLE Console, IN PTERMINAL Terminal)
 
NTSTATUS NTAPI ConDrvDetachTerminal (IN PCONSOLE Console)
 
VOID NTAPI ConDrvDeleteConsole (IN PCONSOLE Console)
 
BOOLEAN NTAPI ConDrvValidateConsoleState (IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
 
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe (IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
 

Function Documentation

◆ ConDrvAttachTerminal()

NTSTATUS NTAPI ConDrvAttachTerminal ( IN PCONSOLE  Console,
IN PTERMINAL  Terminal 
)

Definition at line 159 of file console.c.

161 {
163 
164  if (Console == NULL || Terminal == NULL)
166 
167  /* FIXME: Lock the console before ?? */
168 
169  /*
170  * Attach the terminal to the console. Use now the TermIFace of the console,
171  * and not the user-defined temporary Terminal pointer.
172  */
173  Console->TermIFace = *Terminal;
174  Console->TermIFace.Console = Console;
175 
176  /* Initialize the terminal AFTER having attached it to the console */
177  DPRINT("Finish initialization of terminal\n");
178  Status = Console->TermIFace.Vtbl->InitTerminal(&Console->TermIFace, Console);
179  if (!NT_SUCCESS(Status))
180  {
181  DPRINT1("Terminal initialization failed, Status = 0x%08lx\n", Status);
182 
183  /* We failed, detach the terminal from the console */
184  Terminal->Console = NULL; // For the caller
186  return Status;
187  }
188 
189  /* Copy buffer contents to screen */
190  // Terminal.Draw();
191 
192  DPRINT("Terminal initialization done\n");
193  return STATUS_SUCCESS;
194 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
VOID ResetTerminal(IN PCONSOLE Console)
Definition: dummyterm.c:156
CConsole Console
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConSrvInitConsole().

◆ ConDrvDeleteConsole()

VOID NTAPI ConDrvDeleteConsole ( IN PCONSOLE  Console)

Definition at line 217 of file console.c.

218 {
219  DPRINT("ConDrvDeleteConsole(0x%p)\n", Console);
220 
221  /*
222  * Forbid validation of any console by other threads
223  * during the deletion of this console.
224  */
225  // ConDrvLockConsoleListExclusive();
226 
227  /*
228  * If the console is already being destroyed, i.e. not running
229  * or finishing to be initialized, just return.
230  */
233  {
234  return;
235  }
236 
237  /*
238  * We are about to be destroyed. Signal it to other people
239  * so that they can terminate what they are doing, and that
240  * they cannot longer validate the console.
241  */
242  Console->State = CONSOLE_TERMINATING;
243 
244  /*
245  * Allow other threads to finish their job: basically, unlock
246  * all other calls to EnterCriticalSection(&Console->Lock); by
247  * ConDrvValidateConsoleUnsafe() functions so that they just see
248  * that we are not in CONSOLE_RUNNING state anymore, or unlock
249  * other concurrent calls to ConDrvDeleteConsole() so that they
250  * can see that we are in fact already deleting the console.
251  */
253 
254  /* Deregister the terminal */
255  DPRINT("Deregister terminal\n");
257  DPRINT("Terminal deregistered\n");
258 
259  /***
260  * Check that the console is in terminating state before continuing
261  * (the cleanup code must not change the state of the console...
262  * ...unless to cancel console deletion ?).
263  ***/
264 
266  {
267  return;
268  }
269 
270  /* We are now in destruction */
272 
273  /* We really delete the console. Reset the count to be sure. */
274  Console->ReferenceCount = 0;
275 
276  /* Delete the last screen buffer */
277  ConDrvDeleteScreenBuffer(Console->ActiveBuffer);
278  Console->ActiveBuffer = NULL;
279  if (!IsListEmpty(&Console->BufferList))
280  {
281  /***ConDrvUnlockConsoleList();***/
282  ASSERTMSG("BUGBUGBUG!! screen buffer list not empty\n", FALSE);
283  }
284 
285  /* Deinitialize the input buffer */
287 
288  Console->ConsolePaused = FALSE;
289 
290  DPRINT("ConDrvDeleteConsole - Unlocking\n");
292  DPRINT("ConDrvDeleteConsole - Destroying lock\n");
294  DPRINT("ConDrvDeleteConsole - Lock destroyed\n");
295 
296  DPRINT("ConDrvDeleteConsole - Console destroyed\n");
297 }
VOID NTAPI ConDrvDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:130
NTSTATUS NTAPI ConDrvDetachTerminal(IN PCONSOLE Console)
Definition: console.c:197
#define TRUE
Definition: types.h:120
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FALSE
Definition: types.h:117
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
VOID NTAPI ConDrvDeinitInputBuffer(IN PCONSOLE Console)
Definition: coninput.c:221
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:36
CConsole Console
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by ConSrvDeleteConsole(), and ConSrvInitConsole().

◆ ConDrvDetachTerminal()

NTSTATUS NTAPI ConDrvDetachTerminal ( IN PCONSOLE  Console)

Definition at line 197 of file console.c.

198 {
199  if (Console == NULL) return STATUS_INVALID_PARAMETER;
200 
201  /* FIXME: Lock the console before ?? */
202 
203  /* Deinitialize the terminal BEFORE detaching it from the console */
204  Console->TermIFace.Vtbl->DeinitTerminal(&Console->TermIFace/*, Console*/);
205 
206  /*
207  * Detach the terminal from the console:
208  * reinitialize the terminal interface.
209  */
211 
212  DPRINT("Terminal unregistered\n");
213  return STATUS_SUCCESS;
214 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID ResetTerminal(IN PCONSOLE Console)
Definition: dummyterm.c:156
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConDrvDeleteConsole().

◆ ConDrvInitConsole()

NTSTATUS NTAPI ConDrvInitConsole ( IN OUT PCONSOLE  Console,
IN PCONSOLE_INFO  ConsoleInfo 
)

Definition at line 69 of file console.c.

72 {
74  // CONSOLE_INFO CapturedConsoleInfo;
76  PCONSOLE_SCREEN_BUFFER NewBuffer;
77 
78  if (Console == NULL || ConsoleInfo == NULL)
80 
81  /* Reset the console structure */
82  RtlZeroMemory(Console, sizeof(*Console));
83 
84  /*
85  * Set and fix the screen buffer size if needed.
86  * The rule is: ScreenBufferSize >= ConsoleSize
87  */
88  if (ConsoleInfo->ScreenBufferSize.X == 0) ConsoleInfo->ScreenBufferSize.X = 1;
89  if (ConsoleInfo->ScreenBufferSize.Y == 0) ConsoleInfo->ScreenBufferSize.Y = 1;
90  if (ConsoleInfo->ScreenBufferSize.X < ConsoleInfo->ConsoleSize.X)
91  ConsoleInfo->ScreenBufferSize.X = ConsoleInfo->ConsoleSize.X;
92  if (ConsoleInfo->ScreenBufferSize.Y < ConsoleInfo->ConsoleSize.Y)
93  ConsoleInfo->ScreenBufferSize.Y = ConsoleInfo->ConsoleSize.Y;
94 
95  /*
96  * Initialize the console
97  */
99  Console->ReferenceCount = 0;
101 
102  /* Initialize the terminal interface */
104 
105  Console->ConsoleSize = ConsoleInfo->ConsoleSize;
106  Console->FixedSize = FALSE; // Value by default; is reseted by the terminals if needed.
107 
108  /* Initialize the input buffer */
109  Status = ConDrvInitInputBuffer(Console, 0 /* ConsoleInfo->InputBufferSize */);
110  if (!NT_SUCCESS(Status))
111  {
112  DPRINT1("ConDrvInitInputBuffer: failed, Status = 0x%08lx\n", Status);
114  return Status;
115  }
116 
117  /* Set-up the code page */
118  if (IsValidCodePage(ConsoleInfo->CodePage))
119  Console->InputCodePage = Console->OutputCodePage = ConsoleInfo->CodePage;
120 
121  Console->IsCJK = IsCJKCodePage(Console->OutputCodePage);
122 
123  /* Initialize a new text-mode screen buffer with default settings */
124  ScreenBufferInfo.ScreenBufferSize = ConsoleInfo->ScreenBufferSize;
125  ScreenBufferInfo.ViewSize = ConsoleInfo->ConsoleSize;
126  ScreenBufferInfo.ScreenAttrib = ConsoleInfo->ScreenAttrib;
127  ScreenBufferInfo.PopupAttrib = ConsoleInfo->PopupAttrib;
128  ScreenBufferInfo.CursorSize = ConsoleInfo->CursorSize;
129  ScreenBufferInfo.IsCursorVisible = TRUE;
130 
131  InitializeListHead(&Console->BufferList);
132  Status = ConDrvCreateScreenBuffer(&NewBuffer,
133  Console,
134  NULL,
137  if (!NT_SUCCESS(Status))
138  {
139  DPRINT1("ConDrvCreateScreenBuffer: failed, Status = 0x%08lx\n", Status);
142  return Status;
143  }
144  /* Make the new screen buffer active */
145  Console->ActiveBuffer = NewBuffer;
146  Console->ConsolePaused = FALSE;
147 
148  DPRINT("Console initialized\n");
149 
150  /* The initialization is finished */
151  DPRINT("Change state\n");
152  Console->State = CONSOLE_RUNNING;
153 
154  /* The caller now has a newly initialized console */
155  return STATUS_SUCCESS;
156 }
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ConDrvCreateScreenBuffer(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle OPTIONAL, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
Definition: conoutput.c:85
#define IsCJKCodePage(CodePage)
Definition: font.h:23
#define FALSE
Definition: types.h:117
VOID NTAPI ConDrvDeinitInputBuffer(IN PCONSOLE Console)
Definition: coninput.c:221
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
VOID ResetTerminal(IN PCONSOLE Console)
Definition: dummyterm.c:156
BOOL WINAPI IsValidCodePage(UINT CodePage)
Definition: nls.c:1479
NTSTATUS NTAPI ConDrvInitInputBuffer(IN PCONSOLE Console, IN ULONG InputBufferSize)
Definition: coninput.c:192
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:62
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConSrvInitConsole().

◆ ConDrvValidateConsoleState()

BOOLEAN NTAPI ConDrvValidateConsoleState ( IN PCONSOLE  Console,
IN CONSOLE_STATE  ExpectedState 
)

Definition at line 24 of file console.c.

26 {
27  // if (!Console) return FALSE;
28 
29  /* The console must be locked */
30  // ASSERT(Console_locked);
31 
32  return (Console->State == ExpectedState);
33 }
CConsole Console

Referenced by ConDrvValidateConsoleUnsafe(), ConSrvConsoleProcessCtrlEvent(), and ConSrvSetConsoleProcessFocus().

◆ ConDrvValidateConsoleUnsafe()

BOOLEAN NTAPI ConDrvValidateConsoleUnsafe ( IN PCONSOLE  Console,
IN CONSOLE_STATE  ExpectedState,
IN BOOLEAN  LockConsole 
)

Definition at line 36 of file console.c.

39 {
40  if (!Console) return FALSE;
41 
42  /*
43  * Lock the console to forbid possible console's state changes
44  * (which must be done when the console is already locked).
45  * If we don't want to lock it, it's because the lock is already
46  * held. So there must be no problems.
47  */
48  if (LockConsole) EnterCriticalSection(&Console->Lock);
49 
50  // ASSERT(Console_locked);
51 
52  /* Check whether the console's state is what we expect */
53  if (!ConDrvValidateConsoleState(Console, ExpectedState))
54  {
55  if (LockConsole) LeaveCriticalSection(&Console->Lock);
56  return FALSE;
57  }
58 
59  return TRUE;
60 }
BOOLEAN NTAPI ConDrvValidateConsoleState(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
Definition: console.c:24
#define TRUE
Definition: types.h:120
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define FALSE
Definition: types.h:117
CConsole Console
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by ConDrvDeleteConsole(), ConSrvGetObject(), ConSrvValidateConsole(), GuiApplyUserSettings(), GuiConsoleShowConsoleProperties(), GuiConsoleSwitchFullScreen(), GuiPaintGraphicsBuffer(), GuiPaintTextModeBuffer(), OnClose(), OnFocus(), OnGetMinMaxInfo(), OnKey(), OnMouse(), OnScroll(), OnSize(), OnTimer(), and SendMenuEvent().