Navigation Menu

Skip to content

Commit

Permalink
[qtlocation] Start Geoclue client position interface asynchronously. …
Browse files Browse the repository at this point in the history
…Contributes to JB#38358

Previously, the geoclue client position interface was started via
an asynchronous method call.  This one could stall for multiple
seconds if the dbus call required the geoclue service to be started.

This commit replaces it with an asynchronous call which doesn't stall
the GUI thread.

Contributes to JB#38358
  • Loading branch information
Chris Adams committed Apr 19, 2017
1 parent 8770366 commit 3020dff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/plugins/position/geoclue/qgeocluemaster.cpp
Expand Up @@ -80,6 +80,22 @@ bool QGeoclueMaster::hasMasterClient() const
return m_client && m_masterPosition;
}

void createGeoclueMasterClientPositionCallback(GeoclueMasterClient *,
GeocluePosition *position,
GError *error,
QGeoclueMaster *geoclueMaster)
{
if (error) {
qCritical("QGeoclueMaster failed to get master position object");
g_error_free(error);
g_object_unref(geoclueMaster->m_client);
geoclueMaster->m_client = 0;
return;
}

geoclueMaster->m_masterPosition = position;
}

bool QGeoclueMaster::createMasterClient(GeoclueAccuracyLevel accuracy, GeoclueResourceFlags resourceFlags)
{
Q_ASSERT(!m_client && !m_masterPosition);
Expand Down Expand Up @@ -121,13 +137,7 @@ bool QGeoclueMaster::createMasterClient(GeoclueAccuracyLevel accuracy, GeoclueRe

// Need to create the master position interface even though it will not be used, otherwise
// GetPositionProvider always returns empty strings.
m_masterPosition = geoclue_master_client_create_position(m_client, 0);
if (!m_masterPosition) {
qCritical("QGeoclueMaster failed to get master position object");
g_object_unref(m_client);
m_client = 0;
return false;
}
geoclue_master_client_create_position_async(m_client, reinterpret_cast<CreatePositionCallback>(createGeoclueMasterClientPositionCallback), this);

return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/position/geoclue/qgeocluemaster.h
Expand Up @@ -61,6 +61,10 @@ class QGeoclueMaster
private:
GeoclueMasterClient *m_client;
GeocluePosition *m_masterPosition;
friend void createGeoclueMasterClientPositionCallback(GeoclueMasterClient *,
GeocluePosition *position,
GError *error,
QGeoclueMaster *geoclueMaster);

QObject *m_handler;
};
Expand Down

0 comments on commit 3020dff

Please sign in to comment.