--- nono/host/hostdevice.cpp 2026/04/29 17:05:39 1.1.1.5 +++ nono/host/hostdevice.cpp 2026/04/29 17:05:47 1.1.1.6 @@ -9,13 +9,16 @@ // #include "hostdevice.h" +#include "config.h" #include "scheduler.h" // コンストラクタ -HostDevice::HostDevice(Device *parent_, uint objid_) +HostDevice::HostDevice(Device *parent_, uint objid_, + const std::string& portname_) : inherited(objid_) { parent = parent_; + SetPortName(portname_); } // デストラクタ @@ -54,6 +57,18 @@ HostDevice::Create2() return true; } +// 初期化 +bool +HostDevice::Init() +{ + // Create2() と Config::Fix が終わったところで fallback をオンにする。 + // これ以降の動的変更でエラー終了するのは困るので。 + std::string line = GetConfigKey() + "-fallback=1"; + gConfig->UpdateRunning(line); + + return true; +} + // 設定ファイルキーのプレフィックス ("hostcomX" とか) を返す std::string HostDevice::GetConfigKey() const @@ -88,11 +103,26 @@ HostDevice::AddListen(int ls, int action return kevent_add(kq, ls, EVFILT_READ, action, LISTEN_SOCKET); } +// Listen ソケットを登録解除。 +int +HostDevice::DelListen(int ls) +{ + return kevent_add(kq, ls, EVFILT_READ, EV_DELETE, LISTEN_SOCKET); +} + +// 受信通知コールバックを解除 +void +HostDevice::ResetRxCallback() +{ + rx_func = NULL; +} + // 受信通知コールバックを設定 void -HostDevice::SetRxCallback(DeviceCallback_t func) +HostDevice::SetRxCallback(DeviceCallback_t func, uint32 arg) { rx_func = func; + rx_arg = arg; } // 着信通知コールバックを設定 @@ -153,8 +183,12 @@ HostDevice::Dispatch(int udata) return; } - // 外部に送信 (継承クラスによる) - Write(buf[0]); + if (__predict_false(buf[0] != PIPE_TX)) { + SelectDriver(false); + } else { + // 外部に送信 (継承クラスによる) + Write(); + } } else if (udata == DATA_FROM_OUTER) { // 外部から着信があった @@ -163,7 +197,7 @@ HostDevice::Dispatch(int udata) n = Read(); if (n > 0) { if (rx_func) { - (parent->*rx_func)(); + (parent->*rx_func)(rx_arg); } } }