1 /* sobby - A standalone server for obby
2  * Copyright (C) 2005 0x539 dev group
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #ifndef _SOBBY_AUTOSAVER_HPP_
20 #define _SOBBY_AUTOSAVER_HPP_
21 
22 #include <stdexcept>
23 #include <net6/non_copyable.hpp>
24 #include <sigc++/trackable.h>
25 #include <sigc++/connection.h>
26 #include <sigc++/signal.h>
27 #include "buffer_def.hpp"
28 
29 namespace Sobby
30 {
31 
32 /** This class handles autosaving: It automatically saves the session in
33  * regular intervals to a given file.
34  */
35 class AutoSaver: private net6::non_copyable, public sigc::trackable
36 {
37 public:
38 	typedef sigc::signal<void, const std::exception&> signal_error_type;
39 
40 	AutoSaver(const ServerBuffer& buffer,
41 	          const std::string& filename,
42 	          unsigned int interval,
43 		  const std::string& post_save_hook);
44 	~AutoSaver();
45 
46 	signal_error_type error_event() const;
47 
48 	void save();
49 protected:
50 	bool on_timer();
51 
52 	void on_document_insert(DocumentInfo& info);
53 	void on_document_remove(DocumentInfo& info);
54 	void on_document_change();
55 
56 	const ServerBuffer& m_buffer;
57 	std::string m_filename;
58 	std::string m_post_save_hook;
59 	sigc::connection m_conn_timer;
60 	signal_error_type m_signal_error;
61 
62 	bool m_has_modification;
63 };
64 
65 }
66 
67 #endif // _SOBBY_SERVER_HPP_
68