Modification of GetResult API
[platform/core/csapi/uix-voice-control.git] / Tizen.Uix.VoiceControl / Tizen.Uix.VoiceControl / VoiceControlClient.cs
index 78ea25d..f9d689a 100755 (executable)
@@ -220,6 +220,7 @@ namespace Tizen.Uix.VoiceControl
         private static List<string> s_supportedLanguages;
         private static VcSupportedLanguageCb s_supportedLanguagesCb;
         private static VcResultCb s_resultCb;
+        private static RecognitionResult s_recognitionResult;
 
         /// <summary>
         /// Gets current language.
@@ -228,39 +229,45 @@ namespace Tizen.Uix.VoiceControl
         /// For example, "ko_KR" for Korean, "en_US" for American English.
         /// Empty string is returned incase of some internal error
         /// </summary>
+        /// <value>
+        /// Current language in voice control.
+        /// </value>
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
         /// <precondition>
         /// The State must be Initialized or Ready.
         /// </precondition>
-        public static string GetCurrentLanaguge
+        public static string CurrentLanguage
         {
             get
             {
-                string currentLanaguge;
+                string currentLanguage;
 
-                ErrorCode error = VcGetCurrentLanguage(out currentLanaguge);
+                ErrorCode error = VcGetCurrentLanguage(out currentLanguage);
                 if (error != ErrorCode.None)
                 {
-                    Log.Error(LogTag, "CurrentLanaguge Failed with error " + error);
+                    Log.Error(LogTag, "CurrentLanguage Failed with error " + error);
                     return "";
                 }
 
-                return currentLanaguge;
+                return currentLanguage;
             }
         }
 
         /// <summary>
-        /// Gets current state of voice control client. 
+        /// Gets current state of voice control client.
         /// </summary>
+        /// <value>
+        /// Current state of voice control client.
+        /// </value>
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
         /// <precondition>
         /// The State must be Initialized or Ready.
         /// </precondition>
