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

io.joynr.generator.cpp.interfaces.InterfaceHTemplate Maven / Gradle / Ivy

package io.joynr.generator.cpp.interfaces;

import com.google.inject.Inject;
import io.joynr.generator.cpp.util.CppInterfaceUtil;
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.FMapTypeAsLastComparator;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.NamingUtil;
import java.util.HashSet;
import java.util.List;
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.FAttribute;
import org.franca.core.franca.FMethod;
import org.franca.core.franca.FType;

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

  @Inject
  @Extension
  private CppInterfaceUtil _cppInterfaceUtil;

  @Inject
  @Extension
  private AttributeUtil _attributeUtil;

  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;

  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;

  @Override
  public CharSequence generate(final boolean generateVersion) {
    CharSequence _xblockexpression = null;
    {
      InterfaceUtil.TypeSelector selector = InterfaceUtil.TypeSelector.defaultTypeSelector();
      selector.errorTypes(true);
      selector.typeDefs(true);
      StringConcatenation _builder = new StringConcatenation();
      final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
      _builder.newLineIfNotEmpty();
      String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "_", generateVersion);
      String _plus = ("GENERATED_INTERFACE_" + _packagePathWithJoynrPrefix);
      String _plus_1 = (_plus + "_I");
      String _plus_2 = (_plus_1 + interfaceName);
      final String headerGuard = (_plus_2 + "_h").toUpperCase();
      _builder.newLineIfNotEmpty();
      CharSequence _warning = this._templateBase.warning();
      _builder.append(_warning);
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("#ifndef ");
      _builder.append(headerGuard);
      _builder.newLineIfNotEmpty();
      _builder.append("#define ");
      _builder.append(headerGuard);
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      {
        Iterable _allComplexTypes = this._cppInterfaceUtil.getAllComplexTypes(this.francaIntf, selector);
        FMapTypeAsLastComparator _fMapTypeAsLastComparator = new FMapTypeAsLastComparator();
        List _sortWith = IterableExtensions.sortWith(_allComplexTypes, _fMapTypeAsLastComparator);
        for(final FType datatype : _sortWith) {
          {
            if ((this._cppStdTypeUtil.isCompound(datatype) || (this._cppStdTypeUtil.isMap(datatype) && (!this._cppStdTypeUtil.isTypeDef(datatype))))) {
              CharSequence _forwardDeclaration = this._cppStdTypeUtil.getForwardDeclaration(datatype, generateVersion);
              _builder.append(_forwardDeclaration);
              _builder.newLineIfNotEmpty();
            } else {
              _builder.append("#include ");
              String _includeOf = this._cppStdTypeUtil.getIncludeOf(datatype, generateVersion);
              _builder.append(_includeOf);
              _builder.newLineIfNotEmpty();
            }
          }
        }
      }
      _builder.newLine();
      {
        Set _addElements = this._cppStdTypeUtil.addElements(this._cppStdTypeUtil.getIncludesFor(this._cppInterfaceUtil.getAllPrimitiveTypes(this.francaIntf)), this._cppStdTypeUtil.getIncludeForArray(), this._cppStdTypeUtil.getIncludeForString());
        for(final String include : _addElements) {
          _builder.append("#include ");
          _builder.append(include);
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      _builder.newLine();
      _builder.append("#include ");
      _builder.newLine();
      _builder.append("#include ");
      _builder.newLine();
      _builder.newLine();
      _builder.append("#include ");
      _builder.newLine();
      _builder.append("#include ");
      _builder.newLine();
      _builder.newLine();
      _builder.append("#include \"joynr/MessagingQos.h\"");
      _builder.newLine();
      _builder.newLine();
      _builder.append("namespace joynr");
      _builder.newLine();
      _builder.append("{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("template  class Future;");
      _builder.newLine();
      _builder.newLine();
      _builder.append("namespace exceptions");
      _builder.newLine();
      _builder.append("{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("class JoynrException;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("class JoynrRuntimeException;");
      _builder.newLine();
      _builder.append("} // namespace exceptions");
      _builder.newLine();
      _builder.newLine();
      _builder.append("} // namespace joynr");
      _builder.newLine();
      _builder.newLine();
      String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.francaIntf, generateVersion);
      _builder.append(_namespaceStarter);
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @brief Base interface.");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @version ");
      _builder.append(this.majorVersion, " ");
      _builder.append(".");
      _builder.append(this.minorVersion, " ");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("class I");
      _builder.append(interfaceName);
      _builder.append("Base {");
      _builder.newLineIfNotEmpty();
      _builder.append("public:");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("I");
      _builder.append(interfaceName, "\t");
      _builder.append("Base() = default;");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("virtual ~I");
      _builder.append(interfaceName, "\t");
      _builder.append("Base() = default;");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("static const std::string& INTERFACE_NAME();");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("/**");
      _builder.newLine();
      _builder.append("\t ");
      _builder.append("* @brief MAJOR_VERSION The major version of this provider interface as specified in the");
      _builder.newLine();
      _builder.append("\t ");
      _builder.append("* Franca model.");
      _builder.newLine();
      _builder.append("\t ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("static const std::int32_t MAJOR_VERSION;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("/**");
      _builder.newLine();
      _builder.append("\t ");
      _builder.append("* @brief MINOR_VERSION The minor version of this provider interface as specified in the");
      _builder.newLine();
      _builder.append("\t ");
      _builder.append("* Franca model.");
      _builder.newLine();
      _builder.append("\t ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("static const std::int32_t MINOR_VERSION;");
      _builder.newLine();
      _builder.append("};");
      _builder.newLine();
      _builder.newLine();
      {
        boolean _hasFireAndForgetMethods = this._cppInterfaceUtil.hasFireAndForgetMethods(this.francaIntf);
        if (_hasFireAndForgetMethods) {
          _builder.append("/**");
          _builder.newLine();
          _builder.append(" ");
          _builder.append("* @brief This is the ");
          _builder.append(interfaceName, " ");
          _builder.append(" fireAndForget interface.");
          _builder.newLineIfNotEmpty();
          _builder.append(" ");
          _builder.append("*");
          _builder.newLine();
          _builder.append(" ");
          _builder.append("* @version ");
          _builder.append(this.majorVersion, " ");
          _builder.append(".");
          _builder.append(this.minorVersion, " ");
          _builder.newLineIfNotEmpty();
          _builder.append(" ");
          _builder.append("*/");
          _builder.newLine();
          _builder.append("class I");
          _builder.append(interfaceName);
          _builder.append("FireAndForget : virtual public I");
          _builder.append(interfaceName);
          _builder.append("Base {");
          _builder.newLineIfNotEmpty();
          _builder.append("public:");
          _builder.newLine();
          _builder.append("\t");
          _builder.append("~I");
          _builder.append(interfaceName, "\t");
          _builder.append("FireAndForget() override = default;");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          CharSequence _produceFireAndForgetMethodDeclarations = this._cppInterfaceUtil.produceFireAndForgetMethodDeclarations(this.francaIntf, true, generateVersion);
          _builder.append(_produceFireAndForgetMethodDeclarations, "\t");
          _builder.newLineIfNotEmpty();
          _builder.append("};");
          _builder.newLine();
        }
      }
      _builder.newLine();
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @brief This is the ");
      _builder.append(interfaceName, " ");
      _builder.append(" synchronous interface.");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @version ");
      _builder.append(this.majorVersion, " ");
      _builder.append(".");
      _builder.append(this.minorVersion, " ");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("class I");
      _builder.append(interfaceName);
      _builder.append("Sync :");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("virtual public I");
      _builder.append(interfaceName, "\t\t");
      _builder.append("Base");
      {
        boolean _hasFireAndForgetMethods_1 = this._cppInterfaceUtil.hasFireAndForgetMethods(this.francaIntf);
        if (_hasFireAndForgetMethods_1) {
          _builder.append(",");
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("virtual public I");
          _builder.append(interfaceName, "\t\t");
          _builder.append("FireAndForget");
        }
      }
      _builder.newLineIfNotEmpty();
      _builder.append("{");
      _builder.newLine();
      _builder.append("public:");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("~I");
      _builder.append(interfaceName, "\t");
      _builder.append("Sync() override = default;");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceSyncGetterDeclarations = this._cppInterfaceUtil.produceSyncGetterDeclarations(this.francaIntf, true, generateVersion);
      _builder.append(_produceSyncGetterDeclarations, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceSyncSetterDeclarations = this._cppInterfaceUtil.produceSyncSetterDeclarations(this.francaIntf, true, generateVersion);
      _builder.append(_produceSyncSetterDeclarations, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceSyncMethodDeclarations = this._cppInterfaceUtil.produceSyncMethodDeclarations(this.francaIntf, true, generateVersion);
      _builder.append(_produceSyncMethodDeclarations, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("};");
      _builder.newLine();
      _builder.newLine();
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @brief This is the ");
      _builder.append(interfaceName, " ");
      _builder.append(" asynchronous interface.");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @version ");
      _builder.append(this.majorVersion, " ");
      _builder.append(".");
      _builder.append(this.minorVersion, " ");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("class I");
      _builder.append(interfaceName);
      _builder.append("Async :");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("virtual public I");
      _builder.append(interfaceName, "\t\t");
      _builder.append("Base");
      {
        boolean _hasFireAndForgetMethods_2 = this._cppInterfaceUtil.hasFireAndForgetMethods(this.francaIntf);
        if (_hasFireAndForgetMethods_2) {
          _builder.append(",");
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("virtual public I");
          _builder.append(interfaceName, "\t\t");
          _builder.append("FireAndForget");
        }
      }
      _builder.newLineIfNotEmpty();
      _builder.append("{");
      _builder.newLine();
      _builder.append("public:");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("~I");
      _builder.append(interfaceName, "\t");
      _builder.append("Async() override = default;");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceAsyncGetterDeclarations = this._cppInterfaceUtil.produceAsyncGetterDeclarations(this.francaIntf, true, generateVersion);
      _builder.append(_produceAsyncGetterDeclarations, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceAsyncSetterDeclarations = this._cppInterfaceUtil.produceAsyncSetterDeclarations(this.francaIntf, true, generateVersion);
      _builder.append(_produceAsyncSetterDeclarations, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceAsyncMethodDeclarations = this._cppInterfaceUtil.produceAsyncMethodDeclarations(this.francaIntf, true, true, generateVersion);
      _builder.append(_produceAsyncMethodDeclarations, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("};");
      _builder.newLine();
      _builder.newLine();
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @brief This is the ");
      _builder.append(interfaceName, " ");
      _builder.append(" interface.");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* @version ");
      _builder.append(this.majorVersion, " ");
      _builder.append(".");
      _builder.append(this.minorVersion, " ");
      _builder.newLineIfNotEmpty();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("class I");
      _builder.append(interfaceName);
      _builder.append(" : virtual public I");
      _builder.append(interfaceName);
      _builder.append("Sync, virtual public I");
      _builder.append(interfaceName);
      _builder.append("Async {");
      _builder.newLineIfNotEmpty();
      _builder.append("public:");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("~I");
      _builder.append(interfaceName, "\t");
      _builder.append("() override = default;");
      _builder.newLineIfNotEmpty();
      {
        EList _attributes = this._cppInterfaceUtil.getAttributes(this.francaIntf);
        for(final FAttribute attribute : _attributes) {
          _builder.append("\t");
          final String attributeName = StringExtensions.toFirstUpper(attribute.getName());
          _builder.newLineIfNotEmpty();
          {
            boolean _isReadable = this._attributeUtil.isReadable(attribute);
            if (_isReadable) {
              _builder.append("\t");
              _builder.append("using I");
              _builder.append(interfaceName, "\t");
              _builder.append("Sync::get");
              _builder.append(attributeName, "\t");
              _builder.append(";");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("using I");
              _builder.append(interfaceName, "\t");
              _builder.append("Async::get");
              _builder.append(attributeName, "\t");
              _builder.append("Async;");
              _builder.newLineIfNotEmpty();
            }
          }
          {
            boolean _isWritable = this._attributeUtil.isWritable(attribute);
            if (_isWritable) {
              _builder.append("\t");
              _builder.append("using I");
              _builder.append(interfaceName, "\t");
              _builder.append("Sync::set");
              _builder.append(attributeName, "\t");
              _builder.append(";");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("using I");
              _builder.append(interfaceName, "\t");
              _builder.append("Async::set");
              _builder.append(attributeName, "\t");
              _builder.append("Async;");
              _builder.newLineIfNotEmpty();
            }
          }
        }
      }
      {
        final Function1 _function = new Function1() {
          @Override
          public Boolean apply(final FMethod it) {
            boolean _isFireAndForget = it.isFireAndForget();
            return Boolean.valueOf((!_isFireAndForget));
          }
        };
        HashSet _uniqueMethodNames = this._cppInterfaceUtil.getUniqueMethodNames(IterableExtensions.filter(this._cppInterfaceUtil.getMethods(this.francaIntf), _function));
        for(final String method : _uniqueMethodNames) {
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "\t");
          _builder.append("Sync::");
          _builder.append(method, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "\t");
          _builder.append("Async::");
          _builder.append(method, "\t");
          _builder.append("Async;");
          _builder.newLineIfNotEmpty();
        }
      }
      {
        final Function1 _function_1 = new Function1() {
          @Override
          public Boolean apply(final FMethod it) {
            return Boolean.valueOf(it.isFireAndForget());
          }
        };
        HashSet _uniqueMethodNames_1 = this._cppInterfaceUtil.getUniqueMethodNames(IterableExtensions.filter(this._cppInterfaceUtil.getMethods(this.francaIntf), _function_1));
        for(final String method_1 : _uniqueMethodNames_1) {
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "\t");
          _builder.append("FireAndForget::");
          _builder.append(method_1, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("};");
      _builder.newLine();
      _builder.newLine();
      String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(this.francaIntf, generateVersion);
      _builder.append(_namespaceEnder);
      _builder.newLineIfNotEmpty();
      _builder.append("#endif // ");
      _builder.append(headerGuard);
      _builder.newLineIfNotEmpty();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy