--- nono/vm/event.h 2026/04/29 17:05:29 1.1.1.11 +++ nono/vm/event.h 2026/04/29 17:05:50 1.1.1.12 @@ -10,54 +10,9 @@ #pragma once -#include "nono.h" - -// ユーザ定義リテラルを使ったサフィックス - -// ナノ秒 -static inline constexpr uint64 operator"" _nsec(unsigned long long ns) -{ - return ns; -} -static inline constexpr uint64 operator"" _nsec(long double ns) -{ - return ns; -} - -// マイクロ秒 -static inline constexpr uint64 operator"" _usec(unsigned long long us) -{ - return us * 1000_nsec; -} -static inline constexpr uint64 operator"" _usec(long double us) -{ - return us * 1000_nsec; -} - -// ミリ秒 -static inline constexpr uint64 operator"" _msec(unsigned long long ms) -{ - return ms * 1000_usec; -} -static inline constexpr uint64 operator"" _msec(long double ms) -{ - return ms * 1000_usec; -} - -// 秒 -static inline constexpr uint64 operator"" _sec(unsigned long long sec) -{ - return sec * 1000_msec; -} -static inline constexpr uint64 operator"" _sec(long double sec) -{ - return sec * 1000_msec; -} +#include "device.h" // コールバック関数の型 -class Device; -class Event; -using EventCallback_t = void (Device::*)(Event&); #define ToEventCallback(f) static_cast(f) @@ -71,8 +26,7 @@ using EventCallback_t = void (Device::*) class Event { public: - Event(); - explicit Event(Device *dev_); + Event(Device *, int code_, EventCallback_t, const std::string&); ~Event(); // このイベントが動作中なら true を返す @@ -104,3 +58,40 @@ class Event // '\0' 含まず25文字まで。デバイス名も必要なら含めること。 std::string name {}; }; + +// +// イベントマネージャ +// +class EventManager : public Object +{ + using inherited = Object; + friend class Scheduler; + public: + EventManager(); + ~EventManager() override; + + // イベントを登録する。 + Event *Regist(Device *d) { + return Regist(d, 0); + } + Event *Regist(Device *d, EventCallback_t f) { + return Regist(d, 0, f); + } + Event *Regist(Device *d, EventCallback_t f, const std::string& n) { + return Regist(d, 0, f, n); + } + Event *Regist(Device *d, int code) { + return Regist(d, code, NULL); + } + Event *Regist(Device *d, int code, EventCallback_t f) { + return Regist(d, code, f, ""); + } + Event *Regist(Device *d, int code, EventCallback_t f, const std::string& n); + + private: + std::vector all {}; +}; + +static inline EventManager* GetEventManager() { + return Object::GetObject(OBJ_EVENT_MANAGER); +}