Module: sems Branch: master Commit: e08db61c511f5a369efaec1d602e66c00e695408 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=e08db61c511f5a369efaec1d602e66c00e695408
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Fri Feb 24 21:07:59 2012 +0100 dsm:mod_mysql: mysql.playDBAudioFront and mysql.playDBAudioLooped actions --- apps/dsm/mods/mod_mysql/ModMysql.cpp | 43 ++++++++++++++++++++++++++------- apps/dsm/mods/mod_mysql/ModMysql.h | 2 + doc/dsm/mods/Readme.mod_mysql.txt | 10 ++++++++ 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/apps/dsm/mods/mod_mysql/ModMysql.cpp b/apps/dsm/mods/mod_mysql/ModMysql.cpp index 3bbd63c..2e2f550 100644 --- a/apps/dsm/mods/mod_mysql/ModMysql.cpp +++ b/apps/dsm/mods/mod_mysql/ModMysql.cpp @@ -61,6 +61,8 @@ DSMAction* SCMysqlModule::getAction(const string& from_str) { DEF_CMD("mysql.saveResult", SCMySaveResultAction); DEF_CMD("mysql.useResult", SCMyUseResultAction); DEF_CMD("mysql.playDBAudio", SCMyPlayDBAudioAction); + DEF_CMD("mysql.playDBAudioFront", SCMyPlayDBAudioFrontAction); + DEF_CMD("mysql.playDBAudioLooped", SCMyPlayDBAudioLoopedAction); DEF_CMD("mysql.getFileFromDB", SCMyGetFileFromDBAction); DEF_CMD("mysql.putFileToDB", SCMyPutFileToDBAction); DEF_CMD("mysql.escape", SCMyEscapeAction); @@ -451,12 +453,14 @@ EXEC_ACTION_START(SCMyUseResultAction) { } EXEC_ACTION_END; -CONST_ACTION_2P(SCMyPlayDBAudioAction, ',', true); -EXEC_ACTION_START(SCMyPlayDBAudioAction) { +bool playDBAudio(AmSession* sess, DSMSession* sc_sess, DSMCondition::EventType event, + map<string,string>* event_params, const string& par1, const string& par2, + bool looped, bool front) { mysqlpp::Connection* conn = getMyDSMSessionConnection(sc_sess); - if (NULL == conn) - return false; + if (NULL == conn) + EXEC_ACTION_STOP; + string qstr = replaceQueryParams(par1, sc_sess, event_params); try { @@ -467,14 +471,14 @@ EXEC_ACTION_START(SCMyPlayDBAudioAction) { mysqlpp::Row row = res.fetch_row(); if (!row) { sc_sess->SET_ERRNO(DSM_ERRNO_MY_NOROW); - sc_sess->SET_STRERROR("result does not have row"); - return false; + sc_sess->SET_STRERROR("result does not have row"); + EXEC_ACTION_STOP; } FILE *t_file = tmpfile(); if (NULL == t_file) { sc_sess->SET_ERRNO(DSM_ERRNO_FILE); sc_sess->SET_STRERROR("tmpfile() failed: "+string(strerror(errno))); - return false; + EXEC_ACTION_STOP; } fwrite(row.at(0).data(), 1, row.at(0).size(), t_file); @@ -484,10 +488,12 @@ EXEC_ACTION_START(SCMyPlayDBAudioAction) { if (a_file->fpopen(par2, AmAudioFile::Read, t_file)) { sc_sess->SET_ERRNO(DSM_ERRNO_FILE); sc_sess->SET_STRERROR("fpopen failed!"); - return false; + EXEC_ACTION_STOP; } - sc_sess->addToPlaylist(new AmPlaylistItem(a_file, NULL)); + a_file->loop.set(looped); + + sc_sess->addToPlaylist(new AmPlaylistItem(a_file, NULL), front); sc_sess->transferOwnership(a_file); sc_sess->CLR_ERRNO; @@ -502,6 +508,25 @@ EXEC_ACTION_START(SCMyPlayDBAudioAction) { sc_sess->SET_STRERROR(e.what()); sc_sess->var["db.ereason"] = e.what(); } + return false; +} + +CONST_ACTION_2P(SCMyPlayDBAudioAction, ',', true); +EXEC_ACTION_START(SCMyPlayDBAudioAction) { + playDBAudio(sess, sc_sess, event, event_params, par1, par2, + /*looped = */ false, /*front = */ false); +} EXEC_ACTION_END; + +CONST_ACTION_2P(SCMyPlayDBAudioFrontAction, ',', true); +EXEC_ACTION_START(SCMyPlayDBAudioFrontAction) { + playDBAudio(sess, sc_sess, event, event_params, par1, par2, + /*looped = */ false, /*front = */ true); +} EXEC_ACTION_END; + +CONST_ACTION_2P(SCMyPlayDBAudioLoopedAction, ',', true); +EXEC_ACTION_START(SCMyPlayDBAudioLoopedAction) { + playDBAudio(sess, sc_sess, event, event_params, par1, par2, + /*looped = */ true, /*front = */ false); } EXEC_ACTION_END; CONST_ACTION_2P(SCMyGetFileFromDBAction, ',', true); diff --git a/apps/dsm/mods/mod_mysql/ModMysql.h b/apps/dsm/mods/mod_mysql/ModMysql.h index 85e8b8f..7bf13fb 100644 --- a/apps/dsm/mods/mod_mysql/ModMysql.h +++ b/apps/dsm/mods/mod_mysql/ModMysql.h @@ -88,6 +88,8 @@ DEF_SCCondition(MyConnectedCondition); DEF_ACTION_1P(SCMySaveResultAction); DEF_ACTION_1P(SCMyUseResultAction); DEF_ACTION_2P(SCMyPlayDBAudioAction); +DEF_ACTION_2P(SCMyPlayDBAudioFrontAction); +DEF_ACTION_2P(SCMyPlayDBAudioLoopedAction); DEF_ACTION_2P(SCMyGetFileFromDBAction); DEF_ACTION_2P(SCMyPutFileToDBAction); DEF_ACTION_2P(SCMyEscapeAction); diff --git a/doc/dsm/mods/Readme.mod_mysql.txt b/doc/dsm/mods/Readme.mod_mysql.txt index 2104a70..f9581ca 100644 --- a/doc/dsm/mods/Readme.mod_mysql.txt +++ b/doc/dsm/mods/Readme.mod_mysql.txt @@ -90,6 +90,16 @@ Actions: filename is there to detect file type +-- play a file from DB, looped + mysql.playDBAudioLooped(string query, string filename) + + filename is there to detect file type + +-- play a file from DB, at the front in the playlist + mysql.playDBAudioFront(string query, string filename) + + filename is there to detect file type + -- get a file from DB to local fs mysql.getFileFromDB(string query, string filename) _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
