struct side_tracer_dynamic_struct_visitor_ctx {
enum side_visitor_status (*write_field)(
const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
- const struct side_arg_dynamic_event_struct *dynamic_struct);
+ const struct side_arg_dynamic_event_field *dynamic_field);
void *priv; /* Private tracer context. */
};
}
}
+static side_define_event(my_provider_event_dynamic_struct_visitor,
+ "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG,
+ side_field_list(
+ side_field("dynamic", SIDE_TYPE_DYNAMIC),
+ )
+);
+
+struct struct_visitor_pair {
+ const char *name;
+ uint32_t value;
+};
+
+struct app_dynamic_struct_visitor_ctx {
+ const struct struct_visitor_pair *ptr;
+ uint32_t length;
+};
+
+static
+enum side_visitor_status test_dynamic_struct_visitor(const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, void *_ctx)
+{
+ struct app_dynamic_struct_visitor_ctx *ctx = (struct app_dynamic_struct_visitor_ctx *) _ctx;
+ uint32_t length = ctx->length, i;
+
+ for (i = 0; i < length; i++) {
+ struct side_arg_dynamic_event_field dynamic_field = {
+ .field_name = ctx->ptr[i].name,
+ .elem = {
+ .dynamic_type = SIDE_DYNAMIC_TYPE_U32,
+ .u = {
+ .side_u32 = ctx->ptr[i].value,
+ },
+ },
+ };
+ if (tracer_ctx->write_field(tracer_ctx, &dynamic_field) != SIDE_VISITOR_STATUS_OK)
+ return SIDE_VISITOR_STATUS_ERROR;
+ }
+ return SIDE_VISITOR_STATUS_OK;
+}
+
+static struct struct_visitor_pair testarray_dynamic_struct[] = {
+ { "a", 1, },
+ { "b", 2, },
+ { "c", 3, },
+ { "d", 4, },
+};
+
+static
+void test_dynamic_struct_with_visitor(void)
+{
+ my_provider_event_dynamic_struct_visitor.enabled = 1;
+ side_event_cond(&my_provider_event_dynamic_struct_visitor) {
+ struct app_dynamic_struct_visitor_ctx ctx = {
+ .ptr = testarray_dynamic_struct,
+ .length = SIDE_ARRAY_SIZE(testarray_dynamic_struct),
+ };
+ side_event_call(&my_provider_event_dynamic_struct_visitor,
+ side_arg_list(
+ side_arg_dynamic(
+ side_arg_dynamic_struct_visitor(test_dynamic_struct_visitor, &ctx)
+ )
+ )
+ );
+ }
+}
+
int main()
{
test_fields();
test_bool();
test_dynamic_bool();
test_dynamic_vla_with_visitor();
+ test_dynamic_struct_with_visitor();
return 0;
}
printf(" ]");
}
+struct tracer_dynamic_struct_visitor_priv {
+ int i;
+};
+
+static
+enum side_visitor_status tracer_dynamic_struct_write_elem_cb(
+ const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
+ const struct side_arg_dynamic_event_field *dynamic_field)
+{
+ struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv;
+
+ printf("%s", tracer_priv->i++ ? ", " : "");
+ printf("%s:: ", dynamic_field->field_name);
+ tracer_print_dynamic(&dynamic_field->elem);
+ return SIDE_VISITOR_STATUS_OK;
+}
+
static
void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec *item)
{
- //TODO
+ enum side_visitor_status status;
+ struct tracer_dynamic_struct_visitor_priv tracer_priv = {
+ .i = 0,
+ };
+ const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = {
+ .write_field = tracer_dynamic_struct_write_elem_cb,
+ .priv = &tracer_priv,
+ };
+ void *app_ctx = item->u.side_dynamic_struct_visitor.app_ctx;
+
+ printf("[ ");
+ status = item->u.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx);
+ switch (status) {
+ case SIDE_VISITOR_STATUS_OK:
+ break;
+ case SIDE_VISITOR_STATUS_ERROR:
+ printf("ERROR: Visitor error\n");
+ abort();
+ }
+ printf(" ]");
}
static
abort();
}
printf(" ]");
-
}
static