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

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #pragma once
                      7: 
                      8: #include "device.h"
                      9: #include <list>
                     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: {
                     27:        return us * 1000;
                     28: }
                     29: static inline uint64 operator"" _usec(long double us)
                     30: {
                     31:        return us * 1000;
                     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: // コールバック関数の型
                     55: typedef void (Device::*DeviceCallback_t)(int);
                     56: 
                     57: // イベント
                     58: //
                     59: // イベントは必要なデバイスごとに用意する。おそらく最初から個数が決まって
                     60: // いることが多いはずなので、デバイスクラス内のメンバ変数(実体) として
                     61: // 宣言し、デバイスのコンストラクタ等で初期化するという流れになるはず。
                     62: class Event
                     63: {
                     64:  public:
                     65:        Event();
                     66:        virtual ~Event();
                     67: 
1.1.1.3 ! root       68:        // このイベントタイマーを開始する
        !            69:        void Start();
        !            70:        // このイベントタイマーを停止する
        !            71:        void Stop();
        !            72: 
1.1       root       73:        // 以下はイベントを呼び出す側がセットする
                     74: 
                     75:        // イベントを起こすまでの期間 [nsec]
                     76:        // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。
                     77:        // ここは MPU クロックサイクルではなく仮想時間で指定する。
                     78:        uint64 time = 0;
                     79: 
                     80:        Device *dev = NULL;                             // デバイス
                     81:        DeviceCallback_t func = NULL;   // コールバック関数
                     82:        int code = 0;                                   // コールバック関数への引数
1.1.1.2   root       83:        std::string GetName() const { return name; }
                     84:        void SetName(const std::string& val);
1.1       root       85: 
                     86:        // スケジューラが内部で使う
                     87:        bool active = false;                    // スケジューラにセットされていれば真
                     88:        uint64 cycle = 0;                               // イベントを起こす仮想サイクル
1.1.1.2   root       89: 
                     90:  private:
                     91:        // イベント名(表示用)
                     92:        // '\0' 含まず25文字まで。デバイス名も必要なら含めること。
                     93:        std::string name {};
1.1       root       94: };
                     95: 
                     96: // 全イベントの配列 (scheduler.h にある有効イベントリストとは違うので注意)
                     97: 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.