Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / Commons / ThreadPool.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  * ControllersFactory.h
18  *
19  *  Created on: 2010-06-28
20  *      Author: kmajewski
21  */
22
23 #ifndef WRTDEVICEAPIS_COMMONS_THREADPOOL_H_
24 #define WRTDEVICEAPIS_COMMONS_THREADPOOL_H_
25
26 #include <map>
27 #include <dpl/thread.h>
28 #include <dpl/event/main_event_dispatcher.h>
29 #include <dpl/event/thread_event_dispatcher.h>
30 #include <dpl/event/event_support.h>
31
32 namespace WrtDeviceApis {
33 namespace Commons {
34 class ThreadEnum
35 {
36   private:
37     ThreadEnum()
38     {}
39
40   public:
41     enum Enumeration
42     {
43         NULL_THREAD = 0,
44         CAMERA_THREAD,
45         CALENDAR_THREAD,
46         TELEPHONY_THREAD,
47         APPLAUNCHER_THREAD,
48         MESSAGING_THREAD,
49         FILESYSTEM_THREAD,
50         UI_THREAD,
51         APPCONFIG_THREAD,
52         GALLERY_THREAD,
53         CONTACT_THREAD,
54         BONDI_THREAD,
55         GEOLOCATION_THREAD,
56         DEVICESTATUS_THREAD,
57         PROFILE_THREAD,
58         HAPTICS_THREAD,
59         ACCELEROMETER_THREAD,
60         ORIENTATION_THREAD,
61         TASK_THREAD,
62         POWER_THREAD,
63         PLUGIN_TEMPLETE_THREAD,
64         BLUETOOTH_THREAD,
65         APPLICATION_THREAD,
66         GYROSCOPE_THREAD,
67         CLOCK_THREAD,
68         SYSTEMINFO_THREAD,
69         CALLHISTORY_THREAD,
70         ACCOUNT_THREAD,
71         NFC_THREAD,
72         MEDIACONTENT_THREAD,
73         SE_THREAD,
74         DOWNLOAD_THREAD,
75         PUSH_THREAD,
76         SYNC_THREAD,
77         //....
78         size
79     };
80 };
81
82 class ThreadPool : private DPL::Noncopyable
83 {
84   private:
85     typedef std::map<ThreadEnum::Enumeration, DPL::Thread*> ThreadHandleMap;
86     ThreadHandleMap m_threadHandlers;
87     DPL::Mutex m_threadHandlersMutex;
88
89     DPL::Thread *getThreadHandleCreateIfNotExists(ThreadEnum::Enumeration type);
90
91     //DPL::MainEventDispatcher m_mainEventDispatcher;
92
93     ThreadPool();
94
95   public:
96     ~ThreadPool();
97
98     /*
99      * @throws:  WrtDeviceApis::Commons::InvalidArgumentException
100      */
101     DPL::Thread * getThreadRef(ThreadEnum::Enumeration type);
102
103     /*
104      * Get proper dispatcher for current calling thread
105      */
106     DPL::Event::AbstractEventDispatcher *getDispatcher(
107         DPL::Event::ThreadEventDispatcher &callingThreadDispatcher);
108
109     static ThreadPool& getInstance();
110 };
111 }
112 } // WrtDeviceApisCommon
113
114 #endif // WRTDEVICEAPIS_COMMONS_THREADPOOL_H_