home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / mmos2 / mmtoolkt / samples / fssht / sheprot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-06  |  5.7 KB  |  119 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992                    */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHEPROT.C                                              */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Enumerate Protocols routine            */
  9. /*                                                                          */
  10. /* FUNCTION: Enumerate the protocols installed in this stream handler.      */
  11. /*                                                                          */
  12. /* ENTRY POINTS: ShcEnumerateProtocols                                      */
  13. /*                                                                          */
  14. /*************************** END OF SPECIFICATIONS **************************/
  15. #define  INCL_NOPMAPI                  /* no PM include files required */
  16. #define  INCL_DOSSEMAPHORES
  17. #define  INCL_DOSPROCESS
  18. #include <os2.h>
  19. #include <os2me.h>
  20. #include <hhpheap.h>
  21. #include <shi.h>
  22.  
  23. /************************** START OF SPECIFICATIONS *************************/
  24. /*                                                                          */
  25. /* SUBROUTINE NAME: ShcEnumerateProtocols                                   */
  26. /*                                                                          */
  27. /* DESCRIPTIVE NAME: Stream Handler Command Enumerate Protocols (spcbs)     */
  28. /*                                                                          */
  29. /* FUNCTION: This returns a list of the protocols supported by the stream   */
  30. /*           handler.                                                       */
  31. /*                                                                          */
  32. /* NOTES:                                                                   */
  33. /*                                                                          */
  34. /* ENTRY POINT: ShcEnumerateProtocols                                       */
  35. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  36. /*                                                                          */
  37. /* INPUT:                                                                   */
  38. /*                                                                          */
  39. /* EXIT-NORMAL:                                                             */
  40. /*                                                                          */
  41. /* EXIT-ERROR:                                                              */
  42. /*                                                                          */
  43. /* SIDE EFFECTS:                                                            */
  44. /*                                                                          */
  45. /* INTERNAL REFERENCES:                                                     */
  46. /*        ROUTINES:                                                         */
  47. /*                                                                          */
  48. /* EXTERNAL REFERENCES:                                                     */
  49. /*        ROUTINES:                                                         */
  50. /*        DATA STRUCTURES:                                                  */
  51. /*                                                                          */
  52. /*************************** END OF SPECIFICATIONS **************************/
  53.  
  54. RC ShcEnumerateProtocols(pepparm)
  55. PPARM_ENUMPROT pepparm;
  56.  
  57. { /* Start of ShcEnumerateProtocols */
  58.  
  59. RC rc = NO_ERROR;                       // local return code
  60. ULONG  ulNumEspcbs;                     // loop control
  61. PSPCBKEY aSpcbKeys;                     // array of spcbkeys to return
  62. PESPCB pTempEspcb;                      // temp pointer to espcb
  63.  
  64.  
  65.   //
  66.   // the ESPCB list is under semphore control
  67.   //
  68.   if (!(rc = DosRequestMutexSem(hmtxGlobalData, SEM_INDEFINITE_WAIT)))
  69.     { /* obtained semaphore */
  70.       //
  71.       // Count the number of espcb's installed to
  72.       // check if application passed large enough buffer.
  73.       // If not return error and size needed.
  74.       //
  75.       pTempEspcb = pESPCB_ListHead;
  76.       ulNumEspcbs = 0;
  77.       while (pTempEspcb)
  78.         {
  79.           ulNumEspcbs++;
  80.           pTempEspcb = pTempEspcb->pnxtESPCB;
  81.         }
  82.  
  83.       /* check the buffer size passed */
  84.       if (*pepparm->pulNumSPCBKeys < ulNumEspcbs)
  85.         { /* Not enough space */
  86.           rc = ERROR_INVALID_BUFFER_SIZE;
  87.         } /* Not enough space */
  88.       else
  89.         { /* Get the spcb keys */
  90.           //
  91.           // Loop thru the espcb list and copy the spcbkey to the
  92.           // callers buffer.
  93.           //
  94.           aSpcbKeys = pepparm->paSPCBKeys;
  95.           ulNumEspcbs = 0;
  96.           pTempEspcb = pESPCB_ListHead;
  97.           while (pTempEspcb)
  98.             { /* Loop thru espcbs */
  99.  
  100.               aSpcbKeys[ulNumEspcbs].ulDataType    = pTempEspcb->spcb.spcbkey.ulDataType;
  101.               aSpcbKeys[ulNumEspcbs].ulDataSubType = pTempEspcb->spcb.spcbkey.ulDataSubType;
  102.               aSpcbKeys[ulNumEspcbs].ulIntKey      = pTempEspcb->spcb.spcbkey.ulIntKey;
  103.               ulNumEspcbs++;
  104.               pTempEspcb = pTempEspcb->pnxtESPCB;
  105.  
  106.             } /* Loop thru espcbs */
  107.  
  108.         } /* Get the spcb keys */
  109.  
  110.       /* Return the real number of spcb keys in all cases */
  111.       *pepparm->pulNumSPCBKeys = ulNumEspcbs;
  112.  
  113.       DosReleaseMutexSem(hmtxGlobalData);
  114.     } /* obtained semaphore */
  115.  
  116.   return(rc);
  117.  
  118. } /* End of ShcEnumerateProtocols */
  119.