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