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

📄 ss_msg.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
📖 第 1 页 / 共 5 页
字号:
        while (numBytes--)
            *dBuf->b_wptr++ = *cptr++;
        tmp = tmp->b_cont;
    }
    minfo2->len = minfo1->len;
    /* set the endptr and b_cont of dstBuf to point to dBuf */
    minfo2->endptr = dBuf;
    (*dstBuf)->b_cont = dBuf;

    RETVALUE(ROK);
}



/*
*
*       Fun:   SAddMsgRef
*
*       Desc:  This function is used to copy a message into
*              a new region and or pool of memory.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*              ROUTRES  - failed, out of resources (optional)
*
*       Notes: None
*
*       File:  ss_msg.c
*
*/
#ifdef ANSI
PUBLIC S16 SAddMsgRef
(
Buffer *srcBuf,
Region dstRegion,
Pool dstPool,
Buffer **dstBuf
)
#else
PUBLIC S16 SAddMsgRef(srcBuf, dstRegion, dstPool, dstBuf)
Buffer *srcBuf;
Region dstRegion;
Pool dstPool;
Buffer **dstBuf;
#endif
{
    SsMsgInfo *minfo1;
    SsMsgInfo *minfo2;
    Buffer *tmp;
    Buffer *dBuf;
    Buffer *curblk;
    Buffer *newblk;
    Buffer *prevblk;
    Data *cptr;
    MsgLen numBytes;

    TRC1(SAddMsgRef)

#if (ERRCLASS & ERRCLS_INT_PAR)
    if (!srcBuf)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS282, ERRZERO, "SAddMsgRef : Null Buffer");
        RETVALUE(RFAILED);
    }
    if (srcBuf->b_datap->db_type != SS_M_PROTO)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS283, ERRZERO, "SAddMsgRef : Incorrect\
                                                   buffer type");
        RETVALUE(RFAILED);
    }
#endif

    /* allocate a message buffer */
    if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
    {
#if (ERRCLASS & ERRCLS_DEBUG)
        SSLOGERROR(ERRCLS_DEBUG, ESS284, ERRZERO, "SAddMsgRef : SGetMsg failed");
#endif
        RETVALUE(RFAILED);
    }
    /* get the SsMsgInfo from srcBuf */
    minfo1 = (SsMsgInfo*) srcBuf->b_rptr;

    /* get the SsMsgInfo from srcBuf */
    minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;

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

    /* if srcBuf and dstBuf belong to the same region, increment the reference
     * count
     */
    if (dstRegion == minfo1->region)
    {
        newblk = NULLP;
        curblk = NULLP;
        prevblk = NULLP;

        while (tmp)
        {
            if ((curblk = ssDupB(tmp)) == NULLP)
            {
                while (newblk)
                {
                    curblk = newblk->b_cont;
                    (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
                    newblk = curblk;
                }
                (Void) SPutMsg(*dstBuf);
                RETVALUE(ROUTRES);
            }

            if (!prevblk)
                newblk = curblk;
            else
                prevblk->b_cont = curblk;
            prevblk = curblk;

            tmp = tmp->b_cont;
        }
        if (curblk)
            curblk->b_cont = NULLP;

        minfo2->len = minfo1->len;
        minfo2->endptr = curblk;
        (*dstBuf)->b_cont = newblk;

        RETVALUE(ROK);
    }

    /* allocate a data buffer */
    if (ssGetDBufOfSize(dstRegion, minfo1->len, &dBuf) != ROK)
    {
        SSLOGERROR(ERRCLS_DEBUG, ESS285, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
                 failed");
        RETVALUE(ROUTRES);
    }
    dBuf->b_datap->db_type = SS_M_DATA;

    while (tmp)
    {
        numBytes = tmp->b_wptr - tmp->b_rptr;
        cptr = tmp->b_rptr;
        while (numBytes--)
            *dBuf->b_wptr++ = *cptr++;
        tmp = tmp->b_cont;
    }
    minfo2->len = minfo1->len;
    /* set the endptr and b_cont of dstBuf to point to dBuf */
    minfo2->endptr = dBuf;
    (*dstBuf)->b_cont = dBuf;

    RETVALUE(ROK);
}


/*
*
*       Fun:   SGetDBuf
*
*       Desc:  This function allocates a buffer from the dynamic
*              memory pool indicated by the caller.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*              ROUTRES  - failed, out of resources (optional)
*
*       Notes: The dynamic memory pools are used to create and
*              manipulate messages.
*
*              SGetDBuf is never called by a protocol layer.
*
*              SGetDBuf assumes that interrupts are already disabled.
*
*       File:  ss_msg.c
*
*/

#ifdef ANSI
PUBLIC S16 SGetDBuf
(
Region region,              /* region id */
Pool pool,                  /* pool id */
Buffer **bufPtr
)
#else
PUBLIC S16 SGetDBuf(region, pool, bufPtr)
Region region;              /* region id */
Pool pool;                  /* pool id */
Buffer **bufPtr;            /* pointer to buffer */
#endif
{
    Size size;
    Size mdsize;
    Data *data;
    SsDblk *dptr;
    SsRegionEntry *regp;

    TRC1(SGetDBuf)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check buffer pointer */
    if (!bufPtr)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS286, ERRZERO, "SGetDBuf : Null Buffer");
        RETVALUE(RFAILED);
    }
    if (region >= SS_MAX_REGS)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS287, ERRZERO, "SGetDBuf : Invalid region\
                                                   id");
        RETVALUE(RFAILED);
    }

    if (pool >= SS_MAX_POOLS_PER_REG)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS288, ERRZERO, "SGetDBuf : Invalid pool id");
        RETVALUE(RFAILED);
    }
