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 task RPC methods."""
12 #pylint: disable=relative-import
16 class RPCMethods(object):
17 """Class exposing RPC methods."""
19 _dotted_whitelist
= ['subprocess']
21 def __init__(self
, server
):
23 self
.subprocess
= process
.Process
25 def _dispatch(self
, method
, params
):
28 # Allow only white listed dotted names
29 name
, method
= method
.split('.')
30 assert name
in self
._dotted
_whitelist
31 obj
= getattr(self
, name
)
32 return getattr(obj
, method
)(*params
)
34 def Echo(self
, message
):
35 """Simple RPC method to print and return a message."""
36 logging
.info('Echoing %s', message
)
37 return 'echo %s' % str(message
)
39 def AbsPath(self
, path
):
40 """Returns the absolute path."""
41 return os
.path
.abspath(path
)
44 """Call _server.shutdown in another thread.
46 This is needed because server.shutdown waits for the server to actually
47 quit. However the server cannot shutdown until it completes handling this
48 call. Calling this in the same thread results in a deadlock.
50 t
= threading
.Thread(target
=self
._server
.shutdown
)