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.

1031 lines
24 KiB

  1. //
  2. // Utilities
  3. //
  4. #ifndef _H_UT
  5. #define _H_UT
  6. //
  7. // Data types stored in the profile information.
  8. //
  9. #define COM_PROFTYPE_STRING 1L
  10. #define COM_PROFTYPE_INT 2L
  11. #define COM_PROFTYPE_BOOL 3L
  12. #define COM_PROFTYPE_UNKNOWN 4L
  13. #define COM_MAX_SUBKEY 256
  14. #define COM_MAX_BOOL_STRING 5
  15. //
  16. //
  17. // TYPEDEFS
  18. //
  19. //
  20. //
  21. // Priorities for UT_RegisterEventProc()
  22. //
  23. // Event procedures are registered with a priority that affects the order
  24. // that the event procedures are called in.
  25. //
  26. // All event procedures of a given priority are called before event
  27. // procedures of a numerically lower priority.
  28. //
  29. // The priority can be any number between 0 and UT_MAX_PRIORITY
  30. //
  31. // The following values have been defined for specific uses:
  32. // UT_PRIORITY_OBMAN : Used by OBMAN so its client event procedures
  33. // are called before those of the client
  34. // UT_PRIORITY_APPSHARE : Used by the DCShare Core to ensure it sees
  35. // events before 'Normal' event procs.
  36. // UT_PRIORITY_NORMAL : For all cases where the order of callling is
  37. // not important.
  38. // UT_PRIORITY_NETWORK : Used by the Network Layer to free any
  39. // unprocessed network buffers.
  40. // UT_PRIORITY_LAST : Used by the Utility Services to get the
  41. // default event procedure called last
  42. //
  43. //
  44. typedef enum
  45. {
  46. UT_PRIORITY_LAST = 0,
  47. UT_PRIORITY_NETWORK,
  48. UT_PRIORITY_NORMAL,
  49. UT_PRIORITY_APPSHARING,
  50. UT_PRIORITY_OBMAN,
  51. UT_PRIORITY_MAX
  52. } UT_PRIORITY;
  53. typedef UT_PRIORITY * PUT_PRIORITY;
  54. //
  55. // SYSTEM LIMITS
  56. //
  57. //
  58. // Maximum number of event handlers for each task
  59. //
  60. #define UTEVENT_HANDLERS_MAX 4
  61. //
  62. // Maximum number of exit procedures
  63. //
  64. #define UTEXIT_PROCS_MAX 4
  65. //
  66. // The groupware critsects, identified by constant
  67. //
  68. #define UTLOCK_FIRST 0
  69. typedef enum
  70. {
  71. UTLOCK_UT = UTLOCK_FIRST,
  72. UTLOCK_OM, // obman
  73. UTLOCK_AL, // app loader
  74. UTLOCK_T120, // gcc/mcs
  75. UTLOCK_AS, // app sharing
  76. UTLOCK_MAX
  77. }
  78. UTLOCK;
  79. // Event message
  80. #define WM_UTTRIGGER_MSG (WM_APP)
  81. //
  82. // BASEDLIST
  83. //
  84. // This is a list structure with based offsets
  85. //
  86. // next : the next item in the list
  87. // prev : the previous item in the list
  88. //
  89. //
  90. typedef struct tagBASEDLIST
  91. {
  92. DWORD next;
  93. DWORD prev;
  94. }
  95. BASEDLIST;
  96. typedef BASEDLIST FAR * PBASEDLIST;
  97. typedef struct
  98. {
  99. BASEDLIST chain;
  100. void FAR *pData;
  101. }
  102. SIMPLE_LIST, FAR * PSIMPLE_LIST;
  103. //
  104. //
  105. // MACROS
  106. //
  107. //
  108. //
  109. // List handling
  110. // =============
  111. // The common functions support the concept of a doubly linked list of
  112. // objects. Objects can be inserted and removed from specified locations
  113. // in the list.
  114. //
  115. // At start of day the calling application must call COM_BasedListInit with a
  116. // pointer to a private piece of memory for a BASEDLIST structure. The list
  117. // handling will initialise this structure. The application must not
  118. // release this memory while the list is active. (Nor must it release any
  119. // object while it is in a list!)
  120. //
  121. // The list functions can only manage a single list, however the app
  122. // can load objects with multiple lists. Each call to the common list
  123. // functions takes a BASEDLIST pointer as the object handle and if the
  124. // application defines multiple BASEDLIST structures within an object then it
  125. // may manage them through the list functions.
  126. //
  127. //
  128. // List chaining
  129. // =============
  130. // For normal list chaining, we have something like
  131. //
  132. // while (pointer != NULL)
  133. // {
  134. // do something;
  135. // pointer = pointer->next;
  136. // }
  137. //
  138. // When using lists whose elements contain offsets (in this case, relative
  139. // offsets) to the next element, we have to cast to a 32-bit integer before
  140. // we can add the offset. This macro encapsulates this, and the example
  141. // above would be modified as follows to use it:
  142. //
  143. // while (pointer != NULL)
  144. // {
  145. // do something;
  146. // pointer = (TYPE) COM_BasedNextListField(pointer);
  147. // }
  148. //
  149. // Note also that the value returned by the macro is a pointer to a generic
  150. // list object i.e. a PBASEDLIST, and so must be cast back to the
  151. // appropriate type.
  152. //
  153. //
  154. //
  155. // List traversing macros
  156. // ======================
  157. // These macros make use of DC_NEXT and DC_PREV, but also take the type of
  158. // list being traversed in order to return the start pointer of the chained
  159. // structure.
  160. //
  161. // The LIST_FIND macro supports the searching of a list, matching a key
  162. // value to a selected structure element.
  163. //
  164. // The parameters to the macros are as follows:
  165. //
  166. // pHead (type: PBASEDLIST)
  167. // -----
  168. // a pointer the root of the list
  169. //
  170. // pEntry (type: STRUCT FAR * FAR *)
  171. // ------
  172. // a pointer to pointer to structure to chain from
  173. //
  174. // STRUCT (a type name)
  175. // ------
  176. // the type of **pEntry
  177. //
  178. // chain (a field name)
  179. // -----
  180. // the text name of the field in STRUCT which is the link along which
  181. // you wish to traverse
  182. //
  183. // field (a field name)
  184. // -----
  185. // when FINDing, the text name of the field in STRUCT against which
  186. // you wish to match
  187. //
  188. // key (a value, of the same type as STRUCT.field)
  189. // ---
  190. // when FINDing, the value to match against STRUCT.field against
  191. //
  192. //
  193. //
  194. // Offset arithmetic
  195. // =================
  196. // Using offsets within memory blocks, rather than pointers, to refer to
  197. // objects in shared memory (as necessitated by the DC-Groupware shared
  198. // memory architecture) presents certain difficulties. Pointer arithmetic
  199. // in C assumes that addition/subtraction operations involve objects of the
  200. // same type and the offsets are presented as number of units of that
  201. // particular type, rather than number of bytes.
  202. //
  203. // Therefore, pointers must be cast to integers before performing
  204. // arithmetic on them (note that casting the pointers to byte pointers is
  205. // not enough since on segmented architectures C performs bounds checking
  206. // when doing pointer arithmetic which we don't want).
  207. //
  208. // Since this would make for cumbersome code if repeated everywhere, we
  209. // define some useful macros to convert
  210. //
  211. // - an (offset, base) pair to a pointer (OFFSETBASE_TO_PTR)
  212. //
  213. // - a (pointer, base) pair to an offset (PTRBASE_TO_OFFSET)
  214. //
  215. // - a NULL pointer value to an offset(NULLBASE_TO_OFFSET)
  216. //
  217. // The offset calculated is the offset of the first parameter from the
  218. // second. As described above, the pointers passed in must be cast to
  219. // 32-bit unsigned integers first, subtracted to get the offset, and then
  220. // cast to 32-bit signed.
  221. //
  222. // The NULLBASE_TO_OFFSET value gives an offset that after translation back
  223. // to a pointer gives a NULL. This is NOT the same as a NULL offset, since
  224. // this translates back to the base pointer (which is a perfectly valid
  225. // address).
  226. //
  227. //
  228. #define PTRBASE_TO_OFFSET(pObject, pBase) \
  229. (LONG)(((DWORD_PTR)(pObject)) - ((DWORD_PTR)(pBase)))
  230. #define OFFSETBASE_TO_PTR(offset, pBase) \
  231. ((void FAR *) ((DWORD_PTR)(pBase) + (LONG)(offset)))
  232. #define NULLBASE_TO_OFFSET(pBase) \
  233. ((DWORD_PTR) (0L - (LONG_PTR)(pBase)))
  234. __inline BOOL COM_BasedListIsEmpty ( PBASEDLIST pHead )
  235. {
  236. ASSERT((pHead->next == 0 && pHead->prev == 0) ||
  237. (pHead->next != 0 && pHead->prev != 0));
  238. return (pHead->next == 0);
  239. }
  240. __inline void FAR * COM_BasedFieldToStruct ( PBASEDLIST pField, UINT nOffset )
  241. {
  242. return (void FAR *) ((DWORD_PTR)pField - nOffset);
  243. }
  244. __inline PBASEDLIST COM_BasedStructToField ( void FAR * pStruct, UINT nOffset )
  245. {
  246. return (PBASEDLIST) ((DWORD_PTR) pStruct + nOffset);
  247. }
  248. __inline PBASEDLIST COM_BasedNextListField ( PBASEDLIST p )
  249. {
  250. return (PBASEDLIST) OFFSETBASE_TO_PTR(p->next, p);
  251. }
  252. __inline PBASEDLIST COM_BasedPrevListField ( PBASEDLIST p )
  253. {
  254. return (PBASEDLIST) OFFSETBASE_TO_PTR(p->prev, p);
  255. }
  256. void FAR * COM_BasedListNext ( PBASEDLIST pHead, void FAR * pEntry, UINT nOffset );
  257. void FAR * COM_BasedListPrev ( PBASEDLIST pHead, void FAR * pEntry, UINT nOffset );
  258. void FAR * COM_BasedListFirst ( PBASEDLIST pHead, UINT nOffset );
  259. void FAR * COM_BasedListLast ( PBASEDLIST pHead, UINT nOffset );
  260. typedef enum
  261. {
  262. LIST_FIND_FROM_FIRST,
  263. LIST_FIND_FROM_NEXT
  264. }
  265. LIST_FIND_TYPE;
  266. void COM_BasedListFind ( LIST_FIND_TYPE eType,
  267. PBASEDLIST pHead,
  268. void FAR * FAR* ppEntry,
  269. UINT nOffset,
  270. int nOffsetKey,
  271. DWORD_PTR Key,
  272. int cbKeySize );
  273. PSIMPLE_LIST COM_SimpleListAppend ( PBASEDLIST pHead, void FAR * pData );
  274. void FAR * COM_SimpleListRemoveHead ( PBASEDLIST pHead );
  275. //
  276. //
  277. // FUNCTION PROTOTYPES
  278. //
  279. //
  280. //
  281. // API FUNCTION: COM_Rect16sIntersect(...)
  282. //
  283. // DESCRIPTION:
  284. // ============
  285. // Checks whether two TSHR_RECT16s rectangles intersect. Rectangles are
  286. // defined to be inclusive of all edges.
  287. //
  288. // PARAMETERS:
  289. // ===========
  290. // pRect1 : pointer to a TSHR_RECT16 rectangle.
  291. // pRect2 : pointer to a TSHR_RECT16 rectangle.
  292. //
  293. // RETURNS:
  294. // ========
  295. // TRUE - if the rectangles intersect
  296. // FALSE - otherwise.
  297. //
  298. //
  299. __inline BOOL COM_Rect16sIntersect(LPTSHR_RECT16 pRect1, LPTSHR_RECT16 pRect2)
  300. {
  301. if ((pRect1->left > pRect2->right) ||
  302. (pRect1->right < pRect2->left) ||
  303. (pRect1->top > pRect2->bottom) ||
  304. (pRect1->bottom < pRect2->top))
  305. {
  306. return(FALSE);
  307. }
  308. else
  309. {
  310. return(TRUE);
  311. }
  312. }
  313. //
  314. // API FUNCTION: COM_BasedListInit(...)
  315. //
  316. // DESCRIPTION:
  317. // ============
  318. // Initialise a list root.
  319. //
  320. // PARAMETERS:
  321. // ===========
  322. // pListRoot : pointer to the list root.
  323. //
  324. // RETURNS:
  325. // ========
  326. // Nothing.
  327. //
  328. //
  329. __inline void COM_BasedListInit(PBASEDLIST pListRoot)
  330. {
  331. //
  332. // The <next> and <prev> items in a list are the offsets, from the list
  333. // item, of the next and previous list items.
  334. //
  335. // In an empty list, the next item after the root is the root itself,
  336. // so the <next> offset is zero. Likewise for <prev>.
  337. //
  338. pListRoot->next = 0;
  339. pListRoot->prev = 0;
  340. }
  341. //
  342. // API FUNCTION: COM_BasedListInsertBefore(...)
  343. // Inserts an item into a list. To insert an item at the start of a list,
  344. // specify the list root as the <pListLink> parameter.
  345. //
  346. void COM_BasedListInsertBefore(PBASEDLIST pListLink, PBASEDLIST pNewLink);
  347. //
  348. // API FUNCTION: COM_BasedListInsertAfter(...)
  349. // Inserts an item into a list. To insert an item at the start of a list,
  350. // specify the list root as the <pListLink> parameter.
  351. //
  352. //
  353. void COM_BasedListInsertAfter(PBASEDLIST pListLink, PBASEDLIST pNewLink);
  354. //
  355. // API FUNCTION: COM_BasedListRemove(...)
  356. //
  357. // DESCRIPTION:
  358. // ============
  359. // This function removes an item from a list. The item to be removed is
  360. // specified by a pointer to the BASEDLIST structure within the item.
  361. //
  362. // PARAMETERS:
  363. // ===========
  364. // pListLink : pointer to link of the item to be removed.
  365. //
  366. // RETURNS:
  367. // ========
  368. // Nothing.
  369. //
  370. //
  371. void COM_BasedListRemove(PBASEDLIST pListLink);
  372. //
  373. // API FUNCTION: COM_ReadProfInt(...)
  374. //
  375. // DESCRIPTION:
  376. // ============
  377. // This reads a private profile integer from the registry.
  378. //
  379. // PARAMETERS:
  380. // ===========
  381. // pSection : section containing the entry to read.
  382. // pEntry : entry name of integer to retrieve.
  383. // defaultValue : default value to return
  384. // pValue : buffer to return the entry in.
  385. //
  386. // RETURNS:
  387. // ========
  388. // Nothing.
  389. //
  390. //
  391. void COM_ReadProfInt(LPSTR pSection, LPSTR pEntry, int defValue, int * pValue);
  392. //
  393. // API FUNCTION: COM_GetSiteName(...)
  394. //
  395. // DESCRIPTION:
  396. // ============
  397. // Reads the site name out of the system registry.
  398. //
  399. // PARAMETERS:
  400. // ===========
  401. // siteName : pointer to string to fill in with the site name.
  402. // siteNameLen : length of this string.
  403. //
  404. // RETURNS:
  405. // ========
  406. // None
  407. //
  408. //
  409. void COM_GetSiteName(LPSTR siteName, UINT siteNameLen);
  410. #ifndef DLL_DISP
  411. //
  412. // API FUNCTION: DCS_StartThread(...)
  413. //
  414. // DESCRIPTION:
  415. // ============
  416. // Start a new thread of execution
  417. //
  418. // PARAMETERS:
  419. // ===========
  420. // entryFunction : A pointer to the thread entry point.
  421. //
  422. //
  423. BOOL DCS_StartThread(LPTHREAD_START_ROUTINE entryFunction);
  424. #endif // DLL_DISP
  425. #ifndef DLL_DISP
  426. BOOL COMReadEntry(HKEY topLevelKey,
  427. LPSTR pSection,
  428. LPSTR pEntry,
  429. LPSTR pBuffer,
  430. int bufferSize,
  431. ULONG expectedDataType);
  432. #endif // DLL_DISP
  433. #define MAKE_SUBALLOC_PTR(pPool, chunkOffset) OFFSETBASE_TO_PTR(chunkOffset, pPool)
  434. #define MAKE_SUBALLOC_OFFSET(pPool, pChunk) PTRBASE_TO_OFFSET(pChunk, pPool)
  435. //
  436. //
  437. // Return codes - all offset from UT_BASE_RC
  438. //
  439. //
  440. enum
  441. {
  442. UT_RC_OK = UT_BASE_RC,
  443. UT_RC_NO_MEM
  444. };
  445. //
  446. // The maximum number of UT events which we try to process without yielding
  447. //
  448. #define MAX_EVENTS_TO_PROCESS 10
  449. //
  450. //
  451. // Types
  452. //
  453. //
  454. //
  455. // Utility Functions Interface handle
  456. //
  457. typedef struct tagUT_CLIENT * PUT_CLIENT;
  458. #define UTTASK_FIRST 0
  459. typedef enum
  460. {
  461. UTTASK_UI = UTTASK_FIRST,
  462. UTTASK_CMG,
  463. UTTASK_OM,
  464. UTTASK_AL,
  465. UTTASK_DCS,
  466. UTTASK_WB,
  467. UTTASK_MAX
  468. }
  469. UT_TASK;
  470. //
  471. // Event procedure registered by UT_RegisterEvent().
  472. //
  473. // Takes event handler registered data, event number and 2 parameters
  474. // Returns TRUE if event processed
  475. // Returns FALSE if not and event should be passed on to next handler
  476. //
  477. //
  478. typedef BOOL (CALLBACK * UTEVENT_PROC)(LPVOID, UINT, UINT_PTR, UINT_PTR);
  479. //
  480. // Exit procedure
  481. //
  482. typedef void (CALLBACK * UTEXIT_PROC)( LPVOID exitData );
  483. //
  484. // The name of the class used to create UT windows
  485. //
  486. #define UT_WINDOW_CLASS "DCUTWindowClass"
  487. //
  488. // The ID of the timer to use for trigger events.
  489. //
  490. #define UT_DELAYED_TIMER_ID 0x10101010
  491. //
  492. //
  493. // Prototypes
  494. //
  495. //
  496. //
  497. //
  498. // Task routines
  499. //
  500. // UT_WndProc() Subclassing window procedure
  501. // UT_InitTask() Initialise a task
  502. // UT_TermTask() Terminate a task
  503. // UT_RegisterEvent() Register an event handler
  504. // UT_DeregisterEvent() Deregisters an event handler
  505. // UT_RegisterExit() Register an exit routine
  506. // UT_DeregisterExit() Deregister an exit routine
  507. // UT_PostEvent() Send an event to a task
  508. //
  509. //
  510. LRESULT CALLBACK UT_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  511. BOOL UT_InitTask(UT_TASK task, PUT_CLIENT * pputTask);
  512. //
  513. //
  514. // Overview:
  515. // This registers a task and assigns it a handle.
  516. // All other Utility Functions require this handle to be passed to them.
  517. //
  518. // If a task has already been registered with the same process ID, the
  519. // utilities handle that has already been allocated is returned.
  520. // This is to allows the Utility Functions to be used in the context of
  521. // tasks that DC-SHARE has intercepted the graphics calls for.
  522. //
  523. // Each task is identified by a name.
  524. //
  525. // Parameters:
  526. //
  527. // task
  528. // Unique it for identifying task
  529. //
  530. // pUtHandle (returned)
  531. // Utility Services handle to be used for all calls to the Utility
  532. // Services by this task
  533. //
  534. //
  535. void UT_TermTask(PUT_CLIENT * pputTask);
  536. //
  537. //
  538. // Overview:
  539. // This de-registers a task
  540. // All task resources are freed and the utHandle is released
  541. //
  542. // Parameters:
  543. //
  544. // utHandle
  545. // Utility Functions Handle
  546. //
  547. void UT_RegisterEvent(PUT_CLIENT putTask,
  548. UTEVENT_PROC eventProc,
  549. LPVOID eventData,
  550. UT_PRIORITY priority);
  551. void UT_DeregisterEvent(PUT_CLIENT putTask,
  552. UTEVENT_PROC eventProc,
  553. LPVOID eventData);
  554. void UT_PostEvent(PUT_CLIENT putTaskFrom,
  555. PUT_CLIENT putTaskTo,
  556. UINT delay,
  557. UINT eventNo,
  558. UINT_PTR param1,
  559. UINT_PTR param2);
  560. #define NO_DELAY 0
  561. //
  562. //
  563. // Overview:
  564. // This posts an event to another task.
  565. //
  566. // Parameters:
  567. //
  568. // utHandle
  569. // Utility Functions handle of invoking task
  570. //
  571. // toHandle
  572. // Utility Functions TASK handle of task to post event to
  573. //
  574. // delay
  575. // Delay (in milliseconds) before event is posted
  576. //
  577. // eventNo
  578. // event to be posted (see autevt.h for details of events)
  579. //
  580. // param1
  581. // parameter 1 for event (meaning depends on event)
  582. //
  583. // param2
  584. // parameter 2 for event (meaning depends on event)
  585. //
  586. //
  587. // NOTES:
  588. //
  589. // 1) The delay time is in milliseconds. This may not be supported by
  590. // underlying OS but the setting and checking of the pop time value
  591. // is OS specific.
  592. //
  593. // 2) The posting of events is asynchronous, the delay is simply
  594. // the time before the event is posted. The task the event is
  595. // posted to will receive the event NOT BEFRE this time is up.
  596. //
  597. // 3) If an event is posted with a delay specified, the sending task
  598. // must continue to process messages for the event to be posted
  599. //
  600. void UT_RegisterExit(PUT_CLIENT putTask, UTEXIT_PROC exitProc, LPVOID exitData);
  601. void UT_DeregisterExit(PUT_CLIENT putTask, UTEXIT_PROC exitProc, LPVOID exitData);
  602. //
  603. // Memory routines
  604. // UT_MallocRefCount
  605. // UT_BumpUpRefCount
  606. // UT_FreeRefCount
  607. //
  608. void * UT_MallocRefCount(UINT cbSizeMem, BOOL fZeroMem);
  609. void UT_BumpUpRefCount(void * pMemory);
  610. void UT_FreeRefCount(void ** ppMemory, BOOL fNullOnlyWhenFreed);
  611. // Ref count allocs
  612. typedef struct tagUTREFCOUNTHEADER
  613. {
  614. STRUCTURE_STAMP
  615. UINT refCount;
  616. }
  617. UTREFCOUNTHEADER;
  618. typedef UTREFCOUNTHEADER * PUTREFCOUNTHEADER;
  619. //
  620. // UT_MoveMemory()
  621. // Replacement for CRT memmove(); handles overlapping
  622. //
  623. void * UT_MoveMemory(void * dst, const void * src, size_t count);
  624. //
  625. // Locks
  626. // - UT_Lock() - Locks a lock
  627. // - UT_Unlock() - Unlocks a lock
  628. //
  629. #ifndef DLL_DISP
  630. extern CRITICAL_SECTION g_utLocks[UTLOCK_MAX];
  631. __inline void UT_Lock(UTLOCK lock)
  632. {
  633. ASSERT(lock >= UTLOCK_FIRST);
  634. ASSERT(lock < UTLOCK_MAX);
  635. EnterCriticalSection(&g_utLocks[lock]);
  636. }
  637. __inline void UT_Unlock(UTLOCK lock)
  638. {
  639. ASSERT(lock >= UTLOCK_FIRST);
  640. ASSERT(lock < UTLOCK_MAX);
  641. LeaveCriticalSection(&g_utLocks[lock]);
  642. }
  643. #endif // DLL_DISP
  644. //
  645. // Tasks
  646. // UT_HandleProcessStart()
  647. // UT_HandleProcessEnd()
  648. // UT_HandleThreadEnd()
  649. //
  650. BOOL UT_HandleProcessStart(HINSTANCE hInstance);
  651. void UT_HandleProcessEnd(void);
  652. void UT_HandleThreadEnd(void);
  653. //
  654. // Structure for holding an event. The first two fields allow the event to
  655. // be held on the delayed event Q to be scheduled later.
  656. //
  657. typedef struct tagUTEVENT_INFO
  658. {
  659. STRUCTURE_STAMP
  660. BASEDLIST chain;
  661. // Params
  662. UINT event;
  663. UINT_PTR param1;
  664. UINT_PTR param2;
  665. PUT_CLIENT putTo;
  666. UINT popTime;
  667. }
  668. UTEVENT_INFO;
  669. typedef UTEVENT_INFO * PUTEVENT_INFO;
  670. #ifndef DLL_DISP
  671. void __inline ValidateEventInfo(PUTEVENT_INFO pEventInfo)
  672. {
  673. ASSERT(!IsBadWritePtr(pEventInfo, sizeof(UTEVENT_INFO)));
  674. }
  675. #endif // DLL_DISP
  676. //
  677. // Information held about each exit procedure
  678. //
  679. typedef struct tagUTEXIT_PROC_INFO
  680. {
  681. UTEXIT_PROC exitProc;
  682. LPVOID exitData;
  683. } UTEXIT_PROC_INFO;
  684. typedef UTEXIT_PROC_INFO * PUTEXIT_PROC_INFO;
  685. //
  686. // Information held about each event procedure
  687. //
  688. typedef struct tagUTEVENT_PROC_INFO
  689. {
  690. UTEVENT_PROC eventProc;
  691. LPVOID eventData;
  692. UT_PRIORITY priority;
  693. }
  694. UTEVENT_PROC_INFO;
  695. typedef UTEVENT_PROC_INFO * PUTEVENT_PROC_INFO;
  696. //
  697. //
  698. // UT_CLIENT
  699. //
  700. // Information stored about each Utilities registered task. A pointer to
  701. // this structure is returned as the UT Handle from UT_InitTask(), and is
  702. // passed in as a parameter to subsequent calls to UT.
  703. //
  704. // This structure is allocated in the shared memory bank.
  705. //
  706. // This should be a multiple of 4 bytes to ensure DWORD alignment of the
  707. // allocated memory
  708. //
  709. //
  710. typedef struct tagUT_CLIENT
  711. {
  712. DWORD dwThreadId;
  713. HWND utHwnd; // Window to post UT events to
  714. UTEXIT_PROC_INFO exitProcs[UTEXIT_PROCS_MAX];
  715. // Exit procedures registered for
  716. // this task.
  717. UTEVENT_PROC_INFO eventHandlers[UTEVENT_HANDLERS_MAX];
  718. // Event procedures registered for
  719. // this task.
  720. BASEDLIST pendingEvents; // List of events for this task
  721. // which are ready to be
  722. // processed.
  723. BASEDLIST delayedEvents; // List of delayed events destined
  724. // for this task.
  725. }
  726. UT_CLIENT;
  727. #ifndef DLL_DISP
  728. void __inline ValidateUTClient(PUT_CLIENT putTask)
  729. {
  730. extern UT_CLIENT g_autTasks[UTTASK_MAX];
  731. ASSERT(putTask >= &(g_autTasks[UTTASK_FIRST]));
  732. ASSERT(putTask < &(g_autTasks[UTTASK_MAX]));
  733. ASSERT(putTask->dwThreadId);
  734. }
  735. #endif // DLL_DISP
  736. //
  737. //
  738. // UTTaskEnd(...)
  739. //
  740. // This routine frees all resources associated with the task and
  741. // releases the handle
  742. //
  743. // Parameters:
  744. //
  745. // pTaskData - The Utility Functions handle for the task that is ending
  746. //
  747. //
  748. void UTTaskEnd(PUT_CLIENT putTask);
  749. //
  750. //
  751. // Overview:
  752. // This routine is called to check the status of delayed events and to post
  753. // them to the target process if required.
  754. //
  755. // Parameters:
  756. //
  757. // utHandle
  758. // Utility Functions handle of invoking task
  759. //
  760. // NOTES:
  761. //
  762. // 1) This routine is called periodically or whenever the application
  763. // believes a delayed event has popped.
  764. //
  765. // Return codes: None
  766. //
  767. //
  768. void UTCheckEvents(PUT_CLIENT putTask);
  769. void UTCheckDelayedEvents(PUT_CLIENT putTask);
  770. //
  771. //
  772. // UTProcessEvent(...)
  773. //
  774. // Overview:
  775. // This process an event for the current task
  776. //
  777. //
  778. // Parameters:
  779. //
  780. // utHandle
  781. // Utility Functions Handle
  782. //
  783. // event
  784. // The event to process
  785. //
  786. // param1
  787. // The 1st parameter for the event
  788. //
  789. // param2
  790. // The 2nd parameter for the event
  791. //
  792. //
  793. void UTProcessEvent(PUT_CLIENT putTask, UINT event, UINT_PTR param1, UINT_PTR param2);
  794. //
  795. //
  796. // UTProcessDelayedEvent(...)
  797. //
  798. // A delayed event destined for the current task is ready to be processed.
  799. //
  800. // pTaskData - The current tasks data.
  801. // eventOffset - Offset into the shared memory bank at which the event
  802. // is stored.
  803. //
  804. //
  805. void UTProcessDelayedEvent(PUT_CLIENT putTask, DWORD eventOffset);
  806. //
  807. //
  808. // UTPostImmediateEvt(...)
  809. //
  810. // This function adds an event to a task's pending event queue, and posts
  811. // a trigger event if required.
  812. //
  813. // pSrcTaskData - originating tasks data
  814. // pDestTaskData - destination tasks data
  815. // event - event data
  816. // param1 - parm1
  817. // param2 - parm2
  818. //
  819. //
  820. void UTPostImmediateEvt(PUT_CLIENT putTaskFrom,
  821. PUT_CLIENT putTaskTo,
  822. UINT event,
  823. UINT_PTR param1,
  824. UINT_PTR param2);
  825. //
  826. //
  827. // UTPostDelayedEvt(...)
  828. //
  829. // This function adds an event to a task's delayed event queue, and starts
  830. // a timer (on the destination's task) to get that task to process the
  831. // event when the timer ticks.
  832. //
  833. // pSrcTaskData - originating tasks data
  834. // pDestTaskData - destination tasks data
  835. // delay - the delay (in milliseconds)
  836. // event - event data
  837. // param1 - parm1
  838. // param2 - parm2
  839. //
  840. //
  841. void UTPostDelayedEvt(PUT_CLIENT putTaskFrom,
  842. PUT_CLIENT putTaskTo,
  843. UINT delay,
  844. UINT event,
  845. UINT_PTR param1,
  846. UINT_PTR param2);
  847. //
  848. //
  849. // Overview:
  850. // This posts a event to another task
  851. //
  852. // Parameters:
  853. //
  854. // pSrcTaskInfo - task data for the source task
  855. // pDestTaskInfo - task data for the dest task
  856. //
  857. void UTTriggerEvt(PUT_CLIENT putTaskFrom, PUT_CLIENT putTaskTo);
  858. //
  859. //
  860. // Overview:
  861. // This starts a delayed-event timer for a task.
  862. //
  863. // Parameters:
  864. // pTaskData
  865. // The task data for the task
  866. //
  867. // popTime
  868. // The target time for the timer to pop - this is an OS specific value
  869. // in the same format as that returned by UTPopTime().
  870. //
  871. //
  872. void UTStartDelayedEventTimer(PUT_CLIENT putTask, UINT popTime);
  873. #endif // _H_UT