Implemented ConfigItemBuilder class.

This commit is contained in:
Gunnar Beutner 2012-07-06 14:33:10 +02:00
parent e0bf25e907
commit 37cf22aaf0
25 changed files with 253 additions and 139 deletions

View File

@ -32,6 +32,7 @@ libcib_la_CPPFLAGS = \
-DI2_CIB_BUILD \ -DI2_CIB_BUILD \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga \ -I${top_srcdir}/icinga \
-I${top_srcdir}/third-party/popen-noshell -I${top_srcdir}/third-party/popen-noshell
@ -46,6 +47,7 @@ libcib_la_LIBADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/icinga/libicinga.la \ ${top_builddir}/icinga/libicinga.la \
${top_builddir}/third-party/popen-noshell/libpopen_noshell.la ${top_builddir}/third-party/popen-noshell/libpopen_noshell.la

View File

@ -14,9 +14,12 @@ void CIB::RequireInformation(InformationType types)
Component::Ptr component = app->GetComponent("cibsync"); Component::Ptr component = app->GetComponent("cibsync");
if (!component) { if (!component) {
ConfigObject::Ptr cibsyncComponentConfig = boost::make_shared<ConfigObject>("component", "cibsync"); ConfigItemBuilder::Ptr cb = boost::make_shared<ConfigItemBuilder>();
cibsyncComponentConfig->SetLocal(true); cb->SetType("component");
cibsyncComponentConfig->Commit(); cb->SetName("cibsync");
cb->SetLocal(true);
ConfigItem::Ptr ci = cb->Compile();
ci->Commit();
} }
} }

View File

@ -8,6 +8,7 @@
* updates from all the other Icinga components. * updates from all the other Icinga components.
*/ */
#include <i2-dyn.h>
#include <i2-icinga.h> #include <i2-icinga.h>
#ifdef I2_CIB_BUILD #ifdef I2_CIB_BUILD

View File

@ -11,6 +11,7 @@ checker_la_SOURCES = \
checker_la_CPPFLAGS = \ checker_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga \ -I${top_srcdir}/icinga \
-I${top_srcdir}/cib -I${top_srcdir}/cib
@ -26,6 +27,7 @@ checker_la_LIBADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/icinga/libicinga.la \ ${top_builddir}/icinga/libicinga.la \
${top_builddir}/cib/libcib.la ${top_builddir}/cib/libcib.la

View File

@ -11,6 +11,7 @@ cibsync_la_SOURCES = \
cibsync_la_CPPFLAGS = \ cibsync_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga \ -I${top_srcdir}/icinga \
-I${top_srcdir}/cib -I${top_srcdir}/cib
@ -26,6 +27,7 @@ cibsync_la_LIBADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/icinga/libicinga.la \ ${top_builddir}/icinga/libicinga.la \
${top_builddir}/cib/libcib.la ${top_builddir}/cib/libcib.la

View File

@ -11,6 +11,7 @@ compat_la_SOURCES = \
compat_la_CPPFLAGS = \ compat_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga \ -I${top_srcdir}/icinga \
-I${top_srcdir}/cib -I${top_srcdir}/cib
@ -26,6 +27,7 @@ compat_la_LIBADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/icinga/libicinga.la \ ${top_builddir}/icinga/libicinga.la \
${top_builddir}/cib/libcib.la ${top_builddir}/cib/libcib.la

View File

