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.

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