Merge "DALi C# binding - Follow Pascal case convention for enum members" into devel...
[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   private delegate bool TickCallbackDelegate(IntPtr data);
39   private DaliEventHandlerWithReturnType<object,TickEventArgs,bool> _timerTickEventHandler;
40   private TickCallbackDelegate _timerTickCallbackDelegate;
41
42   /**
43     * @brief Event for Ticked signal which can be used to subscribe/unsubscribe the event handler
44     * (in the type of TickEventHandler-DaliEventHandlerWithReturnType<object,TickEventArgs,bool>) 
45     * provided by the user. Ticked signal is emitted after specified time interval.
46     */
47   public event DaliEventHandlerWithReturnType<object,TickEventArgs,bool> Ticked
48   {
49      add
50      {
51         lock(this)
52         {
53            // Restricted to only one listener
54            if (_timerTickEventHandler == null)
55            {
56               _timerTickEventHandler += value;
57
58               _timerTickCallbackDelegate = new TickCallbackDelegate(OnTick);
59               this.TickSignal().Connect(_timerTickCallbackDelegate);
60            }
61         }
62      }
63
64      remove
65      {
66         lock(this)
67         {
68            if (_timerTickEventHandler != null)
69            {
70               this.TickSignal().Disconnect(_timerTickCallbackDelegate);
71            }
72
73            _timerTickEventHandler -= value;
74         }
75      }
76   }
77
78   // Callback for Timer Tick signal
79   private bool OnTick(IntPtr data)
80   {
81      TickEventArgs e = new TickEventArgs();
82
83      if (_timerTickEventHandler != null)
84      {
85         //here we send all data to user event handlers
86         return _timerTickEventHandler(this, e);
87      }
88      return false;
89   }
90
91 %}
92
93 %enddef
94
95
96 %define DALI_TIMER_EVENTHANDLER_PARAM( NameSpace, ClassName)
97
98   TIMER_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
99   TIMER_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
100
101 %enddef
102
103 namespace Dali
104 {
105   DALI_TIMER_EVENTHANDLER_PARAM( Dali::Adaptor, Timer);
106 }