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

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