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