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