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

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: // モニタ更新を呼び出すマクロ
1.1.1.8   root       70: #define MONITOR_UPDATE(m, scr) ((((m)->obj)->*((m)->func))((m), (scr)))
1.1       root       71: 
                     72: // モニタ
                     73: class Monitor
                     74: {
                     75:  public:
                     76:        Monitor();
1.1.1.8   root       77:        Monitor(uint id_, Object *obj_);
1.1.1.7   root       78:        ~Monitor();
1.1       root       79: 
1.1.1.7   root       80:        uint GetId() const { return id; }
1.1       root       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_)); }
1.1.1.7   root       85:        nnSize GetSize() const { return size; }
1.1.1.9   root       86:        int GetCol() const noexcept { return size.width; }
                     87:        int GetRow() const noexcept { return size.height; }
                     88: 
                     89:        // 行を増やす。
                     90:        void AddHeight(int h) { size.height += h; }
1.1       root       91: 
1.1.1.3   root       92:        // モニターが縦に可変長の場合の最大表示行数。(固定長なら 0)
                     93:        void SetMaxHeight(int maxh_) { maxh = maxh_; }
                     94:        int GetMaxHeight() const { return maxh; }
                     95: 
1.1.1.4   root       96:        // ID を表示用文字列にして返す。
1.1.1.7   root       97:        static const char *GetIdText(uint id);
1.1.1.4   root       98: 
                     99:        // このモニターの ID を表示用文字列にして返す。
                    100:        const char *GetIdText() const { return GetIdText(id); }
                    101: 
1.1.1.8   root      102:        Object *obj {};                         // オブジェクト
                    103: 
                    104:        MonitorCallback_t func {};      // コールバック関数
                    105: 
1.1       root      106:  private:
                    107:        // モニター識別子
1.1.1.7   root      108:        uint id;
1.1       root      109: 
                    110:        // モニターサイズ
                    111:        nnSize size {};
1.1.1.3   root      112: 
                    113:        // 縦に可変長の場合の最大表示行数 (固定長なら 0)
                    114:        int maxh {};
1.1.1.4   root      115: 
                    116:        // ID を表示用のテキストにしたものとの対応表。
1.1.1.7   root      117:        static const std::vector<std::pair<uint, const char *>> idtext;
1.1       root      118: };
                    119: 
                    120: //
                    121: // モニターマネージャ
                    122: //
                    123: class MonitorManager
                    124: {
                    125:        // モニター情報 (事前定義)
                    126:        struct MonitorInfo {
1.1.1.7   root      127:                uint id;
1.1.1.3   root      128:                VMCap vmcap;
1.1       root      129:                std::vector<std::string> aliases;
                    130:        };
                    131: 
                    132:  public:
1.1.1.2   root      133:        MonitorManager();
                    134:        ~MonitorManager();
                    135: 
1.1.1.8   root      136:        // 登録。
                    137:        // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。
                    138:        // Create() の後、Init() より前に -M オプションの処理があるため。
                    139:        // see wx/wxapp.cpp
                    140:        Monitor *Regist(uint id_, Object *parent_);
                    141: 
                    142:        // 削除
                    143:        void Unregist(Monitor *mon_);
                    144: 
                    145:        // 現在登録されているモニターの(穴空きでない)リストを返す。
                    146:        const std::vector<Monitor *> GetList() const;
1.1       root      147: 
                    148:        // 指定された id を持つモニターを返す。
                    149:        // こっちは、なければ assert する。
1.1.1.8   root      150:        Monitor *Get(uint id) const;
1.1       root      151: 
                    152:        // 指定された id を持つモニターを返す。
                    153:        // こっちは、なければ NULL を返す。
1.1.1.7   root      154:        Monitor *Find(uint id) const {
1.1.1.8   root      155:                return monitors[id].get();
1.1       root      156:        }
                    157: 
1.1.1.3   root      158:        // 指定された id に対応する機種ケーパビリティを返す。
1.1.1.7   root      159:        VMCap GetVMCap(uint id) const {
1.1.1.10! root      160:                assertmsg(id < info.size(), "id=%u < %zu", id, info.size());
1.1.1.3   root      161:                return info[id].vmcap;
1.1       root      162:        }
                    163: 
                    164:        // 指定された id に対応する名前のリストを返す。
                    165:        // id が範囲外だと assert する。
1.1.1.7   root      166:        const std::vector<std::string>& GetAliases(uint id) const {
1.1.1.10! root      167:                assertmsg(id < info.size(), "id=%u < %zu", id, info.size());
1.1       root      168:                return info[id].aliases;
                    169:        }
                    170: 
                    171:        // id リストから一覧表示用の文字列を生成して返す
1.1.1.7   root      172:        static std::string MakeListString(std::vector<uint> list);
1.1       root      173: 
                    174:        // 以降の追加を禁止する (プログラムミスを避けるため)
                    175:        void Fix();
                    176: 
                    177:  private:
1.1.1.8   root      178:        // モニターインスタンスの配列。添字はモニター ID なので歯抜け。
                    179:        std::array<std::unique_ptr<Monitor>, ID_SUBWIN_MAX> monitors /*{}*/;
1.1       root      180: 
                    181:        // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。
                    182:        bool fixed {};
1.1.1.4   root      183: 
                    184:        // 事前に設定されているモニター情報
                    185:        static const std::vector<MonitorInfo> info;
1.1       root      186: };
                    187: 
1.1.1.2   root      188: 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.