diff --git a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems index 68bf9f142..e72742eca 100644 --- a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems +++ b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems @@ -1,208 +1,210 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - {45d41acc-2c3c-43d2-bc10-02aa73ffc7c7} - ClientTelemetry - - - - %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {45d41acc-2c3c-43d2-bc10-02aa73ffc7c7} + ClientTelemetry + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters index e86490294..6f30e6100 100644 --- a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters +++ b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters @@ -1,196 +1,198 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/api/DataViewer_CAPI.cpp b/lib/api/DataViewer_CAPI.cpp new file mode 100644 index 000000000..0b06b4b8a --- /dev/null +++ b/lib/api/DataViewer_CAPI.cpp @@ -0,0 +1,37 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +#include "DataViewer_CAPI.hpp" + + +namespace MAT_NS_BEGIN { + DataViewer_CAPI::DataViewer_CAPI(dataviewer_callback_fn_t callbackFn) + : m_callbackFn(callbackFn), + m_endpoint("DataViewer_CAPI") + { + + } + + void DataViewer_CAPI::ReceiveData(const std::vector& packetData) noexcept + { + m_callbackFn(packetData.data(), packetData.size()); + } + + const char* DataViewer_CAPI::GetName() const noexcept + { + return s_name; + } + + bool DataViewer_CAPI::IsTransmissionEnabled() const noexcept + { + return true; + } + + const std::string& DataViewer_CAPI::GetCurrentEndpoint() const noexcept + { + return m_endpoint; + } + + const char* DataViewer_CAPI::s_name = "DataViewer_CAPI"; +} MAT_NS_END \ No newline at end of file diff --git a/lib/api/DataViewer_CAPI.hpp b/lib/api/DataViewer_CAPI.hpp new file mode 100644 index 000000000..4bdbb91ca --- /dev/null +++ b/lib/api/DataViewer_CAPI.hpp @@ -0,0 +1,29 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +#ifndef DATAVIEWER_CAPI_HPP +#define DATAVIEWER_CAPI_HPP + + +#include "IDataViewer.hpp" +#include "mat.h" + +namespace MAT_NS_BEGIN { + class DataViewer_CAPI : public IDataViewer { + public: + DataViewer_CAPI(dataviewer_callback_fn_t callbackFn); + void ReceiveData(const std::vector& packetData) noexcept override; + + const char* GetName() const noexcept override; + bool IsTransmissionEnabled() const noexcept override; + const std::string& GetCurrentEndpoint() const noexcept override; + + private: + dataviewer_callback_fn_t m_callbackFn; + static const char* s_name; + std::string m_endpoint; + }; +} MAT_NS_END + +#endif // DATAVIEWER_CAPI_HPP \ No newline at end of file diff --git a/lib/api/capi.cpp b/lib/api/capi.cpp index 916c4ebda..e05a428a1 100644 --- a/lib/api/capi.cpp +++ b/lib/api/capi.cpp @@ -12,6 +12,7 @@ #include "mat.h" #include "pal/TaskDispatcher_CAPI.hpp" #include "utils/Utils.hpp" +#include "DataViewer_CAPI.hpp" #include "pal/PAL.hpp" @@ -66,14 +67,21 @@ void remove_client(evt_handle_t handle) return ENOENT; \ }; +typedef struct _evt_open_with_params_set_t +{ + http_send_fn_t httpSendFn; + http_cancel_fn_t httpCancelFn; + task_dispatcher_queue_fn_t taskDispatcherQueueFn; + task_dispatcher_cancel_fn_t taskDispatcherCancelFn; + task_dispatcher_join_fn_t taskDispatcherJoinFn; + dataviewer_callback_fn_t dataViewerCallbackFn; +} evt_open_with_params_set_t; + + evt_status_t mat_open_core( evt_context_t *ctx, const char* config, - http_send_fn_t httpSendFn, - http_cancel_fn_t httpCancelFn, - task_dispatcher_queue_fn_t taskDispatcherQueueFn, - task_dispatcher_cancel_fn_t taskDispatcherCancelFn, - task_dispatcher_join_fn_t taskDispatcherJoinFn) + evt_open_with_params_set_t openParamsSet) { if ((config == nullptr) || (config[0] == 0)) { @@ -133,11 +141,11 @@ evt_status_t mat_open_core( #if !defined (ANDROID) || defined(ENABLE_CAPI_HTTP_CLIENT) // Create custom HttpClient - if (httpSendFn != nullptr && httpCancelFn != nullptr) + if (openParamsSet.httpSendFn != nullptr && openParamsSet.httpCancelFn != nullptr) { try { - auto http = std::make_shared(httpSendFn, httpCancelFn); + auto http = std::make_shared(openParamsSet.httpSendFn, openParamsSet.httpCancelFn); clients[code].http = http; clients[code].config.AddModule(CFG_MODULE_HTTP_CLIENT, http); } @@ -148,11 +156,11 @@ evt_status_t mat_open_core( } #endif // Create custom worker thread - if (taskDispatcherQueueFn != nullptr && taskDispatcherCancelFn != nullptr && taskDispatcherJoinFn != nullptr) + if (openParamsSet.taskDispatcherQueueFn != nullptr && openParamsSet.taskDispatcherCancelFn != nullptr && openParamsSet.taskDispatcherJoinFn != nullptr) { try { - auto taskDispatcher = std::make_shared(taskDispatcherQueueFn, taskDispatcherCancelFn, taskDispatcherJoinFn); + auto taskDispatcher = std::make_shared(openParamsSet.taskDispatcherQueueFn, openParamsSet.taskDispatcherCancelFn, openParamsSet.taskDispatcherJoinFn); clients[code].taskDispatcher = taskDispatcher; clients[code].config.AddModule(CFG_MODULE_TASK_DISPATCHER, taskDispatcher); } @@ -162,6 +170,12 @@ evt_status_t mat_open_core( } } + // Add data viewer module. + if (openParamsSet.dataViewerCallbackFn != nullptr) + { + clients[code].config.AddModule(CFG_MODULE_DATA_VIEWER, std::make_shared(openParamsSet.dataViewerCallbackFn)); + } + status_t status = static_cast(EFAULT); clients[code].logmanager = LogManagerProvider::CreateLogManager(clients[code].config, status); @@ -183,7 +197,8 @@ evt_status_t mat_open(evt_context_t *ctx) }; char* config = static_cast(ctx->data); - return mat_open_core(ctx, config, nullptr, nullptr, nullptr, nullptr, nullptr); + evt_open_with_params_set_t openParamsSet = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; + return mat_open_core(ctx, config, openParamsSet); } evt_status_t mat_open_with_params(evt_context_t *ctx) @@ -199,35 +214,40 @@ evt_status_t mat_open_with_params(evt_context_t *ctx) // Invalid param data return EFAULT; } - - http_send_fn_t httpSendFn = nullptr; - http_cancel_fn_t httpCancelFn = nullptr; - task_dispatcher_queue_fn_t taskDispatcherQueueFn = nullptr; - task_dispatcher_cancel_fn_t taskDispatcherCancelFn = nullptr; - task_dispatcher_join_fn_t taskDispatcherJoinFn = nullptr; + + evt_open_with_params_set_t openParamsSet; + openParamsSet.httpSendFn = nullptr; + openParamsSet.httpCancelFn = nullptr; + openParamsSet.taskDispatcherQueueFn = nullptr; + openParamsSet.taskDispatcherCancelFn = nullptr; + openParamsSet.taskDispatcherJoinFn = nullptr; + openParamsSet.dataViewerCallbackFn = nullptr; for (int32_t i = 0; i < data->paramsCount; ++i) { const evt_open_param_t& param = data->params[i]; switch (param.type) { case OPEN_PARAM_TYPE_HTTP_HANDLER_SEND: - httpSendFn = reinterpret_cast(param.data); + openParamsSet.httpSendFn = reinterpret_cast(param.data); break; case OPEN_PARAM_TYPE_HTTP_HANDLER_CANCEL: - httpCancelFn = reinterpret_cast(param.data); + openParamsSet.httpCancelFn = reinterpret_cast(param.data); break; case OPEN_PARAM_TYPE_TASK_DISPATCHER_QUEUE: - taskDispatcherQueueFn = reinterpret_cast(param.data); + openParamsSet.taskDispatcherQueueFn = reinterpret_cast(param.data); break; case OPEN_PARAM_TYPE_TASK_DISPATCHER_CANCEL: - taskDispatcherCancelFn = reinterpret_cast(param.data); + openParamsSet.taskDispatcherCancelFn = reinterpret_cast(param.data); break; case OPEN_PARAM_TYPE_TASK_DISPATCHER_JOIN: - taskDispatcherJoinFn = reinterpret_cast(param.data); + openParamsSet.taskDispatcherJoinFn = reinterpret_cast(param.data); + break; + case OPEN_PARAM_TYPE_DATA_VIEWER: + openParamsSet.dataViewerCallbackFn = reinterpret_cast(param.data); break; } } - return mat_open_core(ctx, data->config, httpSendFn, httpCancelFn, taskDispatcherQueueFn, taskDispatcherCancelFn, taskDispatcherJoinFn); + return mat_open_core(ctx, data->config, openParamsSet); } /** diff --git a/lib/include/public/mat.h b/lib/include/public/mat.h index 535e0ac3a..e3a22ce0b 100644 --- a/lib/include/public/mat.h +++ b/lib/include/public/mat.h @@ -140,6 +140,7 @@ extern "C" { OPEN_PARAM_TYPE_TASK_DISPATCHER_QUEUE = 2, OPEN_PARAM_TYPE_TASK_DISPATCHER_CANCEL = 3, OPEN_PARAM_TYPE_TASK_DISPATCHER_JOIN = 4, + OPEN_PARAM_TYPE_DATA_VIEWER = 5, } evt_open_param_type_t; /** @@ -280,6 +281,9 @@ extern "C" { typedef bool (EVTSDK_LIBABI_CDECL *task_dispatcher_cancel_fn_t)(const char* /*taskId*/); typedef void (EVTSDK_LIBABI_CDECL *task_dispatcher_join_fn_t)(); + /* Dataviewer callback function signatures */ + typedef void (EVTSDK_LIBABI_CDECL *dataviewer_callback_fn_t)(const uint8_t* /*data*/, size_t /*size*/); + #if (_MSC_VER == 1500) || (_MSC_VER == 1600) || (defined(__cplusplus) && !defined(__GNUG__)) /* Code to support C89 compiler, including VS2010 */ #define TELEMETRY_EVENT(...) { __VA_ARGS__ , { NULL, TYPE_NULL } } @@ -638,4 +642,4 @@ extern "C" { #include "CAPIClient.hpp" #endif -#endif +#endif \ No newline at end of file