Implement additional attributes for the Host class

refs #7564
This commit is contained in:
Gunnar Beutner 2015-02-09 08:50:17 +01:00
parent bb12704a31
commit 97fc5bb10b
17 changed files with 68 additions and 35 deletions

View File

@ -53,7 +53,7 @@ DynamicObject::DynamicObject(void)
DynamicType::Ptr DynamicObject::GetType(void) const
{
return DynamicType::GetByName(GetTypeName());
return DynamicType::GetByName(GetTypeNameV());
}
DebugInfo DynamicObject::GetDebugInfo(void) const

View File

@ -44,8 +44,8 @@ abstract class DynamicObject
return m_ShortName;
}}}
};
[config, internal, get_protected] String type (TypeName);
[config] String zone;
[config, internal, get_protected] String type (TypeNameV);
[config] String zone (ZoneName);
[config, internal, get_protected] Array::Ptr templates;
[get_protected] bool active;
[get_protected] bool paused {

View File

@ -258,7 +258,7 @@ void CheckerComponent::ObjectHandler(const DynamicObject::Ptr& object)
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
Zone::Ptr zone = Zone::GetByName(checkable->GetZone());
Zone::Ptr zone = Zone::GetByName(checkable->GetZoneName());
bool same_zone = (!zone || Zone::GetLocalZone() == zone);
{

View File

@ -160,8 +160,8 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
DynamicObject::Ptr dobj = static_pointer_cast<DynamicObject>(type->Instantiate());
dobj->SetDebugInfo(m_DebugInfo);
dobj->SetTypeName(m_Type);
dobj->SetZone(m_Zone);
dobj->SetTypeNameV(m_Type);
dobj->SetZoneName(m_Zone);
dobj->SetName(m_Name);
DebugHint debugHints;

View File

@ -66,7 +66,7 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
if (service)
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "child_service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
String zone = checkable->GetZone();
String zone = checkable->GetZoneName();
if (!zone.IsEmpty())
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));

View File

@ -51,9 +51,9 @@ public:
static HostState CalculateState(ServiceState state);
HostState GetState(void) const;
HostState GetLastState(void) const;
HostState GetLastHardState(void) const;
virtual HostState GetState(void) const;
virtual HostState GetLastState(void) const;
virtual HostState GetLastHardState(void) const;
double GetLastStateUp(void) const;
double GetLastStateDown(void) const;

View File

@ -36,6 +36,17 @@ class Host : Checkable
[config] String address;
[config] String address6;
[enum, no_storage] HostState "state" {
get;
};
[enum, no_storage] HostState last_state {
get;
};
[enum, no_storage] HostState last_hard_state {
get;
};
};
}

View File

@ -65,7 +65,7 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
if (service)
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
String zone = checkable->GetZone();
String zone = checkable->GetZoneName();
if (!zone.IsEmpty())
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));

View File

@ -64,7 +64,7 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
if (service)
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
String zone = checkable->GetZone();
String zone = checkable->GetZoneName();
if (!zone.IsEmpty())
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));

View File

@ -58,7 +58,7 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "name"), OpSetLiteral, MakeLiteral(name), di));
String zone = host->GetZone();
String zone = host->GetZoneName();
if (!zone.IsEmpty())
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));

View File

@ -44,17 +44,17 @@ class Service : Checkable < ServiceNameComposer
}}}
};
[config] String host_name;
[enum] ServiceState "state" {
[enum, no_storage] ServiceState "state" {
get {{{
return GetStateRaw();
}}}
};
[enum] ServiceState last_state {
[enum, no_storage] ServiceState last_state {
get {{{
return GetLastStateRaw();
}}}
};
[enum] ServiceState last_hard_state {
[enum, no_storage] ServiceState last_hard_state {
get {{{
return GetLastHardStateRaw();
}}}

View File

@ -556,7 +556,7 @@ void ApiListener::SyncRelayMessage(const MessageOrigin& origin, const DynamicObj
/* only relay the message to a) the same zone, b) the parent zone and c) direct child zones */
if (target_zone != my_zone && target_zone != my_zone->GetParent() &&
secobj->GetZone() != target_zone->GetName()) {
secobj->GetZoneName() != target_zone->GetName()) {
skippedEndpoints.push_back(endpoint);
continue;
}

View File

@ -60,7 +60,7 @@ bool Zone::CanAccessObject(const DynamicObject::Ptr& object)
if (dynamic_pointer_cast<Zone>(object))
object_zone = static_pointer_cast<Zone>(object);
else
object_zone = Zone::GetByName(object->GetZone());
object_zone = Zone::GetByName(object->GetZoneName());
if (!object_zone)
object_zone = Zone::GetLocalZone();

View File

@ -141,6 +141,7 @@ get_protected { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; }
set_protected { yylval->num = FASetProtected; return T_FIELD_ATTRIBUTE; }
protected { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTRIBUTE; }
internal { yylval->num = FAInternal; return T_FIELD_ATTRIBUTE; }
no_storage { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; }
default { yylval->num = FTDefault; return T_FIELD_ACCESSOR_TYPE; }
get { yylval->num = FTGet; return T_FIELD_ACCESSOR_TYPE; }
set { yylval->num = FTSet; return T_FIELD_ACCESSOR_TYPE; }

View File

@ -265,9 +265,11 @@ class_field: field_attribute_list identifier identifier alternative_name_specifi
switch (it->Type) {
case FTGet:
field->GetAccessor = it->Accessor;
field->PureGetAccessor = it->Pure;
break;
case FTSet:
field->SetAccessor = it->Accessor;
field->PureSetAccessor = it->Pure;
break;
case FTDefault:
field->DefaultAccessor = it->Accessor;
@ -339,9 +341,13 @@ field_accessors: /* empty */
field_accessor: T_FIELD_ACCESSOR_TYPE T_STRING
{
$$ = new FieldAccessor(static_cast<FieldAccessorType>($1), $2);
$$ = new FieldAccessor(static_cast<FieldAccessorType>($1), $2, false);
std::free($2);
}
| T_FIELD_ACCESSOR_TYPE ';'
{
$$ = new FieldAccessor(static_cast<FieldAccessorType>($1), "", true);
}
;
identifier: T_IDENTIFIER

View File

@ -454,16 +454,22 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
prot = "public";
std::cout << prot << ":" << std::endl
<< "\t" << it->Type << " Get" << it->GetFriendlyName() << "(void) const" << std::endl
<< "\t" << "virtual " << it->Type << " Get" << it->GetFriendlyName() << "(void) const";
if (it->PureGetAccessor) {
std::cout << " = 0;" << std::endl;
} else {
std::cout << std::endl
<< "\t" << "{" << std::endl;
if (it->GetAccessor.empty())
if (it->GetAccessor.empty() && !(it->Attributes & FANoStorage))
std::cout << "\t\t" << "return m_" << it->GetFriendlyName() << ";" << std::endl;
else
std::cout << it->GetAccessor << std::endl;
std::cout << "\t" << "}" << std::endl << std::endl;
}
}
/* setters */
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
@ -484,16 +490,21 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
else
std::cout << "const " << it->Type << "&";
std::cout << " value)" << std::endl
<< "\t" << "{" << std::endl;
std::cout << " value)" << std::endl;
if (it->SetAccessor.empty())
if (it->PureSetAccessor) {
std::cout << " = 0;" << std::endl;
} else {
std::cout << "\t" << "{" << std::endl;
if (it->SetAccessor.empty() && !(it->Attributes & FANoStorage))
std::cout << "\t\t" << "m_" << it->GetFriendlyName() << " = value;" << std::endl;
else
std::cout << it->SetAccessor << std::endl;
std::cout << "\t" << "}" << std::endl << std::endl;
}
}
/* default */
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {

View File

@ -48,9 +48,10 @@ struct FieldAccessor
{
FieldAccessorType Type;
std::string Accessor;
bool Pure;
FieldAccessor(FieldAccessorType type, const std::string& accessor)
: Type(type), Accessor(accessor)
FieldAccessor(FieldAccessorType type, const std::string& accessor, bool pure)
: Type(type), Accessor(accessor), Pure(pure)
{ }
};
@ -61,7 +62,8 @@ enum FieldAttribute
FAEnum = 4,
FAGetProtected = 8,
FASetProtected = 16,
FAInternal = 32
FAInternal = 32,
FANoStorage = 64
};
struct Field
@ -71,7 +73,9 @@ struct Field
std::string Name;
std::string AlternativeName;
std::string GetAccessor;
bool PureGetAccessor;
std::string SetAccessor;
bool PureSetAccessor;
std::string DefaultAccessor;
std::string GetFriendlyName(void) const