database_loader.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015, Fetch Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Connor Brew */
36 
38 
39 namespace warehouse_ros
40 {
41 using std::string;
42 
44 {
45  initialize();
46 }
47 
49 {
50 }
51 
53 {
54  // Create the plugin loader.
55  try
56  {
57  db_plugin_loader_.reset(new pluginlib::ClassLoader<DatabaseConnection>("warehouse_ros", "warehouse_ros::"
58  "DatabaseConnection"));
59  }
61  {
62  ROS_FATAL_STREAM("Exception while creating database_connection plugin loader " << ex.what());
63  }
64 }
65 
67 {
68  if (!db_plugin_loader_)
69  {
70  return typename DatabaseConnection::Ptr(new DBConnectionStub());
71  }
72 
73  // Search for the warehouse_plugin parameter in the local namespace of the node, and up the tree of namespaces.
74  // If the desired param is not found, make a final attempt to look for the param in the default namespace
75  string paramName;
76  if (!nh_.searchParam("warehouse_plugin", paramName))
77  paramName = "warehouse_plugin";
78  string db_plugin;
79  if (!nh_.getParamCached(paramName, db_plugin))
80  {
81  ROS_ERROR("Could not find parameter for database plugin name");
82  return typename DatabaseConnection::Ptr(new DBConnectionStub());
83  }
84 
86  try
87  {
88  db = db_plugin_loader_->createUniqueInstance(db_plugin);
89  }
91  {
92  ROS_ERROR_STREAM("Exception while loading database plugin '" << db_plugin << "': " << ex.what() << std::endl);
93  return typename DatabaseConnection::Ptr(new DBConnectionStub());
94  }
95 
96  bool hostFound = false;
97  bool portFound = false;
98 
99  if (!nh_.searchParam("warehouse_host", paramName))
100  paramName = "warehouse_host";
101  std::string host;
102  if (nh_.getParamCached(paramName, host))
103  {
104  hostFound = true;
105  }
106 
107  if (!nh_.searchParam("warehouse_port", paramName))
108  paramName = "warehouse_port";
109  int port;
110  if (nh_.getParamCached(paramName, port))
111  {
112  portFound = true;
113  }
114 
115  if (hostFound && portFound)
116  {
117  db->setParams(host, port);
118  }
119 
120  return db;
121 }
122 
124  const std::string& /*collection_name*/)
125 {
127 }
128 } // namespace warehouse_ros
DatabaseConnection::Ptr loadDatabase()
Load a database connection using pluginlib Looks for ROS params specifying which plugin/host/port to ...
bool getParamCached(const std::string &key, std::string &s) const
DatabaseLoader()
Takes a warehouse_ros DatabaseConnection. The DatabaseConnection is expected to have already been ini...
boost::scoped_ptr< pluginlib::ClassLoader< warehouse_ros::DatabaseConnection > > db_plugin_loader_
#define ROS_FATAL_STREAM(args)
MessageCollectionHelper::Ptr openCollectionHelper(const std::string &db_name, const std::string &collection_name) override
bool searchParam(const std::string &key, std::string &result) const
boost::shared_ptr< MessageCollectionHelper > Ptr
void initialize()
Initialize the DatabaseLoader.
#define ROS_ERROR_STREAM(args)
boost::shared_ptr< DatabaseConnection > Ptr
#define ROS_ERROR(...)


warehouse_ros
Author(s): Bhaskara Marthi , Connor Brew
autogenerated on Mon Apr 26 2021 02:23:26