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
|
|
|
|
|
|
|
|
#ifndef CONFIG_HH_INCLUDED__
|
|
|
|
#define CONFIG_HH_INCLUDED__
|
|
|
|
|
|
|
|
#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-19 15:19:45 +03:00
|
|
|
#define SET_STORABLE( storage, property, value ) (\
|
|
|
|
{\
|
|
|
|
dPrintf( "storable->mutable_"#storage"()->set_"#property"( "#value" )\n" ); \
|
|
|
|
storable->mutable_##storage()->set_##property( value ); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define GET_STORABLE( storage, property ) storable->storage().property()
|
|
|
|
|
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-01-17 20:08:15 +03:00
|
|
|
|
|
|
|
// Default runtime config
|
|
|
|
RuntimeConfig():
|
|
|
|
threads( getNumberOfCpus() ),
|
|
|
|
cacheSize( 40 * 1024 * 1024 ) // 40 MB
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
enum OptionType
|
|
|
|
{
|
|
|
|
Runtime,
|
|
|
|
Storable,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Keyword tokens. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
oBadOption,
|
|
|
|
|
|
|
|
oChunk_max_size,
|
|
|
|
oBundle_max_payload_size,
|
|
|
|
oBundle_compression_method,
|
|
|
|
|
|
|
|
oRuntime_threads,
|
|
|
|
oRuntime_cacheSize,
|
2015-01-18 03:42:52 +03:00
|
|
|
oRuntime_exchange,
|
2015-01-17 20:08:15 +03:00
|
|
|
|
|
|
|
oDeprecated, oUnsupported
|
|
|
|
} OpCodes;
|
2014-12-30 19:27:31 +03:00
|
|
|
|
|
|
|
// Validator for user-supplied configuration
|
|
|
|
static bool validate( const string &, const string & );
|
|
|
|
|
|
|
|
static bool parse( const string & str, google::protobuf::Message * mutable_message );
|
2014-12-29 17:24:09 +03:00
|
|
|
|
2015-01-17 20:08:15 +03:00
|
|
|
static void showHelp( const OptionType );
|
2015-01-13 18:01:47 +03:00
|
|
|
|
2015-01-17 20:08:15 +03:00
|
|
|
OpCodes parseToken( const char * option, const OptionType );
|
|
|
|
bool parseOption( const char * option, const OptionType );
|
2015-01-13 18:01:47 +03:00
|
|
|
|
2015-01-16 18:18:06 +03:00
|
|
|
string toString( google::protobuf::Message const & message );
|
2015-01-19 15:19:45 +03:00
|
|
|
|
|
|
|
Config( const Config &, ConfigInfo * );
|
|
|
|
Config( ConfigInfo * );
|
|
|
|
Config();
|
|
|
|
|
|
|
|
RuntimeConfig runtime;
|
|
|
|
ConfigInfo * storable;
|
2015-01-16 18:18:06 +03:00
|
|
|
private:
|
2014-12-26 17:06:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|