Beautified source code of appfw/src/base/inc
[platform/framework/native/appfw.git] / src / base / inc / FBaseRt_EventDispatcher.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_EventDispatcher.h
19  * @brief       This is the header file for the %_EventDispatcher class.
20  *
21  * This file contains the declarations of the %_EventDispatcher class.
22  */
23 #ifndef _FBASE_RT_INTERNAL_EVENT_DISPATCHER_H_
24 #define _FBASE_RT_INTERNAL_EVENT_DISPATCHER_H_
25
26 #include <glib.h>
27
28 #include <FBaseResult.h>
29 #include <FBaseObject.h>
30 #include <FBaseColLinkedListT.h>
31
32 namespace Tizen { namespace Base { namespace Runtime
33 {
34
35 class _ITask;
36 class Mutex;
37
38 /**
39 * @class   _EventDispatcher
40 * @brief   This class provides methods for _EventDispatcher.
41 * @since 2.0
42 *
43 * This class provides methods for asynchronous operation.
44 */
45 class _OSP_EXPORT_ _EventDispatcher
46         : public Tizen::Base::Object
47 {
48 public:
49         /**
50          *      This is the default constructor for this class.
51          *      value.
52          *
53          *      @since 2.0
54          */
55         _EventDispatcher(void);
56
57         /**
58          * This is the destructor for this class
59          * @since 2.0
60          */
61         virtual ~_EventDispatcher(void);
62
63         /**
64          * Initializes this instanc of %_EventDispatcher.
65          *
66          * @since 2.0
67          * @return              An error code
68          * @param[in]   pGMainContext   A GMainLoopContext
69          * @exception   E_SUCCESS       The method was successful.
70          * @exception   E_SYSTEM        An unknown operating system error occurred.
71          */
72         result Construct(GMainContext* pGMainContext);
73
74         /**
75          * Returns an %_EventDispatcher of current thread.
76          *
77          * @since 2.0
78          * @return              The pointer of _EventDispatcher
79          */
80         static _EventDispatcher* GetCurrentEventDispatcher(void);
81
82         /**
83          * Add an asynchronous task to an %_EventDispatcher.
84          *
85          * @since 2.0
86          * @return              An error code
87          * @param[in]   pITask  An _ITask to send
88          * @param[in]   pParam  A param
89          * @exception   E_SUCCESS       The method was successful.
90          */
91         result PutTask(_ITask* pITask, void* pParam);
92
93         /**
94          * Returns the GMainContext
95          *
96          * @since 2.0
97          * @return              The pointer of GMainContext
98          */
99         GMainContext* GetGMainContext(void);
100
101 private:
102         /**
103          * Handles incoming events
104          */
105         static gboolean OnEventReceived(GIOChannel* pGIOChannel, GIOCondition condition, gpointer data);
106
107         _EventDispatcher(const _EventDispatcher& rhs);
108
109         _EventDispatcher& operator =(const _EventDispatcher& rhs);
110
111 private:
112         struct _EventMessage
113         {
114                 _ITask* pITask;
115                 void* pParam;
116         };
117
118 private:
119         Mutex* __pMutex;
120         Tizen::Base::Collection::LinkedListT< _EventMessage* > __events;
121         GMainContext* __pGMainContext;
122         GIOChannel* __pEventFdIo;
123         GSource* __pEventFdSource;
124 }; // _EventDispatcher
125 }}} // Tizen::Base::Runtime
126 #endif // _FBASE_RT_INTERNAL_EVENT_DISPATCHER_H_