#include "asterisk/lock.h"
Go to the source code of this file.
Data Structures | |
struct | tone_zone |
struct | tone_zone_sound |
Functions | |
tone_zone_sound * | ast_get_indication_tone (const struct tone_zone *zone, const char *indication) |
tone_zone * | ast_get_indication_zone (const char *country) |
int | ast_playtones_start (struct ast_channel *chan, int vol, const char *tonelist, int interruptible) |
void | ast_playtones_stop (struct ast_channel *chan) |
int | ast_register_indication (struct tone_zone *zone, const char *indication, const char *tonelist) |
int | ast_register_indication_country (struct tone_zone *country) |
int | ast_set_indication_country (const char *country) |
int | ast_unregister_indication (struct tone_zone *zone, const char *indication) |
int | ast_unregister_indication_country (const char *country) |
tone_zone * | ast_walk_indications (const struct tone_zone *cur) |
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Primary Author: Pauline Middelink <middelink@polyware.nl>
Definition in file indications.h.
struct tone_zone_sound* ast_get_indication_tone | ( | const struct tone_zone * | zone, | |
const char * | indication | |||
) |
Definition at line 403 of file indications.c.
References ast_mutex_lock(), ast_mutex_unlock(), current_tonezone, tone_zone_sound::name, tone_zone_sound::next, tone_zones, tone_zone::tones, and tzlock.
Referenced by ast_app_dtget(), ast_indicate_data(), dialtone_indicate(), handle_playtones(), play_dialtone(), and read_exec().
00404 { 00405 struct tone_zone_sound *ts; 00406 00407 /* we need some tonezone, pick the first */ 00408 if (zone == NULL && current_tonezone) 00409 zone = current_tonezone; /* default country? */ 00410 if (zone == NULL && tone_zones) 00411 zone = tone_zones; /* any country? */ 00412 if (zone == NULL) 00413 return 0; /* not a single country insight */ 00414 00415 ast_mutex_lock(&tzlock); 00416 for (ts=zone->tones; ts; ts=ts->next) { 00417 if (strcasecmp(indication,ts->name)==0) { 00418 /* found indication! */ 00419 ast_mutex_unlock(&tzlock); 00420 return ts; 00421 } 00422 } 00423 /* nothing found, sorry */ 00424 ast_mutex_unlock(&tzlock); 00425 return 0; 00426 }
struct tone_zone* ast_get_indication_zone | ( | const char * | country | ) |
Definition at line 371 of file indications.c.
References tone_zone::alias, ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), tone_zone::country, current_tonezone, tone_zone::next, tone_zones, and tzlock.
Referenced by ast_set_indication_country(), func_channel_write_real(), handle_add_indication(), and handle_remove_indication().
00372 { 00373 struct tone_zone *tz; 00374 int alias_loop = 0; 00375 00376 if (ast_strlen_zero(country)) { 00377 /* No country specified? Return the default or the first in the list */ 00378 return current_tonezone ? current_tonezone : tone_zones; 00379 } 00380 00381 ast_mutex_lock(&tzlock); 00382 do { 00383 for (tz=tone_zones; tz; tz=tz->next) { 00384 if (strcasecmp(country,tz->country)==0) { 00385 /* tone_zone found */ 00386 if (tz->alias && tz->alias[0]) { 00387 country = tz->alias; 00388 break; 00389 } 00390 ast_mutex_unlock(&tzlock); 00391 return tz; 00392 } 00393 } 00394 } while (++alias_loop<20 && tz); 00395 ast_mutex_unlock(&tzlock); 00396 if (alias_loop==20) 00397 ast_log(LOG_NOTICE,"Alias loop for '%s' forcefull broken\n",country); 00398 /* nothing found, sorry */ 00399 return 0; 00400 }
int ast_playtones_start | ( | struct ast_channel * | chan, | |
int | vol, | |||
const char * | tonelist, | |||
int | interruptible | |||
) |
Definition at line 212 of file indications.c.
00213 { 00214 char *s, *data = ast_strdupa(playlst); /* cute */ 00215 struct playtones_def d = { vol, -1, 0, 1, NULL}; 00216 char *stringp; 00217 char *separator; 00218 00219 if (vol < 1) 00220 d.vol = 7219; /* Default to -8db */ 00221 00222 d.interruptible = interruptible; 00223 00224 stringp=data; 00225 /* the stringp/data is not null here */ 00226 /* check if the data is separated with '|' or with ',' by default */ 00227 if (strchr(stringp,'|')) 00228 separator = "|"; 00229 else 00230 separator = ","; 00231 s = strsep(&stringp,separator); 00232 while (s && *s) { 00233 int freq1, freq2, time, modulate=0, midinote=0; 00234 00235 if (s[0]=='!') 00236 s++; 00237 else if (d.reppos == -1) 00238 d.reppos = d.nitems; 00239 if (sscanf(s, "%30d+%30d/%30d", &freq1, &freq2, &time) == 3) { 00240 /* f1+f2/time format */ 00241 } else if (sscanf(s, "%30d+%30d", &freq1, &freq2) == 2) { 00242 /* f1+f2 format */ 00243 time = 0; 00244 } else if (sscanf(s, "%30d*%30d/%30d", &freq1, &freq2, &time) == 3) { 00245 /* f1*f2/time format */ 00246 modulate = 1; 00247 } else if (sscanf(s, "%30d*%30d", &freq1, &freq2) == 2) { 00248 /* f1*f2 format */ 00249 time = 0; 00250 modulate = 1; 00251 } else if (sscanf(s, "%30d/%30d", &freq1, &time) == 2) { 00252 /* f1/time format */ 00253 freq2 = 0; 00254 } else if (sscanf(s, "%30d", &freq1) == 1) { 00255 /* f1 format */ 00256 freq2 = 0; 00257 time = 0; 00258 } else if (sscanf(s, "M%30d+M%30d/%30d", &freq1, &freq2, &time) == 3) { 00259 /* Mf1+Mf2/time format */ 00260 midinote = 1; 00261 } else if (sscanf(s, "M%30d+M%30d", &freq1, &freq2) == 2) { 00262 /* Mf1+Mf2 format */ 00263 time = 0; 00264 midinote = 1; 00265 } else if (sscanf(s, "M%30d*M%30d/%30d", &freq1, &freq2, &time) == 3) { 00266 /* Mf1*Mf2/time format */ 00267 modulate = 1; 00268 midinote = 1; 00269 } else if (sscanf(s, "M%30d*M%30d", &freq1, &freq2) == 2) { 00270 /* Mf1*Mf2 format */ 00271 time = 0; 00272 modulate = 1; 00273 midinote = 1; 00274 } else if (sscanf(s, "M%30d/%30d", &freq1, &time) == 2) { 00275 /* Mf1/time format */ 00276 freq2 = -1; 00277 midinote = 1; 00278 } else if (sscanf(s, "M%30d", &freq1) == 1) { 00279 /* Mf1 format */ 00280 freq2 = -1; 00281 time = 0; 00282 midinote = 1; 00283 } else { 00284 ast_log(LOG_WARNING,"%s: tone component '%s' of '%s' is no good\n",chan->name,s,playlst); 00285 return -1; 00286 } 00287 00288 if (midinote) { 00289 /* midi notes must be between 0 and 127 */ 00290 if ((freq1 >= 0) && (freq1 <= 127)) 00291 freq1 = midi_tohz[freq1]; 00292 else 00293 freq1 = 0; 00294 00295 if ((freq2 >= 0) && (freq2 <= 127)) 00296 freq2 = midi_tohz[freq2]; 00297 else 00298 freq2 = 0; 00299 } 00300 00301 if (!(d.items = ast_realloc(d.items, (d.nitems + 1) * sizeof(*d.items)))) { 00302 return -1; 00303 } 00304 d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (freq1 / 8000.0)) * 32768.0; 00305 d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (freq1 / 8000.0)) * d.vol; 00306 d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (freq1 / 8000.0)) * d.vol; 00307 00308 d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (freq2 / 8000.0)) * 32768.0; 00309 d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (freq2 / 8000.0)) * d.vol; 00310 d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (freq2 / 8000.0)) * d.vol; 00311 d.items[d.nitems].duration = time; 00312 d.items[d.nitems].modulate = modulate; 00313 d.nitems++; 00314 00315 s = strsep(&stringp,separator); 00316 } 00317 00318 if (ast_activate_generator(chan, &playtones, &d)) { 00319 free(d.items); 00320 return -1; 00321 } 00322 return 0; 00323 }
void ast_playtones_stop | ( | struct ast_channel * | chan | ) |
Stop the tones from playing
Definition at line 325 of file indications.c.
00326 { 00327 ast_deactivate_generator(chan); 00328 }
int ast_register_indication | ( | struct tone_zone * | zone, | |
const char * | indication, | |||
const char * | tonelist | |||
) |
Definition at line 525 of file indications.c.
References tone_zone::alias, ast_malloc, ast_mutex_lock(), ast_mutex_unlock(), ast_strdup, tone_zone_sound::data, free, tone_zone_sound::name, tone_zone_sound::next, tone_zone::tones, and tzlock.
Referenced by handle_add_indication().
00526 { 00527 struct tone_zone_sound *ts,*ps; 00528 00529 /* is it an alias? stop */ 00530 if (zone->alias[0]) 00531 return -1; 00532 00533 ast_mutex_lock(&tzlock); 00534 for (ps=NULL,ts=zone->tones; ts; ps=ts,ts=ts->next) { 00535 if (strcasecmp(indication,ts->name)==0) { 00536 /* indication already there, replace */ 00537 free((void*)ts->name); 00538 free((void*)ts->data); 00539 break; 00540 } 00541 } 00542 if (!ts) { 00543 /* not there, we have to add */ 00544 if (!(ts = ast_malloc(sizeof(*ts)))) { 00545 ast_mutex_unlock(&tzlock); 00546 return -2; 00547 } 00548 ts->next = NULL; 00549 } 00550 if (!(ts->name = ast_strdup(indication)) || !(ts->data = ast_strdup(tonelist))) { 00551 ast_mutex_unlock(&tzlock); 00552 return -2; 00553 } 00554 if (ps) 00555 ps->next = ts; 00556 else 00557 zone->tones = ts; 00558 ast_mutex_unlock(&tzlock); 00559 return 0; 00560 }
int ast_register_indication_country | ( | struct tone_zone * | country | ) |
Definition at line 446 of file indications.c.
References ast_mutex_lock(), ast_mutex_unlock(), tone_zone::country, current_tonezone, free_zone(), tone_zone::next, tone_zones, and tzlock.
Referenced by handle_add_indication(), and ind_load_module().
00447 { 00448 struct tone_zone *tz,*pz; 00449 00450 ast_mutex_lock(&tzlock); 00451 for (pz=NULL,tz=tone_zones; tz; pz=tz,tz=tz->next) { 00452 if (strcasecmp(zone->country,tz->country)==0) { 00453 /* tone_zone already there, replace */ 00454 zone->next = tz->next; 00455 if (pz) 00456 pz->next = zone; 00457 else 00458 tone_zones = zone; 00459 /* if we are replacing the default zone, re-point it */ 00460 if (tz == current_tonezone) 00461 current_tonezone = zone; 00462 /* now free the previous zone */ 00463 free_zone(tz); 00464 ast_mutex_unlock(&tzlock); 00465 return 0; 00466 } 00467 } 00468 /* country not there, add */ 00469 zone->next = NULL; 00470 if (pz) 00471 pz->next = zone; 00472 else 00473 tone_zones = zone; 00474 ast_mutex_unlock(&tzlock); 00475 00476 if (option_verbose > 2) 00477 ast_verbose(VERBOSE_PREFIX_3 "Registered indication country '%s'\n",zone->country); 00478 return 0; 00479 }
int ast_set_indication_country | ( | const char * | country | ) |
Definition at line 356 of file indications.c.
References ast_get_indication_zone(), ast_verbose(), current_tonezone, option_verbose, and VERBOSE_PREFIX_3.
Referenced by ind_load_module().
00357 { 00358 if (country) { 00359 struct tone_zone *z = ast_get_indication_zone(country); 00360 if (z) { 00361 if (option_verbose > 2) 00362 ast_verbose(VERBOSE_PREFIX_3 "Setting default indication country to '%s'\n",country); 00363 current_tonezone = z; 00364 return 0; 00365 } 00366 } 00367 return 1; /* not found */ 00368 }
int ast_unregister_indication | ( | struct tone_zone * | zone, | |
const char * | indication | |||
) |
Definition at line 563 of file indications.c.
References tone_zone::alias, ast_mutex_lock(), ast_mutex_unlock(), tone_zone_sound::data, free, tone_zone_sound::name, tone_zone_sound::next, tone_zone::tones, and tzlock.
Referenced by handle_remove_indication().
00564 { 00565 struct tone_zone_sound *ts,*ps = NULL, *tmp; 00566 int res = -1; 00567 00568 /* is it an alias? stop */ 00569 if (zone->alias[0]) 00570 return -1; 00571 00572 ast_mutex_lock(&tzlock); 00573 ts = zone->tones; 00574 while (ts) { 00575 if (strcasecmp(indication,ts->name)==0) { 00576 /* indication found */ 00577 tmp = ts->next; 00578 if (ps) 00579 ps->next = tmp; 00580 else 00581 zone->tones = tmp; 00582 free((void*)ts->name); 00583 free((void*)ts->data); 00584 free(ts); 00585 ts = tmp; 00586 res = 0; 00587 } 00588 else { 00589 /* next zone please */ 00590 ps = ts; 00591 ts = ts->next; 00592 } 00593 } 00594 /* indication not found, goodbye */ 00595 ast_mutex_unlock(&tzlock); 00596 return res; 00597 }
int ast_unregister_indication_country | ( | const char * | country | ) |
Definition at line 483 of file indications.c.
References tone_zone::alias, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), tone_zone::country, current_tonezone, free_zone(), LOG_NOTICE, tone_zone::next, option_verbose, tone_zones, tzlock, and VERBOSE_PREFIX_3.
Referenced by handle_add_indication(), handle_remove_indication(), reload(), and unload_module().
00484 { 00485 struct tone_zone *tz, *pz = NULL, *tmp; 00486 int res = -1; 00487 00488 ast_mutex_lock(&tzlock); 00489 tz = tone_zones; 00490 while (tz) { 00491 if (country==NULL || 00492 (strcasecmp(country, tz->country)==0 || 00493 strcasecmp(country, tz->alias)==0)) { 00494 /* tone_zone found, remove */ 00495 tmp = tz->next; 00496 if (pz) 00497 pz->next = tmp; 00498 else 00499 tone_zones = tmp; 00500 /* if we are unregistering the default country, w'll notice */ 00501 if (tz == current_tonezone) { 00502 ast_log(LOG_NOTICE,"Removed default indication country '%s'\n",tz->country); 00503 current_tonezone = NULL; 00504 } 00505 if (option_verbose > 2) 00506 ast_verbose(VERBOSE_PREFIX_3 "Unregistered indication country '%s'\n",tz->country); 00507 free_zone(tz); 00508 if (tone_zones == tz) 00509 tone_zones = tmp; 00510 tz = tmp; 00511 res = 0; 00512 } 00513 else { 00514 /* next zone please */ 00515 pz = tz; 00516 tz = tz->next; 00517 } 00518 } 00519 ast_mutex_unlock(&tzlock); 00520 return res; 00521 }
Definition at line 339 of file indications.c.
References ast_mutex_lock(), ast_mutex_unlock(), tone_zone::next, tone_zones, and tzlock.
Referenced by handle_show_indications().
00340 { 00341 struct tone_zone *tz; 00342 00343 if (cur == NULL) 00344 return tone_zones; 00345 ast_mutex_lock(&tzlock); 00346 for (tz = tone_zones; tz; tz = tz->next) 00347 if (tz == cur) 00348 break; 00349 if (tz) 00350 tz = tz->next; 00351 ast_mutex_unlock(&tzlock); 00352 return tz; 00353 }