1 /*
2  * Copyright 2008-2014 Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Id: recogscenario.cpp 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17  */
18 
19 #include <stdlib.h>
20 #include "recogscenario.h"
21 #include "recogsession.h"
22 #include "mrcp_message.h"
23 #include "mrcp_generic_header.h"
24 #include "mrcp_recog_header.h"
25 #include "mrcp_recog_resource.h"
26 #include "apt_log.h"
27 
RecogScenario()28 RecogScenario::RecogScenario() :
29 	m_DefineGrammar(true),
30 	m_Recognize(true),
31 	m_ContentType("application/srgs+xml"),
32 	m_Content(NULL),
33 	m_ContentLength(0),
34 	m_AudioSource(NULL)
35 {
36 }
37 
~RecogScenario()38 RecogScenario::~RecogScenario()
39 {
40 }
41 
Destroy()42 void RecogScenario::Destroy()
43 {
44 }
45 
LoadElement(const apr_xml_elem * pElem,apr_pool_t * pool)46 bool RecogScenario::LoadElement(const apr_xml_elem* pElem, apr_pool_t* pool)
47 {
48 	if(UmcScenario::LoadElement(pElem,pool))
49 		return true;
50 
51 	if(strcasecmp(pElem->name,"define-grammar") == 0)
52 	{
53 		LoadDefineGrammar(pElem,pool);
54 		return true;
55 	}
56 	else if(strcasecmp(pElem->name,"recognize") == 0)
57 	{
58 		LoadRecognize(pElem,pool);
59 		return true;
60 	}
61 
62 	return false;
63 }
64 
LoadRecognize(const apr_xml_elem * pElem,apr_pool_t * pool)65 bool RecogScenario::LoadRecognize(const apr_xml_elem* pElem, apr_pool_t* pool)
66 {
67 	const apr_xml_attr* pAttr;
68 	for(pAttr = pElem->attr; pAttr; pAttr = pAttr->next)
69 	{
70 		if(strcasecmp(pAttr->name,"enable") == 0)
71 		{
72 			m_Recognize = atoi(pAttr->value) > 0;
73 		}
74 		else if(strcasecmp(pAttr->name,"content-type") == 0)
75 		{
76 			m_ContentType = pAttr->value;
77 		}
78 		else if(strcasecmp(pAttr->name,"content-location") == 0)
79 		{
80 			m_Content = LoadFileContent(pAttr->value,pool);
81 		}
82 		else if(strcasecmp(pAttr->name,"audio-source") == 0)
83 		{
84 			m_AudioSource = pAttr->value;
85 		}
86 	}
87 
88 	return true;
89 }
90 
LoadDefineGrammar(const apr_xml_elem * pElem,apr_pool_t * pool)91 bool RecogScenario::LoadDefineGrammar(const apr_xml_elem* pElem, apr_pool_t* pool)
92 {
93 	const apr_xml_attr* pAttr;
94 	for(pAttr = pElem->attr; pAttr; pAttr = pAttr->next)
95 	{
96 		if(strcasecmp(pAttr->name,"enable") == 0)
97 		{
98 			m_DefineGrammar = atoi(pAttr->value) > 0;
99 		}
100 		else if(strcasecmp(pAttr->name,"content-type") == 0)
101 		{
102 			m_ContentType = pAttr->value;
103 		}
104 		else if(strcasecmp(pAttr->name,"content-location") == 0)
105 		{
106 			m_Content = LoadFileContent(pAttr->value,m_ContentLength,pool);
107 		}
108 	}
109 	return true;
110 }
111 
112 
CreateSession()113 UmcSession* RecogScenario::CreateSession()
114 {
115 	return new RecogSession(this);
116 }
117