]> granicus.if.org Git - icinga2/commitdiff
Implemented ConfigItemBuilder class.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 6 Jul 2012 12:33:10 +0000 (14:33 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 6 Jul 2012 12:33:10 +0000 (14:33 +0200)
25 files changed:
cib/Makefile.am
cib/cib.cpp
cib/i2-cib.h
components/checker/Makefile.am
components/cibsync/Makefile.am
components/compat/Makefile.am
components/convenience/conveniencecomponent.cpp
components/delegation/Makefile.am
components/demo/Makefile.am
components/discovery/Makefile.am
dyn/Makefile.am
dyn/config_parser.cc
dyn/config_parser.yy
dyn/configitem.cpp
dyn/configitem.h
dyn/configitembuilder.cpp [new file with mode: 0644]
dyn/configitembuilder.h [new file with mode: 0644]
dyn/debuginfo.h
dyn/expression.cpp
dyn/expression.h
dyn/i2-dyn.h
icinga-app/Makefile.am
icinga/Makefile.am
icinga/i2-icinga.h
icinga/icingaapplication.cpp

index 79e45ae90b0872c1fc016b160c2238290f963eee..9b33ce5c2475a117abe34f3232e089f6cd3d18fa 100644 (file)
@@ -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
index fa2ac41b6fd82122924725b36845eeac6680393b..e09c73f8be9f93dd449864cd41a07108596b94ee 100644 (file)
@@ -14,9 +14,12 @@ void CIB::RequireInformation(InformationType types)
        Component::Ptr component = app->GetComponent("cibsync");
 
        if (!component) {
-               ConfigObject::Ptr cibsyncComponentConfig = boost::make_shared<ConfigObject>("component", "cibsync");
-               cibsyncComponentConfig->SetLocal(true);
-               cibsyncComponentConfig->Commit();
+               ConfigItemBuilder::Ptr cb = boost::make_shared<ConfigItemBuilder>();
+               cb->SetType("component");
+               cb->SetName("cibsync");
+               cb->SetLocal(true);
+               ConfigItem::Ptr ci = cb->Compile();
+               ci->Commit();
        }
 }
 
index 5811b441a23d96b39222aeb2aae7804de81a78b5..83a2b79fbdfdbe7a48f665d49daaf37d927f1fbb 100644 (file)
@@ -8,6 +8,7 @@
  * updates from all the other Icinga components.
  */
 
+#include <i2-dyn.h>
 #include <i2-icinga.h>
 
 #ifdef I2_CIB_BUILD
index fddd0dce504dd56231bab2ec6597ae3d06d119c1..798047c7f76d6bec0131bbed5b82fb09cd218241 100644 (file)
@@ -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
index df926a9b7a0b72e15f32e8af44efc50d82ca3e6f..c2fab7fa264fd8d5b1865e2ace580ef98eb6e751 100644 (file)
@@ -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
index 8d868d1fde798eea270e56ce8ab14d9f4ac9f3f4..7d758ebd34bb01eff5b3b80637554a2084072199 100644 (file)
@@ -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
index 644427c50ec920bfe0d1a37daefd14dd6302c62d..02cb6306b2fd4eafa2076dd2316c215cc9618d10 100644 (file)
@@ -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<ConfigItemBuilder>(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<ConfigItem>("service", name, item->GetDebugInfo());
-                               serviceItem->AddParent(desc);
-
-                               ExpressionList::Ptr exprl = boost::make_shared<ExpressionList>();
-
-                               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);
+                               builder->SetType("service");
+                               builder->SetName(name);
 
-                               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", &macros)) {
-                                       Expression macrosExpr("macros", OperatorPlus, macros, item->GetDebugInfo());
-                                       exprl->AddExpression(macrosExpr);
-                               }
+                               if (host->GetProperty("macros", &macros))
+                                       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);
index 5e9f41f8c900db77e74ae87eb2b15fc0f588c524..47c87284c1d8c76c05f113585907208aa2c3e0e5 100644 (file)
@@ -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
index 3fd22751fc8824a53ba9f741388aaf7f32f0cbba..14e40db9b59422db25227eee9393ebf955dbff3d 100644 (file)
@@ -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
index 9dd6ebd1e6f939be8cedf9602dc9cd5460e56180..7a41350a9af3711816760d6a73087a333374fc3b 100644 (file)
@@ -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
index 31ee61811d2c917caa118ab914c00bd27b06f34c..4a6377b791da0fbe09a740f7e556f348078eaa26 100644 (file)
@@ -16,6 +16,8 @@ libdyn_la_SOURCES = \
        i2-dyn.h \
        configitem.cpp \
        configitem.h \
+       configitembuilder.cpp \
+       configitembuilder.h \
        debuginfo.h \
        expression.cpp \
        expression.h \
