Release 4.0.0-preview1-00286
[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     public partial class AttachPanel
10     {
11         private static IntPtr _attachPanel;
12         private bool isCreationSucceed;
13
14         private static event EventHandler<StateEventArgs> _eventEventHandler;
15         private static event EventHandler<ResultEventArgs> _resultEventHandler;
16
17         private static Interop.AttachPanel.AttachPanelEventCallback SetEventListener;
18         private static Interop.AttachPanel.AttachPanelResultCallback SetResultListener;
19
20         private void StateEventListenStart()
21         {
22             Interop.AttachPanel.ErrorCode err = 0;
23
24             SetEventListener = (attachPanel, eventType, eventInfo, userData) =>
25             {
26                 _eventEventHandler?.Invoke(null, new StateEventArgs((EventType)eventType));
27             };
28             err = Interop.AttachPanel.SetEventCb(_attachPanel, SetEventListener, IntPtr.Zero);
29             CheckException(err);
30         }
31
32         private void StateEventListenStop()
33         {
34             Interop.AttachPanel.ErrorCode err = 0;
35             err = Interop.AttachPanel.UnsetEventCb(_attachPanel);
36             CheckException(err);
37         }
38
39         private void ResultEventListenStart()
40         {
41             Interop.AttachPanel.ErrorCode err = 0;
42             SetResultListener = (attachPanel, category, resulthandler, resultCode, userData) =>
43             {
44                 SafeAppControlHandle handle = new SafeAppControlHandle(resulthandler, false);
45                 AppControl result = new AppControl(handle);
46                 _resultEventHandler?.Invoke(null, new ResultEventArgs((ContentCategory)category, result, (AppControlReplyResult)resultCode));
47             };
48             err = Interop.AttachPanel.SetResultCb(_attachPanel, SetResultListener, IntPtr.Zero);
49             CheckException(err);
50         }
51
52         private void ResultEventListenStop()
53         {
54             Interop.AttachPanel.ErrorCode err = 0;
55             err = Interop.AttachPanel.UnsetResultCb(_attachPanel);
56             CheckException(err);
57         }
58
59         internal static void CheckException(Interop.AttachPanel.ErrorCode err)
60         {
61             switch (err)
62             {
63                 case Interop.AttachPanel.ErrorCode.InvalidParameter:
64                     throw new ArgumentOutOfRangeException("Invalid parameter error at unmanaged code");
65                 case Interop.AttachPanel.ErrorCode.OutOfMemory:
66                     throw new OutOfMemoryException("Out of Memory");
67                 case Interop.AttachPanel.ErrorCode.PermissionDenied:
68                     throw new UnauthorizedAccessException();
69                 case Interop.AttachPanel.ErrorCode.AlreadyExists:
70                     throw new InvalidOperationException("Already Exists");
71                 case Interop.AttachPanel.ErrorCode.NotInitialized:
72                     throw new InvalidOperationException("Not initialized");
73                 case Interop.AttachPanel.ErrorCode.UnsupportedContentCategory:
74                     throw new NotSupportedException("Unsupported Content Category");
75                 case Interop.AttachPanel.ErrorCode.AlreadyDestroyed:
76                     throw new InvalidOperationException("Already Destroyed");
77             }
78         }
79     }
80 }