本文整理汇总了C++中OsTime类的典型用法代码示例。如果您正苦于以下问题:C++ OsTime类的具体用法?C++ OsTime怎么用?C++ OsTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OsTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// Block the task until the semaphore is acquired or the timeout expires
OsStatus OsCSemLinux::acquire(const OsTime& rTimeout)
{
struct timespec timeout;
OsStatus res;
if (rTimeout.isInfinite())
res = (pt_sem_wait(&mSemImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
else if (rTimeout.isNoWait())
res = (pt_sem_trywait(&mSemImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
else
{
OsUtilLinux::cvtOsTimeToTimespec(rTimeout, &timeout);
res = (pt_sem_timedwait(&mSemImp, &timeout) == POSIX_OK) ? OS_SUCCESS : OS_WAIT_TIMEOUT;
}
#ifdef OS_CSEM_DEBUG
if (res == OS_SUCCESS)
{
updateAcquireStats();
}
#endif
#ifdef OS_SYNC_DEBUG
if (res == OS_SUCCESS)
{
mSyncCrumbs.dropCrumb(pthread_self(), crumbAcquired);
}
#endif
return res;
}
示例2: printStatus
void SipProtocolServerBase::printStatus()
{
int numClients = mClientList.getCount();
int iteratorHandle = mClientList.getIteratorHandle();
OsTime time;
OsDateTime::getCurTimeSinceBoot(time);
long currentTime = time.seconds();
//long currentTime = OsDateTime::getSecsSinceEpoch();
SipClient* client;
UtlString clientNames;
long clientTouchedTime;
UtlBoolean clientOk;
osPrintf("%s %d clients in list at: %ld\n",
mProtocolString.data(), numClients, currentTime);
while ((client = (SipClient*)mClientList.next(iteratorHandle)))
{
// Remove this or any other bad client
clientTouchedTime = client->getLastTouchedTime();
clientOk = client->isOk();
client->getClientNames(clientNames);
osPrintf("%s client %p last used: %ld ok: %d names:\n%s\n",
mProtocolString.data(), this, clientTouchedTime,
clientOk, clientNames.data());
}
mClientList.releaseIteratorHandle(iteratorHandle);
}
示例3: FileTimeToSystemTime
/// Convert an OsTime to an OsDateTime
OsDateTimeWnt::OsDateTimeWnt(const OsTime& toTime)
{
// first convert the OsTime to a Windows FILETIME
int64_t winTime_64;
winTime_64 = toTime.seconds();
winTime_64 += WINDOWSTIME2UNIXTIME; // adjust for epoch difference
winTime_64 *= FILETIME_UNITS_PER_SEC; // scale to windows ticks
winTime_64 += toTime.usecs() * FILETIME_UNITS_PER_USEC;
FILETIME winTime;
winTime.dwHighDateTime = (unsigned long)(winTime_64 >> 32);
winTime.dwLowDateTime = (unsigned long)(winTime_64 & 0xFFFFFFFF);
// then the FILETIME to a broken out SYSTEMTIME
SYSTEMTIME sysTime;
FileTimeToSystemTime(&winTime, &sysTime);
// and last, SYSTEMTIME to OsDateTime
mYear = sysTime.wYear;
mMonth = sysTime.wMonth - 1; // windows is 1-based
mDay = (unsigned char)sysTime.wDay;
mHour = (unsigned char)sysTime.wHour;
mMinute = (unsigned char)sysTime.wMinute;
mSecond = (unsigned char)sysTime.wSecond;
mMicrosecond = sysTime.wMilliseconds * MICROSECS_PER_MILLISEC;
}
示例4: checkMeanAgainstThresholds
void checkMeanAgainstThresholds(const OsTime& start, const OsTime& stop,
unsigned nDeltas,
unsigned targetDelta, // <-- was periodUSecs
long lowerMeanThresh, long upperMeanThresh)
{
CPPUNIT_ASSERT_MESSAGE("Timer didn't fire or deltas were not collected!",
nDeltas > 0);
double meanAvg = 0;
int64_t totStartUSecs = start.seconds()*1000*1000 + start.usecs();
int64_t totStopUSecs = stop.seconds()*1000*1000 + stop.usecs();
meanAvg = (totStopUSecs-totStartUSecs)/(double)nDeltas;
printf("Mean: %.2f us\n", meanAvg);
// Assert when mean is outside error range specified above.
char errStrBuf[256];
SNPRINTF(errStrBuf, sizeof(errStrBuf),
"Mean timer value %.2f falls outside threshold of %ld to %ld us",
meanAvg, lowerMeanThresh, upperMeanThresh);
CPPUNIT_ASSERT_MESSAGE(errStrBuf,
(meanAvg-(long)targetDelta >= lowerMeanThresh &&
meanAvg-(long)targetDelta <= upperMeanThresh));
}
示例5: initialize
// Compute the next chain value.
void CallId::nextValue(const char* seed)
{
// If we haven't initialized yet, do so.
if (!sChainValueInitialized)
{
initialize();
}
// Get the time.
OsTime currentTime;
OsDateTime::getCurTime(currentTime);
// Force usecs. to be 6 digits with leading zeros so that we do
// not have to do 64 bit integer math just to build a big unique
// string.
char buffer[256];
sprintf(buffer, "%s/%d%.6d/%.*s/%s",
sKey.data(),
currentTime.seconds(), currentTime.usecs(),
MAX_SEED_CHARS, seed,
sChainValue.data());
// Hash them.
NetMd5Codec encoder;
encoder.encode(buffer, sChainValue);
// Truncate the hash to CHAIN_VALUE_LENGTH characters.
sChainValue.remove(CHAIN_VALUE_LENGTH);
}
示例6: if
// Block the task until the mutex is acquired or the timeout expires
OsStatus OsMutexLinux::acquire(const OsTime& rTimeout)
{
struct timespec timeout;
OsStatus status;
if(rTimeout.isInfinite())
{
status = (pt_mutex_lock(&mMutexImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
}
else if(rTimeout.isNoWait())
{
status = (pt_mutex_trylock(&mMutexImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
}
else
{
OsUtilLinux::cvtOsTimeToTimespec(rTimeout, &timeout);
status = (pt_mutex_timedlock(&mMutexImp, &timeout) == POSIX_OK)
? OS_SUCCESS : OS_WAIT_TIMEOUT;
}
#ifdef OS_SYNC_DEBUG
if (status == OS_SUCCESS)
{
mSyncCrumbs.dropCrumb(pthread_self(), crumbAcquired);
}
#endif
return status;
}
示例7: touch
void SipClient::touch()
{
OsTime time;
OsDateTime::getCurTimeSinceBoot(time);
touchedTime = time.seconds();
//Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipClient[%s]::touch client: %p time: %d\n",
// mName.data(), this, touchedTime);
}
示例8: getResourceListServer
// Declare that some content has changed and needs to be published.
void ResourceListSet::schedulePublishing()
{
Os::Logger::instance().log(FAC_RLS, PRI_DEBUG,
"ResourceListSet::schedulePublishing this = %p",
this);
// If publishing has been suspended, do not start the timer --
// it will be started when publishing is resumed.
if (!publishingSuspended())
{
OsTime pubDelay = getResourceListServer()->getPublishingDelay();
// Check if waiting for the gap timeout (rather than the publishing timeout)
if (mPublishOnTimeout == FALSE)
{
OsTimer::OsTimerState tmrState;
OsTimer::Time tmrExpiresAt;
UtlBoolean tmrPeriodic;
OsTimer::Interval tmrPeriod;
mPublishingTimer.getFullState(tmrState, tmrExpiresAt, tmrPeriodic, tmrPeriod);
// Check if the timer is currently running.
if (tmrState == OsTimer::STARTED)
{
// Calculate the amount of time before the gap timer expires (in seconds and microseconds).
OsTimer::Time timeDelta = tmrExpiresAt - OsTimer::now();
OsTime pubGap(timeDelta / 1000000, timeDelta % 1000000);
// If the remaining gap timeout is less than the pubDelay
// then we need to wait for pubDelay before publishing.
if (pubGap < pubDelay)
{
// Cancel the current gap timeout so that oneshotAfter can restart the timer.
mPublishingTimer.stop();
Os::Logger::instance().log(FAC_RLS, PRI_DEBUG,
"ResourceListSet::schedulePublishing mPublishingTimer.stop()");
}
}
}
// Start the timer with the publishing timeout if the timer is not already started.
// If it is already started, OsTimer::oneshotAfter() does nothing.
mPublishingTimer.oneshotAfter(pubDelay);
Os::Logger::instance().log(FAC_RLS, PRI_DEBUG,
"ResourceListSet::schedulePublishing mPublishingTimer.oneshotAfter(%d.%06d)",
pubDelay.seconds(), pubDelay.usecs());
// Publish once the publishing timer expires.
mPublishOnTimeout = TRUE;
}
}
示例9: deleteAfterSecs
// Is this connection marked for deletion?
void Connection::markForDeletion()
{
OsTime timeNow ;
OsTime deleteAfterSecs(CONN_DELETE_DELAY_SECS, 0) ;
OsDateTime::getCurTimeSinceBoot(deleteAfterSecs) ;
mDeleteAfter = timeNow + deleteAfterSecs ;
Os::Logger::instance().log(FAC_CP, PRI_DEBUG,
"Connection::markForDeletion connection %p in %d secs (now:%ld then: %ld)",
this, deleteAfterSecs.seconds(), timeNow.seconds(),
mDeleteAfter.seconds());
}
示例10:
/// Convert an OsTime to an OsDateTime
OsDateTimeLinux::OsDateTimeLinux(const OsTime& toTime)
{
struct tm dateTime;
time_t seconds = toTime.seconds();
gmtime_r(&seconds, &dateTime);
mYear = 1900 + dateTime.tm_year;
mMonth = (unsigned char) dateTime.tm_mon;
mDay = (unsigned char) dateTime.tm_mday;
mHour = (unsigned char) dateTime.tm_hour;
mMinute = (unsigned char) dateTime.tm_min;
mSecond = (unsigned char) dateTime.tm_sec;
mMicrosecond = toTime.usecs();
}
示例11: markTransfer
// Start the transfer deadman timer, and set mTransferInProgress.
void ParkedCallObject::markTransfer(const OsTime &timeOut)
{
// Mark that a transfer is in progress (and so the call is not
// available for other transfer attempts).
mTransferInProgress = TRUE;
// Start the timer to detect failed transfer attempts.
mTransferTimer.oneshotAfter(timeOut);
OsSysLog::add(FAC_PARK, PRI_DEBUG,
"ParkedCallObject::markTransfer "
"transfer timer started "
"callId = '%s', time = %d.%06d",
mOriginalCallId.data(), (int) timeOut.seconds(),
(int) timeOut.usecs());
}
示例12: encode
/// Encodes identity info
void SipXauthIdentity::encode(UtlString & identityValue,
const UtlString & callId,
const UtlString & fromTag,
const OsDateTime & timestamp,
DialogRule bindRule
)
{
// calculate timestamp
OsTime osTime;
timestamp.cvtToTimeSinceEpoch(osTime);
long seconds = osTime.seconds();
char stamp[65];
sprintf(stamp, "%lX", seconds);
UtlString strSignature(stamp);
strSignature.append(SignatureFieldSeparator);
// signature-hash=MD5(<timestamp><secret><from-tag><call-id><identity>)
NetMd5Codec signatureHash;
signatureHash.hash(stamp);
signatureHash.hash(sSignatureSecret);
if (requireDialogBinding == bindRule)
{
signatureHash.hash(fromTag);
signatureHash.hash(callId);
}
else
{
strSignature.append(SignatureFieldSeparator);
}
signatureHash.hash(mIdentity);
UtlString strSignatureHash;
signatureHash.appendHashValue(strSignature);
Url encodedUrl(mIdentity);
encodedUrl.setScheme(Url::SipUrlScheme);
encodedUrl.setUrlParameter(SignatureUrlParamName, strSignature.data());
encodedUrl.toString(identityValue);
Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
"SipXauthIdentity::encode "
"identity '%s'",
identityValue.data()
);
}
示例13: srand
// Constructor
UtlRandom::UtlRandom()
{
static int siCounter = 0 ;
int iTaskId = 0 ;
OsTime now ;
unsigned int seed ;
OsTask::getCurrentTaskId(iTaskId) ;
OsDateTime::getCurTime(now) ;
seed = (now.cvtToMsecs() ^ (now.usecs() + (now.usecs() << 16)) ^
iTaskId) + siCounter++ ;
srand(seed) ;
}
示例14: disableTimer
// Enable the repeat timer for the designated button.
// A write lock should be acquired before calling this method.
void PsButtonTask::enableTimer(int index)
{
// OsQueuedEvent* pNotifier;
OsTime repInterval;
OsStatus res;
if (mpRepTimers[index] != NULL) // if there already is a repeat timer,
disableTimer(index); // disable it
mpButtonInfo[index].getRepInterval(repInterval);
if (repInterval.isInfinite()) // if the repeat interval is infinite,
return; // don't bother enabling it
mpRepTimers[index] = new OsTimer(&mIncomingQ, index);
res = mpRepTimers[index]->periodicEvery(repInterval, repInterval);
assert(res == OS_SUCCESS);
}
示例15: testAcceptTimeout
/**
* Test accept with various timeouts
*/
void testAcceptTimeout()
{
OsTime before;
OsTime after;
OsServerSocket* server = new OsServerSocket(50, 8021);
OsDateTime::getCurTime(before);
OsSocket* serverClient = server->accept(50);
OsTask::delay(16) ; // Wait a bit to deal for poor time resolution
OsDateTime::getCurTime(after);
CPPUNIT_ASSERT_MESSAGE("socket server accept returned unexpected data",
serverClient == NULL);
CPPUNIT_ASSERT_MESSAGE("socket server accept returned before timeout",
(after.cvtToMsecs() - before.cvtToMsecs()) >= 50);
OsDateTime::getCurTime(before);
serverClient = server->accept(500);
OsTask::delay(16) ; // Wait a bit to deal for poor time resolution
OsDateTime::getCurTime(after);
CPPUNIT_ASSERT_MESSAGE("socket server accept returned unexpected data",
serverClient == NULL);
CPPUNIT_ASSERT_MESSAGE("socket server accept returned before timeout",
(after.cvtToMsecs() - before.cvtToMsecs()) >= 500);
server->close();
delete server;
}