Exemple #1
0
std::wstring ToDateString(time_t seconds) {
  time_t days, hours, minutes;
  std::wstring date;

  if (seconds > 0) {
    #define CALC_TIME(x, y) x = seconds / (y); seconds = seconds % (y);
    CALC_TIME(days, 60 * 60 * 24);
    CALC_TIME(hours, 60 * 60);
    CALC_TIME(minutes, 60);
    #undef CALC_TIME
    date.clear();
    #define ADD_TIME(x, y) \
      if (x > 0) { \
        if (!date.empty()) date += L" "; \
        date += ToWstr(x) + y; \
        if (x > 1) date += L"s"; \
      }
    ADD_TIME(days, L" day");
    ADD_TIME(hours, L" hour");
    ADD_TIME(minutes, L" minute");
    ADD_TIME(seconds, L" second");
    #undef ADD_TIME
  }

  return date;
}
Exemple #2
0
status_code_t sw_timer_start(uint8_t timer_id,
		uint32_t timer_count,
		sw_timeout_type_t timeout_type,
		FUNC_PTR timer_cb,
		void *param_cb)
{
	uint32_t now;
	uint32_t point_in_time;

	if (TOTAL_NUMBER_OF_SW_TIMERS <= timer_id || NULL == timer_cb) {
		return ERR_INVALID_ARG;
	}

	if (NULL != timer_array[timer_id].timer_cb) {
		/*
		 * Timer is already running if the callback function of the
		 * corresponding timer index in the timer array is not NULL.
		 */
		return ERR_TIMER_ALREADY_RUNNING;
	}

	now = gettime();

	switch (timeout_type) {
	case SW_TIMEOUT_RELATIVE:
	{
		if ((timer_count > MAX_TIMEOUT) ||
				(timer_count < MIN_TIMEOUT)) {
			return ERR_INVALID_ARG;
		}

		point_in_time = ADD_TIME(timer_count, now);
	}
	break;

	case SW_TIMEOUT_ABSOLUTE:
	{
		uint32_t timeout;
		timeout = SUB_TIME(timer_count, now);

		if ((timeout > MAX_TIMEOUT) || (timeout < MIN_TIMEOUT)) {
			return ERR_INVALID_ARG;
		}

		point_in_time = timer_count;
	}
	break;

	default:
		return ERR_INVALID_ARG;
	}

	start_absolute_timer(timer_id, point_in_time, timer_cb, param_cb);
	return STATUS_OK;
}
Exemple #3
0
void GLUTAPIENTRY
glutTimerFunc(unsigned int interval, GLUTtimerCB timerFunc, int value)
{
  GLUTtimer *timer, *other;
  GLUTtimer **prevptr;
#ifdef OLD_VMS
   struct timeval6 now;
#else
   struct timeval now;
#endif
   
  if (!timerFunc)
    return;

  if (freeTimerList) {
    timer = freeTimerList;
    freeTimerList = timer->next;
  } else {
    timer = (GLUTtimer *) malloc(sizeof(GLUTtimer));
    if (!timer)
      __glutFatalError("out of memory.");
  }

  timer->func = timerFunc;
#if defined(__vms) && ( __VMS_VER < 70000000 )
  /* VMS time is expressed in units of 100 ns */
  timer->timeout.val = interval * TICKS_PER_MILLISECOND;
#else
  timer->timeout.tv_sec = (int) interval / 1000;
  timer->timeout.tv_usec = (int) (interval % 1000) * 1000;
#endif
  timer->value = value;
  timer->next = NULL;
  GETTIMEOFDAY(&now);
  ADD_TIME(timer->timeout, timer->timeout, now);
  prevptr = &__glutTimerList;
  other = *prevptr;
  while (other && IS_AFTER(other->timeout, timer->timeout)) {
    prevptr = &other->next;
    other = *prevptr;
  }
  timer->next = other;
#ifdef SUPPORT_FORTRAN
  __glutNewTimer = timer;  /* for Fortran binding! */
#endif
  *prevptr = timer;
}
void*
VideoLoader::streamingThreadFunc(void* param)
{
	VideoLoader* videoLoader = reinterpret_cast<VideoLoader*> (param);
	while (1)
	{
		pthread_mutex_lock(&videoLoader->capture_mutex);
		if (!videoLoader->capture)
			pthread_cond_wait(&videoLoader->capture_cond, &videoLoader->capture_mutex);
		if (videoLoader->capture)
		{
			double fps = cvGetCaptureProperty(videoLoader->capture, CV_CAP_PROP_FPS);
			struct timespec tf, t2, r;
			tf.tv_sec = 0;
			tf.tv_nsec = 1000000000L / fps;
			GET_ABSOLUTE_TIME(t2);
			while (videoLoader->capture)
			{
				IplImage* img = cvQueryFrame(videoLoader->capture);
				if (!img)
				{
					cvReleaseCapture(&videoLoader->capture);
					videoLoader->dispatcher->send_signal("videoloader", ABORTED, NULL);
				}
				else
				{
					videoLoader->dispatcher->send_signal("controller", NEW_IMAGE, IplImage2QImage(img));
					/*send the frame*/
					ADD_TIME(r, t2, tf);
					pthread_cond_timedwait(&videoLoader->capture_cond, &videoLoader->capture_mutex, &r);
					GET_ABSOLUTE_TIME(t2);
				}
			}
		}
		else
		{
			pthread_mutex_unlock(&videoLoader->capture_mutex);
			break;
		}
		pthread_mutex_unlock(&videoLoader->capture_mutex);
	}
}
Exemple #5
0
/**
 * @brief Starts regular timer
 *
 * This function starts a regular timer and registers the corresponding
 * callback function to handle the timeout event.
 *
 * @param timer_id Timer identifier
 * @param timer_count Timeout in microseconds
 * @param timeout_type @ref TIMEOUT_RELATIVE / @ref TIMEOUT_ABSOLUTE
 * @param timer_cb Callback handler invoked upon timer expiry
 * @param param_cb Argument for the callback handler
 *
 * @return
 * - @ref PAL_TMR_INVALID_ID  if the timer identifier is undefined,
 * - @ref MAC_INVALID_PARAMETER if the callback function for this timer is NULL or
 *   timeout_type is invalid,
 * - @ref PAL_TMR_ALREADY_RUNNING if the timer is already running,
 * - @ref MAC_SUCCESS if timer is started, or
 * - @ref PAL_TMR_INVALID_TIMEOUT if timeout is not within the timeout range.
 */