#endif

    regp = &osCp.regionTbl[region];

#if (ERRCLASS & ERRCLS_DEBUG)
    if (regp->poolTbl[pool].type != SS_POOL_DYNAMIC)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS289, ERRZERO,
                   "SGetDBuf : Invalid pool type");
        RETVALUE(RFAILED);
    }
#endif

    /* get the size from region/pool */
    size = regp->poolTbl[pool].u.dpool.size;

    mdsize = MDBSIZE;

    /* out board memory */
    if (regp->flags & SS_OUTBOARD_FLAG)
    {
        /* allocate memory for data buffer */
        if (SAlloc(region, &size, 0, &data) != ROK)
        {
            RETVALUE(ROUTRES);
        }
        if (SAlloc(SS_DFLT_REGION, &mdsize, 0, (Data **) bufPtr) != ROK)
        {
            SFree(region, (Data *) data, size);
            RETVALUE(ROUTRES);
        }
    } else
    {
        mdsize += size;
        if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
        {
            RETVALUE(ROUTRES);
        }
        data = (Data *) (*bufPtr) + MDBSIZE;
        size = mdsize - MDBSIZE;
    }

    dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);

    INITB((*bufPtr), dptr, data, size, NULLP)

    RETVALUE(ROK);
}


/*
*
*       Fun:   SGetDBufBySize
*
*       Desc:  This function allocates a buffer from the dynamic
*              memory pool indicated by the caller.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*              ROUTRES  - failed, out of resources (optional)
*
*       Notes: The dynamic memory pools are used to create and
*              manipulate messages.
*
*              SGetDBufBySize is never called by a protocol layer.
*
*              SGetDBufBySize assumes that interrupts are already disabled.
*
*       File:  ss_msg.c
*
*/

#ifdef ANSI
PUBLIC S16 SGetDBufBySize
(
Region region,              /* region id */
Pool pool,                  /* pool id */
Size size,                  /* buffer size */
Buffer **bufPtr
)
#else
PUBLIC S16 SGetDBuf(region, pool, size, bufPtr)
Region region;              /* region id */
Pool pool;                  /* pool id */
Size size;                  /* buffer size */
Buffer **bufPtr;            /* pointer to buffer */
#endif
{
    Size mdsize;
    Data *data;
    SsDblk *dptr;
    SsRegionEntry *regp;

    TRC1(SGetDBuf)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check buffer pointer */
    if (!bufPtr)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS286, ERRZERO, "SGetDBuf : Null Buffer");
        RETVALUE(RFAILED);
    }
    if (region >= SS_MAX_REGS)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS287, ERRZERO, "SGetDBuf : Invalid region\
                                                   id");
        RETVALUE(RFAILED);
    }

    if (pool >= SS_MAX_POOLS_PER_REG)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS288, ERRZERO, "SGetDBuf : Invalid pool id");
        RETVALUE(RFAILED);
    }
    if (0 == size )
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS288, ERRZERO, "SGetDBuf : Invalid size");
        RETVALUE(RFAILED);
    }

#endif

    regp = &osCp.regionTbl[region];

#if (ERRCLASS & ERRCLS_DEBUG)
    if (regp->poolTbl[pool].type != SS_POOL_DYNAMIC)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS289, ERRZERO,
                   "SGetDBuf : Invalid pool type");
        RETVALUE(RFAILED);
    }
