Skip to content

Commit

Permalink
examples: hello world C++: use new API model and fix JSON format
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Feb 15, 2016
1 parent bed4811 commit 6aa1a74
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions examples/hello_world_cpp/hello_world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,35 @@ int main()
int n;
int ret;
char tmp[256];
struct flb_lib_ctx *ctx;
flb_ctx_t *ctx;
flb_input_t *input;
flb_output_t *output;

/* Initialize library */
ctx = flb_lib_init(NULL, (char *) "stdout", NULL);
if (!ctx) {
exit(EXIT_FAILURE);
}
ctx = flb_create();

input = flb_input(ctx, "lib", NULL);
flb_input_set(input, "test");

/* Verbose mode */
/*
flb_config_verbose(FLB_TRUE);
*/
output = flb_output(ctx, "stdout", NULL);
flb_output_set(output, "test");

/* Start the background worker */
flb_lib_start(ctx);
flb_start(ctx);

/* Push some data */
for (i = 0; i < 100; i++) {
n = snprintf(tmp, sizeof(tmp) - 1, "{\"key\": \"val %i\"}", i);
flb_lib_push(ctx, tmp, n);
n = snprintf(tmp, sizeof(tmp) - 1,
"[%lu, {\"key\": \"val %i\"}]",
time(NULL), i);
printf("%s\n", tmp);
flb_lib_push(input, tmp, n);
}

flb_lib_stop(ctx);
flb_stop(ctx);

/* Release Resources */
flb_lib_exit(ctx);
flb_destroy(ctx);

return 0;
}

0 comments on commit 6aa1a74

Please sign in to comment.