void Optimise_Plc(PLC *plc) { TAG *btag=NULL; // Base Tag for optimized Packet PACKET *packet=NULL; int bfindex=0,findex=0,bfunc=0,func=0; int MaxRealPacketSize=50; int MaxEltByPacket=MaxRealPacketSize; TrieChListe(&(plc->Tags),&compare_plc); LISTE *tags=&(plc->Tags); LISTE *packets=&(plc->Packets); Log(LOG_DEBUG,"Optimise Plc: %s (%d Tags)\n",plc->PlcName,tags->Count); ELEMENT *elt=GetFirst(tags); while (elt!=NULL) { if (btag==NULL) { btag=elt->Data; bfindex=_MBGetC_F_Index(btag->Address); //bfunc=_MBGetC_F_Index(btag->Address); bfunc=FTable[bfindex].Read_Function; elt=GetNext(tags,elt); continue; } else { TAG *tag=elt->Data; findex=_MBGetC_F_Index(btag->Address); //func=_MBGetC_F_Index(tag->Address); func=FTable[findex].Read_Function; if ((bfunc==func)&&(_MBGetAddress(btag->Address)+MaxEltByPacket>=_MBGetAddress(tag->Address))) { if (packet==NULL) // create a new packet { packet=malloc(sizeof(PACKET)); if (packet!=NULL) // new packet { AddChListe(packets,packet); memset(packet,0,sizeof(PACKET)); AddPacket(packet,btag); // base tag memcpy(packet->BaseAddress,btag->Address,sizeof(packet->BaseAddress)); RemoveChListe(tags,btag); } else Log(LOG_CRIT,"Optimise_Plc : Unable to allocate memory: %s\n",strerror(errno)); }; if (packet!=NULL) // add to actual packet { AddPacket(packet,tag); tag->Index=_MBGetAddress(tag->Address)-_MBGetAddress(btag->Address);//-1; elt=GetNext(tags,elt); RemoveChListe(tags,tag); packet->NumElt=_MBGetAddress(tag->Address)-_MBGetAddress(btag->Address)+_MBGetDataSize(FTable[findex].DataType); continue; } } else { btag=NULL; // if not, there is no possibility of optimization packet=NULL; continue; } elt=GetNext(tags,elt); } } }
bool TrackList::CanMoveDown(Track * t) const { return GetNext(t, true) != NULL; }
size_t wxDir::Traverse(wxDirTraverser& sink, const wxString& filespec, int flags) const { wxCHECK_MSG( IsOpened(), (size_t)-1, wxT("dir must be opened before traversing it") ); // the total number of files found size_t nFiles = 0; // the name of this dir with path delimiter at the end wxString prefix = GetName(); prefix += wxFILE_SEP_PATH; // first, recurse into subdirs if ( flags & wxDIR_DIRS ) { wxString dirname; for ( bool cont = GetFirst(&dirname, wxEmptyString, wxDIR_DIRS | (flags & wxDIR_HIDDEN) ); cont; cont = cont && GetNext(&dirname) ) { const wxString fulldirname = prefix + dirname; switch ( sink.OnDir(fulldirname) ) { default: wxFAIL_MSG(wxT("unexpected OnDir() return value") ); // fall through case wxDIR_STOP: cont = false; break; case wxDIR_CONTINUE: { wxDir subdir; // don't give the error messages for the directories // which we can't open: there can be all sorts of good // reason for this (e.g. insufficient privileges) and // this shouldn't be treated as an error -- instead // let the user code decide what to do bool ok; do { wxLogNull noLog; ok = subdir.Open(fulldirname); if ( !ok ) { // ask the user code what to do bool tryagain; switch ( sink.OnOpenError(fulldirname) ) { default: wxFAIL_MSG(wxT("unexpected OnOpenError() return value") ); // fall through case wxDIR_STOP: cont = false; // fall through case wxDIR_IGNORE: tryagain = false; break; case wxDIR_CONTINUE: tryagain = true; } if ( !tryagain ) break; } } while ( !ok ); if ( ok ) { nFiles += subdir.Traverse(sink, filespec, flags); } } break; case wxDIR_IGNORE: // nothing to do ; } } } // now enum our own files if ( flags & wxDIR_FILES ) { flags &= ~wxDIR_DIRS; wxString filename; bool cont = GetFirst(&filename, filespec, flags); while ( cont ) { wxDirTraverseResult res = sink.OnFile(prefix + filename); if ( res == wxDIR_STOP ) break; wxASSERT_MSG( res == wxDIR_CONTINUE, wxT("unexpected OnFile() return value") ); nFiles++; cont = GetNext(&filename); } } return nFiles; }
void NEPointerList::OnDraw( VGDevice & hdc ) const { //GRNotationElement* e; GuidoPos pos = GetHeadPosition(); while(pos) GetNext(pos)->OnDraw(hdc); }
void NEPointerList::setPosition(const NVPoint & newPosition) { GuidoPos pos=GetHeadPosition(); while(pos) GetNext(pos)->setPosition(newPosition); }
double TaskLeg::ScanDistanceScored(const GeoPoint &ref) const { return GetScoredDistance(ref) + (GetNext() ? GetNext()->ScanDistanceScored(ref) : 0); }
COHScriptObject *CFunctionCollection::GetFirst() { CSLock lock(m_critsec); enumerator_it = _function_map.begin(); return GetNext(); }
int CheckConnection(PLC *plc) { if (plc==NULL) return(0); Log(LOG_DEBUG,"Checking Connection for %s\n",plc->PlcName); Eip_Connection *new_connection=NULL; Eip_Connection *connection=plc->Connection; Eip_Session *session=plc->Session; if (session==NULL) return(0); if (connection==NULL) { Log(LOG_DEBUG,"Connection for %s is NULL\n",plc->PlcName); return(BuildConnection(plc)); } BYTE *path=(BYTE*)(((void*)connection)+sizeof(Eip_Connection)); if (plc->NetWork) new_connection=_ConnectPLCOverDHP(session, plc->PlcType, _Priority,_TimeOut_Ticks, (int)session, //TO_ConnID, connection->ConnectionSerialNumber, //ConnSerialNumber connection->OriginatorVendorID, connection->OriginatorSerialNumber, _TimeOutMultiplier, MAX_SAMPLE, _Transport, plc->NetWork, path, connection->Path_size); else new_connection=_ConnectPLCOverCNET(session, plc->PlcType, _Priority,_TimeOut_Ticks, (int)session, //TO_ConnID, connection->ConnectionSerialNumber, //ConnSerialNumber connection->OriginatorVendorID, connection->OriginatorSerialNumber, _TimeOutMultiplier, MAX_SAMPLE, _Transport, path, connection->Path_size); //flush(session->query); //flush(session->reply); Log(LOG_DEBUG,"Checking Connection for %s : %s (%X/%X) -> %p\n",plc->PlcName,cip_err_msg,cip_errno,cip_ext_errno,new_connection); if (new_connection==NULL) { if ((cip_errno==0x01)&&(cip_ext_errno==0x100)) { Log(LOG_WARNING,"Connection OK for %s\n",plc->PlcName); return(1); // duplicate Forward open } // error }else { if (cip_errno) { free(new_connection); new_connection=NULL; } }; //Log(LOG_WARNING,"connection = %p\n",connection); RemoveChListe(&CONNECTIONs,connection); ELEMENT *elt=GetFirst(&PLCs); if (elt!=NULL) do { PLC *plc=elt->Data; if (plc->Connection==connection) plc->Connection=new_connection; } while ((elt=GetNext(&PLCs,elt))!=NULL); if (new_connection!=NULL) { AddChListe(&CONNECTIONs,new_connection); Log(LOG_WARNING,"Connection OK for %s (%d connections)\n",plc->PlcName,CONNECTIONs.Count); return(1); }else { Log(LOG_WARNING,"Connection Error for %s (%d connections)\n",plc->PlcName,CONNECTIONs.Count); return(0); } }
// Read next packet UINT EthGetPacket(ETH *e, void **data) { BLOCK *b; bool flag = false; // Validate arguments if (e == NULL || data == NULL) { return INFINITE; } if (e->HasFatalError) { return INFINITE; } if (e->SuAdapter != NULL) { // Read packet with SeLow UINT size; if (SuGetNextPacket(e->SuAdapter, data, &size) == false) { // Error occurred e->HasFatalError = true; return INFINITE; } return size; } RETRY: // Check the presence of the packet in queue b = GetNext(e->PacketQueue); if (b != NULL) { UINT size; size = b->Size; *data = b->Buf; Free(b); if (e->PacketQueue->num_item == 0) { e->Empty = true; } return size; } if (e->Empty) { e->Empty = false; return 0; } if (flag == false) { // Try to get next packet PROBE_STR("EthGetPacket: PacketInitPacket"); wp->PacketInitPacket(e->Packet, e->Buffer, e->BufferSize); PROBE_STR("EthGetPacket: PacketReceivePacket"); if (wp->PacketReceivePacket(e->Adapter, e->Packet, false) == false) { // Failed return INFINITE; } else { UCHAR *buf; UINT total; UINT offset; buf = (UCHAR *)e->Packet->Buffer; total = e->Packet->ulBytesReceived; offset = 0; while (offset < total) { struct bpf_hdr *header; UINT packet_size; UCHAR *packet_data; header = (struct bpf_hdr *)(buf + offset); packet_size = header->bh_caplen; offset += header->bh_hdrlen; packet_data = buf + offset; offset = Packet_WORDALIGN(offset + packet_size); if (packet_size >= 14) { UCHAR *tmp; BLOCK *b; PROBE_DATA2("EthGetPacket: NewBlock", packet_data, packet_size); tmp = MallocFast(packet_size); Copy(tmp, packet_data, packet_size); b = NewBlock(tmp, packet_size, 0); InsertQueue(e->PacketQueue, b); } } flag = true; goto RETRY; } } // No more packet return 0; }
NodeRenderableBounded *CDRArrowheadStore::GetConvertedNode(DWORD Reference, INT32 *Distance, BOOL *NotPresent) { // set up the not present thingy *NotPresent = FALSE; // find the correct chunk CDRArrowheadStoredItem *Item; INT32 Size; if(IsEmpty()) return 0; // no items in the list Item = (CDRArrowheadStoredItem *)GetHead(); // scan though the list looking for the reference while(Item != 0) { if(CDRDATA_DWORD(*((DWORD *)(Item->Block))) == Reference) { Size = Item->Size; break; } Item = (CDRArrowheadStoredItem *)GetNext(Item); } // did we find a chunk? if(Item == 0) { *NotPresent = TRUE; return 0; } // locate the coordinates cdrfArrowhead *Arrow = (cdrfArrowhead *)Item->Block; cdrfCoord *Coords = (cdrfCoord *)(Item->Block + CDRDATA_WORD(Arrow->CoordsOffset) + cdrfARROWHEAD_COORDOFF_CORRECT); // store the distance from the definitons *Distance = CDRDATA_SWORD(Arrow->Distance); // check to see if a cached pointer is available if(Item->pNode != 0) return Item->pNode; // OK, convert that arrowhead // this is not particularly pleasant. We need to scan though the coords creating a path, // each sub path must be a seperate path unless the next subpath has the same closedness // as the previous one, in which case it's a sub path. // this is because closed sub paths have different attributes to open ones. It's a nasty // system, and rather overcomplicated, but never mind. INT32 ThisType = GCN_LASTSUB_NONE; // the type of this subpath INT32 LastType = GCN_LASTSUB_NONE; // the type of the last subpath NodePath *FirstPath = 0; // the first path in my set of paths NodePath *LastPath = 0; // the last path in my set of paths NodePath *ThisPath = 0; // the path I'm currently working on // check that the first node type is a move to avoid stuffing up my next bit if((Arrow->NodeTypes[0] & cdrfPATHCOORDTYPE_MASK) != cdrfPATHCOORDTYPE_MOVE) { // for now, if the first element isn't a move, pretend that it doesn't exist *NotPresent = TRUE; return 0; } INT32 CoordType; INT32 l; UINT32 Control1 = 0; // number of first control point UINT32 Control2 = 0; // of second DocCoord co, cn1, cn2; // coordinates PathFlags Flags; INT32 NNodes = CDRDATA_WORD(Arrow->NNodes); BOOL NeedMoveTo = TRUE; // convert all the coordinates for(l = 0; l < NNodes; l++) { CoordType = Arrow->NodeTypes[l] & cdrfPATHCOORDTYPE_MASK; if(CoordType == cdrfPATHCOORDTYPE_MOVE || l == 0) { // start a new path! LastType = ThisType; // first of all, what type of path is this? if((Arrow->NodeTypes[l] & cdrfPATHCOORDATTR_CLOSE) != 0) ThisType = GCN_LASTSUB_CLOSED; else ThisType = GCN_LASTSUB_OPEN; // OK, do we need to start a new path? if(ThisType != LastType) { // yep, attach the last one we did if(ThisPath != 0) { // check that the path is OK if(!ThisPath->InkPath.EnsureValid()) { // no, it's completely knackered delete ThisPath; ThisPath = 0; } else { // finish off the path ThisPath->InvalidateBoundingRect(); if(FirstPath == 0) FirstPath = ThisPath; if(LastPath != 0) ThisPath->AttachNode(LastPath, NEXT); LastPath = ThisPath; ThisPath = 0; } } // get a new path ThisPath = new NodePath; if(ThisPath == 0) return 0; // no path created. A bit of a pity // set it up ready for conversion if(!ThisPath->SetUpPath()) return 0; ThisPath->InkPath.FindStartOfPath(); // set whether it's filled or not if(ThisType == GCN_LASTSUB_CLOSED) { ThisPath->InkPath.IsFilled = TRUE; ThisPath->InkPath.IsStroked = FALSE; } else { ThisPath->InkPath.IsFilled = FALSE; ThisPath->InkPath.IsStroked = TRUE; } } } co.x = CDRDATA_SWORD(Coords[l].X); co.y = CDRDATA_SWORD(Coords[l].Y); // ensure we get all the move tos we need. if(NeedMoveTo && CoordType != cdrfPATHCOORDTYPE_MOVE) { if(!ThisPath->InkPath.InsertMoveTo(co)) return 0; } NeedMoveTo = FALSE; // convert the coordinates switch(CoordType) { case cdrfPATHCOORDTYPE_MOVE: // add a move to this path if(!ThisPath->InkPath.InsertMoveTo(co)) return 0; break; case cdrfPATHCOORDTYPE_LINETO: // add a line to this coord to the path if(!ThisPath->InkPath.InsertLineTo(co)) return 0; break; case cdrfPATHCOORDTYPE_CURVE: // check we have some control points for this curve // a control point cannot be the first coord, so it's OK to check against 0 if(Control1 == 0 || Control2 == 0) { TRACEUSER( "Ben", _T("No control points for curve element\n")); return 0; } // convert the control points cn1.x = CDRDATA_SWORD(Coords[Control1].X); cn1.y = CDRDATA_SWORD(Coords[Control1].Y); cn2.x = CDRDATA_SWORD(Coords[Control2].X); cn2.y = CDRDATA_SWORD(Coords[Control2].Y); // create the curve Flags.IsSelected = FALSE; Flags.IsSmooth = Flags.IsRotate = ((Arrow->NodeTypes[l] & cdrfPATHCOORDATTR_SMOOTH) != 0)?TRUE:FALSE; Flags.IsEndPoint; // insert it into the path if(!ThisPath->InkPath.InsertCurveTo(cn1, cn2, co, &Flags)) return 0; break; case cdrfPATHCOORDTYPE_CONTROL: // shuffle the control points we've already got and add the new one Control1 = Control2; Control2 = l; break; default: break; } // is this a close subpath situtation? if((Arrow->NodeTypes[l] & cdrfPATHCOORDATTR_CLOSE) != 0) { // close the sub path if(CoordType != cdrfPATHCOORDTYPE_MOVE) { if(!ThisPath->InkPath.CloseSubPath()) return 0; // check the next coord type NeedMoveTo = TRUE; } } } // finish off the last path ThisPath->InvalidateBoundingRect(); // finish off this path we're doing if(ThisPath != 0) { if(FirstPath == 0) FirstPath = ThisPath; if(LastPath != 0) ThisPath->AttachNode(LastPath, NEXT); LastPath = ThisPath; ThisPath = 0; } // make up a nice group if there's more than one path NodeRenderableBounded *ToInsert = 0; if(FirstPath == LastPath) { ToInsert = FirstPath; } else { ToInsert = new NodeGroup; if(ToInsert == 0) return 0; FirstPath->InsertChainSimple(ToInsert, FIRSTCHILD); } Item->pNode = ToInsert; return ToInsert; }
int mainprog(void) { int nfds = getdtablesize(); struct timeval timeout; fd_set rfds; struct sockaddr_in sonadr; int fd; CLIENT *client=NULL; FD_ZERO(&fd_clients); InitChListe(&PLCs); InitChListe(&TAGs); InitChListe(&CLIENTs); InitChListe(&SESSIONs); InitChListe(&CONNECTIONs); if (GetPlc(&PLCs,Alias)<=0) { Log(LOG_CRIT,"Alias File is empty\n"); return(T_Error); } Server=OpenServerSock(SPort); if (Server<0) { Log(LOG_CRIT,"Error creating Server socket : %s\n",strerror(errno)); return(T_Error); } SetCoe(Server); FD_SET(Server,&fd_clients); while ((!Terminated)) { memcpy(&rfds, &fd_clients, sizeof(rfds)); timeout.tv_sec=ScanRate; timeout.tv_usec=uScanRate; switch (select(nfds, &rfds, 0, 0,&timeout)) { case -1:if(errno == EINTR) continue; else { Log(LOG_WARNING,"surveillance des descripteurs : %s\n",strerror(errno)); break; } case 0: { // timeout //continue; break; } default: if(FD_ISSET(Server, &rfds)) { int taille = sizeof (sonadr); if((fd = accept(Server, (struct sockaddr *)&sonadr,(socklen_t *)&taille))==-1) { Log(LOG_WARNING, "accept: connexion impossible (%s)\n",strerror(errno)); } else { Log(LOG_INFO,"Connexion d'un client depuis %s (socket : %d)\n", inet_ntoa(sonadr.sin_addr),fd); SetCoe(fd); client=malloc(sizeof(CLIENT)); if (client!=NULL) { if (AddChListe(&CLIENTs,client)>0) { /* ajout du client dans les socket à surveiller */ memset(client,0,sizeof(CLIENT)); client->FD=fd; FD_SET(fd, &fd_clients); fcntl(fd, F_SETFL, O_NONBLOCK | fcntl(fd, F_GETFL, 0)); Log(LOG_INFO,"Client connecté depuis %s (socket : %d)\n", inet_ntoa(sonadr.sin_addr),fd); } else { close(fd); Log(LOG_CRIT, "Erreur à l'ajout du client (%s)\n",strerror(errno)); } } else { close(fd); Log(LOG_WARNING, "Erreur à la création du client (%s)\n",strerror(errno)); } } } /* Tester si les sockets clientes ont bougées */ for(fd=0; fd<nfds; fd++ ) { if((fd != Server) && FD_ISSET(fd, &rfds)) { /* Recherche du client */ client=FindClient(fd,&CLIENTs); if (client==NULL) { Log(LOG_WARNING, "Client inconnu !!! (socket : %d)--\n",fd); close(fd); FD_CLR(fd, &fd_clients); Reply(fd,"Erreur interne (line : %d)\n",__LINE__); continue; } switch (lire_client(client)) { case 0: RemoveChListe(&CLIENTs,client); free(client); close(fd); FD_CLR(fd, &fd_clients); Log(LOG_INFO, "-- perte d'un client ! (socket : %d)--\n",fd); continue; default:/* Traitement requete */ Log(LOG_DEBUG,"<-Client : %p (buffersize : %d)\n",client,client->InBuffer.size); Traite(client); continue; } } } break; } /* Checking Tag inactivity */ if (TAGs.Count>0) { time_t now=time(NULL); ELEMENT *elt=GetFirst(&TAGs); if (elt!=NULL) do { TAG *tag=elt->Data; if ((now-tag->Time_Value)>INACTIVITY_TO) { ELEMENT *elt_old=elt; Log(LOG_DEBUG,"\t-Deleting Tag %s on %s (%p / %p)\n",tag->TagName,tag->Plc->PlcName,tag,elt); elt=GetNext(&TAGs,elt); RemoveChListe_Ex(&TAGs,elt_old); free(elt_old); if (tag->Plc!=NULL) { tag->Plc->References--; if (tag->Plc->References<=0) { Log(LOG_DEBUG,"No more Tag on plc : %s\n",tag->Plc->PlcName); DisconnectPlc(tag->Plc); } } free(tag); continue; } } while ((elt=GetNext(&TAGs,elt))!=NULL); } } close(Server); Log(LOG_DEBUG,"Killing all connections\n"); KillConnections(); Log(LOG_DEBUG,"Closing list TAGs : %d counts\n",TAGs.Count); CloseList(&TAGs); Log(LOG_DEBUG,"Closing list PLCs : %d counts\n",PLCs.Count); CloseList(&PLCs); Log(LOG_DEBUG,"Closing list CLIENTs : %d counts\n",CLIENTs.Count); CloseList(&CLIENTs); return(0); }
int RichEditBkImg::PositionItem2Value(const POSITION_ITEM &pos ,int nMin, int nMax,BOOL bX) { int nRet=0; switch(pos.pit) { case PIT_NORMAL: if(pos.cMinus == -1) nRet=nMax-(int)pos.nPos; else nRet=nMin+(int)pos.nPos; break; case PIT_PREV_NEAR: //“[”相对于前一兄弟窗口。用于X时,参考前一兄弟窗口的right,用于Y时参考前一兄弟窗口的bottom case PIT_PREV_FAR: //“{”相对于前一兄弟窗口。用于X时,参考前一兄弟窗口的left,用于Y时参考前一兄弟窗口的top { CRect rcRef; RichEditObj *pRefObj=GetPrev(); if(pRefObj) { rcRef = pRefObj->GetRect(); }else { rcRef=m_pObjectHost->GetAdjustedRect(); rcRef.right = rcRef.left; rcRef.bottom = rcRef.top; } if(bX) { LONG refPos = (pos.pit == PIT_PREV_NEAR)?rcRef.right:rcRef.left; nRet=refPos+(int)pos.nPos*pos.cMinus; }else { LONG refPos = (pos.pit == PIT_PREV_NEAR)?rcRef.bottom:rcRef.top; nRet=refPos+(int)pos.nPos*pos.cMinus; } } break; case PIT_NEXT_NEAR: //“]”相对于后一兄弟窗口。用于X时,参考后一兄弟的left,用于Y时参考后一兄弟的top case PIT_NEXT_FAR: //“}”相对于后一兄弟窗口。用于X时,参考后一兄弟的right,用于Y时参考后一兄弟的bottom { CRect rcRef; RichEditObj *pRefObj = GetNext(); if(pRefObj) { rcRef = pRefObj->GetRect(); }else { rcRef = m_pObjectHost->GetAdjustedRect(); rcRef.left = rcRef.right; rcRef.top = rcRef.bottom; } if(bX) { LONG refPos = (pos.pit == PIT_NEXT_NEAR)?rcRef.left:rcRef.right; nRet=refPos+(int)pos.nPos*pos.cMinus; }else { LONG refPos = (pos.pit == PIT_NEXT_NEAR)?rcRef.top:rcRef.bottom; nRet=refPos+(int)pos.nPos*pos.cMinus; } } break; } return nRet; }
const char *ExpectNext() { if (IsEmpty()) UsageError(); return GetNext(); }
int Logger(LISTE *plcs) { int res=0,Comm_err=0,Read_Something=0; if (TEST) { ListePlc(plcs); //return(0); } int now=time(NULL); res=BuildSockets(plcs); while (!Terminated) { ELEMENT *elt=GetFirst(plcs); while (elt!=NULL) // PLCs { PLC *plc=elt->Data; /* Something to do ? */ if (plc->Next_Time>time(NULL)) { elt=GetNext(plcs,elt); continue; } /* Test Socket */ if (plc->socket<0) { if (BuildSocket(plc)<0) { Log(LOG_WARNING,"Socket unavailable for : %s\n",plc->PlcName); plc->Next_Time=now+WAIT_FOR_RECONNECT; elt=GetNext(plcs,elt); continue; } else Log(LOG_INFO,"Socket build for : %s\n",plc->PlcName); } now=time(NULL); Read_Something=0; Comm_err=1; //plc->Next_Time=now+0.95*MAX_SAMPLE/1000; plc->Next_Time=now+MAX_SAMPLE; Log(LOG_DEBUG,"Set plc->Next_Time in %d seconds (MAX_SAMPLE : %d)\n",plc->Next_Time-now,MAX_SAMPLE); /* Read Tags */ ELEMENT *elt2=GetFirst(&(plc->Tags)); while (elt2!=NULL) { TAG *tag=elt2->Data; if ((now-tag->Time_Value)>(1.5*tag->Time_Sample)) Log(LOG_WARNING,"Time Sample exceed on tag : %s (%s)\n",tag->TagName,plc->PlcName); if ((now-tag->Time_Value)>=tag->Time_Sample) { //Log(LOG_DEBUG,"Reading tag : %s (%s) (%d - %d > %d)\n",tag->TagName,plc->PlcName,now,tag->Time_Value,tag->Time_Sample); Read_Something=1; res=ReadTag(plc,tag); if (res==0) Comm_err=0; // At least one tag is Ok if (mb_errno==EPIPE) CloseSocket(plc->socket,plcs); } if ((tag->Time_Value+tag->Time_Sample)<(plc->Next_Time)) { plc->Next_Time=tag->Time_Value+tag->Time_Sample; Log(LOG_DEBUG,"plc->Next_Time in %d seconds*\n",plc->Next_Time-now); } elt2=GetNext(&(plc->Tags),elt2); } /* Read Packets */ elt2=GetFirst(&(plc->Packets)); while (elt2!=NULL) { PACKET *packet=elt2->Data; if ((now-packet->Time_Value)>(1.5*packet->Time_Sample)) Log(LOG_WARNING,"Time Sample exceed on packet : %s (%s)\n",packet->BaseAddress,plc->PlcName); if ((now-packet->Time_Value)>=packet->Time_Sample) { Read_Something=1; res=ReadPacket(plc,packet); if (res>=0) Comm_err=0; // At least one tag is Ok if (mb_errno==EPIPE) CloseSocket(plc->socket,plcs); } if ((packet->Time_Value+packet->Time_Sample)<(plc->Next_Time)) { plc->Next_Time=packet->Time_Value+packet->Time_Sample; Log(LOG_DEBUG,"plc->Next_Time in %d seconds\n",plc->Next_Time-now); } elt2=GetNext(&(plc->Packets),elt2); } /* Check Plc */ if (Comm_err && Read_Something) // All Tags & packets are in error { Log(LOG_WARNING,"All tags in error for : %s suspending for %d seconds\n",plc->PlcName,WAIT_FOR_RECONNECT); plc->Next_Time=now+WAIT_FOR_RECONNECT; } if (plc->Next_Time>0.8*(time(NULL)+MODBUS_SOCK_TIMEOUT)) { close(plc->socket); plc->socket=-1; Log(LOG_DEBUG,"Closing socket for plc : %s \n",plc->PlcName); } elt=GetNext(plcs,elt); } sleep(1); } Log(LOG_NOTICE,"Killing Connections\n"); KillAll(plcs); FreeAll(plcs); return(0); }
double TaskLeg::ScanDistanceMin() const { return GetMinimumLegDistance() + (GetNext() ? GetNext()->ScanDistanceMin() : 0); }
XMLElement XMLElement::GetNext(const String& name) const { return GetNext(name.CString()); }
double TaskLeg::ScanDistanceNominal() const { return GetNominalLegDistance() + (GetNext() ? GetNext()->ScanDistanceNominal() : 0); }
void Body::clearFixtures() { for (auto f = getBody().GetFixtureList(); f; f = f->GetNext()) { getBody().DestroyFixture(f); } }
// Close Ethernet adapter void CloseEth(ETH *e) { // Validate arguments if (e == NULL) { return; } if (e->Tap != NULL) { #ifndef NO_VLAN FreeTap(e->Tap); #endif // NO_VLAN } #ifdef BRIDGE_PCAP { struct CAPTUREBLOCK *block; pcap_breakloop(e->Pcap); WaitThread(e->CaptureThread, INFINITE); ReleaseThread(e->CaptureThread); pcap_close(e->Pcap); while (block = GetNext(e->Queue)){ Free(block->Buf); FreeCaptureBlock(block); } ReleaseQueue(e->Queue); } #endif // BRIDGE_PCAP #ifdef BRIDGE_BPF #ifdef BRIDGE_BPF_THREAD { struct CAPTUREBLOCK *block; int fd = e->Socket; e->Socket = INVALID_SOCKET; WaitThread(e->CaptureThread, INFINITE); ReleaseThread(e->CaptureThread); e->Socket = fd; // restore to close after while (block = GetNext(e->Queue)){ Free(block->Buf); FreeCaptureBlock(block); } ReleaseQueue(e->Queue); } #else // BRIDGE_BPF_THREAD Free(e->Buffer); #endif // BRIDGE_BPF_THREAD #endif // BRIDGE_BPF ReleaseCancel(e->Cancel); Free(e->Name); Free(e->Title); // Restore MTU value EthSetMtu(e, 0); if (e->Socket != INVALID_SOCKET) { #if defined(BRIDGE_BPF) || defined(BRIDGE_PCAP) || defined(UNIX_SOLARIS) close(e->Socket); #else // BRIDGE_PCAP closesocket(e->Socket); #endif // BRIDGE_PCAP #if defined(BRIDGE_BPF) || defined(UNIX_SOLARIS) if (e->SocketBsdIf != INVALID_SOCKET) { close(e->SocketBsdIf); } #endif // BRIDGE_BPF || UNIX_SOLARIS } Free(e); }
/*{{{ data*/ void ReadDataDistanceMatrix(value** points, FILE* inputFile, int k) { List tempList; size_t lineSize = 0; char* lineBuff = NULL; char* temp; char delims[5] = "\t ,\n"; char* token = NULL; int num = 0; int i; int line = 0; dm = malloc(sizeof(datadistanceMatrix)); dm->data=NULL; dm->dataDist=NULL; dm->dataNum=0; dm->queries=NULL; dm->iterator=0; dm->queryDist=NULL; dm->queryNum=0; dm->qIterator=0; dm->k = k; getline(&lineBuff, &lineSize, inputFile); /*skip the first value*/ token = strtok(lineBuff, delims); InitList(&tempList, BUFFSIZE * sizeof(char), NULL, NULL,NULL); while (token != NULL) { token = strtok(NULL, delims); if (token == NULL) break; temp = malloc((LABELSIZE + 1) * sizeof(char)); memcpy(temp, token, strlen(token)); temp[strlen(token)] = '\0'; InsertValueList(tempList, temp); num++; free(temp); } SetDataSize(num); *points = malloc(num*sizeof(value)); value* newData = *points; char* tempVal = GetFirst(tempList); for (i = 0; i < num; i++) { newData[i].name = malloc(LABELSIZE * sizeof(char)); memset(newData[i].name,'\0',LABELSIZE); if(tempVal ==NULL) continue; strcpy(newData[i].name, tempVal); tempVal=GetNext(tempList); } dm->dataDist = malloc(num * sizeof(double*)); while (getline(&lineBuff, &lineSize, inputFile) != -1) { dm->dataDist[line] = malloc(num * sizeof(double)); newData[line].content=malloc(sizeof(int)); memcpy(newData[line].content,&line,sizeof(int)); token = strtok(lineBuff, delims); if (token == NULL) break; for (i = 0; i < num; i++) { dm->dataDist[line][i] = atoi(token); token = strtok(NULL, delims); } line++; } dm->dataNum=line; data.tableSize = dm->dataNum; DestroyList(&tempList); free(lineBuff); }
// ATTENTION, aend timePosition! void NEPointerList::setSpacing(const TYPE_TIMEPOSITION & timePosition, NVPoint& position) { // this is obolete! assert(false); #ifdef BALBAL if (empty()) return; assert(!empty()); GRNotationElement * criticalElement = 0; NEPointerList * list= this; // getElementsWithTimePosition(timePosition); // think about it. TYPE_TIMEPOSITION nextTimePosition (getNextTimePosition(timePosition)); TYPE_SPACING spacing = 0; if(!list->empty()) { NEPointerList* shortyList=list->getElementsWithShortestDuration(); criticalElement=shortyList->getElementWithMaxSpacing(); float criticalElementSize=criticalElement->getBoundingBox().right; assert(criticalElementSize>=0); // get size of real element if(criticalElement->getRelativeEndTimePosition()>nextTimePosition) // is there an Overlap? { criticalElement = new GRSingleNote(nextTimePosition-timePosition); // Dummy element for spacing calculation // I Believe abstractRepresentation will not be created? delete criticalElement; } else { } GuidoPos pos = GetHeadPosition(); GRNotationElement * e; float min = 0; while (pos) { e = GetNext(pos); if (e->getRelativeTimePosition()==timePosition && e->getBoundingBox().left<min) min = e->getBoundingBox().left; } pos = GetHeadPosition(); while(pos) { e = GetNext(pos); if (tmp) { tmp->setHPosition(position.x-min); } else { } } position.x += spacing+criticalElementSize; position.x -= min; delete shortyList; } else { criticalElement = new GRSingleNote(nextTimePosition-timePosition); // special Dummy-Object?? delete criticalElement; GRNotationElement * e; GuidoPos pos=GetHeadPosition(); while(pos) { e=GetNext(pos); } position.x += spacing; } #endif }
// End the tracking of the routing table void RouteTrackingStop(SESSION *s, ROUTE_TRACKING *t) { ROUTE_ENTRY *e; ROUTE_TABLE *table; IP dns_ip; bool network_has_changed = false; bool do_not_delete_routing_entry = false; // Validate arguments if (s == NULL || t == NULL) { return; } Zero(&dns_ip, sizeof(dns_ip)); // Remove the default gateway added by the virtual LAN card if (MsIsVista() == false) { if (t->DefaultGatewayByVLan != NULL) { Debug("Default Gateway by VLAN was deleted.\n"); DeleteRouteEntry(t->DefaultGatewayByVLan); } if (t->VistaOldDefaultGatewayByVLan != NULL) { FreeRouteEntry(t->VistaOldDefaultGatewayByVLan); } } if (t->DefaultGatewayByVLan != NULL) { FreeRouteEntry(t->DefaultGatewayByVLan); t->DefaultGatewayByVLan = NULL; } if (t->VistaDefaultGateway1 != NULL) { Debug("Vista PPP Fix Route Table Deleted.\n"); DeleteRouteEntry(t->VistaDefaultGateway1); FreeRouteEntry(t->VistaDefaultGateway1); DeleteRouteEntry(t->VistaDefaultGateway2); FreeRouteEntry(t->VistaDefaultGateway2); } if (MsIsNt() == false) { // Only in the case of Windows 9x, release the DHCP address of the virtual LAN card Win32ReleaseDhcp9x(t->VLanInterfaceId, false); } // Clear the DNS cache Win32FlushDnsCache(); if (s->Cedar->Client != NULL && s->Account != NULL) { UINT i; ACCOUNT *a; for (i = 0;i < LIST_NUM(s->Cedar->Client->AccountList);i++) { a = LIST_DATA(s->Cedar->Client->AccountList, i); Lock(a->lock); { SESSION *sess = a->ClientSession; if (sess != NULL && sess != s) { VLAN *v = sess->PacketAdapter->Param; if (v != NULL) { ROUTE_TRACKING *tr = v->RouteState; if (tr != NULL) { if (Cmp(tr->RouteToServer, t->RouteToServer, sizeof(ROUTE_ENTRY)) == 0) { do_not_delete_routing_entry = true; } } } } } Unlock(a->lock); } Lock(s->Account->lock); } if (do_not_delete_routing_entry == false) { // Delete the route that is added firstly if (t->RouteToServerAlreadyExists == false) { DeleteRouteEntry(t->RouteToServer); } DeleteRouteEntry(t->RouteToDefaultDns); DeleteRouteEntry(t->RouteToNatTServer); DeleteRouteEntry(t->RouteToRealServerGlobal); } FreeRouteEntry(t->RouteToDefaultDns); FreeRouteEntry(t->RouteToServer); FreeRouteEntry(t->RouteToEight); FreeRouteEntry(t->RouteToNatTServer); FreeRouteEntry(t->RouteToRealServerGlobal); t->RouteToDefaultDns = t->RouteToServer = t->RouteToEight = t->RouteToNatTServer = t->RouteToRealServerGlobal = NULL; if (s->Cedar->Client != NULL && s->Account != NULL) { Unlock(s->Account->lock); } #if 0 // Get the current DNS server if (GetDefaultDns(&dns_ip)) { if (IPToUINT(&t->OldDnsServer) != 0) { if (IPToUINT(&t->OldDnsServer) != IPToUINT(&dns_ip)) { char s1[MAX_SIZE], s2[MAX_SIZE]; network_has_changed = true; IPToStr(s1, sizeof(s1), &t->OldDnsServer); IPToStr(s2, sizeof(s2), &dns_ip); Debug("Old Dns: %s, New Dns: %s\n", s1, s2); } } } if (network_has_changed == false) { Debug("Network: not changed.\n"); } else { Debug("Network: Changed.\n"); } #endif // Get the current routing table table = GetRouteTable(); // Restore the routing table which has been removed so far while (e = GetNext(t->DeletedDefaultGateway)) { bool restore = true; UINT i; // If the restoring routing entry is a default gateway and // the existing routing table contains another default gateway // on the interface, give up restoring the entry if (IPToUINT(&e->DestIP) == 0 && IPToUINT(&e->DestMask) == 0) { for (i = 0;i < table->NumEntry;i++) { ROUTE_ENTRY *r = table->Entry[i]; if (IPToUINT(&r->DestIP) == 0 && IPToUINT(&r->DestMask) == 0) { if (r->InterfaceID == e->InterfaceID) { restore = false; } } } if (network_has_changed) { restore = false; } } if (restore) { // Routing table restoration AddRouteEntry(e); } // Memory release FreeRouteEntry(e); } // Release FreeRouteTable(table); ReleaseQueue(t->DeletedDefaultGateway); FreeRouteChange(t->RouteChange); Free(t); }
void NEPointerList::GetMap( GuidoeElementSelector sel, MapCollector& f, MapInfos& infos ) const { //GRNotationElement* e; GuidoPos pos = GetHeadPosition(); while(pos) GetNext(pos)->GetMap(sel, f, infos); }
CLibraryFile* CLibraryList::GetNextFile(POSITION& pos) const { return Library.LookupFile( GetNext( pos ) ); }
void NEPointerList::setHPosition( float nx ) { GuidoPos pos = GetHeadPosition(); while(pos) GetNext(pos)->setHPosition(nx); }
fixed TaskLeg::ScanDistanceMin() const { return GetMinimumLegDistance() + (GetNext() ? GetNext()->ScanDistanceMin() : fixed(0)); }
MalieExec::MalieExec(char *lpFileName) { execstream bin(lpFileName); DWORD dwCnt = bin.readdw(); for (;dwCnt;--dwCnt)//skip var { DWORD szLen = bin.readdw(); bin.seek(szLen&0x7FFFFFFF,FILE_CURRENT); GetNext(&bin); bin.seek(sizeof(DWORD)*4,FILE_CURRENT); } //至于这里为啥要跳过一个DW我也忘了、最初的解析里面没有写 // [7/20/2013 Azure] bin.seek(sizeof(DWORD),FILE_CURRENT);//skip 0x3130 dwCnt = 0x5F4 ////////////////////////////////////////////////////////////////////////// // Function parse block dwCnt = bin.readdw(); // freopen("functionList.txt","wt,ccs=UNICODE",stdout); for (;dwCnt;--dwCnt)//skip function { DWORD szLen;char temp[1000];DWORD ch[3]; VM_FUNCTION func; szLen = bin.readdw(); bin.read(temp,(szLen&0x7FFFFFFF)); bin.read(ch,3*sizeof(DWORD)); func.dwID = ch[0]; func.wstrName = (WCHAR *)temp; func.dwVMCodeOffset = ch[2]; func.dwReserved0 = ch[1]; funcList[func.wstrName] = func; vecFuncList.push_back(func); // wprintf(L"%d,%ls,%d,0x%.4X\n",ch[0],temp,ch[1],ch[2]); } fprintf(stderr,"VM_FUNCTION:%d\n",funcList.size()); ////////////////////////////////////////////////////////////////////////// // Label parse block dwCnt = bin.readdw(); for (;dwCnt;--dwCnt)//skip label { DWORD szLen;char temp[1000];DWORD ch; MALIE_LABEL label; szLen = bin.readdw(); bin.read(temp,(szLen&0x7FFFFFFF)); ch = bin.readdw(); label.wstrName = (WCHAR *)temp; label.dwVMCodeOffset = ch; labelList[label.wstrName] = label; } fprintf(stderr,"LABEL:%d\n",labelList.size()); ////////////////////////////////////////////////////////////////////////// // VM_DATA : just read to new area szVM_DATA = bin.readdw(); //dump original scene pVM_DATA = new unsigned char[szVM_DATA]; bin.read(pVM_DATA,szVM_DATA); fprintf(stderr,"VM_DATA size: %8X\n",szVM_DATA); ////////////////////////////////////////////////////////////////////////// // VM_CODE : just read to new area szVM_CODE = bin.readdw(); pVM_CODE = new unsigned char [szVM_CODE]; bin.read(pVM_CODE,szVM_CODE); fprintf(stderr,"VM_CODE size: %8X\n",szVM_CODE); // fprintf(stderr,"system_onInit:0x%X\n",func_List.find(L"system_onInit")->second.dwVMCodeOffset); ////////////////////////////////////////////////////////////////////////// // strTable DWORD unkSize = bin.readdw(); if (unkSize*8 >bin.GetFileSize()-bin.seek(0,FILE_CURRENT)) { szStrTable = unkSize;//ziped crypted pStrTable = new unsigned char[unkSize]; bin.read(pStrTable,szStrTable); cntStrIndex = bin.readdw(); vStrIndex.reserve(cntStrIndex/2+1); DWORD offset = bin.readdw(); for (size_t idx = 1;idx<cntStrIndex;++idx) { DWORD tmpOffset = bin.readdw(); vStrIndex.push_back(STRING_INFO(offset,tmpOffset-offset)); offset = tmpOffset; } } else { cntStrIndex = unkSize;//normal vStrIndex.resize(cntStrIndex); bin.read(&vStrIndex[0],cntStrIndex*sizeof(STRING_INFO)); szStrTable = bin.readdw(); pStrTable = new unsigned char[szStrTable]; bin.read(pStrTable,szStrTable); } }
fixed TaskLeg::ScanDistanceNominal() const { return GetNominalLegDistance() + (GetNext() ? GetNext()->ScanDistanceNominal() : fixed(0)); }
BOOL CRKey::EncodeUrl(CPipe *pPipe, DWORD dwEncoding, char chSepNameVal, char chSepValues) {_STTEX(); // Add each value TMem< char > buf; LPREGVALUE prv = NULL; while ( ( prv = (LPREGVALUE)GetNext( prv ) ) != NULL ) { // Write separator if needed if ( pPipe->GetBufferSize() ) pPipe->Write( &chSepValues, 1 ); switch( dwEncoding ) { case 0 : { // Write the key pPipe->Write( prv->cpkey, prv->ksize ); // Separator pPipe->Write( &chSepNameVal, 1 ); // Write raw value if ( REG_BINARY == prv->type ) pPipe->Write( prv->pbdata, prv->size ); else pPipe->Write( GetSz( prv ) ); } break; case 1 : { // Write the name if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( strlen( prv->cpkey ) ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, prv->bpkey, strlen( prv->cpkey ) ); pPipe->Write( buf ); } // end if // Separator pPipe->Write( &chSepNameVal, 1 ); // Write binary buffers if ( REG_BINARY == prv->type ) { // Binary encoding if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( prv->size ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, prv->pbdata, prv->size ); pPipe->Write( buf ); } // end if } // end if else { // Write the name LPCTSTR val = GetSz( prv ); if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( strlen( val ) ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, (LPBYTE)val, strlen( val ) ); pPipe->Write( buf ); } // end if } // end if } break; case 2 : { TMem< char > buf2; // Write the name if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( strlen( prv->cpkey ) ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, prv->bpkey, strlen( prv->cpkey ) ); pPipe->Write( buf ); } // end if // Separator pPipe->Write( &chSepNameVal, 1 ); // Write binary buffers if ( REG_BINARY == prv->type ) { // Binary encoding if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( prv->size ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, prv->pbdata, prv->size ); } // end if } // end if else { // Write the name LPCTSTR val = GetSz( prv ); if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( strlen( val ) ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, (LPBYTE)val, strlen( val ) ); } // end if } // end if // Encoded again then add to buffer if ( buf2.grow( CCfgFile::GetMinCanonicalizeBufferSize( strlen( buf.ptr() ) ) ) ) { buf2.Zero(); CCfgFile::CanonicalizeBuffer( buf2, (LPBYTE)buf.ptr(), strlen( buf.ptr() ) ); pPipe->Write( buf2 ); } // end if } break; } // end switch } // end while return TRUE; }
CChatSession* CChatCore::FindSession(CEDClient* pClient) { CChatSession* pSession; for ( POSITION pos = GetIterator() ; pos ; ) { pSession = GetNext( pos ); // If we already have a session if ( ( ( ! pSession->m_bGUID ) || ( pSession->m_pGUID == pClient->m_pGUID ) ) && ( pSession->m_pHost.sin_addr.S_un.S_addr == pClient->m_pHost.sin_addr.S_un.S_addr ) && ( pSession->m_nProtocol == PROTOCOL_ED2K ) ) { // Update details pSession->m_bGUID = pClient->m_bGUID; pSession->m_pGUID = pClient->m_pGUID; pSession->m_pHost = pClient->m_pHost; pSession->m_sAddress = pClient->m_sAddress; pSession->m_sUserNick = pClient->m_sNick; pSession->m_sUserAgent = pClient->m_sUserAgent; pSession->m_bUnicode = pClient->m_bEmUnicode; pSession->m_nClientID = pClient->m_nClientID; pSession->m_pServer = pClient->m_pServer; pSession->m_bMustPush = ( ( pClient->m_nClientID > 0 ) && ( pClient->m_nClientID < 16777216 ) ); // return existing session return pSession; } } // Create a new chat session pSession = new CChatSession(); pSession->m_nProtocol = PROTOCOL_ED2K; pSession->m_hSocket = INVALID_SOCKET; // Should always remain invalid- has no real connection pSession->m_nState = cssActive; pSession->m_bConnected = TRUE; pSession->m_tConnected = GetTickCount(); // Set details pSession->m_bGUID = pClient->m_bGUID; pSession->m_pGUID = pClient->m_pGUID; pSession->m_pHost = pClient->m_pHost; pSession->m_sAddress = pClient->m_sAddress; pSession->m_sUserNick = pClient->m_sNick; pSession->m_sUserAgent = pClient->m_sUserAgent; pSession->m_bUnicode = pClient->m_bEmUnicode; pSession->m_nClientID = pClient->m_nClientID; pSession->m_pServer = pClient->m_pServer; pSession->m_bMustPush = ( ( pClient->m_nClientID > 0 ) && ( pClient->m_nClientID < 16777216 ) ); // Make new input and output buffer objects DWORD nLimit = 0; pSession->m_pInput = new CBuffer( &nLimit ); pSession->m_pOutput = new CBuffer( &nLimit ); Add( pSession ); return pSession; }