Annotation of nono/cli/cli_app.cpp, revision 1.1.1.12

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       root       11: #include "header.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:        void OnAppExit();
                     27: 
                     28:        int ac {};
                     29:        char **av {};
1.1       root       30: 
1.1.1.9   root       31:        autofd kq {};
                     32:        bool exit_request {};
1.1       root       33: };
                     34: 
                     35: int
                     36: main(int ac, char *av[])
                     37: {
1.1.1.2   root       38:        std::unique_ptr<CLIApp> app(new CLIApp());
1.1       root       39: 
                     40:        // wxApp とよく似せるため
                     41:        app->ac = ac;
                     42:        app->av = av;
1.1.1.4   root       43:        return app->OnInit();
1.1       root       44: }
                     45: 
                     46: // ここがエントリポイント(のつもり)
1.1.1.4   root       47: int
1.1       root       48: CLIApp::OnInit()
                     49: {
1.1.1.4   root       50:        int rv;
                     51: 
1.1.1.6   root       52:        // CLI 側では関係ないが wx 側で必要なので初期化は2ステージに分かれている
                     53:        rv = gMainApp.Init1(true, ac, av);
1.1.1.4   root       54:        if (rv != MainApp::PASS) {
                     55:                return rv;
1.1       root       56:        }
1.1.1.9   root       57:        // UIMessage の初期化はなんとなくスレッド開始前のほうがよかろう
                     58:        kq = CUIMessage::Init();
                     59:        if (kq < 0) {
                     60:                return EXIT_FAILURE;
                     61:        }
1.1.1.12! root       62: 
        !            63:        // モニタ登録締切。CLI ではあまり関係ないけど揃えておく。
        !            64:        gMonitorManager->Fix();
        !            65: 
        !            66:        // スレッド作成を伴う初期化。
1.1.1.6   root       67:        if (!gMainApp.Init2()) {
1.1.1.4   root       68:                return EXIT_FAILURE;
1.1       root       69:        }
                     70: 
                     71:        // メインウィンドウに相当するところ
                     72:        OnCreate();
                     73: 
1.1.1.12! root       74:        // 戻ってきたので、VM を解放。
        !            75:        gMainApp.Dispose();
        !            76: 
1.1.1.4   root       77:        return EXIT_SUCCESS;
1.1       root       78: }
                     79: 
                     80: // メインウィンドウ作成後のイベントに相当するところ
1.1.1.7   root       81: int
1.1       root       82: CLIApp::OnCreate()
                     83: {
1.1.1.9   root       84:        CUIMessage::Connect(UIMessage::APPEXIT,
                     85:                [&](const UIMessage&) { OnAppExit(); });
1.1.1.11  root       86:        if (gMainApp.Has(VMCap::M68K)) {
1.1.1.8   root       87:                CUIMessage::Connect(UIMessage::HALT,
                     88:                        [&](const UIMessage&) { OnHalt(); });
                     89:        }
                     90:        // UIMessage の処理を開始する。
                     91:        UIMessage::Attach(&CUIMessage::Process);
                     92: 
1.1.1.6   root       93:        // 電源投入
1.1.1.11  root       94:        auto power = GetPowerDevice();
1.1.1.12! root       95:        power->PushPowerButton();
1.1       root       96: 
1.1.1.9   root       97:        // メッセージを待つ
                     98:        while (exit_request == false) {
                     99:                struct kevent kev;
                    100: 
                    101:                if (kevent_poll(kq, &kev, 1, NULL) < 0) {
                    102:                        if (errno == EINTR) {
                    103:                                continue;
                    104:                        }
                    105:                        warn("CLIApp::OnCreate: kevent_poll");
                    106:                        // XXX どうする?
                    107:                        continue;
                    108:                }
                    109: 
                    110:                // パイプから1メッセージ分読み出す
                    111:                UIMessage m;
                    112:                if (read((int)kev.ident, &m, sizeof(m)) < 0) {
                    113:                        warn("CLIApp::OnCreate: read");
                    114:                        // XXX どうする?
                    115:                        continue;
                    116:                }
                    117: 
                    118:                // ディスパッチ
                    119:                CUIMessage::Dispatch(m);
                    120:        }
1.1.1.7   root      121: 
                    122:        return 0;
1.1       root      123: }
1.1.1.3   root      124: 
                    125: // m680x0 ダブルバスフォールト時に呼ばれるコールバック。
                    126: void
1.1.1.8   root      127: CLIApp::OnHalt()
1.1.1.3   root      128: {
                    129:        // どうする?
                    130:        warnx("Double bus fault has occurred in VM");
                    131: }
1.1.1.9   root      132: 
                    133: // アプリケーションの終了要求で呼ばれるコールバック。
                    134: void
                    135: CLIApp::OnAppExit()
                    136: {
                    137:        exit_request = true;
                    138: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.