testability-driver-qt-sut-plugin 0.9.2 → 1.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 (27) hide show
  1. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/application.rb +11 -8
  2. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/configure_behaviour.rb +3 -3
  3. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/events.rb +76 -74
  4. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/find.rb +2 -0
  5. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fixture.rb +10 -4
  6. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/gesture.rb +49 -42
  7. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/infologger.rb +0 -9
  8. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/locale_db.rb +5 -0
  9. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/record.rb +11 -1
  10. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/sut.rb +441 -324
  11. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/synchronization.rb +32 -11
  12. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/treewidgetitemcolumn.rb +54 -34
  13. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/view_item.rb +26 -26
  14. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/webkit.rb +61 -21
  15. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/widget.rb +528 -344
  16. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/application.rb +16 -138
  17. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/find_object.rb +3 -67
  18. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/fixture.rb +4 -18
  19. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/plugin.rb +1 -1
  20. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/adapter.rb +166 -149
  21. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb +80 -75
  22. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/find_object_generator.rb +93 -0
  23. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/message_composer.rb +161 -0
  24. data/xml/behaviour/qt.xml +26 -26
  25. data/xml/template/qt.xml +9 -7
  26. metadata +7 -6
  27. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/fixture.rb +0 -45
@@ -23,6 +23,8 @@ module MobyController
23
23
 
24
24
  module Application
25
25
 
26
+ include MobyUtil::MessageComposer
27
+
26
28
  def set_adapter( adapter )
27
29
 
28
30
  @sut_adapter = adapter
@@ -56,11 +58,11 @@ module MobyController
56
58
  # close qttas
57
59
  elsif @_command == :CloseQttas
58
60
  #params = {'uid' => '0'}
59
- command_xml = make_message({:service => 'closeApplication'},'Close',{'uid' => '0'})
61
+ command_xml = make_xml_message({:service => 'closeApplication'},'Close',{'uid' => '0'})
60
62
 
61
63
  # kill application
62
64
  elsif @_command == :Kill
63
- command_xml = make_message({:service => 'closeApplication'},'Kill',{'uid' => @_application_uid})
65
+ command_xml = make_xml_message({:service => 'closeApplication'},'Kill',{'uid' => @_application_uid})
64
66
 
65
67
  # list application -- raises exception??
66
68
  elsif @_command == :List
@@ -69,32 +71,32 @@ module MobyController
69
71
  # list applications
70
72
  elsif @_command == :ListApps
71
73
  service_details = {:service => 'listApps', :name => @_application_name, :id => @_application_uid}
72
- command_xml = make_message(service_details, 'listApps', nil )
74
+ command_xml = make_xml_message(service_details, 'listApps', nil )
73
75
 
74
76
  # list crashed applications
75
77
  elsif @_command == :ListCrashedApps
76
78
  service_details = {:service => 'listCrashedApps', :name => @_application_name, :id => @_application_uid}
77
- command_xml = make_message(service_details, 'listCrashedApps', nil )
79
+ command_xml = make_xml_message(service_details, 'listCrashedApps', nil )
78
80
 
79
81
  # shell command
80
82
  elsif @_command == :Shell
81
- command_xml = make_message({:service => 'shellCommand'}, 'shellCommand', @_flags, @_application_name)
83
+ command_xml = make_xml_message({:service => 'shellCommand'}, 'shellCommand', @_flags, @_application_name)
82
84
 
83
85
  # kill all application started by agent_qt
84
86
  elsif @_command == :KillAll
85
- command_xml = make_message({:service =>'kill'},'Kill', nil)
87
+ command_xml = make_xml_message({:service =>'kill'},'Kill', nil)
86
88
 
87
89
  # tap screen
88
90
  elsif @_command == :TapScreen
89
- command_xml = make_message({:service =>'tapScreen'}, 'TapScreen', params)
91
+ command_xml = make_xml_message({:service =>'tapScreen'}, 'TapScreen', params)
90
92
 
91
93
  # bring application to foreground
92
94
  elsif @_command == :BringToForeground
