⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ss_msg.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifdef ANSI
PUBLIC S16 SRemPstMsg
(
Data *dataPtr,              /* pointer to data */
Buffer *mBuf
)
#else
PUBLIC S16 SRemPstMsg(dataPtr, mBuf)
Data *dataPtr;              /* pointer to data */
Buffer *mBuf;               /* message buffer */
#endif
{
    SsMsgInfo *minfo;
    Buffer *tmp;
    Buffer *last;

    TRC1(SRemPstMsg)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check data pointer */
    if (dataPtr == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS244, ERRZERO, "SRemPstMsg : Null Buffer");
        RETVALUE(RFAILED);
    }
    /* check message buffer */
    if (mBuf == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS245, ERRZERO, "SRemPstMsg : Null Buffer");
        RETVALUE(RFAILED);
    }
    if (mBuf->b_datap->db_type != SS_M_PROTO)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS246, ERRZERO, "SRemPstMsg : Incorrect\
                                                   buffer type");
        RETVALUE(RFAILED);
    }
#endif

    /* get the SsMsgInfo */
    minfo = (SsMsgInfo*) mBuf->b_rptr;

    if (!(last = minfo->endptr))
        RETVALUE(ROKDNA);

    /* read databyte into dataPtr and decrement write ptr */
    *dataPtr = *--last->b_wptr;

    /* if all data is exhausted, release the blk */
    if (last->b_rptr == last->b_wptr)
    {
        for (tmp = mBuf; tmp->b_cont != last;)
            tmp = tmp->b_cont;
        tmp->b_cont = NULLP;
        (Void) SPutDBuf(minfo->region, minfo->pool, last);

        /* update endptr */
        if (mBuf->b_cont)
            minfo->endptr = tmp;
        else
            minfo->endptr = NULLP;
    }
    /* update SsMsgInfo */
    minfo->len--;

    RETVALUE(ROK);
}


/*
*
*       Fun:   SRemPreMsgMult
*
*       Desc:  This function copies and then removes consecutive bytes of
*              data from the beginning of a message.
*
*       Ret:   ROK      - ok
*              ROKDNA   - ok, data not available
*              RFAILED  - failed, general (optional)
*
*       Notes: if message is empty: message is unchanged. return is ok,
*              data not available.
*
*              if the destination buffer is NULL, data is not copied.
*
*              if message is not empty: data is removed from front of
*              message, data is returned by destination pointer. message
*              length is decremented. return is ok.
*
*              the first byte of data read from the message will be placed
*              in the destination buffer first (i.e. this was the first byte
*              of the message), the last byte of data read from the message
*              will be placed in the destination buffer last.
*
*       File:  ss_msg.c
*
*/

#ifdef ANSI
PUBLIC S16 SRemPreMsgMult
(
Data *dst,                  /* destination */
MsgLen cnt,                 /* count */
Buffer *mBuf
)
#else
PUBLIC S16 SRemPreMsgMult(dst, cnt, mBuf)
Data *dst;                  /* destination */
MsgLen cnt;                 /* count */
Buffer *mBuf;               /* message buffer */
#endif
{
    SsMsgInfo *minfo;
    Buffer *tmp;
    MsgLen numBytes;

    TRC1(SRemPreMsgMult)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check count */
    if (cnt <= 0)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS247, ERRZERO, "SRemPreMsgMult:Invalid\
                                                   count");
        RETVALUE(RFAILED);
    }
    /* check message buffer */
    if (!mBuf)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS248, ERRZERO, "SRemPreMsgMult:Null Buffer");
        RETVALUE(RFAILED);
    }
    if (mBuf->b_datap->db_type != SS_M_PROTO)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS249, ERRZERO, "SRemPreMsgMult : Incorrect\
                                                   buffer type");
        RETVALUE(RFAILED);
    }
#endif

    /* get the SsMsgInfo */
    minfo = (SsMsgInfo*) mBuf->b_rptr;

    /* check if data present */
    if (minfo->len < cnt)
        RETVALUE(ROKDNA);
    else
        minfo->len -= cnt;

    while (cnt)
    {
        /* get the first SS_M_DATA blk */
        tmp = mBuf->b_cont;

        /* determine the number of bytes to be copy */
        numBytes = MIN(cnt, tmp->b_wptr - tmp->b_rptr);

        /* decrement cnt */
        cnt -= numBytes;

        /* move data into dst */
        if (dst != NULLP)
        {
            while (numBytes--)
                *dst++ = *tmp->b_rptr++;
        }

        if (tmp->b_rptr == tmp->b_wptr)
        {
            mBuf->b_cont = tmp->b_cont;
            (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
        }
    }
    /* update SsMsgInfo */
    if (!minfo->len)
        minfo->endptr = NULLP;

    RETVALUE(ROK);
}

