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

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: 
                     30:  protected:
1.1.1.5 ! root       31:        HostDevice(Device *parent_, uint objid_);
1.1       root       32:  public:
1.1.1.4   root       33:        ~HostDevice() override;
1.1       root       34: 
                     35:        bool Init() override;
                     36: 
                     37:        void Terminate() override;
                     38: 
                     39:        // 設定ファイルキーのプレフィックス ("hostcomX-" とか) を返す
                     40:        std::string GetConfigKey() const;
                     41: 
                     42:        // NetDriver からのディスクリプタの登録
                     43:        int AddOuter(int fd);
                     44:        int DelOuter(int fd);
                     45:        int AddListen(int ls, int action);
                     46: 
                     47:        void SetRxCallback(DeviceCallback_t func);
                     48:        void SetAcceptCallback(DeviceCallback_t func);
                     49: 
                     50:  protected:
                     51:        void ThreadRun() override;
                     52: 
                     53:        virtual void Dispatch(int udata);
                     54: 
                     55:        // ドライバから読み込み。キューに投入したデータ数を返す。
                     56:        virtual int Read() = 0;
                     57: 
                     58:        // ドライバに書き出し。
                     59:        virtual void Write(uint32 data) = 0;
                     60: 
                     61:        bool WritePipe(uint32 data);
                     62: 
                     63:        // ログ出力
                     64:        void putlogn(const char *fmt, ...) const override __printflike(2, 3);
                     65: 
1.1.1.3   root       66:        // 親デバイス
                     67:        Device *parent {};
                     68: 
1.1       root       69:        autofd kq {};
                     70: 
                     71:        // VM からの送信用パイプ
                     72:        autofd rpipe {};
                     73:        autofd wpipe {};
                     74: 
                     75:        // 各種通知コールバック
                     76:        DeviceCallback_t rx_func {};
                     77:        DeviceCallback_t accept_func {};
                     78: 
                     79:        // スレッド終了フラグ
                     80:        bool exit_requested {};
                     81: };

unix.superglobalmegacorp.com

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