~ssweeny/location-service/async-providers.15.04

« back to all changes in this revision

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

  • Committer: Scott Sweeny
  • Date: 2015-11-19 23:36:32 UTC
  • Revision ID: scott.sweeny@canonical.com-20151119233632-q136n1v14gad5uy9
Make create_provider... call async

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
        trap->stop();
176
176
    });
177
177
 
178
 
    const location::Configuration empty_provider_configuration;
179
 
 
180
178
    location::service::DefaultConfiguration dc;
181
179
    auto engine = dc.the_engine(std::set<location::Provider::Ptr>{}, dc.the_provider_selection_policy(), config.settings);
182
180
 
186
184
 
187
185
        try
188
186
        {
189
 
            location::ProviderFactory::instance().create_provider_for_name_with_config(
190
 
                        provider,
191
 
                        config.provider_options.count(provider) > 0 ?
192
 
                            config.provider_options.at(provider) : empty_provider_configuration,
193
 
                        [engine](Provider::Ptr provider)
194
 
                        {
195
 
                            std::cout << "****** CALLBACK ADDING PROVIDER ******" << std::endl;
196
 
                            engine->add_provider(provider);
197
 
                        });
 
187
            auto result = std::async(std::launch::async, [provider, config, engine] {
 
188
                return location::ProviderFactory::instance().create_provider_for_name_with_config(
 
189
                    provider,
 
190
                    config.provider_options.count(provider) > 0 ?
 
191
                        config.provider_options.at(provider) : location::Configuration {},
 
192
                    [engine](Provider::Ptr provider)
 
193
                    {
 
194
                        engine->add_provider(provider);
 
195
                    }
 
196
                );
 
197
            });
198
198
        } catch(const std::runtime_error& e)
199
199
        {
200
200
            std::cerr << "Issue instantiating provider: " << e.what() << std::endl;