Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
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.CppInterfaceUtil;
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.templates.InterfaceTemplate;
import io.joynr.generator.templates.util.AttributeUtil;
import io.joynr.generator.templates.util.MethodUtil;
import io.joynr.generator.templates.util.NamingUtil;
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.FAttribute;
import org.franca.core.franca.FMethod;
@SuppressWarnings("all")
public class InterfaceAsyncProxyCppTemplate extends InterfaceTemplate {
@Inject
@Extension
private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
@Inject
@Extension
private TemplateBase _templateBase;
@Inject
@Extension
private CppStdTypeUtil _cppStdTypeUtil;
@Inject
@Extension
private NamingUtil _namingUtil;
@Inject
@Extension
private AttributeUtil _attributeUtil;
@Inject
@Extension
private MethodUtil _methodUtil;
@Inject
@Extension
private CppInterfaceUtil _cppInterfaceUtil;
@Override
public CharSequence generate(final boolean generateVersion) {
StringConcatenation _builder = new StringConcatenation();
final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
_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(this.francaIntf, "/", generateVersion);
_builder.append(_packagePathWithJoynrPrefix);
_builder.append("/");
_builder.append(asyncClassName);
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
Set _addElements = this._cppStdTypeUtil.addElements(this._cppStdTypeUtil.getDataTypeIncludesFor(this.francaIntf, generateVersion), this._cppStdTypeUtil.getIncludeForString());
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/JoynrException.h\"");
_builder.newLine();
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.francaIntf, generateVersion);
_builder.append(_namespaceStarter);
_builder.newLineIfNotEmpty();
_builder.append(asyncClassName);
_builder.append("::");
_builder.append(asyncClassName);
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("std::weak_ptr runtime,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("std::shared_ptr connectorFactory,");
_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(") :");
_builder.newLine();
_builder.append("\t");
_builder.append("joynr::ProxyBase(runtime, connectorFactory, domain, qosSettings),");
_builder.newLine();
_builder.append("\t");
_builder.append(className, "\t");
_builder.append("Base(runtime, connectorFactory, domain, qosSettings)");
{
boolean _hasFireAndForgetMethods = this._cppInterfaceUtil.hasFireAndForgetMethods(this.francaIntf);
if (_hasFireAndForgetMethods) {
_builder.append(",");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(interfaceName, "\t");
_builder.append("FireAndForgetProxy(runtime, connectorFactory, domain, qosSettings)");
}
}
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
{
EList _attributes = this._cppInterfaceUtil.getAttributes(this.francaIntf);
for(final FAttribute attribute : _attributes) {
String attributeName = this._namingUtil.joynrName(attribute);
_builder.newLineIfNotEmpty();
String attributeType = this._cppStdTypeUtil.getTypeName(attribute, generateVersion);
_builder.newLineIfNotEmpty();
{
boolean _isReadable = this._attributeUtil.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();
CharSequence _produceAsyncGetterSignature = this._cppInterfaceUtil.produceAsyncGetterSignature(attribute, asyncClassName, generateVersion);
_builder.append(_produceAsyncGetterSignature);
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
_builder.append("auto runtimeSharedPtr = _runtime.lock();");
_builder.newLine();
_builder.append("\t");
_builder.append("if (!runtimeSharedPtr || (connector==nullptr)) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("std::string errorText;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (!runtimeSharedPtr) {");
_builder.newLine();
_builder.append("\t\t\t");
final String errorMsgRuntime = (("proxy cannot invoke " + getAttribute) + " because the required runtime has been already destroyed.");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("errorText = \"");
_builder.append(errorMsgRuntime, "\t\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("else {");
_builder.newLine();
_builder.append("\t\t\t");
final String errorMsg = (("proxy cannot invoke " + getAttribute) + ", because the communication end partner is not (yet) known");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("errorText = \"");
_builder.append(errorMsg, "\t\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("JOYNR_LOG_WARN(logger(), errorText);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("auto error = std::make_shared(errorText);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (onError) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("onError(*error);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("auto future = std::make_shared>();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("future->onError(error);");
_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(std::move(onSuccess), std::move(onError), std::move(qos));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
}
}
{
boolean _isWritable = this._attributeUtil.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();
CharSequence _produceAsyncSetterSignature = this._cppInterfaceUtil.produceAsyncSetterSignature(attribute, asyncClassName, generateVersion);
_builder.append(_produceAsyncSetterSignature);
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
_builder.append("auto runtimeSharedPtr = _runtime.lock();");
_builder.newLine();
_builder.append("\t");
_builder.append("if (!runtimeSharedPtr || (connector==nullptr)) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("std::string errorText;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (!runtimeSharedPtr) {");
_builder.newLine();
_builder.append("\t\t\t");
final String errorMsgRuntime_1 = (("proxy cannot invoke " + setAttribute) + " because the required runtime has been already destroyed.");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("errorText = \"");
_builder.append(errorMsgRuntime_1, "\t\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("else {");
_builder.newLine();
_builder.append("\t\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\t");
_builder.append("errorText = \"");
_builder.append(errorMsg_1, "\t\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("JOYNR_LOG_WARN(logger(), errorText);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("auto error = std::make_shared(errorText);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (onError) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("onError(*error);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("auto future = std::make_shared>();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("future->onError(error);");
_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(", std::move(onSuccess), std::move(onError), std::move(qos));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
}
}
}
}
{
EList _methods = this._cppInterfaceUtil.getMethods(this.francaIntf);
for(final FMethod method : _methods) {
{
boolean _isFireAndForget = method.isFireAndForget();
boolean _not = (!_isFireAndForget);
if (_not) {
String methodName = this._namingUtil.joynrName(method);
_builder.newLineIfNotEmpty();
String outputParameters = this._cppStdTypeUtil.getCommaSeparatedOutputParameterTypes(method, generateVersion);
_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();
CharSequence _produceAsyncMethodSignature = this._cppInterfaceUtil.produceAsyncMethodSignature(this.francaIntf, method, asyncClassName, generateVersion);
_builder.append(_produceAsyncMethodSignature);
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
_builder.append("auto runtimeSharedPtr = _runtime.lock();");
_builder.newLine();
_builder.append("\t");
_builder.append("if (!runtimeSharedPtr || (connector==nullptr)) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("std::string errorText;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (!runtimeSharedPtr) {");
_builder.newLine();
_builder.append("\t\t\t");
final String errorMsgRuntime_2 = (("proxy cannot invoke " + methodName) + " because the required runtime has been already destroyed.");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("errorText = \"");
_builder.append(errorMsgRuntime_2, "\t\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("else {");
_builder.newLine();
_builder.append("\t\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\t");
_builder.append("errorText = \"");
_builder.append(errorMsg_2, "\t\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("JOYNR_LOG_WARN(logger(), errorText);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("auto error = std::make_shared(errorText);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (onRuntimeError) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("onRuntimeError(*error);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("auto future = std::make_shared>();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("future->onError(error);");
_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");
{
boolean _isEmpty = IterableExtensions.isEmpty(this._methodUtil.getInputParameters(method));
boolean _not_1 = (!_isEmpty);
if (_not_1) {
_builder.append(", ");
}
}
_builder.append("std::move(onSuccess), ");
{
boolean _hasErrorEnum = this._methodUtil.hasErrorEnum(method);
if (_hasErrorEnum) {
_builder.append("std::move(onApplicationError), ");
}
}
_builder.append("std::move(onRuntimeError), std::move(qos));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
}
}
String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(this.francaIntf, generateVersion);
_builder.append(_namespaceEnder);
_builder.newLineIfNotEmpty();
return _builder;
}
}