PromptManager.hpp
上传用户:xqtpzdz
上传日期:2022-05-21
资源大小:1764k
文件大小:6k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. /****************License************************************************
  2.  * Vocalocity OpenVXI
  3.  * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
  18.  * registered trademarks of Vocalocity, Inc. 
  19.  * OpenVXI is a trademark of Scansoft, Inc. and used under license 
  20.  * by Vocalocity.
  21.  ***********************************************************************/
  22. #ifndef _PROMPTMANAGER_H_
  23. #define _PROMPTMANAGER_H_
  24. #include "VXIvalue.h"
  25. #include "VXIprompt.h"
  26. #include "ExecutableContentHandler.hpp"
  27. extern "C" struct VXIpromptInterface;
  28. class PromptTranslator;
  29. class PropertyList;
  30. class SimpleLogger;
  31. class VXMLElement;
  32. class VXMLNode;
  33. /**
  34.  * Interface for accessing ECMA Script functions.
  35.  */
  36. class PromptTranslator {
  37. public:
  38.   /**
  39.    * Evaluates an expression which arises during prompt construction.  The
  40.    * returned value will be freed by the PromptManager.
  41.    */
  42.   virtual VXIValue * EvaluateExpression(const vxistring & expression) = 0;
  43.   /**
  44.    * Sets a local variable in the current scope.
  45.    */
  46.   virtual void SetVariable(const vxistring & name, const vxistring & value) =0;
  47.   /** 
  48.    * Evaluates an expression as a boolean.
  49.    */
  50.   virtual bool TestCondition(const vxistring & script) = 0;
  51.   /** 
  52.    * Evaluates an ECMAScript script.
  53.    */
  54.   virtual void EvalScript(const vxistring & script) = 0;
  55.   PromptTranslator() { }
  56.   virtual ~PromptTranslator() { }
  57. };
  58. /**
  59.  * Handles prompts.
  60.  */
  61. class PromptManager {
  62. public:
  63.   /**
  64.    * This function walks through the document, preloading prompts as necessary.
  65.    *
  66.    * @throw VXIException::OutOfMemory, VXIException::InterpreterEvent
  67.    */
  68.   void PreloadPrompts(const VXMLElement& doc, PropertyList &, PromptTranslator &);
  69.   /**
  70.    * Queues a <prompt> element and process it's child nodes (<audio>,
  71.    * <enumerate>, etc...).
  72.    *
  73.    * @throw VXIException::InterpreterEvent
  74.    */
  75.   void Queue(const VXMLElement & child, const VXMLElement & reference,
  76.              const PropertyList &, PromptTranslator &);
  77.   /**
  78.    * Queues a segment from a known URI.
  79.    * @throw VXIException::InterpreterEvent
  80.    */
  81.   //void Queue(const vxistring & uri);
  82.   /**
  83.    * Waits until the prompts currenly marked for playing are done.  Then starts
  84.    * playing everything remaining in the queue.  This is generally followed by
  85.    * a recognition / record attempt.
  86.    *
  87.    * @throw VXIException::InterpreterEvent
  88.    */
  89.   void Play(bool *playedBarginDisabledPrompt);
  90.   /**
  91.    * Play everything currently in the queue.  The user is unable to barge in.
  92.    */
  93.   void PlayAll();
  94.   /**
  95.    * Waits for playback to complete.
  96.    * @throw VXIException::InterpreterEvent
  97.    */
  98.   void WaitAndCheckError(void);
  99.   /** 
  100.    * Returns: the recognition timeout, in milliseconds, or -1 if none was
  101.    * specified.
  102.    */
  103.   int GetMillisecondTimeout() const;
  104.   /**
  105.    * Start playing fetchaudio.
  106.    *
  107.    * @param src        SSML document
  108.    * @param properties Current VXI & VXML properties
  109.    *
  110.    * @throw VXIException::InterpreterEvent
  111.    */
  112.   void PlayFiller(const vxistring & src, const VXIMapHolder & properties);
  113. public:
  114.   bool ConnectResources(SimpleLogger *, VXIpromptInterface *, ExecutableContentHandler *);
  115.   PromptManager() : log(NULL), prompt(NULL), contentHandler(NULL) { }
  116.   ~PromptManager() { }
  117. private:
  118.   enum BargeIn {
  119.     UNSPECIFIED,
  120.     ENABLED,
  121.     DISABLED
  122.   };
  123.   enum SegmentType {
  124.     SEGMENT_AUDIO,
  125.     SEGMENT_SSML
  126.   };
  127.   void DoPreloadPrompts(const VXMLElement& doc,
  128.                         PropertyList & properties,
  129.                         VXIMapHolder & levelProperties,
  130.                         PromptTranslator & translator);
  131.   bool ProcessPrefetchPrompts(const VXMLNode & node, const VXMLElement& item, 
  132.                       const PropertyList & propertyList,
  133.                       PromptTranslator & translator, 
  134.                       vxistring & sofar);
  135.   void ProcessSegments(const VXMLNode & node,
  136.                        const VXMLElement & item,
  137.                        const PropertyList & propertyList,
  138.                        PromptTranslator & translator,
  139.                        BargeIn,
  140.                        VXIMapHolder & props,
  141.                        vxistring & sofar,
  142.                        vxistring & ssmlHeader,
  143.                        bool & hasPromptData,
  144.                        bool replaceXmlBase);
  145.   // Returns: true - segment successfully queued
  146.   //          false - segment addition failed
  147.   bool AddSegment(SegmentType, const vxistring & data,
  148.                   const VXIMapHolder & properties, BargeIn,
  149.                   bool throwExceptions = true);
  150.   // NOTE: This takes ownership of the VXIValue.
  151.   void AddContent(VXIMapHolder & props,
  152.                   vxistring & sofar,
  153.                   VXIValue * value);
  154.   void ThrowEventIfError(VXIpromptResult rc);
  155.   
  156. private:
  157.   SimpleLogger       * log;
  158.   VXIpromptInterface * prompt;
  159.   ExecutableContentHandler *contentHandler;
  160.   bool enabledSegmentInQueue;
  161.   bool playedBargeinDisabledPrompt;
  162.   int timeout;
  163. };
  164. #endif