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