Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRt_TimerImpl.h
1 //
2 // Copyright (c) 2012 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  * @file        FBaseRt_TimerImpl.h
19  * @brief       This is the header file for the _TimerImpl class.
20  *
21  * This file contains the declarations of _TimerImpl.
22  */
23
24
25 #ifndef _FBASE_RT_INTERNAL_TIMER_IMPL_H_
26 #define _FBASE_RT_INTERNAL_TIMER_IMPL_H_
27
28 #include <glib.h>
29
30 #include <FBaseResult.h>
31 #include <FBaseObject.h>
32 #include <FBaseRtTypes.h>
33
34 namespace Tizen { namespace Base { namespace Runtime
35 {
36
37 class Timer;
38 class ITimerEventListener;
39
40 class _TimerImpl
41         : public Tizen::Base::Object
42 {
43 public:
44         /**
45          * This is the default constructor for this class.
46          *
47          * @since 2.0
48          */
49         _TimerImpl(void);
50
51
52         /**
53          * This is the destructor for this class.
54          *
55          * @since 2.0
56          */
57         virtual ~_TimerImpl(void);
58
59         /**
60          * Initializes the time instance.
61          *
62          * @since 2.0
63          * @return              An error code
64          * @param[in]   listener                The event listener
65          * @exception   E_SUCCESS               The method was successful.
66          * @exception   E_OUT_OF_MEMORY Insufficient memory.
67          */
68         result Construct(const Timer& timer, ITimerEventListener& listener);
69
70         /**
71          * Initializes the time instance.
72          *
73          * since 2.1
74          *
75          * @return              An error code
76          * @param[in]   listener        The event listener
77          * @param[in]   awake     Set to @c true, if the timer continues to run even if the system enters sleep mode
78          *                        @c false, if the timer stops running when the system enters sleep mode.
79          *
80          * @exception   E_SUCCESS               The method was successful.
81          * @exception   E_OUT_OF_MEMORY Insufficient memory.
82          *
83          * @exception E_PRIVILEGE_DENIED  The application does not have the privilege to call this method.
84          *
85          * @endif
86          */
87         result Construct(const Timer& timer, ITimerEventListener& listener, bool awake);
88
89         /**
90          * Starts the timer.
91          *
92          * @since 2.0
93          * @return              An error code
94          * @param[in]   timeout         A timeout interval in milliseconds
95          * @exception   E_SUCCESS               The method was successful.
96          * @exception   E_INVALID_ARG   A specified input parameter is invalid.
97          * @exception   E_INVALID_STATE The state of the timer is not a valid state. @n
98          The timer might be in the TIMER_STATUS_ACTIVATED state.
99          * @remark              Once it has been started, it cannot be started again until it expires. @n
100          *              You must cancel it if you want to re-start the timer.
101          * @see                         Cancel()
102          */
103         result Start(int timeout);
104
105
106         /**
107          * Cancels the timer.
108          *
109          * @since 2.0
110          * @return              An error code
111          * @exception   E_SUCCESS               The method was successful.
112          * @exception   E_INVALID_STATE The state of the timer is not a valid state. @n
113          The timer might be in the TIMER_STATUS_NOT_ACTIVATED state.
114          * @remark              The timer cannot be canceled if it is not started.
115          */
116         result Cancel(void);
117
118         /**
119          * Starts the timer. The timer is expired repeatedly until it is canceled.
120          *
121          * @since 2.0
122          * @return              An error code
123          * @param[in]   interval            A interval in milliseconds
124          * @exception   E_SUCCESS               The method was successful.
125          * @exception   E_SYSTEM                A system error has occurred.
126          * @exception   E_INVALID_ARG   A specified input parameter is invalid.
127          * @exception   E_INVALID_STATE The state of the timer is not a valid state. @n
128          *                                                              The timer might be in the TIMER_STATUS_ACTIVATED state.
129          * @see                         Cancel()
130          */
131         result StartAsRepeatable(int interval);
132
133 private:
134         static gboolean OnTimerExpired(GIOChannel* pGIOChannel, GIOCondition condition, gpointer data);
135
136 private:
137         Timer* __pTimer;
138         int __timerFd;
139         GIOChannel* __pTimerIo;
140         GSource* __pTimerSource;
141         ITimerEventListener* __pTimerEventListener;
142         TimerStatus __status;
143 };
144
145
146 } } } // Tizen::Base::Runtime
147
148
149 #endif // _FBASE_RT_INTERNAL_TIMER_IMPL_H_