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 import SimpleJSONRPCServer
as _server
8 class RequestHandler(_server
.SimpleJSONRPCRequestHandler
):
9 """Custom JSON-RPC request handler."""
12 'client.html': {'content-type': 'text/html'},
13 'host.html': {'content-type': 'text/html'},
14 'client.js': {'content-type': 'application/javascript'},
15 'host.js': {'content-type': 'application/javascript'},
16 'jsonrpc.js': {'content-type': 'application/javascript'}
20 """Custom GET handler to return default pages."""
21 filename
= self
.path
.lstrip('/')
22 if filename
not in self
.FILES
:
25 with
open(filename
) as f
:
27 self
.send_response(200)
28 for key
, value
in self
.FILES
[filename
].iteritems():
29 self
.send_header(key
, value
)
31 self
.wfile
.write(data
)
34 class RPCHandler(object):
35 """Class to define and handle RPC calls."""
37 CLEARED_EVENT
= {'action': 0, 'event': 0, 'modifiers': 0}
40 self
.last_event
= self
.CLEARED_EVENT
42 def ClearLastEvent(self
):
43 """Clear the last event."""
44 self
.last_event
= self
.CLEARED_EVENT
47 def SetLastEvent(self
, action
, value
, modifier
):
48 """Set the last action, value, and modifiers."""
56 def GetLastEvent(self
):
57 return self
.last_event
61 server
= _server
.SimpleJSONRPCServer(
62 ('', 3474), requestHandler
=RequestHandler
,
63 logRequests
=True, allow_none
=True)
64 server
.register_instance(RPCHandler())
65 server
.serve_forever()
68 if __name__
== '__main__':