tinykernel
読み取り中…
検索中…
一致する文字列を見つけられません
tk::Actor< MsgType, QueueSize > クラステンプレートabstract

メッセージ駆動型タスク (アクター) の基底クラス [詳解]

#include <actor.hpp>

公開メンバ関数

 Actor ()=default
virtual ~Actor ()
bool start (uint32_t prio=PRIO_NORMAL)
 Actor をタスクとして生成し、EventHub へ自動登録します
bool post (const MsgType &msg)
 この Actor のメッセージキューへ直接メッセージを送信します (コピー渡し)
bool post (MsgType &&msg)
 この Actor のメッセージキューへ直接メッセージを送信します (ムーブ渡し)
template<typename U = MsgType>
std::enable_if< std::is_same< U, Message >::value, bool >::type post (uint32_t id, uintptr_t arg=0)
 tk::Message 型の場合のコンビニエンス送信関数
TaskHandle handle () const

限定公開メンバ関数

virtual void on_start ()
 タスク起動時、イベントループ突入直前に1度だけ呼ばれる初期化関数
virtual void on_message (const MsgType &msg)=0
 メッセージ受信時に呼ばれるハンドラ関数

詳解

template<typename MsgType = Message, size_t QueueSize = 8>
class tk::Actor< MsgType, QueueSize >

メッセージ駆動型タスク (アクター) の基底クラス

固定長リングバッファ付きのメッセージキューを持ち、メッセージ到着時に自動起床して on_message() を実行します。メッセージが無い時は CPU を消費せずブロック待機します。

テンプレート引数
MsgType受信するメッセージの型 (デフォルト: tk::Message)
QueueSizeメッセージキューの最大保持件数 (デフォルト: 8)
struct SensorMsg { float temp; };
class SensorActor : public tk::Actor<SensorMsg, 8> {
protected:
void on_start() override {
// デバイスの初期化
}
void on_message(const SensorMsg& msg) override {
printf("Temp: %.1f\n", msg.temp);
}
};
メッセージ駆動型タスク (アクター) の基底クラス
定義 actor.hpp:174
virtual void on_message(const MsgType &msg)=0
メッセージ受信時に呼ばれるハンドラ関数
virtual void on_start()
タスク起動時、イベントループ突入直前に1度だけ呼ばれる初期化関数
定義 actor.hpp:270

構築子と解体子

◆ Actor()

template<typename MsgType = Message, size_t QueueSize = 8>
tk::Actor< MsgType, QueueSize >::Actor ( )
default

◆ ~Actor()

template<typename MsgType = Message, size_t QueueSize = 8>
virtual tk::Actor< MsgType, QueueSize >::~Actor ( )
inlinevirtual

関数詳解

◆ handle()

template<typename MsgType = Message, size_t QueueSize = 8>
TaskHandle tk::Actor< MsgType, QueueSize >::handle ( ) const
inline

この Actor のタスクハンドルを取得

◆ on_message()

template<typename MsgType = Message, size_t QueueSize = 8>
virtual void tk::Actor< MsgType, QueueSize >::on_message ( const MsgType & msg)
protectedpure virtual

メッセージ受信時に呼ばれるハンドラ関数

キューから取り出されたメッセージの実体への参照が渡されます。 派生クラスで必ず実装します。

引数
msg受信したメッセージ

◆ on_start()

template<typename MsgType = Message, size_t QueueSize = 8>
virtual void tk::Actor< MsgType, QueueSize >::on_start ( )
inlineprotectedvirtual

タスク起動時、イベントループ突入直前に1度だけ呼ばれる初期化関数

タスクコンテキスト内で実行されるため、tk::sleep_ms() を使った初期化ウェイトも安全に行えます。 必要に応じて派生クラスでオーバーライドします。

◆ post() [1/3]

template<typename MsgType = Message, size_t QueueSize = 8>
bool tk::Actor< MsgType, QueueSize >::post ( const MsgType & msg)
inline

この Actor のメッセージキューへ直接メッセージを送信します (コピー渡し)

スレッドセーフ・割り込みセーフ・マルチコアセーフです。

引数
msg送信するメッセージ
戻り値
true 送信成功, false キューが満杯

◆ post() [2/3]

template<typename MsgType = Message, size_t QueueSize = 8>
bool tk::Actor< MsgType, QueueSize >::post ( MsgType && msg)
inline

この Actor のメッセージキューへ直接メッセージを送信します (ムーブ渡し)

引数
msg送信するメッセージ (ムーブ)
戻り値
true 送信成功, false キューが満杯

◆ post() [3/3]

template<typename MsgType = Message, size_t QueueSize = 8>
template<typename U = MsgType>
std::enable_if< std::is_same< U, Message >::value, bool >::type tk::Actor< MsgType, QueueSize >::post ( uint32_t id,
uintptr_t arg = 0 )
inline

tk::Message 型の場合のコンビニエンス送信関数

引数
idメッセージID
arg引数 (省略時: 0)
戻り値
true 送信成功, false キューが満杯

◆ start()

template<typename MsgType = Message, size_t QueueSize = 8>
bool tk::Actor< MsgType, QueueSize >::start ( uint32_t prio = PRIO_NORMAL)
inline

Actor をタスクとして生成し、EventHub へ自動登録します

tk::start() を呼び出す前に登録する必要があります。

引数
prioタスク優先度 (省略時: tk::PRIO_NORMAL)
戻り値
true 登録成功, false 登録失敗 (タスク枠上限など)

このクラス詳解は次のファイルから抽出されました:
  • C:/Users/yoneda/Documents/Pico_Projects/tinykernel/tinykernel/include/tinykernel/actor.hpp