--- nono/host/hostdevice.cpp 2026/04/29 17:05:11 1.1 +++ nono/host/hostdevice.cpp 2026/04/29 17:05:21 1.1.1.3 @@ -10,12 +10,12 @@ #include "hostdevice.h" #include "scheduler.h" -#include "signalthread.h" // コンストラクタ -HostDevice::HostDevice(const std::string& objname_) - : inherited(objname_) +HostDevice::HostDevice(Device *parent_, int objid_) + : inherited(objid_) { + parent = parent_; } // デストラクタ @@ -31,6 +31,10 @@ HostDevice::Init() int fds[2]; int r; + if (inherited::Init() == false) { + return false; + } + kq = kqueue(); if (kq < 0) { putmsg(0, "kqueue: %s", strerror(errno)); @@ -81,22 +85,6 @@ HostDevice::DelOuter(int fd) return kevent_add(kq, fd, EVFILT_READ, EV_DELETE, DATA_FROM_OUTER); } -// シグナルスレッドからのパイプを登録 -int -HostDevice::AddSignal(int rfd, int wfd) -{ - int r; - - r = kevent_add(kq, rfd, EVFILT_READ, EV_ADD, DATA_FROM_SIGNAL); - if (r < 0) { - return r; - } - // シグナルスレッドに登録。 - gSignalThread->AddPipe(wfd); - - return 0; -} - // Listen ソケットを登録 int HostDevice::AddListen(int ls, int action) @@ -104,18 +92,6 @@ HostDevice::AddListen(int ls, int action return kevent_add(kq, ls, EVFILT_READ, action, LISTEN_SOCKET); } -// コールバック先デバイスを設定。 -// -// コールバックはデバイスと関数が両方設定されている時だけ呼び出すので、 -// 設定時は、コールバック関数設定後に SetCallbackDevice() でデバイスを設定、 -// 解除時は、まず SetCallbackDevice(NULL) でデバイスを解除、 -// の順にすること。 -void -HostDevice::SetCallbackDevice(Device *dev_) -{ - dev = dev_; -} - // 受信通知コールバックを設定 void HostDevice::SetRxCallback(DeviceCallback_t func) @@ -188,8 +164,8 @@ HostDevice::Dispatch(int udata) // キューに1個以上データが投入されたら VM に通知 n = Read(); if (n > 0) { - if (dev && rx_func) { - (dev->*rx_func)(); + if (rx_func) { + (parent->*rx_func)(); } } } @@ -225,7 +201,7 @@ HostDevice::putlogn(const char *fmt, ... va_list ap; int len; - uint64 vt = gScheduler->GetVirtTime(); + uint64 vt = scheduler->GetVirtTime(); len = snprintf(buf, sizeof(buf), "%4d.%03d'%03d'%03d %s ", (int)(vt / 1000 / 1000 / 1000), (int)((vt / 1000 / 1000) % 1000),