~ci-train-bot/location-service/location-service-ubuntu-vivid-landing-019

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/service/daemon.cpp

  • Committer: CI Train Bot
  • Author(s): Scott Sweeny
  • Date: 2016-01-06 16:15:26 UTC
  • mfrom: (197.4.11 async-providers.15.04)
  • Revision ID: ci-train-bot@canonical.com-20160106161526-ayi7kslo1eon3d53
Allow providers to register themselves asynchronously Fixes: #1415029
Approved by: Thomas Voß

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
 
184
184
    auto runtime = location::service::Runtime::create(4);
185
185
 
186
 
    const location::Configuration empty_provider_configuration;
187
 
 
188
 
    std::set<location::Provider::Ptr> instantiated_providers;
189
 
 
 
186
    location::service::DefaultConfiguration dc;
 
187
    auto engine = dc.the_engine(std::set<location::Provider::Ptr>{}, dc.the_provider_selection_policy(), config.settings);
190
188
    for (const std::string& provider : config.providers)
191
189
    {
192
190
        std::cout << "Instantiating and configuring: " << provider << std::endl;
193
191
 
194
192
        try
195
193
        {
196
 
            auto p = location::ProviderFactory::instance().create_provider_for_name_with_config(
197
 
                        provider,
198
 
                        config.provider_options.count(provider) > 0 ?
199
 
                            config.provider_options.at(provider) : empty_provider_configuration);
200
 
 
201
 
            if (p)
202
 
                instantiated_providers.insert(p);
203
 
            else
204
 
                throw std::runtime_error("Problem instantiating provider");
205
 
 
 
194
            auto result = std::async(std::launch::async, [provider, config, engine] {
 
195
                return location::ProviderFactory::instance().create_provider_for_name_with_config(
 
196
                    provider,
 
197
                    config.provider_options.count(provider) > 0 ?
 
198
                        config.provider_options.at(provider) : location::Configuration {},
 
199
                    [engine](Provider::Ptr provider)
 
200
                    {
 
201
                        engine->add_provider(provider);
 
202
                    }
 
203
                );
 
204
            });
206
205
        } catch(const std::runtime_error& e)
207
206
        {
208
207
            std::cerr << "Issue instantiating provider: " << e.what() << std::endl;
214
213
 
215
214
    runtime->start();
216
215
 
217
 
    location::service::DefaultConfiguration dc;
218
 
 
219
216
    location::service::Implementation::Configuration configuration
220
217
    {
221
218
        config.incoming,
222
219
        config.outgoing,
223
 
        dc.the_engine(instantiated_providers, dc.the_provider_selection_policy(), config.settings),
 
220
        engine,
224
221
        dc.the_permission_manager(config.outgoing),
225
222
        location::service::Harvester::Configuration
226
223
        {