1e132375c9abf9a5b6ed2c5fdb80eb21a12ca0a6
[reactos.git] / reactos / subsys / smss / smapi.c
1 /* $Id$
2 *
3 * Reactos Session Manager
4 *
5 *
6 */
7
8 /*#include <ddk/ntddk.h>
9 #include <ntdll/rtl.h>*/
10 #define NTOS_MODE_USER
11 #include <ntos.h>
12 #include <sm/api.h>
13 #include <rosrtl/string.h>
14 #include "smss.h"
15
16 #define NDEBUG
17
18 /* GLOBAL VARIABLES *********************************************************/
19
20 static HANDLE SmApiPort = INVALID_HANDLE_VALUE;
21
22 /* SM API *******************************************************************/
23
24 #define SMAPI(n) \
25 NTSTATUS FASTCALL n (PSM_PORT_MESSAGE Request)
26
27 SMAPI(SmInvalid)
28 {
29 DbgPrint("SMSS: %s called\n",__FUNCTION__);
30 Request->Status = STATUS_NOT_IMPLEMENTED;
31 return STATUS_SUCCESS;
32 }
33
34 SMAPI(SmCompSes)
35 {
36 DbgPrint("SMSS: %s called\n",__FUNCTION__);
37 Request->Status = STATUS_NOT_IMPLEMENTED;
38 return STATUS_SUCCESS;
39 }
40 SMAPI(SmExecPgm)
41 {
42 DbgPrint("SMSS: %s called\n",__FUNCTION__);
43 Request->Status = STATUS_NOT_IMPLEMENTED;
44 return STATUS_SUCCESS;
45 }
46
47 /* SM API Table */
48 typedef NTSTATUS (FASTCALL * SM_PORT_API)(PSM_PORT_MESSAGE);
49
50 SM_PORT_API SmApi [] =
51 {
52 SmInvalid, /* unused */
53 SmCompSes,
54 SmInvalid, /* obsolete */
55 SmInvalid, /* unknown */
56 SmExecPgm
57 };
58
59
60 /**********************************************************************
61 * NAME
62 * SmpHandleConnectionRequest/2
63 *
64 * REMARKS
65 * Quoted in http://support.microsoft.com/kb/258060/EN-US/
66 */
67 NTSTATUS STDCALL
68 SmpHandleConnectionRequest (HANDLE Port, PSM_PORT_MESSAGE Request)
69 {
70 DbgPrint("SMSS: %s called\n",__FUNCTION__);
71 return STATUS_SUCCESS;
72 }
73
74 /**********************************************************************
75 * NAME
76 * SmpApiThread/1
77 *
78 * DESCRIPTION
79 * Entry point for the listener thread of LPC port "\SmApiPort".
80 */
81 VOID STDCALL
82 SmpApiThread(HANDLE Port)
83 {
84 NTSTATUS Status = STATUS_SUCCESS;
85 ULONG Unknown = 0;
86 PLPC_MESSAGE Reply = NULL;
87 SM_PORT_MESSAGE Request = {{0}};
88
89 DbgPrint("SMSS: %s running.\n",__FUNCTION__);
90
91 while (TRUE)
92 {
93 DbgPrint("SMSS: %s: waiting for message\n",__FUNCTION__);
94
95 Status = NtReplyWaitReceivePort(Port,
96 & Unknown,
97 Reply,
98 (PLPC_MESSAGE) & Request);
99 if (NT_SUCCESS(Status))
100 {
101 DbgPrint("SMSS: %s: message received\n",__FUNCTION__);
102
103 switch (Request.Header.MessageType)
104 {
105 case LPC_CONNECTION_REQUEST:
106 SmpHandleConnectionRequest (Port, &Request);
107 Reply = NULL;
108 break;
109 case LPC_DEBUG_EVENT:
110 // DbgSsHandleKmApiMsg (&Request, 0);
111 Reply = NULL;
112 break;
113 case LPC_PORT_CLOSED:
114 Reply = NULL;
115 break;
116 default:
117 if ((Request.ApiIndex) &&
118 (Request.ApiIndex < (sizeof SmApi / sizeof SmApi[0])))
119 {
120 Status = SmApi[Request.ApiIndex](&Request);
121 Reply = (PLPC_MESSAGE) & Request;
122 } else {
123 Request.Status = STATUS_NOT_IMPLEMENTED;
124 Reply = (PLPC_MESSAGE) & Request;
125 }
126 }
127 }
128 }
129 }
130
131
132 /* LPC PORT INITIALIZATION **************************************************/
133
134
135 /**********************************************************************
136 * NAME
137 * SmCreateApiPort/0
138 *
139 * DECRIPTION
140 */
141 NTSTATUS
142 SmCreateApiPort(VOID)
143 {
144 OBJECT_ATTRIBUTES ObjectAttributes;
145 UNICODE_STRING UnicodeString;
146 NTSTATUS Status;
147
148 RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
149 L"\\SmApiPort");
150 InitializeObjectAttributes(&ObjectAttributes,
151 &UnicodeString,
152 PORT_ALL_ACCESS,
153 NULL,
154 NULL);
155
156 Status = NtCreatePort(&SmApiPort,
157 &ObjectAttributes,
158 0,
159 0,
160 0);
161 if (!NT_SUCCESS(Status))
162 {
163 return(Status);
164 }
165
166 /* Create two threads for "\SmApiPort" */
167 RtlCreateUserThread(NtCurrentProcess(),
168 NULL,
169 FALSE,
170 0,
171 NULL,
172 NULL,
173 (PTHREAD_START_ROUTINE)SmpApiThread,
174 (PVOID)SmApiPort,
175 NULL,
176 NULL);
177
178 RtlCreateUserThread(NtCurrentProcess(),
179 NULL,
180 FALSE,
181 0,
182 NULL,
183 NULL,
184 (PTHREAD_START_ROUTINE)SmpApiThread,
185 (PVOID)SmApiPort,
186 NULL,
187 NULL);
188
189 return(Status);
190 }
191
192 /* EOF */