#endif

    mdsize = MDBSIZE;

    /* out board memory */
    if (regp->flags & SS_OUTBOARD_FLAG)
    {
        /* allocate memory for data buffer */
        if (SAlloc(region, &size, 0, &data) != ROK)
        {
            RETVALUE(ROUTRES);
        }
        if (SAlloc(SS_DFLT_REGION, &mdsize, 0, (Data **) bufPtr) != ROK)
        {
            SFree(region, (Data *) data, size);
            RETVALUE(ROUTRES);
        }
    } else
    {
        mdsize += size;
        if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
        {
            RETVALUE(ROUTRES);
        }
        data = (Data *) (*bufPtr) + MDBSIZE;
        size = mdsize - MDBSIZE;
    }

    dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);

    INITB((*bufPtr), dptr, data, size, NULLP)

    RETVALUE(ROK);
}




/*
*
*       Fun:   SPutDBuf
*
*       Desc:  This function deallocates a buffer back to the
*              dynamic memory pool indicated by the caller.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*
*       Notes: The dynamic memory pools are used to create and
*              manipulate messages.
*
*              SPutDBuf is never called by a protocol layer.
*
*              SPutDBuf assumes that interrupts are already disabled.
*
*       File:  ss_msg.c
*
*/

#ifdef ANSI
PUBLIC S16 SPutDBuf
(
Region region,
Pool pool,
Buffer *buf
)
#else
PUBLIC S16 SPutDBuf(region, pool, buf)
Region region;
Pool pool;
Buffer *buf;
#endif
{
    Buffer *tmp;
    SsRegionEntry *regp;

    TRC2(SPutDBuf);


#if (ERRCLASS & ERRCLS_INT_PAR)
    if (region >= SS_MAX_REGS)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS290, ERRZERO, "SPutDBuf:Invalid region");
        RETVALUE(RFAILED);
    }

    if (pool >= SS_MAX_POOLS_PER_REG)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS291, ERRZERO, "SPutDBuf:Invalid pool");
        RETVALUE(RFAILED);
    }

    if (buf == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS292, ERRZERO, "SPutDBuf:Null pointer");
        RETVALUE(RFAILED);
    }

    if (buf->b_datap->db_type != SS_M_DATA)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS293, ERRZERO, "SPutDBuf:Incorrect\
                 buffer type");
        RETVALUE(RFAILED);
    }
#endif

    regp = &osCp.regionTbl[region];

#if (ERRCLASS & ERRCLS_DEBUG)
    if (regp->poolTbl[pool].type != SS_POOL_DYNAMIC)
    {
        SSLOGERROR(ERRCLS_DEBUG, ESS294, ERRZERO, "SPutDBuf:Invalid pool type");
        RETVALUE(RFAILED);
    }
#endif
    /* if reference count falls to zero */
    ssLockTsk();
    if (!--buf->b_datap->db_ref)
    {
        ssUnlockTsk();
        /* if the buffer, buf is a message blk obtained during dupb */
        if (buf != (SsMblk *) (((Data*) (buf->b_datap)) - MBSIZE))
        {
            tmp = (SsMblk *) (((Data*) (buf->b_datap)) - MBSIZE);
            SFree(SS_DFLT_REGION, (Data *) buf, MDBSIZE);
            buf = tmp;
        }
        /* if not outboard memory, release MDBSIZE + data buffer */
        if (!(regp->flags & SS_OUTBOARD_FLAG))
            SFree(region, (Data *) buf, MDBSIZE +
                  buf->b_datap->db_lim - buf->b_datap->db_base);
        else
        {
            SFree(region, (Data *) buf->b_datap->db_base,
                  buf->b_datap->db_lim - buf->b_datap->db_base);
            SFree(SS_DFLT_REGION, (Data *) buf, MDBSIZE);
        }
    } else
    {
        ssUnlockTsk();
        /* if the buffer, buf is a message blk obtained during dupb, */
        /* release the message blk */
        if (buf != (SsMblk *) (((Data*) (buf->b_datap)) - MBSIZE))
            SFree(SS_DFLT_REGION, (Data *) buf, MDBSIZE);
    }
    RETVALUE(ROK);
}


/*
*
*       Fun:   SCatMsg
*
*       Desc:  This function will concatenate the two specified messages
*              into one message.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*
*

⌨️ 快捷键说明

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