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

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 logging
8
9 import application_mojom
10 import example_service_mojom
11 import service_provider_mojom
12 import shell_mojom
13
14 import mojo_system
15
16 class ApplicationImpl(application_mojom.Application):
17 def __init__(self):
18 self._providers = []
19
20 def Initialize(self, args):
21 pass
22
23 def AcceptConnection(self, requestor_url, provider):
24 # We keep a reference to ServiceProviderImpl to ensure neither it nor
25 # provider gets garbage collected.
26 service_provider = ServiceProviderImpl(provider)
27 service_provider.AddService(ExampleServiceImpl.manager.name,
qsr 2015/01/14 18:08:41 You do not need to pass 2 parameters here, the cla
etiennej 2015/01/15 00:03:07 Done.
28 ExampleServiceImpl)
29 provider.client = service_provider
30 self._providers.append(provider)
31
32
33 class ServiceProviderImpl(service_provider_mojom.ServiceProvider):
34 def __init__(self, provider):
35 self._provider = provider
36 self._name_to_service_connector = {}
37
38 def AddService(self, name, service_class):
39 self._name_to_service_connector[name] = service_class
40
41 def ConnectToService(self, interface_name, pipe):
42 if interface_name in self._name_to_service_connector:
43 service = self._name_to_service_connector[interface_name]
44 service.manager.Bind(service(), pipe)
45 else:
46 logging.error("Unable to find service " + interface_name)
47
48
49 class ExampleServiceImpl(example_service_mojom.ExampleService):
50 def Ping(self, ping_value):
51 self.client.Pong(ping_value)
52
53 def RunCallback(self):
54 return {}
55
56 def MojoMain(shell_handle):
57 """MojoMain is the entry point for a python Mojo module."""
58 loop = mojo_system.RunLoop()
59
60 shell = shell_mojom.Shell.manager.Proxy(mojo_system.Handle(shell_handle))
61 shell.client = ApplicationImpl()
62 shell.manager.AddOnErrorCallback(loop.Quit)
63
64 loop.Run()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698