ubuntu-location-service: /build/location-service-git/src/location-service/include/location_service/com/ubuntu/location/provider_factory.h Source File

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
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
38 class ProviderFactory
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 // 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@gps --remote::Provider@gps::name="com.ubuntu.android.gps.Provider" --remote::Provider@gps::path="/com/ubuntu/android/gps/Provider"
54 Provider::Ptr create_provider_for_name_with_config(const std::string& name, const Configuration& config);
55
56 // Async version of above.
57 void create_provider_for_name_with_config(const std::string& name, const Configuration& config, const std::function<void(Provider::Ptr)>& cb);
58
59 void enumerate(const std::function<void(const std::string&, const Factory&)>& enumerator);
60
61 static std::string extract_undecorated_name(const std::string& name);
62
63 private:
64 ProviderFactory() = default;
65 ~ProviderFactory() = default;
66
67 ProviderFactory(const ProviderFactory&) = delete;
68 ProviderFactory& operator=(const ProviderFactory&) = delete;
69
70 std::mutex guard;
71 std::map<std::string, Factory> factory_store;
72 };
73 }
74 }
75 }
76
77 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDER_FACTORY_H_
com::ubuntu::location::ProviderFactory
Definition: provider_factory.h:39
com::ubuntu::location::ProviderFactory::create_provider_for_name_with_config
void create_provider_for_name_with_config(const std::string &name, const Configuration &config, const std::function< void(Provider::Ptr)> &cb)
com::ubuntu::location::ProviderFactory::Factory
std::function< Provider::Ptr(const Configuration &)> Factory
Definition: provider_factory.h:42
com::ubuntu::location::ProviderFactory::Configuration
com::ubuntu::location::Configuration Configuration
Definition: provider_factory.h:41
com::ubuntu::location::ProviderFactory::add_factory_for_name
void add_factory_for_name(const std::string &name, const Factory &factory)
com::ubuntu::location::ProviderFactory::enumerate
void enumerate(const std::function< void(const std::string &, const Factory &)> &enumerator)
com::ubuntu::location::ProviderFactory::create_provider_for_name_with_config
Provider::Ptr create_provider_for_name_with_config(const std::string &name, const Configuration &config)
com::ubuntu::location::ProviderFactory::instance
static ProviderFactory & instance()
com::ubuntu::location::ProviderFactory::extract_undecorated_name
static std::string extract_undecorated_name(const std::string &name)
com::ubuntu::location::Provider::Ptr
std::shared_ptr< Provider > Ptr
Definition: provider.h:48
configuration.h
com::ubuntu::location::Configuration
boost::property_tree::ptree Configuration
Definition: configuration.h:29
com
Definition: accuracy.h:24
provider.h