io.joynr.generator.cpp.proxy.InterfaceSyncProxyCppTemplate Maven / Gradle / Ivy
package io.joynr.generator.cpp.proxy;
import com.google.common.base.Objects;
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 InterfaceSyncProxyCppTemplate {
@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 syncClassName = (interfaceName + "SyncProxy");
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(syncClassName, "");
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.append("#include \"joynr/Request.h\"");
_builder.newLine();
_builder.append("#include \"joynr/Reply.h\"");
_builder.newLine();
_builder.append("#include \"joynr/Dispatcher.h\"");
_builder.newLine();
_builder.append("#include \"joynr/DispatcherUtils.h\"");
_builder.newLine();
_builder.append("#include \"joynr/exceptions.h\"");
_builder.newLine();
_builder.newLine();
{
Iterable _requiredIncludesFor = this._joynrCppGeneratorExtensions.getRequiredIncludesFor(fInterface);
for(final String datatype : _requiredIncludesFor) {
_builder.append("#include \"");
_builder.append(datatype, "");
_builder.append("\"");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(fInterface);
_builder.append(_namespaceStarter, "");
_builder.append(" ");
_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(" ");
_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, 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();
String _firstUpper = StringExtensions.toFirstUpper(attributeName);
String getAttribute = ("get" + _firstUpper);
_builder.append(" ");
_builder.newLineIfNotEmpty();
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
String setAttribute = ("set" + _firstUpper_1);
_builder.append(" ");
_builder.newLineIfNotEmpty();
_builder.append("void ");
_builder.append(syncClassName, "");
_builder.append("::");
_builder.append(getAttribute, "");
_builder.append("(joynr::RequestStatus& status, ");
_builder.append(attributeType, "");
_builder.append("& result)");
_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("(status, result);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("void ");
_builder.append(syncClassName, "");
_builder.append("::");
_builder.append(setAttribute, "");
_builder.append("(joynr::RequestStatus& status, const ");
_builder.append(attributeType, "");
_builder.append("& value)");
_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(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("(status, value);");
_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 = method.getName();
_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.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* ");
_builder.append(methodName, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
{
Iterable _mappedOutputParameter = this._joynrCppGeneratorExtensions.getMappedOutputParameter(method);
String _head = IterableExtensions.head(_mappedOutputParameter);
boolean _equals = Objects.equal(_head, "void");
if (_equals) {
_builder.append("void ");
_builder.append(syncClassName, "");
_builder.append("::");
_builder.append(methodName, "");
_builder.append("(joynr::RequestStatus& status ");
_builder.append(paramsSignature, "");
_builder.append(")");
_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(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("(status ");
_builder.append(params, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}\t");
_builder.newLine();
} else {
_builder.append("void ");
_builder.append(syncClassName, "");
_builder.append("::");
_builder.append(methodName, "");
_builder.append("(joynr::RequestStatus& status, ");
Iterable _mappedOutputParameter_1 = this._joynrCppGeneratorExtensions.getMappedOutputParameter(method);
String _head_1 = IterableExtensions.head(_mappedOutputParameter_1);
_builder.append(_head_1, "");
_builder.append(" &result ");
_builder.append(paramsSignature, "");
_builder.append(")");
_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(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("(status, result ");
_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