93
- command_xml = make_message({:service => 'bringToForeground'},'BringToForeground', {'pid' => @_application_uid})
95
+ command_xml = make_xml_message({:service => 'bringToForeground'},'BringToForeground', {'pid' => @_application_uid})
94
96
 
95
97
  # system info
96
98
  elsif @_command == :SystemInfo
97
- command_xml = make_message({:service => 'systemInfo'}, 'systemInfo', nil)
99
+ command_xml = make_xml_message({:service => 'systemInfo'}, 'systemInfo', nil)
98
100
 
99
101
  # start process memory logging
100
102
  elsif @_command == :ProcessMemLoggingStart
@@ -105,7 +107,7 @@ module MobyController
105
107
  'timestamp' => @_flags[ :timestamp ],
106
108
  'interval_s' => @_flags[ :interval_s] }
107
109
 
108
- command_xml = make_message({:service => 'resourceLogging'}, 'ProcessMemLoggingStart', parameters)
110
+ command_xml = make_xml_message({:service => 'resourceLogging'}, 'ProcessMemLoggingStart', parameters)
109
111
 
110
112
 
111
113
  # stop process memory logging
@@ -113,16 +115,16 @@ module MobyController
113
115
  parameters = {'thread_name' => @_application_name,
114
116
  'return_data' => @_flags[ :return_data ]}
115
117
 
116
- command_xml = make_message({ :service =>'resourceLogging'}, 'ProcessMemLoggingStop',paremeters)
118
+ command_xml = make_xml_message({ :service =>'resourceLogging'}, 'ProcessMemLoggingStop',paremeters)
117
119
 
118
120
  # start CPU load generating
119
121
  elsif @_command == :CpuLoadStart
120
122
  parameters = {'cpu_load' => @_flags[ :cpu_load ]}
121
- command_xml = make_message({:service => 'resourceLogging'},'CpuLoadStart',paremeters)
123
+ command_xml = make_xml_message({:service => 'resourceLogging'},'CpuLoadStart',paremeters)
122
124
 
123
125
  # stop CPU load generating
124
126
  elsif @_command == :CpuLoadStop
125
- command_xml = make_message({:service => 'resourceLogging'},'CpuLoadStop', nil)
127
+ command_xml = make_xml_message({:service => 'resourceLogging'},'CpuLoadStop', nil)
126
128
 
127
129
  # unknown command
128
130
  else
@@ -133,131 +135,7 @@ module MobyController
133
135
  @sut_adapter.send_service_request( message, return_response_crc ) if message
134
136
  end
135
137
 
