tecscde 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rubocop.yml +125 -0
  4. data/.rubocop_todo.yml +188 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE +46 -0
  8. data/LICENSE.ja +32 -0
  9. data/README.ja.md +200 -0
  10. data/README.md +35 -0
  11. data/Rakefile +27 -0
  12. data/bin/tecscde +64 -0
  13. data/glade/tecscde-cell-property.glade +205 -0
  14. data/glade/tecscde-celltype-property.glade +172 -0
  15. data/glade/tecscde-celltype.glade +414 -0
  16. data/glade/tecscde-export.glade +161 -0
  17. data/glade/test-cell-plugin.rb +51 -0
  18. data/glade/test-cell-property.rb +35 -0
  19. data/glade/test-export.rb +35 -0
  20. data/glade/test-palette.rb +26 -0
  21. data/lib/tcflow.rb +148 -0
  22. data/lib/tecscde.rb +65 -0
  23. data/lib/tecscde/NewCell.png +0 -0
  24. data/lib/tecscde/SelectArrow.png +0 -0
  25. data/lib/tecscde/attr_tree_view.rb +253 -0
  26. data/lib/tecscde/cell_plugin_dialog.glade +294 -0
  27. data/lib/tecscde/cell_plugin_dialog.rb +89 -0
  28. data/lib/tecscde/celltype_tree_view.rb +105 -0
  29. data/lib/tecscde/change_set_control.rb +35 -0
  30. data/lib/tecscde/change_set_control/change_set.rb +32 -0
  31. data/lib/tecscde/change_set_control/change_set_manager.rb +62 -0
  32. data/lib/tecscde/command.rb +35 -0
  33. data/lib/tecscde/control.rb +491 -0
  34. data/lib/tecscde/highlighted_objects.rb +180 -0
  35. data/lib/tecscde/logger.rb +74 -0
  36. data/lib/tecscde/main_view_and_model.rb +80 -0
  37. data/lib/tecscde/palette.glade +553 -0
  38. data/lib/tecscde/palette.rb +174 -0
  39. data/lib/tecscde/preferences.glade +117 -0
  40. data/lib/tecscde/preferences.rb +44 -0
  41. data/lib/tecscde/tecs_model.rb +1137 -0
  42. data/lib/tecscde/tecs_model/hbar.rb +68 -0
  43. data/lib/tecscde/tecs_model/tm_c_port.rb +122 -0
  44. data/lib/tecscde/tecs_model/tm_c_port_array.rb +98 -0
  45. data/lib/tecscde/tecs_model/tm_cell.rb +496 -0
  46. data/lib/tecscde/tecs_model/tm_e_port.rb +126 -0
  47. data/lib/tecscde/tecs_model/tm_e_port_array.rb +78 -0
  48. data/lib/tecscde/tecs_model/tm_join.rb +293 -0
  49. data/lib/tecscde/tecs_model/tm_join_bar.rb +146 -0
  50. data/lib/tecscde/tecs_model/tm_port.rb +238 -0
  51. data/lib/tecscde/tecs_model/tm_port_array.rb +246 -0
  52. data/lib/tecscde/tecs_model/tm_region.rb +107 -0
  53. data/lib/tecscde/tecs_model/tm_uneditable.rb +68 -0
  54. data/lib/tecscde/tecs_model/vbar.rb +68 -0
  55. data/lib/tecscde/templates/_cell_info.cde.erb +15 -0
  56. data/lib/tecscde/templates/_join_info.cde.erb +28 -0
  57. data/lib/tecscde/templates/main.cde.erb +49 -0
  58. data/lib/tecscde/tm_object.rb +91 -0
  59. data/lib/tecscde/version.rb +4 -0
  60. data/lib/tecscde/view.rb +58 -0
  61. data/lib/tecscde/view/cairo_matrix.rb +90 -0
  62. data/lib/tecscde/view/canvas.rb +59 -0
  63. data/lib/tecscde/view/constants.rb +114 -0
  64. data/lib/tecscde/view/main_view.rb +1245 -0
  65. data/lib/tecsflow.rb +475 -0
  66. data/lib/tecsflow/C_parser.tab.rb +2471 -0
  67. data/lib/tecsflow/C_parser.y.rb +1087 -0
  68. data/lib/tecsflow/classes.rb +421 -0
  69. data/lib/tecsgen.rb +581 -0
  70. data/lib/tecsgen/core/C_parser.tab.rb +2477 -0
  71. data/lib/tecsgen/core/C_parser.y +1032 -0
  72. data/lib/tecsgen/core/bnf-deb.tab.rb +5193 -0
  73. data/lib/tecsgen/core/bnf.tab.rb +5193 -0
  74. data/lib/tecsgen/core/bnf.y +2211 -0
  75. data/lib/tecsgen/core/componentobj.rb +7901 -0
  76. data/lib/tecsgen/core/ctypes.rb +226 -0
  77. data/lib/tecsgen/core/expression.rb +1031 -0
  78. data/lib/tecsgen/core/gen_xml.rb +374 -0
  79. data/lib/tecsgen/core/generate.rb +5206 -0
  80. data/lib/tecsgen/core/location.rb +116 -0
  81. data/lib/tecsgen/core/messages.rb +101 -0
  82. data/lib/tecsgen/core/optimize.rb +456 -0
  83. data/lib/tecsgen/core/plugin.rb +332 -0
  84. data/lib/tecsgen/core/pluginModule.rb +165 -0
  85. data/lib/tecsgen/core/syntaxobj.rb +1234 -0
  86. data/lib/tecsgen/core/tecs_lang.rb +306 -0
  87. data/lib/tecsgen/core/tecsgen.rb +453 -0
  88. data/lib/tecsgen/core/tecsinfo.rb +860 -0
  89. data/lib/tecsgen/core/tool_info.rb +258 -0
  90. data/lib/tecsgen/core/types.rb +1632 -0
  91. data/lib/tecsgen/core/unjoin_plugin.rb +218 -0
  92. data/lib/tecsgen/core/value.rb +650 -0
  93. data/lib/tecsgen/messages/messages_console_en_US.rb +1171 -0
  94. data/lib/tecsgen/messages/messages_console_ja_JP.rb +1171 -0
  95. data/lib/tecsgen/messages/messages_file_en_US.rb +334 -0
  96. data/lib/tecsgen/messages/messages_file_ja_JP.rb +163 -0
  97. data/lib/tecsgen/plugin/ATK1AlarmPlugin.rb +196 -0
  98. data/lib/tecsgen/plugin/ATK1DelayTaskPlugin.rb +106 -0
  99. data/lib/tecsgen/plugin/ATK1EventPlugin.rb +147 -0
  100. data/lib/tecsgen/plugin/ATK1ISRPlugin.rb +174 -0
  101. data/lib/tecsgen/plugin/ATK1KernelPlugin.rb +287 -0
  102. data/lib/tecsgen/plugin/ATK1ResourcePlugin.rb +124 -0
  103. data/lib/tecsgen/plugin/ATK1TaskPlugin.rb +220 -0
  104. data/lib/tecsgen/plugin/C2TECSBridgePlugin.rb +210 -0
  105. data/lib/tecsgen/plugin/CellPlugin.rb +61 -0
  106. data/lib/tecsgen/plugin/CelltypePlugin.rb +72 -0
  107. data/lib/tecsgen/plugin/CompositePlugin.rb +66 -0
  108. data/lib/tecsgen/plugin/DomainPlugin.rb +89 -0
  109. data/lib/tecsgen/plugin/HRP2AlarmHandlerPlugin.rb +76 -0
  110. data/lib/tecsgen/plugin/HRP2Cache.rb +1 -0
  111. data/lib/tecsgen/plugin/HRP2CyclicHandlerPlugin.rb +75 -0
  112. data/lib/tecsgen/plugin/HRP2DataqueuePlugin.rb +68 -0
  113. data/lib/tecsgen/plugin/HRP2EventflagPlugin.rb +68 -0
  114. data/lib/tecsgen/plugin/HRP2FixedSizeMemoryPoolPlugin.rb +68 -0
  115. data/lib/tecsgen/plugin/HRP2HandlerPlugin.rb +117 -0
  116. data/lib/tecsgen/plugin/HRP2KernelObjectPlugin.rb +372 -0
  117. data/lib/tecsgen/plugin/HRP2ObjectPlugin.rb +94 -0
  118. data/lib/tecsgen/plugin/HRP2Plugin.rb +140 -0
  119. data/lib/tecsgen/plugin/HRP2PostHook.rb +111 -0
  120. data/lib/tecsgen/plugin/HRP2PriorityDataqueuePlugin.rb +66 -0
  121. data/lib/tecsgen/plugin/HRP2RPCPlugin.rb +319 -0
  122. data/lib/tecsgen/plugin/HRP2SVCPlugin.rb +473 -0
  123. data/lib/tecsgen/plugin/HRP2SemaphorePlugin.rb +67 -0
  124. data/lib/tecsgen/plugin/HRP2TaskPlugin.rb +200 -0
  125. data/lib/tecsgen/plugin/HRPHandlerPlugin.rb +125 -0
  126. data/lib/tecsgen/plugin/HRPKernelObjectManager.rb +72 -0
  127. data/lib/tecsgen/plugin/HRPKernelObjectPlugin.rb +333 -0
  128. data/lib/tecsgen/plugin/HRPObjectPlugin.rb +93 -0
  129. data/lib/tecsgen/plugin/HRPPlugin.rb +356 -0
  130. data/lib/tecsgen/plugin/HRPRPCPlugin.rb +407 -0
  131. data/lib/tecsgen/plugin/HRPSVCPlugin.rb +859 -0
  132. data/lib/tecsgen/plugin/HRPTaskPlugin.rb +107 -0
  133. data/lib/tecsgen/plugin/Mruby2CBridgePlugin.rb +86 -0
  134. data/lib/tecsgen/plugin/MrubyBridgeCellPlugin.rb +264 -0
  135. data/lib/tecsgen/plugin/MrubyBridgeCelltypePlugin.rb +293 -0
  136. data/lib/tecsgen/plugin/MrubyBridgeCompositePlugin.rb +49 -0
  137. data/lib/tecsgen/plugin/MrubyBridgePlugin.rb +67 -0
  138. data/lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb +1307 -0
  139. data/lib/tecsgen/plugin/MrubyInfoBridgePlugin.rb +14 -0
  140. data/lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb +994 -0
  141. data/lib/tecsgen/plugin/MultiPlugin.rb +57 -0
  142. data/lib/tecsgen/plugin/NotifierPlugin.rb +1217 -0
  143. data/lib/tecsgen/plugin/OpaqueMarshalerPlugin.rb +81 -0
  144. data/lib/tecsgen/plugin/OpaqueRPCPlugin.rb +323 -0
  145. data/lib/tecsgen/plugin/RPCPlugin.rb +266 -0
  146. data/lib/tecsgen/plugin/RepeatCellPlugin.rb +166 -0
  147. data/lib/tecsgen/plugin/RepeatJoinPlugin.rb +130 -0
  148. data/lib/tecsgen/plugin/SharedOpaqueRPCPlugin.rb +357 -0
  149. data/lib/tecsgen/plugin/SharedRPCPlugin.rb +329 -0
  150. data/lib/tecsgen/plugin/SignaturePlugin.rb +77 -0
  151. data/lib/tecsgen/plugin/TECS2CBridgePlugin.rb +178 -0
  152. data/lib/tecsgen/plugin/TECSInfoPlugin.rb +280 -0
  153. data/lib/tecsgen/plugin/ThroughPlugin.rb +333 -0
  154. data/lib/tecsgen/plugin/TracePlugin.rb +484 -0
  155. data/lib/tecsgen/plugin/lib/GenHRP2Marshaler.rb +761 -0
  156. data/lib/tecsgen/plugin/lib/GenOpaqueMarshaler.rb +1107 -0
  157. data/lib/tecsgen/plugin/lib/GenParamCopy.rb +365 -0
  158. data/lib/tecsgen/plugin/lib/GenTransparentMarshaler.rb +683 -0
  159. data/lib/tecsgen/plugin/lib/MrubyBridgeCelltypePluginModule.rb +283 -0
  160. data/lib/tecsgen/plugin/lib/MrubyBridgeSignaturePluginModule.rb +277 -0
  161. data/lib/tecsgen/version.rb +6 -0
  162. data/samples/FigureSamples/active/active.cde +104 -0
  163. data/samples/FigureSamples/active/active.cdl +20 -0
  164. data/samples/FigureSamples/active/active.pdf +0 -0
  165. data/samples/FigureSamples/active/active.png +0 -0
  166. data/samples/FigureSamples/active/gen/tmp_C_src.c +36 -0
  167. data/samples/FigureSamples/active/gen/tmp_cygwin_tecs.h +1908 -0
  168. data/samples/FigureSamples/active/gen/tmp_plugin_post_code.cdl +0 -0
  169. data/samples/FigureSamples/allocator/allocator-internal.png +0 -0
  170. data/samples/FigureSamples/allocator/allocator.cde +171 -0
  171. data/samples/FigureSamples/allocator/allocator.cdl +58 -0
  172. data/samples/FigureSamples/allocator/allocator.png +0 -0
  173. data/samples/FigureSamples/basic/Makefile +87 -0
  174. data/samples/FigureSamples/basic/SimpleSample-trace.cdl +50 -0
  175. data/samples/FigureSamples/basic/SimpleSample.cde +91 -0
  176. data/samples/FigureSamples/basic/SimpleSample.cdl +47 -0
  177. data/samples/FigureSamples/basic/basic.cde +93 -0
  178. data/samples/FigureSamples/basic/basic.cdl +46 -0
  179. data/samples/FigureSamples/basic/basic.png +0 -0
  180. data/samples/FigureSamples/callback/callback.cde +130 -0
  181. data/samples/FigureSamples/callback/callback.cdl +29 -0
  182. data/samples/FigureSamples/callback/callback.png +0 -0
  183. data/samples/FigureSamples/carray/carray.cde +144 -0
  184. data/samples/FigureSamples/carray/carray.cdl +38 -0
  185. data/samples/FigureSamples/carray/carray.png +0 -0
  186. data/samples/FigureSamples/cearray/cearray.cde +314 -0
  187. data/samples/FigureSamples/cearray/cearray.cdl +60 -0
  188. data/samples/FigureSamples/cearray/cearray.png +0 -0
  189. data/samples/FigureSamples/composite/composite-internal.png +0 -0
  190. data/samples/FigureSamples/composite/composite.cde +216 -0
  191. data/samples/FigureSamples/composite/composite.cdl +95 -0
  192. data/samples/FigureSamples/composite/composite.png +0 -0
  193. data/samples/FigureSamples/earray/earray.cde +142 -0
  194. data/samples/FigureSamples/earray/earray.cdl +38 -0
  195. data/samples/FigureSamples/earray/earray.png +0 -0
  196. data/samples/FigureSamples/join/Makefile +87 -0
  197. data/samples/FigureSamples/join/join.cde +132 -0
  198. data/samples/FigureSamples/join/join.cdl +40 -0
  199. data/samples/FigureSamples/join/join.png +0 -0
  200. data/samples/FigureSamples/relay/Makefile +99 -0
  201. data/samples/FigureSamples/relay/relay-internal.png +0 -0
  202. data/samples/FigureSamples/relay/relay.cde +284 -0
  203. data/samples/FigureSamples/relay/relay.cdl +52 -0
  204. data/samples/FigureSamples/relay/relay.png +0 -0
  205. data/samples/FigureSamples/rpc/Makefile +123 -0
  206. data/samples/FigureSamples/rpc/rpc-expand.png +0 -0
  207. data/samples/FigureSamples/rpc/rpc.cde +245 -0
  208. data/samples/FigureSamples/rpc/rpc.png +0 -0
  209. data/samples/FigureSamples/rpc/rpc_sample.cdl +53 -0
  210. data/samples/SimpleSample/Makefile +25 -0
  211. data/samples/SimpleSample/SimpleSample/Makefile +86 -0
  212. data/samples/SimpleSample/SimpleSample/Makefile-trace +91 -0
  213. data/samples/SimpleSample/SimpleSample/README.txt +106 -0
  214. data/samples/SimpleSample/SimpleSample/SimpleSample-trace.cdl +50 -0
  215. data/samples/SimpleSample/SimpleSample/SimpleSample.cdl +45 -0
  216. data/samples/SimpleSample/SimpleSample/src/tSample.c +77 -0
  217. data/samples/SimpleSample/SimpleSample/src/tSimple.c +48 -0
  218. data/samples/SimpleSample/SimpleSample/src/tecs-types.h +27 -0
  219. data/samples/SimpleSample/SimpleSampleOpaqueRPC/Makefile +51 -0
  220. data/samples/SimpleSample/SimpleSampleOpaqueRPC/Makefile-trace +91 -0
  221. data/samples/SimpleSample/SimpleSampleOpaqueRPC/README.txt +106 -0
  222. data/samples/SimpleSample/SimpleSampleOpaqueRPC/SimpleSample-trace.cdl +80 -0
  223. data/samples/SimpleSample/SimpleSampleOpaqueRPC/SimpleSample.cdl +77 -0
  224. data/samples/SimpleSample/SimpleSampleOpaqueRPC/rSample/Makefile +112 -0
  225. data/samples/SimpleSample/SimpleSampleOpaqueRPC/rSimple/Makefile +109 -0
  226. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tSample.c +80 -0
  227. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tSimple.c +47 -0
  228. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tTaskMain.c +66 -0
  229. data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tecs-types.h +27 -0
  230. data/samples/SimpleSample/SimpleSampleTransparentRPC/Makefile +125 -0
  231. data/samples/SimpleSample/SimpleSampleTransparentRPC/Makefile-trace +130 -0
  232. data/samples/SimpleSample/SimpleSampleTransparentRPC/SimpleSample-trace.cdl +54 -0
  233. data/samples/SimpleSample/SimpleSampleTransparentRPC/SimpleSample.cdl +53 -0
  234. data/samples/SimpleSample/SimpleSampleTransparentRPC/src/tSample.c +80 -0
  235. data/samples/SimpleSample/SimpleSampleTransparentRPC/src/tSimple.c +54 -0
  236. data/tecscde.gemspec +41 -0
  237. metadata +353 -0
