--- nono/vm/event.h 2026/04/29 17:04:28 1.1 +++ nono/vm/event.h 2026/04/29 17:04:35 1.1.1.4 @@ -1,16 +1,26 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #pragma once #include "device.h" -#include #include // ユーザ定義リテラルを使ったサフィックス +// ナノ秒 +static inline uint64 operator"" _nsec(unsigned long long ns) +{ + return ns; +} +static inline uint64 operator"" _nsec(long double ns) +{ + return ns; +} + // マイクロ秒 static inline uint64 operator"" _usec(unsigned long long us) { @@ -42,7 +52,7 @@ static inline uint64 operator"" _sec(lon } // コールバック関数の型 -typedef void (Device::*DeviceCallback_t)(int); +using DeviceCallback_t = void (Device::*)(int); // イベント // @@ -55,6 +65,11 @@ class Event Event(); virtual ~Event(); + // このイベントタイマーを開始する + void Start(); + // このイベントタイマーを停止する + void Stop(); + // 以下はイベントを呼び出す側がセットする // イベントを起こすまでの期間 [nsec] @@ -65,11 +80,17 @@ class Event Device *dev = NULL; // デバイス DeviceCallback_t func = NULL; // コールバック関数 int code = 0; // コールバック関数への引数 - std::string name {}; // イベント名(表示用) 最大15文字 + std::string GetName() const { return name; } + void SetName(const std::string& val); // スケジューラが内部で使う bool active = false; // スケジューラにセットされていれば真 uint64 cycle = 0; // イベントを起こす仮想サイクル + + private: + // イベント名(表示用) + // '\0' 含まず25文字まで。デバイス名も必要なら含めること。 + std::string name {}; }; // 全イベントの配列 (scheduler.h にある有効イベントリストとは違うので注意)