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.TemplateBase;
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;

@SuppressWarnings("all")
public class InterfaceProviderCppTemplate {
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  @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 \"");
    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.newLine();
    _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(const joynr::types::ProviderQos &providerQos) :");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("I");
    _builder.append(interfaceName, "	");
    _builder.append("Base(),");
    _builder.newLineIfNotEmpty();
    {
      EList _attributes = this._joynrCppGeneratorExtensions.getAttributes(serviceInterface);
      for(final FAttribute attribute : _attributes) {
        _builder.append("\t");
        String _joynrName = this._joynrCppGeneratorExtensions.joynrName(attribute);
        _builder.append(_joynrName, "	");
        _builder.append("(),");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("    ");
    _builder.append("subscriptionManager(NULL),");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("domain(),");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("interfaceName(),");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("providerQos(providerQos)");
    _builder.newLine();
    _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, "	");
    _builder.append("RequestInterpreter>(getInterfaceName());");
    _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(getInterfaceName());");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("void ");
    _builder.append(interfaceName, "");
    _builder.append("Provider::setSubscriptionManager(joynr::SubscriptionManager* subscriptionManager) {");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.append("this->subscriptionManager = subscriptionManager;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("void ");
    _builder.append(interfaceName, "");
    _builder.append("Provider::setDomainAndInterface(const QString &domain, const QString &interfaceName) {");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.append("this->domain = domain;");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("this->interfaceName = interfaceName;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("joynr::types::ProviderQos ");
    _builder.append(interfaceName, "");
    _builder.append("Provider::getProviderQos() const {");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.append("return providerQos;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    {
      EList _attributes_1 = this._joynrCppGeneratorExtensions.getAttributes(serviceInterface);
      for(final FAttribute attribute_1 : _attributes_1) {
        String attributeType = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute_1);
        _builder.newLineIfNotEmpty();
        String attributeName = this._joynrCppGeneratorExtensions.joynrName(attribute_1);
        _builder.newLineIfNotEmpty();
        _builder.append("void ");
        _builder.append(interfaceName, "");
        _builder.append("Provider::get");
        String _firstUpper = StringExtensions.toFirstUpper(attributeName);
        _builder.append(_firstUpper, "");
        _builder.append("(joynr::RequestStatus& joynrInternalStatus, ");
        _builder.append(attributeType, "");
        _builder.append("& result) {");
        _builder.newLineIfNotEmpty();
        _builder.append("    ");
        _builder.append("result = ");
        _builder.append(attributeName, "    ");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.append("    ");
        _builder.append("joynrInternalStatus.setCode(joynr::RequestStatusCode::OK);");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("void ");
        _builder.append(interfaceName, "");
        _builder.append("Provider::set");
        String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
        _builder.append(_firstUpper_1, "");
        _builder.append("(joynr::RequestStatus& joynrInternalStatus, const ");
        _builder.append(attributeType, "");
        _builder.append("& ");
        _builder.append(attributeName, "");
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("    ");
        _builder.append(attributeName, "    ");
        _builder.append("Changed(");
        _builder.append(attributeName, "    ");
        _builder.append("); ");
        _builder.newLineIfNotEmpty();
        _builder.append("    ");
        _builder.append("joynrInternalStatus.setCode(joynr::RequestStatusCode::OK);");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("void ");
        _builder.append(interfaceName, "");
        _builder.append("Provider::");
        _builder.append(attributeName, "");
        _builder.append("Changed(const ");
        _builder.append(attributeType, "");
        _builder.append("& ");
        _builder.append(attributeName, "");
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("    ");
        _builder.append("if(this->");
        _builder.append(attributeName, "    ");
        _builder.append(" == ");
        _builder.append(attributeName, "    ");
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("        ");
        _builder.append("// the value didn\'t change, no need for notification");
        _builder.newLine();
        _builder.append("        ");
        _builder.append("return;");
        _builder.newLine();
        _builder.append("    ");
        _builder.append("}");
        _builder.newLine();
        _builder.append("    ");
        _builder.append("this->");
        _builder.append(attributeName, "    ");
        _builder.append(" = ");
        _builder.append(attributeName, "    ");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.append("    ");
        _builder.append("onAttributeValueChanged(\"");
        _builder.append(attributeName, "    ");
        _builder.append("\", QVariant::fromValue(");
        _builder.append(attributeName, "    ");
        _builder.append("));");
        _builder.newLineIfNotEmpty();
        _builder.append("}");
        _builder.newLine();
      }
    }
    String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(serviceInterface);
    _builder.append(_namespaceEnder, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy