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

io.joynr.generator.cpp.proxy.InterfaceAsyncProxyCppTemplate 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.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.FInterface;
import org.franca.core.franca.FMethod;

@SuppressWarnings("all")
public class InterfaceAsyncProxyCppTemplate implements InterfaceTemplate {
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
  
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;
  
  public CharSequence generate(final FInterface fInterface) {
    StringConcatenation _builder = new StringConcatenation();
    final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(fInterface);
    _builder.newLineIfNotEmpty();
    final String className = (interfaceName + "Proxy");
    _builder.newLineIfNotEmpty();
    final String asyncClassName = (interfaceName + "AsyncProxy");
    _builder.newLineIfNotEmpty();
    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();
    {
      Set _requiredIncludesFor = this._cppStdTypeUtil.getRequiredIncludesFor(fInterface);
      String _includeForString = this._cppStdTypeUtil.getIncludeForString();
      Set _addElements = this._cppStdTypeUtil.addElements(_requiredIncludesFor, _includeForString);
      for(final String parameterType : _addElements) {
        _builder.append("#include ");
        _builder.append(parameterType, "");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("#include \"joynr/Future.h\"");
    _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 \"joynr/RequestStatus.h\"");
    _builder.newLine();
    _builder.append("#include \"joynr/RequestStatusCode.h\"");
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.newLine();
    String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(fInterface);
    _builder.append(_namespaceStarter, "");
    _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 std::string &domain,");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("const joynr::MessagingQos &qosSettings,");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("bool cached");
    _builder.newLine();
    _builder.append(") :");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("joynr::ProxyBase(connectorFactory, cache, domain, INTERFACE_NAME(), qosSettings, cached),");
    _builder.newLine();
    _builder.append("\t");
    _builder.append(className, "\t");
    _builder.append("Base(messagingAddress, connectorFactory, cache, domain, 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._cppStdTypeUtil.getTypeName(attribute);
        _builder.newLineIfNotEmpty();
        {
          boolean _isReadable = this._joynrCppGeneratorExtensions.isReadable(attribute);
          if (_isReadable) {
            String _firstUpper = StringExtensions.toFirstUpper(attributeName);
            String getAttribute = ("get" + _firstUpper);
            _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("std::shared_ptr> ");
            _builder.append(asyncClassName, "");
            _builder.append("::");
            _builder.append(getAttribute, "");
            _builder.append("Async(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("std::function onSuccess,");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("std::function onError");
            _builder.newLine();
            _builder.append(")");
            _builder.newLine();
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("if (connector==NULL){");
            _builder.newLine();
            _builder.append("\t\t");
            final String errorMsg = (("proxy cannot invoke " + getAttribute) + ", because the communication end partner is not (yet) known");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("LOG_WARN(logger, \"");
            _builder.append(errorMsg, "\t\t");
            _builder.append("\");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("joynr::RequestStatus status(RequestStatusCode::ERROR, \"");
            _builder.append(errorMsg, "\t\t");
            _builder.append("\");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("if (onError) {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("onError(status);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("std::shared_ptr> future(new joynr::Future<");
            _builder.append(attributeType, "\t\t");
            _builder.append(">());");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("future->onError(status);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return future;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("else{");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return connector->");
            _builder.append(getAttribute, "\t\t");
            _builder.append("Async(onSuccess);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
          }
        }
        {
          boolean _isWritable = this._joynrCppGeneratorExtensions.isWritable(attribute);
          if (_isWritable) {
            String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
            String setAttribute = ("set" + _firstUpper_1);
            _builder.newLineIfNotEmpty();
            _builder.append("/*");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* ");
            _builder.append(setAttribute, " ");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.newLine();
            _builder.append("std::shared_ptr> ");
            _builder.append(asyncClassName, "");
            _builder.append("::");
            _builder.append(setAttribute, "");
            _builder.append("Async(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append(attributeType, "\t\t");
            _builder.append(" ");
            _builder.append(attributeName, "\t\t");
            _builder.append(",");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("std::function onSuccess,");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("std::function onError");
            _builder.newLine();
            _builder.append(")");
            _builder.newLine();
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("if (connector==NULL){");
            _builder.newLine();
            _builder.append("\t\t");
            final String errorMsg_1 = (("proxy cannot invoke " + setAttribute) + ", because the communication end partner is not (yet) known");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("LOG_WARN(logger, \"");
            _builder.append(errorMsg_1, "\t\t");
            _builder.append("\");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("joynr::RequestStatus status(RequestStatusCode::ERROR, \"");
            _builder.append(errorMsg_1, "\t\t");
            _builder.append("\");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("if (onError) {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("onError(status);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("std::shared_ptr> future(new joynr::Future());");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("future->onError(status);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return future;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("else{");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return connector->");
            _builder.append(setAttribute, "\t\t");
            _builder.append("Async(");
            _builder.append(attributeName, "\t\t");
            _builder.append(", onSuccess);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _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();
        String outputParameters = this._cppStdTypeUtil.getCommaSeparatedOutputParameterTypes(method);
        _builder.newLineIfNotEmpty();
        String outputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstOutputParameterList(method);
        _builder.newLineIfNotEmpty();
        String inputParamList = this._cppStdTypeUtil.getCommaSeperatedUntypedInputParameterList(method);
        _builder.newLineIfNotEmpty();
        _builder.append("/*");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* ");
        _builder.append(methodName, " ");
        _builder.newLineIfNotEmpty();
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("std::shared_ptr > ");
        _builder.append(asyncClassName, "");
        _builder.append("::");
        _builder.append(methodName, "");
        _builder.append("Async(");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        {
          Iterable _inputParameters = this._joynrCppGeneratorExtensions.getInputParameters(method);
          boolean _isEmpty = IterableExtensions.isEmpty(_inputParameters);
          boolean _not = (!_isEmpty);
          if (_not) {
            String _commaSeperatedTypedConstInputParameterList = this._cppStdTypeUtil.getCommaSeperatedTypedConstInputParameterList(method);
            _builder.append(_commaSeperatedTypedConstInputParameterList, "\t\t");
            _builder.append(",");
          }
        }
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("std::function onSuccess,");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("std::function onError");
        _builder.newLine();
        _builder.append(")");
        _builder.newLine();
        _builder.append("{");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("if (connector==NULL){");
        _builder.newLine();
        _builder.append("\t\t");
        final String errorMsg_2 = (("proxy cannot invoke " + methodName) + ", because the communication end partner is not (yet) known");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("LOG_WARN(logger, \"");
        _builder.append(errorMsg_2, "\t\t");
        _builder.append("\");");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("joynr::RequestStatus status(RequestStatusCode::ERROR, \"");
        _builder.append(errorMsg_2, "\t\t");
        _builder.append("\");");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("if (onError) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("onError(status);");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("std::shared_ptr> future(new joynr::Future<");
        _builder.append(outputParameters, "\t\t");
        _builder.append(">());");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("future->onError(status);");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return future;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("else{");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return connector->");
        _builder.append(methodName, "\t\t");
        _builder.append("Async(");
        _builder.append(inputParamList, "\t\t");
        {
          Iterable _inputParameters_1 = this._joynrCppGeneratorExtensions.getInputParameters(method);
          boolean _isEmpty_1 = IterableExtensions.isEmpty(_inputParameters_1);
          boolean _not_1 = (!_isEmpty_1);
          if (_not_1) {
            _builder.append(", ");
          }
        }
        _builder.append("onSuccess);");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
      }
    }
    String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(fInterface);
    _builder.append(_namespaceEnder, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy