void AutoAwayPlugin::timeout() { unsigned idle_time = getIdleTime(); if ((bAway && getEnableAway() && (idle_time < getAwayTime() * 60)) || (bNA && getEnableNA() && (idle_time < getNATime() * 60))){ bAway = false; bNA = false; for (unsigned i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (!client->getCommonStatus()) continue; client->setStatus(oldStatus, true); } core->setManualStatus(oldStatus); Event e(EventClientStatus); e.process(); return; } if (!bAway && !bNA && getEnableAway() && (idle_time > getAwayTime() * 60)){ unsigned i; unsigned long status = core->getManualStatus(); if ((status == STATUS_AWAY) || (status == STATUS_NA) || (status == STATUS_OFFLINE)) return; oldStatus = status; bAway = true; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (!client->getCommonStatus()) continue; client->setStatus(STATUS_AWAY, true); } core->setManualStatus(STATUS_AWAY); Event e(EventClientStatus); e.process(); return; } if (!bNA && getEnableNA() && (idle_time > getNATime() * 60)){ unsigned i; unsigned long status = core->getManualStatus(); if ((status == STATUS_NA) || (status == STATUS_OFFLINE)) return; if (!bAway) oldStatus = status; bNA = true; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (!client->getCommonStatus()) continue; client->setStatus(STATUS_NA, true); } core->setManualStatus(STATUS_NA); Event e(EventClientStatus); e.process(); return; } }
int main (int argc, char** argv) { char o; int affiche_pourcentage = 0; int repeter = 0; int secondes = 1; while ((o = getopt(argc, argv, "ir:")) != -1) { switch (o) { case 'i': affiche_pourcentage = 1; break; case 'r': repeter = 1; secondes = atoi(optarg); break; } } printf("My PID: %d\n", getpid()); if (repeter) { while (1) { printf("%d processes are sleeping\n", getIdleJobs()); if (affiche_pourcentage) printf("Idle percentage: %f\n",getIdleTime()); sleep(secondes); } } else { printf("%d processes are sleeping\n", getIdleJobs()); if (affiche_pourcentage) printf("Idle percentage: %f\n",getIdleTime()); } }
void AutoAwayPlugin::timeout() { unsigned long newStatus = core->getManualStatus(); unsigned idle_time = getIdleTime() / 60; if ((bAway && (idle_time < getAwayTime())) || (bNA && (idle_time < getNATime())) || (bOff && (idle_time < getOffTime()))){ bAway = false; bNA = false; bOff = false; newStatus = oldStatus; }else if (!bAway && !bNA && !bOff && getEnableAway() && (idle_time >= getAwayTime())){ unsigned long status = core->getManualStatus(); if ((status == STATUS_AWAY) || (status == STATUS_NA) || (status == STATUS_OFFLINE)) return; oldStatus = status; newStatus = STATUS_AWAY; bAway = true; }else if (!bNA && !bOff && getEnableNA() && (idle_time >= getNATime())){ unsigned long status = core->getManualStatus(); if ((status == STATUS_NA) || (status == STATUS_OFFLINE)) return; if (!bAway) oldStatus = status; bNA = true; newStatus = STATUS_NA; }else if (!bOff && getEnableOff() && (idle_time >= getOffTime())){ unsigned long status = core->getManualStatus(); if (status == STATUS_OFFLINE) return; if (!bNA) oldStatus = status; bOff = true; newStatus = STATUS_OFFLINE; } if (newStatus == core->getManualStatus()) return; for (unsigned i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (!client->getCommonStatus()) continue; client->setStatus(newStatus, true); } if (core->getManualStatus() == newStatus) return; time_t now; time(&now); core->data.StatusTime.value = now; core->data.ManualStatus.value = newStatus; Event e(EventClientStatus); e.process(); }
static void setOption (const char c, char *optarg) { switch (c) { case 'n' : exit (sleepImmediately()); break; case 'v' : copyright (); break; case 'V' : args.verbose = 1; break; case 'd' : args.daemon = 1; break; case 'g' : printf ("%ld\n", getIdleTime()); exit (0); break; case 'f' : readConfig (optarg); break; case 'p' : writePidFile (optarg); break; case 'a' : if (args.allowsleepcommand == DENY_SLEEP) args.allowsleepcommand = NULL; args.allowsleepcommand = setstr(args.allowsleepcommand, optarg); if (args.allowsleepcommand == NULL) args.allowsleepcommand = DENY_SLEEP; break; case 'c' : args.cantsleepcommand = setstr(args.cantsleepcommand, optarg); break; case 's' : args.sleepcommand = setstr(args.sleepcommand, optarg); break; case 'w' : args.wakeupcommand = setstr(args.wakeupcommand, optarg); break; case 'D' : args.displaydimcommand = setstr(args.displaydimcommand, optarg); break; case 'E' : args.displayundimcommand = setstr(args.displayundimcommand, optarg); break; case 'S' : args.displaysleepcommand = setstr(args.displaysleepcommand, optarg); break; case 'W' : args.displaywakeupcommand = setstr(args.displaywakeupcommand, optarg); break; case 't' : args.idletimeout = scanTime(optarg, "invalid digit(s) in timeout argument '%s'\n"); break; case 'i' : args.idlecommand = setstr(args.idlecommand, optarg); break; case 'R' : args.idleresume = 0; args.idleresumecommand = setstr(args.idleresumecommand, optarg); break; case 'b' : args.breaklength = scanTime(optarg, "invalid digit(s) in pause argument '%s'\n"); break; case 'r' : args.resumecommand = setstr(args.resumecommand, optarg); break; case 'P' : args.plugcommand = setstr(args.plugcommand, optarg); break; case 'U' : args.unplugcommand = setstr(args.unplugcommand, optarg); break; default : exit (2); break; } }