2 * Copyright (c) 2012 Novell, Inc.
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.
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
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, contact Novell, Inc.
18 * To contact Novell about this file by physical or electronic mail, you may
19 * find current contact information at www.novell.com.
23 #ifndef SNAPPER_CLIENT_H
24 #define SNAPPER_CLIENT_H
31 #include <boost/thread.hpp>
33 #include <snapper/Snapper.h>
34 #include <snapper/Snapshot.h>
35 #include <snapper/Comparison.h>
36 #include <dbus/DBusConnection.h>
37 #include <dbus/DBusMessage.h>
39 #include "MetaSnapper.h"
43 using namespace snapper;
46 #define SERVICE "org.opensuse.Snapper"
47 #define PATH "/org/opensuse/Snapper"
48 #define INTERFACE "org.opensuse.Snapper"
51 extern boost::shared_mutex big_mutex;
54 struct NoComparison : public std::exception
56 explicit NoComparison() throw() {}
57 virtual const char* what() const throw() { return "no comparison"; }
61 class Client : private boost::noncopyable
65 static void introspect(DBus::Connection& conn, DBus::Message& msg);
67 void check_permission(DBus::Connection& conn, DBus::Message& msg) const;
68 void check_permission(DBus::Connection& conn, DBus::Message& msg,
69 const MetaSnapper& meta_snapper) const;
70 void check_lock(DBus::Connection& conn, DBus::Message& msg, const string& config_name) const;
71 void check_config_in_use(const MetaSnapper& meta_snapper) const;
72 void check_snapshot_in_use(const MetaSnapper& meta_snapper, unsigned int number) const;
74 void signal_config_created(DBus::Connection& conn, const string& config_name);
75 void signal_config_deleted(DBus::Connection& conn, const string& config_name);
76 void signal_snapshot_created(DBus::Connection& conn, const string& config_name,
78 void signal_snapshot_modified(DBus::Connection& conn, const string& config_name,
80 void signal_snapshots_deleted(DBus::Connection& conn, const string& config_name,
81 const list<dbus_uint32_t>& nums);
83 void list_configs(DBus::Connection& conn, DBus::Message& msg);
84 void get_config(DBus::Connection& conn, DBus::Message& msg);
85 void create_config(DBus::Connection& conn, DBus::Message& msg);
86 void delete_config(DBus::Connection& conn, DBus::Message& msg);
87 void lock_config(DBus::Connection& conn, DBus::Message& msg);
88 void unlock_config(DBus::Connection& conn, DBus::Message& msg);
89 void list_snapshots(DBus::Connection& conn, DBus::Message& msg);
90 void list_snapshots_at_time(DBus::Connection& conn, DBus::Message& msg);
91 void get_snapshot(DBus::Connection& conn, DBus::Message& msg);
92 void set_snapshot(DBus::Connection& conn, DBus::Message& msg);
93 void create_single_snapshot(DBus::Connection& conn, DBus::Message& msg);
94 void create_pre_snapshot(DBus::Connection& conn, DBus::Message& msg);
95 void create_post_snapshot(DBus::Connection& conn, DBus::Message& msg);
96 void delete_snapshots(DBus::Connection& conn, DBus::Message& msg);
97 void mount_snapshot(DBus::Connection& conn, DBus::Message& msg);
98 void umount_snapshot(DBus::Connection& conn, DBus::Message& msg);
99 void get_mount_point(DBus::Connection& conn, DBus::Message& msg);
100 void create_comparison(DBus::Connection& conn, DBus::Message& msg);
101 void delete_comparison(DBus::Connection& conn, DBus::Message& msg);
102 void get_files(DBus::Connection& conn, DBus::Message& msg);
103 void debug(DBus::Connection& conn, DBus::Message& msg) const;
105 void dispatch(DBus::Connection& conn, DBus::Message& msg);
107 Client(const string& name);
110 list<Comparison*>::iterator find_comparison(Snapper* snapper, unsigned int number1,
111 unsigned int number2);
113 list<Comparison*>::iterator find_comparison(Snapper* snapper,
114 Snapshots::const_iterator snapshot1,
115 Snapshots::const_iterator snapshot2);
117 void delete_comparison(list<Comparison*>::iterator);
119 void add_lock(const string& config_name);
120 void remove_lock(const string& config_name);
121 bool has_lock(const string& config_name) const;
123 void add_mount(const string& config_name, unsigned int number);
124 void remove_mount(const string& config_name, unsigned int number);
128 list<Comparison*> comparisons;
132 map<pair<string, unsigned int>, unsigned int> mounts;
136 Task(DBus::Connection& conn, DBus::Message& msg) : conn(conn), msg(msg) {}
138 DBus::Connection& conn;
142 boost::condition_variable condition;
144 boost::thread thread;
149 void add_task(DBus::Connection& conn, DBus::Message& msg);
162 typedef list<Client>::iterator iterator;
163 typedef list<Client>::const_iterator const_iterator;
165 iterator begin() { return entries.begin(); }
166 const_iterator begin() const { return entries.begin(); }
168 iterator end() { return entries.end(); }
169 const_iterator end() const { return entries.end(); }
171 bool empty() const { return entries.empty(); }
173 iterator find(const string& name);
175 iterator add(const string& name);
176 void remove_zombies();
178 bool has_zombies() const;
182 list<Client> entries;
187 extern Clients clients;