Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: examples/python/__mojo__.py

Issue 796373006: Content handler for python. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 """Example python application implementing the Echo service."""
6
7 import application_mojom
8 import shell_mojom
9 import service_provider_mojom
10 import echo_service_mojom
11
12 import mojo.bindings.reflection
13 import mojo.system
14
15 class ApplicationImpl(application_mojom.Application):
16 def __init__(self):
17 pass
18
19 def Initialize(self, args):
20 pass
21
22 def AcceptConnection(self, requestor_url, provider):
23 # We keep a reference to ServiceProviderImpl to ensure neither it nor
24 # provider gets garbage collected.
25 self._service_provider = ServiceProviderImpl(provider)
qsr 2015/01/07 15:14:45 This is kind of wrong. You must consider that Acce
etiennej 2015/01/08 11:23:12 I'll look into it. Note that I am not planning to
26 self._service_provider.AddService("mojo::examples::EchoService",
27 PyServiceImpl)
28 provider.client = self._service_provider
29
30
31 class ServiceProviderImpl(service_provider_mojom.ServiceProvider):
32 def __init__(self, provider):
33 self._provider = provider
34 self.__name_to_service_connector = {}
qsr 2015/01/07 15:14:45 We do not use double underscore, just use _name_to
etiennej 2015/01/08 11:23:12 Done.
35
36 def AddService(self, name, service_class):
37 self.__name_to_service_connector[name] = service_class
38
39 def ConnectToService(self, interface_name, pipe):
40 service = self.__name_to_service_connector[interface_name]
qsr 2015/01/07 15:14:45 You might want to protect all of this with: if int
etiennej 2015/01/08 11:23:12 Done.
41 service.manager.Bind(service(), pipe)
42
43
44 class PyServiceImpl(echo_service_mojom.EchoService):
45 def EchoString(self, value):
46 mojo.system.RunLoop.Current().Quit()
47 return value
48
49 def MojoMain(shell_handle):
50 """MojoMain is the entry point for a python Mojo module."""
51 loop = mojo.system.RunLoop()
52
53 shell = shell_mojom.Shell.manager.Proxy(mojo.system.Handle(shell_handle))
54 shell.client = ApplicationImpl()
55
56 loop.Run()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698