lomiri-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_LOMIRI_LOCATION_PROVIDER_FACTORY_H_
19#define LOCATION_SERVICE_COM_LOMIRI_LOCATION_PROVIDER_FACTORY_H_
20
23
24#include <functional>
25#include <map>
26#include <memory>
27#include <mutex>
28#include <string>
29
30namespace com
31{
32namespace lomiri
33{
34namespace location
35{
36class Provider;
37
39{
40 public:
42 typedef std::function<Provider::Ptr(const Configuration&)> Factory;
43
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_LOMIRI_LOCATION_PROVIDER_FACTORY_H_
static ProviderFactory & instance()
void add_factory_for_name(const std::string &name, const Factory &factory)
std::function< Provider::Ptr(const Configuration &)> Factory
Provider::Ptr create_provider_for_name_with_config(const std::string &name, const Configuration &config)
static std::string extract_undecorated_name(const std::string &name)
void enumerate(const std::function< void(const std::string &, const Factory &)> &enumerator)
void create_provider_for_name_with_config(const std::string &name, const Configuration &config, const std::function< void(Provider::Ptr)> &cb)
com::lomiri::location::Configuration Configuration
std::shared_ptr< Provider > Ptr
Definition provider.h:48
boost::property_tree::ptree Configuration
Definition accuracy.h:24