All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joynr.generator.cpp.provider.InterfaceRequestInterpreterCppTemplate Maven / Gradle / Ivy

package io.joynr.generator.cpp.provider;

import com.google.inject.Inject;
import io.joynr.generator.cpp.util.CppStdTypeUtil;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import io.joynr.generator.templates.InterfaceTemplate;
import io.joynr.generator.templates.util.AttributeUtil;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.MethodUtil;
import io.joynr.generator.templates.util.NamingUtil;
import java.util.Set;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FArgument;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FMethod;
import org.franca.core.franca.FTypeRef;

@SuppressWarnings("all")
public class InterfaceRequestInterpreterCppTemplate extends InterfaceTemplate {
  @Inject
  @Extension
  private TemplateBase _templateBase;

  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;

  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;

  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private AttributeUtil _attributeUtil;

  @Inject
  @Extension
  private MethodUtil _methodUtil;

  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;

  @Override
  public CharSequence generate(final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
    _builder.newLineIfNotEmpty();
    CharSequence _warning = this._templateBase.warning();
    _builder.append(_warning);
    _builder.newLineIfNotEmpty();
    _builder.append("#include ");
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "/", generateVersion);
    _builder.append(_packagePathWithJoynrPrefix);
    _builder.append("/");
    _builder.append(interfaceName);
    _builder.append("RequestInterpreter.h\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "/", generateVersion);
    _builder.append(_packagePathWithJoynrPrefix_1);
    _builder.append("/");
    _builder.append(interfaceName);
    _builder.append("RequestCaller.h\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"joynr/Util.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/Request.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/OneWayRequest.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/BaseReply.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/exceptions/JoynrException.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/exceptions/MethodInvocationException.h\"");
    _builder.newLine();
    _builder.newLine();
    {
      Set _dataTypeIncludesFor = this._cppStdTypeUtil.getDataTypeIncludesFor(this.francaIntf, generateVersion);
      for(final String parameterType : _dataTypeIncludesFor) {
        _builder.append("#include ");
        _builder.append(parameterType);
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.francaIntf, generateVersion);
    _builder.append(_namespaceStarter);
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _firstLower = StringExtensions.toFirstLower(interfaceName);
    final String requestCallerName = (_firstLower + "RequestCallerVar");
    _builder.newLineIfNotEmpty();
    final EList attributes = this._interfaceUtil.getAttributes(this.francaIntf);
    _builder.newLineIfNotEmpty();
    final Function1 _function = new Function1() {
      @Override
      public Boolean apply(final FMethod it) {
        boolean _isFireAndForget = it.isFireAndForget();
        return Boolean.valueOf((!_isFireAndForget));
      }
    };
    final Iterable methodsWithoutFireAndForget = IterableExtensions.filter(this._interfaceUtil.getMethods(this.francaIntf), _function);
    _builder.newLineIfNotEmpty();
    _builder.append("void ");
    _builder.append(interfaceName);
    _builder.append("RequestInterpreter::execute(");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("std::shared_ptr requestCaller,");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("Request& request,");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("std::function&& onSuccess,");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("std::function& exception)>&& onError");
    _builder.newLine();
    _builder.append(") {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("assert(requestCaller);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("if (!requestCaller) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("JOYNR_LOG_FATAL(logger(), \"{}: requestCaller is nullptr, aborting\", \"");
    _builder.append(interfaceName, "\t\t");
    _builder.append("RequestInterpreter::execute(...)\");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("return;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("assert(onSuccess);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("if (!onSuccess) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("JOYNR_LOG_FATAL(logger(), \"{}: onSuccess is nullptr, aborting\", \"");
    _builder.append(interfaceName, "\t\t");
    _builder.append("RequestInterpreter::execute(...)\");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("return;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("assert(onError);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("if (!onError) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("JOYNR_LOG_FATAL(logger(), \"{}: onError is nullptr, aborting\", \"");
    _builder.append(interfaceName, "\t\t");
    _builder.append("RequestInterpreter::execute(...)\");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("return;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    {
      if (((this._interfaceUtil.hasReadAttribute(this.francaIntf) || this._interfaceUtil.hasWriteAttribute(this.francaIntf)) || (!IterableExtensions.isEmpty(methodsWithoutFireAndForget)))) {
        _builder.append("\t");
        _builder.append("// cast generic RequestCaller to ");
        _builder.append(interfaceName, "\t");
        _builder.append("Requestcaller");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("std::shared_ptr<");
        _builder.append(interfaceName, "\t");
        _builder.append("RequestCaller> ");
        _builder.append(requestCallerName, "\t");
        _builder.append(" =");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t\t");
        _builder.append("std::dynamic_pointer_cast<");
        _builder.append(interfaceName, "\t\t\t");
        _builder.append("RequestCaller>(requestCaller);");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("const std::vector& paramTypes = request.getParamDatatypes();");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("const std::string& methodName = request.getMethodName();");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("// execute operation");
        _builder.newLine();
        {
          boolean _isEmpty = attributes.isEmpty();
          boolean _not = (!_isEmpty);
          if (_not) {
            {
              for(final FAttribute attribute : attributes) {
                _builder.append("\t");
                _builder.append("\t");
                final String attributeName = this._namingUtil.joynrName(attribute);
                _builder.newLineIfNotEmpty();
                {
                  boolean _isReadable = this._attributeUtil.isReadable(attribute);
                  if (_isReadable) {
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("if (methodName == \"get");
                    String _firstUpper = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper, "\t\t");
                    _builder.append("\" && paramTypes.size() == 0){");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("try {");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("auto requestCallerOnSuccess =");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("[onSuccess = std::move(onSuccess)](");
                    String _typeName = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
                    _builder.append(_typeName, "\t\t\t\t\t\t");
                    _builder.append(" ");
                    _builder.append(attributeName, "\t\t\t\t\t\t");
                    _builder.append("){");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t");
                    _builder.append("BaseReply reply;");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t");
                    _builder.append("reply.setResponse(std::move(");
                    _builder.append(attributeName, "\t\t\t\t\t\t\t");
                    _builder.append("));");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t");
                    _builder.append("onSuccess(std::move(reply));");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("};");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append(requestCallerName, "\t\t\t\t");
                    _builder.append("->get");
                    String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_1, "\t\t\t\t");
                    _builder.append("(");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
                    _builder.append("std::move(requestCallerOnSuccess),");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
                    _builder.append("onError);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("} catch (const std::exception& exception) {");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("const std::string errorMessage = \"Unexpected exception occurred in attribute getter get");
                    String _firstUpper_2 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_2, "\t\t\t\t");
                    _builder.append(" (): \" + std::string(exception.what());");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("JOYNR_LOG_ERROR(logger(), errorMessage);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("onError(");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t");
                    _builder.append("std::make_shared(");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("errorMessage,");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("requestCaller->getProviderVersion()));");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return;");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                  }
                }
                {
                  boolean _isWritable = this._attributeUtil.isWritable(attribute);
                  if (_isWritable) {
                    _builder.append("\t");
                    _builder.append("if (methodName == \"set");
                    String _firstUpper_3 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_3, "\t");
                    _builder.append("\" && paramTypes.size() == 1){");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("try {");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    String _typeName_1 = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
                    _builder.append(_typeName_1, "\t\t\t");
                    _builder.append(" typedInput");
                    String _firstUpper_4 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_4, "\t\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("request.getParams(typedInput");
                    String _firstUpper_5 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_5, "\t\t\t");
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("auto requestCallerOnSuccess =");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("[onSuccess = std::move(onSuccess)] () {");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t");
                    _builder.append("BaseReply reply;");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t");
                    _builder.append("reply.setResponse();");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t");
                    _builder.append("onSuccess(std::move(reply));");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("};");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append(requestCallerName, "\t\t\t");
                    _builder.append("->set");
                    String _firstUpper_6 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_6, "\t\t\t");
                    _builder.append("(");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
                    _builder.append("typedInput");
                    String _firstUpper_7 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_7, "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
                    _builder.append(",");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
                    _builder.append("std::move(requestCallerOnSuccess),");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
                    _builder.append("onError);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("} catch (const std::exception& exception) {");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("const std::string errorMessage = \"Unexpected exception occurred in attribute setter set");
                    String _firstUpper_8 = StringExtensions.toFirstUpper(attributeName);
                    _builder.append(_firstUpper_8, "\t\t\t");
                    _builder.append(" (");
                    String _joynrTypeName = this._joynrCppGeneratorExtensions.getJoynrTypeName(attribute, generateVersion);
                    _builder.append(_joynrTypeName, "\t\t\t");
                    _builder.append("): \" + std::string(exception.what());");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("JOYNR_LOG_ERROR(logger(), errorMessage);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("onError(");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t");
                    _builder.append("std::make_shared(");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("errorMessage,");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("requestCaller->getProviderVersion()));");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return;");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                  }
                }
              }
            }
          }
        }
        {
          for(final FMethod method : methodsWithoutFireAndForget) {
            _builder.append("\t");
            final String inputUntypedParamList = this._cppStdTypeUtil.getCommaSeperatedUntypedInputParameterList(method);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            final String methodName = this._namingUtil.joynrName(method);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            final Iterable inputParams = this._methodUtil.getInputParameters(method);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            int iterator = (-1);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("if (methodName == \"");
            _builder.append(methodName, "\t");
            _builder.append("\" && paramTypes.size() == ");
            int _size = IterableExtensions.size(inputParams);
            _builder.append(_size, "\t");
            _builder.newLineIfNotEmpty();
            {
              for(final FArgument input : inputParams) {
                _builder.append("\t");
                _builder.append("\t");
                _builder.append("&& paramTypes.at(");
                _builder.append(iterator = (iterator + 1), "\t\t");
                _builder.append(") == \"");
                String _joynrTypeName_1 = this._joynrCppGeneratorExtensions.getJoynrTypeName(input, generateVersion);
                _builder.append(_joynrTypeName_1, "\t\t");
                _builder.append("\"");
                _builder.newLineIfNotEmpty();
              }
            }
            _builder.append("\t");
            _builder.append(") {");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            final String outputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstOutputParameterList(method, generateVersion);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("auto requestCallerOnSuccess =");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t\t");
            _builder.append("[onSuccess = std::move(onSuccess)](");
            _builder.append(outputTypedParamList, "\t\t\t\t");
            _builder.append("){");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("BaseReply reply;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("reply.setResponse(");
            _builder.newLine();
            {
              Iterable _outputParameters = this._methodUtil.getOutputParameters(method);
              boolean _hasElements = false;
              for(final FArgument param : _outputParameters) {
                if (!_hasElements) {
                  _hasElements = true;
                } else {
                  _builder.appendImmediate(",", "\t\t\t\t\t");
                }
                _builder.append("\t");
                _builder.append("\t\t\t\t");
                String _joynrName = this._namingUtil.joynrName(param);
                _builder.append(_joynrName, "\t\t\t\t\t");
                _builder.newLineIfNotEmpty();
              }
            }
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append(");");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("onSuccess(std::move(reply));");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t\t");
            _builder.append("};");
            _builder.newLine();
            _builder.newLine();
            {
              for(final FArgument input_1 : inputParams) {
                _builder.append("\t");
                _builder.append("\t");
                final String inputName = this._namingUtil.joynrName(input_1);
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("\t");
                final FTypeRef inputType = this._cppStdTypeUtil.resolveTypeDef(input_1.getType());
                _builder.newLineIfNotEmpty();
                {
                  boolean _isArray = input_1.isArray();
                  if (_isArray) {
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("std::vector<");
                    String _typeName_2 = this._cppStdTypeUtil.getTypeName(inputType, generateVersion);
                    _builder.append(_typeName_2, "\t\t");
                    _builder.append("> ");
                    _builder.append(inputName, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                  } else {
                    _builder.append("\t");
                    _builder.append("\t");
                    String _typeName_3 = this._cppStdTypeUtil.getTypeName(inputType, generateVersion);
                    _builder.append(_typeName_3, "\t\t");
                    _builder.append(" ");
                    _builder.append(inputName, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                  }
                }
              }
            }
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("try {");
            _builder.newLine();
            {
              boolean _isEmpty_1 = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method));
              boolean _not_1 = (!_isEmpty_1);
              if (_not_1) {
                _builder.append("\t");
                _builder.append("\t\t");
                _builder.append("request.getParams(");
                _builder.append(inputUntypedParamList, "\t\t\t");
                _builder.append(");");
                _builder.newLineIfNotEmpty();
              }
            }
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append(requestCallerName, "\t\t\t");
            _builder.append("->");
            _builder.append(methodName, "\t\t\t");
            _builder.append("(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            {
              boolean _isEmpty_2 = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method));
              boolean _not_2 = (!_isEmpty_2);
              if (_not_2) {
                _builder.append(inputUntypedParamList, "\t\t\t\t\t");
                _builder.append(",");
              }
            }
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("std::move(requestCallerOnSuccess),");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("onError);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("} catch (const std::exception& exception) {");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("const std::string errorMessage = \"Unexpected exception occurred in method ");
            _builder.append(methodName, "\t\t\t");
            _builder.append(" (...): \" + std::string(exception.what());");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("JOYNR_LOG_ERROR(logger(), errorMessage);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("onError(std::make_shared(errorMessage, requestCaller->getProviderVersion()));");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("return;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
          }
        }
      } else {
        _builder.append("\t");
        _builder.append("std::ignore = requestCaller;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("std::ignore = onSuccess;");
        _builder.newLine();
      }
    }
    _builder.newLine();
    _builder.append("\t");
    _builder.append("JOYNR_LOG_WARN(logger(), \"unknown method name for interface ");
    _builder.append(interfaceName, "\t");
    _builder.append(": {}\", request.getMethodName());");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("onError(");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("std::make_shared(");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("\"unknown method name for interface ");
    _builder.append(interfaceName, "\t\t\t");
    _builder.append(": \" + request.getMethodName(),");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("requestCaller->getProviderVersion()));");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("void ");
    _builder.append(interfaceName);
    _builder.append("RequestInterpreter::execute(");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("std::shared_ptr requestCaller,");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("OneWayRequest& request");
    _builder.newLine();
    _builder.append(") {");
    _builder.newLine();
    _builder.append("\t");
    final Function1 _function_1 = new Function1() {
      @Override
      public Boolean apply(final FMethod it) {
        return Boolean.valueOf(it.isFireAndForget());
      }
    };
    final Iterable fireAndForgetMethods = IterableExtensions.filter(this._interfaceUtil.getMethods(this.francaIntf), _function_1);
    _builder.newLineIfNotEmpty();
    {
      boolean _isEmpty_3 = IterableExtensions.isEmpty(fireAndForgetMethods);
      if (_isEmpty_3) {
        _builder.append("\t");
        _builder.append("std::ignore = requestCaller;");
        _builder.newLine();
      } else {
        _builder.append("\t");
        _builder.append("const std::vector& paramTypes = request.getParamDatatypes();");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("const std::string& methodName = request.getMethodName();");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("// cast generic RequestCaller to ");
        _builder.append(interfaceName, "\t");
        _builder.append("Requestcaller");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("std::shared_ptr<");
        _builder.append(interfaceName, "\t");
        _builder.append("RequestCaller> ");
        _builder.append(requestCallerName, "\t");
        _builder.append(" =");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t\t");
        _builder.append("std::dynamic_pointer_cast<");
        _builder.append(interfaceName, "\t\t\t");
        _builder.append("RequestCaller>(requestCaller);");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("// execute operation");
        _builder.newLine();
        {
          for(final FMethod method_1 : fireAndForgetMethods) {
            _builder.append("\t");
            final String inputUntypedParamList_1 = this._cppStdTypeUtil.getCommaSeperatedUntypedInputParameterList(method_1);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            final String methodName_1 = this._namingUtil.joynrName(method_1);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            final Iterable inputParams_1 = this._methodUtil.getInputParameters(method_1);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            int iterator_1 = (-1);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("if (methodName == \"");
            _builder.append(methodName_1, "\t");
            _builder.append("\" && paramTypes.size() == ");
            int _size_1 = IterableExtensions.size(inputParams_1);
            _builder.append(_size_1, "\t");
            _builder.newLineIfNotEmpty();
            {
              for(final FArgument input_2 : inputParams_1) {
                _builder.append("\t");
                _builder.append("\t");
                _builder.append("&& paramTypes.at(");
                _builder.append(iterator_1 = (iterator_1 + 1), "\t\t");
                _builder.append(") == \"");
                String _joynrTypeName_2 = this._joynrCppGeneratorExtensions.getJoynrTypeName(input_2, generateVersion);
                _builder.append(_joynrTypeName_2, "\t\t");
                _builder.append("\"");
                _builder.newLineIfNotEmpty();
              }
            }
            _builder.append("\t");
            _builder.append("){");
            _builder.newLine();
            {
              for(final FArgument input_3 : inputParams_1) {
                _builder.append("\t");
                _builder.append("\t");
                final String inputName_1 = this._namingUtil.joynrName(input_3);
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("\t");
                final FTypeRef inputType_1 = this._cppStdTypeUtil.resolveTypeDef(input_3.getType());
                _builder.newLineIfNotEmpty();
                {
                  boolean _isArray_1 = input_3.isArray();
                  if (_isArray_1) {
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("std::vector<");
                    String _typeName_4 = this._cppStdTypeUtil.getTypeName(inputType_1, generateVersion);
                    _builder.append(_typeName_4, "\t\t");
                    _builder.append("> ");
                    _builder.append(inputName_1, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                  } else {
                    _builder.append("\t");
                    _builder.append("\t");
                    String _typeName_5 = this._cppStdTypeUtil.getTypeName(inputType_1, generateVersion);
                    _builder.append(_typeName_5, "\t\t");
                    _builder.append(" ");
                    _builder.append(inputName_1, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                  }
                }
              }
            }
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("try {");
            _builder.newLine();
            {
              boolean _isEmpty_4 = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method_1));
              boolean _not_3 = (!_isEmpty_4);
              if (_not_3) {
                _builder.append("\t");
                _builder.append("\t\t");
                _builder.append("request.getParams(");
                _builder.append(inputUntypedParamList_1, "\t\t\t");
                _builder.append(");");
                _builder.newLineIfNotEmpty();
              }
            }
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append(requestCallerName, "\t\t\t");
            _builder.append("->");
            _builder.append(methodName_1, "\t\t\t");
            _builder.append("(");
            {
              boolean _isEmpty_5 = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method_1));
              boolean _not_4 = (!_isEmpty_5);
              if (_not_4) {
                _builder.append(inputUntypedParamList_1, "\t\t\t");
              }
            }
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("} catch (const std::exception& exception) {");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("const std::string errorMessage = \"Unexpected exception occurred in method ");
            _builder.append(methodName_1, "\t\t\t");
            _builder.append(" (...): \" + std::string(exception.what());");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("JOYNR_LOG_ERROR(logger(), errorMessage);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("return;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
          }
        }
      }
    }
    _builder.newLine();
    _builder.append("\t");
    _builder.append("JOYNR_LOG_WARN(logger(), \"unknown method name for interface ");
    _builder.append(interfaceName, "\t");
    _builder.append(": {}\", request.getMethodName());");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(this.francaIntf, generateVersion);
    _builder.append(_namespaceEnder);
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy