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

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

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.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;

@SuppressWarnings("all")
public class InterfaceAsyncProxyCppTemplate {
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  public CharSequence generate(final FInterface fInterface) {
    CharSequence _xblockexpression = null;
    {
      final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(fInterface);
      final String className = (interfaceName + "Proxy");
      final String asyncClassName = (interfaceName + "AsyncProxy");
      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(asyncClassName, "");
      _builder.append(".h\"");
      _builder.newLineIfNotEmpty();
      {
        Iterable _requiredIncludesFor = this._joynrCppGeneratorExtensions.getRequiredIncludesFor(fInterface);
        for(final String datatype : _requiredIncludesFor) {
          _builder.append("#include \"");
          _builder.append(datatype, "");
          _builder.append("\"");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      _builder.append("#include \"joynr/exceptions.h\"");
      _builder.newLine();
      _builder.append("#include \"joynr/Request.h\"");
      _builder.newLine();
      _builder.append("#include \"joynr/Reply.h\"");
      _builder.newLine();
      _builder.append("#include ");
      _builder.newLine();
      _builder.newLine();
      String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(fInterface);
      _builder.append(_namespaceStarter, "");
      _builder.append(" ");
      _builder.newLineIfNotEmpty();
      _builder.append(asyncClassName, "");
      _builder.append("::");
      _builder.append(asyncClassName, "");
      _builder.append("(");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("QSharedPointer messagingAddress,");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("joynr::ConnectorFactory* connectorFactory,");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("joynr::IClientCache *cache,");
      _builder.newLine();
      _builder.append("\t\t");
      _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, getInterfaceName(), proxyQos, qosSettings, cached),");
      _builder.newLine();
      _builder.append("    ");
      _builder.append(className, "    ");
      _builder.append("Base(messagingAddress, connectorFactory, cache, domain, proxyQos, qosSettings, cached)");
      _builder.newLineIfNotEmpty();
      _builder.append("{");
      _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();
          String attributeType = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute);
          _builder.append(" ");
          _builder.newLineIfNotEmpty();
          _builder.append("            ");
          String _firstUpper = StringExtensions.toFirstUpper(attributeName);
          String getAttribute = ("get" + _firstUpper);
          _builder.append(" ");
          _builder.newLineIfNotEmpty();
          _builder.append("            ");
          String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
          String setAttribute = ("set" + _firstUpper_1);
          _builder.append(" ");
          _builder.newLineIfNotEmpty();
          _builder.append("/*");
          _builder.newLine();
          _builder.append(" ");
          _builder.append("* ");
          _builder.append(getAttribute, " ");
          _builder.newLineIfNotEmpty();
          _builder.append(" ");
          _builder.append("*/");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(getAttribute, "");
          _builder.append("(QSharedPointer > future, QSharedPointer< joynr::ICallback< ");
          _builder.append(attributeType, "");
          _builder.append(" > > callback)");
          _builder.newLineIfNotEmpty();
          _builder.append("{");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("assert (!future.isNull());");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(getAttribute, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(getAttribute, "        ");
          _builder.append("(future, callback);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(getAttribute, "");
          _builder.append("(QSharedPointer > future)");
          _builder.newLineIfNotEmpty();
          _builder.append("{");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("assert (!future.isNull());");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(getAttribute, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(getAttribute, "        ");
          _builder.append("(future);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(getAttribute, "");
          _builder.append("(QSharedPointer > callback)");
          _builder.newLineIfNotEmpty();
          _builder.append("{");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(getAttribute, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(getAttribute, "        ");
          _builder.append("(callback);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("/*");
          _builder.newLine();
          _builder.append(" ");
          _builder.append("* ");
          _builder.append(setAttribute, " ");
          _builder.newLineIfNotEmpty();
          _builder.append(" ");
          _builder.append("*/");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(setAttribute, "");
          _builder.append("(QSharedPointer > future, QSharedPointer< joynr::ICallback > callback, ");
          _builder.append(attributeType, "");
          _builder.append(" attributeValue) {");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("assert (!future.isNull());");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(setAttribute, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(setAttribute, "        ");
          _builder.append("(future, callback, attributeValue);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(setAttribute, "");
          _builder.append("(QSharedPointer > future, ");
          _builder.append(attributeType, "");
          _builder.append(" attributeValue) {");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("assert (!future.isNull());");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(setAttribute, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(setAttribute, "        ");
          _builder.append("(future, attributeValue);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(setAttribute, "");
          _builder.append("(QSharedPointer< joynr::ICallback > callBack, ");
          _builder.append(attributeType, "");
          _builder.append(" attributeValue) {");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(setAttribute, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(setAttribute, "        ");
          _builder.append("(callBack, attributeValue);");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
        }
      }
      {
        EList _methods = this._joynrCppGeneratorExtensions.getMethods(fInterface);
        for(final FMethod method : _methods) {
          String methodName = this._joynrCppGeneratorExtensions.joynrName(method);
          _builder.newLineIfNotEmpty();
          Iterable _mappedOutputParameter = this._joynrCppGeneratorExtensions.getMappedOutputParameter(method);
          String outType = IterableExtensions.head(_mappedOutputParameter);
          _builder.newLineIfNotEmpty();
          String _commaSeperatedTypedParameterList = this._joynrCppGeneratorExtensions.getCommaSeperatedTypedParameterList(method);
          String paramsSignature = this._joynrCppGeneratorExtensions.prependCommaIfNotEmpty(_commaSeperatedTypedParameterList);
          _builder.newLineIfNotEmpty();
          String _commaSeperatedUntypedParameterList = this._joynrCppGeneratorExtensions.getCommaSeperatedUntypedParameterList(method);
          String params = this._joynrCppGeneratorExtensions.prependCommaIfNotEmpty(_commaSeperatedUntypedParameterList);
          _builder.newLineIfNotEmpty();
          _builder.newLine();
          _builder.append("/*");
          _builder.newLine();
          _builder.append(" ");
          _builder.append("* ");
          _builder.append(methodName, " ");
          _builder.newLineIfNotEmpty();
          _builder.append(" ");
          _builder.append("*/");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(methodName, "");
          _builder.append("(QSharedPointer > future, QSharedPointer< joynr::ICallback<");
          _builder.append(outType, "");
          _builder.append("> > callback ");
          _builder.append(paramsSignature, "");
          _builder.append(")");
          _builder.newLineIfNotEmpty();
          _builder.append("{");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("assert (!future.isNull());");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(methodName, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(methodName, "        ");
          _builder.append("(future, callback ");
          _builder.append(params, "        ");
          _builder.append(");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(methodName, "");
          _builder.append("(QSharedPointer > future ");
          _builder.append(paramsSignature, "");
          _builder.append(") {");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("assert (!future.isNull());");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(methodName, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(methodName, "        ");
          _builder.append("(future ");
          _builder.append(params, "        ");
          _builder.append(");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
          _builder.append("void ");
          _builder.append(asyncClassName, "");
          _builder.append("::");
          _builder.append(methodName, "");
          _builder.append("(QSharedPointer > callback ");
          _builder.append(paramsSignature, "");
          _builder.append(") { ");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("if (connector==NULL){");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("LOG_WARN(logger, \"proxy cannot invoke ");
          _builder.append(methodName, "        ");
          _builder.append(", because the communication end partner is not (yet) known\");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("    ");
          _builder.append("else{");
          _builder.newLine();
          _builder.append("        ");
          _builder.append("connector->");
          _builder.append(methodName, "        ");
          _builder.append("(callback ");
          _builder.append(params, "        ");
          _builder.append(");");
          _builder.newLineIfNotEmpty();
          _builder.append("    ");
          _builder.append("}");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.newLine();
        }
      }
      String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(fInterface);
      _builder.append(_namespaceEnder, "");
      _builder.newLineIfNotEmpty();
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy