Leaked source code of windows server 2003
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.

552 lines
12 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1998
  3. All rights reserved.
  4. Module Name:
  5. printer.hxx
  6. Abstract:
  7. The printer object handles all information regarding a print
  8. queue (and eventually server object). The printer is not
  9. concerned with UI or listviews; it takes a printer name and
  10. returns via callbacks any changes of the printer state.
  11. The remote server notifies the local printer of changes through
  12. either a single DWORD (downlevel connections), or full change
  13. information (uplevel 3.51+ connections). The TData object
  14. abstracts the changes for us.
  15. Author:
  16. Albert Ting (AlbertT) 10-June-1995
  17. Revision History:
  18. --*/
  19. #ifndef _PRINTER_HXX
  20. #define _PRINTER_HXX
  21. class TPrinter;
  22. /********************************************************************
  23. MPrinterClient
  24. ********************************************************************/
  25. class MPrinterClient : public VInfoClient, public MRefCom {
  26. SIGNATURE( 'prc' )
  27. public:
  28. MPrinterClient(
  29. VOID
  30. ) : _pPrinter( NULL )
  31. { }
  32. VAR( TPrinter*, pPrinter );
  33. /********************************************************************
  34. Retrieve selected items. Used when processing commands against
  35. items or saving and restoring the selection during a refresh.
  36. ********************************************************************/
  37. virtual
  38. COUNT
  39. cSelected(
  40. VOID
  41. ) const;
  42. virtual
  43. HITEM
  44. GetFirstSelItem(
  45. VOID
  46. ) const;
  47. virtual
  48. HITEM
  49. GetNextSelItem(
  50. HITEM hItem
  51. ) const;
  52. virtual
  53. IDENT
  54. GetId(
  55. HITEM hItem
  56. ) const;
  57. //
  58. // kContainerReloadItems: pPrinter has just refreshed and so the
  59. // client must invalidate the old pointers and use re-enumerate
  60. // new items.
  61. //
  62. // kContainerClearItems: pPrinter has just zeroed its list of items,
  63. // so the client must invalidate all old pointers.
  64. //
  65. virtual
  66. VOID
  67. vContainerChanged(
  68. CONTAINER_CHANGE ContainerChange,
  69. INFO Info
  70. ) = 0;
  71. virtual
  72. VOID
  73. vItemChanged(
  74. ITEM_CHANGE ItemChange,
  75. HITEM hItem,
  76. INFO Info,
  77. INFO InfoNew
  78. ) = 0;
  79. /********************************************************************
  80. VInfoClient virtual defaults.
  81. ********************************************************************/
  82. virtual
  83. VOID
  84. vSaveSelections(
  85. VOID
  86. );
  87. virtual
  88. VOID
  89. vRestoreSelections(
  90. VOID
  91. );
  92. virtual
  93. BOOL
  94. bGetPrintLib(
  95. TRefLock<TPrintLib> &refLock
  96. ) const = 0;
  97. };
  98. /********************************************************************
  99. Class definitions.
  100. ********************************************************************/
  101. class TPrinter : public MExecWork, public MDataClient {
  102. SIGNATURE( 'prnt' )
  103. SAFE_NEW
  104. public:
  105. /********************************************************************
  106. Public constants.
  107. ********************************************************************/
  108. enum _CONSTANTS {
  109. kOneSecond = 1000,
  110. kSleepRetry = 30 * kOneSecond, // 30 sec. timeout
  111. };
  112. enum _EXEC {
  113. #ifdef SLEEP_ON_MINIMIZE
  114. kExecSleep = 0x0000001,
  115. kExecAwake = 0x0000002,
  116. #endif
  117. kExecError = 0x0000004, // Error: don't try re-opening.
  118. kExecReopen = 0x0000008,
  119. kExecDelay = 0x0000010, // GetLastError set to error.
  120. kExecClose = 0x0000020,
  121. kExecRequestExit = 0x0000040,
  122. kExecNotifyStart = 0x0000100,
  123. kExecRegister = 0x0000200,
  124. kExecNotifyEnd = 0x0000400,
  125. kExecRefresh = 0x0001000,
  126. kExecRefreshContainer = 0x0002000,
  127. kExecRefreshItem = 0x0004000,
  128. kExecRefreshAll = 0x0007000,
  129. kExecCommand = 0x0010000,
  130. };
  131. enum EJobStatusString {
  132. kMultipleJobStatusString, // Prepend job status string information
  133. kSingleJobStatusString, // Don't prepend job status string information
  134. };
  135. public:
  136. //
  137. // The sub-object that abstracts the type of remote printer from us.
  138. // (May have the polling notifications, single DWORD notifications,
  139. // or full information notifications.)
  140. //
  141. VAR( VData*, pData );
  142. VAR( TRefLock<TPrintLib>, pPrintLib );
  143. //
  144. // Initialized once, then read only; no guarding needed.
  145. // OR called by UI thread.
  146. //
  147. VAR( DWORD, dwAccess );
  148. VAR( EJobStatusString, eJobStatusStringType );
  149. BOOL
  150. bValid(
  151. VOID
  152. ) const
  153. {
  154. return VALID_OBJ( PrinterGuard._strPrinter );
  155. }
  156. /********************************************************************
  157. Don't use the standard ctr and dtr to create and destroy these
  158. objects; instead, use these member functions.
  159. pNew - Returns a new printer object.
  160. vDelete - Request that the printer destroy itself when all
  161. pending commands (pausing printer, jobs, etc.) have completed.
  162. ********************************************************************/
  163. static
  164. TPrinter*
  165. pNew(
  166. MPrinterClient* pPrinterClient,
  167. LPCTSTR pszPrinter,
  168. DWORD dwAccess
  169. );
  170. VOID
  171. vDelete(
  172. VOID
  173. );
  174. const TString&
  175. strPrinter(
  176. VOID
  177. ) const
  178. {
  179. return PrinterGuard._strPrinter;
  180. }
  181. BOOL
  182. bSyncRefresh(
  183. VOID
  184. );
  185. /********************************************************************
  186. UI interface routines: the UI client calls through these
  187. functions for services.
  188. vCommandQueue - Allocate a command object and put it into the
  189. command queue (commands execute serially in a separate
  190. thread).
  191. vCommandRequested - Call when a new command has been added that
  192. requires a sleeping printer to re-awake. This allows a
  193. refresh to take place even if the printer is sleeping in
  194. poll mode.
  195. vProcessData - Call when synchronous data must be processed.
  196. ********************************************************************/
  197. VOID
  198. vCommandQueue(
  199. TSelection* pSelection
  200. );
  201. VOID
  202. vCommandRequested(
  203. VOID
  204. );
  205. VOID
  206. vProcessData(
  207. DWORD dwParam,
  208. HBLOCK hBlock
  209. );
  210. LPTSTR
  211. pszPrinterName(
  212. size_t cchBuffer,
  213. LPTSTR pszPrinterBuffer
  214. ) const;
  215. LPTSTR
  216. pszServerName(
  217. size_t cchBuffer,
  218. LPTSTR pszServerBuffer
  219. ) const;
  220. /********************************************************************
  221. Generic exported services.
  222. ********************************************************************/
  223. static
  224. STATUS
  225. sOpenPrinter(
  226. LPCTSTR pszPrinter,
  227. PDWORD pdwAccess,
  228. PHANDLE phPrinter
  229. );
  230. private:
  231. class TPrinterClientRef {
  232. public:
  233. TPrinterClientRef(
  234. const TPrinter* pPrinter
  235. );
  236. ~TPrinterClientRef(
  237. VOID
  238. );
  239. BOOL
  240. bValid(
  241. VOID
  242. ) const
  243. {
  244. return _pPrinterClient != NULL;
  245. }
  246. MPrinterClient*
  247. ptr(
  248. VOID
  249. )
  250. {
  251. return _pPrinterClient;
  252. }
  253. private:
  254. MPrinterClient* _pPrinterClient;
  255. };
  256. //
  257. // Guarded by TExec: one thread processing TPrinter at a time,
  258. // and/or guarded by state machine.
  259. //
  260. struct _EXEC_GUARD {
  261. VAR( HANDLE, hPrinter );
  262. } ExecGuard;
  263. //
  264. // All field in this structure guarded by gpCritSec.
  265. //
  266. struct PRINTER_GUARD {
  267. //
  268. // Written by Exec threads only; guarding not needed from
  269. // reading from ExecGuard places.
  270. //
  271. VAR( TString, strPrinter );
  272. VAR( TString, strServer );
  273. VAR( HANDLE, hEventCommand );
  274. VAR( DWORD, dwError );
  275. //
  276. // Only changed in UIThread.
  277. //
  278. VAR( MPrinterClient*, pPrinterClient );
  279. //
  280. // Linked list of commands to execute.
  281. //
  282. DLINK_BASE( TSelection, Selection, Selection );
  283. } PrinterGuard;
  284. /********************************************************************
  285. Ctr, dtr declared private so that clients are forced to use
  286. pNew, vDelete.
  287. ********************************************************************/
  288. TPrinter(
  289. MPrinterClient* pPrinterClient,
  290. LPCTSTR pszPrinter,
  291. DWORD dwAccess
  292. );
  293. ~TPrinter(
  294. VOID
  295. );
  296. /********************************************************************
  297. Status reporting.
  298. ********************************************************************/
  299. VOID
  300. vErrorStatusChanged(
  301. DWORD dwStatus
  302. );
  303. VOID
  304. vConnectStatusChanged(
  305. CONNECT_STATUS ConnectStatus
  306. );
  307. /********************************************************************
  308. Define virtual funcs for MExecWork:
  309. svExecute - A job is ready to execute and should run now in the
  310. current thread.
  311. vExecFailedAddJob - This printer object tried to add a job,
  312. but the add failed and we need to put up a suitable
  313. error message.
  314. vExecExitComplete - We requested an EXIT job and we are finally
  315. processing it now (the exit will wait until the currently
  316. pending job has completed). This routine will delete
  317. the object.
  318. ********************************************************************/
  319. STATEVAR
  320. svExecute(
  321. STATEVAR StateVar
  322. );
  323. VOID
  324. vExecFailedAddJob(
  325. VOID
  326. );
  327. VOID
  328. vExecExitComplete(
  329. VOID
  330. );
  331. /********************************************************************
  332. Called by worker threads only; these operations may hit
  333. the network and therefore take a long time to complete.
  334. ********************************************************************/
  335. #ifdef SLEEP_ON_MINIMIZE
  336. STATEVAR
  337. svAwake(
  338. STATEVAR StateVar
  339. );
  340. #endif
  341. STATEVAR
  342. svSleep(
  343. STATEVAR StateVar
  344. );
  345. STATEVAR
  346. svRefresh(
  347. STATEVAR StateVar
  348. );
  349. STATEVAR
  350. svReopen(
  351. STATEVAR StateVar
  352. );
  353. STATEVAR
  354. svDelay(
  355. STATEVAR StateVar
  356. );
  357. STATEVAR
  358. svClose(
  359. STATEVAR StateVar
  360. );
  361. STATEVAR
  362. svRequestExit(
  363. STATEVAR StateVar
  364. );
  365. STATEVAR
  366. svNotifyStart(
  367. STATEVAR StateVar
  368. );
  369. STATEVAR
  370. svNotifyEnd(
  371. STATEVAR StateVar
  372. );
  373. STATEVAR
  374. svCommand(
  375. STATEVAR StateVar
  376. );
  377. /********************************************************************
  378. MDataClient virtual definitions.
  379. ********************************************************************/
  380. VOID
  381. vContainerChanged(
  382. CONTAINER_CHANGE ContainerChange,
  383. INFO Info
  384. );
  385. VOID
  386. vItemChanged(
  387. ITEM_CHANGE ItemChange,
  388. HITEM hItem,
  389. INFO Info,
  390. INFO InfoNew
  391. );
  392. VOID
  393. vSaveSelections(
  394. VOID
  395. );
  396. VOID
  397. vRestoreSelections(
  398. VOID
  399. );
  400. BOOL
  401. bGetPrintLib(
  402. TRefLock<TPrintLib> &refLock
  403. ) const;
  404. VDataNotify*
  405. pNewNotify(
  406. MDataClient* pDataClient
  407. ) const;
  408. VDataRefresh*
  409. pNewRefresh(
  410. MDataClient* pDataClient
  411. ) const;
  412. HANDLE
  413. hPrinter(
  414. VOID
  415. ) const;
  416. HANDLE
  417. hPrinterNew(
  418. VOID
  419. ) const;
  420. friend TPrinterClientRef;
  421. };
  422. #endif // ifndef _PRINTER_HXX