Skip to content

Commit

Permalink
Refs #20817: Move implementation of LoggingLevel in cpp
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <[email protected]>
  • Loading branch information
elianalf committed Apr 18, 2024
1 parent d35b5e6 commit 8ed9e38
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 84 deletions.
89 changes: 5 additions & 84 deletions include/fastdds/rtps/security/logging/LoggingLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef _FASTDDS_RTPS_SECURITY_LOGGING_LOGGINGLEVEL_H_
#define _FASTDDS_RTPS_SECURITY_LOGGING_LOGGINGLEVEL_H_

#include <string>

namespace eprosima {
namespace fastrtps {
Expand All @@ -43,95 +44,15 @@ enum struct LoggingLevel : long
DEBUG_LEVEL
};

inline bool string_to_LogLevel(
bool string_to_LogLevel(
const std::string& s,
LoggingLevel& l,
SecurityException& e)
{
//TODO(artivis): use an array of const char to avoid strings?
bool convert = true;
if (!s.compare("0") || !s.compare("EMERGENCY_LEVEL"))
{
l = LoggingLevel::EMERGENCY_LEVEL;
}
else if (!s.compare("1") || !s.compare("ALERT_LEVEL"))
{
l = LoggingLevel::ALERT_LEVEL;
}
else if (!s.compare("2") || !s.compare("CRITICAL_LEVEL"))
{
l = LoggingLevel::CRITICAL_LEVEL;
}
else if (!s.compare("3") || !s.compare("ERROR_LEVEL"))
{
l = LoggingLevel::ERROR_LEVEL;
}
else if (!s.compare("4") || !s.compare("WARNING_LEVEL"))
{
l = LoggingLevel::WARNING_LEVEL;
}
else if (!s.compare("5") || !s.compare("NOTICE_LEVEL"))
{
l = LoggingLevel::NOTICE_LEVEL;
}
else if (!s.compare("6") || !s.compare("INFORMATIONAL_LEVEL"))
{
l = LoggingLevel::INFORMATIONAL_LEVEL;
}
else if (!s.compare("7") || !s.compare("DEBUG_LEVEL"))
{
l = LoggingLevel::DEBUG_LEVEL;
}
else
{
e = SecurityException("Unknown LoggingLevel");
convert = false;
}

return convert;
}
SecurityException& e);

inline bool LogLevel_to_string(
bool LogLevel_to_string(
const LoggingLevel l,
std::string& s,
SecurityException& e)
{
bool convert = true;
switch (l)
{
case LoggingLevel::EMERGENCY_LEVEL:
s = "EMERGENCY";
break;
case LoggingLevel::ALERT_LEVEL:
s = "ALERT";
break;
case LoggingLevel::CRITICAL_LEVEL:
s = "CRITICAL";
break;
case LoggingLevel::ERROR_LEVEL:
s = "ERROR";
break;
case LoggingLevel::WARNING_LEVEL:
s = "WARNING";
break;
case LoggingLevel::NOTICE_LEVEL:
s = "NOTICE";
break;
case LoggingLevel::INFORMATIONAL_LEVEL:
s = "INFORMATIONAL";
break;
case LoggingLevel::DEBUG_LEVEL:
s = "DEBUG";
break;
default:
s = "UNKNOWN";
convert = false;
e = SecurityException("Unknown LoggingLevel");
break;
}

return convert;
}
SecurityException& e);

} //namespace security
} //namespace rtps
Expand Down
1 change: 1 addition & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ set(${PROJECT_NAME}_security_source_files
rtps/security/exceptions/SecurityException.cpp
rtps/security/common/SharedSecretHandle.cpp
rtps/security/logging/Logging.cpp
rtps/security/logging/LoggingLevel.cpp
rtps/security/SecurityManager.cpp
rtps/security/SecurityPluginFactory.cpp
rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp
Expand Down
120 changes: 120 additions & 0 deletions src/cpp/rtps/security/logging/LoggingLevel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright 2020 Canonical ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file LoggingLevel.cpp
*/
#include <fastdds/rtps/security/logging/LoggingLevel.h>

#include <rtps/security/exceptions/SecurityException.h>

namespace eprosima {
namespace fastrtps {
namespace rtps {
namespace security {

bool string_to_LogLevel(
const std::string& s,
LoggingLevel& l,
SecurityException& e)
{
//TODO(artivis): use an array of const char to avoid strings?
bool convert = true;
if (!s.compare("0") || !s.compare("EMERGENCY_LEVEL"))
{
l = LoggingLevel::EMERGENCY_LEVEL;
}
else if (!s.compare("1") || !s.compare("ALERT_LEVEL"))
{
l = LoggingLevel::ALERT_LEVEL;
}
else if (!s.compare("2") || !s.compare("CRITICAL_LEVEL"))
{
l = LoggingLevel::CRITICAL_LEVEL;
}
else if (!s.compare("3") || !s.compare("ERROR_LEVEL"))
{
l = LoggingLevel::ERROR_LEVEL;
}
else if (!s.compare("4") || !s.compare("WARNING_LEVEL"))
{
l = LoggingLevel::WARNING_LEVEL;
}
else if (!s.compare("5") || !s.compare("NOTICE_LEVEL"))
{
l = LoggingLevel::NOTICE_LEVEL;
}
else if (!s.compare("6") || !s.compare("INFORMATIONAL_LEVEL"))
{
l = LoggingLevel::INFORMATIONAL_LEVEL;
}
else if (!s.compare("7") || !s.compare("DEBUG_LEVEL"))
{
l = LoggingLevel::DEBUG_LEVEL;
}
else
{
e = SecurityException("Unknown LoggingLevel");
convert = false;
}

return convert;
}

bool LogLevel_to_string(
const LoggingLevel l,
std::string& s,
SecurityException& e)
{
bool convert = true;
switch (l)
{
case LoggingLevel::EMERGENCY_LEVEL:
s = "EMERGENCY";
break;
case LoggingLevel::ALERT_LEVEL:
s = "ALERT";
break;
case LoggingLevel::CRITICAL_LEVEL:
s = "CRITICAL";
break;
case LoggingLevel::ERROR_LEVEL:
s = "ERROR";
break;
case LoggingLevel::WARNING_LEVEL:
s = "WARNING";
break;
case LoggingLevel::NOTICE_LEVEL:
s = "NOTICE";
break;
case LoggingLevel::INFORMATIONAL_LEVEL:
s = "INFORMATIONAL";
break;
case LoggingLevel::DEBUG_LEVEL:
s = "DEBUG";
break;
default:
s = "UNKNOWN";
convert = false;
e = SecurityException("Unknown LoggingLevel");
break;
}

return convert;
}

} //namespace security
} //namespace rtps
} //namespace fastrtps
} //namespace eprosima
1 change: 1 addition & 0 deletions test/unittest/dds/publisher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/exceptions/SecurityException.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/common/SharedSecretHandle.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/Logging.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/LoggingLevel.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/SecurityManager.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/SecurityPluginFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/rtps/security/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(SOURCES_SECURITY_TEST_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/exceptions/SecurityException.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/Logging.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/LoggingLevel.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/SecurityManager.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/security/accesscontrol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(COMMON_SOURCES_ACCESS_CONTROL_TEST_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/common/SharedSecretHandle.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/exceptions/SecurityException.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/Logging.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/LoggingLevel.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/security/authentication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set(COMMON_SOURCES_AUTH_PLUGIN_TEST_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/common/SharedSecretHandle.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/exceptions/SecurityException.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/Logging.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/LoggingLevel.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/security/logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(COMMON_SOURCES_LOGGING_PLUGIN_TEST_SOURCE

add_executable(BuiltinLogging ${COMMON_SOURCES_LOGGING_PLUGIN_TEST_SOURCE}
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/Logging.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/LoggingLevel.cpp
${PROJECT_SOURCE_DIR}/src/cpp/security/logging/LogTopic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BuiltinLogTopicTests.cpp)

Expand Down
1 change: 1 addition & 0 deletions test/unittest/statistics/dds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX)
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/exceptions/SecurityException.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/common/SharedSecretHandle.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/Logging.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/logging/LoggingLevel.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/*.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp
${PROJECT_SOURCE_DIR}/src/cpp/security/accesscontrol/*.cpp
Expand Down

0 comments on commit 8ed9e38

Please sign in to comment.