/* threat functions*/
    void datagen_thread_loop(void)
    {
        ostringstream testline;

        /* create testdata*/
        int jj=0;
        for(int ii=0; ii < 8*8-1; ii++) //64 = 63 chars + end line
        {
            if(++jj > 9) jj = 0;
            testline << jj;
        }
        testline << "\n";

        jj=0;
        while(record_thread_running && jj < NUM_LINES)
        {
    #if !defined(WITH_BOOST_TIME)
            clock_gettime(CLOCK_MONOTONIC, &ts_beg); // http://linux.die.net/man/3/clock_gettime
    #else
            start_time = boost::posix_time::microsec_clock::local_time();
    #endif

            // ********************************* //
            *active_buffer += testline.str().c_str();
            if(4*1024 < active_buffer->length()) //write 4 kbyte blocks
            {
                record_trigger.notify_all();
            }
            // ********************************* //

    #if !defined(WITH_BOOST_TIME)
            clock_gettime(CLOCK_MONOTONIC, &ts_end);
            v_fTime_s.push_back(ts_end.tv_sec);
            v_fTime_us.push_back(ts_end.tv_nsec/1e+3);
            v_fDifftime.push_back((ts_end.tv_sec - ts_beg.tv_sec)  + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9);
            f_DT_s = (ts_end.tv_sec - ts_beg.tv_sec)  + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9;
    #else
            stop_time = boost::posix_time::microsec_clock::local_time();
            time_duration = (stop_time - start_time);
            v_fTime_s.push_back( (stop_time-boost::posix_time::from_time_t(0)).total_seconds() );
            v_fTime_us.push_back( (stop_time-boost::posix_time::from_time_t(0)).fractional_seconds() );
            v_fDifftime.push_back( time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
            f_DT_s = (time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
    #endif
    #if defined(DEBUG)
            if(0.5 < 1.e+3*f_DT_s) // log only values above 0.5 ms
            {
                cout << "Line " << jj << " of " << NUM_LINES << ":"
                     << "\t" << v_fTime_s.back() << "." << v_fTime_us.back() << "s: "
                     << "\tdT: " << fixed << 1.e+3*f_DT_s << " ms"
                     << endl;
            }
    #endif
            boost::this_thread::sleep(boost::posix_time::microseconds(4*1e+6*f_DT_s)); //about 50% CPU load
            jj++;
        }//while

        datagen_done = true;
    }
예제 #2
0
      platform_duration(boost::posix_time::time_duration const& rel_time)
      {
#if defined BOOST_THREAD_CHRONO_POSIX_API || defined BOOST_THREAD_CHRONO_MAC_API
        ts_val.tv_sec = rel_time.total_seconds();
        ts_val.tv_nsec = static_cast<long>(rel_time.fractional_seconds() * (1000000000l / rel_time.ticks_per_second()));
#else
        ns_val = static_cast<boost::time_max_t>(rel_time.total_seconds()) * 1000000000l;
        ns_val += rel_time.fractional_seconds() * (1000000000l / rel_time.ticks_per_second());
#endif
      }
예제 #3
0
파일: select.cpp 프로젝트: sheenzhaox/comma
std::size_t select::wait( boost::posix_time::time_duration timeout )
{
    unsigned int sec = timeout.total_seconds();
	unsigned int nanosec = ( static_cast< unsigned int >( timeout.total_microseconds() ) - sec * 1000000 ) * 1000;
//     std::cerr << "select wait " << sec << " , " << nanosec << std::endl;
    return wait( sec, nanosec );
}
예제 #4
0
 void TimeMap::addTStep(boost::posix_time::time_duration step) {
     if (step.total_seconds() > 0) {
       boost::posix_time::ptime newTime = m_timeList.back() + step;
       m_timeList.push_back( newTime );
     } else
       throw std::invalid_argument("Can only add positive steps");
 }
예제 #5
0
boost::posix_time::time_duration Timer::RoundTime (boost::posix_time::time_duration time,
                                                   RoundingDirection direction,
                                                   RoundingDistance distance) const
{
  long totalSeconds = time.total_seconds();
  unsigned int rounding = GetBinInSeconds (distance);
  boost::posix_time::time_duration roundedTime (0,0,0);
  int numIntervals;
  switch (direction) {
  case ROUNDING_NONE:
    roundedTime = time;
    break;
  case ROUNDING_UP:
    numIntervals = int(ceil ((double)totalSeconds/(double)rounding));
    roundedTime = boost::posix_time::seconds(numIntervals * rounding);
    break;
  case ROUNDING_DOWN:
    numIntervals = int(floor ((double)totalSeconds/(double)rounding));
    roundedTime = boost::posix_time::seconds(numIntervals * rounding);
    break;
  case ROUNDING_NEAREST:
    numIntervals = int(((double)totalSeconds/(double)rounding) + 0.5);
    roundedTime = boost::posix_time::seconds(numIntervals * rounding);
    break;
  }
  return roundedTime;
}
예제 #6
0
파일: timespec.hpp 프로젝트: CRF/passenger
 inline struct timespec get_timespec(boost::system_time const& abs_time)
 {
     struct timespec timeout={0};
     boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
     
     timeout.tv_sec=time_since_epoch.total_seconds();
     timeout.tv_nsec=time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second());
     return timeout;
 }
예제 #7
0
inline xtime get_xtime(boost::system_time const& abs_time)
{
    xtime res={0};
    boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
            
    res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
    res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
    return res;
}
예제 #8
0
static void highLevelAPI(std::vector<const char*> const& filenames,
  bool print_bayer_format, const boost::posix_time::time_duration& d,
  unsigned char recordfilter)
{
  contourpp::record_parser parser;
  std::vector<contourpp::record> records;

  records.reserve(128);

  if (!filenames.empty()) {
    for (std::vector<const char*>::const_iterator f = filenames.begin(); f != filenames.end(); ++f) {
      std::ifstream ifs(*f);
      if (!ifs.good())
        throw std::runtime_error(std::string("could not open '") + (*f) + "'");

      std::string buf;
      contourpp::record rec;
      while (std::getline(ifs, buf)) {
        if (parser.parse(buf.data(), buf.data() + buf.size(), rec)) {
          if (records.size() == records.capacity())
            records.reserve(2 * records.capacity());
          records.push_back(rec);
        }
      }
    }
  }
  else
    parser.get_all(records);

  std::vector<contourpp::record>::iterator i, e(records.end());

  if (d.total_seconds() != 0) {
    for (i = records.begin(); i != e; ++i)
      i->shift_time(d);
  }
  if (print_bayer_format) {
    for (i = records.begin(); i != e; ++i) {
      if (getRecordType(*i) & recordfilter) {
        i->print_bayer(std::cout);
        std::cout << std::endl;
      }
    }
  }
  else {
    for (i = records.begin(); i != e; ++i)
      if (getRecordType(*i) & recordfilter)
        std::cout << (*i) << std::endl;
  }
}
예제 #9
0
value_visitor::result_type
value_visitor::operator()(const date_t& value)
{
	static const date_t EPOCH(boost::gregorian::date(1970, 1, 1));
	const boost::posix_time::time_duration duration = value - EPOCH;
	if (duration.seconds() == 0 && duration.fractional_seconds() == 0)
	{
		push_back<std::int8_t>('K');
		push_back<std::int32_t>(duration.total_seconds() / 60);
	}
	else
	{
		push_back<std::int8_t>('J');
		push_back<std::int64_t>(duration.total_milliseconds());
	}
}
예제 #10
0
	void torrent_handle::force_reannounce(
		boost::posix_time::time_duration duration) const
	{
		INVARIANT_CHECK;
		TORRENT_ASYNC_CALL1(force_tracker_request, time_now() + seconds(duration.total_seconds()));
	}
예제 #11
0
/**
 * @brief Purge cache entries that have not been active for some time.
 *
 * @param  indom   Instance domain to purge entries for.
 * @param  recent  All entries that have not been active within this interval
 *                 will be purged.
 *
 * @throw  pcp::exception  On error.
 *
 * @return The number of items purged.
 *
 * @see pmdaCachePurge
 */
inline size_t purge(const pmInDom indom, const boost::posix_time::time_duration &recent)
{
    return purge(indom, recent.total_seconds());
}
예제 #12
0
void torrent_handle::force_reannounce(
    boost::posix_time::time_duration duration) const
{
    async_call(&torrent::force_tracker_request, aux::time_now()
               + seconds(duration.total_seconds()), -1);
}
예제 #13
0
 static double ToSeconds(const boost::posix_time::time_duration &diff) {
     return diff.total_seconds() + diff.total_nanoseconds() / 1e9;
 }
예제 #14
0
	void torrent_handle::force_reannounce(
		boost::posix_time::time_duration duration) const
	{
		TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now()
			+ seconds(duration.total_seconds()), -1);
	}
예제 #15
0
void run( S* stream )
{
    static const unsigned int timeSize = 12;
    boost::mt19937 generator;
    boost::uniform_real< float > distribution( 0, 1 );
    boost::variate_generator< boost::mt19937&, boost::uniform_real< float > > random( generator, distribution );
    comma::uint64 count = 0;
    comma::uint64 dropped_count = 0;
    double compression = 0;
    velodyne::packet packet;
    comma::signal_flag isShutdown;
    velodyne::scan_tick tick;
    comma::uint32 scan_id = 0;
    while( !isShutdown && std::cin.good() && !std::cin.eof() && std::cout.good() && !std::cout.eof() )
    {
        const char* p = velodyne::impl::stream_traits< S >::read( *stream, sizeof( velodyne::packet ) );
        if( p == NULL ) { break; }
        ::memcpy( &packet, p, velodyne::packet::size );
        if( tick.is_new_scan( packet ) ) { ++scan_id; } // quick and dirty
        boost::posix_time::ptime timestamp = stream->timestamp();
        if( scan_rate ) { scan.thin( packet, *scan_rate, angularSpeed( packet ) ); }
        if( !scan_rate || !scan.empty() )
        {
            if( focus ) { velodyne::thin::thin( packet, *focus, *db, angularSpeed( packet ), random ); }
            if( rate ) { velodyne::thin::thin( packet, *rate, random ); }
        }
        const boost::posix_time::ptime base( snark::timing::epoch );
        const boost::posix_time::time_duration d = timestamp - base;
        comma::int64 seconds = d.total_seconds();
        comma::int32 nanoseconds = static_cast< comma::int32 >( d.total_microseconds() % 1000000 ) * 1000;
        if( outputRaw ) // real quick and dirty
        {
            static boost::array< char, 16 + timeSize + velodyne::packet::size + 4 > buf;
            static const boost::array< char, 2 > start = {{ -78, 85 }}; // see QLib::Bytestreams::GetDefaultStartDelimiter()
            static const boost::array< char, 2 > end = {{ 117, -97 }}; // see QLib::Bytestreams::GetDefaultStartDelimiter()
            ::memcpy( &buf[0], &start[0], 2 );
            ::memcpy( &buf[0] + buf.size() - 2, &end[0], 2 );
            ::memcpy( &buf[0] + 16, &seconds, 8 );
            ::memcpy( &buf[0] + 16 + 8, &nanoseconds, 4 );
            ::memcpy( &buf[0] + 16 + 8 + 4, &packet, velodyne::packet::size );
            if( publisher ) { publisher->write( &buf[0], buf.size() ); }
            else if( publisher_udp_socket ) { publisher_udp_socket->send_to( boost::asio::buffer( &buf[0], buf.size() ), udp_destination ); }
            else { std::cout.write( &buf[0], buf.size() ); }
        }
        else
        {
            // todo: certainly rewrite with the proper header using comma::packed
            static char buf[ timeSize + sizeof( comma::uint16 ) + velodyne::thin::maxBufferSize ];
            comma::uint16 size = velodyne::thin::serialize( packet, buf + timeSize + sizeof( comma::uint16 ), scan_id );
            bool empty = size == ( sizeof( comma::uint32 ) + 1 ); // todo: atrocious... i.e. packet is not empty; refactor!!!
            if( !empty )
            {
                size += timeSize;
                ::memcpy( buf, &size, sizeof( comma::uint16 ) );
                size += sizeof( comma::uint16 );
                ::memcpy( buf + sizeof( comma::uint16 ), &seconds, sizeof( comma::int64 ) );
                ::memcpy( buf + sizeof( comma::uint16 ) + sizeof( comma::int64 ), &nanoseconds, sizeof( comma::int32 ) );
                if( publisher ) { publisher->write( buf, size ); }
                else if( publisher_udp_socket ) { publisher_udp_socket->send_to( boost::asio::buffer( buf, size ), udp_destination ); }
                else { std::cout.write( buf, size ); }
            }
            else
            {
                ++dropped_count;
            }
            if( verbose )
            {
                ++count;
                compression = 0.9 * compression + 0.1 * ( empty ? 0.0 : double( size + sizeof( comma::int16 ) ) / ( velodyne::packet::size + timeSize ) );
                if( count % 10000 == 0 ) { std::cerr << "velodyne-thin: processed " << count << " packets; dropped " << ( double( dropped_count ) * 100. / count ) << "% full packets; compression rate " << compression << std::endl; }
            }
        }
    }
    if( publisher ) { publisher->close(); }
    std::cerr << "velodyne-thin: " << ( isShutdown ? "signal received" : "no more data" ) << "; shutdown" << std::endl;
}
boost::posix_time::ptime DateTimeEventsManager::GetEventStartTime(const DateTimeEvent* pEvent) const
{
	boost::posix_time::ptime resultTime;

	switch (pEvent->GetType())
	{
	case DateTimeEvent::typeOnce:
		{
			boost::posix_time::ptime scheduledTime(pEvent->GetDate(), pEvent->GetTime());
			const boost::posix_time::time_duration d = boost::posix_time::second_clock::local_time() - scheduledTime;

			// This may happen after player startup if there is an event with date/time in the past.
			if (d.total_seconds() > 1)
			{
				scheduledTime = boost::posix_time::not_a_date_time;
			}

			resultTime = scheduledTime;
		}
		break;

	case DateTimeEvent::typeDaily:
		{
			boost::posix_time::ptime startTime(boost::gregorian::day_clock::local_day(), pEvent->GetTime());
			
			if (boost::posix_time::second_clock::local_time() >= startTime)
				startTime += boost::gregorian::days(1);

			resultTime = startTime;
		}
		break;

	case DateTimeEvent::typeWeekly:
		{
			boost::gregorian::date dateNow(boost::gregorian::day_clock::local_day());

			int currentDayOfWeek = dateNow.day_of_week().as_number();

			if (currentDayOfWeek == 0)
				currentDayOfWeek = 7;

			--currentDayOfWeek; // Format 0 = Mon, 1 = Tue, .. , 6 = Sun
			
			boost::gregorian::date weekStartDate =
				dateNow - boost::gregorian::date_duration(currentDayOfWeek);

			std::vector<boost::posix_time::ptime> times;

			for (int i = 0; i < 7; ++i)
				if (pEvent->GetWeekDays() & (1 << i))
				{
					boost::posix_time::ptime startTime(
						weekStartDate + boost::gregorian::date_duration(i), pEvent->GetTime());

					if (boost::posix_time::second_clock::local_time() >= startTime)
						startTime += boost::gregorian::days(7);

					times.push_back(startTime);
				}

			std::sort(times.begin(), times.end());

			_ASSERTE(!times.empty());
			resultTime = times[0];
		}
		break;
	}

	return resultTime;
}