d3eec30de2983bbde8446ab0dcd1bd679edc1208
[platform/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 <dpl/shared_ptr.h>
30 #include <dpl/noncopyable.h>
31 #include <wrt_plugin_export.h>
32 #include <Commons/JSObjectDeclaration.h>
33
34 class Plugin;
35 typedef DPL::SharedPtr<Plugin> PluginPtr;
36
37 class Plugin : private DPL::Noncopyable
38 {
39   public:
40     typedef JSObjectDeclaration Class;
41     typedef JSObjectDeclarationPtr ClassPtr;
42     typedef std::list<ClassPtr> ClassList;
43     typedef DPL::SharedPtr<ClassList> ClassPtrList;
44
45   private:
46     ///< Plug-in identifier. Currently plug-in file name is used as the ID
47     std::string m_fileName;
48
49     ///< Handle for the plug-in library. A plug-in is a dynamic loadable library
50     void* m_libHandle;
51
52     // Plugin API
53     on_widget_start_proc* m_apiOnWidgetStart;
54     on_widget_init_proc* m_apiOnWidgetInit;
55     on_widget_stop_proc* m_apiOnWidgetStop;
56     on_frame_load_proc* m_apiOnFrameLoad;
57     on_frame_unload_proc* m_apiOnFrameUnload;
58     const ClassPtrList m_apiClassList;
59
60     Plugin(const std::string &fileName,
61             void *libHandle,
62             on_widget_start_proc* apiOnWidgetStart,
63             on_widget_init_proc* apiOnWidgetInit,
64             on_widget_stop_proc* apiOnWidgetStop,
65             on_frame_load_proc* apiOnFrameLoad,
66             on_frame_unload_proc* apiOnFrameUnload,
67             const ClassPtrList &apiClassList);
68
69   public:
70     virtual ~Plugin();
71
72     // Loading
73     static PluginPtr LoadFromFile(const std::string &fileName);
74
75     // Filename
76     std::string GetFileName() const;
77
78     // API
79     void OnWidgetStart(int widgetId);
80
81     void OnWidgetInit(feature_mapping_interface_t *interface);
82
83     void OnWidgetStop(int widgetId);
84
85     void OnFrameLoad(java_script_context_t context);
86
87     void OnFrameUnload(java_script_context_t context);
88
89     const ClassPtrList GetClassList() const;
90 };
91
92 #endif // PLUGIN_H