1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/*
* Copyright (c) [2012-2014] Novell, Inc.
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail, you may
* find current contact information at www.novell.com.
*/
#ifndef SNAPPER_CLIENT_H
#define SNAPPER_CLIENT_H
#include <string>
#include <list>
#include <queue>
#include <set>
#include <boost/thread.hpp>
#include <snapper/Snapper.h>
#include <snapper/Snapshot.h>
#include <snapper/Comparison.h>
#include <dbus/DBusConnection.h>
#include <dbus/DBusMessage.h>
#include "MetaSnapper.h"
using namespace std;
using namespace snapper;
#define SERVICE "org.opensuse.Snapper"
#define PATH "/org/opensuse/Snapper"
#define INTERFACE "org.opensuse.Snapper"
extern boost::shared_mutex big_mutex;
struct NoComparison : public std::exception
{
explicit NoComparison() throw() {}
virtual const char* what() const throw() { return "no comparison"; }
};
class Client : private boost::noncopyable
{
public:
static void introspect(DBus::Connection& conn, DBus::Message& msg);
void check_permission(DBus::Connection& conn, DBus::Message& msg) const;
void check_permission(DBus::Connection& conn, DBus::Message& msg,
const MetaSnapper& meta_snapper) const;
void check_lock(DBus::Connection& conn, DBus::Message& msg, const string& config_name) const;
void check_config_in_use(const MetaSnapper& meta_snapper) const;
void check_snapshot_in_use(const MetaSnapper& meta_snapper, unsigned int number) const;
void signal_config_created(DBus::Connection& conn, const string& config_name);
void signal_config_modified(DBus::Connection& conn, const string& config_name);
void signal_config_deleted(DBus::Connection& conn, const string& config_name);
void signal_snapshot_created(DBus::Connection& conn, const string& config_name,
unsigned int num);
void signal_snapshot_modified(DBus::Connection& conn, const string& config_name,
unsigned int num);
void signal_snapshots_deleted(DBus::Connection& conn, const string& config_name,
const list<dbus_uint32_t>& nums);
void list_configs(DBus::Connection& conn, DBus::Message& msg);
void get_config(DBus::Connection& conn, DBus::Message& msg);
void set_config(DBus::Connection& conn, DBus::Message& msg);
void create_config(DBus::Connection& conn, DBus::Message& msg);
void delete_config(DBus::Connection& conn, DBus::Message& msg);
void lock_config(DBus::Connection& conn, DBus::Message& msg);
void unlock_config(DBus::Connection& conn, DBus::Message& msg);
void list_snapshots(DBus::Connection& conn, DBus::Message& msg);
void list_snapshots_at_time(DBus::Connection& conn, DBus::Message& msg);
void get_snapshot(DBus::Connection& conn, DBus::Message& msg);
void set_snapshot(DBus::Connection& conn, DBus::Message& msg);
void create_single_snapshot(DBus::Connection& conn, DBus::Message& msg);
void create_single_snapshot_v2(DBus::Connection& conn, DBus::Message& msg);
void create_single_snapshot_of_default(DBus::Connection& conn, DBus::Message& msg);
void create_pre_snapshot(DBus::Connection& conn, DBus::Message& msg);
void create_post_snapshot(DBus::Connection& conn, DBus::Message& msg);
void delete_snapshots(DBus::Connection& conn, DBus::Message& msg);
void mount_snapshot(DBus::Connection& conn, DBus::Message& msg);
void umount_snapshot(DBus::Connection& conn, DBus::Message& msg);
void get_mount_point(DBus::Connection& conn, DBus::Message& msg);
void create_comparison(DBus::Connection& conn, DBus::Message& msg);
void delete_comparison(DBus::Connection& conn, DBus::Message& msg);
void get_files(DBus::Connection& conn, DBus::Message& msg);
void debug(DBus::Connection& conn, DBus::Message& msg) const;
void dispatch(DBus::Connection& conn, DBus::Message& msg);
Client(const string& name);
~Client();
list<Comparison*>::iterator find_comparison(Snapper* snapper, unsigned int number1,
unsigned int number2);
list<Comparison*>::iterator find_comparison(Snapper* snapper,
Snapshots::const_iterator snapshot1,
Snapshots::const_iterator snapshot2);
void delete_comparison(list<Comparison*>::iterator);
void add_lock(const string& config_name);
void remove_lock(const string& config_name);
bool has_lock(const string& config_name) const;
void add_mount(const string& config_name, unsigned int number);
void remove_mount(const string& config_name, unsigned int number);
const string name;
list<Comparison*> comparisons;
set<string> locks;
map<pair<string, unsigned int>, unsigned int> mounts;
struct Task
{
Task(DBus::Connection& conn, DBus::Message& msg) : conn(conn), msg(msg) {}
DBus::Connection& conn;
DBus::Message msg;
};
boost::condition_variable condition;
boost::mutex mutex;
boost::thread thread;
queue<Task> tasks;
bool zombie;
void add_task(DBus::Connection& conn, DBus::Message& msg);
private:
void worker();
};
class Clients
{
public:
typedef list<Client>::iterator iterator;
typedef list<Client>::const_iterator const_iterator;
iterator begin() { return entries.begin(); }
const_iterator begin() const { return entries.begin(); }
iterator end() { return entries.end(); }
const_iterator end() const { return entries.end(); }
bool empty() const { return entries.empty(); }
iterator find(const string& name);
iterator add(const string& name);
void remove_zombies();
bool has_zombies() const;
private:
list<Client> entries;
};
extern Clients clients;
#endif
|