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

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