Skip to content

Commit

Permalink
Merge pull request #213 from MrAnno/fix-app-parser-meta
Browse files Browse the repository at this point in the history
appmodel: filterx-related fixes
  • Loading branch information
bazsi authored Jul 23, 2024
2 parents 1799eb8 + ed46b97 commit 28a7e99
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
40 changes: 27 additions & 13 deletions modules/appmodel/app-parser-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct _AppParserGenerator
{
AppObjectGenerator super;
const gchar *topic;
const gchar *filterx_app_variable;
GString *block;
gboolean first_app_generated;
gboolean allow_overlaps;
Expand Down Expand Up @@ -60,6 +61,13 @@ _parse_allow_overlaps(AppParserGenerator *self, CfgArgs *args, const gchar *refe
return TRUE;
}

static gboolean
_parse_filterx_app_variable(AppParserGenerator *self, CfgArgs *args, const gchar *reference)
{
self->filterx_app_variable = cfg_args_get(args, "filterx-app-variable");
return TRUE;
}

static gboolean
app_parser_generator_parse_arguments(AppObjectGenerator *s, CfgArgs *args, const gchar *reference)
{
Expand All @@ -72,6 +80,9 @@ app_parser_generator_parse_arguments(AppObjectGenerator *s, CfgArgs *args, const
if (!_parse_allow_overlaps(self, args, reference))
return FALSE;

if (!_parse_filterx_app_variable(self, args, reference))
return FALSE;

if (!app_object_generator_parse_arguments_method(&self->super, args, reference))
return FALSE;

Expand Down Expand Up @@ -139,20 +150,23 @@ _generate_action(AppParserGenerator *self, Application *app)
if (self->allow_overlaps)
return;

if (app->filterx_expr)
g_string_append_printf(self->block,
" filterx {\n"
" meta.app_name = '%s';\n"
" };\n",
app->super.name);

if (self->filterx_app_variable)
{
g_string_append_printf(self->block,
" filterx {\n"
" %s = '%s';\n"
" };\n",
self->filterx_app_variable, app->super.name);
}
else
g_string_append_printf(self->block,
" rewrite {\n"
" set-tag('.app.%s');\n"
" set('%s' value('.app.name'));\n"
" };\n",
app->super.name, app->super.name);
{
g_string_append_printf(self->block,
" rewrite {\n"
" set-tag('.app.%s');\n"
" set('%s' value('.app.name'));\n"
" };\n",
app->super.name, app->super.name);
}
}

static void
Expand Down
20 changes: 19 additions & 1 deletion modules/appmodel/app-transform-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef struct _AppTransformGenerator
{
AppObjectGenerator super;
const gchar *flavour;
const gchar *filterx_app_variable;
GString *block;
} AppTransformGenerator;

Expand All @@ -41,6 +42,19 @@ _parse_transforms_arg(AppTransformGenerator *self, CfgArgs *args, const gchar *r
return TRUE;
}

static gboolean
_parse_filterx_app_variable(AppTransformGenerator *self, CfgArgs *args, const gchar *reference)
{
self->filterx_app_variable = cfg_args_get(args, "filterx-app-variable");
if (!self->filterx_app_variable)
{
msg_error("app-transform() requires a filterx-app-variable() argument",
evt_tag_str("reference", reference));
return FALSE;
}
return TRUE;
}

static gboolean
app_transform_generator_parse_arguments(AppObjectGenerator *s, CfgArgs *args, const gchar *reference)
{
Expand All @@ -50,6 +64,9 @@ app_transform_generator_parse_arguments(AppObjectGenerator *s, CfgArgs *args, co
if (!_parse_transforms_arg(self, args, reference))
return FALSE;

if (!_parse_filterx_app_variable(self, args, reference))
return FALSE;

if (!app_object_generator_parse_arguments_method(&self->super, args, reference))
return FALSE;

Expand Down Expand Up @@ -82,7 +99,8 @@ _generate_app_transform(Transformation *transformation, gpointer user_data)
return;

g_string_append_printf(self->block, "\n#Start Application %s\n", transformation->super.name);
g_string_append_printf(self->block, " if (meta.app_name == '%s') {\n", transformation->super.name);
g_string_append_printf(self->block, " if (%s == '%s') {\n", self->filterx_app_variable,
transformation->super.name);
for (GList *l = transformation->blocks; l; l = l->next)
{
TransformationBlock *block = l->data;
Expand Down

0 comments on commit 28a7e99

Please sign in to comment.