blob: 79fa3397f84677d69de6804a3f779a5a0bd2d4dd [file] [log] [blame]
Charlie Mooneybbc05f52015-03-24 13:36:22 -07001# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""This module launches the cherrypy server for webplot and sets up
6web sockets to handle the messages between the clients and the server.
7"""
8
9import argparse
10import base64
11import json
12import logging
13import os
14import re
15import subprocess
Charlie Mooneyc68f9c32015-04-16 15:23:22 -070016import time
Charlie Mooneybbc05f52015-03-24 13:36:22 -070017import threading
18
19import cherrypy
20
Charlie Mooneybbc05f52015-03-24 13:36:22 -070021from ws4py import configure_logger
22from ws4py.messaging import TextMessage
23from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
24from ws4py.websocket import WebSocket
25
Charlie Mooney04b41532015-04-02 12:41:37 -070026from remote import ChromeOSTouchDevice, AndroidTouchDevice
Charlie Mooneybbc05f52015-03-24 13:36:22 -070027
28
29# The WebSocket connection state object.
30state = None
31
32# The touch events are saved in this file as default.
33SAVED_FILE = '/tmp/webplot.dat'
34SAVED_IMAGE = '/tmp/webplot.png'
35
36
Joseph Hwang4782a042015-04-08 17:15:50 +080037def SimpleSystem(cmd):
38 """Execute a system command."""
39 ret = subprocess.call(cmd, shell=True)
40 if ret:
41 logging.warning('Command (%s) failed (ret=%s).', cmd, ret)
42 return ret
43
44
45def SimpleSystemOutput(cmd):
46 """Execute a system command and get its output."""
47 try:
48 proc = subprocess.Popen(
49 cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
50 stdout, _ = proc.communicate()
51 except Exception, e:
52 logging.warning('Command (%s) failed (%s).', cmd, e)
53 else:
54 return None if proc.returncode else stdout.strip()
55
56
57def IsDestinationPortEnabled(port):
58 """Check if the destination port is enabled in iptables.
59
60 If port 8000 is enabled, it looks like
61 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 ctstate NEW tcp dpt:8000
62 """
63 pattern = re.compile('ACCEPT\s+tcp.+\s+ctstate\s+NEW\s+tcp\s+dpt:%d' % port)
64 rules = SimpleSystemOutput('sudo iptables -L INPUT -n --line-number')
65 for rule in rules.splitlines():
66 if pattern.search(rule):
67 return True
68 return False
69
70
71def EnableDestinationPort(port):
72 """Enable the destination port for input traffic in iptables."""
73 if IsDestinationPortEnabled(port):
74 cherrypy.log('Port %d has been already enabled in iptables.' % port)
75 else:
76 cherrypy.log('To enable port %d in iptables.' % port)
77 cmd = ('sudo iptables -A INPUT -p tcp -m conntrack --ctstate NEW '
78 '--dport %d -j ACCEPT' % port)
79 if SimpleSystem(cmd) != 0:
80 raise Error('Failed to enable port in iptables: %d.' % port)
81
82
Charlie Mooneybbc05f52015-03-24 13:36:22 -070083def InterruptHandler():
84 """An interrupt handler for both SIGINT and SIGTERM
85
86 The stop procedure triggered is as follows:
87 1. This handler sends a 'quit' message to the listening client.
88 2. The client sends the canvas image back to the server in its quit message.
89 3. WebplotWSHandler.received_message() saves the image.
90 4. WebplotWSHandler.received_message() handles the 'quit' message.
91 The cherrypy engine exits if this is the last client.
92 """
93 cherrypy.log('Cherrypy engine is sending quit message to clients.')
Joseph Hwang95bf52a2015-04-14 13:09:39 +080094 state.QuitAndShutdown()
95
96
97def _IOError(e, filename):
98 err_msg = ['\n', '!' * 60, str(e),
99 'It is likely that %s is owned by root.' % filename,
100 'Please remove the file and then run webplot again.',
101 '!' * 60, '\n']
102 cherrypy.log('\n'.join(err_msg))
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700103
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700104image_lock = threading.Event()
105image_string = ''
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700106
107class WebplotWSHandler(WebSocket):
108 """The web socket handler for webplot."""
109
110 def opened(self):
111 """This method is called when the handler is opened."""
112 cherrypy.log('WS handler is opened!')
113
114 def received_message(self, msg):
115 """A callback for received message."""
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700116 data = msg.data.split(':', 1)
117 mtype = data[0].lower()
118 content = data[1] if len(data) == 2 else None
Joseph Hwang0c1fa7d2015-04-09 17:01:45 +0800119
120 # Do not print the image data since it is too large.
121 if mtype != 'save':
122 cherrypy.log('Received message: %s' % str(msg.data))
123
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700124 if mtype == 'quit':
125 # A shutdown message requested by the user.
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700126 cherrypy.log('The user requests to shutdown the cherrypy server....')
127 state.DecCount()
128 elif mtype == 'save':
Charlie Mooneyb476e892015-04-02 13:25:49 -0700129 cherrypy.log('All data saved to "%s"' % SAVED_FILE)
130 self.SaveImage(content, SAVED_IMAGE)
131 cherrypy.log('Plot image saved to "%s"' % SAVED_IMAGE)
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700132 else:
133 cherrypy.log('Unknown message type: %s' % mtype)
134
135 def closed(self, code, reason="A client left the room."):
136 """This method is called when the handler is closed."""
137 cherrypy.log('A client requests to close WS.')
138 cherrypy.engine.publish('websocket-broadcast', TextMessage(reason))
139
140 @staticmethod
141 def SaveImage(image_data, image_file):
142 """Decoded the base64 image data and save it in the file."""
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700143 global image_string
144 image_string = base64.b64decode(image_data)
145 image_lock.set()
146 with open(image_file, 'w') as f:
147 f.write(image_string)
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700148
149
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700150class ConnectionState(object):
151 """A ws connection state object for shutting down the cherrypy server.
152
153 It shuts down the cherrypy server when the count is down to 0 and is not
154 increased before the shutdown_timer expires.
155
156 Note that when a page refreshes, it closes the WS connection first and
157 then re-connects immediately. This is why we would like to wait a while
158 before actually shutting down the server.
159 """
160 TIMEOUT = 1.0
161
162 def __init__(self):
163 self.count = 0;
164 self.lock = threading.Lock()
165 self.shutdown_timer = None
Joseph Hwang95bf52a2015-04-14 13:09:39 +0800166 self.quit_flag = False
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700167
168 def IncCount(self):
169 """Increase the connection count, and cancel the shutdown timer if exists.
170 """
171 self.lock.acquire()
172 self.count += 1;
173 cherrypy.log(' WS connection count: %d' % self.count)
174 if self.shutdown_timer:
175 self.shutdown_timer.cancel()
176 self.shutdown_timer = None
177 self.lock.release()
178
179 def DecCount(self):
180 """Decrease the connection count, and start a shutdown timer if no other
181 clients are connecting to the server.
182 """
183 self.lock.acquire()
184 self.count -= 1;
185 cherrypy.log(' WS connection count: %d' % self.count)
186 if self.count == 0:
187 self.shutdown_timer = threading.Timer(self.TIMEOUT, self.Shutdown)
188 self.shutdown_timer.start()
189 self.lock.release()
190
Joseph Hwang3f561d32015-04-09 16:33:56 +0800191 def ShutdownWhenNoConnections(self):
192 """Shutdown cherrypy server when there is no client connection."""
193 self.lock.acquire()
194 if self.count == 0 and self.shutdown_timer is None:
195 self.Shutdown()
196 self.lock.release()
197
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700198 def Shutdown(self):
199 """Shutdown the cherrypy server."""
200 cherrypy.log('Shutdown timer expires. Cherrypy server for Webplot exits.')
201 cherrypy.engine.exit()
202
Joseph Hwang95bf52a2015-04-14 13:09:39 +0800203 def QuitAndShutdown(self):
204 """The server notifies clients to quit and then shuts down."""
205 if not self.quit_flag:
206 self.quit_flag = True
207 cherrypy.engine.publish('websocket-broadcast', TextMessage('quit'))
208 self.ShutdownWhenNoConnections()
209
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700210
211class Root(object):
212 """A class to handle requests about docroot."""
213
214 def __init__(self, ip, port, touch_min_x, touch_max_x, touch_min_y,
215 touch_max_y, touch_min_pressure, touch_max_pressure):
216 self.ip = ip
217 self.port = port
218 self.touch_min_x = touch_min_x
219 self.touch_max_x = touch_max_x
220 self.touch_min_y = touch_min_y
221 self.touch_max_y = touch_max_y
222 self.touch_min_pressure = touch_min_pressure
223 self.touch_max_pressure = touch_max_pressure
224 self.scheme = 'ws'
225 cherrypy.log('Root address: (%s, %s)' % (ip, str(port)))
226 cherrypy.log('scheme: %s' % self.scheme)
227
228 @cherrypy.expose
229 def index(self):
230 """This is the default index.html page."""
231 websocket_dict = {
232 'websocketUrl': '%s://%s:%s/ws' % (self.scheme, self.ip, self.port),
233 'touchMinX': str(self.touch_min_x),
234 'touchMaxX': str(self.touch_max_x),
235 'touchMinY': str(self.touch_min_y),
236 'touchMaxY': str(self.touch_max_y),
237 'touchMinPressure': str(self.touch_min_pressure),
238 'touchMaxPressure': str(self.touch_max_pressure),
239 }
240 root_page = os.path.join(os.path.abspath(os.path.dirname(__file__)),
241 'webplot.html')
242 with open(root_page) as f:
243 return f.read() % websocket_dict
244
245 @cherrypy.expose
246 def ws(self):
247 """This handles the request to create a new web socket per client."""
248 cherrypy.log('A new client requesting for WS')
249 cherrypy.log('WS handler created: %s' % repr(cherrypy.request.ws_handler))
250 state.IncCount()
251
252
Joseph Hwang4782a042015-04-08 17:15:50 +0800253class Webplot(threading.Thread):
254 """The server handling the Plotting of finger traces.
255
256 Use case 1: embedding Webplot as a plotter in an application
257
258 # Instantiate a webplot server and starts the daemon.
259 plot = Webplot(server_addr, server_port, device)
260 plot.start()
261
262 # Repeatedly get a snapshot and add it for plotting.
263 while True:
264 # GetSnapshot() is essentially device.NextSnapshot()
265 snapshot = plot.GetSnapshot()
266 if not snapshot:
267 break
268 # Add the snapshot to the plotter for plotting.
269 plot.AddSnapshot(snapshot)
270
271 # Save a screen dump
272 plot.Save()
273
274 # Notify the browser to clear the screen.
275 plot.Clear()
276
277 # Notify both the browser and the cherrypy engine to quit.
278 plot.Quit()
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700279
280
Joseph Hwang4782a042015-04-08 17:15:50 +0800281 Use case 2: using webplot standalone
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700282
Joseph Hwang4782a042015-04-08 17:15:50 +0800283 # Instantiate a webplot server and starts the daemon.
284 plot = Webplot(server_addr, server_port, device)
285 plot.start()
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700286
Joseph Hwang4782a042015-04-08 17:15:50 +0800287 # Get touch snapshots from the touch device and have clients plot them.
288 webplot.GetAndPlotSnapshots()
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700289 """
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700290
Joseph Hwange9cfd642015-04-20 16:00:33 +0800291 def __init__(self, server_addr, server_port, device, saved_file=SAVED_FILE,
292 logging=False):
Joseph Hwang4782a042015-04-08 17:15:50 +0800293 self._server_addr = server_addr
294 self._server_port = server_port
295 self._device = device
296 self._saved_file = saved_file
297 super(Webplot, self).__init__(name='webplot thread')
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700298
Joseph Hwang4782a042015-04-08 17:15:50 +0800299 self.daemon = True
300 self._prev_tids = []
301
Joseph Hwange9cfd642015-04-20 16:00:33 +0800302 # The logging is turned off by default when imported as a module so that
303 # it does not mess up the screen.
304 if not logging:
305 cherrypy.log.screen = None
306
Joseph Hwang4782a042015-04-08 17:15:50 +0800307 # Allow input traffic in iptables.
308 EnableDestinationPort(self._server_port)
309
310 # Create a ws connection state object to wait for the condition to
311 # shutdown the whole process.
312 global state
313 state = ConnectionState()
314
315 cherrypy.config.update({
316 'server.socket_host': self._server_addr,
317 'server.socket_port': self._server_port,
318 })
319
320 WebSocketPlugin(cherrypy.engine).subscribe()
321 cherrypy.tools.websocket = WebSocketTool()
322
323 # If the cherrypy server exits for whatever reason, close the device
324 # for required cleanup. Otherwise, there might exist local/remote
325 # zombie processes.
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700326 cherrypy.engine.subscribe('exit', self._device.__del__)
Joseph Hwang4782a042015-04-08 17:15:50 +0800327
328 cherrypy.engine.signal_handler.handlers['SIGINT'] = InterruptHandler
329 cherrypy.engine.signal_handler.handlers['SIGTERM'] = InterruptHandler
330
331 def run(self):
332 """Start the cherrypy engine."""
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700333 x_min, x_max = self._device.RangeX()
334 y_min, y_max = self._device.RangeY()
335 p_min, p_max = self._device.RangeP()
Joseph Hwang4782a042015-04-08 17:15:50 +0800336
337 cherrypy.quickstart(
338 Root(self._server_addr, self._server_port,
339 x_min, x_max, y_min, y_max, p_min, p_max),
340 '',
341 config={
342 '/': {
343 'tools.staticdir.root':
344 os.path.abspath(os.path.dirname(__file__)),
345 'tools.staticdir.on': True,
346 'tools.staticdir.dir': '',
347 },
348 '/ws': {
349 'tools.websocket.on': True,
350 'tools.websocket.handler_cls': WebplotWSHandler,
351 },
352 }
353 )
354
355 def _ConvertNamedtupleToDict(self, snapshot):
356 """Convert namedtuples to ordinary dictionaries and add leaving slots.
357
358 This is to make a snapshot json serializable. Otherwise, the namedtuples
359 would be transmitted as arrays which is less readable.
360
361 A snapshot looks like
362 MtSnapshot(
363 syn_time=1420524008.368854,
364 button_pressed=False,
365 fingers=[
366 MtFinger(tid=162, slot=0, syn_time=1420524008.368854, x=524,
367 y=231, pressure=45),
368 MtFinger(tid=163, slot=1, syn_time=1420524008.368854, x=677,
369 y=135, pressure=57)
370 ]
371 )
372
373 Note:
374 1. that there are two levels of namedtuples to convert.
375 2. The leaving slots are used to notify javascript that a finger is leaving
376 so that the corresponding finger color could be released for reuse.
377 """
378 # Convert MtSnapshot.
379 converted = dict(snapshot.__dict__.items())
380
381 # Convert MtFinger.
382 converted['fingers'] = [dict(finger.__dict__.items())
383 for finger in converted['fingers']]
384 converted['raw_events'] = [str(event) for event in converted['raw_events']]
385
386 # Add leaving fingers to notify js for reclaiming the finger colors.
387 curr_tids = [finger['tid'] for finger in converted['fingers']]
388 for tid in set(self._prev_tids) - set(curr_tids):
389 leaving_finger = {'tid': tid, 'leaving': True}
390 converted['fingers'].append(leaving_finger)
391 self._prev_tids = curr_tids
392
Joseph Hwang02e829c2015-04-13 17:09:07 +0800393 # Convert raw events from a list of classes to a list of its strings
394 # so that the raw_events is serializable.
395 converted['raw_events'] = [str(event) for event in converted['raw_events']]
396
Joseph Hwang4782a042015-04-08 17:15:50 +0800397 return converted
398
399 def GetSnapshot(self):
400 """Get a snapshot from the touch device."""
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700401 return self._device.NextSnapshot()
Joseph Hwang4782a042015-04-08 17:15:50 +0800402
403 def AddSnapshot(self, snapshot):
404 """Convert the snapshot to a proper format and publish it to clients."""
405 snapshot = self._ConvertNamedtupleToDict(snapshot)
406 cherrypy.engine.publish('websocket-broadcast', json.dumps(snapshot))
Joseph Hwang02e829c2015-04-13 17:09:07 +0800407 return snapshot
Joseph Hwang4782a042015-04-08 17:15:50 +0800408
409 def GetAndPlotSnapshots(self):
410 """Get and plot snapshots."""
411 cherrypy.log('Start getting the live stream snapshots....')
Joseph Hwang95bf52a2015-04-14 13:09:39 +0800412 try:
413 with open(self._saved_file, 'w') as f:
414 while True:
415 try:
416 snapshot = self.GetSnapshot()
417 if not snapshot:
418 cherrypy.log('webplot is terminated.')
419 break
420 converted_snapshot = self.AddSnapshot(snapshot)
421 f.write('\n'.join(converted_snapshot['raw_events']) + '\n')
422 f.flush()
423 except KeyboardInterrupt:
424 cherrypy.log('Keyboard Interrupt accepted')
425 cherrypy.log('webplot is being terminated...')
426 state.QuitAndShutdown()
427 except IOError as e:
428 _IOError(e, self._saved_file)
429 state.QuitAndShutdown()
Joseph Hwang4782a042015-04-08 17:15:50 +0800430
431 def Publish(self, msg):
432 """Publish a message to clients."""
433 cherrypy.engine.publish('websocket-broadcast', TextMessage(msg))
434
435 def Clear(self):
436 """Notify clients to clear the display."""
437 self.Publish('clear')
438
439 def Quit(self):
440 """Notify clients to quit.
441
442 Note that the cherrypy engine would quit accordingly.
443 """
Joseph Hwang95bf52a2015-04-14 13:09:39 +0800444 state.QuitAndShutdown()
Joseph Hwang4782a042015-04-08 17:15:50 +0800445
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700446 def Save(self, wait_for_image=False):
447 """Notify clients to save the screen, then wait for the file to appear
448 on disk and return it.
449 """
450 global image_lock
451 global image_string
452
453 # Trigger a save action
Joseph Hwang4782a042015-04-08 17:15:50 +0800454 self.Publish('save')
455
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700456 # Block until the server has completed saving it to disk
457 image_lock.wait()
458 image_lock.clear()
459 return image_string
460
Joseph Hwang4782a042015-04-08 17:15:50 +0800461 def Url(self):
462 """The url the server is serving at."""
463 return 'http://%s:%d' % (self._server_addr, self._server_port)
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700464
465
Joseph Hwanga1c84782015-04-14 15:07:00 +0800466def _CheckLegalUser():
467 """If this program is run in chroot, it should not be run as root for security
468 reason.
469 """
470 if os.path.exists('/etc/cros_chroot_version') and os.getuid() == 0:
471 print ('You should run webplot in chroot as a regular user '
472 'instead of as root.\n')
473 exit(1)
474
475
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700476def _ParseArguments():
477 """Parse the command line options."""
478 parser = argparse.ArgumentParser(description='Webplot Server')
Charlie Mooney8026f2a2015-04-02 13:01:28 -0700479 parser.add_argument('-d', '--dut_addr', default=None,
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700480 help='the address of the dut')
Joseph Hwang59db4412015-04-09 12:43:16 +0800481
482 # Make an exclusive group to make the webplot.py command option
483 # consistent with the webplot.sh script command option.
484 # What is desired:
485 # When no command option specified in webplot.sh/webplot.py: grab is True
486 # When '--grab' option specified in webplot.sh/webplot.py: grab is True
487 # When '--nograb' option specified in webplot.sh/webplot.py: grab is False
488 grab_group = parser.add_mutually_exclusive_group()
489 grab_group.add_argument('--grab', help='grab the device exclusively',
490 action='store_true')
491 grab_group.add_argument('--nograb', help='do not grab the device',
492 action='store_true')
493
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700494 parser.add_argument('--is_touchscreen', help='the DUT is touchscreen',
495 action='store_true')
Joseph Hwang59db4412015-04-09 12:43:16 +0800496 parser.add_argument('-p', '--server_port', default=80, type=int,
497 help='the port the web server to listen to (default: 80)')
498 parser.add_argument('-s', '--server_addr', default='localhost',
499 help='the address the webplot http server listens to')
500 parser.add_argument('-t', '--dut_type', default='chromeos', type=str.lower,
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700501 help='dut type: chromeos, android')
502 args = parser.parse_args()
Joseph Hwang59db4412015-04-09 12:43:16 +0800503
504 args.grab = not args.nograb
505
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700506 return args
507
508
509def Main():
510 """The main function to launch webplot service."""
Joseph Hwanga1c84782015-04-14 15:07:00 +0800511 _CheckLegalUser()
512
Joseph Hwange9cfd642015-04-20 16:00:33 +0800513 configure_logger(level=logging.ERROR)
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700514 args = _ParseArguments()
515
516 print '\n' + '-' * 70
517 cherrypy.log('dut machine type: %s' % args.dut_type)
518 cherrypy.log('dut\'s touch device: %s' %
519 ('touchscreen' if args.is_touchscreen else 'touchpad'))
520 cherrypy.log('dut address: %s' % args.dut_addr)
521 cherrypy.log('web server address: %s' % args.server_addr)
522 cherrypy.log('web server port: %s' % args.server_port)
Joseph Hwang59db4412015-04-09 12:43:16 +0800523 cherrypy.log('grab the touch device: %s' % args.grab)
524 if args.dut_type == 'android' and args.grab:
525 cherrypy.log('Warning: the grab option is not supported on Android devices'
526 ' yet.')
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700527 cherrypy.log('touch events are saved in %s' % SAVED_FILE)
528 print '-' * 70 + '\n\n'
529
530 if args.server_port == 80:
531 url = args.server_addr
532 else:
533 url = '%s:%d' % (args.server_addr, args.server_port)
534
535 msg = 'Type "%s" in browser %s to see finger traces.\n'
536 if args.server_addr == 'localhost':
537 which_machine = 'on the webplot server machine'
538 else:
539 which_machine = 'on any machine'
540
541 print '*' * 70
542 print msg % (url, which_machine)
543 print 'Press \'q\' on the browser to quit.'
544 print '*' * 70 + '\n\n'
545
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700546 # Instantiate a touch device.
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700547 if args.dut_type == 'chromeos':
548 addr = args.dut_addr if args.dut_addr else '127.0.0.1'
549 device = ChromeOSTouchDevice(addr, args.is_touchscreen, grab=args.grab)
550 else:
551 device = AndroidTouchDevice(args.dut_addr, True)
552
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700553
Joseph Hwang4782a042015-04-08 17:15:50 +0800554 # Instantiate a webplot server daemon and start it.
Joseph Hwange9cfd642015-04-20 16:00:33 +0800555 webplot = Webplot(args.server_addr, args.server_port, device, logging=True)
Joseph Hwang4782a042015-04-08 17:15:50 +0800556 webplot.start()
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700557
Joseph Hwang4782a042015-04-08 17:15:50 +0800558 # Get touch snapshots from the touch device and have clients plot them.
559 webplot.GetAndPlotSnapshots()
Charlie Mooneybbc05f52015-03-24 13:36:22 -0700560
561
562if __name__ == '__main__':
563 Main()