Changeset 09ef9023bca7d8c58c93e3e13e8cd9ad6b110c4b
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rcb5a2ef
|
r09ef902
|
|
| 3 | 3 | * LADI Session Handler (ladish) |
| 4 | 4 | * |
| 5 | | * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name> |
| | 5 | * Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name> |
| 6 | 6 | * |
| 7 | 7 | ************************************************************************** |
| … |
… |
|
| 25 | 25 | */ |
| 26 | 26 | |
| | 27 | #include <unistd.h> |
| | 28 | |
| 27 | 29 | #include "cmd.h" |
| 28 | 30 | #include "studio_internal.h" |
| 29 | 31 | #include "loader.h" |
| 30 | 32 | |
| 31 | | #define cmd_ptr ((struct ladish_command *)context) |
| | 33 | struct ladish_command_start_studio |
| | 34 | { |
| | 35 | struct ladish_command command; |
| | 36 | uint64_t deadline; |
| | 37 | }; |
| | 38 | |
| | 39 | static 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) |
| 32 | 50 | |
| 33 | 51 | static bool run(void * context) |
| … |
… |
|
| 36 | 54 | unsigned int app_count; |
| 37 | 55 | |
| 38 | | switch (cmd_ptr->state) |
| | 56 | switch (cmd_ptr->command.state) |
| 39 | 57 | { |
| 40 | 58 | case LADISH_COMMAND_STATE_PENDING: |
| … |
… |
|
| 43 | 61 | log_info("Ignoring start request because studio is already started."); |
| 44 | 62 | /* nothing to do, studio is already running */ |
| 45 | | cmd_ptr->state = LADISH_COMMAND_STATE_DONE; |
| | 63 | cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE; |
| 46 | 64 | return true; |
| 47 | 65 | } |
| … |
… |
|
| 66 | 84 | } |
| 67 | 85 | |
| 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; |
| 69 | 93 | /* fall through */ |
| 70 | 94 | case LADISH_COMMAND_STATE_WAITING: |
| … |
… |
|
| 73 | 97 | /* we are still waiting for the JACK server start */ |
| 74 | 98 | 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 | |
| 75 | 107 | return true; |
| 76 | 108 | } |
| … |
… |
|
| 82 | 114 | on_event_jack_started(); /* fetch configuration and announce start */ |
| 83 | 115 | |
| 84 | | cmd_ptr->state = LADISH_COMMAND_STATE_DONE; |
| | 116 | cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE; |
| 85 | 117 | return true; |
| 86 | 118 | } |
| … |
… |
|
| 94 | 126 | bool ladish_command_start_studio(void * call_ptr, struct ladish_cqueue * queue_ptr) |
| 95 | 127 | { |
| 96 | | struct ladish_command * cmd_ptr; |
| | 128 | struct ladish_command_start_studio * cmd_ptr; |
| 97 | 129 | |
| 98 | | cmd_ptr = ladish_command_new(sizeof(struct ladish_command)); |
| | 130 | cmd_ptr = ladish_command_new(sizeof(struct ladish_command_start_studio)); |
| 99 | 131 | if (cmd_ptr == NULL) |
| 100 | 132 | { |
| … |
… |
|
| 103 | 135 | } |
| 104 | 136 | |
| 105 | | cmd_ptr->run = run; |
| | 137 | cmd_ptr->command.run = run; |
| | 138 | cmd_ptr->deadline = 0; |
| 106 | 139 | |
| 107 | | if (!ladish_cqueue_add_command(queue_ptr, cmd_ptr)) |
| | 140 | if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command)) |
| 108 | 141 | { |
| 109 | 142 | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_cqueue_add_command() failed."); |