62bd7e06fa83180905a4f73ffe3735e031135217
[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 {
34 class Main
35     : public WaitableHandleWatchSupport
36 {
37 public:
38     class Exception
39     {
40     public:
41         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
42         DECLARE_EXCEPTION_TYPE(Base, CreateFailed)
43     };
44
45 protected:
46     Ecore_Fd_Handler *m_invokerHandler;
47
48     static Eina_Bool StaticDispatchInvoker(void *data, Ecore_Fd_Handler *fd_handler);
49     static Eina_Bool StaticDispatchReadWatcher(void *data, Ecore_Fd_Handler *fd_handler);
50     static Eina_Bool StaticDispatchWriteWatcher(void *data, Ecore_Fd_Handler *fd_handler);
51
52     typedef std::list<Ecore_Fd_Handler *> EcoreFdHandlerList;
53
54     EcoreFdHandlerList m_readWatchersList;
55     EcoreFdHandlerList m_writeWatchersList;
56
57     void DispatchInvoker();
58     void DispatchReadWatcher(WaitableHandle waitableHandle);
59     void DispatchWriteWatcher(WaitableHandle waitableHandle);
60
61     void ReloadWatchList();
62
63     // WaitableHandleWatchSupport
64     virtual Thread *GetInvokerThread();
65     virtual void HandleDirectInvoker();
66
67 #ifdef DPL_ENABLE_GLIB_LOOP_INTEGRATION_WORKAROUND
68     // GLIB loop intergration workaround
69     typedef int (*EcoreSelectType)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
70     EcoreSelectType m_oldEcoreSelect;
71
72     static int EcoreSelectInterceptor(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
73 #endif // DPL_ENABLE_GLIB_LOOP_INTEGRATION_WORKAROUND
74
75 public:
76     explicit Main();
77     virtual ~Main();
78 };
79
80 /**
81  * Main singleton
82  */
83 typedef Singleton<Main> MainSingleton;
84 } // namespace DPL
85
86 #endif // DPL_MAIN_H