2003-08-11 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / subsys / csrss / init.c
index 58bd906..adbb53f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: init.c,v 1.8 2000/04/23 17:44:53 phreak Exp $
+/* $Id: init.c,v 1.20 2003/08/11 18:50:12 chorns Exp $
  * 
  * reactos/subsys/csrss/init.c
  *
 #include <ddk/ntddk.h>
 #include <ntdll/rtl.h>
 #include <csrss/csrss.h>
+#include <win32k/win32k.h>
 
 #include "api.h"
 
+#define NDEBUG
+#include <debug.h>
+
 /* GLOBALS ******************************************************************/
 
 /*
@@ -35,6 +39,9 @@ UNICODE_STRING CsrDirectoryName;
 
 extern HANDLE CsrssApiHeap;
 
+ULONG
+InitializeVideoAddressSpace(VOID);
+
 static NTSTATUS
 CsrParseCommandLine (
        ULONG ArgumentCount,
@@ -47,11 +54,11 @@ CsrParseCommandLine (
 
    ULONG i;
 
-   DbgPrint ("Arguments: %ld\n", ArgumentCount);
+   /*   DbgPrint ("Arguments: %ld\n", ArgumentCount);
    for (i = 0; i < ArgumentCount; i++)
      {
        DbgPrint ("Argument %ld: %S\n", i, ArgumentArray[i]);
-     }
+       }*/
 
 
        /* create object directory ('\Windows') */
@@ -72,6 +79,36 @@ CsrParseCommandLine (
 }
 
 
+static VOID
+CsrInitVideo(VOID)
+{
+  OBJECT_ATTRIBUTES ObjectAttributes;
+  UNICODE_STRING DeviceName;
+  IO_STATUS_BLOCK Iosb;
+  HANDLE VideoHandle;
+  NTSTATUS Status;
+
+  InitializeVideoAddressSpace();
+
+  RtlInitUnicodeStringFromLiteral(&DeviceName, L"\\??\\DISPLAY1");
+  InitializeObjectAttributes(&ObjectAttributes,
+                            &DeviceName,
+                            0,
+                            NULL,
+                            NULL);
+  Status = NtOpenFile(&VideoHandle,
+                     FILE_ALL_ACCESS,
+                     &ObjectAttributes,
+                     &Iosb,
+                     0,
+                     0);
+  if (NT_SUCCESS(Status))
+    {
+      NtClose(VideoHandle);
+    }
+}
+
+
 /**********************************************************************
  * NAME
  *     CsrServerInitialization
@@ -95,16 +132,21 @@ CsrServerInitialization (
    NTSTATUS            Status;
    OBJECT_ATTRIBUTES   ObAttributes;
    UNICODE_STRING PortName;
+   OBJECT_ATTRIBUTES RefreshEventAttr;
+   UNICODE_STRING RefreshEventName;
+   HANDLE RefreshEventHandle;
 
    Status = CsrParseCommandLine (ArgumentCount, ArgumentArray);
    if (!NT_SUCCESS(Status))
      {
-       PrintString("CSR: Unable to parse the command line (Status: %x)\n", Status);
+       DPRINT1("CSR: Unable to parse the command line (Status: %x)\n", Status);
        return(FALSE);
      }
-   
+
+   CsrInitVideo();
+
    /* NEW NAMED PORT: \ApiPort */
-   RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
+   RtlInitUnicodeStringFromLiteral(&PortName, L"\\Windows\\ApiPort");
    InitializeObjectAttributes(&ObAttributes,
                              &PortName,
                              0,
@@ -118,7 +160,7 @@ CsrServerInitialization (
                         0);
    if (!NT_SUCCESS(Status))
      {
-       PrintString("CSR: Unable to create \\ApiPort (Status %x)\n", Status);
+       DPRINT1("CSR: Unable to create \\ApiPort (Status %x)\n", Status);
        return(FALSE);
      }
    CsrssApiHeap = RtlCreateHeap(HEAP_GROWABLE,
@@ -129,7 +171,7 @@ CsrServerInitialization (
                                NULL);
    if (CsrssApiHeap == NULL)
      {
-       PrintString("CSR: Failed to create private heap, aborting\n");
+       DPRINT1("CSR: Failed to create private heap, aborting\n");
        return FALSE;
      }
 
@@ -146,16 +188,27 @@ CsrServerInitialization (
                                NULL);
    if (!NT_SUCCESS(Status))
      {
-       PrintString("CSR: Unable to create server thread\n");
+       DPRINT1("CSR: Unable to create server thread\n");
        NtClose(ApiPortHandle);
        return FALSE;
      }
-   Status = RtlCreateUserThread( NtCurrentProcess(), NULL, FALSE, 0, NULL, NULL, (PTHREAD_START_ROUTINE)Console_Api, 0, NULL, NULL );
+   RtlInitUnicodeStringFromLiteral( &RefreshEventName, L"\\TextConsoleRefreshEvent" );
+   InitializeObjectAttributes( &RefreshEventAttr, &RefreshEventName, 0, NULL, NULL );
+   Status = NtCreateEvent( &RefreshEventHandle, STANDARD_RIGHTS_ALL, &RefreshEventAttr, FALSE, FALSE );
    if( !NT_SUCCESS( Status ) )
      {
-       PrintString( "CSR: Unable to create console thread\n" );
+       DPRINT1( "CSR: Unable to create refresh event!\n" );
        return FALSE;
      }
+   Status = RtlCreateUserThread( NtCurrentProcess(), NULL, FALSE, 0, NULL, NULL, (PTHREAD_START_ROUTINE)Console_Api, (PVOID) RefreshEventHandle, NULL, NULL );
+   if( !NT_SUCCESS( Status ) )
+     {
+       DPRINT1( "CSR: Unable to create console thread\n" );
+       return FALSE;
+     }
+
+   W32kInitialize();
+
    return TRUE;
 }