
io.joynr.generator.cpp.provider.InterfaceProviderHTemplate Maven / Gradle / Ivy
package io.joynr.generator.cpp.provider;
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 InterfaceProviderHTemplate {
@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);
String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "_");
String _plus = ("GENERATED_INTERFACE_" + _packagePathWithJoynrPrefix);
String _plus_1 = (_plus + "_");
String _plus_2 = (_plus_1 + interfaceName);
String _plus_3 = (_plus_2 + "Provider_h");
final String headerGuard = _plus_3.toUpperCase();
StringConcatenation _builder = new StringConcatenation();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning, "");
_builder.newLineIfNotEmpty();
_builder.append("#ifndef ");
_builder.append(headerGuard, "");
_builder.newLineIfNotEmpty();
_builder.append("#define ");
_builder.append(headerGuard, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("#include \"joynr/PrivateCopyAssign.h\"");
_builder.newLine();
_builder.newLine();
_builder.append("#include \"joynr/Provider.h\"");
_builder.newLine();
_builder.append("#include \"");
String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
_builder.append(_packagePathWithJoynrPrefix_1, "");
_builder.append("/I");
_builder.append(interfaceName, "");
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.append("#include \"joynr/DeclareMetatypeUtil.h\"");
_builder.newLine();
_builder.append("#include \"joynr/types/ProviderQos.h\"");
_builder.newLine();
_builder.append("#include \"joynr/RequestCallerFactory.h\"");
_builder.newLine();
_builder.append("#include \"");
String _packagePathWithJoynrPrefix_2 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "/");
_builder.append(_packagePathWithJoynrPrefix_2, "");
_builder.append("/");
_builder.append(interfaceName, "");
_builder.append("RequestCaller.h\"");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
Iterable _requiredIncludesFor = this._joynrCppGeneratorExtensions.getRequiredIncludesFor(serviceInterface);
for(final String parameterType : _requiredIncludesFor) {
_builder.append("#include \"");
_builder.append(parameterType, "");
_builder.append("\"");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
String _dllExportIncludeStatement = this._joynrCppGeneratorExtensions.getDllExportIncludeStatement();
_builder.append(_dllExportIncludeStatement, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("namespace joynr { class SubscriptionManager; }");
_builder.newLine();
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(serviceInterface);
_builder.append(_namespaceStarter, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("class ");
String _dllExportMacro = this._joynrCppGeneratorExtensions.getDllExportMacro();
_builder.append(_dllExportMacro, "");
_builder.append(" ");
_builder.append(interfaceName, "");
_builder.append("Provider : public ");
String _packagePathWithJoynrPrefix_3 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "::");
_builder.append(_packagePathWithJoynrPrefix_3, "");
_builder.append("::I");
_builder.append(interfaceName, "");
_builder.append("Sync, public joynr::Provider {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("public:");
_builder.newLine();
_builder.append(" ");
_builder.append("//TODO remove default value for ProviderQos and pass in real qos parameters");
_builder.newLine();
_builder.append(" ");
_builder.append(interfaceName, " ");
_builder.append("Provider(const joynr::types::ProviderQos& providerQos);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("//for each Attribute the provider needs setters, sync and async getters.");
_builder.newLine();
_builder.append(" ");
_builder.append("//They have default implementation for pushing Providers and can be overwritten by pulling Providers.");
_builder.newLine();
_builder.append(" ");
_builder.append("virtual ~");
_builder.append(interfaceName, " ");
_builder.append("Provider();");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("// request status, result, (params......)*");
_builder.newLine();
_builder.newLine();
{
EList _attributes = this._joynrCppGeneratorExtensions.getAttributes(serviceInterface);
for(final FAttribute attribute : _attributes) {
_builder.append("\t");
String attributeName = this._joynrCppGeneratorExtensions.joynrName(attribute);
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("virtual void get");
String _firstUpper = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper, " ");
_builder.append("(joynr::RequestStatus& joynrInternalStatus, ");
String _mappedDatatypeOrList = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute);
_builder.append(_mappedDatatypeOrList, " ");
_builder.append("& result);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("virtual void set");
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_1, " ");
_builder.append("(joynr::RequestStatus& joynrInternalStatus, const ");
String _mappedDatatypeOrList_1 = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute);
_builder.append(_mappedDatatypeOrList_1, " ");
_builder.append("& ");
_builder.append(attributeName, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append("* @brief ");
_builder.append(attributeName, " ");
_builder.append("Changed must be called by a concrete provider to signal attribute");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("* modifications. It is used to implement onchange subscriptions.");
_builder.newLine();
_builder.append("\t");
_builder.append("* @param ");
_builder.append(attributeName, " ");
_builder.append(" the new attribute value");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("void ");
_builder.append(attributeName, " ");
_builder.append("Changed(const ");
String _mappedDatatypeOrList_2 = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute);
_builder.append(_mappedDatatypeOrList_2, " ");
_builder.append("& ");
_builder.append(attributeName, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
{
EList _methods = this._joynrCppGeneratorExtensions.getMethods(serviceInterface);
for(final FMethod method : _methods) {
_builder.append("\t");
final Iterable outputParameterType = this._joynrCppGeneratorExtensions.getMappedOutputParameter(method);
_builder.newLineIfNotEmpty();
{
String _head = IterableExtensions.head(outputParameterType);
boolean _equals = Objects.equal(_head, "void");
if (_equals) {
_builder.append("\t");
_builder.append("virtual void ");
String _name = method.getName();
_builder.append(_name, " ");
_builder.append("(joynr::RequestStatus& joynrInternalStatus");
String _commaSeperatedTypedParameterList = this._joynrCppGeneratorExtensions.getCommaSeperatedTypedParameterList(method);
String _prependCommaIfNotEmpty = this._joynrCppGeneratorExtensions.prependCommaIfNotEmpty(_commaSeperatedTypedParameterList);
_builder.append(_prependCommaIfNotEmpty, " ");
_builder.append(") = 0;");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
_builder.append("virtual void ");
String _name_1 = method.getName();
_builder.append(_name_1, " ");
_builder.append("(joynr::RequestStatus& joynrInternalStatus");
String _commaSeperatedTypedOutputParameterList = this._joynrCppGeneratorExtensions.getCommaSeperatedTypedOutputParameterList(method);
String _prependCommaIfNotEmpty_1 = this._joynrCppGeneratorExtensions.prependCommaIfNotEmpty(_commaSeperatedTypedOutputParameterList);
_builder.append(_prependCommaIfNotEmpty_1, " ");
String _commaSeperatedTypedParameterList_1 = this._joynrCppGeneratorExtensions.getCommaSeperatedTypedParameterList(method);
String _prependCommaIfNotEmpty_2 = this._joynrCppGeneratorExtensions.prependCommaIfNotEmpty(_commaSeperatedTypedParameterList_1);
_builder.append(_prependCommaIfNotEmpty_2, " ");
_builder.append(") = 0;");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.append(" ");
_builder.append("void setSubscriptionManager(joynr::SubscriptionManager* subscriptionManager);");
_builder.newLine();
_builder.append(" ");
_builder.append("void setDomainAndInterface(const QString& domain, const QString& interfaceName);");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append(" ");
_builder.append("joynr::types::ProviderQos getProviderQos() const;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("protected:");
_builder.newLine();
{
EList _attributes_1 = this._joynrCppGeneratorExtensions.getAttributes(serviceInterface);
for(final FAttribute attribute_1 : _attributes_1) {
_builder.append("\t");
String _mappedDatatypeOrList_3 = this._joynrCppGeneratorExtensions.getMappedDatatypeOrList(attribute_1);
_builder.append(_mappedDatatypeOrList_3, " ");
_builder.append(" ");
String _joynrName = this._joynrCppGeneratorExtensions.joynrName(attribute_1);
_builder.append(_joynrName, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("private:");
_builder.newLine();
_builder.append(" ");
_builder.append("DISALLOW_COPY_AND_ASSIGN(");
_builder.append(interfaceName, " ");
_builder.append("Provider);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("joynr::SubscriptionManager* subscriptionManager;");
_builder.newLine();
_builder.append(" ");
_builder.append("QString domain;");
_builder.newLine();
_builder.append(" ");
_builder.append("QString interfaceName;");
_builder.newLine();
_builder.append(" ");
_builder.append("joynr::types::ProviderQos providerQos;");
_builder.newLine();
_builder.append("};");
_builder.newLine();
String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(serviceInterface);
_builder.append(_namespaceEnder, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("namespace joynr {");
_builder.newLine();
_builder.newLine();
_builder.append("// Helper class for use by the RequestCallerFactory.");
_builder.newLine();
_builder.append("// This class creates instances of ");
_builder.append(interfaceName, "");
_builder.append("RequestCaller");
_builder.newLineIfNotEmpty();
_builder.append("template<>");
_builder.newLine();
_builder.append("class RequestCallerFactoryHelper<");
String _packagePathWithJoynrPrefix_4 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "::");
_builder.append(_packagePathWithJoynrPrefix_4, "");
_builder.append("::");
_builder.append(interfaceName, "");
_builder.append("Provider> {");
_builder.newLineIfNotEmpty();
_builder.append("public:");
_builder.newLine();
_builder.append("\t");
_builder.append("QSharedPointer create(QSharedPointer<");
String _packagePathWithJoynrPrefix_5 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "::");
_builder.append(_packagePathWithJoynrPrefix_5, " ");
_builder.append("::");
_builder.append(interfaceName, " ");
_builder.append("Provider> provider) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return QSharedPointer(new ");
String _packagePathWithJoynrPrefix_6 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, "::");
_builder.append(_packagePathWithJoynrPrefix_6, " ");
_builder.append("::");
_builder.append(interfaceName, " ");
_builder.append("RequestCaller(provider));");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("};");
_builder.newLine();
_builder.append("} // namespace joynr\t");
_builder.newLine();
_builder.newLine();
_builder.append("#endif // ");
_builder.append(headerGuard, "");
_builder.newLineIfNotEmpty();
_xblockexpression = (_builder);
}
return _xblockexpression;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy