Skip to content

Commit

Permalink
Reformat with Eclipse formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 10, 2023
1 parent 1420449 commit 769b95e
Show file tree
Hide file tree
Showing 140 changed files with 12,321 additions and 11,511 deletions.
142 changes: 71 additions & 71 deletions cpp/base/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,118 +21,118 @@ Device::Device(PbDeviceType type, int lun) : type(type), lun(lun)

void Device::Reset()
{
locked = false;
attn = false;
reset = false;
locked = false;
attn = false;
reset = false;
}

void Device::SetProtected(bool b)
{
if (protectable && !read_only) {
write_protected = b;
}
if (protectable && !read_only) {
write_protected = b;
}
}

void Device::SetVendor(const string& v)
void Device::SetVendor(const string &v)
{
if (v.empty() || v.length() > 8) {
throw invalid_argument("Vendor '" + v + "' must have between 1 and 8 characters");
}
if (v.empty() || v.length() > 8) {
throw invalid_argument("Vendor '" + v + "' must have between 1 and 8 characters");
}

vendor = v;
vendor = v;
}

void Device::SetProduct(const string& p, bool force)
void Device::SetProduct(const string &p, bool force)
{
if (p.empty() || p.length() > 16) {
throw invalid_argument("Product '" + p + "' must have between 1 and 16 characters");
}
if (p.empty() || p.length() > 16) {
throw invalid_argument("Product '" + p + "' must have between 1 and 16 characters");
}

// Changing vital product data is not SCSI compliant
if (!product.empty() && !force) {
return;
}
// Changing vital product data is not SCSI compliant
if (!product.empty() && !force) {
return;
}

product = p;
product = p;
}

void Device::SetRevision(const string& r)
void Device::SetRevision(const string &r)
{
if (r.empty() || r.length() > 4) {
throw invalid_argument("Revision '" + r + "' must have between 1 and 4 characters");
}
if (r.empty() || r.length() > 4) {
throw invalid_argument("Revision '" + r + "' must have between 1 and 4 characters");
}

revision = r;
revision = r;
}

string Device::GetPaddedName() const
{
return fmt::format("{0:8}{1:16}{2:4}", vendor, product, revision);
}

string Device::GetParam(const string& key) const
string Device::GetParam(const string &key) const
{
const auto& it = params.find(key);
return it == params.end() ? "" : it->second;
const auto &it = params.find(key);
return it == params.end() ? "" : it->second;
}

void Device::SetParams(const param_map& set_params)
void Device::SetParams(const param_map &set_params)
{
params = GetDefaultParams();

// Devices with image file support implicitly support the "file" parameter
if (SupportsFile()) {
params["file"] = "";
}

for (const auto& [key, value] : set_params) {
// It is assumed that there are default parameters for all supported parameters
if (params.contains(key)) {
params[key] = value;
}
else {
spdlog::warn("Ignored unknown parameter '" + key + "'");
}
}
params = GetDefaultParams();

// Devices with image file support implicitly support the "file" parameter
if (SupportsFile()) {
params["file"] = "";
}

for (const auto& [key, value] : set_params) {
// It is assumed that there are default parameters for all supported parameters
if (params.contains(key)) {
params[key] = value;
}
else {
spdlog::warn("Ignored unknown parameter '" + key + "'");
}
}
}

bool Device::Start()
{
if (!ready) {
return false;
}
if (!ready) {
return false;
}

stopped = false;
stopped = false;

return true;
return true;
}

void Device::Stop()
{
ready = false;
attn = false;
stopped = true;
ready = false;
attn = false;
stopped = true;

status_code = 0;
status_code = 0;
}

bool Device::Eject(bool force)
{
if (!ready || !removable) {
return false;
}

// Must be unlocked if there is no force flag
if (!force && locked) {
return false;
}

ready = false;
attn = false;
removed = true;
write_protected = false;
locked = false;
stopped = true;

return true;
if (!ready || !removable) {
return false;
}

// Must be unlocked if there is no force flag
if (!force && locked) {
return false;
}

ready = false;
attn = false;
removed = true;
write_protected = false;
locked = false;
stopped = true;

return true;
}
Loading

0 comments on commit 769b95e

Please sign in to comment.