Imported Upstream version 0.1.2
[platform/upstream/snapper.git] / server / Background.h
1 /*
2  * Copyright (c) 2012 Novell, Inc.
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21
22
23 #ifndef SNAPPER_BACKGROUND_H
24 #define SNAPPER_BACKGROUND_H
25
26
27 #include <boost/thread.hpp>
28
29 #include "MetaSnapper.h"
30
31
32 using namespace std;
33 using namespace snapper;
34
35
36 class Backgrounds : private boost::noncopyable
37 {
38
39 public:
40
41     Backgrounds();
42     ~Backgrounds();
43
44     struct Task
45     {
46         Task(MetaSnappers::iterator meta_snapper, Snapshots::const_iterator snapshot1,
47              Snapshots::const_iterator snapshot2)
48             : meta_snapper(meta_snapper), snapshot1(snapshot1), snapshot2(snapshot2) {}
49
50         MetaSnappers::iterator meta_snapper;
51         Snapshots::const_iterator snapshot1;
52         Snapshots::const_iterator snapshot2;
53     };
54
55     typedef list<Task>::const_iterator const_iterator;
56
57     const_iterator begin() const { return tasks.begin(); }
58
59     const_iterator end() const { return tasks.end(); }
60
61     bool empty() const { return tasks.empty(); }
62
63     void add_task(MetaSnappers::iterator meta_snapper, Snapshots::const_iterator snapshot1,
64                   Snapshots::const_iterator snapshot2);
65
66 private:
67
68     void worker();
69
70     boost::condition_variable condition;
71     boost::mutex mutex;
72     boost::thread thread;
73     list<Task> tasks;
74
75 };
76
77
78 extern Backgrounds backgrounds;
79
80
81 #endif