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

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
Index: examples/python/__mojo__.py
diff --git a/examples/python/__mojo__.py b/examples/python/__mojo__.py
new file mode 100644
index 0000000000000000000000000000000000000000..8a749bd53c5bfd277fc2ea3364a156d8322a10c4
--- /dev/null
+++ b/examples/python/__mojo__.py
@@ -0,0 +1,56 @@
+# 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 application_mojom
+import shell_mojom
+import service_provider_mojom
+import echo_service_mojom
+
+import mojo.bindings.reflection
+import mojo.system
+
+class ApplicationImpl(application_mojom.Application):
+ def __init__(self):
+ pass
+
+ def Initialize(self, args):
+ pass
+
+ def AcceptConnection(self, requestor_url, provider):
+ # We keep a reference to ServiceProviderImpl to ensure neither it nor
+ # provider gets garbage collected.
+ 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
+ self._service_provider.AddService("mojo::examples::EchoService",
+ PyServiceImpl)
+ provider.client = self._service_provider
+
+
+class ServiceProviderImpl(service_provider_mojom.ServiceProvider):
+ def __init__(self, provider):
+ self._provider = provider
+ 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.
+
+ def AddService(self, name, service_class):
+ self.__name_to_service_connector[name] = service_class
+
+ def ConnectToService(self, interface_name, pipe):
+ 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.
+ service.manager.Bind(service(), pipe)
+
+
+class PyServiceImpl(echo_service_mojom.EchoService):
+ def EchoString(self, value):
+ mojo.system.RunLoop.Current().Quit()
+ return value
+
+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()
+
+ loop.Run()

Powered by Google App Engine
This is Rietveld 408576698