Skinny: store accessory status in db instead of memory

(this is not used yet)
This commit is contained in:
Mathieu Parent 2011-04-14 13:02:27 +02:00
parent 2b6f70708c
commit 6105757898
3 changed files with 48 additions and 18 deletions

View File

@ -58,7 +58,10 @@ static char devices_sql[] =
" type INTEGER,\n" " type INTEGER,\n"
" max_streams INTEGER,\n" " max_streams INTEGER,\n"
" port INTEGER,\n" " port INTEGER,\n"
" codec_string VARCHAR(255)\n" " codec_string VARCHAR(255),\n"
" headset INTEGER,\n"
" handset INTEGER,\n"
" speaker INTEGER\n"
");\n"; ");\n";
static char lines_sql[] = static char lines_sql[] =
@ -1916,10 +1919,10 @@ static switch_status_t load_skinny_config(void)
switch_odbc_handle_exec(profile->master_odbc, active_lines_sql, NULL, NULL); switch_odbc_handle_exec(profile->master_odbc, active_lines_sql, NULL, NULL);
} else { } else {
if ((db = switch_core_db_open_file(profile->dbname))) { if ((db = switch_core_db_open_file(profile->dbname))) {
switch_core_db_test_reactive(db, "SELECT * FROM skinny_devices", NULL, devices_sql); switch_core_db_test_reactive(db, "SELECT headset FROM skinny_devices", "DROP TABLE skinny_devices", devices_sql);
switch_core_db_test_reactive(db, "SELECT * FROM skinny_lines", NULL, lines_sql); switch_core_db_test_reactive(db, "SELECT * FROM skinny_lines", "DROP TABLE skinny_lines", lines_sql);
switch_core_db_test_reactive(db, "SELECT * FROM skinny_buttons", NULL, buttons_sql); switch_core_db_test_reactive(db, "SELECT * FROM skinny_buttons", "DROP TABLE skinny_buttons", buttons_sql);
switch_core_db_test_reactive(db, "SELECT * FROM skinny_active_lines", NULL, active_lines_sql); switch_core_db_test_reactive(db, "SELECT * FROM skinny_active_lines", "DROP TABLE skinny_active_lines", active_lines_sql);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
continue; continue;

View File

@ -136,9 +136,6 @@ struct listener {
char device_name[16]; char device_name[16];
uint32_t device_instance; uint32_t device_instance;
uint32_t device_type; uint32_t device_type;
uint32_t headset;
uint32_t handset;
uint32_t speaker;
char firmware_version[16]; char firmware_version[16];
char *soft_key_set_set; char *soft_key_set_set;

View File

@ -1900,16 +1900,20 @@ switch_status_t skinny_handle_soft_key_template_request(listener_t *listener, sk
switch_status_t skinny_headset_status_message(listener_t *listener, skinny_message_t *request) switch_status_t skinny_headset_status_message(listener_t *listener, skinny_message_t *request)
{ {
char *sql;
skinny_check_data_length(request, sizeof(request->data.headset_status)); skinny_check_data_length(request, sizeof(request->data.headset_status));
switch(request->data.headset_status.mode) { if ((sql = switch_mprintf(
case 1: "UPDATE skinny_devices SET headset=%d WHERE name='%s' and instance=%d",
listener->headset = SKINNY_ACCESSORY_STATE_OFFHOOK; (request->data.headset_status.mode==1) ? SKINNY_ACCESSORY_STATE_OFFHOOK : SKINNY_ACCESSORY_STATE_ONHOOK,
break; listener->device_name,
default: listener->device_instance
listener->headset = SKINNY_ACCESSORY_STATE_ONHOOK; ))) {
break; skinny_execute_sql(listener->profile, sql, listener->profile->sql_mutex);
switch_safe_free(sql);
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -2037,17 +2041,43 @@ switch_status_t skinny_handle_dialed_phone_book_message(listener_t *listener, sk
} }
switch_status_t skinny_handle_accessory_status_message(listener_t *listener, skinny_message_t *request) switch_status_t skinny_handle_accessory_status_message(listener_t *listener, skinny_message_t *request)
{ {
char *sql;
skinny_check_data_length(request, sizeof(request->data.accessory_status)); skinny_check_data_length(request, sizeof(request->data.accessory_status));
switch(request->data.accessory_status.accessory_id) { switch(request->data.accessory_status.accessory_id) {
case SKINNY_ACCESSORY_HEADSET: case SKINNY_ACCESSORY_HEADSET:
listener->headset = request->data.accessory_status.accessory_status; if ((sql = switch_mprintf(
"UPDATE skinny_devices SET headset=%d WHERE name='%s' and instance=%d",
request->data.accessory_status.accessory_status,
listener->device_name,
listener->device_instance
))) {
skinny_execute_sql(listener->profile, sql, listener->profile->sql_mutex);
switch_safe_free(sql);
}
break; break;
case SKINNY_ACCESSORY_HANDSET: case SKINNY_ACCESSORY_HANDSET:
listener->handset = request->data.accessory_status.accessory_status; if ((sql = switch_mprintf(
"UPDATE skinny_devices SET handset=%d WHERE name='%s' and instance=%d",
request->data.accessory_status.accessory_status,
listener->device_name,
listener->device_instance
))) {
skinny_execute_sql(listener->profile, sql, listener->profile->sql_mutex);
switch_safe_free(sql);
}
break; break;
case SKINNY_ACCESSORY_SPEAKER: case SKINNY_ACCESSORY_SPEAKER:
listener->speaker = request->data.accessory_status.accessory_status; if ((sql = switch_mprintf(
"UPDATE skinny_devices SET speaker=%d WHERE name='%s' and instance=%d",
request->data.accessory_status.accessory_status,
listener->device_name,
listener->device_instance
))) {
skinny_execute_sql(listener->profile, sql, listener->profile->sql_mutex);
switch_safe_free(sql);
}
break; break;
} }