Added PbDevices to PbServerInfo for client convenience (#176)

* Added device list to server info

* Updated loggin

* Added comment

* Added comment

* Added comment

* Comment update

* Deprecate LIST

* Comment update

* Updated duplicate ID/unit check

* Updated logging

* Updated logging

* Unified error message handling: Errors are now consistently logged

* REview

* Added missing field initialization (reported by Eclipse IDE)

* Added some translations

* Fixed typo

Co-authored-by: akuker <akuker@gmail.com>
This commit is contained in:
Uwe Seimet 2021-08-10 03:24:56 +02:00 committed by GitHub
parent 157172b566
commit 79de9e29e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 56 deletions

View File

@ -2697,19 +2697,19 @@ BOOL CHostFcb::Close()
//===========================================================================
//
// FCB処理 マネージャ
// FCB processing manager
//
//===========================================================================
#ifdef _DEBUG
//---------------------------------------------------------------------------
//
/// デストラクタ final
// Final destructor
//
//---------------------------------------------------------------------------
CHostFcbManager::~CHostFcbManager()
{
// 実体が存在しないことを確認 (念のため)
// Confirm that the entity does not exist (just in case)
ASSERT(m_cRing.Next() == &m_cRing);
ASSERT(m_cRing.Prev() == &m_cRing);
}
@ -2717,17 +2717,17 @@ CHostFcbManager::~CHostFcbManager()
//---------------------------------------------------------------------------
//
/// 初期化 (ドライバ組込み時)
// Initialization (when the driver is installed)
//
//---------------------------------------------------------------------------
void CHostFcbManager::Init()
{
// 実体が存在しないことを確認 (念のため)
// Confirm that the entity does not exist (just in case)
ASSERT(m_cRing.Next() == &m_cRing);
ASSERT(m_cRing.Prev() == &m_cRing);
// メモリ確保
// Memory allocation
for (DWORD i = 0; i < XM6_HOST_FCB_MAX; i++) {
ring_t* p = new ring_t;
ASSERT(p);
@ -2737,13 +2737,13 @@ void CHostFcbManager::Init()
//---------------------------------------------------------------------------
//
/// 解放 (起動・リセット時)
// Clean (at startup/reset)
//
//---------------------------------------------------------------------------
void CHostFcbManager::Clean()
{
// メモリ解放
// Fast task killer
CRing* p;
while ((p = m_cRing.Next()) != &m_cRing) {
delete (ring_t*)p;
@ -2752,26 +2752,26 @@ void CHostFcbManager::Clean()
//---------------------------------------------------------------------------
//
/// 確保
// Alloc
//
//---------------------------------------------------------------------------
CHostFcb* CHostFcbManager::Alloc(DWORD nKey)
{
ASSERT(nKey);
// 末尾から選択
// Select from the end
ring_t* p = (ring_t*)m_cRing.Prev();
// 使用中ならエラー (念のため)
// Error if in use (just in case)
if (p->f.isSameKey(0) == FALSE) {
ASSERT(0);
return NULL;
}
// リング先頭へ移動
// Move to the top of the ring
p->r.Insert(&m_cRing);
// キーを設定
// Set key
p->f.SetKey(nKey);
return &p->f;
@ -2779,18 +2779,18 @@ CHostFcb* CHostFcbManager::Alloc(DWORD nKey)
//---------------------------------------------------------------------------
//
/// 検索
// Search
//
//---------------------------------------------------------------------------
CHostFcb* CHostFcbManager::Search(DWORD nKey)
{
ASSERT(nKey);
// 該当するオブジェクトを検索
// Search for applicable objects
ring_t* p = (ring_t*)m_cRing.Next();
while (p != (ring_t*)&m_cRing) {
if (p->f.isSameKey(nKey)) {
// リング先頭へ移動
// Move to the top of the ring
p->r.Insert(&m_cRing);
return &p->f;
}
@ -2802,40 +2802,40 @@ CHostFcb* CHostFcbManager::Search(DWORD nKey)
//---------------------------------------------------------------------------
//
/// 解放
// Free
//
//---------------------------------------------------------------------------
void CHostFcbManager::Free(CHostFcb* pFcb)
{
ASSERT(pFcb);
// 解放
// Free
pFcb->SetKey(0);
pFcb->Close();
// リング末尾へ移動
// Move to the end of the ring
ring_t* p = (ring_t*)((size_t)pFcb - offsetof(ring_t, f));
p->r.InsertTail(&m_cRing);
}
//===========================================================================
//
// ホスト側ファイルシステム
// Host side file system
//
//===========================================================================
DWORD CFileSys::g_nOption; ///< ファイル名変換フラグ
DWORD CFileSys::g_nOption; // File name conversion flag
//---------------------------------------------------------------------------
//
/// デフォルトコンストラクタ
// Default constructor
//
//---------------------------------------------------------------------------
CFileSys::CFileSys()
{
m_nHostSectorCount = 0;
// コンフィグデータ初期化
// Config data initialization
m_nDrives = 0;
for (size_t n = 0; n < DriveMax; n++) {

View File

@ -89,6 +89,17 @@ DWORD bcm_host_get_peripheral_address(void)
//---------------------------------------------------------------------------
GPIOBUS::GPIOBUS()
{
actmode = TARGET;
baseaddr = 0;
gicc = 0;
gicd = 0;
gpio = 0;
level = 0;
pads = 0;
irpctl = 0;
qa7regs = 0;
signals = 0;
rpitype = 0;
}
//---------------------------------------------------------------------------

View File

@ -618,8 +618,7 @@ private:
DWORD baseaddr; // Base address
int rpitype;
// Type of Raspberry Pi
int rpitype; // Type of Raspberry Pi
volatile DWORD *gpio; // GPIO register

View File

@ -267,7 +267,7 @@ void Reset()
// Get the list of attached devices
//
//---------------------------------------------------------------------------
PbDevices GetDevices() {
const PbDevices GetDevices() {
PbDevices devices;
for (int i = 0; i < CtrlMax * UnitNum; i++) {
@ -433,8 +433,12 @@ bool MapController(Disk **map)
bool ReturnStatus(int fd, bool status = true, const string msg = "")
{
if (!status && !msg.empty()) {
LOGWARN("%s", msg.c_str());
}
if (fd == -1) {
if (msg.length()) {
if (!msg.empty()) {
FPRT(stderr, "Error: ");
FPRT(stderr, msg.c_str());
FPRT(stderr, "\n");
@ -487,7 +491,7 @@ bool SetLogLevel(const string& log_level)
return true;
}
void LogDeviceList(const string& device_list)
void LogDevices(const string& device_list)
{
stringstream ss(device_list);
string line;
@ -536,10 +540,6 @@ bool ProcessCmd(int fd, const PbCommand &command)
s << "Processing: cmd=" << PbOperation_Name(cmd) << ", id=" << id << ", un=" << un << ", type=" << PbDeviceType_Name(type) << ", params=" << params;
LOGINFO("%s", s.str().c_str());
// Copy the Unit List
Disk *map[CtrlMax * UnitNum];
memcpy(map, disk, sizeof(disk));
// Check the Controller Number
if (id < 0 || id >= CtrlMax) {
error << "Invalid ID " << id << " (0-" << CtrlMax - 1 << ")";
@ -558,9 +558,13 @@ bool ProcessCmd(int fd, const PbCommand &command)
ext = params.substr(len - 3);
}
// Copy the Unit List
Disk *map[CtrlMax * UnitNum];
memcpy(map, disk, sizeof(disk));
// Connect Command
if (cmd == ATTACH) {
if (map[id]) {
if (map[id * UnitNum + un]) {
error << "Duplicate ID " << id;
return ReturnStatus(fd, false, error);
}
@ -642,7 +646,6 @@ bool ProcessCmd(int fd, const PbCommand &command)
delete pUnit;
error << "Tried to open an invalid file '" << file << "': " << e.getmsg();
LOGWARN("%s", error.str().c_str());
return ReturnStatus(fd, false, error);
}
}
@ -672,17 +675,15 @@ bool ProcessCmd(int fd, const PbCommand &command)
// Does the controller exist?
if (ctrl[id] == NULL) {
LOGWARN("Received a command for invalid controller %d", id);
return ReturnStatus(fd, false, "No such device");
error << "Received a command for invalid ID " << id;
return ReturnStatus(fd, false, error);
}
// Does the unit exist?
pUnit = disk[id * UnitNum + un];
if (pUnit == NULL) {
LOGWARN("Received a command for invalid unit ID %d UN %d", id, un);
return ReturnStatus(fd, false, "No such device");
error << "Received a command for invalid ID " << id << ", unit " << un;
return ReturnStatus(fd, false, error);
}
// Disconnect Command
@ -704,16 +705,12 @@ bool ProcessCmd(int fd, const PbCommand &command)
// Only MOs or CDs may be inserted/ejected, only MOs, CDs or hard disks may be protected
if ((cmd == INSERT || cmd == EJECT) && !pUnit->IsRemovable()) {
LOGWARN("%s requested for incompatible type %s", PbOperation_Name(cmd).c_str(), pUnit->GetID().c_str());
error << "Operation denied (Device type " << pUnit->GetID().c_str() << " isn't removable)";
error << PbOperation_Name(cmd) << " operation denied (Device type " << pUnit->GetID() << " isn't removable)";
return ReturnStatus(fd, false, error);
}
if ((cmd == PROTECT || cmd == UNPROTECT) && (!pUnit->IsProtectable() || pUnit->IsReadOnly())) {
LOGWARN("%s requested for incompatible type %s", PbOperation_Name(cmd).c_str(), pUnit->GetID().c_str());
error << "Operation denied (Device type " << pUnit->GetID().c_str() << " isn't protectable)";
error << PbOperation_Name(cmd) << " operation denied (Device type " << pUnit->GetID() << " isn't protectable)";
return ReturnStatus(fd, false, error);
}
@ -761,7 +758,6 @@ bool ProcessCmd(int fd, const PbCommand &command)
default:
error << "Received unknown command: " << PbOperation_Name(cmd);
LOGWARN("%s", error.str().c_str());
return ReturnStatus(fd, false, error);
}
@ -867,10 +863,9 @@ bool ParseArgument(int argc, char* argv[], int& port)
}
// Display and log the device list
const PbDevices devices = GetDevices();
const string device_list = ListDevices(devices);
cout << device_list << endl;
LogDeviceList(device_list);
const string devices = ListDevices(GetDevices());
cout << devices << endl;
LogDevices(devices);
return true;
}
@ -940,7 +935,7 @@ static void *MonThread(void *param)
case LIST: {
const PbDevices devices = GetDevices();
SerializeMessage(fd, devices);
LogDeviceList(ListDevices(devices));
LogDevices(ListDevices(devices));
break;
}
@ -964,6 +959,7 @@ static void *MonThread(void *param)
serverInfo.set_current_log_level(current_log_level);
serverInfo.set_default_image_folder(default_image_folder);
GetAvailableImages(serverInfo);
serverInfo.set_allocated_devices(new PbDevices(GetDevices()));
SerializeMessage(fd, serverInfo);
break;
}

View File

@ -17,9 +17,11 @@ enum PbDeviceType {
// rascsi remote operations
enum PbOperation {
NONE = 0;
// Returns the full server information
SERVER_INFO = 1;
LOG_LEVEL = 2;
LIST = 3;
// Returns the device list only (required for rasctl/logging semantics compatibility)
LIST = 2 [deprecated = true];
LOG_LEVEL = 3;
ATTACH = 4;
DETACH = 5;
INSERT = 6;
@ -43,7 +45,6 @@ message PbResult {
string msg = 2;
}
// The device meta data
message PbDevice {
int32 id = 1;
@ -53,7 +54,7 @@ message PbDevice {
bool read_only = 5;
// Note: Read-only media (e.g. CD-ROMs) are not protectable
bool protectable = 6;
// Note: Read-only media (e.g. CD-ROMs) are not protected by just read-only
// Note: Read-only media (e.g. CD-ROMs) are not protected but just read-only
bool protected = 7;
bool removable = 8;
bool removed = 9;
@ -75,4 +76,6 @@ message PbServerInfo {
string default_image_folder = 4;
// Files in the default folder
repeated string available_image_files = 5;
// The attached devices
PbDevices devices = 6;
}