Skip to content
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
12 changes: 12 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,10 @@ 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_FLUSHANDTEARDOWN + 1,
} evt_call_t;

typedef enum evt_prop_t
Expand Down Expand Up @@ -577,6 +578,22 @@ extern "C" {
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>
* <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.
* </summary>
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