@@ -0,0 +1,1107 @@
1
+ #
2
+ # TECS Generator
3
+ # Generator for TOPPERS Embedded Component System
4
+ #
5
+ # Copyright (C) 2008-2018 by TOPPERS Project
6
+ #--
7
+ # 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
8
+ # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
9
+ # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
10
+ # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
11
+ # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
12
+ # スコード中に含まれていること.
13
+ # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
14
+ # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
15
+ # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
16
+ # の無保証規定を掲載すること.
17
+ # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
18
+ # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
19
+ # と.
20
+ # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
21
+ # 作権表示,この利用条件および下記の無保証規定を掲載すること.
22
+ # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
23
+ # 報告すること.
24
+ # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
25
+ # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
26
+ # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
27
+ # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
28
+ # 免責すること.
29
+ #
30
+ # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
31
+ # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
32
+ # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
33
+ # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
34
+ # の責任を負わない.
35
+ #
36
+ # $Id: GenOpaqueMarshaler.rb 2952 2018-05-07 10:19:07Z okuma-top $
37
+ #++
38
+
39
+ #== GenOpaqueMarshaler
40
+ # OpaqueRPCPlugin, sharedOpaqueRPCPlugin 共通の要素を集めたモジュール
41
+ module GenOpaqueMarshaler
42
+
43
+ # プラグイン引数名と Proc
44
+ RPCPluginArgProc = {
45
+ "clientChannelCelltype" => Proc.new {|obj, rhs| obj.set_clientChannelCelltype rhs },
46
+ "serverChannelCelltype" => Proc.new {|obj, rhs| obj.set_serverChannelCelltype rhs },
47
+ "clientChannelCell" => Proc.new {|obj, rhs| obj.set_clientChannelCell rhs },
48
+ "serverChannelCell" => Proc.new {|obj, rhs| obj.set_serverChannelCell rhs },
49
+ "clientChannelInitializer" => Proc.new {|obj, rhs| obj.set_clientChannelInitializer rhs },
50
+ "serverChannelInitializer" => Proc.new {|obj, rhs| obj.set_serverChannelInitializer rhs },
51
+ "clientSemaphoreCelltype" => Proc.new {|obj, rhs| obj.set_clientSemaphoreCelltype rhs },
52
+ "clientSemaphoreInitializer" => Proc.new {|obj, rhs| obj.set_clientSemaphoreInitializer rhs },
53
+ "clientErrorHandler" => Proc.new {|obj, rhs| obj.set_clientErrorHandler rhs },
54
+ "serverErrorHandler" => Proc.new {|obj, rhs| obj.set_serverErrorHandler rhs },
55
+ "TDRCelltype" => Proc.new {|obj, rhs| obj.set_TDRCelltype rhs },
56
+ "PPAllocatorSize" => Proc.new {|obj, rhs| obj.set_PPAllocatorSize rhs },
57
+ "substituteAllocator" => Proc.new {|obj, rhs| obj.set_substituteAllocator rhs },
58
+ "noServerChannelOpenerCode" => Proc.new {|obj, rhs| obj.set_noServerChannelOpenerCode rhs },
59
+ "taskCelltype" => Proc.new {|obj, rhs| obj.set_taskCelltype rhs },
60
+ "taskPriority" => Proc.new {|obj, rhs| obj.set_taskPriority rhs },
61
+ "stackSize" => Proc.new {|obj, rhs| obj.set_stackSize rhs },
62
+ }
63
+
64
+ ##### プラグイン引数チェック関数
65
+
66
+ #=== プラグイン引数 taskPriority のチェック
67
+ def set_taskPriority(rhs)
68
+ @taskPriority = rhs
69
+ end
70
+
71
+ #=== プラグイン引数 serverChannelCelltype のチェック
72
+ def set_serverChannelCelltype(rhs)
73
+ @serverChannelCelltype = rhs.to_sym
74
+ # path = [ "::", @serverChannelCelltype ]
75
+ # obj = Namespace.find( path )
76
+ nsp = NamespacePath.analyze(@serverChannelCelltype.to_s)
77
+ obj = Namespace.find(nsp)
78
+ if !obj.instance_of?(Celltype) && !obj.instance_of?(CompositeCelltype)
79
+ cdl_error("RPCPlugin: serverChannelCelltype '#{rhs}' not celltype or not defined")
80
+ end
81
+ end
82
+
83
+ #=== プラグイン引数 clientChannelCelltype のチェック
84
+ def set_clientChannelCelltype(rhs)
85
+ @clientChannelCelltype = rhs.to_sym
86
+ # path = [ "::", @clientChannelCelltype ]
87
+ # obj = Namespace.find( path )
88
+ nsp = NamespacePath.analyze(@clientChannelCelltype.to_s)
89
+ obj = Namespace.find(nsp)
90
+ if !obj.instance_of?(Celltype) && !obj.instance_of?(CompositeCelltype)
91
+ cdl_error("RPCPlugin: clientChanneclCelltype '#{rhs}' not celltype or not defined")
92
+ end
93
+ end
94
+
95
+ #=== プラグイン引数 serverChannelCell のチェック
96
+ def set_serverChannelCell(rhs)
97
+ @serverChannelCell = rhs.to_sym
98
+ # ChannelCell はプラグインで生成されるため、ここではチェックできない
99
+ # path = [ "::", @serverChannelCell ]
100
+ # obj = Namespace.find( path )
101
+ # if ! obj.instance_of?( Cell ) then
102
+ # cdl_error( "RPCPlugin: serverChanneclCell '#{rhs}' not cell or not defined" )
103
+ # end
104
+ end
105
+
106
+ #=== プラグイン引数 clientChannelCell のチェック
107
+ def set_clientChannelCell(rhs)
108
+ @clientChannelCell = rhs.to_sym
109
+ # ChannelCell はプラグインで生成されるため、ここではチェックできない
110
+ # path = [ "::", @clientChannelCell ]
111
+ # obj = Namespace.find( path )
112
+ # if ! obj.instance_of?( Cell ) then
113
+ # cdl_error( "RPCPlugin: clientChanneclCell '#{rhs}' not cell or not defined" )
114
+ # end
115
+ end
116
+
117
+ #=== プラグイン引数 serverChannelInitializer のチェック
118
+ def set_serverChannelInitializer(rhs)
119
+ @serverChannelInitializer = rhs.to_sym
120
+ end
121
+
122
+ #=== プラグイン引数 clientChannelInitializer のチェック
123
+ def set_clientChannelInitializer(rhs)
124
+ @clientChannelInitializer = rhs.to_sym
125
+ end
126
+
127
+ #=== タスクタイプ taskCellype のチェック
128
+ def set_taskCelltype(rhs)
129
+ @taskCelltype = rhs.to_sym
130
+ # path = [ "::", @taskCelltype ]
131
+ # obj = Namespace.find( path )
132
+ nsp = NamespacePath.analyze(@taskCelltype.to_s)
133
+ obj = Namespace.find(nsp)
134
+ if !obj.instance_of?(Celltype) && !obj.instance_of?(CompositeCelltype)
135
+ cdl_error("RPCPlugin: taskCelltype '#{rhs}' not celltype or not defined")
136
+ end
137
+ end
138
+
139
+ #=== タスクタイプ stack\size のチェック
140
+ def set_stackSize(rhs)
141
+ @stackSize = rhs
142
+ end
143
+
144
+ #=== プラグイン引数 PPAllocatorSize のチェック
145
+ def set_PPAllocatorSize(rhs)
146
+ @PPAllocatorSize = rhs
147
+ end
148
+
149
+ #=== プラグイン引数 TDRCelltype のチェック
150
+ def set_TDRCelltype(rhs)
151
+ @TDRCelltype = rhs.to_sym
152
+ # path = [ "::", @TDRCelltype ]
153
+ # obj = Namespace.find( path )
154
+ nsp = NamespacePath.analyze(@TDRCelltype.to_s)
155
+ obj = Namespace.find(nsp)
156
+ if !obj.instance_of?(Celltype) && !obj.instance_of?(CompositeCelltype)
157
+ cdl_error("RPCPlugin: TDRCelltype '#{rhs}' not celltype or not found")
158
+ end
159
+ end
160
+
161
+ #=== プラグイン引数 substituteAllocator のチェック
162
+ # オプション引数が、以下の形式であることをチェック
163
+ # substituteAllocator(Alloc.eAlloc=>Subst.eAlloc,Alloc2.eAlloc=>Subst2.eAlloc)
164
+ def set_substituteAllocator(rhs)
165
+ # str::String : 破壊される(マッチした残りになる)。str.empty? で空になったことをチェックできる
166
+ # regexp::Regexp : 期待するトークンにマッチする正規表現。 "\A" 出始める
167
+ # expected::String: 期待するトークン、regexp が出現しなかった場合にエラーメッセージとして表示
168
+ def optparse (str, regexp, expected)
169
+ str.strip!
170
+ token = nil
171
+ res = str.sub!(regexp){|matched| token = matched; "" }
172
+ if !token
173
+ cdl_error("syntax error in substituteAllocator option near '#{str}', expected '#{expected}'")
174
+ end
175
+ return token
176
+ end
177
+
178
+ opt = rhs.dup
179
+ ident_rexpr = /\A(\w[\w\d]*)/
180
+
181
+ # "Alloc.eAlloc=>CAlloc.eAlloc" の形式になっていることをチェック
182
+ while true
183
+ lhs_alloc_cell = optparse(opt, ident_rexpr, "allocator cell name")
184
+ break if !lhs_alloc_cell
185
+
186
+ res = optparse(opt, /\A\./, ".")
187
+ break if !res
188
+
189
+ lhs_alloc_ent = optparse(opt, ident_rexpr, "allocator cell entry name")
190
+ break if !lhs_alloc_ent
191
+
192
+ res = optparse(opt, /\A\=\>/, "=>")
193
+ break if !res
194
+
195
+ rhs_alloc_cell = optparse(opt, ident_rexpr, "allocator cell name")
196
+ break if !rhs_alloc_cell
197
+
198
+ res = optparse(opt, /\A\./, ".")
199
+ break if !res
200
+
201
+ rhs_alloc_ent = optparse(opt, ident_rexpr, "allocator cell entry name")
202
+ break if !rhs_alloc_ent
203
+
204
+ # ここでは、右辺のチェックはできない。右辺のセルは前方参照となる
205
+ # path = [ "::", rhs_alloc_cell.to_sym ] # mikan namespace
206
+ # obj = Namespace.find( path )
207
+ # if ! obj.instance_of?( Cell ) || obj.get_region.get_path_string != @clientRegion then
208
+ # cdl_error( "RPCPlugin: substituteAllocator: '#{rhs_alloc_cell}' not cell or not found in client region" )
209
+ # else
210
+ # ct = obj.get_celltype
211
+ # if ct # nil なら既にエラー
212
+ # ent = ct.find rhs_alloc_ent
213
+ # if ! ent.instance_of? Port || ent.get_port_type != :ENTRY || ent.get_signature == nil || ! ent.get_signature.is_allocator?
214
+ # cdl_error( "RPCPlugin: substituteAllocator: '#{rhs_alloc_cell}.#{rhs_alloc_ent}' not entry port or not have alllocator signature" )
215
+ # end
216
+ # end
217
+ # end
218
+
219
+ @substituteAllocator[ "#{lhs_alloc_cell}.#{lhs_alloc_ent}".to_sym ] =
220
+ [lhs_alloc_cell, lhs_alloc_ent, rhs_alloc_cell, rhs_alloc_ent]
221
+
222
+ # p "substituteAllocator: #{lhs_alloc_cell}.#{lhs_alloc_ent}=>#{rhs_alloc_cell}.#{rhs_alloc_ent}"
223
+
224
+ break if opt.empty?
225
+
226
+ res = optparse(opt, /\A\,/, ",")
227
+ break if !res
228
+ end
229
+ end
230
+
231
+ #=== プラグイン引数 noServerChannelOpenerCode のチェック
232
+ def set_noServerChannelOpenerCode(rhs)
233
+ rhs = rhs.to_sym
234
+ if rhs == :true
235
+ @noServerChannelOpenerCode = true
236
+ elsif rhs == :false
237
+ @noServerChannelOpenerCode = false
238
+ else
239
+ cdl_error("RPCPlugin: specify true or false for noServerChannelOpenerCode")
240
+ end
241
+ end
242
+
243
+ #=== プラグイン引数 clientSemaphoreCelltype のチェック
244
+ def set_clientSemaphoreCelltype(rhs)
245
+ @semaphoreCelltype = rhs.to_sym
246
+ nsp = NamespacePath.analyze(@semaphoreCelltype.to_s)
247
+ obj = Namespace.find(nsp)
248
+ if !obj.instance_of?(Celltype) && !obj.instance_of?(CompositeCelltype)
249
+ cdl_error("RPCPlugin: clientSemaphoreCelltype '#{rhs}' not celltype or not defined")
250
+ end
251
+ end
252
+
253
+ #=== プラグイン引数 clientSemaphoreInitializer のチェック
254
+ def set_clientSemaphoreInitializer(rhs)
255
+ @semaphoreInitializer = rhs.to_sym
256
+ end
257
+
258
+ #=== プラグイン引数 clientErrorHandler のチェック
259
+ def set_clientErrorHandler(rhs)
260
+ @clientErrorHandler = rhs.to_sym
261
+ end
262
+
263
+ #=== プラグイン引数 serverErrorHandler のチェック
264
+ def set_serverErrorHandler(rhs)
265
+ @serverErrorHandler = rhs.to_sym
266
+ end
267
+
268
+ #=== セルの名前を得る
269
+ # ThroughPlugin::get_cell_name plugin.rb をオーバーライド
270
+ def get_cell_name
271
+ @cell_name
272
+ # @clientChannelCell
273
+ end
274
+
275
+ #=== marshaler のセルタイプ名を設定する
276
+ def initialize_opaque_marshaler
277
+ # オプション設定される変数のデフォルトを設定
278
+ @taskPriority = 11
279
+ @stackSize = 4096
280
+ @serverChannelCelltype = :tSocketServer
281
+ @clientChannelCelltype = :tSocketClient
282
+ @serverChannelCell = :"#{@cell_name}Server"
283
+ @clientChannelCell = :"#{@cell_name}Client"
284
+ @serverChannelInitializer = subst_name("portNo=8931+$count$;").to_sym
285
+ @clientChannelInitializer = subst_name("portNo=8931+$count$; serverAddr=\"127.0.0.1\"; ").to_sym
286
+ @taskCelltype = :tTask
287
+ @PPAllocatorSize = nil
288
+ # @TDRCelltype = :"tTDR" # "tNBOTDR" に変更の予定
289
+ @TDRCelltype = :tNBOTDR
290
+ @substituteAllocator = {}
291
+ @noServerChannelOpenerCode = false
292
+ @semaphoreCelltype = :tSemaphore
293
+ @semaphoreInitializer = :"count = 1; attribute = C_EXP( \"TA_NULL\" ); "
294
+ @clientErrorHandler = nil
295
+ @serverErrorHandler = nil
296
+ @b_genOpener = false
297
+ @taskMainCelltype = :tRPCDedicatedTaskMain
298
+
299
+ @marshaler_celltype_name = :"tOpaqueMarshaler_#{@signature.get_global_name}"
300
+ @unmarshaler_celltype_name = :"tOpaqueUnmarshaler_#{@signature.get_global_name}"
301
+ @marshaler_celltype_file_name = "#{$gen}/#{@marshaler_celltype_name}.cdl"
302
+
303
+ # signature で対応できないものをチェック
304
+ @signature.each_param{|func_decl, param_decl|
305
+ if param_decl.get_direction == :OUT
306
+ if param_decl.get_count && !param_decl.get_size
307
+ cdl_error("#{@signature.get_namespace_path}.#{func_decl.get_name}.#{param_decl.get_name}: size_is must be specified for out parameter of Opaque RPC")
308
+ end
309
+ if param_decl.get_string == -1
310
+ cdl_error("#{@signature.get_namespace_path}.#{func_decl.get_name}.#{param_decl.get_name}: string length must be specified for out parameter of Opaque RPC")
311
+ end
312
+ end
313
+ }
314
+ end
315
+
316
+ #=== GenOpaqueMarshaler# Opener Code の生成時のチェック
317
+ def check_opener_code
318
+ # サーバーチャンネルセルタイプが entry sServerChannelOpener eOpener を持つかどうかをチェック
319
+ # mikan entry か (call でないか) をチェックしていない
320
+ # scct = Namespace.find ["::", @serverChannelCelltype] # mikan namespace
321
+ nsp = NamespacePath.analyze(@serverChannelCelltype.to_s)
322
+ scct = Namespace.find nsp
323
+ if scct
324
+ obj = scct.find(:eOpener)
325
+ if obj.instance_of? Port
326
+ if obj.get_signature.get_name.to_sym == :sServerChannelOpener
327
+ if @noServerChannelOpenerCode == false
328
+ @b_genOpener = true
329
+ @taskMainCelltype = :tRPCDedicatedTaskMainWithOpener
330
+ end
331
+ end
332
+ end
333
+ end
334
+ if @noServerChannelOpenerCode == false && @taskMainCelltype != :tRPCDedicatedTaskMainWithOpener
335
+ cdl_warning("O9999 ServerChannelOpener code not generated, not found 'entry sServerChannelOpener eOpener'")
336
+ end
337
+ end
338
+
339
+ #=== GenOpaqueMarshaler# PPAllocator の必要性をチェックする
340
+ def check_PPAllocator
341
+ if @signature.need_PPAllocator?(true)
342
+ if @PPAllocatorSize.nil?
343
+ cdl_error("PPAllocatorSize must be speicified for size_is array")
344
+ end
345
+ end
346
+ end
347
+
348
+ #####
349
+
350
+ def gen_marshaler_celltype
351
+ f = CFile.open(@marshaler_celltype_file_name, "w")
352
+ # 同じ内容を二度書く可能性あり (AppFile は不可)
353
+
354
+ if @PPAllocatorSize
355
+ alloc_call_port = " call sPPAllocator cPPAllocator;\n"
356
+ else
357
+ alloc_call_port = ""
358
+ end
359
+
360
+ f.print <<EOT
361
+
362
+ celltype #{@marshaler_celltype_name} {
363
+ entry #{@signature.get_namespace_path} eClientEntry;
364
+ call sTDR cTDR;
365
+ [optional]
366
+ call sSemaphore cLockChannel;
367
+ [optional]
368
+ call sRPCErrorHandler cErrorHandler;
369
+ };
370
+ celltype #{@unmarshaler_celltype_name} {
371
+ call #{@signature.get_namespace_path} cServerCall;
372
+ call sTDR cTDR;
373
+ [optional]
374
+ call sRPCErrorHandler cErrorHandler;
375
+ entry sUnmarshalerMain eService;
376
+ #{alloc_call_port}};
377
+ EOT
378
+ f.close
379
+ end
380
+
381
+ #=== 受け口関数の本体コードを生成(頭部と末尾は別途出力)
382
+ # ct_name:: Symbol (through プラグインで生成された) セルタイプ名 .Symbol として送られてくる(らしい)
383
+ def gen_ep_func_body(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params)
384
+ # unmarshaler クラスか?
385
+ if ct_name == @unmarshaler_celltype_name.to_sym
386
+ gen_ep_func_body_unmarshal(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params)
387
+ else
388
+ gen_ep_func_body_marshal(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params)
389
+ end
390
+ end
391
+
392
+ #=== marshal コードの生成
393
+ def gen_ep_func_body_marshal(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params)
394
+ b_void = false
395
+ b_ret_er = false
396
+
397
+ # 関数の戻り値の元の型を得る(typedef されている場合)
398
+ type = func_type.get_type.get_original_type
399
+
400
+ # 戻り値記憶用の変数を出力(void 型の関数では出力しない)
401
+ if !type.is_void?
402
+ file.print("\t#{func_type.get_type.get_type_str}\t\tretval_;\n")
403
+ if func_type.get_type.is_a?(DefinedType) && (func_type.get_type.get_type_str == "ER" || func_type.get_type.get_type_str == "ER_INT")
404
+ b_ret_er = true
405
+ end
406
+ else
407
+ b_void = true
408
+ end
409
+
410
+ file.print("\tER\t\tercd_;\n")
411
+ file.print("\tint16_t\tstate_;\n")
412
+
413
+ # 関数 ID (整数値)
414
+ func_id = "FUNCID_#{@signature.get_global_name}_#{func_name}".upcase
415
+ fid = @signature.get_id_from_func_name(func_name)
416
+ file.print("\tint16_t\tfunc_id_ = #{func_id}; /* (id of '#{func_name}') = #{fid}*/\n")
417
+
418
+ # シングルトンでないか?
419
+ if !b_singleton
420
+
421
+ # singleton でなければ p_cellcb 取得コードを出力
422
+ file.print <<EOT
423
+ #{ct_name}_CB *p_cellcb;
424
+
425
+ if( VALID_IDX( idx ) ){
426
+ p_cellcb = GET_CELLCB(idx);
427
+ EOT
428
+
429
+ # エラーを返すか?
430
+ if b_ret_er
431
+ file.print <<EOT
432
+ }else{
433
+ return ERCD( E_RPC, E_ID );
434
+ }
435
+ EOT
436
+ else
437
+ file.print <<EOT
438
+ }else{
439
+ /* エラー処理コードをここに記述 */
440
+ }
441
+
442
+ EOT
443
+ end
444
+ end
445
+
446
+ if func_type.has_receive?
447
+ file.print " /* initialize receive parameters */\n"
448
+ params.each{|param|
449
+ if param.get_direction == :RECEIVE
450
+ file.print " *#{param.get_name} = 0;\n"
451
+ end
452
+ }
453
+ end
454
+
455
+ # channel lock コード
456
+ file.print <<EOT
457
+
458
+ /* Channel Lock */
459
+ SET_RPC_STATE( state_, RPCSTATE_CLIENT_GET_SEM );
460
+ if( is_cLockChannel_joined() )
461
+ cLockChannel_wait();
462
+ EOT
463
+
464
+ # SOP を送信
465
+ file.print " /* SOPの送出 */\n"
466
+ file.print " SET_RPC_STATE( state_, RPCSTATE_CLIENT_SEND_SOP );\n"
467
+ file.print " if( ( ercd_ = cTDR_sendSOP( true ) ) != E_OK )\n"
468
+ file.print " goto error_reset;\n"
469
+
470
+ # func_id を送信
471
+ file.print " /* 関数 id の送出 */\n"
472
+ file.print " if( ( ercd_ = cTDR_putInt16( func_id_ ) ) != E_OK )\n"
473
+ file.print " goto error_reset;\n"
474
+
475
+ # p "celltype_name, sig_name, func_name, func_global_name"
476
+ # p "#{ct_name}, #{sig_name}, #{func_name}, #{func_global_name}"
477
+
478
+ b_get = false # marshal なら put
479
+ b_marshal = true # marshal
480
+
481
+ # in 方向の入出力を出力
482
+ if func_type.has_inward?
483
+ file.print " /* 入力引数送出 */\n"
484
+ file.print " SET_RPC_STATE( state_, RPCSTATE_CLIENT_SEND_BODY );\n"
485
+ print_params(params, file, 1, b_marshal, b_get, true, "eClientEntry", func_name)
486
+ print_params(params, file, 1, b_marshal, b_get, false, "eClientEntry", func_name)
487
+ end
488
+ print_out_nullable(params, file, 1, b_marshal)
489
+
490
+ if !func_type.is_oneway?
491
+ b_continue = "true"
492
+ else
493
+ b_continue = "false"
494
+ end
495
+ file.print " /* EOPの送出(パケットの掃きだし) */\n"
496
+ file.print " SET_RPC_STATE( state_, RPCSTATE_CLIENT_SEND_EOP );\n"
497
+ file.print " if( (ercd_=cTDR_sendEOP(#{b_continue})) != E_OK )\n"
498
+ file.print " goto error_reset;\n\n"
499
+
500
+ # send のメモリをデアロケート
501
+ if func_type.has_send?
502
+ file.print " /* dealloc send parameter while executing */\n"
503
+ file.print " SET_RPC_STATE( state_, RPCSTATE_CLIENT_EXEC );\n"
504
+ dir = :SEND
505
+ nest = 1
506
+ dealloc_cp = "eClientEntry_#{func_name}"
507
+ dealloc_for_params(params, file, nest, dir, dealloc_cp)
508
+ file.print "\n"
509
+ end
510
+
511
+ if !func_type.is_oneway?
512
+
513
+ file.print " /* パケットの始まりをチェック */\n"
514
+ file.print " SET_RPC_STATE( state_, RPCSTATE_CLIENT_RECV_SOP );\n"
515
+ file.print " if( (ercd_=cTDR_receiveSOP( true )) != E_OK )\n"
516
+ file.print " goto error_reset;\n"
517
+
518
+ b_get = true # marshaler は get
519
+ file.print " /* 戻り値の受け取り */\n"
520
+ print_param("retval_", func_type.get_type, file, 1, :RETURN, nil, nil, b_marshal, b_get)
521
+
522
+ if func_type.has_outward?
523
+ if b_ret_er
524
+ indent_level = 2
525
+ file.print " if( MERCD( retval_ ) != E_RPC ){\n"
526
+ else
527
+ indent_level = 1
528
+ end
529
+ indent = " " * indent_level
530
+
531
+ file.print "#{indent}/* 出力値の受け取り */\n"
532
+ file.print "#{indent}SET_RPC_STATE( state_, RPCSTATE_CLIENT_RECV_BODY );\n"
533
+ print_params(params, file, indent_level, b_marshal, b_get, true, "eClientEntry", func_name)
534
+ print_params(params, file, indent_level, b_marshal, b_get, false, "eClientEntry", func_name)
535
+
536
+ if b_ret_er
537
+ file.print " }\n"
538
+ end
539
+ end
540
+
541
+ file.print "\n /* パケットの終わりをチェック */\n"
542
+ file.print " SET_RPC_STATE( state_, RPCSTATE_CLIENT_RECV_EOP );\n"
543
+ file.print " if( (ercd_=cTDR_receiveEOP(false)) != E_OK )\n" # b_continue = false
544
+ file.print " goto error_reset;\n"
545
+
546
+ end # ! func_type.is_oneway?
547
+
548
+ # channel lock コード
549
+ file.print <<EOT
550
+ /* Channel Unlock */
551
+ SET_RPC_STATE( state_, RPCSTATE_CLIENT_RELEASE_SEM );
552
+ if( is_cLockChannel_joined() )
553
+ cLockChannel_signal();
554
+ EOT
555
+
556
+ if b_void == false
557
+ # 呼び元に戻り値をリターン
558
+ file.print(" return retval_;\n")
559
+ else
560
+ file.print(" return;\n")
561
+ end
562
+
563
+ file.print <<EOT
564
+
565
+ error_reset:
566
+ EOT
567
+ # send のメモリをデアロケート
568
+ if func_type.has_send?
569
+ file.print " /* dealloc send parameter */\n"
570
+ file.print " if( state_ < RPCSTATE_CLIENT_EXEC ){\n"
571
+ dir = :SEND
572
+ nest = 2
573
+ dealloc_cp = "eClientEntry_#{func_name}"
574
+ dealloc_for_params(params, file, nest, dir, dealloc_cp)
575
+ file.print " }\n"
576
+ end
577
+
578
+ # receive のメモリをデアロケート
579
+ if func_type.has_receive?
580
+ file.print(" /* receive parameter */\n")
581
+ dir = :RECEIVE
582
+ nest = 1
583
+ dealloc_cp = "eClientEntry_#{func_name}"
584
+ dealloc_for_params(params, file, nest, dir, dealloc_cp, true)
585
+ end
586
+
587
+ file.print <<EOT
588
+ if( MERCD( ercd_ ) != E_RESET )
589
+ (void)cTDR_reset();
590
+ EOT
591
+
592
+ # channel lock コード
593
+ file.print <<EOT
594
+ /* Channel Unlock */
595
+ if( is_cLockChannel_joined() )
596
+ cLockChannel_signal();
597
+
598
+ if( ercd_ != E_OK && is_cErrorHandler_joined() )
599
+ cErrorHandler_errorOccured( func_id_, ercd_, state_ );
600
+ EOT
601
+
602
+ if b_ret_er != false
603
+ # 呼び元に戻り値をリターン
604
+ file.print(" return ERCD( E_RPC, MERCD( ercd_ ) );\n")
605
+ else
606
+ file.print(" return;\n")
607
+ end
608
+ end
609
+
610
+ #=== unmarshal コードの生成
611
+ def gen_ep_func_body_unmarshal(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params)
612
+ b_ret_er = true
613
+
614
+ # func_id を得るコードを生成
615
+ file.print <<EOT
616
+
617
+ int16_t func_id_;
618
+ ER ercd_ = E_OK;
619
+ int16_t state_;
620
+
621
+ #{ct_name}_CB *p_cellcb;
622
+
623
+ if( VALID_IDX( idx ) ){
624
+ p_cellcb = GET_CELLCB(idx);
625
+ EOT
626
+
627
+ if b_ret_er
628
+ file.print <<EOT
629
+ }else{
630
+ return E_ID;
631
+ }
632
+ EOT
633
+ else
634
+ file.print <<EOT
635
+ }else{
636
+ /* エラー処理コードをここに記述 */
637
+ }
638
+ EOT
639
+ end
640
+
641
+ file.print <<EOT
642
+
643
+ #ifdef RPC_DEBUG
644
+ syslog(LOG_INFO, "Entering RPC service loop" );
645
+ #endif
646
+
647
+ /* SOPのチェック */
648
+ SET_RPC_STATE( state_, RPCSTATE_SERVER_RECV_SOP );
649
+ if( (ercd_=cTDR_receiveSOP( false )) != E_OK )
650
+ goto error_reset;
651
+ /* func_id の取得 */
652
+ if( (ercd_=cTDR_getInt16( &func_id_ )) != E_OK )
653
+ goto error_reset;
654
+
655
+ #ifdef RPC_DEBUG
656
+ syslog(LOG_INFO, "unmarshaler task: func_id: %d", func_id_ );
657
+ #endif
658
+ switch( func_id_ ){
659
+ EOT
660
+
661
+ # signature に含まれる すべての関数について
662
+ @signature.get_function_head_array.each {|f|
663
+ f_name = f.get_name
664
+ f_type = f.get_declarator.get_type
665
+ func_id = "FUNCID_#{@signature.get_global_name}_#{f_name}".upcase
666
+ fid = @signature.get_id_from_func_name(f_name)
667
+
668
+ file.print " case #{func_id}: /* (id of '#{f_name}') = #{fid} */ \n"
669
+ file.print " ercd_ = tOpaqueUnmarshaler_#{@signature.get_global_name}_#{f_name}( p_cellcb, &state_ );\n"
670
+ file.print " break;\n"
671
+
672
+ } #
673
+
674
+ if @PPAllocatorSize
675
+ ppallocator_dealloc_str = " /* PPAllocator のすべてを解放 */\n cPPAllocator_dealloc_all();"
676
+ else
677
+ ppallocator_dealloc_str = ""
678
+ end
679
+
680
+ file.print <<EOT
681
+ default:
682
+ syslog(LOG_INFO, "unmarshaler task: ERROR: unknown func_id: %d", func_id_ );
683
+ ercd_ = E_ID;
684
+ };
685
+ error_reset: /* OK cases also come here */
686
+ #{ppallocator_dealloc_str}
687
+ if( ercd_ == E_OK )
688
+ return ercd_;
689
+ if( is_cErrorHandler_joined() )
690
+ ercd_ = cErrorHandler_errorOccured( func_id_, ercd_, state_ );
691
+ if( MERCD( ercd_ ) != E_RESET )
692
+ (void)cTDR_reset();
693
+ return ercd_;
694
+ EOT
695
+ end
696
+
697
+ #=== PREAMBLE 部のコード生成
698
+ # アンマーシャラセルタイプの場合、アンマーシャラ関数のプロトタイプ宣言を生成
699
+ def gen_preamble(file, b_singleton, ct_name, global_name)
700
+ if ct_name != @unmarshaler_celltype_name.to_sym
701
+ return
702
+ end
703
+
704
+ # string.h の include (memset, strlen のため)
705
+ file.print "/* header file (strlen, memset) */\n"
706
+ file.print "#include\t<string.h>\n\n"
707
+
708
+ file.print "/* アンマーシャラ関数のプロトタイプ宣言 */\n"
709
+ # signature に含まれる すべての関数について
710
+ @signature.get_function_head_array.each {|f|
711
+ f_name = f.get_name
712
+ f_type = f.get_declarator.get_type
713
+ id = @signature.get_id_from_func_name(f_name)
714
+ file.print "static ER tOpaqueUnmarshaler_#{@signature.get_global_name}_#{f_name}(CELLCB *p_cellcb, int16_t *state);\t/* func_id: #{id} */\n"
715
+ }
716
+ file.print "\n"
717
+ end
718
+
719
+ #=== POSTAMBLE 部のコード生成
720
+ # アンマーシャラセルタイプの場合、個々のアンマーシャラ関数の生成
721
+ def gen_postamble(file, b_singleton, ct_name, global_name)
722
+ if ct_name != @unmarshaler_celltype_name.to_sym
723
+ return
724
+ end
725
+
726
+ file.print "\n/*** アンマーシャラ関数 ***/\n\n"
727
+ @signature.get_function_head_array.each {|f|
728
+ f_name = f.get_name
729
+ f_type = f.get_declarator.get_type
730
+ id = @signature.get_id_from_func_name(f_name)
731
+
732
+ # 関数は返り値を持つか?
733
+ b_ret_er = false
734
+ init_retval = ""
735
+ if f_type.get_type.is_void?
736
+ b_void = true
737
+ else
738
+ b_void = false
739
+ if f_type.get_type.get_type_str == "ER" || f_type.get_type.get_type_str == "ER_INT"
740
+ b_ret_er = true
741
+ init_retval = " = E_OK"
742
+ end
743
+ end
744
+
745
+ file.print <<EOT
746
+ /*
747
+ * name: #{f_name}
748
+ * func_id: #{id}
749
+ */
750
+ EOT
751
+ file.print "static ER\n"
752
+ file.print "tOpaqueUnmarshaler_#{@signature.get_global_name}_#{f_name}(CELLCB *p_cellcb, int16_t *state_)\t\t\n"
753
+ file.print "{\n"
754
+ file.print " ER ercd_;\n"
755
+
756
+ # 引数を受取る変数の定義
757
+ params = f.get_declarator.get_type.get_paramlist.get_items
758
+ # FuncHead-> Decl-> FuncType->ParamList
759
+ params.each{|par|
760
+ name = par.get_name
761
+ type = par.get_type.get_original_type
762
+
763
+ dir = par.get_direction
764
+ if dir == :RECEIVE
765
+ # type は PtrType で、それを取り除いた型
766
+ type = type.get_type
767
+ end
768
+ if dir == :SEND || dir == :RECEIVE
769
+ init = " = 0"
770
+ else
771
+ init = ""
772
+ end
773
+
774
+ if type.is_a? ArrayType
775
+ type = type.get_type
776
+ aster = "(*"
777
+ aster2 = ")"
778
+ else
779
+ aster = ""
780
+ aster2 = ""
781
+ end
782
+
783
+ type_str = type.get_type_str.gsub(/\bconst\b */, "") # "const" を外す
784
+ file.printf(" %-12s %s%s%s%s%s;\n", type_str, aster, name, aster2, type.get_type_str_post, init)
785
+
786
+ if dir == :OUT && type.is_nullable?
787
+ file.print(" int8_t\tb_#{name}_null_;\n")
788
+ end
789
+ }
790
+
791
+ if !b_void
792
+ file.printf(" %-12s retval_%s%s;\n", f_type.get_type.get_type_str, f_type.get_type.get_type_str_post, init_retval)
793
+ end
794
+
795
+ # in 方向の入出力を入力
796
+ file.print "\n /* 入力引数受取 */\n"
797
+ file.print " SET_RPC_STATE( *state_, RPCSTATE_SERVER_RECV_BODY );\n"
798
+ b_get = true # unmarshal では get
799
+ b_marshal = false
800
+ print_params(params, file, 1, b_marshal, b_get, true, "cServerCall", f_name)
801
+ print_params(params, file, 1, b_marshal, b_get, false, "cServerCall", f_name)
802
+ print_out_nullable(params, file, 1, b_marshal)
803
+
804
+
805
+ # パケットの受信完了
806
+ file.print " /* パケット終わりをチェック */\n"
807
+ file.print " SET_RPC_STATE( *state_, RPCSTATE_SERVER_RECV_EOP );\n"
808
+ if !f_type.is_oneway?
809
+ b_continue = "true"
810
+ else
811
+ b_continue = "false"
812
+ end
813
+ file.print " if( (ercd_=cTDR_receiveEOP(#{b_continue})) != E_OK )\n"
814
+ file.print " goto error_reset;\n\n"
815
+
816
+ # out のメモリをアロケート
817
+ dir = :OUT
818
+ alloc_cp = "cPPAllocator_alloc"
819
+ alloc_cp_extra = nil
820
+ nest = 1
821
+ alloc_for_out_params(params, file, nest, dir, alloc_cp, alloc_cp_extra)
822
+
823
+ # 対象関数を呼出す
824
+ file.print " /* 対象関数の呼出し */\n"
825
+ file.print " SET_RPC_STATE( *state_, RPCSTATE_SERVER_EXEC );\n"
826
+ if b_void
827
+ file.print(" cServerCall_#{f_name}(")
828
+ else
829
+ file.print(" retval_ = cServerCall_#{f_name}(")
830
+ end
831
+
832
+ delim = " "
833
+ params.each{|par|
834
+ file.print delim
835
+ delim = ", "
836
+ if par.get_direction == :RECEIVE
837
+ file.print "&"
838
+ end
839
+ file.print par.get_name
840
+ }
841
+ file.print(" );\n")
842
+
843
+ # 戻り値、出力引数の受取コードの生成
844
+
845
+ # oneway の場合出力、戻り値が無く、受取を待たない(非同期な呼出し)
846
+ if !f.is_oneway?
847
+
848
+ file.print "\n /* SOPの送出 */\n"
849
+ file.print " SET_RPC_STATE( *state_, RPCSTATE_SERVER_SEND_SOP );\n"
850
+
851
+ file.print " if( ( ercd_ = cTDR_sendSOP( false ) ) != E_OK )\n"
852
+ file.print " goto error_reset;\n"
853
+
854
+ b_get = false # unmarshaler は put
855
+ if !b_void
856
+ file.print " /* 戻り値の送出 */\n"
857
+ print_param("retval_", f_type.get_type, file, 1, :RETURN, nil, nil, b_marshal, b_get)
858
+ end
859
+
860
+ if f_type.has_outward?
861
+ if b_ret_er
862
+ indent_level = 2
863
+ file.print " if( MERCD( retval_ ) != E_RPC ){\n"
864
+ else
865
+ indent_level = 1
866
+ end
867
+ indent = " " * indent_level
868
+
869
+ file.print "#{indent}/* 出力値の送出 */\n"
870
+ file.print "#{indent}SET_RPC_STATE( *state_, RPCSTATE_SERVER_SEND_BODY );\n"
871
+ print_params(params, file, indent_level, b_marshal, b_get, true, "cServerCall", f_name)
872
+ print_params(params, file, indent_level, b_marshal, b_get, false, "cServerCall", f_name)
873
+
874
+ # receive のメモリをデアロケート
875
+ if f_type.has_receive?
876
+ file.print "#{indent}/* dealloc receive parameter */\n"
877
+ dir = :RECEIVE
878
+ dealloc_cp = "cServerCall_#{f_name}"
879
+ dealloc_for_params(params, file, indent_level, dir, dealloc_cp)
880
+ end
881
+
882
+ if b_ret_er
883
+ file.print " }\n"
884
+ end
885
+ end
886
+
887
+ file.print " /* パケットの終わり(掃きだし) */\n"
888
+ file.print " SET_RPC_STATE( *state_, RPCSTATE_SERVER_SEND_EOP );\n"
889
+ file.print " if( (ercd_=cTDR_sendEOP(false)) != E_OK )\n" # b_continue = false
890
+ file.print " goto error_reset;\n"
891
+ end # ! f.is_oneway?
892
+
893
+ file.print " return E_OK;\n"
894
+ file.print <<EOT
895
+
896
+ error_reset:
897
+ EOT
898
+ # send のリセット用デアロケート
899
+ if f_type.has_send?
900
+ file.print " /* dealloc send parameter */\n"
901
+ file.print " if( *state_ < RPCSTATE_SERVER_EXEC ){\n"
902
+ dir = :SEND
903
+ indent_level = 2
904
+ dealloc_cp = "cServerCall_#{f_name}"
905
+ dealloc_for_params(params, file, indent_level, dir, dealloc_cp, true)
906
+ file.print " }\n"
907
+ end
908
+
909
+ # receive のメモリをデアロケート
910
+ if f_type.has_receive? && b_ret_er
911
+ file.print " /* dealloc receive parameter */\n"
912
+ file.print " if( MERCD( retval_ ) != E_RPC ){\n"
913
+ dir = :RECEIVE
914
+ indent_level = 2
915
+ dealloc_cp = "cServerCall_#{f_name}"
916
+ dealloc_for_params(params, file, indent_level, dir, dealloc_cp)
917
+ file.print " }\n"
918
+ end
919
+
920
+ file.print " return ERCD( E_RPC, MERCD( ercd_ ) );\n"
921
+ file.print "}\n\n"
922
+
923
+ # ここ(個々の関数)ではエラーハンドラーは呼び出さない。呼び元(サーバーのメイン関数)で呼び出す。
924
+ }
925
+ end
926
+
927
+ # b_marshal:: bool
928
+ # b_get:: bool
929
+ # b_marshal = true && b_get == false : マーシャラで入力引数送出
930
+ # b_marshal = true && b_get == true : マーシャラで出力引数受取
931
+ # b_marshal = false && b_get == false : アンマーシャラで入力引数受取
932
+ # b_marshal = false && b_get == true : アンマーシャラで出力引数送出
933
+ # b_referenced:: size_is, count_is, string で参照されているものを出力
934
+ def print_params(params, file, nest, b_marshal, b_get, b_referenced, port_name, func_name)
935
+ params.each{|param|
936
+ # p "#{param.get_name}: b_marshal: #{b_marshal} b_get: #{b_get}"
937
+ if !(b_referenced == param.is_referenced?)
938
+ next
939
+ end
940
+
941
+ dir = param.get_direction
942
+ if b_get == false && b_marshal == true || b_get == true && b_marshal == false
943
+ case dir
944
+ when :IN, :INOUT
945
+ alloc_cp = "cPPAllocator_alloc"
946
+ alloc_cp_extra = nil
947
+ print_param(param.get_name, param.get_type, file, nest, dir, nil, nil, b_marshal, b_get, alloc_cp, alloc_cp_extra)
948
+ when :SEND
949
+ alloc_cp = "#{port_name}_#{func_name}_#{param.get_name}_alloc"
950
+ alloc_cp_extra = nil
951
+ print_param(param.get_name, param.get_type, file, nest, dir, nil, nil, b_marshal, b_get, alloc_cp, alloc_cp_extra)
952
+ end
953
+ else
954
+ case dir
955
+ when :OUT, :INOUT
956
+ alloc_cp = nil # inout の b_get==true&&b_marsha==true のときアロケータコードは不用
957
+ alloc_cp_extra = nil
958
+ print_param(param.get_name, param.get_type, file, nest, dir, nil, nil, b_marshal, b_get, alloc_cp, alloc_cp_extra)
959
+ when :RECEIVE
960
+ alloc_cp = "#{port_name}_#{func_name}_#{param.get_name}_alloc"
961
+ alloc_cp_extra = nil
962
+ if b_get
963
+ outer = "(*" # マーシャラ側では、ポインタが (send と比べ) 一つ多い
964
+ outer2 = ")"
965
+ else
966
+ outer = nil # アンマーシャラ側では、ポインタが一つ外されている
967
+ outer2 = nil
968
+ end
969
+ type = param.get_type.get_referto
970
+ print_param(param.get_name, type, file, nest, dir, outer, outer2, b_marshal, b_get, alloc_cp, alloc_cp_extra)
971
+ end
972
+ end
973
+ }
974
+ end
975
+
976
+ #=== アロケータコードを生成 (out のアンマーシャラ用)
977
+ def alloc_for_out_params(params, file, nest, dir, alloc_cp, alloc_cp_extra)
978
+ params.each{|param|
979
+ dir = param.get_direction
980
+ if dir == :OUT
981
+ alloc_for_out_param(param.get_name, param.get_type, file, nest, nil, nil, alloc_cp, alloc_cp_extra)
982
+ end
983
+ }
984
+ end
985
+
986
+ #=== アロケータコードを生成 (out のアンマーシャラ用個別パラメータの生成)
987
+ def alloc_for_out_param(name, type, file, nest, outer, outer2, alloc_cp, alloc_cp_extra)
988
+ org_type = type.get_original_type
989
+ if org_type.is_nullable?
990
+ indent = "\t" * nest
991
+ file.print "#{indent}if( ! b_#{name}_null_ ){\n"
992
+ nest += 1
993
+ end
994
+ case org_type
995
+ when PtrType
996
+ indent = "\t" * nest
997
+ count = type.get_count
998
+ size = type.get_size
999
+ string = type.get_string
1000
+ if count || size || string
1001
+ loop_counter_type = IntType.new(16) # mikan 方を size_is, count_is の引数の型とする
1002
+ if count
1003
+ len = type.get_count.to_s
1004
+ elsif size
1005
+ len = type.get_size.to_s
1006
+ elsif string
1007
+ if type.get_string.instance_of? Expression
1008
+ len = type.get_string.to_s
1009
+ else
1010
+ raise "unsuscripted string used for out parameter #{name}"
1011
+ end
1012
+ end
1013
+
1014
+ # size_is に max 指定がある場合、length が max を超えているかチェックするコードを生成
1015
+ if !org_type.get_max.nil? && string.nil?
1016
+ file.print "#{indent}if( #{len} > #{type.get_max} ){\t/* GenOpaqueMarshaler max check 2 */\n"
1017
+ file.print "#{indent} ercd_ = E_PAR;\n"
1018
+ file.print "#{indent} goto error_reset;\n"
1019
+ file.print "#{indent}}\n"
1020
+ end
1021
+
1022
+ file.print <<EOT
1023
+ #{indent}if((ercd_=#{alloc_cp}(sizeof(#{type.get_type.get_type_str}#{type.get_type.get_type_str_post})*#{len},(void **)&#{outer}#{name}#{outer2}#{alloc_cp_extra}))!=E_OK)\t/* GenOpaqueMarshaler 1 */
1024
+ #{indent} goto error_reset;
1025
+ EOT
1026
+
1027
+ if type.get_type.is_a? PtrType
1028
+ file.print "#{indent}{\n"
1029
+ file.print "#{indent} #{loop_counter_type.get_type_str} i__#{nest}, length__#{nest} = #{len};\n"
1030
+ file.print "#{indent} for( i__#{nest} = 0; i__#{nest} < length__#{nest}; i__#{nest}++ ){\n"
1031
+ alloc_for_out_param(name, type.get_type, file, nest + 2, outer, "#{outer2}[i__#{nest}]", alloc_cp, alloc_cp_extra)
1032
+ file.print "#{indent} }\n"
1033
+ file.print "#{indent}}\n"
1034
+ end
1035
+
1036
+ else
1037
+ file.print <<EOT
1038
+ #{indent}if((ercd_=#{alloc_cp}(sizeof(#{type.get_type.get_type_str}#{type.get_type.get_type_str_post}),(void **)&#{outer}#{name}#{outer2}#{alloc_cp_extra}))!=E_OK)\t/* GenOpaqueMarshaler 2 */
1039
+ #{indent} goto error_reset;
1040
+ EOT
1041
+ end
1042
+ end
1043
+ if org_type.is_nullable?
1044
+ nest -= 1
1045
+ indent = "\t" * nest
1046
+ file.print "#{indent}} else {\n"
1047
+ file.print "#{indent} #{name} = NULL;\n"
1048
+ file.print "#{indent}}\n"
1049
+ nest += 1
1050
+ end
1051
+ end
1052
+
1053
+ #=== 引数の一括デアロケートコードの生成
1054
+ # send:マーシャラの最後、receive:アンマーシャラの最後で一括して引数をデアロケートする
1055
+ def dealloc_for_params(params, file, nest, dir, dealloc_cp, b_reset = false)
1056
+ if b_reset
1057
+ reset_str = "_reset"
1058
+ else
1059
+ reset_str = ""
1060
+ end
1061
+
1062
+ params.each{|param|
1063
+ if dir == param.get_direction
1064
+ indent = "\t" * nest
1065
+ type = param.get_type.get_original_type
1066
+ aster = ""
1067
+ if dir == :RECEIVE
1068
+ type = type.get_type.get_original_type # ポインタを一つ外す
1069
+ if b_reset
1070
+ aster = "*"
1071
+ end
1072
+ end
1073
+ count = type.get_count
1074
+ size = type.get_size
1075
+ if (size || count) && type.get_type.has_pointer?
1076
+ if count
1077
+ len = ", #{type.get_count}"
1078
+ elsif size
1079
+ len = ", #{type.get_size}"
1080
+ end
1081
+ else
1082
+ len = ""
1083
+ end
1084
+ cp = "#{dealloc_cp}_#{param.get_name}_dealloc#{reset_str}".upcase
1085
+ file.print "#{indent}#{cp}(#{aster}#{param.get_name}#{len});\n"
1086
+ end
1087
+ }
1088
+ end
1089
+
1090
+ #== out で nullable な引数の情報を渡す
1091
+ # out nullable の場合、in, send, receive のように、値を渡す直前ではなく、呼出し時に渡す
1092
+ def print_out_nullable(params, file, nest, b_marshal)
1093
+ indent = "\t" * nest
1094
+ params.each{|param|
1095
+ next if param.get_direction != :OUT
1096
+ next if !param.is_nullable?
1097
+ if b_marshal
1098
+ file.print "#{indent}if( (ercd_=cTDR_putInt8( (int8_t)(#{param.get_name} == NULL) )) != E_OK )\n"
1099
+ file.print "#{indent}\tgoto error_reset;\n"
1100
+ else
1101
+ # 呼び先は alloc_for_out_param で nullable の対応する
1102
+ file.print "#{indent}if( (ercd_=cTDR_getInt8( &b_#{param.get_name}_null_)) != E_OK )\n"
1103
+ file.print "#{indent}\tgoto error_reset;\n"
1104
+ end
1105
+ }
1106
+ end
1107
+ end