Skip to content

Commit

Permalink
Add DataViewer to CAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayodeji Ige committed Nov 27, 2024
1 parent f02d236 commit 85b115d
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 427 deletions.
418 changes: 210 additions & 208 deletions Solutions/Clienttelemetry/Clienttelemetry.vcxitems

Large diffs are not rendered by default.

394 changes: 198 additions & 196 deletions Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions lib/api/DataViewer_CAPI.cpp
Original file line number Diff line number Diff line change
@@ -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<uint8_t>& 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
29 changes: 29 additions & 0 deletions lib/api/DataViewer_CAPI.hpp
Original file line number Diff line number Diff line change
@@ -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<uint8_t>& 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
64 changes: 42 additions & 22 deletions lib/api/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "mat.h"
#include "pal/TaskDispatcher_CAPI.hpp"
#include "utils/Utils.hpp"
#include "DataViewer_CAPI.hpp"

#include "pal/PAL.hpp"

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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<HttpClient_CAPI>(httpSendFn, httpCancelFn);
auto http = std::make_shared<HttpClient_CAPI>(openParamsSet.httpSendFn, openParamsSet.httpCancelFn);
clients[code].http = http;
clients[code].config.AddModule(CFG_MODULE_HTTP_CLIENT, http);
}
Expand All @@ -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<PAL::TaskDispatcher_CAPI>(taskDispatcherQueueFn, taskDispatcherCancelFn, taskDispatcherJoinFn);
auto taskDispatcher = std::make_shared<PAL::TaskDispatcher_CAPI>(openParamsSet.taskDispatcherQueueFn, openParamsSet.taskDispatcherCancelFn, openParamsSet.taskDispatcherJoinFn);
clients[code].taskDispatcher = taskDispatcher;
clients[code].config.AddModule(CFG_MODULE_TASK_DISPATCHER, taskDispatcher);
}
Expand All @@ -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<DataViewer_CAPI>(openParamsSet.dataViewerCallbackFn));
}

status_t status = static_cast<status_t>(EFAULT);
clients[code].logmanager = LogManagerProvider::CreateLogManager(clients[code].config, status);

Expand All @@ -183,7 +197,8 @@ evt_status_t mat_open(evt_context_t *ctx)
};

char* config = static_cast<char *>(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)
Expand All @@ -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<http_send_fn_t>(param.data);
openParamsSet.httpSendFn = reinterpret_cast<http_send_fn_t>(param.data);
break;
case OPEN_PARAM_TYPE_HTTP_HANDLER_CANCEL:
httpCancelFn = reinterpret_cast<http_cancel_fn_t>(param.data);
openParamsSet.httpCancelFn = reinterpret_cast<http_cancel_fn_t>(param.data);
break;
case OPEN_PARAM_TYPE_TASK_DISPATCHER_QUEUE:
taskDispatcherQueueFn = reinterpret_cast<task_dispatcher_queue_fn_t>(param.data);
openParamsSet.taskDispatcherQueueFn = reinterpret_cast<task_dispatcher_queue_fn_t>(param.data);
break;
case OPEN_PARAM_TYPE_TASK_DISPATCHER_CANCEL:
taskDispatcherCancelFn = reinterpret_cast<task_dispatcher_cancel_fn_t>(param.data);
openParamsSet.taskDispatcherCancelFn = reinterpret_cast<task_dispatcher_cancel_fn_t>(param.data);
break;
case OPEN_PARAM_TYPE_TASK_DISPATCHER_JOIN:
taskDispatcherJoinFn = reinterpret_cast<task_dispatcher_join_fn_t>(param.data);
openParamsSet.taskDispatcherJoinFn = reinterpret_cast<task_dispatcher_join_fn_t>(param.data);
break;
case OPEN_PARAM_TYPE_DATA_VIEWER:
openParamsSet.dataViewerCallbackFn = reinterpret_cast<dataviewer_callback_fn_t>(param.data);
break;
}
}

return mat_open_core(ctx, data->config, httpSendFn, httpCancelFn, taskDispatcherQueueFn, taskDispatcherCancelFn, taskDispatcherJoinFn);
return mat_open_core(ctx, data->config, openParamsSet);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/include/public/mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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 } }
Expand Down Expand Up @@ -638,4 +642,4 @@ extern "C" {
#include "CAPIClient.hpp"
#endif

#endif
#endif

0 comments on commit 85b115d

Please sign in to comment.