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

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 example_service_mojom
qsr 2015/01/12 17:37:45 Alphabetize
etiennej 2015/01/14 00:54:04 Done.
11
12 import mojo_bindings.reflection
qsr 2015/01/12 17:37:44 This is (luckily) not used. We do not really want
etiennej 2015/01/14 00:54:04 Done.
13 import mojo_system
14
15 class ApplicationImpl(application_mojom.Application):
16 def __init__(self):
17 self._providers = []
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 service_provider = ServiceProviderImpl(provider)
26 service_provider.AddService("mojo::ExampleService",
qsr 2015/01/12 17:37:45 Isn't this available somewhere from the example_se
etiennej 2015/01/14 00:54:04 Done.
27 PyServiceImpl)
28 provider.client = service_provider
29 self._providers.append(provider)
30
31
32 class ServiceProviderImpl(service_provider_mojom.ServiceProvider):
33 def __init__(self, provider):
34 self._provider = provider
35 self._name_to_service_connector = {}
36
37 def AddService(self, name, service_class):
38 self._name_to_service_connector[name] = service_class
39
40 def ConnectToService(self, interface_name, pipe):
41 if interface_name in self._name_to_service_connector:
42 service = self._name_to_service_connector[interface_name]
43 service.manager.Bind(service(), pipe)
qsr 2015/01/12 17:37:45 Maybe some logging if the class is not registered.
etiennej 2015/01/14 00:54:04 Done.
44
45
46 class PyServiceImpl(example_service_mojom.ExampleService):
qsr 2015/01/12 17:37:44 What about calling this ExampleServiceImpl or some
etiennej 2015/01/14 00:54:03 Done.
47 def Ping(self, ping_value):
48 self.client.Pong(ping_value)
49
50 def RunCallback(self):
51 return {}
52
53 def MojoMain(shell_handle):
54 """MojoMain is the entry point for a python Mojo module."""
55 loop = mojo_system.RunLoop()
56
57 shell = shell_mojom.Shell.manager.Proxy(mojo_system.Handle(shell_handle))
58 shell.client = ApplicationImpl()
59 shell.manager.AddOnErrorCallback(loop.Quit)
60
61 loop.Run()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698