/** The driver_wait function to work out if we have used more time then available to process one cycle. This is written once for either timespec (HAVE_CLOCK_GETTIME) or jack_time_t, see the unified_jack_time.h file. This function manages the time now and the next expected time to return. The return happens once per block of time (period_size). The general idea of *_driver_wait is to do the following : a] Mark the time now if this is the first time through or if an overrun previously happened. b] If an overrun is detected (we have exceeded the maximum time held in our audio buffers) then indicate. c] If we are late but not dangerously, then keep going. d] If we are early then sleep a little to allow clients enough time to process. The effect of 'c]' and 'd]' is to create time pumping. Theoretically we will always be either a little over or under time, and it will be difficult to match audio block time exactly. This doesn't matter if the time pumping is a small fraction of our block time. This means that the clients will have slightly more or less then audio block time to process. */ static jack_nframes_t iio_driver_wait(iio_driver_t *driver, int extra_fd, int *status, float *delayed_usecs) { jack_nframes_t nframes = driver->period_size; //Debugger<<"iio_driver_wait\n"; *delayed_usecs = 0; *status = 0; timeType now; getNow(&now); // the time right now if (compareTimesLt(NEXT_TIME, now)) { // NEXT_TIME < now ... this is a problem as the next time should be >= now //printf("iio_driver_wait NOT good\n"); if (compareTimeZero(NEXT_TIME)) { /* first time through */ //DebuggerLocal<<"iio_driver_first time - OK\n"; //printf("first time through\n\n\n"); getNow(&NEXT_TIME); // reset the next time to now, will be incremented later } else if (timeDiffUsComp(now, driver->next_wakeup, driver->maxDelayUSecs)) { /* xrun = (now - NEXT_TIME) > maxDelayTime */ ////Debugger<<"NEXT_TIME "<<NEXT_TIME<<" now "<<now<<endl; jack_error("**** iio: xrun of %ju usec", timeDiffUs(now, NEXT_TIME)); nframes=0; // indicated the xrun zeroTime(&NEXT_TIME); // reset the next time to zero because of the overrun, we don't know when to start again. //*status=-1; // xruns are fatal } else /* late, but handled by our "buffer" */ ; } else { // now sleep to ensure we give the clients enough time to process *status = nanoSleep(NEXT_TIME, delayed_usecs); //printf("iio_driver_wait all good\n"); } if (nframes!=0) // if there is no xrun, then indicate the next expected time to land in this funciton. NEXT_TIME=addTimes(NEXT_TIME, driver->wait_time); driver->last_wait_ust = driver->engine->get_microseconds (); driver->engine->transport_cycle_start (driver->engine, driver->last_wait_ust); return nframes; }
void addLog(const std::string& msg) { std::ostringstream os; os << getNow(); os << " Local : " << localAddress_; os << " Message : " << msg; logger_->addLog(category_, os.str()); }
//处理超时的Event static void processTimeouts() { dlog("~~~~ +processTimeouts ~~~~"); MUTEX_ACQUIRE(); struct timeval now; struct ril_event * tev = timer_list.next; struct ril_event * next; getNow(&now); // walk list, see if now >= ev->timeout for any events dlog("~~~~ Looking for timers <= %ds + %dus ~~~~", (int)now.tv_sec, (int)now.tv_usec); // 如果timer_list中某个事件已经超时 while ((tev != &timer_list) && (timercmp(&now, &tev->timeout, >))) { // Timer expired dlog("~~~~ firing timer ~~~~"); next = tev->next; // 从timer_list中删除 removeFromList(tev); // 添加到pending_list中 addToList(tev, &pending_list); tev = next; }
//Merged from Connection::sendPosition() and TelescopeTCP::performReading() void TelescopeClientDirectLx200::sendPosition(unsigned int ra_int, int dec_int, int status) { //Server time is "now", because this class is the server const qint64 server_micros = (qint64) getNow(); const double ra = ra_int * (M_PI/(unsigned int)0x80000000); const double dec = dec_int * (M_PI/(unsigned int)0x80000000); const double cdec = cos(dec); Vec3d position(cos(ra)*cdec, sin(ra)*cdec, sin(dec)); Vec3d j2000Position = position; if (equinox == EquinoxJNow) { const StelCore* core = StelApp::getInstance().getCore(); j2000Position = core->equinoxEquToJ2000(position); } interpolatedPosition.add(j2000Position, getNow(), server_micros, status); }
bool RunContextManager::createProject(const std::string& Path, const std::string& Name, const std::string& Description, const std::string& Authors, const bool Inc) { if (m_ProjectIsOpen) return false; if (QDir().mkpath(QString::fromStdString(getInputDirFromProjectPath(Path)))) { m_ProjectPath = Path; m_InputDir = getInputDirFromProjectPath(Path); m_OutputDir = getOuputDirFromProjectPath(Path); QString PrjFilePath = QString::fromStdString(getFilePathFromProjectPath(Path)); mp_ProjectFile = new QSettings(PrjFilePath,QSettings::IniFormat); m_ProjectName = Name; m_ProjectDescription = Description; m_ProjectAuthors = Authors; m_ProjectIncOutputDir = Inc; m_ProjectCreationDate = getNow(); updateWaresEnvironment(); m_ProjectIsOpen = true; return saveProject(); } return false; }
GregorianCalendar::GregorianCalendar(const Locale& aLocale, UErrorCode& status) : Calendar(TimeZone::createDefault(), aLocale, status), fGregorianCutover(kPapalCutover), fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582), fIsGregorian(TRUE), fInvertGregorian(FALSE) { setTimeInMillis(getNow(), status); }
GregorianCalendar::GregorianCalendar(UErrorCode& status) : Calendar(status), fGregorianCutover(kPapalCutover), fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582), fIsGregorian(TRUE), fInvertGregorian(FALSE) { setTimeInMillis(getNow(), status); }
ChineseCalendar::ChineseCalendar(const Locale& aLocale, UErrorCode& success) : Calendar(TimeZone::createDefault(), aLocale, success), isLeapYear(FALSE), fEpochYear(CHINESE_EPOCH_YEAR), fZoneAstroCalc(getChineseCalZoneAstroCalc()) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. }
ChineseCalendar::ChineseCalendar(const Locale& aLocale, int32_t epochYear, const TimeZone* zoneAstroCalc, UErrorCode &success) : Calendar(TimeZone::createDefault(), aLocale, success), isLeapYear(FALSE), fEpochYear(epochYear), fZoneAstroCalc(zoneAstroCalc) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. }
void newPasscode() { char seq[17]; seq[16] = '\0'; Helpers::randSeq(seq); curPasscode = seq; qrExpTime = *getNow(); qrExpTime.tm_sec += ServerThreads::qrexp; }
static void updateDirEnt_ModTimes(struct pcdir *dp) { timestruc_t ts; getNow(&dp->pcd_mtime, NULL); dp->pcd_ladate = dp->pcd_mtime.pct_date; dp->pcd_attr |= PCA_ARCH; markClusterModified(findImpactedCluster(dp)); }
int LX200Foc::setTo (double num) { offset = getPosition () - num; if (fabs (offset) < 0.1) return 0; start_focusing = getNow (); expected_end = start_focusing + estimateOffsetDuration (num); if (telConn->getSerialConn ()->writePort (offset > 0 ? ":F+#" : ":F-#", 4) < 0) return -1; return 0; }
void passcode(Packet* up, CommunicationTask* ct) { auto now = *getNow(); if (curPasscode.empty() || difftime(mktime(&now), mktime(&qrExpTime)) > 0) { newPasscode(); } PasscodePacket pc = PasscodePacket(curPasscode.c_str(), mktime(&qrExpTime)); pc.sequenceNumber = up->sequenceNumber; TCPServer::SendPacket(&pc, ct->sockfd_, true); TCPServer::CloseConnection(ct->sockfd_); }
void RunContextManager::updateProjectOutputDir() { if (m_ProjectIsOpen && m_ProjectIncOutputDir) { std::string Now = getNow(); Now.replace(8,1,"-"); m_OutputDir = getOuputDirFromProjectPath(m_ProjectPath).append("_").append(Now); } else m_OutputDir = getOuputDirFromProjectPath(m_ProjectPath); }
virtual int setValue (rts2core::Value * old_value, rts2core::Value * newValue) { updateTime->setValueInteger (getNow ()); sendValueAll (updateTime); if (old_value == goodWeather) { setWeatherState (((rts2core::ValueBool *)newValue)->getValueBool (), "weather state set from goodWeather value"); } return SensorWeather::setValue (old_value, newValue); }
void FocusCameraClient::postEvent (rts2core::Event *event) { switch (event->getType ()) { case EVENT_EXP_CHECK: if (getConnection ()->getState () & (CAM_EXPOSING | CAM_READING)) { double fr = getConnection ()->getProgress (getNow ()); std::cout << ((getConnection ()->getState () & CAM_EXPOSING) ? "EXPOSING " : "READING ") << ProgressIndicator (fr, COLS - 20) << std::fixed << std::setprecision (1) << std::setw (5) << fr << "% \r"; std::cout.flush (); } break; } rts2image::DevClientCameraFoc::postEvent (event); }
bool ServerThreads::unlockWithPasscode(const char* psc) { auto now = *getNow(); if (difftime(mktime(&now), mktime(&qrExpTime)) > 0) { newPasscode(); } if (curPasscode == psc) { unlockDoor(); return true; } error(); return false; }
U_CDECL_END U_NAMESPACE_BEGIN //------------------------------------------------------------------------- // Constructors... //------------------------------------------------------------------------- /** * Constructs a default <code>HebrewCalendar</code> using the current time * in the default time zone with the default locale. * @internal */ HebrewCalendar::HebrewCalendar(const Locale& aLocale, UErrorCode& success) : Calendar(TimeZone::createDefault(), aLocale, success) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. }
bool RunContextManager::saveProject() { if (!m_ProjectIsOpen) return false; m_ProjectLastModDate = getNow(); mp_ProjectFile->beginGroup(m_ProjectFileGroupName); mp_ProjectFile->setValue("Name",openfluid::tools::toIniCompatible(m_ProjectName)); mp_ProjectFile->setValue("Description",openfluid::tools::toIniCompatible(m_ProjectDescription)); mp_ProjectFile->setValue("Authors",openfluid::tools::toIniCompatible(m_ProjectAuthors)); mp_ProjectFile->setValue("CreationDate",QString::fromStdString(m_ProjectCreationDate)); mp_ProjectFile->setValue("LastModDate",QString::fromStdString(m_ProjectLastModDate)); mp_ProjectFile->setValue("IncOutput",m_ProjectIncOutputDir); mp_ProjectFile->endGroup(); mp_ProjectFile->sync(); return true; }
Name SecPublicInfo::getNewKeyName (const Name& identityName, bool useKsk) { std::ostringstream oss; if (useKsk) oss << "ksk-"; else oss << "dsk-"; oss << static_cast<int>(getNow()/1000); Name keyName = Name(identityName).append(oss.str()); if (doesPublicKeyExist(keyName)) throw Error("Key name already exists"); return keyName; }
static void processTimeouts(upile_context* context) { upil_printf(MSG_EXCESSIVE, "~~~~ +processTimeouts ~~~~"); MUTEX_ACQUIRE(context->listMutex); struct timeval now; struct upil_event * tev = context->timer_list.next; struct upil_event * next; getNow(&now); // walk list, see if now >= ev->timeout for any events upil_printf(MSG_EXCESSIVE, "~~~~ Looking for timers <= %ds + %dus ~~~~", (int)now.tv_sec, (int)now.tv_usec); while ((tev != &context->timer_list) && (timercmp(&now, &tev->timeout, >))) { // Timer expired upil_printf(MSG_EXCESSIVE, "~~~~ firing timer ~~~~"); next = tev->next; removeFromList(tev); addToList(tev, &context->pending_list); tev = next; }
boost::posix_time::ptime DataObject::getHandshakeExpiry( unsigned int hs ) { /* * */ if( handshakeExists(hs) ) { VLOG(9) << " from_iso_string: " << m_handshakeQueue[hs]["expiry"]; return boost::posix_time::from_iso_string( m_handshakeQueue[hs]["expiry"] ); } else { /* * Handicap it if we can't find it ... 5000ms should be * sufficient */ return (getNow() - boost::posix_time::milliseconds(5000)); } }
error_t timer_sleep(void* h, uint32_t until) { HANDLE; ENTER; uint64_t now = getNow(); uint32_t diff; if (until > now) { diff = until - now; } else { diff = until + (0xFFFFFFFFFFFFFFFFull - now); } struct timespec req = { diff / 1000, (diff % 1000) * 1000 * 1000 }; int res = nanosleep(&req, NULL); if (res != 0) { errorExit("nanosleep"); } LEAVE; return SUCCESS; }
std::vector<std::string> DataObject::expireClientSessionCache( unsigned int expiry ) { std::vector<std::string> expiredCSC; expiredCSC.clear(); /* * Iterate over all the client caches, and if there is no corresponding * client session, remove the cache */ boost::posix_time::ptime now = getNow(); boost::posix_time::ptime etime; /* * Grab our list of expired cache items */ for( auto& f : m_listreqExpiry ) { VLOG(8) << " iterate m_listreqExpiry : " << f.first << "=" << f.second; etime = boost::posix_time::from_iso_string(f.second) + boost::posix_time::seconds(expiry); VLOG(9) << " evaluate etime : " << etime; VLOG(9) << " evaluate now : " << now; if ( now > etime ) { VLOG(8) << " expire m_listreqExpiry : " << f.first; expiredCSC.push_back(f.first); } } VLOG(8) << " collected expiredCSC(" << expiredCSC.size() << ")"; for( auto& f : expiredCSC ) { VLOG(7) << " purge expired(" << f << ")"; m_listreqExpiry.erase(f); m_serverListreq.erase(f); } return expiredCSC; }
BuddhistCalendar::BuddhistCalendar(const Locale& aLocale, UErrorCode& success) : GregorianCalendar(aLocale, success) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. }
CECalendar::CECalendar(const Locale& aLocale, UErrorCode& success) : Calendar(TimeZone::createDefault(), aLocale, success) { setTimeInMillis(getNow(), success); }
//! estimates where the telescope is by interpolation in the stored //! telescope positions: Vec3d TelescopeClientDirectNexStar::getJ2000EquatorialPos(const StelCore*) const { const qint64 now = getNow() - time_delay; return interpolatedPosition.get(now); }
Calendar* Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success) { UObject* u = getService()->get(aLocale, LocaleKey::KIND_ANY, success); Calendar* c = NULL; if(U_FAILURE(success) || !u) { delete zone; if(U_SUCCESS(success)) { // Propagate some kind of err success = U_INTERNAL_PROGRAM_ERROR; } return NULL; } if(u->getDynamicClassID() == UnicodeString::getStaticClassID()) { // It's a unicode string telling us what type of calendar to load ("gregorian", etc) char tmp[200]; const UnicodeString& str = *(UnicodeString*)u; // Extract a char* out of it.. int32_t len = str.length(); if(len > sizeof(tmp)-1) { len = sizeof(tmp)-1; } str.extract(0,len,tmp); tmp[len]=0; #ifdef U_DEBUG_CALSVC // fprintf(stderr, "createInstance(%s) told to look at %s..\n", (const char*)aLocale.getName(), tmp); #endif // Create a Locale over this string Locale l(tmp); delete u; u = NULL; c = (Calendar*)getService()->get(l, LocaleKey::KIND_ANY, success); if(U_FAILURE(success) || !c) { delete zone; if(U_SUCCESS(success)) { success = U_INTERNAL_PROGRAM_ERROR; // Propagate some err } return NULL; } if(c->getDynamicClassID() == UnicodeString::getStaticClassID()) { // recursed! Second lookup returned a UnicodeString. // Perhaps DefaultCalendar{} was set to another locale. success = U_MISSING_RESOURCE_ERROR; // requested a calendar type which could NOT be found. delete c; delete zone; return NULL; } #ifdef U_DEBUG_CALSVC fprintf(stderr, "setting to locale %s\n", (const char*)aLocale.getName()); #endif c->setWeekCountData(aLocale, success); // set the correct locale (this was an indirected calendar) } else { // a calendar was returned - we assume the factory did the right thing. c = (Calendar*)u; } // Now, reset calendar to default state: c->adoptTimeZone(zone); // Set the correct time zone c->setTimeInMillis(getNow(), success); // let the new calendar have the current time. return c; }
IslamicCalendar::IslamicCalendar(const Locale& aLocale, UErrorCode& success, ECivil beCivil) : Calendar(TimeZone::createDefault(), aLocale, success), civil(beCivil) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. }
//! queues a GOTO command with the specified position to the write buffer. //! For the data format of the command see the //! "Stellarium telescope control protocol" text file void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos) { if (!isConnected()) return; Vec3d position = j2000Pos; if (equinox == EquinoxJNow) { const StelCore* core = StelApp::getInstance().getCore(); position = core->j2000ToEquinoxEqu(j2000Pos); } if (writeBufferEnd - writeBuffer + 20 < (int)sizeof(writeBuffer)) { const double ra_signed = atan2(position[1], position[0]); //Workaround for the discrepancy in precision between Windows/Linux/PPC Macs and Intel Macs: const double ra = (ra_signed >= 0) ? ra_signed : (ra_signed + 2.0 * M_PI); const double dec = atan2(position[2], std::sqrt(position[0]*position[0]+position[1]*position[1])); unsigned int ra_int = (unsigned int)floor(0.5 + ra*(((unsigned int)0x80000000)/M_PI)); int dec_int = (int)floor(0.5 + dec*(((unsigned int)0x80000000)/M_PI)); // length of packet: *writeBufferEnd++ = 20; *writeBufferEnd++ = 0; // type of packet: *writeBufferEnd++ = 0; *writeBufferEnd++ = 0; // client_micros: qint64 now = getNow(); *writeBufferEnd++ = now; now>>=8; *writeBufferEnd++ = now; now>>=8; *writeBufferEnd++ = now; now>>=8; *writeBufferEnd++ = now; now>>=8; *writeBufferEnd++ = now; now>>=8; *writeBufferEnd++ = now; now>>=8; *writeBufferEnd++ = now; now>>=8; *writeBufferEnd++ = now; // ra: *writeBufferEnd++ = ra_int; ra_int>>=8; *writeBufferEnd++ = ra_int; ra_int>>=8; *writeBufferEnd++ = ra_int; ra_int>>=8; *writeBufferEnd++ = ra_int; // dec: *writeBufferEnd++ = dec_int; dec_int>>=8; *writeBufferEnd++ = dec_int; dec_int>>=8; *writeBufferEnd++ = dec_int; dec_int>>=8; *writeBufferEnd++ = dec_int; } else {