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

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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 for base in bases: 175 for base in bases:
176 if isinstance(base, mcs): 176 if isinstance(base, mcs):
177 return type.__new__(mcs, name, bases, dictionary) 177 return type.__new__(mcs, name, bases, dictionary)
178 178
179 descriptor = dictionary.pop('DESCRIPTOR', {}) 179 descriptor = dictionary.pop('DESCRIPTOR', {})
180 180
181 methods = [_MethodDescriptor(x) for x in descriptor.get('methods', [])] 181 methods = [_MethodDescriptor(x) for x in descriptor.get('methods', [])]
182 for method in methods: 182 for method in methods:
183 dictionary[method.name] = _NotImplemented 183 dictionary[method.name] = _NotImplemented
184 client_class_getter = descriptor.get('client', None) 184 client_class_getter = descriptor.get('client', None)
185 normalized_name = descriptor['normalized_name']
qsr 2015/01/14 18:08:41 I would use fully_qualified_name instead of normal
etiennej 2015/01/15 00:03:07 Done.
185 186
186 interface_manager = InterfaceManager(name, methods, client_class_getter) 187 interface_manager = InterfaceManager(normalized_name, methods,
188 client_class_getter)
187 dictionary.update({ 189 dictionary.update({
188 'client': None, 190 'client': None,
189 'manager': None, 191 'manager': None,
190 '_interface_manager': interface_manager, 192 '_interface_manager': interface_manager,
191 }) 193 })
192 194
193 interface_class = type.__new__(mcs, name, bases, dictionary) 195 interface_class = type.__new__(mcs, name, bases, dictionary)
194 interface_manager.interface_class = interface_class 196 interface_manager.interface_class = interface_class
195 return interface_class 197 return interface_class
196 198
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 retainer = _Retainer(router) 277 retainer = _Retainer(router)
276 def Cleanup(_): 278 def Cleanup(_):
277 retainer.release() 279 retainer.release()
278 error_handler.AddCallback(Cleanup) 280 error_handler.AddCallback(Cleanup)
279 281
280 if self.client_manager: 282 if self.client_manager:
281 impl.client = self.client_manager._InternalProxy(router, error_handler) 283 impl.client = self.client_manager._InternalProxy(router, error_handler)
282 284
283 # Give an instance manager to the implementation to allow it to close 285 # Give an instance manager to the implementation to allow it to close
284 # the connection. 286 # the connection.
285 impl.manager = InstanceManager(router) 287 impl.manager = InstanceManager(router, error_handler)
286 288
287 router.Start() 289 router.Start()
288 290
289 def _InternalProxy(self, router, error_handler): 291 def _InternalProxy(self, router, error_handler):
290 if not self._proxy_class: 292 if not self._proxy_class:
291 dictionary = { 293 dictionary = {
292 '__module__': __name__, 294 '__module__': __name__,
293 '__init__': _ProxyInit, 295 '__init__': _ProxyInit,
294 } 296 }
295 if self.client_manager: 297 if self.client_manager:
296 dictionary['client'] = property(_ProxyGetClient, _ProxySetClient) 298 dictionary['client'] = property(_ProxyGetClient, _ProxySetClient)
297 dictionary['manager'] = None 299 dictionary['manager'] = None
298 dictionary['_client_manager'] = self.client_manager 300 dictionary['_client_manager'] = self.client_manager
299 for method in self.methods: 301 for method in self.methods:
300 dictionary[method.name] = _ProxyMethodCall(method) 302 dictionary[method.name] = _ProxyMethodCall(method)
301 self._proxy_class = type('%sProxy' % self.name, 303 self._proxy_class = type('%sProxy' % self.name,
302 (self.interface_class, InterfaceProxy), 304 (self.interface_class, InterfaceProxy),
303 dictionary) 305 dictionary)
304 306
305 proxy = self._proxy_class(router, error_handler) 307 proxy = self._proxy_class(router, error_handler)
306 # Give an instance manager to the proxy to allow to close the connection. 308 # Give an instance manager to the proxy to allow to close the connection.
307 proxy.manager = InstanceManager(router) 309 proxy.manager = InstanceManager(router, error_handler)
308 return proxy 310 return proxy
309 311
310 def _Stub(self, impl): 312 def _Stub(self, impl):
311 if not self._stub_class: 313 if not self._stub_class:
312 accept_method = _StubAccept(self.methods) 314 accept_method = _StubAccept(self.methods)
313 dictionary = { 315 dictionary = {
314 '__module__': __name__, 316 '__module__': __name__,
315 '__init__': _StubInit, 317 '__init__': _StubInit,
316 'Accept': accept_method, 318 'Accept': accept_method,
317 'AcceptWithResponder': accept_method, 319 'AcceptWithResponder': accept_method,
318 } 320 }
319 self._stub_class = type('%sStub' % self.name, 321 self._stub_class = type('%sStub' % self.name,
320 (messaging.MessageReceiverWithResponder,), 322 (messaging.MessageReceiverWithResponder,),
321 dictionary) 323 dictionary)
322 return self._stub_class(impl) 324 return self._stub_class(impl)
323 325
324 326
325 class InstanceManager(object): 327 class InstanceManager(object):
326 """ 328 """
327 Manager for the implementation of an interface or a proxy. The manager allows 329 Manager for the implementation of an interface or a proxy. The manager allows
328 to control the connection over the pipe. 330 to control the connection over the pipe.
329 """ 331 """
330 def __init__(self, router): 332 def __init__(self, router, error_handler):
331 self.router = router 333 self._router = router
334 self._error_handler = error_handler
332 335
333 def Close(self): 336 def Close(self):
334 self.router.Close() 337 self._router.Close()
335 338
336 def PassMessagePipe(self): 339 def PassMessagePipe(self):
337 return self.router.PassMessagePipe() 340 return self._router.PassMessagePipe()
341
342 def AddOnErrorCallback(self, callback):
343 self._error_handler.AddCallback(lambda _: callback())
338 344
339 345
340 class _MethodDescriptor(object): 346 class _MethodDescriptor(object):
341 def __init__(self, descriptor): 347 def __init__(self, descriptor):
342 self.name = descriptor['name'] 348 self.name = descriptor['name']
343 self.ordinal = descriptor['ordinal'] 349 self.ordinal = descriptor['ordinal']
344 self.parameters_struct = _ConstructParameterStruct( 350 self.parameters_struct = _ConstructParameterStruct(
345 descriptor['parameters'], self.name, "Parameters") 351 descriptor['parameters'], self.name, "Parameters")
346 self.response_struct = _ConstructParameterStruct( 352 self.response_struct = _ConstructParameterStruct(
347 descriptor.get('responses'), self.name, "Responses") 353 descriptor.get('responses'), self.name, "Responses")
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 logging.warning( 566 logging.warning(
561 'Error occured in accept method. Connection will be closed.') 567 'Error occured in accept method. Connection will be closed.')
562 if self.impl.manager: 568 if self.impl.manager:
563 self.impl.manager.Close() 569 self.impl.manager.Close()
564 return False 570 return False
565 return Accept 571 return Accept
566 572
567 573
568 def _NotImplemented(*_1, **_2): 574 def _NotImplemented(*_1, **_2):
569 raise NotImplementedError() 575 raise NotImplementedError()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698