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.

1011 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. #ifndef DLL_DISP
  393. //
  394. // API FUNCTION: DCS_StartThread(...)
  395. //
  396. // DESCRIPTION:
  397. // ============
  398. // Start a new thread of execution
  399. //
  400. // PARAMETERS:
  401. // ===========
  402. // entryFunction : A pointer to the thread entry point.
  403. //
  404. //
  405. BOOL DCS_StartThread(LPTHREAD_START_ROUTINE entryFunction);
  406. #endif // DLL_DISP
  407. #ifndef DLL_DISP
  408. BOOL COMReadEntry(HKEY topLevelKey,
  409. LPSTR pSection,
  410. LPSTR pEntry,
  411. LPSTR pBuffer,
  412. int bufferSize,
  413. ULONG expectedDataType);
  414. #endif // DLL_DISP
  415. #define MAKE_SUBALLOC_PTR(pPool, chunkOffset) OFFSETBASE_TO_PTR(chunkOffset, pPool)
  416. #define MAKE_SUBALLOC_OFFSET(pPool, pChunk) PTRBASE_TO_OFFSET(pChunk, pPool)
  417. //
  418. //
  419. // Return codes - all offset from UT_BASE_RC
  420. //
  421. //
  422. enum
  423. {
  424. UT_RC_OK = UT_BASE_RC,
  425. UT_RC_NO_MEM
  426. };
  427. //
  428. // The maximum number of UT events which we try to process without yielding
  429. //
  430. #define MAX_EVENTS_TO_PROCESS 10
  431. //
  432. //
  433. // Types
  434. //
  435. //
  436. //
  437. // Utility Functions Interface handle
  438. //
  439. typedef struct tagUT_CLIENT * PUT_CLIENT;
  440. #define UTTASK_FIRST 0
  441. typedef enum
  442. {
  443. UTTASK_UI = UTTASK_FIRST,
  444. UTTASK_CMG,
  445. UTTASK_OM,
  446. UTTASK_AL,
  447. UTTASK_DCS,
  448. UTTASK_WB,
  449. UTTASK_MAX
  450. }
  451. UT_TASK;
  452. //
  453. // Event procedure registered by UT_RegisterEvent().
  454. //
  455. // Takes event handler registered data, event number and 2 parameters
  456. // Returns TRUE if event processed
  457. // Returns FALSE if not and event should be passed on to next handler
  458. //
  459. //
  460. typedef BOOL (CALLBACK * UTEVENT_PROC)(LPVOID, UINT, UINT_PTR, UINT_PTR);
  461. //
  462. // Exit procedure
  463. //
  464. typedef void (CALLBACK * UTEXIT_PROC)( LPVOID exitData );
  465. //
  466. // The name of the class used to create UT windows
  467. //
  468. #define UT_WINDOW_CLASS "DCUTWindowClass"
  469. //
  470. // The ID of the timer to use for trigger events.
  471. //
  472. #define UT_DELAYED_TIMER_ID 0x10101010
  473. //
  474. //
  475. // Prototypes
  476. //
  477. //
  478. //
  479. //
  480. // Task routines
  481. //
  482. // UT_WndProc() Subclassing window procedure
  483. // UT_InitTask() Initialise a task
  484. // UT_TermTask() Terminate a task
  485. // UT_RegisterEvent() Register an event handler
  486. // UT_DeregisterEvent() Deregisters an event handler
  487. // UT_RegisterExit() Register an exit routine
  488. // UT_DeregisterExit() Deregister an exit routine
  489. // UT_PostEvent() Send an event to a task
  490. //
  491. //
  492. LRESULT CALLBACK UT_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  493. BOOL UT_InitTask(UT_TASK task, PUT_CLIENT * pputTask);
  494. //
  495. //
  496. // Overview:
  497. // This registers a task and assigns it a handle.
  498. // All other Utility Functions require this handle to be passed to them.
  499. //
  500. // If a task has already been registered with the same process ID, the
  501. // utilities handle that has already been allocated is returned.
  502. // This is to allows the Utility Functions to be used in the context of
  503. // tasks that DC-SHARE has intercepted the graphics calls for.
  504. //
  505. // Each task is identified by a name.
  506. //
  507. // Parameters:
  508. //
  509. // task
  510. // Unique it for identifying task
  511. //
  512. // pUtHandle (returned)
  513. // Utility Services handle to be used for all calls to the Utility
  514. // Services by this task
  515. //
  516. //
  517. void UT_TermTask(PUT_CLIENT * pputTask);
  518. //
  519. //
  520. // Overview:
  521. // This de-registers a task
  522. // All task resources are freed and the utHandle is released
  523. //
  524. // Parameters:
  525. //
  526. // utHandle
  527. // Utility Functions Handle
  528. //
  529. void UT_RegisterEvent(PUT_CLIENT putTask,
  530. UTEVENT_PROC eventProc,
  531. LPVOID eventData,
  532. UT_PRIORITY priority);
  533. void UT_DeregisterEvent(PUT_CLIENT putTask,
  534. UTEVENT_PROC eventProc,
  535. LPVOID eventData);
  536. void UT_PostEvent(PUT_CLIENT putTaskFrom,
  537. PUT_CLIENT putTaskTo,
  538. UINT delay,
  539. UINT eventNo,
  540. UINT_PTR param1,
  541. UINT_PTR param2);
  542. #define NO_DELAY 0
  543. //
  544. //
  545. // Overview:
  546. // This posts an event to another task.
  547. //
  548. // Parameters:
  549. //
  550. // utHandle
  551. // Utility Functions handle of invoking task
  552. //
  553. // toHandle
  554. // Utility Functions TASK handle of task to post event to
  555. //
  556. // delay
  557. // Delay (in milliseconds) before event is posted
  558. //
  559. // eventNo
  560. // event to be posted (see autevt.h for details of events)
  561. //
  562. // param1
  563. // parameter 1 for event (meaning depends on event)
  564. //
  565. // param2
  566. // parameter 2 for event (meaning depends on event)
  567. //
  568. //
  569. // NOTES:
  570. //
  571. // 1) The delay time is in milliseconds. This may not be supported by
  572. // underlying OS but the setting and checking of the pop time value
  573. // is OS specific.
  574. //
  575. // 2) The posting of events is asynchronous, the delay is simply
  576. // the time before the event is posted. The task the event is
  577. // posted to will receive the event NOT BEFRE this time is up.
  578. //
  579. // 3) If an event is posted with a delay specified, the sending task
  580. // must continue to process messages for the event to be posted
  581. //
  582. void UT_RegisterExit(PUT_CLIENT putTask, UTEXIT_PROC exitProc, LPVOID exitData);
  583. void UT_DeregisterExit(PUT_CLIENT putTask, UTEXIT_PROC exitProc, LPVOID exitData);
  584. //
  585. // Memory routines
  586. // UT_MallocRefCount
  587. // UT_BumpUpRefCount
  588. // UT_FreeRefCount
  589. //
  590. void * UT_MallocRefCount(UINT cbSizeMem, BOOL fZeroMem);
  591. void UT_BumpUpRefCount(void * pMemory);
  592. void UT_FreeRefCount(void ** ppMemory, BOOL fNullOnlyWhenFreed);
  593. // Ref count allocs
  594. typedef struct tagUTREFCOUNTHEADER
  595. {
  596. STRUCTURE_STAMP
  597. UINT refCount;
  598. }
  599. UTREFCOUNTHEADER;
  600. typedef UTREFCOUNTHEADER * PUTREFCOUNTHEADER;
  601. //
  602. // UT_MoveMemory()
  603. // Replacement for CRT memmove(); handles overlapping
  604. //
  605. void * UT_MoveMemory(void * dst, const void * src, size_t count);
  606. //
  607. // Locks
  608. // - UT_Lock() - Locks a lock
  609. // - UT_Unlock() - Unlocks a lock
  610. //
  611. #ifndef DLL_DISP
  612. extern CRITICAL_SECTION g_utLocks[UTLOCK_MAX];
  613. __inline void UT_Lock(UTLOCK lock)
  614. {
  615. ASSERT(lock >= UTLOCK_FIRST);
  616. ASSERT(lock < UTLOCK_MAX);
  617. EnterCriticalSection(&g_utLocks[lock]);
  618. }
  619. __inline void UT_Unlock(UTLOCK lock)
  620. {
  621. ASSERT(lock >= UTLOCK_FIRST);
  622. ASSERT(lock < UTLOCK_MAX);
  623. LeaveCriticalSection(&g_utLocks[lock]);
  624. }
  625. #endif // DLL_DISP
  626. //
  627. // Tasks
  628. // UT_HandleProcessStart()
  629. // UT_HandleProcessEnd()
  630. // UT_HandleThreadEnd()
  631. //
  632. BOOL UT_HandleProcessStart(HINSTANCE hInstance);
  633. void UT_HandleProcessEnd(void);
  634. void UT_HandleThreadEnd(void);
  635. //
  636. // Structure for holding an event. The first two fields allow the event to
  637. // be held on the delayed event Q to be scheduled later.
  638. //
  639. typedef struct tagUTEVENT_INFO
  640. {
  641. STRUCTURE_STAMP
  642. BASEDLIST chain;
  643. // Params
  644. UINT event;
  645. UINT_PTR param1;
  646. UINT_PTR param2;
  647. PUT_CLIENT putTo;
  648. UINT popTime;
  649. }
  650. UTEVENT_INFO;
  651. typedef UTEVENT_INFO * PUTEVENT_INFO;
  652. #ifndef DLL_DISP
  653. void __inline ValidateEventInfo(PUTEVENT_INFO pEventInfo)
  654. {
  655. ASSERT(!IsBadWritePtr(pEventInfo, sizeof(UTEVENT_INFO)));
  656. }
  657. #endif // DLL_DISP
  658. //
  659. // Information held about each exit procedure
  660. //
  661. typedef struct tagUTEXIT_PROC_INFO
  662. {
  663. UTEXIT_PROC exitProc;
  664. LPVOID exitData;
  665. } UTEXIT_PROC_INFO;
  666. typedef UTEXIT_PROC_INFO * PUTEXIT_PROC_INFO;
  667. //
  668. // Information held about each event procedure
  669. //
  670. typedef struct tagUTEVENT_PROC_INFO
  671. {
  672. UTEVENT_PROC eventProc;
  673. LPVOID eventData;
  674. UT_PRIORITY priority;
  675. }
  676. UTEVENT_PROC_INFO;
  677. typedef UTEVENT_PROC_INFO * PUTEVENT_PROC_INFO;
  678. //
  679. //
  680. // UT_CLIENT
  681. //
  682. // Information stored about each Utilities registered task. A pointer to
  683. // this structure is returned as the UT Handle from UT_InitTask(), and is
  684. // passed in as a parameter to subsequent calls to UT.
  685. //
  686. // This structure is allocated in the shared memory bank.
  687. //
  688. // This should be a multiple of 4 bytes to ensure DWORD alignment of the
  689. // allocated memory
  690. //
  691. //
  692. typedef struct tagUT_CLIENT
  693. {
  694. DWORD dwThreadId;
  695. HWND utHwnd; // Window to post UT events to
  696. UTEXIT_PROC_INFO exitProcs[UTEXIT_PROCS_MAX];
  697. // Exit procedures registered for
  698. // this task.
  699. UTEVENT_PROC_INFO eventHandlers[UTEVENT_HANDLERS_MAX];
  700. // Event procedures registered for
  701. // this task.
  702. BASEDLIST pendingEvents; // List of events for this task
  703. // which are ready to be
  704. // processed.
  705. BASEDLIST delayedEvents; // List of delayed events destined
  706. // for this task.
  707. }
  708. UT_CLIENT;
  709. #ifndef DLL_DISP
  710. void __inline ValidateUTClient(PUT_CLIENT putTask)
  711. {
  712. extern UT_CLIENT g_autTasks[UTTASK_MAX];
  713. ASSERT(putTask >= &(g_autTasks[UTTASK_FIRST]));
  714. ASSERT(putTask < &(g_autTasks[UTTASK_MAX]));
  715. ASSERT(putTask->dwThreadId);
  716. }
  717. #endif // DLL_DISP
  718. //
  719. //
  720. // UTTaskEnd(...)
  721. //
  722. // This routine frees all resources associated with the task and
  723. // releases the handle
  724. //
  725. // Parameters:
  726. //
  727. // pTaskData - The Utility Functions handle for the task that is ending
  728. //
  729. //
  730. void UTTaskEnd(PUT_CLIENT putTask);
  731. //
  732. //
  733. // Overview:
  734. // This routine is called to check the status of delayed events and to post
  735. // them to the target process if required.
  736. //
  737. // Parameters:
  738. //
  739. // utHandle
  740. // Utility Functions handle of invoking task
  741. //
  742. // NOTES:
  743. //
  744. // 1) This routine is called periodically or whenever the application
  745. // believes a delayed event has popped.
  746. //
  747. // Return codes: None
  748. //
  749. //
  750. void UTCheckEvents(PUT_CLIENT putTask);
  751. void UTCheckDelayedEvents(PUT_CLIENT putTask);
  752. //
  753. //
  754. // UTProcessEvent(...)
  755. //
  756. // Overview:
  757. // This process an event for the current task
  758. //
  759. //
  760. // Parameters:
  761. //
  762. // utHandle
  763. // Utility Functions Handle
  764. //
  765. // event
  766. // The event to process
  767. //
  768. // param1
  769. // The 1st parameter for the event
  770. //
  771. // param2
  772. // The 2nd parameter for the event
  773. //
  774. //
  775. void UTProcessEvent(PUT_CLIENT putTask, UINT event, UINT_PTR param1, UINT_PTR param2);
  776. //
  777. //
  778. // UTProcessDelayedEvent(...)
  779. //
  780. // A delayed event destined for the current task is ready to be processed.
  781. //
  782. // pTaskData - The current tasks data.
  783. // eventOffset - Offset into the shared memory bank at which the event
  784. // is stored.
  785. //
  786. //
  787. void UTProcessDelayedEvent(PUT_CLIENT putTask, DWORD eventOffset);
  788. //
  789. //
  790. // UTPostImmediateEvt(...)
  791. //
  792. // This function adds an event to a task's pending event queue, and posts
  793. // a trigger event if required.
  794. //
  795. // pSrcTaskData - originating tasks data
  796. // pDestTaskData - destination tasks data
  797. // event - event data
  798. // param1 - parm1
  799. // param2 - parm2
  800. //
  801. //
  802. void UTPostImmediateEvt(PUT_CLIENT putTaskFrom,
  803. PUT_CLIENT putTaskTo,
  804. UINT event,
  805. UINT_PTR param1,
  806. UINT_PTR param2);
  807. //
  808. //
  809. // UTPostDelayedEvt(...)
  810. //
  811. // This function adds an event to a task's delayed event queue, and starts
  812. // a timer (on the destination's task) to get that task to process the
  813. // event when the timer ticks.
  814. //
  815. // pSrcTaskData - originating tasks data
  816. // pDestTaskData - destination tasks data
  817. // delay - the delay (in milliseconds)
  818. // event - event data
  819. // param1 - parm1
  820. // param2 - parm2
  821. //
  822. //
  823. void UTPostDelayedEvt(PUT_CLIENT putTaskFrom,
  824. PUT_CLIENT putTaskTo,
  825. UINT delay,
  826. UINT event,
  827. UINT_PTR param1,
  828. UINT_PTR param2);
  829. //
  830. //
  831. // Overview:
  832. // This posts a event to another task
  833. //
  834. // Parameters:
  835. //
  836. // pSrcTaskInfo - task data for the source task
  837. // pDestTaskInfo - task data for the dest task
  838. //
  839. void UTTriggerEvt(PUT_CLIENT putTaskFrom, PUT_CLIENT putTaskTo);
  840. //
  841. //
  842. // Overview:
  843. // This starts a delayed-event timer for a task.
  844. //
  845. // Parameters:
  846. // pTaskData
  847. // The task data for the task
  848. //
  849. // popTime
  850. // The target time for the timer to pop - this is an OS specific value
  851. // in the same format as that returned by UTPopTime().
  852. //
  853. //
  854. void UTStartDelayedEventTimer(PUT_CLIENT putTask, UINT popTime);
  855. #endif // _H_UT