2014-12-26 17:06:50 +03:00
|
|
|
// 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
|
|
|
|
|
2015-01-25 19:44:15 +03:00
|
|
|
#ifndef CONFIG_HH_INCLUDED
|
|
|
|
#define CONFIG_HH_INCLUDED
|
2014-12-26 17:06:50 +03:00
|
|
|
|
|
|
|
#include <string>
|
2015-01-18 03:42:52 +03:00
|
|
|
#include <bitset>
|
2014-12-26 17:06:50 +03:00
|
|
|
#include <google/protobuf/text_format.h>
|
2015-01-16 18:18:06 +03:00
|
|
|
#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"
|
2014-12-26 17:06:50 +03:00
|
|
|
|
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-19 15:19:45 +03:00
|
|
|
|
2015-01-20 05:20:44 +03:00
|
|
|
#define GET_STORABLE( storage, property ) \
|
|
|
|
storable->storage().property()
|
2015-01-19 15:19:45 +03:00
|
|
|
|
2014-12-26 17:06:50 +03:00
|
|
|
using std::string;
|
2015-01-18 03:42:52 +03:00
|
|
|
using std::bitset;
|
2014-12-26 17:06:50 +03:00
|
|
|
|
2015-01-16 18:18:06 +03:00
|
|
|
class Config
|
2014-12-26 17:06:50 +03:00
|
|
|
{
|
|
|
|
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;
|
2015-08-18 19:02:12 +03:00
|
|
|
bool gcRepack;
|
2015-08-20 12:01:09 +03:00
|
|
|
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
|
2015-08-20 12:01:09 +03:00
|
|
|
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,
|
2015-01-23 14:32:40 +03:00
|
|
|
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,
|
2015-08-18 19:02:12 +03:00
|
|
|
oRuntime_gcRepack,
|
2015-08-20 12:01:09 +03:00
|
|
|
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 & );
|
2015-01-19 17:29:01 +03:00
|
|
|
|
|
|
|
// Print configuration to screen
|
|
|
|
static void show( const ConfigInfo & );
|
|
|
|
void show();
|
|
|
|
|
2015-01-30 11:27:11 +03:00
|
|
|
void showHelp( const OptionType );
|
|
|
|
|
2015-01-20 15:46:08 +03:00
|
|
|
OpCodes parseToken( const char *, const OptionType );
|
2015-02-10 14:40:11 +03:00
|
|
|
bool parseOrValidate( const string &, const OptionType, bool validate = false );
|
2015-01-13 18:01:47 +03:00
|
|
|
|
2015-08-04 09:55:01 +03:00
|
|
|
Config( const Config & );
|
2015-01-19 15:19:45 +03:00
|
|
|
Config( const Config &, ConfigInfo * );
|
|
|
|
Config( ConfigInfo * );
|
|
|
|
Config();
|
2015-01-19 18:08:24 +03:00
|
|
|
~Config();
|
2015-01-19 15:19:45 +03:00
|
|
|
|
2015-01-20 15:46:08 +03:00
|
|
|
void reset_storable();
|
|
|
|
|
2015-01-19 15:19:45 +03:00
|
|
|
RuntimeConfig runtime;
|
|
|
|
ConfigInfo * storable;
|
2015-01-19 18:08:24 +03:00
|
|
|
private:
|
2015-01-30 11:27:11 +03:00
|
|
|
struct Keyword
|
|
|
|
{
|
|
|
|
string name;
|
|
|
|
Config::OpCodes opcode;
|
|
|
|
Config::OptionType type;
|
|
|
|
string description;
|
|
|
|
string defaultValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
Keyword * keywords;
|
|
|
|
|
|
|
|
bool cleanup_storable;
|
|
|
|
bool cleanup_keywords;
|
|
|
|
|
|
|
|
void prefillKeywords();
|
2014-12-26 17:06:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|