MINT-core 1.0.1 → 2.0.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 (214) hide show
  1. data/Gemfile +22 -3
  2. data/Gemfile.lock +98 -22
  3. data/History.txt +262 -0
  4. data/LICENSE +30 -0
  5. data/MINT-core.gemspec +25 -80
  6. data/Manifest.txt +145 -30
  7. data/README.rdoc +6 -163
  8. data/Rakefile +16 -17
  9. data/bin/mint-aui +3 -3
  10. data/bin/mint-cui-gfx +3 -2
  11. data/bin/mint-juggernaut.sh +0 -0
  12. data/bin/mint-tuplespace +0 -0
  13. data/lib/MINT-core.rb +53 -15
  14. data/lib/MINT-core/agent/agent.rb +1 -1
  15. data/lib/MINT-core/agent/aui.rb +0 -14
  16. data/lib/MINT-core/agent/auicontrol.rb +91 -38
  17. data/lib/MINT-core/agent/cui-gfx.rb +3 -3
  18. data/lib/MINT-core/agent/cuicontrol.rb +94 -24
  19. data/lib/MINT-core/connector/redis_connector.rb +16 -0
  20. data/lib/MINT-core/manager/mapping_manager.rb +101 -0
  21. data/lib/MINT-core/manager/mapping_parser.rb +89 -0
  22. data/lib/MINT-core/manager/mapping_server.rb +99 -0
  23. data/lib/MINT-core/manager/position_updater.rb +33 -0
  24. data/lib/MINT-core/manager/scxml_client.rb +118 -0
  25. data/lib/MINT-core/manager/scxml_server.rb +86 -0
  26. data/lib/MINT-core/mapping/action/action.rb +32 -0
  27. data/lib/MINT-core/mapping/action/backend_action.rb +32 -0
  28. data/lib/MINT-core/mapping/action/bind_action.rb +88 -0
  29. data/lib/MINT-core/mapping/action/event_action.rb +40 -0
  30. data/lib/MINT-core/mapping/complementary_mapping.rb +31 -0
  31. data/lib/MINT-core/mapping/mapping.rb +170 -34
  32. data/lib/MINT-core/mapping/observation/negation_observation.rb +64 -0
  33. data/lib/MINT-core/mapping/observation/observation.rb +219 -0
  34. data/lib/MINT-core/mapping/sequential.rb +1 -2
  35. data/lib/MINT-core/mapping/sequential_mapping.rb +60 -0
  36. data/lib/MINT-core/model/aui/AIChoiceElement.rb +17 -0
  37. data/lib/MINT-core/model/aui/AICommand.rb +7 -0
  38. data/lib/MINT-core/model/aui/AIContainer.rb +73 -0
  39. data/lib/MINT-core/model/aui/AIContext.rb +12 -0
  40. data/lib/MINT-core/model/aui/AIIN.rb +8 -0
  41. data/lib/MINT-core/model/aui/AIINContinuous.rb +56 -0
  42. data/lib/MINT-core/model/aui/AIINDiscrete.rb +8 -0
  43. data/lib/MINT-core/model/aui/AIMultiChoice.rb +1 -2
  44. data/lib/MINT-core/model/aui/AIMultiChoiceElement.rb +4 -51
  45. data/lib/MINT-core/model/aui/AIO.rb +76 -123
  46. data/lib/MINT-core/model/aui/AIOUT.rb +8 -0
  47. data/lib/MINT-core/model/aui/AIOUTContinuous.rb +61 -0
  48. data/lib/MINT-core/model/aui/AIReference.rb +16 -0
  49. data/lib/MINT-core/model/aui/AISingleChoice.rb +18 -1
  50. data/lib/MINT-core/model/aui/AISingleChoiceElement.rb +10 -56
  51. data/lib/MINT-core/model/aui/AISinglePresence.rb +39 -71
  52. data/lib/MINT-core/model/aui/aicommand.scxml +47 -0
  53. data/lib/MINT-core/model/aui/aicontainer.scxml +41 -0
  54. data/lib/MINT-core/model/aui/aicontext.scxml +34 -0
  55. data/lib/MINT-core/model/aui/aiincontinuous.scxml +59 -0
  56. data/lib/MINT-core/model/aui/aiinrange.scxml +86 -0
  57. data/lib/MINT-core/model/aui/aimultichoice.scxml +67 -0
  58. data/lib/MINT-core/model/aui/aimultichoiceelement.scxml +51 -0
  59. data/lib/MINT-core/model/aui/aio.scxml +18 -27
  60. data/lib/MINT-core/model/aui/aioutcontinuous.scxml +66 -0
  61. data/lib/MINT-core/model/aui/aireference.scxml +28 -0
  62. data/lib/MINT-core/model/aui/aisinglechoice.scxml +60 -0
  63. data/lib/MINT-core/model/aui/aisinglechoiceelement.scxml +45 -60
  64. data/lib/MINT-core/model/aui/aisinglepresence.scxml +15 -24
  65. data/lib/MINT-core/model/aui/model.rb +15 -38
  66. data/lib/MINT-core/model/cui/gfx/CIC.rb +34 -10
  67. data/lib/MINT-core/model/cui/gfx/CIO.rb +66 -115
  68. data/lib/MINT-core/model/cui/gfx/CarouFredSel.scxml +58 -0
  69. data/lib/MINT-core/model/cui/gfx/MarkableRadioButton.rb +8 -0
  70. data/lib/MINT-core/model/cui/gfx/RadioButton.rb +8 -0
  71. data/lib/MINT-core/model/cui/gfx/RadioButtonGroup.rb +6 -0
  72. data/lib/MINT-core/model/cui/gfx/button.rb +16 -0
  73. data/lib/MINT-core/model/cui/gfx/button.scxml +58 -0
  74. data/lib/MINT-core/model/cui/gfx/caroufredsel.rb +48 -0
  75. data/lib/MINT-core/model/cui/gfx/cic.scxml +57 -0
  76. data/lib/MINT-core/model/cui/gfx/cio.scxml +54 -0
  77. data/lib/MINT-core/model/cui/gfx/markableradiobutton.scxml +67 -0
  78. data/lib/MINT-core/model/cui/gfx/model.rb +39 -176
  79. data/lib/MINT-core/model/cui/gfx/radiobutton.scxml +59 -0
  80. data/lib/MINT-core/model/interactor.rb +167 -46
  81. data/lib/MINT-core/model/interactor.scxml +3 -0
  82. data/lib/MINT-core/model/interactor_helpers.rb +25 -0
  83. data/lib/MINT-core/model/ir/body/OneHandPoseNavigation.rb +15 -0
  84. data/lib/MINT-core/model/ir/body/body.rb +5 -0
  85. data/lib/MINT-core/model/ir/body/fingertip.rb +114 -0
  86. data/lib/MINT-core/model/ir/body/fingertip.scxml +43 -0
  87. data/lib/MINT-core/model/{body → ir/body}/gesture_button.rb +0 -0
  88. data/lib/MINT-core/model/ir/body/hand.rb +5 -0
  89. data/lib/MINT-core/model/ir/body/head.rb +102 -0
  90. data/lib/MINT-core/model/ir/body/head.scxml +92 -0
  91. data/lib/MINT-core/model/ir/body/onehandposenavigation.scxml +53 -0
  92. data/lib/MINT-core/model/ir/body/pose.rb +99 -0
  93. data/lib/MINT-core/model/ir/browserscreen.rb +27 -0
  94. data/lib/MINT-core/model/ir/browserscreen.scxml +14 -0
  95. data/lib/MINT-core/model/{device → ir}/button.rb +1 -1
  96. data/lib/MINT-core/model/ir/ir.rb +5 -0
  97. data/lib/MINT-core/model/ir/irmedia.rb +5 -0
  98. data/lib/MINT-core/model/ir/irmode.rb +5 -0
  99. data/lib/MINT-core/model/{device → ir}/joypad.rb +1 -1
  100. data/lib/MINT-core/model/ir/mouse.rb +44 -0
  101. data/lib/MINT-core/model/ir/mouse.scxml +35 -0
  102. data/lib/MINT-core/model/{device/mouse.rb → ir/mouse_old.rb} +2 -2
  103. data/lib/MINT-core/model/{device → ir}/pointer.rb +20 -22
  104. data/lib/MINT-core/model/ir/pointer.scxml +19 -0
  105. data/lib/MINT-core/model/ir/screen.rb +5 -0
  106. data/lib/MINT-core/model/{device → ir}/wheel.rb +1 -1
  107. data/lib/MINT-core/model/mim/aicommand_activate_to_button_press.xml +13 -0
  108. data/lib/MINT-core/model/mim/aicommand_deactivate_to_button_release.xml +13 -0
  109. data/lib/MINT-core/model/mim/aio_defocus_to_cio_unhighlight.xml +13 -0
  110. data/lib/MINT-core/model/mim/aio_focus_to_cio_highlight.xml +14 -0
  111. data/lib/MINT-core/model/mim/aio_present_to_cio_display.xml +14 -0
  112. data/lib/MINT-core/model/mim/aio_suspend_to_cio_hide.xml +13 -0
  113. data/lib/MINT-core/model/mim/aisinglechoice_present_to_child_present.xml +14 -0
  114. data/lib/MINT-core/model/mim/aisinglechoiceelement_chosen_to_radiobutton_select.xml +13 -0
  115. data/lib/MINT-core/model/mim/aisinglechoiceelement_unchosen_to_radiobutton_unselect.xml +13 -0
  116. data/lib/MINT-core/model/mim/aisinglepresence_children_finished_to_caroufredsel_init_js.xml +14 -0
  117. data/lib/MINT-core/model/mim/aisinglepresence_present_to_child_present.xml +15 -0
  118. data/lib/MINT-core/model/mim/browserscreen_reload_to_cuicontrol_refresh_all.xml +12 -0
  119. data/lib/MINT-core/model/mim/button_press_to_aicommand_activate.xml +12 -0
  120. data/lib/MINT-core/model/mim/button_release_to_aicommand_deactivate.xml +12 -0
  121. data/lib/MINT-core/model/mim/caroufredsel_refreshing_to_caroufredsel_init_js.xml +14 -0
  122. data/lib/MINT-core/model/mim/cio_display_to_aio_defocus.xml +13 -0
  123. data/lib/MINT-core/model/mim/cio_display_to_aio_present.xml +12 -0
  124. data/lib/MINT-core/model/mim/cio_display_to_cio_display_cache_add.xml +11 -0
  125. data/lib/MINT-core/model/mim/cio_hide_to_aio_suspend.xml +12 -0
  126. data/lib/MINT-core/model/mim/cio_hide_to_cio_display_cache_remove.xml +12 -0
  127. data/lib/MINT-core/model/mim/cio_highlight_to_aio_focus.xml +13 -0
  128. data/lib/MINT-core/model/mim/head_looking_left_to_aisinglepresence_prev.xml +14 -0
  129. data/lib/MINT-core/model/mim/head_looking_right_to_aisinglepresence_next.xml +15 -0
  130. data/lib/MINT-core/model/mim/head_nodding_to_aisinglepresence_next.xml +15 -0
  131. data/lib/MINT-core/model/mim/head_tilting_left_to_aisinglepresence_prev.xml +14 -0
  132. data/lib/MINT-core/model/mim/head_tilting_right_to_aisinglepresence_next.xml +15 -0
  133. data/lib/MINT-core/model/mim/left_button_aisinglepresence_enter.xml +15 -0
  134. data/lib/MINT-core/model/mim/left_button_aisinglepresence_next.xml +15 -0
  135. data/lib/MINT-core/model/mim/mim_default.xml +52 -0
  136. data/lib/MINT-core/model/mim/mint-mappings.xsd +127 -0
  137. data/lib/MINT-core/model/mim/mouse_press_to_aicommand_activate.xml +17 -0
  138. data/lib/MINT-core/model/mim/mouse_press_to_aisinglechoiceelement_choose.xml +17 -0
  139. data/lib/MINT-core/model/mim/mouse_press_to_aisinglechoiceelement_unchoose.xml +17 -0
  140. data/lib/MINT-core/model/mim/mouse_release_to_aicommand_deactivate.xml +16 -0
  141. data/lib/MINT-core/model/mim/mouse_stop_to_cio_highlight.xml +13 -0
  142. data/lib/MINT-core/model/mim/onehandposnav_confirm_to_aichoiceelement_choose.xml +14 -0
  143. data/lib/MINT-core/model/mim/onehandposnav_next_to_aio_next.xml +14 -0
  144. data/lib/MINT-core/model/mim/onehandposnav_previous_to_aio_prev.xml +14 -0
  145. data/lib/MINT-core/model/mim/radiobutton_selected_to_aisinglechoiceelement_choose.xml +13 -0
  146. data/lib/MINT-core/model/mim/radiobutton_unselected_to_aisinglechoiceelement_unchoose.xml +13 -0
  147. data/lib/MINT-core/model/mim/right_button_aisinglepresence_prev.xml +15 -0
  148. data/lib/MINT-core/model/task.rb +6 -6
  149. data/script/console +0 -0
  150. data/script/destroy +0 -0
  151. data/script/generate +0 -0
  152. data/spec/AICommand_spec.rb +20 -0
  153. data/spec/AIContainer_spec.rb +161 -0
  154. data/spec/AIINContinuous_spec.rb +92 -0
  155. data/spec/AIOUTContinuous_spec.rb +93 -0
  156. data/spec/AIO_spec.rb +73 -0
  157. data/spec/AIReference_spec.rb +105 -0
  158. data/spec/AISinglePresence_spec.rb +204 -60
  159. data/spec/Button_spec.rb +114 -0
  160. data/spec/CIO_spec.rb +145 -0
  161. data/spec/Interactor_spec.rb +95 -0
  162. data/spec/MappingManager_spec.rb +126 -0
  163. data/spec/Spontaneous_spec.rb +53 -0
  164. data/spec/aio_agent_spec.rb +215 -186
  165. data/spec/aisinglechoice_spec.rb +147 -88
  166. data/spec/aisinglechoiceelement_spec.rb +154 -70
  167. data/spec/complementary_mapping_spec.rb +158 -0
  168. data/spec/core_spec.rb +27 -15
  169. data/spec/cui_helper.rb +100 -0
  170. data/spec/examples/browserscreen_reload_to_cuicontrol_refresh_all.xml +12 -0
  171. data/spec/examples/mim_streaming_example.xml +9 -0
  172. data/spec/examples/mouse_highlight.xml +22 -0
  173. data/spec/examples/performance_mapping.xml +15 -0
  174. data/spec/examples/reset_click.xml +24 -0
  175. data/spec/interactor_test.scxml +32 -0
  176. data/spec/interactor_test_2.scxml +16 -0
  177. data/spec/mapping_performance_spec.rb +118 -0
  178. data/spec/mapping_server_spec.rb +161 -0
  179. data/spec/mapping_spec.rb +307 -0
  180. data/spec/music_spec.rb +301 -135
  181. data/spec/performance_counter.scxml +9 -0
  182. data/spec/sequential_mappings_spec.rb +69 -0
  183. data/spec/shared/aio_shared.rb +144 -0
  184. data/spec/spec_helper.rb +22 -3
  185. data/spec/spontaneous.scxml +11 -0
  186. data/spec/support/connection_helper.rb +19 -0
  187. data/spec/support/redis_connector_monkey_patch.rb +1 -0
  188. data/spec/support/statemachine_helper.rb +84 -0
  189. data/spec/sync_mappings_spec.rb +96 -0
  190. metadata +219 -354
  191. data/lib/MINT-core/mapping/complementary.rb +0 -100
  192. data/lib/MINT-core/mapping/on_state_change.rb +0 -65
  193. data/lib/MINT-core/model/aui/AIC.rb +0 -86
  194. data/lib/MINT-core/model/aui/AIChoice.rb +0 -65
  195. data/lib/MINT-core/model/aui/AIINChoose.rb +0 -54
  196. data/lib/MINT-core/model/aui/AIOUTDiscrete.rb +0 -43
  197. data/lib/MINT-core/model/aui/aic.png +0 -0
  198. data/lib/MINT-core/model/aui/aic.scxml +0 -50
  199. data/lib/MINT-core/model/aui/aichoice.png +0 -0
  200. data/lib/MINT-core/model/aui/aichoice.scxml +0 -60
  201. data/lib/MINT-core/model/aui/aio.png +0 -0
  202. data/lib/MINT-core/model/aui/aisinglechoiceelement.png +0 -0
  203. data/lib/MINT-core/model/aui/aisinglepresence.png +0 -0
  204. data/lib/MINT-core/model/body/handgesture.rb +0 -279
  205. data/lib/MINT-core/model/body/head.png +0 -0
  206. data/lib/MINT-core/model/body/head.rb +0 -51
  207. data/lib/MINT-core/model/body/head.scxml +0 -28
  208. data/lib/MINT-core/model/cui/gfx/screen.rb +0 -18
  209. data/lib/MINT-core/overrides/rinda.rb +0 -34
  210. data/spec/AIC_spec.rb +0 -69
  211. data/spec/MINT-core_spec.rb +0 -11
  212. data/spec/aio_spec.rb +0 -144
  213. data/spec/cio_spec.rb +0 -369
  214. data/tasks/rspec.rake +0 -21
