classtk_1_1_actor.tex 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. \doxysection{tk::Actor$<$ Msg\+Type, Queue\+Size $>$ クラステンプレート}
  2. \label{classtk_1_1_actor}\index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  3. メッセージ駆動型タスク (アクター) の基底クラス
  4. {\ttfamily \+\#include $<$actor.\+hpp$>$}
  5. \doxysubsubsection*{公開メンバ関数}
  6. \begin{DoxyCompactItemize}
  7. \item
  8. \textbf{ Actor} ()=default
  9. \item
  10. virtual \textbf{ $\sim$\+Actor} ()
  11. \item
  12. bool \textbf{ start} (uint32\+\_\+t prio=\textbf{ PRIO\+\_\+\+NORMAL})
  13. \begin{DoxyCompactList}\small\item\em \doxyref{Actor}{p.}{classtk_1_1_actor} をタスクとして生成し、\+Event\+Hub へ自動登録します \end{DoxyCompactList}\item
  14. bool \textbf{ post} (const Msg\+Type \&msg)
  15. \begin{DoxyCompactList}\small\item\em この \doxyref{Actor}{p.}{classtk_1_1_actor} のメッセージキューへ直接メッセージを送信します (コピー渡し) \end{DoxyCompactList}\item
  16. bool \textbf{ post} (Msg\+Type \&\&msg)
  17. \begin{DoxyCompactList}\small\item\em この \doxyref{Actor}{p.}{classtk_1_1_actor} のメッセージキューへ直接メッセージを送信します (ムーブ渡し) \end{DoxyCompactList}\item
  18. {\footnotesize template$<$typename U = Msg\+Type$>$ }\\std::\+enable\+\_\+if$<$ std::\+is\+\_\+same$<$ U, \textbf{ Message} $>$::\+value, bool $>$::\+type \textbf{ post} (uint32\+\_\+t id, uintptr\+\_\+t arg=0)
  19. \begin{DoxyCompactList}\small\item\em \doxyref{tk::\+\+Message}{p.}{structtk_1_1_message} 型の場合のコンビニエンス送信関数 \end{DoxyCompactList}\item
  20. \textbf{ Task\+Handle} \textbf{ handle} () const
  21. \end{DoxyCompactItemize}
  22. \doxysubsubsection*{限定公開メンバ関数}
  23. \begin{DoxyCompactItemize}
  24. \item
  25. virtual void \textbf{ on\+\_\+start} ()
  26. \begin{DoxyCompactList}\small\item\em タスク起動時、イベントループ突入直前に1度だけ呼ばれる初期化関数 \end{DoxyCompactList}\item
  27. virtual void \textbf{ on\+\_\+message} (const Msg\+Type \&msg)=0
  28. \begin{DoxyCompactList}\small\item\em メッセージ受信時に呼ばれるハンドラ関数 \end{DoxyCompactList}\end{DoxyCompactItemize}
  29. \doxysubsection{詳解}
  30. \subsubsection*{template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$\newline
  31. class tk::\+\+Actor$<$ Msg\+Type, Queue\+Size $>$}
  32. メッセージ駆動型タスク (アクター) の基底クラス
  33. 固定長リングバッファ付きのメッセージキューを持ち、メッセージ到着時に自動起床して {\ttfamily \doxyref{on\+\_\+message()}{p.}{classtk_1_1_actor_a1147554d6ddb64d822285ca5a03506a4}} を実行します。メッセージが無い時は CPU を消費せずブロック待機します。
  34. \begin{DoxyTemplParams}{テンプレート引数}
  35. {\em Msg\+Type} & 受信するメッセージの型 (デフォルト: \doxyref{tk::\+\+Message}{p.}{structtk_1_1_message}) \\
  36. \hline
  37. {\em Queue\+Size} & メッセージキューの最大保持件数 (デフォルト: 8)\\
  38. \hline
  39. \end{DoxyTemplParams}
  40. \begin{DoxyCode}{0}
  41. \DoxyCodeLine{\textcolor{keyword}{struct\ }SensorMsg\ \{\ \textcolor{keywordtype}{float}\ temp;\ \};}
  42. \DoxyCodeLine{}
  43. \DoxyCodeLine{\textcolor{keyword}{class\ }SensorActor\ :\ \textcolor{keyword}{public}\ tk::Actor<SensorMsg,\ 8>\ \{}
  44. \DoxyCodeLine{\textcolor{keyword}{protected}:}
  45. \DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{void}\ on\_start()\textcolor{keyword}{\ override\ }\{}
  46. \DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{comment}{//\ デバイスの初期化}}
  47. \DoxyCodeLine{\ \ \ \ \}}
  48. \DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{void}\ on\_message(\textcolor{keyword}{const}\ SensorMsg\&\ msg)\textcolor{keyword}{\ override\ }\{}
  49. \DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}Temp:\ \%.1f\(\backslash\)n"{}},\ msg.temp);}
  50. \DoxyCodeLine{\ \ \ \ \}}
  51. \DoxyCodeLine{\};}
  52. \end{DoxyCode}
  53. \label{classtk_1_1_actor_doc-constructors}
  54. \doxysubsection{構築子と解体子}
  55. \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!Actor@{Actor}}
  56. \index{Actor@{Actor}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  57. \doxysubsubsection{Actor()}
  58. {\footnotesize\ttfamily \label{classtk_1_1_actor_a776aef8cdcfb4416ef976697eb518ed5}
  59. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  60. \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+\+Actor (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [default]}}
  61. \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!````~Actor@{$\sim$Actor}}
  62. \index{````~Actor@{$\sim$Actor}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  63. \doxysubsubsection{$\sim$Actor()}
  64. {\footnotesize\ttfamily \label{classtk_1_1_actor_abfc63a514a3ae7cdbdf9ceee81c3b0fc}
  65. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  66. virtual \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+$\sim$\textbf{ Actor} (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}
  67. \label{classtk_1_1_actor_doc-func-members}
  68. \doxysubsection{関数詳解}
  69. \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!handle@{handle}}
  70. \index{handle@{handle}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  71. \doxysubsubsection{handle()}
  72. {\footnotesize\ttfamily \label{classtk_1_1_actor_a60a2752360fa7185ec7776f2a6ef766a}
  73. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  74. \textbf{ Task\+Handle} \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+handle (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}
  75. この \doxyref{Actor}{p.}{classtk_1_1_actor} のタスクハンドルを取得 \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!on\_message@{on\_message}}
  76. \index{on\_message@{on\_message}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  77. \doxysubsubsection{on\_message()}
  78. {\footnotesize\ttfamily \label{classtk_1_1_actor_a1147554d6ddb64d822285ca5a03506a4}
  79. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  80. virtual void \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+on\+\_\+message (\begin{DoxyParamCaption}\item[{const Msg\+Type \&}]{msg}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [protected]}, {\ttfamily [pure virtual]}}
  81. メッセージ受信時に呼ばれるハンドラ関数
  82. キューから取り出されたメッセージの実体への参照が渡されます。 派生クラスで必ず実装します。
  83. \begin{DoxyParams}{引数}
  84. {\em msg} & 受信したメッセージ \\
  85. \hline
  86. \end{DoxyParams}
  87. \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!on\_start@{on\_start}}
  88. \index{on\_start@{on\_start}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  89. \doxysubsubsection{on\_start()}
  90. {\footnotesize\ttfamily \label{classtk_1_1_actor_afb31ec0d50d1ac97e6a4ce148a96f78d}
  91. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  92. virtual void \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+on\+\_\+start (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [protected]}, {\ttfamily [virtual]}}
  93. タスク起動時、イベントループ突入直前に1度だけ呼ばれる初期化関数
  94. タスクコンテキスト内で実行されるため、{\ttfamily \doxyref{tk::\+sleep\+\_\+ms()}{p.}{namespacetk_aae83f84121085578a7568437a8dc2447}} を使った初期化ウェイトも安全に行えます。 必要に応じて派生クラスでオーバーライドします。 \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!post@{post}}
  95. \index{post@{post}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  96. \doxysubsubsection{post()\hspace{0.1cm}{\footnotesize\ttfamily [1/3]}}
  97. {\footnotesize\ttfamily \label{classtk_1_1_actor_a224e6be4dca0d1500f2121e97bd0f92d}
  98. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  99. bool \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+post (\begin{DoxyParamCaption}\item[{const Msg\+Type \&}]{msg}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  100. この \doxyref{Actor}{p.}{classtk_1_1_actor} のメッセージキューへ直接メッセージを送信します (コピー渡し)
  101. スレッドセーフ・割り込みセーフ・マルチコアセーフです。
  102. \begin{DoxyParams}{引数}
  103. {\em msg} & 送信するメッセージ \\
  104. \hline
  105. \end{DoxyParams}
  106. \begin{DoxyReturn}{戻り値}
  107. true 送信成功, false キューが満杯
  108. \end{DoxyReturn}
  109. \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!post@{post}}
  110. \index{post@{post}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  111. \doxysubsubsection{post()\hspace{0.1cm}{\footnotesize\ttfamily [2/3]}}
  112. {\footnotesize\ttfamily \label{classtk_1_1_actor_a863f28d824aaa78c75789166b1c2a010}
  113. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  114. bool \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+post (\begin{DoxyParamCaption}\item[{Msg\+Type \&\&}]{msg}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  115. この \doxyref{Actor}{p.}{classtk_1_1_actor} のメッセージキューへ直接メッセージを送信します (ムーブ渡し)
  116. \begin{DoxyParams}{引数}
  117. {\em msg} & 送信するメッセージ (ムーブ) \\
  118. \hline
  119. \end{DoxyParams}
  120. \begin{DoxyReturn}{戻り値}
  121. true 送信成功, false キューが満杯
  122. \end{DoxyReturn}
  123. \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!post@{post}}
  124. \index{post@{post}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  125. \doxysubsubsection{post()\hspace{0.1cm}{\footnotesize\ttfamily [3/3]}}
  126. {\footnotesize\ttfamily \label{classtk_1_1_actor_a5c4f4f2f1b8011a37773617e34218c2d}
  127. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  128. template$<$typename U = Msg\+Type$>$ \\
  129. std::\+enable\+\_\+if$<$ std::\+is\+\_\+same$<$ U, \textbf{ Message} $>$::\+value, bool $>$::\+type \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+post (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{id}{, }\item[{uintptr\+\_\+t}]{arg}{ = {\ttfamily 0}}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  130. \doxyref{tk::\+\+Message}{p.}{structtk_1_1_message} 型の場合のコンビニエンス送信関数
  131. \begin{DoxyParams}{引数}
  132. {\em id} & メッセージ\+ID \\
  133. \hline
  134. {\em arg} & 引数 (省略時: 0) \\
  135. \hline
  136. \end{DoxyParams}
  137. \begin{DoxyReturn}{戻り値}
  138. true 送信成功, false キューが満杯
  139. \end{DoxyReturn}
  140. \index{tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}!start@{start}}
  141. \index{start@{start}!tk::Actor$<$ MsgType, QueueSize $>$@{tk::Actor$<$ MsgType, QueueSize $>$}}
  142. \doxysubsubsection{start()}
  143. {\footnotesize\ttfamily \label{classtk_1_1_actor_ac98ec3132f2ded910a6899b030c06f3f}
  144. template$<$typename Msg\+Type = Message, size\+\_\+t Queue\+Size = 8$>$ \\
  145. bool \textbf{ tk::\+\+Actor}$<$ Msg\+Type, Queue\+Size $>$::\+start (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{prio}{ = {\ttfamily \textbf{ PRIO\+\_\+\+NORMAL}}}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  146. \doxyref{Actor}{p.}{classtk_1_1_actor} をタスクとして生成し、\+Event\+Hub へ自動登録します
  147. {\ttfamily \doxyref{tk::\+start()}{p.}{namespacetk_a675f1829b87e2a43239b6f80a526d0ed}} を呼び出す前に登録する必要があります。
  148. \begin{DoxyParams}{引数}
  149. {\em prio} & タスク優先度 (省略時: \doxyref{tk::\+\+PRIO\+\_\+\+NORMAL}{p.}{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50ea0e6779023b97999c2cef66ba1d4d1fca}) \\
  150. \hline
  151. \end{DoxyParams}
  152. \begin{DoxyReturn}{戻り値}
  153. true 登録成功, false 登録失敗 (タスク枠上限など)
  154. \end{DoxyReturn}
  155. このクラス詳解は次のファイルから抽出されました:\begin{DoxyCompactItemize}
  156. \item
  157. C:\+/\+\+Users/\+yoneda/\+\+Documents/\+\+Pico\+\_\+\+Projects/\+tinykernel/\+tinykernel/\+include/\+tinykernel/\textbf{ actor.\+hpp}\end{DoxyCompactItemize}