Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / 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 #include <dpl/mutex.h>
32
33 namespace WrtDeviceApis {
34 namespace Commons {
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         BONDI_THREAD,
56         GEOLOCATION_THREAD,
57         DEVICESTATUS_THREAD,
58         PROFILE_THREAD,
59         HAPTICS_THREAD,
60         ACCELEROMETER_THREAD,
61         ORIENTATION_THREAD,
62         TASK_THREAD,
63         POWER_THREAD,
64         PLUGIN_TEMPLETE_THREAD,
65         BLUETOOTH_THREAD,
66         APPLICATION_THREAD,
67         GYROSCOPE_THREAD,
68         CLOCK_THREAD,
69         SYSTEMINFO_THREAD,
70         CALLHISTORY_THREAD,
71         ACCOUNT_THREAD,
72         NFC_THREAD,
73         MEDIACONTENT_THREAD,
74         SE_THREAD,
75         DOWNLOAD_THREAD,
76         PUSH_THREAD,
77         SYNC_THREAD,
78         //....
79         size
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
96   public:
97     ~ThreadPool();
98
99     /*
100      * @throws:  WrtDeviceApis::Commons::InvalidArgumentException
101      */
102     DPL::Thread * getThreadRef(ThreadEnum::Enumeration type);
103
104     /*
105      * Get proper dispatcher for current calling thread
106      */
107     DPL::Event::AbstractEventDispatcher *getDispatcher(
108         DPL::Event::ThreadEventDispatcher &callingThreadDispatcher);
109
110     static ThreadPool& getInstance();
111 };
112 }
113 } // WrtDeviceApisCommon
114
115 #endif // WRTDEVICEAPIS_COMMONS_THREADPOOL_H_