zbackup/config.hh

87 lines
1.9 KiB
C++
Raw 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"
#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()
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;
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
string toString( google::protobuf::Message const & message );
Config( const Config &, ConfigInfo * );
Config( ConfigInfo * );
Config();
RuntimeConfig runtime;
ConfigInfo * storable;
private:
};
#endif