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
00041 #include <warehouse/SetupCollection.h>
00042 #include <warehouse/exception.h>
00043 #include <boost/algorithm/string.hpp>
00044
00045 namespace warehouse
00046 {
00047
00048 namespace mt=ros::message_traits;
00049 using std::string;
00050 using std::vector;
00051
00052
00053 template <class M>
00054 Collection<M>
00055 WarehouseClient::setupCollection (const string& collection,
00056 const StringVec& indexed,
00057 const StringVec& additional_metadata)
00058 {
00059 return setupCollection<M> (collection, "", indexed,
00060 additional_metadata);
00061 }
00062
00063 template <class M>
00064 Collection<M>
00065 WarehouseClient::setupCollection (const string& collection,
00066 const string& topic, const StringVec& indexed,
00067 const StringVec& additional_metadata)
00068 {
00069 typedef mt::DataType<M> DataType;
00070 boost::mutex::scoped_lock l(mutex_);
00071
00072
00073 const string data_type = DataType::value();
00074 vector<string> tokens;
00075 boost::split(tokens, data_type, boost::is_any_of(string("/")));
00076 ROS_ASSERT_MSG(tokens.size()==2, "Data type of message was %s, "
00077 "which is invalid", data_type.c_str());
00078
00079
00080 SetupCollection srv;
00081 srv.request.db_name = db_;
00082 srv.request.collection_name = collection;
00083 srv.request.topic = topic;
00084 srv.request.msg_pkg = tokens[0];
00085 srv.request.msg_type = tokens[1];
00086 srv.request.indexed_fields = indexed;
00087 srv.request.additional_metadata_fields = additional_metadata;
00088
00089
00090 if (!setup_client_.call(srv))
00091 throw WarehouseClientException("Service call to setup_collection failed");
00092
00093
00094 if (srv.response.error_code != SetupCollection::Response::SUCCESS)
00095 throw SetupCollectionException(srv.response.error_msg);
00096
00097
00098 ROS_DEBUG_STREAM_NAMED ("setup_collection", "Service call succeeded");
00099 const string actual_topic = topic.empty() ?
00100 "warehouse/"+db_+"/"+collection+"/insert" :
00101 topic;
00102
00103 return Collection<M>(actual_topic, db_, collection, nh_);
00104 }
00105
00106
00107
00108 }