SMH_NOTIFY - Example Code

The following code illustrates how to notify the Sync/Stream Manager of a stream buffer request.

/*----------------------------------------------------------------
 *  Source Stream Handler Example
 *---------------------------------------------------------------*/

#include        "os2.h"
#include        "os2me.h"

  ULONG         ulRC;              /* Error return code          */
  HID           hidSource;         /* Source handler ID          */
  HSTREAM       hstream;           /* Stream handle              */
  PARM_NOTIFY   parm_notify; /* Notify parameter block     */
  SRCBUFTAB     srcbuftab;         /* Source buffer table        */
  PSMHFN        SMHEntryPoint;     /* Pointer to SMH entry point */

/*-----------------------------------------------------------------
 *  Request an empty stream buffer from the Sync/Stream Manager.
 *----------------------------------------------------------------*/
  parm_notify.ulFunction = SMH_NOTIFY;    /* Set function              */
  parm_notify.hid = hidSource;            /* Source handler ID         */
  parm_notify.hstream = hstream;          /* Stream handle             */

  parm_notify.ulFlags = BUF_GETEMPTY;     /* Get an empty buffer       */
  parm_notify.ulGetNumEntries = 1;        /* Number of buffers to get  */
  parm_notify.ulRetNumEntries = 0;        /* Not returning any buffers */
  parm_notify.pGetBufTab = &srcbuftab;    /* Pointer to buffer table   */
  parm_notify.pRetBufTab = NULL;          /* Not returning any buffers */

  if (ulRC = SMHEntryPoint (&parm_notify))
     return(ulRC);                               /* Error! */
                            .
                            .
                            .
/*--------------------------------------------------------*/
 *  Fill the buffer with data.
 *
 *    srcbuftab.pBuffer = Pointer to buffer
 *    srcbuftab.ulLength = Length of buffer
 *--------------------------------------------------------*/
                            .
                            .
                            .

/*---------------------------------------------------------*/
 *  Return a full buffer to the Sync/Stream Manager.
 *---------------------------------------------------------*/
  parm_notify.ulFlags = BUF_RETURNFULL;    /* Return a full buffer    */
  parm_notify.ulGetNumEntries = 0;         /* Not getting any buffers */
  parm_notify.ulRetNumEntries = 1;         /* Number of buffers
                                              to return               */
  parm_notify.pGetBufTab = NULL;           /* Not getting any buffers */
  parm_notify.pRetBufTab = &srcbuftab;     /* Pointer to buffer table */

  if (ulRC = SMHEntryPoint (&parm_notify))
     return(ulRC);                               /* Error! */

/*-----------------------------------------------------------------------*/
 *  Target Stream Handler Example
 *----------------------------------------------------------------------*/

#include        "os2.h"
#include        "os2me.h"

  ULONG         ulRC;                    /* Error return code          */
  HID           hidTarget;               /* Target handler ID          */
  HSTREAM       hstream;                 /* Stream handle              */
  PARM_NOTIFY   parm_notify;       /* Notify parameter block     */
  TGTBUFTAB     tgtbuftab;               /* Target buffer table        */
  PSMHFN        SMHEntryPoint;           /* Pointer to SMH entry point */

/*---------------------------------------------------------------------
 *  Request a full buffer from the Sync/Stream Manager.
 *---------------------------------------------------------------------*/
  parm_notify.ulFunction = SMH_NOTIFY;     /* Set function           */
  parm_notify.hid = hidTarget;             /* Target handler ID      */
  parm_notify.hstream = hstream;           /* Stream handle          */
  parm_notify.ulFlags = BUF_GETFULL;    /* Get a full buffer         */
  parm_notify.ulGetNumEntries = 1;         /* Number of buffers to get  */
  parm_notify.ulRetNumEntries = 0;         /* Not returning any buffers */
  parm_notify.pGetBufTab = &tgtbuftab;     /* Pointer to buffer table   */
  parmnotify.pRetBufTab = NULL;           /* Not returning any buffers */

  if (ulRC = SMHEntryPoint (&parm_notify))
     return(ulRC);                               /* Error! */
                            .
                            .
                            .

/*----------------------------------------------------------------------
 *  Drain the buffer of data.
 *
 *    tgtbuftab.pBuffer = Pointer to buffer
 *    tgtbuftab.ulLength = Length of buffer
 *----------------------------------------------------------------------*/
                            .
                            .
                            .
 *-----------------------------------------------------------------------
 *  Return an empty buffer to the Sync/Stream Manager.
 *----------------------------------------------------------------------*/
  parm_notify.ulFlags = BUF_RETURNEMPTY; /* Return an empty buffer     */
  parm_notify.ulGetNumEntries = 0;       /* Not getting any buffers    */
  parm_notify.ulRetNumEntries = 1;       /* Number of buffers to return*/
  parm_notify.pGetBufTab = NULL;         /* Not getting any buffers    */
  parm_notify.pRetBufTab = &tgtbuftab;  /* Pointer to buffer table    */

  if (ulRC = SMHEntryPoint (&parm_notify))
     return(ulRC);                               /* Error! */


[Back: SMH_NOTIFY - Remarks]
[Next: SMH_NOTIFY - Topics]