Exemplo n.º 1
0
 // Idle time in millisecond
 void set(uint64_t idle_usec = 0)
 {
     this->set_state = true;
     URT idle_time(idle_usec);
     URT now;
     this->trigger_time = now + idle_time;
 }
Exemplo n.º 2
0
UiMode Ui::DispatchEvents(App *app) {

  while (event_queue_.available()) {
    const UI::Event event = event_queue_.PullEvent();
    if (IgnoreEvent(event))
      continue;

    switch (event.type) {
      case UI::EVENT_BUTTON_PRESS:
        app->HandleButtonEvent(event);
        break;
      case UI::EVENT_BUTTON_LONG_PRESS:
        if (OC::CONTROL_BUTTON_R != event.control)
          app->HandleButtonEvent(event);
        else
          return UI_MODE_APP_SETTINGS;
        break;
      case UI::EVENT_ENCODER:
        app->HandleEncoderEvent(event);
        break;
      default:
        break;
    }
    MENU_REDRAW = 1;
  }

  if (idle_time() > SCREENSAVER_TIMEOUT_MS) {
    if (!screensaver_)
      screensaver_ = true;
    return UI_MODE_SCREENSAVER;
  } else {
    return UI_MODE_MENU;
  }
}
Exemplo n.º 3
0
void fastPoll( void )
	{
	RANDOM_STATE randomState;
	BYTE buffer[ RANDOM_BUFSIZE + 8 ];
	struct timeval tv;
	system_info info;

	initRandomData( randomState, buffer, RANDOM_BUFSIZE );

	gettimeofday( &tv, NULL );
	addRandomValue( randomState, tv.tv_sec );
	addRandomValue( randomState, tv.tv_usec );

	/* Get the number of microseconds since the user last provided any input
	   to any part of the system, the state of keyboard shift keys */
#if 0	/* See comment at start */
	bigtime_t idleTime;
	uint32 value;

	idleTime = idle_time();
	addRandomData( randomState, &idleTime, sizeof( bigtime_t ) );
	value = modifiers();
	addRandomValue( randomState, value );
#endif /* 0 */

	/* Get various fixed values (the 64-bit machine ID, CPU count and type(s),
	   clock speed, platform type, etc) and variable resources (number of in-
	   use pages, semaphores, ports, threads, teams, number of page faults,
	   and number of microseconds the CPU has been active) */
	get_system_info( &info );
	addRandomData( randomState, &info, sizeof( info ) );

	/* Flush any remaining data through */
	endRandomData( randomState, 5 );
	}
