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

io.joynr.generator.cpp.provider.InterfaceProviderCppTemplate Maven / Gradle / Ivy

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

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

@SuppressWarnings("all")
public class InterfaceProviderCppTemplate implements InterfaceTemplate {
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  @Inject
  @Extension
  private QtTypeUtil _qtTypeUtil;
  
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  public CharSequence generate(final FInterface serviceInterface) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence _warning = this._templateBase.warning();
    _builder.append(_warning, "");
    _builder.newLineIfNotEmpty();
    final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(serviceInterface);
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
    _builder.append(_packagePathWithJoynrPrefix, "");
    _builder.append("/");
    _builder.append(interfaceName, "");
    _builder.append("Provider.h\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"joynr/InterfaceRegistrar.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/MetaTypeRegistrar.h\"");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
    _builder.append(_packagePathWithJoynrPrefix_1, "");
    _builder.append("/");
    _builder.append(interfaceName, "");
    _builder.append("RequestInterpreter.h\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"joynr/RequestStatus.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/TypeUtil.h\"");
    _builder.newLine();
    {
      Set _requiredIncludesFor = this._qtTypeUtil.getRequiredIncludesFor(serviceInterface);
      for(final String parameterType : _requiredIncludesFor) {
        _builder.append("#include ");
        _builder.append(parameterType, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(serviceInterface);
    _builder.append(_namespaceStarter, "");
    _builder.newLineIfNotEmpty();
    _builder.append(interfaceName, "");
    _builder.append("Provider::");
    _builder.append(interfaceName, "");
    _builder.append("Provider()");
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("// Register a request interpreter to interpret requests to this interface");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("joynr::InterfaceRegistrar::instance().registerRequestInterpreter<");
    _builder.append(interfaceName, "\t");
    _builder.append("RequestInterpreter>(INTERFACE_NAME());");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    final Iterable typeObjs = this._joynrCppGeneratorExtensions.getAllComplexAndEnumTypes(serviceInterface);
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      boolean _isEmpty = IterableExtensions.isEmpty(typeObjs);
      boolean _not = (!_isEmpty);
      if (_not) {
        _builder.append("\t");
        _builder.append("joynr::MetaTypeRegistrar& registrar = joynr::MetaTypeRegistrar::instance();");
        _builder.newLine();
      }
    }
    {
      for(final Object typeobj : typeObjs) {
        _builder.append("\t");
        final FType datatype = ((FType) typeobj);
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("// Register metatype ");
        String _typeName = this._qtTypeUtil.getTypeName(datatype);
        _builder.append(_typeName, "\t");
        _builder.newLineIfNotEmpty();
        {
          boolean _isEnum = this._joynrCppGeneratorExtensions.isEnum(datatype);
          if (_isEnum) {
            _builder.append("\t");
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            String _enumContainer = this._joynrCppGeneratorExtensions.getEnumContainer(datatype);
            String _registerMetatypeStatement = this._qtTypeUtil.registerMetatypeStatement(_enumContainer);
            _builder.append(_registerMetatypeStatement, "\t\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("int id = ");
            String _typeName_1 = this._qtTypeUtil.getTypeName(datatype);
            String _registerMetatypeStatement_1 = this._qtTypeUtil.registerMetatypeStatement(_typeName_1);
            _builder.append(_registerMetatypeStatement_1, "\t\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("registrar.registerEnumMetaType<");
            String _enumContainer_1 = this._joynrCppGeneratorExtensions.getEnumContainer(datatype);
            _builder.append(_enumContainer_1, "\t\t");
            _builder.append(">();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("QJson::Serializer::registerEnum(id, ");
            String _enumContainer_2 = this._joynrCppGeneratorExtensions.getEnumContainer(datatype);
            _builder.append(_enumContainer_2, "\t\t");
            _builder.append("::staticMetaObject.enumerator(0));");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
          } else {
            _builder.append("\t");
            String _typeName_2 = this._qtTypeUtil.getTypeName(datatype);
            String _registerMetatypeStatement_2 = this._qtTypeUtil.registerMetatypeStatement(_typeName_2);
            _builder.append(_registerMetatypeStatement_2, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("registrar.registerMetaType<");
            String _typeName_3 = this._qtTypeUtil.getTypeName(datatype);
            _builder.append(_typeName_3, "\t");
            _builder.append(">();");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append(interfaceName, "");
    _builder.append("Provider::~");
    _builder.append(interfaceName, "");
    _builder.append("Provider()");
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("// Unregister the request interpreter");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("joynr::InterfaceRegistrar::instance().unregisterRequestInterpreter(");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("INTERFACE_NAME()");
    _builder.newLine();
    _builder.append("\t");
    _builder.append(");");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("const std::string& ");
    _builder.append(interfaceName, "");
    _builder.append("Provider::INTERFACE_NAME()");
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static const std::string INTERFACE_NAME(\"");
    String _packagePathWithoutJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithoutJoynrPrefix(serviceInterface, "/");
    _builder.append(_packagePathWithoutJoynrPrefix, "\t");
    _builder.append("/");
    String _lowerCase = interfaceName.toLowerCase();
    _builder.append(_lowerCase, "\t");
    _builder.append("\");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("return INTERFACE_NAME;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(serviceInterface);
    _builder.append(_namespaceEnder, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}