Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose FlushAndTearDown API in C-API #1198

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/api/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ evt_status_t mat_upload(evt_context_t *ctx)
return result;
}

evt_status_t mat_flushAndTeardown(evt_context_t *ctx)
{
VERIFY_CLIENT_HANDLE(client, ctx);
client->logmanager->FlushAndTeardown();
ctx->result = STATUS_SUCCESS;
return STATUS_SUCCESS;
}

evt_status_t mat_flush(evt_context_t *ctx)
{
VERIFY_CLIENT_HANDLE(client, ctx);
Expand Down Expand Up @@ -411,6 +419,9 @@ extern "C" {
result = STATUS_SUCCESS;
break;

case EVT_OP_FLUSHANDTEARDOWN:
result = mat_flushAndTeardown(ctx);
break;
// Add more OPs here

default:
Expand Down
5 changes: 5 additions & 0 deletions lib/include/public/CAPIClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ namespace MAT_NS_BEGIN
return evt_upload(handle);
}

evt_status_t flushAndTeardown()
{
return evt_flushAndTeardown(handle);
}

evt_status_t flush()
{
return evt_flush(handle);
Expand Down
19 changes: 18 additions & 1 deletion lib/include/public/mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extern "C" {
EVT_OP_FLUSH = 0x0000000A,
EVT_OP_VERSION = 0x0000000B,
EVT_OP_OPEN_WITH_PARAMS = 0x0000000C,
EVT_OP_MAX = EVT_OP_OPEN_WITH_PARAMS + 1
EVT_OP_FLUSHANDTEARDOWN = 0x0000000D,
EVT_OP_MAX = EVT_OP_OPEN_WITH_PARAMS + 1,
} evt_call_t;

typedef enum evt_prop_t
Expand Down Expand Up @@ -576,6 +577,22 @@ extern "C" {
ctx.handle = handle;
return evt_api_call(&ctx);
}

/** <summary>
* Flush any pending telemetry events in memory to disk,
* attempt upload of events if tear down interval is configured,
* and eventually tear down the telemetry logging system.
* </summary>
shivpratap1992 marked this conversation as resolved.
Show resolved Hide resolved
* <param name="handle">SDK handle.</param>
* <returns>Status code.</returns>
*/
static inline evt_status_t evt_flushAndTeardown(evt_handle_t handle)
{
evt_context_t ctx;
ctx.call = EVT_OP_FLUSHANDTEARDOWN;
ctx.handle = handle;
return evt_api_call(&ctx);
}

/** <summary>
* Save pending telemetry events to offline storage on disk.
Expand Down
1 change: 1 addition & 0 deletions tests/functests/APITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ TEST(APITest, C_API_Test)

// Must remove event listener befor closing the handle!
client->logmanager->RemoveEventListener(EVT_LOG_EVENT, debugListener);
evt_flushAndTeardown(handle);
evt_close(handle);
ASSERT_EQ(capi_get_client(handle), nullptr);

Expand Down
Loading