--- nono/host/hostcom.cpp 2026/04/29 17:05:21 1.1.1.3 +++ nono/host/hostcom.cpp 2026/04/29 17:05:43 1.1.1.7 @@ -12,14 +12,12 @@ // // VM thread : Host thread // -// 各シリアルデバイス::Tx() : -// | -// SerialDevice::Tx() : +// 各デバイス::Tx() : // | // HostCOMDevice::Tx() : HostDevice::ThreadRun // | -// +-------------->| queue |----+ -// +-------------->| pipe |----+ +// +-------------->| queue |----+ … 送信キューに追加し +// +-------------->| pipe |----+ … パイプでホストスレッドに通知 // | | // <-+ : v // --- kevent @@ -43,12 +41,17 @@ // : | // HostCOMDevice::Read() // | -// +---------------| queue |<---+ -// +---------------| event |<---+ +// | queue |<---+ … 受信キューに追加 +// ‖ +// ‖ HostCOMDevice::*(rx_func)() +// | +// +-------------| Message |<---+ … メッセージで VM スレッドに通知 // v -// SerialDevice::Callback() -// | -// 各シリアルデバイス::Rx() +// 各デバイス::RxMessage() ‖ … メッセージコールバック +// | ‖ +// 各デバイス::Rx() ‖ … イベントコールバック +// | ‖ +// HostCOMDevice::Rx() <==++ … ここで queue から読み出す // ログ名 // MPSCC HostDevice COMDriver @@ -63,11 +66,13 @@ #include "hostcom.h" +#include "comdriver_cons.h" #include "comdriver_none.h" #include "comdriver_stdio.h" #include "comdriver_tcp.h" #include "config.h" #include "mainapp.h" +#include "monitor.h" // コンストラクタ // @@ -89,9 +94,9 @@ HostCOMDevice::HostCOMDevice(Device *par // のログレベルは独立。 // モニタは hostcom* のみ必要。 - monitor.func = ToMonitorCallback(&HostCOMDevice::MonitorUpdate); - monitor.SetSize(30, 17); - monitor.Regist(ID_MONITOR_HOSTCOM); + monitor = gMonitorManager->Regist(ID_MONITOR_HOSTCOM, this); + monitor->func = ToMonitorCallback(&HostCOMDevice::MonitorUpdate); + monitor->SetSize(30, 17); } } @@ -111,11 +116,11 @@ HostCOMDevice::SetLogLevel(int loglevel_ } } -// 初期化 +// 動的コンストラクションその2 bool -HostCOMDevice::Init() +HostCOMDevice::Create2() { - if (inherited::Init() == false) { + if (inherited::Create2() == false) { return false; } @@ -157,13 +162,32 @@ HostCOMDevice::SelectDriver() } } - driver.reset(new COMDriverStdio(this)); + try { + driver.reset(new COMDriverStdio(this)); + } catch (...) { } if ((bool)driver && driver->InitDriver() == false) { driver.reset(); } } else if (type == "tcp") { - driver.reset(new COMDriverTCP(this)); + try { + driver.reset(new COMDriverTCP(this)); + } catch (...) { } + if ((bool)driver && driver->InitDriver() == false) { + driver.reset(); + } + + } else if (type == "cons") { + // console デバイスのいない機種では指定出来ない。 + if (gMainApp.FindObject(OBJ_CONSOLE) == NULL) { + item.Err("cannot be specified on vmtype=%s", + gMainApp.GetVMTypeStr().c_str()); + return false; + } + + try { + driver.reset(new COMDriverCons(this)); + } catch (...) { } if ((bool)driver && driver->InitDriver() == false) { driver.reset(); } @@ -207,7 +231,9 @@ HostCOMDevice::SelectDriver() } if ((bool)driver == false) { - driver.reset(new COMDriverNone(this)); + try { + driver.reset(new COMDriverNone(this)); + } catch (...) { } if ((bool)driver && driver->InitDriver() == false) { // 失敗したら出来ることはあまりなさげ assert(false); @@ -263,7 +289,7 @@ HostCOMDevice::Tx(uint32 data) stat.tx_bytes++; // ざっくりピーク値 - stat.txq_peak = std::max((int)txq.Length(), stat.txq_peak); + stat.txq_peak = std::max((uint)txq.Length(), stat.txq_peak); // パイプに通知 (値はダミー) return WritePipe(0); @@ -313,7 +339,7 @@ HostCOMDevice::Read() } // ざっくりピーク値 - stat.rxq_peak = std::max((int)rxq.Length(), stat.rxq_peak); + stat.rxq_peak = std::max((uint)rxq.Length(), stat.rxq_peak); return 1; } @@ -364,8 +390,8 @@ HostCOMDevice::MonitorUpdate(Monitor *, y++; screen.Print(5, y++, "Capacity Peak"); - screen.Print(0, y++, "TxQ %4d/%4d %4d", - (int)txq.Length(), (int)txq.Capacity(), stat.txq_peak); - screen.Print(0, y++, "RxQ %4d/%4d %4d", - (int)rxq.Length(), (int)rxq.Capacity(), stat.rxq_peak); + screen.Print(0, y++, "TxQ %4u/%4u %4u", + (uint)txq.Length(), (uint)txq.Capacity(), stat.txq_peak); + screen.Print(0, y++, "RxQ %4u/%4u %4u", + (uint)rxq.Length(), (uint)rxq.Capacity(), stat.rxq_peak); }