Exemplo n.º 4
0
bool
RunWhenIdleTask::IsIdle(bigtime_t currentTime, float taskOverhead)
{
    bigtime_t currentActivityLevel = ActivityLevel();
    float load = (float)(currentActivityLevel - fActivityLevel)
                 / (float)(currentTime - fActivityLevelStart);

    fActivityLevel = currentActivityLevel;
    fActivityLevelStart = currentTime;

    load -= taskOverhead;

    bool idle = true;

    if (load > kIdleTreshold) {
//		PRINT(("not idle enough %f\n", load));
        idle = false;
    } else if ((currentTime - fLastCPUTooBusyTime) < fIdleFor
               || idle_time() < fIdleFor) {
//		PRINT(("load %f, not idle long enough %Ld, %Ld\n", load,
//			currentTime - fLastCPUTooBusyTime,
//			idle_time()));
        idle = false;
    }

#if xDEBUG
    else
        PRINT(("load %f, idle for %Ld sec, go\n", load,
               (currentTime - fLastCPUTooBusyTime) / 1000000));
#endif

    return idle;
}
Exemplo n.º 5
0
bool ApnsConnection::SendNotification(PushNotification* notice)
{
	if (!conn_tsl_->IsConnect())
	{
		send_queue_.push_back(notice);
		if (send_queue_.size() > 64)
		{
			//将消息转交到有效连接, 没有有效则丢弃
			ApnsConnection* conn = apns_service_->GetVaildConn();
			while (!send_queue_.empty())
			{
				PushNotification* n = send_queue_.front();
				send_queue_.pop_front();
				if (conn != NULL)
				{
					conn->SendNotification(n);
				}
				else
				{
					gNoticePool.Put(n);
					LOGFMTW("链接长时间断开,丢弃已经缓存的消息!");
				}
			}
		}
		return false;
	}

	//空闲过长,重连
	if (idle_time())
	{
		send_queue_.push_back(notice);
		conn_tsl_->Close();

		LOGFMTW("连接空闲时常过长, 重连~");

		std::this_thread::sleep_for(std::chrono::milliseconds(1000));
		conn_tsl_->ReConnect();
		return false;
	}

	//放入发送队列
	bool free = send_queue_.empty();
	send_queue_.push_back(notice);

	if (free)
	{
		post();
	}

	//清理 sended_queue_
	size_t num = sended_queue_.size();
	if (num > MAX_SENDED_QUEUE)
	{
		sub_sended_queue();
	}
	return true;
}
Exemplo n.º 6
0
static void cmdout_wl(ICB_SERVER_REC *server, char **args)
{
	struct tm *logintime;
	char logbuf[20];
	char idlebuf[20];
	char line[255];
	time_t temptime;
	int op;

	/* "wl" : In a who listing, a line of output listing a user. Has the following format:

	* Field 1: String indicating whether user is moderator or not. Usually "*" for
	* moderator, and " " for not.
	* Field 2: Nickname of user.
	* Field 3: Number of seconds user has been idle.
	* Field 4: Response Time. No longer in use.
	* Field 5: Login Time. Unix time_t format. Seconds since Jan. 1, 1970 GMT.
	* Field 6: Username of user.
	* Field 7: Hostname of user.
	* Field 8: Registration status.
	*/
	temptime = strtol(args[4], NULL, 10);
	logintime = gmtime(&temptime);
	strftime(logbuf, sizeof(logbuf), "%b %e %H:%M", logintime);
	temptime = strtol(args[2], NULL, 10);
	idle_time(idlebuf, sizeof(idlebuf), temptime);

	/* Update nicklist */
	if (server->updatenicks) {
		op = FALSE;
#ifdef NO_MOD_SUPPORT_YET
		switch(args[0][0]) {
		case '*':
		case 'm':
			op = TRUE;
			break;
		}
#endif
		icb_nicklist_insert(server->group, args[1], op);
	}
	if (!server->silentwho) {
		snprintf(line, sizeof(line), "*** %c%-14.14s %6.6s %12.12s %s@%s %s",
			  args[0][0] == ' '?' ':'*', args[1], idlebuf, logbuf, args[5],
			  args[6], args[7]);
		printtext(server, NULL, MSGLEVEL_CRAP, line);
	}
}
Exemplo n.º 7
0
void handle_alarm (int sig) {
    /*
     *     Check for new idling
     *     Accumulate total idle time per window use
     *     Check for changed window
     *     Log status if interesting
     *     Set for next iteration
     */
    void               *status;
    unsigned long       idle;               /* Idle time in ms */
    time_t              idle_dur;
#ifdef GUI
    int                 idx;
#endif

    if (sig != SIGALRM) {
        return;
    }
    signal(SIGALRM, SIG_IGN);

    if (opts.pause) {
        if (current.pause_since == 0) {
            time(&current.pause_since);
        }
        signal(SIGALRM, handle_alarm);
        alarm(opts.poll_period);
        return;
    }

    idle = idle_time();

    if (thr_wx_running < 0) {
        pthread_join(thr_wx, &status);
        thr_wx_running = 0;
    }
    time(&idle_dur);
    if(thr_wx_running == 0 &&
            opts.use_database &&
            idle_dur - current.weather_since > 60 * 60 * 10) {
        time(&current.weather_since);
        pthread_create(&thr_wx, NULL, get_weather_data, 0);
    }

    if(idle < current.last_idle) {
        /* New idle "session" */
        if(idle > opts.idle_threshold * (unsigned long)1000) {
            /* It has been long enough, so reset the idle timer */
            /* ...but round up. */
            time(&current.idle_start);
            current.idle_start -= (idle + 500) / 1000;
        }
        else if(current.idle_start != 0) {
            /* If we're tracking idle time and it grows, add it */
            time(&idle_dur);
            idle_dur -= current.idle_start;
            current.idle_accumulated += idle_dur;
            current.idle_start = 0;
        }
    }

#ifdef GUI
    for(idx = 0; idx < opts.menu_len; idx++) {
        if (opts.userdef[idx] == 1) {
            /* Newly active */
            time((time_t *)&opts.userdef[idx]);
        } else if (opts.userdef[idx] < 0) {
            /* Deactivated Option */
            time(&idle_dur);
            opts.userdef[idx] = -opts.userdef[idx];
            report_duration(current.csv, opts.time_format, (time_t *)&opts.userdef[idx], &idle_dur);
            if (opts.use_database) {
                write_duration_to_database(current.csv, opts.menu_items[idx], opts.cycle_db);
            }
            opts.userdef[idx] = 0;
        }
    }

    if(opts.jiggle != 0) {
        time(&idle_dur);
        /* We need to worry about jiggling the mouse */
        if(current.last_jiggle == 0) {
            time(&current.last_jiggle);
        } else if ((idle_dur - current.last_jiggle) / opts.mouse_period > 0) {
            move_mouse(opts.mouse_dist);
            current.last_jiggle = 0;
        }
    }

    if (current.jiggle_since == 0 && opts.jiggle != 0) {
        /* Feature turned on, needs to be tracked */
        time(&current.jiggle_since);
    } else if (current.jiggle_since != 0 && opts.jiggle == 0) {
        /* Feature turned off, emit duration */
        time(&idle_dur);
        report_duration(current.csv, opts.time_format, &current.jiggle_since, &idle_dur);
        current.jiggle_since = 0;
        if (opts.use_database) {
            write_keepalive_to_database(current.csv, opts.cycle_db);
        }
    }

    if (current.pause_since != 0 && opts.pause == 0) {
        /* Feature turned off, emit duration */
        time(&idle_dur);
        report_duration(current.csv, opts.time_format, &current.pause_since, &idle_dur);
        current.pause_since = 0;
        if (opts.use_database) {
            write_duration_to_database(current.csv, "Pause", opts.cycle_db);
        }
    }
#endif

    if(is_window_updated(&current, &poll_continue, opts.use_database)) {
        if (opts.use_database) {
            write_activity_to_database(current.csv, opts.cycle_db);
        }
        if (opts.text_out) {
            /* Flush in case someone monitors the output file */
            fprintf(report, "%s\n", current.csv);
            fflush(report);
        }
    }
    /* Reset this, so that we don't have problems exiting */
    current.force = 0;

    if(opts.poll_period < 1) {
        /* I might want to use this for one-off scripts */
        return;
    }
    signal(SIGALRM, handle_alarm);
    alarm(opts.poll_period);
}