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

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.10  root       15: #include "power.h"
1.1       root       16: #include "vm.h"
                     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.6   root       62:        if (!gMainApp.Init2()) {
1.1.1.4   root       63:                return EXIT_FAILURE;
1.1       root       64:        }
                     65: 
                     66:        // メインウィンドウに相当するところ
                     67:        OnCreate();
                     68: 
1.1.1.4   root       69:        return EXIT_SUCCESS;
1.1       root       70: }
                     71: 
                     72: // メインウィンドウ作成後のイベントに相当するところ
1.1.1.7   root       73: int
1.1       root       74: CLIApp::OnCreate()
                     75: {
1.1.1.9   root       76:        CUIMessage::Connect(UIMessage::APPEXIT,
                     77:                [&](const UIMessage&) { OnAppExit(); });
1.1.1.11! root       78:        if (gMainApp.Has(VMCap::M68K)) {
1.1.1.8   root       79:                CUIMessage::Connect(UIMessage::HALT,
                     80:                        [&](const UIMessage&) { OnHalt(); });
                     81:        }
                     82:        // UIMessage の処理を開始する。
                     83:        UIMessage::Attach(&CUIMessage::Process);
                     84: 
1.1.1.6   root       85:        // 電源投入
1.1.1.11! root       86:        auto power = GetPowerDevice();
        !            87:        power->PowerButton();
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メッセージ分読み出す
                    103:                UIMessage m;
                    104:                if (read((int)kev.ident, &m, sizeof(m)) < 0) {
                    105:                        warn("CLIApp::OnCreate: read");
                    106:                        // XXX どうする?
                    107:                        continue;
                    108:                }
                    109: 
                    110:                // ディスパッチ
                    111:                CUIMessage::Dispatch(m);
                    112:        }
1.1.1.7   root      113: 
1.1.1.9   root      114:        // VM を解放
                    115:        gVM->Dispose();
1.1.1.7   root      116: 
                    117:        return 0;
1.1       root      118: }
1.1.1.3   root      119: 
                    120: // m680x0 ダブルバスフォールト時に呼ばれるコールバック。
                    121: void
1.1.1.8   root      122: CLIApp::OnHalt()
1.1.1.3   root      123: {
                    124:        // どうする?
                    125:        warnx("Double bus fault has occurred in VM");
                    126: }
1.1.1.9   root      127: 
                    128: // アプリケーションの終了要求で呼ばれるコールバック。
                    129: void
                    130: CLIApp::OnAppExit()
                    131: {
                    132:        exit_request = true;
                    133: }

unix.superglobalmegacorp.com

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