Skip to content

Commit

Permalink
msg-generator: sending a limited number of messages
Browse files Browse the repository at this point in the history
Signed-off-by: Terez Nemes <terez.noble@gmail.com>
  • Loading branch information
nobles committed Feb 22, 2019
1 parent e771c6b commit 290eafc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ MsgGeneratorSourceOptions *last_msg_generator_source_options;

%token KW_MSG_GENERATOR
%token KW_FREQ
%token KW_NUM
%token KW_TEMPLATE

%type <ptr> source_msg_generator
Expand Down Expand Up @@ -92,6 +93,10 @@ source_msg_generator_option
{
msg_generator_source_options_set_freq(last_msg_generator_source_options, $3);
}
| KW_NUM '(' nonnegative_integer ')'
{
msg_generator_source_options_set_num(last_msg_generator_source_options, $3);
}
| KW_TEMPLATE '(' template_content ')'
{
msg_generator_source_options_set_template(last_msg_generator_source_options, $3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static CfgLexerKeyword msg_generator_keywords[] =
{
{ "example_msg_generator", KW_MSG_GENERATOR },
{ "freq", KW_FREQ },
{ "num", KW_NUM },
{ "template", KW_TEMPLATE },
{ NULL }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct
{
LogSourceOptions super;
guint freq;
gint max_num;
LogTemplate *template;
} MsgGeneratorSourceOptions;

Expand Down Expand Up @@ -60,6 +61,12 @@ msg_generator_source_options_set_freq(MsgGeneratorSourceOptions *self, gdouble f
self->freq = (guint) (freq * 1000);
}

static inline void
msg_generator_source_options_set_num(MsgGeneratorSourceOptions *self, gint max_num)
{
self->max_num = max_num;
}

static inline void
msg_generator_source_options_set_template(MsgGeneratorSourceOptions *self, LogTemplate *template)
{
Expand Down
14 changes: 13 additions & 1 deletion modules/examples/sources/msg-generator/msg-generator-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct MsgGeneratorSource
LogSource super;
MsgGeneratorSourceOptions *options;
struct iv_timer timer;
gint num;
};

static void
Expand Down Expand Up @@ -120,7 +121,18 @@ _timer_expired(void *cookie)

_send_generated_message(self);

_start_timer(self);
if (self->options->max_num > 0)
{
self->num++;
if (self->num < self->options->max_num)
{
_start_timer(self);
}
}
else
{
_start_timer(self);
}
}

gboolean
Expand Down

0 comments on commit 290eafc

Please sign in to comment.