@@ -0,0 +1,59 @@
1
+ <scxml initial="initialized" name="RadioButton" version="0.9" xmlns="http://www.w3.org/2005/07/scxml"><!-- node-size-and-position x=0.0 y=0.0 w=885.0 h=723.0 -->
2
+ <state id="initialized"><!-- node-size-and-position x=220.0 y=130.0 w=100.0 h=40.0 -->
3
+ <transition event="position" target="positioning"></transition>
4
+ </state>
5
+ <state id="positioning"><!-- node-size-and-position x=220.0 y=220.0 w=100.0 h=40.0 -->
6
+ <transition event="calculated" target="positioned">
7
+ <invoke src="store_calculated_values_in_model" type="x-mint"></invoke>
8
+ </transition>
9
+ </state>
10
+ <state id="positioned"><!-- node-size-and-position x=220.0 y=320.0 w=100.0 h=40.0 -->
11
+ <transition event="display" target="p"></transition>
12
+ <transition event="hide" target="hidden"></transition>
13
+ </state>
14
+ <parallel id="p"><!-- node-size-and-position x=380.0 y=270.0 w=480.0 h=407.0 -->
15
+ <transition event="disable" target="disabled"></transition>
16
+ <transition event="hide" target="hidden"></transition>
17
+ <state id="s" initial="unselected"><!-- node-size-and-position x=290.0 y=30.0 w=180.0 h=240.0 -->
18
+ <state id="selected"><!-- node-size-and-position x=50.0 y=170.0 w=100.0 h=30.0 -->
19
+ <transition event="unselect" target="unselected"></transition>
20
+ </state>
21
+ <state id="unselected"><!-- node-size-and-position x=50.0 y=70.0 w=100.0 h=30.0 -->
22
+ <transition event="select" target="selected"><!-- edge-path [selected] x=40.0 y=130.0 --></transition>
23
+ </state>
24
+ </state>
25
+ <state id="d"><!-- node-size-and-position x=0.0 y=30.0 w=280.0 h=360.0 -->
26
+ <state id="displaying" initial="displayed"><!-- node-size-and-position x=10.0 y=30.0 w=270.0 h=170.0 -->
27
+ <transition event="refresh" target="refreshing"><!-- edge-path [refreshing] x=100.0 y=230.0 --></transition>
28
+ <state id="displayed"><!-- node-size-and-position x=80.0 y=40.0 w=100.0 h=30.0 -->
29
+ <transition event="highlight" target="highlighted"><!-- edge-path [highlighted] x=70.0 y=100.0 pointx=0.0 pointy=18.0 offsetx=19.0 offsety=-14.0 --></transition>
30
+ </state>
31
+ <state id="highlighted"><!-- node-size-and-position x=80.0 y=130.0 w=100.0 h=30.0 -->
32
+ <transition event="unhighlight" target="displayed"><!-- edge-path [displayed] x=170.0 y=100.0 --></transition>
33
+ <transition event="up" target="displayed">
34
+ <invoke src="highlight_up" type="x-mint"></invoke>
35
+ <!-- edge-path [displayed] x=210.0 y=140.0 x=210.0 y=60.0 pointx=0.0 pointy=-10.0 offsetx=0.0 offsety=5.0 --></transition>
36
+ <transition event="down" target="displayed">
37
+ <invoke src="highlight_down" type="x-mint"></invoke>
38
+ <!-- edge-path [displayed] x=40.0 y=140.0 x=40.0 y=60.0 --></transition>
39
+ <transition event="left" target="displayed">
40
+ <invoke src="highlight_left" type="x-mint"></invoke>
41
+ <!-- edge-path [displayed] x=10.0 y=150.0 x=10.0 y=50.0 --></transition>
42
+ <transition event="right" target="displayed">
43
+ <invoke src="highlight_right" type="x-mint"></invoke>
44
+ <!-- edge-path [displayed] x=250.0 y=150.0 x=250.0 y=50.0 --></transition>
45
+ </state>
46
+ </state>
47
+ <state id="refreshing"><!-- node-size-and-position x=100.0 y=260.0 w=70.0 h=40.0 -->
48
+ <transition target="displaying"></transition>
49
+ </state>
50
+ </state>
51
+ </parallel>
52
+ <state id="disabled"><!-- node-size-and-position x=570.0 y=140.0 w=110.0 h=40.0 -->
53
+ <transition event="hide" target="hidden"></transition>
54
+ </state>
55
+ <state id="hidden"><!-- node-size-and-position x=400.0 y=140.0 w=110.0 h=40.0 -->
56
+ <transition event="position" target="positioning"></transition>
57
+ <transition event="display" target="p"><!-- edge-path [p] x=410.0 y=240.0 --></transition>
58
+ </state>
59
+ </scxml>
@@ -1,18 +1,39 @@
1
1
  module MINT
