Annotation of nono/vm/ethernet.h, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2019 [email protected]
        !             4: //
        !             5: 
        !             6: #pragma once
        !             7: 
        !             8: #include <array>
        !             9: #include <condition_variable>
        !            10: #include <mutex>
        !            11: #include <vector>
        !            12: #include "device.h"
        !            13: #include "mystring.h"
        !            14: #include "qvector.h"
        !            15: 
        !            16: //          IODevice
        !            17: //              |
        !            18: //              v
        !            19: //        EthernetDevice (イーサネットとしての共通部分)
        !            20: //              |
        !            21: //     +--------+-------+
        !            22: //     v                v
        !            23: // LanceDevice     RTL8019Device
        !            24: // (LUNA, AM7990)  (X68000, RTL8019)
        !            25: //
        !            26: // これ自体は IODevice である必要はないが、LanceDevice などの親になるため
        !            27: // IODevice にしてある。(多重継承はしない) 
        !            28: 
        !            29: class NetDriver;
        !            30: 
        !            31: // MAC アドレス格納用のクラス
        !            32: class macaddr_t : public std::array<uint8, 6>
        !            33: {
        !            34:        typedef std::array<uint8, 6> inherited;
        !            35:  public:
        !            36:        // この MAC アドレスが 00:00:00:00:00:00 なら true
        !            37:        bool empty() const {
        !            38:                for (const auto& v : *this) {
        !            39:                        if (v != 0) {
        !            40:                                return false;
        !            41:                        }
        !            42:                }
        !            43:                return true;
        !            44:        }
        !            45: 
        !            46:        // 文字列形式を返す
        !            47:        std::string to_string() const {
        !            48:                std::string buf;
        !            49:                for (const auto& v : *this) {
        !            50:                        buf += string_format("%02x:", v);
        !            51:                }
        !            52:                buf.pop_back();
        !            53:                return buf;
        !            54:        }
        !            55: };
        !            56: 
        !            57: class EthernetDevice : public IODevice
        !            58: {
        !            59:        typedef IODevice inherited;
        !            60:  protected:
        !            61:        EthernetDevice();
        !            62:  public:
        !            63:        virtual ~EthernetDevice();
        !            64: 
        !            65:        virtual bool Create();
        !            66:        virtual bool Init();
        !            67: 
        !            68:        // パケットを受信した。
        !            69:        // ホストネットワークドライバから呼ばれる。
        !            70:        // ホストネットワークスレッドで mtx 取得状態で呼ばれるので、
        !            71:        // バッファをコピーしてこちらのスレッドに処理を引き渡すところまでを行う。
        !            72:        // buf はプリアンブルを含まず、イーサネットフレームヘッダ(14バイト)、
        !            73:        // データ(46-1500バイト)、FCS(CRC) (4バイト) からなる。
        !            74:        virtual bool RecvPacket(qvector<uint8>& buf) = 0;
        !            75: 
        !            76:        // パケット受信許可。
        !            77:        // true の場合のみホストドライバは RecvPacket() をコールしてよい。
        !            78:        bool RecvEnabled = false;
        !            79: 
        !            80:        // このデバイスと継承デバイスのメンバ変数を読み書きする場合は
        !            81:        // 必ずこのロックを取得する。?
        !            82:        // cv もこのロックを使う。
        !            83:        std::mutex mtx {};
        !            84:        // ワーカスレッドへ指示を出すための条件変数
        !            85:        std::condition_variable cv {};
        !            86:        // ワーカスレッドへのリクエストフラグ
        !            87:        uint32 request = 0;
        !            88: 
        !            89:  protected:
        !            90:        // MAC アドレスを生成する
        !            91:        static void GenerateMacAddr(macaddr_t *addr);
        !            92: 
        !            93:        // MAC アドレス文字列をバイナリに変換する
        !            94:        static bool ParseMacAddr(macaddr_t& dst, const std::string& src);
        !            95: 
        !            96:        // パケットを送信する
        !            97:        bool SendPacket(const std::vector<uint8>& buf);
        !            98: };
        !            99: 
        !           100: extern EthernetDevice *gEthernet;

unix.superglobalmegacorp.com

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