ubuntu-location-service  ..
An aggregating location service providing positioning and geocoding capabilities to applications.
provider_factory.h
Go to the documentation of this file.
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 
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:
42  typedef std::function<Provider::Ptr(const Configuration&)> Factory;
43 
44  static ProviderFactory& instance();
45 
46  // Makes the given factory functor known for the given name.
47  void add_factory_for_name(const std::string& name, const Factory& factory);
48 
49  // Tries to lookup the factory for the given name, and create a provider instance
50  // by calling the factory and passing it the given config. Please note that the name
51  // can be decorated with @ for distinguishing providers of the same type but different configs.
52  // Eg.:
53  // --provider=remote::Provider@espoo --remote::Provider@espoo::name="com.ubuntu.espoo.service.Provider" --remote::Provider@espoo::path="/com/ubuntu/espoo/service/Provider"
54  // --provider=remote::Provider@gps --remote::Provider@gps::name="com.ubuntu.android.gps.Provider" --remote::Provider@gps::path="/com/ubuntu/android/gps/Provider"
55  Provider::Ptr create_provider_for_name_with_config(const std::string& name, const Configuration& config);
56 
57  // Async version of above.
58  void create_provider_for_name_with_config(const std::string& name, const Configuration& config, const std::function<void(Provider::Ptr)>& cb);
59 
60  void enumerate(const std::function<void(const std::string&, const Factory&)>& enumerator);
61 
62  private:
63  ProviderFactory() = default;
64  ~ProviderFactory() = default;
65 
66  ProviderFactory(const ProviderFactory&) = delete;
67  ProviderFactory& operator=(const ProviderFactory&) = delete;
68 
69  std::mutex guard;
70  std::map<std::string, Factory> factory_store;
71 };
72 }
73 }
74 }
75 
76 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_FACTORY_H_
void add_factory_for_name(const std::string &name, const Factory &factory)
Definition: accuracy.h:23
std::function< Provider::Ptr(const Configuration &)> Factory
std::shared_ptr< Provider > Ptr
Definition: provider.h:48
boost::property_tree::ptree Configuration
Definition: configuration.h:29
void enumerate(const std::function< void(const std::string &, const Factory &)> &enumerator)
com::ubuntu::location::Configuration Configuration
Provider::Ptr create_provider_for_name_with_config(const std::string &name, const Configuration &config)
static ProviderFactory & instance()