2
- # An {Element} is the basic abstract element of the complete MINT markup language. Nearly all other
3
- # classes are derived from {MINT::Element} since early everything can be activated by {#state} and has
2
+ # An {Interactor} is the basic abstract element of the complete MINT markup language. Nearly all other
3
+ # classes are derived from {MINT::Interactor} since early everything can be activated by {#state} and has
4
4
  # a {#name}.
5
5
  #
6
- class Element
6
+ class Interactor
7
7
  include DataMapper::Resource
8
+ include MINT::InteractorHelpers
9
+ def self.getModel
10
+ "core"
11
+ end
12
+
13
+
14
+ class << self
15
+ alias get_dm get
16
+ end
17
+
18
+ def self.get(*name)
19
+ if name.length == 1
20
+ get_dm(getModel,name[0])
21
+ else
22
+ get_dm(*name)
23
+ end
24
+ end
25
+
8
26
  private
9
- property :id, Serial
27
+
28
+
10
29
  property :classtype, Discriminator
30
+ property :mint_model, String, :default => lambda { |r,p| r.class.getModel}, :key=>true
11
31
 
12
- # Each abstract {Element} needs to have a name that we will use as the primary key for each model.
13
- property :name, String
32
+ # Each abstract {Interactor} needs to have a name that we will use as the primary key for each model.
33
+ property :name, String, :key => true
34
+ #property :id, Serial
14
35
 
