1 |
douglas |
402 |
// Spectre 2 |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#ifndef _Daemon_hpp_ |
8 |
|
|
#define _Daemon_hpp_ |
9 |
|
|
|
10 |
douglas |
430 |
#include "Spectre2.hpp" |
11 |
douglas |
402 |
|
12 |
|
|
#ifndef MENES_PRAGMA_ONCE |
13 |
|
|
#pragma once |
14 |
|
|
#endif |
15 |
|
|
|
16 |
|
|
#include <menes-api/threads.hpp> |
17 |
|
|
#include <menes-etl/fnbind.hpp> |
18 |
douglas |
428 |
#include <menes-ext/threadset.hpp> |
19 |
douglas |
402 |
|
20 |
douglas |
430 |
class Share; |
21 |
|
|
|
22 |
douglas |
402 |
class Daemon |
23 |
|
|
{ |
24 |
|
|
private: |
25 |
douglas |
429 |
const api::Path& config; |
26 |
|
|
bool running, loaded; |
27 |
douglas |
441 |
unsigned interval; |
28 |
douglas |
402 |
_H<api::Thread> thread; |
29 |
douglas |
403 |
int loop(); |
30 |
douglas |
429 |
void load(); |
31 |
|
|
template <typename Worker> |
32 |
|
|
int work(); |
33 |
douglas |
431 |
template <typename Worker> |
34 |
|
|
int work_(const Share& share); |
35 |
|
|
void sleep(); |
36 |
douglas |
402 |
public: |
37 |
douglas |
441 |
Daemon(const api::Path& config) : config(config), running(true), loaded(false), interval(60), thread(new api::Thread(etl::BindAll(&Daemon::loop, this))) {} |
38 |
douglas |
429 |
~Daemon(); |
39 |
douglas |
430 |
static ext::RedBlackSet<Share> shares; |
40 |
douglas |
431 |
#ifdef __FreeBSD__ |
41 |
|
|
static ext::String secret; |
42 |
douglas |
432 |
static api::ThreadMutex secretLock; |
43 |
|
|
#else |
44 |
|
|
static ext::RedBlackMap<ext::String, ext::String> secrets; |
45 |
|
|
static api::ThreadMutex secretsLock; |
46 |
douglas |
431 |
#endif |
47 |
douglas |
402 |
void reload() { loaded = false; } |
48 |
|
|
void stop() { running = false; } |
49 |
|
|
}; |
50 |
|
|
|
51 |
douglas |
428 |
#endif//_Daemon_hpp_ |