|
|
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番目で指定)
1.1.1.7 ! root 27: static constexpr uint ID_MONITOR_ATC(uint n) {
1.1 root 28: return ID_MONITOR_ATC0 + n;
29: }
1.1.1.7 ! root 30: static constexpr uint ID_MONITOR_CMMU(uint n) {
1.1 root 31: return ID_MONITOR_CMMU0 + n;
32: }
1.1.1.7 ! root 33: static constexpr uint ID_MONITOR_HOSTNET(uint n) {
1.1.1.5 root 34: return ID_MONITOR_HOSTNET0 + n;
35: }
1.1.1.7 ! root 36: static constexpr uint ID_SUBWIN_CACHE(uint n) {
1.1 root 37: return ID_SUBWIN_CACHE0 + n;
38: }
1.1.1.7 ! root 39: static constexpr uint ID_MONITOR_MEMDUMP(uint n) {
1.1 root 40: return ID_MONITOR_MEMDUMP0 + n;
41: }
1.1.1.7 ! root 42: static constexpr uint ID_MONITOR_RTL8019AS(uint n) {
1.1.1.5 root 43: return ID_MONITOR_RTL8019AS0 + n;
44: }
1.1.1.7 ! root 45: static constexpr uint ID_MONITOR_VIRTIO_BLOCK(uint n) {
1.1.1.6 root 46: return ID_MONITOR_VIRTIO_BLOCK0 + n;
47: }
1.1.1.7 ! root 48: static constexpr uint ID_MONITOR_XPMEMDUMP(uint n) {
1.1.1.4 root 49: return ID_MONITOR_XPMEMDUMP0 + n;
50: }
1.1 root 51: // 判定
1.1.1.7 ! root 52: static constexpr bool IS_MONITOR_MEMDUMP(uint id) {
1.1 root 53: return (ID_MONITOR_MEMDUMP0 <= id &&
1.1.1.4 root 54: id < ID_MONITOR_MEMDUMP(MAX_MEMDUMP_MONITOR));
55: }
1.1.1.7 ! root 56: static constexpr bool IS_MONITOR_XPMEMDUMP(uint id) {
1.1.1.4 root 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();
1.1.1.7 ! root 77: explicit Monitor(Object *obj_);
! 78: ~Monitor();
1.1 root 79:
80: Object *obj {}; // オブジェクト
81: MonitorCallback_t func {}; // コールバック関数
82:
1.1.1.7 ! root 83: uint GetId() const { return id; }
1.1 root 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_)); }
1.1.1.7 ! root 88: nnSize GetSize() const { return size; }
1.1 root 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
1.1.1.7 ! root 98: void Regist(uint id);
1.1 root 99:
100: // 削除。
101: void Unregist();
102:
1.1.1.4 root 103: // ID を表示用文字列にして返す。
1.1.1.7 ! root 104: static const char *GetIdText(uint id);
1.1.1.4 root 105:
106: // このモニターの ID を表示用文字列にして返す。
107: const char *GetIdText() const { return GetIdText(id); }
108:
1.1 root 109: private:
110: // モニター識別子
1.1.1.7 ! root 111: uint id;
1.1 root 112:
113: // モニターサイズ
114: nnSize size {};
1.1.1.3 root 115:
116: // 縦に可変長の場合の最大表示行数 (固定長なら 0)
117: int maxh {};
1.1.1.4 root 118:
119: // ID を表示用のテキストにしたものとの対応表。
1.1.1.7 ! root 120: static const std::vector<std::pair<uint, const char *>> idtext;
1.1 root 121: };
122:
123: //
124: // モニターマネージャ
125: //
126: class MonitorManager
127: {
128: friend class Monitor;
129:
130: // モニター情報 (事前定義)
131: struct MonitorInfo {
1.1.1.7 ! root 132: uint 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 する。
1.1.1.7 ! root 146: Monitor& Get(uint id) const {
1.1 root 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 を返す。
1.1.1.7 ! root 157: Monitor *Find(uint id) const {
1.1 root 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 に対応する機種ケーパビリティを返す。
1.1.1.7 ! root 167: VMCap GetVMCap(uint id) const {
! 168: assert(id < info.size());
1.1.1.3 root 169: return info[id].vmcap;
1.1 root 170: }
171:
172: // 指定された id に対応する名前のリストを返す。
173: // id が範囲外だと assert する。
1.1.1.7 ! root 174: const std::vector<std::string>& GetAliases(uint id) const {
! 175: assert(id < info.size());
1.1 root 176: return info[id].aliases;
177: }
178:
179: // id リストから一覧表示用の文字列を生成して返す
1.1.1.7 ! root 180: static std::string MakeListString(std::vector<uint> list);
1.1 root 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;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.