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

Unified Diff: mojo/dart/packages/mojo_services/lib/nfc/nfc.mojom.dart

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Move code from mojo_patch to proxy.dart Created 4 years, 7 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
Index: mojo/dart/packages/mojo_services/lib/nfc/nfc.mojom.dart
diff --git a/mojo/dart/packages/mojo_services/lib/nfc/nfc.mojom.dart b/mojo/dart/packages/mojo_services/lib/nfc/nfc.mojom.dart
index 7abd0e3c7dd477efe808e9b96a36a9b542ae0d52..de7c28b8f49c58e77a65e498502220786f6d2029 100644
--- a/mojo/dart/packages/mojo_services/lib/nfc/nfc.mojom.dart
+++ b/mojo/dart/packages/mojo_services/lib/nfc/nfc.mojom.dart
@@ -18,6 +18,10 @@ class NfcData extends bindings.Struct {
NfcData() : super(kVersions.last.size);
+ NfcData.init(
+ List<int> this.data
+ ) : super(kVersions.last.size);
+
static NfcData deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
@@ -89,6 +93,9 @@ class _NfcTransmissionCancelParams extends bindings.Struct {
_NfcTransmissionCancelParams() : super(kVersions.last.size);
+ _NfcTransmissionCancelParams.init(
+ ) : super(kVersions.last.size);
+
static _NfcTransmissionCancelParams deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
@@ -148,6 +155,10 @@ class _NfcReceiverOnReceivedNfcDataParams extends bindings.Struct {
_NfcReceiverOnReceivedNfcDataParams() : super(kVersions.last.size);
+ _NfcReceiverOnReceivedNfcDataParams.init(
+ NfcData this.nfcData
+ ) : super(kVersions.last.size);
+
static _NfcReceiverOnReceivedNfcDataParams deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
@@ -222,6 +233,11 @@ class _NfcTransmitOnNextConnectionParams extends bindings.Struct {
_NfcTransmitOnNextConnectionParams() : super(kVersions.last.size);
+ _NfcTransmitOnNextConnectionParams.init(
+ NfcData this.nfcData,
+ NfcTransmissionInterfaceRequest this.transmission
+ ) : super(kVersions.last.size);
+
static _NfcTransmitOnNextConnectionParams deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
@@ -306,6 +322,10 @@ class NfcTransmitOnNextConnectionResponseParams extends bindings.Struct {
NfcTransmitOnNextConnectionResponseParams() : super(kVersions.last.size);
+ NfcTransmitOnNextConnectionResponseParams.init(
+ bool this.success
+ ) : super(kVersions.last.size);
+
static NfcTransmitOnNextConnectionResponseParams deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
@@ -377,6 +397,9 @@ class _NfcRegisterParams extends bindings.Struct {
_NfcRegisterParams() : super(kVersions.last.size);
+ _NfcRegisterParams.init(
+ ) : super(kVersions.last.size);
+
static _NfcRegisterParams deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
@@ -435,6 +458,9 @@ class _NfcUnregisterParams extends bindings.Struct {
_NfcUnregisterParams() : super(kVersions.last.size);
+ _NfcUnregisterParams.init(
+ ) : super(kVersions.last.size);
+
static _NfcUnregisterParams deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
@@ -488,14 +514,17 @@ class _NfcUnregisterParams extends bindings.Struct {
const int _nfcTransmissionMethodCancelName = 0;
class _NfcTransmissionServiceDescription implements service_describer.ServiceDescription {
- dynamic getTopLevelInterface([Function responseFactory]) =>
- responseFactory(null);
+ void getTopLevelInterface(Function responder) {
+ responder(null);
+ }
- dynamic getTypeDefinition(String typeKey, [Function responseFactory]) =>
- responseFactory(null);
+ void getTypeDefinition(String typeKey, Function responder) {
+ responder(null);
+ }
- dynamic getAllTypeDefinitions([Function responseFactory]) =>
- responseFactory(null);
+ void getAllTypeDefinitions(Function responder) {
+ responder(null);
+ }
}
abstract class NfcTransmission {
@@ -631,11 +660,11 @@ class _NfcTransmissionStubControl
- dynamic handleMessage(bindings.ServiceMessage message) {
+ void handleMessage(bindings.ServiceMessage message) {
if (bindings.ControlMessageHandler.isControlMessage(message)) {
- return bindings.ControlMessageHandler.handleMessage(this,
- 0,
- message);
+ bindings.ControlMessageHandler.handleMessage(
+ this, 0, message);
+ return;
}
if (_impl == null) {
throw new core.MojoApiError("$this has no implementation set");
@@ -648,7 +677,6 @@ class _NfcTransmissionStubControl
throw new bindings.MojoCodecError("Unexpected message name");
break;
}
- return null;
}
NfcTransmission get impl => _impl;
@@ -710,14 +738,17 @@ class NfcTransmissionStub
const int _nfcReceiverMethodOnReceivedNfcDataName = 0;
class _NfcReceiverServiceDescription implements service_describer.ServiceDescription {
- dynamic getTopLevelInterface([Function responseFactory]) =>
- responseFactory(null);
+ void getTopLevelInterface(Function responder) {
+ responder(null);
+ }
- dynamic getTypeDefinition(String typeKey, [Function responseFactory]) =>
- responseFactory(null);
+ void getTypeDefinition(String typeKey, Function responder) {
+ responder(null);
+ }
- dynamic getAllTypeDefinitions([Function responseFactory]) =>
- responseFactory(null);
+ void getAllTypeDefinitions(Function responder) {
+ responder(null);
+ }
}
abstract class NfcReceiver {
@@ -854,11 +885,11 @@ class _NfcReceiverStubControl
- dynamic handleMessage(bindings.ServiceMessage message) {
+ void handleMessage(bindings.ServiceMessage message) {
if (bindings.ControlMessageHandler.isControlMessage(message)) {
- return bindings.ControlMessageHandler.handleMessage(this,
- 0,
- message);
+ bindings.ControlMessageHandler.handleMessage(
+ this, 0, message);
+ return;
}
if (_impl == null) {
throw new core.MojoApiError("$this has no implementation set");
@@ -873,7 +904,6 @@ class _NfcReceiverStubControl
throw new bindings.MojoCodecError("Unexpected message name");
break;
}
- return null;
}
NfcReceiver get impl => _impl;
@@ -937,14 +967,17 @@ const int _nfcMethodRegisterName = 1;
const int _nfcMethodUnregisterName = 2;
class _NfcServiceDescription implements service_describer.ServiceDescription {
- dynamic getTopLevelInterface([Function responseFactory]) =>
- responseFactory(null);
+ void getTopLevelInterface(Function responder) {
+ responder(null);
+ }
- dynamic getTypeDefinition(String typeKey, [Function responseFactory]) =>
- responseFactory(null);
+ void getTypeDefinition(String typeKey, Function responder) {
+ responder(null);
+ }
- dynamic getAllTypeDefinitions([Function responseFactory]) =>
- responseFactory(null);
+ void getAllTypeDefinitions(Function responder) {
+ responder(null);
+ }
}
abstract class Nfc {
@@ -969,7 +1002,7 @@ abstract class Nfc {
s.connectToService(url, p, name);
return p;
}
- dynamic transmitOnNextConnection(NfcData nfcData,NfcTransmissionInterfaceRequest transmission,[Function responseFactory = null]);
+ void transmitOnNextConnection(NfcData nfcData,NfcTransmissionInterfaceRequest transmission,void callback(bool success));
void register();
void unregister();
}
@@ -1014,18 +1047,14 @@ class _NfcProxyControl
proxyError("Expected a message with a valid request Id.");
return;
}
- Completer c = completerMap[message.header.requestId];
- if (c == null) {
+ Function callback = callbackMap[message.header.requestId];
+ if (callback == null) {
proxyError(
"Message had unknown request Id: ${message.header.requestId}");
return;
}
- completerMap.remove(message.header.requestId);
- if (c.isCompleted) {
- proxyError("Response completer already completed");
- return;
- }
- c.complete(r);
+ callbackMap.remove(message.header.requestId);
+ callback(r.success );
break;
default:
proxyError("Unexpected message type: ${message.header.type}");
@@ -1068,15 +1097,16 @@ class NfcProxy
}
- dynamic transmitOnNextConnection(NfcData nfcData,NfcTransmissionInterfaceRequest transmission,[Function responseFactory = null]) {
+ void transmitOnNextConnection(NfcData nfcData,NfcTransmissionInterfaceRequest transmission,void callback(bool success)) {
var params = new _NfcTransmitOnNextConnectionParams();
params.nfcData = nfcData;
params.transmission = transmission;
- return ctrl.sendMessageWithRequestId(
+ ctrl.sendMessageWithRequestId(
params,
_nfcMethodTransmitOnNextConnectionName,
-1,
- bindings.MessageHeader.kMessageExpectsResponse);
+ bindings.MessageHeader.kMessageExpectsResponse,
+ callback);
}
void register() {
if (!ctrl.isBound) {
@@ -1120,17 +1150,24 @@ class _NfcStubControl
String get serviceName => Nfc.serviceName;
- NfcTransmitOnNextConnectionResponseParams _nfcTransmitOnNextConnectionResponseParamsFactory(bool success) {
- var result = new NfcTransmitOnNextConnectionResponseParams();
- result.success = success;
- return result;
+ Function _nfcTransmitOnNextConnectionResponseParamsResponder(
+ int requestId) {
+ return (bool success) {
+ var result = new NfcTransmitOnNextConnectionResponseParams();
+ result.success = success;
+ sendResponse(buildResponseWithId(
+ result,
+ _nfcMethodTransmitOnNextConnectionName,
+ requestId,
+ bindings.MessageHeader.kMessageIsResponse));
+ };
}
- dynamic handleMessage(bindings.ServiceMessage message) {
+ void handleMessage(bindings.ServiceMessage message) {
if (bindings.ControlMessageHandler.isControlMessage(message)) {
- return bindings.ControlMessageHandler.handleMessage(this,
- 0,
- message);
+ bindings.ControlMessageHandler.handleMessage(
+ this, 0, message);
+ return;
}
if (_impl == null) {
throw new core.MojoApiError("$this has no implementation set");
@@ -1139,24 +1176,7 @@ class _NfcStubControl
case _nfcMethodTransmitOnNextConnectionName:
var params = _NfcTransmitOnNextConnectionParams.deserialize(
message.payload);
- var response = _impl.transmitOnNextConnection(params.nfcData,params.transmission,_nfcTransmitOnNextConnectionResponseParamsFactory);
- if (response is Future) {
- return response.then((response) {
- if (response != null) {
- return buildResponseWithId(
- response,
- _nfcMethodTransmitOnNextConnectionName,
- message.header.requestId,
- bindings.MessageHeader.kMessageIsResponse);
- }
- });
- } else if (response != null) {
- return buildResponseWithId(
- response,
- _nfcMethodTransmitOnNextConnectionName,
- message.header.requestId,
- bindings.MessageHeader.kMessageIsResponse);
- }
+ _impl.transmitOnNextConnection(params.nfcData, params.transmission, _nfcTransmitOnNextConnectionResponseParamsResponder(message.header.requestId));
break;
case _nfcMethodRegisterName:
_impl.register();
@@ -1168,7 +1188,6 @@ class _NfcStubControl
throw new bindings.MojoCodecError("Unexpected message name");
break;
}
- return null;
}
Nfc get impl => _impl;
@@ -1222,8 +1241,8 @@ class NfcStub
}
- dynamic transmitOnNextConnection(NfcData nfcData,NfcTransmissionInterfaceRequest transmission,[Function responseFactory = null]) {
- return impl.transmitOnNextConnection(nfcData,transmission,responseFactory);
+ void transmitOnNextConnection(NfcData nfcData,NfcTransmissionInterfaceRequest transmission,void callback(bool success)) {
+ return impl.transmitOnNextConnection(nfcData,transmission,callback);
}
void register() {
return impl.register();

Powered by Google App Engine
This is Rietveld 408576698