StateFS
 All Classes Files Functions Variables Typedefs Enumerations Groups Pages
config.hpp
1 #ifndef _STATEFS_PRIVATE_CONFIG_HPP_
2 #define _STATEFS_PRIVATE_CONFIG_HPP_
3 
4 #include <statefs/config.hpp>
5 
6 #include <cor/inotify.hpp>
7 #include <cor/options.hpp>
8 
9 //#include <thread>
10 #include <future>
11 
12 #include <boost/filesystem.hpp>
13 
14 #include <poll.h>
15 
16 namespace config
17 {
18 
19 class Monitor
20 {
21 public:
22 
23  typedef std::shared_ptr<config::Library> lib_ptr;
24  typedef std::map<std::string, lib_ptr> config_map_type;
25 
26  Monitor(std::string const &, ConfigReceiver &);
27  ~Monitor();
28 
29 private:
30  int watch_thread();
31  bool process_poll();
32  int watch();
33  void lib_add(std::string const &cfg_path, lib_ptr p);
34  void lib_rm(std::string const &name);
35 
36  cor::inotify::Handle inotify_;
37  std::string path_;
38  cor::FdHandle event_;
39  ConfigReceiver &target_;
40 
41  std::unique_ptr<cor::inotify::Watch> watch_;
42  std::array<pollfd, 2> fds_;
43  std::thread mon_thread_;
44 
45  config_map_type files_libs_;
46 };
47 
48 bool check_name_load(std::string const &, config_receiver_fn);
49 
50 std::string dump(std::string const&, std::ostream &
51  , std::string const&, std::string const&);
52 
53 void save(std::string const&, std::string const&, std::string const&);
54 
55 } // config
56 
57 #endif // _STATEFS_PRIVATE_CONFIG_HPP_