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>
25 
28 
30 #define GZ_MODEL_MANIFEST_FILENAME "model.config"
31 
33 #define GZ_MODEL_DB_MANIFEST_FILENAME "database.config"
34 
35 namespace gazebo
36 {
37  namespace common
38  {
41 
45  class ModelDatabase : public SingletonT<ModelDatabase>
46  {
48  private: ModelDatabase();
49 
51  private: virtual ~ModelDatabase();
52 
56  public: void Start(bool _fetchImmediately = false);
57 
59  public: void Fini();
60 
63  public: std::string GetURI();
64 
70  public: std::map<std::string, std::string> GetModels();
71 
77  public: void GetModels(boost::function<
78  void (const std::map<std::string, std::string> &)> _func);
79 
87  public: std::string GetModelName(const std::string &_uri);
88 
91  public: std::string GetModelConfig(const std::string &_uri);
92 
95  public: std::string GetDBConfig(const std::string &_uri);
96 
100  public: std::string GetManifest(const std::string &_uri)
101  GAZEBO_DEPRECATED(1.5);
102 
110  public: std::string GetModelPath(const std::string &_uri,
111  bool _forceDownload = false);
112 
119  public: std::string GetModelFile(const std::string &_uri);
120 
127  public: void DownloadDependencies(const std::string &_path);
128 
134  public: bool HasModel(const std::string &_modelName);
135 
139  private: std::string GetManifestImpl(const std::string &_uri);
140 
144  private: void UpdateModelCache(bool _fetchImmediately);
145 
148  private: bool UpdateModelCacheImpl();
149 
151  private: boost::thread *updateCacheThread;
152 
154  private: std::map<std::string, std::string> modelCache;
155 
157  private: bool stop;
158 
160  private: boost::mutex updateMutex;
161 
163  private: boost::recursive_mutex startCacheMutex;
164 
166  private: boost::condition_variable updateCacheCondition;
167 
169  private: boost::condition_variable updateCacheCompleteCondition;
170 
173  private: typedef boost::function<
174  void (const std::map<std::string, std::string> &)> CallbackFunc;
175 
178  private: std::list<CallbackFunc> callbacks;
179 
182  private: static ModelDatabase *myself;
183 
185  private: friend class SingletonT<ModelDatabase>;
186  };
187  }
188 }
189 #endif