diff --git a/cib/Makefile.am b/cib/Makefile.am index 79e45ae90..9b33ce5c2 100644 --- a/cib/Makefile.am +++ b/cib/Makefile.am @@ -32,6 +32,7 @@ libcib_la_CPPFLAGS = \ -DI2_CIB_BUILD \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga \ -I${top_srcdir}/third-party/popen-noshell @@ -46,6 +47,7 @@ libcib_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la \ ${top_builddir}/third-party/popen-noshell/libpopen_noshell.la diff --git a/cib/cib.cpp b/cib/cib.cpp index fa2ac41b6..e09c73f8b 100644 --- a/cib/cib.cpp +++ b/cib/cib.cpp @@ -14,9 +14,12 @@ void CIB::RequireInformation(InformationType types) Component::Ptr component = app->GetComponent("cibsync"); if (!component) { - ConfigObject::Ptr cibsyncComponentConfig = boost::make_shared("component", "cibsync"); - cibsyncComponentConfig->SetLocal(true); - cibsyncComponentConfig->Commit(); + ConfigItemBuilder::Ptr cb = boost::make_shared(); + cb->SetType("component"); + cb->SetName("cibsync"); + cb->SetLocal(true); + ConfigItem::Ptr ci = cb->Compile(); + ci->Commit(); } } diff --git a/cib/i2-cib.h b/cib/i2-cib.h index 5811b441a..83a2b79fb 100644 --- a/cib/i2-cib.h +++ b/cib/i2-cib.h @@ -8,6 +8,7 @@ * updates from all the other Icinga components. */ +#include #include #ifdef I2_CIB_BUILD diff --git a/components/checker/Makefile.am b/components/checker/Makefile.am index fddd0dce5..798047c7f 100644 --- a/components/checker/Makefile.am +++ b/components/checker/Makefile.am @@ -11,6 +11,7 @@ checker_la_SOURCES = \ checker_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga \ -I${top_srcdir}/cib @@ -26,6 +27,7 @@ checker_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la \ ${top_builddir}/cib/libcib.la diff --git a/components/cibsync/Makefile.am b/components/cibsync/Makefile.am index df926a9b7..c2fab7fa2 100644 --- a/components/cibsync/Makefile.am +++ b/components/cibsync/Makefile.am @@ -11,6 +11,7 @@ cibsync_la_SOURCES = \ cibsync_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga \ -I${top_srcdir}/cib @@ -26,6 +27,7 @@ cibsync_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la \ ${top_builddir}/cib/libcib.la diff --git a/components/compat/Makefile.am b/components/compat/Makefile.am index 8d868d1fd..7d758ebd3 100644 --- a/components/compat/Makefile.am +++ b/components/compat/Makefile.am @@ -11,6 +11,7 @@ compat_la_SOURCES = \ compat_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga \ -I${top_srcdir}/cib @@ -26,6 +27,7 @@ compat_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la \ ${top_builddir}/cib/libcib.la diff --git a/components/convenience/conveniencecomponent.cpp b/components/convenience/conveniencecomponent.cpp index 644427c50..02cb6306b 100644 --- a/components/convenience/conveniencecomponent.cpp +++ b/components/convenience/conveniencecomponent.cpp @@ -73,7 +73,8 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item) Dictionary::Iterator it; for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) { Variant desc = it->second; - ConfigItem::Ptr serviceItem; + + ConfigItemBuilder::Ptr builder = boost::make_shared(item->GetDebugInfo()); string name; @@ -82,60 +83,34 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item) namebuf << item->GetName() << "-" << string(desc); name = namebuf.str(); - serviceItem = boost::make_shared("service", name, item->GetDebugInfo()); - serviceItem->AddParent(desc); + builder->SetType("service"); + builder->SetName(name); - ExpressionList::Ptr exprl = boost::make_shared(); - - Expression localExpr("__local", OperatorSet, 1, item->GetDebugInfo()); - exprl->AddExpression(localExpr); - - Expression abstractExpr("__abstract", OperatorSet, 0, item->GetDebugInfo()); - exprl->AddExpression(abstractExpr); - - Expression typeExpr("__type", OperatorSet, "service", item->GetDebugInfo()); - exprl->AddExpression(typeExpr); - - Expression nameExpr("__name", OperatorSet, name, item->GetDebugInfo()); - exprl->AddExpression(nameExpr); - - Expression hostExpr("host_name", OperatorSet, item->GetName(), item->GetDebugInfo()); - exprl->AddExpression(hostExpr); - - Expression aliasExpr("alias", OperatorSet, string(desc), item->GetDebugInfo()); - exprl->AddExpression(aliasExpr); + builder->AddParent(desc); + builder->AddExpression("host_name", OperatorSet, item->GetName()); + builder->AddExpression("alias", OperatorSet, string(desc)); Dictionary::Ptr macros; - if (host->GetProperty("macros", ¯os)) { - Expression macrosExpr("macros", OperatorPlus, macros, item->GetDebugInfo()); - exprl->AddExpression(macrosExpr); - } + if (host->GetProperty("macros", ¯os)) + builder->AddExpression("macros", OperatorPlus, macros); long checkInterval; - if (host->GetProperty("check_interval", &checkInterval)) { - Expression checkExpr("check_interval", OperatorSet, checkInterval, item->GetDebugInfo()); - exprl->AddExpression(checkExpr); - } + if (host->GetProperty("check_interval", &checkInterval)) + builder->AddExpression("check_interval", OperatorSet, checkInterval); long retryInterval; - if (host->GetProperty("retry_interval", &retryInterval)) { - Expression retryExpr("retry_interval", OperatorSet, retryInterval, item->GetDebugInfo()); - exprl->AddExpression(retryExpr); - } + if (host->GetProperty("retry_interval", &retryInterval)) + builder->AddExpression("retry_interval", OperatorSet, retryInterval); Dictionary::Ptr sgroups; - if (host->GetProperty("servicegroups", &sgroups)) { - Expression sgroupsExpr("servicegroups", OperatorPlus, sgroups, item->GetDebugInfo()); - exprl->AddExpression(sgroupsExpr); - } + if (host->GetProperty("servicegroups", &sgroups)) + builder->AddExpression("servicegroups", OperatorPlus, sgroups); Dictionary::Ptr checkers; - if (host->GetProperty("checkers", &checkers)) { - Expression checkersExpr("checkers", OperatorSet, checkers, item->GetDebugInfo()); - exprl->AddExpression(checkersExpr); - } + if (host->GetProperty("checkers", &checkers)) + builder->AddExpression("checkers", OperatorSet, checkers); - serviceItem->SetExpressionList(exprl); + ConfigItem::Ptr serviceItem = builder->Compile(); ConfigObject::Ptr service = serviceItem->Commit(); newServices->SetProperty(name, serviceItem); diff --git a/components/delegation/Makefile.am b/components/delegation/Makefile.am index 5e9f41f8c..47c87284c 100644 --- a/components/delegation/Makefile.am +++ b/components/delegation/Makefile.am @@ -11,6 +11,7 @@ delegation_la_SOURCES = \ delegation_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga \ -I${top_srcdir}/cib @@ -26,6 +27,7 @@ delegation_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la \ ${top_builddir}/cib/libcib.la diff --git a/components/demo/Makefile.am b/components/demo/Makefile.am index 3fd22751f..14e40db9b 100644 --- a/components/demo/Makefile.am +++ b/components/demo/Makefile.am @@ -11,6 +11,7 @@ demo_la_SOURCES = \ demo_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga @@ -25,5 +26,6 @@ demo_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la diff --git a/components/discovery/Makefile.am b/components/discovery/Makefile.am index 9dd6ebd1e..7a41350a9 100644 --- a/components/discovery/Makefile.am +++ b/components/discovery/Makefile.am @@ -13,6 +13,7 @@ discovery_la_SOURCES = \ discovery_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga \ -I${top_srcdir}/cib @@ -28,6 +29,7 @@ discovery_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la \ ${top_builddir}/cib/libcib.la diff --git a/dyn/Makefile.am b/dyn/Makefile.am index 31ee61811..4a6377b79 100644 --- a/dyn/Makefile.am +++ b/dyn/Makefile.am @@ -16,6 +16,8 @@ libdyn_la_SOURCES = \ i2-dyn.h \ configitem.cpp \ configitem.h \ + configitembuilder.cpp \ + configitembuilder.h \ debuginfo.h \ expression.cpp \ expression.h \ diff --git a/dyn/config_parser.cc b/dyn/config_parser.cc index 55640951f..48a966fc2 100644 --- a/dyn/config_parser.cc +++ b/dyn/config_parser.cc @@ -223,7 +223,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err) int yyparse(ConfigCompiler *context); static stack m_ExpressionLists; -static ConfigItem::Ptr m_Object; +static ConfigItemBuilder::Ptr m_Item; static bool m_Abstract; static bool m_Local; static Dictionary::Ptr m_Array; @@ -543,10 +543,10 @@ static const yytype_int8 yyrhs[] = static const yytype_uint16 yyrline[] = { 0, 100, 100, 101, 104, 104, 107, 113, 118, 113, - 148, 149, 152, 156, 162, 163, 166, 173, 174, 178, - 177, 189, 190, 192, 193, 194, 197, 205, 219, 228, - 229, 230, 231, 232, 238, 243, 247, 253, 254, 255, - 262, 261, 273, 279, 280, 282, 284, 285 + 138, 139, 142, 146, 152, 153, 156, 163, 164, 168, + 167, 179, 180, 182, 183, 184, 187, 195, 209, 218, + 219, 220, 221, 222, 228, 233, 237, 243, 244, 245, + 252, 251, 263, 269, 270, 272, 274, 275 }; #endif @@ -1588,9 +1588,9 @@ yyreduce: /* Line 1806 of yacc.c */ #line 118 "config_parser.yy" { - m_Object = boost::make_shared((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc); - free((yyvsp[(4) - (5)].text)); - free((yyvsp[(5) - (5)].text)); + m_Item = boost::make_shared(yylloc); + m_Item->SetType((yyvsp[(4) - (5)].text)); + m_Item->SetName((yyvsp[(5) - (5)].text)); } break; @@ -1603,29 +1603,19 @@ yyreduce: delete (yyvsp[(8) - (8)].variant); ExpressionList::Ptr exprl = dynamic_pointer_cast(exprl_object); - Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc); - exprl->AddExpression(typeexpr); + m_Item->AddExpressionList(exprl); + m_Item->SetLocal(m_Local); + m_Item->SetAbstract(m_Abstract); - Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc); - exprl->AddExpression(nameexpr); - - Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc); - exprl->AddExpression(abstractexpr); - - Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc); - exprl->AddExpression(localexpr); - - m_Object->SetExpressionList(exprl); - - context->AddObject(m_Object); - m_Object.reset(); + context->AddObject(m_Item->Compile()); + m_Item.reset(); } break; case 12: /* Line 1806 of yacc.c */ -#line 153 "config_parser.yy" +#line 143 "config_parser.yy" { m_Abstract = true; } @@ -1634,7 +1624,7 @@ yyreduce: case 13: /* Line 1806 of yacc.c */ -#line 157 "config_parser.yy" +#line 147 "config_parser.yy" { m_Local = true; } @@ -1643,9 +1633,9 @@ yyreduce: case 16: /* Line 1806 of yacc.c */ -#line 167 "config_parser.yy" +#line 157 "config_parser.yy" { - m_Object->AddParent((yyvsp[(1) - (1)].text)); + m_Item->AddParent((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); } break; @@ -1653,7 +1643,7 @@ yyreduce: case 19: /* Line 1806 of yacc.c */ -#line 178 "config_parser.yy" +#line 168 "config_parser.yy" { m_ExpressionLists.push(boost::make_shared()); } @@ -1662,7 +1652,7 @@ yyreduce: case 20: /* Line 1806 of yacc.c */ -#line 183 "config_parser.yy" +#line 173 "config_parser.yy" { (yyval.variant) = new Variant(m_ExpressionLists.top()); m_ExpressionLists.pop(); @@ -1672,7 +1662,7 @@ yyreduce: case 26: /* Line 1806 of yacc.c */ -#line 198 "config_parser.yy" +#line 188 "config_parser.yy" { Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc); free((yyvsp[(1) - (3)].text)); @@ -1685,7 +1675,7 @@ yyreduce: case 27: /* Line 1806 of yacc.c */ -#line 206 "config_parser.yy" +#line 196 "config_parser.yy" { Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc); free((yyvsp[(3) - (6)].text)); @@ -1704,7 +1694,7 @@ yyreduce: case 28: /* Line 1806 of yacc.c */ -#line 220 "config_parser.yy" +#line 210 "config_parser.yy" { Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text), yylloc); free((yyvsp[(1) - (1)].text)); @@ -1716,7 +1706,7 @@ yyreduce: case 33: /* Line 1806 of yacc.c */ -#line 233 "config_parser.yy" +#line 223 "config_parser.yy" { (yyval.op) = (yyvsp[(1) - (1)].op); } @@ -1725,7 +1715,7 @@ yyreduce: case 34: /* Line 1806 of yacc.c */ -#line 239 "config_parser.yy" +#line 229 "config_parser.yy" { (yyval.variant) = new Variant((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -1735,7 +1725,7 @@ yyreduce: case 35: /* Line 1806 of yacc.c */ -#line 244 "config_parser.yy" +#line 234 "config_parser.yy" { (yyval.variant) = new Variant((yyvsp[(1) - (1)].num)); } @@ -1744,7 +1734,7 @@ yyreduce: case 36: /* Line 1806 of yacc.c */ -#line 248 "config_parser.yy" +#line 238 "config_parser.yy" { (yyval.variant) = new Variant(); } @@ -1753,7 +1743,7 @@ yyreduce: case 39: /* Line 1806 of yacc.c */ -#line 256 "config_parser.yy" +#line 246 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } @@ -1762,7 +1752,7 @@ yyreduce: case 40: /* Line 1806 of yacc.c */ -#line 262 "config_parser.yy" +#line 252 "config_parser.yy" { m_Array = boost::make_shared(); } @@ -1771,7 +1761,7 @@ yyreduce: case 41: /* Line 1806 of yacc.c */ -#line 267 "config_parser.yy" +#line 257 "config_parser.yy" { (yyval.variant) = new Variant(m_Array); m_Array.reset(); @@ -1781,7 +1771,7 @@ yyreduce: case 42: /* Line 1806 of yacc.c */ -#line 274 "config_parser.yy" +#line 264 "config_parser.yy" { m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant)); delete (yyvsp[(1) - (1)].variant); @@ -1791,7 +1781,7 @@ yyreduce: /* Line 1806 of yacc.c */ -#line 1795 "config_parser.cc" +#line 1785 "config_parser.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2029,6 +2019,6 @@ yyreturn: /* Line 2067 of yacc.c */ -#line 287 "config_parser.yy" +#line 277 "config_parser.yy" diff --git a/dyn/config_parser.yy b/dyn/config_parser.yy index 4b1934169..12a50847d 100644 --- a/dyn/config_parser.yy +++ b/dyn/config_parser.yy @@ -82,7 +82,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err) int yyparse(ConfigCompiler *context); static stack m_ExpressionLists; -static ConfigItem::Ptr m_Object; +static ConfigItemBuilder::Ptr m_Item; static bool m_Abstract; static bool m_Local; static Dictionary::Ptr m_Array; @@ -116,9 +116,9 @@ object: } attributes T_OBJECT T_IDENTIFIER T_STRING { - m_Object = boost::make_shared($4, $5, yylloc); - free($4); - free($5); + m_Item = boost::make_shared(yylloc); + m_Item->SetType($4); + m_Item->SetName($5); } inherits_specifier expressionlist { @@ -126,22 +126,12 @@ inherits_specifier expressionlist delete $8; ExpressionList::Ptr exprl = dynamic_pointer_cast(exprl_object); - Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc); - exprl->AddExpression(typeexpr); + m_Item->AddExpressionList(exprl); + m_Item->SetLocal(m_Local); + m_Item->SetAbstract(m_Abstract); - Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc); - exprl->AddExpression(nameexpr); - - Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc); - exprl->AddExpression(abstractexpr); - - Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc); - exprl->AddExpression(localexpr); - - m_Object->SetExpressionList(exprl); - - context->AddObject(m_Object); - m_Object.reset(); + context->AddObject(m_Item->Compile()); + m_Item.reset(); } ; @@ -165,7 +155,7 @@ inherits_list: inherits_item inherits_item: T_STRING { - m_Object->AddParent($1); + m_Item->AddParent($1); free($1); } ; diff --git a/dyn/configitem.cpp b/dyn/configitem.cpp index 37e693ea0..faea417ed 100644 --- a/dyn/configitem.cpp +++ b/dyn/configitem.cpp @@ -21,8 +21,11 @@ using namespace icinga; -ConfigItem::ConfigItem(const string& type, const string& name, const DebugInfo& debuginfo) - : m_Type(type), m_Name(name), m_DebugInfo(debuginfo) +ConfigItem::ConfigItem(const string& type, const string& name, + const ExpressionList::Ptr& exprl, const vector& parents, + const DebugInfo& debuginfo) + : m_Type(type), m_Name(name), m_ExpressionList(exprl), + m_Parents(parents), m_DebugInfo(debuginfo) { } @@ -46,21 +49,11 @@ ExpressionList::Ptr ConfigItem::GetExpressionList(void) const return m_ExpressionList; } -void ConfigItem::SetExpressionList(const ExpressionList::Ptr& exprl) -{ - m_ExpressionList = exprl; -} - vector ConfigItem::GetParents(void) const { return m_Parents; } -void ConfigItem::AddParent(const string& parent) -{ - m_Parents.push_back(parent); -} - void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const { vector::const_iterator it; diff --git a/dyn/configitem.h b/dyn/configitem.h index fd93590b8..429367885 100644 --- a/dyn/configitem.h +++ b/dyn/configitem.h @@ -32,16 +32,16 @@ public: typedef ObjectMap, ConfigItem::Ptr> TNMap; - ConfigItem(const string& type, const string& name, const DebugInfo& debuginfo); + ConfigItem(const string& type, const string& name, + const ExpressionList::Ptr& exprl, const vector& parents, + const DebugInfo& debuginfo); string GetType(void) const; string GetName(void) const; vector GetParents(void) const; - void AddParent(const string& parent); ExpressionList::Ptr GetExpressionList(void) const; - void SetExpressionList(const ExpressionList::Ptr& exprl); void CalculateProperties(Dictionary::Ptr dictionary) const; @@ -59,9 +59,10 @@ public: private: string m_Type; string m_Name; - DebugInfo m_DebugInfo; - vector m_Parents; + ExpressionList::Ptr m_ExpressionList; + vector m_Parents; + DebugInfo m_DebugInfo; ConfigObject::WeakPtr m_ConfigObject; diff --git a/dyn/configitembuilder.cpp b/dyn/configitembuilder.cpp new file mode 100644 index 000000000..2c5d7446f --- /dev/null +++ b/dyn/configitembuilder.cpp @@ -0,0 +1,86 @@ +#include "i2-dyn.h" + +using namespace icinga; + +ConfigItemBuilder::ConfigItemBuilder(void) + : m_Local(false), m_Abstract(false), + m_ExpressionList(boost::make_shared()) +{ + m_DebugInfo.FirstLine = 0; + m_DebugInfo.FirstColumn = 0; + m_DebugInfo.LastLine = 0; + m_DebugInfo.LastColumn = 0; +} + +ConfigItemBuilder::ConfigItemBuilder(const DebugInfo& debugInfo) + : m_Local(false), m_Abstract(false), + m_ExpressionList(boost::make_shared()) +{ + m_DebugInfo = debugInfo; +} + +void ConfigItemBuilder::SetType(const string& type) +{ + m_Type = type; +} + +void ConfigItemBuilder::SetName(const string& name) +{ + m_Name = name; +} + +void ConfigItemBuilder::SetLocal(bool local) +{ + m_Local = local; +} + +void ConfigItemBuilder::SetAbstract(bool abstract) +{ + m_Abstract = abstract; +} + +void ConfigItemBuilder::AddParent(const string& parent) +{ + m_Parents.push_back(parent); +} + +void ConfigItemBuilder::AddExpression(const Expression& expr) +{ + m_ExpressionList->AddExpression(expr); +} + +void ConfigItemBuilder::AddExpression(const string& key, ExpressionOperator op, const Variant& value) +{ + Expression expr(key, op, value, m_DebugInfo); + AddExpression(expr); +} + +void ConfigItemBuilder::AddExpressionList(const ExpressionList::Ptr& exprl) +{ + AddExpression("", OperatorExecute, exprl); +} + +ConfigItem::Ptr ConfigItemBuilder::Compile(void) +{ + assert(!m_Type.empty()); + assert(!m_Name.empty()); + + ExpressionList::Ptr exprl = boost::make_shared(); + + Expression execExpr("", OperatorExecute, m_ExpressionList, m_DebugInfo); + exprl->AddExpression(execExpr); + + Expression typeExpr("__type", OperatorSet, m_Type, m_DebugInfo); + exprl->AddExpression(typeExpr); + + Expression nameExpr("__name", OperatorSet, m_Name, m_DebugInfo); + exprl->AddExpression(nameExpr); + + Expression localExpr("__local", OperatorSet, m_Local, m_DebugInfo); + exprl->AddExpression(localExpr); + + Expression abstractExpr("__abstract", OperatorSet, m_Abstract, m_DebugInfo); + exprl->AddExpression(abstractExpr); + + return boost::make_shared(m_Type, m_Name, exprl, m_Parents, m_DebugInfo); +} diff --git a/dyn/configitembuilder.h b/dyn/configitembuilder.h new file mode 100644 index 000000000..1a2b09e75 --- /dev/null +++ b/dyn/configitembuilder.h @@ -0,0 +1,41 @@ +#ifndef CONFIGITEMBUILDER_H +#define CONFIGITEMBUILDER_H + +namespace icinga +{ + +class ConfigItemBuilder : public Object +{ +public: + typedef shared_ptr Ptr; + typedef weak_ptr WeakPtr; + + ConfigItemBuilder(void); + ConfigItemBuilder(const DebugInfo& debugInfo); + + void SetType(const string& type); + void SetName(const string& name); + void SetLocal(bool local); + void SetAbstract(bool abstract); + + void AddParent(const string& parent); + + void AddExpression(const Expression& expr); + void AddExpression(const string& key, ExpressionOperator op, const Variant& value); + void AddExpressionList(const ExpressionList::Ptr& exprl); + + ConfigItem::Ptr Compile(void); + +private: + string m_Type; + string m_Name; + bool m_Local; + bool m_Abstract; + vector m_Parents; + ExpressionList::Ptr m_ExpressionList; + DebugInfo m_DebugInfo; +}; + +} + +#endif /* CONFIGITEMBUILDER */ diff --git a/dyn/debuginfo.h b/dyn/debuginfo.h index 83550761d..a49661184 100644 --- a/dyn/debuginfo.h +++ b/dyn/debuginfo.h @@ -39,14 +39,14 @@ struct DebugInfo union { - int LastColumn; - int last_column; + int LastLine; + int last_line; }; union { - int LastLine; - int last_line; + int LastColumn; + int last_column; }; }; diff --git a/dyn/expression.cpp b/dyn/expression.cpp index 0096aa4e2..d6740bd77 100644 --- a/dyn/expression.cpp +++ b/dyn/expression.cpp @@ -42,6 +42,14 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const Dictionary::Ptr dict; switch (m_Operator) { + case OperatorExecute: + if (!valueExprl) + throw invalid_argument("Operand for OperatorExecute must be an ExpressionList."); + + valueExprl->Execute(dictionary); + + return; + case OperatorSet: if (valueExprl) { dict = boost::make_shared(); @@ -85,9 +93,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const break; default: - assert(!"Not yet implemented."); - - break; + throw runtime_error("Not yet implemented."); } dictionary->SetProperty(m_Key, newValue); diff --git a/dyn/expression.h b/dyn/expression.h index 4b70a65fb..5ef8b5c32 100644 --- a/dyn/expression.h +++ b/dyn/expression.h @@ -25,6 +25,7 @@ namespace icinga enum ExpressionOperator { + OperatorExecute, OperatorSet, OperatorPlus, OperatorMinus, diff --git a/dyn/i2-dyn.h b/dyn/i2-dyn.h index 29a201d36..b504ff841 100644 --- a/dyn/i2-dyn.h +++ b/dyn/i2-dyn.h @@ -48,6 +48,7 @@ using std::endl; #include "expression.h" #include "expressionlist.h" #include "configitem.h" +#include "configitembuilder.h" #include "configcompiler.h" #endif /* I2DYN_H */ diff --git a/icinga-app/Makefile.am b/icinga-app/Makefile.am index 39ea3a41b..9ee0e406e 100644 --- a/icinga-app/Makefile.am +++ b/icinga-app/Makefile.am @@ -11,6 +11,7 @@ icinga_CPPFLAGS = \ -DI2_ICINGALAUNCHER_BUILD \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/icinga \ -I${top_srcdir} @@ -22,6 +23,7 @@ icinga_LDADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ ${top_builddir}/icinga/libicinga.la \ -dlopen ${top_builddir}/components/checker/checker.la \ -dlopen ${top_builddir}/components/cibsync/cibsync.la \ diff --git a/icinga/Makefile.am b/icinga/Makefile.am index 52405e656..744f80825 100644 --- a/icinga/Makefile.am +++ b/icinga/Makefile.am @@ -21,6 +21,7 @@ libicinga_la_CPPFLAGS = \ -DI2_ICINGA_BUILD \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ -I${top_srcdir}/jsonrpc \ -I${top_srcdir}/cJSON \ -I${top_srcdir} @@ -33,5 +34,6 @@ libicinga_la_LDFLAGS = \ libicinga_la_LIBADD = \ $(BOOST_THREAD_LIB) \ - ${top_builddir}/jsonrpc/libjsonrpc.la \ - ${top_builddir}/base/libbase.la + ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la \ + ${top_builddir}/jsonrpc/libjsonrpc.la diff --git a/icinga/i2-icinga.h b/icinga/i2-icinga.h index a9284165b..70f7aef04 100644 --- a/icinga/i2-icinga.h +++ b/icinga/i2-icinga.h @@ -28,6 +28,8 @@ */ #include +#include +#include #include #include diff --git a/icinga/icingaapplication.cpp b/icinga/icingaapplication.cpp index 562ea9529..52af54afb 100644 --- a/icinga/icingaapplication.cpp +++ b/icinga/icingaapplication.cpp @@ -62,15 +62,19 @@ int IcingaApplication::Main(const vector& args) componentObjects->Start(); /* load convenience config component */ - ConfigObject::Ptr convenienceComponentConfig = boost::make_shared("component", "convenience"); + ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared(); + convenienceComponentConfig->SetType("component"); + convenienceComponentConfig->SetName("convenience"); convenienceComponentConfig->SetLocal(true); - convenienceComponentConfig->Commit(); + convenienceComponentConfig->Compile()->Commit(); /* load config file */ - ConfigObject::Ptr fileComponentConfig = boost::make_shared("component", "configfile"); + ConfigItemBuilder::Ptr fileComponentConfig = boost::make_shared(); + fileComponentConfig->SetType("component"); + fileComponentConfig->SetName("configfile"); fileComponentConfig->SetLocal(true); - fileComponentConfig->SetProperty("configFilename", args[1]); - fileComponentConfig->Commit(); + fileComponentConfig->AddExpression("configFilename", OperatorSet, args[1]); + fileComponentConfig->Compile()->Commit(); ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga");