diff --git a/lib/api/capi.cpp b/lib/api/capi.cpp
index 3e0d9bd53..15bb45cf1 100644
--- a/lib/api/capi.cpp
+++ b/lib/api/capi.cpp
@@ -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);
@@ -411,6 +419,10 @@ extern "C" {
result = STATUS_SUCCESS;
break;
+ case EVT_OP_FLUSHANDTEARDOWN:
+ result = mat_flushAndTeardown(ctx);
+ break;
+
// Add more OPs here
default:
diff --git a/lib/include/public/CAPIClient.hpp b/lib/include/public/CAPIClient.hpp
index 01654db98..6ec397a08 100644
--- a/lib/include/public/CAPIClient.hpp
+++ b/lib/include/public/CAPIClient.hpp
@@ -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);
diff --git a/lib/include/public/mat.h b/lib/include/public/mat.h
index 949f9a338..483e48afd 100644
--- a/lib/include/public/mat.h
+++ b/lib/include/public/mat.h
@@ -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
@@ -577,6 +578,22 @@ extern "C" {
return evt_api_call(&ctx);
}
+ /**
+ * 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.
+ *
+ * SDK handle.
+ * Status code.
+ */
+ 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);
+ }
+
/**
* Save pending telemetry events to offline storage on disk.
*
diff --git a/tests/functests/APITest.cpp b/tests/functests/APITest.cpp
index 131b45e8e..c7f7817a5 100644
--- a/tests/functests/APITest.cpp
+++ b/tests/functests/APITest.cpp
@@ -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);