tizen beta release
[framework/web/wrt-plugins-common.git] / src / Commons / WrtWrapper / WrtWrappersMgr.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  * @author      Grzegorz Krawczyk
18  * @version     0.1
19  * @brief       This file provide factory to create wrapper for api from wrt
20  */
21
22 #ifndef WRT_PLUGINS_WRT_WRAPPERS_MGR_INTERFACE_H_
23 #define WRT_PLUGINS_WRT_WRAPPERS_MGR_INTERFACE_H_
24
25 #include <map>
26 #include <dpl/noncopyable.h>
27 #include <Commons/plugin_initializer_def.h>
28 #include <Commons/WrtWrapper/IWrtWrapper.h>
29
30 namespace WrtDeviceApis {
31 namespace Commons {
32
33 class WrtWrappersMgr : private DPL::Noncopyable
34 {
35     typedef std::map<JavaScriptContext, IWrtWrapperPtr> RegisteredWrappers;
36     typedef RegisteredWrappers::iterator RegisteredWrappersIterator;
37     typedef RegisteredWrappers::const_iterator RegisteredWrappersConstIterator;
38
39   public:
40
41     static WrtWrappersMgr& getInstance();
42
43     /*
44      * creates wrt wrappers for widgetId
45      * @throw Exception::Exception if creation fail
46      * @throw Exception::InvalidArgumentException if arguments are wrong
47      * if Wrapper exist
48      * */
49     virtual IWrtWrapperPtr registerWrapper(int widgetId,
50             JavaScriptContext context,
51             const engine_interface_t* interface);
52
53     /*
54      * removes previously created wrapper
55      * @throw Exception::InvalidArgumentException if creation fail
56      * if widget is not registered
57      * */
58     virtual void removeWrapper(int widgetId);
59
60     /*
61      * removes previously created wrapper
62      * @throw Exception::InvalidArgumentException if creation fail
63      * if widget is not registered
64      * */
65     virtual void removeWrapper(JavaScriptContext context);
66
67     /*
68      * a get previously created wrapper
69      * @throw Exception::InvalidArgumentException if creation fail
70      *  if wrapper is not registered
71      * */
72     virtual IWrtWrapperPtr getWrtWrapper(const JavaScriptContext context) const;
73
74     virtual bool isWrapperRegistered(JavaScriptContext context) const;
75
76     virtual ~WrtWrappersMgr();
77
78   private:
79     WrtWrappersMgr();
80
81     IWrtWrapperPtr getWrapper(const JavaScriptContext context) const;
82
83     void addWrapper(JavaScriptContext context,
84             IWrtWrapperPtr wrapper);
85
86     RegisteredWrappers m_wrappers;
87 };
88
89 }
90 } // WrtDeviceApisCommon
91
92 #endif