/*
*
*       Fun:   SRemPstMsgMult
*
*       Desc:  This function copies and then removes consecutive bytes of
*              data from the end of a message.
*
*       Ret:   ROK      - ok
*              ROKDNA   - ok, data not available
*              RFAILED  - failed, general (optional)
*
*       Notes: if message is empty: message is unchanged. return is ok,
*              data not available.
*
*              if the destination buffer is NULL, data is not copied.
*
*              if message is not empty: data is removed from front of
*              message, data is returned by destination pointer. message
*              length is decremented. return is ok.
*
*              the first byte of data read from the message will be placed
*              in the destination buffer first (i.e. this was the last byte
*              of the message), the last byte of data read from the message
*              will be placed in the destination buffer last.
*
*       File:  ss_msg.c
*
*/

#ifdef ANSI
PUBLIC S16 SRemPstMsgMult
(
Data *dst,                  /* destination */
MsgLen cnt,                 /* count */
Buffer *mBuf
)
#else
PUBLIC S16 SRemPstMsgMult(dst, cnt, mBuf)
Data *dst;                  /* destination */
MsgLen cnt;                 /* count */
Buffer *mBuf;               /* message buffer */
#endif
{
    SsMsgInfo *minfo;
    Buffer *tmp;
    Buffer *prev;
    MsgLen count;
    MsgLen numBytes;
    Data *cptr;

    TRC1(SRemPstMsgMult)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check count */
    if (cnt <= 0)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS250, ERRZERO, "SRemPstMsgMult:Invalid\
                                                   count");
        RETVALUE(RFAILED);
    }
    /* check message buffer */
    if (mBuf == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS251, ERRZERO, "SRemPstMsgMult:Null Buffer");
        RETVALUE(RFAILED);
    }
    if (mBuf->b_datap->db_type != SS_M_PROTO)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS252, ERRZERO, "SRemPstMsgMult : Incorrect\
                                                   buffer type");
        RETVALUE(RFAILED);
    }
#endif

    /* get the SsMsgInfo */
    minfo = (SsMsgInfo*) mBuf->b_rptr;

    /* check if data present */
    if (minfo->len < cnt)
        RETVALUE(ROKDNA);
    else
    {
        minfo->len -= cnt;
        count = minfo->len;
        prev = mBuf;
        tmp = mBuf->b_cont;
    }

    /* determine blk containing offset, and prev node */
    FIND_OFFSET_AND_PREV(prev, tmp, count)

    if (dst != NULLP)
        dst += cnt;

    while (cnt)
    {
        numBytes = MIN(cnt, (tmp->b_wptr - tmp->b_rptr - count));

        tmp->b_wptr -= numBytes;

        cnt -= numBytes;

        /* copy data */
        cptr = tmp->b_wptr;
        if (dst != NULLP)
        {
            while (numBytes--)
                *--dst = *cptr++;
        }

        if (tmp->b_rptr == tmp->b_wptr)
        {
            prev->b_cont = tmp->b_cont;
            (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
            tmp = prev;
        }
        prev = tmp;
        tmp = tmp->b_cont;

        count = 0;
    }
    if (mBuf == prev)
        minfo->endptr = NULLP;
    else
        minfo->endptr = prev;

    RETVALUE(ROK);
}

/*
*
*       Fun:   SExamMsg
*
*       Desc:  This function copies one byte of data from a message
*              without modifying the message.
*
*       Ret:   ROK      - ok
*              ROKDNA   - ok, data not available
*              RFAILED  - failed, general (optional)
*
*       Notes: index is 0 based and indicates location in message
*
*              if index is less than the length of the message:
*              message is unchanged and data is examined at specified
*              index and returned via pointer to data. message length
*              is unchanged. return is ok.
*
*              if index is greater than or equal to
*              the length of the message: message is unchanged and 0
*              is returned via pointer to data. return is ok, data
*              not available.
*
*       File:  ss_msg.c
*
*/


