diff --git a/apps/dsm/DSMDialog.cpp b/apps/dsm/DSMDialog.cpp index 5d4895df..45e0f25d 100644 --- a/apps/dsm/DSMDialog.cpp +++ b/apps/dsm/DSMDialog.cpp @@ -43,6 +43,10 @@ DSMDialog::DSMDialog(AmPromptCollection* prompts, DSMDialog::~DSMDialog() { + for (std::set::iterator it= + gc_trash.begin(); it != gc_trash.end(); it++) + delete *it; + for (vector::iterator it= audiofiles.begin();it!=audiofiles.end();it++) delete *it; @@ -196,6 +200,11 @@ void DSMDialog::closePlaylist(bool notify) { playlist.close(notify); } +void DSMDialog::addToPlaylist(AmPlaylistItem* item) { + DBG("add item to playlist\n"); + playlist.addToPlaylist(item); +} + void DSMDialog::playFile(const string& name, bool loop) { AmAudioFile* af = new AmAudioFile(); if(af->open(name,AmAudioFile::Read)) { @@ -290,3 +299,7 @@ void DSMDialog::addSeparator(const string& name) { audiofiles.push_back(sep); SET_ERRNO(DSM_ERRNO_OK); } + +void DSMDialog::transferOwnership(DSMDisposable* d) { + gc_trash.insert(d); +} diff --git a/apps/dsm/DSMDialog.h b/apps/dsm/DSMDialog.h index 214d5644..a70c8ff4 100644 --- a/apps/dsm/DSMDialog.h +++ b/apps/dsm/DSMDialog.h @@ -55,6 +55,9 @@ class DSMDialog : public AmSession, map prompt_sets; std::set used_prompt_sets; + // owned by this instance + std::set gc_trash; + bool checkVar(const string& var_name, const string& var_val); public: DSMDialog(AmPromptCollection* prompts, @@ -81,6 +84,7 @@ public: void playPrompt(const string& name, bool loop = false); void closePlaylist(bool notify); + void addToPlaylist(AmPlaylistItem* item); void playFile(const string& name, bool loop); void recordFile(const string& name); void stopRecord(); @@ -88,6 +92,8 @@ public: void setPromptSet(const string& name); void addSeparator(const string& name); void connectMedia(); + + void transferOwnership(DSMDisposable* d); }; #endif diff --git a/apps/dsm/DSMSession.h b/apps/dsm/DSMSession.h index 2c45e649..deaca321 100644 --- a/apps/dsm/DSMSession.h +++ b/apps/dsm/DSMSession.h @@ -53,6 +53,9 @@ using std::map; #define SET_ERRNO(new_errno) \ var["errno"] = new_errno +class DSMDisposable; +class AmPlaylistItem; + class DSMSession { public: @@ -63,10 +66,15 @@ class DSMSession { virtual void playFile(const string& name, bool loop) = 0; virtual void recordFile(const string& name) = 0; virtual void stopRecord() = 0; + virtual void addToPlaylist(AmPlaylistItem* item) = 0; virtual void closePlaylist(bool notify) = 0; virtual void setPromptSet(const string& name) = 0; virtual void addSeparator(const string& name) = 0; virtual void connectMedia() = 0; + + /** transfer ownership of object to this session instance */ + virtual void transferOwnership(DSMDisposable* d) = 0; + /* holds variables which are accessed by $varname */ map var; @@ -79,6 +87,12 @@ class DSMSession { +class DSMDisposable { + public: + DSMDisposable() { } + virtual ~DSMDisposable() { } +}; + #define DSM_EVENT_ID -10 /** generic event for passing events between DSM sessions */ struct DSMEvent : public AmEvent {