new core functions:

* getRecordLength
 * getRecordDataSize

new configuration "set_param_variables" that sets parameters from P-App-Param as variables in DSM session

This work was kindly sponsored by Teltech Systems Inc.



git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1325 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 17 years ago
parent 7bfba0a07d
commit cdaa3e25d3

@ -58,6 +58,7 @@ string DSMFactory::InboundStartDiag;
string DSMFactory::OutboundStartDiag;
map<string, string> DSMFactory::config;
bool DSMFactory::RunInviteEvent;
bool DSMFactory::SetParamVariables;
DSMFactory::DSMFactory(const string& _app_name)
: AmSessionFactory(_app_name),AmDynInvokeFactory(_app_name),
@ -221,6 +222,8 @@ int DSMFactory::onLoad()
RunInviteEvent = cfg.getParameter("run_invite_event")=="yes";
SetParamVariables = cfg.getParameter("set_param_variables")=="yes";
return 0;
}
@ -235,6 +238,19 @@ void DSMFactory::addVariables(DSMDialog* s, const string& prefix,
s->var[prefix+it->first] = it->second;
}
void DSMFactory::addParams(DSMDialog* s, const string& hdrs) {
// TODO: use real parser with quoting and optimize
map<string, string> params;
vector<string> items = explode(getHeader(hdrs, PARAM_HDR), ";");
for (vector<string>::iterator it=items.begin();
it != items.end(); it++) {
vector<string> kv = explode(*it, "=");
if (kv.size()==2)
params.insert(make_pair(kv[0], kv[1]));
}
addVariables(s, "", params);
}
AmSession* DSMFactory::onInvite(const AmSipRequest& req)
{
string start_diag;
@ -250,6 +266,10 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req)
DSMDialog* s = new DSMDialog(&prompts, diags, start_diag, NULL);
prepareSession(s);
addVariables(s, "config.", config);
if (SetParamVariables)
addParams(s, req.hdrs);
return s;
}
@ -306,6 +326,9 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req,
if (!vars.empty())
addVariables(s, "", vars);
if (SetParamVariables)
addParams(s, req.hdrs);
if (NULL == cred) {
WARN("discarding unknown session parameters.\n");
} else {

@ -65,7 +65,7 @@ class DSMFactory
void prepareSession(DSMDialog* s);
void addVariables(DSMDialog* s, const string& prefix,
map<string, string>& vars);
void addParams(DSMDialog* s, const string& hdrs);
vector<DSMModule*> preloaded_mods;
public:
@ -73,6 +73,8 @@ public:
static map<string, string> config;
static bool RunInviteEvent;
static bool SetParamVariables;
int onLoad();
AmSession* onInvite(const AmSipRequest& req);

@ -62,6 +62,8 @@ DSMAction* DSMCoreModule::getAction(const string& from_str) {
DEF_CMD("playFile", SCPlayFileAction);
DEF_CMD("recordFile", SCRecordFileAction);
DEF_CMD("stopRecord", SCStopRecordAction);
DEF_CMD("getRecordLength", SCGetRecordLengthAction);
DEF_CMD("getRecordDataSize", SCGetRecordDataSizeAction);
DEF_CMD("closePlaylist", SCClosePlaylistAction);
DEF_CMD("addSeparator", SCAddSeparatorAction);
DEF_CMD("connectMedia", SCConnectMediaAction);
@ -200,6 +202,20 @@ EXEC_ACTION_START(SCStopRecordAction) {
sc_sess->stopRecord();
} EXEC_ACTION_END;
EXEC_ACTION_START(SCGetRecordLengthAction) {
string varname = resolveVars(arg, sess, sc_sess, event_params);
if (varname.empty())
varname = "record_length";
sc_sess->var[varname]=int2str(sc_sess->getRecordLength());
} EXEC_ACTION_END;
EXEC_ACTION_START(SCGetRecordDataSizeAction) {
string varname = resolveVars(arg, sess, sc_sess, event_params);
if (varname.empty())
varname = "record_data_size";
sc_sess->var[varname]=int2str(sc_sess->getRecordDataSize());
} EXEC_ACTION_END;
EXEC_ACTION_START(SCClosePlaylistAction) {
bool notify =
resolveVars(arg, sess, sc_sess, event_params) == "true";

@ -54,6 +54,8 @@ DEF_ACTION_1P(SCPlayPromptAction);
DEF_ACTION_1P(SCPlayPromptLoopedAction);
DEF_ACTION_1P(SCRecordFileAction);
DEF_ACTION_1P(SCStopRecordAction);
DEF_ACTION_1P(SCGetRecordDataSizeAction);
DEF_ACTION_1P(SCGetRecordLengthAction);
DEF_ACTION_1P(SCClosePlaylistAction);
DEF_ACTION_1P(SCStopAction);
DEF_ACTION_1P(SCConnectMediaAction);

@ -258,6 +258,24 @@ void DSMDialog::recordFile(const string& name) {
SET_ERRNO(DSM_ERRNO_OK);
}
unsigned int DSMDialog::getRecordLength() {
if (!rec_file) {
SET_ERRNO(DSM_ERRNO_FILE);
return 0;
}
SET_ERRNO(DSM_ERRNO_OK);
return rec_file->getLength();
}
unsigned int DSMDialog::getRecordDataSize() {
if (!rec_file) {
SET_ERRNO(DSM_ERRNO_FILE);
return 0;
}
SET_ERRNO(DSM_ERRNO_OK);
return rec_file->getDataSize();
}
void DSMDialog::stopRecord() {
if (rec_file) {
setInput(&playlist);

@ -87,6 +87,8 @@ public:
void addToPlaylist(AmPlaylistItem* item);
void playFile(const string& name, bool loop);
void recordFile(const string& name);
unsigned int getRecordLength();
unsigned int getRecordDataSize();
void stopRecord();
void setPromptSet(const string& name);

@ -65,6 +65,8 @@ class DSMSession {
virtual void playPrompt(const string& name, bool loop = false) = 0;
virtual void playFile(const string& name, bool loop) = 0;
virtual void recordFile(const string& name) = 0;
virtual unsigned int getRecordLength() = 0;
virtual unsigned int getRecordDataSize() = 0;
virtual void stopRecord() = 0;
virtual void addToPlaylist(AmPlaylistItem* item) = 0;
virtual void closePlaylist(bool notify) = 0;

@ -44,6 +44,8 @@ actions:
playFile(filename)
recordFile(filename)
stopRecord()
getRecordLength([dst_varname]) -- only while recording! default dst var: record_length
getRecordDataSize([dst_varname]) -- only while recording! default dst var: record_data_size
closePlaylist()
addSeparator(id)
fires event when playlist hits it

@ -35,3 +35,9 @@ load_prompts=/usr/local/etc/sems/etc/dsm_in_prompts.conf,/usr/local/etc/sems/etc
# of delaying final reply
#
#run_invite_event=yes
# set_param_variables controls whether application parameters
# from the P-App-Param header are set as variables in the DSM
# dialog. Default: no
#
#set_param_variables=yes

Loading…
Cancel
Save