Avoid debug assert when Timer is destroyed
[platform/core/uifw/dali-adaptor.git] / adaptors / common / timer-impl.h
1 #ifndef __DALI_INTERNAL_TIMER_H__
2 #define __DALI_INTERNAL_TIMER_H__
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <base/interfaces/timer-interface.h>
27 #include <timer.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37 class Timer;
38
39 typedef IntrusivePtr<Timer> TimerPtr;
40
41 /**
42  * Implementation of the timer
43  */
44 class Timer : public BaseObject, public TimerInterface
45 {
46 public:
47   static TimerPtr New( unsigned int milliSec );
48
49   /**
50    * Constructor
51    * @param[in]  milliSec  Interval in milliseconds.
52    */
53   Timer( unsigned int milliSec );
54
55   /**
56    * Destructor.
57    */
58   virtual ~Timer();
59
60 public:
61
62   /**
63    * @copydoc Dali::Timer::Start()
64    */
65   virtual void Start();
66
67   /**
68    * @copydoc Dali::Timer::Stop()
69    */
70   virtual void Stop();
71
72   /**
73    * @copydoc Dali::Timer::SetInterval()
74    */
75   virtual void SetInterval( unsigned int interval );
76
77   /**
78    * @copydoc Dali::Timer::GetInterval()
79    */
80   virtual unsigned int GetInterval() const;
81
82   /**
83    * @copydoc Dali::Timer::IsRunning()
84    */
85   virtual bool IsRunning() const;
86
87   /**
88    * Tick
89    */
90   bool Tick();
91
92 public: // Signals
93
94   Dali::Timer::TimerSignalType& TickSignal();
95
96 private: // Implementation
97
98   // not implemented
99   Timer( const Timer& );
100   Timer& operator=( const Timer& );
101
102   /**
103    * Resets any stored timer data.
104    */
105   void ResetTimerData();
106
107 private: // Data
108
109   Dali::Timer::TimerSignalType mTickSignal;
110
111   // To hide away implementation details
112   struct Impl;
113   Impl* mImpl;
114 };
115
116 inline Timer& GetImplementation(Dali::Timer& timer)
117 {
118   DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
119
120   BaseObject& handle = timer.GetBaseObject();
121
122   return static_cast<Internal::Adaptor::Timer&>(handle);
123 }
124
125 inline const Timer& GetImplementation(const Dali::Timer& timer)
126 {
127   DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
128
129   const BaseObject& handle = timer.GetBaseObject();
130
131   return static_cast<const Internal::Adaptor::Timer&>(handle);
132 }
133
134 } // namespace Adaptor
135
136 } // namespace Internal
137
138 } // namespace Dali
139
140 #endif // __DALI_INTERNAL_TIMER_H__