Source code formating unification
[framework/web/wrt-commons.git] / modules / core / include / dpl / main.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        main.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of main for EFL
21  */
22 #ifndef DPL_MAIN_H
23 #define DPL_MAIN_H
24
25 #include <dpl/waitable_handle_watch_support.h>
26 #include <dpl/exception.h>
27 #include <dpl/singleton.h>
28 #include <dpl/workaround.h>
29 #include <dpl/framework_efl.h>
30 #include <list>
31
32 namespace DPL {
33 class Main :
34     public WaitableHandleWatchSupport
35 {
36   public:
37     class Exception
38     {
39       public:
40         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
41         DECLARE_EXCEPTION_TYPE(Base, CreateFailed)
42     };
43
44   protected:
45     Ecore_Fd_Handler *m_invokerHandler;
46
47     static Eina_Bool StaticDispatchInvoker(void *data,
48                                            Ecore_Fd_Handler *fd_handler);
49     static Eina_Bool StaticDispatchReadWatcher(void *data,
50                                                Ecore_Fd_Handler *fd_handler);
51     static Eina_Bool StaticDispatchWriteWatcher(void *data,
52                                                 Ecore_Fd_Handler *fd_handler);
53
54     typedef std::list<Ecore_Fd_Handler *> EcoreFdHandlerList;
55
56     EcoreFdHandlerList m_readWatchersList;
57     EcoreFdHandlerList m_writeWatchersList;
58
59     void DispatchInvoker();
60     void DispatchReadWatcher(WaitableHandle waitableHandle);
61     void DispatchWriteWatcher(WaitableHandle waitableHandle);
62
63     void ReloadWatchList();
64
65     // WaitableHandleWatchSupport
66     virtual Thread *GetInvokerThread();
67     virtual void HandleDirectInvoker();
68
69 #ifdef DPL_ENABLE_GLIB_LOOP_INTEGRATION_WORKAROUND
70     // GLIB loop intergration workaround
71     typedef int (*EcoreSelectType)(int nfds, fd_set *readfds, fd_set *writefds,
72                                    fd_set *exceptfds, struct timeval *timeout);
73     EcoreSelectType m_oldEcoreSelect;
74
75     static int EcoreSelectInterceptor(int nfds,
76                                       fd_set *readfds,
77                                       fd_set *writefds,
78                                       fd_set *exceptfds,
79                                       struct timeval *timeout);
80 #endif // DPL_ENABLE_GLIB_LOOP_INTEGRATION_WORKAROUND
81
82   public:
83     explicit Main();
84     virtual ~Main();
85 };
86
87 /**
88  * Main singleton
89  */
90 typedef Singleton<Main> MainSingleton;
91 } // namespace DPL
92
93 #endif // DPL_MAIN_H