OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #include "vm/native_message_handler.h" | |
6 | |
7 #include "vm/isolate.h" | |
8 #include "vm/message.h" | |
9 #include "vm/thread.h" | |
10 | |
11 namespace dart { | |
12 | |
13 NativeMessageHandler::NativeMessageHandler(const char* name, | |
14 Dart_NativeMessageHandler func) | |
15 : name_(strdup(name)), | |
16 func_(func) { | |
17 // A NativeMessageHandler always has one live port. | |
18 increment_live_ports(); | |
19 } | |
20 | |
21 | |
22 NativeMessageHandler::~NativeMessageHandler() { | |
23 free(name_); | |
24 } | |
25 | |
26 | |
27 #if defined(DEBUG) | |
28 void NativeMessageHandler::CheckAccess() { | |
29 ASSERT(Isolate::Current() == NULL); | |
30 } | |
31 #endif | |
32 | |
33 | |
34 static void RunWorker(uword parameter) { | |
35 NativeMessageHandler* handler = | |
36 reinterpret_cast<NativeMessageHandler*>(parameter); | |
37 #if defined(DEBUG) | |
38 handler->CheckAccess(); | |
39 #endif | |
40 | |
41 while (handler->HasLivePorts()) { | |
42 Message* message = handler->queue()->Dequeue(0); | |
43 if (message != NULL) { | |
44 if (message->priority() >= Message::kOOBPriority) { | |
45 // TODO(turnidge): Out of band messages will not go through | |
46 // the regular message handler. Instead they will be | |
47 // dispatched to special vm code. Implement. | |
48 UNIMPLEMENTED(); | |
49 } | |
siva
2012/02/01 00:38:56
I suppose CMessageReader::ReadObject will be calle
turnidge
2012/02/01 18:51:27
Done.
| |
50 (*handler->func())(message->dest_port(), | |
51 message->reply_port(), | |
52 message->data()); | |
53 delete message; | |
54 } | |
55 } | |
56 } | |
57 | |
58 | |
59 void NativeMessageHandler::StartWorker() { | |
60 new Thread(RunWorker, reinterpret_cast<uword>(this)); | |
61 } | |
62 | |
63 | |
64 } // namespace dart | |
OLD | NEW |