mirror of
https://github.com/openSUSE/snapper.git
synced 2026-02-06 00:45:39 +01:00
186 lines
5.5 KiB
C++
186 lines
5.5 KiB
C++
/*
|
|
* Copyright (c) 2012 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/Factory.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_in_use(const MetaSnapper& meta_snapper) const;
|
|
|
|
void signal_config_created(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 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_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;
|
|
|
|
const string name;
|
|
|
|
list<Comparison*> comparisons;
|
|
|
|
set<string> locks;
|
|
|
|
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
|