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

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

There is a newer version: 0.9.3
Show newest version
package io.joynr.generator.cpp.communicationmodel;

import com.google.inject.Inject;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import java.util.HashSet;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FType;

@SuppressWarnings("all")
public class InterfaceCppTemplate {
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  public CharSequence generate(final FInterface serviceInterface) {
    CharSequence _xblockexpression = null;
    {
      final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(serviceInterface);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("\t");
      CharSequence _warning = this._templateBase.warning();
      _builder.append(_warning, "	");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("#include \"");
      String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
      _builder.append(_packagePathWithJoynrPrefix, "	");
      _builder.append("/I");
      _builder.append(interfaceName, "	");
      _builder.append(".h\"");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("#include \"qjson/serializer.h\"");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("#include \"joynr/MetaTypeRegistrar.h\"");
      _builder.newLine();
      _builder.newLine();
      {
        Iterable _requiredIncludesFor = this._joynrCppGeneratorExtensions.getRequiredIncludesFor(serviceInterface);
        for(final String parameterType : _requiredIncludesFor) {
          _builder.append("\t");
          _builder.append("#include \"");
          _builder.append(parameterType, "	");
          _builder.append("\"");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      _builder.append("\t");
      _builder.append("#include \"joynr/Future.h\"");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("#include \"joynr/ICallback.h\"");
      _builder.newLine();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("\t");
      String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(serviceInterface);
      _builder.append(_namespaceStarter, "	");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("I");
      _builder.append(interfaceName, "	");
      _builder.append("Base::I");
      _builder.append(interfaceName, "	");
      _builder.append("Base()");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("{");
      _builder.newLine();
      _builder.append("\t\t");
      final HashSet typeObjs = this._joynrCppGeneratorExtensions.getAllComplexAndEnumTypes(serviceInterface);
      _builder.newLineIfNotEmpty();
      {
        boolean _isEmpty = typeObjs.isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
          _builder.append("\t\t");
          _builder.append("joynr::MetaTypeRegistrar& registrar = joynr::MetaTypeRegistrar::instance();");
          _builder.newLine();
        }
      }
      {
        for(final Object typeobj : typeObjs) {
          _builder.append("\t\t");
          final FType datatype = ((FType) typeobj);
          _builder.newLineIfNotEmpty();
          _builder.newLine();
          _builder.append("\t\t");
          _builder.append("// Register metatype ");
          String _mappedDatatype = this._joynrCppGeneratorExtensions.getMappedDatatype(datatype);
          _builder.append(_mappedDatatype, "		");
          _builder.newLineIfNotEmpty();
          {
            boolean _isEnum = this._joynrCppGeneratorExtensions.isEnum(datatype);
            if (_isEnum) {
              _builder.append("\t\t");
              _builder.append("{");
              _builder.newLine();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("qRegisterMetaType<");
              String _enumContainer = this._joynrCppGeneratorExtensions.getEnumContainer(datatype);
              _builder.append(_enumContainer, "			");
              _builder.append(">();");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("int id = qRegisterMetaType<");
              String _mappedDatatype_1 = this._joynrCppGeneratorExtensions.getMappedDatatype(datatype);
              _builder.append(_mappedDatatype_1, "			");
              _builder.append(">();");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("registrar.registerEnumMetaType<");
              String _enumContainer_1 = this._joynrCppGeneratorExtensions.getEnumContainer(datatype);
              _builder.append(_enumContainer_1, "			");
              _builder.append(">();");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("QJson::Serializer::registerEnum(id, ");
              String _enumContainer_2 = this._joynrCppGeneratorExtensions.getEnumContainer(datatype);
              _builder.append(_enumContainer_2, "			");
              _builder.append("::staticMetaObject.enumerator(0));");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("}");
              _builder.newLine();
            } else {
              _builder.append("\t\t");
              _builder.append("qRegisterMetaType<");
              String _mappedDatatype_2 = this._joynrCppGeneratorExtensions.getMappedDatatype(datatype);
              _builder.append(_mappedDatatype_2, "		");
              _builder.append(">(\"");
              String _mappedDatatype_3 = this._joynrCppGeneratorExtensions.getMappedDatatype(datatype);
              _builder.append(_mappedDatatype_3, "		");
              _builder.append("\");");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("registrar.registerMetaType<");
              String _mappedDatatype_4 = this._joynrCppGeneratorExtensions.getMappedDatatype(datatype);
              _builder.append(_mappedDatatype_4, "		");
              _builder.append(">();");
              _builder.newLineIfNotEmpty();
            }
          }
        }
      }
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("static const QString INTERFACE_NAME(\"");
      String _packagePathWithoutJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithoutJoynrPrefix(serviceInterface, "/");
      _builder.append(_packagePathWithoutJoynrPrefix, "	");
      _builder.append("/");
      String _lowerCase = interfaceName.toLowerCase();
      _builder.append(_lowerCase, "	");
      _builder.append("\");");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("const QString I");
      _builder.append(interfaceName, "	");
      _builder.append("Base::getInterfaceName()");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("{");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("return INTERFACE_NAME;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("\t");
      String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(serviceInterface);
      _builder.append(_namespaceEnder, "	");
      _builder.newLineIfNotEmpty();
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
}