Skip to content

Commit 9ac31e7

Browse files
Fix clang-tidy warnings
Signed-off-by: Rahul Bramandlapalli <rbramand@amd.com>
1 parent e617963 commit 9ac31e7

4 files changed

Lines changed: 51 additions & 37 deletions

File tree

src/runtime_src/core/common/detail/linux/syslog.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88
#include <map>
99
#include <syslog.h>
1010

11-
namespace xrt_core { namespace message {
11+
namespace xrt_core::message {
1212

1313
class syslog_dispatch : public message_dispatch
1414
{
1515
public:
1616
syslog_dispatch()
1717
{ openlog("sdaccel", LOG_PID|LOG_CONS, LOG_USER); }
1818

19-
~syslog_dispatch()
19+
syslog_dispatch(const syslog_dispatch&) = delete;
20+
syslog_dispatch& operator=(const syslog_dispatch&) = delete;
21+
syslog_dispatch(syslog_dispatch&&) = delete;
22+
syslog_dispatch& operator=(syslog_dispatch&&) = delete;
23+
24+
~syslog_dispatch() override
2025
{ closelog(); }
2126

2227
void
@@ -36,4 +41,4 @@ class syslog_dispatch : public message_dispatch
3641
};
3742
};
3843

39-
}} // xrt_core::message
44+
} // xrt_core::message

src/runtime_src/core/common/detail/windows/syslog.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
#include "core/common/message.h"
1919

20+
#include <array>
2021
#include <iostream>
2122
#include <string>
2223
#include <windows.h>
2324

24-
namespace xrt_core { namespace message {
25+
namespace xrt_core::message {
2526

2627
class syslog_dispatch : public message_dispatch
2728
{
@@ -41,7 +42,12 @@ class syslog_dispatch : public message_dispatch
4142
<< "(error " << GetLastError() << "). Logging disabled.\n";
4243
}
4344

44-
~syslog_dispatch()
45+
syslog_dispatch(const syslog_dispatch&) = delete;
46+
syslog_dispatch& operator=(const syslog_dispatch&) = delete;
47+
syslog_dispatch(syslog_dispatch&&) = delete;
48+
syslog_dispatch& operator=(syslog_dispatch&&) = delete;
49+
50+
~syslog_dispatch() override
4551
{
4652
if (m_handle)
4753
DeregisterEventSource(m_handle);
@@ -54,37 +60,32 @@ class syslog_dispatch : public message_dispatch
5460
return;
5561

5662
std::string full_msg = std::string("[") + tag + "] : " + msg;
57-
LPCSTR strings[] = {full_msg.c_str()};
63+
std::array<LPCSTR, 1> strings = {full_msg.c_str()};
5864
// Event ID 1 matches the pass-through entry in EventCreate.exe's message
5965
// table (%1), so Event Viewer displays our text directly without a warning.
6066
// Severity filtering uses wType (Level column), not event ID.
6167
static constexpr DWORD event_id = 1;
6268
ReportEventA(m_handle, to_event_type(l), 0, event_id,
63-
nullptr, 1, 0, strings, nullptr);
69+
nullptr, 1, 0, strings.data(), nullptr);
6470
}
6571

6672
private:
6773
HANDLE m_handle = nullptr;
6874

6975
// Maps XRT severity to Windows event type (controls icon in Event Viewer):
70-
// EVENTLOG_ERROR_TYPE -> red X
76+
// EVENTLOG_ERROR_TYPE -> red X (emergency/alert/critical/error)
7177
// EVENTLOG_WARNING_TYPE -> yellow triangle
72-
// EVENTLOG_INFORMATION_TYPE -> blue i
78+
// EVENTLOG_INFORMATION_TYPE -> blue i (notice/info/debug)
7379
static WORD
7480
to_event_type(severity_level l)
7581
{
76-
switch (l) {
77-
case severity_level::emergency:
78-
case severity_level::alert:
79-
case severity_level::critical:
80-
case severity_level::error:
81-
return EVENTLOG_ERROR_TYPE;
82-
case severity_level::warning:
82+
if (l == severity_level::warning)
8383
return EVENTLOG_WARNING_TYPE;
84-
default:
85-
return EVENTLOG_INFORMATION_TYPE;
86-
}
84+
if (l == severity_level::emergency || l == severity_level::alert ||
85+
l == severity_level::critical || l == severity_level::error)
86+
return EVENTLOG_ERROR_TYPE;
87+
return EVENTLOG_INFORMATION_TYPE;
8788
}
8889
};
8990

90-
}} // xrt_core::message
91+
} // xrt_core::message

src/runtime_src/core/common/message.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,23 @@ send(severity_level l, const char* tag, const char* msg)
166166

167167
namespace xrt_core { namespace message {
168168

169-
message_dispatch*
169+
std::unique_ptr<message_dispatch>
170170
message_dispatch::
171171
make_dispatcher(const std::string& choice)
172172
{
173173
if ((choice == "null") || (choice == ""))
174-
return new null_dispatch;
175-
else if (choice == "console")
176-
return new console_dispatch;
177-
else if (choice == "syslog")
178-
return new syslog_dispatch;
179-
else {
180-
if (choice.front() == '"') {
181-
std::string file = choice;
182-
file.erase(0, 1);
183-
file.erase(file.size()-1);
184-
return new file_dispatch(file);
185-
}
186-
return new file_dispatch(choice);
174+
return std::make_unique<null_dispatch>();
175+
if (choice == "console")
176+
return std::make_unique<console_dispatch>();
177+
if (choice == "syslog")
178+
return std::make_unique<syslog_dispatch>();
179+
180+
std::string file = choice;
181+
if (file.front() == '"') {
182+
file.erase(0, 1);
183+
file.erase(file.size()-1);
187184
}
185+
return std::make_unique<file_dispatch>(file);
188186
}
189187

190188
void
@@ -195,7 +193,7 @@ send(severity_level l, const char* tag, const char* msg)
195193
int lev = static_cast<int>(l);
196194

197195
if(ver >= lev) {
198-
static message_dispatch* dispatcher = message_dispatch::make_dispatcher(logger);
196+
static auto dispatcher = message_dispatch::make_dispatcher(logger);
199197
dispatcher->send(l, tag, msg);
200198
}
201199
}

src/runtime_src/core/common/message.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "core/common/config_reader.h"
99
#include "core/include/xrt.h"
1010
#include "core/include/xrt/experimental/xrt_message.h"
11+
#include <memory>
1112
#include <string>
1213
#include <cstdio>
1314
#include <vector>
@@ -19,9 +20,18 @@ using severity_level = xrt::message::level;
1920
class message_dispatch
2021
{
2122
public:
23+
message_dispatch() = default;
24+
message_dispatch(const message_dispatch&) = delete;
25+
message_dispatch& operator=(const message_dispatch&) = delete;
26+
message_dispatch(message_dispatch&&) = delete;
27+
message_dispatch& operator=(message_dispatch&&) = delete;
2228
virtual ~message_dispatch() = default;
23-
static message_dispatch* make_dispatcher(const std::string& choice);
24-
virtual void send(severity_level l, const char* tag, const char* msg) = 0;
29+
30+
static std::unique_ptr<message_dispatch>
31+
make_dispatcher(const std::string& choice);
32+
33+
virtual void
34+
send(severity_level l, const char* tag, const char* msg) = 0;
2535
};
2636

2737
XRT_CORE_COMMON_EXPORT

0 commit comments

Comments
 (0)