|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2021 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: // ! 8: // ホストデバイス (基本クラス) ! 9: // ! 10: ! 11: #pragma once ! 12: ! 13: #include "thread.h" ! 14: #include "autofd.h" ! 15: #include "kevent.h" ! 16: ! 17: using DeviceCallback_t = void (Device::*)(); ! 18: #define ToDeviceCallback(f) static_cast<DeviceCallback_t>(f) ! 19: ! 20: class HostDevice : public ThreadDevice ! 21: { ! 22: using inherited = ThreadDevice; ! 23: ! 24: public: ! 25: static const int DONE = 0; // 処理終了 ! 26: static const int DATA_FROM_VM = 1; // VM からの着信 ! 27: static const int DATA_FROM_OUTER = 2; // 外部からの着信 ! 28: static const int LISTEN_SOCKET = 3; // 待受ソケット着信 ! 29: static const int DATA_FROM_SIGNAL = 4; // シグナル受信 ! 30: ! 31: protected: ! 32: HostDevice(const std::string& objname_); ! 33: public: ! 34: virtual ~HostDevice() override; ! 35: ! 36: bool Init() override; ! 37: ! 38: void Terminate() override; ! 39: ! 40: // 設定ファイルキーのプレフィックス ("hostcomX-" とか) を返す ! 41: std::string GetConfigKey() const; ! 42: ! 43: // NetDriver からのディスクリプタの登録 ! 44: int AddOuter(int fd); ! 45: int DelOuter(int fd); ! 46: int AddSignal(int rfd, int wfd); ! 47: int AddListen(int ls, int action); ! 48: ! 49: void SetCallbackDevice(Device *); ! 50: void SetRxCallback(DeviceCallback_t func); ! 51: void SetAcceptCallback(DeviceCallback_t func); ! 52: ! 53: protected: ! 54: void ThreadRun() override; ! 55: ! 56: virtual void Dispatch(int udata); ! 57: ! 58: // ドライバから読み込み。キューに投入したデータ数を返す。 ! 59: virtual int Read() = 0; ! 60: ! 61: // ドライバに書き出し。 ! 62: virtual void Write(uint32 data) = 0; ! 63: ! 64: bool WritePipe(uint32 data); ! 65: ! 66: // ログ出力 ! 67: void putlogn(const char *fmt, ...) const override __printflike(2, 3); ! 68: ! 69: autofd kq {}; ! 70: ! 71: // VM からの送信用パイプ ! 72: autofd rpipe {}; ! 73: autofd wpipe {}; ! 74: ! 75: // 各種通知コールバック ! 76: Device *dev {}; ! 77: DeviceCallback_t rx_func {}; ! 78: DeviceCallback_t accept_func {}; ! 79: ! 80: // スレッド終了フラグ ! 81: bool exit_requested {}; ! 82: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.