Setting since_tizen 3/4 on Tizen.NET API
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.AttachPanel / Tizen.Applications.AttachPanel / AttachPanelInternal.cs
1 using System;
2 using System.Collections.Generic;
3
4 namespace Tizen.Applications.AttachPanel
5 {
6     /// <summary>
7     /// Attach panel internal implementation
8     /// </summary>
9     /// <since_tizen> 4 </since_tizen>
10     public partial class AttachPanel
11     {
12         private static IntPtr _attachPanel;
13         private bool isCreationSucceed;
14
15         private static event EventHandler<StateEventArgs> _eventEventHandler;
16         private static event EventHandler<ResultEventArgs> _resultEventHandler;
17
18         private static Interop.AttachPanel.AttachPanelEventCallback SetEventListener;
19         private static Interop.AttachPanel.AttachPanelResultCallback SetResultListener;
20
21         private void StateEventListenStart()
22         {
23             Interop.AttachPanel.ErrorCode err = 0;
24
25             SetEventListener = (attachPanel, eventType, eventInfo, userData) =>
26             {
27                 _eventEventHandler?.Invoke(null, new StateEventArgs((EventType)eventType));
28             };
29             err = Interop.AttachPanel.SetEventCb(_attachPanel, SetEventListener, IntPtr.Zero);
30             CheckException(err);
31         }
32
33         private void StateEventListenStop()
34         {
35             Interop.AttachPanel.ErrorCode err = 0;
36             err = Interop.AttachPanel.UnsetEventCb(_attachPanel);
37             CheckException(err);
38         }
39
40         private void ResultEventListenStart()
41         {
42             Interop.AttachPanel.ErrorCode err = 0;
43             SetResultListener = (attachPanel, category, resulthandler, resultCode, userData) =>
44             {
45                 SafeAppControlHandle handle = new SafeAppControlHandle(resulthandler, false);
46                 AppControl result = new AppControl(handle);
47                 _resultEventHandler?.Invoke(null, new ResultEventArgs((ContentCategory)category, result, (AppControlReplyResult)resultCode));
48             };
49             err = Interop.AttachPanel.SetResultCb(_attachPanel, SetResultListener, IntPtr.Zero);
50             CheckException(err);
51         }
52
53         private void ResultEventListenStop()
54         {
55             Interop.AttachPanel.ErrorCode err = 0;
56             err = Interop.AttachPanel.UnsetResultCb(_attachPanel);
57             CheckException(err);
58         }
59
60         internal static void CheckException(Interop.AttachPanel.ErrorCode err)
61         {
62             switch (err)
63             {
64                 case Interop.AttachPanel.ErrorCode.InvalidParameter:
65                     throw new ArgumentOutOfRangeException("Invalid parameter error at unmanaged code");
66                 case Interop.AttachPanel.ErrorCode.OutOfMemory:
67                     throw new OutOfMemoryException("Out of Memory");
68                 case Interop.AttachPanel.ErrorCode.PermissionDenied:
69                     throw new UnauthorizedAccessException();
70                 case Interop.AttachPanel.ErrorCode.AlreadyExists:
71                     throw new InvalidOperationException("Already Exists");
72                 case Interop.AttachPanel.ErrorCode.NotInitialized:
73                     throw new InvalidOperationException("Not initialized");
74                 case Interop.AttachPanel.ErrorCode.UnsupportedContentCategory:
75                     throw new NotSupportedException("Unsupported Content Category");
76                 case Interop.AttachPanel.ErrorCode.AlreadyDestroyed:
77                     throw new InvalidOperationException("Already Destroyed");
78             }
79         }
80     }
81 }