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

io.joynr.generator.cpp.util.InterfaceSubscriptionUtil Maven / Gradle / Ivy

package io.joynr.generator.cpp.util;

import com.google.inject.Inject;
import io.joynr.generator.templates.util.AttributeUtil;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.NamingUtil;
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.FInterface;

@SuppressWarnings("all")
public class InterfaceSubscriptionUtil {
  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;

  @Inject
  @Extension
  private AttributeUtil _attributeUtil;

  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;

  public CharSequence produceSubscribeToAttributeComments(final FAttribute attribute) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief creates a new subscription to attribute ");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(attribute));
    _builder.append(_firstUpper, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* @param subscriptionListener The listener callback providing methods to call on publication and failure");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @param subscriptionQos The subscription quality of service settings");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @return a future representing the result (subscription id) as string. It provides methods to wait for");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* completion, to get the subscription id or the request status object. The subscription id will be available");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* when the subscription is successfully registered at the provider.");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceUpdateAttributeSubscriptionComments(final FAttribute attribute) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief updates an existing subscription to attribute ");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(attribute));
    _builder.append(_firstUpper, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* @param subscriptionListener The listener callback providing methods to call on publication and failure");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @param subscriptionQos The subscription quality of service settings");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @param subscriptionId The subscription id returned earlier on creation of the subscription");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @return a future representing the result (subscription id) as string. It provides methods to wait for");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* completion, to get the subscription id or the request status object. The subscription id will be available");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* when the subscription is successfully registered at the provider.");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceUnsubscribeFromAttributeComments(final FAttribute attribute) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief unsubscribes from attribute ");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(attribute));
    _builder.append(_firstUpper, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* @param subscriptionId The subscription id returned earlier on creation of the subscription");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceSubscribeToBroadcastComments(final FBroadcast broadcast) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief subscribes to ");
    {
      boolean _isSelective = broadcast.isSelective();
      if (_isSelective) {
        _builder.append("selective ");
      }
    }
    _builder.append("broadcast ");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(broadcast));
    _builder.append(_firstUpper, " ");
    {
      boolean _isSelective_1 = broadcast.isSelective();
      if (_isSelective_1) {
        _builder.append(" with filter parameters");
        _builder.newLineIfNotEmpty();
        _builder.append(" ");
        _builder.append("* @param filterParameters The filter parameters for selection of suitable broadcasts");
      }
    }
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* @param subscriptionListener The listener callback providing methods to call on publication and failure");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @param subscriptionQos The subscription quality of service settings");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @return a future representing the result (subscription id) as string. It provides methods to wait for");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* completion, to get the subscription id or the request status object. The subscription id will be available");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* when the subscription is successfully registered at the provider.");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceUpdateBroadcastSubscriptionComments(final FBroadcast broadcast) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief updates an existing subscription to ");
    {
      boolean _isSelective = broadcast.isSelective();
      if (_isSelective) {
        _builder.append("selective ");
      }
    }
    _builder.append("broadcast ");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(broadcast));
    _builder.append(_firstUpper, " ");
    {
      boolean _isSelective_1 = broadcast.isSelective();
      if (_isSelective_1) {
        _builder.append(" with filter parameters");
        _builder.newLineIfNotEmpty();
        _builder.append(" ");
        _builder.append("* @param filterParameters The filter parameters for selection of suitable broadcasts");
      }
    }
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* @param subscriptionListener The listener callback providing methods to call on publication and failure");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @param subscriptionQos The subscription quality of service settings");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @param subscriptionId The subscription id returned earlier on creation of the subscription");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @return a future representing the result (subscription id) as string. It provides methods to wait for");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* completion, to get the subscription id or the request status object. The subscription id will be available");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* when the subscription is successfully updated at the provider.");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceUnsubscribeFromBroadcastComments(final FBroadcast broadcast) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief unsubscribes from broadcast ");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(broadcast));
    _builder.append(_firstUpper, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("* @param subscriptionId The subscription id returned earlier on creation of the subscription");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceSubscribeToAttributeSignature(final FAttribute attribute, final boolean updateSubscription, final String className, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String returnType = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
    _builder.newLineIfNotEmpty();
    _builder.append("std::shared_ptr> ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("subscribeTo");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(attribute));
    _builder.append(_firstUpper);
    _builder.append("(");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("std::shared_ptr > subscriptionListener,");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("std::shared_ptr subscriptionQos");
    {
      if (updateSubscription) {
        _builder.append(",");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t\t");
        _builder.append("const std::string& subscriptionId");
      }
    }
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  public CharSequence produceSubscribeToAttributeSignature(final FAttribute attribute, final boolean generateVersion) {
    return this.produceSubscribeToAttributeSignature(attribute, false, null, generateVersion);
  }

  public CharSequence produceSubscribeToAttributeSignature(final FAttribute attribute, final String className, final boolean generateVersion) {
    return this.produceSubscribeToAttributeSignature(attribute, false, className, generateVersion);
  }

  public CharSequence produceUpdateAttributeSubscriptionSignature(final FAttribute attribute, final boolean generateVersion) {
    return this.produceSubscribeToAttributeSignature(attribute, true, null, generateVersion);
  }

  public CharSequence produceUpdateAttributeSubscriptionSignature(final FAttribute attribute, final String className, final boolean generateVersion) {
    return this.produceSubscribeToAttributeSignature(attribute, true, className, generateVersion);
  }

  public CharSequence produceUnsubscribeFromAttributeSignature(final FAttribute attribute, final String className) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("void ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("unsubscribeFrom");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(attribute));
    _builder.append(_firstUpper);
    _builder.append("(const std::string& subscriptionId)");
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  public CharSequence produceUnsubscribeFromAttributeSignature(final FAttribute attribute) {
    return this.produceUnsubscribeFromAttributeSignature(attribute, null);
  }

  public CharSequence produceSubscribeToBroadcastSignature(final FBroadcast broadcast, final FInterface serviceInterface, final boolean updateSubscription, final String className, final boolean hTemplate, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String returnTypes = this._cppStdTypeUtil.getCommaSeparatedOutputParameterTypes(broadcast, generateVersion);
    _builder.newLineIfNotEmpty();
    _builder.append("std::shared_ptr> ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("subscribeTo");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(broadcast));
    _builder.append(_firstUpper);
    _builder.append("Broadcast(");
    _builder.newLineIfNotEmpty();
    {
      if (updateSubscription) {
        _builder.append("\t\t\t");
        _builder.append("const std::string& subscriptionId,");
        _builder.newLine();
      }
    }
    {
      boolean _isSelective = broadcast.isSelective();
      if (_isSelective) {
        _builder.append("\t\t\t");
        _builder.append("const ");
        String _firstUpper_1 = StringExtensions.toFirstUpper(serviceInterface.getName());
        _builder.append(_firstUpper_1, "\t\t\t");
        String _firstUpper_2 = StringExtensions.toFirstUpper(this._namingUtil.joynrName(broadcast));
        _builder.append(_firstUpper_2, "\t\t\t");
        _builder.append("BroadcastFilterParameters& filterParameters,");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t\t");
        _builder.append("std::shared_ptr> subscriptionListener,");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t\t");
        _builder.append("std::shared_ptr subscriptionQos");
        _builder.newLine();
      } else {
        _builder.append("\t\t\t");
        _builder.append("std::shared_ptr> subscriptionListener,");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t\t");
        _builder.append("std::shared_ptr subscriptionQos,");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("const std::vector& partitions");
        {
          if (hTemplate) {
            _builder.append(" = std::vector()");
          }
        }
      }
    }
    _builder.newLineIfNotEmpty();
    _builder.append(")");
    _builder.newLine();
    return _builder;
  }

  public CharSequence produceSubscribeToBroadcastSignature(final FBroadcast broadcast, final FInterface serviceInterface, final boolean generateVersion) {
    return this.produceSubscribeToBroadcastSignature(broadcast, serviceInterface, false, null, false, generateVersion);
  }

  public CharSequence produceSubscribeToBroadcastSignature(final FBroadcast broadcast, final FInterface serviceInterface, final boolean hTemplate, final boolean generateVersion) {
    return this.produceSubscribeToBroadcastSignature(broadcast, serviceInterface, false, null, hTemplate, generateVersion);
  }

  public CharSequence produceSubscribeToBroadcastSignature(final FBroadcast broadcast, final FInterface serviceInterface, final String className, final boolean generateVersion) {
    return this.produceSubscribeToBroadcastSignature(broadcast, serviceInterface, false, className, false, generateVersion);
  }

  public CharSequence produceUpdateBroadcastSubscriptionSignature(final FBroadcast broadcast, final FInterface serviceInterface, final boolean generateVersion) {
    return this.produceSubscribeToBroadcastSignature(broadcast, serviceInterface, true, null, false, generateVersion);
  }

  public CharSequence produceUpdateBroadcastSubscriptionSignature(final FBroadcast broadcast, final FInterface serviceInterface, final boolean hTemplate, final boolean generateVersion) {
    return this.produceSubscribeToBroadcastSignature(broadcast, serviceInterface, true, null, hTemplate, generateVersion);
  }

  public CharSequence produceUpdateBroadcastSubscriptionSignature(final FBroadcast broadcast, final FInterface serviceInterface, final String className, final boolean generateVersion) {
    return this.produceSubscribeToBroadcastSignature(broadcast, serviceInterface, true, className, false, generateVersion);
  }

  public CharSequence produceUnsubscribeFromBroadcastSignature(final FBroadcast broadcast, final String className) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("void ");
    {
      if ((className != null)) {
        _builder.append(className);
        _builder.append("::");
      }
    }
    _builder.append("unsubscribeFrom");
    String _firstUpper = StringExtensions.toFirstUpper(this._namingUtil.joynrName(broadcast));
    _builder.append(_firstUpper);
    _builder.append("Broadcast(const std::string& subscriptionId)");
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  public CharSequence produceUnsubscribeFromBroadcastSignature(final FBroadcast broadcast) {
    return this.produceUnsubscribeFromBroadcastSignature(broadcast, null);
  }

  public CharSequence produceSubscribeUnsubscribeMethodDeclarations(final FInterface serviceInterface, final boolean pure, final boolean generateVersion) {
    return this.produceSubscribeUnsubscribeMethodDeclarations(serviceInterface, pure, false, generateVersion);
  }

  public CharSequence produceSubscribeUnsubscribeMethodDeclarations(final FInterface serviceInterface, final boolean pure, final boolean hTemplate, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    {
      final Function1 _function = new Function1() {
        @Override
        public Boolean apply(final FAttribute attribute) {
          return Boolean.valueOf(InterfaceSubscriptionUtil.this._attributeUtil.isNotifiable(attribute));
        }
      };
      Iterable _filter = IterableExtensions.filter(this._interfaceUtil.getAttributes(serviceInterface), _function);
      for(final FAttribute attribute : _filter) {
        CharSequence _produceSubscribeToAttributeComments = this.produceSubscribeToAttributeComments(attribute);
        _builder.append(_produceSubscribeToAttributeComments);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        CharSequence _produceSubscribeToAttributeSignature = this.produceSubscribeToAttributeSignature(attribute, generateVersion);
        _builder.append(_produceSubscribeToAttributeSignature);
        _builder.append(" ");
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        CharSequence _produceUpdateAttributeSubscriptionComments = this.produceUpdateAttributeSubscriptionComments(attribute);
        _builder.append(_produceUpdateAttributeSubscriptionComments);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        CharSequence _produceUpdateAttributeSubscriptionSignature = this.produceUpdateAttributeSubscriptionSignature(attribute, generateVersion);
        _builder.append(_produceUpdateAttributeSubscriptionSignature);
        _builder.append(" ");
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        CharSequence _produceUnsubscribeFromAttributeComments = this.produceUnsubscribeFromAttributeComments(attribute);
        _builder.append(_produceUnsubscribeFromAttributeComments);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        CharSequence _produceUnsubscribeFromAttributeSignature = this.produceUnsubscribeFromAttributeSignature(attribute);
        _builder.append(_produceUnsubscribeFromAttributeSignature);
        _builder.append(" ");
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
      }
    }
    {
      EList _broadcasts = serviceInterface.getBroadcasts();
      for(final FBroadcast broadcast : _broadcasts) {
        CharSequence _produceSubscribeToBroadcastComments = this.produceSubscribeToBroadcastComments(broadcast);
        _builder.append(_produceSubscribeToBroadcastComments);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        CharSequence _produceSubscribeToBroadcastSignature = this.produceSubscribeToBroadcastSignature(broadcast, serviceInterface, hTemplate, generateVersion);
        _builder.append(_produceSubscribeToBroadcastSignature);
        _builder.append(" ");
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        CharSequence _produceUpdateBroadcastSubscriptionComments = this.produceUpdateBroadcastSubscriptionComments(broadcast);
        _builder.append(_produceUpdateBroadcastSubscriptionComments);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        CharSequence _produceUpdateBroadcastSubscriptionSignature = this.produceUpdateBroadcastSubscriptionSignature(broadcast, serviceInterface, hTemplate, generateVersion);
        _builder.append(_produceUpdateBroadcastSubscriptionSignature);
        _builder.append(" ");
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        CharSequence _produceUnsubscribeFromBroadcastComments = this.produceUnsubscribeFromBroadcastComments(broadcast);
        _builder.append(_produceUnsubscribeFromBroadcastComments);
        _builder.newLineIfNotEmpty();
        {
          if (pure) {
            _builder.append("virtual ");
          }
        }
        CharSequence _produceUnsubscribeFromBroadcastSignature = this.produceUnsubscribeFromBroadcastSignature(broadcast);
        _builder.append(_produceUnsubscribeFromBroadcastSignature);
        _builder.append(" ");
        {
          if (pure) {
            _builder.append("= 0");
          } else {
            _builder.append("override");
          }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
      }
    }
    return _builder;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy