Do not invoke DrawFadedString() if it knows it does not fade.
[chromium-blink-merge.git] / tools / usb_gadget / __main__.py
blob0391a34d2fbc7b01fa6ae57ff75fa9665e13ed9a
1 # Copyright 2014 The Chromium 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.
5 """Package entry-point."""
7 import argparse
9 import netifaces
10 from tornado import ioloop
12 import echo_gadget
13 import hid_echo_gadget
14 import keyboard_gadget
15 import linux_gadgetfs
16 import mouse_gadget
17 import server
20 def ParseArgs():
21 """Parse application arguments."""
22 parser = argparse.ArgumentParser(description='USB gadget server.')
23 parser.add_argument(
24 '-i', '--interface', default='lo',
25 help='Listen for HTTP connections on this interface.')
26 parser.add_argument(
27 '-p', '--port', default=8080,
28 help='Listen for HTTP connections on this port.')
29 parser.add_argument(
30 '--hardware', default='beaglebone-black',
31 help='Hardware configuration.')
32 parser.add_argument(
33 '--start-claimed',
34 help='Start with the device claimed by this client.')
35 return parser.parse_args()
38 def main():
39 args = ParseArgs()
41 server.interface = args.interface
42 server.port = args.port
43 server.hardware = args.hardware
44 server.claimed_by = args.start_claimed
46 addrs = netifaces.ifaddresses(server.interface)
47 ip_address = addrs[netifaces.AF_INET][0]['addr']
48 server.address = '{}:{}'.format(ip_address, server.port)
50 server.chip = linux_gadgetfs.LinuxGadgetfs(server.hardware)
51 server.SwitchGadget(server.default)
53 echo_gadget.RegisterHandlers()
54 hid_echo_gadget.RegisterHandlers()
55 keyboard_gadget.RegisterHandlers()
56 mouse_gadget.RegisterHandlers()
58 server.http_server.listen(server.port)
60 ioloop.IOLoop.instance().start()
61 print 'Exiting...'
64 if __name__ == '__main__':
65 main()