@ -73,7 +73,8 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
Dictionary::Iterator it; Dictionary::Iterator it;
for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) { for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) {
Variant desc = it->second; Variant desc = it->second;
ConfigItem::Ptr serviceItem;
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(item->GetDebugInfo());
string name; string name;
@ -82,60 +83,34 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
namebuf << item->GetName() << "-" << string(desc); namebuf << item->GetName() << "-" << string(desc);
name = namebuf.str(); name = namebuf.str();
serviceItem = boost::make_shared<ConfigItem>("service", name, item->GetDebugInfo()); builder->SetType("service");
serviceItem->AddParent(desc); builder->SetName(name);
ExpressionList::Ptr exprl = boost::make_shared<ExpressionList>(); builder->AddParent(desc);
builder->AddExpression("host_name", OperatorSet, item->GetName());
Expression localExpr("__local", OperatorSet, 1, item->GetDebugInfo()); builder->AddExpression("alias", OperatorSet, string(desc));
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);
Dictionary::Ptr macros; Dictionary::Ptr macros;
if (host->GetProperty("macros", &macros)) { if (host->GetProperty("macros", &macros))
Expression macrosExpr("macros", OperatorPlus, macros, item->GetDebugInfo()); builder->AddExpression("macros", OperatorPlus, macros);
exprl->AddExpression(macrosExpr);
}
long checkInterval; long checkInterval;
if (host->GetProperty("check_interval", &checkInterval)) { if (host->GetProperty("check_interval", &checkInterval))
Expression checkExpr("check_interval", OperatorSet, checkInterval, item->GetDebugInfo()); builder->AddExpression("check_interval", OperatorSet, checkInterval);
exprl->AddExpression(checkExpr);
}
long retryInterval; long retryInterval;
if (host->GetProperty("retry_interval", &retryInterval)) { if (host->GetProperty("retry_interval", &retryInterval))
Expression retryExpr("retry_interval", OperatorSet, retryInterval, item->GetDebugInfo()); builder->AddExpression("retry_interval", OperatorSet, retryInterval);
exprl->AddExpression(retryExpr);
}
Dictionary::Ptr sgroups; Dictionary::Ptr sgroups;
if (host->GetProperty("servicegroups", &sgroups)) { if (host->GetProperty("servicegroups", &sgroups))
Expression sgroupsExpr("servicegroups", OperatorPlus, sgroups, item->GetDebugInfo()); builder->AddExpression("servicegroups", OperatorPlus, sgroups);
exprl->AddExpression(sgroupsExpr);
}
Dictionary::Ptr checkers; Dictionary::Ptr checkers;
if (host->GetProperty("checkers", &checkers)) { if (host->GetProperty("checkers", &checkers))
Expression checkersExpr("checkers", OperatorSet, checkers, item->GetDebugInfo()); builder->AddExpression("checkers", OperatorSet, checkers);
exprl->AddExpression(checkersExpr);
}
serviceItem->SetExpressionList(exprl); ConfigItem::Ptr serviceItem = builder->Compile();
ConfigObject::Ptr service = serviceItem->Commit(); ConfigObject::Ptr service = serviceItem->Commit();
newServices->SetProperty(name, serviceItem); newServices->SetProperty(name, serviceItem);

View File

@ -11,6 +11,7 @@ delegation_la_SOURCES = \
delegation_la_CPPFLAGS = \ delegation_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga \ -I${top_srcdir}/icinga \
-I${top_srcdir}/cib -I${top_srcdir}/cib
@ -26,6 +27,7 @@ delegation_la_LIBADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/icinga/libicinga.la \ ${top_builddir}/icinga/libicinga.la \
${top_builddir}/cib/libcib.la ${top_builddir}/cib/libcib.la

View File

@ -11,6 +11,7 @@ demo_la_SOURCES = \
demo_la_CPPFLAGS = \ demo_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga -I${top_srcdir}/icinga
@ -25,5 +26,6 @@ demo_la_LIBADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/icinga/libicinga.la ${top_builddir}/icinga/libicinga.la

View File

@ -13,6 +13,7 @@ discovery_la_SOURCES = \
discovery_la_CPPFLAGS = \ discovery_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga \ -I${top_srcdir}/icinga \
-I${top_srcdir}/cib -I${top_srcdir}/cib
@ -28,6 +29,7 @@ discovery_la_LIBADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/icinga/libicinga.la \ ${top_builddir}/icinga/libicinga.la \
${top_builddir}/cib/libcib.la ${top_builddir}/cib/libcib.la

View File

@ -16,6 +16,8 @@ libdyn_la_SOURCES = \
i2-dyn.h \ i2-dyn.h \
configitem.cpp \ configitem.cpp \
configitem.h \ configitem.h \
configitembuilder.cpp \
configitembuilder.h \
debuginfo.h \ debuginfo.h \
expression.cpp \ expression.cpp \
expression.h \ expression.h \

View File

@ -223,7 +223,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
int yyparse(ConfigCompiler *context); int yyparse(ConfigCompiler *context);
static stack<ExpressionList::Ptr> m_ExpressionLists; static stack<ExpressionList::Ptr> m_ExpressionLists;
static ConfigItem::Ptr m_Object; static ConfigItemBuilder::Ptr m_Item;
static bool m_Abstract; static bool m_Abstract;
static bool m_Local; static bool m_Local;
static Dictionary::Ptr m_Array; static Dictionary::Ptr m_Array;
@ -543,10 +543,10 @@ static const yytype_int8 yyrhs[] =
static const yytype_uint16 yyrline[] = static const yytype_uint16 yyrline[] =
{ {
0, 100, 100, 101, 104, 104, 107, 113, 118, 113, 0, 100, 100, 101, 104, 104, 107, 113, 118, 113,
148, 149, 152, 156, 162, 163, 166, 173, 174, 178, 138, 139, 142, 146, 152, 153, 156, 163, 164, 168,
177, 189, 190, 192, 193, 194, 197, 205, 219, 228, 167, 179, 180, 182, 183, 184, 187, 195, 209, 218,
229, 230, 231, 232, 238, 243, 247, 253, 254, 255, 219, 220, 221, 222, 228, 233, 237, 243, 244, 245,
262, 261, 273, 279, 280, 282, 284, 285 252, 251, 263, 269, 270, 272, 274, 275
}; };
#endif #endif
@ -1588,9 +1588,9 @@ yyreduce:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 118 "config_parser.yy" #line 118 "config_parser.yy"
{ {
m_Object = boost::make_shared<ConfigItem>((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc); m_Item = boost::make_shared<ConfigItemBuilder>(yylloc);
free((yyvsp[(4) - (5)].text)); m_Item->SetType((yyvsp[(4) - (5)].text));
free((yyvsp[(5) - (5)].text)); m_Item->SetName((yyvsp[(5) - (5)].text));
} }
break; break;
@ -1603,29 +1603,19 @@ yyreduce:
delete (yyvsp[(8) - (8)].variant); delete (yyvsp[(8) - (8)].variant);
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object); ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc); m_Item->AddExpressionList(exprl);
exprl->AddExpression(typeexpr); m_Item->SetLocal(m_Local);
m_Item->SetAbstract(m_Abstract);
Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc); context->AddObject(m_Item->Compile());
exprl->AddExpression(nameexpr); m_Item.reset();
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();
} }
break; break;
case 12: case 12:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 153 "config_parser.yy" #line 143 "config_parser.yy"
{ {
m_Abstract = true; m_Abstract = true;
} }
@ -1634,7 +1624,7 @@ yyreduce:
case 13: case 13:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 157 "config_parser.yy" #line 147 "config_parser.yy"
{ {
m_Local = true; m_Local = true;
} }
@ -1643,9 +1633,9 @@ yyreduce:
case 16: case 16:
/* Line 1806 of yacc.c */ /* 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)); free((yyvsp[(1) - (1)].text));
} }
break; break;
@ -1653,7 +1643,7 @@ yyreduce:
case 19: case 19:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 178 "config_parser.yy" #line 168 "config_parser.yy"
{ {
m_ExpressionLists.push(boost::make_shared<ExpressionList>()); m_ExpressionLists.push(boost::make_shared<ExpressionList>());
} }
@ -1662,7 +1652,7 @@ yyreduce:
case 20: case 20:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 183 "config_parser.yy" #line 173 "config_parser.yy"
{ {
(yyval.variant) = new Variant(m_ExpressionLists.top()); (yyval.variant) = new Variant(m_ExpressionLists.top());
m_ExpressionLists.pop(); m_ExpressionLists.pop();
@ -1672,7 +1662,7 @@ yyreduce:
case 26: case 26:
/* Line 1806 of yacc.c */ /* 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); Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc);
free((yyvsp[(1) - (3)].text)); free((yyvsp[(1) - (3)].text));
@ -1685,7 +1675,7 @@ yyreduce:
case 27: case 27:
/* Line 1806 of yacc.c */ /* 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); Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc);
free((yyvsp[(3) - (6)].text)); free((yyvsp[(3) - (6)].text));
@ -1704,7 +1694,7 @@ yyreduce:
case 28: case 28:
/* Line 1806 of yacc.c */ /* 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); Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text), yylloc);
free((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text));
@ -1716,7 +1706,7 @@ yyreduce:
case 33: case 33:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 233 "config_parser.yy" #line 223 "config_parser.yy"
{ {
(yyval.op) = (yyvsp[(1) - (1)].op); (yyval.op) = (yyvsp[(1) - (1)].op);
} }
@ -1725,7 +1715,7 @@ yyreduce:
case 34: case 34:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 239 "config_parser.yy" #line 229 "config_parser.yy"
{ {
(yyval.variant) = new Variant((yyvsp[(1) - (1)].text)); (yyval.variant) = new Variant((yyvsp[(1) - (1)].text));
free((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text));
@ -1735,7 +1725,7 @@ yyreduce:
case 35: case 35:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 244 "config_parser.yy" #line 234 "config_parser.yy"
{ {
(yyval.variant) = new Variant((yyvsp[(1) - (1)].num)); (yyval.variant) = new Variant((yyvsp[(1) - (1)].num));
} }
@ -1744,7 +1734,7 @@ yyreduce:
case 36: case 36:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 248 "config_parser.yy" #line 238 "config_parser.yy"
{ {
(yyval.variant) = new Variant(); (yyval.variant) = new Variant();
} }
@ -1753,7 +1743,7 @@ yyreduce:
case 39: case 39:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 256 "config_parser.yy" #line 246 "config_parser.yy"
{ {
(yyval.variant) = (yyvsp[(1) - (1)].variant); (yyval.variant) = (yyvsp[(1) - (1)].variant);
} }
@ -1762,7 +1752,7 @@ yyreduce:
case 40: case 40:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 262 "config_parser.yy" #line 252 "config_parser.yy"
{ {
m_Array = boost::make_shared<Dictionary>(); m_Array = boost::make_shared<Dictionary>();
} }
@ -1771,7 +1761,7 @@ yyreduce:
case 41: case 41:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 267 "config_parser.yy" #line 257 "config_parser.yy"
{ {
(yyval.variant) = new Variant(m_Array); (yyval.variant) = new Variant(m_Array);
m_Array.reset(); m_Array.reset();
@ -1781,7 +1771,7 @@ yyreduce:
case 42: case 42:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 274 "config_parser.yy" #line 264 "config_parser.yy"
{ {
m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant)); m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant));
delete (yyvsp[(1) - (1)].variant); delete (yyvsp[(1) - (1)].variant);
@ -1791,7 +1781,7 @@ yyreduce:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 1795 "config_parser.cc" #line 1785 "config_parser.cc"
default: break; default: break;
} }
/* User semantic actions sometimes alter yychar, and that requires /* User semantic actions sometimes alter yychar, and that requires
@ -2029,6 +2019,6 @@ yyreturn:
/* Line 2067 of yacc.c */ /* Line 2067 of yacc.c */
#line 287 "config_parser.yy" #line 277 "config_parser.yy"

View File

@ -82,7 +82,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
int yyparse(ConfigCompiler *context); int yyparse(ConfigCompiler *context);
static stack<ExpressionList::Ptr> m_ExpressionLists; static stack<ExpressionList::Ptr> m_ExpressionLists;
static ConfigItem::Ptr m_Object; static ConfigItemBuilder::Ptr m_Item;
static bool m_Abstract; static bool m_Abstract;
static bool m_Local; static bool m_Local;
static Dictionary::Ptr m_Array; static Dictionary::Ptr m_Array;
@ -116,9 +116,9 @@ object:
} }
attributes T_OBJECT T_IDENTIFIER T_STRING attributes T_OBJECT T_IDENTIFIER T_STRING
{ {
m_Object = boost::make_shared<ConfigItem>($4, $5, yylloc); m_Item = boost::make_shared<ConfigItemBuilder>(yylloc);
free($4); m_Item->SetType($4);
free($5); m_Item->SetName($5);
} }
inherits_specifier expressionlist inherits_specifier expressionlist
{ {
@ -126,22 +126,12 @@ inherits_specifier expressionlist
delete $8; delete $8;
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object); ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc); m_Item->AddExpressionList(exprl);
exprl->AddExpression(typeexpr); m_Item->SetLocal(m_Local);
m_Item->SetAbstract(m_Abstract);
Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc); context->AddObject(m_Item->Compile());
exprl->AddExpression(nameexpr); m_Item.reset();
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();
} }
; ;
@ -165,7 +155,7 @@ inherits_list: inherits_item
inherits_item: T_STRING inherits_item: T_STRING
{ {
m_Object->AddParent($1); m_Item->AddParent($1);
free($1); free($1);
} }
; ;

