dynamic_trafficlight.mvc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. include "primitives.alh"
  2. Diagram dynamic_trafficlight {
  3. name = "Dynamic Traffic Light"
  4. author = "Yentl Van Tendeloo"
  5. }
  6. Class manager {
  7. name = "Manager"
  8. default = True
  9. constructor_body = $
  10. Void function constructor(attributes : Element, parameters : Element):
  11. dict_add(attributes, "counter", 0)
  12. return !
  13. $
  14. {behaviour} CompositeState manager_root {
  15. name = "root"
  16. isInitial = True
  17. {composite_children} BasicState manager_root_start {
  18. name = "start"
  19. isInitial = True
  20. }
  21. }
  22. }
  23. transition (manager_root_start, manager_root_start) {
  24. name = "create"
  25. event = "create"
  26. {transition_raises} Raise {
  27. scope = "cd"
  28. event = "create_instance"
  29. parameter = $
  30. Element function raise(attributes : Element, parameters : Element):
  31. Element result
  32. result = create_node()
  33. list_append(result, "TrafficLight")
  34. list_append(result, attributes["counter"])
  35. list_append(result, read_root())
  36. dict_overwrite(attributes, "counter", integer_addition(attributes["counter"], 1))
  37. return result!
  38. $
  39. }
  40. }
  41. transition (manager_root_start, manager_root_start) {
  42. name = "delete"
  43. event = "delete"
  44. {transition_raises} Raise {
  45. scope = "cd"
  46. event = "delete_instance"
  47. parameter = $
  48. Element function raise(attributes : Element, parameters : Element):
  49. Element result
  50. result = create_node()
  51. list_append(result, parameters["id"])
  52. return result!
  53. $
  54. }
  55. }
  56. Class trafficlight {
  57. name = "TrafficLight"
  58. default = False
  59. constructor_body = $
  60. Void function constructor(attributes : Element, parameters : Element):
  61. dict_add(attributes, "counter", 0)
  62. return!
  63. $
  64. {behaviour} CompositeState trafficlight_root {
  65. name = "root"
  66. isInitial = True
  67. {composite_children} BasicState trafficlight_root_off {
  68. name = "off"
  69. isInitial = True
  70. }
  71. {composite_children} ParallelState trafficlight_root_main {
  72. name = "main"
  73. isInitial = False
  74. {parallel_children} CompositeState trafficlight_root_main_trafficlight {
  75. name = "trafficlight"
  76. isInitial = False
  77. {composite_children} CompositeState trafficlight_root_main_trafficlight_normal {
  78. name = "normal"
  79. isInitial = True
  80. {composite_children} BasicState trafficlight_root_main_trafficlight_normal_red {
  81. name = "red"
  82. isInitial = True
  83. }
  84. {composite_children} BasicState trafficlight_root_main_trafficlight_normal_green {
  85. name = "green"
  86. isInitial = False
  87. }
  88. {composite_children} BasicState trafficlight_root_main_trafficlight_normal_yellow {
  89. name = "yellow"
  90. isInitial = False
  91. }
  92. {composite_children} HistoryState trafficlight_root_main_trafficlight_normal_hist {
  93. name = "hist"
  94. }
  95. }
  96. {composite_children} CompositeState trafficlight_root_main_trafficlight_interrupted {
  97. {composite_children} BasicState trafficlight_root_main_trafficlight_interrupted_yellow {
  98. name = "yellow"
  99. isInitial = True
  100. }
  101. {composite_children} BasicState trafficlight_root_main_trafficlight_interrupted_black {
  102. name = "black"
  103. isInitial = False
  104. }
  105. }
  106. }
  107. {parallel_children} CompositeState trafficlight_root_main_timer {
  108. name = "timer"
  109. isInitial = False
  110. {composite_children} BasicState trafficlight_root_main_timer_disabled {
  111. name = "disabled"
  112. isInitial = False
  113. }
  114. {composite_children} BasicState trafficlight_root_main_timer_running {
  115. name = "running"
  116. isInitial = True
  117. }
  118. }
  119. }
  120. }
  121. }