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.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 InterfaceSyncProxyCppTemplate 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 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(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.append("#include \"joynr/RequestStatus.h\"");
_builder.newLine();
_builder.newLine();
{
Set _requiredIncludesFor = this._cppStdTypeUtil.getRequiredIncludesFor(fInterface);
for(final String datatype : _requiredIncludesFor) {
_builder.append("#include ");
_builder.append(datatype, "");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(fInterface);
_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("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\t");
_builder.append("joynr::ProxyBase(connectorFactory, cache, domain, INTERFACE_NAME(), qosSettings, cached),");
_builder.newLine();
_builder.append("\t\t");
_builder.append(className, "\t\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();
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._joynrCppGeneratorExtensions.isReadable(attribute);
if (_isReadable) {
_builder.append("joynr::RequestStatus ");
_builder.append(syncClassName, "");
_builder.append("::");
_builder.append(getAttribute, "");
_builder.append("(");
_builder.append(attributeType, "");
_builder.append("& result)");
_builder.newLineIfNotEmpty();
_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("return joynr::RequestStatus(joynr::RequestStatusCode::ERROR, \"");
_builder.append(errorMsg, "\t\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_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("(result);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
{
boolean _isWritable = this._joynrCppGeneratorExtensions.isWritable(attribute);
if (_isWritable) {
_builder.append("joynr::RequestStatus ");
_builder.append(syncClassName, "");
_builder.append("::");
_builder.append(setAttribute, "");
_builder.append("(const ");
_builder.append(attributeType, "");
_builder.append("& value)");
_builder.newLineIfNotEmpty();
_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("return joynr::RequestStatus(joynr::RequestStatusCode::ERROR, \"");
_builder.append(errorMsg_1, "\t\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_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("(value);");
_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 = method.getName();
_builder.newLineIfNotEmpty();
String inputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedConstInputParameterList(method);
_builder.newLineIfNotEmpty();
final String outputTypedParamList = this._cppStdTypeUtil.getCommaSeperatedTypedOutputParameterList(method);
_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();
_builder.newLine();
_builder.append("joynr::RequestStatus ");
_builder.append(syncClassName, "");
_builder.append("::");
_builder.append(methodName, "");
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(outputTypedParamList, "\t");
{
boolean _and = false;
Iterable _outputParameters = this._joynrCppGeneratorExtensions.getOutputParameters(method);
int _size = IterableExtensions.size(_outputParameters);
boolean _greaterThan = (_size > 0);
if (!_greaterThan) {
_and = false;
} else {
Iterable _inputParameters = this._joynrCppGeneratorExtensions.getInputParameters(method);
int _size_1 = IterableExtensions.size(_inputParameters);
boolean _greaterThan_1 = (_size_1 > 0);
_and = _greaterThan_1;
}
if (_and) {
_builder.append(", ");
}
}
_builder.append(inputTypedParamList, "\t");
_builder.append(")");
_builder.newLineIfNotEmpty();
_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("return joynr::RequestStatus(joynr::RequestStatusCode::ERROR, \"");
_builder.append(errorMsg_2, "\t\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_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");
{
boolean _and_1 = false;
Iterable _outputParameters_1 = this._joynrCppGeneratorExtensions.getOutputParameters(method);
int _size_2 = IterableExtensions.size(_outputParameters_1);
boolean _greaterThan_2 = (_size_2 > 0);
if (!_greaterThan_2) {
_and_1 = false;
} else {
Iterable _inputParameters_1 = this._joynrCppGeneratorExtensions.getInputParameters(method);
int _size_3 = IterableExtensions.size(_inputParameters_1);
boolean _greaterThan_3 = (_size_3 > 0);
_and_1 = _greaterThan_3;
}
if (_and_1) {
_builder.append(", ");
}
}
_builder.append(params, "\t\t");
_builder.append(");");
_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