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

io.joynr.generator.cpp.provider.InterfaceProviderHTemplate 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.CppStdTypeUtil;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import io.joynr.generator.util.InterfaceTemplate;
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.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FArgument;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FBroadcast;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;

@SuppressWarnings("all")
public class InterfaceProviderHTemplate implements InterfaceTemplate {
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;
  
  public CharSequence generate(final FInterface serviceInterface) {
    StringConcatenation _builder = new StringConcatenation();
    final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(serviceInterface);
    _builder.newLineIfNotEmpty();
    String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "_");
    String _plus = ("GENERATED_INTERFACE_" + _packagePathWithJoynrPrefix);
    String _plus_1 = (_plus + 
      "_");
    String _plus_2 = (_plus_1 + interfaceName);
    String _plus_3 = (_plus_2 + "Provider_h");
    final String headerGuard = _plus_3.toUpperCase();
    _builder.newLineIfNotEmpty();
    CharSequence _warning = this._templateBase.warning();
    _builder.append(_warning, "");
    _builder.newLineIfNotEmpty();
    _builder.append("#ifndef ");
    _builder.append(headerGuard, "");
    _builder.newLineIfNotEmpty();
    _builder.append("#define ");
    _builder.append(headerGuard, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#include \"joynr/PrivateCopyAssign.h\"");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#include \"joynr/IJoynrProvider.h\"");
    _builder.newLine();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
    _builder.append(_packagePathWithJoynrPrefix_1, "");
    _builder.append("/I");
    _builder.append(interfaceName, "");
    _builder.append(".h\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#include \"joynr/DeclareMetatypeUtil.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/RequestCallerFactory.h\"");
    _builder.newLine();
    _builder.append("#include \"");
    String _packagePathWithJoynrPrefix_2 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
    _builder.append(_packagePathWithJoynrPrefix_2, "");
    _builder.append("/");
    _builder.append(interfaceName, "");
    _builder.append("RequestCaller.h\"");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      Set _requiredIncludesFor = this._cppStdTypeUtil.getRequiredIncludesFor(serviceInterface);
      for(final String parameterType : _requiredIncludesFor) {
        _builder.append("#include ");
        _builder.append(parameterType, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    String _dllExportIncludeStatement = this._joynrCppGeneratorExtensions.getDllExportIncludeStatement();
    _builder.append(_dllExportIncludeStatement, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(serviceInterface);
    _builder.append(_namespaceStarter, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("/** @brief Provider class for interface ");
    _builder.append(interfaceName, "");
    _builder.append(" */");
    _builder.newLineIfNotEmpty();
    _builder.append("class ");
    String _dllExportMacro = this._joynrCppGeneratorExtensions.getDllExportMacro();
    _builder.append(_dllExportMacro, "");
    _builder.append(" ");
    _builder.append(interfaceName, "");
    _builder.append("Provider : public virtual IJoynrProvider");
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/** @brief Default constructor */");
    _builder.newLine();
    _builder.append("\t");
    _builder.append(interfaceName, "\t");
    _builder.append("Provider();");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("//for each Attribute the provider needs setters, sync and async getters.");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("//They have default implementation for pushing Providers and can be overwritten by pulling Providers.");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/** @brief Destructor */");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("virtual ~");
    _builder.append(interfaceName, "\t");
    _builder.append("Provider();");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static const std::string& INTERFACE_NAME();");
    _builder.newLine();
    _builder.newLine();
    {
      EList _attributes = serviceInterface.getAttributes();
      boolean _isEmpty = _attributes.isEmpty();
      boolean _not = (!_isEmpty);
      if (_not) {
        _builder.append("\t");
        _builder.append("// attributes");
        _builder.newLine();
      }
    }
    {
      EList _attributes_1 = serviceInterface.getAttributes();
      for(final FAttribute attribute : _attributes_1) {
        _builder.append("\t");
        String attributeName = this._joynrCppGeneratorExtensions.joynrName(attribute);
        _builder.newLineIfNotEmpty();
        {
          boolean _isReadable = this._joynrCppGeneratorExtensions.isReadable(attribute);
          if (_isReadable) {
            _builder.append("\t");
            _builder.append("/**");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @brief Gets ");
            String _firstUpper = StringExtensions.toFirstUpper(attributeName);
            _builder.append(_firstUpper, "\t ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @param callbackFct A callback function to be called once the asynchronous computation has");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* finished. It must expect a request status object as well as the attribute value.");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @return the value of the attribute ");
            String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
            _builder.append(_firstUpper_1, "\t ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("virtual void get");
            String _firstUpper_2 = StringExtensions.toFirstUpper(attributeName);
            _builder.append(_firstUpper_2, "\t");
            _builder.append("(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("std::function onSuccess");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(") = 0;");
            _builder.newLine();
          }
        }
        {
          boolean _isWritable = this._joynrCppGeneratorExtensions.isWritable(attribute);
          if (_isWritable) {
            _builder.append("\t");
            _builder.append("/**");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @brief Sets ");
            String _firstUpper_3 = StringExtensions.toFirstUpper(attributeName);
            _builder.append(_firstUpper_3, "\t ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @param ");
            _builder.append(attributeName, "\t ");
            _builder.append(" the new value of the attribute");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @param callbackFct A callback function to be called once the asynchronous computation has");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* finished. It must expect a request status object.");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("virtual void set");
            String _firstUpper_4 = StringExtensions.toFirstUpper(attributeName);
            _builder.append(_firstUpper_4, "\t");
            _builder.append("(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("const ");
            String _typeName_1 = this._cppStdTypeUtil.getTypeName(attribute);
            _builder.append(_typeName_1, "\t\t\t");
            _builder.append("& ");
            _builder.append(attributeName, "\t\t\t");
            _builder.append(",");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("std::function onSuccess");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(") = 0;");
            _builder.newLine();
          }
        }
        {
          boolean _isNotifiable = this._joynrCppGeneratorExtensions.isNotifiable(attribute);
          if (_isNotifiable) {
            _builder.append("\t");
            _builder.append("/**");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @brief ");
            _builder.append(attributeName, "\t ");
            _builder.append("Changed must be called by a concrete provider");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* to signal attribute modifications. It is used to implement onchange");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* subscriptions.");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* @param ");
            _builder.append(attributeName, "\t ");
            _builder.append(" the new attribute value");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("virtual void ");
            _builder.append(attributeName, "\t");
            _builder.append("Changed(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("const ");
            String _typeName_2 = this._cppStdTypeUtil.getTypeName(attribute);
            _builder.append(_typeName_2, "\t\t\t");
            _builder.append("& ");
            _builder.append(attributeName, "\t\t\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(") = 0;");
            _builder.newLine();
          }
        }
        _builder.newLine();
      }
    }
    {
      EList _methods = serviceInterface.getMethods();
      boolean _isEmpty_1 = _methods.isEmpty();
      boolean _not_1 = (!_isEmpty_1);
      if (_not_1) {
        _builder.append("\t");
        _builder.append("// methods");
        _builder.newLine();
      }
    }
    {
      EList _methods_1 = serviceInterface.getMethods();
      for(final FMethod method : _methods_1) {
        _builder.append("\t");
        final String outputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstOutputParameterList(method);
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        final String inputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstInputParameterList(method);
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @brief Implementation of the Franca method ");
        String _joynrName = this._joynrCppGeneratorExtensions.joynrName(method);
        _builder.append(_joynrName, "\t ");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @param callbackFct A callback function to be called once the asynchronous computation has");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* finished. It must expect a request status object as well as the method out parameters.");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("virtual void ");
        String _joynrName_1 = this._joynrCppGeneratorExtensions.joynrName(method);
        _builder.append(_joynrName_1, "\t");
        _builder.append("(");
        _builder.newLineIfNotEmpty();
        {
          Iterable _inputParameters = this._joynrCppGeneratorExtensions.getInputParameters(method);
          boolean _isEmpty_2 = IterableExtensions.isEmpty(_inputParameters);
          boolean _not_2 = (!_isEmpty_2);
          if (_not_2) {
            _builder.append("\t");
            _builder.append("\t\t");
            String _substring = inputTypedParamList.substring(1);
            _builder.append(_substring, "\t\t\t");
            _builder.append(",");
            _builder.newLineIfNotEmpty();
          }
        }
        {
          Iterable _outputParameters = this._joynrCppGeneratorExtensions.getOutputParameters(method);
          boolean _isEmpty_3 = IterableExtensions.isEmpty(_outputParameters);
          if (_isEmpty_3) {
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("std::function onSuccess");
            _builder.newLine();
          } else {
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("std::function onSuccess");
            _builder.newLine();
          }
        }
        _builder.append("\t");
        _builder.append(") = 0;");
        _builder.newLine();
        _builder.newLine();
      }
    }
    {
      EList _broadcasts = serviceInterface.getBroadcasts();
      boolean _isEmpty_4 = _broadcasts.isEmpty();
      boolean _not_3 = (!_isEmpty_4);
      if (_not_3) {
        _builder.append("\t");
        _builder.append("// broadcasts");
        _builder.newLine();
      }
    }
    {
      EList _broadcasts_1 = serviceInterface.getBroadcasts();
      for(final FBroadcast broadcast : _broadcasts_1) {
        _builder.append("\t");
        String broadcastName = this._joynrCppGeneratorExtensions.joynrName(broadcast);
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @brief fire");
        String _firstUpper_5 = StringExtensions.toFirstUpper(broadcastName);
        _builder.append(_firstUpper_5, "\t ");
        _builder.append(" must be called by a concrete");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* provider to signal an occured event. It is used to implement broadcast");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* publications.");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("* @param ");
        _builder.append(broadcastName, "\t ");
        _builder.append(" the new broadcast value");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("virtual void fire");
        String _firstUpper_6 = StringExtensions.toFirstUpper(broadcastName);
        _builder.append(_firstUpper_6, "\t");
        _builder.append("(");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t\t");
        String _commaSeperatedTypedConstOutputParameterList = this._cppStdTypeUtil.getCommaSeperatedTypedConstOutputParameterList(broadcast);
        _builder.append(_commaSeperatedTypedConstOutputParameterList, "\t\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(") = 0;");
        _builder.newLine();
        _builder.newLine();
      }
    }
    _builder.append("private:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("DISALLOW_COPY_AND_ASSIGN(");
    _builder.append(interfaceName, "\t");
    _builder.append("Provider);");
    _builder.newLineIfNotEmpty();
    _builder.append("};");
    _builder.newLine();
    String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(serviceInterface);
    _builder.append(_namespaceEnder, "");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("namespace joynr {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("// Helper class for use by the RequestCallerFactory.");
    _builder.newLine();
    _builder.append("// This class creates instances of ");
    _builder.append(interfaceName, "");
    _builder.append("RequestCaller");
    _builder.newLineIfNotEmpty();
    _builder.append("template<>");
    _builder.newLine();
    _builder.append("class RequestCallerFactoryHelper<");
    String _packagePathWithJoynrPrefix_3 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "::");
    _builder.append(_packagePathWithJoynrPrefix_3, "");
    _builder.append("::");
    _builder.append(interfaceName, "");
    _builder.append("Provider> {");
    _builder.newLineIfNotEmpty();
    _builder.append("public:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("QSharedPointer create(std::shared_ptr<");
    String _packagePathWithJoynrPrefix_4 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "::");
    _builder.append(_packagePathWithJoynrPrefix_4, "\t");
    _builder.append("::");
    _builder.append(interfaceName, "\t");
    _builder.append("Provider> provider) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("return QSharedPointer(new ");
    String _packagePathWithJoynrPrefix_5 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "::");
    _builder.append(_packagePathWithJoynrPrefix_5, "\t\t");
    _builder.append("::");
    _builder.append(interfaceName, "\t\t");
    _builder.append("RequestCaller(provider));");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("};");
    _builder.newLine();
    _builder.append("} // namespace joynr");
    _builder.newLine();
    _builder.newLine();
    _builder.append("#endif // ");
    _builder.append(headerGuard, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy