[TtsEngine/SttEngine] Fix invalid marshalling (#29)
authorstomHwang <35016426+stomHwang@users.noreply.github.com>
Fri, 12 Jan 2018 13:55:32 +0000 (22:55 +0900)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2018 13:55:32 +0000 (22:55 +0900)
* [TtsEngine] Fix invalid marshalling

Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
* [TtsEngine] Fix invalid marshalling

Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
* [SttEngine] Fix invalid marshalling

Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
src/Tizen.Uix.SttEngine/Interop/Interop.SttEngine.cs
src/Tizen.Uix.SttEngine/Tizen.Uix.SttEngine/SttEngine.cs
src/Tizen.Uix.TtsEngine/Interop/Interop.TtsEngine.cs
src/Tizen.Uix.TtsEngine/Tizen.Uix.TtsEngine/TtsEngine.cs

index 6aea927..25394c8 100755 (executable)
@@ -60,13 +60,13 @@ internal static partial class Interop
         internal delegate Error ForEachSupportedLangsCb(SupportedLanguages cb, IntPtr userData);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate Error IsValidLanguageCb(IntPtr language, IntPtr isValid);
+        internal delegate Error IsValidLanguageCb(string language, out byte isValid);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate bool SupportSilenceDetectionCb();
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate Error SupportRecognitionTypeCb(string type, out bool isSupported);
+        internal delegate Error SupportRecognitionTypeCb(string type, out byte isSupported);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate Error GetRecordingFormatCb(out AudioType types, out int rate, out int channels);
@@ -75,7 +75,7 @@ internal static partial class Interop
         internal delegate Error SetSilenceDetectionCb(bool isSet);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate Error CheckAppAgreedCb(string appid, out bool isAgreed);
+        internal delegate Error CheckAppAgreedCb(string appid, out byte isAgreed);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate bool NeedAppCredentialCb();
@@ -84,7 +84,7 @@ internal static partial class Interop
         internal delegate Error ForEachResultTimeCb(IntPtr timeInfo, ResultTime callback, IntPtr userData);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate Error StartCb(IntPtr language, IntPtr type, IntPtr appid, IntPtr credential, IntPtr userData);
+        internal delegate Error StartCb(string language, string type, string appid, string credential, IntPtr userData);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate Error SetRecordingDataCb(string data, uint length);
@@ -96,7 +96,7 @@ internal static partial class Interop
         internal delegate Error CancelCb();
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate Error GetInfoCb(out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out IntPtr useNetwork);
+        internal delegate Error GetInfoCb(out string engineUuid, out string engineName, out string engineSetting, out byte useNetwork);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate Error PrivateDataSetCb(string key, string data);
index ed3580b..c85a64a 100755 (executable)
@@ -545,15 +545,15 @@ namespace Tizen.Uix.SttEngine
             _callbackStructGCHandle.CallbackStruct.supportedLanaguge = ForEachSupportedLanguages;
             _callbackStructGCHandle.CallbackStruct.validLanaguage = _isValidLanguageCb;
             _callbackStructGCHandle.CallbackStruct.silence = SupportSilenceDetection;
-            _callbackStructGCHandle.CallbackStruct.recognitionType = SupportRecognitionType;
+            _callbackStructGCHandle.CallbackStruct.recognitionType = _supportRecognitionTypeCb;
             _callbackStructGCHandle.CallbackStruct.recordingFormat = GetRecordingFormat;
             _callbackStructGCHandle.CallbackStruct.resultTime = ForEachResultTime;
             _callbackStructGCHandle.CallbackStruct.silenceDetection = SetSilenceDetection;
-            _callbackStructGCHandle.CallbackStruct.start = _startCb;
+            _callbackStructGCHandle.CallbackStruct.start = Start;
             _callbackStructGCHandle.CallbackStruct.recordingData = SetRecordingData;
             _callbackStructGCHandle.CallbackStruct.stop = Stop;
             _callbackStructGCHandle.CallbackStruct.cancel = Cancel;
-            _callbackStructGCHandle.CallbackStruct.checkAppAgreed = CheckAppAgreed;
+            _callbackStructGCHandle.CallbackStruct.checkAppAgreed = _checkAppAgreedCb;
             _callbackStructGCHandle.CallbackStruct.needAppCredential = NeedAppCredential;
             _structIntPtrHandle = Marshal.AllocHGlobal(Marshal.SizeOf(_callbackStructGCHandle.CallbackStruct));
             Marshal.StructureToPtr<RequestCallbackStruct>(_callbackStructGCHandle.CallbackStruct, _structIntPtrHandle, false);
@@ -804,60 +804,68 @@ namespace Tizen.Uix.SttEngine
 
         }
 
