OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Utility classes to handle sending and receiving messages.""" | 5 """Utility classes to handle sending and receiving messages.""" |
6 | 6 |
7 | 7 |
8 import struct | 8 import struct |
9 import sys | 9 import sys |
10 import weakref | 10 import weakref |
11 | 11 |
12 import mojo.bindings.serialization as serialization | 12 import mojo_bindings.serialization as serialization |
13 | 13 |
14 # pylint: disable=E0611,F0401 | 14 # pylint: disable=E0611,F0401 |
15 import mojo.system as system | 15 import mojo_system as system |
16 | 16 |
17 | 17 |
18 # The flag values for a message header. | 18 # The flag values for a message header. |
19 NO_FLAG = 0 | 19 NO_FLAG = 0 |
20 MESSAGE_EXPECTS_RESPONSE_FLAG = 1 << 0 | 20 MESSAGE_EXPECTS_RESPONSE_FLAG = 1 << 0 |
21 MESSAGE_IS_RESPONSE_FLAG = 1 << 1 | 21 MESSAGE_IS_RESPONSE_FLAG = 1 << 1 |
22 | 22 |
23 | 23 |
24 class MessagingException(Exception): | 24 class MessagingException(Exception): |
25 def __init__(self, *args, **kwargs): | 25 def __init__(self, *args, **kwargs): |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 message_receiver.Accept(Message(bytearray(), [])) | 398 message_receiver.Accept(Message(bytearray(), [])) |
399 if result != system.RESULT_RESOURCE_EXHAUSTED: | 399 if result != system.RESULT_RESOURCE_EXHAUSTED: |
400 return result | 400 return result |
401 (result, data, _) = handle.ReadMessage(bytearray(sizes[0]), sizes[1]) | 401 (result, data, _) = handle.ReadMessage(bytearray(sizes[0]), sizes[1]) |
402 if result == system.RESULT_OK and message_receiver: | 402 if result == system.RESULT_OK and message_receiver: |
403 message_receiver.Accept(Message(data[0], data[1])) | 403 message_receiver.Accept(Message(data[0], data[1])) |
404 return result | 404 return result |
405 | 405 |
406 def _HasRequestId(flags): | 406 def _HasRequestId(flags): |
407 return flags & (MESSAGE_EXPECTS_RESPONSE_FLAG|MESSAGE_IS_RESPONSE_FLAG) != 0 | 407 return flags & (MESSAGE_EXPECTS_RESPONSE_FLAG|MESSAGE_IS_RESPONSE_FLAG) != 0 |
OLD | NEW |