| /** |
| * 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.translationUnits |
| |
| import org.eclipse.app4mc.amalthea.model.InterProcessTrigger |
| import org.eclipse.app4mc.slg.commons.m2t.translationUnits.SyntheticTranslationUnit |
| import org.eclipse.app4mc.slg.ros2.transformers.utils.Utils |
| import org.eclipse.app4mc.transformation.util.OutputBuffer |
| |
| class RosInterProcessTriggerUtilsTranslationUnit extends SyntheticTranslationUnit { |
| |
| InterProcessTrigger ip |
| |
| new(OutputBuffer outputBuffer, InterProcessTrigger ip) { |
| super(outputBuffer) |
| this.ip = ip |
| genFiles() |
| } |
| |
| static def getModulePathStatic() { return basePathStatic + "/" + moduleNameStatic } |
| |
| static def getMakeFilePathStatic() { return modulePathStatic + "/" + makeFileName } |
| |
| // translation unit specific settings |
| static def getModuleNameStatic() { return "interProcessTriggerUtils" } |
| |
| static def getLibName() { return "INTERPROCESSTRIGGER_UTIL" } |
| |
| override getModuleName() { return moduleNameStatic } |
| |
| override getIncFile() { return moduleName + ".h" } |
| |
| def getExecCall(String param) { |
| return '''call_service_«param»(«param»_client)''' |
| } |
| |
| |
| def genFiles() { |
| if (isSrcFileEmpty()) { |
| incAppend(toHeader().toString()) |
| |
| } |
| if (isSrcFileEmpty()) { |
| srcAppend(toCPPHead().toString()) |
| |
| } |
| |
| incAppend(toH().toString()) |
| srcAppend(toCPP().toString()) |
| } |
| |
| def toCPPHead() ''' |
| #include "interProcessTriggerUtils.h" |
| |
| using namespace std::chrono_literals; |
| ''' |
| |
| def toHeader() ''' |
| #include <string> |
| |
| #include "rclcpp/rclcpp.hpp" |
| #include "std_msgs/msg/string.hpp" |
| |
| ''' |
| |
| def toCPP() ''' |
| |
| void call_service_«ip.stimulus.name»(rclcpp::Client<«ip.stimulus.name»_service::srv::«Utils.toIdlCompliantName(ip.stimulus.name + '_service')»>::SharedPtr& client) { |
| |
| auto request = std::make_shared<«ip.stimulus.name»_service::srv::«Utils.toIdlCompliantName(ip.stimulus.name + '_service')»::Request>(); |
| |
| while (!client->wait_for_service(50ms)) { |
| if (!rclcpp::ok()) { |
| RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Interrupted while waiting for the service. Exiting."); |
| exit; |
| } |
| RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "service not available, waiting again..."); |
| } |
| auto result = client->async_send_request(request); |
| } |
| ''' |
| |
| def toH() ''' |
| #include "«ip.stimulus.name»_service/srv/«ip.stimulus.name»_service.hpp" |
| void call_service_«ip.stimulus.name»(rclcpp::Client<«ip.stimulus.name»_service::srv::«Utils.toIdlCompliantName(ip.stimulus.name + '_service')»>::SharedPtr& client); |
| |
| ''' |
| |
| } |