2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
19 using static Interop.SttEngine;
21 namespace Tizen.Uix.SttEngine
24 /// Enumeration for the audio types.
26 /// <since_tizen> 4 </since_tizen>
30 /// Signed 16-bit audio type, little endian.
34 /// Unsigned 8-bit audio type.
40 /// Enumeration for the results.
42 /// <since_tizen> 4 </since_tizen>
43 public enum ResultEvent
46 /// Event when either the full matched or the final result is delivered.
50 /// Event when the partial matched result is delivered.
54 /// Event when the recognition has failed.
60 /// Enumeration for the result time.
62 /// <since_tizen> 4 </since_tizen>
66 /// Event when the token is beginning type.
70 /// Event when the token is middle type.
74 /// Event when the token is end type.
80 /// Enumeration for the speech status.
82 /// <since_tizen> 4 </since_tizen>
83 public enum SpeechStatus
86 /// Beginning point of the speech is detected.
88 BeginningPointDetected = 0,
90 /// End point of the speech is detected.
96 /// Enumeration for representing the result message.
98 /// <since_tizen> 4 </since_tizen>
99 public enum ResultMessage
106 /// Recognition failed because the speech started too soon.
110 /// Recognition failed because the speech is too short.
114 /// Recognition failed because the speech is too long.
118 /// Recognition failed because the speech is too quiet to listen.
122 /// Recognition failed because the speech is too loud to listen.
126 /// Recognition failed because the speech is too fast to listen.
133 /// Enumeration for the error values that can occur.
135 /// <since_tizen> 4 </since_tizen>
139 /// Successful, no error.
141 None = ErrorCode.None,
145 OutOfMemory = ErrorCode.OutOfMemory,
149 IoError = ErrorCode.IoError,
151 /// Invalid parameter.
153 InvalidParameter = ErrorCode.InvalidParameter,
155 /// Network down (Out of network).
157 NetworkDown = ErrorCode.NetworkDown,
161 InvalidState = ErrorCode.InvalidState,
163 /// Invalid language.
165 InvalidLanguage = ErrorCode.InvalidLanguage,
167 /// Operation failed.
169 OperationFailed = ErrorCode.OperationFailed,
171 /// Not supported feature of the current engine.
173 NotSupportedFeature = ErrorCode.NotSupportedFeature,
177 NotSupported = ErrorCode.NotSupported,
179 /// Permission denied.
181 PermissionDenied = ErrorCode.PermissionDenied,
183 /// Recording timed out.
185 RecordingTimedOut = ErrorCode.RecordingTimedOut
189 /// This class represents the STT Engine, which has to be inherited to make the engine.
191 /// <since_tizen> 4 </since_tizen>
192 public abstract class Engine
194 private CallbackStructGCHandle _callbackStructGCHandle = new CallbackStructGCHandle();
195 private PrivateDataSetCb _privateDataSetCb;
196 private Action<string> _privateDatacallback;
197 private PrivateDataRequestedCb _privateDataRequestedCb;
198 private OutAction<string> _privateDataRequestedCallback;
199 private static Engine _engine;
200 private IntPtr _structIntPtrHandle;
203 /// An action with 2 input parameters returning an error.
205 /// <typeparam name="T">Generic type for parameter 1.</typeparam>
206 /// <param name="a">The input parameter 1.</param>
207 /// <param name="b">The input parameter 2.</param>
208 /// <returns>Error value.</returns>
209 /// <since_tizen> 4 </since_tizen>
210 public delegate Error Action<T>(T a, T b);
213 /// An action with 2 out parameters returning an error.
215 /// <typeparam name="T">Generic type for parameter 1.</typeparam>
216 /// <param name="a">The input parameter 1.</param>
217 /// <param name="b">The input parameter 2.</param>
218 /// <returns>Error value.</returns>
219 /// <since_tizen> 4 </since_tizen>
220 public delegate Error OutAction<T>(T a, out T b);
223 /// Called when the STT engine provides the time stamp of result to the engine service user.
224 /// This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
226 /// <param name="index">The result index.</param>
227 /// <param name="resultEvent">The token event.</param>
228 /// <param name="text">The result text.</param>
229 /// <param name="startTime">The time started speaking the result text.</param>
230 /// <param name="endTime">The time finished speaking the result text.</param>
231 /// <param name="userData">The user data.</param>
232 /// <returns>true to continue with the next iteration of the loop, false to break out of the loop.</returns>
233 /// <precondition>SendResult() should be called.</precondition>
234 /// <since_tizen> 4 </since_tizen>
235 public delegate bool ResultTime(int index, TimeEvent resultEvent, string text, long startTime, long endTime, IntPtr userData);
238 /// Called when the STT engine informs the engine service user about the whole supported language list.
239 /// This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
241 /// <param name="language">The language is specified as an ISO 3166 alpha-2 two letter country-code
242 /// followed by an ISO 639-1 for the two-letter language code.
243 /// For example, "ko_KR" for Korean, "en_US" for American English.</param>
244 /// <param name="userData">The user data.</param>
245 /// <returns>true to continue with the next iteration of the loop, false to break out of the loop.</returns>
246 /// <precondition>ForEachSupportedLanguages() should be called.</precondition>
247 /// <since_tizen> 4 </since_tizen>
248 public delegate bool SupportedLanguages(string language, IntPtr userData);
251 /// Called when the engine service user requests the basic information of the STT engine.
254 /// In order to upload the engine at Tizen Appstore, both a service application and a UI application are necessary. Therefore, engineSetting must be transferred to the engine service user.
256 /// <param name="engineUuid">UUID of the engine.</param>
257 /// <param name="engineName">Name of the engine.</param>
258 /// <param name="engineSetting">The engine setting application (UI app)'s ID.</param>
259 /// <param name="useNetwork">A variable for checking whether the network is used or not.</param>
261 /// The following error codes can be returned:
263 /// 2. OperationFailed
264 /// 3. InvalidParameter
266 /// <since_tizen> 4 </since_tizen>
267 public abstract Error GetInformation(out string engineUuid, out string engineName, out string engineSetting, out bool useNetwork);
270 /// Called when the engine service user initializes the STT engine.
271 /// This callback function is called by the engine service user to request for the STT engine to be started.
274 /// The following error codes can be returned:
276 /// 2. InvalidParameter
278 /// 4. OperationFailed
280 /// <since_tizen> 4 </since_tizen>
281 public abstract Error Initialize();
284 /// Called when the engine service user deinitializes the STT engine.
285 /// This callback function is called by the engine service user to request for the STT engine to be deinitialized.
288 /// The following error codes can be returned:
292 /// <since_tizen> 4 </since_tizen>
293 public abstract Error Deinitialize();
296 /// Called when the engine service user gets the whole supported language list.
299 /// In this function, the engine service user's callback function 'SupportedLanguages' is invoked repeatedly for getting all the supported languages
300 /// and user_data must be transferred to 'SupportedLanguages'. If 'SupportedLanguages' returns false, it should be stopped to call 'SupportedLanguages'.
302 /// <param name="callback">The callback function,</param>
303 /// <param name="userData">The user data, which must be passed to the callback delegate 'SupportedLanguages'.</param>
305 /// The following error codes can be returned:
308 /// 3. InvalidParameter
311 /// This callback function invokes SupportedLanguages repeatedly for getting the supported languages.
313 /// <since_tizen> 4 </since_tizen>
314 public abstract Error ForEachSupportedLanguages(SupportedLanguages callback, IntPtr userData);
317 /// Called when the engine service user checks whether the corresponding language is valid or not in the STT engine.
319 /// <param name="language">The language is specified as an ISO 3166 alpha-2 two letter country-code followed by an ISO 639-1 for the two-letter language code.
320 /// For example, "ko_KR" for Korean, "en_US" for American English.</param>
321 /// <param name="isValid">A variable for checking whether the corresponding language is valid or not. true to be valid, false to be invalid.</param>
323 /// The following error codes can be returned:
325 /// 2. InvalidParameter
327 /// <since_tizen> 4 </since_tizen>
328 public abstract Error IsValidLanguage(string language, out bool isValid);
331 /// Called when the engine service user checks whether the STT engine supports silence detection.
333 /// <returns>true to support silence detection, false not to support silence detection.</returns>
334 /// <since_tizen> 4 </since_tizen>
335 public abstract bool SupportSilenceDetection();
338 /// Called when the engine service user checks whether the STT engine supports the corresponding recognition type.
340 /// <param name="type">The type for recognition, "stt.recognition.type.FREE", or "stt.recognition.type.FREE.PARTIAL".</param>
341 /// <param name="isSupported">A variable for checking whether the STT engine supports the corresponding recognition type.
342 /// true to support the recognition type, false not to support the recognition type.</param>
344 /// The following error codes can be returned:
346 /// 2. InvalidParameter
348 /// <since_tizen> 4 </since_tizen>
349 public abstract Error SupportRecognitionType(string type, out bool isSupported);
352 /// Called when the engine service user gets the proper recording format of the STT engine.
353 /// The recording format is used for creating the recorder.
355 /// <param name="types">The format used by the recorder.</param>
356 /// <param name="rate">The sample rate used by the recorder.</param>
357 /// <param name="channels">The number of channels used by the recorder.</param>
359 /// The following error codes can be returned:
363 /// <since_tizen> 4 </since_tizen>
364 public abstract Error GetRecordingFormat(out AudioType types, out int rate, out int channels);
367 /// Called when the engine service user sets the silence detection.
368 /// If the engine service user sets this option as 'TRUE', the STT engine will detect the silence (EPD) and send the callback event about it.
370 /// <param name="isSet">A variable for setting the silence detection. true to detect the silence, false not to detect the silence.</param>
372 /// The following error codes can be returned:
375 /// 3. NotSupportedFeature
377 /// <since_tizen> 4 </since_tizen>
378 public abstract Error SetSilenceDetection(bool isSet);
381 /// Called when the engine service user requests for the STT engine to check whether the application agreed the usage of the STT engine.
382 /// This callback function is called when the engine service user requests for the STT engine to check the application's agreement about using the engine.
383 /// According to the need, the engine developer can provide some user interfaces to check the agreement.
385 /// <param name="appid">The Application ID</param>
386 /// <param name="isAgreed">A variable for checking whether the application agreed to use the STT engine or not. true to agree, false to disagree.</param>
388 /// The following error codes can be returned:
391 /// 3. NotSupportedFeature
393 /// <since_tizen> 4 </since_tizen>
394 public abstract Error CheckAppAgreed(string appid, out bool isAgreed);
397 /// Called when the engine service user checks whether STT engine needs the application's credential.
399 /// <returns>true if the STT engine needs the application's credential, otherwise false.</returns>
400 /// <since_tizen> 4 </since_tizen>
401 public abstract bool NeedAppCredential();
404 /// Called when the engine service user gets the result time information(stamp).
407 /// In this function, the engine service user's callback delegate 'ResultTime' is invoked repeatedly for sending the time information to the engine service user
408 /// and user_data must be transferred to 'ResultTime'. If 'ResultTime' returns false, it should be stopped to call 'ResultTime'.
409 /// timeInfo is transferred from SendResult. The type of timeInfo is up to the STT engine developer.
411 /// <param name="timeInfo">The time information.</param>
412 /// <param name="callback">The callback function.</param>
413 /// <param name="userData">The user data, which must be passed to the callback function ResultTime.</param>
415 /// The following error codes can be returned:
418 /// 3. InvalidParameter
421 /// SendResult will invoke this function.
424 /// This function invokes the ResultTime repeatedly for getting the result time information.
426 /// <since_tizen> 4 </since_tizen>
427 public abstract Error ForEachResultTime(IntPtr timeInfo, ResultTime callback, IntPtr userData);
430 /// Called when the engine service user starts to recognize the recording data.
431 /// In this callback function, the STT engine must transfer the recognition result and userData to the engine service user using SendResult().
432 /// Also, if the STT engine needs the application's credential, it sets the credential granted to the application.
434 /// <param name="language">The language is specified as an ISO 3166 alpha-2 two letter country-code followed by an ISO 639-1 for the two-letter language code.
435 /// For example, "ko_KR" for Korean, "en_US" for American English.</param>
436 /// <param name="type">The recognition type, "stt.recognition.type.FREE", or "stt.recognition.type.FREE.PARTIAL".</param>
437 /// <param name="appid">The application ID.</param>
438 /// <param name="credential">The credential granted to the application.</param>
439 /// <param name="userData">The user data to be passed to the callback function.</param>
441 /// The following error codes can be returned:
444 /// 3. InvalidParameter
445 /// 4. InvalidLanguage
446 /// 5. OperationFailed
450 /// The engine is not in recognition processing.
452 /// <since_tizen> 4 </since_tizen>
453 public abstract Error Start(string language, string type, string appid, string credential, IntPtr userData);
456 /// Called when the engine service user sets and sends the recording data for speech recognition.
457 /// This callback function is called by the engine service user to send the recording data to the STT engine. The engine receives the recording data and uses for speech recognition.
458 /// This function should be returned immediately after recording data copy.
460 /// <param name="data">The recording data.</param>
461 /// <param name="length">The length of the recording data.</param>
463 /// The following error codes can be returned:
466 /// 3. InvalidParameter
467 /// 4. OperationFailed
470 /// Start should succeed.</precondition>
472 /// If the engine supports partial result, SendResult() should be invoked.</postcondition>
473 /// <since_tizen> 4 </since_tizen>
474 public abstract Error SetRecordingData(string data, uint length);
477 /// Called when the engine service user stops to recognize the recording data.
478 /// This callback function is called by the engine service user to stop recording and to get the recognition result.
480 /// <returns>The following error codes can be returned:
483 /// 3. OperationFailed
487 /// Start should succeed.</precondition>
489 /// After processing of the engine, SendResult() should be invoked.</postcondition>
490 /// <since_tizen> 4 </since_tizen>
491 public abstract Error Stop();
494 /// Called when the engine service user cancels to recognize the recording data.
495 /// This callback function is called by the engine service user to cancel to recognize the recording data. Also, when starting the recorder is failed, this function is called.
498 /// The following error codes can be returned:
502 /// <precondition>The STT engine is in recognition processing or recording.</precondition>
503 /// <since_tizen> 4 </since_tizen>
504 public abstract Error Cancel();
507 /// Public constructor.
510 /// http://tizen.org/feature/speech.recognition
511 /// http://tizen.org/feature/microphone
513 /// <since_tizen> 4 </since_tizen>
520 /// Main function for the Speech-To-Text (STT) engine.
521 /// This function is the main function for operating the STT engine.
524 /// http://tizen.org/privilege/recorder
527 /// http://tizen.org/feature/speech.recognition
528 /// http://tizen.org/feature/microphone
531 /// ServiceAppMain should be used for working the engine after this function.
533 /// <param name="argc">The number of arguments.</param>
534 /// <param name="argv">The arguments array.</param>
535 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
536 /// <exception cref="NotSupportedException">Thrown in case of not supported.</exception>
537 /// <exception cref="InvalidOperationException">Thrown in case of an operation failure.</exception>
538 /// <since_tizen> 4 </since_tizen>
539 public void EngineMain(int argc, string[] argv)
541 _callbackStructGCHandle.CallbackStruct.version = 1;
542 _callbackStructGCHandle.CallbackStruct.getInfo = _getInfoCb;
543 _callbackStructGCHandle.CallbackStruct.initialize = Initialize;
544 _callbackStructGCHandle.CallbackStruct.deinitialize = _deinitializeCb;
545 _callbackStructGCHandle.CallbackStruct.supportedLanaguge = ForEachSupportedLanguages;
546 _callbackStructGCHandle.CallbackStruct.validLanaguage = _isValidLanguageCb;
547 _callbackStructGCHandle.CallbackStruct.silence = SupportSilenceDetection;
548 _callbackStructGCHandle.CallbackStruct.recognitionType = SupportRecognitionType;
549 _callbackStructGCHandle.CallbackStruct.recordingFormat = GetRecordingFormat;
550 _callbackStructGCHandle.CallbackStruct.resultTime = ForEachResultTime;
551 _callbackStructGCHandle.CallbackStruct.silenceDetection = SetSilenceDetection;
552 _callbackStructGCHandle.CallbackStruct.start = _startCb;
553 _callbackStructGCHandle.CallbackStruct.recordingData = SetRecordingData;
554 _callbackStructGCHandle.CallbackStruct.stop = Stop;
555 _callbackStructGCHandle.CallbackStruct.cancel = Cancel;
556 _callbackStructGCHandle.CallbackStruct.checkAppAgreed = CheckAppAgreed;
557 _callbackStructGCHandle.CallbackStruct.needAppCredential = NeedAppCredential;
558 _structIntPtrHandle = Marshal.AllocHGlobal(Marshal.SizeOf(_callbackStructGCHandle.CallbackStruct));
559 Marshal.StructureToPtr<RequestCallbackStruct>(_callbackStructGCHandle.CallbackStruct, _structIntPtrHandle, false);
560 Error error = STTEMain(argc, argv, _structIntPtrHandle);
561 if (error != Error.None)
563 Log.Error(LogTag, "STTEMain Failed with error " + error);
564 throw ExceptionFactory.CreateException((ErrorCode)error);
567 Log.Info(LogTag, "After STTEMain");
571 /// Sends the recognition result to the engine service user.
574 /// http://tizen.org/feature/speech.recognition
575 /// http://tizen.org/feature/microphone
578 /// This API is used in SetRecordingData() and Stop(), when the STT engine sends the recognition result to the engine service user.
579 /// This function is called in the following situations: 1) After Stop() is called, 2) The end point of speech is detected from recording, or 3) Partial result is occurred.
580 /// The recognition result must be transferred to the engine service user through this function. Also, the timeInfo must be transferred to ForEachResultTime().
581 /// The type of timeInfo is up to the STT engine developer.
583 /// <param name="resultEvent">The result event.</param>
584 /// <param name="type">The recognition type, "stt.recognition.type.FREE", or "stt.recognition.type.FREE.PARTIAL".</param>
585 /// <param name="result">Result texts.</param>
586 /// <param name="resultCount">Result text count.</param>
587 /// <param name="msg">Engine message.</param>
588 /// <param name="timeInfo">The time information.</param>
589 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
590 /// <exception cref="NotSupportedException">Thrown in case of not supported.</exception>
591 /// <exception cref="InvalidOperationException">Thrown in case of an operation failure.</exception>
593 /// The EngineMain function should be invoked before this function is called. Stop will invoke this function.
596 /// This function invokes ForEachResultTime
598 /// <since_tizen> 4 </since_tizen>
599 public void SendResult(ResultEvent resultEvent, string type, string[] result, int resultCount, ResultMessage msg, IntPtr timeInfo)
601 if ((result != null) && (result.Length != 0))
604 string message = "stt.result.message.none";
607 case ResultMessage.None:
608 message = "stt.result.message.none";
611 case ResultMessage.TooFast:
612 message = "stt.result.message.error.too.fast";
615 case ResultMessage.TooLong:
616 message = "stt.result.message.error.too.long";
619 case ResultMessage.TooLoud:
620 message = "stt.result.message.error.too.loud";
623 case ResultMessage.TooQuiet:
624 message = "stt.result.message.error.too.quiet";
627 case ResultMessage.TooShort:
628 message = "stt.result.message.error.too.short";
631 case ResultMessage.TooSoon:
632 message = "stt.result.message.error.too.soon";
636 Error error = STTESendResult(resultEvent, type, result, resultCount, message, timeInfo, IntPtr.Zero);
637 if (error != Error.None)
639 Log.Error(LogTag, "STTESendResult Failed with error " + error);
640 throw ExceptionFactory.CreateException((ErrorCode)error);
646 throw new ArgumentNullException("result", "is null or empty");
651 /// Sends the error to the engine service user.
654 /// http://tizen.org/feature/speech.recognition
655 /// http://tizen.org/feature/microphone
657 /// <param name="error">The error reason.</param>
658 /// <param name="msg">The error message.</param>
659 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
660 /// <exception cref="NotSupportedException">Thrown in case of not supported.</exception>
661 /// <exception cref="InvalidOperationException">Thrown in case of an operation failure.</exception>
663 /// The main function should be invoked before this function is called.
665 /// <since_tizen> 4 </since_tizen>
666 public void SendError(Error error, string msg)
668 Error err = STTESendError(error, msg);
669 if (err != Error.None)
671 Log.Error(LogTag, "SendError Failed with error " + err);
672 throw ExceptionFactory.CreateException((ErrorCode)error);
677 /// Sends the speech status to the engine service user when the STT engine notifies the change of the speech status.
680 /// http://tizen.org/feature/speech.recognition
681 /// http://tizen.org/feature/microphone
684 /// This API is invoked when the STT engine wants to notify the change of the speech status anytime. Note that this API can be invoked for recognizing the speech.
686 /// <param name="status">SpeechStatus</param>
687 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
688 /// <exception cref="NotSupportedException">Thrown in case of not supported.</exception>
689 /// <exception cref="InvalidOperationException">Thrown in case of an operation failure.</exception>
691 /// The main function should be invoked before this function is called. The Start() and SetRecordingData() will invoke this function.
693 /// <since_tizen> 4 </since_tizen>
694 public void SendSpeechStatus(SpeechStatus status)
696 Error error = STTESendSpeechStatus(status, IntPtr.Zero);
697 if (error != Error.None)
699 Log.Error(LogTag, "SendSpeechStatus Failed with error " + error);
700 throw ExceptionFactory.CreateException((ErrorCode)error);
706 /// Sets a callback function for setting the private data.
709 /// http://tizen.org/privilege/recorder
712 /// http://tizen.org/feature/speech.recognition
713 /// http://tizen.org/feature/microphone
715 /// <param name="callback">
716 /// Called when the STT engine receives the private data from the engine service user.
717 /// This callback function is called when the engine service user sends the private data to the STT engine.
719 /// a = Key -- The key field of private data
720 /// b = data -- The data field of private data
721 /// The following error codes can be returned:
723 /// 2. InvalidParameter
724 /// 3. OperationFailed
726 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
727 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
728 /// <exception cref="NotSupportedException">Thrown in case of not supported.</exception>
729 /// <exception cref="InvalidOperationException">Thrown in case of an operation failure.</exception>
731 /// The main function should be invoked before this function is called.
733 /// <since_tizen> 4 </since_tizen>
734 public void SetPrivateDataSetDelegate(Action<string> callback)
736 if (null == callback)
738 Log.Error(LogTag, "callback is null");
739 throw ExceptionFactory.CreateException(ErrorCode.InvalidParameter);
742 _privateDatacallback = callback;
743 _privateDataSetCb = (string key, string data) =>
745 return _privateDatacallback.Invoke(key, data);
747 Error error = STTESetPrivateDataSetCb(_privateDataSetCb);
748 if (error != Error.None)
750 Log.Error(LogTag, "SetPrivateDataSetDelegate Failed with error " + error);
751 throw ExceptionFactory.CreateException((ErrorCode)error);
757 /// Sets a callback delegate for requesting the private data.
760 /// http://tizen.org/privilege/recorder
763 /// http://tizen.org/feature/speech.recognition
764 /// http://tizen.org/feature/microphone
766 /// <param name="callback">The callback function.
767 /// Called when the STT engine provides the engine service user with the private data.
768 /// This callback function is called when the engine service user gets the private data from the STT engine.
770 /// a = Key -- The key field of private data
771 /// b = data -- The data field of private data
772 /// The following error codes can be returned:
774 /// 2. InvalidParameter
775 /// 3. OperationFailed
777 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
778 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
779 /// <exception cref="NotSupportedException">Thrown in case of not supported.</exception>
780 /// <exception cref="InvalidOperationException">Thrown in case of an operation failure.</exception>
782 /// The main function should be invoked before this function is called.
784 /// <since_tizen> 4 </since_tizen>
785 public void SetPrivateDataRequestedDelegate(OutAction<string> callback)
787 if (null == callback)
789 Log.Error(LogTag, "callback is null");
790 throw ExceptionFactory.CreateException(ErrorCode.InvalidParameter);
793 _privateDataRequestedCallback = callback;
794 _privateDataRequestedCb = (string key, out string data) =>
796 return _privateDataRequestedCallback.Invoke(key, out data);
798 Error error = STTESetPrivateDataRequestedCb(_privateDataRequestedCb);
799 if (error != Error.None)
801 Log.Error(LogTag, "SetPrivateDataRequestedDelegate Failed with error " + error);
802 throw ExceptionFactory.CreateException((ErrorCode)error);
807 private StartCb _startCb = (IntPtr language, IntPtr type, IntPtr appid, IntPtr credential, IntPtr userData) =>
813 if (language != null)
814 lan = Marshal.PtrToStringAnsi(language);
816 typ = Marshal.PtrToStringAnsi(type);
818 apid = Marshal.PtrToStringAnsi(appid);
819 if (credential != null)
820 cre = Marshal.PtrToStringAnsi(credential);
821 return _engine.Start(lan, typ, apid, cre, IntPtr.Zero);
824 private IsValidLanguageCb _isValidLanguageCb = (IntPtr langauge, IntPtr isValid) =>
826 string langaugeStr = Marshal.PtrToStringAnsi(langauge);
828 Error err = _engine.IsValidLanguage(langaugeStr, out valid);
831 Marshal.WriteByte(isValid, 0, 1);
835 Marshal.WriteByte(isValid, 0, 0);
840 private GetInfoCb _getInfoCb = (out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out IntPtr useNetwork) =>
846 Error err = _engine.GetInformation(out uuid, out name, out setting, out network);
847 int size = Marshal.SizeOf<int>();
848 IntPtr pBool = Marshal.AllocHGlobal(size);
851 Marshal.WriteInt32(pBool, 0, 1);
855 Marshal.WriteInt32(pBool, 0, 0);
857 engineUuid = Marshal.StringToHGlobalAnsi(uuid);
858 engineName = Marshal.StringToHGlobalAnsi(name);
859 engineSetting = Marshal.StringToHGlobalAnsi(setting);
864 private DeinitializeCb _deinitializeCb = () =>
866 Marshal.FreeHGlobal(_engine._structIntPtrHandle);
867 return _engine.Deinitialize();