136
- private
137
-
138
- def make_parametrized_message( service_details, command_name, params, command_params = {} )
139
-
140
- Nokogiri::XML::Builder.new{
141
- TasCommands( service_details ) {
142
- Target( :TasId => "Application" ) {
143
- Command( ( params || {} ).merge( :name => command_name ) ){
144
- command_params.collect{ | name, value |
145
- param( :name => name, :value => value )
146
- }
147
- }
148
- }
149
- }
150
- }.to_xml
151
-
152
- end
153
-
154
- def make_message( service_details, command_name, params, command_value = nil )
155
-
156
- Nokogiri::XML::Builder.new{
157
- TasCommands( service_details ) {
158
- Target( :TasId => "Application" ) {
159
- Command( command_value || "", ( params || {} ).merge( :name => command_name ) )
160
- }
161
- }
162
- }.to_xml
163
-
164
- end
165
-
166
-
167
- def encode_string( source )
168
- source = source.to_s
169
- source.gsub!( '&', '&' );
170
- source.gsub!( '>', '>' );
171
- source.gsub!( '<', '&lt;' );
172
- source.gsub!( '"', '&quot;' );
173
- source.gsub!( '\'', '&apos;' );
174
- source
175
- end
176
-
177
- def make_filters
178
-
179
- params = {}
180
-
181
- # get sut paramteres only once, store to local variable
182
- sut_parameters = MobyUtil::Parameter[ @_sut.id ]
183
-
184
- params[ 'filterProperties' ] = $last_parameter if sut_parameters[ :filter_properties, nil ]
185
- params[ 'pluginBlackList' ] = $last_parameter if sut_parameters[ :plugin_blacklist, nil ]
186
- params[ 'pluginWhiteList' ] = $last_parameter if sut_parameters[ :plugin_whitelist, nil ]
187
-
188
- case sut_parameters[ :filter_type, 'none' ]
189
-
190
- when 'dynamic'
191
-
192
- # updates the filter with the current backtrace file list
193
- MobyUtil::DynamicAttributeFilter.instance.update_filter( caller( 0 ) )
194
-
195
- white_list = MobyUtil::DynamicAttributeFilter.instance.filter_string
196
- params['attributeWhiteList'] = white_list if white_list
197
-
198
- when 'static'
199
-
200
- params['attributeBlackList'] = $last_parameter if sut_parameters[ :attribute_blacklist, nil ]
201
- params['attributeWhiteList'] = $last_parameter if sut_parameters[ :attribute_whitelist, nil ]
202
-
203
- end
204
-
205
- params
206
-
207
- end
208
-
209
- def state_message
210
- app_details = { :service => 'uiState', :name => @_application_name, :id => @_application_uid }
211
- app_details[ :applicationUid ] = @_refresh_args[ :applicationUid ] if @_refresh_args.include?( :applicationUid )
212
-
213
- case MobyUtil::Parameter[ @_sut.id ][ :filter_type, 'none' ]
214
- when 'none'
215
- command_xml = make_message( app_details, 'UiState', @_flags || {} )
216
- when 'dynamic'
217
- params = @_flags || {}
218
- params[ :filtered ] = 'true'
219
- command_xml = make_parametrized_message( app_details, 'UiState', params, make_filters )
220
- else
221
- command_xml = make_parametrized_message( app_details, 'UiState', @_flags || {}, make_filters )
222
- end
223
- command_xml
224
- end
225
-
226
- def run_message
227
- #clone to not make changes permanent
228
- arguments = MobyUtil::Parameter[ @_sut.id ][ :application_start_arguments, "" ].clone
229
- if @_arguments
230
- arguments << "," unless arguments.empty?
231
- arguments << @_arguments
232
- end
233
-
234
- parameters = {
235
- 'application_path' => @_application_name,
236
- 'arguments' => arguments,
237
- 'environment' => @_environment,
238
- 'events_to_listen' => @_events_to_listen,
239
- 'signals_to_listen' => @_signals_to_listen,
240
- 'start_command' => @_start_command
241
- }
242
-
243
- make_message({:service => 'startApplication'}, 'Run', parameters)
244
- end
245
-
246
- def close_message
247
- sut_id = @_sut.id
248
-
249
- parameters = {
250
- 'uid' => @_application_uid,
251
- 'kill' => ( @_flags || {} )[ :force_kill ] || MobyUtil::Parameter[ sut_id ][ :application_close_kill ],
252
- 'wait_time' => MobyUtil::Parameter[ sut_id ][ :application_close_wait ]
253
- }
254
-
255
- make_message({:service => 'closeApplication', :id => @_application_uid }, 'Close', parameters)
256
- end
257
-
258
- # enable hooking for performance measurement & debug logging
259
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
260
- end #application
138
+ end # application
261
139
 
262
140
  end # QT
263
141
 
@@ -22,6 +22,7 @@ module MobyController
22
22
  module QT
23
23
 
24
24
  module FindObjectCommand
25
+ include MobyUtil::FindObjectGenerator
25
26
 
26
27
  # Execute the command
27
28
  # Sends the message to the device using the @sut_adapter (see base class)
@@ -30,79 +31,14 @@ module MobyController
30
31
  # == raises
31
32
  # NotImplementedError: raised if unsupported command type
32
33
  def execute
