Merge "Add missed parameter documentation" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / timer-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 TIMER_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22
23 %}
24 %enddef
25
26 %define TIMER_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27 %typemap(cscode) NameSpace::ClassName %{
28
29   /**
30     * @brief Event arguments that passed via Tick signal
31     *
32     */
33   public class TickEventArgs : EventArgs
34   {
35   }
36
37   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
38   public delegate bool TickEventHandler(object source, TickEventArgs e);
39
40   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
41   private delegate bool TickCallbackDelegate(IntPtr data);
42   private TickEventHandler _timerTickEventHandler;
43   private TickCallbackDelegate _timerTickCallbackDelegate;
44
45   /**
46     * @brief Event for Ticked signal which can be used to subscribe/unsubscribe the event handler
47     * (in the type of TickEventHandler) provided by the user.
48     * Ticked signal is emitted after specified time interval.
49     */
50   public event TickEventHandler Ticked
51   {
52      add
53      {
54         lock(this)
55         {
56            // Restricted to only one listener
57            if (_timerTickEventHandler == null)
58            {
59               _timerTickEventHandler += value;
60
61               _timerTickCallbackDelegate = new TickCallbackDelegate(OnTick);
62               this.TickSignal().Connect(_timerTickCallbackDelegate);
63            }
64         }
65      }
66
67      remove
68      {
69         lock(this)
70         {
71            if (_timerTickEventHandler != null)
72            {
73               this.TickSignal().Disconnect(_timerTickCallbackDelegate);
74            }
75
76            _timerTickEventHandler -= value;
77         }
78      }
79   }
80
81   // Callback for Timer Tick signal
82   private bool OnTick(IntPtr data)
83   {
84      TickEventArgs e = new TickEventArgs();
85
86      if (_timerTickEventHandler != null)
87      {
88         //here we send all data to user event handlers
89         return _timerTickEventHandler(this, e);
90      }
91      return false;
92   }
93
94 %}
95
96 %enddef
97
98
99 %define DALI_TIMER_EVENTHANDLER_PARAM( NameSpace, ClassName)
100
101   TIMER_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
102   TIMER_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
103
104 %enddef
105
106 namespace Dali
107 {
108   DALI_TIMER_EVENTHANDLER_PARAM( Dali::Adaptor, Timer);
109 }