Index: mojo/dart/packages/mojo/lib/src/internal_contract.dart |
diff --git a/mojo/dart/packages/mojo/sdk_ext/src/natives.dart b/mojo/dart/packages/mojo/lib/src/internal_contract.dart |
similarity index 71% |
copy from mojo/dart/packages/mojo/sdk_ext/src/natives.dart |
copy to mojo/dart/packages/mojo/lib/src/internal_contract.dart |
index dc0de37f87c194bb9c1381eb7947fff2611f038b..fe2376415a875926c8a7e27f4ce6b2f30b2518c8 100644 |
--- a/mojo/dart/packages/mojo/sdk_ext/src/natives.dart |
+++ b/mojo/dart/packages/mojo/lib/src/internal_contract.dart |
@@ -1,14 +1,99 @@ |
-// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-part of internal; |
+import 'dart:async'; |
+import 'dart:isolate' show SendPort; |
+import 'dart:typed_data' show ByteData; |
+ |
+// The following import is only here to get references in the documentation |
+// to work. There is no dependency from the internal library to 'core'. |
+// TODO(floitsch): move the constants into the internal-library, and |
+// reference them from the package-classes. |
+import '../core.dart' |
+ show |
+ MojoResult, |
+ MojoHandleSignals, |
+ MojoMessagePipe, |
+ MojoMessagePipeEndpoint, |
+ MojoDataPipe, |
+ MojoDataPipeProducer, |
+ MojoDataPipeConsumer, |
+ MojoEventSubscription, |
+ MojoSharedBuffer; |
+ |
+/// This class contains static methods to send a stream of events to application |
+/// isolates that register Mojo handles with it. |
+class MojoHandleWatcher { |
+ /// Starts watching for events on the given [handleToken]. |
+ /// |
+ /// Returns an integer, encoding the result as specified in the [MojoResult] |
+ /// class. In particular, a successful operation returns [MojoResult.kOk]. |
+ /// |
+ /// Instructs the MojoHandleWatcher isolate to add [handleToken] to the set of |
+ /// handles it watches, and to notify the calling isolate only for the events |
+ /// specified by [signals] using the send port [port]. |
+ // TODO(floitsch): what does "MojoHandleWatcher isolate" mean? |
+ // TODO(floitsch): what is the calling isolate? |
+ /// |
+ /// The [handleToken] is a token that identifies the Mojo handle. |
+ /// |
+ /// The filtering [signals] are encoded as specified in the |
+ /// [MojoHandleSignals] class. For example, setting [signals] to |
+ /// [MojoHandleSignals.kPeerClosedReadable] instructs the handle watcher to |
+ /// notify the caller, when the handle becomes readable (that is, has data |
+ /// available for reading), or when it is closed. |
+ static int add(Object handleToken, SendPort port, int signals) { |
+ throw new UnsupportedError("MojoHandleWatcher.add on contract"); |
+ } |
+ |
+ /// Stops watching the given [handleToken]. |
+ /// |
+ /// Returns an integer, encoding the result as specified in the [MojoResult] |
+ /// class. In particular, a successful operation returns [MojoResult.kOk]. |
+ /// |
+ /// Instructs the MojoHandleWatcher isolate to remove [handleToken] from the |
+ /// set of handles it watches. This allows the application isolate |
+ /// to, for example, pause the stream of events. |
+ /// |
+ /// The [handleToken] is a token that identifies the Mojo handle. |
+ static int remove(Object handleToken) { |
+ throw new UnsupportedError("MojoHandleWatcher.remove on contract"); |
+ } |
-// Data associated with an open handle. |
-class _OpenHandle { |
- final StackTrace stack; |
- String description; |
- _OpenHandle(this.stack, {this.description}); |
+ /// Stops watching and closes the given [handleToken]. |
+ /// |
+ /// Returns an integer, encoding the result as specified in the [MojoResult] |
+ /// class. In particular, a successful operation returns [MojoResult.kOk]. |
+ /// |
+ /// Notifies the HandleWatcherIsolate that a handle it is |
+ /// watching should be removed from its set and closed. |
+ /// |
+ /// The [handleToken] is a token that identifies the Mojo handle. |
+ /// |
+ /// If [wait] is true, returns a future that resolves only after the handle |
+ // has actually been closed by the handle watcher. Otherwise, returns a |
+ // future that resolves immediately. |
+ static Future<int> close(Object handleToken, {bool wait: false}) { |
+ throw new UnsupportedError("MojoHandleWatcher.close on contract"); |
+ } |
+ |
+ /// Requests a notification on the given [port] at [deadline]. |
+ /// |
+ /// Returns an integer, encoding the result as specified in the [MojoResult] |
+ /// class. In particular, a successful operation returns [MojoResult.kOk]. |
+ /// |
+ /// The [deadline] is in milliseconds, with |
+ /// [MojoCoreNatives.timerMillisecondClock] as reference. |
+ /// |
+ /// If the given [port] was already registered for a timer (in any isolate), |
+ /// then the old value is discarded. |
+ /// |
+ /// A negative [deadline] is used to remove a port. That is, a negative value |
+ /// is ignored after any existing value for the port has been discarded. |
+ static int timer(Object ignored, SendPort port, int deadline) { |
+ throw new UnsupportedError("MojoHandleWatcher.timer on contract"); |
+ } |
} |
class MojoCoreNatives { |
@@ -21,29 +106,28 @@ class MojoCoreNatives { |
/// |
/// Although the units are microseconds, the resolution of the clock may vary |
/// and is typically in the range of ~1-15 ms. |
- static int getTimeTicksNow() native "Mojo_GetTimeTicksNow"; |
+ static int getTimeTicksNow() { |
+ throw new UnsupportedError("MojoCoreNatives.getTimeTicksNow on contract"); |
+ } |
/// Returns the time, in milliseconds, since some undefined point in the past. |
/// |
/// This method is equivalent to `getTimeTicksNow() ~/ 1000`. |
- static int timerMillisecondClock() => getTimeTicksNow() ~/ 1000; |
+ static int timerMillisecondClock() { |
+ throw new UnsupportedError( |
+ "MojoCoreNatives.timerMillisecondClock on contract"); |
+ } |
} |
class MojoHandleNatives { |
- static HashMap<int, _OpenHandle> _openHandles = new HashMap(); |
- |
/// Puts the given [handleToken] with the given [description] into the set of |
/// open handles. |
/// |
/// The [handleToken] is a token that identifies the Mojo handle. |
/// |
/// This method is only used to report open handles (see [reportOpenHandles]). |
- static void addOpenHandle(int handleToken, {String description}) { |
- var stack; |
- // We only remember a stack trace when in checked mode. |
- assert((stack = StackTrace.current) != null); |
- var openHandle = new _OpenHandle(stack, description: description); |
- _openHandles[handleToken] = openHandle; |
+ static void addOpenHandle(Object handleToken, {String description}) { |
+ throw new UnsupportedError("MojoHandleNatives.addOpenHandle on contract"); |
} |
/// Removes the given [handleToken] from the set of open handles. |
@@ -54,23 +138,9 @@ class MojoHandleNatives { |
/// |
/// Handles are removed from the set when they are closed, but also, when they |
/// are serialized in the mojo encoder [codec.dart]. |
- static void removeOpenHandle(int handleToken) { |
- _openHandles.remove(handleToken); |
- } |
- |
- static void _reportOpenHandle(int handle, _OpenHandle openHandle) { |
- StringBuffer sb = new StringBuffer(); |
- sb.writeln('HANDLE LEAK: handle: $handle'); |
- if (openHandle.description != null) { |
- sb.writeln('HANDLE LEAK: description: ${openHandle.description}'); |
- } |
- if (openHandle.stack != null) { |
- sb.writeln('HANDLE LEAK: creation stack trace:'); |
- sb.writeln(openHandle.stack); |
- } else { |
- sb.writeln('HANDLE LEAK: creation stack trace available in strict mode.'); |
- } |
- print(sb.toString()); |
+ static void removeOpenHandle(Object handleToken) { |
+ throw new UnsupportedError( |
+ "MojoHandleNatives.removeOpenHandle on contract"); |
} |
/// Prints a list of all open handles. |
@@ -82,11 +152,8 @@ class MojoHandleNatives { |
/// |
/// Programs should not have open handles when the program terminates. |
static bool reportOpenHandles() { |
- if (_openHandles.length == 0) { |
- return true; |
- } |
- _openHandles.forEach(_reportOpenHandle); |
- return false; |
+ throw new UnsupportedError( |
+ "MojoHandleNatives.reportOpenHandles on contract"); |
} |
/// Updates the description of the given [handleToken] in the set of open |
@@ -95,12 +162,8 @@ class MojoHandleNatives { |
/// The [handleToken] is a token that identifies the Mojo handle. |
/// |
/// Does nothing, if the [handleToken] isn't in the set. |
- static bool setDescription(int handleToken, String description) { |
- _OpenHandle openHandle = _openHandles[handleToken]; |
- if (openHandle != null) { |
- openHandle.description = description; |
- } |
- return true; |
+ static bool setDescription(Object handleToken, String description) { |
+ throw new UnsupportedError("MojoHandleNatives.setDescription on contract"); |
} |
/// Registers a finalizer on [eventSubscription] to close the given |
@@ -116,8 +179,10 @@ class MojoHandleNatives { |
/// The [handleToken] is a token that identifies the Mojo handle. |
/// Since the token can be an integer, it's not possible to install the |
/// finalizer directly on the token. |
- static int registerFinalizer(Object eventSubscription, int handleToken) |
- native "MojoHandle_RegisterFinalizer"; |
+ static int registerFinalizer(Object eventStream, Object handleToken) { |
+ throw new UnsupportedError( |
+ "MojoHandleNatives.registerFinalizer on contract"); |
+ } |
/// Closes the given [handleToken]. |
/// |
@@ -125,7 +190,9 @@ class MojoHandleNatives { |
/// class. In particular, a successful operation returns [MojoResult.kOk]. |
/// |
/// The [handleToken] is a token that identifies the Mojo handle. |
- static int close(int handleToken) native "MojoHandle_Close"; |
+ static int close(Object handleToken) { |
+ throw new UnsupportedError("MojoHandleNatives.close on contract"); |
+ } |
/// Waits on the given [handleToken] for a signal. |
/// |
@@ -152,8 +219,9 @@ class MojoHandleNatives { |
/// - It becomes known that no signal indicated by [signals] will ever be |
/// satisfied (for example the handle has been closed on the other side). |
/// - The [deadline] has passed. |
- static List wait(int handleToken, int signals, int deadline) |
- native "MojoHandle_Wait"; |
+ static List wait(Object handleToken, int signals, int deadline) { |
+ throw new UnsupportedError("MojoHandleNatives.woit on contract"); |
+ } |
/// Waits on many handles at the same time. |
/// |
@@ -168,32 +236,12 @@ class MojoHandleNatives { |
/// |
/// Behaves as if [wait] was called on each of the [handleTokens] separately, |
/// completing when the first would complete. |
- static List waitMany(List<int> handleTokens, List<int> signals, int deadline) |
- native "MojoHandle_WaitMany"; |
- |
- // Called from the embedder's unhandled exception callback. |
- // Returns the number of successfully closed handles. |
- static int _closeOpenHandles() { |
- int count = 0; |
- _openHandles.forEach((int handle, _) { |
- if (MojoHandleNatives.close(handle) == 0) { |
- count++; |
- } |
- }); |
- _openHandles.clear(); |
- return count; |
+ static List waitMany( |
+ List<Object> handleTokens, List<int> signals, int deadline) { |
+ throw new UnsupportedError("MojoHandleNatives.wainMany on contract"); |
} |
} |
-class _MojoHandleWatcherNatives { |
- static int sendControlData( |
- int controlHandle, |
- int commandCode, |
- int handleOrDeadline, |
- SendPort port, |
- int data) native "MojoHandleWatcher_SendControlData"; |
-} |
- |
class MojoMessagePipeNatives { |
/// Creates a message pipe represented by its two endpoints (handles). |
/// |
@@ -205,7 +253,10 @@ class MojoMessagePipeNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoMessagePipe.FLAG_NONE] (equal to 0). |
- static List MojoCreateMessagePipe(int flags) native "MojoMessagePipe_Create"; |
+ static List MojoCreateMessagePipe(int flags) { |
+ throw new UnsupportedError( |
+ "MojoMessagePipeNatives.MojoCreateMessagePipe on contract"); |
+ } |
/// Writes a message into the endpoint [handleToken]. |
/// |
@@ -219,8 +270,11 @@ class MojoMessagePipeNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoMessagePipeEndpoint.WRITE_FLAG_NONE] (equal to 0). |
- static int MojoWriteMessage(int handleToken, ByteData data, int numBytes, |
- List<int> handles, int flags) native "MojoMessagePipe_Write"; |
+ static int MojoWriteMessage(Object handleToken, ByteData data, int numBytes, |
+ List<Object> handleTokens, int flags) { |
+ throw new UnsupportedError( |
+ "MojoMessagePipeNatives.MojoWriteMessage on contract"); |
+ } |
/// Reads a message from the endpoint [handleToken]. |
/// |
@@ -259,8 +313,11 @@ class MojoMessagePipeNatives { |
/// [MojoMessagePipeEndpoint.READ_FLAG_MAY_DISCARD] (equal to 1). In the |
/// latter case messages that couldn't be read (for example, because the |
/// [data] or [handleTokens] wasn't big enough) are discarded. |
- static List MojoReadMessage(int handleToken, ByteData data, int numBytes, |
- List<int> handleTokens, int flags) native "MojoMessagePipe_Read"; |
+ static List MojoReadMessage(Object handleToken, ByteData data, int numBytes, |
+ List<Object> handleTokens, int flags) { |
+ throw new UnsupportedError( |
+ "MojoMessagePipeNatives.MojoReadMessage on contract"); |
+ } |
/// Reads a message from the endpoint [handleToken]. |
/// |
@@ -290,8 +347,11 @@ class MojoMessagePipeNatives { |
/// latter case messages that couldn't be read are discarded. |
/// |
/// Also see [MojoReadMessage]. |
- static void MojoQueryAndReadMessage(int handleToken, int flags, List result) |
- native "MojoMessagePipe_QueryAndRead"; |
+ static void MojoQueryAndReadMessage( |
+ Object handleToken, int flags, List result) { |
+ throw new UnsupportedError( |
+ "MojoMessagePipeNatives.MojoQueryAndReadMessage on contract"); |
+ } |
} |
class MojoDataPipeNatives { |
@@ -317,8 +377,11 @@ class MojoDataPipeNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoDataPipe.FLAG_NONE] (equal to 0). |
- static List MojoCreateDataPipe(int elementBytes, int capacityBytes, int flags) |
- native "MojoDataPipe_Create"; |
+ static List MojoCreateDataPipe( |
+ int elementBytes, int capacityBytes, int flags) { |
+ throw new UnsupportedError( |
+ "MojoDataPipeNatives.MojoCreateDataPipe on contract"); |
+ } |
/// Writes [numBytes] bytes from [data] into the producer handle. |
/// |
@@ -342,8 +405,10 @@ class MojoDataPipeNatives { |
/// If no data can currently be written to an open consumer (and [flags] is |
/// *not* set to [MojoDataPipeProducer.FLAG_ALL_OR_NONE]), then the |
/// result-integer is set to [MojoResult.kShouldWait]. |
- static List MojoWriteData(int handle, ByteData data, int numBytes, int flags) |
- native "MojoDataPipe_WriteData"; |
+ static List MojoWriteData( |
+ Object handleToken, ByteData data, int numBytes, int flags) { |
+ throw new UnsupportedError("MojoDataPipeNatives.MojoWriteData on contract"); |
+ } |
/// Starts a two-phase write. |
/// |
@@ -372,8 +437,10 @@ class MojoDataPipeNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoDataPipeProducer.FLAG_NONE] (equal to 0). |
- static List MojoBeginWriteData(int handleToken, int flags) |
- native "MojoDataPipe_BeginWriteData"; |
+ static List MojoBeginWriteData(Object handleToken, int flags) { |
+ throw new UnsupportedError( |
+ "MojoDataPipeNatives.MojoBeginWriteData on contract"); |
+ } |
/// Finishes a two-phase write. |
/// |
@@ -388,8 +455,10 @@ class MojoDataPipeNatives { |
/// [MojoBeginWriteData] into the pipe. The parameter [bytesWritten] must be |
/// less or equal to the size of the [ByteData] buffer and must be a multiple |
/// of the data pipe's element size. |
- static int MojoEndWriteData(int handleToken, int bytesWritten) |
- native "MojoDataPipe_EndWriteData"; |
+ static int MojoEndWriteData(Object handleToken, int bytesWritten) { |
+ throw new UnsupportedError( |
+ "MojoDataPipeNatives.MojoEndWriteData on contract"); |
+ } |
/// Reads up to [numBytes] from the given consumer [handleToken]. |
/// |
@@ -430,8 +499,10 @@ class MojoDataPipeNatives { |
/// this case, [MojoDataPipeConsumer.FLAG_DISCARD] must not be set, and |
/// [MojoDataPipeConsumer.FLAG_ALL_OR_NONE] is ignored, as are [data] and |
/// [numBytes]. |
- static List MojoReadData(int handleToken, ByteData data, int numBytes, |
- int flags) native "MojoDataPipe_ReadData"; |
+ static List MojoReadData( |
+ Object handleToken, ByteData data, int numBytes, int flags) { |
+ throw new UnsupportedError("MojoDataPipeNatives.MojoReadData on contract"); |
+ } |
/// Starts a two-phase read. |
/// |
@@ -463,8 +534,10 @@ class MojoDataPipeNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoDataPipeConsumer.FLAG_NONE] (equal to 0). |
- static List MojoBeginReadData(int handleToken, int flags) |
- native "MojoDataPipe_BeginReadData"; |
+ static List MojoBeginReadData(Object handleToken, int flags) { |
+ throw new UnsupportedError( |
+ "MojoDataPipeNatives.MojoBeginReadData on contract"); |
+ } |
/// Finishes a two-phase read. |
/// |
@@ -479,8 +552,10 @@ class MojoDataPipeNatives { |
/// [MojoBeginReadData]. The parameter [bytesWritten] must be |
/// less or equal to the size of the [ByteData] buffer and must be a multiple |
/// of the data pipe's element size. |
- static int MojoEndReadData(int handleToken, int bytesRead) |
- native "MojoDataPipe_EndReadData"; |
+ static int MojoEndReadData(Object handleToken, int bytesRead) { |
+ throw new UnsupportedError( |
+ "MojoDataPipeNatives.MojoEndReadData on contract"); |
+ } |
} |
class MojoSharedBufferNatives { |
@@ -498,7 +573,9 @@ class MojoSharedBufferNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoSharedBuffer.createFlagNone] (equal to 0). |
- static List Create(int numBytes, int flags) native "MojoSharedBuffer_Create"; |
+ static List Create(int numBytes, int flags) { |
+ throw new UnsupportedError("MojoSharedBufferNatives.Create on contract"); |
+ } |
/// Duplicates the given [bufferHandleToken] so that it can be shared through |
/// a message pipe. |
@@ -517,8 +594,9 @@ class MojoSharedBufferNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoSharedBuffer.duplicateFlagNone] (equal to 0). |
- static List Duplicate(int bufferHandleToken, int flags) |
- native "MojoSharedBuffer_Duplicate"; |
+ static List Duplicate(Object bufferHandleToken, int flags) { |
+ throw new UnsupportedError("MojoSharedBufferNatives.Duplicate on contract"); |
+ } |
/// Maps the given [bufferHandleToken] so that its data can be access through |
/// a [ByteData] buffer. |
@@ -538,9 +616,10 @@ class MojoSharedBufferNatives { |
/// |
/// The parameter [flags] is reserved for future use and should currently be |
/// set to [MojoSharedBuffer.mapFlagNone] (equal to 0). |
- static List Map(int bufferHandleToken, int offset, int numBytes, int flags) |
- native "MojoSharedBuffer_Map"; |
- |
+ static List Map( |
+ Object bufferHandleToken, int offset, int numBytes, int flags) { |
+ throw new UnsupportedError("MojoSharedBufferNatives.Map on contract"); |
+ } |
/// Returns information about [bufferHandleToken]. |
/// |
@@ -551,6 +630,8 @@ class MojoSharedBufferNatives { |
/// 3. The size of the buffer (in bytes). |
/// |
/// The [bufferHandleToken] must be a handle created by [Create]. |
- static List GetInformation(int bufferHandleToken) |
- native "MojoSharedBuffer_GetInformation"; |
+ static List GetInformation(Object bufferHandleToken) { |
+ throw new UnsupportedError( |
+ "MojoSharedBufferNatives.GetInformation on contract"); |
+ } |
} |