All Downloads are FREE. Search and download functionalities are using the official Maven repository.
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.InterfaceSyncProxyCppTemplate 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.Functions.Function1;
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 InterfaceSyncProxyCppTemplate 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 syncClassName = (interfaceName + "SyncProxy");
_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(syncClassName);
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
Set _dataTypeIncludesFor = this._cppStdTypeUtil.getDataTypeIncludesFor(this.francaIntf, generateVersion);
for(final String datatype : _dataTypeIncludesFor) {
_builder.append("#include ");
_builder.append(datatype);
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.francaIntf, generateVersion);
_builder.append(_namespaceStarter);
_builder.newLineIfNotEmpty();
_builder.append("// The proxies will contain all arbitration checks");
_builder.newLine();
_builder.append("// the connectors will contain the JSON related code");
_builder.newLine();
_builder.newLine();
_builder.append(syncClassName);
_builder.append("::");
_builder.append(syncClassName);
_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\t");
_builder.append("joynr::ProxyBase(runtime, connectorFactory, domain, qosSettings),");
_builder.newLine();
_builder.append("\t\t");
_builder.append(className, "\t\t");
_builder.append("Base(runtime, connectorFactory, domain, qosSettings)");
{
boolean _hasFireAndForgetMethods = this._cppInterfaceUtil.hasFireAndForgetMethods(this.francaIntf);
if (_hasFireAndForgetMethods) {
_builder.append(",");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append(interfaceName, "\t\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 _firstUpper = StringExtensions.toFirstUpper(attributeName);
String getAttribute = ("get" + _firstUpper);
_builder.newLineIfNotEmpty();
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
String setAttribute = ("set" + _firstUpper_1);
_builder.newLineIfNotEmpty();
{
boolean _isReadable = this._attributeUtil.isReadable(attribute);
if (_isReadable) {
CharSequence _produceSyncGetterSignature = this._cppInterfaceUtil.produceSyncGetterSignature(attribute, syncClassName, generateVersion);
_builder.append(_produceSyncGetterSignature);
_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 errorMsg;");
_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("errorMsg = \"");
_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 errorMsgCommunication = (("proxy cannot invoke " + getAttribute) + " because the communication end partner is not (yet) known");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("errorMsg = \"");
_builder.append(errorMsgCommunication, "\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(), errorMsg);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("exceptions::JoynrRuntimeException error(errorMsg);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw error;");
_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("(");
_builder.append(attributeName, "\t\t");
_builder.append(", std::move(qos));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
{
boolean _isWritable = this._attributeUtil.isWritable(attribute);
if (_isWritable) {
CharSequence _produceSyncSetterSignature = this._cppInterfaceUtil.produceSyncSetterSignature(attribute, syncClassName, generateVersion);
_builder.append(_produceSyncSetterSignature);
_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 errorMsg;");
_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("errorMsg = \"");
_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 errorMsgCommunication_1 = (("proxy cannot invoke " + setAttribute) + " because the communication end partner is not (yet) known");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("errorMsg = \"");
_builder.append(errorMsgCommunication_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(), errorMsg);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("exceptions::JoynrRuntimeException error(errorMsg);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw error;");
_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("(");
_builder.append(attributeName, "\t\t");
_builder.append(", std::move(qos));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
}
}
{
final Function1 _function = new Function1() {
@Override
public Boolean apply(final FMethod it) {
boolean _isFireAndForget = it.isFireAndForget();
return Boolean.valueOf((!_isFireAndForget));
}
};
Iterable _filter = IterableExtensions.filter(this._cppInterfaceUtil.getMethods(this.francaIntf), _function);
for(final FMethod method : _filter) {
String methodName = method.getName();
_builder.newLineIfNotEmpty();
final String outputUntypedParamList = this._cppStdTypeUtil.getCommaSeperatedUntypedOutputParameterList(method);
_builder.newLineIfNotEmpty();
String params = 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 _produceSyncMethodSignature = this._cppInterfaceUtil.produceSyncMethodSignature(method, syncClassName, generateVersion);
_builder.append(_produceSyncMethodSignature);
_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 errorMsg;");
_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("errorMsg = \"");
_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("if (connector==nullptr){");
_builder.newLine();
_builder.append("\t\t\t");
final String errorMsgCommunication_2 = (("proxy cannot invoke " + methodName) + " because the communication end partner is not (yet) known");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("errorMsg = \"");
_builder.append(errorMsgCommunication_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(), errorMsg);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("exceptions::JoynrRuntimeException error(errorMsg);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw error;");
_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("(");
_builder.append(outputUntypedParamList, "\t\t");
{
int _size = IterableExtensions.size(this._methodUtil.getOutputParameters(method));
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
_builder.append(", ");
}
}
_builder.append(params, "\t\t");
{
int _size_1 = IterableExtensions.size(this._methodUtil.getInputParameters(method));
boolean _greaterThan_1 = (_size_1 > 0);
if (_greaterThan_1) {
_builder.append(",");
}
}
_builder.append(" 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;
}
}