Change Interop for iotcon_attributes_get_str()
authorJooseok Park <jooseok.park@samsung.com>
Thu, 30 Mar 2017 00:49:48 +0000 (09:49 +0900)
committerJooseok Park <jooseok.park@samsung.com>
Thu, 30 Mar 2017 00:49:48 +0000 (09:49 +0900)
 - Change string to IntPtr to avoid to free char pointer in C#
 - Also, need to marshal pointer to string

Change-Id: Iaa3851c99717b93cd923d6a77cabffa48ec3f63d

src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Common.cs
src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs

index d1d9af0..9b4fa48 100755 (executable)
@@ -131,7 +131,7 @@ internal static partial class Interop
                 internal static extern int GetDouble(IntPtr attributes, string key, out double val);
 
                 [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_str")]
-                internal static extern int GetStr(IntPtr attributes, string key, out string val);
+                internal static extern int GetStr(IntPtr attributes, string key, out IntPtr val);
 
                 [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_byte_str")]
                 internal static extern int GetByteStr(IntPtr attributes, string key, out IntPtr value, out int size);
index fd7012a..57a6e3a 100755 (executable)
@@ -63,7 +63,7 @@ namespace Tizen.Network.IoTConnectivity
                 throw IoTConnectivityErrorFactory.GetException(ret);
             }
 
-            SetAttributes(attributesHandleToClone);
+            SetAttributes(_resourceAttributesHandle);
         }
 
         /// <summary>
@@ -538,14 +538,16 @@ namespace Tizen.Network.IoTConnectivity
                         }
                     case Interop.IoTConnectivity.Common.DataType.String:
                         {
-                            string value;
+                            IntPtr value;
+                            string Str;
                             ret = Interop.IoTConnectivity.Common.Attributes.GetStr(attributes, key, out value);
                             if (ret != (int)IoTConnectivityError.None)
                             {
                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
                                 throw IoTConnectivityErrorFactory.GetException(ret);
                             }
-                            _attributes.Add(key, value);
+                            Str = Marshal.PtrToStringAnsi(value);
+                            _attributes.Add(key, Str);
                             break;
                         }
                     case Interop.IoTConnectivity.Common.DataType.ByteStr: