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.

568 lines
14 KiB

  1. #define __DEBUG_MODULE_IN_USE__ CIC_ACTIONS_CPP
  2. #include "stdhdrs.h"
  3. #include "actions.h"
  4. // @doc
  5. /**********************************************************************
  6. *
  7. * @module Actions.cpp |
  8. *
  9. * Implementation of accessor functions for action objects.
  10. *
  11. * History
  12. * ----------------------------------------------------------
  13. * Mitchell S. Dernis Original
  14. *
  15. * (c) 1986-1998 Microsoft Corporation. All right reserved.
  16. *
  17. * @topic Actions |
  18. * Contains the implementation of the accessor functions for the
  19. * EVENT, TIMED_EVENT, TIMED_MACRO, and related structures.
  20. *
  21. **********************************************************************/
  22. /***********************************************************************************
  23. **
  24. ** @mfunc Get an event in a TIMED_MACRO structure, given an index
  25. **
  26. ** @rdesc Pointer to next event in TIMED_MACRO
  27. ** @rdesc NULL if index too big.
  28. **
  29. *************************************************************************************/
  30. PTIMED_EVENT
  31. TIMED_MACRO::GetEvent
  32. (
  33. ULONG uEventNum //@parm [in] One based index of event to get.
  34. )
  35. {
  36. ASSERT( 0 != uEventNum && "GetEvent uses 1 based index of events!");
  37. //
  38. // Implement in terms of GetNextEvent
  39. //
  40. PTIMED_EVENT pResult = NULL;
  41. ULONG uEventIndex=0;
  42. do
  43. {
  44. pResult = GetNextEvent(pResult, uEventIndex);
  45. }while(pResult && uEventIndex!=uEventNum);
  46. return pResult;
  47. }
  48. /***********************************************************************************
  49. **
  50. ** @mfunc Get next TIMED_EVENT in a TIMED_MACRO structure.
  51. **
  52. ** @rdesc Pointer to next TIMED_EVENT in TIMED_MACRO
  53. **
  54. *************************************************************************************/
  55. PTIMED_EVENT
  56. TIMED_MACRO::GetNextEvent
  57. (
  58. PTIMED_EVENT pCurrentEvent, // @parm [in] Pointer to current event.
  59. ULONG& rulCurrentEvent // @parm [in\out] Current event before and after call.
  60. )
  61. {
  62. //
  63. // Range check, is there even a next event.
  64. //
  65. if( ++rulCurrentEvent > ulEventCount )
  66. {
  67. return NULL;
  68. }
  69. //
  70. // Check if this is the first
  71. //
  72. if(rulCurrentEvent == 1)
  73. {
  74. return rgEvents;
  75. }
  76. //
  77. // Otherwise skip to next
  78. //
  79. PCHAR pcBytePointer = reinterpret_cast<PCHAR>(pCurrentEvent);
  80. pcBytePointer += TIMED_EVENT::RequiredByteSize(pCurrentEvent->Event.ulNumXfers);
  81. //
  82. // Sanity check on debug to make sure we haven't stepped over the edge.
  83. //
  84. ASSERT(pcBytePointer <= (reinterpret_cast<PCHAR>(this)+this->AssignmentBlock.CommandHeader.ulByteSize));
  85. //
  86. // Cast back to proper type
  87. //
  88. return reinterpret_cast<PTIMED_EVENT>(pcBytePointer);
  89. }
  90. /***********************************************************************************
  91. **
  92. ** @mfunc Creates a TIMED_MACRO in an empty buffer.
  93. **
  94. ** @rdesc Pointer to TIMED_MACRO (start of buffer), or NULL if buffer is too small
  95. **
  96. *************************************************************************************/
  97. PTIMED_MACRO TIMED_MACRO::Init
  98. (
  99. ULONG ulVidPid, // @parm [in] Vid/Pid for macro
  100. ULONG ulFlagsParm, // @parm [in] Flags for macro.
  101. PCHAR pcBuffer, // @parm [in] Pointer to raw buffer
  102. ULONG& rulRemainingBuffer // @parm [in\out] Size of buffer on entry, remaining buffer on exit
  103. )
  104. {
  105. //
  106. // Make sure buffer is large enough
  107. //
  108. if( rulRemainingBuffer < sizeof(TIMED_MACRO))
  109. {
  110. return NULL;
  111. }
  112. PTIMED_MACRO pThis = reinterpret_cast<PTIMED_MACRO>(pcBuffer);
  113. //
  114. // Copy flags
  115. //
  116. pThis->ulFlags = ulFlagsParm;
  117. //
  118. // Calculate remaining buffer
  119. //
  120. rulRemainingBuffer -= (sizeof(TIMED_MACRO) - sizeof(TIMED_EVENT));
  121. //
  122. // Fill out AssignmentBlock
  123. //
  124. pThis->AssignmentBlock.CommandHeader.eID = eTimedMacro;
  125. pThis->AssignmentBlock.CommandHeader.ulByteSize = (sizeof(TIMED_MACRO) - sizeof(TIMED_EVENT));
  126. pThis->AssignmentBlock.ulVidPid = ulVidPid;
  127. // Set no events as of yet
  128. pThis->ulEventCount=0;
  129. return pThis;
  130. }
  131. /***********************************************************************************
  132. **
  133. ** HRESULT AddEvent(PTIMED_EVENT pTimedEvent, PTIMED_MACRO pTimedMacro, ULONG& rulRemainingBuffer)
  134. **
  135. ** @mfunc Adds an event to a TIMED_MACRO and recalulates remaining buffer.
  136. **
  137. ** @rdesc S_OK on Success, E_OUTOFMEMORY if buffer is too small
  138. **
  139. *************************************************************************************/
  140. HRESULT TIMED_MACRO::AddEvent
  141. (
  142. PTIMED_EVENT pTimedEvent, // @parm [in] Pointer to TIMED_EVENT to add
  143. ULONG& rulRemainingBuffer // @parm [in\out] Remaining buffer before and after call.
  144. )
  145. {
  146. //
  147. // Make sure buffer is large enough
  148. //
  149. ULONG ulEventLength = TIMED_EVENT::RequiredByteSize(pTimedEvent->Event.ulNumXfers);
  150. if( ulEventLength > rulRemainingBuffer)
  151. {
  152. return E_OUTOFMEMORY;
  153. }
  154. //
  155. // Skip to end of TIMED_MACRO as is.
  156. //
  157. PCHAR pcBuffer = reinterpret_cast<PCHAR>(this) + AssignmentBlock.CommandHeader.ulByteSize;
  158. //
  159. // Copy event
  160. //
  161. DualMode::BufferCopy
  162. (
  163. reinterpret_cast<PVOID>(pcBuffer),
  164. reinterpret_cast<PVOID>(pTimedEvent),
  165. ulEventLength
  166. );
  167. //
  168. // Fix up size in COMMAND_HEADER
  169. //
  170. AssignmentBlock.CommandHeader.ulByteSize += ulEventLength;
  171. //
  172. // Increment number of Events
  173. //
  174. ulEventCount++;
  175. //
  176. // Recalculate remaining buffer
  177. //
  178. rulRemainingBuffer -= ulEventLength;
  179. return S_OK;
  180. }
  181. /************************* MULTI_MACRO Functions **************************/
  182. /***********************************************************************************
  183. **
  184. ** @mfunc Get an event in a MULTI_MACRO structure, given an index
  185. **
  186. ** @rdesc Pointer to next event in MULTI_MACRO
  187. ** @rdesc NULL if index too big.
  188. **
  189. *************************************************************************************/
  190. EVENT*
  191. MULTI_MACRO::GetEvent
  192. (
  193. ULONG uEventNum //@parm [in] One based index of event to get.
  194. )
  195. {
  196. ASSERT( 0 != uEventNum && "GetEvent uses 1 based index of events!");
  197. //
  198. // Implement in terms of GetNextEvent
  199. //
  200. EVENT* pResult = NULL;
  201. ULONG uEventIndex=0;
  202. do
  203. {
  204. pResult = GetNextEvent(pResult, uEventIndex);
  205. }while(pResult && uEventIndex!=uEventNum);
  206. return pResult;
  207. }
  208. /***********************************************************************************
  209. **
  210. ** @mfunc Get next EVENT in a MULTI_MACRO structure.
  211. **
  212. ** @rdesc Pointer to next EVENT in MULTI_MACRO
  213. **
  214. *************************************************************************************/
  215. EVENT*
  216. MULTI_MACRO::GetNextEvent
  217. (
  218. EVENT* pCurrentEvent, // @parm [in] Pointer to current event.
  219. ULONG& rulCurrentEvent // @parm [in\out] Current event before and after call.
  220. )
  221. {
  222. //
  223. // Range check, is there even a next event.
  224. //
  225. if( ++rulCurrentEvent > ulEventCount )
  226. {
  227. return NULL;
  228. }
  229. //
  230. // Check if this is the first
  231. //
  232. if(rulCurrentEvent == 1)
  233. {
  234. return rgEvents;
  235. }
  236. //
  237. // Otherwise skip to next
  238. //
  239. PCHAR pcBytePointer = reinterpret_cast<PCHAR>(pCurrentEvent);
  240. pcBytePointer += EVENT::RequiredByteSize(pCurrentEvent->ulNumXfers);
  241. //
  242. // Sanity check on debug to make sure we haven't stepped over the edge.
  243. //
  244. ASSERT(pcBytePointer <= (reinterpret_cast<PCHAR>(this)+this->AssignmentBlock.CommandHeader.ulByteSize));
  245. //
  246. // Cast back to proper type
  247. //
  248. return reinterpret_cast<EVENT*>(pcBytePointer);
  249. }
  250. /***********************************************************************************
  251. **
  252. ** @mfunc Creates a MULTI_MACRO in an empty buffer.
  253. **
  254. ** @rdesc Pointer to MULTI_MACRO (start of buffer), or NULL if buffer is too small
  255. **
  256. *************************************************************************************/
  257. MULTI_MACRO* MULTI_MACRO::Init
  258. (
  259. ULONG ulVidPid, // @parm [in] Vid/Pid for macro
  260. ULONG ulFlagsParm, // @parm [in] Flags for macro.
  261. PCHAR pcBuffer, // @parm [in] Pointer to raw buffer
  262. ULONG& rulRemainingBuffer // @parm [in\out] Size of buffer on entry, remaining buffer on exit
  263. )
  264. {
  265. //
  266. // Make sure buffer is large enough
  267. //
  268. if( rulRemainingBuffer < sizeof(MULTI_MACRO))
  269. {
  270. return NULL;
  271. }
  272. MULTI_MACRO* pThis = reinterpret_cast<MULTI_MACRO*>(pcBuffer);
  273. //
  274. // Copy flags
  275. //
  276. pThis->ulFlags = ulFlagsParm;
  277. //
  278. // Calculate remaining buffer
  279. //
  280. rulRemainingBuffer -= (sizeof(MULTI_MACRO) - sizeof(EVENT));
  281. //
  282. // Fill out AssignmentBlock
  283. //
  284. pThis->AssignmentBlock.CommandHeader.eID = eTimedMacro;
  285. pThis->AssignmentBlock.CommandHeader.ulByteSize = (sizeof(MULTI_MACRO) - sizeof(EVENT));
  286. pThis->AssignmentBlock.ulVidPid = ulVidPid;
  287. // Set no events as of yet
  288. pThis->ulEventCount=0;
  289. return pThis;
  290. }
  291. /***********************************************************************************
  292. **
  293. ** HRESULT AddEvent(EVENT* pTimedEvent, MULTI_MACRO* pTimedMacro, ULONG& rulRemainingBuffer)
  294. **
  295. ** @mfunc Adds an event to a MULTI_MACRO and recalulates remaining buffer.
  296. **
  297. ** @rdesc S_OK on Success, E_OUTOFMEMORY if buffer is too small
  298. **
  299. *************************************************************************************/
  300. HRESULT MULTI_MACRO::AddEvent
  301. (
  302. EVENT* pEvent, // @parm [in] Pointer to EVENT to add
  303. ULONG& rulRemainingBuffer // @parm [in\out] Remaining buffer before and after call.
  304. )
  305. {
  306. //
  307. // Make sure buffer is large enough
  308. //
  309. ULONG ulEventLength = EVENT::RequiredByteSize(pEvent->ulNumXfers);
  310. if( ulEventLength > rulRemainingBuffer)
  311. {
  312. return E_OUTOFMEMORY;
  313. }
  314. //
  315. // Skip to end of TIMED_MACRO as is.
  316. //
  317. PCHAR pcBuffer = reinterpret_cast<PCHAR>(this) + AssignmentBlock.CommandHeader.ulByteSize;
  318. //
  319. // Copy event
  320. //
  321. DualMode::BufferCopy
  322. (
  323. reinterpret_cast<PVOID>(pcBuffer),
  324. reinterpret_cast<PVOID>(pEvent),
  325. ulEventLength
  326. );
  327. //
  328. // Fix up size in COMMAND_HEADER
  329. //
  330. AssignmentBlock.CommandHeader.ulByteSize += ulEventLength;
  331. //
  332. // Increment number of Events
  333. //
  334. ulEventCount++;
  335. //
  336. // Recalculate remaining buffer
  337. //
  338. rulRemainingBuffer -= ulEventLength;
  339. return S_OK;
  340. }
  341. /************************* MAP_LIST Functions (also CYCLE_MAP, KEYSTRING_MAP) **************************/
  342. /***********************************************************************************
  343. **
  344. ** @mfunc Creates a MAP_LIST in an empty buffer. The assignment block will be set
  345. ** as eKeyString be sure to change it if you have other preferences
  346. **
  347. ** @rdesc Pointer to MAP_LIST (start of buffer), or NULL if buffer is too small
  348. **
  349. *************************************************************************************/
  350. MAP_LIST* MAP_LIST::Init
  351. (
  352. ULONG ulVidPid, // @parm [in] Vid/Pid for macro
  353. ULONG ulFlagsParm, // @parm [in] Flags for macro.
  354. PCHAR pcBuffer, // @parm [in] Pointer to raw buffer
  355. ULONG& rulRemainingBuffer // @parm [in\out] Size of buffer on entry, remaining buffer on exit
  356. )
  357. {
  358. //
  359. // Make sure buffer is large enough
  360. //
  361. if( rulRemainingBuffer < sizeof(MAP_LIST))
  362. {
  363. return NULL;
  364. }
  365. MAP_LIST* pThis = reinterpret_cast<MAP_LIST*>(pcBuffer);
  366. //
  367. // Copy flags
  368. //
  369. pThis->ulFlags = ulFlagsParm;
  370. //
  371. // Calculate remaining buffer
  372. //
  373. rulRemainingBuffer -= (sizeof(MAP_LIST) - sizeof(EVENT));
  374. //
  375. // Fill out AssignmentBlock
  376. //
  377. pThis->AssignmentBlock.CommandHeader.eID = eKeyString;
  378. pThis->AssignmentBlock.CommandHeader.ulByteSize = (sizeof(MAP_LIST) - sizeof(EVENT));
  379. pThis->AssignmentBlock.ulVidPid = ulVidPid;
  380. //Init event count to zero
  381. pThis->ulEventCount=0;
  382. return pThis;
  383. }
  384. /***********************************************************************************
  385. **
  386. ** @mfunc Get next EVENT in a MAP_LIST structure.
  387. **
  388. ** @rdesc Pointer to requested EVENT in MAP_LIST, or NULL if index too big
  389. **
  390. *************************************************************************************/
  391. PEVENT MAP_LIST::GetEvent
  392. (
  393. ULONG uEventNum //@parm [in] One based index of event to get.
  394. )
  395. {
  396. ASSERT( 0 != uEventNum && "GetEvent uses 1 based index of events!");
  397. //
  398. // Implement in terms of GetNextEvent
  399. //
  400. PEVENT pResult = NULL;
  401. ULONG uEventIndex=0;
  402. do
  403. {
  404. pResult = GetNextEvent(pResult, uEventIndex);
  405. }while(pResult && uEventIndex!=uEventNum);
  406. return pResult;
  407. }
  408. /***********************************************************************************
  409. **
  410. ** PEVENT MAP_LIST::GetNextEvent(PEVENT pCurrentEvent, ULONG& rulCurrentEvent)
  411. **
  412. ** @mfunc Gets the next event in a MAP_LIST
  413. **
  414. ** @rdesc Pointer to next EVENT on success, NULL if no more EVENTs
  415. **
  416. *************************************************************************************/
  417. PEVENT MAP_LIST::GetNextEvent
  418. (
  419. PEVENT pCurrentEvent, // @parm Pointer to current EVENT
  420. ULONG& rulCurrentEvent // @parm [in/out] Event number before and after call.
  421. )
  422. {
  423. //
  424. // Range check, is there even a next event.
  425. //
  426. if( ++rulCurrentEvent > ulEventCount )
  427. {
  428. return NULL;
  429. }
  430. //
  431. // Check if this is the first
  432. //
  433. if(rulCurrentEvent == 1)
  434. {
  435. return rgEvents;
  436. }
  437. //
  438. // Otherwise skip to next
  439. //
  440. PCHAR pcBytePointer = reinterpret_cast<PCHAR>(pCurrentEvent);
  441. pcBytePointer += EVENT::RequiredByteSize(pCurrentEvent->ulNumXfers);
  442. //
  443. // Sanity check on debug to make sure we haven't stepped over the edge.
  444. //
  445. ASSERT(pcBytePointer <= (reinterpret_cast<PCHAR>(this)+this->AssignmentBlock.CommandHeader.ulByteSize));
  446. //
  447. // Cast back to proper type
  448. //
  449. return reinterpret_cast<PEVENT>(pcBytePointer);
  450. }
  451. /***********************************************************************************
  452. **
  453. ** HRESULT AddEvent(PTIMED_EVENT pTimedEvent, PTIMED_MACRO pTimedMacro, ULONG& rulRemainingBuffer)
  454. **
  455. ** @mfunc Adds an event to a TIMED_MACRO and recalulates remaining buffer.
  456. **
  457. ** @rdesc S_OK on Success, E_OUTOFMEMORY if buffer is too small
  458. **
  459. *************************************************************************************/
  460. HRESULT MAP_LIST::AddEvent
  461. (
  462. EVENT* pEvent, // @parm [in] Pointer to EVENT to add
  463. ULONG& rulRemainingBuffer // @parm [in\out] Remaining buffer before and after call.
  464. )
  465. {
  466. //
  467. // Make sure buffer is large enough
  468. //
  469. ULONG ulEventLength = EVENT::RequiredByteSize(pEvent->ulNumXfers);
  470. if( ulEventLength > rulRemainingBuffer)
  471. {
  472. return E_OUTOFMEMORY;
  473. }
  474. //
  475. // Skip to end of MAP_LIST as is.
  476. //
  477. PCHAR pcBuffer = reinterpret_cast<PCHAR>(this) + AssignmentBlock.CommandHeader.ulByteSize;
  478. //
  479. // Copy event
  480. //
  481. DualMode::BufferCopy
  482. (
  483. reinterpret_cast<PVOID>(pcBuffer),
  484. reinterpret_cast<PVOID>(pEvent),
  485. ulEventLength
  486. );
  487. //
  488. // Fix up size in COMMAND_HEADER
  489. //
  490. AssignmentBlock.CommandHeader.ulByteSize += ulEventLength;
  491. //
  492. // Increment number of Events
  493. //
  494. ulEventCount++;
  495. //
  496. // Recalculate remaining buffer
  497. //
  498. rulRemainingBuffer -= ulEventLength;
  499. return S_OK;
  500. }