File: reloadthread.cpp

package info (click to toggle)
newsbeuter 2.5-2+deb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,632 kB
  • sloc: cpp: 17,401; ruby: 1,796; xml: 350; makefile: 198; sh: 153; perl: 64
file content (45 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <reloadthread.h>
#include <logger.h>
#include <unistd.h>

namespace newsbeuter {

reloadthread::reloadthread(controller * c, configcontainer * cf) : ctrl(c), oldtime(0), waittime_sec(0), suppressed_first(false), cfg(cf) {
	LOG(LOG_INFO,"reloadthread: waiting %u seconds between reloads",waittime_sec);
}

reloadthread::~reloadthread() { }

void reloadthread::run() {
	for (;;) {
		oldtime = time(NULL);
		LOG(LOG_INFO,"reloadthread: starting reload");

		waittime_sec = 60 * cfg->get_configvalue_as_int("reload-time");
		if (waittime_sec == 0)
			waittime_sec = 60;

		if (cfg->get_configvalue_as_bool("auto-reload")) {
			if (suppressed_first) {
				ctrl->start_reload_all_thread();
			} else {
				suppressed_first = true;
				if (!cfg->get_configvalue_as_bool("suppress-first-reload")) {
					ctrl->start_reload_all_thread();
				}
			}
		} else {
			waittime_sec = 60; // if auto-reload is disabled, we poll every 60 seconds whether it changed.
		}

		time_t seconds_to_wait = 0;
		if ((oldtime + waittime_sec) > time(NULL))
			seconds_to_wait = oldtime + waittime_sec - time(NULL);

		while (seconds_to_wait > 0) {
			seconds_to_wait = ::sleep(seconds_to_wait);
		}
	}
}

}