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

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: 
                      7: #pragma once
                      8: 
                      9: #include "device.h"
                     10: #include <vector>
                     11: 
                     12: // ユーザ定義リテラルを使ったサフィックス
                     13: 
1.1.1.2   root       14: // ナノ秒
                     15: static inline uint64 operator"" _nsec(unsigned long long ns)
                     16: {
                     17:        return ns;
                     18: }
                     19: static inline uint64 operator"" _nsec(long double ns)
                     20: {
                     21:        return ns;
                     22: }
                     23: 
1.1       root       24: // マイクロ秒
                     25: static inline uint64 operator"" _usec(unsigned long long us)
                     26: {
1.1.1.5   root       27:        return us * 1000_nsec;
1.1       root       28: }
                     29: static inline uint64 operator"" _usec(long double us)
                     30: {
1.1.1.5   root       31:        return us * 1000_nsec;
1.1       root       32: }
                     33: 
                     34: // ミリ秒
                     35: static inline uint64 operator"" _msec(unsigned long long ms)
                     36: {
                     37:        return ms * 1000_usec;
                     38: }
                     39: static inline uint64 operator"" _msec(long double ms)
                     40: {
                     41:        return ms * 1000_usec;
                     42: }
                     43: 
                     44: // 秒
                     45: static inline uint64 operator"" _sec(unsigned long long sec)
                     46: {
                     47:        return sec * 1000_msec;
                     48: }
                     49: static inline uint64 operator"" _sec(long double sec)
                     50: {
                     51:        return sec * 1000_msec;
                     52: }
                     53: 
                     54: // コールバック関数の型
1.1.1.5   root       55: class Event;
                     56: using DeviceCallback_t = void (Device::*)(Event&);
1.1       root       57: 
                     58: // イベント
                     59: //
                     60: // イベントは必要なデバイスごとに用意する。おそらく最初から個数が決まって
                     61: // いることが多いはずなので、デバイスクラス内のメンバ変数(実体) として
                     62: // 宣言し、デバイスのコンストラクタ等で初期化するという流れになるはず。
1.1.1.5   root       63: //
                     64: // VM リセットによるイベントタイマーの停止処理は各デバイスの責任で行うこと。
1.1       root       65: class Event
                     66: {
                     67:  public:
                     68:        Event();
                     69:        virtual ~Event();
                     70: 
1.1.1.3   root       71:        // このイベントタイマーを開始する
                     72:        void Start();
                     73:        // このイベントタイマーを停止する
                     74:        void Stop();
                     75: 
1.1       root       76:        // 以下はイベントを呼び出す側がセットする
                     77: 
1.1.1.6 ! root       78:        // イベントを起こすまでの仮想時刻での相対時間 [nsec]
1.1       root       79:        // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。
1.1.1.5   root       80:        uint64 time {};
1.1       root       81: 
1.1.1.5   root       82:        Device *dev {};                         // デバイス
                     83:        DeviceCallback_t func {};       // コールバック関数
                     84:        int code {};                            // コールバック関数への引数
1.1.1.2   root       85:        std::string GetName() const { return name; }
                     86:        void SetName(const std::string& val);
1.1       root       87: 
                     88:        // スケジューラが内部で使う
1.1.1.5   root       89:        bool active {};                         // スケジューラにセットされていれば真
1.1.1.6 ! root       90:        uint64 vtime {};                        // イベントを起こす仮想時刻
1.1.1.2   root       91: 
                     92:  private:
                     93:        // イベント名(表示用)
                     94:        // '\0' 含まず25文字まで。デバイス名も必要なら含めること。
                     95:        std::string name {};
1.1       root       96: };
                     97: 
                     98: // 全イベントの配列 (scheduler.h にある有効イベントリストとは違うので注意)
                     99: extern std::vector<Event *> gEvents;

unix.superglobalmegacorp.com

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