OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_MESSAGE_H_ | 5 #ifndef VM_MESSAGE_H_ |
6 #define VM_MESSAGE_H_ | 6 #define VM_MESSAGE_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" |
9 #include "vm/globals.h" | 10 #include "vm/globals.h" |
10 | 11 |
11 // Duplicated from dart_api.h to avoid including the whole header. | 12 // Duplicated from dart_api.h to avoid including the whole header. |
12 typedef int64_t Dart_Port; | 13 typedef int64_t Dart_Port; |
13 | 14 |
14 namespace dart { | 15 namespace dart { |
15 | 16 |
| 17 class JSONStream; |
| 18 |
16 class Message { | 19 class Message { |
17 public: | 20 public: |
18 typedef enum { | 21 typedef enum { |
19 kNormalPriority = 0, // Deliver message when idle. | 22 kNormalPriority = 0, // Deliver message when idle. |
20 kOOBPriority = 1, // Deliver message asap. | 23 kOOBPriority = 1, // Deliver message asap. |
21 | 24 |
22 // Iteration. | 25 // Iteration. |
23 kFirstPriority = 0, | 26 kFirstPriority = 0, |
24 kNumPriorities = 2, | 27 kNumPriorities = 2, |
25 } Priority; | 28 } Priority; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 64 |
62 Dart_Port dest_port() const { return dest_port_; } | 65 Dart_Port dest_port() const { return dest_port_; } |
63 uint8_t* data() const { return data_; } | 66 uint8_t* data() const { return data_; } |
64 intptr_t len() const { return len_; } | 67 intptr_t len() const { return len_; } |
65 Priority priority() const { return priority_; } | 68 Priority priority() const { return priority_; } |
66 | 69 |
67 bool IsOOB() const { return priority_ == Message::kOOBPriority; } | 70 bool IsOOB() const { return priority_ == Message::kOOBPriority; } |
68 | 71 |
69 bool RedirectToDeliveryFailurePort(); | 72 bool RedirectToDeliveryFailurePort(); |
70 | 73 |
| 74 intptr_t Id() const; |
| 75 |
| 76 static const char* PriorityAsString(Priority priority); |
| 77 |
71 private: | 78 private: |
72 friend class MessageQueue; | 79 friend class MessageQueue; |
73 | 80 |
74 Message* next_; | 81 Message* next_; |
75 Dart_Port dest_port_; | 82 Dart_Port dest_port_; |
76 Dart_Port delivery_failure_port_; | 83 Dart_Port delivery_failure_port_; |
77 uint8_t* data_; | 84 uint8_t* data_; |
78 intptr_t len_; | 85 intptr_t len_; |
79 Priority priority_; | 86 Priority priority_; |
80 | 87 |
(...skipping 10 matching lines...) Expand all Loading... |
91 | 98 |
92 // Gets the next message from the message queue or NULL if no | 99 // Gets the next message from the message queue or NULL if no |
93 // message is available. This function will not block. | 100 // message is available. This function will not block. |
94 Message* Dequeue(); | 101 Message* Dequeue(); |
95 | 102 |
96 bool IsEmpty() { return head_ == NULL; } | 103 bool IsEmpty() { return head_ == NULL; } |
97 | 104 |
98 // Clear all messages from the message queue. | 105 // Clear all messages from the message queue. |
99 void Clear(); | 106 void Clear(); |
100 | 107 |
| 108 // Iterator class. |
| 109 class Iterator : public ValueObject { |
| 110 public: |
| 111 explicit Iterator(const MessageQueue* queue); |
| 112 virtual ~Iterator(); |
| 113 |
| 114 void Reset(const MessageQueue* queue); |
| 115 |
| 116 // Returns false when there are no more messages left. |
| 117 bool HasNext(); |
| 118 |
| 119 // Returns the current message and moves forward. |
| 120 Message* Next(); |
| 121 |
| 122 private: |
| 123 Message* next_; |
| 124 }; |
| 125 |
| 126 intptr_t Length() const; |
| 127 |
| 128 // Returns the message with id or NULL. |
| 129 Message* FindMessageById(intptr_t id); |
| 130 |
| 131 void PrintJSON(JSONStream* stream); |
| 132 |
101 private: | 133 private: |
102 Message* head_; | 134 Message* head_; |
103 Message* tail_; | 135 Message* tail_; |
104 | 136 |
105 DISALLOW_COPY_AND_ASSIGN(MessageQueue); | 137 DISALLOW_COPY_AND_ASSIGN(MessageQueue); |
106 }; | 138 }; |
107 | 139 |
108 } // namespace dart | 140 } // namespace dart |
109 | 141 |
110 #endif // VM_MESSAGE_H_ | 142 #endif // VM_MESSAGE_H_ |
OLD | NEW |