Exemplo n.º 1
0
void VJSONValue::GetTime(VTime& outTime) const
{
	VError err = VE_OK;
	switch (fType)
	{

		case JSON_string:
		{
			VString s;
			s.FromString(fString);
			outTime.FromString(s);
			break;
		}

		case JSON_date:
		{
			outTime.FromMilliseconds(fTimeStamp);
			break;
		}

		case JSON_number:
		{
			outTime.FromMilliseconds(fNumber);
			break;
		}

		default:
		{
			outTime.Clear();
			outTime.SetNull(true);
			break;
		}
	}
}
Exemplo n.º 2
0
bool JS4D::DateObjectToVTime( ContextRef inContext, ObjectRef inObject, VTime& outTime, ExceptionRef *outException)
{
	// it's caller responsibility to check inObject is really a Date using ValueIsInstanceOf
	
	// call getTime()
	bool ok = false;
    JSStringRef jsString = JSStringCreateWithUTF8CString( "getTime");
	JSValueRef getTime = JSObjectGetProperty( inContext, inObject, jsString, outException);
	JSObjectRef getTimeFunction = JSValueToObject( inContext, getTime, outException);
    JSStringRelease( jsString);
	JSValueRef result = (getTime != NULL) ? JSObjectCallAsFunction( inContext, getTimeFunction, inObject, 0, NULL, outException) : NULL;
	if (result != NULL)
	{
		// The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
		double r = JSValueToNumber( inContext, result, outException);
		sLONG8 n = (sLONG8) r;
		if (n == r)
		{
			outTime.FromUTCTime( 1970, 1, 1, 0, 0, 0, 0);
			outTime.AddMilliseconds( n);
			ok = true;
		}
		else
		{
			outTime.SetNull( true);
		}
	}
	else
	{
		outTime.SetNull( true);
	}
	return ok;
}
Exemplo n.º 3
0
JS4D::ObjectRef JS4D::VTimeToObject( ContextRef inContext, const VTime& inTime, ExceptionRef *outException)
{
	if (inTime.IsNull())
		return NULL;	// can't return JSValueMakeNull as an object
	
	sWORD year, month, day, hour, minute, second, millisecond;
	
	inTime.GetLocalTime( year, month, day, hour, minute, second, millisecond);

	JSValueRef	args[6];
	args[0] = JSValueMakeNumber( inContext, year);
	args[1] = JSValueMakeNumber( inContext, month-1);
	args[2] = JSValueMakeNumber( inContext, day);
	args[3] = JSValueMakeNumber( inContext, hour);
	args[4] = JSValueMakeNumber( inContext, minute);
	args[5] = JSValueMakeNumber( inContext, second);

	#if NEW_WEBKIT
	JSObjectRef date = JSObjectMakeDate( inContext, 6, args, outException);
	#else
    JSStringRef jsClassName = JSStringCreateWithUTF8CString("Date");
    JSObjectRef constructor = JSValueToObject( inContext, JSObjectGetProperty( inContext, JSContextGetGlobalObject( inContext), jsClassName, NULL), NULL);
    JSStringRelease( jsClassName);
    JSObjectRef date = JSObjectCallAsConstructor( inContext, constructor, 6, args, outException);
	#endif

	return date;
}
void VJSGlobalClass::do_isoToDate(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VTime dd;
	VString s;
	ioParms.GetStringParam(1, s);
	dd.FromJSONString(s);
	ioParms.ReturnTime(dd);
}
Exemplo n.º 5
0
void VJSONValue::SetTime(const VTime& inTime)
{
	_Dispose();
	if (inTime.IsNull())
		fType = JSON_null;
	else
	{
		fType = JSON_date;
		fTimeStamp = inTime.GetMilliseconds();
	}
}
Exemplo n.º 6
0
//jmo - Ranger ca qq part !
static VTime UnixToXBoxTime(time_t inTime)
{
    VTime res;
    struct tm tm;

    if(gmtime_r(&inTime, &tm)!=NULL)
        //jmo - gmtime month is in the range 0 to 11 but FromUTCTime() wants it in 1 to 12
        // YT - 31-Mar-2011 - tm_year is Year-1900 see struct tm declaration.
        res.FromUTCTime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 0);

    return res;
}
void VJSGlobalClass::do_dateToIso(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString s;
	VJSValue jsval(ioParms.GetContextRef());
	if (ioParms.CountParams() > 0)
	{
		VTime dd;
		jsval = ioParms.GetParamValue(1);
		jsval.GetTime(dd);
		dd.GetJSONString(s);
	}
	ioParms.ReturnString(s);
}
bool VJSGlobalObject::IsIncludedFilesHaveBeenChanged() const
{
	bool haveChanges = false;

	for (VectorOfFileModificationTime::const_iterator iter = fIncludedFilesModificationTime.begin() ; (iter != fIncludedFilesModificationTime.end()) && !haveChanges ; ++iter)
	{
		if (iter->first != NULL)
		{
			VTime modificationTime;
			iter->first->GetTimeAttributes( &modificationTime);
			haveChanges = (modificationTime.CompareTo( iter->second) != CR_EQUAL);
		}
	}
	return haveChanges;
}
Exemplo n.º 9
0
ShellMaturityEvent::ShellMaturityEvent( const VTime & tSend, const VTime & tRecv,
                                        const ObjectID &sender,
                                        const ObjectID & receiver,
                                        const EventId & evtID,
                                        const VTime & tMature ) :
    ClothoEvent( tSend, tRecv, sender, receiver, evtID ),
    m_age_of_maturity( tMature.clone() ) {}
Exemplo n.º 10
0
void ThreadedOptFossilCollManager::fossilCollect(SimulationObject *object,
		const VTime &currentTime, const unsigned int &threadId) {
	unsigned int objId = object->getObjectID()->getSimulationObjectID();
	fossilPeriod[objId]++;
	if (fossilPeriod[objId] >= 20) {
		int intCurTime = currentTime.getApproximateIntTime();
		if (intCurTime > activeHistoryLength[objId]) {
			int collectTime = intCurTime - activeHistoryLength[objId];
			if (collectTime > lastCollectTimes[objId]) {
				lastCollectTimes[objId] = collectTime;
				cout << "Fossil Collecting " << collectTime << endl;
				mySimManager->getStateManagerNew()->fossilCollect(object,
						collectTime, threadId);
				mySimManager->getOutputManagerNew()->fossilCollect(object,
						collectTime, threadId);
				mySimManager->getEventSetManagerNew()->fossilCollect(object,
						collectTime, threadId);
				/*
				 utils::debug << "Fossil Collecting Obj " << objId
				 << " at time " << collectTime << " now at " << intCurTime << endl;
				 */
			}
		}
		fossilPeriod[objId] = 0;
	}
	mySimManager->setCheckpointing(false);
}
Exemplo n.º 11
0
// добавление таймштампа
bool VSQLGenerator::AddTimestamp(const std::string & name, const VTime & value)
{	
	if (this->NameExists(name)) return false;
//	this->prm_names.push_back(name);
//	struct tm __t = value.ToTM();
//	this->prm_bodies.push_back(VIBParameter(SQL_TIMESTAMP, (const char*)&__t));

	if (InlineSQL)
	{
		this->AddString(name, value.DateToStringISO());
	}
	else
	{
		struct tm __t = value.ToTM();
		this->AddParameter(name, VIBParameter(SQL_TIMESTAMP, (const char*)&__t));
	}

	return true;
}
Exemplo n.º 12
0
void XWinIntlMgr::FormatTime( const VTime& inTime, VString& outTime, EOSFormats inFormat, bool inUseGMTTimeZoneForDisplay)
{
	// 1:system short time; 2:system medium time; 3:system long time

	DWORD timeFormat=0;
	switch(inFormat)
	{
		case eOS_SHORT_FORMAT:// No signs
		case eOS_MEDIUM_FORMAT:// No signs
			timeFormat=TIME_NOTIMEMARKER;
			break;
		case eOS_LONG_FORMAT://all
			break;
		default:
			break;
	};

	// Prepare SYSTEMTIME for windows.
	sWORD YY=0,MM=0,DD=0,hh=0,mm=0,ss=0,ms=0;
	SYSTEMTIME osTime={0};
	if (inUseGMTTimeZoneForDisplay)
		inTime.GetUTCTime (YY,MM,DD,hh,mm,ss,ms);
	else
		inTime.GetLocalTime (YY,MM,DD,hh,mm,ss,ms);
	osTime.wYear=YY;
	osTime.wMonth=MM;
	osTime.wDay=DD;
	osTime.wHour=hh;
	osTime.wMinute=mm;
	osTime.wSecond=ss;
	osTime.wMilliseconds=ms;

	// Let the OS do the stuff.
	UniChar acBuffer[256];
	if (::GetTimeFormatW( fDialect,timeFormat,&osTime,NULL,acBuffer,sizeof(acBuffer)))
		outTime=acBuffer;
	else
		outTime.Clear();
}
Exemplo n.º 13
0
bool VJSValue::GetTime( VTime& outTime, JS4D::ExceptionRef *outException) const
{
	bool ok;
	if (JS4D::ValueIsInstanceOf( fContext, fValue, CVSTR( "Date"), outException))
	{
		JSObjectRef dateObject = JSValueToObject( fContext, fValue, outException);
		ok = JS4D::DateObjectToVTime( fContext, dateObject, outTime, outException, false);
	}
	else
	{
		outTime.SetNull( true);
		ok = false;
	}
	return ok;
}
//static
icu::GregorianCalendar XLinuxIntlMgr::VTimeToGregorianCalendar(const VTime& inDate)
{
	//VTime is in GMT time zone
	icu::TimeZone* gmt=TimeZone::getGMT()->clone();

	UErrorCode err=U_ZERO_ERROR;
	GregorianCalendar cal(gmt, err);	//cal owns gmt and should destroy it
	xbox_assert(err==U_ZERO_ERROR);

	sWORD year, month, day, hour, minute, second, millisecond;
	inDate.GetUTCTime(year, month, day, hour, minute, second, millisecond);

	cal.set(year, month, day, hour, minute, second);

	return cal;
}
Exemplo n.º 15
0
static time_t XBoxToUnixTime(const VTime& inTime)
{
    struct tm tm;
    memset(&tm, 0, sizeof(tm));

    sWORD year, mon, day, hour, min, sec, ms;
    inTime.GetUTCTime(year, mon, day, hour, min, sec, ms /*unused*/);

    //jmo - mktime month is in the range 0 to 11 but GetUTCTime() give it in 1 to 12
    // YT - 31-Mar-2011 - tm_year is Year-1900 see struct tm declaration.
    tm.tm_year=year-1900, tm.tm_mon=mon-1, tm.tm_mday=day, tm.tm_hour=hour, tm.tm_min=min, tm.tm_sec=sec;

    time_t res=mktime(&tm); //Calling mktime() also sets the external variable tzname
    xbox_assert(res!=(time_t)-1);

    return res;
}
Exemplo n.º 16
0
void testMySQLConnectorPreparedStatementWithDateParam()
{
    CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) );

    VJSONObject* params = new VJSONObject();

    params->SetProperty ( "hostname",	MYSQL_HOST );

    params->SetProperty ( "user",		MYSQL_USER );

    params->SetProperty ( "password",	MYSQL_CORRECT_PASSWORD );

    params->SetProperty ( "database",	MYSQL_DATABASE );

    params->SetProperty ( "port",		MYSQL_PORT );

    params->SetProperty ( "ssl",			MYSQL_SSL_FALSE );

    ISQLSession* session = connector->CreateSession ( params );

    ReleaseRefCountable ( &params );

    if ( session != NULL )
    {
        ISQLStatement* statement = session->CreateStatement ( "SELECT * FROM people WHERE date_of_birth = ?" );

        VError error = VE_OK;

        ISQLPreparedStatement* pStmt = statement->CreatePreparedStatement ( error );

        VTime keyDate;

        keyDate.FromUTCTime ( 1984, 8, 11, 0, 0, 0, 0 );

        pStmt->SetNthParameter ( 1, keyDate );

        ISQLResultSet* res = pStmt->Execute ( error );

        if ( error == VE_OK )
        {
            if ( res->IsError() )
            {
                printf ( "an error occured in the execution of the prepared statement!\n" );

                VString msg = res->GetErrorMessage();

                printf ( "error msg = %V\n", &msg );
            }
            else
            {
                while ( !res->IsEOF() )
                {
                    ISQLRow* row = res->RetainNextRow();

                    VValue* idValue = row->GetNthValue ( 1 );

                    VValue* firstNameValue = row->GetNthValue ( 3 );

                    VValue* dateValue = row->GetNthValue ( 5 );

                    VString DbgMsg;

                    DbgMsg.AppendPrintf ( "idValue = %V, firstNameValue = %V, dateValue = %V", idValue, firstNameValue, dateValue );

                    DebugMsg ( "%V", &DbgMsg );

                    ReleaseRefCountable ( &row );
                }
            }

            ReleaseRefCountable ( &res );
        }
        else
        {
            printf ( "an error occured in the execution of the prepared statement!\n" );
        }

        ReleaseRefCountable ( &session );
    }
    else
    {
        printf ( "connection to mysql server failed ..\n" );
    }

    ReleaseRefCountable ( &connector );

}
Exemplo n.º 17
0
void XWinIntlMgr::FormatDate( const VTime& inDate, VString& outDate, EOSFormats inFormat, bool inUseGMTTimeZoneForDisplay)
{
	// Prepare SYSTEMTIME for windows.
	sWORD YY = 0;
	sWORD MM = 0;
	sWORD DD = 0;
	sWORD hh = 0;
	sWORD mm = 0;
	sWORD ss = 0;
	sWORD ms = 0;
	if (inUseGMTTimeZoneForDisplay)
		inDate.GetUTCTime (YY,MM,DD,hh,mm,ss,ms);
	else
		inDate.GetLocalTime (YY,MM,DD,hh,mm,ss,ms);

	// Verify if date >1st Jan 1601 (GetDateFormat doesn't support earlier dates.
	if (YY>=1601)
	{
		// Let the OS do it's job.
		UniChar acBuffer[256];

		SYSTEMTIME osDate={0};
		osDate.wYear=YY;
		osDate.wMonth=MM;
		osDate.wDay=DD;
		osDate.wHour=hh;
		osDate.wMinute=mm;
		osDate.wSecond=ss;
		osDate.wMilliseconds=ms;

		if (inFormat == eOS_MEDIUM_FORMAT)
		{
			VString pattern;
			if (GetLocaleInfo( LOCALE_SLONGDATE, pattern))
			{
				// replace long month and date by medium ones
				pattern.ExchangeRawString( CVSTR( "MMMM"), CVSTR( "MMM"));
				pattern.ExchangeRawString( CVSTR( "dddd"), CVSTR( "ddd"));
				if (::GetDateFormatW( fDialect, 0, &osDate, pattern.GetCPointer(), acBuffer, sizeof(acBuffer)))
					outDate = acBuffer;
			}
		}
		else
		{
			// Let the OS do the stuff.
			DWORD dateFormat = (inFormat == eOS_SHORT_FORMAT) ? DATE_SHORTDATE : DATE_LONGDATE;
			if (::GetDateFormatW(fDialect,dateFormat,&osDate,NULL,acBuffer,sizeof(acBuffer)))
				outDate = acBuffer;
		}
	}
	else
	{
		// Get the date pattern
		VString pattern;
		if (GetLocaleInfo( (inFormat == eOS_LONG_FORMAT) ? LOCALE_SLONGDATE : LOCALE_SSHORTDATE, pattern))
		{
			XBOX::VString tokens="gyMd";
			UniChar oldToken=0;
			sLONG count=0;
			pattern.AppendChar(' ');
			sLONG YY2=YY%100;
			XBOX::VString oneName;
			for (int pos=0;pos<pattern.GetLength();pos++)
			{
				UniChar token=pattern[pos];
				if (tokens.FindUniChar(token)>=1)
				{
					if (token==oldToken)
						count++;
					else
					{
						if (!count)
						{
							count=1;
							oldToken=token;
						}
					}
				}

				if (count && token!=oldToken)
				{
					switch(oldToken)
					{
					case 'g':
						if (count==2)
						{
							// TODO: ERA will be added if really wanted.
						}
						else
						{
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
						}
						break;

					case 'y':	// YEAR
						switch(count)
						{
						case 5:
						case 4:		// 4 or more digits date
							outDate.AppendLong(YY);
							break;

						case 2:		// 2 digits with starting 0.
							if (YY2<=9)
								outDate.AppendLong(0);
						case 1:		// 1 or 2 digits
							outDate.AppendLong(YY2);
							break;

						default:
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
							break;
						}
						break;

					case 'M':	// MONTH
						switch(count)
						{
						case 4:	// Long name
						case 3:	// Abbreviated name
							if (GetLocaleInfo( ((count==4) ? LOCALE_SMONTHNAME1 : LOCALE_SABBREVMONTHNAME1) + MM - 1, oneName))
								outDate += oneName;
							break;

						case 2:	// 2 digits number (leading 0)
							if (MM<=9)
								outDate.AppendLong(0);
						case 1:	// 1 or 2 digits number
							outDate.AppendLong(MM);
							break;

						default:
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
							break;
						}
						break;

					case 'd':	// DAY
						switch(count)
						{
						case 4:	// Weekday long name
						case 3:	// Weekday abbreviated name
							if (GetLocaleInfo( ((count==4) ? LOCALE_SDAYNAME1 : LOCALE_SABBREVDAYNAME1) + (inDate.GetWeekDay() + 6) % 7, oneName))
								outDate += oneName;
							break;

						case 2:	// Month day on 2 digits (leading 0)
							if (DD<=9)
								outDate.AppendLong(0);
						case 1:	// Month day on 1 or 2 digits.
							outDate.AppendLong(DD);
							break;

						default:
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
							break;
						}
						break;

					}
					count=0;
				}

				if (!count)
					outDate.AppendUniChar(token);
				oldToken=token;
			}

			// Remove the extra space at end of pattern.
			if (outDate.GetLength()>1)
				outDate.SubString(1,outDate.GetLength()-1);
		}
	}
}
void
ThreadedChebyFossilCollManager::sampleRollback(SimulationObject* object, const VTime& rollVTime) {
    int rollbackTime = rollVTime.getApproximateIntTime();
    int rollbackDistance = object->getSimulationTime().getApproximateIntTime() - rollbackTime;
    unsigned int objId = object->getObjectID()->getSimulationObjectID();
    
    int threadId = *((int*) pthread_getspecific(threadKey)); 
    getOfcChebyLock(threadId,mySimManager->getSyncMechanism()); 
    
    if (numSamples[objId] < maxSamples) {
        // Sample the rollback.
        total[objId] = total[objId] - samples[objId][sampleIndex[objId]];
        samples[objId][sampleIndex[objId]] = rollbackDistance;
        total[objId] = total[objId] + rollbackDistance;

        sampleIndex[objId]++;
        numSamples[objId]++;

        // If there are enough samples, then calculate the mean, variance
        // and new active history length.
        if (numSamples[objId] > minSamples) {
            double sampleVariance = 0;
            double mean1, mean2;
            double variance1, variance2;
            mean1 = mean2 = variance1 = variance2 = 0;

            double sampleMean = total[objId] / double(numSamples[objId]);

            for (int i = 0; i < numSamples[objId]; i++) {
                sampleVariance += ((double(samples[objId][i]) - sampleMean) *
                                   (double(samples[objId][i]) - sampleMean));
            }

            sampleVariance = sampleVariance / numSamples[objId];

            mean1 = sampleMean - 1.96*sqrt(sampleVariance/(double)numSamples[objId]);
            mean2 = sampleMean + 1.96*sqrt(sampleVariance/(double)numSamples[objId]);

            for (int i = 0; i < numSamples[objId]; i++) {
                variance1 += ((double(samples[objId][i]) - mean1) *
                              (double(samples[objId][i]) - mean1));
                variance2 += ((double(samples[objId][i]) - mean2) *
                              (double(samples[objId][i]) - mean2));
            }

            variance1 = variance1 / numSamples[objId];
            variance2 = variance2 / numSamples[objId];

            if (variance1 < variance2) {
                sampleVariance = variance2;
            } else {
                sampleVariance = variance1;
            }

            activeHistoryLength[objId] = sampleMean + errorTerm * sqrt(sampleVariance/(1.0-riskFactor));
            debug::debugout << objId << " - NEW LENGTH: " << activeHistoryLength[objId] << endl;
        }
    }

    if (lastCollectTimes[objId] >= 0 && !recovering && rollbackTime <= lastCollectTimes[objId]) {
        debug::debugout << mySimManager->getSimulationManagerID()
                        << " - Catastrophic Rollback: Last collection time: " << lastCollectTimes[objId]
                        << ", Rollback Time: " << rollbackTime << ", Starting Recovery." << endl;

        setRecovery(objId, rollbackTime);
    }
    releaseOfcChebyLock(threadId,mySimManager->getSyncMechanism()); 
}
Exemplo n.º 19
0
void ThreadedTimeWarpMultiSet::rollback(SimulationObject* simObj,
                                        const VTime& rollbackTime, int threadId) {
    // Go through the entire processed events queue and put any events with
    // a receive time greater than or equal to the rollback time back in the
    // unprocessed queue.
    unsigned int objId = simObj->getObjectID()->getSimulationObjectID();
    this->getProcessedLock(threadId, objId);
    vectorIterator[threadId] = processedQueue[objId]->begin();
    int tempCount = 0;
    if (rollbackTime.getApproximateIntTime() == 0) {
        tempCount = processedQueue[objId]->size();
    } else {
        vectorIterator[threadId] = processedQueue[objId]->begin();
        while (vectorIterator[threadId] != processedQueue[objId]->end()
                && (*(vectorIterator[threadId]))->getReceiveTime()
                < rollbackTime) {
            (vectorIterator[threadId])++;
            tempCount++;
        }
        const unsigned int
        eventIdRollback =
            mySimulationManager->getStateManagerNew()->getEventIdForRollback(
                threadId, objId);
        const unsigned int
        senderObjectId =
            mySimulationManager->getStateManagerNew()->getSenderObjectIdForRollback(
                threadId, objId);
        const unsigned int
        senderObjectSimId =
            mySimulationManager->getStateManagerNew()->getSenderObjectSimIdForRollback(
                threadId, objId);
        //  cout << "The saved EventId is --------------------->>>>>>>>>>>> : "
        //          << eventIdRollback << endl;
        //  cout << "The First EventId is --------------------->>>>>>>>>>>> : "
        //          << (*(vectorIterator[threadId]))->getEventId() << endl;
        //  cout << "The saved SenderObjectId is --------------------->>>>>>>>>>>> : "
        //          << senderObjectId << endl;
        while (vectorIterator[threadId] != processedQueue[objId]->end()) {
            EventId tempEventId = (*(vectorIterator[threadId]))->getEventId();
            unsigned int
            tempSenderObjectId =
                (*(vectorIterator[threadId]))->getSender().getSimulationObjectID();
            if (tempEventId.getEventNum() != eventIdRollback
                    || tempSenderObjectId != senderObjectId) {
                /*cout << "Skipping Event.......::::::::::::: "
                 << **(vectorIterator[threadId]) << endl;*/
                (vectorIterator[threadId])++;
                tempCount++;
            } else {
                /*          cout << " Matched EventId ::::" << **(vectorIterator[threadId])
                 << endl;*/
                break;
            }
        }
        tempCount = processedQueue[objId]->size() - tempCount;
    }

    debug::debugout << "( " << mySimulationManager->getSimulationManagerID()
                    << " ) Object - " << objId << " Rollback returns : " << tempCount
                    << " events back to Unprocessed Queue - " << threadId << endl;
    unProcessedQueue[objId]->insert(vectorIterator[threadId],
                                    processedQueue[objId]->end());
    processedQueue[objId]->erase(vectorIterator[threadId],
                                 processedQueue[objId]->end());
    this->releaseProcessedLock(threadId, objId);

    // Increment number of rolled back events
    //cout << "rollback completed " << tempCount << " events rolled back, LTSF " << LTSFObjId[objId][LTSFOWNER] << endl;
    __sync_fetch_and_add(&(rolledBackEventsByObj[objId]), tempCount);
    __sync_fetch_and_add(&(rolledBackEventsByLTSF[ LTSFObjId[objId][LTSFOWNER] ]), tempCount);

    // Perform calculation to see if a load balance 'action' is necessary
    // Load balancing function is performed using the currently running thread
    if (lbType) {
        myLoadBalancer->balanceCheck();
    }
}
void GVTManagerImplementationBase::setGVT( const VTime &newGVT ){
  //It is possible some thread is using gVT so it cant be deleted here
  //for the threadedTimeWarp Version
  //delete gVT;
  gVT = newGVT.clone();
}
Exemplo n.º 21
0
void
DefaultSchedulingManager::setLastScheduledEventTime( const VTime &newTime ) {
    delete lastScheduledTime;
    lastScheduledTime = newTime.clone();
}
Exemplo n.º 22
0
VJSONValue::VJSONValue(const VTime& inTime)
: fType(inTime.IsNull() ? JSON_null : JSON_date)
{
	if (fType == JSON_date)
		fTimeStamp = inTime.GetMilliseconds();
}
Exemplo n.º 23
0
VError VJSONBinaryImporter::GetValue(VJSONValue& outVal)
{
	VError err = VE_OK;
	sBYTE btype = *((uBYTE*)fCurPtr);
	++fCurPtr;
	switch (btype)
	{
		case JSON_null:
			outVal.SetNull();
			break;

		case JSON_undefined:
			outVal.SetUndefined();
			break;

		case JSON_true:
			outVal.SetBool(true);
			break;

		case JSON_false:
			outVal.SetBool(false);
			break;

		case JSON_string:
			{
				VString s;
				sLONG len = *((sLONG*)fCurPtr);
				fCurPtr += 4;
				s.FromBlock(fCurPtr, len * 2, VTC_UTF_16);
				fCurPtr += (len * 2);
				outVal.SetString(s);
			}
			break;

		case JSON_date:
			{
				VTime dd;
				sLONG8 ll = *((sLONG8*)fCurPtr);
				fCurPtr += 8;
				dd.FromMilliseconds(ll);
				outVal.SetTime(dd);
			}
			break;

		case JSON_number:
			{
				Real rr = *((Real*)fCurPtr);
				fCurPtr += sizeof(Real);
				outVal.SetNumber(rr);
			}
			break;

		case JSON_object:
			{
				if (*((sWORD*)fCurPtr) == -2)
				{
					outVal.SetUndefined();
				}
				else
				{
					VJSONObject* obj = new VJSONObject();
					sWORD len;
					do
					{
						len = *((sWORD*)fCurPtr);
						fCurPtr += 2;
						if (len >= 0)
						{
							VString name;
							name.FromBlock(fCurPtr, (sLONG)len * 2, VTC_UTF_16);
							fCurPtr += ((sLONG)len * 2);
							VJSONValue val;
							err = GetValue(val);
							obj->SetProperty(name, val);
						}
					} while (err == VE_OK && len != -1);
					outVal.SetObject(obj);
					QuickReleaseRefCountable(obj);
				}
			}
			break;

		case JSON_array:
			{
				sLONG count = *((sLONG*)fCurPtr);
				fCurPtr += 4;
				if (count == -2)
				{
					outVal.SetUndefined();
				}
				else
				{
					VJSONArray* arr = new VJSONArray();
					for (sLONG i = 0; i < count && err == VE_OK; ++i)
					{
						VJSONValue val;
						err = GetValue(val);
						arr->Push(val);
					}
					outVal.SetArray(arr);
					QuickReleaseRefCountable(arr);
				}
			}
			break;

		default:
			xbox_assert(false);
			break;
	}
	return err;
}
Exemplo n.º 24
0
ShellMaturityEvent::ShellMaturityEvent( const VTime & tSend, const VTime & tRecv,
                                        const ObjectID &sender,
                                        const ObjectID & receiver,
                                        const unsigned int evtID ) :
    ClothoEvent( tSend, tRecv, sender, receiver, evtID ),
    m_age_of_maturity( tRecv.clone() ) {}
Exemplo n.º 25
0
ShellMaturityEvent::ShellMaturityEvent( const VTime & tSend, const VTime &tRecv,
                                        SimulationObject * sender,
                                        SimulationObject * receiver,
                                        const VTime & tMature ) :
    ClothoEvent( tSend, tRecv, sender, receiver ),
    m_age_of_maturity( tMature.clone() ) {}
Exemplo n.º 26
0
VError VJSONValue::GetString( VString& outString) const
{
	VError err = VE_OK;
	switch( fType)
	{
		case JSON_undefined:
			{
				outString.Clear();	// not 'undefined'. toString() returns an empty string on an undefined value in a javascript array 
				break;
			}

		case JSON_null:
			{
				outString.Clear();	// not 'null'. toString() returns an empty string on a null value in a javascript array
				break;
			}

		case JSON_true:
			{
				outString = sTrueString;
				break;
			}

		case JSON_false:
			{
				outString = sFalseString;
				break;
			}
			
		case JSON_string:
			{
				outString.FromString( fString);
				break;
			}
			
		case JSON_number:
			{
				VReal r( fNumber);
				err = r.GetJSONString( outString, JSON_Default);
				break;
			}

		case JSON_date:
			{
				VTime dd;
				dd.FromMilliseconds(fTimeStamp);
				dd.GetJSONString(outString, JSON_Default);
				break;
			}

		case JSON_array:
			{
				err = fArray->GetString( outString);
				break;
			}

		case JSON_object:
			{
				err = fObject->GetString( outString);
				break;
			}
		
		default:
			xbox_assert( false);
	}
	
	return err;
}
Exemplo n.º 27
0
void
SimulationObject::setSimulationTime( const VTime &newSimulationTime ){
  ASSERT( newSimulationTime >= newSimulationTime.getZero() );
  delete localVirtualTime;
  localVirtualTime = newSimulationTime.clone();
}
Exemplo n.º 28
0
VError VJSONWriter::StringifyValue( const VJSONValue& inValue, VString& outString)
{
	VError err = VE_OK;
	switch( inValue.GetType())
	{
		case JSON_undefined:
			{
				outString = VJSONValue::sUndefinedString;
				break;
			}

		case JSON_null:
			{
				outString = VJSONValue::sNullString;
				break;
			}

		case JSON_true:
			{
				outString = VJSONValue::sTrueString;
				break;
			}

		case JSON_false:
			{
				outString = VJSONValue::sFalseString;
				break;
			}
			
		case JSON_string:
			{
				VString s;
				err = inValue.GetString( s);
				s.GetJSONString( outString, GetOptions());
				break;
			}

		case JSON_date:
			{
				VTime dd;
				VString s;
				inValue.GetTime(dd);
				dd.GetJSONString(s);
				if ((GetOptions() & JSON_AllowDates) != 0)
				{
					outString = "\"!!" + s + "!!\"";
				}
				else
					outString = "\"" + s + "\"";
				break;
			}

		case JSON_number:
			{
				VReal r( inValue.GetNumber());
				err = r.GetJSONString( outString, GetOptions());
				break;
			}

		case JSON_array:
			{
				err = StringifyArray( inValue.GetArray(), outString);
				break;
			}

		case JSON_object:
			{
				err = StringifyObject( inValue.GetObject(), outString);
				break;
			}
		
		default:
			xbox_assert( false);
	}
	
	return err;
}
Exemplo n.º 29
0
void ThreadedOptFossilCollManager::checkpoint(const VTime &checkTime,
		const ObjectID &objId, const unsigned int &threadId) {
	int time = checkTime.getApproximateIntTime();
	int id = objId.getSimulationObjectID();

	// If the time is less than the last checkpoint time, then save at the last
	// checkpoint time again.
	updateCheckpointTime(id, time);

	while (time >= nextCheckpointTime[id]) {
		utils::debug << mySimManager->getSimulationManagerID()
				<< " - Checkpointing object " << id << " at " << time << endl;
		int highestNextCheckpointTime = nextCheckpointTime[0];
		for (int iter = 1; iter < mySimManager->getNumberOfSimulationObjects(); iter++) {
			if (nextCheckpointTime[iter] > highestNextCheckpointTime)
				highestNextCheckpointTime = nextCheckpointTime[iter];
		}

		vector<State *> *states;
		if (nextCheckpointTime[id] == highestNextCheckpointTime) {
			// No states have been check pointed for this time yet.
			// Thus we create a state vector for all the objects
			utils::debug << "Creating new states to be saved at time "
					<< nextCheckpointTime[id] << endl;
			states = new vector<State*> (
					mySimManager->getNumberOfSimulationObjects(), NULL);
			checkpointedStates.insert(
					pair<int, vector<State*> *> (nextCheckpointTime[id], states));
		} else {
			// States have been saved for other objects but not this object at this time
			// or a roll back in this object is causing this to happen.
			utils::debug
					<< "Adding the current state of the object to checkpointedStates "
					<< nextCheckpointTime[id] << endl;

			map<int, vector<State*>*>::iterator it = checkpointedStates.find(
					nextCheckpointTime[id]);
			states = it->second;
		}

		SimulationObject *object = mySimManager->getObjectHandle(objId);

		// Save the state of the object at the checkpoint time.
		State *newState = object->allocateState();
		newState->copyState(object->getState());
		(*states)[id] = newState;

		lastCheckpointTime[id] = nextCheckpointTime[id];
		nextCheckpointTime[id] += checkpointPeriod;

		stringstream filename;
		filename << ckptFilePath << "LP"
				<< mySimManager->getSimulationManagerID() << "."
				<< lastCheckpointTime[id] << "." << id;

		ofstream ckFile(filename.str().c_str(), ofstream::binary);
		if (!ckFile.is_open()) {
			cerr << mySimManager->getSimulationManagerID()
					<< " - Could not open file: " << filename.str()
					<< ", aborting simulation." << endl;
			abort();
		}

		mySimManager->getOutputManagerNew()->saveOutputCheckpoint(&ckFile,
				objId, lastCheckpointTime[id], threadId);
		ckFile.close();
	}
}