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

io.joynr.generator.cpp.communicationmodel.InterfaceHTemplate 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.InterfaceUtil;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import java.util.HashSet;
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.FInterface;
import org.franca.core.franca.FType;

@SuppressWarnings("all")
public class InterfaceHTemplate {
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;
  
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  public CharSequence generate(final FInterface serviceInterface) {
    CharSequence _xblockexpression = null;
    {
      final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(serviceInterface);
      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();
      StringConcatenation _builder = new StringConcatenation();
      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();
      {
        HashSet _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));
                  _builder.append(_namespaceStarter, "");
                  _builder.append(" class ");
                  String _joynrName = this._joynrCppGeneratorExtensions.joynrName(((FType) datatype));
                  _builder.append(_joynrName, "");
                  _builder.append("; ");
                  String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(((FType) datatype));
                  _builder.append(_namespaceEnder, "");
                  _builder.newLineIfNotEmpty();
                } else {
                  _builder.append("#include \"");
                  String _includeOf = this._joynrCppGeneratorExtensions.getIncludeOf(((FType) datatype));
                  _builder.append(_includeOf, "");
                  _builder.append("\"");
                  _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 {\t");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("class RequestStatus;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("template  class Future;\t\t");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("template  class ICallback;\t\t");
      _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, "	");
      _builder.append("Base();");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("virtual ~I");
      _builder.append(interfaceName, "	");
      _builder.append("Base() { }");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("// Visual C++ does not export static const variables from DLLs");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("// This getter is used instead");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("static const QString getInterfaceName();");
      _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("*/\t\t");
      _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("    ");
      _builder.append("virtual ~I");
      _builder.append(interfaceName, "    ");
      _builder.append("Sync(){ }");
      _builder.newLineIfNotEmpty();
      _builder.append("    ");
      CharSequence _produceSyncGetters = this._interfaceUtil.produceSyncGetters(serviceInterface, true);
      _builder.append(_produceSyncGetters, "    ");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceSyncSetters = this._interfaceUtil.produceSyncSetters(serviceInterface, true);
      _builder.append(_produceSyncSetters, "	");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceSyncMethods = this._interfaceUtil.produceSyncMethods(serviceInterface, true);
      _builder.append(_produceSyncMethods, "	");
      _builder.newLineIfNotEmpty();
      _builder.append("};");
      _builder.newLine();
      _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("*/\t\t");
      _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("    ");
      _builder.append("virtual ~I");
      _builder.append(interfaceName, "    ");
      _builder.append("Async(){ }");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceAsyncGetters = this._interfaceUtil.produceAsyncGetters(serviceInterface, true);
      _builder.append(_produceAsyncGetters, "	");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceAsyncSetters = this._interfaceUtil.produceAsyncSetters(serviceInterface, true);
      _builder.append(_produceAsyncSetters, "	");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _produceAsyncMethods = this._interfaceUtil.produceAsyncMethods(serviceInterface, true);
      _builder.append(_produceAsyncMethods, "	");
      _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("    ");
      _builder.append("virtual ~I");
      _builder.append(interfaceName, "    ");
      _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();
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "	");
          _builder.append("Sync::get");
          _builder.append(attributeName, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "	");
          _builder.append("Async::get");
          _builder.append(attributeName, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "	");
          _builder.append("Sync::set");
          _builder.append(attributeName, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "	");
          _builder.append("Async::set");
          _builder.append(attributeName, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      {
        HashSet _uniqueMethodNames = this._joynrCppGeneratorExtensions.getUniqueMethodNames(serviceInterface);
        for(final String methodName : _uniqueMethodNames) {
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "	");
          _builder.append("Sync::");
          _builder.append(methodName, "	");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("using I");
          _builder.append(interfaceName, "	");
          _builder.append("Async::");
          _builder.append(methodName, "	");
          _builder.append(";");
          _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();
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
}