zbackup/config.hh

116 lines
2.4 KiB
C++
Raw Permalink Normal View History

// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
#ifndef CONFIG_HH_INCLUDED
#define CONFIG_HH_INCLUDED
#include <string>
2015-01-18 03:42:52 +03:00
#include <bitset>
#include <google/protobuf/text_format.h>
#include "zbackup.pb.h"
2015-01-17 20:08:15 +03:00
#include "mt.hh"
2015-01-18 03:42:52 +03:00
#include "backup_exchanger.hh"
2015-01-20 15:46:08 +03:00
// TODO: make *_storable to be variadic
2015-01-20 17:55:58 +03:00
#define SET_STORABLE( storage, property, value ) \
2015-01-20 05:20:44 +03:00
storable->mutable_##storage()->set_##property( value )
2015-01-20 05:20:44 +03:00
#define GET_STORABLE( storage, property ) \
storable->storage().property()
using std::string;
2015-01-18 03:42:52 +03:00
using std::bitset;
class Config
{
public:
2015-01-17 20:08:15 +03:00
struct RuntimeConfig
{
size_t threads;
size_t cacheSize;
2015-01-18 03:42:52 +03:00
bitset< BackupExchanger::Flags > exchange;
bool gcRepack;
bool pathsRespectTmp;
2015-01-17 20:08:15 +03:00
// Default runtime config
RuntimeConfig():
threads( getNumberOfCpus() ),
2015-08-12 16:27:54 +03:00
cacheSize( 40 * 1024 * 1024 ), // 40 MB
gcRepack ( false ),
pathsRespectTmp( false )
2015-01-17 20:08:15 +03:00
{
}
};
enum OptionType
{
Runtime,
Storable,
None
};
/* Keyword tokens. */
typedef enum
{
oBadOption,
oChunk_max_size,
oBundle_max_payload_size,
oBundle_compression_method,
oLZMA_compression_level,
2015-01-17 20:08:15 +03:00
oRuntime_threads,
oRuntime_cacheSize,
2015-01-18 03:42:52 +03:00
oRuntime_exchange,
oRuntime_gcRepack,
oRuntime_pathsRespectTmp,
2015-01-17 20:08:15 +03:00
oDeprecated, oUnsupported
} OpCodes;
2014-12-30 19:27:31 +03:00
2015-01-20 15:46:08 +03:00
// Validator for user-supplied storable configuration
static bool validateProto( const string &, const string & );
2014-12-30 19:27:31 +03:00
2015-01-20 15:46:08 +03:00
static bool parseProto( const string &, google::protobuf::Message * );
2014-12-29 17:24:09 +03:00
2015-01-20 15:46:08 +03:00
static string toString( google::protobuf::Message const & );
// Print configuration to screen
static void show( const ConfigInfo & );
void show();
void showHelp( const OptionType );
2015-01-20 15:46:08 +03:00
OpCodes parseToken( const char *, const OptionType );
bool parseOrValidate( const string &, const OptionType, bool validate = false );
2015-01-13 18:01:47 +03:00
Config( const Config & );
Config( const Config &, ConfigInfo * );
Config( ConfigInfo * );
Config();
~Config();
2015-01-20 15:46:08 +03:00
void reset_storable();
RuntimeConfig runtime;
ConfigInfo * storable;
private:
struct Keyword
{
string name;
Config::OpCodes opcode;
Config::OptionType type;
string description;
string defaultValue;
};
Keyword * keywords;
bool cleanup_storable;
bool cleanup_keywords;
void prefillKeywords();
};
#endif