tizen 2.4 release
[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  * #include <dpl/wrt-dao-ro/wrt_db_types.h>
63  *
64  * #define OBJECT_WIDGET "widget"
65  * #define OBJECT_TEST "__test"
66  *
67  *  using namespace WrtPlugins::W3C;
68  *  using namespace WrtDeviceApis;
69  *  using namespace WrtDeviceApis::Commons;
70  *  using namespace WrtPluginsApi;
71  *
72  *  namespace W3CTest
73  *  {
74  *
75  *  void on_widget_start_callback(WidgetHandle widgetId)
76  *  {
77  *
78  *  }
79  *
80  *  void on_widget_stop_callback(WidgetHandle widgetId)
81  *  {
82  *  }
83  *
84  *  }
85  *
86  *  void Register(PluginRegistration& r)
87  *  {
88  *      Plugin* plugin = new Plugin();
89  *
90  *      auto test = ObjectFactory::createMainObject(
91  *                          OBJECT_TEST,
92  *                          WrtPlugins::W3C::JSTest::getClassRef,
93  *                          OBJECT_WIDGET);
94  *
95  *      plugin->AddObject(test);
96  *
97  *      r.Connect<OnWidgetStart>(W3CTest::on_widget_start_callback);
98  *
99  *      r.Connect<OnWidgetStop>(W3CTest::on_widget_stop_callback);
100  *
101  *      r.AddPlugin(*plugin);
102  *  }
103  *
104  *  void Unregister(PluginRegistration& r, Plugin* plugin)
105  *  {
106  *      r.DisconnectAll();
107  *      delete plugin;
108  *  }
109  *
110  *  void GetProvidedFeatures(feature_mapping_interface_t *mapping)
111  *  {
112  *      WrtPlugins::W3C::WidgetTestDeclarations::getMappingInterface(mapping);
113  *  }
114  *
115  *  ExportedApi dll_api={Register, Unregister, GetProvidedFeatures};
116  *
117  * #undef OBJECT_WIDGET
118  * #undef OBJECT_TEST
119  *
120  *
121  * */
122
123 //forward declaration
124 struct feature_mapping_interface_s;
125 typedef struct feature_mapping_interface_s feature_mapping_interface_t;
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 constexpr const char* GetExportedSymbolName()
148 {
149     return "dll_api";
150 }
151
152 #endif