Changeset 09ef9023bca7d8c58c93e3e13e8cd9ad6b110c4b

Show
Ignore:
Timestamp:
03/06/10 01:35:47 (5 months ago)
Author:
Nedko Arnaudov <nedko@…>
Children:
fc21df8068e684f6a73263e74d440c9ba045ffb0
Parents:
945b3aa6865654fd54707c298636a428c6510755
git-committer:
Nedko Arnaudov <nedko@arnaudov.name> / 2010-03-06T01:35:47Z+0200
Message:

daemon: implement timeout when waiting for jack server started signal

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • daemon/cmd_start_studio.c

    rcb5a2ef r09ef902  
    33 * LADI Session Handler (ladish) 
    44 * 
    5  * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name> 
     5 * Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name> 
    66 * 
    77 ************************************************************************** 
     
    2525 */ 
    2626 
     27#include <unistd.h> 
     28 
    2729#include "cmd.h" 
    2830#include "studio_internal.h" 
    2931#include "loader.h" 
    3032 
    31 #define cmd_ptr ((struct ladish_command *)context) 
     33struct ladish_command_start_studio 
     34{ 
     35  struct ladish_command command; 
     36  uint64_t deadline; 
     37}; 
     38 
     39static uint64_t get_current_microseconds(void) 
     40{ 
     41  struct timeval time; 
     42 
     43  if (gettimeofday(&time, NULL) != 0) 
     44    return 0; 
     45 
     46  return (uint64_t)time.tv_sec * 1000000 + (uint64_t)time.tv_usec; 
     47} 
     48 
     49#define cmd_ptr ((struct ladish_command_start_studio *)context) 
    3250 
    3351static bool run(void * context) 
     
    3654  unsigned int app_count; 
    3755 
    38   switch (cmd_ptr->state) 
     56  switch (cmd_ptr->command.state) 
    3957  { 
    4058  case LADISH_COMMAND_STATE_PENDING: 
     
    4361      log_info("Ignoring start request because studio is already started."); 
    4462      /* nothing to do, studio is already running */ 
    45       cmd_ptr->state = LADISH_COMMAND_STATE_DONE; 
     63      cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE; 
    4664      return true; 
    4765    } 
     
    6684    } 
    6785 
    68     cmd_ptr->state = LADISH_COMMAND_STATE_WAITING; 
     86    cmd_ptr->deadline = get_current_microseconds(); 
     87    if (cmd_ptr->deadline != 0) 
     88    { 
     89      cmd_ptr->deadline += 5000000; 
     90    } 
     91 
     92    cmd_ptr->command.state = LADISH_COMMAND_STATE_WAITING; 
    6993    /* fall through */ 
    7094  case LADISH_COMMAND_STATE_WAITING: 
     
    7397      /* we are still waiting for the JACK server start */ 
    7498      ASSERT(!ladish_environment_get(&g_studio.env_store, ladish_environment_jack_server_started)); /* someone else consumed the state change? */ 
     99 
     100      if (cmd_ptr->deadline != 0 && get_current_microseconds() >= cmd_ptr->deadline) 
     101      { 
     102        log_error("Starting JACK server succeded, but 'started' signal was not received within 5 seconds."); 
     103        cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE; 
     104        return false; 
     105      } 
     106 
    75107      return true; 
    76108    } 
     
    82114    on_event_jack_started();    /* fetch configuration and announce start */ 
    83115 
    84     cmd_ptr->state = LADISH_COMMAND_STATE_DONE; 
     116    cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE; 
    85117    return true; 
    86118  } 
     
    94126bool ladish_command_start_studio(void * call_ptr, struct ladish_cqueue * queue_ptr) 
    95127{ 
    96   struct ladish_command * cmd_ptr; 
     128  struct ladish_command_start_studio * cmd_ptr; 
    97129 
    98   cmd_ptr = ladish_command_new(sizeof(struct ladish_command)); 
     130  cmd_ptr = ladish_command_new(sizeof(struct ladish_command_start_studio)); 
    99131  if (cmd_ptr == NULL) 
    100132  { 
     
    103135  } 
    104136 
    105   cmd_ptr->run = run; 
     137  cmd_ptr->command.run = run; 
     138  cmd_ptr->deadline = 0; 
    106139 
    107   if (!ladish_cqueue_add_command(queue_ptr, cmd_ptr)) 
     140  if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command)) 
    108141  { 
    109142    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_cqueue_add_command() failed.");