Sat Mar 24 23:29:04 2007

Asterisk developer's documentation


indications.h File Reference

BSD Telephony Of Mexico "Tormenta" Tone Zone Support 2/22/01. More...

#include "asterisk/lock.h"

Include dependency graph for indications.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tone_zone
struct  tone_zone_sound

Functions

tone_zone_soundast_get_indication_tone (const struct tone_zone *zone, const char *indication)
tone_zoneast_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)

Variables

tone_zonetone_zones
ast_mutex_t tzlock


Detailed Description

BSD Telephony Of Mexico "Tormenta" Tone Zone Support 2/22/01.

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.


Function Documentation

struct tone_zone_sound* ast_get_indication_tone const struct tone_zone zone,
const char *  indication
 

Definition at line 397 of file indications.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), current_tonezone, LOG_WARNING, tone_zone_sound::name, tone_zone_sound::next, tone_zones, tone_zone::tones, and tzlock.

Referenced by ast_app_dtget(), ast_indicate(), handle_playtones(), and play_dialtone().

00398 {
00399    struct tone_zone_sound *ts;
00400 
00401    /* we need some tonezone, pick the first */
00402    if (zone == NULL && current_tonezone)
00403       zone = current_tonezone;   /* default country? */
00404    if (zone == NULL && tone_zones)
00405       zone = tone_zones;      /* any country? */
00406    if (zone == NULL)
00407       return 0;   /* not a single country insight */
00408 
00409    if (ast_mutex_lock(&tzlock)) {
00410       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00411       return 0;
00412    }
00413    for (ts=zone->tones; ts; ts=ts->next) {
00414       if (strcasecmp(indication,ts->name)==0) {
00415          /* found indication! */
00416          ast_mutex_unlock(&tzlock);
00417          return ts;
00418       }
00419    }
00420    /* nothing found, sorry */
00421    ast_mutex_unlock(&tzlock);
00422    return 0;
00423 }

struct tone_zone* ast_get_indication_zone const char *  country  ) 
 

Definition at line 359 of file indications.c.

References tone_zone::alias, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), tone_zone::country, current_tonezone, LOG_WARNING, tone_zone::next, tone_zones, and tzlock.

Referenced by ast_set_indication_country(), handle_add_indication(), and handle_remove_indication().

00360 {
00361    struct tone_zone *tz;
00362    int alias_loop = 0;
00363 
00364    /* we need some tonezone, pick the first */
00365    if (country == NULL && current_tonezone)
00366       return current_tonezone;   /* default country? */
00367    if (country == NULL && tone_zones)
00368       return tone_zones;      /* any country? */
00369    if (country == NULL)
00370       return 0;   /* not a single country insight */
00371 
00372    if (ast_mutex_lock(&tzlock)) {
00373       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00374       return 0;
00375    }
00376    do {
00377       for (tz=tone_zones; tz; tz=tz->next) {
00378          if (strcasecmp(country,tz->country)==0) {
00379             /* tone_zone found */
00380             if (tz->alias && tz->alias[0]) {
00381                country = tz->alias;
00382                break;
00383             }
00384             ast_mutex_unlock(&tzlock);
00385             return tz;
00386          }
00387       }
00388    } while (++alias_loop<20 && tz);
00389    ast_mutex_unlock(&tzlock);
00390    if (alias_loop==20)
00391       ast_log(LOG_NOTICE,"Alias loop for '%s' forcefull broken\n",country);
00392    /* nothing found, sorry */
00393    return 0;
00394 }

int ast_playtones_start struct ast_channel chan,
int  vol,
const char *  tonelist,
int  interruptible
 

Definition at line 213 of file indications.c.

References ast_activate_generator(), ast_log(), ast_strdupa, playtones_item::duration, playtones_item::fac1, playtones_item::fac2, free, playtones_item::init_v2_1, playtones_item::init_v2_2, playtones_item::init_v3_1, playtones_item::init_v3_2, playtones_def::interruptible, playtones_def::items, LOG_WARNING, midi_tohz, playtones_item::modulate, ast_channel::name, playtones_def::nitems, playtones, realloc, playtones_def::reppos, s, strsep(), and playtones_def::vol.

Referenced by ast_app_dtget(), ast_indicate(), do_senddigit(), handle_playtones(), play_dialtone(), and send_digit_to_chan().

00214 {
00215    char *s, *data = ast_strdupa(playlst); /* cute */
00216    struct playtones_def d = { vol, -1, 0, 1, NULL};
00217    char *stringp=NULL;
00218    char *separator;
00219    if (!data)
00220       return -1;
00221    if (vol < 1)
00222       d.vol = 7219; /* Default to -8db */
00223 
00224    d.interruptible = interruptible;
00225    
00226    stringp=data;
00227    /* the stringp/data is not null here */
00228    /* check if the data is separated with '|' or with ',' by default */
00229    if (strchr(stringp,'|'))
00230       separator = "|";
00231    else
00232       separator = ",";
00233    s = strsep(&stringp,separator);
00234    while (s && *s) {
00235       int freq1, freq2, time, modulate=0, midinote=0;
00236 
00237       if (s[0]=='!')
00238          s++;
00239       else if (d.reppos == -1)
00240          d.reppos = d.nitems;
00241       if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &time) == 3) {
00242          /* f1+f2/time format */
00243       } else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
00244          /* f1+f2 format */
00245          time = 0;
00246       } else if (sscanf(s, "%d*%d/%d", &freq1, &freq2, &time) == 3) {
00247          /* f1*f2/time format */
00248          modulate = 1;
00249       } else if (sscanf(s, "%d*%d", &freq1, &freq2) == 2) {
00250          /* f1*f2 format */
00251          time = 0;
00252          modulate = 1;
00253       } else if (sscanf(s, "%d/%d", &freq1, &time) == 2) {
00254          /* f1/time format */
00255          freq2 = 0;
00256       } else if (sscanf(s, "%d", &freq1) == 1) {
00257          /* f1 format */
00258          freq2 = 0;
00259          time = 0;
00260       } else if (sscanf(s, "M%d+M%d/%d", &freq1, &freq2, &time) == 3) {
00261          /* Mf1+Mf2/time format */
00262          midinote = 1;
00263       } else if (sscanf(s, "M%d+M%d", &freq1, &freq2) == 2) {
00264          /* Mf1+Mf2 format */
00265          time = 0;
00266          midinote = 1;
00267       } else if (sscanf(s, "M%d*M%d/%d", &freq1, &freq2, &time) == 3) {
00268          /* Mf1*Mf2/time format */
00269          modulate = 1;
00270          midinote = 1;
00271       } else if (sscanf(s, "M%d*M%d", &freq1, &freq2) == 2) {
00272          /* Mf1*Mf2 format */
00273          time = 0;
00274          modulate = 1;
00275          midinote = 1;
00276       } else if (sscanf(s, "M%d/%d", &freq1, &time) == 2) {
00277          /* Mf1/time format */
00278          freq2 = -1;
00279          midinote = 1;
00280       } else if (sscanf(s, "M%d", &freq1) == 1) {
00281          /* Mf1 format */
00282          freq2 = -1;
00283          time = 0;
00284          midinote = 1;
00285       } else {
00286          ast_log(LOG_WARNING,"%s: tone component '%s' of '%s' is no good\n",chan->name,s,playlst);
00287          return -1;
00288       }
00289 
00290       if (midinote) {
00291          /* midi notes must be between 0 and 127 */
00292          if ((freq1 >= 0) && (freq1 <= 127))
00293             freq1 = midi_tohz[freq1];
00294          else
00295             freq1 = 0;
00296 
00297          if ((freq2 >= 0) && (freq2 <= 127))
00298             freq2 = midi_tohz[freq2];
00299          else
00300             freq2 = 0;
00301       }
00302 
00303       d.items = realloc(d.items,(d.nitems+1)*sizeof(struct playtones_item));
00304       if (d.items == NULL) {
00305          ast_log(LOG_WARNING, "Realloc failed!\n");
00306          return -1;
00307       }
00308       d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (freq1 / 8000.0)) * 32768.0;
00309       d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (freq1 / 8000.0)) * d.vol;
00310       d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (freq1 / 8000.0)) * d.vol;
00311 
00312       d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (freq2 / 8000.0)) * 32768.0;
00313       d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (freq2 / 8000.0)) * d.vol;
00314       d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (freq2 / 8000.0)) * d.vol;
00315       d.items[d.nitems].duration = time;
00316       d.items[d.nitems].modulate = modulate;
00317       d.nitems++;
00318 
00319       s = strsep(&stringp,separator);
00320    }
00321 
00322    if (ast_activate_generator(chan, &playtones, &d)) {
00323       free(d.items);
00324       return -1;
00325    }
00326    return 0;
00327 }

void ast_playtones_stop struct ast_channel chan  ) 
 

Stop the tones from playing

Definition at line 329 of file indications.c.

References ast_deactivate_generator().

Referenced by ast_app_dtget(), ast_indicate(), and handle_stopplaytones().

00330 {
00331    ast_deactivate_generator(chan);
00332 }

int ast_register_indication struct tone_zone zone,
const char *  indication,
const char *  tonelist
 

Definition at line 528 of file indications.c.

References tone_zone::alias, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), tone_zone_sound::data, free, LOG_WARNING, malloc, tone_zone_sound::name, tone_zone_sound::next, strdup, tone_zone::tones, and tzlock.

Referenced by handle_add_indication().

