|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
1.1.1.9 root 7: //
8: // CLI アプリケーションのエントリポイント
9: //
10:
1.1.1.13 root 11: #include "nono.h"
1.1.1.8 root 12: #include "cuimessage.h"
1.1.1.9 root 13: #include "kevent.h"
1.1 root 14: #include "mainapp.h"
1.1.1.12 root 15: #include "monitor.h"
1.1.1.10 root 16: #include "power.h"
1.1 root 17:
18: // wxApp と相似にするためのクラス
19: class CLIApp
20: {
21: public:
1.1.1.4 root 22: int OnInit();
1.1 root 23: bool Parse();
1.1.1.7 root 24: int OnCreate();
1.1.1.8 root 25: void OnHalt();
1.1.1.9 root 26:
27: int ac {};
28: char **av {};
1.1 root 29:
1.1.1.9 root 30: autofd kq {};
31: bool exit_request {};
1.1 root 32: };
33:
34: int
35: main(int ac, char *av[])
36: {
1.1.1.2 root 37: std::unique_ptr<CLIApp> app(new CLIApp());
1.1 root 38:
39: // wxApp とよく似せるため
40: app->ac = ac;
41: app->av = av;
1.1.1.4 root 42: return app->OnInit();
1.1 root 43: }
44:
45: // ここがエントリポイント(のつもり)
1.1.1.4 root 46: int
1.1 root 47: CLIApp::OnInit()
48: {
1.1.1.4 root 49: int rv;
50:
1.1.1.6 root 51: // CLI 側では関係ないが wx 側で必要なので初期化は2ステージに分かれている
1.1.1.14! root 52: rv = gMainApp.Init1(ac, av, NULL);
1.1.1.4 root 53: if (rv != MainApp::PASS) {
54: return rv;
1.1 root 55: }
1.1.1.9 root 56: // UIMessage の初期化はなんとなくスレッド開始前のほうがよかろう
57: kq = CUIMessage::Init();
58: if (kq < 0) {
59: return EXIT_FAILURE;
60: }
1.1.1.12 root 61:
62: // モニタ登録締切。CLI ではあまり関係ないけど揃えておく。
63: gMonitorManager->Fix();
64:
65: // スレッド作成を伴う初期化。
1.1.1.6 root 66: if (!gMainApp.Init2()) {
1.1.1.4 root 67: return EXIT_FAILURE;
1.1 root 68: }
69:
70: // メインウィンドウに相当するところ
71: OnCreate();
72:
1.1.1.12 root 73: // 戻ってきたので、VM を解放。
74: gMainApp.Dispose();
75:
1.1.1.4 root 76: return EXIT_SUCCESS;
1.1 root 77: }
78:
79: // メインウィンドウ作成後のイベントに相当するところ
1.1.1.7 root 80: int
1.1 root 81: CLIApp::OnCreate()
82: {
1.1.1.14! root 83: gMainApp.GetUIMessage()->StartUIMessage(&CUIMessage::Process);
1.1.1.8 root 84:
1.1.1.6 root 85: // 電源投入
1.1.1.11 root 86: auto power = GetPowerDevice();
1.1.1.12 root 87: power->PushPowerButton();
1.1 root 88:
1.1.1.9 root 89: // メッセージを待つ
90: while (exit_request == false) {
91: struct kevent kev;
92:
93: if (kevent_poll(kq, &kev, 1, NULL) < 0) {
94: if (errno == EINTR) {
95: continue;
96: }
97: warn("CLIApp::OnCreate: kevent_poll");
98: // XXX どうする?
99: continue;
100: }
101:
102: // パイプから1メッセージ分読み出す
1.1.1.14! root 103: union64 m;
1.1.1.9 root 104: if (read((int)kev.ident, &m, sizeof(m)) < 0) {
105: warn("CLIApp::OnCreate: read");
106: // XXX どうする?
107: continue;
108: }
1.1.1.14! root 109: uint id = m.h;
1.1.1.9 root 110:
1.1.1.14! root 111: // 少ないのでこの場でディスパッチする。
! 112: switch (id) {
! 113: case UIMessage::APPEXIT:
! 114: exit_request = true;
! 115: break;
! 116: case UIMessage::HALT:
! 117: OnHalt();
! 118: break;
! 119: default:
! 120: break;
! 121: }
1.1.1.9 root 122: }
1.1.1.7 root 123:
1.1.1.14! root 124: gMainApp.GetUIMessage()->StopUIMessage();
! 125:
1.1.1.7 root 126: return 0;
1.1 root 127: }
1.1.1.3 root 128:
129: // m680x0 ダブルバスフォールト時に呼ばれるコールバック。
130: void
1.1.1.8 root 131: CLIApp::OnHalt()
1.1.1.3 root 132: {
133: // どうする?
134: warnx("Double bus fault has occurred in VM");
135: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.