15
- # States of the {Element} Reflects the actual atomic states of the interactors state machine.
36
+ # States of the {Interactor} Reflects the actual atomic states of the interactors state machine.
16
37
  property :states, String
17
38
 
18
39
  # reflects all active states including abstract superstates of an interactor as a |-seperated state id list
@@ -21,15 +42,97 @@ module MINT
21
42
  #always contains the new atomic states that have been entered by the event that has been processed - especially useful for parallel states
22
43
  property :new_states, String
23
44
 
24
- protected
45
+ protected
25
46
  before :save, :save_statemachine
47
+ after :create, :init_statemachine
26
48
 
27
49
  public
28
50
 
51
+ def init_statemachine
52
+ initialize_statemachine true
53
+ end
54
+
55
+
56
+ PUBLISH_ATTRIBUTES = [:name,:states,:abstract_states,:new_states,:classtype, :mint_model]
57
+
58
+ def self.create_channel_name
59
+ a = [self]
60
+ a.unshift a.first.superclass while (a.first!=MINT::Interactor)
61
+ a.map!{|x| x.to_s.split('::').last}
62
+ a.join(".")
63
+ end
64
+
65
+ def create_attribute_channel_name(attribute)
66
+ "#{attribute}:"+self.class.create_channel_name+".#{self.name}"
67
+ end
68
+
69
+ def create_channel_w_name
70
+ self.class.create_channel_name+".#{self.name}"
71
+ end
72
+
73
+
74
+ def self.class_from_channel_name(channel)
75
+ Object.const_get("MINT").const_get channel.split('.').last
76
+ end
77
+
78
+ def publish_update(states,abstract_states, atomic_states)
79
+
80
+
81
+ as_copy = attribute_get(:abstract_states)
82
+ new_copy = attribute_get(:new_states)
83
+ states_copy = attribute_get(:states)
84
+
85
+ attribute_set(:abstract_states, abstract_states.join('|'))
86
+ attribute_set(:new_states, states.join('|'))
87
+ attribute_set(:states, atomic_states.join('|'))
88
+
89
+ RedisConnector.redis.publish self.create_channel_w_name, self.to_json(:only => self.class::PUBLISH_ATTRIBUTES)
90
+
91
+ attribute_set(:abstract_states, as_copy)
92
+ attribute_set(:new_states, new_copy)
93
+ attribute_set(:states, states_copy)
94
+ end
95
+
96
+ def sync_states()
97
+ values = RedisConnector.sync_redis.hmget "mint_interactors:#{self.class.getModel}#{name}","states","new_states","abstract_states"
98
+
99
+ attribute_set(:abstract_states, values[2])
100
+ attribute_set(:new_states, values[1])
101
+ attribute_set(:states, values[0])
102
+ recover_statemachine
103
+ end
104
+
105
+ def self.notify(action,query,callback,time = nil)
106
+ RedisConnector.sub.subscribe("#{self.create_channel_name}")
107
+
108
+ RedisConnector.sub.on(:message) { |channel, message|
109
+ found=MultiJson.decode message
110
+ puts query.inspect
111
+ query.keys.each do |k|
112
+ if found[k.to_s]
113
+ a = found[k.to_s]
114
+ query[k].each do |e|
115
+ puts "found #{e} a:#{a.inspect}"
116
+ if a.include? e
117
+ callback.call found
118
+ break
119
+ end
120
+ end
121
+ end
122
+ end
123
+ }
124
+ end
125
+
126
+
127
+ def self.wait(action,query,callback,time = nil)
128
+ # q = scoped_query(query)
129
+ # q.repository.notify(action,query,callback,self,q, time)
130
+ end
131
+
29
132
  def to_dot(filename)
