{
if (_handlers.ContainsKey(EventType.AppControlReceived))
{
+ // Create a SafeAppControlHandle but the ownsHandle is false,
+ // because the appControlHandle will be closed by native appfw after this method automatically.
+ SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);
+
var handler = _handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
- handler.Invoke(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
+ handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
}
}
{
if (_handlers.ContainsKey(EventType.AppControlReceived))
{
+ // Create a SafeAppControlHandle but the ownsHandle is false,
+ // because the appControlHandle will be closed by native appfw after this method automatically.
+ SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);
+
var handler = _handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
- handler.Invoke(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
+ handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
}
}
/// <param name="handle"></param>
public AppControl(SafeAppControlHandle handle)
{
- _handle = handle;
+ Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle.DangerousGetHandle());
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
+ }
}
- internal AppControl(IntPtr handle)
+ private AppControl(IntPtr handle)
{
Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle);
if (err != Interop.AppControl.ErrorCode.None)
public class AppControlReceivedEventArgs : EventArgs
{
/// <summary>
+ /// Initializes AppControlReceivedEventArgs class.
+ /// </summary>
+ /// <param name="appControl"></param>
+ public AppControlReceivedEventArgs(ReceivedAppControl appControl)
+ {
+ ReceivedAppControl = appControl;
+ }
+
+ /// <summary>
/// The received AppControl.
/// </summary>
- public ReceivedAppControl ReceivedAppControl { get; internal set; }
+ public ReceivedAppControl ReceivedAppControl { get; private set; }
}
}
{
private const string LogTag = "Tizen.Applications";
- internal ReceivedAppControl(IntPtr handle) : base(handle)
+ /// <summary>
+ /// Initializes a ReceivedAppControl class.
+ /// </summary>
+ public ReceivedAppControl(SafeAppControlHandle handle) : base(handle)
{
}
}
/// <summary>
+ /// Initializes a new instance of the SafeAppControlHandle class.
+ /// </summary>
+ /// <param name="existingHandle">An IntPtr object that represents the pre-existing handle to use.</param>
+ /// <param name="ownsHandle">true to reliably release the handle during the finalization phase; false to prevent reliable release.</param>
+ public SafeAppControlHandle(IntPtr existingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
+ {
+ SetHandle(existingHandle);
+ }
+
+ /// <summary>
/// Gets a value that indicates whether the handle is invalid.
/// </summary>
public override bool IsInvalid