40 #include <sys/types.h>
44 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
52 #include <boost/algorithm/string.hpp>
88 const std::string &cname,
89 const std::string &url):
93 loaded_cam_info_(false)
122 boost::mutex::scoped_lock lock_(
mutex_);
141 return sensor_msgs::CameraInfo();
155 size_t prefix_len = std::string(
"package://").length();
156 size_t rest = url.find(
'/', prefix_len);
157 std::string
package(url.substr(prefix_len, rest - prefix_len));
169 return pkgPath + url.substr(rest);
189 boost::mutex::scoped_lock lock_(
mutex_);
220 const std::string &cname)
222 bool success =
false;
224 const std::string resURL(
resolveURL(url, cname));
236 ROS_INFO(
"using default calibration URL");
253 if (!filename.empty())
278 const std::string &cname)
280 bool success =
false;
283 std::string cam_name;
284 sensor_msgs::CameraInfo cam_info;
288 if (cname != cam_name)
291 << cam_name <<
" in file " << filename);
296 boost::mutex::scoped_lock lock(
mutex_);
302 ROS_WARN_STREAM(
"Camera calibration file " << filename <<
" not found.");
309 const std::string &cname) {
310 ROS_WARN(
"[CameraInfoManager] reading from flash not implemented for this CameraInfoManager");
329 boost::mutex::scoped_lock lock(
mutex_);
349 const std::string &cname)
351 std::string resolved;
357 size_t dollar = url.find(
'$', rest);
359 if (dollar >= url.length())
362 resolved += url.substr(rest);
367 resolved += url.substr(rest, dollar-rest);
369 if (url.substr(dollar+1, 1) !=
"{")
374 else if (url.substr(dollar+1, 6) ==
"{NAME}")
380 else if (url.substr(dollar+1, 10) ==
"{ROS_HOME}")
383 std::string ros_home;
385 if ((ros_home_env = getenv(
"ROS_HOME")))
388 ros_home = ros_home_env;
390 else if ((ros_home_env = getenv(
"HOME")))
393 ros_home = ros_home_env;
396 resolved += ros_home;
403 " invalid URL substitution (not resolved): "
428 if (boost::iequals(url.substr(0, 8),
"file:///"))
432 if (boost::iequals(url.substr(0, 9),
"flash:///"))
436 if (boost::iequals(url.substr(0, 10),
"package://"))
440 size_t rest = url.find(
'/', 10);
441 if (rest < url.length()-1 && rest > 10)
459 const std::string &url,
460 const std::string &cname)
462 bool success =
false;
464 const std::string resURL(
resolveURL(url, cname));
482 if (!filename.empty())
514 const std::string &filename,
515 const std::string &cname)
520 size_t last_slash = filename.rfind(
'/');
521 if (last_slash >= filename.length())
530 std::string dirname(filename.substr(0, last_slash+1));
531 struct stat stat_data;
532 int rc = stat(dirname.c_str(), &stat_data);
538 std::string
command(
"mkdir -p " + dirname);
555 else if (!S_ISDIR(stat_data.st_mode))
570 const std::string &flashURL,
571 const std::string &cname) {
586 sensor_msgs::SetCameraInfo::Response &rsp)
589 std::string url_copy;
592 boost::mutex::scoped_lock lock(
mutex_);
601 ROS_ERROR(
"set_camera_info service called, but driver not running.");
602 rsp.status_message =
"Camera driver not running.";
609 rsp.status_message =
"Error storing camera calibration.";
631 for (
unsigned i = 0; i < cname.size(); ++i)
633 if (!isalnum(cname[i]) && cname[i] !=
'_')
641 boost::mutex::scoped_lock lock(
mutex_);
659 boost::mutex::scoped_lock lock(
mutex_);
678 boost::mutex::scoped_lock lock(
mutex_);