Annotation of nono/lib/monitor.h, revision 1.1.1.12

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2021 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
1.1.1.2   root        7: //
                      8: // モニタ管理
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
                     13: #include "geometric.h"
1.1.1.3   root       14: #include "mainapp.h"
1.1       root       15: #include "textscreen.h"
1.1.1.8   root       16: #include <array>
1.1       root       17: 
                     18: // モニタ識別子
                     19: //
                     20: // テキストモニタの識別子だがメニューID (とウィンドウの識別ID) としても使う
                     21: // ので wxmainframe あたりも参照。
                     22: enum {
                     23: #include "monitor_id.h"
                     24: };
                     25: 
                     26: // 識別子 (n番目で指定)
1.1.1.12! root       27: constexpr uint ID_MONITOR_ATC(uint n)          { return ID_MONITOR_ATC0 + n; }
        !            28: constexpr uint ID_MONITOR_CMMU(uint n)         { return ID_MONITOR_CMMU0 + n; }
        !            29: constexpr uint ID_MONITOR_HOSTCOM(uint n)      { return ID_MONITOR_HOSTCOM0 + n; }
        !            30: constexpr uint ID_MONITOR_HOSTNET(uint n)      { return ID_MONITOR_HOSTNET0 + n; }
        !            31: constexpr uint ID_SUBWIN_CACHE(uint n)         { return ID_SUBWIN_CACHE0 + n; }
        !            32: constexpr uint ID_MONITOR_MEMDUMP(uint n)      { return ID_MONITOR_MEMDUMP0 + n; }
        !            33: constexpr uint ID_MONITOR_RTL8019AS(uint n) {
1.1.1.5   root       34:        return ID_MONITOR_RTL8019AS0 + n;
                     35: }
1.1.1.12! root       36: constexpr uint ID_MONITOR_VIRTIO_BLOCK(uint n) {
1.1.1.6   root       37:        return ID_MONITOR_VIRTIO_BLOCK0 + n;
                     38: }
1.1.1.12! root       39: constexpr uint ID_MONITOR_XPMEMDUMP(uint n) {
1.1.1.4   root       40:        return ID_MONITOR_XPMEMDUMP0 + n;
                     41: }
1.1       root       42: // 判定
1.1.1.12! root       43: constexpr bool IS_MONITOR_MEMDUMP(uint id) {
1.1       root       44:        return (ID_MONITOR_MEMDUMP0 <= id &&
1.1.1.4   root       45:                id < ID_MONITOR_MEMDUMP(MAX_MEMDUMP_MONITOR));
                     46: }
1.1.1.12! root       47: constexpr bool IS_MONITOR_XPMEMDUMP(uint id) {
1.1.1.4   root       48:        return (ID_MONITOR_XPMEMDUMP0 <= id &&
                     49:                id < ID_MONITOR_XPMEMDUMP(MAX_XPMEMDUMP_MONITOR));
1.1       root       50: }
                     51: 
1.1.1.12! root       52: class BitmapRGBX;
1.1       root       53: class Monitor;
1.1.1.12! root       54: class Object;
        !            55: using MonitorScreenCallback_t = void (Object::*)(Monitor *, TextScreen&);
        !            56: using MonitorBitmapCallback_t = void (Object::*)(Monitor *, BitmapRGBX&);
