ubuntu-location-service  0.0.2
provider_factory.h
1 /*
2  * Copyright © 2012-2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 #ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_FACTORY_H_
19 #define LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_FACTORY_H_
20 
21 #include "com/ubuntu/location/configuration.h"
22 #include "com/ubuntu/location/provider.h"
23 
24 #include <functional>
25 #include <map>
26 #include <memory>
27 #include <mutex>
28 #include <string>
29 
30 namespace com
31 {
32 namespace ubuntu
33 {
34 namespace location
35 {
36 class Provider;
37 
39 {
40  public:
41  typedef com::ubuntu::location::Configuration Configuration;
42  typedef std::function<Provider::Ptr(const Configuration&)> Factory;
43 
44  static ProviderFactory& instance();
45 
46  void add_factory_for_name(const std::string& name, const Factory& factory);
47 
48  Provider::Ptr create_provider_for_name_with_config(const std::string& name, const Configuration& config);
49 
50  void enumerate(const std::function<void(const std::string&, const Factory&)>& enumerator);
51 
52  private:
53  ProviderFactory() = default;
54  ~ProviderFactory() = default;
55 
56  ProviderFactory(const ProviderFactory&) = delete;
57  ProviderFactory& operator=(const ProviderFactory&) = delete;
58 
59  std::mutex guard;
60  std::map<std::string, Factory> factory_store;
61 };
62 }
63 }
64 }
65 
66 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_FACTORY_H_