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

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