8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-30 20:03:03 +01:00
firebird-mirror/src/common/config/config.cpp

434 lines
11 KiB
C++
Raw Normal View History

2002-11-03 17:26:12 +01:00
/*
* PROGRAM: Client/Server Common Code
* MODULE: config.cpp
* DESCRIPTION: Configuration manager (generic code)
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* Created by: Dmitry Yemanov <yemanov@yandex.ru>
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
#include "../../common/config/config.h"
#include "../../common/config/config_impl.h"
#include "../../common/config/config_file.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "../jrd/gdsassert.h"
typedef Firebird::string string;
/******************************************************************************
*
* Configuration entries
2002-11-03 17:26:12 +01:00
*/
const ConfigImpl::ConfigEntry ConfigImpl::entries[] =
{
{TYPE_STRING, "RootDirectory", (ConfigValue) 0},
2002-12-07 14:27:12 +01:00
{TYPE_INTEGER, "SortMemBlockSize", (ConfigValue) 1048576}, // bytes
2003-02-02 17:01:12 +01:00
#ifdef SUPERSERVER
{TYPE_INTEGER, "SortMemUpperLimit", (ConfigValue) 67108864}, // bytes
#else
2002-12-23 16:50:59 +01:00
{TYPE_INTEGER, "SortMemUpperLimit", (ConfigValue) 0}, // bytes
2003-02-02 17:01:12 +01:00
#endif
{TYPE_BOOLEAN, "RemoteFileOpenAbility", (ConfigValue) false},
{TYPE_INTEGER, "GuardianOption", (ConfigValue) 1},
{TYPE_INTEGER, "CpuAffinityMask", (ConfigValue) 1},
2002-12-06 13:34:43 +01:00
{TYPE_BOOLEAN, "OldParameterOrdering", (ConfigValue) false},
2002-12-07 14:27:12 +01:00
{TYPE_INTEGER, "TcpRemoteBufferSize", (ConfigValue) 8192}, // bytes
2002-12-06 22:12:59 +01:00
{TYPE_BOOLEAN, "TcpNoNagle", (ConfigValue) false},
2002-12-07 14:27:12 +01:00
{TYPE_INTEGER, "IpcMapSize", (ConfigValue) 4096}, // bytes
2002-12-06 22:12:59 +01:00
#ifdef SUPERSERVER
2002-12-07 14:27:12 +01:00
{TYPE_INTEGER, "DefaultDbCachePages", (ConfigValue) 2048}, // pages
2002-12-06 22:12:59 +01:00
#else
2002-12-07 14:27:12 +01:00
{TYPE_INTEGER, "DefaultDbCachePages", (ConfigValue) 75}, // pages
2002-12-06 22:12:59 +01:00
#endif
2002-12-07 14:27:12 +01:00
{TYPE_INTEGER, "ConnectionTimeout", (ConfigValue) 180}, // seconds
{TYPE_INTEGER, "DummyPacketInterval", (ConfigValue) 60}, // seconds
{TYPE_INTEGER, "LockMemSize", (ConfigValue) 262144}, // bytes
#ifdef SINIXZ
{TYPE_INTEGER, "LockSemCount", (ConfigValue) 25}, // semaphores
#else
{TYPE_INTEGER, "LockSemCount", (ConfigValue) 32}, // semaphores
#endif
{TYPE_INTEGER, "LockSignal", (ConfigValue) 16}, // signal #
{TYPE_BOOLEAN, "LockGrantOrder", (ConfigValue) true},
{TYPE_INTEGER, "LockHashSlots", (ConfigValue) 101}, // slots
{TYPE_BOOLEAN, "LockRequireSpins", (ConfigValue) false},
{TYPE_INTEGER, "EventMemSize", (ConfigValue) 65536}, // bytes
{TYPE_INTEGER, "DeadlockTimeout", (ConfigValue) 10}, // seconds
2002-12-07 14:49:37 +01:00
{TYPE_INTEGER, "SolarisStallValue", (ConfigValue) 60}, // seconds
{TYPE_BOOLEAN, "TraceMemoryPools", (ConfigValue) false}, // for internal use only
{TYPE_INTEGER, "PrioritySwitchDelay", (ConfigValue) 100}, // milliseconds
{TYPE_INTEGER, "DeadThreadsCollection", (ConfigValue) 50}, // number of PrioritySwitchDelay cycles before dead threads collection
{TYPE_INTEGER, "PriorityBoost", (ConfigValue) 5}, // ratio oh high- to low-priority thread ticks in jrd.cpp
2003-01-15 15:10:07 +01:00
{TYPE_STRING, "RemoteServiceName", (ConfigValue) FB_SERVICE_NAME},
{TYPE_INTEGER, "RemoteServicePort", (ConfigValue) FB_SERVICE_PORT},
{TYPE_STRING, "RemotePipeName", (ConfigValue) FB_PIPE_NAME},
{TYPE_STRING, "IpcName", (ConfigValue) FB_IPC_NAME},
#ifdef WIN_NT
2003-02-16 14:26:53 +01:00
{TYPE_INTEGER, "MaxUnflushedWrites", (ConfigValue) 100},
2003-02-16 19:58:56 +01:00
{TYPE_INTEGER, "MaxUnflushedWriteTime", (ConfigValue) 5},
#else
2003-02-16 14:26:53 +01:00
{TYPE_INTEGER, "MaxUnflushedWrites", (ConfigValue) -1},
2003-02-16 19:58:56 +01:00
{TYPE_INTEGER, "MaxUnflushedWriteTime", (ConfigValue) -1},
#endif
2003-02-16 19:58:56 +01:00
{TYPE_INTEGER, "ProcessPriorityLevel", (ConfigValue) 0},
{TYPE_BOOLEAN, "CreateInternalWindow", (ConfigValue) true},
2003-03-11 15:57:08 +01:00
{TYPE_BOOLEAN, "CompleteBooleanEvaluation",(ConfigValue) false},
{TYPE_INTEGER, "RemoteAuxPort", (ConfigValue) 0},
2003-03-15 21:02:39 +01:00
{TYPE_STRING, "RemoteBindAddress", (ConfigValue) 0},
{TYPE_STRING, "ExternalFileAccess", (ConfigValue) "None"}, // location(s) of external files for tables
{TYPE_STRING, "DatabaseAccess", (ConfigValue) "Full"} // location(s) of databases
2002-11-03 17:26:12 +01:00
};
/******************************************************************************
*
* Static instance of the system configuration file
*/
// was: const static ConfigImpl sysConfig;
const ConfigImpl& ConfigImpl::instance()
{
2003-02-16 19:58:56 +01:00
static ConfigImpl *config = 0;
if (!config) {
config = FB_NEW(*getDefaultMemoryPool()) ConfigImpl;
}
return *config;
}
#define sysConfig ConfigImpl::instance()
2002-11-03 17:26:12 +01:00
/******************************************************************************
*
* Implementation interface
*/
ConfigImpl::ConfigImpl()
{
/* Prepare some stuff */
ConfigFile file;
2002-12-06 13:04:39 +01:00
root_dir = getRootDirectory();
MemoryPool *pool = getDefaultMemoryPool();
int size = FB_NELEM(entries);
values = FB_NEW(*pool) ConfigValue[size];
string val_sep = ",";
2002-11-03 17:26:12 +01:00
file.setConfigFile(getConfigFile());
/* Iterate through the known configuration entries */
2002-11-03 17:26:12 +01:00
for (int i = 0; i < size; i++)
2002-11-03 17:26:12 +01:00
{
ConfigEntry entry = entries[i];
string value = getValue(file, entries[i].key);
2002-11-03 17:26:12 +01:00
if (!value.length())
{
/* Assign the default value */
values[i] = entries[i].default_value;
continue;
}
/* Assign the actual value */
switch (entry.data_type)
{
case TYPE_BOOLEAN:
values[i] = (ConfigValue) asBoolean(value);
break;
case TYPE_INTEGER:
values[i] = (ConfigValue) asInteger(value);
break;
case TYPE_STRING:
{
const char *src = asString(value);
char *dst = FB_NEW(*pool) char[strlen(src) + 1];
strcpy(dst, src);
values[i] = (ConfigValue) dst;
}
break;
case TYPE_STRING_VECTOR:
;
}
2002-11-03 17:26:12 +01:00
}
}
ConfigImpl::~ConfigImpl()
2002-11-03 17:26:12 +01:00
{
int size = FB_NELEM(entries);
/* Free allocated memory */
2002-11-03 17:26:12 +01:00
for (int i = 0; i < size; i++)
2002-11-03 17:26:12 +01:00
{
if (values[i] == entries[i].default_value)
continue;
switch (entries[i].data_type)
{
case TYPE_STRING:
delete[] (char*)values[i];
break;
case TYPE_STRING_VECTOR:
;
}
2002-11-03 17:26:12 +01:00
}
delete[] values;
2002-11-03 17:26:12 +01:00
}
2003-01-30 14:26:16 +01:00
string ConfigImpl::getValue(ConfigFile& file, ConfigKey key)
2002-11-03 17:26:12 +01:00
{
return file.doesKeyExist(key) ? file.getString(key) : "";
}
2002-11-03 17:26:12 +01:00
int ConfigImpl::asInteger(const string &value)
{
return atoi(value.data());
}
2002-11-03 17:26:12 +01:00
bool ConfigImpl::asBoolean(const string &value)
{
return (atoi(value.data()) != 0);
}
2002-11-03 17:26:12 +01:00
const char* ConfigImpl::asString(const string &value)
{
return value.c_str();
2002-11-03 17:26:12 +01:00
}
/******************************************************************************
*
* Public interface
*/
const char* Config::getRootDirectory()
2002-11-03 17:26:12 +01:00
{
const char* result = (char*) sysConfig.values[KEY_ROOT_DIRECTORY];
return result ? result : sysConfig.root_dir;
2002-11-03 17:26:12 +01:00
}
int Config::getSortMemBlockSize()
2002-11-03 17:26:12 +01:00
{
return (int) sysConfig.values[KEY_SORT_MEM_BLOCK_SIZE];
2002-11-03 17:26:12 +01:00
}
int Config::getSortMemUpperLimit()
2002-11-03 17:26:12 +01:00
{
return (int) sysConfig.values[KEY_SORT_MEM_UPPER_LIMIT];
2002-11-03 17:26:12 +01:00
}
bool Config::getRemoteFileOpenAbility()
2002-11-03 17:26:12 +01:00
{
return (bool) sysConfig.values[KEY_REMOTE_FILE_OPEN_ABILITY];
2002-11-03 17:26:12 +01:00
}
int Config::getGuardianOption()
2002-11-03 17:26:12 +01:00
{
return (int) sysConfig.values[KEY_GUARDIAN_OPTION];
2002-11-03 17:26:12 +01:00
}
int Config::getCpuAffinityMask()
{
return (int) sysConfig.values[KEY_CPU_AFFINITY_MASK];
}
bool Config::getOldParameterOrdering()
{
return (bool) sysConfig.values[KEY_OLD_PARAMETER_ORDERING];
}
2002-12-06 13:34:43 +01:00
int Config::getTcpRemoteBufferSize()
{
return (int) sysConfig.values[KEY_TCP_REMOTE_BUFFER_SIZE];
}
bool Config::getTcpNoNagle()
{
return (bool) sysConfig.values[KEY_TCP_NO_NAGLE];
}
2002-12-06 22:12:59 +01:00
int Config::getIpcMapSize()
{
return (int) sysConfig.values[KEY_IPC_MAP_SIZE];
}
int Config::getDefaultDbCachePages()
{
return (int) sysConfig.values[KEY_DEFAULT_DB_CACHE_PAGES];
}
int Config::getConnectionTimeout()
{
return (int) sysConfig.values[KEY_CONNECTION_TIMEOUT];
}
int Config::getDummyPacketInterval()
{
return (int) sysConfig.values[KEY_DUMMY_PACKET_INTERVAL];
}
2002-12-07 14:27:12 +01:00
int Config::getLockMemSize()
{
return (int) sysConfig.values[KEY_LOCK_MEM_SIZE];
}
int Config::getLockSemCount()
{
return (int) sysConfig.values[KEY_LOCK_SEM_COUNT];
}
int Config::getLockSignal()
{
return (int) sysConfig.values[KEY_LOCK_SIGNAL];
}
bool Config::getLockGrantOrder()
{
return (bool) sysConfig.values[KEY_LOCK_GRANT_ORDER];
}
int Config::getLockHashSlots()
{
return (int) sysConfig.values[KEY_LOCK_HASH_SLOTS];
}
bool Config::getLockAcquireSpins()
{
return (bool) sysConfig.values[KEY_LOCK_ACQUIRE_SPINS];
}
int Config::getEventMemSize()
{
return (int) sysConfig.values[KEY_EVENT_MEM_SIZE];
}
int Config::getDeadlockTimeout()
{
return (int) sysConfig.values[KEY_DEADLOCK_TIMEOUT];
}
int Config::getSolarisStallValue()
{
return (int) sysConfig.values[KEY_SOLARIS_STALL_VALUE];
}
2002-12-07 14:49:37 +01:00
bool Config::getTraceMemoryPools()
{
return (bool) sysConfig.values[KEY_TRACE_MEMORY_POOLS];
}
int Config::getPrioritySwitchDelay()
{
int rc = (int) sysConfig.values[KEY_PRIORITY_SWITCH_DELAY];
if (rc < 1)
rc = 1;
return rc;
}
int Config::getDeadThreadsCollection()
{
int rc = (int) sysConfig.values[KEY_DEAD_THREADS_COLLECTION];
if (rc < 1)
rc = 1;
return rc;
}
int Config::getPriorityBoost()
{
int rc = (int) sysConfig.values[KEY_PRIORITY_BOOST];
if (rc < 1)
rc = 1;
if (rc > 1000)
rc = 1000;
return rc;
}
2003-01-15 15:10:07 +01:00
const char *Config::getRemoteServiceName()
{
return (const char*) sysConfig.values[KEY_REMOTE_SERVICE_NAME];
}
int Config::getRemoteServicePort()
{
return (int) sysConfig.values[KEY_REMOTE_SERVICE_PORT];
}
const char *Config::getRemotePipeName()
2003-01-15 15:10:07 +01:00
{
return (const char*) sysConfig.values[KEY_REMOTE_PIPE_NAME];
2003-01-15 15:10:07 +01:00
}
const char *Config::getIpcName()
2003-01-15 15:10:07 +01:00
{
return (const char*) sysConfig.values[KEY_IPC_NAME];
2003-01-15 15:10:07 +01:00
}
int Config::getMaxUnflushedWrites()
{
return (int) sysConfig.values[KEY_MAX_UNFLUSHED_WRITES];
}
int Config::getMaxUnflushedWriteTime()
{
return (int) sysConfig.values[KEY_MAX_UNFLUSHED_WRITE_TIME];
2003-02-09 12:22:10 +01:00
}
2003-02-16 19:58:56 +01:00
int Config::getProcessPriorityLevel()
{
return (int) sysConfig.values[KEY_PROCESS_PRIORITY_LEVEL];
}
bool Config::getCreateInternalWindow()
{
return (bool) sysConfig.values[KEY_CREATE_INTERNAL_WINDOW];
}
bool Config::getCompleteBooleanEvaluation()
{
return (bool) sysConfig.values[KEY_COMPLETE_BOOLEAN_EVALUATION];
}
2003-03-11 15:57:08 +01:00
int Config::getRemoteAuxPort()
{
return (int) sysConfig.values[KEY_REMOTE_AUX_PORT];
}
const char *Config::getRemoteBindAddress()
{
return (const char*) sysConfig.values[KEY_REMOTE_BIND_ADDRESS];
}
2003-03-15 21:02:39 +01:00
const char *Config::getExternalFileAccess()
2003-03-15 21:02:39 +01:00
{
return (const char*) sysConfig.values[KEY_EXTERNAL_FILE_ACCESS];
2003-03-15 21:02:39 +01:00
}
const char *Config::getDatabaseAccess()
{
return (const char*) sysConfig.values[KEY_DATABASE_ACCESS];
}