[Opalvoip-svn] SF.net SVN: opalvoip:[34645] ptlib/branches/v2_16
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2016-02-24 17:58:10
|
Revision: 34645 http://sourceforge.net/p/opalvoip/code/34645 Author: rjongbloed Date: 2016-02-24 17:58:08 +0000 (Wed, 24 Feb 2016) Log Message: ----------- Added scripting language, if available, to VXML. Modified Paths: -------------- ptlib/branches/v2_16/include/ptclib/vxml.h ptlib/branches/v2_16/src/ptclib/vxml.cxx Modified: ptlib/branches/v2_16/include/ptclib/vxml.h =================================================================== --- ptlib/branches/v2_16/include/ptclib/vxml.h 2016-02-24 17:19:11 UTC (rev 34644) +++ ptlib/branches/v2_16/include/ptclib/vxml.h 2016-02-24 17:58:08 UTC (rev 34645) @@ -44,6 +44,7 @@ #include <ptclib/pwavfile.h> #include <ptclib/ptts.h> #include <ptclib/url.h> +#include <ptclib/script.h> #include <queue> @@ -329,6 +330,9 @@ PStringToString m_variables; PString m_variableScope; +#if P_SCRIPTS + PScriptLanguage *m_scriptContext; +#endif std::queue<char> m_userInputQueue; PDECLARE_MUTEX(m_userInputMutex); Modified: ptlib/branches/v2_16/src/ptclib/vxml.cxx =================================================================== --- ptlib/branches/v2_16/src/ptclib/vxml.cxx 2016-02-24 17:19:11 UTC (rev 34644) +++ ptlib/branches/v2_16/src/ptclib/vxml.cxx 2016-02-24 17:58:08 UTC (rev 34645) @@ -167,7 +167,11 @@ #define MEDIUM_BREAK_MSECS 2500 #define LARGE_BREAK_MSECS 5000 +static PConstString ApplicationScope("application"); +static PConstString DialogScope("dialog"); +static PConstString PropertyScope("property"); + ////////////////////////////////////////////////////////// PVXMLPlayable::PVXMLPlayable() @@ -759,6 +763,17 @@ , m_transferStatus(NotTransfering) , m_transferStartTime(0) { +#if P_SCRIPTS + m_scriptContext = PScriptLanguage::Create("Java"); + if (m_scriptContext == NULL) + m_scriptContext = PScriptLanguage::Create("Lua"); // Back up + if (m_scriptContext != NULL) { + m_scriptContext->CreateComposite(ApplicationScope); + m_scriptContext->CreateComposite(DialogScope); + m_scriptContext->CreateComposite(PropertyScope); + } +#endif + SetVar("property.timeout" , "10s"); SetVar("property.bargein", "true"); } @@ -770,6 +785,10 @@ if (m_autoDeleteTextToSpeech) delete m_textToSpeech; + +#if P_SCRIPTS + delete m_scriptContext; +#endif } @@ -913,7 +932,7 @@ return false; } - m_variableScope = m_variableScope.IsEmpty() ? "application" : "document"; + m_variableScope = m_variableScope.IsEmpty() ? ApplicationScope : "document"; PURL pathURL = m_rootURL; pathURL.ChangePath(PString::Empty()); // Remove last element of root URL @@ -1495,6 +1514,16 @@ PString PVXMLSession::EvaluateExpr(const PString & expr) { +#if P_SCRIPTS + if (m_scriptContext != NULL) { + static PConstString const EvalVarName("PTLibEvaluateExpressionResult"); + if (m_scriptContext->Run(PSTRSTRM(EvalVarName<<'='<<expr))) + return m_scriptContext->GetString(EvalVarName); + PTRACE(2, "VXML\tCould not evaluate expression \"" << expr << "\" with script language " << m_scriptContext->GetLanguageName()); + return PString::Empty(); + } +#endif + // Should be full ECMAScript but ... // We only support expressions of the form 'literal'+variable or all digits @@ -1544,6 +1573,11 @@ if (varName.Find('.') == P_MAX_INDEX) fullVarName = m_variableScope+'.'+varName; +#if P_SCRIPTS + if (m_scriptContext != NULL) + return m_scriptContext->GetString(fullVarName); +#endif + return m_variables(fullVarName); } @@ -1554,6 +1588,11 @@ if (varName.Find('.') == P_MAX_INDEX) fullVarName = m_variableScope+'.'+varName; +#if P_SCRIPTS + if (m_scriptContext != NULL) + m_scriptContext->SetString(fullVarName, value); +#endif + m_variables.SetAt(fullVarName, value); } @@ -2268,14 +2307,14 @@ PBoolean PVXMLSession::TraverseForm(PXMLElement &) { - m_variableScope = "dialog"; + m_variableScope = DialogScope; return true; } PBoolean PVXMLSession::TraversedForm(PXMLElement &) { - m_variableScope = "application"; + m_variableScope = ApplicationScope; return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |