| /** |
| * Copyright (c) 2020-2021 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| */ |
| |
| package org.eclipse.app4mc.slg.ros2.generators; |
| |
| import org.eclipse.app4mc.amalthea.model.InterProcessStimulus; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit; |
| import org.eclipse.app4mc.slg.ros2.transformers.utils.Utils; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| |
| public class RosIpStimulusTranslationunit extends TranslationUnit { |
| private InterProcessStimulus ip; |
| private OutputBuffer outputBuffer; |
| |
| public RosIpStimulusTranslationunit(final OutputBuffer outputBuffer, final InterProcessStimulus ip) { |
| super(); |
| this.ip = ip; |
| this.outputBuffer = outputBuffer; |
| |
| this.genFiles(); |
| } |
| |
| public String getSrcFile() { |
| return (Utils.toIdlCompliantName(this.getModuleName()) + ".srv"); |
| } |
| |
| public String getSrcPath() { |
| return getModulePath() + "/srv/" + getSrcFile(); |
| } |
| |
| public String getBasePath() { |
| return "services"; |
| } |
| |
| public String getModuleName() { |
| return ip.getName() + "_service"; |
| } |
| |
| public boolean genFiles() { |
| return srcAppend(toSrvFile().toString()); |
| } |
| |
| public CharSequence getMakeFilePath() { |
| StringConcatenation _builder = new StringConcatenation(); |
| String _basePath = this.getBasePath(); |
| _builder.append(_basePath); |
| _builder.append("/"); |
| String _moduleName = this.getModuleName(); |
| _builder.append(_moduleName); |
| _builder.newLineIfNotEmpty(); |
| return _builder; |
| } |
| |
| public CharSequence toSrvFile() { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("int64 request"); |
| _builder.newLine(); |
| _builder.append("---"); |
| _builder.newLine(); |
| _builder.append("int64 response"); |
| _builder.newLine(); |
| return _builder; |
| } |
| |
| public String getModulePath() { |
| return this.getBasePath() + "/" + this.getModuleName(); |
| } |
| |
| @Override |
| public String getIncFile() { |
| return getModuleName() + ".hpp"; |
| } |
| |
| public String getIncPath() { |
| return getModulePath() + "/_inc/" + getIncFile(); |
| } |
| |
| public boolean isIncFileEmpty() { |
| return !outputBuffer.bufferExists("INC", getModulePath() + "/_inc/" + getModuleName()); |
| } |
| |
| public boolean isSrcFileEmpty() { |
| return !outputBuffer.bufferExists("SRC", getModulePath() + "/_src/" + getModuleName()); |
| } |
| |
| public boolean incAppend(final String str) { |
| return outputBuffer.appendTo("INC", getModulePath() + "/_inc/" + getModuleName(), str); |
| } |
| |
| public boolean srcAppend(final String str) { |
| return outputBuffer.appendTo("SRC", getModulePath() + "/_src/" + getModuleName(), str); |
| } |
| |
| } |