retval_t pal_timer_start(uint8_t timer_id,
                         uint32_t timer_count,
                         timeout_type_t timeout_type,
                         FUNC_PTR timer_cb,
                         void *param_cb)
{
    uint32_t now;
    uint32_t point_in_time;

    if (timer_id >= TOTAL_NUMBER_OF_TIMERS)
    {
        return PAL_TMR_INVALID_ID;
    }

    if (NULL == timer_cb)
    {
        return MAC_INVALID_PARAMETER;
    }

    if (NULL != timer_array[timer_id].timer_cb)
    {
        /*
         * Timer is already running if the callback function of the
         * corresponding timer index in the timer array is not NULL.
         */
        return PAL_TMR_ALREADY_RUNNING;
    }

    now = gettime();

    /* The timeout is pre scaled according to the clock period. */
    timer_count = (uint32_t)(timer_count / CLOCK_PERIOD);

    switch (timeout_type)
    {
        case TIMEOUT_RELATIVE:
            {
                if ((timer_count > MAX_TIMEOUT) || (timer_count < MIN_TIMEOUT))
                {
                    return PAL_TMR_INVALID_TIMEOUT;
                }

                point_in_time = ADD_TIME(timer_count, now);
            }
            break;

        case TIMEOUT_ABSOLUTE:
            {
                uint32_t timeout;

                timeout = SUB_TIME(timer_count, now);

                if ((timeout > MAX_TIMEOUT) || (timeout < MIN_TIMEOUT))
                {
                    return PAL_TMR_INVALID_TIMEOUT;
                }
                point_in_time = timer_count;
            }
            break;

        default:
            return MAC_INVALID_PARAMETER;
    }

    start_absolute_timer(timer_id, point_in_time, timer_cb, param_cb);
    return MAC_SUCCESS;
}
/**
 * @brief Start regular timer
 *
 * This function starts a regular timer and installs the corresponding
 * callback function to handle the timeout event.
 *
 * @param timer_id Timer identifier
 * @param timer_count Timeout in microseconds
 * @param timeout_type @ref TIMEOUT_RELATIVE / @ref TIMEOUT_ABSOLUTE
 * @param timer_cb Callback handler invoked upon timer expiry
 * @param param_cb Argument for the callback handler
 *
 * @return
 * - @ref INVALID_ID  if the timer identifier is undefined,
 * - @ref INVALID_PARAMETER if the callback function for this timer is NULL or
 *   timeout_type is invalid,
 * - @ref ALREADY_RUNNING if the timer is already running,
 * - @ref SUCCESS if timer is started, or
 * - @ref INVALID_TIMEOUT if timeout is not within timeout range.
 */
retval_t pal_timer_start(uint8_t timer_id,
                         uint32_t timer_count,
                         timeout_type_t timeout_type,
                         void *timer_cb,
                         void *param_cb)
{
    uint32_t now;
    uint32_t point_in_time;
    uint32_t timeout;

    if (TOTAL_NUMBER_OF_TIMERS <= timer_id)
    {
        return PAL_TMR_INVALID_ID;
    }

    if (NULL == timer_cb)
    {
        return MAC_INVALID_PARAMETER;
    }

    if (NULL != timer_array[timer_id].timer_cb)
    {
        /*
         * Timer is already running if the callback function of the
         * corresponding timer index in the timer array is not NULL.
         */
        return PAL_TMR_ALREADY_RUNNING;
    }

    /*To get the current system time*/
    now = gettime();

    switch(timeout_type)
    {
        /* Timeout Relative */
        case TIMEOUT_RELATIVE:
        {
            if ((timer_count > MAX_TIMEOUT) || (timer_count < MIN_TIMEOUT))
            {
                return PAL_TMR_INVALID_TIMEOUT;
            }

            point_in_time = ADD_TIME(timer_count, now);
        }
        break;
        /* Timeout Absolute */
        case TIMEOUT_ABSOLUTE:
        {
            timeout = SUB_TIME(timer_count, now);
            if ((timeout > MAX_TIMEOUT) || (timeout < MIN_TIMEOUT))
            {
                return PAL_TMR_INVALID_TIMEOUT;
            }
            point_in_time = timer_count;
        }
        break;

        default:
            return MAC_INVALID_PARAMETER;
    }
    /*Starting the absolute timer for the output compare to get fired*/
    start_absolute_timer(timer_id, point_in_time, timer_cb, param_cb);
    return MAC_SUCCESS;
}