executeRemoteFunctionRequest method

DataPackage executeRemoteFunctionRequest(
  1. DataPackage rpcRequest
)

Implementation

DataPackage executeRemoteFunctionRequest(DataPackage rpcRequest)
{
  RemoteFunctionRunnableResult<T> status;

  RemoteFunctionRequest executionRequest =
      rpcRequest.controlVal.remoteFunctionRequest;

  RemoteFunctionIdentifier remoteFunctionIdentifier =
      executionRequest.remoteFunctionIdentifier;

  int payloadsSize = executionRequest.parameterPayloads.length;

  if (payloadsSize != this._parameterTypes.length)
  {
    Logger.logError(
        'Failed to execute RemoteFunctionRunnable "${getFunctionSignature(remoteFunctionIdentifier, executionRequest)}". Number of parameters do not match. Function expected ${this._parameterTypes.length} parameters, but was executed with $payloadsSize');

    status = RemoteFunctionRunnableResult.makeFailedResult(
        RemoteFunctionStatus.FAILED_INVALID_NUMBER_OF_PARAMETERS);
    return makeRPCResponsePackage(status, rpcRequest);
  }

  List<dynamic> parameters = [];
  for (int i = 0; i < payloadsSize; i++) {
    Mutator mutator = TypeMapping().getMutator(this._parameterTypes[i]);

    DataPackage tmpPackage = DataPackage();
    tmpPackage.payload = executionRequest.parameterPayloads[i];


    dynamic data = mutator.getter(tmpPackage);
    parameters.add(data);

    if (parameters[i].runtimeType != this._parameterTypes[i].runtimeType)
    {
      Logger.logError(
          'Failed to execute RemoteFunctionRunnable "${getFunctionSignature(remoteFunctionIdentifier, executionRequest)}". Parameter object $i is of type "${parameters[i].runtimeType}", but expected type "${this._parameterTypes[i]}".');
      status = RemoteFunctionRunnableResult.makeFailedResult(
          RemoteFunctionStatus.FAILED_MISMATCHING_PARAMETERS);
      return makeRPCResponsePackage(status, rpcRequest);
    }
  }

  status = executeFunction(parameters);

  return makeRPCResponsePackage(status, rpcRequest);
}