30
- if not @statemachine
133
+ if not @statemachine
31
134
  initialize_statemachine
32
- end
135
+ end
33
136
  @statemachine.to_dot(:output => filename)
34
137
  end
35
138
  def states
@@ -42,7 +145,7 @@ module MINT
42
145
 
43
146
  def new_states
44
147
  if attribute_get(:new_states)
45
- return attribute_get(:new_states).split("|").map &:to_sym if attribute_get(:new_states).class!=Array
148
+ return attribute_get(:new_states).split("|").map &:to_sym if attribute_get(:new_states).class!=Array
46
149
  return attribute_get(:new_states)
47
150
  else return []
48
151
  end
@@ -56,28 +159,34 @@ module MINT
56
159
  save_statemachine
57
160
  end
58
161
 
59
- def initialize(attributes = {}, &block)
60
- super(attributes, &block)
61
- recover_statemachine
62
- end
162
+ # def initialize(attributes = nil)
163
+ # super(attributes)
164
+
165
+ # recover_statemachine
166
+ # end
63
167
 
64
168
  # The sync event method is overwritten in the derived classes to prevent synchronization cycles by setting an empty callback
65
169
  def sync_event(event)
66
170
  process_event(event)
67
171
  end
68
172
 
69
- def process_event(event, callback=nil)
173
+ #allows to set variables that will be passed as parameters to the actions
174
+ def process_event_vars(event, *vars)
175
+ process_event(event,nil,vars)
176
+ end
177
+
178
+ def process_event(event, callback=nil, vars = nil)
70
179
 
