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

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 "object.h"
                     16: #include "textscreen.h"
1.1.1.8   root       17: #include <array>
1.1       root       18: 
                     19: // モニタ識別子
                     20: //
                     21: // テキストモニタの識別子だがメニューID (とウィンドウの識別ID) としても使う
                     22: // ので wxmainframe あたりも参照。
                     23: enum {
                     24: #include "monitor_id.h"
                     25: };
                     26: 
                     27: // 識別子 (n番目で指定)
1.1.1.7   root       28: static constexpr uint ID_MONITOR_ATC(uint n) {
1.1       root       29:        return ID_MONITOR_ATC0 + n;
                     30: }
1.1.1.7   root       31: static constexpr uint ID_MONITOR_CMMU(uint n) {
1.1       root       32:        return ID_MONITOR_CMMU0 + n;
                     33: }
1.1.1.9   root       34: static constexpr uint ID_MONITOR_HOSTCOM(uint n) {
                     35:        return ID_MONITOR_HOSTCOM0 + n;
                     36: }
1.1.1.7   root       37: static constexpr uint ID_MONITOR_HOSTNET(uint n) {
1.1.1.5   root       38:        return ID_MONITOR_HOSTNET0 + n;
                     39: }
1.1.1.7   root       40: static constexpr uint ID_SUBWIN_CACHE(uint n) {
1.1       root       41:        return ID_SUBWIN_CACHE0 + n;
                     42: }
1.1.1.7   root       43: static constexpr uint ID_MONITOR_MEMDUMP(uint n) {
1.1       root       44:        return ID_MONITOR_MEMDUMP0 + n;
                     45: }
1.1.1.7   root       46: static constexpr uint ID_MONITOR_RTL8019AS(uint n) {
1.1.1.5   root       47:        return ID_MONITOR_RTL8019AS0 + n;
                     48: }
1.1.1.7   root       49: static constexpr uint ID_MONITOR_VIRTIO_BLOCK(uint n) {
1.1.1.6   root       50:        return ID_MONITOR_VIRTIO_BLOCK0 + n;
                     51: }
1.1.1.7   root       52: static constexpr uint ID_MONITOR_XPMEMDUMP(uint n) {
1.1.1.4   root       53:        return ID_MONITOR_XPMEMDUMP0 + n;
                     54: }
1.1       root       55: // 判定
1.1.1.7   root       56: static constexpr bool IS_MONITOR_MEMDUMP(uint id) {
1.1       root       57:        return (ID_MONITOR_MEMDUMP0 <= id &&
1.1.1.4   root       58:                id < ID_MONITOR_MEMDUMP(MAX_MEMDUMP_MONITOR));
                     59: }
1.1.1.7   root       60: static constexpr bool IS_MONITOR_XPMEMDUMP(uint id) {
1.1.1.4   root       61:        return (ID_MONITOR_XPMEMDUMP0 <= id &&
                     62:                id < ID_MONITOR_XPMEMDUMP(MAX_XPMEMDUMP_MONITOR));
1.1       root       63: }
                     64: 
                     65: class Monitor;
                     66: using MonitorCallback_t = void (Object::*)(Monitor *, TextScreen&);
1.1.1.2   root       67: #define ToMonitorCallback(f) static_cast<MonitorCallback_t>(f)
                     68: 
1.1       root       69: // モニタ
                     70: class Monitor
                     71: {
                     72:  public:
                     73:        Monitor();
1.1.1.8   root       74:        Monitor(uint id_, Object *obj_);
1.1.1.7   root       75:        ~Monitor();
1.1       root       76: 
1.1.1.7   root       77:        uint GetId() const { return id; }
1.1       root       78: 
1.1.1.3   root       79:        // モニターの表示サイズを設定・取得。
1.1       root       80:        void SetSize(nnSize size_) { size = size_; }
                     81:        void SetSize(int col_, int row_) { SetSize(nnSize(col_, row_)); }
1.1.1.7   root       82:        nnSize GetSize() const { return size; }
1.1.1.9   root       83:        int GetCol() const noexcept { return size.width; }
                     84:        int GetRow() const noexcept { return size.height; }
                     85: 
                     86:        // 行を増やす。
                     87:        void AddHeight(int h) { size.height += h; }
1.1       root       88: 
1.1.1.3   root       89:        // モニターが縦に可変長の場合の最大表示行数。(固定長なら 0)
                     90:        void SetMaxHeight(int maxh_) { maxh = maxh_; }
                     91:        int GetMaxHeight() const { return maxh; }
                     92: 
1.1.1.4   root       93:        // ID を表示用文字列にして返す。
1.1.1.7   root       94:        static const char *GetIdText(uint id);
1.1.1.4   root       95: 
                     96:        // このモニターの ID を表示用文字列にして返す。
                     97:        const char *GetIdText() const { return GetIdText(id); }
                     98: 
1.1.1.11! root       99:        // モニタを更新する。
        !           100:        void Update(TextScreen& screen) {
        !           101:                (obj->*(func))(this, screen);
        !           102:        }
        !           103: 
1.1.1.8   root      104:        Object *obj {};                         // オブジェクト
                    105: 
                    106:        MonitorCallback_t func {};      // コールバック関数
                    107: 
1.1       root      108:  private:
                    109:        // モニター識別子
1.1.1.11! root      110:        uint id {};
1.1       root      111: 
                    112:        // モニターサイズ
                    113:        nnSize size {};
1.1.1.3   root      114: 
                    115:        // 縦に可変長の場合の最大表示行数 (固定長なら 0)
                    116:        int maxh {};
1.1.1.4   root      117: 
                    118:        // ID を表示用のテキストにしたものとの対応表。
1.1.1.7   root      119:        static const std::vector<std::pair<uint, const char *>> idtext;
1.1       root      120: };
                    121: 
                    122: //
                    123: // モニターマネージャ
                    124: //
                    125: class MonitorManager
                    126: {
                    127:        // モニター情報 (事前定義)
                    128:        struct MonitorInfo {
1.1.1.7   root      129:                uint id;
1.1.1.3   root      130:                VMCap vmcap;
1.1       root      131:                std::vector<std::string> aliases;
                    132:        };
                    133: 
                    134:  public:
1.1.1.2   root      135:        MonitorManager();
                    136:        ~MonitorManager();
                    137: 
1.1.1.8   root      138:        // 登録。
                    139:        // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。
                    140:        // Create() の後、Init() より前に -M オプションの処理があるため。
                    141:        // see wx/wxapp.cpp
                    142:        Monitor *Regist(uint id_, Object *parent_);
                    143: 
                    144:        // 削除
                    145:        void Unregist(Monitor *mon_);
                    146: 
                    147:        // 現在登録されているモニターの(穴空きでない)リストを返す。
                    148:        const std::vector<Monitor *> GetList() const;
1.1       root      149: 
                    150:        // 指定された id を持つモニターを返す。
                    151:        // こっちは、なければ assert する。
1.1.1.8   root      152:        Monitor *Get(uint id) const;
1.1       root      153: 
                    154:        // 指定された id を持つモニターを返す。
                    155:        // こっちは、なければ NULL を返す。
1.1.1.7   root      156:        Monitor *Find(uint id) const {
1.1.1.8   root      157:                return monitors[id].get();
1.1       root      158:        }
                    159: 
1.1.1.3   root      160:        // 指定された id に対応する機種ケーパビリティを返す。
1.1.1.7   root      161:        VMCap GetVMCap(uint id) const {
1.1.1.10  root      162:                assertmsg(id < info.size(), "id=%u < %zu", id, info.size());
1.1.1.3   root      163:                return info[id].vmcap;
1.1       root      164:        }
                    165: 
                    166:        // 指定された id に対応する名前のリストを返す。
                    167:        // id が範囲外だと assert する。
1.1.1.7   root      168:        const std::vector<std::string>& GetAliases(uint id) const {
1.1.1.10  root      169:                assertmsg(id < info.size(), "id=%u < %zu", id, info.size());
1.1       root      170:                return info[id].aliases;
                    171:        }
                    172: 
1.1.1.11! root      173:        // id リストから一覧表示用の文字列リストを生成して返す
        !           174:        std::vector<std::string> MakeListString(std::vector<uint> list) const;
1.1       root      175: 
                    176:        // 以降の追加を禁止する (プログラムミスを避けるため)
                    177:        void Fix();
                    178: 
                    179:  private:
1.1.1.8   root      180:        // モニターインスタンスの配列。添字はモニター ID なので歯抜け。
                    181:        std::array<std::unique_ptr<Monitor>, ID_SUBWIN_MAX> monitors /*{}*/;
1.1       root      182: 
                    183:        // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。
                    184:        bool fixed {};
1.1.1.4   root      185: 
                    186:        // 事前に設定されているモニター情報
                    187:        static const std::vector<MonitorInfo> info;
1.1       root      188: };
                    189: 
1.1.1.2   root      190: 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.