729e8a3febf67ce23e952c85b8f2da75c26f91a4
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / rendertask-event.i
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 %define RenderTask_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22
23 %}
24
25 %enddef
26
27 %define RenderTask_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
28 %typemap(cscode) NameSpace::ClassName %{
29
30
31 public class FinishedEventArgs : EventArgs
32 {
33    private RenderTask _renderTask;
34
35    public RenderTask RenderTask
36    {
37       get
38       {
39          return _renderTask;
40       }
41       set
42       {
43          _renderTask = value;
44       }
45    }
46 }
47
48   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
49   public delegate void RenderTaskEventHandler(object source, FinishedEventArgs e);
50
51   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
52   private delegate void RenderTaskCallbackDelegate(IntPtr renderTask);
53   private RenderTaskEventHandler _renderTaskEventHandler;
54   private RenderTaskCallbackDelegate _renderTaskCallbackDelegate;
55
56
57   public event RenderTaskEventHandler Finished
58   {
59      add
60      {
61         lock(this)
62         {
63            // Restricted to only one listener
64            if (_renderTaskEventHandler == null)
65            {
66               _renderTaskEventHandler += value;
67
68               _renderTaskCallbackDelegate = new RenderTaskCallbackDelegate(OnFinished);
69               this.FinishedSignal().Connect(_renderTaskCallbackDelegate);
70            }
71         }
72      }
73
74      remove
75      {
76         lock(this)
77         {
78            if (_renderTaskEventHandler != null)
79            {
80               this.FinishedSignal().Disconnect(_renderTaskCallbackDelegate);
81            }
82
83            _renderTaskEventHandler -= value;
84         }
85      }
86   }
87
88  private void OnFinished(IntPtr actor, IntPtr renderTask)
89   {
90    FinishedEventArgs e = new FinishedEventArgs();
91
92    // Populate all members of "e" (FinishedEventArgs) with real data
93    e.RenderTask = Dali.RenderTask.GetRenderTaskFromPtr(renderTask);
94
95    if (_renderTaskEventHandler != null)
96    {
97       //here we send all data to user event handlers
98       _renderTaskEventHandler(this, e);
99    }
100
101   }
102
103
104 public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
105    ClassName ret = new ClassName(cPtr, false);
106    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107     return ret;
108   }
109
110 %}
111
112 %enddef
113
114 %define DALI_renderTask_EVENTHANDLER_PARAM( NameSpace, ClassName)
115
116   RenderTask_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
117   RenderTask_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
118
119 %enddef
120
121 namespace Dali
122 {
123   DALI_renderTask_EVENTHANDLER_PARAM( Dali, RenderTask);
124 }