View File

@ -21,8 +21,11 @@
using namespace icinga; using namespace icinga;
ConfigItem::ConfigItem(const string& type, const string& name, const DebugInfo& debuginfo) ConfigItem::ConfigItem(const string& type, const string& name,
: m_Type(type), m_Name(name), m_DebugInfo(debuginfo) const ExpressionList::Ptr& exprl, const vector<string>& 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; return m_ExpressionList;
} }
void ConfigItem::SetExpressionList(const ExpressionList::Ptr& exprl)
{
m_ExpressionList = exprl;
}
vector<string> ConfigItem::GetParents(void) const vector<string> ConfigItem::GetParents(void) const
{ {
return m_Parents; return m_Parents;
} }
void ConfigItem::AddParent(const string& parent)
{
m_Parents.push_back(parent);
}
void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const
{ {
vector<string>::const_iterator it; vector<string>::const_iterator it;

View File

@ -32,16 +32,16 @@ public:
typedef ObjectMap<pair<string, string>, ConfigItem::Ptr> TNMap; typedef ObjectMap<pair<string, string>, 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<string>& parents,
const DebugInfo& debuginfo);
string GetType(void) const; string GetType(void) const;
string GetName(void) const; string GetName(void) const;
vector<string> GetParents(void) const; vector<string> GetParents(void) const;
void AddParent(const string& parent);
ExpressionList::Ptr GetExpressionList(void) const; ExpressionList::Ptr GetExpressionList(void) const;
void SetExpressionList(const ExpressionList::Ptr& exprl);
void CalculateProperties(Dictionary::Ptr dictionary) const; void CalculateProperties(Dictionary::Ptr dictionary) const;
@ -59,9 +59,10 @@ public:
private: private:
string m_Type; string m_Type;
string m_Name; string m_Name;
DebugInfo m_DebugInfo;
vector<string> m_Parents;
ExpressionList::Ptr m_ExpressionList; ExpressionList::Ptr m_ExpressionList;
vector<string> m_Parents;
DebugInfo m_DebugInfo;
ConfigObject::WeakPtr m_ConfigObject; ConfigObject::WeakPtr m_ConfigObject;

86
dyn/configitembuilder.cpp Normal file
View File

@ -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<ExpressionList>())
{
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<ExpressionList>())
{
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<ExpressionList>();
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<ConfigItem>(m_Type, m_Name, exprl, m_Parents, m_DebugInfo);
}

41
dyn/configitembuilder.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef CONFIGITEMBUILDER_H
#define CONFIGITEMBUILDER_H
namespace icinga
{
class ConfigItemBuilder : public Object
{
public:
typedef shared_ptr<ConfigItemBuilder> Ptr;
typedef weak_ptr<ConfigItemBuilder> 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<string> m_Parents;
ExpressionList::Ptr m_ExpressionList;
DebugInfo m_DebugInfo;
};
}
#endif /* CONFIGITEMBUILDER */

View File

@ -39,14 +39,14 @@ struct DebugInfo
union union
{ {
int LastColumn; int LastLine;
int last_column; int last_line;
}; };
union union
{ {
int LastLine; int LastColumn;
int last_line; int last_column;
}; };
}; };

View File

