Annotation of nono/vm/event.h, revision 1.1.1.12

1.1       root        1: //
                      2: // nono
1.1.1.4   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: // イベント
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
1.1.1.12! root       13: #include "device.h"
1.1       root       14: 
                     15: // コールバック関数の型
1.1.1.9   root       16: #define ToEventCallback(f) static_cast<EventCallback_t>(f)
                     17: 
1.1       root       18: 
                     19: // イベント
                     20: //
                     21: // イベントは必要なデバイスごとに用意する。おそらく最初から個数が決まって
                     22: // いることが多いはずなので、デバイスクラス内のメンバ変数(実体) として
                     23: // 宣言し、デバイスのコンストラクタ等で初期化するという流れになるはず。
1.1.1.5   root       24: //
                     25: // VM リセットによるイベントタイマーの停止処理は各デバイスの責任で行うこと。
1.1       root       26: class Event
                     27: {
                     28:  public:
1.1.1.12! root       29:        Event(Device *, int code_, EventCallback_t, const std::string&);
1.1.1.9   root       30:        ~Event();
1.1       root       31: 
1.1.1.7   root       32:        // このイベントが動作中なら true を返す
                     33:        bool IsRunning() const {
                     34:                return active;
                     35:        }
                     36: 
1.1       root       37:        // 以下はイベントを呼び出す側がセットする
                     38: 
1.1.1.6   root       39:        // イベントを起こすまでの仮想時刻での相対時間 [nsec]
1.1       root       40:        // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。
1.1.1.5   root       41:        uint64 time {};
1.1       root       42: 
1.1.1.5   root       43:        Device *dev {};                         // デバイス
1.1.1.9   root       44:        EventCallback_t func {};        // コールバック関数
1.1.1.5   root       45:        int code {};                            // コールバック関数への引数
1.1.1.9   root       46:        const std::string GetName() const { return name; }
1.1.1.2   root       47:        void SetName(const std::string& val);
1.1       root       48: 
                     49:        // スケジューラが内部で使う
1.1.1.5   root       50:        bool active {};                         // スケジューラにセットされていれば真
1.1.1.6   root       51:        uint64 vtime {};                        // イベントを起こす仮想時刻
1.1.1.2   root       52: 
1.1.1.9   root       53:        uint64 count {};                        // コールバックを呼び出した回数
                     54:        uint64 last_count {};           // (表示用)前回表示したときの count
                     55: 
1.1.1.2   root       56:  private:
                     57:        // イベント名(表示用)
                     58:        // '\0' 含まず25文字まで。デバイス名も必要なら含めること。
                     59:        std::string name {};
1.1       root       60: };
1.1.1.12! root       61: 
        !            62: //
        !            63: // イベントマネージャ
        !            64: //
        !            65: class EventManager : public Object
        !            66: {
        !            67:        using inherited = Object;
        !            68:        friend class Scheduler;
        !            69:  public:
        !            70:        EventManager();
        !            71:        ~EventManager() override;
        !            72: 
        !            73:        // イベントを登録する。
        !            74:        Event *Regist(Device *d) {
        !            75:                return Regist(d, 0);
        !            76:        }
        !            77:        Event *Regist(Device *d, EventCallback_t f) {
        !            78:                return Regist(d, 0, f);
        !            79:        }
        !            80:        Event *Regist(Device *d, EventCallback_t f, const std::string& n) {
        !            81:                return Regist(d, 0, f, n);
        !            82:        }
        !            83:        Event *Regist(Device *d, int code) {
        !            84:                return Regist(d, code, NULL);
        !            85:        }
        !            86:        Event *Regist(Device *d, int code, EventCallback_t f) {
        !            87:                return Regist(d, code, f, "");
        !            88:        }
        !            89:        Event *Regist(Device *d, int code, EventCallback_t f, const std::string& n);
        !            90: 
        !            91:  private:
        !            92:        std::vector<Event *> all {};
        !            93: };
        !            94: 
        !            95: static inline EventManager* GetEventManager() {
        !            96:        return Object::GetObject<EventManager>(OBJ_EVENT_MANAGER);
        !            97: }

unix.superglobalmegacorp.com

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