Annotation of nono/host/hostdevice.h, revision 1.1.1.3

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:
1.1.1.3 ! root       32:        HostDevice(Device *parent_, int objid_);
1.1       root       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 AddListen(int ls, int action);
                     47: 
                     48:        void SetRxCallback(DeviceCallback_t func);
                     49:        void SetAcceptCallback(DeviceCallback_t func);
                     50: 
                     51:  protected:
                     52:        void ThreadRun() override;
                     53: 
                     54:        virtual void Dispatch(int udata);
                     55: 
                     56:        // ドライバから読み込み。キューに投入したデータ数を返す。
                     57:        virtual int Read() = 0;
                     58: 
                     59:        // ドライバに書き出し。
                     60:        virtual void Write(uint32 data) = 0;
                     61: 
                     62:        bool WritePipe(uint32 data);
                     63: 
                     64:        // ログ出力
                     65:        void putlogn(const char *fmt, ...) const override __printflike(2, 3);
                     66: 
1.1.1.3 ! root       67:        // 親デバイス
        !            68:        Device *parent {};
        !            69: 
1.1       root       70:        autofd kq {};
                     71: 
                     72:        // VM からの送信用パイプ
                     73:        autofd rpipe {};
                     74:        autofd wpipe {};
                     75: 
                     76:        // 各種通知コールバック
                     77:        DeviceCallback_t rx_func {};
                     78:        DeviceCallback_t accept_func {};
                     79: 
                     80:        // スレッド終了フラグ
                     81:        bool exit_requested {};
                     82: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.