00529 {
00530    struct tone_zone_sound *ts,*ps;
00531 
00532    /* is it an alias? stop */
00533    if (zone->alias[0])
00534       return -1;
00535 
00536    if (ast_mutex_lock(&tzlock)) {
00537       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00538       return -2;
00539    }
00540    for (ps=NULL,ts=zone->tones; ts; ps=ts,ts=ts->next) {
00541       if (strcasecmp(indication,ts->name)==0) {
00542          /* indication already there, replace */
00543          free((void*)ts->name);
00544          free((void*)ts->data);
00545          break;
00546       }
00547    }
00548    if (!ts) {
00549       /* not there, we have to add */
00550       ts = malloc(sizeof(struct tone_zone_sound));
00551       if (!ts) {
00552          ast_log(LOG_WARNING, "Out of memory\n");
00553          ast_mutex_unlock(&tzlock);
00554          return -2;
00555       }
00556       ts->next = NULL;
00557    }
00558    ts->name = strdup(indication);
00559    ts->data = strdup(tonelist);
00560    if (ts->name==NULL || ts->data==NULL) {
00561       ast_log(LOG_WARNING, "Out of memory\n");
00562       ast_mutex_unlock(&tzlock);
00563       return -2;
00564    }
00565    if (ps)
00566       ps->next = ts;
00567    else
00568       zone->tones = ts;
00569    ast_mutex_unlock(&tzlock);
00570    return 0;
00571 }

int ast_register_indication_country struct tone_zone country  ) 
 

Definition at line 443 of file indications.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), tone_zone::country, current_tonezone, free_zone(), LOG_WARNING, tone_zone::next, tone_zones, and tzlock.

Referenced by handle_add_indication(), and ind_load_module().

00444 {
00445    struct tone_zone *tz,*pz;
00446 
00447    if (ast_mutex_lock(&tzlock)) {
00448       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00449       return -1;
00450    }
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 344 of file indications.c.

References ast_get_indication_zone(), ast_verbose(), current_tonezone, option_verbose, and VERBOSE_PREFIX_3.

Referenced by ind_load_module().

00345 {
00346    if (country) {
00347       struct tone_zone *z = ast_get_indication_zone(country);
00348       if (z) {
00349          if (option_verbose > 2)
00350             ast_verbose(VERBOSE_PREFIX_3 "Setting default indication country to '%s'\n",country);
00351          current_tonezone = z;
00352          return 0;
00353       }
00354    }
00355    return 1; /* not found */
00356 }

int ast_unregister_indication struct tone_zone zone,
const char *  indication
 

Definition at line 574 of file indications.c.

References tone_zone::alias, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), tone_zone_sound::data, free, LOG_WARNING, tone_zone_sound::name, tone_zone_sound::next, tone_zone::tones, and tzlock.

Referenced by handle_remove_indication().

00575 {
00576    struct tone_zone_sound *ts,*ps = NULL, *tmp;
00577    int res = -1;
00578 
00579    /* is it an alias? stop */
00580    if (zone->alias[0])
00581       return -1;
00582 
00583    if (ast_mutex_lock(&tzlock)) {
00584       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00585       return -1;
00586    }
00587    ts = zone->tones;
00588    while (ts) {
00589       if (strcasecmp(indication,ts->name)==0) {
00590          /* indication found */
00591          tmp = ts->next;
00592          if (ps)
00593             ps->next = tmp;
00594          else
00595             zone->tones = tmp;
00596          free((void*)ts->name);
00597          free((void*)ts->data);
00598          free(ts);
00599          ts = tmp;
00600          res = 0;
00601       }
00602       else {
00603          /* next zone please */
00604          ps = ts;
00605          ts = ts->next;
00606       }
00607    }
00608    /* indication not found, goodbye */
00609    ast_mutex_unlock(&tzlock);
00610    return res;
00611 }

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, LOG_WARNING, 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    if (ast_mutex_lock(&tzlock)) {
00489       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00490       return -1;
00491    }
00492    tz = tone_zones;
00493    while (tz) {
00494       if (country==NULL ||
00495           (strcasecmp(country, tz->country)==0 ||
00496            strcasecmp(country, tz->alias)==0)) {
00497          /* tone_zone found, remove */
00498          tmp = tz->next;
00499          if (pz)
00500             pz->next = tmp;
00501          else
00502             tone_zones = tmp;
00503          /* if we are unregistering the default country, w'll notice */
00504          if (tz == current_tonezone) {
00505             ast_log(LOG_NOTICE,"Removed default indication country '%s'\n",tz->country);
00506             current_tonezone = NULL;
00507          }
00508          if (option_verbose > 2)
00509             ast_verbose(VERBOSE_PREFIX_3 "Unregistered indication country '%s'\n",tz->country);
00510          free_zone(tz);
00511          if (tone_zones == tz)
00512             tone_zones = tmp;
00513          tz = tmp;
00514          res = 0;
00515       }
00516       else {
00517          /* next zone please */
00518          pz = tz;
00519          tz = tz->next;
00520       }
00521    }
00522    ast_mutex_unlock(&tzlock);
00523    return res;
00524 }


Variable Documentation

struct tone_zone* tone_zones
 

Definition at line 336 of file indications.c.

Referenced by ast_get_indication_tone(), ast_get_indication_zone(), ast_register_indication_country(), ast_unregister_indication_country(), and handle_show_indications().

ast_mutex_t tzlock
 

Referenced by ast_get_indication_tone(), ast_get_indication_zone(), ast_register_indication(), ast_register_indication_country(), ast_unregister_indication(), ast_unregister_indication_country(), and handle_show_indications().


Generated on Sat Mar 24 23:29:04 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.6