本文整理汇总了C++中GlobalEvent::getNextExecution方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalEvent::getNextExecution方法的具体用法?C++ GlobalEvent::getNextExecution怎么用?C++ GlobalEvent::getNextExecution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalEvent
的用法示例。
在下文中一共展示了GlobalEvent::getNextExecution方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: think
void GlobalEvents::think()
{
int64_t now = OTSYS_TIME();
int64_t nextScheduledTime = std::numeric_limits<int64_t>::max();
for (const auto& it : thinkMap) {
GlobalEvent* globalEvent = it.second;
int64_t nextExecutionTime = globalEvent->getNextExecution() - now;
if (nextExecutionTime > 0) {
if (nextExecutionTime < nextScheduledTime) {
nextScheduledTime = nextExecutionTime;
}
continue;
}
if (!globalEvent->executeEvent()) {
std::cout << "[Error - GlobalEvents::think] Failed to execute event: " << globalEvent->getName() << std::endl;
}
nextExecutionTime = globalEvent->getInterval();
if (nextExecutionTime < nextScheduledTime) {
nextScheduledTime = nextExecutionTime;
}
globalEvent->setNextExecution(globalEvent->getNextExecution() + nextExecutionTime);
}
if (nextScheduledTime != std::numeric_limits<int64_t>::max()) {
thinkEventId = g_scheduler->addEvent(createSchedulerTask(std::max<int64_t>(SCHEDULER_MINTICKS, nextScheduledTime),
std::bind(&GlobalEvents::think, this)));
}
}
示例2: timer
void GlobalEvents::timer()
{
time_t now = time(nullptr);
int64_t nextScheduledTime = std::numeric_limits<int64_t>::max();
auto it = timerMap.begin();
while (it != timerMap.end()) {
GlobalEvent* globalEvent = it->second;
int64_t nextExecutionTime = globalEvent->getNextExecution() - now;
if (nextExecutionTime > 0) {
if (nextExecutionTime < nextScheduledTime) {
nextScheduledTime = nextExecutionTime;
}
++it;
continue;
}
if (!globalEvent->executeEvent()) {
std::cout << "[Error - GlobalEvents::timer] Failed to execute event: " << globalEvent->getName() << std::endl;
}
if (g_config.getBoolean(ConfigManager::SHUTDOWN_AT_SERVERSAVE)) {
it = timerMap.erase(it);
continue;
}
nextExecutionTime = 86400;
if (nextExecutionTime < nextScheduledTime) {
nextScheduledTime = nextExecutionTime;
}
globalEvent->setNextExecution(globalEvent->getNextExecution() + nextExecutionTime);
++it;
}
if (nextScheduledTime != std::numeric_limits<int64_t>::max()) {
timerEventId = g_scheduler.addEvent(createSchedulerTask(std::max<int64_t>(1000, nextScheduledTime * 1000),
boost::bind(&GlobalEvents::timer, this)));
}
}
示例3: timer
void GlobalEvents::timer()
{
time_t now = time(nullptr);
int64_t nextScheduledTime = std::numeric_limits<int64_t>::max();
auto it = timerMap.begin();
while (it != timerMap.end()) {
GlobalEvent* globalEvent = it->second;
int64_t nextExecutionTime = globalEvent->getNextExecution() - now;
if (nextExecutionTime > 0) {
if (nextExecutionTime < nextScheduledTime) {
nextScheduledTime = nextExecutionTime;
}
++it;
continue;
}
if (!globalEvent->executeEvent()) {
it = timerMap.erase(it);
continue;
}
nextExecutionTime = 86400;
if (nextExecutionTime < nextScheduledTime) {
nextScheduledTime = nextExecutionTime;
}
globalEvent->setNextExecution(globalEvent->getNextExecution() + nextExecutionTime);
++it;
}
if (nextScheduledTime != std::numeric_limits<int64_t>::max()) {
timerEventId = g_scheduler->addEvent(createSchedulerTask(std::max<int64_t>(1000, nextScheduledTime * 1000),
std::bind(&GlobalEvents::timer, this)));
}
}