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 = \
+++ /dev/null
-#include "i2-configfile.h"
-
-using namespace icinga;
-
-ConfigContext::ConfigContext(istream *input)
-{
- Input = input;
- InitializeScanner();
-}
-
-ConfigContext::~ConfigContext(void)
-{
- DestroyScanner();
-}
-
#include <i2-base.h>
#include <i2-icinga.h>
-#include "configcontext.h"
#include "configfilecomponent.h"
#endif /* I2CONFIGFILECOMPONENT_H */
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 \
-#line 3 "icinga_lexer.cc"
+#line 3 "config_lexer.cc"
#define YY_INT_ALIGNED short int
#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
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;
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();
#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);
}
%{
-#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)
%}
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);
}
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
/* 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
/* 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
/* Line 2067 of yacc.c */
-#line 105 "icinga_parser.yy"
+#line 109 "icinga_parser.yy"
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())
%}
--- /dev/null
+#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;
+}
+
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);
};
# define I2_DYN_API I2_IMPORT
#endif /* I2_DYN_BUILD */
+#include "configcontext.h"
#include "dynamicdictionary.h"
#include "dynamicobject.h"
#include "objectset.h"
$(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 = \
dyntest_LDADD = \
${top_builddir}/base/libbase.la \
- ${top_builddir}/dyn/libdyn.la
+ ${top_builddir}/dyn/libdyn.la \
+ ${top_builddir}/components/configfile/configfile.la
-#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;
}