71
- states = process_event!(event,callback)
180
+ states = process_event!(event,callback,vars)
72
181
  if states
73
182
  save_statemachine
74
- states
183
+ return states
75
184
  else
76
- false
185
+ return false
77
186
  end
78
187
  end
79
188
 
80
- def process_event!(event, callback=nil)
189
+ def process_event!(event, callback=nil,vars=nil)
81
190
  if not @statemachine
82
191
  initialize_statemachine
83
192
  recover_statemachine
@@ -88,53 +197,69 @@ module MINT
88
197
  @statemachine.context = self
89
198
  end
90
199
  begin
91
- old_states = @statemachine.states_id
92
- old_abstract_states = @statemachine.abstract_states
93
- @statemachine.process_event(event)
94
- calc_new_states = @statemachine.states_id-old_states
95
- calc_new_states = calc_new_states + (@statemachine.abstract_states - old_abstract_states)
96
- calc_new_states = @statemachine.states_id if calc_new_states.length==0
200
+ old_states = @statemachine.states_id
201
+ old_abstract_states = @statemachine.abstract_states
202
+ @statemachine.process_event(event,*vars)
203
+ calc_new_states = @statemachine.states_id-old_states
204
+ calc_new_states = calc_new_states + (@statemachine.abstract_states - old_abstract_states)
205
+ calc_new_states = @statemachine.states_id if calc_new_states.length==0
97
206
  attribute_set(:new_states, calc_new_states.join('|'))
