home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / fssht / shi.h < prev    next >
C/C++ Source or Header  |  1999-05-11  |  18KB  |  344 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992, 1993              */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHI.H                                                  */
  7. /*                                                                          */
  8. /* This file contains the stream handler internal definitions and types.    */
  9. /*                                                                          */
  10. /****************************************************************************/
  11. #include <shifwd.h>
  12.  
  13. /*
  14.  *   Miscellaneous defines
  15.  */
  16. #define EXTLSTADD_ORDER       0x6201   /* Exit list order for us */
  17. /* #define CREATE_SUSPENDED   1L          DosCreateThread suspended      */
  18. #define STACKSIZE             65536L   /* Stack size for new thread */
  19. #define STACKSIZE32           1024*64L /* Stack size for new thread */
  20. #define HEAPSIZE              4096L    /* Heap size for control blocks */
  21. #define SPI_SEEK_MODE_MASK    (SPI_SEEK_ABSOLUTE+SPI_SEEK_RELATIVE+SPI_SEEK_FROMEND)
  22. #define TEMPORARY_ERROR       0L
  23. #define RECOVERABLE_ERROR     1L
  24. #define NONRECOVERABLE_ERROR  2L
  25.  
  26.  
  27. /*
  28.  * SleepNCheck input/Output bit flags
  29.  */
  30. #define DO_SLEEP                0x00000000L     /* Input Flags */
  31.  
  32. #ifdef INCL_NEWSH
  33. #define DONT_SLEEP              0x00000004L
  34. #define DONT_SLEEP_FLUSH        0x00000008L
  35. #define DONT_SLEEP_DISCARD      0x00000010L
  36.  
  37. #define AWAKEN_BY_OTHER         0x00000000L     /* Output Flags */
  38. #define AWAKEN_BY_DISCARD_STOP  0x00010000L
  39. #define AWAKEN_BY_FLUSH_STOP    0x00020000L
  40.  
  41.  
  42. #else
  43. #define DONT_SLEEP            5L
  44. #define DONT_SLEEP_FLUSH      6L
  45. #endif
  46.  
  47. #define IOTHREAD_PRIORITYCLASS       PRTYC_TIMECRITICAL
  48. #define IOTHREAD_PRIORITYDELTA       02L
  49.  
  50. /*
  51.  *   Structure declarations
  52.  */
  53.  
  54. /*
  55.  * E_EVCB - Extended Event Control Blocks.  These are used
  56.  *          to chain multiple EVCBs in a linked list
  57.  *          the extra fields are used to support report time
  58.  *          for both the recurring and non recurring events
  59.  */
  60. typedef struct _E_EVCB { /* e_evcb */
  61.           struct _E_EVCB *pNext_e_evcb; /* pointer to the next EVCB */
  62.           HEVENT      hevent;                /* saved event handle */
  63.           TIME_EVCB   time_evcb;             /* time event control block */
  64.           MMTIME      mmtimeDynamicTime;     /* single event report time (dynamic time line) */
  65.           MMTIME      mmtimeStaticTime;      /* period of notification, and  */
  66.                                              /* in single events contains */
  67.                                              /* copy of above for generic */
  68.                                              /* chain adding purposed     */
  69.           ULONG       ulState;               /* event state */                                          /*WPOS*/
  70.           MMTIME      mmReferenceTime;       /* current stream time for recurring events */             /*WPOS*/
  71.           MMTIME      mmIntervalTime;        /* needed to retain the  "sticky" cuepoint from walking */ /*WPOS*/
  72. } E_EVCB, *PE_EVCB;
  73.  
  74. /*
  75.  *  ulState
  76.  */
  77. #define EVENT_PASSED    0x0000L              /* this event has already taken place */                   /*WPOS*/
  78. #define EVENT_WAITING   0x0001L              /* this event is pending for cue to happen */              /*WPOS*/
  79.  
  80. /*
  81.  * EVENTS - Event substructure
  82.  */
  83. typedef struct _EVENTBLK { /* event */
  84.           BOOL        fAnyEventsEnabled;     /* quick test so see if any events enabled */
  85.           MMTIME      mmtimeGranularity;     /* see SetGranularity () below (optional if a granularity factor is in the stream )*/
  86.           HEVENT      heventDataUnderRun;    /* data under run event handle NULL if disabled */
  87.           HEVENT      heventDataOverRun;     /* data over run event handle NULL if disabled */    /*WPOS*/
  88.           PE_EVCB     pActiveRecurrEvcbChain;/* Pointer to the active recurring EVCB chain */
  89.           PE_EVCB     pActiveSingleEvcbChain;/* Pointer to the active single shot EVCB chain */
  90.           PE_EVCB     pInactiveEvcbChain;    /* Pointer to the inactive EVCB chain */
  91.         } EVENTBLK, *PEVENTBLK;
  92.  
  93. /*
  94.  *   Extended Stream Protocol Control Block (ESPCB)
  95.  */
  96. typedef struct espcb {
  97.           struct espcb *pnxtESPCB;  /* rtn for events of this datatype */
  98.           SPCB         spcb;        /* Stream Protocol Control Block */
  99.         } ESPCB, *PESPCB;
  100.  
  101. /*
  102.  * Stream Instance Block
  103.  */
  104. typedef struct sib {                   /* Stream Instance Block */
  105.            struct sib *pnxtSIB;        /* Pointer to next SIB */
  106.            ESPCB       espcb;          /* Extended SPCB */
  107.            HSTREAM     hStream;        /* Stream handle for this instance */
  108.            HID         HandlerID;      /* Handler ID (src or tgt) */
  109.            ULONG       ulStatus;       /* Status of this instance */
  110.            ULONG       ulActionFlags;  /* Flags that indicate that the */
  111.                                        /*  read/write thread needs to do */
  112.                                        /*  some special action. */
  113.            TID         ThreadID;       /* ID of I/O thread */
  114.            PID         ProcessID;      /* Process ID that created the stream */
  115.            ULONG       ulAssocP1;      /* Associate Parm 1 */
  116.            ULONG       ulAssocP2;      /* Associate Parm 2 */
  117.            ULONG       aulInfo[5];     /* Array for misc information */
  118.            MMTIME      mmtimeCurrentTime; /* current mmtime of the stream */
  119.            HEV         hevStop;
  120.            HEV         hevCmdSync;     /* sem for synchronizing command */
  121.            BOOL        fSyncFlag;      /* sync pulse flag (indicates whether enabled or not) */
  122.            SYNC_EVCB   syncEvcb;       /* generic sync evcb support for master & slave SH's */
  123.            EVENTBLK    eventBlk;       /* generic event support linked lists */
  124.         }  SIB, *PSIB;
  125.  
  126. /*
  127.  * SIB fSyncFlag states
  128.  */
  129. #define SYNC_ENABLED           0x0001L    /* enable the adaptive stuff */
  130. #define SYNC_DISABLED          0x0000L    /* Default state for the sync evcb */
  131.  
  132. /*
  133.  *   SIB ulStatus States
  134.  */
  135. #define SIB_INITIALIZED          1L
  136. #define SIB_NEGOTIATED           2L
  137. #define SIB_READY_TO_RUN         3L
  138. #define SIB_RUNNING              4L
  139.  
  140. #ifdef INCL_NEWSH
  141. #define SIB_STOPPED              8L
  142. #define SIB_PAUSED               9L
  143. #else
  144. #define SIB_PAUSED               5L
  145. #endif
  146.  
  147. /*
  148.  * SIB ulActionFlag bit meanings
  149.  */
  150. #define SIBACTFLG_KILL         0x0001L     /* Kill the read/write thread */
  151. #define SIBACTFLG_STOP_FLUSH   0x0002L     /* Stop and flush all filled buffers. */
  152.                                            /*  This flag is the same value as the */
  153.                                            /*  Stop stream flag bit value. */
  154. #define SIBACTFLG_STOP_DISCARD 0x0004L     /* Stop and discard all filled buffers. */
  155.                                            /*  This flag is the same value as the */
  156.                                            /*  Stop stream flag bit value. */
  157. #define SIBACTFLG_STOP_PAUSE   0x0008L     /* Stop Pause the IO thread */
  158.                                            /*  This is only used for stream handlers that the IO */
  159.                                            /*  thread gets the global data mutex sem. */
  160. #define SIBACTFLG_THREAD_DEAD  0x0010L     /* The IO Thread has exited.  This could be due */
  161.                                            /*  to several reasons including exit list processing. */
  162.                                            /*  The synchronous commands should not wait on the */
  163.                                            /*  io thread to post an event if this flag is set. */
  164.  
  165. /*
  166.  *   External Global Data Definitions
  167.  */
  168. extern PESPCB pESPCB_ListHead;         /* Pointer to list of Extended SPCB's */
  169. extern ULONG ulProcessCount;           /* # of processes using this stream */
  170.                                        /*  handler */
  171. extern PSIB pSIB_list_head;            /* Pointer to list of SIB's in use */
  172.                                        /*  for this process. */
  173. extern PSZ pszHandlerName;             /* Name of this stream handler */
  174. extern ULONG ulHandlerVersion;         /* Version of this handler */
  175. extern HID SrcHandlerID;               /* Handler ID returned from Register */
  176. extern HID TgtHandlerID;               /* Handler ID returned from Register */
  177. extern HHUGEHEAP hHeap;                /* Handle of heap for SIB's and EVCB's */
  178. extern PSZ pszProcCntMutexName;        /* Name of semaphore to control the */
  179.                                        /*  usProcessCount variable. */
  180. extern HMTX hmtxProcCnt;               /* Handle of semaphore to control the */
  181.                                        /*  usProcessCount variable. */
  182. extern HMTX hmtxGlobalData;            /* Handle of semaphore to control the */
  183.                                        /*  Global Data structures. */
  184. extern PFNTHREAD ShWriteRtn;           /* variable to hold @ of write routine */
  185. extern PFNTHREAD ShReadRtn;            /* variable to hold @ of read routine. */
  186. extern PFNTHREAD ShRdWrRtn;            /* variable to hold read/write routine. */
  187.  
  188. typedef RC (* _System PFNSHINSTALLCHECK)(PPARM_INSTPROT pInstProt);
  189. extern PFNSHINSTALLCHECK pfnShInstallCheck;          /* variable to hold @ of install check routine */
  190. typedef RC (* _System PFNSHCSENDMSG)(PPARM_SNDMSG pSndMsg);
  191. extern PFNSHCSENDMSG pfnShcSendMsg;              /* variable to hold @ of ShcSendMsg routine */
  192. typedef RC (* _System PFNSHCGETTIME)(PPARM_GTIME pGetTime);
  193. extern PFNSHCGETTIME pfnShcGetTime;              /* variable to hold @ of ShcGetTime routine */
  194. typedef RC (* _System PFNSHCENABLEEVENT)(PPARM_ENEVENT pEnableEvent);
  195. extern PFNSHCENABLEEVENT pfnShcEnableEvent;          /* variable to hold @ of ShcEnableEvent routine */
  196. typedef RC (* _System PFNSHCDISABLEEVENT)(PPARM_DISEVENT pDisableEvent);
  197. extern PFNSHCDISABLEEVENT pfnShcDisableEvent;         /* variable to hold @ of ShcDisableEvent routine */
  198. typedef RC (* _System PFNSHCENABLESYNC)(PPARM_ENSYNC pEnableSync);
  199. extern PFNSHCENABLESYNC pfnShcEnableSync;           /* variable to hold @ of ShcEnableSync routine */
  200. typedef RC (* _System PFNSHCDISABLESYNC)(PPARM_DISSYNC pDisableSync);
  201. extern PFNSHCDISABLESYNC pfnShcDisableSync;          /* variable to hold @ of ShcDisableSync routine */
  202.  
  203. extern ULONG ulHandlerFlags;           /* Stream handler specific flags */
  204.  
  205.  
  206. /*
  207.  * fHandlerFlag Defines - flags that describe and alter functionality of stream
  208.  *                        handlers using this common code
  209.  */
  210. #define  HANDLER_CAN_BE_SOURCE     0x001L    /* Stream handler can be a source stream handler */
  211. #define  HANDLER_CAN_BE_TARGET     0x002L    /* Stream handler can be a target stream handler */
  212. #define  HANDLER_INSTALL_CHECKS    0x004L    /* Stream handler does additional checks when */
  213.                                              /*  processing SHC_INSTALL_PROTOCOL */
  214. #define  HANDLER_IS_NONSTREAMING   0x008L    /* Stream handler is non streaming */
  215. #define  HANDLER_SHC_SENDMSG       0x100L    /* Stream handler supports SHC_SENDMSG api */
  216. #define  HANDLER_SHC_GET_TIME      0x200L    /* Stream handler supports SHC_GET_TIME api */
  217. #define  HANDLER_SHC_EVENT_CALLS   0x400L    /* Stream handler supports shc event apis */
  218. #define  HANDLER_SHC_SYNC_CALLS    0x800L    /* Stream handler supports shc sync apis */
  219.  
  220. /*
  221.  *  ShFindESPCB() ulDefaults defines
  222.  */
  223. #define ESPCB_DEFAULT_LAST_GENERIC    0x0001L     /* If no match, use the last installed GENERIC espcb */
  224. #define ESPCB_IGNORE_INTKEY           0x8000L     /* Ignore the ulIntKey field when matching */
  225. #define ESPCB_IGNORE_DATASUBTYPE      0x8001L     /* Ignore the ulDataSubType field when matching */
  226.  
  227. /*
  228.  * Macros
  229.  */
  230. #define ENTERCRITX(rc)         if (rc = DosRequestMutexSem(hmtxGlobalData, SEM_INDEFINITE_WAIT)) return(rc);
  231. #define ENTERCRIT(rc)          (rc = DosRequestMutexSem(hmtxGlobalData, SEM_INDEFINITE_WAIT))
  232. #define EXITCRIT               (DosReleaseMutexSem(hmtxGlobalData))
  233.  
  234. #define DEAD(psib)             (psib->ulActionFlags & SIBACTFLG_THREAD_DEAD)
  235.  
  236. #define WAIT_FOR_DEAD_IO(psib) {                                              \
  237.                                if (!DEAD(psib))                               \
  238.                                   DosWaitThread(&psib->ThreadID, DCWW_WAIT);  \
  239.                                }
  240.  
  241. #define RESUME_IO(psib,status) {                                                          \
  242.                                if (psib->ulStatus == SIB_PAUSED) {                        \
  243.                                   if (status)                                             \
  244.                                      psib->ulStatus = status;                             \
  245.                                   DosResumeThread(psib->ThreadID);                        \
  246.                                   }                                                       \
  247.                                }
  248.  
  249. #define SUSPEND_IO(psib)       {                                                                        \
  250.                                if ((psib->ThreadID) && !(psib->ulActionFlags & SIBACTFLG_THREAD_DEAD))  \
  251.                                    rc = DosSuspendThread(psib->ThreadID);                               \
  252.                                }
  253.  
  254. #define RECEIVE_MSG(psib,rc)   {                                                          \
  255.                                rc = DosWaitEventSem(psib->hevStop, SEM_INDEFINITE_WAIT);  \
  256.                                }
  257.  
  258. #define SEND_MSG(psib,cmd,status) {                                \
  259.                                psib->ulActionFlags |= cmd;         \
  260.                                DosPostEventSem(psib->hevStop);     \
  261.                                RESUME_IO(psib,status);             \
  262.                                }
  263.  
  264. #define SYNC_SEND_MSG(psib,cmd,status) {                           \
  265.                                RESET_REPLY(psib);                  \
  266.                                SEND_MSG(psib,cmd,status);          \
  267.                                RECEIVE_REPLY(psib);                \
  268.                                }
  269.  
  270. #define RESET_MSG(psib)        {                                                          \
  271.                                ULONG ulPostCount;                                         \
  272.                                DosResetEventSem(psib->hevStop, &ulPostCount);             \
  273.                                }
  274.  
  275. #define SEND_REPLY(psib)       {                                   \
  276.                                DosPostEventSem(psib->hevCmdSync);  \
  277.                                }
  278.  
  279. #define RECEIVE_REPLY(psib)    {                                                          \
  280.                                if (!DEAD(psib))                                           \
  281.                                   DosWaitEventSem(psib->hevCmdSync, SEM_INDEFINITE_WAIT); \
  282.                                }
  283.  
  284. #define RESET_REPLY(psib)      {                                                          \
  285.                                ULONG ulPostCount;                                         \
  286.                                DosResetEventSem(psib->hevCmdSync, &ulPostCount);          \
  287.                                }
  288.  
  289.  
  290.  
  291. /*
  292.  * Prototype statements
  293.  */
  294.  
  295.   /* SHC commands that must be supported */
  296. RC ShcAssociate(PPARM_ASSOC);                         /* SH specific */
  297. RC ShcCreate(PPARM_CREATE);                           /* SH specific */
  298. RC ShcDestroy(PPARM_DESTROY);                         /* shdestry.c or SH specific */
  299. RC ShcEnumerateProtocols(PPARM_ENUMPROT);             /* sheprot.c */
  300. RC ShcGetProtocol(PPARM_GPROT);                       /* shgprot.c */
  301. RC ShcInstallProtocol(PPARM_INSTPROT);                /* shiprot.c */
  302. RC ShcNegotiateResult(PPARM_NEGOTIATE);               /* shnegot.c or SH specific */
  303. RC ShcSeek(PPARM_SEEK);                               /* SH specific */
  304. RC ShcStart(PPARM_START);                             /* shstart.c  or SH specific */
  305. RC ShcStop(PPARM_STOP);                               /* shstop.c or SH specific */
  306.  
  307.   /* Optional SHC Commands to support */
  308. RC _System ShcDisableEvent(PPARM_DISEVENT);                   /* shevent.c or SH specific */
  309. RC _System ShcDisableSync(PPARM_DISSYNC);                     /* shsync.c or SH specific */
  310. RC _System ShcEnableEvent(PPARM_ENEVENT);                     /* shevent.c or SH specific */
  311. RC _System ShcEnableSync(PPARM_ENSYNC);                       /* shsync.c or SH specific */
  312. RC _System ShcGetTime(PPARM_GTIME);                           /* shtime.c or SH specific */
  313. RC _System ShcSendMsg(PPARM_SNDMSG);                          /* shmsg.c or SH specific */
  314.  
  315.   /* In shinit.c */
  316. ULONG _DLL_InitTerm( HMODULE hmod, ULONG fTerm);
  317. VOID APIENTRY ShExitList(VOID);
  318.  
  319.   /* IN shrouter.c */
  320. SHCFN ShcRouter;
  321.  
  322.   /* In shmisc.c */
  323. RC ShFindSib(PSIB*, HSTREAM, HID);
  324. PESPCB ShFindEspcb(SPCBKEY);
  325. PESPCB ShFindESPCB(SPCBKEY, ULONG);
  326. #ifdef FIXSH
  327. PESPCB ShSearchESPCBList(PSPCBKEY, ULONG, PESPCB *);
  328. #else
  329. PESPCB ShSearchESPCBList(PSPCBKEY, ULONG, PESPCB);
  330. #endif
  331. RC DestroySIB (PSIB psib);
  332.  
  333.   /* In shioutil.c */
  334. RC ReportEvent(PSIB, RC, ULONG, ULONG, ULONG);
  335. RC CheckNSleep(PSIB);
  336. RC SleepNCheck(PSIB, PULONG);
  337. RC ShIOError(PSIB, PARM_NOTIFY, RC);
  338.  
  339.   /* In shevent.c */
  340. RC CheckEvents       ( PSIB );
  341. RC ReCalcEventChains ( PEVENTBLK, MMTIME, BOOL);
  342. RC SetGranularity    ( PSIB, MMTIME );
  343.  
  344.