#ifdef ANSI
PUBLIC S16 SExamMsg
(
Data *dataPtr,              /* pointer to data */
Buffer *mBuf,               /* message buffer */
MsgLen idx
)
#else
PUBLIC S16 SExamMsg(dataPtr, mBuf, idx)
Data *dataPtr;              /* pointer to data */
Buffer *mBuf;               /* message buffer */
MsgLen idx;                 /* index */
#endif
{
    SsMsgInfo *minfo;
    Buffer *tmp;

    TRC1(SExamMsg)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check data pointer */
    if (!dataPtr)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS253, ERRZERO, "SExamMsg : Null Buffer");
        RETVALUE(RFAILED);
    }
    /* check message buffer */
    if (!mBuf)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS254, ERRZERO, "SExamMsg : Null Buffer");
        RETVALUE(RFAILED);
    }
    /* check index */
    if (idx < 0)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS255, ERRZERO, "SExamMsg : Invalid Index");
        RETVALUE(RFAILED);
    }
    if (mBuf->b_datap->db_type != SS_M_PROTO)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS256, ERRZERO, "SExamMsg : Incorrect buffer\
                                                   type");
        RETVALUE(RFAILED);
    }
#endif

    /* get the SsMsgInfo */
    minfo = (SsMsgInfo*) mBuf->b_rptr;

    if (minfo->len <= idx)
    {
        RETVALUE(ROKDNA);
    }

    /* get the first SS_M_DATA blk */
    tmp = mBuf->b_cont;

    /* determine offset */
    FIND_OFFSET(tmp, idx)

    *dataPtr = *(tmp->b_rptr + idx);

    RETVALUE(ROK);
}

/*
*
*       Fun:   SFndLenMsg
*
*       Desc:  This function determines the length of data within
*              a message.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*
*       Notes: length of message is determined, message is unchanged
*              and length is returned via pointer to length. return is ok.
*
*       File:  ss_msg.c
*
*/
#ifdef ANSI
PUBLIC S16 SFndLenMsg
(
REG1 Buffer *mBuf,          /* message buffer */
MsgLen *lngPtr
)
#else
PUBLIC S16 SFndLenMsg(mBuf, lngPtr)
REG1 Buffer *mBuf;          /* message buffer */
MsgLen *lngPtr;             /* pointer to length */
#endif
{
    SsMsgInfo *minfo;

    TRC1(SFndLenMsg)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check message buffer */
    if (mBuf == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS257, ERRZERO, "SFndLenMsg : Null Buffer");
        RETVALUE(RFAILED);
    }
    /* check length pointer */
    if (lngPtr == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS258, ERRZERO, "SFndLenMsg : Null Buffer");
        RETVALUE(RFAILED);
    }
    if (mBuf->b_datap->db_type != SS_M_PROTO)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS259, ERRZERO, "SFndLenMsg : Incorrect\
                                                   buffer type");
        RETVALUE(RFAILED);
    }
#endif

    /* get the SsMsgInfo */
    minfo = (SsMsgInfo*) mBuf->b_rptr;

    /* read length */
    *lngPtr = minfo->len;

    RETVALUE(ROK);
}

/*
*
*       Fun:   SSegMsg
*
*       Desc:  This function will segment one specified message into two
*              messages.
*
*       Ret:   ROK     - ok
*              ROKDNA  - ok, data not available
*              RFAILED - failed, general (optional)
*              ROUTRES - failed, out of resources (optional)
*
*       Notes: message 1 is the original message.
*
*              message 2 is the new message.
*
*              index is 0 based and indicates location in message 1
*              from which message 2 will be created.
*
*              if index is equal to 0: message 2 is created and all data
*              attached to message 1 is moved to message 2. message 1
*              is not returned to memory. return is ok.
*
*              if index is not equal to 0 and less than the length of
*              the message minus 1: message 2 is created, all data
*              attached to message 1 from index (inclusive) is moved to
*              message 2. message 1 contains data from index 0 to index
*              minus 1. return is ok.
*
*              if index is not equal to 0 and greater than or equal to
*              the length of the message minus 1: message 1 is unchanged.
*              message 2 is set to null. return is ok, data not available.
*
*       File:  ss_msg.c
*
*/


#ifdef ANSI
PUBLIC S16 SSegMsg
(
Buffer *mBuf1,              /* message 1 */
MsgLen idx,                 /* index */
Buffer **mBuf2
)
#else
PUBLIC S16 SSegMsg(mBuf1, idx, mBuf2)
Buffer *mBuf1;              /* message 1 */
MsgLen idx;                 /* index */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -