--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Libc
+ {
+ [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int Free(IntPtr ptr);
+ }
+}
internal static extern string GetPkgId(string widgetId);
[DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_supported_sizes")]
- internal static extern ErrorCode GetSupportedSizes(string widgetId, ref int cnt, out int[] w, out int[] h);
+ internal static extern ErrorCode GetSupportedSizes(string widgetId, ref int cnt, out IntPtr w, out IntPtr h);
[DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_supported_size_types")]
- internal static extern ErrorCode GetSupportedSizeTypes(string widgetId, ref int cnt, out int[] types);
+ internal static extern ErrorCode GetSupportedSizeTypes(string widgetId, ref int cnt, out IntPtr types);
[DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_preview_image_path")]
internal static extern string GetPreviewImagePath(string widgetId, int sizeType);
using System;
using System.Collections.Generic;
using Tizen.Applications;
+using System.Runtime.InteropServices;
namespace Tizen.Applications
{
/// </summary>
public class WidgetControl : IDisposable
{
+ protected static readonly string LogTag = "WidgetControl";
/// <summary>
/// Class for the widget instance.
/// </summary>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
public IEnumerable<Scale> GetScales()
{
- int[] w = new int[100];
- int[] h = new int[100];
- int[] types = new int[100];
+ IntPtr wPtr;
+ IntPtr hPtr;
+ IntPtr typesPtr;
+ int[] w;
+ int[] h;
+ int[] types;
int cnt1 = 100;
int cnt2 = 100;
IList<Scale> scales = new List<Scale>();
+ Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetSupportedSizes(Id, ref cnt1, out wPtr, out hPtr);
- Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetSupportedSizes(Id, ref cnt1, out w, out h);
+ if (cnt1 == 0)
+ {
+ Log.Error(LogTag, "No supported size :" + Id);
+ return null;
+ }
switch (err)
{
case Interop.WidgetService.ErrorCode.PermissionDenied:
throw new UnauthorizedAccessException();
}
+ w = new int[cnt1];
+ Marshal.Copy(wPtr, w, 0, cnt1);
+ Interop.Libc.Free(wPtr);
- err = Interop.WidgetService.GetSupportedSizeTypes(Id, ref cnt2, out types);
+ h = new int[cnt1];
+ Marshal.Copy(hPtr, h, 0, cnt1);
+ Interop.Libc.Free(hPtr);
+ err = Interop.WidgetService.GetSupportedSizeTypes(Id, ref cnt2, out typesPtr);
switch (err)
{
case Interop.WidgetService.ErrorCode.InvalidParameter:
}
if (cnt1 != cnt2)
+ {
+ Log.Error(LogTag, "Count not match cnt1 :" + cnt1 + ", cnt2 :" + cnt2);
return null;
+ }
+
+ types = new int[cnt2];
+ Marshal.Copy(typesPtr, types, 0, cnt2);
+ Interop.Libc.Free(typesPtr);
for (int i = 0; i < cnt1; i++)
{