[LOCALSPL]
[reactos.git] / reactos / win32ss / printing / base / spoolss / monitors.c
1 /*
2 * PROJECT: ReactOS Spooler Router
3 * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
4 * PURPOSE: Functions related to Print Monitors
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 BOOL WINAPI
11 EnumMonitorsW(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
12 {
13 BOOL bReturnValue;
14 DWORD cbCallBuffer;
15 DWORD cbNeeded;
16 DWORD dwReturned;
17 PBYTE pCallBuffer;
18 PSPOOLSS_PRINT_PROVIDER pPrintProvider;
19 PLIST_ENTRY pEntry;
20
21 // Sanity checks.
22 if ((cbBuf && !pMonitors) || !pcbNeeded || !pcReturned)
23 {
24 SetLastError(ERROR_INVALID_PARAMETER);
25 return FALSE;
26 }
27
28 // Begin counting.
29 *pcbNeeded = 0;
30 *pcReturned = 0;
31
32 // At the beginning, we have the full buffer available.
33 cbCallBuffer = cbBuf;
34 pCallBuffer = pMonitors;
35
36 // Loop through all Print Provider.
37 for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
38 {
39 pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
40
41 // Check if this Print Provider provides an EnumMonitors function.
42 if (!pPrintProvider->PrintProvider.fpEnumMonitors)
43 continue;
44
45 // Call the EnumMonitors function of this Print Provider.
46 bReturnValue = pPrintProvider->PrintProvider.fpEnumMonitors(pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
47
48 // Add the returned counts to the total values.
49 *pcbNeeded += cbNeeded;
50 *pcReturned += dwReturned;
51
52 // Reduce the available buffer size for the next call without risking an underflow.
53 if (cbNeeded < cbCallBuffer)
54 cbCallBuffer -= cbNeeded;
55 else
56 cbCallBuffer = 0;
57
58 // Advance the buffer if the caller provided it.
59 if (pCallBuffer)
60 pCallBuffer += cbNeeded;
61
62 // Check if we shall not ask other Print Providers.
63 if (bReturnValue == ROUTER_STOP_ROUTING)
64 break;
65 }
66
67 return bReturnValue;
68 }