1.1.1.2   root       57: 
1.1       root       58: // モニタ
                     59: class Monitor
                     60: {
                     61:  public:
                     62:        Monitor();
1.1.1.8   root       63:        Monitor(uint id_, Object *obj_);
1.1.1.12! root       64:        virtual ~Monitor();
1.1       root       65: 
1.1.1.7   root       66:        uint GetId() const { return id; }
1.1       root       67: 
1.1.1.3   root       68:        // モニターの表示サイズを設定・取得。
1.1       root       69:        void SetSize(nnSize size_) { size = size_; }
                     70:        void SetSize(int col_, int row_) { SetSize(nnSize(col_, row_)); }
1.1.1.7   root       71:        nnSize GetSize() const { return size; }
1.1.1.9   root       72:        int GetCol() const noexcept { return size.width; }
                     73:        int GetRow() const noexcept { return size.height; }
                     74: 
                     75:        // 行を増やす。
                     76:        void AddHeight(int h) { size.height += h; }
1.1       root       77: 
1.1.1.3   root       78:        // モニターが縦に可変長の場合の最大表示行数。(固定長なら 0)
                     79:        void SetMaxHeight(int maxh_) { maxh = maxh_; }
                     80:        int GetMaxHeight() const { return maxh; }
                     81: 
1.1.1.4   root       82:        // ID を表示用文字列にして返す。
1.1.1.7   root       83:        static const char *GetIdText(uint id);
1.1.1.4   root       84: 
                     85:        // このモニターの ID を表示用文字列にして返す。
                     86:        const char *GetIdText() const { return GetIdText(id); }
                     87: 
1.1.1.12! root       88:        // コールバック関数(テキストのみ)をセットする。
        !            89:        template <typename T>
        !            90:        void SetCallback(void (T::*func_)(Monitor *, TextScreen&)) {
        !            91:                screen_func = static_cast<MonitorScreenCallback_t>(func_);
        !            92:        }
        !            93:        // コールバック関数(テキスト、ビットマップ両方)をセットする。
        !            94:        template <typename T>
        !            95:        void SetCallback(void (T::*screen_func_)(Monitor *, TextScreen&),
        !            96:                         void (T::*bitmap_func_)(Monitor *, BitmapRGBX&)) {
        !            97:                SetCallback(screen_func_);
        !            98:                bitmap_func = static_cast<MonitorBitmapCallback_t>(bitmap_func_);
        !            99:        }
        !           100: 
        !           101:        // ビットマップオーバーレイ用にパディング情報をセットする。
        !           102:        void SetPadding(uint padding_) {
        !           103:                padding = padding_;
        !           104:        }
        !           105:        // ビットマップオーバーレイ用にフォントサイズをセットする。
        !           106:        void SetFontSize(uint width, uint height) {
        !           107:                font_width  = width;
        !           108:                font_height = height;
        !           109:        }
        !           110: 
        !           111:        uint GetFontWidth()  const noexcept { return font_width; }
        !           112:        uint GetFontHeight() const noexcept { return font_height; }
        !           113:        // テキスト座標をビットマップ座標に変換する便利関数。
        !           114:        uint BX(uint col) const noexcept { return padding + col * font_width; }
        !           115:        uint BY(uint row) const noexcept { return padding + row * font_height; }
        !           116: 
1.1.1.11  root      117:        // モニタを更新する。
1.1.1.12! root      118:        void UpdateScreen(TextScreen& screen) {
        !           119:                (obj->*(screen_func))(this, screen);
        !           120:        }
        !           121:        // (あれば)ビットマップでモニタ更新する。
        !           122:        bool UpdateBitmap(BitmapRGBX& bitmap) {
        !           123:                if (__predict_false(bitmap_func != NULL)) {
        !           124:                        (obj->*(bitmap_func))(this, bitmap);
        !           125:                        return true;
        !           126:                } else {
        !           127:                        return false;
        !           128:                }
1.1.1.11  root      129:        }
                    130: 
1.1.1.8   root      131:        Object *obj {};                         // オブジェクト
                    132: 
1.1       root      133:  private:
1.1.1.12! root      134:        // コールバック関数
        !           135:        MonitorScreenCallback_t screen_func {};
        !           136:        MonitorBitmapCallback_t bitmap_func {};
        !           137: 
1.1       root      138:        // モニター識別子
1.1.1.11  root      139:        uint id {};
1.1       root      140: 
                    141:        // モニターサイズ
                    142:        nnSize size {};
1.1.1.3   root      143: 
                    144:        // 縦に可変長の場合の最大表示行数 (固定長なら 0)
                    145:        int maxh {};
1.1.1.4   root      146: 
1.1.1.12! root      147:        // ビットマップ描画用。
        !           148:        uint font_width {};
        !           149:        uint font_height {};
        !           150:        uint padding {};
        !           151: 
1.1.1.4   root      152:        // ID を表示用のテキストにしたものとの対応表。
1.1.1.7   root      153:        static const std::vector<std::pair<uint, const char *>> idtext;
1.1       root      154: };
                    155: 
                    156: //
                    157: // モニターマネージャ
                    158: //
                    159: class MonitorManager
                    160: {
                    161:        // モニター情報 (事前定義)
                    162:        struct MonitorInfo {
1.1.1.7   root      163:                uint id;
1.1.1.3   root      164:                VMCap vmcap;
1.1       root      165:                std::vector<std::string> aliases;
                    166:        };
                    167: 
                    168:  public:
1.1.1.2   root      169:        MonitorManager();
                    170:        ~MonitorManager();
                    171: 
1.1.1.8   root      172:        // 登録。
                    173:        // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。
                    174:        // Create() の後、Init() より前に -M オプションの処理があるため。
                    175:        // see wx/wxapp.cpp
                    176:        Monitor *Regist(uint id_, Object *parent_);
1.1.1.12! root      177:        Monitor *Regist(Monitor *monitor_);
1.1.1.8   root      178: 
                    179:        // 削除
                    180:        void Unregist(Monitor *mon_);
                    181: 
                    182:        // 現在登録されているモニターの(穴空きでない)リストを返す。
                    183:        const std::vector<Monitor *> GetList() const;
1.1       root      184: 
                    185:        // 指定された id を持つモニターを返す。
                    186:        // こっちは、なければ assert する。
1.1.1.8   root      187:        Monitor *Get(uint id) const;
1.1       root      188: 
                    189:        // 指定された id を持つモニターを返す。
                    190:        // こっちは、なければ NULL を返す。
1.1.1.7   root      191:        Monitor *Find(uint id) const {
1.1.1.8   root      192:                return monitors[id].get();
1.1       root      193:        }
                    194: 
1.1.1.3   root      195:        // 指定された id に対応する機種ケーパビリティを返す。
1.1.1.7   root      196:        VMCap GetVMCap(uint id) const {
1.1.1.10  root      197:                assertmsg(id < info.size(), "id=%u < %zu", id, info.size());
1.1.1.3   root      198:                return info[id].vmcap;
1.1       root      199:        }
                    200: 
                    201:        // 指定された id に対応する名前のリストを返す。
                    202:        // id が範囲外だと assert する。
1.1.1.7   root      203:        const std::vector<std::string>& GetAliases(uint id) const {
1.1.1.10  root      204:                assertmsg(id < info.size(), "id=%u < %zu", id, info.size());
1.1       root      205:                return info[id].aliases;
                    206:        }
                    207: 
1.1.1.11  root      208:        // id リストから一覧表示用の文字列リストを生成して返す
                    209:        std::vector<std::string> MakeListString(std::vector<uint> list) const;
1.1       root      210: 
                    211:        // 以降の追加を禁止する (プログラムミスを避けるため)
                    212:        void Fix();
                    213: 
                    214:  private:
1.1.1.12! root      215:        // Regist() の実体。
        !           216:        Monitor *RegistCommon(uint id_, Object *parent_, Monitor *monitor_);
        !           217: 
1.1.1.8   root      218:        // モニターインスタンスの配列。添字はモニター ID なので歯抜け。
                    219:        std::array<std::unique_ptr<Monitor>, ID_SUBWIN_MAX> monitors /*{}*/;
1.1       root      220: 
                    221:        // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。
                    222:        bool fixed {};
1.1.1.4   root      223: 
                    224:        // 事前に設定されているモニター情報
                    225:        static const std::vector<MonitorInfo> info;
1.1       root      226: };
                    227: 
1.1.1.2   root      228: extern MonitorManager *gMonitorManager;

unix.superglobalmegacorp.com

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