tk::Actor actor.hpp typename MsgType Message size_t QueueSize QueueSize 8 MsgType MsgType tk::Actor< MsgType, QueueSize >::queue_[QueueSize] [QueueSize] queue_ tk::Actor::queue_ {} size_t size_t tk::Actor< MsgType, QueueSize >::head_ head_ tk::Actor::head_ {0} size_t size_t tk::Actor< MsgType, QueueSize >::tail_ tail_ tk::Actor::tail_ {0} size_t size_t tk::Actor< MsgType, QueueSize >::count_ count_ tk::Actor::count_ {0} bool bool tk::Actor< MsgType, QueueSize >::waiting_ waiting_ tk::Actor::waiting_ {false} TaskHandle TaskHandle tk::Actor< MsgType, QueueSize >::handle_ handle_ tk::Actor::handle_ {} tk::Actor< MsgType, QueueSize >::Actor ()=default Actor tk::Actor::Actor virtual tk::Actor< MsgType, QueueSize >::~Actor () ~Actor tk::Actor::~Actor bool bool tk::Actor< MsgType, QueueSize >::start (uint32_t prio=PRIO_NORMAL) start tk::Actor::start uint32_t prio PRIO_NORMAL Actor をタスクとして生成し、EventHub へ自動登録します tk::start() を呼び出す前に登録する必要があります。 prio タスク優先度 (省略時: tk::PRIO_NORMAL) true 登録成功, false 登録失敗 (タスク枠上限など) bool bool tk::Actor< MsgType, QueueSize >::post (const MsgType &msg) post tk::Actor::post const MsgType & msg この Actor のメッセージキューへ直接メッセージを送信します (コピー渡し) スレッドセーフ・割り込みセーフ・マルチコアセーフです。 msg 送信するメッセージ true 送信成功, false キューが満杯 bool bool tk::Actor< MsgType, QueueSize >::post (MsgType &&msg) post tk::Actor::post MsgType && msg この Actor のメッセージキューへ直接メッセージを送信します (ムーブ渡し) msg 送信するメッセージ (ムーブ) true 送信成功, false キューが満杯 typename U MsgType std::enable_if< std::is_same< U, Message >::value, bool >::type std::enable_if< std::is_same< U, Message >::value, bool >::type tk::Actor< MsgType, QueueSize >::post (uint32_t id, uintptr_t arg=0) post tk::Actor::post uint32_t id uintptr_t arg 0 tk::Message 型の場合のコンビニエンス送信関数 id メッセージID arg 引数 (省略時: 0) true 送信成功, false キューが満杯 TaskHandle TaskHandle tk::Actor< MsgType, QueueSize >::handle () const handle tk::Actor::handle この Actor のタスクハンドルを取得 void virtual void tk::Actor< MsgType, QueueSize >::on_start () on_start tk::Actor::on_start タスク起動時、イベントループ突入直前に1度だけ呼ばれる初期化関数 タスクコンテキスト内で実行されるため、tk::sleep_ms() を使った初期化ウェイトも安全に行えます。 必要に応じて派生クラスでオーバーライドします。 void virtual void tk::Actor< MsgType, QueueSize >::on_message (const MsgType &msg)=0 on_message tk::Actor::on_message const MsgType & msg メッセージ受信時に呼ばれるハンドラ関数 キューから取り出されたメッセージの実体への参照が渡されます。 派生クラスで必ず実装します。 msg 受信したメッセージ void static void tk::Actor< MsgType, QueueSize >::task_entry (void *arg) task_entry tk::Actor::task_entry void * arg void void tk::Actor< MsgType, QueueSize >::event_loop () event_loop tk::Actor::event_loop メッセージ駆動型タスク (アクター) の基底クラス 固定長リングバッファ付きのメッセージキューを持ち、メッセージ到着時に自動起床して on_message() を実行します。メッセージが無い時は CPU を消費せずブロック待機します。 MsgType 受信するメッセージの型 (デフォルト: tk::Message) QueueSize メッセージキューの最大保持件数 (デフォルト: 8) structSensorMsg{floattemp;}; classSensorActor:publictk::Actor<SensorMsg,8>{ protected: voidon_start()override{ //デバイスの初期化 } voidon_message(constSensorMsg&msg)override{ printf("Temp:%.1f\n",msg.temp); } }; tk::ActorActor tk::Actorcount_ tk::Actorevent_loop tk::Actorhandle tk::Actorhandle_ tk::Actorhead_ tk::Actoron_message tk::Actoron_start tk::Actorpost tk::Actorpost tk::Actorpost tk::Actorqueue_ tk::Actorstart tk::Actortail_ tk::Actortask_entry tk::Actorwaiting_ tk::Actor~Actor