test: util.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# util.c File Reference

`#include "precomp.h"`

Go to the source code of this file.

## Functions

BOOL | AddLink (PCONV_INFO pcoi, GATOM gaItem, WORD wFmt, WORD wType)
VOID | DeleteLinkCount (PCL_INSTANCE_INFO pcii, PLINK_COUNT pLinkCountDelete)

## Function Documentation

BOOL AddLink | ( | PCONV_INFO | pcoi,
|  | GATOM | gaItem,
|  | WORD | wFmt,
|  | WORD | wType
| ) |

Definition at line 23 of file util.c.

References tagCONV_INFO::aLinks, BOOL, tagCONV_INFO::cLinks, DDEMLAlloc, DDEMLReAlloc, FALSE, tagLINK_COUNT::gaItem, GlobalToLocalAtom(), IncGlobalAtomCount(), IncLocalAtomCount(), tagLINK_COUNT::laItem, tagADVISE_LINK::laItem, LATOM, tagCONV_INFO::laTopic, tagLINK_COUNT::laTopic, tagLINK_COUNT::next, NULL, tagCONV_INFO::pcii, tagCL_INSTANCE_INFO::pLinkCount, tagADVISE_LINK::pLinkCount, SetLastDDEMLError(), tagCONV_INFO::state, tagADVISE_LINK::state, tagLINK_COUNT::Total, TRUE, tagLINK_COUNT::wFmt, tagADVISE_LINK::wFmt, and tagADVISE_LINK::wType.

Referenced by ClRespAdviseAck(), and SvSpontAdvise().

    00028 {
    00029     PADVISE_LINK aLinkNew;
    00030     int cLinks;
    00031     LATOM la;
    00032     PCL_INSTANCE_INFO pcii;
    00033
    00034     /*
    00035      * if the link already exists, update its flags, otherwise create a
    00036      * new one.
    00037      */
    00038
    00039     aLinkNew = pcoi->aLinks;
    00040     cLinks = pcoi->cLinks;
    00041     la = GlobalToLocalAtom(gaItem);     // aLinkNew copy
    00042     while (cLinks) {
    00043         if (aLinkNew->laItem == la && aLinkNew->wFmt == wFmt) {
    00044             aLinkNew->wType = wType;
    00045             aLinkNew->state = 0;
    00046             DeleteAtom(la);
    00047             return TRUE;
    00048         }
    00049         aLinkNew++;
    00050         cLinks--;
    00051     }
    00052
    00053     if (pcoi->aLinks == NULL) {
    00054         aLinkNew = (PADVISE_LINK)DDEMLAlloc(sizeof(ADVISE_LINK));
    00055     } else {
    00056         aLinkNew = (PADVISE_LINK)DDEMLReAlloc(pcoi->aLinks,
    00057                 sizeof(ADVISE_LINK) * (pcoi->cLinks + 1));
    00058     }
    00059     if (aLinkNew == NULL) {
    00060         SetLastDDEMLError(pcoi->pcii, DMLERR_MEMORY_ERROR);
    00061         DeleteAtom(la);
    00062         return FALSE;
    00063     }
    00064     pcoi->aLinks = aLinkNew;
    00065     aLinkNew += pcoi->cLinks;
    00066     pcoi->cLinks++;
    00067
    00068     aLinkNew->laItem = la;
    00069     aLinkNew->wFmt = wFmt;
    00070     aLinkNew->wType = wType;
    00071     aLinkNew->state = 0;
    00072
    00073     if (!(pcoi->state & ST_CLIENT)) {
    00074         /*
    00075          * Add count for this link
    00076          */
    00077         pcii = pcoi->pcii;
    00078
    00079         for (aLinkNew->pLinkCount = pcii->pLinkCount;
    00080                 aLinkNew->pLinkCount;
    00081                     aLinkNew->pLinkCount = aLinkNew->pLinkCount->next) {
    00082             if (aLinkNew->pLinkCount->laTopic == pcoi->laTopic &&
    00083                     aLinkNew->pLinkCount->gaItem == gaItem &&
    00084                     aLinkNew->pLinkCount->wFmt == wFmt) {
    00085                 aLinkNew->pLinkCount->Total++;
    00086                 return(TRUE);
    00087             }
    00088         }
    00089
    00090         /*
    00091          * Not found - add an entry
    00092          */
    00093         aLinkNew->pLinkCount = (PLINK_COUNT)DDEMLAlloc(sizeof(LINK_COUNT));
    00094         if (aLinkNew->pLinkCount == NULL) {
    00095             SetLastDDEMLError(pcoi->pcii, DMLERR_MEMORY_ERROR);
    00096             return FALSE;
    00097         }
    00098         aLinkNew->pLinkCount->next = pcii->pLinkCount;
    00099         pcii->pLinkCount = aLinkNew->pLinkCount;
    00100
    00101         aLinkNew->pLinkCount->laTopic = IncLocalAtomCount(pcoi->laTopic); // LinkCount copy
    00102         aLinkNew->pLinkCount->gaItem = IncGlobalAtomCount(gaItem); // LinkCount copy
    00103         aLinkNew->pLinkCount->laItem = IncLocalAtomCount(la); // LinkCount copy
    00104
    00105         aLinkNew->pLinkCount->wFmt = wFmt;
    00106         aLinkNew->pLinkCount->Total = 1;
    00107         // doesn't matter: aLinkNew->pLinkCount->Count = 0;
    00108     }
    00109
    00110     return TRUE;
    00111 }

VOID DeleteLinkCount | ( | PCL_INSTANCE_INFO | pcii,
|  | PLINK_COUNT | pLinkCountDelete
| ) |

Definition at line 123 of file util.c.

References DDEMLFree, tagLINK_COUNT::gaItem, tagLINK_COUNT::laItem, tagLINK_COUNT::laTopic, tagLINK_COUNT::next, NULL, tagCL_INSTANCE_INFO::pLinkCount, tagLINK_COUNT::Total, and VOID().

Referenced by FreeConversationResources(), and SvSpontUnadvise().

    00126 {
    00127     PLINK_COUNT pLinkCount, pLinkCountPrev;
    00128
    00129     if (--pLinkCountDelete->Total != 0) {
    00130         return;
    00131     }
    00132     pLinkCountPrev = NULL;
    00133     pLinkCount     = pcii->pLinkCount;
    00134     while (pLinkCount) {
    00135
    00136         if (pLinkCount == pLinkCountDelete) {
    00137             GlobalDeleteAtom(pLinkCount->gaItem);
    00138             DeleteAtom(pLinkCount->laItem);
    00139             DeleteAtom(pLinkCount->laTopic);
    00140             if (pLinkCountPrev == NULL) {
    00141                 pcii->pLinkCount = pLinkCount->next;
    00142             } else {
    00143                 pLinkCountPrev->next = pLinkCount->next;
    00144             }
    00145             DDEMLFree(pLinkCount);
    00146             return;
    00147         }
    00148
    00149         pLinkCountPrev = pLinkCount;
    00150         pLinkCount = pLinkCount->next;
    00151     }
    00152 }