All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ModelDatabase.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_MODELDATABSE_HH_
18 #define _GAZEBO_MODELDATABSE_HH_
19 
20 #include <string>
21 #include <map>
22 #include <list>
23 #include <boost/thread.hpp>
24 #include <boost/thread/mutex.hpp>
26 
28 #define GZ_MODEL_MANIFEST_FILENAME "model.config"
29 
31 #define GZ_MODEL_DB_MANIFEST_FILENAME "database.config"
32 
33 namespace gazebo
34 {
35  namespace common
36  {
39 
43  class ModelDatabase : public SingletonT<ModelDatabase>
44  {
46  private: ModelDatabase();
47 
49  private: virtual ~ModelDatabase();
50 
53  public: std::string GetURI();
54 
60  public: std::map<std::string, std::string> GetModels();
61 
67  public: void GetModels(boost::function<
68  void (const std::map<std::string, std::string> &)> _func);
69 
77  public: std::string GetModelName(const std::string &_uri);
78 
81  public: std::string GetModelConfig(const std::string &_uri);
82 
85  public: std::string GetDBConfig(const std::string &_uri);
86 
90  public: std::string GetManifest(const std::string &_uri)
91  GAZEBO_DEPRECATED(1.5);
92 
100  public: std::string GetModelPath(const std::string &_uri,
101  bool _forceDownload = false);
102 
109  public: std::string GetModelFile(const std::string &_uri);
110 
117  public: void DownloadDependencies(const std::string &_path);
118 
124  public: bool HasModel(const std::string &_modelName);
125 
129  private: std::string GetManifestImpl(const std::string &_uri);
130 
132  private: void UpdateModelCache();
133 
136  private: bool UpdateModelCacheImpl();
137 
139  private: std::map<std::string, std::string> modelCache;
140 
142  private: bool stop;
143 
145  private: boost::mutex updateMutex;
146 
148  private: boost::thread *updateCacheThread;
149 
151  private: boost::condition_variable updateCacheCondition;
152 
155  private: typedef boost::function<
156  void (const std::map<std::string, std::string> &)> CallbackFunc;
157 
160  private: std::list<CallbackFunc> callbacks;
161 
164  private: static ModelDatabase *myself;
165 
167  private: friend class SingletonT<ModelDatabase>;
168  };
169  }
170 }
171 #endif