33
- filters = make_params if MobyUtil::Parameter[ @_sut.id ][ :filter_type, 'none' ] == 'dynamic'
34
-
35
- params = search_parameters
36
-
37
- builder = Nokogiri::XML::Builder.new do |xml|
38
- xml.TasCommands( ( application_details || {} ).merge( :service => "findObject") ) {
39
- xml.Target{
40
- add_objects(xml, params)
41
- xml.Command( :name => 'findObject' ){
42
- filters.collect{ | name, value |
43
- xml.param( :name => name, :value => value )
44
- }
45
- } if MobyUtil::Parameter[ @_sut.id ][ :filter_type, 'none' ] == 'dynamic'
46
- } if params and params.size > 0
47
- }
48
- end
49
- msg = builder.to_xml
50
- #puts msg.to_s
51
-
52
- @sut_adapter.send_service_request(Comms::MessageGenerator.generate(msg), true)
53
-
34
+ msg = generate_message
35
+ @sut_adapter.send_service_request(MobyController::QT::Comms::MessageGenerator.generate(msg), true)
54
36
  end
55
37
 
56
38
  def set_adapter( adapter )
57
39
  @sut_adapter = adapter
58
40
  end
59
41
 
60
- private
61
-
62
- def add_objects(builder, params)
63
- parent = builder.parent
64
- params.each{|objectParams| parent = create_object_node(builder, objectParams, parent)}
65
- end
66
-
67
- def create_object_node(builder, params, parent)
68
- node = Nokogiri::XML::Node.new('object', builder.doc)
69
- params.keys.each{|key| node[key.to_s] = params[key].to_s}
70
- parent.add_child(node)
71
- end
72
-
73
-
74
- def make_params
75
- params = {}
76
-
77
- # get sut paramteres only once, store to local variable
78
- sut_parameters = MobyUtil::Parameter[ @_sut.id ]
79
-
80
- params[ 'filterProperties' ] = $last_parameter if sut_parameters[ :filter_properties, nil ]
81
- params[ 'pluginBlackList' ] = $last_parameter if sut_parameters[ :plugin_blacklist, nil ]
82
- params[ 'pluginWhiteList' ] = $last_parameter if sut_parameters[ :plugin_whitelist, nil ]
83
-
84
- case sut_parameters[ :filter_type, 'none' ]
85
-
86
- when 'dynamic'
87
-
88
- # updates the filter with the current backtrace file list
89
- MobyUtil::DynamicAttributeFilter.instance.update_filter( caller( 0 ) )
90
-
91
- white_list = MobyUtil::DynamicAttributeFilter.instance.filter_string
92
- params['attributeWhiteList'] = white_list if white_list
93
-
94
- when 'static'
95
-
96
- params['attributeBlackList'] = $last_parameter if sut_parameters[ :attribute_blacklist, nil ]
97
- params['attributeWhiteList'] = $last_parameter if sut_parameters[ :attribute_whitelist, nil ]
98
-
99
- end
100
-
101
- params
102
-
103
- end
104
-
105
-
106
42
  # enable hooking for performance measurement & debug logging
107
43
  MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
108
44
 
@@ -22,6 +22,7 @@ module MobyController
22
22
  module QT
23
23
 
24
24
  module Fixture
25
+ include MobyUtil::MessageComposer
25
26
 
26
27
  # Execute the command
27
28
  # Sends the message to the device using the @sut_adapter (see base class)
@@ -30,25 +31,10 @@ module MobyController
30
31
  # == raises
31
32
  # NotImplementedError: raised if unsupported command type
32
33
  def execute
33
-
34
- Kernel::raise ArgumentError.new( "Fixture '%s' not found for sut id '%s'" % [ @name, @sut_adapter.sut_id ] ) if ( fixture_plugin = MobyUtil::Parameter[ @sut_adapter.sut_id.to_sym ][ :fixtures ][ @name.to_sym, nil ] ).nil?
34
+ Kernel::raise ArgumentError.new( "Fixture '%s' not found for sut id '%s'" % [ @name, @sut_adapter.sut_id ] ) if ( plugin_params = MobyUtil::Parameter[ @sut_adapter.sut_id.to_sym ][ :fixtures ][ @params[:name].to_sym, nil ] ).nil?
35
35
 
