75211ac534d2459d502dce982162bfc529c532a9
[reactos.git] / reactos / subsys / smss / smapi.c
1 /* $Id: smapi.c,v 1.9 2002/09/08 10:23:46 chorns Exp $
2 *
3 * Reactos Session Manager
4 *
5 *
6 */
7
8 #include <ddk/ntddk.h>
9 #include <ntdll/rtl.h>
10 #include <napi/lpc.h>
11
12 #include "smss.h"
13
14 #define NDEBUG
15
16 /* GLOBAL VARIABLES *********************************************************/
17
18 static HANDLE SmApiPort = INVALID_HANDLE_VALUE;
19
20 /* FUNCTIONS ****************************************************************/
21
22
23 VOID STDCALL
24 SmApiThread(HANDLE Port)
25 {
26 NTSTATUS Status;
27 ULONG Unknown;
28 PLPC_MESSAGE Reply = NULL;
29 LPC_MESSAGE Message;
30
31 #ifndef NDEBUG
32 DisplayString(L"SmApiThread: running\n");
33 #endif
34
35 while (TRUE)
36 {
37 #ifndef NDEBUG
38 DisplayString(L"SmApiThread: waiting for message\n");
39 #endif
40
41 Status = NtReplyWaitReceivePort(Port,
42 &Unknown,
43 Reply,
44 &Message);
45 if (NT_SUCCESS(Status))
46 {
47 #ifndef NDEBUG
48 DisplayString(L"SmApiThread: message received\n");
49 #endif
50
51 if (Message.MessageType == LPC_CONNECTION_REQUEST)
52 {
53 // SmHandleConnectionRequest (Port, &Message);
54 Reply = NULL;
55 }
56 else if (Message.MessageType == LPC_DEBUG_EVENT)
57 {
58 // DbgSsHandleKmApiMsg (&Message, 0);
59 Reply = NULL;
60 }
61 else if (Message.MessageType == LPC_PORT_CLOSED)
62 {
63 Reply = NULL;
64 }
65 else
66 {
67 // Reply = &Message;
68 }
69 }
70 }
71 }
72
73
74 NTSTATUS
75 SmCreateApiPort(VOID)
76 {
77 OBJECT_ATTRIBUTES ObjectAttributes;
78 UNICODE_STRING UnicodeString;
79 NTSTATUS Status;
80
81 RtlInitUnicodeStringFromLiteral(&UnicodeString,
82 L"\\SmApiPort");
83 InitializeObjectAttributes(&ObjectAttributes,
84 &UnicodeString,
85 PORT_ALL_ACCESS,
86 NULL,
87 NULL);
88
89 Status = NtCreatePort(&SmApiPort,
90 &ObjectAttributes,
91 0,
92 0,
93 0);
94 if (!NT_SUCCESS(Status))
95 {
96 return(Status);
97 }
98
99 /* Create two threads for "\SmApiPort" */
100 RtlCreateUserThread(NtCurrentProcess(),
101 NULL,
102 FALSE,
103 0,
104 NULL,
105 NULL,
106 (PTHREAD_START_ROUTINE)SmApiThread,
107 (PVOID)SmApiPort,
108 NULL,
109 NULL);
110
111 RtlCreateUserThread(NtCurrentProcess(),
112 NULL,
113 FALSE,
114 0,
115 NULL,
116 NULL,
117 (PTHREAD_START_ROUTINE)SmApiThread,
118 (PVOID)SmApiPort,
119 NULL,
120 NULL);
121
122 return(Status);
123 }
124
125 /* EOF */