index 55640951f7f05751bc0a153e19c1d7d1f04f7ccf..48a966fc25c34be6cbbb0885f20456d5009c4f4e 100644 (file)
@@ -223,7 +223,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
 int yyparse(ConfigCompiler *context);
 
 static stack<ExpressionList::Ptr> 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<ConfigItem>((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc);
-               free((yyvsp[(4) - (5)].text));
-               free((yyvsp[(5) - (5)].text));
+               m_Item = boost::make_shared<ConfigItemBuilder>(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<ExpressionList>(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<ExpressionList>());
        }
@@ -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<Dictionary>();
        }
@@ -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"
 
 
index 4b1934169f76df8a1cabf669a9cef3382d0c4740..12a50847d221354d37adaf29de545ecd85d43216 100644 (file)
@@ -82,7 +82,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
 int yyparse(ConfigCompiler *context);
 
 static stack<ExpressionList::Ptr> 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<ConfigItem>($4, $5, yylloc);
-               free($4);
-               free($5);
+               m_Item = boost::make_shared<ConfigItemBuilder>(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<ExpressionList>(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);
        }
        ;
index 37e693ea0916d048f658b24b54d0864857e1a8d5..faea417ed48b9653e101ba19556e8eb635215306 100644 (file)
 
 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<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;
 }
 
-void ConfigItem::SetExpressionList(const ExpressionList::Ptr& exprl)
-{
-       m_ExpressionList = exprl;
-}
-
 vector<string> 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<string>::const_iterator it;
index fd93590b823c1842d9c2af367afae1ef6e7378b0..4293678858dcad580169ce93fe3481c6ab25b3b3 100644 (file)
@@ -32,16 +32,16 @@ public:
 
        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 GetName(void) const;
 
        vector<string> 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<string> m_Parents;
+
        ExpressionList::Ptr m_ExpressionList;
+       vector<string> m_Parents;
+       DebugInfo m_DebugInfo;
 
        ConfigObject::WeakPtr m_ConfigObject;
 
diff --git a/dyn/configitembuilder.cpp b/dyn/configitembuilder.cpp
new file mode 100644 (file)
index 0000000..2c5d744
--- /dev/null
@@ -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);
+}
diff --git a/dyn/configitembuilder.h b/dyn/configitembuilder.h
new file mode 100644 (file)
index 0000000..1a2b09e
--- /dev/null
@@ -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 */
index 83550761d57f08933306ca70da3a8bd26b4d29e7..a4966118429d37e293c7f9cd4eafbc3eaf282299 100644 (file)
@@ -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;
        };
 };
 
index 0096aa4e2b1ccdfa09a864483fac8cc7551a0bf8..d6740bd7745bd26a66a5ac0b6d5abae1d3b1b5fc 100644 (file)
@@ -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<Dictionary>();
@@ -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);
index 4b70a65fb900f02edae651be4c03f838e9d7e8eb..5ef8b5c32e8b1b1d6afb1f62f204a5e369a1f540 100644 (file)
@@ -25,6 +25,7 @@ namespace icinga
 
 enum ExpressionOperator
 {
+       OperatorExecute,
        OperatorSet,
        OperatorPlus,
        OperatorMinus,
index 29a201d3637c0827c6e12aefea493cb31c42caab..b504ff841aca4d3b8554bf48cfd98f04359a4be4 100644 (file)
@@ -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 */
index 39ea3a41b7dc94259c5fe5b7cd7a97b9a64c5cca..9ee0e406ec241f7a9c96388937464308183bb75e 100644 (file)
@@ -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 \
index 52405e65637fa2680360d796f9757306648d6a4e..744f808256a2b063bcdf3c48289d831fc22f74b6 100644 (file)
@@ -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
index a9284165bdbaa86f781a3db5ad0ef2abe41189dc..70f7aef04d1fa318305e99e8d8dca86e2847e342 100644 (file)
@@ -28,6 +28,8 @@
  */
 
 #include <i2-base.h>
+#include <i2-dyn.h>
+#include <i2-dyn.h>
 #include <i2-jsonrpc.h>
 #include <set>
 
index 562ea95292792c3a1402651556f4a3f2e82b46d4..52af54afb83b6026e982a79d6ee2198fcd08b30f 100644 (file)
@@ -62,15 +62,19 @@ int IcingaApplication::Main(const vector<string>& args)
        componentObjects->Start();
 
        /* 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->Commit();
+       convenienceComponentConfig->Compile()->Commit();
 
        /* 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->SetProperty("configFilename", args[1]);
-       fileComponentConfig->Commit();
+       fileComponentConfig->AddExpression("configFilename", OperatorSet, args[1]);
+       fileComponentConfig->Compile()->Commit();
 
        ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga");