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

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

There is a newer version: 0.9.3
Show newest version
package io.joynr.generator.cpp.proxy;

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 InterfaceProxyBaseCppTemplate {
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  public CharSequence generate(final FInterface fInterface) {
    CharSequence _xblockexpression = null;
    {
      final String serviceName = this._joynrCppGeneratorExtensions.joynrName(fInterface);
      final String className = (serviceName + "ProxyBase");
      StringConcatenation _builder = new StringConcatenation();
      CharSequence _warning = this._templateBase.warning();
      _builder.append(_warning, "");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("#include \"");
      String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(fInterface, "/");
      _builder.append(_packagePathWithJoynrPrefix, "");
      _builder.append("/");
      _builder.append(className, "");
      _builder.append(".h\"");
      _builder.newLineIfNotEmpty();
      _builder.append("#include \"joynr/exceptions.h\"");
      _builder.newLine();
      _builder.append("#include \"joynr/ConnectorFactory.h\"");
      _builder.newLine();
      _builder.append("#include \"joynr/ISubscriptionListener.h\"");
      _builder.newLine();
      _builder.append("#include \"");
      String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(fInterface, "/");
      _builder.append(_packagePathWithJoynrPrefix_1, "");
      _builder.append("/");
      _builder.append(serviceName, "");
      _builder.append("InProcessConnector.h\"");
      _builder.newLineIfNotEmpty();
      _builder.append("#include \"");
      String _packagePathWithJoynrPrefix_2 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(fInterface, "/");
      _builder.append(_packagePathWithJoynrPrefix_2, "");
      _builder.append("/");
      _builder.append(serviceName, "");
      _builder.append("JoynrMessagingConnector.h\"");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.newLine();
      String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(fInterface);
      _builder.append(_namespaceStarter, "");
      _builder.newLineIfNotEmpty();
      _builder.append(className, "");
      _builder.append("::");
      _builder.append(className, "");
      _builder.append("(");
      _builder.newLineIfNotEmpty();
      _builder.append("        ");
      _builder.append("QSharedPointer messagingAddress,");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("joynr::ConnectorFactory* connectorFactory,");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("joynr::IClientCache *cache,");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("const QString &domain,");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("const joynr::ProxyQos &proxyQos,");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("const joynr::MessagingQos &qosSettings,");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("bool cached");
      _builder.newLine();
      _builder.append(") :");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("joynr::ProxyBase(connectorFactory, cache, domain, interfaceName, proxyQos, qosSettings, cached),");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("messagingAddress(messagingAddress),");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("connector(NULL)");
      _builder.newLine();
      _builder.append("{");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("//tm todo: this could probably moved into async proxy, by setting the IArbitrationListener in the ProxyBase");
      _builder.newLine();
      _builder.append("void ");
      _builder.append(className, "");
      _builder.append("::handleArbitrationFinished(");
      _builder.newLineIfNotEmpty();
      _builder.append("        ");
      _builder.append("const QString &providerParticipantId,");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("const joynr::system::CommunicationMiddleware::Enum& connection");
      _builder.newLine();
      _builder.append(") {");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("if (connector != NULL){");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("delete connector;");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("}");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("connector = connectorFactory->create<");
      String _packagePathWithJoynrPrefix_3 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(fInterface, "::");
      _builder.append(_packagePathWithJoynrPrefix_3, "    ");
      _builder.append("::I");
      _builder.append(serviceName, "    ");
      _builder.append("Connector>(");
      _builder.newLineIfNotEmpty();
      _builder.append("                ");
      _builder.append("domain,");
      _builder.newLine();
      _builder.append("                ");
      _builder.append("proxyParticipantId,");
      _builder.newLine();
      _builder.append("                ");
      _builder.append("providerParticipantId,");
      _builder.newLine();
      _builder.append("                ");
      _builder.append("qosSettings,");
      _builder.newLine();
      _builder.append("                ");
      _builder.append("cache,");
      _builder.newLine();
      _builder.append("                ");
      _builder.append("cached,");
      _builder.newLine();
      _builder.append("                ");
      _builder.append("proxyQos.getReqCacheDataFreshness_ms(),");
      _builder.newLine();
      _builder.append("                ");
      _builder.append("connection");
      _builder.newLine();
      _builder.append("    ");
      _builder.append(");");
      _builder.newLine();
      _builder.append("    ");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("joynr::ProxyBase::handleArbitrationFinished(providerParticipantId, connection);");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      {
        EList _attributes = this._joynrCppGeneratorExtensions.getAttributes(fInterface);
        for(final FAttribute attribute : _attributes) {
          String attributeName = this._joynrCppGeneratorExtensions.joynrName(attribute);
          _builder.newLineIfNotEmpty();
          final String returnType = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute);
          _builder.newLineIfNotEmpty();
          _builder.append("void ");
          _builder.append(className, "");
          _builder.append("::unsubscribeFrom");
          String _firstUpper = StringExtensions.toFirstUpper(attributeName);
          _builder.append(_firstUpper, "");
          _builder.append("(QString& subscriptionId)");
          _builder.newLineIfNotEmpty();
          _builder.append("{");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot unsubscribe from ");
          _builder.append(className, "        ");
          _builder.append(".");
          _builder.append(attributeName, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("        ");
          _builder.append("return;");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->unsubscribeFrom");
          String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
          _builder.append(_firstUpper_1, "        ");
          _builder.append("(subscriptionId);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("QString ");
          _builder.append(className, "");
          _builder.append("::subscribeTo");
          String _firstUpper_2 = StringExtensions.toFirstUpper(attributeName);
          _builder.append(_firstUpper_2, "");
          _builder.append("(QSharedPointer > subscriptionListener, QSharedPointer subscriptionQos) {");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot subscribe to ");
          _builder.append(className, "        ");
          _builder.append(".");
          _builder.append(attributeName, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("        ");
          _builder.append("return \"\";");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("return connector->subscribeTo");
          String _firstUpper_3 = StringExtensions.toFirstUpper(attributeName);
          _builder.append(_firstUpper_3, "        ");
          _builder.append("(subscriptionListener, subscriptionQos);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
        }
      }
      _builder.append(className, "");
      _builder.append("::~");
      _builder.append(className, "");
      _builder.append("(){");
      _builder.newLineIfNotEmpty();
      _builder.append("    ");
      _builder.append("if (connector != NULL){");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("delete connector;");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(fInterface);
      _builder.append(_namespaceEnder, "");
      _builder.newLineIfNotEmpty();
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy