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): |
| 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): |
415 return (IsNonInterfaceHandleKind(kind) or | 444 return (IsNonInterfaceHandleKind(kind) or |
416 IsInterfaceKind(kind) or | 445 IsInterfaceKind(kind) or |
417 IsInterfaceRequestKind(kind)) | 446 IsInterfaceRequestKind(kind)) |
418 | 447 |
419 | 448 |
420 def IsMoveOnlyKind(kind): | 449 def IsMoveOnlyKind(kind): |
421 return IsObjectKind(kind) or IsAnyHandleKind(kind) | 450 return IsObjectKind(kind) or IsAnyHandleKind(kind) |
422 | 451 |
423 | 452 |
424 def HasCallbacks(interface): | 453 def HasCallbacks(interface): |
425 for method in interface.methods: | 454 for method in interface.methods: |
426 if method.response_parameters != None: | 455 if method.response_parameters != None: |
427 return True | 456 return True |
428 return False | 457 return False |
429 | 458 |
OLD | NEW |