-        private StartCb _startCb = (IntPtr language, IntPtr type, IntPtr appid, IntPtr credential, IntPtr userData) =>
+        private IsValidLanguageCb _isValidLanguageCb = (string langauge, out byte isValid) =>
         {
-            string lan = null;
-            string typ = null;
-            string apid = null;
-            string cre = null;
-            if (language != null)
-                lan = Marshal.PtrToStringAnsi(language);
-            if (type != null)
-                typ = Marshal.PtrToStringAnsi(type);
-            if (appid != null)
-                apid = Marshal.PtrToStringAnsi(appid);
-            if (credential != null)
-                cre = Marshal.PtrToStringAnsi(credential);
-            return _engine.Start(lan, typ, apid, cre, IntPtr.Zero);
+            bool valid;
+            Error err = _engine.IsValidLanguage(langauge, out valid);
+            if (true == valid)
+            {
+                isValid = 1;
+            }
+            else
+            {
+                isValid = 0;
+            }
+
+            return err;
+        };
+        
+        private CheckAppAgreedCb _checkAppAgreedCb = (string appid, out byte isAgreed) =>
+        {
+            bool agreed;
+            Error err = _engine.CheckAppAgreed(appid, out agreed);
+            if (true == agreed)
+            {
+                isAgreed = 1;
+            }
+            else
+            {
+                isAgreed = 0;
+            }
+
+            return err;
         };
 
-        private IsValidLanguageCb _isValidLanguageCb = (IntPtr langauge, IntPtr isValid) =>
+        private SupportRecognitionTypeCb _supportRecognitionTypeCb = (string type, out byte isSupported) =>
         {
-            string langaugeStr = Marshal.PtrToStringAnsi(langauge);
-            bool valid;
-            Error err = _engine.IsValidLanguage(langaugeStr, out valid);
-            if (valid == true)
+            bool supported;
+            Error err = _engine.SupportRecognitionType(type, out supported);
+            if (true == supported)
             {
-                Marshal.WriteByte(isValid, 0, 1);
+                isSupported = 1;
             }
             else
             {
-                Marshal.WriteByte(isValid, 0, 0);
+                isSupported = 0;
             }
+
             return err;
         };
 
-        private GetInfoCb _getInfoCb = (out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out IntPtr useNetwork) =>
+        private GetInfoCb _getInfoCb = (out string engineUuid, out string engineName, out string engineSetting, out byte useNetwork) =>
         {
-            string uuid;
-            string name;
-            string setting;
             bool network;
-            Error err = _engine.GetInformation(out uuid, out name, out setting, out network);
-            int size = Marshal.SizeOf<int>();
-            IntPtr pBool = Marshal.AllocHGlobal(size);
-            if (network == true)
+
+            Error err = _engine.GetInformation(out engineUuid, out engineName, out engineSetting, out network);
+            if (true == network)
             {
-                Marshal.WriteInt32(pBool, 0, 1);
+                useNetwork = 1;
             }
             else
             {
-                Marshal.WriteInt32(pBool, 0, 0);
+                useNetwork = 0;
             }
-            engineUuid = Marshal.StringToHGlobalAnsi(uuid);
-            engineName = Marshal.StringToHGlobalAnsi(name);
-            engineSetting = Marshal.StringToHGlobalAnsi(setting);
-            useNetwork = pBool;
+
             return err;
         };
 
