rtt_rostopic_ros_publish_activity.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Ruben Smits  Tue Nov 16 09:19:02 CET 2010  ros_publish_activity.cpp
00003 
00004                         ros_publish_activity.cpp -  description
00005                            -------------------
00006     begin                : Tue November 16 2010
00007     copyright            : (C) 2010 Ruben Smits
00008     email                : first.last@mech.kuleuven.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 
00029 
00030 #include <rtt_roscomm/rtt_rostopic_ros_publish_activity.hpp>
00031 
00032 namespace rtt_roscomm {
00033 
00034     using namespace RTT;
00035 
00036     RosPublishActivity::weak_ptr RosPublishActivity::ros_pub_act;
00037 
00038     RosPublishActivity::RosPublishActivity( const std::string& name)
00039       : Activity(ORO_SCHED_OTHER, RTT::os::LowestPriority, 0.0, 0, name)
00040     {
00041       Logger::In in("RosPublishActivity");
00042       log(Debug)<<"Creating RosPublishActivity"<<endlog();
00043     }
00044 
00045     void RosPublishActivity::loop(){
00046       os::MutexLock lock(publishers_lock);
00047       for(iterator it = publishers.begin(); it != publishers.end(); ++it) {
00048         (*it)->publish();
00049       }
00050     }
00051 
00052     RosPublishActivity::shared_ptr RosPublishActivity::Instance() {
00053       shared_ptr ret = ros_pub_act.lock();
00054       if ( !ret ) {
00055         ret.reset(new RosPublishActivity("RosPublishActivity"));
00056         ros_pub_act = ret;
00057         ret->start();
00058       }
00059       return ret;
00060     }
00061 
00062     void RosPublishActivity::addPublisher(RosPublisher* pub) {
00063       os::MutexLock lock(publishers_lock);
00064       publishers.insert(pub);
00065     }
00066 
00067     void RosPublishActivity::removePublisher(RosPublisher* pub) {
00068       os::MutexLock lock(publishers_lock);
00069       publishers.erase(pub);
00070     }
00071 
00072     RosPublishActivity::~RosPublishActivity() {
00073       Logger::In in("RosPublishActivity");
00074       log(Info) << "RosPublishActivity cleans up: no more work."<<endlog();
00075       stop();
00076     }
00077 
00078 }


rtt_roscomm
Author(s): Ruben Smits, Jonathan Bohren
autogenerated on Mon Apr 3 2017 03:34:43