]> granicus.if.org Git - icinga2/commitdiff
Moved config parser into dyn/.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 31 May 2012 07:43:46 +0000 (09:43 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 31 May 2012 07:43:46 +0000 (09:43 +0200)
14 files changed:
components/configfile/Makefile.am
components/configfile/configcontext.cpp [deleted file]
components/configfile/i2-configfile.h
dyn/Makefile.am
dyn/config_lexer.cc [moved from components/configfile/icinga_lexer.cc with 98% similarity]
dyn/config_lexer.ll [moved from components/configfile/icinga_lexer.ll with 80% similarity]
dyn/config_parser.cc [moved from components/configfile/icinga_parser.cc with 99% similarity]
dyn/config_parser.h [moved from components/configfile/icinga_parser.h with 100% similarity]
dyn/config_parser.yy [moved from components/configfile/icinga_parser.yy with 88% similarity]
dyn/configcontext.cpp [new file with mode: 0644]
dyn/configcontext.h [moved from components/configfile/configcontext.h with 93% similarity]
dyn/i2-dyn.h
dyntest/Makefile.am
dyntest/dyntest.cpp

index f1d6783ff9934fbad2d8f8b80c0519a5210299af..931ae6790258e8ef2e0906da4cb098b459e9bdd3 100644 (file)
@@ -3,17 +3,9 @@
 pkglib_LTLIBRARIES = \
        configfile.la
 
-BUILD_SOURCES = icinga_parser.h
-
-AM_YFLAGS = -d
-
 configfile_la_SOURCES = \
-       configcontext.cpp \
-       configcontext.h \
        configfilecomponent.cpp \
        configfilecomponent.h \
-       icinga_lexer.ll \
-       icinga_parser.yy \
        i2-configfile.h
 
 configfile_la_CPPFLAGS = \
diff --git a/components/configfile/configcontext.cpp b/components/configfile/configcontext.cpp
deleted file mode 100644 (file)
index 263c77c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "i2-configfile.h"
-
-using namespace icinga;
-
-ConfigContext::ConfigContext(istream *input)
-{
-       Input = input;
-       InitializeScanner();
-}
-
-ConfigContext::~ConfigContext(void)
-{
-       DestroyScanner();
-}
-
index 96776dee384114bc39bbf4879ad4c25695e725da..25dbe9334592166c66050667e61d34a8c9eabdce 100644 (file)
@@ -30,7 +30,6 @@
 #include <i2-base.h>
 #include <i2-icinga.h>
 
-#include "configcontext.h"
 #include "configfilecomponent.h"
 
 #endif /* I2CONFIGFILECOMPONENT_H */
index 2d8136059b69bb92c79a3472bc449934d035701e..7987149bb67aaca39ebbd4c2d70d317e81119413 100644 (file)
@@ -4,7 +4,15 @@
 pkglib_LTLIBRARIES = \
        libdyn.la
 
+BUILT_SOURCES = config_parser.h
+
+AM_YFLAGS = -d
+
 libdyn_la_SOURCES = \
+       configcontext.cpp \
+       configcontext.h \
+       config_lexer.ll
+       config_parser.yy \
        i2-dyn.h \
        dynamicobject.cpp \
        dynamicobject.h \
similarity index 98%
rename from components/configfile/icinga_lexer.cc
rename to dyn/config_lexer.cc
index cd05cccecbb0338042fc7f92be555bae231cd7f2..3e448729976dc7920f0f91c7fb67aaefeccb6a9b 100644 (file)
@@ -1,5 +1,5 @@
 
-#line 3 "icinga_lexer.cc"
+#line 3 "config_lexer.cc"
 
 #define  YY_INT_ALIGNED short int
 
@@ -500,24 +500,23 @@ static yyconst flex_int32_t yy_rule_can_match_eol[23] =
 #define yymore() yymore_used_but_not_detected
 #define YY_MORE_ADJ 0
 #define YY_RESTORE_YY_MORE_OFFSET
-#line 1 "icinga_lexer.ll"
-#line 2 "icinga_lexer.ll"
-#include "i2-configfile.h"
-#include "icinga_parser.h"
+#line 1 "config_lexer.ll"
+#line 2 "config_lexer.ll"
+#include "i2-dyn.h"
+#include "config_parser.h"
 
 using namespace icinga;
 
 #define YY_EXTRA_TYPE ConfigContext *
 #define YY_USER_ACTION yylloc->first_line = yylineno;
 
-#define YY_INPUT(buf, result, max_size)                \
-do {                                           \
-       yyextra->Input->read(buf, max_size);    \
-       result = yyextra->Input->gcount();      \
+#define YY_INPUT(buf, result, max_size)                        \
+do {                                                   \
+       result = yyextra->ReadInput(buf, max_size);     \
 } while (0)
 #define YY_NO_UNISTD_H 1
 
-#line 521 "icinga_lexer.cc"
+#line 520 "config_lexer.cc"
 
 #define INITIAL 0
 #define IN_C_COMMENT 1
@@ -764,9 +763,9 @@ YY_DECL
        register int yy_act;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
-#line 23 "icinga_lexer.ll"
+#line 22 "config_lexer.ll"
 
-#line 770 "icinga_lexer.cc"
+#line 769 "config_lexer.cc"
 
     yylval = yylval_param;
 
@@ -863,122 +862,122 @@ do_action:      /* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 24 "icinga_lexer.ll"
+#line 23 "config_lexer.ll"
 return T_ABSTRACT;
        YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 25 "icinga_lexer.ll"
+#line 24 "config_lexer.ll"
 return T_LOCAL;
        YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 26 "icinga_lexer.ll"
+#line 25 "config_lexer.ll"
 return T_OBJECT;
        YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 27 "icinga_lexer.ll"
+#line 26 "config_lexer.ll"
 return T_INCLUDE;
        YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 28 "icinga_lexer.ll"
+#line 27 "config_lexer.ll"
 return T_INHERITS;
        YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 29 "icinga_lexer.ll"
+#line 28 "config_lexer.ll"
 return T_IDENTIFIER;
        YY_BREAK
 case 7:
 /* rule 7 can match eol */
 YY_RULE_SETUP
-#line 30 "icinga_lexer.ll"
+#line 29 "config_lexer.ll"
 { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; }
        YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 31 "icinga_lexer.ll"
+#line 30 "config_lexer.ll"
 { yylval->num = atoi(yytext); return T_NUMBER; }
        YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 32 "icinga_lexer.ll"
+#line 31 "config_lexer.ll"
 return T_OPEN_BRACE;
        YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 33 "icinga_lexer.ll"
+#line 32 "config_lexer.ll"
 return T_CLOSE_BRACE;
        YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 34 "icinga_lexer.ll"
+#line 33 "config_lexer.ll"
 return T_OPEN_BRACKET;
        YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 35 "icinga_lexer.ll"
+#line 34 "config_lexer.ll"
 return T_CLOSE_BRACKET;
        YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 36 "icinga_lexer.ll"
+#line 35 "config_lexer.ll"
 return T_COMMA;
        YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 37 "icinga_lexer.ll"
+#line 36 "config_lexer.ll"
 return T_EQUAL;
        YY_BREAK
 
 case 15:
 YY_RULE_SETUP
-#line 40 "icinga_lexer.ll"
+#line 39 "config_lexer.ll"
 BEGIN(IN_C_COMMENT);
        YY_BREAK
 
 
 case 16:
 YY_RULE_SETUP
-#line 44 "icinga_lexer.ll"
+#line 43 "config_lexer.ll"
 BEGIN(INITIAL);
        YY_BREAK
 case 17:
 /* rule 17 can match eol */
 YY_RULE_SETUP
-#line 45 "icinga_lexer.ll"
+#line 44 "config_lexer.ll"
 /* ignore comment */
        YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 46 "icinga_lexer.ll"
+#line 45 "config_lexer.ll"
 /* ignore star */
        YY_BREAK
 
 case 19:
 YY_RULE_SETUP
-#line 49 "icinga_lexer.ll"
+#line 48 "config_lexer.ll"
 /* ignore C++-style comments */
        YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 50 "icinga_lexer.ll"
+#line 49 "config_lexer.ll"
 /* ignore shell-style comments */
        YY_BREAK
 case 21:
 /* rule 21 can match eol */
 YY_RULE_SETUP
-#line 51 "icinga_lexer.ll"
+#line 50 "config_lexer.ll"
 /* ignore whitespace */
        YY_BREAK
 case 22:
 YY_RULE_SETUP
-#line 52 "icinga_lexer.ll"
+#line 51 "config_lexer.ll"
 ECHO;
        YY_BREAK
-#line 982 "icinga_lexer.cc"
+#line 981 "config_lexer.cc"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(IN_C_COMMENT):
        yyterminate();
@@ -2166,20 +2165,20 @@ void yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 52 "icinga_lexer.ll"
+#line 51 "config_lexer.ll"
 
 
 
 
 void ConfigContext::InitializeScanner(void)
 {
-       yylex_init(&Scanner);
-       yyset_extra(this,Scanner);
+       yylex_init(&m_Scanner);
+       yyset_extra(this,m_Scanner);
 }
 
 void ConfigContext::DestroyScanner(void)
 {
-       yylex_destroy(Scanner);
+       yylex_destroy(m_Scanner);
 }
 
 
similarity index 80%
rename from components/configfile/icinga_lexer.ll
rename to dyn/config_lexer.ll
index c0af41a24fad00789dd69fa4882b08b76d98cb8a..3fc488c9baa86f70753e09767587e66242417517 100644 (file)
@@ -1,16 +1,15 @@
 %{
-#include "i2-configfile.h"
-#include "icinga_parser.h"
+#include "i2-dyn.h"
+#include "config_parser.h"
 
 using namespace icinga;
 
 #define YY_EXTRA_TYPE ConfigContext *
 #define YY_USER_ACTION yylloc->first_line = yylineno;
 
-#define YY_INPUT(buf, result, max_size)                \
-do {                                           \
-       yyextra->Input->read(buf, max_size);    \
-       result = yyextra->Input->gcount();      \
+#define YY_INPUT(buf, result, max_size)                        \
+do {                                                   \
+       result = yyextra->ReadInput(buf, max_size);     \
 } while (0)
 %}
 
@@ -54,12 +53,12 @@ inherits            return T_INHERITS;
 
 void ConfigContext::InitializeScanner(void)
 {
-       yylex_init(&Scanner);
-       yyset_extra(this, Scanner);
+       yylex_init(&m_Scanner);
+       yyset_extra(this, m_Scanner);
 }
 
 void ConfigContext::DestroyScanner(void)
 {
-       yylex_destroy(Scanner);
+       yylex_destroy(m_Scanner);
 }
 
similarity index 99%
rename from components/configfile/icinga_parser.cc
rename to dyn/config_parser.cc
index 0f44e3f3694eb6d90abf1407f719f1cdc4237eaf..55d4656f0ef38c38f00b965ceef21192c65e9ca4 100644 (file)
@@ -176,18 +176,22 @@ int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
 
 void yyerror(YYLTYPE *locp, ConfigContext *context, const char *err)
 {
-       std::cout << locp->first_line << ":" << locp->first_column
+       stringstream message;
+
+       message << locp->first_line << ":" << locp->first_column
            << "-"
            << locp->last_line << ":" << locp->last_column
            << ": " << err << std::endl;
+
+       throw runtime_error(message.str());
 }
 
-#define scanner context->Scanner
+#define scanner (context->GetScanner())
 
 
 
 /* Line 343 of yacc.c  */
-#line 191 "icinga_parser.cc"
+#line 195 "icinga_parser.cc"
 
 #ifdef short
 # undef short
@@ -486,10 +490,10 @@ static const yytype_int8 yyrhs[] =
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint8 yyrline[] =
 {
-       0,    50,    50,    51,    54,    54,    57,    60,    61,    64,
-      67,    68,    71,    72,    75,    76,    79,    80,    83,    86,
-      87,    88,    91,    94,    94,    94,    94,    97,   100,   102,
-     103
+       0,    54,    54,    55,    58,    58,    61,    64,    65,    68,
+      71,    72,    75,    76,    79,    80,    83,    84,    87,    90,
+      91,    92,    95,    98,    98,    98,    98,   101,   104,   106,
+     107
 };
 #endif
 
@@ -1494,7 +1498,7 @@ yyreduce:
       
 
 /* Line 1806 of yacc.c  */
-#line 1498 "icinga_parser.cc"
+#line 1502 "icinga_parser.cc"
       default: break;
     }
   /* User semantic actions sometimes alter yychar, and that requires
@@ -1732,6 +1736,6 @@ yyreturn:
 
 
 /* Line 2067 of yacc.c  */
-#line 105 "icinga_parser.yy"
+#line 109 "icinga_parser.yy"
 
 
similarity index 88%
rename from components/configfile/icinga_parser.yy
rename to dyn/config_parser.yy
index 7fcfe96e9d1ba123c6458104a87067f7a9e87625..0432255b9abcecb03f3e948fd8e3d8c5e702d2ca 100644 (file)
@@ -36,13 +36,17 @@ int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
 
 void yyerror(YYLTYPE *locp, ConfigContext *context, const char *err)
 {
-       std::cout << locp->first_line << ":" << locp->first_column
+       stringstream message;
+
+       message << locp->first_line << ":" << locp->first_column
            << "-"
            << locp->last_line << ":" << locp->last_column
-           << ": " << err << std::endl;
+           << ": " << err << endl;
+
+       throw runtime_error(message.str());
 }
 
-#define scanner context->Scanner
+#define scanner (context->GetScanner())
 
 %}
 
diff --git a/dyn/configcontext.cpp b/dyn/configcontext.cpp
new file mode 100644 (file)
index 0000000..99963c9
--- /dev/null
@@ -0,0 +1,26 @@
+#include "i2-dyn.h"
+
+using namespace icinga;
+
+ConfigContext::ConfigContext(istream *input)
+{
+       m_Input = input;
+       InitializeScanner();
+}
+
+ConfigContext::~ConfigContext(void)
+{
+       DestroyScanner();
+}
+
+size_t ConfigContext::ReadInput(char *buffer, size_t max_size)
+{
+       m_Input->read(buffer, max_size);
+       return m_Input->gcount();
+}
+
+void *ConfigContext::GetScanner(void) const
+{
+       return m_Scanner;
+}
+
similarity index 93%
rename from components/configfile/configcontext.h
rename to dyn/configcontext.h
index 2d49b300c48878f934643ac0583ad8d99c27c1ce..6dca6f9ec6ec9ee10b944dc4587df3571eba60fc 100644 (file)
@@ -29,10 +29,13 @@ public:
        ConfigContext(istream *input = &cin);
        virtual ~ConfigContext(void);
 
-       istream *Input;
-       void *Scanner;
+       size_t ReadInput(char *buffer, size_t max_bytes);
+       void *GetScanner(void) const;
 
 private:
+       istream *m_Input;
+       void *m_Scanner;
+
        void InitializeScanner(void);
        void DestroyScanner(void);
 };
