--- nono/host/hostdevice.cpp 2026/04/29 17:05:39 1.1.1.5 +++ nono/host/hostdevice.cpp 2026/04/29 17:06:02 1.1.1.8 @@ -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_); } // デストラクタ @@ -88,11 +91,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 +171,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 +185,7 @@ HostDevice::Dispatch(int udata) n = Read(); if (n > 0) { if (rx_func) { - (parent->*rx_func)(); + (parent->*rx_func)(rx_arg); } } } @@ -200,11 +222,8 @@ HostDevice::putlogn(const char *fmt, ... int len; uint64 vt = scheduler->GetVirtTime(); - len = snprintf(buf, sizeof(buf), "%4u.%03u'%03u'%03u %s ", - (uint)(vt / 1000 / 1000 / 1000), - (uint)((vt / 1000 / 1000) % 1000), - (uint)((vt / 1000) % 1000), - (uint)(vt % 1000), + len = snprintf(buf, sizeof(buf), "%16s %s ", + SecToStr(vt).c_str(), GetName().c_str()); va_start(ap, fmt);