| 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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 #include "bin/eventhandler.h" | 6 #include "bin/eventhandler.h" |
| 7 #include "bin/socket.h" |
| 7 | 8 |
| 8 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 9 | 10 |
| 10 | 11 |
| 11 static const intptr_t kNativeEventHandlerFieldIndex = 0; | 12 static const int kNativeEventHandlerFieldIndex = 0; |
| 13 static const intptr_t kTimerId = -1; |
| 14 static const intptr_t kInvalidId = -2; |
| 12 | 15 |
| 13 /* | 16 /* |
| 14 * Returns the reference of the EventHandler stored in the native field. | 17 * Returns the reference of the EventHandler stored in the native field. |
| 15 */ | 18 */ |
| 16 static EventHandler* GetEventHandler(Dart_Handle handle) { | 19 static EventHandler* GetEventHandler(Dart_Handle handle) { |
| 17 intptr_t value = 0; | 20 intptr_t value = 0; |
| 18 Dart_Handle result = Dart_GetNativeInstanceField( | 21 Dart_Handle result = Dart_GetNativeInstanceField( |
| 19 handle, kNativeEventHandlerFieldIndex, &value); | 22 handle, kNativeEventHandlerFieldIndex, &value); |
| 20 if (Dart_IsError(result)) { | 23 if (Dart_IsError(result)) { |
| 21 Dart_PropagateError(result); | 24 Dart_PropagateError(result); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 | 55 |
| 53 /* | 56 /* |
| 54 * Send data to the EventHandler thread to register for a given instance | 57 * Send data to the EventHandler thread to register for a given instance |
| 55 * args[1] a ReceivePort args[2] with a notification event args[3]. args[0] | 58 * args[1] a ReceivePort args[2] with a notification event args[3]. args[0] |
| 56 * holds the reference to the dart EventHandler object. | 59 * holds the reference to the dart EventHandler object. |
| 57 */ | 60 */ |
| 58 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) { | 61 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) { |
| 59 Dart_EnterScope(); | 62 Dart_EnterScope(); |
| 60 Dart_Handle handle = Dart_GetNativeArgument(args, 0); | 63 Dart_Handle handle = Dart_GetNativeArgument(args, 0); |
| 61 EventHandler* event_handler = GetEventHandler(handle); | 64 EventHandler* event_handler = GetEventHandler(handle); |
| 62 intptr_t id = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 65 Dart_Handle sender = Dart_GetNativeArgument(args, 1); |
| 66 intptr_t id = kInvalidId; |
| 67 if (Dart_IsNull(sender)) { |
| 68 id = kTimerId; |
| 69 } else { |
| 70 Socket::GetSocketIdNativeField(sender, &id); |
| 71 } |
| 63 handle = Dart_GetNativeArgument(args, 2); | 72 handle = Dart_GetNativeArgument(args, 2); |
| 64 Dart_Port dart_port = | 73 Dart_Port dart_port = |
| 65 DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName); | 74 DartUtils::GetIntegerField(handle, DartUtils::kIdFieldName); |
| 66 intptr_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 75 intptr_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 67 event_handler->SendData(id, dart_port, data); | 76 event_handler->SendData(id, dart_port, data); |
| 68 Dart_ExitScope(); | 77 Dart_ExitScope(); |
| 69 } | 78 } |
| OLD | NEW |