io.joynr.generator.cpp.proxy.InterfaceProxyBaseCppTemplate 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 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.FBroadcast;
import org.franca.core.franca.FInterface;
@SuppressWarnings("all")
public class InterfaceProxyBaseCppTemplate 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 serviceName = this._joynrCppGeneratorExtensions.joynrName(fInterface);
_builder.newLineIfNotEmpty();
final String className = (serviceName + "ProxyBase");
_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(className, "");
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.append("#include \"joynr/exceptions.h\"");
_builder.newLine();
_builder.append("#include \"joynr/ConnectorFactory.h\"");
_builder.newLine();
_builder.append("#include \"joynr/ISubscriptionListener.h\"");
_builder.newLine();
_builder.append("#include \"");
String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(fInterface, "/");
_builder.append(_packagePathWithJoynrPrefix_1, "");
_builder.append("/");
_builder.append(serviceName, "");
_builder.append("InProcessConnector.h\"");
_builder.newLineIfNotEmpty();
_builder.append("#include \"");
String _packagePathWithJoynrPrefix_2 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(fInterface, "/");
_builder.append(_packagePathWithJoynrPrefix_2, "");
_builder.append("/");
_builder.append(serviceName, "");
_builder.append("JoynrMessagingConnector.h\"");
_builder.newLineIfNotEmpty();
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(fInterface);
_builder.append(_namespaceStarter, "");
_builder.newLineIfNotEmpty();
_builder.append(className, "");
_builder.append("::");
_builder.append(className, "");
_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, interfaceName, qosSettings, cached),");
_builder.newLine();
_builder.append("\t\t");
_builder.append("messagingAddress(messagingAddress),");
_builder.newLine();
_builder.append("\t\t");
_builder.append("connector(NULL)");
_builder.newLine();
_builder.append("{");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("//tm todo: this could probably moved into async proxy, by setting the IArbitrationListener in the ProxyBase");
_builder.newLine();
_builder.append("void ");
_builder.append(className, "");
_builder.append("::handleArbitrationFinished(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("const std::string &providerParticipantId,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("const joynr::types::CommunicationMiddleware::Enum& connection");
_builder.newLine();
_builder.append(") {");
_builder.newLine();
_builder.append("\t");
_builder.append("if (connector != NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("delete connector;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("connector = connectorFactory->create<");
String _packagePathWithJoynrPrefix_3 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(fInterface, "::");
_builder.append(_packagePathWithJoynrPrefix_3, "\t");
_builder.append("::I");
_builder.append(serviceName, "\t");
_builder.append("Connector>(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t");
_builder.append("domain,");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("proxyParticipantId,");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("providerParticipantId,");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("qosSettings,");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("cache,");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("cached,");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("connection");
_builder.newLine();
_builder.append("\t");
_builder.append(");");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("joynr::ProxyBase::handleArbitrationFinished(providerParticipantId, connection);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
{
EList _attributes = this._joynrCppGeneratorExtensions.getAttributes(fInterface);
final Function1 _function = new Function1() {
public Boolean apply(final FAttribute attribute) {
return Boolean.valueOf(InterfaceProxyBaseCppTemplate.this._joynrCppGeneratorExtensions.isNotifiable(attribute));
}
};
Iterable _filter = IterableExtensions.filter(_attributes, _function);
for(final FAttribute attribute : _filter) {
String attributeName = this._joynrCppGeneratorExtensions.joynrName(attribute);
_builder.newLineIfNotEmpty();
final String returnType = this._cppStdTypeUtil.getTypeName(attribute);
_builder.newLineIfNotEmpty();
_builder.append("void ");
_builder.append(className, "");
_builder.append("::unsubscribeFrom");
String _firstUpper = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper, "");
_builder.append("(std::string& subscriptionId)");
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
_builder.append("if (connector==NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("LOG_WARN(logger, \"proxy cannot subscribe to ");
_builder.append(className, "\t\t");
_builder.append(".");
_builder.append(attributeName, "\t\t");
_builder.append(", \\");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t ");
_builder.append("because the communication end partner is not (yet) known\");");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("else{");
_builder.newLine();
_builder.append("\t\t");
_builder.append("connector->unsubscribeFrom");
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_1, "\t\t");
_builder.append("(subscriptionId);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("std::string ");
_builder.append(className, "");
_builder.append("::subscribeTo");
String _firstUpper_2 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_2, "");
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("std::shared_ptr > subscriptionListener,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const joynr::SubscriptionQos& subscriptionQos,");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("std::string& subscriptionId) {");
_builder.newLine();
_builder.append("\t");
_builder.append("if (connector==NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("LOG_WARN(logger, \"proxy cannot subscribe to ");
_builder.append(className, "\t\t");
_builder.append(".");
_builder.append(attributeName, "\t\t");
_builder.append(", \\");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t ");
_builder.append("because the communication end partner is not (yet) known\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"\";");
_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->subscribeTo");
String _firstUpper_3 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_3, "\t\t");
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t\t");
_builder.append("subscriptionListener,");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("subscriptionQos,");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("subscriptionId);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("std::string ");
_builder.append(className, "");
_builder.append("::subscribeTo");
String _firstUpper_4 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_4, "");
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("std::shared_ptr > subscriptionListener,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const joynr::SubscriptionQos& subscriptionQos) {");
_builder.newLine();
_builder.append("\t");
_builder.append("if (connector==NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("LOG_WARN(logger, \"proxy cannot subscribe to ");
_builder.append(className, "\t\t");
_builder.append(".");
_builder.append(attributeName, "\t\t");
_builder.append(", \\");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t ");
_builder.append("because the communication end partner is not (yet) known\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"\";");
_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->subscribeTo");
String _firstUpper_5 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_5, "\t\t");
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t\t");
_builder.append("subscriptionListener,");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("subscriptionQos);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
}
}
_builder.newLine();
{
EList _broadcasts = fInterface.getBroadcasts();
for(final FBroadcast broadcast : _broadcasts) {
String broadcastName = this._joynrCppGeneratorExtensions.joynrName(broadcast);
_builder.newLineIfNotEmpty();
final String returnTypes = this._cppStdTypeUtil.getCommaSeparatedOutputParameterTypes(broadcast);
_builder.newLineIfNotEmpty();
_builder.append("void ");
_builder.append(className, "");
_builder.append("::unsubscribeFrom");
String _firstUpper_6 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_6, "");
_builder.append("Broadcast(std::string& subscriptionId)");
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
_builder.append("if (connector==NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("LOG_WARN(logger, \"proxy cannot unsubscribe from ");
_builder.append(className, "\t\t");
_builder.append(".");
_builder.append(broadcastName, "\t\t");
_builder.append(" broadcast, \\");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t ");
_builder.append("because the communication end partner is not (yet) known\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("else{");
_builder.newLine();
_builder.append("\t\t");
_builder.append("connector->unsubscribeFrom");
String _firstUpper_7 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_7, "\t\t");
_builder.append("Broadcast(subscriptionId);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
{
boolean _isSelective = this._joynrCppGeneratorExtensions.isSelective(broadcast);
if (_isSelective) {
_builder.append("std::string ");
_builder.append(className, "");
_builder.append("::subscribeTo");
String _firstUpper_8 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_8, "");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const ");
String _name = fInterface.getName();
String _firstUpper_9 = StringExtensions.toFirstUpper(_name);
_builder.append(_firstUpper_9, "\t\t\t");
String _firstUpper_10 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_10, "\t\t\t");
_builder.append("BroadcastFilterParameters& filterParameters,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("std::shared_ptr > subscriptionListener,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const joynr::OnChangeSubscriptionQos& subscriptionQos) {");
_builder.newLine();
} else {
_builder.append("std::string ");
_builder.append(className, "");
_builder.append("::subscribeTo");
String _firstUpper_11 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_11, "");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("std::shared_ptr > subscriptionListener,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const joynr::OnChangeSubscriptionQos& subscriptionQos) {");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("if (connector==NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("LOG_WARN(logger, \"proxy cannot subscribe to ");
_builder.append(className, "\t\t");
_builder.append(".");
_builder.append(broadcastName, "\t\t");
_builder.append(" broadcast, \\");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t ");
_builder.append("because the communication end partner is not (yet) known\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"\";");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("else{");
_builder.newLine();
{
boolean _isSelective_1 = this._joynrCppGeneratorExtensions.isSelective(broadcast);
if (_isSelective_1) {
_builder.append("\t\t");
_builder.append("return connector->subscribeTo");
String _firstUpper_12 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_12, "\t\t");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("filterParameters,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("subscriptionListener,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("subscriptionQos);");
_builder.newLine();
} else {
_builder.append("\t\t");
_builder.append("return connector->subscribeTo");
String _firstUpper_13 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_13, "\t\t");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("subscriptionListener,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("subscriptionQos);");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
{
boolean _isSelective_2 = this._joynrCppGeneratorExtensions.isSelective(broadcast);
if (_isSelective_2) {
_builder.append("std::string ");
_builder.append(className, "");
_builder.append("::subscribeTo");
String _firstUpper_14 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_14, "");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const ");
String _name_1 = fInterface.getName();
String _firstUpper_15 = StringExtensions.toFirstUpper(_name_1);
_builder.append(_firstUpper_15, "\t\t\t");
String _firstUpper_16 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_16, "\t\t\t");
_builder.append("BroadcastFilterParameters& filterParameters,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("std::shared_ptr > subscriptionListener,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const joynr::OnChangeSubscriptionQos& subscriptionQos,");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("std::string& subscriptionId) {");
_builder.newLine();
} else {
_builder.append("std::string ");
_builder.append(className, "");
_builder.append("::subscribeTo");
String _firstUpper_17 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_17, "");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("std::shared_ptr > subscriptionListener,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("const joynr::OnChangeSubscriptionQos& subscriptionQos,");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("std::string& subscriptionId) {");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("if (connector==NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("LOG_WARN(logger, \"proxy cannot subscribe to ");
_builder.append(className, "\t\t");
_builder.append(".");
_builder.append(broadcastName, "\t\t");
_builder.append(" broadcast, \\");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t ");
_builder.append("because the communication end partner is not (yet) known\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"\";");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("else{");
_builder.newLine();
{
boolean _isSelective_3 = this._joynrCppGeneratorExtensions.isSelective(broadcast);
if (_isSelective_3) {
_builder.append("\t\t");
_builder.append("return connector->subscribeTo");
String _firstUpper_18 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_18, "\t\t");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t\t");
_builder.append("filterParameters,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t\t");
_builder.append("subscriptionListener,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t\t");
_builder.append("subscriptionQos,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t\t");
_builder.append("subscriptionId);");
_builder.newLine();
} else {
_builder.append("\t\t");
_builder.append("return connector->subscribeTo");
String _firstUpper_19 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_19, "\t\t");
_builder.append("Broadcast(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t\t");
_builder.append("subscriptionListener,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t\t");
_builder.append("subscriptionQos,");
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t\t\t");
_builder.append("subscriptionId);");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
_builder.append(className, "");
_builder.append("::~");
_builder.append(className, "");
_builder.append("(){");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("if (connector != NULL){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("delete connector;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(fInterface);
_builder.append(_namespaceEnder, "");
_builder.newLineIfNotEmpty();
return _builder;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy