blob: 7f946a05a5c4f0dd94f004cdb103cb13396b2142 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard,
* Regent L'Archeveque,
* Sebastien Gemme - initial API and implementation
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.addons.ros.impl;
import org.eclipse.apogy.addons.ros.ROSNode;
import org.eclipse.apogy.addons.ros.utilities.AsynchronousShutdowner;
import org.ros.internal.message.Message;
import org.ros.node.topic.Publisher;
public class ROSPublisherCustomImpl<T extends Message> extends ROSPublisherImpl<T> {
@Override
public boolean isLaunched() {
this.launched = (this.publisher != null);
return this.launched;
}
@Override
@SuppressWarnings("unchecked")
public void launch(ROSNode node) {
setNode(node);
setPublisher((Publisher<T>) node.createPublisher(getTopicName(), getMessageType()));
}
@Override
public void publish(T message) {
if (isLaunched())
getPublisher().publish(message);
}
@Override
public T newMessage() {
if (isLaunched())
return getPublisher().newMessage();
else
return null;
}
@Override
public void stop() {
try {
AsynchronousShutdowner.add(getPublisher());
} catch (Exception e) {
}
setPublisher(null);
}
} // ROSPublisherImpl