@ -41,9 +41,14 @@ DSMDialog::DSMDialog(AmPromptCollection& prompts,
DSMDialog : : ~ DSMDialog ( )
{
for ( vector < AmAudio File * > : : iterator it =
for ( vector < AmAudio * > : : iterator it =
audiofiles . begin ( ) ; it ! = audiofiles . end ( ) ; it + + )
delete * it ;
prompts . cleanup ( ( long ) this ) ;
for ( map < string , AmPromptCollection * > : : iterator it =
prompt_sets . begin ( ) ; it ! = prompt_sets . end ( ) ; it + + )
it - > second - > cleanup ( ( long ) this ) ;
}
void DSMDialog : : onInvite ( const AmSipRequest & req ) {
@ -93,13 +98,20 @@ void DSMDialog::onBye(const AmSipRequest& req)
void DSMDialog : : process ( AmEvent * event )
{
if ( event - > event_id = = DSM_EVENT_ID ) {
DSMEvent * dsm_event = dynamic_cast < DSMEvent * > ( event ) ;
if ( dsm_event ) {
engine . runEvent ( this , DSMCondition : : DSMEvent , & dsm_event - > params ) ;
return ;
}
}
AmAudioEvent * audio_event = dynamic_cast < AmAudioEvent * > ( event ) ;
if ( audio_event & &
( ( audio_event - > event_id = = AmAudioEvent : : cleared ) | |
( audio_event - > event_id = = AmAudioEvent : : noAudio ) ) ) {
// todo: run event
engine . runEvent ( this , DSMCondition : : NoAudio , NULL ) ;
return ;
}
@ -111,6 +123,13 @@ void DSMDialog::process(AmEvent* event)
engine . runEvent ( this , DSMCondition : : Timer , & params ) ;
}
AmPlaylistSeparatorEvent * sep_ev = dynamic_cast < AmPlaylistSeparatorEvent * > ( event ) ;
if ( sep_ev ) {
map < string , string > params ;
params [ " id " ] = int2str ( sep_ev - > event_id ) ;
engine . runEvent ( this , DSMCondition : : PlaylistSeparator , & params ) ;
}
AmSession : : process ( event ) ;
}
@ -120,7 +139,12 @@ inline UACAuthCred* DSMDialog::getCredentials() {
void DSMDialog : : playPrompt ( const string & name , bool loop ) {
DBG ( " playing prompt '%s' \n " , name . c_str ( ) ) ;
prompts . addToPlaylist ( name , ( long ) this , playlist , /*front =*/ false , loop ) ;
if ( prompts . addToPlaylist ( name , ( long ) this , playlist ,
/*front =*/ false , loop ) )
SET_ERRNO ( DSM_ERRNO_UNKNOWN_ARG ) ;
else
SET_ERRNO ( DSM_ERRNO_OK ) ;
}
void DSMDialog : : closePlaylist ( bool notify ) {
@ -134,6 +158,7 @@ void DSMDialog::playFile(const string& name, bool loop) {
ERROR ( " audio file '%s' could not be opened for reading. \n " ,
name . c_str ( ) ) ;
delete af ;
SET_ERRNO ( DSM_ERRNO_FILE ) ;
return ;
}
if ( loop )
@ -141,6 +166,7 @@ void DSMDialog::playFile(const string& name, bool loop) {
playlist . addToPlaylist ( new AmPlaylistItem ( af , NULL ) ) ;
audiofiles . push_back ( af ) ;
SET_ERRNO ( DSM_ERRNO_OK ) ;
}
void DSMDialog : : recordFile ( const string & name ) {
@ -154,9 +180,11 @@ void DSMDialog::recordFile(const string& name) {
name . c_str ( ) ) ;
delete rec_file ;
rec_file = NULL ;
SET_ERRNO ( DSM_ERRNO_FILE ) ;
return ;
}
setInput ( rec_file ) ;
SET_ERRNO ( DSM_ERRNO_OK ) ;
}
void DSMDialog : : stopRecord ( ) {
@ -165,8 +193,10 @@ void DSMDialog::stopRecord() {
rec_file - > close ( ) ;
delete rec_file ;
rec_file = NULL ;
SET_ERRNO ( DSM_ERRNO_OK ) ;
} else {
WARN ( " stopRecord: we are not recording \n " ) ;
SET_ERRNO ( DSM_ERRNO_FILE ) ;
return ;
}
}
@ -192,10 +222,26 @@ void DSMDialog::setPromptSet(const string& name) {
if ( it = = prompt_sets . end ( ) ) {
ERROR ( " prompt set %s unknown \n " , name . c_str ( ) ) ;
SET_ERRNO ( DSM_ERRNO_UNKNOWN_ARG ) ;
return ;
}
DBG ( " setting prompt set '%s' \n " , name . c_str ( ) ) ;
prompts = * it - > second ;
SET_ERRNO ( DSM_ERRNO_OK ) ;
}
void DSMDialog : : addSeparator ( const string & name ) {
unsigned int id = 0 ;
if ( str2i ( name , id ) ) {
SET_ERRNO ( DSM_ERRNO_UNKNOWN_ARG ) ;
return ;
}
AmPlaylistSeparator * sep = new AmPlaylistSeparator ( this , id ) ;
playlist . addToPlaylist ( new AmPlaylistItem ( sep , sep ) ) ;
// for garbage collector
audiofiles . push_back ( sep ) ;
SET_ERRNO ( DSM_ERRNO_OK ) ;
}