36
-
37
- @sut_adapter.send_service_request(
38
- Comms::MessageGenerator.generate(
39
- Nokogiri::XML::Builder.new{
40
- TasCommands( :id => @context.application_id, :transitions => @context.transitions, :service => "fixture", :async => @context.asynchronous ) {
41
- Target( :TasId => @context.object_id, :type => @context.object_type ) {
42
- Command( :name => "Fixture", :plugin => fixture_plugin, :method => @context.command ) {
43
- @context.params.collect{ | name, value |
44
- param( :name => name, :value => value )
45
- }
46
- }
47
- }
48
- }
49
- }.to_xml
50
- )
51
- )
36
+ fixture_plugin = plugin_params[:plugin]
37
+ @sut_adapter.send_service_request(Comms::MessageGenerator.generate(make_fixture_message(fixture_plugin, @params)))
52
38
 
53
39
  end
54
40
 
@@ -18,7 +18,7 @@
18
18
  ############################################################################
19
19
 
20
20
  # verify that TDriver is loaded
21
- Kernel::raise RuntimeError.new( "SUT plugin requires TDriver" ) unless (defined?( MATTI ) || defined?( TDriver ))
21
+ Kernel::raise RuntimeError.new( "This SUT plugin requires Testability Driver and cannot be launched in standalone mode" ) unless (defined?( MATTI ) || defined?( TDriver ))
22
22
 
23
23
  module MobyPlugin
24
24
 
@@ -20,205 +20,222 @@
20
20
  module MobyController
21
21
 
22
22
  module QT
23
-
24
- # Sut adapter that used TCP/IP connections to send and receive data from QT side.
25
- class SutAdapter < MobyController::SutAdapter
26
-
27
- attr_reader :sut_id
28
-
29
- attr_accessor(
30
-
31
- :socket_read_timeout,
32
- :socket_write_timeout,
33
- :socket_received_bytes,
34
- :socket_sent_bytes
35
-
36
- )
37
-
38
- # TODO: better way to set the host and port parameters
39
- # Initialize the tcp adapter for communicating with the device.
40
- # Communication is done using two tcp channels one form commanding
41
- # the device and one for receiving ui state data.
42
- # UI state data receivin is done in a seprate thread so it is good
43
- # once usage is complete the shutdown_comms is called
44
- # == params
45
- # sut_id id for the sut so that client details can be fetched from params
46
- def initialize( sut_id, receive_timeout = 25, send_timeout = 25 )
47
-
48
- @socket = nil
49
- @connected = false
23
+
24
+ # Sut adapter that used TCP/IP connections to send and receive data from QT side.
25
+ class SutAdapter < MobyController::SutAdapter
26
+
27
+ attr_reader :sut_id
28
+
29
+ attr_accessor(
30
+
31
+ :socket_read_timeout,
32
+ :socket_write_timeout,
33
+ :socket_received_bytes,
34
+ :socket_sent_bytes
35
+
36
+ )
37
+
38
+ # TODO: better way to set the host and port parameters
39
+ # Initialize the tcp adapter for communicating with the device.
40
+ # Communication is done using two tcp channels one form commanding
41
+ # the device and one for receiving ui state data.
42
+ # UI state data receivin is done in a seprate thread so it is good
43
+ # once usage is complete the shutdown_comms is called
44
+ # == params
45
+ # sut_id id for the sut so that client details can be fetched from params
46
+ def initialize( sut_id, receive_timeout = 25, send_timeout = 25 )
47
+
48
+ @socket = nil
49
+ @connected = false
50
50
  @socket_received_bytes=0
51
51
  @socket_sent_bytes=0
52
52
 
53
- @sut_id = sut_id
53
+ @sut_id = sut_id
54
54
 
55
- # set timeouts
56
- @socket_read_timeout = receive_timeout
57
- @socket_write_timeout = send_timeout
55
+ # set timeouts
56
+ @socket_read_timeout = receive_timeout
57
+ @socket_write_timeout = send_timeout
58
58
 
59
- @counter = rand( 1000 )
59
+ @counter = rand( 1000 )
60
60
 
61
- # connect socket
62
- #connect( @sut_id )
61
+ # connect socket
62
+ #connect( @sut_id )
63
63
 
64
- end
64
+ end
65
65
 
66
- def disconnect
66
+ def disconnect
67
67
 
68
- @socket.close if @connected
68
+ @socket.close if @connected
69
69
 
70
- @connected = false
70
+ @connected = false
71
71
 
72
- end
72
+ end
73
73
 
74
- def connect( id = nil )
74
+ def connect( id = nil )
75
75
 
76
- id ||= @sut_id
76
+ id ||= @sut_id
77
77
 
78
- begin
78
+ begin
79
79
 
80
- @socket = TCPSocket.open( MobyUtil::Parameter[ id ][ :qttas_server_ip ], MobyUtil::Parameter[ id ][ :qttas_server_port ].to_i )
80
+ @socket = TCPSocket.open( MobyUtil::Parameter[ id ][ :qttas_server_ip ], MobyUtil::Parameter[ id ][ :qttas_server_port ].to_i )
81
81
 
82
- rescue => ex
82
+ rescue => ex
83
83
 
84
- ip = "no ip" if ( ip = MobyUtil::Parameter[ id ][ :qttas_server_ip, "" ] ).empty?
85
- port = "no port" if ( port = MobyUtil::Parameter[ id ][ :qttas_server_port, "" ] ).empty?
84
+ ip = "no ip" if ( ip = MobyUtil::Parameter[ id ][ :qttas_server_ip, "" ] ).empty?
85
+ port = "no port" if ( port = MobyUtil::Parameter[ id ][ :qttas_server_port, "" ] ).empty?
86
86
 
87
- Kernel::raise IOError.new("Unable to connect QTTAS server, verify that it is running properly (#{ ip }:#{ port }): .\nException: #{ ex.message }")
88
- end
87
+ Kernel::raise IOError.new("Unable to connect QTTAS server, verify that it is running properly (#{ ip }:#{ port }): .\nException: #{ ex.message }")
88
+ end
89
89
 
90
- @connected = true
91
-
92
- end
93
-
94
- def group?
95
- @_group
96
- end
97
-
98
- # Set the document builder for the grouped behaviour message.
99
- def set_message_builder(builder)
100
- @_group = true
101
- @_builder = builder
102
- end
103
-
104
- def append_command(node_list)
105
- node_list.each {|ch| @_builder.doc.root.add_child(ch)}
106
- end
107
-
108
- # Sends a grouped command message to the server. Sets group to false and nils the builder
109
- # to prevent future behviours of being grouped (unless so wanted)
110
- # == returns
111
- # the amout of commands grouped (and send)
112
- def send_grouped_request
113
- @_group = false
114
- size = @_builder.doc.root.children.size
115
- send_service_request(Comms::MessageGenerator.generate(@_builder.to_xml))
116
- @_builder = nil
117
- size
118
- end
119
-
120
- # Send the message to the qt server
121
- # If there is no exception propagated the send to the device was successful
122
- # == params
123
- # message:: message in qttas protocol format
124
- # == returns
125
- # the response body
126
- def send_service_request( message, return_crc = false )
127
-
128
- connect if !@connected
129
-
130
- # set request message id
131
- message.message_id = ( @counter += 1 )
132
-
133
- # write request message to socket
134
- write_socket( message.make_binary_message(@counter) )
135
-
136
- # read response to determine was the message handled properly and parse the header
137
- # header[ 0 ] = command_flag
90
+ @connected = true
91
+
92
+ end
93
+
94
+ def group?
95
+ @_group
96
+ end
97
+
98
+ # Set the document builder for the grouped behaviour message.
99
+ def set_message_builder(builder)
100
+ @_group = true
101
+ @_builder = builder
102
+ end
103
+
104
+ def append_command(node_list)
105
+ node_list.each {|ch| @_builder.doc.root.add_child(ch)}
106
+ end
107
+
108
+ # Sends a grouped command message to the server. Sets group to false and nils the builder
109
+ # to prevent future behviours of being grouped (unless so wanted)
110
+ # == returns
111
+ # the amout of commands grouped (and send)
112
+ def send_grouped_request
113
+ @_group = false
114
+ size = @_builder.doc.root.children.size
115
+ send_service_request(Comms::MessageGenerator.generate(@_builder.to_xml))
116
+ @_builder = nil
117
+ size
118
+ end
119
+
120
+ # Send the message to the qt server
121
+ # If there is no exception propagated the send to the device was successful
122
+ # == params
123
+ # message:: message in qttas protocol format
124
+ # == returns
125
+ # the response body
126
+ def send_service_request( message, return_crc = false )
127
+
128
+ connect if !@connected
129
+
130
+ # set request message id
131
+ message.message_id = ( @counter += 1 )
132
+
133
+ # write request message to socket
134
+ write_socket( message.make_binary_message(@counter) )
135
+
136
+ # read response to determine was the message handled properly and parse the header
137
+ # header[ 0 ] = command_flag
138
138
  # header[ 1 ] = body_size
139
139
  # header[ 2 ] = crc
140
140
  # header[ 3 ] = compression_flag
141
141
  # header[ 4 ] = message_id
142
- header = nil
143
- body = nil
144
-
145
- read_message_id = 0
146
- until read_message_id == @counter
147
- header = read_socket( 12 ).unpack( 'CISCI' )
148
-
149
- # read the message body and compare crc checksum
150
- Kernel::raise IOError.new( "CRC do not match. Maybe the message is corrupted!" ) if CRC::Crc16.crc16_ibm( body = read_socket( header[ 1 ] ) , 0xffff ) != header[ 2 ]
151
-
152
- # validate response message; check that response message id matches the request
153
- # if smaller than expected try to read the next message but if bigger raise error
154
- read_message_id = header[ 4 ]
155
- if read_message_id < @counter
156
- MobyUtil::Logger.instance.log "warning" , "Response to request did not match: \"#{ header[ 4 ].to_s }\"<\"#{ @counter.to_s }\""
157
- elsif read_message_id > @counter
158
- MobyUtil::Logger.instance.log "fatal" , "Response to request did not match: \"#{ header[ 4 ].to_s }\">\"#{ @counter.to_s }\""
159
- # save to file?
160
- MobyUtil::Logger.instance.log "fatal" , body
161
- Kernel::raise RuntimeError.new( "Response to request did not match: \"#{ header[ 4 ].to_s }\"!=\"#{ @counter.to_s }\"" )
162
- end
163
- end
164
-
142
+
143
+ header = nil
144
+ body = nil
145
+
146
+ read_message_id = 0
147
+
148
+ until read_message_id == @counter
149
+
150
+ header = read_socket( 12 ).unpack( 'CISCI' )
151
+
152
+ # read the message body and compare crc checksum
153
+ Kernel::raise IOError.new( "CRC do not match. Maybe the message is corrupted!" ) if CRC::Crc16.crc16_ibm( body = read_socket( header[ 1 ] ) , 0xffff ) != header[ 2 ]
154
+
155
+ # validate response message; check that response message id matches the request
156
+ # if smaller than expected try to read the next message but if bigger raise error
157
+ read_message_id = header[ 4 ]
158
+
159
+ if read_message_id < @counter
160
+
161
+ MobyUtil::Logger.instance.log "warning" , "Response to request did not match: \"#{ header[ 4 ].to_s }\"<\"#{ @counter.to_s }\""
162
+
163
+ elsif read_message_id > @counter
164
+
165
+ MobyUtil::Logger.instance.log "fatal" , "Response to request did not match: \"#{ header[ 4 ].to_s }\">\"#{ @counter.to_s }\""
166
+
167
+ # save to file?
168
+ MobyUtil::Logger.instance.log "fatal" , body
169
+ Kernel::raise RuntimeError.new( "Response to request did not match: \"#{ header[ 4 ].to_s }\"!=\"#{ @counter.to_s }\"" )
170
+
171
+ end
172
+
173
+ end
174
+
165
175
  # inflate the message body if compressed
166
176
  if ( header[ 3 ] == 2 )
167
-
177
+
168
178
  body = Zlib::Inflate.inflate( body ) unless ( body = body[ 4..-1 ] ).empty?
169
179
 
170
180
  end
171
181
 
172
182
  # raise exception if messages error flag is set
173
- # Flag statuses:
174
- # 0 -> ERROR_MSG
183
+ # Flag statuses:
184
+ # 0 -> ERROR_MSG
175
185
  # 1 -> VALID_MSG
176
186
  # 2 -> OK_MESSAGE
177
- Kernel::raise RuntimeError.new( body ) if header[ 0 ] == 0
187
+ if header[ 0 ] == 0
188
+ if body =~ /The application with Id \d+ is no longer available/
189
+ Kernel::raise MobyBase::ApplicationNotAvailableError.new( body )
190
+ else
191
+ Kernel::raise RuntimeError.new( body )
192
+ end
193
+ end
178
194
 
179
- # return the body ( and crc if required )
180
- return_crc ? [ body, header[ 2 ] ] : body
195
+ # return the body ( and crc if required )
196
+ return_crc ? [ body, header[ 2 ] ] : body
181
197
 
182
- end
198
+ end
183
199
 
184
- private
200
+ private
185
201
 
186
- def read_socket( bytes_count )
202
+ def read_socket( bytes_count )
187
203
 
188
- # store time before start receving data
189
- start_time = Time.now
204
+ # store time before start receving data
205
+ start_time = Time.now
190
206
 
191
- # verify that there is data available to be read
192
- Kernel::raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ @socket_read_timeout, bytes_count ] ) if TCPSocket::select( [ @socket ], nil, nil, @socket_read_timeout ).nil?
207
+ # verify that there is data available to be read
208
+ Kernel::raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ @socket_read_timeout, bytes_count ] ) if TCPSocket::select( [ @socket ], nil, nil, @socket_read_timeout ).nil?
193
209
 
194
- # read data from socket
195
- read_buffer = @socket.read( bytes_count ){
210
+ # read data from socket
211
+ read_buffer = @socket.read( bytes_count ){
196
212
 
197
- Kernel::raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ @socket_read_timeout, bytes_count ] ) if ( Time.now - start_time ) > @socket_read_timeout
213
+ Kernel::raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ @socket_read_timeout, bytes_count ] ) if ( Time.now - start_time ) > @socket_read_timeout
198
214
 
199
- }
215
+ }
200
216
 
201
- Kernel::raise IOError.new( "Socket reading error for %i bytes - No data retrieved" % [ bytes_count ] ) if read_buffer.nil?
202
- @socket_received_bytes+=read_buffer.size
203
- read_buffer
217
+ Kernel::raise IOError.new( "Socket reading error for %i bytes - No data retrieved" % [ bytes_count ] ) if read_buffer.nil?
204
218
 
205
- end
219
+ @socket_received_bytes += read_buffer.size
220
+ read_buffer
206
221
 
207
- def write_socket( data )
208
- @socket_sent_bytes+=data.size
222
+ end
209
223
 
210
- @socket.write( data )
224
+ def write_socket( data )
225
+
226
+ @socket_sent_bytes += data.size
211
227
 
212
- # verify that there is no data in writing buffer
213
- Kernel::raise IOError.new( "Socket writing timeout (%i) exceeded for %i bytes" % [ @socket_write_timeout, data.length ] ) if TCPSocket::select( nil, [ @socket ], nil, @socket_write_timeout ).nil?
228
+ @socket.write( data )
214
229
 
215
- end
230
+ # verify that there is no data in writing buffer
231
+ Kernel::raise IOError.new( "Socket writing timeout (%i) exceeded for %i bytes" % [ @socket_write_timeout, data.length ] ) if TCPSocket::select( nil, [ @socket ], nil, @socket_write_timeout ).nil?
216
232
 
217
- # enable hooking for performance measurement & debug logging
218
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
233
+ end
219
234
 
235
+ # enable hooking for performance measurement & debug logging
236
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
220
237
 
221
- end # SutAdapter
238
+ end # SutAdapter
222
239
 
223
240
  end # QT
224
241