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

Unified Diff: runtime/vm/native_api_impl.cc

Issue 16973003: Split dart_api.h into multiple parts: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/mirrors_api_impl.cc ('k') | runtime/vm/native_message_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/native_api_impl.cc
===================================================================
--- runtime/vm/native_api_impl.cc (revision 0)
+++ runtime/vm/native_api_impl.cc (revision 0)
@@ -0,0 +1,136 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "include/dart_native_api.h"
+
+#include "platform/assert.h"
+#include "vm/dart_api_impl.h"
+#include "vm/dart_api_message.h"
+#include "vm/dart_api_state.h"
+#include "vm/message.h"
+#include "vm/native_message_handler.h"
+#include "vm/port.h"
+
+namespace dart {
+
+// --- Message sending/receiving from native code ---
+
+static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
+ void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
+ return reinterpret_cast<uint8_t*>(new_ptr);
+}
+
+
+DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) {
+ uint8_t* buffer = NULL;
+ ApiMessageWriter writer(&buffer, allocator);
+ bool success = writer.WriteCMessage(message);
+
+ if (!success) return success;
+
+ // Post the message at the given port.
+ return PortMap::PostMessage(new Message(
+ port_id, Message::kIllegalPort, buffer, writer.BytesWritten(),
+ Message::kNormalPriority));
+}
+
+
+DART_EXPORT Dart_Port Dart_NewNativePort(const char* name,
+ Dart_NativeMessageHandler handler,
+ bool handle_concurrently) {
+ if (name == NULL) {
+ name = "<UnnamedNativePort>";
+ }
+ if (handler == NULL) {
+ OS::PrintErr("%s expects argument 'handler' to be non-null.\n",
+ CURRENT_FUNC);
+ return ILLEGAL_PORT;
+ }
+ // Start the native port without a current isolate.
+ IsolateSaver saver(Isolate::Current());
+ Isolate::SetCurrent(NULL);
+
+ NativeMessageHandler* nmh = new NativeMessageHandler(name, handler);
+ Dart_Port port_id = PortMap::CreatePort(nmh);
+ nmh->Run(Dart::thread_pool(), NULL, NULL, 0);
+ return port_id;
+}
+
+
+DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) {
+ // Close the native port without a current isolate.
+ IsolateSaver saver(Isolate::Current());
+ Isolate::SetCurrent(NULL);
+
+ // TODO(turnidge): Check that the port is native before trying to close.
+ return PortMap::ClosePort(native_port_id);
+}
+
+
+// --- Profiling support ---
+
+// TODO(7565): Dartium should use the new VM flag "generate_pprof_symbols" for
+// pprof profiling. Then these symbols should be removed.
+
+DART_EXPORT void Dart_InitPprofSupport() { }
+
+DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) {
+ *buffer = NULL;
+ *buffer_size = 0;
+}
+
+
+// --- Heap Profiler ---
+
+DART_EXPORT Dart_Handle Dart_HeapProfile(Dart_FileWriteCallback callback,
+ void* stream) {
+ Isolate* isolate = Isolate::Current();
+ CHECK_ISOLATE(isolate);
+ if (callback == NULL) {
+ RETURN_NULL_ERROR(callback);
+ }
+ isolate->heap()->Profile(callback, stream);
+ return Api::Success();
+}
+
+
+// --- Verification tools ---
+
+static void CompileAll(Isolate* isolate, Dart_Handle* result) {
+ ASSERT(isolate != NULL);
+ const Error& error = Error::Handle(isolate, Library::CompileAll());
+ if (error.IsNull()) {
+ *result = Api::Success();
+ } else {
+ *result = Api::NewHandle(isolate, error.raw());
+ }
+}
+
+
+DART_EXPORT Dart_Handle Dart_CompileAll() {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ Dart_Handle result = Api::CheckIsolateState(isolate);
+ if (::Dart_IsError(result)) {
+ return result;
+ }
+ CHECK_CALLBACK_STATE(isolate);
+ CompileAll(isolate, &result);
+ return result;
+}
+
+
+DART_EXPORT Dart_Handle Dart_CheckFunctionFingerprints() {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ Dart_Handle result = Api::CheckIsolateState(isolate);
+ if (::Dart_IsError(result)) {
+ return result;
+ }
+ CHECK_CALLBACK_STATE(isolate);
+ Library::CheckFunctionFingerprints();
+ return result;
+}
+
+} // namespace dart
« no previous file with comments | « runtime/vm/mirrors_api_impl.cc ('k') | runtime/vm/native_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698