1
0

BlockTypeRegistry: Added hint manipulation

This commit is contained in:
Mattes D
2019-01-24 09:48:30 +01:00
parent 3722a239bf
commit f48ac9f0c3
3 changed files with 181 additions and 3 deletions

View File

@@ -56,6 +56,33 @@ AString BlockInfo::hintValue(
void BlockInfo::setHint(const AString & aHintKey, const AString & aHintValue)
{
mHints[aHintKey] = aHintValue;
// Warn if the hint is already provided by a callback (aHintValue will be ignored when evaluating the hint):
auto itrC = mHintCallbacks.find(aHintKey);
if (itrC != mHintCallbacks.end())
{
LOGINFO("Setting a static hint %s for block type %s, but there's already a callback for that hint. The static hint will be ignored.",
aHintKey.c_str(), mBlockTypeName.c_str()
);
}
}
void BlockInfo::removeHint(const AString & aHintKey)
{
mHints.erase(aHintKey);
}
////////////////////////////////////////////////////////////////////////////////
// BlockTypeRegistry:
@@ -123,6 +150,43 @@ void BlockTypeRegistry::removeAllByPlugin(const AString & aPluginName)
void BlockTypeRegistry::setBlockTypeHint(
const AString & aBlockTypeName,
const AString & aHintKey,
const AString & aHintValue
)
{
cCSLock lock(mCSRegistry);
auto blockInfo = mRegistry.find(aBlockTypeName);
if (blockInfo == mRegistry.end())
{
throw NotRegisteredException(aBlockTypeName, aHintKey, aHintValue);
}
blockInfo->second->setHint(aHintKey, aHintValue);
}
void BlockTypeRegistry::removeBlockTypeHint(
const AString & aBlockTypeName,
const AString & aHintKey
)
{
cCSLock lock(mCSRegistry);
auto blockInfo = mRegistry.find(aBlockTypeName);
if (blockInfo == mRegistry.end())
{
return;
}
blockInfo->second->removeHint(aHintKey);
}
////////////////////////////////////////////////////////////////////////////////
// BlockTypeRegistry::AlreadyRegisteredException:
@@ -151,3 +215,24 @@ AString BlockTypeRegistry::AlreadyRegisteredException::message(
aPreviousRegistration->pluginName().c_str()
);
}
////////////////////////////////////////////////////////////////////////////////
// BlockTypeRegistry::NotRegisteredException:
BlockTypeRegistry::NotRegisteredException::NotRegisteredException(
const AString & aBlockTypeName,
const AString & aHintKey,
const AString & aHintValue
):
Super(Printf(
"Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = %s\n\tHintKey = %s\n\tHintValue = %s",
aBlockTypeName.c_str(),
aHintKey.c_str(),
aHintValue.c_str()
))
{
}