-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseModuleSystemContext.cpp
More file actions
92 lines (78 loc) · 2.88 KB
/
Copy pathBaseModuleSystemContext.cpp
File metadata and controls
92 lines (78 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Copyright (C) 2021-2026 Advanced Micro Devices, Inc. All rights reserved. */
#include <BaseModuleSystemContext.h>
#include <g_InfoClient.h>
// =======================================================================================
BaseModuleSystemContext::BaseModuleSystemContext(
const DDModuleSystemContextCreateInfo& createInfo)
: m_createInfo(createInfo)
, m_logger(createInfo.loader)
{
}
// =======================================================================================
BaseModuleSystemContext::~BaseModuleSystemContext()
{
}
// =======================================================================================
DD_RESULT BaseModuleSystemContext::Initialize()
{
// Return success by default
return DD_RESULT_SUCCESS;
}
// =======================================================================================
void BaseModuleSystemContext::HandleEvent(
DD_MODULE_SYSTEM_EVENT eventId,
const void* pEventData,
size_t eventDataSize)
{
// Do nothing by default
DD_API_UNUSED(eventId);
DD_API_UNUSED(pEventData);
DD_API_UNUSED(eventDataSize);
}
// =======================================================================================
DD_RESULT BaseModuleSystemContext::QuerySystemInfo(
DDModuleSystemContext hSystemContext,
void* pUserdata,
PFN_ddReceiveText pfnReceiveJson)
{
DD_RESULT result = DD_RESULT_COMMON_INVALID_PARAMETER;
if ((hSystemContext != DD_API_INVALID_HANDLE) && (pfnReceiveJson != nullptr))
{
BaseModuleSystemContext* pContext = reinterpret_cast<BaseModuleSystemContext*>(hSystemContext);
result = pContext->QuerySystemInfoImpl(pUserdata, pfnReceiveJson);
}
return result;
}
// =======================================================================================
DD_RESULT BaseModuleSystemContext::QuerySystemInfoImpl(
void* pUserdata,
PFN_ddReceiveText pfnReceiveJson)
{
DD_RESULT result = DD_RESULT_COMMON_INVALID_PARAMETER;
if (pfnReceiveJson != nullptr)
{
Info::InfoClient client;
DDRpcClientCreateInfo clientInfo = {};
clientInfo.clientId = m_createInfo.systemClients[DD_MODULE_SYSTEM_CLIENT_TYPE_ROUTER].id;
clientInfo.hConnection = m_createInfo.connection;
result = client.Connect(clientInfo);
if (result == DD_RESULT_SUCCESS)
{
DynamicBufferByteWriter dynamicWriter;
result = client.QueryInfoAll(*dynamicWriter.Writer());
if (result == DD_RESULT_SUCCESS)
{
const char* pJson = dynamicWriter.DataAsString();
if (pJson != nullptr)
{
pfnReceiveJson(pUserdata, pJson);
}
else
{
result = DD_RESULT_PARSING_INVALID_JSON;
}
}
}
}
return result;
}