index a6c5b3b..70270a7 100755 (executable)
@@ -77,13 +77,13 @@ internal static partial class Interop
         internal delegate bool NeedAppCredentialCb();
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate Error StartSynthesisCb(IntPtr language, int type, IntPtr text, int speed, IntPtr appid, IntPtr credential, IntPtr userData);
+        internal delegate Error StartSynthesisCb(string language, int type, string text, int speed, string appid, string credential, IntPtr userData);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate Error CancelSynthesisCb();
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate Error GetInfoCb(out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out byte useNetwork);
+        internal delegate Error GetInfoCb(out string engineUuid, out string engineName, out string engineSetting, out byte useNetwork);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate Error PrivateDataSetCb(string key, string data);
index c52050b..aa573b1 100755 (executable)
@@ -172,7 +172,7 @@ namespace Tizen.Uix.TtsEngine
 
         /// <summary>
         /// Called when the TTS engine informs the engine service user about whole supported language and voice type list.
-        /// This callback function is implemented by the engine service user, therefore, the engine developer does NOT have to implement this callback function. 
+        /// This callback function is implemented by the engine service user, therefore, the engine developer does NOT have to implement this callback function.
         /// </summary>
         /// <remarks>
         /// This callback function is called by ForEachSupportedVoices() to inform the whole supported voice list. userData must be transferred from ForEachSupportedVoices().
@@ -425,7 +425,7 @@ namespace Tizen.Uix.TtsEngine
             _callbackStructGCHandle.CallbackStruct.pitch = SetPitch;
             _callbackStructGCHandle.CallbackStruct.loadVoice = LoadVoice;
             _callbackStructGCHandle.CallbackStruct.unloadVoice = UnloadVoice;
-            _callbackStructGCHandle.CallbackStruct.startSynthesis = _startSynthesisCb;
+            _callbackStructGCHandle.CallbackStruct.startSynthesis = StartSynthesis;
             _callbackStructGCHandle.CallbackStruct.cancelSynthesis = CancelSynthesis;
             _callbackStructGCHandle.CallbackStruct.checkAppAgreed = _checkAppAgreedCb;
             _callbackStructGCHandle.CallbackStruct.needAppCredential = NeedAppCredential;
@@ -645,11 +645,9 @@ namespace Tizen.Uix.TtsEngine
 
         private IsValidVoiceCb _validVoiceCb = (string language, int type, out byte isValid) =>
         {
-            Log.Error(LogTag, "_isValidVoiceCb called");
             bool valid;
             Error err = _engine.IsValidVoice(language, type, out valid);
 
-            Log.Error(LogTag, "check valid and insert value" + valid);
             if (true == valid)
             {
                 isValid = 1;
@@ -679,30 +677,11 @@ namespace Tizen.Uix.TtsEngine
             return err;
         };
 
-        private StartSynthesisCb _startSynthesisCb = (IntPtr language, int type, IntPtr text, int speed, IntPtr appid, IntPtr credential, IntPtr userData) =>
+        private GetInfoCb _getInfoCb = (out string engineUuid, out string engineName, out string engineSetting, out byte useNetwork) =>
         {
-            string lan = null;
-            string txt = null;
-            string apid = null;
-            string cre = null;
-            if (language != null)
-                lan = Marshal.PtrToStringAnsi(language);
-            if (text != null)
-                txt = Marshal.PtrToStringAnsi(text);
-            if (appid != null)
-                apid = Marshal.PtrToStringAnsi(appid);
-            if (credential != null)
-                cre = Marshal.PtrToStringAnsi(credential);
-            return _engine.StartSynthesis(lan, type, txt, speed, apid, cre, IntPtr.Zero);
-        };
-
-        private GetInfoCb _getInfoCb = (out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out byte useNetwork) =>
-        {
-            string uuid;
-            string name;
-            string setting;
             bool network;
-            Error err = _engine.GetInformation(out uuid, out name, out setting, out network);
+
+            Error err = _engine.GetInformation(out engineUuid, out engineName, out engineSetting, out network);
             if (true == network)
             {
                 useNetwork = 1;
@@ -711,9 +690,7 @@ namespace Tizen.Uix.TtsEngine
             {
                 useNetwork = 0;
             }
-            engineUuid = Marshal.StringToHGlobalAnsi(uuid);
-            engineName = Marshal.StringToHGlobalAnsi(name);
-            engineSetting = Marshal.StringToHGlobalAnsi(setting);
+
             return err;
         };