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

io.joynr.generator.cpp.util.CppInterfaceUtil Maven / Gradle / Ivy

package io.joynr.generator.cpp.util;

import com.google.inject.Inject;
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.HashMap;
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.FEnumerationType;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;

@SuppressWarnings("all")
public class CppInterfaceUtil extends InterfaceUtil {
  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;

  @Inject
  @Extension
  private AttributeUtil _attributeUtil;

  @Inject
  @Extension
  private MethodUtil _methodUtil;

  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;

  public CharSequence printFutureReturnDefinition() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("* @returns A future representing the result of the asynchronous method call. It provides methods");
    _builder.newLine();
    _builder.append("* to wait for completion, to get the result or the request status object.");
    _builder.newLine();
    return _builder;
  }

  public CharSequence printOnSuccessFctParamDefinition() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("* @param onSuccess A callback function to be called once the asynchronous computation has");
    _builder.newLine();
    _builder.append("* finished successfully. It must expect the method out parameters.");
    _builder.newLine();
    return _builder;
  }

  public CharSequence printOnRuntimeErrorFctParamDefinition() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("* @param onRuntimeError A callback function to be called once the asynchronous computation has");
    _builder.newLine();
    _builder.append("* failed with an unexpected non-modeled exception. It must expect a JoynrRuntimeException object.");
    _builder.newLine();
    return _builder;
  }

  public CharSequence printOnApplicationErrorFctParamDefinition() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("* @param onApplicationError A callback function to be called once the asynchronous computation has");
    _builder.newLine();
    _builder.append("* failed with an unexpected modeled exception. It must expect an Error enum as modeled in Franca.");
    _builder.newLine();
    return _builder;
  }

  public CharSequence printMessagingQosParamDefinition() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("* @param qos optional MessagingQos parameter; if specified, this will overwrite the MessagingQos that");
    _builder.newLine();
    _builder.append("* was specified when building the proxy.");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceSyncGetterSignature(final FAttribute attribute, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String returnType = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
    _builder.newLineIfNotEmpty();
    final String attributeName = this._namingUtil.joynrName(attribute);
    _builder.newLineIfNotEmpty();
    _builder.append("void ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("get");
    String _firstUpper = StringExtensions.toFirstUpper(attributeName);
    _builder.append(_firstUpper);
    _builder.append("(");
    _builder.append(returnType);
    _builder.append("& ");
    _builder.append(attributeName);
    _builder.append(", boost::optional qos");
    {
      if ((className == null)) {
        _builder.append(" = boost::none");
      }
    }
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  public CharSequence produceSyncGetterSignature(final FAttribute attribute, final boolean generateVersion) {
    return this.produceSyncGetterSignature(attribute, null, generateVersion);
  }

  public CharSequence produceSyncGetterDeclarations(final FInterface serviceInterface, final boolean pure, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FAttribute attribute) {
          return Boolean.valueOf(CppInterfaceUtil.this._attributeUtil.isReadable(attribute));
        }
      };
      Iterable _filter = IterableExtensions.filter(this.getAttributes(serviceInterface), _function);
      for(final FAttribute attribute : _filter) {
        final String attributeName = this._namingUtil.joynrName(attribute);
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @brief Synchronous getter for the ");
        _builder.append(attributeName);
        _builder.append(" attribute.");
        _builder.newLineIfNotEmpty();
        _builder.append("*");
        _builder.newLine();
        _builder.append("* @param result The result that will be returned to the caller.");
        _builder.newLine();
        CharSequence _printMessagingQosParamDefinition = this.printMessagingQosParamDefinition();
        _builder.append(_printMessagingQosParamDefinition);
        _builder.newLineIfNotEmpty();
        _builder.append("* @throws JoynrException if the request is not successful");
        _builder.newLine();
        _builder.append("*/");
        _builder.newLine();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        _builder.newLineIfNotEmpty();
        CharSequence _produceSyncGetterSignature = this.produceSyncGetterSignature(attribute, generateVersion);
        _builder.append(_produceSyncGetterSignature);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
      }
    }
    return _builder;
  }

  public CharSequence produceAsyncGetterSignature(final FAttribute attribute, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String returnType = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
    _builder.newLineIfNotEmpty();
    final String attributeName = this._namingUtil.joynrName(attribute);
    _builder.newLineIfNotEmpty();
    String _xifexpression = null;
    if ((className == null)) {
      _xifexpression = " = nullptr";
    } else {
      _xifexpression = "";
    }
    final String defaultArg = _xifexpression;
    _builder.newLineIfNotEmpty();
    _builder.append("std::shared_ptr > ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("get");
    String _firstUpper = StringExtensions.toFirstUpper(attributeName);
    _builder.append(_firstUpper);
    _builder.append("Async(");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("std::function onSuccess");
    _builder.append(defaultArg, "\t\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("std::function onError");
    _builder.append(defaultArg, "\t\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("boost::optional qos");
    {
      if ((className == null)) {
        _builder.append(" = boost::none");
      }
    }
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("noexcept");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceAsyncGetterSignature(final FAttribute attribute, final boolean generateVersion) {
    return this.produceAsyncGetterSignature(attribute, null, generateVersion);
  }

  public CharSequence produceAsyncGetterDeclarations(final FInterface serviceInterface, final boolean pure, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FAttribute attribute) {
          return Boolean.valueOf(CppInterfaceUtil.this._attributeUtil.isReadable(attribute));
        }
      };
      Iterable _filter = IterableExtensions.filter(this.getAttributes(serviceInterface), _function);
      for(final FAttribute attribute : _filter) {
        final String attributeName = this._namingUtil.joynrName(attribute);
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @brief Asynchronous getter for the ");
        _builder.append(attributeName);
        _builder.append(" attribute.");
        _builder.newLineIfNotEmpty();
        _builder.append("*");
        _builder.newLine();
        CharSequence _printOnSuccessFctParamDefinition = this.printOnSuccessFctParamDefinition();
        _builder.append(_printOnSuccessFctParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printOnRuntimeErrorFctParamDefinition = this.printOnRuntimeErrorFctParamDefinition();
        _builder.append(_printOnRuntimeErrorFctParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printMessagingQosParamDefinition = this.printMessagingQosParamDefinition();
        _builder.append(_printMessagingQosParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printFutureReturnDefinition = this.printFutureReturnDefinition();
        _builder.append(_printFutureReturnDefinition);
        _builder.newLineIfNotEmpty();
        _builder.append("*/");
        _builder.newLine();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        _builder.newLineIfNotEmpty();
        CharSequence _produceAsyncGetterSignature = this.produceAsyncGetterSignature(attribute, generateVersion);
        _builder.append(_produceAsyncGetterSignature);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }

  public CharSequence produceSyncSetterSignature(final FAttribute attribute, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String returnType = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
    _builder.newLineIfNotEmpty();
    final String attributeName = this._namingUtil.joynrName(attribute);
    _builder.newLineIfNotEmpty();
    _builder.append("void ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("set");
    String _firstUpper = StringExtensions.toFirstUpper(attributeName);
    _builder.append(_firstUpper);
    _builder.append("(const ");
    _builder.append(returnType);
    _builder.append("& ");
    _builder.append(attributeName);
    _builder.append(", boost::optional qos");
    {
      if ((className == null)) {
        _builder.append(" = boost::none");
      }
    }
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  public CharSequence produceSyncSetterSignature(final FAttribute attribute, final boolean generateVersion) {
    return this.produceSyncSetterSignature(attribute, null, generateVersion);
  }

  public CharSequence produceSyncSetterDeclarations(final FInterface serviceInterface, final boolean pure, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FAttribute attribute) {
          return Boolean.valueOf(CppInterfaceUtil.this._attributeUtil.isWritable(attribute));
        }
      };
      Iterable _filter = IterableExtensions.filter(this.getAttributes(serviceInterface), _function);
      for(final FAttribute attribute : _filter) {
        final String attributeName = this._namingUtil.joynrName(attribute);
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @brief Synchronous setter for the ");
        _builder.append(attributeName);
        _builder.append(" attribute.");
        _builder.newLineIfNotEmpty();
        _builder.append("*");
        _builder.newLine();
        _builder.append("* @param ");
        _builder.append(attributeName);
        _builder.append(" The value to set.");
        _builder.newLineIfNotEmpty();
        CharSequence _printMessagingQosParamDefinition = this.printMessagingQosParamDefinition();
        _builder.append(_printMessagingQosParamDefinition);
        _builder.newLineIfNotEmpty();
        _builder.append("* @throws JoynrException if the request is not successful");
        _builder.newLine();
        _builder.append("*/");
        _builder.newLine();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        _builder.newLineIfNotEmpty();
        CharSequence _produceSyncSetterSignature = this.produceSyncSetterSignature(attribute, generateVersion);
        _builder.append(_produceSyncSetterSignature);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }

  public CharSequence produceAsyncSetterSignature(final FAttribute attribute, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String returnType = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
    _builder.newLineIfNotEmpty();
    final String attributeName = this._namingUtil.joynrName(attribute);
    _builder.newLineIfNotEmpty();
    String _xifexpression = null;
    if ((className == null)) {
      _xifexpression = " = nullptr";
    } else {
      _xifexpression = "";
    }
    final String defaultArg = _xifexpression;
    _builder.newLineIfNotEmpty();
    _builder.append("std::shared_ptr > ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("set");
    String _firstUpper = StringExtensions.toFirstUpper(attributeName);
    _builder.append(_firstUpper);
    _builder.append("Async(");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append(returnType, "\t\t\t");
    _builder.append(" ");
    _builder.append(attributeName, "\t\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("std::function onSuccess");
    _builder.append(defaultArg, "\t\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("std::function onError");
    _builder.append(defaultArg, "\t\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("boost::optional qos");
    {
      if ((className == null)) {
        _builder.append(" = boost::none");
      }
    }
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("noexcept");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceAsyncSetterSignature(final FAttribute attribute, final boolean generateVersion) {
    return this.produceAsyncSetterSignature(attribute, null, generateVersion);
  }

  public CharSequence produceAsyncSetterDeclarations(final FInterface serviceInterface, final boolean pure, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FAttribute attribute) {
          return Boolean.valueOf(CppInterfaceUtil.this._attributeUtil.isWritable(attribute));
        }
      };
      Iterable _filter = IterableExtensions.filter(this.getAttributes(serviceInterface), _function);
      for(final FAttribute attribute : _filter) {
        final String attributeName = this._namingUtil.joynrName(attribute);
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @brief Asynchronous setter for the ");
        _builder.append(attributeName);
        _builder.append(" attribute.");
        _builder.newLineIfNotEmpty();
        _builder.append("*");
        _builder.newLine();
        _builder.append("* @param ");
        _builder.append(attributeName);
        _builder.append(" The value to set.");
        _builder.newLineIfNotEmpty();
        CharSequence _printOnSuccessFctParamDefinition = this.printOnSuccessFctParamDefinition();
        _builder.append(_printOnSuccessFctParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printOnRuntimeErrorFctParamDefinition = this.printOnRuntimeErrorFctParamDefinition();
        _builder.append(_printOnRuntimeErrorFctParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printMessagingQosParamDefinition = this.printMessagingQosParamDefinition();
        _builder.append(_printMessagingQosParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printFutureReturnDefinition = this.printFutureReturnDefinition();
        _builder.append(_printFutureReturnDefinition);
        _builder.newLineIfNotEmpty();
        _builder.append("*/");
        _builder.newLine();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        _builder.newLineIfNotEmpty();
        CharSequence _produceAsyncSetterSignature = this.produceAsyncSetterSignature(attribute, generateVersion);
        _builder.append(_produceAsyncSetterSignature);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }

  public CharSequence produceSyncMethodSignature(final FMethod method, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String outputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedOutputParameterList(method, generateVersion);
    _builder.newLineIfNotEmpty();
    final String inputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstInputParameterList(method, generateVersion);
    _builder.newLineIfNotEmpty();
    _builder.append("void ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    String _joynrName = this._namingUtil.joynrName(method);
    _builder.append(_joynrName);
    _builder.append("(");
    _builder.newLineIfNotEmpty();
    {
      boolean _isEmpty = IterableExtensions.isEmpty(this._methodUtil.getOutputParameters(method));
      boolean _not = (!_isEmpty);
      if (_not) {
        _builder.append("\t\t\t");
        _builder.append(outputTypedParamList, "\t\t\t");
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    {
      boolean _isEmpty_1 = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method));
      boolean _not_1 = (!_isEmpty_1);
      if (_not_1) {
        _builder.append("\t\t\t");
        _builder.append(inputTypedParamList, "\t\t\t");
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t\t\t");
    _builder.append("boost::optional qos");
    {
      if ((className == null)) {
        _builder.append(" = boost::none");
      }
    }
    _builder.newLineIfNotEmpty();
    _builder.append(")");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceSyncMethodSignature(final FMethod method, final boolean generateVersion) {
    return this.produceSyncMethodSignature(method, null, generateVersion);
  }

  public CharSequence produceSyncMethodDeclarations(final FInterface serviceInterface, final boolean pure, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FMethod it) {
          boolean _isFireAndForget = it.isFireAndForget();
          return Boolean.valueOf((!_isFireAndForget));
        }
      };
      Iterable _filter = IterableExtensions.filter(this.getMethods(serviceInterface), _function);
      for(final FMethod method : _filter) {
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @brief Synchronous operation ");
        String _joynrName = this._namingUtil.joynrName(method);
        _builder.append(_joynrName);
        _builder.append(".");
        _builder.newLineIfNotEmpty();
        _builder.append("*");
        _builder.newLine();
        {
          Iterable _outputParameters = this._methodUtil.getOutputParameters(method);
          for(final FArgument outputParam : _outputParameters) {
            _builder.append("* @param ");
            String _typeName = this._cppStdTypeUtil.getTypeName(outputParam, generateVersion);
            _builder.append(_typeName);
            _builder.append(" ");
            String _joynrName_1 = this._namingUtil.joynrName(outputParam);
            _builder.append(_joynrName_1);
            _builder.append(" this is an output parameter");
            _builder.newLineIfNotEmpty();
            _builder.append("*        and will be set within function ");
            String _joynrName_2 = this._namingUtil.joynrName(method);
            _builder.append(_joynrName_2);
            _builder.newLineIfNotEmpty();
          }
        }
        {
          Iterable _inputParameters = this._methodUtil.getInputParameters(method);
          for(final FArgument inputParam : _inputParameters) {
            _builder.append("* @param ");
            String _typeName_1 = this._cppStdTypeUtil.getTypeName(inputParam, generateVersion);
            _builder.append(_typeName_1);
            _builder.append(" ");
            String _joynrName_3 = this._namingUtil.joynrName(inputParam);
            _builder.append(_joynrName_3);
            _builder.newLineIfNotEmpty();
          }
        }
        CharSequence _printMessagingQosParamDefinition = this.printMessagingQosParamDefinition();
        _builder.append(_printMessagingQosParamDefinition);
        _builder.newLineIfNotEmpty();
        _builder.append("* @throws JoynrException if the request is not successful");
        _builder.newLine();
        _builder.append("*/");
        _builder.newLine();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        _builder.newLineIfNotEmpty();
        CharSequence _produceSyncMethodSignature = this.produceSyncMethodSignature(method, generateVersion);
        _builder.append(_produceSyncMethodSignature);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }

  public String getMethodErrorEnum(final FInterface serviceInterface, final FMethod method, final boolean generateVersion) {
    final HashMap methodToErrorEnumName = this.methodToErrorEnumName(serviceInterface);
    FEnumerationType _errors = method.getErrors();
    boolean _tripleNotEquals = (_errors != null);
    if (_tripleNotEquals) {
      final String packagePath = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(method.getErrors(), "::", generateVersion);
      String _get = methodToErrorEnumName.get(method);
      String _plus = ((packagePath + "::") + _get);
      String _plus_1 = (_plus + "::");
      String _nestedEnumName = this._joynrCppGeneratorExtensions.getNestedEnumName();
      return (_plus_1 + _nestedEnumName);
    } else {
      return this._cppStdTypeUtil.getTypeName(method.getErrorEnum(), generateVersion);
    }
  }

  public CharSequence produceAsyncMethodSignature(final FInterface serviceInterface, final FMethod method, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String outputParameters = this._cppStdTypeUtil.getCommaSeparatedOutputParameterTypes(method, generateVersion);
    _builder.newLineIfNotEmpty();
    final String outputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstOutputParameterList(method, generateVersion);
    _builder.newLineIfNotEmpty();
    final String returnValue = (("std::shared_ptr>");
    _builder.newLineIfNotEmpty();
    String _xifexpression = null;
    if ((className == null)) {
      _xifexpression = " = nullptr";
    } else {
      _xifexpression = "";
    }
    final String defaultArg = _xifexpression;
    _builder.newLineIfNotEmpty();
    _builder.append(returnValue);
    _builder.append(" ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append(" ");
    String _joynrName = this._namingUtil.joynrName(method);
    _builder.append(_joynrName);
    _builder.append("Async(");
    _builder.newLineIfNotEmpty();
    {
      boolean _isEmpty = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method));
      boolean _not = (!_isEmpty);
      if (_not) {
        _builder.append("\t\t\t");
        String _commaSeperatedTypedConstInputParameterList = this._cppStdTypeUtil.getCommaSeperatedTypedConstInputParameterList(method, generateVersion);
        _builder.append(_commaSeperatedTypedConstInputParameterList, "\t\t\t");
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t\t\t");
    _builder.append("std::function onSuccess");
    _builder.append(defaultArg, "\t\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    {
      boolean _hasErrorEnum = this._methodUtil.hasErrorEnum(method);
      if (_hasErrorEnum) {
        _builder.append("\t\t\t");
        _builder.append("std::function onApplicationError");
        _builder.append(defaultArg, "\t\t\t");
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t\t\t");
    _builder.append("std::function onRuntimeError");
    _builder.append(defaultArg, "\t\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("boost::optional qos");
    {
      if ((className == null)) {
        _builder.append(" = boost::none");
      }
    }
    _builder.newLineIfNotEmpty();
    _builder.append(") noexcept");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceAsyncMethodSignature(final FInterface serviceInterface, final FMethod method, final boolean generateVersion) {
    return this.produceAsyncMethodSignature(serviceInterface, method, null, generateVersion);
  }

  public CharSequence produceAsyncMethodDeclarations(final FInterface serviceInterface, final boolean pure, final boolean useDefaultParam, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FMethod it) {
          boolean _isFireAndForget = it.isFireAndForget();
          return Boolean.valueOf((!_isFireAndForget));
        }
      };
      Iterable _filter = IterableExtensions.filter(this.getMethods(serviceInterface), _function);
      for(final FMethod method : _filter) {
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @brief Asynchronous operation ");
        String _joynrName = this._namingUtil.joynrName(method);
        _builder.append(_joynrName);
        _builder.append(".");
        _builder.newLineIfNotEmpty();
        _builder.append("*");
        _builder.newLine();
        CharSequence _printOnSuccessFctParamDefinition = this.printOnSuccessFctParamDefinition();
        _builder.append(_printOnSuccessFctParamDefinition);
        _builder.newLineIfNotEmpty();
        {
          boolean _hasErrorEnum = this._methodUtil.hasErrorEnum(method);
          if (_hasErrorEnum) {
            CharSequence _printOnApplicationErrorFctParamDefinition = this.printOnApplicationErrorFctParamDefinition();
            _builder.append(_printOnApplicationErrorFctParamDefinition);
            _builder.newLineIfNotEmpty();
          }
        }
        CharSequence _printOnRuntimeErrorFctParamDefinition = this.printOnRuntimeErrorFctParamDefinition();
        _builder.append(_printOnRuntimeErrorFctParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printMessagingQosParamDefinition = this.printMessagingQosParamDefinition();
        _builder.append(_printMessagingQosParamDefinition);
        _builder.newLineIfNotEmpty();
        CharSequence _printFutureReturnDefinition = this.printFutureReturnDefinition();
        _builder.append(_printFutureReturnDefinition);
        _builder.newLineIfNotEmpty();
        _builder.append("*/");
        _builder.newLine();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        _builder.newLineIfNotEmpty();
        CharSequence _produceAsyncMethodSignature = this.produceAsyncMethodSignature(serviceInterface, method, generateVersion);
        _builder.append(_produceAsyncMethodSignature);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }

  public CharSequence produceFireAndForgetMethodDeclarations(final FInterface serviceInterface, final boolean pure, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FMethod it) {
          return Boolean.valueOf(it.isFireAndForget());
        }
      };
      Iterable _filter = IterableExtensions.filter(this.getMethods(serviceInterface), _function);
      for(final FMethod method : _filter) {
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @brief FireAndForget operation ");
        String _joynrName = this._namingUtil.joynrName(method);
        _builder.append(_joynrName);
        _builder.append(".");
        _builder.newLineIfNotEmpty();
        _builder.append("*");
        _builder.newLine();
        {
          Iterable _inputParameters = this._methodUtil.getInputParameters(method);
          for(final FArgument inputParam : _inputParameters) {
            _builder.append("* @param ");
            String _typeName = this._cppStdTypeUtil.getTypeName(inputParam, generateVersion);
            _builder.append(_typeName);
            _builder.append(" ");
            String _joynrName_1 = this._namingUtil.joynrName(inputParam);
            _builder.append(_joynrName_1);
            _builder.newLineIfNotEmpty();
          }
        }
        CharSequence _printMessagingQosParamDefinition = this.printMessagingQosParamDefinition();
        _builder.append(_printMessagingQosParamDefinition);
        _builder.newLineIfNotEmpty();
        _builder.append("*/");
        _builder.newLine();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        _builder.newLineIfNotEmpty();
        CharSequence _produceFireAndForgetMethodSignature = this.produceFireAndForgetMethodSignature(method, generateVersion);
        _builder.append(_produceFireAndForgetMethodSignature);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }

  public CharSequence produceFireAndForgetMethodSignature(final FMethod method, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String inputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstInputParameterList(method, generateVersion);
    _builder.newLineIfNotEmpty();
    _builder.append("void ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    String _joynrName = this._namingUtil.joynrName(method);
    _builder.append(_joynrName);
    _builder.append("(");
    _builder.newLineIfNotEmpty();
    {
      boolean _isEmpty = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method));
      boolean _not = (!_isEmpty);
      if (_not) {
        _builder.append(inputTypedParamList);
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("boost::optional qos");
    {
      if ((className == null)) {
        _builder.append(" = boost::none");
      }
    }
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  public CharSequence produceFireAndForgetMethodSignature(final FMethod method, final boolean generateVersion) {
    return this.produceSyncMethodSignature(method, null, generateVersion);
  }

  public CharSequence produceApplicationRuntimeErrorSplitForOnErrorWrapper(final FInterface serviceInterface, final FMethod method, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      boolean _hasErrorEnum = this._methodUtil.hasErrorEnum(method);
      if (_hasErrorEnum) {
        _builder.append("future->onError(error);");
        _builder.newLine();
        _builder.append("if (const exceptions::JoynrRuntimeException* runtimeError = dynamic_cast(error.get())) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("if(onRuntimeError) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("onRuntimeError(*runtimeError);");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("else if (const exceptions::ApplicationException* applicationError = dynamic_cast(error.get())) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("const std::string& enumName = applicationError->getName();");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("if(onApplicationError) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("JOYNR_LOG_DEBUG(logger(), \"An ApplicationException was received. Error: {}, message: {}\", enumName, applicationError->getMessage());");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("onApplicationError(muesli::EnumTraits<");
        String _methodErrorEnum = this.getMethodErrorEnum(serviceInterface, method, generateVersion);
        _builder.append(_methodErrorEnum, "\t\t");
        _builder.append(">::Wrapper::getEnum(enumName));");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("else if (onRuntimeError) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("const std::string errorMessage = \"An ApplicationException was received, but no onApplicationError callback function was provided.\" \\");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\" Error \" + enumName + \", message: \" + applicationError->getMessage();");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("JOYNR_LOG_WARN(logger(), errorMessage);");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("onRuntimeError(exceptions::JoynrRuntimeException(errorMessage));");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("else{");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("JOYNR_LOG_WARN(logger(),");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\"An ApplicationException was received, but no callback function was provided. Error {}, message: {}\",");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("enumName, applicationError->getMessage());");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("else {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("const std::string errorMessage = \"Unknown exception: \" + error->getTypeName() + \": \" + error->getMessage();");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("JOYNR_LOG_ERROR(logger(), errorMessage);");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("if (onRuntimeError) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("onRuntimeError(exceptions::JoynrRuntimeException(errorMessage));");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
      } else {
        _builder.append("if (const exceptions::ApplicationException* applicationError = dynamic_cast(error.get())) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("const std::string& enumName = applicationError->getName();");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("const std::string errorMessage = \"An ApplicationException was received, but none was expected.\" \\");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\" Is the provider version incompatible with the consumer?\" \\");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\" Error \" + enumName + \", message: \" + applicationError->getMessage();");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("JOYNR_LOG_ERROR(logger(), errorMessage);");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("std::shared_ptr wrappedException = std::make_shared(errorMessage);");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("future->onError(wrappedException);");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (onRuntimeError) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("onRuntimeError(static_cast(*wrappedException));");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("else {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("future->onError(error);");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("if (onRuntimeError) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("onRuntimeError(static_cast(*error));");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
      }
    }
    return _builder;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy