Added eventlog service stub.
[reactos.git] / reactos / services / eventlog / logport.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: logport.c,v 1.1 2002/06/25 21:10:14 ekohl Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/eventlog/logport.c
24 * PURPOSE: Event logger service
25 * PROGRAMMER: Eric Kohl
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #define UNICODE
31
32 #define NTOS_MODE_USER
33 #include <ntos.h>
34 #include <napi/lpc.h>
35 #include <windows.h>
36
37 #include "eventlog.h"
38
39 #define NDEBUG
40 #include <debug.h>
41
42
43 /* GLOBALS ******************************************************************/
44
45 HANDLE PortThreadHandle = NULL;
46 HANDLE ConnectPortHandle = NULL;
47 HANDLE MessagePortHandle = NULL;
48
49
50 /* FUNCTIONS ****************************************************************/
51
52 static NTSTATUS
53 InitLogPort(VOID)
54 {
55 OBJECT_ATTRIBUTES ObjectAttributes;
56 UNICODE_STRING PortName;
57 LPC_MESSAGE Message;
58 NTSTATUS Status;
59
60 ConnectPortHandle = NULL;
61 MessagePortHandle = NULL;
62
63 RtlInitUnicodeString(&PortName,
64 L"\\ErrorLogPort");
65 InitializeObjectAttributes(&ObjectAttributes,
66 &PortName,
67 0,
68 NULL,
69 NULL);
70
71 Status = NtCreatePort(&ConnectPortHandle,
72 &ObjectAttributes,
73 0,
74 0x100,
75 0x2000);
76 if (!NT_SUCCESS(Status))
77 goto ByeBye;
78
79 Message.DataSize = sizeof(LPC_MESSAGE);
80 Message.MessageSize = 0;
81
82 Status = NtListenPort(ConnectPortHandle,
83 &Message);
84 if (!NT_SUCCESS(Status))
85 goto ByeBye;
86
87 Status = NtAcceptConnectPort(&MessagePortHandle,
88 0,
89 &Message,
90 1,
91 0,
92 0);
93 if (!NT_SUCCESS(Status))
94 goto ByeBye;
95
96 Status = NtCompleteConnectPort(MessagePortHandle);
97 if (!NT_SUCCESS(Status))
98 goto ByeBye;
99
100 ByeBye:
101 if (ConnectPortHandle != NULL)
102 NtClose(ConnectPortHandle);
103
104 if (MessagePortHandle != NULL)
105 NtClose(MessagePortHandle);
106
107 return(Status);
108 }
109
110
111 static NTSTATUS
112 ProcessPortMessage(VOID)
113 {
114 PLPC_MAX_MESSAGE Request;
115 LPC_MESSAGE Reply;
116 BOOL ReplyReady = FALSE;
117 NTSTATUS Status;
118
119 Request = HeapAlloc(GetProcessHeap(),
120 HEAP_ZERO_MEMORY,
121 sizeof(LPC_MAX_MESSAGE));
122 if (Request == NULL)
123 return(STATUS_NO_MEMORY);
124
125 while (TRUE)
126 {
127 Status = NtReplyWaitReceivePort(MessagePortHandle,
128 0,
129 (ReplyReady)? &Reply : NULL,
130 (PLPC_MESSAGE)Request);
131 if (!NT_SUCCESS(Status))
132 {
133 HeapFree(GetProcessHeap(),
134 0,
135 Request);
136 return(Status);
137 }
138
139 ReplyReady = FALSE;
140 if (Request->Header.MessageType == LPC_REQUEST)
141 {
142 DPRINT1("Received request\n");
143
144 ReplyReady = FALSE;
145 }
146 else if (Request->Header.MessageType == LPC_DATAGRAM)
147 {
148 DPRINT1("Received datagram\n");
149 }
150 }
151 }
152
153
154 static NTSTATUS STDCALL
155 PortThreadRoutine(PVOID Param)
156 {
157 NTSTATUS Status = STATUS_SUCCESS;
158
159 Status = InitLogPort();
160 if (!NT_SUCCESS(Status))
161 return(Status);
162
163 while (!NT_SUCCESS(Status))
164 {
165 Status = ProcessPortMessage();
166 }
167
168 return(Status);
169 }
170
171
172 BOOL
173 StartPortThread(VOID)
174 {
175 DWORD ThreadId;
176
177 PortThreadHandle = CreateThread(NULL,
178 0x1000,
179 PortThreadRoutine,
180 NULL,
181 0,
182 &ThreadId);
183
184 return((PortThreadHandle != NULL));
185 }
186
187 /* EOF */