tizen 2.4 release
[framework/web/wrt-plugins-common.git] / src / plugin-loading / plugin.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  * @file        plugin.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of plugin
21  */
22 #ifndef WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_
23 #define WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_
24
25 #include <list>
26 #include <map>
27 #include <string>
28 #include <dpl/atomic.h>
29 #include <memory>
30 #include <dpl/noncopyable.h>
31 #include <wrt_plugin_export.h>
32 #include <Commons/JSObjectDeclaration.h>
33 #include <dpl/wrt-dao-ro/wrt_db_types.h>
34
35 class Plugin;
36 typedef std::shared_ptr<Plugin> PluginPtr;
37
38 class Plugin : private DPL::Noncopyable
39 {
40   public:
41     typedef JSObjectDeclaration Class;
42     typedef JSObjectDeclarationPtr ClassPtr;
43     typedef std::list<ClassPtr> ClassList;
44     typedef std::shared_ptr<ClassList> ClassPtrList;
45
46   private:
47     ///< Plug-in identifier. Currently plug-in file name is used as the ID
48     std::string m_fileName;
49
50     ///< Handle for the plug-in library. A plug-in is a dynamic loadable library
51     void* m_libHandle;
52
53     // Plugin API
54     on_widget_start_proc* m_apiOnWidgetStart;
55     on_widget_init_proc* m_apiOnWidgetInit;
56     on_widget_stop_proc* m_apiOnWidgetStop;
57     on_frame_load_proc* m_apiOnFrameLoad;
58     on_frame_unload_proc* m_apiOnFrameUnload;
59     const ClassPtrList m_apiClassList;
60
61     Plugin(const std::string &fileName,
62            void *libHandle,
63            on_widget_start_proc* apiOnWidgetStart,
64            on_widget_init_proc* apiOnWidgetInit,
65            on_widget_stop_proc* apiOnWidgetStop,
66            on_frame_load_proc* apiOnFrameLoad,
67            on_frame_unload_proc* apiOnFrameUnload,
68            const ClassPtrList &apiClassList);
69
70   public:
71     virtual ~Plugin();
72
73     // Loading
74     static PluginPtr LoadFromFile(const std::string &fileName);
75
76     // Filename
77     std::string GetFileName() const;
78
79     // API
80     void OnWidgetStart(WidgetHandle widgetId);
81
82     void OnWidgetInit(feature_mapping_interface_t *interface);
83
84     void OnWidgetStop(WidgetHandle widgetId);
85
86     void OnFrameLoad(java_script_context_t context);
87
88     void OnFrameUnload(java_script_context_t context);
89
90     const ClassPtrList GetClassList() const;
91 };
92
93 #endif // PLUGIN_H