6a27a7cdc5a3b12fbe6872c9ed6855324985dc78
[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         //....
76         size
77     };
78 };
79
80
81 class ThreadPool : private DPL::Noncopyable
82 {
83   private:
84     typedef std::map<ThreadEnum::Enumeration, DPL::Thread*> ThreadHandleMap;
85     ThreadHandleMap m_threadHandlers;
86     DPL::Mutex m_threadHandlersMutex;
87
88     DPL::Thread *getThreadHandleCreateIfNotExists(ThreadEnum::Enumeration type);
89
90     //DPL::MainEventDispatcher m_mainEventDispatcher;
91
92     ThreadPool();
93   public:
94     ~ThreadPool();
95
96     /*
97      * @throws:  WrtDeviceApis::Commons::InvalidArgumentException
98      */
99     DPL::Thread * getThreadRef(ThreadEnum::Enumeration type);
100
101     /*
102      * Get proper dispatcher for current calling thread
103      */
104     DPL::Event::AbstractEventDispatcher *getDispatcher(
105             DPL::Event::ThreadEventDispatcher &callingThreadDispatcher);
106
107     static ThreadPool& getInstance();
108 };
109
110 }
111 } // WrtDeviceApisCommon
112
113 #endif // WRTDEVICEAPIS_COMMONS_THREADPOOL_H_