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

📄 udfree.c

📁 工业组态软件modbus驱动源代码, 包括帮助文件.共享.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Header: "%n Ver=%v  %f  LastEdit=%w  Locker=%l" */
/* "UDFREE.C Ver=1  5-Nov-97,14:00:00  LastEdit=JIMV  Locker=***_NOBODY_***" */
/***********************************************************************\
*                                                                       *
*       Copyright Wonderware Software Development Corp. 1989-1997       *
*                                                                       *
*               ThisFileName="L:\ww\dde_serv\src\udsample\udfree.c"     *
*               LastEditDate="1997 Nov 05  14:00:00"                    *
*                                                                       *
\***********************************************************************/

#include <windows.h>
#include <windowsx.h>
#include <string.h>

#include "ntconv.h"
#include "hmemcpy.h"
#include "chainmgr.h"
#include "udprot.h"
#include "uddefs.h"
#include "udgetstr.h"
#include "wwassert.h"
#include "ntsrvr.h"

USES_ASSERT

extern CHAIN PortList;

/***********************************************************************/
/** free memory associated with message in queue
    returns pointer to next message in queue, if successful **/

LPUDMSG
WINAPI
UdprotFreeMsg(LPUDMSG lpMsg)
{
    LPUDMSG         lpNextMsg;
    LPSTAT          lpTopic;
    LPPORT          lpPort;

#ifdef DEBUG_CALL_TRAFFIC
    if (Verbose)
        debug("UdprotFreeMsg( %Fp )", lpMsg);
#endif

    if (lpMsg == (LPUDMSG) NULL) {
        /* do nothing, return NULL pointer */
        return (LPUDMSG) NULL;
    }

    /* get pointer to next message in queue, if any */
    lpNextMsg = (LPUDMSG) lpMsg->mmChainLink.next_item.ptr;

    /* get pointer to station for this message */
    lpTopic = lpMsg->mmTopic;
    if (lpTopic != (LPSTAT) NULL) {

        /* check current station messages */
        if (lpTopic->statCurMsg == lpMsg) {
            /* station current message is this message, clear pointer */
            lpTopic->statCurMsg = (LPUDMSG) NULL;
        }
        if (lpTopic->statCurReadMsg == lpMsg) {
            /* station current read message is this message, clear pointer */
            lpTopic->statCurReadMsg = (LPUDMSG) NULL;
        }

        /* get pointer to station port */
        lpPort = lpTopic->statPort;
        if (lpPort != (LPPORT) NULL) {
            /* check current port messages */
            if (lpPort->mbCurMsg == lpMsg) {
                /* port current message is this message, clear pointer */
                lpPort->mbCurMsg = (LPUDMSG) NULL;
                /* indicate port is idle */
                lpPort->mbState = PROT_IDLE;
            }
        }
    }

    /* unlock and free memory for this message structure */
    wwHeap_FreePtr( hHeap, lpMsg);
    /* return pointer to next message in queue, if any */
    return lpNextMsg;
} /* UdprotFreeMsg */

/***********************************************************************/
/* delete a message given its chain link pointer */

BOOL FAR DeleteMessageItem (LPCHAINLINK chain_link)
{
    BOOL status;

    /* initialize return value */
    status = FALSE;

    /* check whether pointer is null */
    if (chain_link)
    {
        /* deactivate message and free its memory */
        UdprotFreeMsg((LPUDMSG) chain_link);
        status = TRUE;
    }
    /* indicate whether message was found and deleted */
    return (status);
} /* DeleteMessageItem */

/***********************************************************************/
/** free memory associated with station in list
    return pointer to next station in list, if successful **/

LPSTAT
WINAPI
UdprotFreeTopic(LPSTAT lpTopic)
{
    LPSTAT          lpNextTopic;

    if (lpTopic == (LPSTAT) NULL) {
        /* do nothing, return NULL pointer */
        return (LPSTAT) NULL;
    }

    /* get pointer to next station in list, if any */
    lpNextTopic = (LPSTAT) lpTopic->statChainLink.next_item.ptr;

    /* free any symbol table associated with this station */
    DeleteExtArray (&lpTopic->statSymTab);    /* free the Symbol Table */
    DeleteExtArray (&lpTopic->statSymInd);    /* free the array of indexes */

    /* free any read messages associated with this station */
    DeleteChain (&lpTopic->statReadMsgList, DeleteMessageItem);

    /* free any write messages associated with this station */
    DeleteChain (&lpTopic->statWriteMsgList, DeleteMessageItem);

    /* unlock and free memory for this station structure */
    wwHeap_FreePtr( hHeap, lpTopic);
    /* return pointer to next station */
    return lpNextTopic;
} /* UdprotFreeTopic */

/***********************************************************************/
/* delete a station given its chain link pointer */

BOOL FAR DeleteStationItem (LPCHAINLINK chain_link)
{
    BOOL status;

    /* initialize return value */
    status = FALSE;

    /* check whether pointer is null */
    if (chain_link)
    {
        /* deactivate station and free its memory */
        UdprotFreeTopic((LPSTAT) chain_link);
        status = TRUE;
    }
    /* indicate whether station was found and deleted */
    return (status);
} /* DeleteStationItem */

/***********************************************************************/
/** free memory associated with port in list
    return pointer to next port in list, if successful **/

LPPORT
WINAPI
UdprotFreePort(LPPORT lpPort)
{
    LPPORT          lpNextPort;

    if (lpPort == (LPPORT) NULL) {
        /* do nothing, return NULL pointer */
        return (LPPORT) NULL;
    }

    /* get pointer to next port, if any */
    lpNextPort = (LPPORT) lpPort->mbChainLink.next_item.ptr;

    /* free any stations associated with the port */
    DeleteChain (&lpPort->mbTopicList, DeleteStationItem);

    /* shut down port */
    ClosePort(lpPort);

    /* unlock and free memory for this port structure */
    wwHeap_FreePtr( hHeap, lpPort);
    /* return pointer to next port */
    return lpNextPort;
} /* UdprotFreePort */

/***********************************************************************/
/* deactivate and delete a port given its chain link pointer */

BOOL FAR DeletePortItem (LPCHAINLINK chain_link)
{
    BOOL status;

    /* initialize return value */
    status = FALSE;

    /* check whether pointer is null */
    if (chain_link)
    {
        /* deactivate port and free its memory */
        UdprotFreePort((LPPORT) chain_link);
        status = TRUE;
    }
    /* indicate whether port was found and deleted */
    return (status);
} /* DeletePortItem */

/***********************************************************************/
/** free memory associated with a symbol table entry
    given the topic and the symbol pointer **/

BOOL
WINAPI
UdprotFreeSymEnt(LPSTAT   lpTopic,
                 SYMPTR   lpSymEnt)
{
    assert(lpTopic);
    assert(lpSymEnt);

#ifdef DEBUG_CALL_TRAFFIC
    if (Verbose)
        debug("UdprotFreeSymEnt( %Fp, %ul )",
              lpTopic, (unsigned long) lpSymEnt->msIndex);
#endif

    /****************************************************************\
       The symbol table entry has already been removed from the list
       of symbols in use and returned to the list of unused symbols.
       This can be left as is until the server is shut down,
       or you can add code to shrink the size of the symbol table.
    \****************************************************************/

    return TRUE;
} /* UdprotFreeSymEnt */

/***********************************************************************/
/** free symbol table entry in symbol table for indicated station
    return TRUE if successful **/

⌨️ 快捷键说明

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