io.joynr.generator.cpp.defaultProvider.DefaultProviderCppTemplate Maven / Gradle / Ivy
package io.joynr.generator.cpp.defaultProvider;
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.FArgument;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;
@SuppressWarnings("all")
public class DefaultProviderCppTemplate {
@Inject
@Extension
private TemplateBase _templateBase;
@Inject
@Extension
private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
public CharSequence generate(final FInterface serviceInterface) {
CharSequence _xblockexpression = null;
{
final String interfaceName = this._joynrCppGeneratorExtensions.joynrName(serviceInterface);
StringConcatenation _builder = new StringConcatenation();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning, "");
_builder.newLineIfNotEmpty();
_builder.append("#include \"");
String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
_builder.append(_packagePathWithJoynrPrefix, "");
_builder.append("/Default");
_builder.append(interfaceName, "");
_builder.append("Provider.h\"");
_builder.newLineIfNotEmpty();
_builder.append("#include \"joynr/RequestStatus.h\"");
_builder.newLine();
_builder.append("#include \"joynr/joynrlogging.h\"");
_builder.newLine();
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(serviceInterface);
_builder.append(_namespaceStarter, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("using namespace joynr::joynr_logging;");
_builder.newLine();
_builder.newLine();
_builder.append("Logger* Default");
_builder.append(interfaceName, "");
_builder.append("Provider::logger = Logging::getInstance()->getLogger(\"PROV\", \"Default");
_builder.append(interfaceName, "");
_builder.append("Provider\");");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("Default");
_builder.append(interfaceName, "");
_builder.append("Provider::Default");
_builder.append(interfaceName, "");
_builder.append("Provider(const joynr::types::ProviderQos& providerQos) :");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(interfaceName, " ");
_builder.append("Provider(providerQos)");
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("Default");
_builder.append(interfaceName, "");
_builder.append("Provider::~Default");
_builder.append(interfaceName, "");
_builder.append("Provider()");
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
{
EList _attributes = this._joynrCppGeneratorExtensions.getAttributes(serviceInterface);
for(final FAttribute attribute : _attributes) {
final String attributename = this._joynrCppGeneratorExtensions.joynrName(attribute);
_builder.newLineIfNotEmpty();
String attributeType = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute);
_builder.newLineIfNotEmpty();
_builder.append("// Only use this for pulling providers, not for pushing providers");
_builder.newLine();
_builder.append("//void Default");
_builder.append(interfaceName, "");
_builder.append("Provider::get");
String _firstUpper = StringExtensions.toFirstUpper(attributename);
_builder.append(_firstUpper, "");
_builder.append("(RequestStatus& status, ");
String _mappedDatatypeOrList = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute);
_builder.append(_mappedDatatypeOrList, "");
_builder.append("& result) {");
_builder.newLineIfNotEmpty();
_builder.append("// LOG_WARN(logger, \"**********************************************\");");
_builder.newLine();
_builder.append("// LOG_WARN(logger, \"* Default");
_builder.append(interfaceName, "");
_builder.append("Provider::get");
String _firstUpper_1 = StringExtensions.toFirstUpper(attributename);
_builder.append(_firstUpper_1, "");
_builder.append(" called\");");
_builder.newLineIfNotEmpty();
_builder.append("// LOG_WARN(logger, \"**********************************************\");");
_builder.newLine();
{
boolean _equals = Objects.equal(attributeType, "QString");
if (_equals) {
_builder.append("//\t\tresult = \"Hello World\";");
_builder.newLine();
} else {
boolean _equals_1 = Objects.equal(attributeType, "bool");
if (_equals_1) {
_builder.append("//\t\tresult = false;");
_builder.newLine();
} else {
boolean _equals_2 = Objects.equal(attributeType, "int");
if (_equals_2) {
_builder.append("//\t\tresult = 42;");
_builder.newLine();
} else {
boolean _equals_3 = Objects.equal(attributeType, "double");
if (_equals_3) {
_builder.append("//\t\tresult = 3.1415;");
_builder.newLine();
} else {
_builder.append("//\t\tresult = ");
_builder.append(attributeType, "");
_builder.append("(); ");
_builder.newLineIfNotEmpty();
}
}
}
}
}
_builder.append("// status.setCode(RequestStatusCode::OK);");
_builder.newLine();
_builder.append("//}");
_builder.newLine();
_builder.newLine();
}
}
{
EList _methods = this._joynrCppGeneratorExtensions.getMethods(serviceInterface);
for(final FMethod method : _methods) {
final String methodName = this._joynrCppGeneratorExtensions.joynrName(method);
_builder.newLineIfNotEmpty();
final Iterable outputParameterType = this._joynrCppGeneratorExtensions.getMappedOutputParameter(method);
_builder.newLineIfNotEmpty();
{
String _head = IterableExtensions.head(outputParameterType);
boolean _equals_4 = Objects.equal(_head, "void");
if (_equals_4) {
_builder.append("void Default");
_builder.append(interfaceName, "");
_builder.append("Provider::");
_builder.append(methodName, "");
_builder.append("(joynr::RequestStatus& status");
String _commaSeperatedTypedParameterList = this._joynrCppGeneratorExtensions.getCommaSeperatedTypedParameterList(method);
String _prependCommaIfNotEmpty = this._joynrCppGeneratorExtensions.prependCommaIfNotEmpty(_commaSeperatedTypedParameterList);
_builder.append(_prependCommaIfNotEmpty, "");
_builder.append(" ) {");
_builder.newLineIfNotEmpty();
} else {
_builder.append("void Default");
_builder.append(interfaceName, "");
_builder.append("Provider::");
_builder.append(methodName, "");
_builder.append("(joynr::RequestStatus& status, ");
String _head_1 = IterableExtensions.head(outputParameterType);
_builder.append(_head_1, "");
_builder.append("& result");
String _commaSeperatedTypedParameterList_1 = this._joynrCppGeneratorExtensions.getCommaSeperatedTypedParameterList(method);
String _prependCommaIfNotEmpty_1 = this._joynrCppGeneratorExtensions.prependCommaIfNotEmpty(_commaSeperatedTypedParameterList_1);
_builder.append(_prependCommaIfNotEmpty_1, "");
_builder.append(") {");
_builder.newLineIfNotEmpty();
{
String _head_2 = IterableExtensions.head(outputParameterType);
boolean _equals_5 = Objects.equal(_head_2, "QString");
if (_equals_5) {
_builder.append("result = \"Hello World\";");
_builder.newLine();
} else {
String _head_3 = IterableExtensions.head(outputParameterType);
boolean _equals_6 = Objects.equal(_head_3, "bool");
if (_equals_6) {
_builder.append("result = false;");
_builder.newLine();
} else {
String _head_4 = IterableExtensions.head(outputParameterType);
boolean _equals_7 = Objects.equal(_head_4, "int");
if (_equals_7) {
_builder.append("result = 42;");
_builder.newLine();
} else {
String _head_5 = IterableExtensions.head(outputParameterType);
boolean _equals_8 = Objects.equal(_head_5, "double");
if (_equals_8) {
_builder.append("result = 3.1415;");
_builder.newLine();
} else {
_builder.append("Q_UNUSED(result);");
_builder.newLine();
}
}
}
}
}
}
}
{
Iterable _inputParameters = this._joynrCppGeneratorExtensions.getInputParameters(method);
for(final FArgument inputParameter : _inputParameters) {
_builder.append("\t");
_builder.append("Q_UNUSED(");
String _joynrName = this._joynrCppGeneratorExtensions.joynrName(inputParameter);
_builder.append(_joynrName, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("LOG_WARN(logger, \"**********************************************\");");
_builder.newLine();
_builder.append("\t");
_builder.append("LOG_WARN(logger, \"* Default");
_builder.append(interfaceName, " ");
_builder.append("Provider::");
_builder.append(methodName, " ");
_builder.append(" called\");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("LOG_WARN(logger, \"**********************************************\");\t");
_builder.newLine();
_builder.append("\t");
_builder.append("status.setCode(joynr::RequestStatusCode::OK);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
}
}
String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(serviceInterface);
_builder.append(_namespaceEnder, "");
_builder.newLineIfNotEmpty();
_xblockexpression = (_builder);
}
return _xblockexpression;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy