add functions: iniGetByteValueEx and iniGetIntCorrectValueEx
parent
5a04c1c656
commit
85354b6ef6
|
|
@ -85,7 +85,7 @@ void fast_timer_add_ex(FastTimer *timer, FastTimerEntry *entry,
|
|||
new_expires = expires;
|
||||
new_set_expires = set_expires;
|
||||
} else {
|
||||
new_expires = timer->current_time;
|
||||
new_expires = timer->current_time + 1; //plus 1 for rare case
|
||||
new_set_expires = true;
|
||||
}
|
||||
slot = TIMER_GET_SLOT_POINTER(timer, new_expires);
|
||||
|
|
@ -97,10 +97,6 @@ int fast_timer_modify(FastTimer *timer, FastTimerEntry *entry,
|
|||
{
|
||||
int result;
|
||||
|
||||
if (new_expires <= timer->current_time) {
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
|
||||
if (new_expires > entry->expires) {
|
||||
entry->rehash = TIMER_GET_SLOT_INDEX(timer, new_expires) !=
|
||||
TIMER_GET_SLOT_INDEX(timer, entry->expires);
|
||||
|
|
|
|||
|
|
@ -2854,6 +2854,44 @@ char *iniGetStrValueEx(const char *szSectionName, const char *szItemName,
|
|||
return pFound->value;
|
||||
}
|
||||
|
||||
#define INI_FILL_SECTION_PROMPT(prompt, size, section_name) \
|
||||
do { \
|
||||
if (section_name != NULL && *(section_name) != '\0') { \
|
||||
snprintf(prompt, size, "section: %s, ", section_name); \
|
||||
} else { \
|
||||
*prompt = '\0'; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int64_t iniCheckAndCorrectIntValue(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int64_t nValue,
|
||||
const int64_t nMinValue, const int64_t nMaxValue)
|
||||
{
|
||||
char section_prompt[128];
|
||||
if (nValue < nMinValue) {
|
||||
INI_FILL_SECTION_PROMPT(section_prompt, sizeof(section_prompt),
|
||||
pIniContext->section_name);
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"config file: %s, %sitem name: %s, item value: %"PRId64
|
||||
" < min value: %"PRId64", set to min value: %"PRId64,
|
||||
__LINE__, pIniContext->filename, section_prompt, szItemName,
|
||||
nValue, nMinValue, nMinValue);
|
||||
|
||||
return nMinValue;
|
||||
} else if (nValue > nMaxValue) {
|
||||
INI_FILL_SECTION_PROMPT(section_prompt, sizeof(section_prompt),
|
||||
pIniContext->section_name);
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"config file: %s, %sitem name: %s, item value: %"PRId64
|
||||
" > max value: %"PRId64", set to max value: %"PRId64,
|
||||
__LINE__, pIniContext->filename, section_prompt, szItemName,
|
||||
nValue, nMaxValue, nMaxValue);
|
||||
return nMaxValue;
|
||||
}
|
||||
|
||||
return nValue;
|
||||
}
|
||||
|
||||
int64_t iniGetInt64ValueEx(const char *szSectionName,
|
||||
const char *szItemName, IniContext *pContext,
|
||||
const int64_t nDefaultValue, const bool bRetryGlobal)
|
||||
|
|
@ -2872,6 +2910,56 @@ int64_t iniGetInt64ValueEx(const char *szSectionName,
|
|||
}
|
||||
}
|
||||
|
||||
int64_t iniGetInt64CorrectValueEx(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int64_t nDefaultValue,
|
||||
const int64_t nMinValue, const int64_t nMaxValue,
|
||||
const bool bRetryGlobal)
|
||||
{
|
||||
int64_t value;
|
||||
|
||||
value = iniGetInt64ValueEx(pIniContext->section_name, szItemName,
|
||||
pIniContext->context, nDefaultValue, bRetryGlobal);
|
||||
return iniCheckAndCorrectIntValue(pIniContext, szItemName,
|
||||
value, nMinValue, nMaxValue);
|
||||
}
|
||||
|
||||
int64_t iniGetByteValueEx(const char *szSectionName,
|
||||
const char *szItemName, IniContext *pContext,
|
||||
const int64_t nDefaultValue, const int nDefaultUnitBytes,
|
||||
const bool bRetryGlobal)
|
||||
{
|
||||
char *pValue;
|
||||
int64_t nValue;
|
||||
|
||||
pValue = iniGetStrValueEx(szSectionName,
|
||||
szItemName, pContext, bRetryGlobal);
|
||||
if (pValue == NULL)
|
||||
{
|
||||
return nDefaultValue;
|
||||
}
|
||||
|
||||
if (parse_bytes(pValue, nDefaultUnitBytes, &nValue) != 0)
|
||||
{
|
||||
return nDefaultValue;
|
||||
}
|
||||
|
||||
return nValue;
|
||||
}
|
||||
|
||||
int64_t iniGetByteCorrectValueEx(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int64_t nDefaultValue,
|
||||
const int nDefaultUnitBytes, const int64_t nMinValue,
|
||||
const int64_t nMaxValue, const bool bRetryGlobal)
|
||||
{
|
||||
int64_t nValue;
|
||||
|
||||
nValue = iniGetByteValueEx(pIniContext->section_name, szItemName,
|
||||
pIniContext->context, nDefaultValue, nDefaultUnitBytes,
|
||||
bRetryGlobal);
|
||||
return iniCheckAndCorrectIntValue(pIniContext, szItemName,
|
||||
nValue, nMinValue, nMaxValue);
|
||||
}
|
||||
|
||||
int iniGetIntValueEx(const char *szSectionName,
|
||||
const char *szItemName, IniContext *pContext,
|
||||
const int nDefaultValue, const bool bRetryGlobal)
|
||||
|
|
@ -2890,6 +2978,18 @@ int iniGetIntValueEx(const char *szSectionName,
|
|||
}
|
||||
}
|
||||
|
||||
int iniGetIntCorrectValueEx(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int nDefaultValue,
|
||||
const int nMinValue, const int nMaxValue, const bool bRetryGlobal)
|
||||
{
|
||||
int value;
|
||||
|
||||
value = iniGetIntValueEx(pIniContext->section_name, szItemName,
|
||||
pIniContext->context, nDefaultValue, bRetryGlobal);
|
||||
return iniCheckAndCorrectIntValue(pIniContext, szItemName,
|
||||
value, nMinValue, nMaxValue);
|
||||
}
|
||||
|
||||
double iniGetDoubleValueEx(const char *szSectionName,
|
||||
const char *szItemName, IniContext *pContext,
|
||||
const double dbDefaultValue, const bool bRetryGlobal)
|
||||
|
|
|
|||
|
|
@ -136,6 +136,25 @@ extern "C" {
|
|||
#define iniGetPercentValue(ini_ctx, item_name, item_value, default_value) \
|
||||
iniGetPercentValueEx(ini_ctx, item_name, item_value, default_value, false)
|
||||
|
||||
#define iniGetByteValue(szSectionName, szItemName, pContext, nDefaultValue) \
|
||||
iniGetByteValueEx(szSectionName, szItemName, pContext, \
|
||||
nDefaultValue, 1, false)
|
||||
|
||||
#define iniGetIntCorrectValue(ini_ctx, item_name, \
|
||||
default_value, min_value, max_value) \
|
||||
iniGetIntCorrectValueEx(ini_ctx, item_name, \
|
||||
default_value, min_value, max_value, false)
|
||||
|
||||
#define iniGetInt64CorrectValue(ini_ctx, item_name, \
|
||||
default_value, min_value, max_value) \
|
||||
iniGetInt64CorrectValueEx(ini_ctx, item_name, \
|
||||
default_value, min_value, max_value, false)
|
||||
|
||||
#define iniGetByteCorrectValue(ini_ctx, item_name, \
|
||||
default_value, min_value, max_value) \
|
||||
iniGetByteCorrectValueEx(ini_ctx, item_name, \
|
||||
default_value, 1, min_value, max_value, false)
|
||||
|
||||
int iniSetAnnotationCallBack(AnnotationEntry *annotations, int count);
|
||||
void iniDestroyAnnotationCallBack();
|
||||
|
||||
|
|
@ -232,6 +251,33 @@ int iniGetIntValueEx(const char *szSectionName,
|
|||
const char *szItemName, IniContext *pContext,
|
||||
const int nDefaultValue, const bool bRetryGlobal);
|
||||
|
||||
/** check and correct item value
|
||||
* parameters:
|
||||
* pIniContext: the full ini context
|
||||
* szItemName: the item name
|
||||
* nValue: the item value
|
||||
* nMinValue: the min value to check (including)
|
||||
* nMaxValue: the max value to check (including)
|
||||
* return: corrected value
|
||||
*/
|
||||
int64_t iniCheckAndCorrectIntValue(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int64_t nValue,
|
||||
const int64_t nMinValue, const int64_t nMaxValue);
|
||||
|
||||
/** get item correct value (32 bits integer)
|
||||
* parameters:
|
||||
* pIniContext: the full ini context
|
||||
* szItemName: the item name
|
||||
* nDefaultValue: the default value
|
||||
* nMinValue: the min value to check (including)
|
||||
* nMaxValue: the max value to check (including)
|
||||
* bRetryGlobal: if fetch from global section when the item not exist
|
||||
* return: item value, return nDefaultValue when the item not exist
|
||||
*/
|
||||
int iniGetIntCorrectValueEx(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int nDefaultValue,
|
||||
const int nMinValue, const int nMaxValue, const bool bRetryGlobal);
|
||||
|
||||
/** get item string value array
|
||||
* parameters:
|
||||
* szSectionName: the section name, NULL or empty string for
|
||||
|
|
@ -244,7 +290,7 @@ int iniGetIntValueEx(const char *szSectionName,
|
|||
IniItem *iniGetValuesEx(const char *szSectionName, const char *szItemName,
|
||||
IniContext *pContext, int *nTargetCount);
|
||||
|
||||
/** get item int64 value (64 bits)
|
||||
/** get item value (64 bits integer)
|
||||
* parameters:
|
||||
* szSectionName: the section name, NULL or empty string for
|
||||
* global section
|
||||
|
|
@ -258,6 +304,53 @@ int64_t iniGetInt64ValueEx(const char *szSectionName,
|
|||
const char *szItemName, IniContext *pContext,
|
||||
const int64_t nDefaultValue, const bool bRetryGlobal);
|
||||
|
||||
/** get item correct value (64 bits integer)
|
||||
* parameters:
|
||||
* pIniContext: the full ini context
|
||||
* szItemName: the item name
|
||||
* nDefaultValue: the default value
|
||||
* nMinValue: the min value to check (including)
|
||||
* nMaxValue: the max value to check (including)
|
||||
* bRetryGlobal: if fetch from global section when the item not exist
|
||||
* return: int64 value, return nDefaultValue when the item not exist
|
||||
*/
|
||||
int64_t iniGetInt64CorrectValueEx(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int64_t nDefaultValue,
|
||||
const int64_t nMinValue, const int64_t nMaxValue,
|
||||
const bool bRetryGlobal);
|
||||
|
||||
/** get item byte value (64 bits integer)
|
||||
* parameters:
|
||||
* szSectionName: the section name, NULL or empty string for
|
||||
* global section
|
||||
* szItemName: the item name
|
||||
* pContext: the ini context
|
||||
* nDefaultValue: the default value
|
||||
* nDefaultUnitBytes: the default byte unit, such as 1 for byte, 1024 for KB
|
||||
* bRetryGlobal: if fetch from global section when the item not exist
|
||||
* return: int64 value, return nDefaultValue when the item not exist
|
||||
*/
|
||||
int64_t iniGetByteValueEx(const char *szSectionName,
|
||||
const char *szItemName, IniContext *pContext,
|
||||
const int64_t nDefaultValue, const int nDefaultUnitBytes,
|
||||
const bool bRetryGlobal);
|
||||
|
||||
/** get item correct byte value (64 bits integer)
|
||||
* parameters:
|
||||
* pIniContext: the full ini context
|
||||
* szItemName: the item name
|
||||
* nDefaultValue: the default value
|
||||
* nDefaultUnitBytes: the default byte unit, such as 1 for byte, 1024 for KB
|
||||
* nMinValue: the min value to check (including)
|
||||
* nMaxValue: the max value to check (including)
|
||||
* bRetryGlobal: if fetch from global section when the item not exist
|
||||
* return: int64 value, return nDefaultValue when the item not exist
|
||||
*/
|
||||
int64_t iniGetByteCorrectValueEx(IniFullContext *pIniContext,
|
||||
const char *szItemName, const int64_t nDefaultValue,
|
||||
const int nDefaultUnitBytes, const int64_t nMinValue,
|
||||
const int64_t nMaxValue, const bool bRetryGlobal);
|
||||
|
||||
/** get item boolean value
|
||||
* parameters:
|
||||
* szSectionName: the section name, NULL or empty string for
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ void locked_timer_add_ex(LockedTimer *timer, LockedTimerEntry *entry,
|
|||
new_expires = expires;
|
||||
new_flags = flags;
|
||||
} else {
|
||||
new_expires = timer->current_time;
|
||||
new_expires = timer->current_time + 1; //plus 1 for rare case
|
||||
new_flags = flags | FAST_TIMER_FLAGS_SET_EXPIRES;
|
||||
}
|
||||
slot = TIMER_GET_SLOT_POINTER(timer, new_expires);
|
||||
|
|
@ -240,10 +240,6 @@ int locked_timer_modify(LockedTimer *timer, LockedTimerEntry *entry,
|
|||
int result;
|
||||
int slot_index;
|
||||
|
||||
if (new_expires <= timer->current_time) {
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
|
||||
if (new_expires > entry->expires) {
|
||||
if ((result=check_entry_status(timer, entry, &slot_index)) != 0) {
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Reference in New Issue