classtk_1_1_actor.tex 15 KB

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