dsm:mod_mysql: mysql.playDBAudioFront and mysql.playDBAudioLooped actions

sayer/1.4-spce2.6
Stefan Sayer 15 years ago
parent 90739aec1d
commit aef6223c86

@ -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);
@ -450,12 +452,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 {
@ -466,14 +470,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);
@ -483,10 +487,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;
@ -501,6 +507,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);

@ -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);

@ -91,6 +91,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)

Loading…
Cancel
Save