Refactor name helper classes a bit.

Refs #5925
This commit is contained in:
Gunnar Beutner 2014-04-06 08:09:49 +02:00
parent 020eaf99ab
commit ad42367999
13 changed files with 30 additions and 29 deletions

View File

@ -35,8 +35,8 @@ The semi-colon after the last element (i.e. `address6`) may be omitted.
Each object is uniquely identified by its type (`Host`) and name
(`host1.example.org`). Some types have composite names, e.g. the
`Service` type which uses the hostname and the name you specified
to generate its object name.
`Service` type which uses the `host_name` attribute and the name
you specified to generate its object name.
Objects can contain a comma-separated list of property
declarations. Instead of commas semi-colons may also be used.

View File

@ -2,9 +2,9 @@ namespace icinga
{
code {{{
class DynamicObjectNameHelper {
class NameComposer {
public:
virtual String MakeObjectName(const String& shortName, const Dictionary::Ptr props) const = 0;
virtual String MakeName(const String& shortName, const Dictionary::Ptr props) const = 0;
};
}}}

View File

@ -525,10 +525,10 @@ Value AExpression::OpObject(const AExpression* expr, const Dictionary::Ptr& loca
String checkName = name;
if (!abstract) {
const DynamicObjectNameHelper *nh = dynamic_cast<const DynamicObjectNameHelper *>(Type::GetByName(type));
const NameComposer *nc = dynamic_cast<const NameComposer *>(Type::GetByName(type));
if (nh)
checkName = nh->MakeObjectName(name, Dictionary::Ptr());
if (nc)
checkName = nc->MakeName(name, Dictionary::Ptr());
}
if (!checkName.IsEmpty()) {

View File

@ -124,10 +124,10 @@ Dictionary::Ptr ConfigItem::GetProperties(void)
String name = m_Name;
if (!m_Abstract) {
const DynamicObjectNameHelper *nh = dynamic_cast<const DynamicObjectNameHelper *>(Type::GetByName(m_Type));
const NameComposer *nc = dynamic_cast<const NameComposer *>(Type::GetByName(m_Type));
if (nh) {
name = nh->MakeObjectName(m_Name, m_Properties);
if (nc) {
name = nc->MakeName(m_Name, m_Properties);
if (name.IsEmpty())
BOOST_THROW_EXCEPTION(std::runtime_error("Could not determine name for object"));
@ -197,10 +197,10 @@ void ConfigItem::Register(void)
/* If this is a non-abstract object we need to figure out
* its real name now - or assign it a temporary name. */
if (!m_Abstract) {
const DynamicObjectNameHelper *nh = dynamic_cast<const DynamicObjectNameHelper *>(Type::GetByName(m_Type));
const NameComposer *nc = dynamic_cast<const NameComposer *>(Type::GetByName(m_Type));
if (nh) {
name = nh->MakeObjectName(m_Name, Dictionary::Ptr());
if (nc) {
name = nc->MakeName(m_Name, Dictionary::Ptr());
ASSERT(name.IsEmpty() || name == m_Name);

View File

@ -28,7 +28,7 @@ using namespace icinga;
REGISTER_TYPE(Dependency);
String DependencyNameHelper::MakeObjectName(const String& shortName, const Dictionary::Ptr props) const
String DependencyNameComposer::MakeName(const String& shortName, const Dictionary::Ptr props) const
{
if (!props)
return "";

View File

@ -5,14 +5,14 @@ namespace icinga
{
code {{{
class I2_ICINGA_API DependencyNameHelper : public DynamicObjectNameHelper
class I2_ICINGA_API DependencyNameComposer : public NameComposer
{
public:
virtual String MakeObjectName(const String& shortName, const Dictionary::Ptr props) const;
virtual String MakeName(const String& shortName, const Dictionary::Ptr props) const;
};
}}}
class Dependency : DynamicObject < DependencyNameHelper
class Dependency : DynamicObject < DependencyNameComposer
{
[config] String child_host_name;
[config] String child_service_name;

View File

@ -412,6 +412,7 @@ Dictionary::Ptr LegacyTimePeriod::FindNextSegment(const String& daydef, const St
Dictionary::Ptr bestSegment;
double bestBegin;
ObjectLock olock(segments);
BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
double begin = segment->Get("begin");

View File

@ -38,7 +38,7 @@ INITIALIZE_ONCE(&Notification::StaticInitialize);
boost::signals2::signal<void (const Notification::Ptr&, double, const String&)> Notification::OnNextNotificationChanged;
String NotificationNameHelper::MakeObjectName(const String& shortName, const Dictionary::Ptr props) const
String NotificationNameComposer::MakeName(const String& shortName, const Dictionary::Ptr props) const
{
if (!props)
return "";

View File

@ -4,14 +4,14 @@ namespace icinga
{
code {{{
class I2_ICINGA_API NotificationNameHelper : public DynamicObjectNameHelper
class I2_ICINGA_API NotificationNameComposer : public NameComposer
{
public:
virtual String MakeObjectName(const String& shortName, const Dictionary::Ptr props) const;
virtual String MakeName(const String& shortName, const Dictionary::Ptr props) const;
};
}}}
class Notification : DynamicObject < NotificationNameHelper
class Notification : DynamicObject < NotificationNameComposer
{
[config, protected] String notification_command (NotificationCommandRaw);
[config] double notification_interval {

View File

@ -37,7 +37,7 @@ INITIALIZE_ONCE(&ScheduledDowntime::StaticInitialize);
static Timer::Ptr l_Timer;
String ScheduledDowntimeNameHelper::MakeObjectName(const String& shortName, const Dictionary::Ptr props) const
String ScheduledDowntimeNameComposer::MakeName(const String& shortName, const Dictionary::Ptr props) const
{
if (!props)
return "";

View File

@ -4,14 +4,14 @@ namespace icinga
{
code {{{
class I2_ICINGA_API ScheduledDowntimeNameHelper : public DynamicObjectNameHelper
class I2_ICINGA_API ScheduledDowntimeNameComposer : public NameComposer
{
public:
virtual String MakeObjectName(const String& shortName, const Dictionary::Ptr props) const;
virtual String MakeName(const String& shortName, const Dictionary::Ptr props) const;
};
}}}
class ScheduledDowntime : DynamicObject < ScheduledDowntimeNameHelper
class ScheduledDowntime : DynamicObject < ScheduledDowntimeNameComposer
{
[config, protected] String host_name;
[config, protected] String service_name;

View File

@ -39,7 +39,7 @@ REGISTER_TYPE(Service);
INITIALIZE_ONCE(&Service::StartDowntimesExpiredTimer);
String ServiceNameHelper::MakeObjectName(const String& shortName, const Dictionary::Ptr props) const {
String ServiceNameComposer::MakeName(const String& shortName, const Dictionary::Ptr props) const {
if (!props)
return "";

View File

@ -7,14 +7,14 @@ namespace icinga
{
code {{{
class I2_ICINGA_API ServiceNameHelper : public DynamicObjectNameHelper
class I2_ICINGA_API ServiceNameComposer : public NameComposer
{
public:
virtual String MakeObjectName(const String& shortName, const Dictionary::Ptr props) const;
virtual String MakeName(const String& shortName, const Dictionary::Ptr props) const;
};
}}}
class Service : Checkable < ServiceNameHelper
class Service : Checkable < ServiceNameComposer
{
[config] String display_name {
get {{{