void osDestroyCmdLineOptHandler(pvoid handler) { osAssert(handler); CSimpleOpt * pArgs = (CSimpleOpt *)((CmdOptHandle *)handler)->pArgs; osFree(((CmdOptHandle *)handler)->myArgv); osFree(((CmdOptHandle *)handler)->pOptions); delete pArgs; }
/** * osFreeVMMembers * * Frees the different memory objects for a given VM instance data object: * * @return OK if successful else ERR_ERROR */ IEC_UINT osFreeVMMembers(STaskInfoVM *pVM) { IEC_UINT uRes = OK; #if defined(RTS_CFG_FFO) uRes |= osFree((IEC_DATA **)&pVM->Local.pStack); uRes |= osFree((IEC_DATA **)&pVM->Local.pBuffer); #endif RETURN(uRes); }
/** * dbiFinalize * */ IEC_UINT dbiFinalize(STaskInfoVMM *pVMM) { SDBIInfo *pDBI = &pVMM->DBI; IEC_UINT uRes = OK; if (pDBI->bInitialized == FALSE) { RETURN(OK); } /* Free instances */ uRes = dbiDeleteInstance(pDBI->pInstRoot); if (uRes != OK) { RETURN(uRes); } uRes = osFree((IEC_DATA OS_LPTR **)&pDBI->pInstRoot); if (uRes != OK) { RETURN(uRes); } /* Free types */ uRes = dbiDeleteTypes(pDBI->uTypes, pDBI->pTypes); if (uRes != OK) { RETURN(uRes); } uRes = osFree((IEC_DATA OS_LPTR **)&pDBI->pTypes); if (uRes != OK) { RETURN(uRes); } if ((VMF_FILE)pDBI->hInst != VMF_INVALID_HANDLE) { xxxClose(pDBI->hInst); pDBI->hInst = (IEC_UDINT)VMF_INVALID_HANDLE; } if ((VMF_FILE)pDBI->hVar != VMF_INVALID_HANDLE) { xxxClose(pDBI->hVar); pDBI->hVar = (IEC_UDINT)VMF_INVALID_HANDLE; } pDBI->bInitialized = FALSE; RETURN(OK); }
/** * osCreateImageReg * * Creates memory for IO layer process image information. * * STaskInfoVM.Task.pIR sizeof(SImageReg) * * @return OK if successful else error number */ SImageReg *osCreateImageReg(STaskInfoVM *pVM, IEC_UINT uTasks) { #if defined(RTS_CFG_FFO) if (g_uTasks != uTasks) { if (g_pImageReg != NULL) { IEC_UINT uRes = osFree((IEC_DATA **)&g_pImageReg); TR_RET(uRes); uRes++; } } g_uTasks = uTasks; if (g_pImageReg == NULL) { g_pImageReg = (SImageReg *)(osMalloc(sizeof(SImageReg) * uTasks)); if (g_pImageReg == NULL) { TR_RET(ERR_OUT_OF_MEMORY); return NULL; } } #endif return g_pImageReg + pVM->usTask; }
/** * visCheckProject * * Verifies if the currently loaded project ID of this library instance is still * the same as of the project ID of the attached ATCMControl Run Time System. * * Important: If this function fails, all stored addresses must be abandoned and * reloaded again from the attached RTS. (Possibly a new download to the remote * RTS has been done.) * * return OK if successful, else error number. * */ VIS_UINT visCheckProject(void) { SVisInfo *pVI = &g_VI; IEC_UINT uRes = OK; IEC_DATA *pProjectID; if (pVI->bInitialized == FALSE) { RETURN(ERR_INIT); } if (pVI->bLogin == FALSE) { RETURN(ERR_LOGIN); } uRes = domGetProjVersion(pVI, &pProjectID); if (uRes != OK) { RETURN(uRes); } uRes = (IEC_UINT)(OS_MEMCMP(pVI->pProjectID, pProjectID, VMM_GUID) == 0 ? OK : ERR_WRONG_PROJECT); osFree(&pProjectID); return uRes; }
/** * visLogin * * Login to a connected remote ATCMControl Run Time System and retrieve the actual * project ID from the attached RTS. * * This function will fail, if no project is loaded on the attached RTS. * * return OK if successful, else error number. */ VIS_UINT visLogin(void) { SVisInfo *pVI = &g_VI; IEC_UINT uRes = OK; IEC_DATA *pData = NULL; if (pVI->bInitialized == FALSE) { RETURN(ERR_INIT); } if (pVI->bLogin == TRUE) { visLogout(); } uRes = domGetProjVersion(pVI, &pData); if (uRes != OK) { RETURN(uRes); } OS_MEMCPY(pVI->pProjectID, pData, VMM_GUID); osFree(&pData); uRes = domLogin(pVI, pVI->pProjectID); if (uRes == OK) { pVI->bLogin = TRUE; } RETURN(uRes); }
void sortlist(struct jbList *list) { struct jbNode *jb,**buf,**work; uint32_t count=0; for(jb=list->First;jb;jb=jb->Next) count++; if(count < 2) return; if(!(buf=(struct jbNode **)osAlloc(count * sizeof(struct jbNode *)))) return; work=buf; for(jb=list->First;jb;jb=jb->Next) *work++=jb; qsort(buf,(size_t)count,(size_t)sizeof(struct jbNode *),sortcompare); jbNewList(list); for(work=buf;count--;) jbAddNode(list,*work++); osFree(buf); }
bool SortNodes(struct jbList *list) { struct NodeStatsNode *sn,**buf,**work; uint32_t nc; nc=0; for(sn=(struct NodeStatsNode *)list->First;sn;sn=sn->Next) nc++; if(nc==0) return(TRUE); /* Nothing to sort */ if(!(buf=(struct NodeStatsNode **)osAlloc(nc*sizeof(struct NodeStatsNode *)))) return(FALSE); work=buf; for(sn=(struct NodeStatsNode *)list->First;sn;sn=sn->Next) *work++=sn; qsort(buf,nc,ptrsize,CompareNodes); jbNewList(list); for(work=buf;nc--;) jbAddNode(list,(struct jbNode *)*work++); osFree(buf); return(TRUE); }
char *PrintFlowSize(struct fileentry *fe) { static char buf[50]; char fullfile[200],line[200]; osFile os; struct osFileEntry *osfe; uint32_t files,bytes; files=0; bytes=0; MakeFullPath(cfg_Dir,fe->file,fullfile,200); if(!(os=osOpen(fullfile,MODE_OLDFILE))) { sprintf(buf,"?/?"); return(buf); } while(osFGets(os,line,200)) { strip(line); if(line[0]) { if(line[0] == '#' || line[0] == '^' || line[0] == '-') strcpy(line,&line[1]); if(stricmp(GetFilePart(line),line) == 0) { /* No path specified */ MakeFullPath(fe->dir,line,fullfile,200); osfe=osGetFileEntry(fullfile); } else { osfe=osGetFileEntry(line); } if(osfe) { files++; bytes+=osfe->Size; TotalFiles++; TotalBytes+=osfe->Size; osFree(osfe); } } } osClose(os); sprintf(buf,"%s/%u",unit(bytes),files); return(buf); }
void CloseDupeDB(void) { osFile newfh; uint32_t c; char duptemp[200]; if(!dupechanged) { osClose(dupefh); return; } strcpy(duptemp,config.cfg_DupeFile); strcat(duptemp,".tmp"); if(!(newfh=osOpen(duptemp,MODE_NEWFILE))) { uint32_t err=osError(); LogWrite(1,SYSTEMERR,"Failed to open temporary dupe file %s for writing",duptemp); LogWrite(1,SYSTEMERR,"Error: %s",osErrorMsg(err)); osFree(dupebuf); osClose(dupefh); return; } osWrite(newfh,DUPES_IDENTIFIER,4); for(c=dupeentrynum;c<dupeentrymax;c++) copydupe(c,dupefh,newfh); for(c=0;c<dupeentrynum;c++) copydupe(c,dupefh,newfh); osClose(dupefh); osClose(newfh); osFree(dupebuf); dupechanged=FALSE; osDelete(config.cfg_DupeFile); osRename(duptemp,config.cfg_DupeFile); return; }
void DisplayFlowContents(struct fileentry *fe) { char size[40],*todo; char fullfile[200],line[200]; osFile os; struct osFileEntry *osfe; MakeFullPath(cfg_Dir,fe->file,fullfile,200); if(!(os=osOpen(fullfile,MODE_OLDFILE))) { printf("Failed to open file\n"); } else { while(osFGets(os,line,200)) { strip(line); if(line[0]) { todo=""; if(line[0] == '#' || line[0] == '^') todo="(To be truncated)"; if(line[0] == '-') todo="(To be deleted)"; if(line[0] == '#' || line[0] == '^' || line[0] == '-') strcpy(line,&line[1]); if(stricmp(GetFilePart(line),line) == 0) { /* No path specified */ MakeFullPath(fe->dir,line,fullfile,200); osfe=osGetFileEntry(fullfile); } else { osfe=osGetFileEntry(line); } strcpy(size,"Not found"); if(osfe) { sprintf(size, "%s", unit(osfe->Size)); osFree(osfe); } printf(" %-39.39s %10s %s\n",line,size,todo); } } osClose(os); } printf("\n"); }
/** * dbiDeleteInstance * */ static IEC_UINT dbiDeleteInstance(SDBIInstance *pInst) { IEC_UINT uRes = OK; IEC_UINT i; for (i = 0; i < pInst->uChildren; i++) { if (pInst->ppChildren == NULL || pInst->ppChildren[i] == NULL) { /* Child not loaded */ continue; } uRes = dbiDeleteInstance(pInst->ppChildren[i]); if (uRes != OK) { RETURN(uRes); } uRes = osFree((IEC_DATA OS_LPTR **)&pInst->ppChildren[i]); if (uRes != OK) { RETURN(uRes); } } uRes = osFree((IEC_DATA OS_LPTR **)&pInst->szName); if (uRes != OK) { RETURN(uRes); } if (pInst->ppChildren != NULL) { uRes = osFree((IEC_DATA OS_LPTR **)&pInst->ppChildren); if (uRes != OK) { RETURN(uRes); } } RETURN(uRes); }
/** * osFreeTaskInfoVM * * Free the VM instance data object. * * @return OK if successful else ERR_ERROR */ IEC_UINT osFreeTaskInfoVM(STaskInfoVM *pVM) { IEC_UINT uRes = OK; #if defined(RTS_CFG_FFO) uRes = osFree((IEC_DATA **)&pVM); #endif RETURN(uRes); }
pvoid osCreateCmdLineOptHandler(int argc, char ** argv, CmdOpt * pCmdOpt, uint32 nNumOfOpts) { int myArgc = argc + sizeof(g_rgFlags) / sizeof(CSimpleOpt::SOption) - 1; CmdOptHandle * handler = new CmdOptHandle(); if (handler == NULL) return NULL; handler->myArgv = (char**)osMalloc(sizeof(char*)*(myArgc)); uint32 i = 0; if (handler->myArgv == NULL) return NULL; memcpy(handler->myArgv, argv, sizeof(char*)*argc); while (g_rgFlags[i].nId != -1) { handler->myArgv[i + argc] = const_cast<char*>(g_rgFlags[i].pszArg); i++; } osAssert((i + argc) == myArgc); handler->pOptions = (CSimpleOpt::SOption*) osMalloc(sizeof(CSimpleOpt::SOption)*(nNumOfOpts + 1)); if (handler->pOptions == NULL) { osFree(handler->myArgv); return NULL; } memcpy(handler->pOptions, pCmdOpt, sizeof(CSimpleOpt::SOption)*(nNumOfOpts)); handler->pOptions[nNumOfOpts] = g_endOpt; int nFlags = SO_O_USEALL; handler->pArgs = new CSimpleOpt(myArgc, handler->myArgv, handler->pOptions, SO_O_NOERR | SO_O_EXACT); if (handler->pArgs == NULL) { osFree(handler->myArgv); osFree(handler->pOptions); handler->myArgv = NULL; handler->pOptions = NULL; return NULL; } return handler; }
bool Sort(struct jbList *list,char sortmode) { uint32_t nc; struct StatsNode *sn,**buf,**work; nc=0; for(sn=(struct StatsNode *)list->First;sn;sn=sn->Next) nc++; if(nc==0) return(TRUE); /* Nothing to sort */ if(!(buf=(struct StatsNode **)osAlloc(nc*sizeof(struct StatsNode *)))) return(FALSE); work=buf; for(sn=(struct StatsNode *)list->First;sn;sn=sn->Next) *work++=sn; switch(sortmode) { case 'a': qsort(buf,nc,ptrsize,CompareAlpha); break; case 't': qsort(buf,nc,ptrsize,CompareTotal); break; case 'm': qsort(buf,nc,ptrsize,CompareMsgsDay); break; case 'd': qsort(buf,nc,ptrsize,CompareFirstTime); break; case 'l': qsort(buf,nc,ptrsize,CompareLastTime); break; case 'u': qsort(buf,nc,ptrsize,CompareDupes); break; } jbNewList(list); for(work=buf;nc--;) jbAddNode(list,(struct jbNode *)*work++); osFree(buf); return(TRUE); }
/** * dbiDeleteType * */ static IEC_UINT dbiDeleteType(SDBIType *pType) { IEC_UINT uRes = OK; IEC_UINT i; IEC_UINT uElem; if (pType->pMember == NULL) { RETURN(OK); } if ((pType->uType & DBI_DTM_ARRAY) != 0 && (pType->uType & DBI_DTM_SIMPLE) != 0) { /* For simple arrays we only have the first array element stored * within the Debug Information. */ uElem = 1; } else { uElem = pType->uMember; } for (i = 0; i < uElem; i++) { uRes = osFree((IEC_DATA OS_LPTR **)&pType->pMember[i].szName); if (uRes != OK) { RETURN(uRes); } } uRes = osFree((IEC_DATA OS_LPTR **)&pType->pMember); RETURN(uRes); }
/** * visFinalize * * Closes any connection to a remote 4C Run Time System and skips any * stored configuration data. * * return OK if successful, else error number. */ VIS_UINT visFinalize(void) { SVisInfo *pVI = &g_VI; IEC_UINT uRes = OK; if (pVI->bLogin == TRUE) { uRes = visLogout(); } uRes = domCloseComm(pVI); osFree(&pVI->pCmdBuff); pVI->bInitialized = FALSE; RETURN(uRes); }
void addentry(char *dir,char *file,uint32_t type,struct Node4D *boss,bool flow) { struct osFileEntry *fe; struct fileentry *entry; struct Node4D n4d; char buf[200]; char buf2[200]; uint32_t hex; hex=hextodec(file); if(boss) { Copy4D(&n4d,boss); n4d.Point = hex; } else { n4d.Zone = cfg_Zone; n4d.Net = NET(hex); n4d.Node = NODE(hex); n4d.Point = 0; } if(Compare4DPat(&cfg_Pattern,&n4d)!=0) return; if(dir) MakeFullPath(dir,file,buf,200); else mystrncpy(buf,file,200); MakeFullPath(cfg_Dir,buf,buf2,200); if(!(fe=osGetFileEntry(buf2))) { return; } if(!(entry=osAlloc(sizeof(struct fileentry)))) { osFree(fe); return; } Copy4D(&entry->Node,&n4d); if(dir) { MakeFullPath(dir,file,entry->file,100); MakeFullPath(cfg_Dir,dir,entry->dir,100); } else { mystrncpy(entry->file,file,100); mystrncpy(entry->dir,cfg_Dir,100); } mystrncpy(entry->file,buf,100); entry->size=fe->Size; entry->date=fe->Date; entry->type=type; entry->flow=flow; jbAddNode(&list,(struct jbNode *)entry); osFree(fe); }
/** * visFree * * Releases (frees) memory. All memory retrieved from the VisuComm library must * be release with this function. * * IO ppMemory Pointer to pointer to memory to be freed. (Original pointer * will be nulled after the memory release.) * * return void. * */ void visFree(VIS_DATA **ppMemory) { osFree(ppMemory); }