From: urmain Date: Mon, 13 May 2019 22:25:34 +0000 (+0900) Subject: [STT/TTS] support multi handle for event (#812) X-Git-Tag: 5.5_M2~217 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a1aa33bc7e53a65d2f2c11d8225f3f660a27384;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [STT/TTS] support multi handle for event (#812) * [STT/TTS] Fix desctructor to call dispose (#596) Signed-off-by: sooyeon.kim * Support multi handle --- diff --git a/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs b/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs index 76f70ca..c39b953 100644 --- a/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs +++ b/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs @@ -381,28 +381,29 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) => + if (_recognitionResult == null) { - Log.Info(LogTag, "Recognition Result Event Triggered"); - if (data != null && msg != null) + _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) => { - RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg)); - _recognitionResult?.Invoke(this, args); - } - else + Log.Info(LogTag, "Recognition Result Event Triggered"); + if (data != null && msg != null) + { + RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg)); + _recognitionResult?.Invoke(this, args); + } + else + { + Log.Info(LogTag, "Recognition Result Event null received"); + } + }; + + SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero); + if (error != SttError.None) { - Log.Info(LogTag, "Recognition Result Event null received"); + Log.Error(LogTag, "Add RecognitionResult Failed with error " + error); } - }; - SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero); - if (error != SttError.None) - { - Log.Error(LogTag, "Add RecognitionResult Failed with error " + error); - } - else - { - _recognitionResult += value; } + _recognitionResult += value; } } @@ -410,13 +411,15 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - SttError error = SttUnsetRecognitionResultCB(_handle); - if (error != SttError.None) + _recognitionResult -= value; + if (_recognitionResult == null) { - Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error); + SttError error = SttUnsetRecognitionResultCB(_handle); + if (error != SttError.None) + { + Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error); + } } - - _recognitionResult -= value; } } } @@ -431,21 +434,22 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - SttClient obj = this; - _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) => - { - StateChangedEventArgs args = new StateChangedEventArgs(previous, current); - _stateChanged?.Invoke(obj, args); - }; - SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero); - if (error != SttError.None) + if (_stateChanged == null) { - Log.Error(LogTag, "Add StateChanged Failed with error " + error); - } - else - { - _stateChanged += value; + SttClient obj = this; + _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) => + { + StateChangedEventArgs args = new StateChangedEventArgs(previous, current); + _stateChanged?.Invoke(obj, args); + }; + + SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero); + if (error != SttError.None) + { + Log.Error(LogTag, "Add StateChanged Failed with error " + error); + } } + _stateChanged += value; } } @@ -453,13 +457,15 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - SttError error = SttUnsetStateChangedCB(_handle); - if (error != SttError.None) + _stateChanged -= value; + if (_stateChanged == null) { - Log.Error(LogTag, "Remove StateChanged Failed with error " + error); + SttError error = SttUnsetStateChangedCB(_handle); + if (error != SttError.None) + { + Log.Error(LogTag, "Remove StateChanged Failed with error " + error); + } } - - _stateChanged -= value; } } @@ -475,21 +481,21 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) => + if (_errorOccurred == null) { - ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, reason); - _errorOccurred?.Invoke(this, args); - }; - SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero); - if (error != SttError.None) - { - Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error); - } + _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) => + { + ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, reason); + _errorOccurred?.Invoke(this, args); + }; - else - { - _errorOccurred += value; + SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero); + if (error != SttError.None) + { + Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error); + } } + _errorOccurred += value; } } @@ -497,13 +503,15 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - SttError error = SttUnsetErrorCB(_handle); - if (error != SttError.None) + _errorOccurred -= value; + if (_errorOccurred == null) { - Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error); + SttError error = SttUnsetErrorCB(_handle); + if (error != SttError.None) + { + Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error); + } } - - _errorOccurred -= value; } } } @@ -518,23 +526,23 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) => - { - string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage); - string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage); - DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString); - _defaultLanguageChanged?.Invoke(this, args); - }; - SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero); - if (error != SttError.None) - { - Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error); - } - - else + if (_defaultLanguageChanged == null) { - _defaultLanguageChanged += value; + _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) => + { + string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage); + string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage); + DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString); + _defaultLanguageChanged?.Invoke(this, args); + }; + + SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero); + if (error != SttError.None) + { + Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error); + } } + _defaultLanguageChanged += value; } } @@ -542,13 +550,15 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - SttError error = SttUnsetDefaultLanguageChangedCB(_handle); - if (error != SttError.None) + _defaultLanguageChanged -= value; + if (_defaultLanguageChanged == null) { - Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error); + SttError error = SttUnsetDefaultLanguageChangedCB(_handle); + if (error != SttError.None) + { + Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error); + } } - - _defaultLanguageChanged -= value; } } @@ -564,22 +574,23 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) => - { - string engineIdString = Marshal.PtrToStringAnsi(engineId); - string languageString = Marshal.PtrToStringAnsi(language); - EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential); - _engineChanged?.Invoke(this, args); - }; - SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero); - if (error != SttError.None) - { - Log.Error(LogTag, "Add EngineChanged Failed with error " + error); - } - else + if (_engineChanged == null) { - _engineChanged += value; + _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) => + { + string engineIdString = Marshal.PtrToStringAnsi(engineId); + string languageString = Marshal.PtrToStringAnsi(language); + EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential); + _engineChanged?.Invoke(this, args); + }; + + SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero); + if (error != SttError.None) + { + Log.Error(LogTag, "Add EngineChanged Failed with error " + error); + } } + _engineChanged += value; } } @@ -587,13 +598,15 @@ namespace Tizen.Uix.Stt { lock (thisLock) { - SttError error = SttUnsetEngineChangedCB(_handle); - if (error != SttError.None) + _engineChanged -= value; + if (_engineChanged == null) { - Log.Error(LogTag, "Remove EngineChanged Failed with error " + error); + SttError error = SttUnsetEngineChangedCB(_handle); + if (error != SttError.None) + { + Log.Error(LogTag, "Remove EngineChanged Failed with error " + error); + } } - - _engineChanged -= value; } } } diff --git a/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs b/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs index 6a53f5c..7c9a2ad 100644 --- a/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs +++ b/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs @@ -257,20 +257,21 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) => + if (_stateChanged == null) { - StateChangedEventArgs args = new StateChangedEventArgs(previous, current); - _stateChanged?.Invoke(this, args); - }; - TtsError error = TtsSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero); - if (error != TtsError.None) - { - Log.Error(LogTag, "Add StateChanged Failed with error " + error); - } - else - { - _stateChanged += value; + _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) => + { + StateChangedEventArgs args = new StateChangedEventArgs(previous, current); + _stateChanged?.Invoke(this, args); + }; + + TtsError error = TtsSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero); + if (error != TtsError.None) + { + Log.Error(LogTag, "Add StateChanged Failed with error " + error); + } } + _stateChanged += value; } } @@ -279,13 +280,15 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - TtsError error = TtsUnsetStateChangedCB(_handle); - if (error != TtsError.None) + _stateChanged -= value; + if (_stateChanged == null) { - Log.Error(LogTag, "Remove StateChanged Failed with error " + error); + TtsError error = TtsUnsetStateChangedCB(_handle); + if (error != TtsError.None) + { + Log.Error(LogTag, "Remove StateChanged Failed with error " + error); + } } - - _stateChanged -= value; } } @@ -301,20 +304,21 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - _utteranceStartedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) => - { - UtteranceEventArgs args = new UtteranceEventArgs(uttId); - _utteranceStarted?.Invoke(this, args); - }; - TtsError error = TtsSetUtteranceStartedCB(_handle, _utteranceStartedResultDelegate, IntPtr.Zero); - if (error != TtsError.None) + if (_utteranceStarted == null) { - Log.Error(LogTag, "Add UtteranceStarted Failed with error " + error); - } - else - { - _utteranceStarted += value; + _utteranceStartedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) => + { + UtteranceEventArgs args = new UtteranceEventArgs(uttId); + _utteranceStarted?.Invoke(this, args); + }; + + TtsError error = TtsSetUtteranceStartedCB(_handle, _utteranceStartedResultDelegate, IntPtr.Zero); + if (error != TtsError.None) + { + Log.Error(LogTag, "Add UtteranceStarted Failed with error " + error); + } } + _utteranceStarted += value; } } @@ -322,13 +326,15 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - TtsError error = TtsUnsetUtteranceStartedCB(_handle); - if (error != TtsError.None) + _utteranceStarted -= value; + if (_utteranceStarted == null) { - Log.Error(LogTag, "Remove UtteranceStarted Failed with error " + error); + TtsError error = TtsUnsetUtteranceStartedCB(_handle); + if (error != TtsError.None) + { + Log.Error(LogTag, "Remove UtteranceStarted Failed with error " + error); + } } - - _utteranceStarted -= value; } } } @@ -343,20 +349,21 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - _utteranceCompletedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) => - { - UtteranceEventArgs args = new UtteranceEventArgs(uttId); - _utteranceCompleted?.Invoke(this, args); - }; - TtsError error = TtsSetUtteranceCompletedCB(_handle, _utteranceCompletedResultDelegate, IntPtr.Zero); - if (error != TtsError.None) - { - Log.Error(LogTag, "Add UtteranceCompleted Failed with error " + error); - } - else + if (_utteranceCompleted == null) { - _utteranceCompleted += value; + _utteranceCompletedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) => + { + UtteranceEventArgs args = new UtteranceEventArgs(uttId); + _utteranceCompleted?.Invoke(this, args); + }; + + TtsError error = TtsSetUtteranceCompletedCB(_handle, _utteranceCompletedResultDelegate, IntPtr.Zero); + if (error != TtsError.None) + { + Log.Error(LogTag, "Add UtteranceCompleted Failed with error " + error); + } } + _utteranceCompleted += value; } } @@ -364,13 +371,15 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - TtsError error = TtsUnsetUtteranceCompletedCB(_handle); - if (error != TtsError.None) + _utteranceCompleted -= value; + if (_utteranceCompleted == null) { - Log.Error(LogTag, "Remove UtteranceCompleted Failed with error " + error); + TtsError error = TtsUnsetUtteranceCompletedCB(_handle); + if (error != TtsError.None) + { + Log.Error(LogTag, "Remove UtteranceCompleted Failed with error " + error); + } } - - _utteranceCompleted -= value; } } } @@ -385,21 +394,21 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - _errorDelegate = (IntPtr handle, int uttId, TtsError reason, IntPtr userData) => - { - ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, uttId, reason); - _errorOccurred?.Invoke(this, args); - }; - TtsError error = TtsSetErrorCB(_handle, _errorDelegate, IntPtr.Zero); - if (error != TtsError.None) + if (_errorOccurred == null) { - Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error); - } - - else - { - _errorOccurred += value; + _errorDelegate = (IntPtr handle, int uttId, TtsError reason, IntPtr userData) => + { + ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, uttId, reason); + _errorOccurred?.Invoke(this, args); + }; + + TtsError error = TtsSetErrorCB(_handle, _errorDelegate, IntPtr.Zero); + if (error != TtsError.None) + { + Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error); + } } + _errorOccurred += value; } } @@ -407,13 +416,15 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - TtsError error = TtsUnsetErrorCB(_handle); - if (error != TtsError.None) + _errorOccurred -= value; + if (_errorOccurred == null) { - Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error); + TtsError error = TtsUnsetErrorCB(_handle); + if (error != TtsError.None) + { + Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error); + } } - - _errorOccurred -= value; } } } @@ -428,23 +439,23 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - _voiceChangedDelegate = (IntPtr handle, IntPtr previousLanguage, int previousVoiceType, IntPtr currentLanguage, int currentVoiceType, IntPtr userData) => + if (_defaultVoiceChanged == null) { - string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage); - string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage); - DefaultVoiceChangedEventArgs args = new DefaultVoiceChangedEventArgs(previousLanguageString, previousVoiceType, currentLanguageString, currentVoiceType); - _defaultVoiceChanged?.Invoke(this, args); - }; - TtsError error = TtsSetDefaultVoiceChangedCB(_handle, _voiceChangedDelegate, IntPtr.Zero); - if (error != TtsError.None) - { - Log.Error(LogTag, "Add DefaultVoiceChanged Failed with error " + error); - } - - else - { - _defaultVoiceChanged += value; + _voiceChangedDelegate = (IntPtr handle, IntPtr previousLanguage, int previousVoiceType, IntPtr currentLanguage, int currentVoiceType, IntPtr userData) => + { + string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage); + string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage); + DefaultVoiceChangedEventArgs args = new DefaultVoiceChangedEventArgs(previousLanguageString, previousVoiceType, currentLanguageString, currentVoiceType); + _defaultVoiceChanged?.Invoke(this, args); + }; + + TtsError error = TtsSetDefaultVoiceChangedCB(_handle, _voiceChangedDelegate, IntPtr.Zero); + if (error != TtsError.None) + { + Log.Error(LogTag, "Add DefaultVoiceChanged Failed with error " + error); + } } + _defaultVoiceChanged += value; } } @@ -453,13 +464,15 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - TtsError error = TtsUnsetDefaultVoiceChangedCB(_handle); - if (error != TtsError.None) - { - Log.Error(LogTag, "Remove DefaultVoiceChanged Failed with error " + error); - } - _defaultVoiceChanged -= value; + if (_defaultVoiceChanged == null) + { + TtsError error = TtsUnsetDefaultVoiceChangedCB(_handle); + if (error != TtsError.None) + { + Log.Error(LogTag, "Remove DefaultVoiceChanged Failed with error " + error); + } + } } } } @@ -474,22 +487,22 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, int voiceType, bool needCredential, IntPtr userData) => - { - string engineIdString = Marshal.PtrToStringAnsi(engineId); - string languageString = Marshal.PtrToStringAnsi(language); - EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, voiceType, needCredential); - _engineChanged?.Invoke(this, args); - }; - TtsError error = TtsSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero); - if (error != TtsError.None) + if (_engineChanged == null) { - Log.Error(LogTag, "Add EngineChanged Failed with error " + error); - } - else - { - _engineChanged += value; + _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, int voiceType, bool needCredential, IntPtr userData) => + { + string engineIdString = Marshal.PtrToStringAnsi(engineId); + string languageString = Marshal.PtrToStringAnsi(language); + EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, voiceType, needCredential); + _engineChanged?.Invoke(this, args); + }; + TtsError error = TtsSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero); + if (error != TtsError.None) + { + Log.Error(LogTag, "Add EngineChanged Failed with error " + error); + } } + _engineChanged += value; } } @@ -497,13 +510,15 @@ namespace Tizen.Uix.Tts { lock (thisLock) { - TtsError error = TtsUnsetEngineChangedCB(_handle); - if (error != TtsError.None) + _engineChanged -= value; + if (_engineChanged == null) { - Log.Error(LogTag, "Remove EngineChanged Failed with error " + error); + TtsError error = TtsUnsetEngineChangedCB(_handle); + if (error != TtsError.None) + { + Log.Error(LogTag, "Remove EngineChanged Failed with error " + error); + } } - - _engineChanged -= value; } } }