@ -42,6 +42,14 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
Dictionary::Ptr dict; Dictionary::Ptr dict;
switch (m_Operator) { switch (m_Operator) {
case OperatorExecute:
if (!valueExprl)
throw invalid_argument("Operand for OperatorExecute must be an ExpressionList.");
valueExprl->Execute(dictionary);
return;
case OperatorSet: case OperatorSet:
if (valueExprl) { if (valueExprl) {
dict = boost::make_shared<Dictionary>(); dict = boost::make_shared<Dictionary>();
@ -85,9 +93,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
break; break;
default: default:
assert(!"Not yet implemented."); throw runtime_error("Not yet implemented.");
break;
} }
dictionary->SetProperty(m_Key, newValue); dictionary->SetProperty(m_Key, newValue);

View File

@ -25,6 +25,7 @@ namespace icinga
enum ExpressionOperator enum ExpressionOperator
{ {
OperatorExecute,
OperatorSet, OperatorSet,
OperatorPlus, OperatorPlus,
OperatorMinus, OperatorMinus,

View File

@ -48,6 +48,7 @@ using std::endl;
#include "expression.h" #include "expression.h"
#include "expressionlist.h" #include "expressionlist.h"
#include "configitem.h" #include "configitem.h"
#include "configitembuilder.h"
#include "configcompiler.h" #include "configcompiler.h"
#endif /* I2DYN_H */ #endif /* I2DYN_H */

View File

@ -11,6 +11,7 @@ icinga_CPPFLAGS = \
-DI2_ICINGALAUNCHER_BUILD \ -DI2_ICINGALAUNCHER_BUILD \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/icinga \ -I${top_srcdir}/icinga \
-I${top_srcdir} -I${top_srcdir}
@ -22,6 +23,7 @@ icinga_LDADD = \
$(BOOST_SIGNALS_LIB) \ $(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \ $(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \ ${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la \
${top_builddir}/icinga/libicinga.la \ ${top_builddir}/icinga/libicinga.la \
-dlopen ${top_builddir}/components/checker/checker.la \ -dlopen ${top_builddir}/components/checker/checker.la \
-dlopen ${top_builddir}/components/cibsync/cibsync.la \ -dlopen ${top_builddir}/components/cibsync/cibsync.la \

View File

@ -21,6 +21,7 @@ libicinga_la_CPPFLAGS = \
-DI2_ICINGA_BUILD \ -DI2_ICINGA_BUILD \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \ -I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}/jsonrpc \ -I${top_srcdir}/jsonrpc \
-I${top_srcdir}/cJSON \ -I${top_srcdir}/cJSON \
-I${top_srcdir} -I${top_srcdir}
@ -33,5 +34,6 @@ libicinga_la_LDFLAGS = \
libicinga_la_LIBADD = \ libicinga_la_LIBADD = \
$(BOOST_THREAD_LIB) \ $(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

View File

@ -28,6 +28,8 @@
*/ */
#include <i2-base.h> #include <i2-base.h>
#include <i2-dyn.h>
#include <i2-dyn.h>
#include <i2-jsonrpc.h> #include <i2-jsonrpc.h>
#include <set> #include <set>

View File

@ -62,15 +62,19 @@ int IcingaApplication::Main(const vector<string>& args)
componentObjects->Start(); componentObjects->Start();
/* load convenience config component */ /* load convenience config component */
ConfigObject::Ptr convenienceComponentConfig = boost::make_shared<ConfigObject>("component", "convenience"); ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared<ConfigItemBuilder>();
convenienceComponentConfig->SetType("component");
convenienceComponentConfig->SetName("convenience");
convenienceComponentConfig->SetLocal(true); convenienceComponentConfig->SetLocal(true);
convenienceComponentConfig->Commit(); convenienceComponentConfig->Compile()->Commit();
/* load config file */ /* load config file */
ConfigObject::Ptr fileComponentConfig = boost::make_shared<ConfigObject>("component", "configfile"); ConfigItemBuilder::Ptr fileComponentConfig = boost::make_shared<ConfigItemBuilder>();
fileComponentConfig->SetType("component");
fileComponentConfig->SetName("configfile");
fileComponentConfig->SetLocal(true); fileComponentConfig->SetLocal(true);
fileComponentConfig->SetProperty("configFilename", args[1]); fileComponentConfig->AddExpression("configFilename", OperatorSet, args[1]);
fileComponentConfig->Commit(); fileComponentConfig->Compile()->Commit();
ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga"); ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga");