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 |
| 435 IsMapKind(kind)) |
404 | 436 |
405 | 437 |
406 def IsNonInterfaceHandleKind(kind): | 438 def IsNonInterfaceHandleKind(kind): |
407 return (IsHandleKind(kind) or | 439 return (IsHandleKind(kind) or |
408 IsDataPipeConsumerKind(kind) or | 440 IsDataPipeConsumerKind(kind) or |
409 IsDataPipeProducerKind(kind) or | 441 IsDataPipeProducerKind(kind) or |
410 IsMessagePipeKind(kind) or | 442 IsMessagePipeKind(kind) or |
411 IsSharedBufferKind(kind)) | 443 IsSharedBufferKind(kind)) |
412 | 444 |
413 | 445 |
(...skipping 25 matching lines...) Expand all Loading... |
439 | 471 |
440 return not ContainsHandles(kind, set()) | 472 return not ContainsHandles(kind, set()) |
441 | 473 |
442 | 474 |
443 def HasCallbacks(interface): | 475 def HasCallbacks(interface): |
444 for method in interface.methods: | 476 for method in interface.methods: |
445 if method.response_parameters != None: | 477 if method.response_parameters != None: |
446 return True | 478 return True |
447 return False | 479 return False |
448 | 480 |
OLD | NEW |