1 # Copyright 2015 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 """Defines the host controller base library.
7 This module is the basis on which host controllers are built and executed.
13 #pylint: disable=relative-import
16 import discovery_server
19 class HostController(object):
20 """The base host controller class."""
23 self
._discovery
_server
= discovery_server
.DiscoveryServer()
26 """Setup method used by the subclass."""
30 """Main task method used by the subclass."""
34 """Teardown method used by the subclass."""
37 def NewClient(self
, *args
, **kwargs
):
38 controller
= client_lib
.ClientController(*args
, **kwargs
)
39 self
._discovery
_server
.RegisterClientCallback(
40 controller
.otp
, controller
.OnConnect
)
43 def RunController(self
):
44 """Main entry point for the controller."""
45 print ' '.join(sys
.argv
)
46 common_lib
.InitLogging()
47 self
._discovery
_server
.Start()
54 except Exception as e
:
55 # Defer raising exceptions until after TearDown and _TearDown are called.
57 tb
= sys
.exc_info()[-1]
60 except Exception as e
:
61 # Defer raising exceptions until after _TearDown is called.
62 # Note that an error raised here will obscure any errors raised
65 tb
= sys
.exc_info()[-1]
67 self
._discovery
_server
.Shutdown()
68 client_lib
.ClientController
.ReleaseAllControllers()
70 raise error
, None, tb
#pylint: disable=raising-bad-type