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.

594 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. message.hxx
  5. Abstract:
  6. The MESSAGE class provides a dummy implementation of a message displayer
  7. class. Message displayers are meant to be used by applications to
  8. relay information to the user. Many functions will require a 'MESSAGE'
  9. parameter through which to relay their output.
  10. This particular implementation of this concept will do nothing. It
  11. will be used by users who do not wish to have any output from their
  12. applications.
  13. Additionally, this class serves as a base class to real implementations
  14. of the virtual methods.
  15. --*/
  16. #if !defined(MESSAGE_DEFN)
  17. #define MESSAGE_DEFN
  18. #include "wstring.hxx"
  19. #include "hmem.hxx"
  20. extern "C" {
  21. #include <stdarg.h>
  22. }
  23. enum MESSAGE_TYPE {
  24. NORMAL_MESSAGE,
  25. ERROR_MESSAGE,
  26. PROGRESS_MESSAGE
  27. };
  28. //
  29. // Each message also has a visualization: text or GUI. The default is both
  30. //
  31. #define TEXT_MESSAGE 0x1
  32. #define GUI_MESSAGE 0x2
  33. #define NORMAL_VISUAL (TEXT_MESSAGE | GUI_MESSAGE)
  34. DECLARE_CLASS( MESSAGE );
  35. DECLARE_CLASS( HMEM );
  36. DEFINE_TYPE(ULONG, MSGID);
  37. class MESSAGE : public OBJECT {
  38. public:
  39. ULIB_EXPORT
  40. DECLARE_CONSTRUCTOR(MESSAGE);
  41. VIRTUAL
  42. ULIB_EXPORT
  43. ~MESSAGE(
  44. );
  45. NONVIRTUAL
  46. ULIB_EXPORT
  47. BOOLEAN
  48. Initialize(
  49. );
  50. VIRTUAL
  51. ULIB_EXPORT
  52. BOOLEAN
  53. IsSuppressedMessage(
  54. );
  55. NONVIRTUAL
  56. MSGID &
  57. GetMessageId(
  58. );
  59. NONVIRTUAL
  60. VOID
  61. SetMessageId(
  62. IN MSGID MsgId
  63. );
  64. VIRTUAL
  65. BOOLEAN
  66. Set(
  67. IN MSGID MsgId,
  68. IN MESSAGE_TYPE MessageType DEFAULT NORMAL_MESSAGE,
  69. IN ULONG MessageVisual DEFAULT NORMAL_VISUAL
  70. );
  71. NONVIRTUAL
  72. BOOLEAN
  73. Display(
  74. );
  75. NONVIRTUAL
  76. ULIB_EXPORT
  77. BOOLEAN
  78. Display(
  79. IN PCSTR Format ...
  80. );
  81. NONVIRTUAL
  82. ULIB_EXPORT
  83. BOOLEAN
  84. DisplayMsg(
  85. IN MSGID MsgId,
  86. IN PCSTR Format ...
  87. );
  88. NONVIRTUAL
  89. ULIB_EXPORT
  90. BOOLEAN
  91. DisplayMsg(
  92. IN MSGID MsgId
  93. );
  94. NONVIRTUAL
  95. ULIB_EXPORT
  96. BOOLEAN
  97. DisplayMsg(
  98. IN MSGID MsgId,
  99. IN MESSAGE_TYPE MessageType,
  100. IN ULONG MessageVisual DEFAULT NORMAL_VISUAL
  101. );
  102. NONVIRTUAL
  103. ULIB_EXPORT
  104. BOOLEAN
  105. DisplayMsg(
  106. IN MSGID MsgId,
  107. IN MESSAGE_TYPE MessageType,
  108. IN ULONG MessageVisual,
  109. IN PCSTR Format ...
  110. );
  111. NONVIRTUAL
  112. BOOLEAN
  113. Log(
  114. );
  115. NONVIRTUAL
  116. ULIB_EXPORT
  117. BOOLEAN
  118. Log(
  119. IN PCSTR Format ...
  120. );
  121. NONVIRTUAL
  122. ULIB_EXPORT
  123. BOOLEAN
  124. LogMsg(
  125. IN MSGID MsgId,
  126. IN PCSTR Format ...
  127. );
  128. NONVIRTUAL
  129. ULIB_EXPORT
  130. BOOLEAN
  131. LogMsg(
  132. IN MSGID MsgId
  133. );
  134. NONVIRTUAL
  135. ULIB_EXPORT
  136. BOOLEAN
  137. DumpDataToLog(
  138. IN PVOID Data,
  139. IN ULONG Length
  140. );
  141. VIRTUAL
  142. BOOLEAN
  143. DisplayV(
  144. IN PCSTR Format,
  145. IN va_list VarPointer
  146. );
  147. NONVIRTUAL
  148. BOOLEAN
  149. LogV(
  150. IN PCSTR Format,
  151. IN va_list VarPointer
  152. );
  153. VIRTUAL
  154. ULIB_EXPORT
  155. BOOLEAN
  156. IsYesResponse(
  157. IN BOOLEAN Default DEFAULT TRUE
  158. );
  159. VIRTUAL
  160. ULIB_EXPORT
  161. BOOLEAN
  162. QueryStringInput(
  163. OUT PWSTRING String
  164. );
  165. VIRTUAL
  166. ULIB_EXPORT
  167. BOOLEAN
  168. IsInAutoChk(
  169. );
  170. VIRTUAL
  171. ULIB_EXPORT
  172. BOOLEAN
  173. IsInSetup(
  174. );
  175. VIRTUAL
  176. ULIB_EXPORT
  177. BOOLEAN
  178. IsKeyPressed(
  179. MSGID MsgId,
  180. ULONG TimeOutInSeconds
  181. );
  182. VIRTUAL
  183. ULIB_EXPORT
  184. BOOLEAN
  185. WaitForUserSignal(
  186. );
  187. VIRTUAL
  188. ULIB_EXPORT
  189. MSGID
  190. SelectResponse(
  191. IN ULONG NumberOfSelections ...
  192. );
  193. VIRTUAL
  194. PMESSAGE
  195. Dup(
  196. );
  197. NONVIRTUAL
  198. ULIB_EXPORT
  199. BOOLEAN
  200. IsLoggingEnabled(
  201. );
  202. NONVIRTUAL
  203. ULIB_EXPORT
  204. VOID
  205. SetLoggingEnabled(
  206. IN BOOLEAN Enable DEFAULT TRUE
  207. );
  208. NONVIRTUAL
  209. ULIB_EXPORT
  210. VOID
  211. ResetLoggingIterator(
  212. );
  213. NONVIRTUAL
  214. ULIB_EXPORT
  215. BOOLEAN
  216. QueryNextLoggedMessage(
  217. OUT PFSTRING MessageText
  218. );
  219. NONVIRTUAL
  220. ULIB_EXPORT
  221. BOOLEAN
  222. QueryPackedLog(
  223. IN OUT PHMEM Mem,
  224. OUT PULONG PackedDataLength
  225. );
  226. VIRTUAL
  227. ULIB_EXPORT
  228. BOOLEAN
  229. SetDotsOnly(
  230. IN BOOLEAN DotsState
  231. );
  232. NONVIRTUAL
  233. ULIB_EXPORT
  234. BOOLEAN
  235. LogMessage(
  236. PCWSTRING Message
  237. );
  238. NONVIRTUAL
  239. ULIB_EXPORT
  240. VOID
  241. Lock(
  242. );
  243. NONVIRTUAL
  244. ULIB_EXPORT
  245. VOID
  246. Unlock(
  247. );
  248. private:
  249. NONVIRTUAL
  250. VOID
  251. Construct(
  252. );
  253. NONVIRTUAL
  254. VOID
  255. Destroy(
  256. );
  257. HMEM _log_buffer;
  258. ULONG _logged_chars;
  259. ULONG _next_message_offset;
  260. BOOLEAN _logging_enabled;
  261. MSGID _msgid;
  262. LONG _inuse;
  263. LARGE_INTEGER _timeout;
  264. };
  265. INLINE
  266. BOOLEAN
  267. MESSAGE::Display(
  268. )
  269. /*++
  270. Routine Description:
  271. This routine displays the message with no parameters.
  272. Arguments:
  273. None.
  274. Return Value:
  275. FALSE - Failure.
  276. TRUE - Success.
  277. --*/
  278. {
  279. return Display("");
  280. }
  281. INLINE
  282. BOOLEAN
  283. MESSAGE::DisplayMsg(
  284. IN MSGID MsgId
  285. )
  286. /*++
  287. Routine Description:
  288. This routine displays the message with no parameters.
  289. Arguments:
  290. MsgId - Supplies the resource message id.
  291. Return Value:
  292. FALSE - Failure.
  293. TRUE - Success.
  294. --*/
  295. {
  296. return DisplayMsg(MsgId, "");
  297. }
  298. INLINE
  299. BOOLEAN
  300. MESSAGE::DisplayMsg(
  301. IN MSGID MsgId,
  302. IN MESSAGE_TYPE MessageType,
  303. IN ULONG MessageVisual
  304. )
  305. /*++
  306. Routine Description:
  307. This routine displays the message with no parameters.
  308. Arguments:
  309. MsgId - Supplies the resource message id.
  310. Return Value:
  311. FALSE - Failure.
  312. TRUE - Success.
  313. --*/
  314. {
  315. return DisplayMsg(MsgId, MessageType, MessageVisual, "");
  316. }
  317. INLINE
  318. BOOLEAN
  319. MESSAGE::Log(
  320. )
  321. /*++
  322. Routine Description:
  323. This routine logs the message with no parameters.
  324. Arguments:
  325. None.
  326. Return Value:
  327. FALSE - Failure.
  328. TRUE - Success.
  329. --*/
  330. {
  331. return Log("");
  332. }
  333. INLINE
  334. BOOLEAN
  335. MESSAGE::LogMsg(
  336. IN MSGID MsgId
  337. )
  338. /*++
  339. Routine Description:
  340. This routine logs the message with no parameters.
  341. Arguments:
  342. MsgId - Supplies the resource message id.
  343. Return Value:
  344. FALSE - Failure.
  345. TRUE - Success.
  346. --*/
  347. {
  348. return LogMsg(MsgId, "");
  349. }
  350. INLINE
  351. BOOLEAN
  352. MESSAGE::Set(
  353. IN MSGID MsgId,
  354. IN MESSAGE_TYPE MessageType,
  355. IN ULONG MessageVisual
  356. )
  357. /*++
  358. Routine Description:
  359. This routine sets up the class to display the message with the 'MsgId'
  360. resource identifier.
  361. Arguments:
  362. MsgId - Supplies the resource message id.
  363. Return Value:
  364. FALSE - Failure.
  365. TRUE - Success.
  366. --*/
  367. {
  368. (void) MessageType;
  369. (void) MessageVisual;
  370. _msgid = MsgId;
  371. return TRUE;
  372. }
  373. INLINE
  374. MSGID &
  375. MESSAGE::GetMessageId(
  376. )
  377. /*++
  378. Routine Description:
  379. This routine returns the message id last passed to Set() or SetMessageId().
  380. Arguments:
  381. N/A
  382. Return Value:
  383. MSGID - A reference to the message id
  384. --*/
  385. {
  386. return _msgid;
  387. }
  388. INLINE
  389. VOID
  390. MESSAGE::SetMessageId(
  391. IN MSGID MsgId
  392. )
  393. /*++
  394. Routine Description:
  395. This routine sets the message id to the given one.
  396. Arguments:
  397. MsgId - Supplies the message id
  398. Return Value:
  399. N/A
  400. --*/
  401. {
  402. _msgid = MsgId;
  403. }
  404. INLINE
  405. BOOLEAN
  406. MESSAGE::IsLoggingEnabled(
  407. )
  408. /*++
  409. Routine Description:
  410. This routines returns the logging state of the logging facility.
  411. Arguments:
  412. N/A
  413. Return Value:
  414. TRUE if logging is enabled.
  415. FALSE if logging is disabled.
  416. --*/
  417. {
  418. return _logging_enabled;
  419. }
  420. INLINE
  421. VOID
  422. MESSAGE::SetLoggingEnabled(
  423. IN BOOLEAN Enable
  424. )
  425. /*++
  426. Routine Description:
  427. This routines enables/disable the logging facility.
  428. Arguments:
  429. Enable - TRUE if logging should be enabled.
  430. Return Value:
  431. N/A
  432. --*/
  433. {
  434. _logging_enabled = Enable;
  435. }
  436. INLINE
  437. VOID
  438. MESSAGE::ResetLoggingIterator(
  439. )
  440. {
  441. _next_message_offset = 0;
  442. }
  443. #endif // MESSAGE_DEFN