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

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

package io.joynr.generator.cpp.communicationmodel;

import com.google.inject.Inject;
import io.joynr.generator.cpp.util.CppStdTypeUtil;
import io.joynr.generator.cpp.util.InterfaceUtil;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import io.joynr.generator.util.InterfaceTemplate;
import java.util.HashSet;
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.StringExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FBasicTypeId;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FType;

@SuppressWarnings("all")
public class InterfaceHTemplate implements InterfaceTemplate {
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;
  
  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;
  
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  public CharSequence generate(final FInterface serviceInterface) {
    StringConcatenation _builder = new StringConcatenation();
    final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(serviceInterface);
    _builder.newLineIfNotEmpty();
    String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "_");
    String _plus = ("GENERATED_INTERFACE_" + _packagePathWithJoynrPrefix);
    String _plus_1 = (_plus + "_I");
    String _plus_2 = (_plus_1 + interfaceName);
    String _plus_3 = (_plus_2 + "_h");
    final String headerGuard = _plus_3.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 _allComplexAndEnumTypes = this._joynrCppGeneratorExtensions.getAllComplexAndEnumTypes(serviceInterface);
      for(final Object datatype : _allComplexAndEnumTypes) {
        {
          if ((datatype instanceof FType)) {
            {
              boolean _isComplex = this._joynrCppGeneratorExtensions.isComplex(((FType)datatype));
              if (_isComplex) {
                String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(((FType)datatype), true);
                _builder.append(_namespaceStarter, "");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("class ");
                String _joynrNameStd = this._joynrCppGeneratorExtensions.joynrNameStd(((FType)datatype));
                _builder.append(_joynrNameStd, "\t");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
                String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(((FType)datatype), true);
                _builder.append(_namespaceEnder, "");
                _builder.newLineIfNotEmpty();
              } else {
                _builder.append("#include \"");
                String _includeOf = this._cppStdTypeUtil.getIncludeOf(((FType)datatype));
                _builder.append(_includeOf, "");
                _builder.append("\"");
                _builder.newLineIfNotEmpty();
              }
            }
          }
        }
      }
    }
    _builder.newLine();
    {
      Iterable _allPrimitiveTypes = this._joynrCppGeneratorExtensions.getAllPrimitiveTypes(serviceInterface);
      Set _includesFor = this._cppStdTypeUtil.getIncludesFor(_allPrimitiveTypes);
      String _includeForArray = this._cppStdTypeUtil.getIncludeForArray();
      String _includeForString = this._cppStdTypeUtil.getIncludeForString();
      Set _addElements = this._cppStdTypeUtil.addElements(_includesFor, _includeForArray, _includeForString);
      for(final String include : _addElements) {
        _builder.append("#include ");
        _builder.append(include, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    String _dllExportIncludeStatement = this._joynrCppGeneratorExtensions.getDllExportIncludeStatement();
    _builder.append(_dllExportIncludeStatement, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.newLine();
    _builder.append("namespace joynr {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("class RequestStatus;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("template  class Future;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    String _namespaceStarter_1 = this._joynrCppGeneratorExtensions.getNamespaceStarter(serviceInterface);
    _builder.append(_namespaceStarter_1, "");
    _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("class ");
    String _dllExportMacro = this._joynrCppGeneratorExtensions.getDllExportMacro();
    _builder.append(_dllExportMacro, "");
    _builder.append(" 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();");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("virtual ~I");
    _builder.append(interfaceName, "\t");
    _builder.append("Base() { }");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static const std::string& INTERFACE_NAME();");
    _builder.newLine();
    _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("*/");
    _builder.newLine();
    _builder.append("class ");
    String _dllExportMacro_1 = this._joynrCppGeneratorExtensions.getDllExportMacro();
    _builder.append(_dllExportMacro_1, "");
    _builder.append(" I");
    _builder.append(interfaceName, "");
    _builder.append("Sync : virtual public I");
    _builder.append(interfaceName, "");
    _builder.append("Base {");
    _builder.newLineIfNotEmpty();
    _builder.append("public:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("virtual ~I");
    _builder.append(interfaceName, "\t");
    _builder.append("Sync(){ }");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _produceSyncGetters = this._interfaceUtil.produceSyncGetters(serviceInterface, true);
    _builder.append(_produceSyncGetters, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _produceSyncSetters = this._interfaceUtil.produceSyncSetters(serviceInterface, true);
    _builder.append(_produceSyncSetters, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _produceSyncMethods = this._interfaceUtil.produceSyncMethods(serviceInterface, true);
    _builder.append(_produceSyncMethods, "\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("*/");
    _builder.newLine();
    _builder.append("class ");
    String _dllExportMacro_2 = this._joynrCppGeneratorExtensions.getDllExportMacro();
    _builder.append(_dllExportMacro_2, "");
    _builder.append(" I");
    _builder.append(interfaceName, "");
    _builder.append("Async : virtual public I");
    _builder.append(interfaceName, "");
    _builder.append("Base {");
    _builder.newLineIfNotEmpty();
    _builder.append("public:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("virtual ~I");
    _builder.append(interfaceName, "\t");
    _builder.append("Async(){ }");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _produceAsyncGetters = this._interfaceUtil.produceAsyncGetters(serviceInterface, true);
    _builder.append(_produceAsyncGetters, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _produceAsyncSetters = this._interfaceUtil.produceAsyncSetters(serviceInterface, true);
    _builder.append(_produceAsyncSetters, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    CharSequence _produceAsyncMethods = this._interfaceUtil.produceAsyncMethods(serviceInterface, true);
    _builder.append(_produceAsyncMethods, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("};");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class ");
    String _dllExportMacro_3 = this._joynrCppGeneratorExtensions.getDllExportMacro();
    _builder.append(_dllExportMacro_3, "");
    _builder.append(" 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("virtual ~I");
    _builder.append(interfaceName, "\t");
    _builder.append("(){ }");
    _builder.newLineIfNotEmpty();
    {
      EList _attributes = this._joynrCppGeneratorExtensions.getAttributes(serviceInterface);
      for(final FAttribute attribute : _attributes) {
        _builder.append("\t");
        String _name = attribute.getName();
        final String attributeName = StringExtensions.toFirstUpper(_name);
        _builder.newLineIfNotEmpty();
        {
          boolean _isReadable = this._joynrCppGeneratorExtensions.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._joynrCppGeneratorExtensions.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();
          }
        }
      }
    }
    {
      HashSet _uniqueMethodNames = this._joynrCppGeneratorExtensions.getUniqueMethodNames(serviceInterface);
      for(final String methodName : _uniqueMethodNames) {
        _builder.append("\t");
        _builder.append("using I");
        _builder.append(interfaceName, "\t");
        _builder.append("Sync::");
        _builder.append(methodName, "\t");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("using I");
        _builder.append(interfaceName, "\t");
        _builder.append("Async::");
        _builder.append(methodName, "\t");
        _builder.append("Async;");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("};");
    _builder.newLine();
    _builder.newLine();
    String _namespaceEnder_1 = this._joynrCppGeneratorExtensions.getNamespaceEnder(serviceInterface);
    _builder.append(_namespaceEnder_1, "");
    _builder.newLineIfNotEmpty();
    _builder.append("#endif // ");
    _builder.append(headerGuard, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}