3 * Copyright (C) 2015 ReactOS Team
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Services
22 * FILE: base/services/schedsvc/rpcserver.c
23 * PURPOSE: Scheduler service
24 * PROGRAMMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
33 WINE_DEFAULT_DEBUG_CHANNEL(schedsvc
);
47 DWORD dwNextJobId
= 0;
49 LIST_ENTRY JobListHead
;
50 RTL_RESOURCE JobListLock
;
53 /* FUNCTIONS *****************************************************************/
62 Status
= RpcServerUseProtseqEpW(L
"ncacn_np", 20, L
"\\pipe\\atsvc", NULL
);
63 if (Status
!= RPC_S_OK
)
65 ERR("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status
);
69 Status
= RpcServerRegisterIf(atsvc_v1_0_s_ifspec
, NULL
, NULL
);
70 if (Status
!= RPC_S_OK
)
72 ERR("RpcServerRegisterIf() failed (Status %lx)\n", Status
);
76 Status
= RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, FALSE
);
77 if (Status
!= RPC_S_OK
)
79 ERR("RpcServerListen() failed (Status %lx)\n", Status
);
86 void __RPC_FAR
* __RPC_USER
midl_user_allocate(SIZE_T len
)
88 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
92 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
94 HeapFree(GetProcessHeap(), 0, ptr
);
102 ATSVC_HANDLE ServerName
,
108 TRACE("NetrJobAdd(%S %p %p)\n",
109 ServerName
, pAtInfo
, pJobId
);
111 /* Allocate a new job object */
112 pJob
= HeapAlloc(GetProcessHeap(),
114 sizeof(JOB
) + wcslen(pAtInfo
->Command
) * sizeof(WCHAR
));
116 return ERROR_OUTOFMEMORY
;
118 /* Initialize the job object */
119 pJob
->JobTime
= pAtInfo
->JobTime
;
120 pJob
->DaysOfMonth
= pAtInfo
->DaysOfMonth
;
121 pJob
->DaysOfWeek
= pAtInfo
->DaysOfWeek
;
122 pJob
->Flags
= pAtInfo
->Flags
;
123 wcscpy(pJob
->Command
, pAtInfo
->Command
);
125 /* Acquire the job list lock exclusively */
126 RtlAcquireResourceExclusive(&JobListLock
, TRUE
);
128 /* Assign a new job ID */
129 pJob
->JobId
= dwNextJobId
++;
132 /* Append the new job to the job list */
133 InsertTailList(&JobListHead
, &pJob
->Entry
);
135 /* Release the job list lock */
136 RtlReleaseResource(&JobListLock
);
138 /* Return the new job ID */
139 *pJobId
= pJob
->JobId
;
141 return ERROR_SUCCESS
;
149 ATSVC_HANDLE ServerName
,
153 PLIST_ENTRY JobEntry
, NextEntry
;
156 TRACE("NetrJobDel(%S %lu %lu)\n",
157 ServerName
, MinJobId
, MaxJobId
);
159 /* Acquire the job list lock exclusively */
160 RtlAcquireResourceExclusive(&JobListLock
, TRUE
);
162 JobEntry
= JobListHead
.Flink
;
163 while (JobEntry
!= &JobListHead
)
165 CurrentJob
= CONTAINING_RECORD(JobEntry
, JOB
, Entry
);
167 if ((CurrentJob
->JobId
>= MinJobId
) && (CurrentJob
->JobId
<= MaxJobId
))
169 NextEntry
= JobEntry
->Flink
;
170 if (RemoveEntryList(JobEntry
))
173 HeapFree(GetProcessHeap(), 0, CurrentJob
);
174 JobEntry
= NextEntry
;
179 JobEntry
= JobEntry
->Flink
;
182 /* Release the job list lock */
183 RtlReleaseResource(&JobListLock
);
185 return ERROR_SUCCESS
;
193 ATSVC_HANDLE ServerName
,
194 LPAT_ENUM_CONTAINER pEnumContainer
,
195 DWORD PreferedMaximumLength
,
196 LPDWORD pTotalEntries
,
197 LPDWORD pResumeHandle
)
199 TRACE("NetrJobEnum(%S %p %lu %p %p)\n",
200 ServerName
, pEnumContainer
, PreferedMaximumLength
, pTotalEntries
, pResumeHandle
);
201 return ERROR_SUCCESS
;
209 ATSVC_HANDLE ServerName
,
213 PLIST_ENTRY JobEntry
;
216 DWORD dwError
= ERROR_FILE_NOT_FOUND
;
218 TRACE("NetrJobGetInfo(%S %lu %p)\n",
219 ServerName
, JobId
, ppAtInfo
);
221 /* Acquire the job list lock exclusively */
222 RtlAcquireResourceShared(&JobListLock
, TRUE
);
224 /* Traverse the job list */
225 JobEntry
= JobListHead
.Flink
;
226 while (JobEntry
!= &JobListHead
)
228 CurrentJob
= CONTAINING_RECORD(JobEntry
, JOB
, Entry
);
230 /* Do we have the right job? */
231 if (CurrentJob
->JobId
== JobId
)
233 pInfo
= midl_user_allocate(sizeof(AT_INFO
));
236 dwError
= ERROR_OUTOFMEMORY
;
240 pInfo
->Command
= midl_user_allocate((wcslen(CurrentJob
->Command
) + 1) * sizeof(WCHAR
));
241 if (pInfo
->Command
== NULL
)
243 midl_user_free(pInfo
);
244 dwError
= ERROR_OUTOFMEMORY
;
248 pInfo
->JobTime
= CurrentJob
->JobTime
;
249 pInfo
->DaysOfMonth
= CurrentJob
->DaysOfMonth
;
250 pInfo
->DaysOfWeek
= CurrentJob
->DaysOfWeek
;
251 pInfo
->Flags
= CurrentJob
->Flags
;
252 wcscpy(pInfo
->Command
, CurrentJob
->Command
);
256 dwError
= ERROR_SUCCESS
;
261 JobEntry
= JobEntry
->Flink
;
265 /* Release the job list lock */
266 RtlReleaseResource(&JobListLock
);