Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: runtime/vm/native_message_handler.cc

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/native_message_handler.h ('k') | runtime/vm/port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
50 // TODO(sgjesse): Once CMessageReader::ReadObject is committed,
51 // use that here and pass the resulting data object to the
52 // handler instead.
53 (*handler->func())(message->dest_port(),
54 message->reply_port(),
55 message->data());
56 delete message;
57 }
58 }
59 }
60
61
62 void NativeMessageHandler::StartWorker() {
63 new Thread(RunWorker, reinterpret_cast<uword>(this));
64 }
65
66
67 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/native_message_handler.h ('k') | runtime/vm/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698