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)
92 
99  public: std::string GetModelPath(const std::string &_uri);
100 
107  public: std::string GetModelFile(const std::string &_uri);
108 
115  public: void DownloadDependencies(const std::string &_path);
116 
122  public: bool HasModel(const std::string &_modelName);
123 
127  private: std::string GetManifestImpl(const std::string &_uri);
128 
130  private: void UpdateModelCache();
131 
134  private: bool UpdateModelCacheImpl();
135 
137  private: std::map<std::string, std::string> modelCache;
138 
140  private: bool stop;
141 
143  private: boost::mutex updateMutex;
144 
146  private: boost::thread *updateCacheThread;
147 
149  private: boost::condition_variable updateCacheCondition;
150 
153  private: typedef boost::function<
154  void (const std::map<std::string, std::string> &)> CallbackFunc;
155 
158  private: std::list<CallbackFunc> callbacks;
159 
162  private: static ModelDatabase *myself;
163 
165  private: friend class SingletonT<ModelDatabase>;
166  };
167  }
168 }
169 #endif