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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/python/BUILD.gn ('k') | mojo/public/python/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/python/__mojo__.py
diff --git a/examples/python/__mojo__.py b/examples/python/__mojo__.py
new file mode 100644
index 0000000000000000000000000000000000000000..c60f2dcf584f20f8b47fef8f49586bbbb1fefb57
--- /dev/null
+++ b/examples/python/__mojo__.py
@@ -0,0 +1,63 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Example python application implementing the Echo service."""
+
+import logging
+
+import application_mojom
+import example_service_mojom
+import service_provider_mojom
+import shell_mojom
+
+import mojo_system
+
+class ApplicationImpl(application_mojom.Application):
+ def __init__(self):
+ self._providers = []
+
+ def Initialize(self, args):
+ pass
+
+ def AcceptConnection(self, requestor_url, services, exposed_services):
+ # We keep a reference to ServiceProviderImpl to ensure neither it nor
+ # provider gets garbage collected.
+ service_provider = ServiceProviderImpl(services)
+ service_provider.AddService(ExampleServiceImpl)
+ services.Bind(service_provider)
+ self._providers.append(services)
+
+
+class ServiceProviderImpl(service_provider_mojom.ServiceProvider):
+ def __init__(self, provider):
+ self._provider = provider
+ self._name_to_service_connector = {}
+
+ def AddService(self, service_class):
+ self._name_to_service_connector[service_class.manager.name] = service_class
+
+ def ConnectToService(self, interface_name, pipe):
+ if interface_name in self._name_to_service_connector:
+ service = self._name_to_service_connector[interface_name]
+ service.manager.Bind(service(), pipe)
+ else:
+ logging.error("Unable to find service " + interface_name)
+
+
+class ExampleServiceImpl(example_service_mojom.ExampleService):
+ def Ping(self, ping_value):
+ self.client.Pong(ping_value)
+
+ def RunCallback(self):
+ return {}
+
+def MojoMain(shell_handle):
+ """MojoMain is the entry point for a python Mojo module."""
+ loop = mojo_system.RunLoop()
+
+ shell = shell_mojom.Shell.manager.Proxy(mojo_system.Handle(shell_handle))
+ shell.client = ApplicationImpl()
+ shell.manager.AddOnErrorCallback(loop.Quit)
+
+ loop.Run()
« no previous file with comments | « examples/python/BUILD.gn ('k') | mojo/public/python/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698