index 13ede7c25ace91c83a9f84827191e4c91af4bcb4..e930716c8b866d81baba582d5e339c27572927f2 100644 (file)
@@ -35,6 +35,7 @@
 #      define I2_DYN_API I2_IMPORT
 #endif /* I2_DYN_BUILD */
 
+#include "configcontext.h"
 #include "dynamicdictionary.h"
 #include "dynamicobject.h"
 #include "objectset.h"
index 8dcdc755c03bd34fa90f46a29899672b461756f7..3c271c109a49aea596b9454e0748b77d3f67bf56 100644 (file)
@@ -12,6 +12,9 @@ dyntest_CPPFLAGS = \
        $(BOOST_CPPFLAGS) \
        -I${top_srcdir}/base \
        -I${top_srcdir}/dyn \
+       -I${top_srcdir}/jsonrpc \
+       -I${top_srcdir}/icinga \
+       -I${top_srcdir}/components/configfile \
        -I${top_srcdir}
 
 dyntest_LDFLAGS = \
@@ -19,4 +22,5 @@ dyntest_LDFLAGS = \
 
 dyntest_LDADD = \
        ${top_builddir}/base/libbase.la \
-       ${top_builddir}/dyn/libdyn.la
+       ${top_builddir}/dyn/libdyn.la \
+       ${top_builddir}/components/configfile/configfile.la
index 1b8faba5ffd206e109fb07090ac1c9338f9a5d27..3ad489a210edda69e92e678bcc4088b409064ff7 100644 (file)
@@ -1,38 +1,12 @@
-#include <i2-dyn.h>
+#include <i2-configfile.h>
 
 using namespace icinga;
 
-bool propgetter(string prop, const Object::Ptr& object, string *key)
-{
-       DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
-       return dobj->GetConfig()->GetProperty(prop, key);
-}
-
 int main(int argc, char **argv)
 {
-       for (int i = 0; i < 10000; i++) {
-               stringstream sname;
-               sname << "foo" << i;
-
-               DynamicObject::Ptr dobj = make_shared<DynamicObject>();
-               dobj->GetConfig()->SetProperty("type", "process");
-               dobj->GetConfig()->SetProperty("name", sname.str());
-               dobj->Commit();
-       }
-
-       ObjectMap::Ptr byType = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
-           bind(&propgetter, "type", _1, _2));
-       byType->Start();
-
-       ObjectMap::Ptr byName = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
-           bind(&propgetter, "name", _1, _2));
-       byName->Start();
-
-       ObjectMap::Range processes = byType->GetRange("process");
-       cout << distance(processes.first, processes.second) << " processes" << endl;
-
-       ObjectMap::Range foo55 = byName->GetRange("foo55");
-       cout << distance(foo55.first, foo55.second) << " foo55s" << endl;
-
+       stringstream config;
+       config << "object process \"foo\" {}";
+       ConfigContext ctx(&config);
+       yyparse(&ctx);
        return 0;
 }