00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef NODELET_NODELET_H
00031 #define NODELET_NODELET_H
00032
00033 #include "exception.h"
00034
00035 #include <string>
00036 #include <vector>
00037 #include <map>
00038
00039 #include <ros/console.h>
00040 #include <boost/shared_ptr.hpp>
00041 #include <bondcpp/bond.h>
00042
00043 namespace ros
00044 {
00045 class NodeHandle;
00046 class CallbackQueue;
00047 class CallbackQueueInterface;
00048 class AsyncSpinner;
00049 }
00050
00051 #define NODELET_DEBUG(...) ROS_DEBUG_NAMED(getName(), __VA_ARGS__)
00052 #define NODELET_DEBUG_STREAM(...) ROS_DEBUG_STREAM_NAMED(getName(), __VA_ARGS__)
00053 #define NODELET_DEBUG_ONCE(...) ROS_DEBUG_ONCE_NAMED(getName(), __VA_ARGS__)
00054 #define NODELET_DEBUG_STREAM_ONCE(...) ROS_DEBUG_STREAM_ONCE_NAMED(getName(), __VA_ARGS__)
00055 #define NODELET_DEBUG_COND(cond, ...) ROS_DEBUG_COND_NAMED(cond, getName(), __VA_ARGS__)
00056 #define NODELET_DEBUG_STREAM_COND(cond, ...) ROS_DEBUG_STREAM_COND_NAMED(cond, getName(), __VA_ARGS__)
00057 #define NODELET_DEBUG_THROTTLE(rate, ...) ROS_DEBUG_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00058 #define NODELET_DEBUG_STREAM_THROTTLE(rate, ...) ROS_DEBUG_STREAM_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00059 #define NODELET_DEBUG_FILTER(filter, ...) ROS_DEBUG_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00060 #define NODELET_DEBUG_STREAM_FILTER(filter, ...) ROS_DEBUG_STREAM_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00061
00062 #define NODELET_INFO(...) ROS_INFO_NAMED(getName(), __VA_ARGS__)
00063 #define NODELET_INFO_STREAM(...) ROS_INFO_STREAM_NAMED(getName(), __VA_ARGS__)
00064 #define NODELET_INFO_ONCE(...) ROS_INFO_ONCE_NAMED(getName(), __VA_ARGS__)
00065 #define NODELET_INFO_STREAM_ONCE(...) ROS_INFO_STREAM_ONCE_NAMED(getName(), __VA_ARGS__)
00066 #define NODELET_INFO_COND(cond, ...) ROS_INFO_COND_NAMED(cond, getName(), __VA_ARGS__)
00067 #define NODELET_INFO_STREAM_COND(cond, ...) ROS_INFO_STREAM_COND_NAMED(cond, getName(), __VA_ARGS__)
00068 #define NODELET_INFO_THROTTLE(rate, ...) ROS_INFO_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00069 #define NODELET_INFO_STREAM_THROTTLE(rate, ...) ROS_INFO_STREAM_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00070 #define NODELET_INFO_FILTER(filter, ...) ROS_INFO_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00071 #define NODELET_INFO_STREAM_FILTER(filter, ...) ROS_INFO_STREAM_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00072
00073 #define NODELET_WARN(...) ROS_WARN_NAMED(getName(), __VA_ARGS__)
00074 #define NODELET_WARN_STREAM(...) ROS_WARN_STREAM_NAMED(getName(), __VA_ARGS__)
00075 #define NODELET_WARN_ONCE(...) ROS_WARN_ONCE_NAMED(getName(), __VA_ARGS__)
00076 #define NODELET_WARN_STREAM_ONCE(...) ROS_WARN_STREAM_ONCE_NAMED(getName(), __VA_ARGS__)
00077 #define NODELET_WARN_COND(cond, ...) ROS_WARN_COND_NAMED(cond, getName(), __VA_ARGS__)
00078 #define NODELET_WARN_STREAM_COND(cond, ...) ROS_WARN_STREAM_COND_NAMED(cond, getName(), __VA_ARGS__)
00079 #define NODELET_WARN_THROTTLE(rate, ...) ROS_WARN_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00080 #define NODELET_WARN_STREAM_THROTTLE(rate, ...) ROS_WARN_STREAM_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00081 #define NODELET_WARN_FILTER(filter, ...) ROS_WARN_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00082 #define NODELET_WARN_STREAM_FILTER(filter, ...) ROS_WARN_STREAM_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00083
00084 #define NODELET_ERROR(...) ROS_ERROR_NAMED(getName(), __VA_ARGS__)
00085 #define NODELET_ERROR_STREAM(...) ROS_ERROR_STREAM_NAMED(getName(), __VA_ARGS__)
00086 #define NODELET_ERROR_ONCE(...) ROS_ERROR_ONCE_NAMED(getName(), __VA_ARGS__)
00087 #define NODELET_ERROR_STREAM_ONCE(...) ROS_ERROR_STREAM_ONCE_NAMED(getName(), __VA_ARGS__)
00088 #define NODELET_ERROR_COND(cond, ...) ROS_ERROR_COND_NAMED(cond, getName(), __VA_ARGS__)
00089 #define NODELET_ERROR_STREAM_COND(cond, ...) ROS_ERROR_STREAM_COND_NAMED(cond, getName(), __VA_ARGS__)
00090 #define NODELET_ERROR_THROTTLE(rate, ...) ROS_ERROR_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00091 #define NODELET_ERROR_STREAM_THROTTLE(rate, ...) ROS_ERROR_STREAM_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00092 #define NODELET_ERROR_FILTER(filter, ...) ROS_ERROR_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00093 #define NODELET_ERROR_STREAM_FILTER(filter, ...) ROS_ERROR_STREAM_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00094
00095 #define NODELET_FATAL(...) ROS_FATAL_NAMED(getName(), __VA_ARGS__)
00096 #define NODELET_FATAL_STREAM(...) ROS_FATAL_STREAM_NAMED(getName(), __VA_ARGS__)
00097 #define NODELET_FATAL_ONCE(...) ROS_FATAL_ONCE_NAMED(getName(), __VA_ARGS__)
00098 #define NODELET_FATAL_STREAM_ONCE(...) ROS_FATAL_STREAM_ONCE_NAMED(getName(), __VA_ARGS__)
00099 #define NODELET_FATAL_COND(cond, ...) ROS_FATAL_COND_NAMED(cond, getName(), __VA_ARGS__)
00100 #define NODELET_FATAL_STREAM_COND(cond, ...) ROS_FATAL_STREAM_COND_NAMED(cond, getName(), __VA_ARGS__)
00101 #define NODELET_FATAL_THROTTLE(rate, ...) ROS_FATAL_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00102 #define NODELET_FATAL_STREAM_THROTTLE(rate, ...) ROS_FATAL_STREAM_THROTTLE_NAMED(rate, getName(), __VA_ARGS__)
00103 #define NODELET_FATAL_FILTER(filter, ...) ROS_FATAL_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00104 #define NODELET_FATAL_STREAM_FILTER(filter, ...) ROS_FATAL_STREAM_FILTER_NAMED(filter, getName(), __VA_ARGS__)
00105
00106 namespace nodelet
00107 {
00108 typedef boost::shared_ptr<ros::NodeHandle> NodeHandlePtr;
00109 typedef std::map<std::string, std::string> M_string;
00110 typedef std::vector<std::string> V_string;
00111
00112 namespace detail
00113 {
00114 class CallbackQueueManager;
00115 class CallbackQueue;
00116 typedef boost::shared_ptr<CallbackQueue> CallbackQueuePtr;
00117 }
00118
00119 class UninitializedException : public Exception
00120 {
00121 public:
00122 UninitializedException(const std::string& method_name)
00123 : Exception("Calling [" + method_name + "] before the Nodelet is initialized is not allowed.")
00124 {}
00125 };
00126
00127 class MultipleInitializationException : public Exception
00128 {
00129 public:
00130 MultipleInitializationException()
00131 : Exception("Initialized multiple times")
00132 {}
00133 };
00134
00135 class Nodelet
00136 {
00137
00138 protected:
00139 inline const std::string& getName() const { return nodelet_name_; }
00140 inline const V_string& getMyArgv() const { return my_argv_; }
00141
00142 ros::NodeHandle& getNodeHandle() const;
00143 ros::NodeHandle& getPrivateNodeHandle() const;
00144 ros::NodeHandle& getMTNodeHandle() const;
00145 ros::NodeHandle& getMTPrivateNodeHandle() const;
00146
00147 ros::CallbackQueueInterface& getSTCallbackQueue() const;
00148 ros::CallbackQueueInterface& getMTCallbackQueue() const;
00149
00150
00151
00152 private:
00153 bool inited_;
00154
00155 std::string nodelet_name_;
00156
00157 detail::CallbackQueuePtr mt_callback_queue_;
00158 detail::CallbackQueuePtr st_callback_queue_;
00159 detail::CallbackQueueManager* callback_manager_;
00160
00161 NodeHandlePtr nh_;
00162 NodeHandlePtr private_nh_;
00163 NodeHandlePtr mt_nh_;
00164 NodeHandlePtr mt_private_nh_;
00165 V_string my_argv_;
00166
00167 boost::shared_ptr<bond::Bond> bond_;
00168
00169
00170 virtual void onInit() = 0;
00171
00172
00173 void disable();
00174
00175
00176 public:
00178 Nodelet();
00179
00185 void init(const std::string& name, const M_string& remapping_args, const V_string& my_argv,
00186 detail::CallbackQueueManager* callback_manager, boost::shared_ptr<bond::Bond> bond);
00187
00188 virtual ~Nodelet();
00189
00191 friend class Loader;
00192 };
00193
00194 }
00195 #endif //NODELET_NODELET_H