RASCSI/src/raspberrypi/devices/primary_device.h
Uwe Seimet 05db0e4688
Fix simple SonarCloud issues (#834)
* Fixing SonarCloud issues, first round

* Fixing SonarCLoud issues, next round

* Fixing SonarQube issues, next round

* Fixed warning

* Replaced empty constructors/destructors with = default;

* Fixed warning

* Replaced new

* Use constants instead of macros

* Use structured binding declarations

* Use init statements for if

* Use string views

* Use enum class, use using instead of typedef

* Fixed more SonarCloud warnings

* Replaced redundant/duplicate types with auto

* Devlared methods const

* Memory management update

* Fixed warning

* Added missing const

* Improved RaScsiResponse memory management

* Improved memory management

* Improved memory management

* Replaced macros by constants, removed unused constants

* Made member private

* Fixed warning

* Added comment

* Fixed shadowing warnings

* Cleanup

* Cleanup

* Cleanup

* Fixed shadowing warning

* Removed unused code

* Fixed more warnings

* Removed obsolete casts

* Fixed warnings

* Removed unused field

* Removed library not needed by rasctl

* Include cleanup

* Updated platform check for better compatibility

* Improved check for invalid option. This prevents rasctl to break on macos.

* Updated option check

* Fixed typo

* Added TODO

* Removed macro

* Scope update

* Replaced macro

* Added TODO, update memory management

* Fixed typo

* Replaced NULL by nullptr

* Use more structured bindings

* Added TODO

* Use calloc instead of mallco to not need memset

* Fixed warnings

* Fixed SonarQube initialization issues

* Fixed warning

* Cleaned up override/virtual/final

* Fixed warnings

* Constructor update

* Fixed tests

* Improved memory management

* Added missing const

* Added const

* Fixed two bugs reported by SonarCloud

* Fix SonarCloud hotspot

* Fixed memory management

* Memory management update

* Addressing hotspot by using strncpy

* Fixed SonarCloud issues

* Fixed SonarQube issues

* Added missing const

* Added const

* Added const

* Suppress false positive

* Added SonarQube suppressions for false positives

* Added suppresoin

* Fixed code smells

* Reverted changes that is a SonarQube issue, but caused problems with -O3

* Removed TODO based on review
2022-09-07 09:38:42 -05:00

59 lines
1.5 KiB
C++

//---------------------------------------------------------------------------
//
// SCSI Target Emulator RaSCSI Reloaded
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
//
// A device implementing mandatory SCSI primary commands, to be used for subclassing
//
//---------------------------------------------------------------------------
#pragma once
#include "interfaces/scsi_primary_commands.h"
#include "controllers/scsi_controller.h"
#include "device.h"
#include "dispatcher.h"
#include <string>
using namespace std;
class PrimaryDevice: public Device, virtual public ScsiPrimaryCommands
{
public:
explicit PrimaryDevice(const string&);
~PrimaryDevice() override = default;
bool Dispatch() override;
void SetController(AbstractController *);
virtual bool WriteByteSequence(BYTE *, uint32_t);
virtual int GetSendDelay() const { return BUS::SEND_NO_DELAY; }
protected:
vector<BYTE> HandleInquiry(scsi_defs::device_type, scsi_level, bool) const;
virtual vector<BYTE> InquiryInternal() const = 0;
void CheckReady();
void EnterStatusPhase() { controller->Status(); }
void EnterDataInPhase() { controller->DataIn(); }
void EnterDataOutPhase() { controller->DataOut(); }
AbstractController *controller = nullptr;
AbstractController::ctrl_t *ctrl = nullptr;
private:
void TestUnitReady() override;
void RequestSense() override;
void ReportLuns() override;
void Inquiry() override;
vector<BYTE> HandleRequestSense();
Dispatcher<PrimaryDevice> dispatcher;
};