• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*---------------------------------------------------------------------------*
2  *  SR_Session.c  *
3  *                                                                           *
4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5  *                                                                           *
6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7  *  you may not use this file except in compliance with the License.         *
8  *                                                                           *
9  *  You may obtain a copy of the License at                                  *
10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
11  *                                                                           *
12  *  Unless required by applicable law or agreed to in writing, software      *
13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15  *  See the License for the specific language governing permissions and      *
16  *  limitations under the License.                                           *
17  *                                                                           *
18  *---------------------------------------------------------------------------*/
19 
20 
21 #include "ESR_Session.h"
22 #include "SR_EventLog.h"
23 #include "SR_Session.h"
24 #include "plog.h"
25 
26 
SR_SessionCreate(const LCHAR * filename)27 ESR_ReturnCode SR_SessionCreate(const LCHAR* filename)
28 {
29   ESR_ReturnCode rc;
30   LCHAR baseDirectory[P_PATH_MAX];
31   LCHAR* fwdSlash;
32   LCHAR* backSlash;
33   ESR_BOOL exists;
34   SR_EventLog* eventLog = NULL;
35   size_t logLevel;
36 
37   CHKLOG(rc, ESR_SessionCreate(filename));
38   rc = ESR_SessionGetSize_t(L("SREC.Recognizer.osi_log_level"), &logLevel);
39   if (rc == ESR_SUCCESS)
40     CHKLOG(rc, SR_EventLogCreate(&eventLog));
41   else if (rc == ESR_NO_MATCH_ERROR)
42     CHKLOG(rc, ESR_SessionSetSize_t(L("SREC.Recognizer.osi_log_level"), 0));
43   else
44   {
45     PLogError(ESR_rc2str(rc));
46     goto CLEANUP;
47   }
48   LSTRCPY(baseDirectory, filename);
49   fwdSlash = LSTRRCHR(baseDirectory, '\\');
50   backSlash = LSTRRCHR(baseDirectory, '/');
51 
52   if (fwdSlash == NULL && backSlash == NULL)
53     LSTRCPY(baseDirectory, "");
54   else if (fwdSlash != NULL && fwdSlash > backSlash)
55     *(fwdSlash + 1) = L('\0');
56   else
57     *(backSlash + 1) = L('\0');
58   CHKLOG(rc, ESR_SessionSetLCHAR(L("parFile.baseDirectory"), baseDirectory));
59   return ESR_SUCCESS;
60 CLEANUP:
61   if (ESR_SessionExists(&exists) == ESR_SUCCESS)
62   {
63     if (exists)
64       ESR_SessionDestroy();
65   }
66   return rc;
67 }
68 
SR_SessionDestroy()69 ESR_ReturnCode SR_SessionDestroy()
70 {
71   ESR_ReturnCode rc;
72   SR_EventLog* eventLog = NULL;
73 
74   ESR_SessionGetProperty(L("eventlog"), (void **)&eventLog, TYPES_SR_EVENTLOG);
75   if (eventLog != NULL)
76   {
77     CHKLOG(rc, eventLog->destroy(eventLog));
78     ESR_SessionRemoveProperty(L("eventlog")); /* failure is ok */
79   }
80 
81 
82   CHKLOG(rc, ESR_SessionDestroy());
83   return ESR_SUCCESS;
84 CLEANUP:
85   return rc;
86 }
87