98
207
  rescue Statemachine::TransitionMissingException
99
208
  p "#{self.name} is in state #{self.states} and could not handle #{event}"
100
209
  return false
101
210
  end
102
- @statemachine.states_id
211
+ return @statemachine.states_id
103
212
  end
104
213
 
105
214
  def is_in?(state)
106
- if not @statemachine
215
+ if not @statemachine
216
+
217
+ #return true if (attribute_get(:states).split('|').map &:intern).include? state.intern
218
+ #return true if (attribute_get(:abstract_states).split('|').map &:intern).include? state.intern
219
+ #return false
107
220
  initialize_statemachine
108
221
  recover_statemachine
109
- end
222
+ end
110
223
  @statemachine.In(state)
111
224
  end
225
+
226
+
227
+ def getSCXML
228
+ "#{File.dirname(__FILE__)}/interactor.scxml"
229
+ end
230
+
112
231
  protected
113
- def initialize_statemachine
114
- if @statemachine.blank?
115
- @statemachine = Statemachine.build do
116
- trans :initialized, :run, :running
117
- trans :running, :done, :finished
118
- end
232
+
233
+ def initialize_statemachine(publish_initialize = false)
234
+ if @statemachine.nil?
235
+ parser = StatemachineParser.new(self)
236
+ @statemachine = parser.build_from_scxml getSCXML
237
+
238
+ @statemachine.activation=self.method(:publish_update)
239
+
240
+ @statemachine.reset(nil,publish_initialize)
241
+
119
242
  end
120
243
  end
121
244
 
122
245
  private
123
246
 
124
247
  def save_statemachine
125
- if not @statemachine
126
- initialize_statemachine
248
+ if not @statemachine
249
+ initialize_statemachine true
127
250
  recover_statemachine
128
251
  end
129
252
  attribute_set(:states, @statemachine.states_id.join('|'))
130
- attribute_set(:abstract_states, @statemachine.abstract_states.concat(@statemachine.states_id).join('|'))
253
+ attribute_set(:abstract_states, @statemachine.abstract_states.join('|'))
131
254
  # attribute_set(:new_states,new_states) if new_states and new_states.length>0 # second condition to
132
255
  save!
256
+ # publish_update
133
257
  end
134
258
 
259
+
135
260
  # @TODO check this for parallel states!
136
261
  def recover_statemachine
137
- if (@statemachine.blank?)
262
+ if (@statemachine.nil?)
138
263
  initialize_statemachine
139
264
  end
140
265
  if attribute_get(:states)
@@ -148,9 +273,9 @@ module MINT
148
273
  attribute_set(:states, @statemachine.states_id.join('|'))
149
274
  attribute_set(:abstract_states, @statemachine.abstract_states.concat(@statemachine.states_id).join('|'))
150
275
  end
151
- if not attribute_get(:new_states)
152
- attribute_set(:new_states, @statemachine.states_id.join('|'))
153
- end
276
+ if not attribute_get(:new_states)
277
+ attribute_set(:new_states, @statemachine.states_id.join('|'))
278
+ end
154
279
  end
155
280
 
156
281
  def is_set(attribute)
@@ -158,10 +283,6 @@ module MINT
158
283
  end
159
284
  end
160
285
 
161
- class IR <Element
162
- end
163
286
 
164
- class IN < IR
165
- end
166
287
 
167
288
  end
@@ -0,0 +1,3 @@
1
+ <scxml initial="initialized" name="Interactor" version="0.9" xmlns="http://www.w3.org/2005/07/scxml"><!-- node-size-and-position x=0.0 y=0.0 w=662.0 h=581.0 -->
2
+ <state id="initialized"><!-- node-size-and-position x=280.0 y=122.0 w=100.0 h=100.0 --></state>
3
+ </scxml>
@@ -0,0 +1,25 @@
1
+ module MINT
2
+ module InteractorHelpers
3
+ def start_timeout(seconds,event,cb = nil)
4
+ if not @timer
5
+ @timer = EventMachine::Timer.new(seconds) do
6
+ cb.call if cb
7
+ process_event event
8
+ end
9
+ else
10
+ puts "timer already started!!!"
11
+ end
12
+ end
13
+ def stop_timeout
14
+ if @timer
15
+ # p "stopped timer"
16
+ @timer.cancel
17
+ @timer = nil
18
+ end
19
+ end
20
+ def restart_timeout(seconds,event,cb = nil)
21
+ stop_timeout
22
+ start_timeout(seconds,event,cb)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module MINT
3
+
4
+ class OneHandPoseNavigation < Pose
5
+
6
+ def getSCXML
7
+ "#{File.dirname(__FILE__)}/onehandposenavigation.scxml"
8
+ end
9
+
10
+ def initialize(attributes = nil)
11
+ super(attributes)
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module MINT
2
+ class Body < IRMode
3
+
4
+ end
5
+ end
@@ -0,0 +1,114 @@
1
+ module MINT
2
+ class Fingertip < Hand
3
+ property :x, Integer, :default => -1
4
+ property :y, Integer, :default => -1
5
+ property :touched, Boolean, :default => false
6
+ property :threshold_x, Integer, :default => 15
7
+ property :threshold_y, Integer, :default => 10
8
+
9
+ property :screen_width, Integer, :default => 640
10
+ PUBLISH_ATTRIBUTES += [:x,:y,:touched]
11
+
12
+ # performance optimization to prevent mulitple subscribes
13
+ @subscribed = false
14
+
15
+ def getSCXML
16
+ "#{File.dirname(__FILE__)}/fingertip.scxml"
17
+ end
18
+ end
19
+
20
+ def cache_coordinates(x,y)
21
+ @cached_x = x
22
+ @cached_y = y
23
+ end
24
+
25
+ def start_timeout
26
+ if not @timer
27
+ @timer = EventMachine::Timer.new(0.3) do
28
+ attribute_set(:x, @cached_x)
29
+ attribute_set(:y, @cached_y)
30
+ process_event("stop")
31
+ end
32
+ else
33
+ puts "timer already started!!!"
34
+ end
35
+ end
36
+ def stop_timeout
37
+ if @timer
38
+ # p "stopped timer"
39
+ @timer.cancel
40
+ @timer = nil
41
+ end
42
+ end
43
+
44
+ def start_one_time_tick(time,event)
45
+ EventMachine::Timer.new(time) {
46
+ process_event event
47
+ }
48
+ end
49
+
50
+ def restart_timeout
51
+ stop_timeout
52
+ start_timeout
53
+ end
54
+
55
+ def touch_changed?(touch)
56
+ return true if attribute_get(:touched) != touch
57
+ false
58
+ end
59
+
60
+ def cache_touched(touch)
61
+ attribute_set(:touched, touch)
62
+ end
63
+
64
+ def filter(x,y)
65
+ [(attribute_get(:screen_width) - x),y]
66
+ end
67
+
68
+ def has_moved?(x,y)
69
+ return true if @cached_x.nil? or @cached_y.nil?
70
+ return true if ((x-@cached_x).abs > threshold_x) or ((y-@cached_y).abs > threshold_y)
71
+ false
72
+ end
73
+
74
+ def consume(id)
75
+ # subscription = "data:"+self.class.create_channel_name+"."+id.to_s+":*"
76
+
77
+ return if @subscribed
78
+
79
+ redis = RedisConnector.redis
80
+
81
+ redis.pubsub.subscribe("ss:event") { |message|
82
+
83
+ # if (key.eql? subscription)
84
+ data = MultiJson.decode message
85
+
86
+ if data["e"].eql? "touches"
87
+ touches = data["p"][0]
88
+ touched_value,x,y = touches[0].map &:to_i
89
+
90
+ x,y = filter x,y
91
+ touched_value= (touched_value==0)?false:true
92
+
93
+ if has_moved? x,y
94
+ cache_coordinates x,y
95
+ process_event("move") if not is_in? :moving
96
+ restart_timeout
97
+ else
98
+ if is_in? :stopped
99
+ if touch_changed? touched_value
100
+ if touched_value
101
+ process_event :press
102
+ else
103
+ process_event :release
104
+ end
105
+ cache_touched touched_value
106
+ end
107
+ end
108
+ end
109
+ end
110
+ # end
111
+ }
112
+ @subscribed = true
113
+ end
114
+ end