OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 # This module's classes provide an interface to mojo modules. Modules are | 5 # This module's classes provide an interface to mojo modules. Modules are |
6 # collections of interfaces and structs to be used by mojo ipc clients and | 6 # collections of interfaces and structs to be used by mojo ipc clients and |
7 # servers. | 7 # servers. |
8 # | 8 # |
9 # A simple interface would be created this way: | 9 # A simple interface would be created this way: |
10 # module = mojom.generate.module.Module('Foo') | 10 # module = mojom.generate.module.Module('Foo') |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 | 221 |
222 def __init__(self, length=-1, kind=None): | 222 def __init__(self, length=-1, kind=None): |
223 if kind is not None: | 223 if kind is not None: |
224 ReferenceKind.__init__(self, 'a%d:%s' % (length, kind.spec)) | 224 ReferenceKind.__init__(self, 'a%d:%s' % (length, kind.spec)) |
225 else: | 225 else: |
226 ReferenceKind.__init__(self) | 226 ReferenceKind.__init__(self) |
227 self.kind = kind | 227 self.kind = kind |
228 self.length = length | 228 self.length = length |
229 | 229 |
230 | 230 |
231 class Map(ReferenceKind): | |
232 ReferenceKind.AddSharedProperty('key_kind') | |
233 ReferenceKind.AddSharedProperty('value_kind') | |
234 | |
235 def __init__(self, key_kind=None, value_kind=None): | |
236 if (key_kind is not None and value_kind is not None): | |
237 ReferenceKind.__init__(self, | |
238 'm[' + key_kind.spec + '][' + value_kind.spec + | |
239 ']') | |
240 if IsNullableKind(key_kind): | |
241 raise Exception("Nullable kinds can not be keys in maps.") | |
242 if IsStructKind(key_kind): | |
243 # TODO(erg): It would sometimes be nice if we could key on struct | |
244 # values. However, what happens if the struct has a handle in it? Or | |
245 # non-copyable data like an array? | |
246 raise Exception("Structs can not be keys in maps.") | |
247 if IsAnyHandleKind(key_kind): | |
248 raise Exception("Handles can not be keys in maps.") | |
249 if IsAnyArrayKind(key_kind): | |
250 raise Exception("Arrays can not be keys in maps.") | |
251 else: | |
252 ReferenceKind.__init__(self) | |
253 | |
254 self.key_kind = key_kind | |
255 self.value_kind = value_kind | |
256 | |
257 | |
231 class InterfaceRequest(ReferenceKind): | 258 class InterfaceRequest(ReferenceKind): |
232 ReferenceKind.AddSharedProperty('kind') | 259 ReferenceKind.AddSharedProperty('kind') |
233 | 260 |
234 def __init__(self, kind=None): | 261 def __init__(self, kind=None): |
235 if kind is not None: | 262 if kind is not None: |
236 ReferenceKind.__init__(self, 'r:' + kind.spec) | 263 ReferenceKind.__init__(self, 'r:' + kind.spec) |
237 else: | 264 else: |
238 ReferenceKind.__init__(self) | 265 ReferenceKind.__init__(self) |
239 self.kind = kind | 266 self.kind = kind |
240 | 267 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 | 419 |
393 | 420 |
394 def IsNullableKind(kind): | 421 def IsNullableKind(kind): |
395 return IsReferenceKind(kind) and kind.is_nullable | 422 return IsReferenceKind(kind) and kind.is_nullable |
396 | 423 |
397 | 424 |
398 def IsAnyArrayKind(kind): | 425 def IsAnyArrayKind(kind): |
399 return IsArrayKind(kind) or IsFixedArrayKind(kind) | 426 return IsArrayKind(kind) or IsFixedArrayKind(kind) |
400 | 427 |
401 | 428 |
429 def IsMapKind(kind): | |
430 return isinstance(kind, Map) | |
431 | |
432 | |
402 def IsObjectKind(kind): | 433 def IsObjectKind(kind): |
403 return IsStructKind(kind) or IsAnyArrayKind(kind) or IsStringKind(kind) | 434 return (IsStructKind(kind) or IsAnyArrayKind(kind) or IsStringKind(kind) or |
404 | 435 IsMapKind(kind)) |
405 | 436 |
viettrungluu
2014/10/09 22:22:35
nit: one more blank line (apparently), please, for
| |
406 def IsNonInterfaceHandleKind(kind): | 437 def IsNonInterfaceHandleKind(kind): |
407 return (IsHandleKind(kind) or | 438 return (IsHandleKind(kind) or |
408 IsDataPipeConsumerKind(kind) or | 439 IsDataPipeConsumerKind(kind) or |
409 IsDataPipeProducerKind(kind) or | 440 IsDataPipeProducerKind(kind) or |
410 IsMessagePipeKind(kind) or | 441 IsMessagePipeKind(kind) or |
411 IsSharedBufferKind(kind)) | 442 IsSharedBufferKind(kind)) |
412 | 443 |
413 | 444 |
414 def IsAnyHandleKind(kind): | 445 def IsAnyHandleKind(kind): |
415 return (IsNonInterfaceHandleKind(kind) or | 446 return (IsNonInterfaceHandleKind(kind) or |
(...skipping 23 matching lines...) Expand all Loading... | |
439 | 470 |
440 return not ContainsHandles(kind, set()) | 471 return not ContainsHandles(kind, set()) |
441 | 472 |
442 | 473 |
443 def HasCallbacks(interface): | 474 def HasCallbacks(interface): |
444 for method in interface.methods: | 475 for method in interface.methods: |
445 if method.response_parameters != None: | 476 if method.response_parameters != None: |
446 return True | 477 return True |
447 return False | 478 return False |
448 | 479 |
OLD | NEW |