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