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 
104  public: std::string GetModelPath(const std::string &_uri,
105  bool _forceDownload = false);
106 
113  public: std::string GetModelFile(const std::string &_uri);
114 
121  public: void DownloadDependencies(const std::string &_path);
122 
128  public: bool HasModel(const std::string &_modelName);
129 
133  private: std::string GetManifestImpl(const std::string &_uri);
134 
138  private: void UpdateModelCache(bool _fetchImmediately);
139 
142  private: bool UpdateModelCacheImpl();
143 
145  private: boost::thread *updateCacheThread;
146 
148  private: std::map<std::string, std::string> modelCache;
149 
151  private: bool stop;
152 
154  private: boost::mutex updateMutex;
155 
157  private: boost::recursive_mutex startCacheMutex;
158 
160  private: boost::condition_variable updateCacheCondition;
161 
163  private: boost::condition_variable updateCacheCompleteCondition;
164 
167  private: typedef boost::function<
168  void (const std::map<std::string, std::string> &)> CallbackFunc;
169 
172  private: std::list<CallbackFunc> callbacks;
173 
176  private: static ModelDatabase *myself;
177 
179  private: friend class SingletonT<ModelDatabase>;
180  };
181  }
182 }
183 #endif