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

Side by Side Diff: mojo/public/python/mojo_bindings/reflection.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
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """The metaclasses used by the mojo python bindings.""" 5 """The metaclasses used by the mojo python bindings."""
6 6
7 import itertools 7 import itertools
8 import logging 8 import logging
9 import sys 9 import sys
10 10
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 retainer = _Retainer(router) 275 retainer = _Retainer(router)
276 def Cleanup(_): 276 def Cleanup(_):
277 retainer.release() 277 retainer.release()
278 error_handler.AddCallback(Cleanup) 278 error_handler.AddCallback(Cleanup)
279 279
280 if self.client_manager: 280 if self.client_manager:
281 impl.client = self.client_manager._InternalProxy(router, error_handler) 281 impl.client = self.client_manager._InternalProxy(router, error_handler)
282 282
283 # Give an instance manager to the implementation to allow it to close 283 # Give an instance manager to the implementation to allow it to close
284 # the connection. 284 # the connection.
285 impl.manager = InstanceManager(router) 285 impl.manager = InstanceManager(router, error_handler)
286 286
287 router.Start() 287 router.Start()
288 288
289 def _InternalProxy(self, router, error_handler): 289 def _InternalProxy(self, router, error_handler):
290 if not self._proxy_class: 290 if not self._proxy_class:
291 dictionary = { 291 dictionary = {
292 '__module__': __name__, 292 '__module__': __name__,
293 '__init__': _ProxyInit, 293 '__init__': _ProxyInit,
294 } 294 }
295 if self.client_manager: 295 if self.client_manager:
296 dictionary['client'] = property(_ProxyGetClient, _ProxySetClient) 296 dictionary['client'] = property(_ProxyGetClient, _ProxySetClient)
297 dictionary['manager'] = None 297 dictionary['manager'] = None
298 dictionary['_client_manager'] = self.client_manager 298 dictionary['_client_manager'] = self.client_manager
299 for method in self.methods: 299 for method in self.methods:
300 dictionary[method.name] = _ProxyMethodCall(method) 300 dictionary[method.name] = _ProxyMethodCall(method)
301 self._proxy_class = type('%sProxy' % self.name, 301 self._proxy_class = type('%sProxy' % self.name,
302 (self.interface_class, InterfaceProxy), 302 (self.interface_class, InterfaceProxy),
303 dictionary) 303 dictionary)
304 304
305 proxy = self._proxy_class(router, error_handler) 305 proxy = self._proxy_class(router, error_handler)
306 # Give an instance manager to the proxy to allow to close the connection. 306 # Give an instance manager to the proxy to allow to close the connection.
307 proxy.manager = InstanceManager(router) 307 proxy.manager = InstanceManager(router, error_handler)
308 return proxy 308 return proxy
309 309
310 def _Stub(self, impl): 310 def _Stub(self, impl):
311 if not self._stub_class: 311 if not self._stub_class:
312 accept_method = _StubAccept(self.methods) 312 accept_method = _StubAccept(self.methods)
313 dictionary = { 313 dictionary = {
314 '__module__': __name__, 314 '__module__': __name__,
315 '__init__': _StubInit, 315 '__init__': _StubInit,
316 'Accept': accept_method, 316 'Accept': accept_method,
317 'AcceptWithResponder': accept_method, 317 'AcceptWithResponder': accept_method,
318 } 318 }
319 self._stub_class = type('%sStub' % self.name, 319 self._stub_class = type('%sStub' % self.name,
320 (messaging.MessageReceiverWithResponder,), 320 (messaging.MessageReceiverWithResponder,),
321 dictionary) 321 dictionary)
322 return self._stub_class(impl) 322 return self._stub_class(impl)
323 323
324 324
325 class InstanceManager(object): 325 class InstanceManager(object):
326 """ 326 """
327 Manager for the implementation of an interface or a proxy. The manager allows 327 Manager for the implementation of an interface or a proxy. The manager allows
328 to control the connection over the pipe. 328 to control the connection over the pipe.
329 """ 329 """
330 def __init__(self, router): 330 def __init__(self, router, error_handler):
331 self.router = router 331 self._router = router
332 self._error_handler = error_handler
332 333
333 def Close(self): 334 def Close(self):
334 self.router.Close() 335 self._router.Close()
335 336
336 def PassMessagePipe(self): 337 def PassMessagePipe(self):
337 return self.router.PassMessagePipe() 338 return self._router.PassMessagePipe()
339
340 def AddOnErrorCallback(self, callback):
341 self._error_handler.AddCallback(lambda _: callback())
338 342
339 343
340 class _MethodDescriptor(object): 344 class _MethodDescriptor(object):
341 def __init__(self, descriptor): 345 def __init__(self, descriptor):
342 self.name = descriptor['name'] 346 self.name = descriptor['name']
343 self.ordinal = descriptor['ordinal'] 347 self.ordinal = descriptor['ordinal']
344 self.parameters_struct = _ConstructParameterStruct( 348 self.parameters_struct = _ConstructParameterStruct(
345 descriptor['parameters'], self.name, "Parameters") 349 descriptor['parameters'], self.name, "Parameters")
346 self.response_struct = _ConstructParameterStruct( 350 self.response_struct = _ConstructParameterStruct(
347 descriptor.get('responses'), self.name, "Responses") 351 descriptor.get('responses'), self.name, "Responses")
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 logging.warning( 564 logging.warning(
561 'Error occured in accept method. Connection will be closed.') 565 'Error occured in accept method. Connection will be closed.')
562 if self.impl.manager: 566 if self.impl.manager:
563 self.impl.manager.Close() 567 self.impl.manager.Close()
564 return False 568 return False
565 return Accept 569 return Accept
566 570
567 571
568 def _NotImplemented(*_1, **_2): 572 def _NotImplemented(*_1, **_2):
569 raise NotImplementedError() 573 raise NotImplementedError()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698