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

io.joynr.generator.cpp.proxy.InterfaceProxyHTemplate Maven / Gradle / Ivy

package io.joynr.generator.cpp.proxy;

import com.google.inject.Inject;
import io.joynr.generator.cpp.util.CppStdTypeUtil;
import io.joynr.generator.cpp.util.InterfaceSubscriptionUtil;
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.InterfaceUtil;
import io.joynr.generator.templates.util.NamingUtil;
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.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.FBroadcast;
import org.franca.core.franca.FMethod;

@SuppressWarnings("all")
public class InterfaceProxyHTemplate extends InterfaceTemplate {
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;

  @Inject
  @Extension
  private TemplateBase _templateBase;

  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;

  @Inject
  @Extension
  private InterfaceSubscriptionUtil _interfaceSubscriptionUtil;

  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private AttributeUtil _attributeUtil;

  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;

  @Override
  public CharSequence generate(final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
    _builder.newLineIfNotEmpty();
    final String className = (interfaceName + "Proxy");
    _builder.newLineIfNotEmpty();
    final String asyncClassName = (interfaceName + "AsyncProxy");
    _builder.newLineIfNotEmpty();
    final String syncClassName = (interfaceName + "SyncProxy");
    _builder.newLineIfNotEmpty();
    String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "_", generateVersion);
    String _plus = ("GENERATED_INTERFACE_" + _packagePathWithJoynrPrefix);
    String _plus_1 = (_plus + 
      "_");
    String _plus_2 = (_plus_1 + interfaceName);
    final String headerGuard = (_plus_2 + "Proxy_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();
    _builder.append("#include \"joynr/PrivateCopyAssign.h\"");
    _builder.newLine();
    {
      Set _addElements = this._cppStdTypeUtil.addElements(this._cppStdTypeUtil.getDataTypeIncludesFor(this.francaIntf, generateVersion), this._cppStdTypeUtil.getIncludeForString());
      for(final String parameterType : _addElements) {
        _builder.append("#include ");
        _builder.append(parameterType);
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("#include ");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "/", generateVersion);
    _builder.append(_packagePathWithJoynrPrefix_1);
    _builder.append("/");
    _builder.append(syncClassName);
    _builder.append(".h\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix_2 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "/", generateVersion);
    _builder.append(_packagePathWithJoynrPrefix_2);
    _builder.append("/");
    _builder.append(asyncClassName);
    _builder.append(".h\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix_3 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "/", generateVersion);
    _builder.append(_packagePathWithJoynrPrefix_3);
    _builder.append("/I");
    _builder.append(interfaceName);
    _builder.append(".h\"");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("#ifdef _MSC_VER");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("// Visual C++ gives a warning which is caused by diamond inheritance, but this is");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("// not relevant when using pure virtual methods:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("// http://msdn.microsoft.com/en-us/library/6b3sy7ae(v=vs.80).aspx");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("#pragma warning( disable : 4250 )");
    _builder.newLine();
    _builder.append("#endif");
    _builder.newLine();
    _builder.newLine();
    String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.francaIntf, generateVersion);
    _builder.append(_namespaceStarter);
    _builder.newLineIfNotEmpty();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief Proxy class for interface ");
    _builder.append(interfaceName, " ");
    _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 ");
    _builder.append(className);
    _builder.append(" : virtual public I");
    _builder.append(interfaceName);
    _builder.append(", virtual public ");
    _builder.append(syncClassName);
    _builder.append(", virtual public ");
    _builder.append(asyncClassName);
    _builder.append(" {");
    _builder.newLineIfNotEmpty();
    _builder.append("public:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* @brief Parameterized constructor");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* @param connectorFactory The connector factory");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* @param domain The provider domain");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* @param qosSettings The quality of service settings");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("\t");
    _builder.append(className, "\t");
    _builder.append("(");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("std::weak_ptr runtime,");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("std::shared_ptr connectorFactory,");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("const std::string& domain,");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("const joynr::MessagingQos& qosSettings");
    _builder.newLine();
    _builder.append("\t");
    _builder.append(");");
    _builder.newLine();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FAttribute attribute) {
          return Boolean.valueOf(InterfaceProxyHTemplate.this._attributeUtil.isNotifiable(attribute));
        }
      };
      Iterable _filter = IterableExtensions.filter(this._interfaceUtil.getAttributes(this.francaIntf), _function);
      for(final FAttribute attribute : _filter) {
        _builder.append("\t");
        String attributeName = this._namingUtil.joynrName(attribute);
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @brief unsubscribes from attribute ");
        String _firstUpper = StringExtensions.toFirstUpper(attributeName);
        _builder.append(_firstUpper, "\t ");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @param subscriptionId The subscription id returned earlier on creation of the subscription");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("void unsubscribeFrom");
        String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
        _builder.append(_firstUpper_1, "\t");
        _builder.append("(const std::string &subscriptionId) override {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append(className, "\t\t");
        _builder.append("Base::unsubscribeFrom");
        String _firstUpper_2 = StringExtensions.toFirstUpper(attributeName);
        _builder.append(_firstUpper_2, "\t\t");
        _builder.append("(subscriptionId);");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        CharSequence _produceSubscribeToAttributeComments = this._interfaceSubscriptionUtil.produceSubscribeToAttributeComments(attribute);
        _builder.append(_produceSubscribeToAttributeComments, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        CharSequence _produceSubscribeToAttributeSignature = this._interfaceSubscriptionUtil.produceSubscribeToAttributeSignature(attribute, generateVersion);
        _builder.append(_produceSubscribeToAttributeSignature, "\t");
        _builder.append(" override {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("return ");
        _builder.append(className, "\t\t");
        _builder.append("Base::subscribeTo");
        String _firstUpper_3 = StringExtensions.toFirstUpper(attributeName);
        _builder.append(_firstUpper_3, "\t\t");
        _builder.append("(");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionListener,");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionQos);");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        CharSequence _produceUpdateAttributeSubscriptionComments = this._interfaceSubscriptionUtil.produceUpdateAttributeSubscriptionComments(attribute);
        _builder.append(_produceUpdateAttributeSubscriptionComments, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        CharSequence _produceUpdateAttributeSubscriptionSignature = this._interfaceSubscriptionUtil.produceUpdateAttributeSubscriptionSignature(attribute, generateVersion);
        _builder.append(_produceUpdateAttributeSubscriptionSignature, "\t");
        _builder.append(" override{");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("return ");
        _builder.append(className, "\t\t");
        _builder.append("Base::subscribeTo");
        String _firstUpper_4 = StringExtensions.toFirstUpper(attributeName);
        _builder.append(_firstUpper_4, "\t\t");
        _builder.append("(");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionListener,");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionQos,");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionId);");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
      }
    }
    _builder.newLine();
    {
      EList _broadcasts = this.francaIntf.getBroadcasts();
      for(final FBroadcast broadcast : _broadcasts) {
        _builder.append("\t");
        String broadcastName = this._namingUtil.joynrName(broadcast);
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @brief unsubscribes from broadcast ");
        String _firstUpper_5 = StringExtensions.toFirstUpper(broadcastName);
        _builder.append(_firstUpper_5, "\t ");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @param subscriptionId The subscription id returned earlier on creation of the subscription");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("void unsubscribeFrom");
        String _firstUpper_6 = StringExtensions.toFirstUpper(broadcastName);
        _builder.append(_firstUpper_6, "\t");
        _builder.append("Broadcast(const std::string &subscriptionId) override {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append(className, "\t\t");
        _builder.append("Base::unsubscribeFrom");
        String _firstUpper_7 = StringExtensions.toFirstUpper(broadcastName);
        _builder.append(_firstUpper_7, "\t\t");
        _builder.append("Broadcast(subscriptionId);");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        CharSequence _produceSubscribeToBroadcastComments = this._interfaceSubscriptionUtil.produceSubscribeToBroadcastComments(broadcast);
        _builder.append(_produceSubscribeToBroadcastComments, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        CharSequence _produceSubscribeToBroadcastSignature = this._interfaceSubscriptionUtil.produceSubscribeToBroadcastSignature(broadcast, this.francaIntf, true, generateVersion);
        _builder.append(_produceSubscribeToBroadcastSignature, "\t");
        _builder.append(" override {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("return ");
        _builder.append(className, "\t\t");
        _builder.append("Base::subscribeTo");
        String _firstUpper_8 = StringExtensions.toFirstUpper(broadcastName);
        _builder.append(_firstUpper_8, "\t\t");
        _builder.append("Broadcast(");
        {
          boolean _isSelective = broadcast.isSelective();
          if (_isSelective) {
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("filterParameters,");
          }
        }
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionListener,");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionQos");
        {
          boolean _isSelective_1 = broadcast.isSelective();
          boolean _not = (!_isSelective_1);
          if (_not) {
            _builder.append(",");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("partitions");
          }
        }
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append(");");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        CharSequence _produceUpdateBroadcastSubscriptionComments = this._interfaceSubscriptionUtil.produceUpdateBroadcastSubscriptionComments(broadcast);
        _builder.append(_produceUpdateBroadcastSubscriptionComments, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        CharSequence _produceUpdateBroadcastSubscriptionSignature = this._interfaceSubscriptionUtil.produceUpdateBroadcastSubscriptionSignature(broadcast, this.francaIntf, true, generateVersion);
        _builder.append(_produceUpdateBroadcastSubscriptionSignature, "\t");
        _builder.append(" override {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("return ");
        _builder.append(className, "\t\t");
        _builder.append("Base::subscribeTo");
        String _firstUpper_9 = StringExtensions.toFirstUpper(broadcastName);
        _builder.append(_firstUpper_9, "\t\t");
        _builder.append("Broadcast(");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionId,");
        _builder.newLine();
        {
          boolean _isSelective_2 = broadcast.isSelective();
          if (_isSelective_2) {
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("filterParameters,");
            _builder.newLine();
          }
        }
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionListener,");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("\t\t\t\t");
        _builder.append("subscriptionQos");
        {
          boolean _isSelective_3 = broadcast.isSelective();
          boolean _not_1 = (!_isSelective_3);
          if (_not_1) {
            _builder.append(",");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t\t\t");
            _builder.append("partitions");
          }
        }
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append(");");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
      }
    }
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/** @brief Destructor */");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("~");
    _builder.append(className, "\t");
    _builder.append("() override = default;");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("// attributes");
    _builder.newLine();
    {
      EList _attributes = this._interfaceUtil.getAttributes(this.francaIntf);
      for(final FAttribute attribute_1 : _attributes) {
        _builder.append("\t");
        String attributeName_1 = this._namingUtil.joynrName(attribute_1);
        _builder.newLineIfNotEmpty();
        {
          boolean _isReadable = this._attributeUtil.isReadable(attribute_1);
          if (_isReadable) {
            _builder.append("\t");
            _builder.append("using ");
            _builder.append(asyncClassName, "\t");
            _builder.append("::get");
            String _firstUpper_10 = StringExtensions.toFirstUpper(attributeName_1);
            _builder.append(_firstUpper_10, "\t");
            _builder.append("Async;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("using ");
            _builder.append(syncClassName, "\t");
            _builder.append("::get");
            String _firstUpper_11 = StringExtensions.toFirstUpper(attributeName_1);
            _builder.append(_firstUpper_11, "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
          }
        }
        {
          boolean _isWritable = this._attributeUtil.isWritable(attribute_1);
          if (_isWritable) {
            _builder.append("\t");
            _builder.append("using ");
            _builder.append(asyncClassName, "\t");
            _builder.append("::set");
            String _firstUpper_12 = StringExtensions.toFirstUpper(attributeName_1);
            _builder.append(_firstUpper_12, "\t");
            _builder.append("Async;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("using ");
            _builder.append(syncClassName, "\t");
            _builder.append("::set");
            String _firstUpper_13 = StringExtensions.toFirstUpper(attributeName_1);
            _builder.append(_firstUpper_13, "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.newLine();
    {
      final Function1 _function_1 = new Function1() {
        @Override
        public Boolean apply(final FMethod it) {
          boolean _isFireAndForget = it.isFireAndForget();
          return Boolean.valueOf((!_isFireAndForget));
        }
      };
      HashSet _uniqueMethodNames = this._interfaceUtil.getUniqueMethodNames(IterableExtensions.filter(this._interfaceUtil.getMethods(this.francaIntf), _function_1));
      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();
      }
    }
    {
      final Function1 _function_2 = new Function1() {
        @Override
        public Boolean apply(final FMethod it) {
          return Boolean.valueOf(it.isFireAndForget());
        }
      };
      HashSet _uniqueMethodNames_1 = this._interfaceUtil.getUniqueMethodNames(IterableExtensions.filter(this._interfaceUtil.getMethods(this.francaIntf), _function_2));
      for(final String methodName_1 : _uniqueMethodNames_1) {
        _builder.append("\t");
        _builder.append("using I");
        _builder.append(interfaceName, "\t");
        _builder.append("FireAndForget::");
        _builder.append(methodName_1, "\t");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
      }
    }
    _builder.append("private:");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("DISALLOW_COPY_AND_ASSIGN(");
    _builder.append(className, "\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.newLine();
    _builder.append("#endif // ");
    _builder.append(headerGuard);
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy