1 |
// Spectre 2 |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#ifndef _Daemon_hpp_ |
8 |
#define _Daemon_hpp_ |
9 |
|
10 |
#include "Share.hpp" |
11 |
|
12 |
#ifndef MENES_PRAGMA_ONCE |
13 |
#pragma once |
14 |
#endif |
15 |
|
16 |
#include <menes-api/threads.hpp> |
17 |
#include <menes-etl/fnbind.hpp> |
18 |
#include <menes-ext/threadset.hpp> |
19 |
|
20 |
class Daemon |
21 |
{ |
22 |
private: |
23 |
#ifdef __FreeBSD__ |
24 |
static ext::String secret; |
25 |
#endif |
26 |
const api::Path& config; |
27 |
ext::RedBlackSet<Share> shares; |
28 |
bool running, loaded; |
29 |
_H<api::Thread> thread; |
30 |
int loop(); |
31 |
void load(); |
32 |
template <typename Worker> |
33 |
int work(); |
34 |
public: |
35 |
Daemon(const ext::String& config) : config(config), running(true), loaded(false), thread(new api::Thread(etl::BindAll(&Daemon::loop, this))) {} |
36 |
~Daemon(); |
37 |
void reload() { loaded = false; } |
38 |
void stop() { running = false; } |
39 |
}; |
40 |
|
41 |
#endif//_Daemon_hpp_ |