Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1990-1994 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. Change.c
  6. Abstract:
  7. Handles implementation for WaitForPrinterChange and related apis.
  8. FindFirstPrinterChangeNotification
  9. FindClosePrinterChangeNotification
  10. RefreshPrinterChangeNotification
  11. Author:
  12. Albert Ting (AlbertT) 24-Apr-94
  13. Environment:
  14. User Mode -Win32
  15. Revision History:
  16. --*/
  17. #include <precomp.h>
  18. #pragma hdrstop
  19. BOOL
  20. RemoteFindFirstPrinterChangeNotification(
  21. HANDLE hPrinter,
  22. DWORD fdwFlags,
  23. DWORD fdwOptions,
  24. HANDLE hNotify,
  25. PDWORD pfdwStatus,
  26. PVOID pvReserved0,
  27. PVOID pvReserved1);
  28. BOOL
  29. RemoteFindClosePrinterChangeNotification(
  30. HANDLE hPrinter);
  31. BOOL
  32. RemoteFindFirstPrinterChangeNotification(
  33. HANDLE hPrinter,
  34. DWORD fdwFlags,
  35. DWORD fdwOptions,
  36. HANDLE hNotify,
  37. PDWORD pfdwStatus,
  38. PVOID pvReserved0,
  39. PVOID pvReserved1)
  40. {
  41. BOOL bReturnValue = TRUE;
  42. PWSPOOL pSpool = (PWSPOOL)hPrinter;
  43. VALIDATEW32HANDLE( pSpool );
  44. SPLASSERT( !*pfdwStatus );
  45. if( pSpool->Status & WSPOOL_STATUS_NOTIFY ){
  46. DBGMSG( DBG_WARNING, ( "RemoteFFPCN: Already waiting.\n" ));
  47. SetLastError( ERROR_ALREADY_WAITING );
  48. return FALSE;
  49. }
  50. if( pSpool->Type == SJ_WIN32HANDLE ){
  51. DWORD dwStatus;
  52. SYNCRPCHANDLE( pSpool );
  53. dwStatus = CallRouterFindFirstPrinterChangeNotification(
  54. pSpool->RpcHandle,
  55. fdwFlags,
  56. fdwOptions,
  57. hNotify,
  58. pvReserved0);
  59. switch( dwStatus ){
  60. case RPC_S_SERVER_UNAVAILABLE:
  61. //
  62. // Drop into polling mode. This can happen if the
  63. // server service on the client is disabled.
  64. //
  65. *pfdwStatus = PRINTER_NOTIFY_STATUS_ENDPOINT |
  66. PRINTER_NOTIFY_STATUS_POLL;
  67. pSpool->Status |= WSPOOL_STATUS_NOTIFY_POLL;
  68. DBGMSG( DBG_WARNING, ( "RemoteFFPCN: Dropping into poll mode.\n" ));
  69. break;
  70. case ERROR_SUCCESS:
  71. //
  72. // Using regular notification system; not polling.
  73. //
  74. pSpool->Status &= ~WSPOOL_STATUS_NOTIFY_POLL;
  75. break;
  76. default:
  77. SetLastError(dwStatus);
  78. bReturnValue = FALSE;
  79. break;
  80. }
  81. } else {
  82. bReturnValue = LMFindFirstPrinterChangeNotification(
  83. hPrinter,
  84. fdwFlags,
  85. fdwOptions,
  86. hNotify,
  87. pfdwStatus);
  88. }
  89. if( bReturnValue ){
  90. pSpool->Status |= WSPOOL_STATUS_NOTIFY;
  91. }
  92. return bReturnValue;
  93. }
  94. BOOL
  95. RemoteFindClosePrinterChangeNotification(
  96. HANDLE hPrinter)
  97. {
  98. DWORD ReturnValue;
  99. PWSPOOL pSpool = (PWSPOOL)hPrinter;
  100. VALIDATEW32HANDLE( pSpool );
  101. pSpool->Status &= ~WSPOOL_STATUS_NOTIFY;
  102. if( pSpool->Status & WSPOOL_STATUS_NOTIFY_POLL ){
  103. //
  104. // In the polling case, there's no cleanup.
  105. //
  106. return TRUE;
  107. }
  108. if (pSpool->Type == SJ_WIN32HANDLE) {
  109. SYNCRPCHANDLE( pSpool );
  110. RpcTryExcept {
  111. if (ReturnValue = RpcFindClosePrinterChangeNotification(
  112. pSpool->RpcHandle)) {
  113. SetLastError(ReturnValue);
  114. ReturnValue = FALSE;
  115. } else
  116. ReturnValue = TRUE;
  117. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  118. SetLastError(RpcExceptionCode());
  119. ReturnValue = FALSE;
  120. } RpcEndExcept
  121. } else {
  122. EnterSplSem();
  123. ReturnValue = LMFindClosePrinterChangeNotification(hPrinter);
  124. LeaveSplSem();
  125. }
  126. return ReturnValue;
  127. }
  128. BOOL
  129. RemoteRefreshPrinterChangeNotification(
  130. HANDLE hPrinter,
  131. DWORD dwColor,
  132. PVOID pPrinterNotifyOptions,
  133. PVOID* ppPrinterNotifyInfo)
  134. {
  135. DWORD ReturnValue;
  136. PWSPOOL pSpool = (PWSPOOL)hPrinter;
  137. VALIDATEW32HANDLE( pSpool );
  138. if (ppPrinterNotifyInfo)
  139. *ppPrinterNotifyInfo = NULL;
  140. if (pSpool->Type != SJ_WIN32HANDLE) {
  141. SetLastError(ERROR_INVALID_FUNCTION);
  142. return FALSE;
  143. }
  144. SYNCRPCHANDLE( pSpool );
  145. RpcTryExcept {
  146. if (ReturnValue = RpcRouterRefreshPrinterChangeNotification(
  147. pSpool->RpcHandle,
  148. dwColor,
  149. pPrinterNotifyOptions,
  150. (PRPC_V2_NOTIFY_INFO*)ppPrinterNotifyInfo)) {
  151. SetLastError(ReturnValue);
  152. ReturnValue = FALSE;
  153. } else
  154. ReturnValue = TRUE;
  155. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  156. SetLastError(RpcExceptionCode());
  157. ReturnValue = FALSE;
  158. } RpcEndExcept
  159. return ReturnValue;
  160. }