SM: simplify and fix client (subsystem servers) management.
[reactos.git] / reactos / subsys / smss / debug.c
1 /* $Id$
2 *
3 * debug.c - Session Manager debug messages switch and router
4 *
5 * ReactOS Operating System
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
22 * MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 */
26 #include "smss.h"
27
28 #define NDEBUG
29 #include <debug.h>
30
31
32 /* GLOBALS ***********************************************************/
33
34 HANDLE DbgSsApiPort = (HANDLE) 0;
35 HANDLE DbgUiApiPort = (HANDLE) 0;
36 HANDLE hSmDbgApiPort = (HANDLE) 0;
37
38 /* FUNCTIONS *********************************************************/
39
40 static VOID STDCALL
41 DbgSsApiPortThread (PVOID dummy)
42 {
43 NTSTATUS Status = STATUS_SUCCESS;
44 PORT_MESSAGE Request ;
45
46 RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
47 while (TRUE)
48 {
49 Status = NtListenPort (DbgSsApiPort, & Request);
50 if (!NT_SUCCESS(Status))
51 {
52 DPRINT1("SM: %s: NtListenPort() failed! (Status==x%08lx)\n", __FUNCTION__, Status);
53 break;
54 }
55 /* TODO */
56 }
57 NtTerminateThread(NtCurrentThread(),Status);
58 }
59
60 static VOID STDCALL
61 DbgUiApiPortThread (PVOID dummy)
62 {
63 NTSTATUS Status = STATUS_SUCCESS;
64 PORT_MESSAGE Request;
65
66 RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
67 while (TRUE)
68 {
69 Status = NtListenPort (DbgUiApiPort, & Request);
70 if (!NT_SUCCESS(Status))
71 {
72 DPRINT1("SM: %s: NtListenPort() failed! (Status==x%08lx)\n", __FUNCTION__, Status);
73 break;
74 }
75 /* TODO */
76 }
77 NtTerminateThread(NtCurrentThread(),Status);
78 }
79
80 static NTSTATUS STDCALL
81 SmpCreatePT (IN OUT PHANDLE hPort,
82 IN LPWSTR wcPortName,
83 IN ULONG ulMaxDataSize,
84 IN ULONG ulMaxMessageSize,
85 IN ULONG ulPoolCharge OPTIONAL,
86 IN VOID (STDCALL * procServingThread)(PVOID) OPTIONAL,
87 IN OUT PHANDLE phServingThread OPTIONAL)
88 {
89 NTSTATUS Status = STATUS_SUCCESS;
90 UNICODE_STRING PortName = {0};
91 OBJECT_ATTRIBUTES ObjectAttributes;
92 HANDLE Thread = (HANDLE) 0;
93 CLIENT_ID Cid = {0, 0};
94
95 RtlInitUnicodeString (& PortName, wcPortName);
96 InitializeObjectAttributes (& ObjectAttributes,
97 & PortName,
98 0,
99 NULL,
100 NULL);
101 Status = NtCreatePort (hPort,
102 & ObjectAttributes,
103 ulMaxDataSize,
104 ulMaxMessageSize,
105 ulPoolCharge);
106 if(STATUS_SUCCESS != Status)
107 {
108 return Status;
109 }
110 /* Create thread for DbgSsApiPort */
111 RtlCreateUserThread(NtCurrentProcess(),
112 NULL,
113 FALSE,
114 0,
115 0,
116 0,
117 (PTHREAD_START_ROUTINE) procServingThread,
118 hPort,
119 & Thread,
120 & Cid);
121 if((HANDLE) 0 == Thread)
122 {
123 NtClose(*hPort);
124 Status = STATUS_UNSUCCESSFUL;
125 }
126 if(NULL != phServingThread)
127 {
128 *phServingThread = Thread;
129 }
130 return Status;
131 }
132
133 NTSTATUS
134 SmInitializeDbgSs (VOID)
135 {
136 NTSTATUS Status = STATUS_SUCCESS;
137 HANDLE hDbgSsApiPortThread = (HANDLE) 0;
138
139
140 DPRINT("SM: %s called\n", __FUNCTION__);
141
142 /* Self register */
143 #if 0
144 Status = SmRegisterInternalSubsystem (L"Debug",
145 (USHORT)-1,
146 & hSmDbgApiPort);
147 if (!NT_SUCCESS(Status))
148 {
149 DPRINT1("DBG:%s: SmRegisterInternalSubsystem failed with Status=%08lx\n",
150 __FUNCTION__, Status);
151 return Status;
152 }
153 #endif
154 /* Create the \DbgSsApiPort object (LPC) */
155 Status = SmpCreatePT(& DbgSsApiPort,
156 SM_DBGSS_PORT_NAME,
157 0, /* MaxDataSize */
158 0, /* MaxMessageSize */
159 0, /* PoolCharge */
160 DbgSsApiPortThread,
161 & hDbgSsApiPortThread);
162 if(!NT_SUCCESS(Status))
163 {
164 DPRINT("SM: %s: DBGSS port not created\n",__FUNCTION__);
165 return Status;
166 }
167 /* Create the \DbgUiApiPort object (LPC) */
168 Status = SmpCreatePT(& DbgUiApiPort,
169 SM_DBGUI_PORT_NAME,
170 0, /* MaxDataSize */
171 0, /* MaxMessageSize */
172 0, /* PoolCharge */
173 DbgUiApiPortThread,
174 NULL);
175 if(!NT_SUCCESS(Status))
176 {
177 DPRINT("SM: %s: DBGUI port not created\n",__FUNCTION__);
178 NtClose (hDbgSsApiPortThread);
179 NtClose (DbgSsApiPort);
180 return Status;
181 }
182 return STATUS_SUCCESS;
183 }
184
185 /* EOF */
186