sync
[platform/framework/web/wrt-plugins-common.git] / src / plugins-api-support / ExportedApi.h
1 /*
2  * Copyright (c) 2012 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  *
18  * @file       ExportedApi.h
19  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23 #ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_EXPORTED_API_H_
24 #define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_EXPORTED_API_H_
25
26 #include <PluginRegistration.h>
27
28 /**
29  * This file provides definition of entry point to the plugin's shared library
30  * used by wrt.
31  *
32  * Each plugin have to provide 1 symbol which is get by dlsym.
33  * The name of required symbol is specified by 'GetExportedSymbolName' function
34  * The type of this symbol is pointer to ExportedApi struct
35  *
36  * To allow access to your plugin, you have to:
37  *
38  * 1)define 3 functions:
39  *  - Register,
40  *  - Unregister,
41  *  - GetProvidedFeatures
42  *  (names are not important)
43  *
44  * 2)define global struct named "dll_api" and initialize it with above functions
45  *   *Example:
46  *    ExportedApi dll_api = {Register, Unregister, GetProvidedFeatures};
47  *
48  *
49  * Detailed Example how the file with api may looks like file:
50  *
51     #include <Commons/Exception.h>
52     #include <Commons/WrtAccess/WrtAccess.h>
53
54     #include <Plugin.h>
55     #include <ObjectFactory.h>
56     #include <PluginRegistration.h>
57     #include <ExportedApi.h>
58
59     #include "JSTest.h"
60     #include "plugin_config.h"
61
62     #define OBJECT_WIDGET "widget"
63     #define OBJECT_TEST "__test"
64
65     using namespace WrtPlugins::W3C;
66     using namespace WrtDeviceApis;
67     using namespace WrtDeviceApis::Commons;
68     using namespace WrtPluginsApi;
69
70     namespace W3CTest
71     {
72
73     void on_widget_start_callback(int widgetId)
74     {
75
76     }
77
78     void on_widget_stop_callback(int widgetId)
79     {
80     }
81
82     }
83
84     void Register(PluginRegistration& r)
85     {
86         Plugin* plugin = new Plugin();
87
88         auto test = ObjectFactory::createMainObject(
89                             OBJECT_TEST,
90                             WrtPlugins::W3C::JSTest::getClassRef,
91                             OBJECT_WIDGET);
92
93         plugin->AddObject(test);
94
95         r.Connect<OnWidgetStart>(W3CTest::on_widget_start_callback);
96
97         r.Connect<OnWidgetStop>(W3CTest::on_widget_stop_callback);
98
99         r.AddPlugin(*plugin);
100     }
101
102     void Unregister(PluginRegistration& r, Plugin* plugin)
103     {
104         r.DisconnectAll();
105         delete plugin;
106     }
107
108     void GetProvidedFeatures(feature_mapping_interface_t *mapping)
109     {
110         WrtPlugins::W3C::WidgetTestDeclarations::getMappingInterface(mapping);
111     }
112
113     ExportedApi dll_api={Register, Unregister, GetProvidedFeatures};
114
115     #undef OBJECT_WIDGET
116     #undef OBJECT_TEST
117  *
118  *
119  * */
120
121 //forward declaration
122 struct feature_mapping_interface_s;
123 typedef struct feature_mapping_interface_s feature_mapping_interface_t;
124
125 class WrtPluginsApi::Plugin;
126
127 extern "C" struct ExportedApi
128 {
129     /*
130      * This function is invoked when library is loaded
131      * */
132     void (*Register)(WrtPluginsApi::PluginRegistration&);
133
134     /*
135      * This function is invoked when library is unloaded
136      * */
137     void (*Unregister)(WrtPluginsApi::PluginRegistration&,
138                        WrtPluginsApi::Plugin* plugin);
139
140     /*
141      * This function is invoked by wrt-plugins-installer to obtain
142      * info about features,functions,objects provided by plugin
143      * */
144     void (*GetProvidedFeatures)(feature_mapping_interface_t*);
145 };
146
147
148 constexpr const char* GetExportedSymbolName()
149 {
150     return "dll_api";
151 }
152
153 #endif