Skip to content

Commit 02c276d

Browse files
Expose FlushAndTearDown API in C-API (#1198)
* Add C-API * Test
1 parent 6129741 commit 02c276d

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

lib/api/capi.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ evt_status_t mat_upload(evt_context_t *ctx)
329329
return result;
330330
}
331331

332+
evt_status_t mat_flushAndTeardown(evt_context_t *ctx)
333+
{
334+
VERIFY_CLIENT_HANDLE(client, ctx);
335+
client->logmanager->FlushAndTeardown();
336+
ctx->result = STATUS_SUCCESS;
337+
return STATUS_SUCCESS;
338+
}
339+
332340
evt_status_t mat_flush(evt_context_t *ctx)
333341
{
334342
VERIFY_CLIENT_HANDLE(client, ctx);
@@ -411,6 +419,9 @@ extern "C" {
411419
result = STATUS_SUCCESS;
412420
break;
413421

422+
case EVT_OP_FLUSHANDTEARDOWN:
423+
result = mat_flushAndTeardown(ctx);
424+
break;
414425
// Add more OPs here
415426

416427
default:

lib/include/public/CAPIClient.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ namespace MAT_NS_BEGIN
7474
return evt_upload(handle);
7575
}
7676

77+
evt_status_t flushAndTeardown()
78+
{
79+
return evt_flushAndTeardown(handle);
80+
}
81+
7782
evt_status_t flush()
7883
{
7984
return evt_flush(handle);

lib/include/public/mat.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ extern "C" {
5959
EVT_OP_FLUSH = 0x0000000A,
6060
EVT_OP_VERSION = 0x0000000B,
6161
EVT_OP_OPEN_WITH_PARAMS = 0x0000000C,
62-
EVT_OP_MAX = EVT_OP_OPEN_WITH_PARAMS + 1
62+
EVT_OP_FLUSHANDTEARDOWN = 0x0000000D,
63+
EVT_OP_MAX = EVT_OP_OPEN_WITH_PARAMS + 1,
6364
} evt_call_t;
6465

6566
typedef enum evt_prop_t
@@ -576,6 +577,22 @@ extern "C" {
576577
ctx.handle = handle;
577578
return evt_api_call(&ctx);
578579
}
580+
581+
/** <summary>
582+
* Flush any pending telemetry events in memory to disk,
583+
* attempt upload of events if tear down interval is configured,
584+
* and eventually tear down the telemetry logging system.
585+
* </summary>
586+
* <param name="handle">SDK handle.</param>
587+
* <returns>Status code.</returns>
588+
*/
589+
static inline evt_status_t evt_flushAndTeardown(evt_handle_t handle)
590+
{
591+
evt_context_t ctx;
592+
ctx.call = EVT_OP_FLUSHANDTEARDOWN;
593+
ctx.handle = handle;
594+
return evt_api_call(&ctx);
595+
}
579596

580597
/** <summary>
581598
* Save pending telemetry events to offline storage on disk.

tests/functests/APITest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ TEST(APITest, C_API_Test)
725725

726726
// Must remove event listener befor closing the handle!
727727
client->logmanager->RemoveEventListener(EVT_LOG_EVENT, debugListener);
728+
evt_flushAndTeardown(handle);
728729
evt_close(handle);
729730
ASSERT_EQ(capi_get_client(handle), nullptr);
730731

0 commit comments

Comments
 (0)