OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/native_message_handler.h" | 5 #include "vm/native_message_handler.h" |
6 | 6 |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/message.h" | 8 #include "vm/message.h" |
9 #include "vm/snapshot.h" | |
9 #include "vm/thread.h" | 10 #include "vm/thread.h" |
10 | 11 |
11 namespace dart { | 12 namespace dart { |
12 | 13 |
13 NativeMessageHandler::NativeMessageHandler(const char* name, | 14 NativeMessageHandler::NativeMessageHandler(const char* name, |
14 Dart_NativeMessageHandler func) | 15 Dart_NativeMessageHandler func) |
15 : name_(strdup(name)), | 16 : name_(strdup(name)), |
16 func_(func) { | 17 func_(func) { |
17 // A NativeMessageHandler always has one live port. | 18 // A NativeMessageHandler always has one live port. |
18 increment_live_ports(); | 19 increment_live_ports(); |
(...skipping 21 matching lines...) Expand all Loading... | |
40 | 41 |
41 while (handler->HasLivePorts()) { | 42 while (handler->HasLivePorts()) { |
42 Message* message = handler->queue()->Dequeue(0); | 43 Message* message = handler->queue()->Dequeue(0); |
43 if (message != NULL) { | 44 if (message != NULL) { |
44 if (message->priority() >= Message::kOOBPriority) { | 45 if (message->priority() >= Message::kOOBPriority) { |
45 // TODO(turnidge): Out of band messages will not go through | 46 // TODO(turnidge): Out of band messages will not go through |
46 // the regular message handler. Instead they will be | 47 // the regular message handler. Instead they will be |
47 // dispatched to special vm code. Implement. | 48 // dispatched to special vm code. Implement. |
48 UNIMPLEMENTED(); | 49 UNIMPLEMENTED(); |
49 } | 50 } |
50 // TODO(sgjesse): Once CMessageReader::ReadObject is committed, | 51 // Create a new zone for allocating all the structures for the |
51 // use that here and pass the resulting data object to the | 52 // decoded message. |
52 // handler instead. | 53 Zone zone; |
siva
2012/02/04 01:55:43
Instead of modifying zone to accept a version with
Søren Gjesse
2012/02/06 16:25:52
The problem with using an ApiZone here is that the
siva
2012/02/07 01:03:24
You could make BaseGrowableArray use BaseZone* as
| |
54 int32_t length = reinterpret_cast<int32_t*>( | |
55 message->data())[Snapshot::kLengthIndex]; | |
56 CMessageReader message_reader(message->data() + Snapshot::kHeaderSize, | |
57 length, | |
58 &zone); | |
siva
2012/02/04 01:55:43
Do you really want a version of the reader with a
Søren Gjesse
2012/02/06 16:25:52
We do need a thread local if we are not passing in
siva
2012/02/07 01:03:24
I have reviewed that change, it seems fine to abst
| |
59 Dart_CMessage* cmessage = message_reader.ReadMessage(); | |
53 (*handler->func())(message->dest_port(), | 60 (*handler->func())(message->dest_port(), |
54 message->reply_port(), | 61 message->reply_port(), |
55 message->data()); | 62 cmessage); |
56 delete message; | 63 delete message; |
57 } | 64 } |
58 } | 65 } |
59 } | 66 } |
60 | 67 |
61 | 68 |
62 void NativeMessageHandler::StartWorker() { | 69 void NativeMessageHandler::StartWorker() { |
63 int result = Thread::Start(RunWorker, reinterpret_cast<uword>(this)); | 70 int result = Thread::Start(RunWorker, reinterpret_cast<uword>(this)); |
64 if (result != 0) { | 71 if (result != 0) { |
65 FATAL1("Failed to start native message handler worker thread %d", result); | 72 FATAL1("Failed to start native message handler worker thread %d", result); |
66 } | 73 } |
67 } | 74 } |
68 | 75 |
69 | 76 |
70 } // namespace dart | 77 } // namespace dart |
OLD | NEW |