Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / 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
35 class ThreadEnum
36 {
37   private:
38     ThreadEnum()
39     {
40     }
41   public:
42     enum Enumeration
43     {
44         NULL_THREAD = 0,
45         CAMERA_THREAD,
46         CALENDAR_THREAD,
47         TELEPHONY_THREAD,
48         APPLAUNCHER_THREAD,
49         MESSAGING_THREAD,
50         FILESYSTEM_THREAD,
51         UI_THREAD,
52         APPCONFIG_THREAD,
53         GALLERY_THREAD,
54         CONTACT_THREAD,
55         MMPLAYER_THREAD,
56         BONDI_THREAD,
57         GEOLOCATION_THREAD,
58         DEVICESTATUS_THREAD,
59         PROFILE_THREAD,
60         HAPTICS_THREAD,
61         ACCELEROMETER_THREAD,
62         ORIENTATION_THREAD,
63         TASK_THREAD,
64         POWER_THREAD,
65         PLUGIN_TEMPLETE_THREAD,
66         BLUETOOTH_THREAD,
67         APPLICATION_THREAD,
68         GYROSCOPE_THREAD,
69         CLOCK_THREAD,
70         SYSTEMINFO_THREAD,
71         CALLHISTORY_THREAD,
72         ACCOUNT_THREAD,
73         NFC_THREAD,
74         MEDIACONTENT_THREAD,
75         SE_THREAD,
76         DOWNLOAD_THREAD,
77         //....
78         size
79     };
80 };
81
82
83 class ThreadPool : private DPL::Noncopyable
84 {
85   private:
86     typedef std::map<ThreadEnum::Enumeration, DPL::Thread*> ThreadHandleMap;
87     ThreadHandleMap m_threadHandlers;
88     DPL::Mutex m_threadHandlersMutex;
89
90     DPL::Thread *getThreadHandleCreateIfNotExists(ThreadEnum::Enumeration type);
91
92     //DPL::MainEventDispatcher m_mainEventDispatcher;
93
94     ThreadPool();
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 }
113 } // WrtDeviceApisCommon
114
115 #endif // WRTDEVICEAPIS_COMMONS_THREADPOOL_H_