diff --git a/base/application.cpp b/base/application.cpp index d402dba3f..0e6a5753c 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -27,6 +27,7 @@ using namespace icinga; Application::Ptr I2_EXPORT Application::m_Instance; bool I2_EXPORT Application::m_ShuttingDown = false; +bool I2_EXPORT Application::m_Debugging = false; /** * Constructor for the Application class. @@ -416,7 +417,7 @@ void Application::AddComponentSearchDir(const string& componentDirectory) * * @returns true if the application is being debugged, false otherwise */ -bool Application::IsDebugging(void) const +bool Application::IsDebugging(void) { return m_Debugging; } diff --git a/base/application.h b/base/application.h index c8ee5afd1..befeeff06 100644 --- a/base/application.h +++ b/base/application.h @@ -56,7 +56,7 @@ public: shared_ptr GetComponent(const string& name) const; void AddComponentSearchDir(const string& componentDirectory); - bool IsDebugging(void) const; + static bool IsDebugging(void); protected: void RunEventLoop(void); @@ -71,7 +71,7 @@ private: map< string, shared_ptr > m_Components; /**< Components that were loaded by the application. */ vector m_Arguments; /**< Command-line arguments */ - bool m_Debugging; /**< Whether debugging is enabled. */ + static bool m_Debugging; /**< Whether debugging is enabled. */ #ifndef _WIN32 static void SigIntHandler(int signum); diff --git a/dyn/config_lexer.cc b/dyn/config_lexer.cc index 4b86e62e0..ab464a058 100644 --- a/dyn/config_lexer.cc +++ b/dyn/config_lexer.cc @@ -370,8 +370,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 27 -#define YY_END_OF_BUFFER 28 +#define YY_NUM_RULES 30 +#define YY_END_OF_BUFFER 31 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -379,16 +379,16 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[76] = +static yyconst flex_int16_t yy_accept[79] = { 0, - 0, 0, 0, 0, 28, 27, 26, 27, 27, 27, - 27, 14, 7, 27, 9, 15, 7, 12, 13, 7, - 7, 7, 7, 7, 10, 11, 22, 23, 26, 0, - 25, 18, 16, 7, 17, 20, 0, 19, 9, 7, - 7, 7, 7, 7, 22, 21, 8, 24, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, - 7, 7, 7, 2, 7, 7, 7, 7, 3, 7, - 4, 7, 1, 5, 0 + 0, 0, 0, 0, 31, 29, 28, 28, 29, 29, + 10, 11, 29, 29, 16, 7, 29, 9, 17, 7, + 14, 15, 7, 7, 7, 7, 7, 12, 13, 24, + 25, 28, 0, 27, 20, 18, 7, 19, 22, 0, + 21, 9, 7, 7, 7, 7, 7, 24, 23, 8, + 26, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 6, 7, 7, 7, 7, 2, 7, 7, 7, + 7, 3, 7, 4, 7, 1, 5, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -396,17 +396,17 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 4, 5, 1, 1, 1, 1, 1, - 1, 6, 7, 8, 9, 1, 10, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 1, 1, 1, - 12, 1, 1, 1, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 14, 1, 15, 1, 13, 1, 16, 17, 18, 19, + 1, 2, 1, 4, 5, 1, 1, 1, 1, 6, + 7, 8, 9, 10, 11, 1, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 1, 17, 1, 15, 1, 18, 19, 20, 21, - 20, 13, 13, 21, 22, 23, 13, 24, 13, 25, - 26, 13, 13, 27, 28, 29, 30, 13, 13, 13, - 13, 13, 31, 1, 32, 1, 1, 1, 1, 1, + 22, 15, 15, 23, 24, 25, 15, 26, 15, 27, + 28, 15, 15, 29, 30, 31, 32, 15, 15, 15, + 15, 15, 33, 1, 34, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -423,91 +423,91 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[33] = +static yyconst flex_int32_t yy_meta[35] = { 0, - 1, 1, 2, 3, 1, 4, 1, 1, 5, 1, - 5, 5, 5, 1, 1, 5, 5, 5, 5, 5, + 1, 1, 2, 3, 1, 1, 1, 4, 1, 1, + 5, 1, 5, 5, 5, 1, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 1, 1 + 5, 5, 1, 1 } ; -static yyconst flex_int16_t yy_base[82] = +static yyconst flex_int16_t yy_base[85] = { 0, - 0, 0, 134, 133, 138, 141, 31, 0, 0, 122, - 119, 141, 112, 29, 109, 141, 97, 141, 141, 25, - 24, 26, 28, 31, 141, 141, 0, 98, 42, 103, - 0, 141, 141, 94, 141, 141, 0, 141, 94, 34, - 35, 39, 42, 38, 0, 141, 141, 0, 43, 47, - 48, 51, 52, 53, 57, 58, 62, 63, 92, 65, - 66, 67, 68, 91, 69, 73, 80, 81, 90, 82, - 89, 84, 87, 85, 141, 112, 117, 122, 90, 127, - 132 + 0, 0, 136, 135, 142, 145, 33, 35, 0, 0, + 145, 145, 124, 121, 145, 114, 31, 111, 145, 99, + 145, 145, 27, 26, 28, 30, 33, 145, 145, 0, + 100, 46, 107, 0, 145, 145, 96, 145, 145, 0, + 145, 96, 36, 37, 41, 44, 40, 0, 145, 145, + 0, 45, 49, 50, 53, 54, 55, 59, 60, 64, + 65, 94, 67, 68, 69, 70, 93, 71, 75, 82, + 83, 92, 84, 91, 86, 89, 87, 145, 116, 121, + 126, 94, 131, 136 } ; -static yyconst flex_int16_t yy_def[82] = +static yyconst flex_int16_t yy_def[85] = { 0, - 75, 1, 76, 76, 75, 75, 75, 77, 78, 75, - 75, 75, 79, 75, 75, 75, 79, 75, 75, 79, - 79, 79, 79, 79, 75, 75, 80, 75, 75, 77, - 78, 75, 75, 79, 75, 75, 81, 75, 75, 79, - 79, 79, 79, 79, 80, 75, 75, 81, 79, 79, - 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, - 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, - 79, 79, 79, 79, 0, 75, 75, 75, 75, 75, - 75 + 78, 1, 79, 79, 78, 78, 78, 78, 80, 81, + 78, 78, 78, 78, 78, 82, 78, 78, 78, 82, + 78, 78, 82, 82, 82, 82, 82, 78, 78, 83, + 78, 78, 80, 81, 78, 78, 82, 78, 78, 84, + 78, 78, 82, 82, 82, 82, 82, 83, 78, 78, + 84, 82, 82, 82, 82, 82, 82, 82, 82, 82, + 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, + 82, 82, 82, 82, 82, 82, 82, 0, 78, 78, + 78, 78, 78, 78 } ; -static yyconst flex_int16_t yy_nxt[174] = +static yyconst flex_int16_t yy_nxt[180] = { 0, - 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 17, 17, 17, 17, - 17, 21, 17, 22, 23, 24, 17, 17, 17, 17, - 25, 26, 29, 29, 36, 75, 75, 75, 37, 75, - 38, 40, 75, 29, 29, 75, 75, 44, 41, 75, - 75, 42, 50, 75, 75, 51, 52, 43, 75, 75, - 54, 49, 75, 75, 75, 53, 58, 57, 75, 75, - 56, 55, 60, 75, 75, 59, 75, 75, 75, 75, - 75, 66, 65, 61, 75, 67, 64, 62, 63, 68, - 70, 75, 75, 75, 34, 75, 75, 69, 75, 71, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 20, 20, + 20, 20, 20, 24, 20, 25, 26, 27, 20, 20, + 20, 20, 28, 29, 32, 32, 32, 32, 39, 78, + 78, 78, 40, 78, 41, 43, 78, 32, 32, 78, + 78, 47, 44, 78, 78, 45, 53, 78, 78, 54, + 55, 46, 78, 78, 57, 52, 78, 78, 78, 56, + 61, 60, 78, 78, 59, 58, 63, 78, 78, 62, + 78, 78, 78, 78, 78, 69, 68, 64, 78, 70, + 67, 65, 66, 71, 73, 78, 78, 78, 37, 78, - 75, 75, 75, 75, 39, 75, 47, 46, 75, 72, - 73, 74, 27, 27, 27, 27, 27, 30, 30, 39, - 30, 30, 31, 35, 31, 31, 31, 45, 45, 45, - 33, 45, 48, 32, 48, 48, 48, 75, 28, 28, - 5, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75 + 78, 72, 78, 74, 78, 78, 78, 78, 42, 78, + 50, 49, 78, 75, 76, 77, 30, 30, 30, 30, + 30, 33, 33, 42, 33, 33, 34, 38, 34, 34, + 34, 48, 48, 48, 36, 48, 51, 35, 51, 51, + 51, 78, 31, 31, 5, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78 } ; -static yyconst flex_int16_t yy_chk[174] = +static yyconst flex_int16_t yy_chk[180] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 7, 7, 14, 21, 20, 22, 14, 23, - 14, 20, 24, 29, 29, 40, 41, 24, 21, 44, - 42, 22, 41, 43, 49, 41, 42, 23, 50, 51, - 44, 40, 52, 53, 54, 43, 52, 51, 55, 56, - 50, 49, 54, 57, 58, 53, 60, 61, 62, 63, - 65, 61, 60, 55, 66, 62, 58, 56, 57, 63, - 66, 67, 68, 70, 79, 72, 74, 65, 73, 67, + 1, 1, 1, 1, 7, 7, 8, 8, 17, 24, + 23, 25, 17, 26, 17, 23, 27, 32, 32, 43, + 44, 27, 24, 47, 45, 25, 44, 46, 52, 44, + 45, 26, 53, 54, 47, 43, 55, 56, 57, 46, + 55, 54, 58, 59, 53, 52, 57, 60, 61, 56, + 63, 64, 65, 66, 68, 64, 63, 58, 69, 65, + 61, 59, 60, 66, 69, 70, 71, 73, 82, 75, - 71, 69, 64, 59, 39, 34, 30, 28, 17, 68, - 70, 72, 76, 76, 76, 76, 76, 77, 77, 15, - 77, 77, 78, 13, 78, 78, 78, 80, 80, 80, - 11, 80, 81, 10, 81, 81, 81, 5, 4, 3, - 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75 + 77, 68, 76, 70, 74, 72, 67, 62, 42, 37, + 33, 31, 20, 71, 73, 75, 79, 79, 79, 79, + 79, 80, 80, 18, 80, 80, 81, 16, 81, 81, + 81, 83, 83, 83, 14, 83, 84, 13, 84, 84, + 84, 5, 4, 3, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78 } ; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[28] = +static yyconst flex_int32_t yy_rule_can_match_eol[31] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 1, 0, }; + 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, }; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -857,13 +857,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 76 ) + if ( yy_current_state >= 79 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_current_state != 75 ); + while ( yy_current_state != 78 ); yy_cp = yyg->yy_last_accepting_cpos; yy_current_state = yyg->yy_last_accepting_state; @@ -944,100 +944,115 @@ YY_RULE_SETUP case 10: YY_RULE_SETUP #line 51 "config_lexer.ll" -return T_OPEN_BRACE; +return T_OPEN_PARENTHESIS; YY_BREAK case 11: YY_RULE_SETUP #line 52 "config_lexer.ll" -return T_CLOSE_BRACE; +return T_CLOSE_PARENTHESIS; YY_BREAK case 12: YY_RULE_SETUP #line 53 "config_lexer.ll" -return T_OPEN_BRACKET; +return T_OPEN_BRACE; YY_BREAK case 13: YY_RULE_SETUP #line 54 "config_lexer.ll" -return T_CLOSE_BRACKET; +return T_CLOSE_BRACE; YY_BREAK case 14: YY_RULE_SETUP #line 55 "config_lexer.ll" -return T_COMMA; +return T_OPEN_BRACKET; YY_BREAK case 15: YY_RULE_SETUP #line 56 "config_lexer.ll" -{ yylval->op = OperatorSet; return T_EQUAL; } +return T_CLOSE_BRACKET; YY_BREAK case 16: YY_RULE_SETUP #line 57 "config_lexer.ll" -{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; } +return T_COMMA; YY_BREAK case 17: YY_RULE_SETUP #line 58 "config_lexer.ll" -{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; } +{ yylval->op = OperatorSet; return T_EQUAL; } YY_BREAK case 18: YY_RULE_SETUP #line 59 "config_lexer.ll" -{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; } +{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; } YY_BREAK case 19: YY_RULE_SETUP #line 60 "config_lexer.ll" +{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 61 "config_lexer.ll" +{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 62 "config_lexer.ll" { yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; } YY_BREAK -case 20: +case 22: YY_RULE_SETUP -#line 63 "config_lexer.ll" +#line 65 "config_lexer.ll" BEGIN(IN_C_COMMENT); YY_BREAK -case 21: -YY_RULE_SETUP -#line 67 "config_lexer.ll" -BEGIN(INITIAL); - YY_BREAK -case 22: -/* rule 22 can match eol */ -YY_RULE_SETUP -#line 68 "config_lexer.ll" -/* ignore comment */ - YY_BREAK case 23: YY_RULE_SETUP #line 69 "config_lexer.ll" -/* ignore star */ +BEGIN(INITIAL); YY_BREAK - case 24: +/* rule 24 can match eol */ YY_RULE_SETUP -#line 72 "config_lexer.ll" -/* ignore C++-style comments */ +#line 70 "config_lexer.ll" +/* ignore comment */ YY_BREAK case 25: YY_RULE_SETUP -#line 73 "config_lexer.ll" -/* ignore shell-style comments */ +#line 71 "config_lexer.ll" +/* ignore star */ YY_BREAK + case 26: -/* rule 26 can match eol */ YY_RULE_SETUP #line 74 "config_lexer.ll" -/* ignore whitespace */ +/* ignore C++-style comments */ YY_BREAK case 27: YY_RULE_SETUP #line 75 "config_lexer.ll" +/* ignore shell-style comments */ + YY_BREAK +case 28: +/* rule 28 can match eol */ +YY_RULE_SETUP +#line 76 "config_lexer.ll" +/* ignore whitespace */ + YY_BREAK +case 29: +YY_RULE_SETUP +#line 78 "config_lexer.ll" +return yytext[0]; + YY_BREAK +case 30: +YY_RULE_SETUP +#line 79 "config_lexer.ll" ECHO; YY_BREAK -#line 1041 "config_lexer.cc" +#line 1056 "config_lexer.cc" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(IN_C_COMMENT): yyterminate(); @@ -1333,7 +1348,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 76 ) + if ( yy_current_state >= 79 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1362,11 +1377,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 76 ) + if ( yy_current_state >= 79 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 75); + yy_is_jam = (yy_current_state == 78); return yy_is_jam ? 0 : yy_current_state; } @@ -2225,7 +2240,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 75 "config_lexer.ll" +#line 79 "config_lexer.ll" diff --git a/dyn/config_lexer.ll b/dyn/config_lexer.ll index 632660be1..00ac86f4c 100644 --- a/dyn/config_lexer.ll +++ b/dyn/config_lexer.ll @@ -48,6 +48,8 @@ null return T_NULL; [a-zA-Z\-_][a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; } \"[^\"]+\" { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; } [0-9]+ { yylval->num = atoi(yytext); return T_NUMBER; } +\( return T_OPEN_PARENTHESIS; +\) return T_CLOSE_PARENTHESIS; \{ return T_OPEN_BRACE; \} return T_CLOSE_BRACE; \[ return T_OPEN_BRACKET; @@ -72,6 +74,8 @@ null return T_NULL; \/\/[^\n]+ /* ignore C++-style comments */ #[^\n]+ /* ignore shell-style comments */ [ \t\n]+ /* ignore whitespace */ + +. return yytext[0]; %% diff --git a/dyn/config_parser.cc b/dyn/config_parser.cc index 034a9250f..1a27d532c 100644 --- a/dyn/config_parser.cc +++ b/dyn/config_parser.cc @@ -125,21 +125,23 @@ using namespace icinga; T_NUMBER = 259, T_NULL = 260, T_IDENTIFIER = 261, - T_OPEN_BRACE = 262, - T_CLOSE_BRACE = 263, - T_OPEN_BRACKET = 264, - T_CLOSE_BRACKET = 265, - T_EQUAL = 266, - T_PLUS_EQUAL = 267, - T_MINUS_EQUAL = 268, - T_MULTIPLY_EQUAL = 269, - T_DIVIDE_EQUAL = 270, - T_COMMA = 271, - T_ABSTRACT = 272, - T_LOCAL = 273, - T_OBJECT = 274, - T_INCLUDE = 275, - T_INHERITS = 276 + T_OPEN_PARENTHESIS = 262, + T_CLOSE_PARENTHESIS = 263, + T_OPEN_BRACE = 264, + T_CLOSE_BRACE = 265, + T_OPEN_BRACKET = 266, + T_CLOSE_BRACKET = 267, + T_EQUAL = 268, + T_PLUS_EQUAL = 269, + T_MINUS_EQUAL = 270, + T_MULTIPLY_EQUAL = 271, + T_DIVIDE_EQUAL = 272, + T_COMMA = 273, + T_ABSTRACT = 274, + T_LOCAL = 275, + T_OBJECT = 276, + T_INCLUDE = 277, + T_INHERITS = 278 }; #endif /* Tokens. */ @@ -147,21 +149,23 @@ using namespace icinga; #define T_NUMBER 259 #define T_NULL 260 #define T_IDENTIFIER 261 -#define T_OPEN_BRACE 262 -#define T_CLOSE_BRACE 263 -#define T_OPEN_BRACKET 264 -#define T_CLOSE_BRACKET 265 -#define T_EQUAL 266 -#define T_PLUS_EQUAL 267 -#define T_MINUS_EQUAL 268 -#define T_MULTIPLY_EQUAL 269 -#define T_DIVIDE_EQUAL 270 -#define T_COMMA 271 -#define T_ABSTRACT 272 -#define T_LOCAL 273 -#define T_OBJECT 274 -#define T_INCLUDE 275 -#define T_INHERITS 276 +#define T_OPEN_PARENTHESIS 262 +#define T_CLOSE_PARENTHESIS 263 +#define T_OPEN_BRACE 264 +#define T_CLOSE_BRACE 265 +#define T_OPEN_BRACKET 266 +#define T_CLOSE_BRACKET 267 +#define T_EQUAL 268 +#define T_PLUS_EQUAL 269 +#define T_MINUS_EQUAL 270 +#define T_MULTIPLY_EQUAL 271 +#define T_DIVIDE_EQUAL 272 +#define T_COMMA 273 +#define T_ABSTRACT 274 +#define T_LOCAL 275 +#define T_OBJECT 276 +#define T_INCLUDE 277 +#define T_INHERITS 278 @@ -181,7 +185,7 @@ typedef union YYSTYPE /* Line 293 of yacc.c */ -#line 185 "config_parser.cc" +#line 189 "config_parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -205,7 +209,7 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ /* Line 343 of yacc.c */ -#line 69 "config_parser.yy" +#line 71 "config_parser.yy" int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); @@ -232,17 +236,15 @@ void ConfigContext::Compile(void) #define scanner (context->GetScanner()) static stack m_ExpressionLists; -static map, DConfigObject::Ptr> m_Objects; +static set m_Objects; static DConfigObject::Ptr m_Object; -static string m_Name; -static string m_Type; static bool m_Abstract; static bool m_Local; static Dictionary::Ptr m_Array; /* Line 343 of yacc.c */ -#line 246 "config_parser.cc" +#line 248 "config_parser.cc" #ifdef short # undef short @@ -466,17 +468,17 @@ union yyalloc #define YYLAST 46 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 26 +#define YYNTOKENS 28 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 22 +#define YYNNTS 23 /* YYNRULES -- Number of rules. */ -#define YYNRULES 42 +#define YYNRULES 43 /* YYNRULES -- Number of states. */ -#define YYNSTATES 59 +#define YYNSTATES 60 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 276 +#define YYMAXUTOK 278 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -488,7 +490,7 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 24, 22, 2, 23, 2, 25, 2, 2, + 2, 2, 26, 24, 2, 25, 2, 27, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -511,7 +513,7 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21 + 15, 16, 17, 18, 19, 20, 21, 22, 23 }; #if YYDEBUG @@ -523,33 +525,33 @@ static const yytype_uint8 yyprhs[] = 25, 26, 29, 31, 33, 35, 39, 41, 42, 45, 46, 51, 52, 54, 58, 62, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 94, - 99, 100, 102 + 99, 101, 102, 104 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { - 27, 0, -1, -1, 27, 28, -1, 30, -1, 29, - -1, 20, 3, -1, -1, -1, 31, 33, 19, 6, - 3, 32, 37, 38, -1, -1, 33, 34, -1, 17, - -1, 18, -1, 36, -1, 35, 16, 36, -1, 3, - -1, -1, 21, 35, -1, -1, 7, 39, 40, 8, - -1, -1, 41, -1, 40, 16, 41, -1, 6, 42, - 44, -1, 6, 9, 3, 10, 42, 44, -1, 3, - -1, 11, -1, 12, -1, 13, -1, 14, -1, 15, - -1, 3, -1, 4, -1, 5, -1, 43, -1, 45, - -1, 38, -1, -1, 9, 46, 47, 10, -1, -1, - 43, -1, 47, 16, 43, -1 + 29, 0, -1, -1, 29, 30, -1, 32, -1, 31, + -1, 22, 3, -1, -1, -1, 33, 35, 21, 6, + 3, 34, 39, 40, -1, -1, 35, 36, -1, 19, + -1, 20, -1, 38, -1, 37, 18, 38, -1, 3, + -1, -1, 23, 37, -1, -1, 9, 41, 42, 10, + -1, -1, 43, -1, 43, 18, 42, -1, 6, 44, + 46, -1, 6, 11, 3, 12, 44, 46, -1, 3, + -1, 13, -1, 14, -1, 15, -1, 16, -1, 17, + -1, 3, -1, 4, -1, 5, -1, 45, -1, 47, + -1, 40, -1, -1, 7, 48, 50, 8, -1, 45, + -1, -1, 49, -1, 49, 18, 50, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 105, 105, 106, 112, 112, 115, 119, 125, 119, - 159, 160, 163, 167, 173, 174, 177, 183, 184, 188, - 187, 199, 200, 201, 204, 212, 225, 234, 235, 236, - 237, 238, 244, 248, 252, 258, 259, 260, 267, 266, - 278, 280, 285 + 0, 105, 105, 106, 112, 112, 115, 119, 124, 119, + 155, 156, 159, 163, 169, 170, 173, 179, 180, 184, + 183, 195, 196, 197, 200, 208, 221, 230, 231, 232, + 233, 234, 240, 244, 248, 254, 255, 256, 263, 262, + 274, 280, 282, 283 }; #endif @@ -559,15 +561,16 @@ static const yytype_uint16 yyrline[] = static const char *const yytname[] = { "$end", "error", "$undefined", "T_STRING", "T_NUMBER", "T_NULL", - "T_IDENTIFIER", "T_OPEN_BRACE", "T_CLOSE_BRACE", "T_OPEN_BRACKET", - "T_CLOSE_BRACKET", "T_EQUAL", "T_PLUS_EQUAL", "T_MINUS_EQUAL", - "T_MULTIPLY_EQUAL", "T_DIVIDE_EQUAL", "T_COMMA", "T_ABSTRACT", "T_LOCAL", - "T_OBJECT", "T_INCLUDE", "T_INHERITS", "'+'", "'-'", "'*'", "'/'", - "$accept", "statements", "statement", "include", "object", "$@1", "$@2", + "T_IDENTIFIER", "T_OPEN_PARENTHESIS", "T_CLOSE_PARENTHESIS", + "T_OPEN_BRACE", "T_CLOSE_BRACE", "T_OPEN_BRACKET", "T_CLOSE_BRACKET", + "T_EQUAL", "T_PLUS_EQUAL", "T_MINUS_EQUAL", "T_MULTIPLY_EQUAL", + "T_DIVIDE_EQUAL", "T_COMMA", "T_ABSTRACT", "T_LOCAL", "T_OBJECT", + "T_INCLUDE", "T_INHERITS", "'+'", "'-'", "'*'", "'/'", "$accept", + "statements", "statement", "include", "object", "$@1", "$@2", "attributes", "attribute", "inherits_list", "inherits_item", "inherits_specifier", "expressionlist", "$@3", "expressions", - "expression", "operator", "simplevalue", "value", "array", "$@4", - "arrayitems", 0 + "expression", "operator", "simplevalue", "value", "tuple", "$@4", + "tupleitem", "tupleitems", 0 }; #endif @@ -578,18 +581,18 @@ static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 43, 45, 42, 47 + 275, 276, 277, 278, 43, 45, 42, 47 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { - 0, 26, 27, 27, 28, 28, 29, 31, 32, 30, - 33, 33, 34, 34, 35, 35, 36, 37, 37, 39, - 38, 40, 40, 40, 41, 41, 41, 42, 42, 42, - 42, 42, 43, 43, 43, 44, 44, 44, 46, 45, - 47, 47, 47 + 0, 28, 29, 29, 30, 30, 31, 33, 34, 32, + 35, 35, 36, 36, 37, 37, 38, 39, 39, 41, + 40, 42, 42, 42, 43, 43, 43, 44, 44, 44, + 44, 44, 45, 45, 45, 46, 46, 46, 48, 47, + 49, 50, 50, 50 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ @@ -599,7 +602,7 @@ static const yytype_uint8 yyr2[] = 0, 2, 1, 1, 1, 3, 1, 0, 2, 0, 4, 0, 1, 3, 3, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 4, - 0, 1, 3 + 1, 0, 1, 3 }; /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. @@ -610,9 +613,9 @@ static const yytype_uint8 yydefact[] = 2, 7, 1, 0, 3, 5, 4, 10, 6, 0, 12, 13, 0, 11, 0, 8, 17, 0, 0, 16, 18, 14, 19, 9, 0, 21, 15, 26, 0, 0, - 22, 0, 27, 28, 29, 30, 31, 0, 20, 0, + 22, 0, 27, 28, 29, 30, 31, 0, 20, 21, 0, 32, 33, 34, 38, 37, 35, 24, 36, 23, - 0, 40, 0, 41, 0, 25, 39, 0, 42 + 0, 41, 0, 40, 42, 0, 25, 41, 39, 43 }; /* YYDEFGOTO[NTERM-NUM]. */ @@ -620,28 +623,28 @@ static const yytype_int8 yydefgoto[] = { -1, 1, 4, 5, 6, 7, 16, 9, 13, 20, 21, 18, 45, 25, 29, 30, 37, 46, 47, 48, - 51, 54 + 51, 54, 55 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -30 +#define YYPACT_NINF -41 static const yytype_int8 yypact[] = { - -30, 0, -30, 4, -30, -30, -30, -30, -30, 13, - -30, -30, 19, -30, 24, -30, 15, 26, 31, -30, - 21, -30, -30, -30, 26, 20, -30, -30, -1, -7, - -30, 36, -30, -30, -30, -30, -30, 12, -30, 20, - 32, -30, -30, -30, -30, -30, -30, -30, -30, -30, - -9, 30, 12, -30, 8, -30, -30, 30, -30 + -41, 0, -41, -1, -41, -41, -41, -41, -41, 9, + -41, -41, 7, -41, 13, -41, 8, 29, 24, -41, + 17, -41, -41, -41, 29, 12, -41, -41, -10, 26, + 19, 31, -41, -41, -41, -41, -41, 5, -41, 12, + 27, -41, -41, -41, -41, -41, -41, -41, -41, -41, + 10, 16, 5, -41, 20, 32, -41, 16, -41, -41 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, - 16, -30, 23, -30, -30, 5, -5, -29, -6, -30, - -30, -30 + -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, + 18, -41, 23, -41, 4, -41, -6, -40, -7, -41, + -41, -41, -11 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -650,38 +653,38 @@ static const yytype_int8 yypgoto[] = #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { - 2, 38, 32, 33, 34, 35, 36, 8, 31, 39, - 32, 33, 34, 35, 36, 41, 42, 43, 56, 22, - 3, 44, 53, 27, 57, 14, 28, 15, 58, 19, - 10, 11, 12, 41, 42, 43, 17, 24, 22, 40, - 26, 23, 50, 0, 49, 52, 55 + 2, 31, 8, 32, 33, 34, 35, 36, 41, 42, + 43, 53, 44, 14, 22, 27, 15, 53, 28, 41, + 42, 43, 3, 32, 33, 34, 35, 36, 10, 11, + 12, 17, 19, 22, 40, 24, 38, 39, 57, 50, + 58, 23, 26, 49, 52, 56, 59 }; #define yypact_value_is_default(yystate) \ - ((yystate) == (-30)) + ((yystate) == (-41)) #define yytable_value_is_error(yytable_value) \ YYID (0) -static const yytype_int8 yycheck[] = +static const yytype_uint8 yycheck[] = { - 0, 8, 11, 12, 13, 14, 15, 3, 9, 16, - 11, 12, 13, 14, 15, 3, 4, 5, 10, 7, - 20, 9, 51, 3, 16, 6, 6, 3, 57, 3, - 17, 18, 19, 3, 4, 5, 21, 16, 7, 3, - 24, 18, 10, -1, 39, 50, 52 + 0, 11, 3, 13, 14, 15, 16, 17, 3, 4, + 5, 51, 7, 6, 9, 3, 3, 57, 6, 3, + 4, 5, 22, 13, 14, 15, 16, 17, 19, 20, + 21, 23, 3, 9, 3, 18, 10, 18, 18, 12, + 8, 18, 24, 39, 50, 52, 57 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 27, 0, 20, 28, 29, 30, 31, 3, 33, - 17, 18, 19, 34, 6, 3, 32, 21, 37, 3, - 35, 36, 7, 38, 16, 39, 36, 3, 6, 40, - 41, 9, 11, 12, 13, 14, 15, 42, 8, 16, - 3, 3, 4, 5, 9, 38, 43, 44, 45, 41, - 10, 46, 42, 43, 47, 44, 10, 16, 43 + 0, 29, 0, 22, 30, 31, 32, 33, 3, 35, + 19, 20, 21, 36, 6, 3, 34, 23, 39, 3, + 37, 38, 9, 40, 18, 41, 38, 3, 6, 42, + 43, 11, 13, 14, 15, 16, 17, 44, 10, 18, + 3, 3, 4, 5, 7, 40, 45, 46, 47, 42, + 12, 48, 44, 45, 49, 50, 46, 18, 8, 50 }; #define yyerrok (yyerrstatus = 0) @@ -1578,7 +1581,6 @@ yyreduce: /* Line 1806 of yacc.c */ #line 119 "config_parser.yy" { - m_Object = make_shared(); m_Abstract = false; m_Local = false; } @@ -1587,12 +1589,10 @@ yyreduce: case 8: /* Line 1806 of yacc.c */ -#line 125 "config_parser.yy" +#line 124 "config_parser.yy" { - m_Type = (yyvsp[(4) - (5)].text); + m_Object = make_shared((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc.first_line); free((yyvsp[(4) - (5)].text)); - - m_Name = (yyvsp[(5) - (5)].text); free((yyvsp[(5) - (5)].text)); } break; @@ -1600,37 +1600,36 @@ yyreduce: case 9: /* Line 1806 of yacc.c */ -#line 133 "config_parser.yy" +#line 130 "config_parser.yy" { Object::Ptr exprl_object = *(yyvsp[(8) - (8)].variant); delete (yyvsp[(8) - (8)].variant); ExpressionList::Ptr exprl = dynamic_pointer_cast(exprl_object); - Expression typeexpr("__type", OperatorSet, m_Type); + Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc.first_line); exprl->AddExpression(typeexpr); - Expression nameexpr("__name", OperatorSet, m_Name); + Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc.first_line); exprl->AddExpression(nameexpr); - Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0); + Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc.first_line); exprl->AddExpression(abstractexpr); - Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0); + Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc.first_line); exprl->AddExpression(localexpr); m_Object->SetExpressionList(exprl); - m_Objects[pair(m_Type, m_Name)] = m_Object; - - free((yyvsp[(4) - (8)].text)); - free((yyvsp[(5) - (8)].text)); + DConfigObject::AddObject(m_Object); + m_Objects.insert(m_Object); + m_Object.reset(); } break; case 12: /* Line 1806 of yacc.c */ -#line 164 "config_parser.yy" +#line 160 "config_parser.yy" { m_Abstract = true; } @@ -1639,7 +1638,7 @@ yyreduce: case 13: /* Line 1806 of yacc.c */ -#line 168 "config_parser.yy" +#line 164 "config_parser.yy" { m_Local = true; } @@ -1648,7 +1647,7 @@ yyreduce: case 16: /* Line 1806 of yacc.c */ -#line 178 "config_parser.yy" +#line 174 "config_parser.yy" { m_Object->AddParent((yyvsp[(1) - (1)].text)); } @@ -1657,7 +1656,7 @@ yyreduce: case 19: /* Line 1806 of yacc.c */ -#line 188 "config_parser.yy" +#line 184 "config_parser.yy" { m_ExpressionLists.push(make_shared()); } @@ -1666,7 +1665,7 @@ yyreduce: case 20: /* Line 1806 of yacc.c */ -#line 193 "config_parser.yy" +#line 189 "config_parser.yy" { (yyval.variant) = new Variant(m_ExpressionLists.top()); m_ExpressionLists.pop(); @@ -1676,9 +1675,9 @@ yyreduce: case 24: /* Line 1806 of yacc.c */ -#line 205 "config_parser.yy" +#line 201 "config_parser.yy" { - Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant)); + Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc.first_line); free((yyvsp[(1) - (3)].text)); delete (yyvsp[(3) - (3)].variant); @@ -1689,16 +1688,16 @@ yyreduce: case 25: /* Line 1806 of yacc.c */ -#line 213 "config_parser.yy" +#line 209 "config_parser.yy" { - Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant)); + Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc.first_line); free((yyvsp[(3) - (6)].text)); delete (yyvsp[(6) - (6)].variant); ExpressionList::Ptr subexprl = make_shared(); subexprl->AddExpression(subexpr); - Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl); + Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl, yylloc.first_line); m_ExpressionLists.top()->AddExpression(expr); } @@ -1707,9 +1706,9 @@ yyreduce: case 26: /* Line 1806 of yacc.c */ -#line 226 "config_parser.yy" +#line 222 "config_parser.yy" { - Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text)); + Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text), yylloc.first_line); free((yyvsp[(1) - (1)].text)); m_ExpressionLists.top()->AddExpression(expr); @@ -1719,7 +1718,7 @@ yyreduce: case 31: /* Line 1806 of yacc.c */ -#line 239 "config_parser.yy" +#line 235 "config_parser.yy" { (yyval.op) = (yyvsp[(1) - (1)].op); } @@ -1728,7 +1727,7 @@ yyreduce: case 32: /* Line 1806 of yacc.c */ -#line 245 "config_parser.yy" +#line 241 "config_parser.yy" { (yyval.variant) = new Variant((yyvsp[(1) - (1)].text)); } @@ -1737,7 +1736,7 @@ yyreduce: case 33: /* Line 1806 of yacc.c */ -#line 249 "config_parser.yy" +#line 245 "config_parser.yy" { (yyval.variant) = new Variant((yyvsp[(1) - (1)].num)); } @@ -1746,7 +1745,7 @@ yyreduce: case 34: /* Line 1806 of yacc.c */ -#line 253 "config_parser.yy" +#line 249 "config_parser.yy" { (yyval.variant) = new Variant(); } @@ -1755,7 +1754,7 @@ yyreduce: case 37: /* Line 1806 of yacc.c */ -#line 261 "config_parser.yy" +#line 257 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } @@ -1764,7 +1763,7 @@ yyreduce: case 38: /* Line 1806 of yacc.c */ -#line 267 "config_parser.yy" +#line 263 "config_parser.yy" { m_Array = make_shared(); } @@ -1773,37 +1772,27 @@ yyreduce: case 39: /* Line 1806 of yacc.c */ -#line 272 "config_parser.yy" +#line 268 "config_parser.yy" { (yyval.variant) = new Variant(m_Array); m_Array.reset(); } break; - case 41: + case 40: /* Line 1806 of yacc.c */ -#line 281 "config_parser.yy" +#line 275 "config_parser.yy" { m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant)); delete (yyvsp[(1) - (1)].variant); } break; - case 42: - -/* Line 1806 of yacc.c */ -#line 286 "config_parser.yy" - { - m_Array->AddUnnamedProperty(*(yyvsp[(3) - (3)].variant)); - delete (yyvsp[(3) - (3)].variant); - } - break; - /* Line 1806 of yacc.c */ -#line 1807 "config_parser.cc" +#line 1796 "config_parser.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2041,6 +2030,6 @@ yyreturn: /* Line 2067 of yacc.c */ -#line 291 "config_parser.yy" +#line 285 "config_parser.yy" diff --git a/dyn/config_parser.h b/dyn/config_parser.h index eea7148ec..c0de4e930 100644 --- a/dyn/config_parser.h +++ b/dyn/config_parser.h @@ -41,21 +41,23 @@ T_NUMBER = 259, T_NULL = 260, T_IDENTIFIER = 261, - T_OPEN_BRACE = 262, - T_CLOSE_BRACE = 263, - T_OPEN_BRACKET = 264, - T_CLOSE_BRACKET = 265, - T_EQUAL = 266, - T_PLUS_EQUAL = 267, - T_MINUS_EQUAL = 268, - T_MULTIPLY_EQUAL = 269, - T_DIVIDE_EQUAL = 270, - T_COMMA = 271, - T_ABSTRACT = 272, - T_LOCAL = 273, - T_OBJECT = 274, - T_INCLUDE = 275, - T_INHERITS = 276 + T_OPEN_PARENTHESIS = 262, + T_CLOSE_PARENTHESIS = 263, + T_OPEN_BRACE = 264, + T_CLOSE_BRACE = 265, + T_OPEN_BRACKET = 266, + T_CLOSE_BRACKET = 267, + T_EQUAL = 268, + T_PLUS_EQUAL = 269, + T_MINUS_EQUAL = 270, + T_MULTIPLY_EQUAL = 271, + T_DIVIDE_EQUAL = 272, + T_COMMA = 273, + T_ABSTRACT = 274, + T_LOCAL = 275, + T_OBJECT = 276, + T_INCLUDE = 277, + T_INHERITS = 278 }; #endif /* Tokens. */ @@ -63,21 +65,23 @@ #define T_NUMBER 259 #define T_NULL 260 #define T_IDENTIFIER 261 -#define T_OPEN_BRACE 262 -#define T_CLOSE_BRACE 263 -#define T_OPEN_BRACKET 264 -#define T_CLOSE_BRACKET 265 -#define T_EQUAL 266 -#define T_PLUS_EQUAL 267 -#define T_MINUS_EQUAL 268 -#define T_MULTIPLY_EQUAL 269 -#define T_DIVIDE_EQUAL 270 -#define T_COMMA 271 -#define T_ABSTRACT 272 -#define T_LOCAL 273 -#define T_OBJECT 274 -#define T_INCLUDE 275 -#define T_INHERITS 276 +#define T_OPEN_PARENTHESIS 262 +#define T_CLOSE_PARENTHESIS 263 +#define T_OPEN_BRACE 264 +#define T_CLOSE_BRACE 265 +#define T_OPEN_BRACKET 266 +#define T_CLOSE_BRACKET 267 +#define T_EQUAL 268 +#define T_PLUS_EQUAL 269 +#define T_MINUS_EQUAL 270 +#define T_MULTIPLY_EQUAL 271 +#define T_DIVIDE_EQUAL 272 +#define T_COMMA 273 +#define T_ABSTRACT 274 +#define T_LOCAL 275 +#define T_OBJECT 276 +#define T_INCLUDE 277 +#define T_INHERITS 278 @@ -97,7 +101,7 @@ typedef union YYSTYPE /* Line 2068 of yacc.c */ -#line 101 "config_parser.h" +#line 105 "config_parser.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/dyn/config_parser.yy b/dyn/config_parser.yy index 354fd4e41..97c70b130 100644 --- a/dyn/config_parser.yy +++ b/dyn/config_parser.yy @@ -44,6 +44,8 @@ using namespace icinga; %token T_NUMBER %token T_NULL %token T_IDENTIFIER +%token T_OPEN_PARENTHESIS +%token T_CLOSE_PARENTHESIS %token T_OPEN_BRACE %token T_CLOSE_BRACE %token T_OPEN_BRACKET @@ -61,7 +63,7 @@ using namespace icinga; %token T_INHERITS %type simplevalue %type value -%type array +%type tuple %type expressionlist %type operator %left '+' '-' @@ -92,10 +94,8 @@ void ConfigContext::Compile(void) #define scanner (context->GetScanner()) static stack m_ExpressionLists; -static map, DConfigObject::Ptr> m_Objects; +static set m_Objects; static DConfigObject::Ptr m_Object; -static string m_Name; -static string m_Type; static bool m_Abstract; static bool m_Local; static Dictionary::Ptr m_Array; @@ -117,16 +117,13 @@ include: T_INCLUDE T_STRING object: { - m_Object = make_shared(); m_Abstract = false; m_Local = false; } attributes T_OBJECT T_IDENTIFIER T_STRING { - m_Type = $4; + m_Object = make_shared($4, $5, yylloc.first_line); free($4); - - m_Name = $5; free($5); } inherits_specifier expressionlist @@ -135,24 +132,23 @@ inherits_specifier expressionlist delete $8; ExpressionList::Ptr exprl = dynamic_pointer_cast(exprl_object); - Expression typeexpr("__type", OperatorSet, m_Type); + Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc.first_line); exprl->AddExpression(typeexpr); - Expression nameexpr("__name", OperatorSet, m_Name); + Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc.first_line); exprl->AddExpression(nameexpr); - Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0); + Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc.first_line); exprl->AddExpression(abstractexpr); - Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0); + Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc.first_line); exprl->AddExpression(localexpr); m_Object->SetExpressionList(exprl); - m_Objects[pair(m_Type, m_Name)] = m_Object; - - free($4); - free($5); + DConfigObject::AddObject(m_Object); + m_Objects.insert(m_Object); + m_Object.reset(); } ; @@ -198,12 +194,12 @@ expressionlist: T_OPEN_BRACE expressions: /* empty */ | expression - | expressions T_COMMA expression + | expression T_COMMA expressions ; expression: T_IDENTIFIER operator value { - Expression expr($1, $2, *$3); + Expression expr($1, $2, *$3, yylloc.first_line); free($1); delete $3; @@ -211,20 +207,20 @@ expression: T_IDENTIFIER operator value } | T_IDENTIFIER T_OPEN_BRACKET T_STRING T_CLOSE_BRACKET operator value { - Expression subexpr($3, $5, *$6); + Expression subexpr($3, $5, *$6, yylloc.first_line); free($3); delete $6; ExpressionList::Ptr subexprl = make_shared(); subexprl->AddExpression(subexpr); - Expression expr($1, OperatorPlus, subexprl); + Expression expr($1, OperatorPlus, subexprl, yylloc.first_line); m_ExpressionLists.top()->AddExpression(expr); } | T_STRING { - Expression expr($1, OperatorSet, $1); + Expression expr($1, OperatorSet, $1, yylloc.first_line); free($1); m_ExpressionLists.top()->AddExpression(expr); @@ -256,36 +252,34 @@ simplevalue: T_STRING ; value: simplevalue - | array + | tuple | expressionlist { $$ = $1; } ; -array: T_OPEN_BRACKET +tuple: T_OPEN_PARENTHESIS { m_Array = make_shared(); } - arrayitems - T_CLOSE_BRACKET + tupleitems + T_CLOSE_PARENTHESIS { $$ = new Variant(m_Array); m_Array.reset(); } ; -arrayitems: - /* empty */ - | simplevalue +tupleitem: simplevalue { m_Array->AddUnnamedProperty(*$1); delete $1; } - | arrayitems T_COMMA simplevalue - { - m_Array->AddUnnamedProperty(*$3); - delete $3; - } + +tupleitems: + /* empty */ + | tupleitem + | tupleitem T_COMMA tupleitems ; %% diff --git a/dyn/configcontext.cpp b/dyn/configcontext.cpp index 2bd28ed72..e3ae4b97f 100644 --- a/dyn/configcontext.cpp +++ b/dyn/configcontext.cpp @@ -24,12 +24,12 @@ void *ConfigContext::GetScanner(void) const return m_Scanner; } -void ConfigContext::SetResult(map, DConfigObject::Ptr> result) +void ConfigContext::SetResult(set result) { m_Result = result; } -map, DConfigObject::Ptr> ConfigContext::GetResult(void) const +set ConfigContext::GetResult(void) const { return m_Result; } diff --git a/dyn/configcontext.h b/dyn/configcontext.h index 026dcaf7c..2b0fd921d 100644 --- a/dyn/configcontext.h +++ b/dyn/configcontext.h @@ -31,8 +31,8 @@ public: void Compile(void); - void SetResult(map, DConfigObject::Ptr> result); - map, DConfigObject::Ptr> GetResult(void) const; + void SetResult(set result); + set GetResult(void) const; size_t ReadInput(char *buffer, size_t max_bytes); void *GetScanner(void) const; @@ -40,7 +40,7 @@ public: private: istream *m_Input; void *m_Scanner; - map, DConfigObject::Ptr> m_Result; + set m_Result; void InitializeScanner(void); void DestroyScanner(void); diff --git a/dyn/configobject.h b/dyn/configobject.h deleted file mode 100644 index 96bb6d00b..000000000 --- a/dyn/configobject.h +++ /dev/null @@ -1,35 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software Foundation * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ - -#ifndef CONFIGOBJECT_H -#define CONFIGOBJECT_H - -namespace icinga -{ - -class I2_DYN_API ConfigObject : public Object -{ -public: -private: - DynamicObject::WeakPtr m_DynamicObject; -}; - -} - -#endif /* CONFIGOBJECT_H */ \ No newline at end of file diff --git a/dyn/dconfigobject.cpp b/dyn/dconfigobject.cpp index f55103bac..0f34e3558 100644 --- a/dyn/dconfigobject.cpp +++ b/dyn/dconfigobject.cpp @@ -2,6 +2,21 @@ using namespace icinga; +DConfigObject::DConfigObject(string type, string name, long debuginfo) + : m_Type(type), m_Name(name), m_DebugInfo(debuginfo) +{ +} + +string DConfigObject::GetType(void) const +{ + return m_Type; +} + +string DConfigObject::GetName(void) const +{ + return m_Name; +} + ExpressionList::Ptr DConfigObject::GetExpressionList(void) const { return m_ExpressionList; @@ -21,3 +36,79 @@ void DConfigObject::AddParent(string parent) { m_Parents.push_back(parent); } + +Dictionary::Ptr DConfigObject::CalculateProperties(void) const +{ + Dictionary::Ptr result = make_shared(); + + vector::const_iterator it; + for (it = m_Parents.begin(); it != m_Parents.end(); it++) { + DConfigObject::Ptr parent = DConfigObject::GetObject(GetType(), *it); + + if (!parent) { + stringstream message; + message << "Parent object '" << *it << "' does not exist (in line " << m_DebugInfo << ")"; + throw domain_error(message.str()); + } + + parent->GetExpressionList()->Execute(result); + } + + m_ExpressionList->Execute(result); + + return result; +} + +ObjectSet::Ptr DConfigObject::GetAllObjects(void) +{ + static ObjectSet::Ptr allObjects; + + if (!allObjects) { + allObjects = make_shared >(); + allObjects->Start(); + } + + return allObjects; +} + +bool DConfigObject::GetTypeAndName(const DConfigObject::Ptr& object, pair *key) +{ + *key = make_pair(object->GetType(), object->GetName()); + + return true; +} + +ObjectMap, DConfigObject::Ptr>::Ptr DConfigObject::GetObjectsByTypeAndName(void) +{ + static ObjectMap, DConfigObject::Ptr>::Ptr tnmap; + + if (!tnmap) { + tnmap = make_shared, DConfigObject::Ptr> >(GetAllObjects(), &DConfigObject::GetTypeAndName); + tnmap->Start(); + } + + return tnmap; +} + +void DConfigObject::AddObject(DConfigObject::Ptr object) +{ + GetAllObjects()->AddObject(object); +} + +void DConfigObject::RemoveObject(DConfigObject::Ptr object) +{ + throw logic_error("not implemented."); +} + +DConfigObject::Ptr DConfigObject::GetObject(string type, string name) +{ + ObjectMap, DConfigObject::Ptr>::Range range; + range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name)); + + assert(distance(range.first, range.second) <= 1); + + if (range.first == range.second) + return DConfigObject::Ptr(); + else + return range.first->second; +} diff --git a/dyn/dconfigobject.h b/dyn/dconfigobject.h index eefb8922d..c5c54f382 100644 --- a/dyn/dconfigobject.h +++ b/dyn/dconfigobject.h @@ -9,18 +9,33 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; + DConfigObject(string type, string name, long debuginfo); + + string GetType(void) const; + string GetName(void) const; + vector GetParents(void) const; void AddParent(string parent); ExpressionList::Ptr GetExpressionList(void) const; void SetExpressionList(const ExpressionList::Ptr& exprl); + Dictionary::Ptr CalculateProperties(void) const; + + static ObjectSet::Ptr GetAllObjects(void); + static ObjectMap, DConfigObject::Ptr>::Ptr GetObjectsByTypeAndName(void); + static void AddObject(DConfigObject::Ptr object); + static void RemoveObject(DConfigObject::Ptr object); + static DConfigObject::Ptr GetObject(string type, string name); + private: string m_Type; string m_Name; + long m_DebugInfo; vector m_Parents; ExpressionList::Ptr m_ExpressionList; + static bool GetTypeAndName(const DConfigObject::Ptr& object, pair *key); }; diff --git a/dyn/dynamicobject.cpp b/dyn/dynamicobject.cpp index a136341a6..fc31187cb 100644 --- a/dyn/dynamicobject.cpp +++ b/dyn/dynamicobject.cpp @@ -39,11 +39,23 @@ Dictionary::Ptr DynamicObject::GetTags(void) const void DynamicObject::Commit(void) { DynamicObject::Ptr self = static_pointer_cast(shared_from_this()); - ObjectSet::GetAllObjects()->CheckObject(self); + DynamicObject::GetAllObjects()->CheckObject(self); } void DynamicObject::Unregister(void) { DynamicObject::Ptr self = static_pointer_cast(shared_from_this()); - ObjectSet::GetAllObjects()->RemoveObject(self); + DynamicObject::GetAllObjects()->RemoveObject(self); +} + +ObjectSet::Ptr DynamicObject::GetAllObjects(void) +{ + static ObjectSet::Ptr allObjects; + + if (!allObjects) { + allObjects = make_shared >(); + allObjects->Start(); + } + + return allObjects; } diff --git a/dyn/dynamicobject.h b/dyn/dynamicobject.h index d665dda2e..6813dfe54 100644 --- a/dyn/dynamicobject.h +++ b/dyn/dynamicobject.h @@ -37,6 +37,8 @@ public: void Commit(void); void Unregister(void); + static ObjectSet::Ptr GetAllObjects(void); + private: Dictionary::Ptr m_Config; Dictionary::Ptr m_Tags; diff --git a/dyn/expression.cpp b/dyn/expression.cpp index 344db4436..26aa4e719 100644 --- a/dyn/expression.cpp +++ b/dyn/expression.cpp @@ -21,31 +21,61 @@ using namespace icinga; -Expression::Expression(string key, ExpressionOperator op, Variant value) +Expression::Expression(string key, ExpressionOperator op, Variant value, long debuginfo) + : Key(key), Operator(op), Value(value), DebugInfo(debuginfo) { - Key = key; - Operator = op; - Value = value; } -void Expression::Execute(const Dictionary::Ptr& dictionary) +void Expression::Execute(const Dictionary::Ptr& dictionary) const { Variant oldValue, newValue; dictionary->GetProperty(Key, &oldValue); + ExpressionList::Ptr exprl; + if (Value.GetType() == VariantObject) + exprl = dynamic_pointer_cast(Value.GetObject()); + + newValue = Value; + switch (Operator) { case OperatorSet: - if (oldValue.GetType() == VariantObject) { - Object::Ptr object = oldValue; - ExpressionList::Ptr exprl = dynamic_pointer_cast(object); - - if (exprl) - newValue = exprl->Execute(); + if (exprl) { + Dictionary::Ptr dict = make_shared(); + exprl->Execute(dict); + newValue = dict; } - default: - assert(!"Not yet implemented."); + break; + case OperatorPlus: + if (exprl) { + Dictionary::Ptr dict; + if (oldValue.GetType() == VariantObject) + dict = dynamic_pointer_cast(oldValue.GetObject()); + + if (!dict) { + if (!oldValue.IsEmpty()) { + stringstream message; + message << "Wrong argument types for += (non-dictionary and dictionary) (in line " << DebugInfo << ")"; + throw domain_error(message.str()); + } + + dict = make_shared(); + } + + exprl->Execute(dict); + newValue = dict; + } else { + stringstream message; + message << "+= only works for dictionaries (in line " << DebugInfo << ")"; + throw domain_error(message.str()); + } + + break; + + default: + break; + //assert(!"Not yet implemented."); } dictionary->SetProperty(Key, newValue); diff --git a/dyn/expression.h b/dyn/expression.h index 08d55b6ab..cf7053e61 100644 --- a/dyn/expression.h +++ b/dyn/expression.h @@ -37,10 +37,11 @@ struct I2_DYN_API Expression string Key; ExpressionOperator Operator; Variant Value; + long DebugInfo; - Expression(string key, ExpressionOperator op, Variant value); + Expression(string key, ExpressionOperator op, Variant value, long debuginfo); - void Execute(const Dictionary::Ptr& dictionary); + void Execute(const Dictionary::Ptr& dictionary) const; }; } diff --git a/dyn/expressionlist.cpp b/dyn/expressionlist.cpp index 4a9e17f2d..c9d504875 100644 --- a/dyn/expressionlist.cpp +++ b/dyn/expressionlist.cpp @@ -35,3 +35,11 @@ size_t ExpressionList::GetLength(void) const return m_Expressions.size(); } +void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const +{ + vector::const_iterator it; + + for (it = m_Expressions.begin(); it != m_Expressions.end(); it++) { + it->Execute(dictionary); + } +} diff --git a/dyn/expressionlist.h b/dyn/expressionlist.h index e82fce0ac..527ec9e0c 100644 --- a/dyn/expressionlist.h +++ b/dyn/expressionlist.h @@ -34,8 +34,7 @@ public: void AddExpression(const Expression& expression); - Dictionary::Ptr Execute(void) const; - Dictionary::Ptr Execute(Dictionary::Ptr input) const; + void Execute(const Dictionary::Ptr& dictionary) const; size_t GetLength(void) const; diff --git a/dyn/i2-dyn.h b/dyn/i2-dyn.h index 3abbf6e02..970d3f889 100644 --- a/dyn/i2-dyn.h +++ b/dyn/i2-dyn.h @@ -39,9 +39,9 @@ #include "expression.h" #include "expressionlist.h" -#include "dynamicobject.h" #include "objectset.h" #include "objectmap.h" +#include "dynamicobject.h" #include "dconfigobject.h" #include "configcontext.h" diff --git a/dyn/objectmap.cpp b/dyn/objectmap.cpp index 5c70bf8c4..87e29b3c1 100644 --- a/dyn/objectmap.cpp +++ b/dyn/objectmap.cpp @@ -21,73 +21,3 @@ using namespace icinga; -ObjectMap::ObjectMap(const ObjectSet::Ptr& parent, ObjectKeyGetter keygetter) - : m_Parent(parent), m_KeyGetter(keygetter) -{ - assert(m_Parent); - assert(m_KeyGetter); -} - -void ObjectMap::Start(void) -{ - m_Parent->OnObjectAdded += bind_weak(&ObjectMap::ObjectAddedHandler, shared_from_this()); - m_Parent->OnObjectCommitted += bind_weak(&ObjectMap::ObjectCommittedHandler, shared_from_this()); - m_Parent->OnObjectRemoved += bind_weak(&ObjectMap::ObjectRemovedHandler, shared_from_this()); - - for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++) - AddObject(*it); -} - -void ObjectMap::AddObject(const Object::Ptr& object) -{ - string key; - if (!m_KeyGetter(object, &key)) - return; - - m_Objects.insert(pair(key, object)); -} - -void ObjectMap::RemoveObject(const Object::Ptr& object) -{ - string key; - if (!m_KeyGetter(object, &key)) - return; - - pair range = GetRange(key); - - for (Iterator i = range.first; i != range.second; i++) { - if (i->second == object) { - m_Objects.erase(i); - break; - } - } -} - -void ObjectMap::CheckObject(const Object::Ptr& object) -{ - RemoveObject(object); - AddObject(object); -} - -ObjectMap::Range ObjectMap::GetRange(string key) -{ - return m_Objects.equal_range(key); -} - -int ObjectMap::ObjectAddedHandler(const ObjectSetEventArgs& ea) -{ - AddObject(ea.Target); - return 0; -} - -int ObjectMap::ObjectCommittedHandler(const ObjectSetEventArgs& ea) -{ - CheckObject(ea.Target); - return 0; -} - -int ObjectMap::ObjectRemovedHandler(const ObjectSetEventArgs& ea) -{ - RemoveObject(ea.Target); - return 0; -} diff --git a/dyn/objectmap.h b/dyn/objectmap.h index 8cd14a7b5..d4d96da71 100644 --- a/dyn/objectmap.h +++ b/dyn/objectmap.h @@ -23,35 +23,95 @@ namespace icinga { -typedef function ObjectKeyGetter; - +template class I2_DYN_API ObjectMap : public Object { public: - typedef shared_ptr Ptr; - typedef weak_ptr WeakPtr; + typedef shared_ptr > Ptr; + typedef weak_ptr > WeakPtr; - typedef multimap::iterator Iterator; + typedef typename multimap::iterator Iterator; typedef pair Range; - ObjectMap(const ObjectSet::Ptr& parent, ObjectKeyGetter keygetter); + ObjectMap(const typename ObjectSet::Ptr& parent, + function keygetter) + : m_Parent(parent), m_KeyGetter(keygetter) + { + assert(m_Parent); + assert(m_KeyGetter); + } - void Start(void); + void Start(void) + { + m_Parent->OnObjectAdded += bind_weak(&ObjectMap::ObjectAddedHandler, shared_from_this()); + m_Parent->OnObjectCommitted += bind_weak(&ObjectMap::ObjectCommittedHandler, shared_from_this()); + m_Parent->OnObjectRemoved += bind_weak(&ObjectMap::ObjectRemovedHandler, shared_from_this()); - Range GetRange(string key); + for (typename ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++) + AddObject(*it); + } + + Range GetRange(TKey key) + { + return m_Objects.equal_range(key); + } private: - multimap m_Objects; - ObjectSet::Ptr m_Parent; - ObjectKeyGetter m_KeyGetter; + multimap m_Objects; + typename ObjectSet::Ptr m_Parent; + function m_KeyGetter; - void AddObject(const Object::Ptr& object); - void RemoveObject(const Object::Ptr& object); - void CheckObject(const Object::Ptr& object); + void AddObject(const TValue& object) + { + TKey key; + if (!m_KeyGetter(object, &key)) + return; - int ObjectAddedHandler(const ObjectSetEventArgs& ea); - int ObjectCommittedHandler(const ObjectSetEventArgs& ea); - int ObjectRemovedHandler(const ObjectSetEventArgs& ea); + m_Objects.insert(make_pair(key, object)); + } + + void RemoveObject(const TValue& object) + { + TKey key; + if (!m_KeyGetter(object, &key)) + return; + + pair range = GetRange(key); + + for (Iterator i = range.first; i != range.second; i++) { + if (i->second == object) { + m_Objects.erase(i); + break; + } + } + } + + void CheckObject(const TValue& object) + { + RemoveObject(object); + AddObject(object); + } + + int ObjectAddedHandler(const ObjectSetEventArgs& ea) + { + AddObject(ea.Target); + + return 0; + } + + int ObjectCommittedHandler(const ObjectSetEventArgs& ea) + { + CheckObject(ea.Target); + + return 0; + } + + int ObjectRemovedHandler(const ObjectSetEventArgs& ea) + { + RemoveObject(ea.Target); + + return 0; + } }; } diff --git a/dyn/objectset.cpp b/dyn/objectset.cpp index 47ed599bb..87e29b3c1 100644 --- a/dyn/objectset.cpp +++ b/dyn/objectset.cpp @@ -21,105 +21,3 @@ using namespace icinga; -ObjectSet::ObjectSet(void) - : m_Parent(), m_Filter() -{ -} - -ObjectSet::ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter) - : m_Parent(parent), m_Filter(filter) -{ -} - -void ObjectSet::Start(void) -{ - if (m_Parent) { - m_Parent->OnObjectAdded += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this()); - m_Parent->OnObjectCommitted += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this()); - m_Parent->OnObjectRemoved += bind_weak(&ObjectSet::ObjectRemovedHandler, shared_from_this()); - - for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++) - CheckObject(*it); - } -} - -void ObjectSet::AddObject(const Object::Ptr& object) -{ - m_Objects.insert(object); - - ObjectSetEventArgs ea; - ea.Source = shared_from_this(); - ea.Target = object; - OnObjectAdded(ea); -} - -void ObjectSet::RemoveObject(const Object::Ptr& object) -{ - ObjectSet::Iterator it = m_Objects.find(object); - - if (it != m_Objects.end()) { - m_Objects.erase(it); - - ObjectSetEventArgs ea; - ea.Source = shared_from_this(); - ea.Target = object; - OnObjectRemoved(ea); - } -} - -bool ObjectSet::Contains(const Object::Ptr& object) const -{ - ObjectSet::Iterator it = m_Objects.find(object); - - return !(it == m_Objects.end()); -} - -void ObjectSet::CheckObject(const Object::Ptr& object) -{ - if (m_Filter && !m_Filter(object)) - RemoveObject(object); - else { - if (!Contains(object)) - AddObject(object); - else { - ObjectSetEventArgs ea; - ea.Source = shared_from_this(); - ea.Target = object; - OnObjectCommitted(ea); - } - } -} - -int ObjectSet::ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea) -{ - CheckObject(ea.Target); - return 0; -} - -int ObjectSet::ObjectRemovedHandler(const ObjectSetEventArgs& ea) -{ - RemoveObject(ea.Target); - return 0; -} - -ObjectSet::Iterator ObjectSet::Begin(void) -{ - return m_Objects.begin(); -} - -ObjectSet::Iterator ObjectSet::End(void) -{ - return m_Objects.end(); -} - -ObjectSet::Ptr ObjectSet::GetAllObjects(void) -{ - static ObjectSet::Ptr allObjects; - - if (!allObjects) { - allObjects = make_shared(); - allObjects->Start(); - } - - return allObjects; -} \ No newline at end of file diff --git a/dyn/objectset.h b/dyn/objectset.h index a8377ca93..770b12f0e 100644 --- a/dyn/objectset.h +++ b/dyn/objectset.h @@ -23,51 +23,125 @@ namespace icinga { +template struct ObjectSetEventArgs : public EventArgs { - Object::Ptr Target; + TValue Target; }; -typedef function ObjectPredicate; - +template class I2_DYN_API ObjectSet : public Object { public: - typedef shared_ptr Ptr; - typedef weak_ptr WeakPtr; + typedef shared_ptr > Ptr; + typedef weak_ptr > WeakPtr; - typedef set::iterator Iterator; + typedef typename set::iterator Iterator; - ObjectSet(void); - ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter); + ObjectSet(void) + : m_Parent(), m_Predicate() + { } - void Start(void); + ObjectSet(const typename ObjectSet::Ptr& parent, function predicate) + : m_Parent(parent), m_Predicate(predicate) + { } - void AddObject(const Object::Ptr& object); - void RemoveObject(const Object::Ptr& object); - bool Contains(const Object::Ptr& object) const; + void Start(void) + { + if (m_Parent) { + m_Parent->OnObjectAdded += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this()); + m_Parent->OnObjectCommitted += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this()); + m_Parent->OnObjectRemoved += bind_weak(&ObjectSet::ObjectRemovedHandler, shared_from_this()); - void CheckObject(const Object::Ptr& object); + for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++) + CheckObject(*it); + } - Observable OnObjectAdded; - Observable OnObjectCommitted; - Observable OnObjectRemoved; - Iterator Begin(void); - Iterator End(void); + } - static ObjectSet::Ptr GetAllObjects(void); + void AddObject(const TValue& object) + { + m_Objects.insert(object); + + ObjectSetEventArgs ea; + ea.Source = shared_from_this(); + ea.Target = object; + OnObjectAdded(ea); + } + + void RemoveObject(const TValue& object) + { + ObjectSet::Iterator it = m_Objects.find(object); + + if (it != m_Objects.end()) { + m_Objects.erase(it); + + ObjectSetEventArgs ea; + ea.Source = shared_from_this(); + ea.Target = object; + OnObjectRemoved(ea); + } + } + + bool Contains(const TValue& object) const + { + ObjectSet::Iterator it = m_Objects.find(object); + + return !(it == m_Objects.end()); + } + + void CheckObject(const TValue& object) + { + if (m_Predicate && !m_Predicate(object)) { + RemoveObject(object); + } else { + if (!Contains(object)) { + AddObject(object); + } else { + ObjectSetEventArgs ea; + ea.Source = shared_from_this(); + ea.Target = object; + OnObjectCommitted(ea); + } + } + } + + Observable > OnObjectAdded; + Observable > OnObjectCommitted; + Observable > OnObjectRemoved; + + Iterator Begin(void) + { + return m_Objects.begin(); + } + + Iterator End(void) + { + return m_Objects.end(); + } private: - set m_Objects; + set m_Objects; ObjectSet::Ptr m_Parent; - ObjectPredicate m_Filter; + function m_Predicate; - int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea); - int ObjectRemovedHandler(const ObjectSetEventArgs& ea); + int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea) + { + CheckObject(ea.Target); + + return 0; + } + + int ObjectRemovedHandler(const ObjectSetEventArgs& ea) + { + RemoveObject(ea.Target); + + return 0; + } }; } -#endif /* OBJECTSET_H */ \ No newline at end of file +#endif /* OBJECTSET_H */ diff --git a/dyntest/Makefile.am b/dyntest/Makefile.am index 8dcdc755c..6bd7b6554 100644 --- a/dyntest/Makefile.am +++ b/dyntest/Makefile.am @@ -12,6 +12,7 @@ dyntest_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ -I${top_srcdir}/dyn \ + -I${top_srcdir}/jsonrpc \ -I${top_srcdir} dyntest_LDFLAGS = \ @@ -19,4 +20,5 @@ dyntest_LDFLAGS = \ dyntest_LDADD = \ ${top_builddir}/base/libbase.la \ - ${top_builddir}/dyn/libdyn.la + ${top_builddir}/dyn/libdyn.la \ + ${top_builddir}/jsonrpc/libjsonrpc.la diff --git a/dyntest/dyntest.cpp b/dyntest/dyntest.cpp index 2372cb69c..b08dda6d2 100644 --- a/dyntest/dyntest.cpp +++ b/dyntest/dyntest.cpp @@ -1,4 +1,5 @@ #include +#include using namespace icinga; @@ -6,13 +7,19 @@ int main(int argc, char **argv) { ConfigContext ctx; ctx.Compile(); - map, DConfigObject::Ptr> objects = ctx.GetResult(); + set objects = ctx.GetResult(); for (auto it = objects.begin(); it != objects.end(); it++) { - DConfigObject::Ptr obj = it->second; - cout << "Object, name: " << it->first.second << ", type: " << it->first.first << endl; + DConfigObject::Ptr obj = *it; + cout << "Object, name: " << obj->GetName() << ", type: " << obj->GetType() << endl; cout << "\t" << obj->GetParents().size() << " parents" << endl; cout << "\t" << obj->GetExpressionList()->GetLength() << " top-level exprs" << endl; + + Dictionary::Ptr props = obj->CalculateProperties(); + cout << "\t" << props->GetLength() << " top-level properties" << endl; + + MessagePart mp(props); + cout << mp.ToJsonString() << endl; } return 0;