void ArrivalPaxLandsideBehavior::processGetOnVehicle_old( const ElapsedTime& t )
{
	WriteLogEntry(t);
	//get on to vehicle
	ARCVector3 vehiclepos = m_pVehicle->getState(t).pos;
	setDestination(vehiclepos);
	ElapsedTime etime = moveTime();
	//setLocation(vehiclepos);	
	WriteLogEntry(etime + t);
	m_pPerson->setState(On_Vehicle);
	GenerateEvent(etime+t);
}
	void SyncTestbed::ValidatePair(const Sync::SyncManagerPtr& syncMgr1, const SyncTestObjectPtr& syncObj1, const Sync::SyncManagerPtr& syncMgr2, const SyncTestObjectPtr& syncObj2) const
	{
		if (!syncObj1->Equals(syncObj2))
		{
			WriteLogEntry("===========================================\n");
			syncMgr1->PrintSyncData();

			WriteLogEntry("\n===========================================\n");
			syncMgr2->PrintSyncData();

			Assert::Fail(L"Sync pair does not match");
		}
	}
void ArrivalPaxLandsideBehavior::ProcessMoveToVehicle( const ElapsedTime& eEventTime )
{
	WriteLogEntry(eEventTime);
	//get on to vehicle
	ARCVector3 vehiclepos = m_pVehicle->getState(eEventTime).pos;
	setDestination(vehiclepos);
	ElapsedTime eMovetime = moveTime();

	ElapsedTime eCurTime = eMovetime + eEventTime;
	//setLocation(vehiclepos);	
	WriteLogEntry(eCurTime);
	m_pPerson->setState(PutCarryonToVehicle);
	GenerateEvent(eCurTime);
}
Example #4
0
  void Profiler::StopLogging ()
  {
    if (!isLogging)
      return;

    // Write column headers at the end. This isn't really csv format, but we do
    // this to cope with any added columns during profiling
    csString data, data2;
    for (size_t i = 0; i < allZones.GetSize (); ++i)
    {
      data2.Format ("%s_Time, %s_Count, ", allZones[i]->zoneName, allZones[i]->zoneName);
      data.Append (data2);
    }
    data.Append ("\n");
    WriteLogEntry (data);

    if (logfile)
    {
      logfile->Flush ();
      logfile = 0;
    }

    if (nativeLogfile)
    {
      fflush (nativeLogfile);
      fclose (nativeLogfile);
      nativeLogfile = 0;
    }

    isLogging = false;
  }
Example #5
0
  void Profiler::Reset ()
  {
    // Dump to file if we have one
    if (isLogging && allZones.GetSize () > 0)
    {
      csString data, data2;
      for (size_t i = 0; i < allZones.GetSize (); ++i)
      {
        data2.Format ("%" PRIu64 ", %u, ", allZones[i]->totalTime, allZones[i]->enterCount);
        data.Append (data2);
      }
      data.Append ("\n");
      WriteLogEntry (data);
    }

    // Reset
    for (size_t i = 0; i < allZones.GetSize (); ++i)
    {
      ProfileZone* zone = allZones[i];
      zone->totalTime = 0;
      zone->enterCount = 0;
    }

    for (size_t i = 0; i < allCounters.GetSize(); ++i)
    {
      ProfileCounter* counter = allCounters[i];
      counter->counterValue = 0;
    }
  }
Example #6
0
bool CScales::ReadBytes(BYTE *pValues, DWORD nSize)
{
    DWORD dwBytesRead = 0;
    ZeroMemory(pValues, nSize);
    BOOL bResult = ReadFile(m_CommPort, pValues, nSize, &dwBytesRead, NULL);
    WriteLogEntry(ReadPort, pValues, nSize);
    return (bResult == TRUE) && (dwBytesRead == nSize);
}
void ArrivalPaxLandsideBehavior::ProcessGetOffVehicle( const ElapsedTime& eEventTime )
{
	//get vehicle

	//get
	//the position where the vehicle stops
	//
	WriteLogEntry(eEventTime);

	setState(GetOffVehicle);
	setDestination(m_pVehicle->getLastState().pos);
	//setLocation(m_pVechile->getState().pos);
	WriteLogEntry(eEventTime);

	CPoint2008 nextPt(0,0,0);

	LandsideBusStationInSim*  pBusStation = NULL;
	if( LandsideResourceInSim* pRes = getResource())
	{
		pBusStation =  pRes->toBusSation();
		if ( pBusStation)
		{
			nextPt = pBusStation->GetPaxWaitPos();
		}
	}
	//move outside vehicle
	CPoint2008 nextpos = m_pVehicle->getOffVehiclePos(nextPt);
	setDestination(nextpos);
	ElapsedTime eMovetime = moveTime();
	ElapsedTime eCurTime = eMovetime + eEventTime;

	//setLocation(nextpos);
	WriteLogEntry(eCurTime);

	m_pVehicle->RemoveOnPax(this, eCurTime);

	//start to pick the Bag
	
	m_pPerson->setState(PickCarryOnFromVehicle);
	GenerateEvent(eCurTime);


}
void ArrivalPaxLandsideBehavior::processOnVehicle( const ElapsedTime& t )
{
	//do nothing , wait for vehicle flush its log
	WriteLogEntry(t);
	if(m_pVehicle)
	{
		m_pVehicle->Activate(t);
		m_pVehicle->AddOnPax(this);
	}
	return;
}
void ArrivalPaxLandsideBehavior::processPutBag( const ElapsedTime& t )
{
	WriteLogEntry(t);

	//go to the pak
	ARCVector3 bagPos = m_pVehicle->getLastState().pos;
	setDestination(bagPos);
	ElapsedTime dNextTime = t;
	dNextTime += moveTime();
	//setLocation(bagPos);		
	WriteLogEntry(dNextTime);

	//write bag log
	Passenger* pPassenger = (Passenger*)m_pPerson;
	int nCount = pPassenger->m_pVisitorList.size();
	for( int i=nCount-1; i>=0; i-- )
	{
		PaxVisitor* pVis = pPassenger->m_pVisitorList[i];
		if (pVis == NULL)
			continue;
		VisitorLandsideBehavior* pCarryonBehavior = (VisitorLandsideBehavior*)pVis->getLandsideBehavior();
		ASSERT(pCarryonBehavior);
		//non passenger move to ground
		if(pCarryonBehavior)
		{
			pCarryonBehavior->setDestination(bagPos);			
			ElapsedTime eTime = moveTime();
			pCarryonBehavior->setLocation(bagPos);
			pCarryonBehavior->WriteLogEntry(eTime+t, i);
		}

		//detach to passenger
		pPassenger->m_pVisitorList[i] = NULL;		
	}

	setState(GetOn_Vehicle);
	GenerateEvent(dNextTime);

}
Example #10
0
File: log.cpp Project: Thalur/ak
void LogAppend(ELogLevel aLogLevel, const char* aFile, const std::string& aFunc,
               const std::string& aMessage, int aLine, ...)
{
   if (!loggerInitialized && !uninitializedLoggerUseReported) {
      uninitializedLoggerUseReported = true;
      std::cout << "WARNING: Logger used without initialization. Call InitLogFile() first!" << std::endl;
   }

   // Remove the path from the filename
   aFile = RemovePath(aFile);

   // Assemble the user-generated message
   char buffer[510];
   va_list args;
   va_start(args, aLine);
#ifdef AK_SYSTEM_WINDOWS
   vsnprintf_s(buffer, 500, _TRUNCATE, aMessage.c_str(), args);
#else
   vsnprintf(buffer, 500, aMessage.c_str(), args);
#endif
   va_end(args);

   CClock now;
   std::string timestamp(now.GetTimeLong());
   if (loggerInitialized && aLogLevel >= fileLogLevel) {
      WriteLogEntry(*logFile, timestamp, GetLevelString(aLogLevel), aFile, aFunc, aLine, buffer);
   }
   if (aLogLevel >= consoleLogLevel) {
#ifdef AK_SYSTEM_ANDROID
         __android_log_print(ANDROID_LOG_DEBUG + static_cast<int32_t>(aLogLevel), appName.c_str(), buffer);
#else
      if (simplifiedConsoleOutput) {
         std::cout << buffer << std::endl;
      } else {
         WriteLogEntry(std::cout, timestamp, GetLevelString(aLogLevel), aFile, aFunc, aLine, buffer);
      }
#endif
   }
}
void ArrivalPaxLandsideBehavior::ProcessPutCarryonToVehicle( const ElapsedTime& eEventTime )
{
	ElapsedTime serviceT = ElapsedTime(0L);
	LandsideResourceInSim* pRes = getResource();
	LandsideVehicleInSim* pV = getVehicle();
	if(pRes && pV)
	{
		serviceT = pRes->getLayoutObject()->GetServiceTime(pV->getName());
	}
	ElapsedTime nextT = eEventTime+serviceT;
	WriteLogEntry(nextT);

	////go to the parking 
	//ARCVector3 bagPos = m_pVehicle->getLastState().pos;
	//setDestination(bagPos);
	//ElapsedTime dNextTime = eEventTime;
	//dNextTime += moveTime();
	////setLocation(bagPos);		
	//WriteLogEntry(dNextTime);

	////write bag log
	//Passenger* pPassenger = (Passenger*)m_pPerson;
	//int nCount = pPassenger->m_pVisitorList.size();
	//for( int i=nCount-1; i>=0; i-- )
	//{
	//	PaxVisitor* pVis = pPassenger->m_pVisitorList[i];
	//	if (pVis == NULL)
	//		continue;
	//	VisitorLandsideBehavior* pCarryonBehavior = (VisitorLandsideBehavior*)pVis->getLandsideBehavior();
	//	ASSERT(pCarryonBehavior);
	//	//non passenger move to ground
	//	if(pCarryonBehavior)
	//	{
	//		pCarryonBehavior->setDestination(bagPos);

	//		ElapsedTime eMoveTime = moveTime();
	//		ElapsedTime eCurTime = dNextTime + eMoveTime;

	//		pCarryonBehavior->setLocation( bagPos);
	//		pCarryonBehavior->WriteLogEntry(eCurTime, i);
	//	}

	//	//detach to passenger
	//	pPassenger->m_pVisitorList[i] = NULL;		
	//}

	setState(GetOnVehicle);
	GenerateEvent(nextT);
}
void ArrivalPaxLandsideBehavior::ProcessGetOnVehicle( const ElapsedTime& eEventTime )
{
	WriteLogEntry(eEventTime);

	setState(StayOnVehicle);
	WriteLogEntry(eEventTime);

	//Notify vehicle that one passenger has moved into
	//
	LandsideVehicleInSim* pVehicle = getVehicle();
	if(pVehicle)
	{	
		if(LandsideResourceInSim* pRes = getResource())
		{
			pRes->PassengerMoveOut(this,eEventTime);
		}
		pVehicle->AddOnPax(this);
		pVehicle->NotifyPaxMoveInto(m_pPerson->getEngine(),this, eEventTime);
	}
	else
	{
		ASSERT(FALSE);
	}
}
void VisitorLandsideBehavior::flushLog( ElapsedTime p_time, bool bmissflight /*= false*/ )
{
	m_pPerson->setState(Death);
	WriteLogEntry(p_time,false);
	m_pPerson->getLogEntry().setExitTime( p_time );

	m_pPerson->getLogEntry().saveEventsToLog();
	m_pPerson->GetTerminal()->paxLog->updateItem (m_pPerson->getLogEntry(), m_pPerson->getLogEntry().getIndex());

	FlushLogforFollower(p_time);

	if(m_pPerson->getEngine()->m_simBobileelemList.IsAlive(m_pPerson))
	{
		MobileElementExitSystemEvent *pEvent = new MobileElementExitSystemEvent(m_pPerson, p_time);
		pEvent->addEvent();
	}
	else
	{
		ASSERT(0);
	}
}
Example #14
0
bool CScales::WriteByte(BYTE nValue)
{
    DWORD dwBytesWritten = 0;
    WriteLogEntry(WritePort, &nValue, 1);
    return WriteFile(m_CommPort, &nValue, 1, &dwBytesWritten, NULL) == TRUE;
}
void ArrivalPaxLandsideBehavior::processEntryLandisde( const ElapsedTime& eEventTime )
{
	if(!m_pPerson)
		return;

	InitializeBehavior();
	SetEnterLandsideLocation(location);

	if(simEngineConfig()->isSimTerminalMode())
	{	
		//WriteLogEntry(t);
		Processor* pProc=  m_pPerson->getTerminalBehavior()->getLastTerminalProc();
		ASSERT(pProc);
		if(pProc)//find 
		{
			CString strProcName = pProc->getIDName();
			CFacilityBehaviorsInSim *pFacilityBehavior = m_pPerson->getEngine()->GetLandsideSimulation()->getFacilityBehaviors();
			LandsideResourceInSim* pLandsideLinkageObject = pFacilityBehavior->GetLandsideTerminalLinkage(*pProc->getID());
			if(pLandsideLinkageObject)
			{
				//it could be curbside, bus station ...
				pLandsideLinkageObject->PassengerMoveInto(this, eEventTime);
				return;
			}
			else //the last processor is not link to any 
			{
				//check parking spot
				LandsideResourceInSim *pDestResource = NULL;
				LandsideVehicleInSim* pVehicle = m_pPerson->getEngine()->GetLandsideSimulation()->FindPaxVehicle(m_pPerson->getID());
				if(pVehicle)
				{
					setVehicle(pVehicle);
				}
				else  //vehicle not entry simulation?
				{
					//LandsideSimErrorShown::PaxSimWarning(m_pPerson,_T("Pick Vehicle is not entry simulation yet"),_T("Pax Runtime Error"),eEventTime);
					terminate(eEventTime);
					return;
				}

				if(LandsideResourceInSim* pDestResource = pVehicle->getLastState().getLandsideRes() )
				{
					setResource(pDestResource);
					//destination is parking lot
					setDestResource(pDestResource);
					setState(MoveToFacility);
					GenerateEvent(eEventTime + ElapsedTime(2L)); //@CodeWarn ?2sec what for
					return;
				}
				else 
				{
					LandsideSimErrorShown::PaxSimWarning(m_pPerson,_T("Pax vehicle is not in any resource"),_T("Pax Runtime Error"),eEventTime);
					terminate(eEventTime);
					return;
				}
			}			
		}
		else  //no proc?
		{
			LandsideSimErrorShown::PaxSimWarning(m_pPerson,_T("No Last Processor"),_T("Pax Runtime Error"),eEventTime);
			terminate(eEventTime);
			return;
		}
	}
	else
	{
		if(!m_pVehicle)
		{
			LandsideVehicleInSim* pVehicle = m_pPerson->getEngine()->GetLandsideSimulation()->FindPaxVehicle(m_pPerson->getID());
			if(pVehicle)
			{
				setVehicle(pVehicle);
			}
			else
			{
				ASSERT(FALSE);
				terminate(eEventTime);
				return;
			}
		}

		UpdateEntryTime(eEventTime);
		//get on to the vehicle straight
		CPoint2008 pos= m_pVehicle->getOffVehiclePos( CPoint2008(getPoint()) );
		LandsideResourceInSim* pRes= m_pVehicle->getState(eEventTime).getLandsideRes();
		setResource(pRes);
		setLocation(pos);
		setDestination(pos);
		WriteLogEntry(eEventTime);

		m_pPerson->setState(MoveToVehicle);
		GenerateEvent(eEventTime);
	}
	

	
	
}
Example #16
0
int LogHandler(char cmd, int id_in, varList **commands, int *id_out) {
	int ret = 0;
	FILE *post_file = NULL;
	FILE *pre_file = NULL;
	char *post_log = NULL;
	char *pre_log = NULL;
	int post_log_len = strlen(LOG_PATH) + strlen(LOG_POST_NAME) + strlen(DB_GLOBAL) + 1;
	int pre_log_len = strlen(LOG_PATH) + strlen(LOG_PRE_NAME) + strlen(DB_GLOBAL) + 1;

	post_log = (char *)malloc(sizeof(char *) * post_log_len);
	pre_log = (char *)malloc(sizeof(char *) * pre_log_len);

	strncpy(post_log, LOG_PATH, post_log_len);
	strncat(post_log, DB_GLOBAL, post_log_len);
	strncat(post_log, LOG_POST_NAME, post_log_len);

	strncpy(pre_log, LOG_PATH, pre_log_len);
	strncat(pre_log, DB_GLOBAL, pre_log_len);
	strncat(pre_log, LOG_PRE_NAME, pre_log_len);

	switch (cmd){
		case LOG_WRITE_PRE:
			debug_out(4, "log: In LOG_WRITE_PRE\n");
			pre_file = fopen(pre_log, "a");
			if(pre_file != NULL)
				debug_out(4, "log: Opened file '%s'\n", pre_log);
			else
			{
				debug_out(4, "log: Could not open file '%s'\n", pre_log);
				ret = -1;
				break;
			}
			WriteLogEntry(pre_file, id_in, *commands);
			debug_out(4, "log: logentry written to file\n");
			break;
		case LOG_WRITE_POST:
			debug_out(4, "log: In LOG_WRITE_POST\n");
			post_file = fopen(post_log, "a");
			if(post_file != NULL)
				debug_out(4, "log: Opened file '%s'\n", post_log);
			else {
				debug_out(4, "log: Could not open file '%s'\n", post_log);
				ret = -1;
				break;
			}
			WriteLogEntry(post_file, id_in, *commands);
			debug_out(4, "log: logentry written to file\n");
			break;
		case LOG_READ_POST:
			post_file = fopen(post_log, "r");
			if(post_file != NULL) {
				if(ReadLogEntry(&post_file, &id_in, commands) == -1) {
					*id_out = LOG_NO_ID;
					ret = -1;
				}
			}
			break;
		case LOG_READ_PRE:
			pre_file = fopen(pre_log, "r");
			if(pre_file != NULL) {
				if(ReadLogEntry(&pre_file, &id_in, commands) == -1) {
					*id_out = LOG_NO_ID;
					ret = -1;
				}
			}
			break;
		case LOG_LAST_ID:
			if(id_out != NULL) {
				ret = GetLastId(pre_log, post_log, id_out);
			}
			else
				ret = -1;
			break;
		case LOG_GET_NEXT_PRE_ID:
			if(id_out != NULL)
				*id_out = GetNextId(pre_log, id_in);
			else
				ret = -1;
			break;
		case LOG_GET_NEXT_POST_ID:
			if(id_out != NULL)
				*id_out = GetNextId(post_log, id_in);
			else
				ret = -1;
			break;
		case LOG_CHECK_ID:
			break;
		default:
			ret = -1;
			break;
	}
	if(pre_file) {
		fclose(pre_file);
	}
	if(post_file) {
		fclose(post_file);
	}

	return ret;
}
Example #17
0
int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE hArray[3]; // process, event, heartbeat
    DWORD dwResult, dwTimeout, dwElapsed, dwSize;
    time_t tNow, tLast, tStart;
    TCHAR  tszBuffer[MAX_PATH+1];

    for(tLast = 0 ; tLast < 30 ; tLast++) Sleep(1000);

    if (argc < 5)
    {
        return 1;
    }

    if (!_stscanf_s(argv[1], _T("%d"), &hArray[0])) // process
    {
        return 2;
    }


    if (!_stscanf_s(argv[2], _T("%d"), &hArray[1])) // restart
    {
        return 2;
    }

    if (!_stscanf_s(argv[3], _T("%d"), &hArray[2])) // heartbeat
    {
        return 2;
    }

    if (!_stscanf_s(argv[4], _T("%d"), &dwTimeout)) // timeout
    {
        return 2;
    }

    dwSize = GetEnvironmentVariable(_T("ioFTPD_LogDir"), tszBuffer, sizeof(tszBuffer)/sizeof(*tszBuffer));
    if ((dwSize == 0) || (dwSize + 10 >= sizeof(tszBuffer)/sizeof(*tszBuffer)))
    {
        tszBuffer[0] = _T('.');
        tszBuffer[1] = 0;
    }

    _stprintf_s(tszLogFileName, sizeof(tszLogFileName)/sizeof(*tszLogFileName), _T("%s\\%s"), tszBuffer, _T("Watch.log"));

    time(&tStart);
    tLast = 0;

    while (1)
    {
        dwResult = WaitForMultipleObjectsEx(3, hArray, FALSE, 10000, TRUE);

        if (dwResult == WAIT_TIMEOUT)
        {
            time(&tNow);
            if (tLast)
            {
                // we updated it at least once which means we are watching it now...
                // preloading could take minutes so we can't start timing it out until we know that's done.
                dwElapsed = (DWORD) (tNow - tLast);
                if ((tLast < tNow) && (dwElapsed > dwTimeout))
                {
                    // rut ro!  it appears like it locked up!
                    WriteLogEntry("Server timeout reached (%d > %d), killing it.\r\n", dwElapsed, dwTimeout);
                    TerminateProcess(hArray[0], 1);
                    return 1;
                }
            }
            continue;
        }
        if (dwResult == WAIT_OBJECT_0)
        {
            // ioFTPD exited on it's own, time to commit suicide
            return 0;
        }
        if (dwResult == (WAIT_OBJECT_0 + 1))
        {
            // the deadlock event was signaled, terminate the process
            WriteLogEntry("Received deadlock signal from ioFTPD, killing it.\r\n");
            TerminateProcess(hArray[0], 1);
            return 1;
        }
        if (dwResult == (WAIT_OBJECT_0 + 2))
        {
            // we received a heartbeat signal, so it's still alive...
            time(&tLast);
            continue;
        }

        if (dwResult == WAIT_IO_COMPLETION)
        {
            // something weird going on if this happens... remote thread injection?
            WriteLogEntry("Received IO completion ?!?\r\n");
            continue;
        }

        WriteLogEntry("Wait error, aborting!.\r\n");
        return 0;
    }

    return 0;
}
void ArrivalPaxLandsideBehavior::ProcessMoveToFacility( const ElapsedTime& eEventTime )
{
	LandsideResourceInSim *pDestResource = getDestResource();
	if(pDestResource->toParkLotSpot())
	{
		LandsideParkingSpotInSim* pParkSpot = pDestResource->toParkLotSpot();

		ARCVector3 nextPos = pParkSpot->getPos();
		CPoint2008 endPos;
		endPos.init(nextPos.n[VX],nextPos.n[VY],nextPos.n[VZ]);

		CLandsideTrafficSystem* pLandsideTrafficInSim = m_pLandsideSim->GetLandsideTrafficeManager();
//		LandsideResourceInSim* pStartLandsideResInSim = getResource();
//		LandsideResourceInSim* pEndLandsideResInSim = pParkSpot->getParkingLot();

		CPoint2008 startPos;
		startPos.init(getPoint().n[VX],getPoint().n[VY],getPoint().n[VZ]);

		if( !pLandsideTrafficInSim->EnterTrafficSystem(eEventTime,ArriveAtFacility,this,startPos,endPos))
		{
			ElapsedTime dNextTime = eEventTime;
			setDestination(endPos);
			ElapsedTime etime = moveTime();
			//setLocation(nextPos);	
			dNextTime += etime;
			WriteLogEntry(dNextTime);
			m_pPerson->setState(ArriveAtFacility);
			GenerateEvent(dNextTime);
			return;
		}
	}
	else if(pDestResource->toLaneSpot())//move to curbside
	{
		//go to the waiting area of curbside
		IParkingSpotInSim *pCurbsideSpot = pDestResource->toLaneSpot();
		LandsideResourceInSim *pParentResource = pCurbsideSpot->GetParentResource();
		LandsideCurbSideInSim *pCurbsideInsim = pParentResource->toCurbSide();
		ASSERT(pCurbsideInsim != NULL);
		CPoint2008 pPaxWaitAreaPosInCurbside = pCurbsideInsim->GetPaxWaitPos();

		CPoint2008 startPos;
		startPos.init(getPoint().n[VX],getPoint().n[VY],getPoint().n[VZ]);

		CPoint2008 endPos = pPaxWaitAreaPosInCurbside;

		CLandsideTrafficSystem* pLandsideTrafficInSim = m_pLandsideSim->GetLandsideTrafficeManager();
		if( !pLandsideTrafficInSim->EnterTrafficSystem(eEventTime,ArriveAtFacility,this,startPos,endPos))
		{
			ElapsedTime dNextTime = eEventTime;
			setDestination(endPos);
			ElapsedTime etime = moveTime();
			//setLocation(nextPos);	
			dNextTime += etime;
			WriteLogEntry(dNextTime);
			m_pPerson->setState(ArriveAtFacility);
			GenerateEvent(dNextTime);
			return;
		}

	}
	else
	{
		ASSERT(FALSE);
		terminate(eEventTime);
	}

}