-        public static State GetState
+        public static State State
         {
             get
             {
@@ -269,7 +276,7 @@ namespace Tizen.Uix.VoiceControl
                 ErrorCode error = VcGetState(out state);
                 if (error != ErrorCode.None)
                 {
-                    Log.Error(LogTag, "GetState Failed with error " + error);
+                    Log.Error(LogTag, "State Failed with error " + error);
                     return State.Unavailable;
                 }
 
@@ -280,13 +287,16 @@ namespace Tizen.Uix.VoiceControl
         /// <summary>
         /// Gets current state of voice control service.
         /// </summary>
+        /// <value>
+        /// Current state of voice control service.
+        /// </value>
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
         /// <precondition>
         /// The State must be Ready.
         /// </precondition>
-        public static ServiceState GetServiceState
+        public static ServiceState ServiceState
         {
             get
             {
@@ -295,7 +305,7 @@ namespace Tizen.Uix.VoiceControl
                 ErrorCode error = VcGetServiceState(out state);
                 if (error != ErrorCode.None)
                 {
-                    Log.Error(LogTag, "GetServiceState Failed with error " + error);
+                    Log.Error(LogTag, "ServiceState Failed with error " + error);
                     return ServiceState.Unavailable;
                 }
 
@@ -309,6 +319,13 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
         /// <remarks>
         /// Invocation name is used to activate background commands. The invocation name can be the same as the application name or any other phrase.
         /// For example, an application "Tizen Sample" has a background command, "Play music", and the invocation name of the application is set to "Tizen Sample".
@@ -318,13 +335,10 @@ namespace Tizen.Uix.VoiceControl
         /// This function should be called before SetCommandList().
         /// </remarks>
         /// <param name="name">Invocation name that an application wants to be invoked by</param>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Invalid parameter
-        /// 2. Invalid state
-        /// 3. Not Supported
-        /// 4. Permission Denied
-        /// </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State must be Ready.
         /// </precondition>
@@ -344,13 +358,17 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Out Of Memory
-        /// 2. Operation Failed
-        /// 3. Not Supported
-        /// 4. Permission Denied
-        /// </exception>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+        /// <exception cref="OutOfMemoryException"> This Exception can be due to Out Of Memory. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <postcondition>
         /// The State will be Initialized.
         /// </postcondition>
@@ -370,13 +388,17 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Operation Failed
-        /// 2. Invalid state
-        /// 3. Not Supported
-        /// 4. Permission Denied
-        /// </exception>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         public static void Deinitialize()
         {
             ErrorCode error = VcDeinitialize();
@@ -393,13 +415,17 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Operation Failed
-        /// 2. Not Supported
-        /// 3. Permission Denied
-        /// 4. Invalid State
-        /// </exception>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State should be Initialized
         /// </precondition>
@@ -422,12 +448,16 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Not Supported
-        /// 2. Permission Denied
-        /// 3. Invalid State
-        /// </exception>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
@@ -453,17 +483,21 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Operation Failed
-        /// 2. Not Supported
-        /// 3. Permission Denied
-        /// 4. Invalid State
-        /// </exception>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State should be Ready or Initialized
         /// </precondition>
-        public static IEnumerable<string> GetSupportedLangauges()
+        public static IEnumerable<string> GetSupportedLanguages()
         {
             s_supportedLanguages = new List<string>();
             s_supportedLanguagesCb = (IntPtr language, IntPtr userData) =>
@@ -475,7 +509,7 @@ namespace Tizen.Uix.VoiceControl
             ErrorCode error = VcForeachSupportedLanguages(s_supportedLanguagesCb, IntPtr.Zero);
             if (error != ErrorCode.None)
             {
-                Log.Error(LogTag, "GetSupportedLangauges Failed with error " + error);
+                Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
                 throw ExceptionFactory.CreateException(error);
             }
 
@@ -491,20 +525,25 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
         /// <remarks>
         /// In the system command list, there are system commands predefined by product manufacturers.
         /// Those commands have the highest priority. Therefore, the user can not set any commands same with the system commands.
         /// </remarks>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Not Supported
-        /// 2. Permission Denied
-        /// 3. Invalid State
-        /// </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
-        public static VoiceCommandList GetSytemCommandList()
+        public static VoiceCommandList GetSystemCommandList()
         {
             IntPtr handle = IntPtr.Zero;
             ErrorCode error = VcGetSystemCommandList(out handle);
@@ -535,19 +574,23 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
         /// <remarks>
         /// If autoStart is true, the recognition will start again. In this case, it can be restarted up to 4 times.
         /// </remarks>
         /// <param name="dispText"> Text to be displayed on the screen/// </param>
         /// <param name="uttText">Text to be spoken</param>
         /// <param name="autoStart">A variable for setting whether the dialog session will be restarted automatically or not</param>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Not Supported
-        /// 2. Permission Denied
-        /// 3. Invalid State
-        /// 4. Invalid parameter
-        /// </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
@@ -567,19 +610,23 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
         /// <remarks>
         /// The command type is valid for CommandType 'Foreground' or 'Background'.
         /// The matched commands of command list should be set and they should include type and command text at least.
         /// </remarks>
         /// <param name="list">Command list</param>
         /// <param name="type">Command type</param>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Not Supported
-        /// 2. Permission Denied
-        /// 3. Invalid State
-        /// 4. Invalid parameter
-        /// </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
@@ -607,14 +654,18 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
         /// <param name="type">Command type</param>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Not Supported
-        /// 2. Permission Denied
-        /// 3. Invalid State
-        /// 4. Invalid parameter
-        /// </exception>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
@@ -645,25 +696,26 @@ namespace Tizen.Uix.VoiceControl
         /// <privilege>
         /// http://tizen.org/privilege/recorder
         /// </privilege>
-        /// <param name="resultDelegate">
-        /// Callback function to get recognition result
-        /// </param>
-        /// <exception cref="InvalidOperationException">
-        /// This Exception can be due to the following reaons
-        /// 1. Not Supported
-        /// 2. Invalid State
-        /// 3. Invalid parameter
-        /// </exception>
+        /// <privlevel>
+        /// public
+        /// </privlevel>
+        /// <feature>
+        /// http://tizen.org/feature/speech.control
+        /// http://tizen.org/feature/microphone
+        /// </feature>
+        /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+        /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
+        /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <returns>The Recognition Result if possible else a null object</returns>
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
-        public static void GetResult(RecognitionResultDelegate resultDelegate)
+        public static RecognitionResult GetResult()
         {
+            s_recognitionResult = null;
             s_resultCb = (ResultEvent evt, IntPtr cmdList, IntPtr result, IntPtr userData) =>
             {
-                VoiceCommandList list = new VoiceCommandList(new SafeCommandListHandle(cmdList));
-                string resultStr = Marshal.PtrToStringAnsi(result);
-                resultDelegate(evt, list, resultStr);
+                s_recognitionResult = new RecognitionResult(evt, cmdList, result);
             };
             ErrorCode error = VcGetResult(s_resultCb, IntPtr.Zero);
             if (error != ErrorCode.None)
@@ -671,6 +723,8 @@ namespace Tizen.Uix.VoiceControl
                 Log.Error(LogTag, "GetResult Failed with error " + error);
                 throw ExceptionFactory.CreateException(error);
             }
+
+            return s_recognitionResult;
         }
 
         /// <summary>
@@ -688,7 +742,7 @@ namespace Tizen.Uix.VoiceControl
                     Log.Info(LogTag, "Recognition Result Event Triggered");
                     if ((cmdList != null) && (result != null))
                     {
-                        RecognitionResultEventArgs args = new RecognitionResultEventArgs(evt, cmdList, result);
+                        RecognitionResultEventArgs args = new RecognitionResultEventArgs(new RecognitionResult( evt, cmdList, result));
                         _recognitionResult?.Invoke(null, args);
                     }
                     else