--- nono/vm/event.cpp 2026/04/29 17:04:28 1.1 +++ nono/vm/event.cpp 2026/04/29 17:05:50 1.1.1.10 @@ -1,21 +1,65 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include "event.h" +// +// イベント +// -// 全イベントの配列 -std::vector gEvents; +#include "event.h" +#include "scheduler.h" // コンストラクタ -Event::Event() +Event::Event(Device *dev_, int code_, + EventCallback_t func_, const std::string& name_) { - // 自身をリストに追加する - gEvents.push_back(this); + dev = dev_; + code = code_; + func = func_; + name = name_; } // デストラクタ Event::~Event() { } + +// 名前をセットする +void +Event::SetName(const std::string& val) +{ + name = val; + if (name.length() > 25) { + dev->putmsgn("Event Name \"%s\" is too long(%u chars)", + name.c_str(), (uint)name.length()); + name.resize(25); + } +} + + +// +// イベントマネージャ +// + +// コンストラクタ +EventManager::EventManager() + : inherited(OBJ_EVENT_MANAGER) +{ +} + +// デストラクタ +EventManager::~EventManager() +{ +} + +// イベントを登録する。 +// こっちは初期設定のほう。イベントを有効にする、ではない。 +Event * +EventManager::Regist(Device *dev_, int code_, + EventCallback_t func_, const std::string& name_) +{ + all.push_back(new Event(dev_, code_, func_, name_)); + return all.back(); +}