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 IsHandleKind(key_kind): | |
yzshen1
2014/10/08 21:58:33
IsAnyHandleKind?
Besides, shall we also disable A
| |
248 raise Exception("Handles can not be keys in maps.") | |
249 else: | |
250 ReferenceKind.__init__(self) | |
251 | |
252 self.key_kind = key_kind | |
253 self.value_kind = value_kind | |
254 | |
255 | |
231 class InterfaceRequest(ReferenceKind): | 256 class InterfaceRequest(ReferenceKind): |
232 ReferenceKind.AddSharedProperty('kind') | 257 ReferenceKind.AddSharedProperty('kind') |
233 | 258 |
234 def __init__(self, kind=None): | 259 def __init__(self, kind=None): |
235 if kind is not None: | 260 if kind is not None: |
236 ReferenceKind.__init__(self, 'r:' + kind.spec) | 261 ReferenceKind.__init__(self, 'r:' + kind.spec) |
237 else: | 262 else: |
238 ReferenceKind.__init__(self) | 263 ReferenceKind.__init__(self) |
239 self.kind = kind | 264 self.kind = kind |
240 | 265 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 | 417 |
393 | 418 |
394 def IsNullableKind(kind): | 419 def IsNullableKind(kind): |
395 return IsReferenceKind(kind) and kind.is_nullable | 420 return IsReferenceKind(kind) and kind.is_nullable |
396 | 421 |
397 | 422 |
398 def IsAnyArrayKind(kind): | 423 def IsAnyArrayKind(kind): |
399 return IsArrayKind(kind) or IsFixedArrayKind(kind) | 424 return IsArrayKind(kind) or IsFixedArrayKind(kind) |
400 | 425 |
401 | 426 |
427 def IsMapKind(kind): | |
428 return isinstance(kind, Map) | |
429 | |
430 | |
402 def IsObjectKind(kind): | 431 def IsObjectKind(kind): |
403 return IsStructKind(kind) or IsAnyArrayKind(kind) or IsStringKind(kind) | 432 return (IsStructKind(kind) or IsAnyArrayKind(kind) or IsStringKind(kind) or |
404 | 433 IsMapKind(kind)) |
405 | 434 |
406 def IsNonInterfaceHandleKind(kind): | 435 def IsNonInterfaceHandleKind(kind): |
407 return (IsHandleKind(kind) or | 436 return (IsHandleKind(kind) or |
408 IsDataPipeConsumerKind(kind) or | 437 IsDataPipeConsumerKind(kind) or |
409 IsDataPipeProducerKind(kind) or | 438 IsDataPipeProducerKind(kind) or |
410 IsMessagePipeKind(kind) or | 439 IsMessagePipeKind(kind) or |
411 IsSharedBufferKind(kind)) | 440 IsSharedBufferKind(kind)) |
412 | 441 |
413 | 442 |
414 def IsAnyHandleKind(kind): | 443 def IsAnyHandleKind(kind): |
(...skipping 24 matching lines...) Expand all Loading... | |
439 | 468 |
440 return not ContainsHandles(kind, set()) | 469 return not ContainsHandles(kind, set()) |
441 | 470 |
442 | 471 |
443 def HasCallbacks(interface): | 472 def HasCallbacks(interface): |
444 for method in interface.methods: | 473 for method in interface.methods: |
445 if method.response_parameters != None: | 474 if method.response_parameters != None: |
446 return True | 475 return True |
447 return False | 476 return False |
448 | 477 |
OLD | NEW |