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

Unified Diff: mojo/public/python/mojo/bindings/descriptor.py

Issue 703273002: Update mojo sdk to rev 04a510fb37db10642e156957f9b2c11c2f6442ac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix content/child -> mojo/common linking Created 6 years, 1 month 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 | « mojo/public/mojo_public.gyp ('k') | mojo/public/python/mojo/bindings/messaging.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/python/mojo/bindings/descriptor.py
diff --git a/mojo/public/python/mojo/bindings/descriptor.py b/mojo/public/python/mojo/bindings/descriptor.py
index 44c0f395432f273298aebc50c8740be6fb8880a6..f566d4757dafd0acc6ada7d606003b026eee3644 100644
--- a/mojo/public/python/mojo/bindings/descriptor.py
+++ b/mojo/public/python/mojo/bindings/descriptor.py
@@ -210,36 +210,104 @@ class StringType(PointerType):
return unicode(string_array.tostring(), 'utf8')
-class HandleType(SerializableType):
+class BaseHandleType(SerializableType):
"""Type object for handles."""
def __init__(self, nullable=False):
SerializableType.__init__(self, 'i')
self.nullable = nullable
- def Convert(self, value):
- if value is None:
- return mojo.system.Handle()
- if not isinstance(value, mojo.system.Handle):
- raise TypeError('%r is not a handle' % value)
- return value
-
def Serialize(self, value, data_offset, data, handle_offset):
- if not value.IsValid() and not self.nullable:
+ handle = self.ToHandle(value)
+ if not handle.IsValid() and not self.nullable:
raise serialization.SerializationException(
'Trying to serialize null for non nullable type.')
- if not value.IsValid():
+ if not handle.IsValid():
return (-1, [])
- return (handle_offset, [value])
+ return (handle_offset, [handle])
def Deserialize(self, value, data, handles):
if value == -1:
if not self.nullable:
raise serialization.DeserializationException(
'Trying to deserialize null for non nullable type.')
- return mojo.system.Handle()
+ return self.FromHandle(mojo.system.Handle())
# TODO(qsr) validate handle order
- return handles[value]
+ return self.FromHandle(handles[value])
+
+ def FromHandle(self, handle):
+ raise NotImplementedError()
+
+ def ToHandle(self, value):
+ raise NotImplementedError()
+
+
+class HandleType(BaseHandleType):
+ """Type object for handles."""
+
+ def Convert(self, value):
+ if value is None:
+ return mojo.system.Handle()
+ if not isinstance(value, mojo.system.Handle):
+ raise TypeError('%r is not a handle' % value)
+ return value
+
+ def FromHandle(self, handle):
+ return handle
+
+ def ToHandle(self, value):
+ return value
+
+
+class InterfaceRequestType(BaseHandleType):
+ """Type object for interface requests."""
+
+ def Convert(self, value):
+ if value is None:
+ return reflection.InterfaceRequest(mojo.system.Handle())
+ if not isinstance(value, reflection.InterfaceRequest):
+ raise TypeError('%r is not an interface request' % value)
+ return value
+
+ def FromHandle(self, handle):
+ return reflection.InterfaceRequest(handle)
+
+ def ToHandle(self, value):
+ return value.PassMessagePipe()
+
+
+class InterfaceType(BaseHandleType):
+ """Type object for interfaces."""
+
+ def __init__(self, interface_getter, nullable=False):
+ BaseHandleType.__init__(self, nullable)
+ self._interface_getter = interface_getter
+ self._interface = None
+
+ def Convert(self, value):
+ if value is None or isinstance(value, self.interface):
+ return value
+ raise TypeError('%r is not an instance of ' % self.interface)
+
+ @property
+ def interface(self):
+ if not self._interface:
+ self._interface = self._interface_getter()
+ return self._interface
+
+ def FromHandle(self, handle):
+ if handle.IsValid():
+ return self.interface.manager.Proxy(handle)
+ return None
+
+ def ToHandle(self, value):
+ if not value:
+ return mojo.system.Handle()
+ if isinstance(value, reflection.InterfaceProxy):
+ return value.manager.PassMessagePipe()
+ pipe = mojo.system.MessagePipe()
+ self.interface.manager.Bind(value, pipe.handle0)
+ return pipe.handle1
class BaseArrayType(PointerType):
@@ -460,24 +528,6 @@ class MapType(SerializableType):
return GenericArrayType(t)
-class NoneType(SerializableType):
- """Placeholder type, used temporarily until all mojo types are handled."""
-
- def __init__(self):
- SerializableType.__init__(self, 'B')
-
- def Convert(self, value):
- return None
-
- def Serialize(self, value, data_offset, data, handle_offset):
- return (0, [])
-
- def Deserialize(self, value, data, handles):
- return None
-
-
-TYPE_NONE = NoneType()
-
TYPE_BOOL = BooleanType()
TYPE_INT8 = IntegerType('b')
@@ -499,6 +549,9 @@ TYPE_NULLABLE_STRING = StringType(True)
TYPE_HANDLE = HandleType()
TYPE_NULLABLE_HANDLE = HandleType(True)
+TYPE_INTERFACE_REQUEST = InterfaceRequestType()
+TYPE_NULLABLE_INTERFACE_REQUEST = InterfaceRequestType(True)
+
class FieldDescriptor(object):
"""Describes a field in a generated struct."""
« no previous file with comments | « mojo/public/mojo_public.gyp ('k') | mojo/public/python/mojo/bindings/messaging.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698