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

io.joynr.generator.cpp.defaultProvider.DefaultInterfaceProviderCppTemplate Maven / Gradle / Ivy

package io.joynr.generator.cpp.defaultProvider;

import com.google.common.base.Objects;
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.HashMap;
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.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.FBasicTypeId;
import org.franca.core.franca.FEnumerationType;
import org.franca.core.franca.FMethod;
import org.franca.core.franca.FTypeRef;

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

  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;

  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private MethodUtil _methodUtil;

  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;

  @Inject
  @Extension
  private AttributeUtil _attributeUtil;

  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;

  @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 \"");
    String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "/", generateVersion);
    _builder.append(_packagePathWithJoynrPrefix);
    _builder.append("/Default");
    _builder.append(interfaceName);
    _builder.append("Provider.h\"");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.newLine();
    _builder.newLine();
    String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.francaIntf, generateVersion);
    _builder.append(_namespaceStarter);
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("Default");
    _builder.append(interfaceName);
    _builder.append("Provider::Default");
    _builder.append(interfaceName);
    _builder.append("Provider() :");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append(interfaceName, "\t\t");
    _builder.append("AbstractProvider()");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    {
      boolean _isEmpty = this.francaIntf.getAttributes().isEmpty();
      boolean _not = (!_isEmpty);
      if (_not) {
        _builder.append(",");
      }
    }
    _builder.newLineIfNotEmpty();
    {
      EList _attributes = this.francaIntf.getAttributes();
      boolean _hasElements = false;
      for(final FAttribute attribute : _attributes) {
        if (!_hasElements) {
          _hasElements = true;
        } else {
          _builder.appendImmediate(",", "\t\t");
        }
        _builder.append("\t\t");
        String _joynrName = this._namingUtil.joynrName(attribute);
        _builder.append(_joynrName, "\t\t");
        _builder.append("()");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("{");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("Default");
    _builder.append(interfaceName);
    _builder.append("Provider::~Default");
    _builder.append(interfaceName);
    _builder.append("Provider() = default;");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      boolean _isEmpty_1 = this.francaIntf.getAttributes().isEmpty();
      boolean _not_1 = (!_isEmpty_1);
      if (_not_1) {
        _builder.append("// attributes");
        _builder.newLine();
      }
    }
    {
      EList _attributes_1 = this.francaIntf.getAttributes();
      for(final FAttribute attribute_1 : _attributes_1) {
        String attributeName = this._namingUtil.joynrName(attribute_1);
        _builder.newLineIfNotEmpty();
        {
          boolean _isReadable = this._attributeUtil.isReadable(attribute_1);
          if (_isReadable) {
            _builder.append("void Default");
            _builder.append(interfaceName);
            _builder.append("Provider::get");
            String _firstUpper = StringExtensions.toFirstUpper(attributeName);
            _builder.append(_firstUpper);
            _builder.append("(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("std::function onSuccess,");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("std::function onError");
            _builder.newLine();
            _builder.append(") {");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("std::ignore = onError;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("onSuccess(");
            _builder.append(attributeName, "\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
          }
        }
        {
          boolean _isWritable = this._attributeUtil.isWritable(attribute_1);
          if (_isWritable) {
            _builder.append("void Default");
            _builder.append(interfaceName);
            _builder.append("Provider::set");
            String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
            _builder.append(_firstUpper_1);
            _builder.append("(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("const ");
            String _typeName_1 = this._cppStdTypeUtil.getTypeName(attribute_1, generateVersion);
            _builder.append(_typeName_1, "\t\t");
            _builder.append("& _");
            _builder.append(attributeName, "\t\t");
            _builder.append(",");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("std::function onSuccess,");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("std::function onError");
            _builder.newLine();
            _builder.append(") {");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("std::ignore = onError;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("this->");
            _builder.append(attributeName, "\t");
            _builder.append(" = _");
            _builder.append(attributeName, "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            {
              boolean _isNotifiable = this._attributeUtil.isNotifiable(attribute_1);
              if (_isNotifiable) {
                _builder.append("\t");
                _builder.append(attributeName, "\t");
                _builder.append("Changed(_");
                _builder.append(attributeName, "\t");
                _builder.append(");");
                _builder.newLineIfNotEmpty();
              }
            }
            _builder.append("\t");
            _builder.append("onSuccess();");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
          }
        }
      }
    }
    final HashMap methodToErrorEnumName = this._interfaceUtil.methodToErrorEnumName(this.francaIntf);
    _builder.newLineIfNotEmpty();
    {
      boolean _isEmpty_2 = this.francaIntf.getMethods().isEmpty();
      boolean _not_2 = (!_isEmpty_2);
      if (_not_2) {
        _builder.append("// methods");
        _builder.newLine();
      }
    }
    {
      EList _methods = this.francaIntf.getMethods();
      for(final FMethod method : _methods) {
        final String outputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstOutputParameterList(method, generateVersion);
        _builder.newLineIfNotEmpty();
        final String outputUntypedParamList = this._cppStdTypeUtil.getCommaSeperatedUntypedOutputParameterList(method);
        _builder.newLineIfNotEmpty();
        final String inputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstInputParameterList(method, generateVersion);
        _builder.newLineIfNotEmpty();
        final String methodName = this._namingUtil.joynrName(method);
        _builder.newLineIfNotEmpty();
        _builder.append("void Default");
        _builder.append(interfaceName);
        _builder.append("Provider::");
        String _joynrName_1 = this._namingUtil.joynrName(method);
        _builder.append(_joynrName_1);
        _builder.append("(");
        _builder.newLineIfNotEmpty();
        {
          boolean _isEmpty_3 = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method));
          boolean _not_3 = (!_isEmpty_3);
          if (_not_3) {
            _builder.append("\t\t");
            _builder.append(inputTypedParamList, "\t\t");
            {
              boolean _isFireAndForget = method.isFireAndForget();
              boolean _not_4 = (!_isFireAndForget);
              if (_not_4) {
                _builder.append(",");
              }
            }
            _builder.newLineIfNotEmpty();
          }
        }
        {
          boolean _isFireAndForget_1 = method.isFireAndForget();
          boolean _not_5 = (!_isFireAndForget_1);
          if (_not_5) {
            {
              boolean _isEmpty_4 = IterableExtensions.isEmpty(this._methodUtil.getOutputParameters(method));
              if (_isEmpty_4) {
                _builder.append("\t\t");
                _builder.append("std::function onSuccess,");
                _builder.newLine();
              } else {
                _builder.append("\t\t");
                _builder.append("std::function onSuccess,");
                _builder.newLine();
              }
            }
            {
              boolean _hasErrorEnum = this._methodUtil.hasErrorEnum(method);
              if (_hasErrorEnum) {
                {
                  FEnumerationType _errors = method.getErrors();
                  boolean _tripleNotEquals = (_errors != null);
                  if (_tripleNotEquals) {
                    _builder.append("\t\t");
                    final String packagePath = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(method.getErrors(), "::", generateVersion);
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("std::function onError");
                    _builder.newLineIfNotEmpty();
                  } else {
                    _builder.append("\t\t");
                    _builder.append("std::function onError");
                    _builder.newLineIfNotEmpty();
                  }
                }
              } else {
                _builder.append("\t\t");
                _builder.append("std::function onError");
                _builder.newLine();
              }
            }
          }
        }
        _builder.append(") {");
        _builder.newLine();
        {
          boolean _isFireAndForget_2 = method.isFireAndForget();
          boolean _not_6 = (!_isFireAndForget_2);
          if (_not_6) {
            _builder.append("\t");
            _builder.append("std::ignore = onError;");
            _builder.newLine();
          }
        }
        {
          Iterable _inputParameters = this._methodUtil.getInputParameters(method);
          for(final FArgument inputParameter : _inputParameters) {
            _builder.append("\t");
            _builder.append("std::ignore = ");
            String _joynrName_2 = this._namingUtil.joynrName(inputParameter);
            _builder.append(_joynrName_2, "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
          }
        }
        {
          Iterable _outputParameters = this._methodUtil.getOutputParameters(method);
          for(final FArgument argument : _outputParameters) {
            _builder.append("\t");
            final String outputParamType = this._cppStdTypeUtil.getTypeName(argument, generateVersion);
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            final FTypeRef argumentType = this._cppStdTypeUtil.resolveTypeDef(argument.getType());
            _builder.newLineIfNotEmpty();
            {
              if (((!argument.isArray()) && this._cppStdTypeUtil.isPrimitive(argumentType))) {
                _builder.append("\t");
                final FBasicTypeId type = this._cppStdTypeUtil.getPrimitive(argumentType);
                _builder.newLineIfNotEmpty();
                {
                  boolean _equals = Objects.equal(type, FBasicTypeId.STRING);
                  if (_equals) {
                    _builder.append("\t");
                    _builder.append(outputParamType, "\t");
                    _builder.append(" ");
                    String _joynrName_3 = this._namingUtil.joynrName(argument);
                    _builder.append(_joynrName_3, "\t");
                    _builder.append(" = \"Hello World\";");
                    _builder.newLineIfNotEmpty();
                  } else {
                    boolean _equals_1 = Objects.equal(type, FBasicTypeId.BOOLEAN);
                    if (_equals_1) {
                      _builder.append("\t");
                      _builder.append(outputParamType, "\t");
                      _builder.append(" ");
                      String _joynrName_4 = this._namingUtil.joynrName(argument);
                      _builder.append(_joynrName_4, "\t");
                      _builder.append(" = false;");
                      _builder.newLineIfNotEmpty();
                    } else {
                      if ((((((((Objects.equal(type, FBasicTypeId.INT8) || 
                        Objects.equal(type, FBasicTypeId.UINT8)) || 
                        Objects.equal(type, FBasicTypeId.INT16)) || 
                        Objects.equal(type, FBasicTypeId.UINT16)) || 
                        Objects.equal(type, FBasicTypeId.INT32)) || 
                        Objects.equal(type, FBasicTypeId.UINT32)) || 
                        Objects.equal(type, FBasicTypeId.INT64)) || 
                        Objects.equal(type, FBasicTypeId.UINT64))) {
                        _builder.append("\t");
                        _builder.append(outputParamType, "\t");
                        _builder.append(" ");
                        String _joynrName_5 = this._namingUtil.joynrName(argument);
                        _builder.append(_joynrName_5, "\t");
                        _builder.append(" = 42;");
                        _builder.newLineIfNotEmpty();
                      } else {
                        if ((Objects.equal(type, FBasicTypeId.DOUBLE) || 
                          Objects.equal(type, FBasicTypeId.FLOAT))) {
                          _builder.append("\t");
                          _builder.append(outputParamType, "\t");
                          _builder.append(" ");
                          String _joynrName_6 = this._namingUtil.joynrName(argument);
                          _builder.append(_joynrName_6, "\t");
                          _builder.append(" = 3.1415;");
                          _builder.newLineIfNotEmpty();
                        } else {
                          _builder.append("\t");
                          _builder.append(outputParamType, "\t");
                          _builder.append(" ");
                          String _joynrName_7 = this._namingUtil.joynrName(argument);
                          _builder.append(_joynrName_7, "\t");
                          _builder.append(";");
                          _builder.newLineIfNotEmpty();
                        }
                      }
                    }
                  }
                }
              } else {
                {
                  if (((!argument.isArray()) && this._cppStdTypeUtil.isEnum(argumentType))) {
                    _builder.append("\t");
                    _builder.append(outputParamType, "\t");
                    _builder.append(" ");
                    String _joynrName_8 = this._namingUtil.joynrName(argument);
                    _builder.append(_joynrName_8, "\t");
                    _builder.append("(");
                    String _defaultValue = this._cppStdTypeUtil.getDefaultValue(argument, generateVersion);
                    _builder.append(_defaultValue, "\t");
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                  } else {
                    _builder.append("\t");
                    _builder.append(outputParamType, "\t");
                    _builder.append(" ");
                    String _joynrName_9 = this._namingUtil.joynrName(argument);
                    _builder.append(_joynrName_9, "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                  }
                }
              }
            }
          }
        }
        _builder.append("\t");
        _builder.append("JOYNR_LOG_WARN(logger(), \"**********************************************\");");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("JOYNR_LOG_WARN(logger(), \"* Default");
        _builder.append(interfaceName, "\t");
        _builder.append("Provider::");
        _builder.append(methodName, "\t");
        _builder.append(" called\");");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("JOYNR_LOG_WARN(logger(), \"**********************************************\");");
        _builder.newLine();
        {
          boolean _isFireAndForget_3 = method.isFireAndForget();
          boolean _not_7 = (!_isFireAndForget_3);
          if (_not_7) {
            _builder.append("\t");
            _builder.append("onSuccess(");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append(outputUntypedParamList, "\t\t\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(");");
            _builder.newLine();
          }
        }
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
      }
    }
    String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(this.francaIntf, generateVersion);
    _builder.append(_namespaceEnder);
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy