Move method

This commit is contained in:
Uwe Seimet 2023-10-01 10:16:16 +02:00
parent 0d7beabdf0
commit 8b89736b50
5 changed files with 15 additions and 29 deletions

View File

@ -14,6 +14,7 @@
#include <cassert>
#include <sstream>
#include <iomanip>
#include <stdexcept>
using namespace std;
@ -24,17 +25,6 @@ Device::Device(PbDeviceType type, int lun) : type(type), lun(lun)
revision = os.str();
}
PbDeviceType Device::ParseDeviceType(const string& value)
{
string t;
ranges::transform(value, back_inserter(t), ::toupper);
if (PbDeviceType type; PbDeviceType_Parse(t, &type)) {
return type;
}
throw parser_exception("Illegal device type '" + value + "'");
}
void Device::Reset()
{
locked = false;

View File

@ -95,7 +95,6 @@ public:
virtual ~Device() = default;
static PbDeviceType ParseDeviceType(const string&);
PbDeviceType GetType() const { return type; }
string GetTypeString() const { return PbDeviceType_Name(type); }
string GetIdentifier() const { return GetTypeString() + " " + to_string(GetId()) + ":" + to_string(lun); }

View File

@ -209,7 +209,7 @@ string Piscsi::ParseArguments(span<char *> args, PbCommand& command, int& port,
continue;
case 't':
type = Device::ParseDeviceType(optarg);
type = ParseDeviceType(optarg);
continue;
case 1:
@ -254,6 +254,17 @@ string Piscsi::ParseArguments(span<char *> args, PbCommand& command, int& port,
return locale;
}
PbDeviceType Piscsi::ParseDeviceType(const string& value)
{
string t;
ranges::transform(value, back_inserter(t), ::toupper);
if (PbDeviceType type; PbDeviceType_Parse(t, &type)) {
return type;
}
throw parser_exception("Illegal device type '" + value + "'");
}
bool Piscsi::SetLogLevel(const string& log_level) const
{
int id = -1;

View File

@ -57,6 +57,8 @@ private:
const shared_ptr<spdlog::logger> logger = spdlog::stdout_color_mt("piscsi stdout logger");
static PbDeviceType ParseDeviceType(const string&);
// Processing flag
atomic_bool target_is_active;

View File

@ -8,7 +8,6 @@
//---------------------------------------------------------------------------
#include "mocks.h"
#include "shared/piscsi_exceptions.h"
#include "devices/device.h"
TEST(DeviceTest, Properties)
@ -115,21 +114,6 @@ TEST(DeviceTest, Properties)
EXPECT_EQ(LUN, device.GetLun());
}
TEST(DeviceTest, ParseDeviceType)
{
EXPECT_EQ(SCHD, Device::ParseDeviceType("schd"));
EXPECT_EQ(SCRM, Device::ParseDeviceType("scrm"));
EXPECT_EQ(SCMO, Device::ParseDeviceType("SCMO"));
EXPECT_EQ(SCCD, Device::ParseDeviceType("scCd"));
EXPECT_EQ(SCHS, Device::ParseDeviceType("SChS"));
EXPECT_EQ(SCBR, Device::ParseDeviceType("SCBR"));
EXPECT_EQ(SCDP, Device::ParseDeviceType("SCDP"));
EXPECT_EQ(SCLP, Device::ParseDeviceType("sclp"));
EXPECT_THROW(Device::ParseDeviceType("foo"), parser_exception);
EXPECT_THROW(Device::ParseDeviceType(""), parser_exception);
}
TEST(DeviceTest, GetTypeString)
{
MockDevice schd(SCHD);