Wait as short as possible after starting win32 sensor app

Do not use a fixed 5 second delay after having a started a windows
sensor application, instead try to access the shared memory area
repeatedly and only give up after 10 seconds. Please note that for this
feature to be usable the sensor app must be found in PATH.
This commit is contained in:
Stefan Gehn 2014-07-06 18:37:43 +02:00
parent ff5cd65678
commit d712ce32ce
1 changed files with 10 additions and 4 deletions

View File

@ -73,6 +73,8 @@ static gboolean
shm_open_or_start_app(ShmData *shm, const wchar_t *shm_name,
const gchar *app_name)
{
guint retries;
/* Try to open shared memory area and return if successful*/
if (shm_open(shm, shm_name))
return TRUE;
@ -91,11 +93,15 @@ shm_open_or_start_app(ShmData *shm, const wchar_t *shm_name,
"Started sensor-app %s, waiting for it to initialize\n",
app_name);
// 5 second wait to allow sensor-app init
g_usleep(5 * G_USEC_PER_SEC);
/* Wait up to retries seconds for the shared memory area to be accessible */
for (retries = 10; retries > 0; --retries)
{
if (shm_open(shm, shm_name))
return TRUE;
g_usleep(1 * G_USEC_PER_SEC); /* delay to allow sensor-app to startup */
}
/* Retry open of shm-file */
return shm_open(shm, shm_name);
return FALSE;
}