summaryrefslogtreecommitdiff
path: root/src/plugins-api-support
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins-api-support')
-rw-r--r--src/plugins-api-support/CMakeLists.txt73
-rw-r--r--src/plugins-api-support/CallbackSupport.h82
-rw-r--r--src/plugins-api-support/ExportedApi.h152
-rw-r--r--src/plugins-api-support/IObject.h70
-rw-r--r--src/plugins-api-support/IObject_cast.h35
-rw-r--r--src/plugins-api-support/Object.cpp130
-rw-r--r--src/plugins-api-support/Object.h104
-rw-r--r--src/plugins-api-support/ObjectFactory.cpp61
-rw-r--r--src/plugins-api-support/ObjectFactory.h50
-rw-r--r--src/plugins-api-support/Plugin.cpp40
-rw-r--r--src/plugins-api-support/Plugin.h45
-rw-r--r--src/plugins-api-support/PluginRegistration.cpp57
-rw-r--r--src/plugins-api-support/PluginRegistration.h48
-rw-r--r--src/plugins-api-support/PluginRegistrationImpl.h60
-rw-r--r--src/plugins-api-support/PluginRegistry.cpp169
-rw-r--r--src/plugins-api-support/PluginRegistry.h80
-rw-r--r--src/plugins-api-support/PluginSignals.h36
-rw-r--r--src/plugins-api-support/SignalSignature.h37
-rw-r--r--src/plugins-api-support/SignalsSupport.h98
-rw-r--r--src/plugins-api-support/detail/traits.h76
-rw-r--r--src/plugins-api-support/js_types.h41
-rw-r--r--src/plugins-api-support/traits.h41
-rw-r--r--src/plugins-api-support/tuple.h37
23 files changed, 1622 insertions, 0 deletions
diff --git a/src/plugins-api-support/CMakeLists.txt b/src/plugins-api-support/CMakeLists.txt
new file mode 100644
index 0000000..5a8f7c5
--- /dev/null
+++ b/src/plugins-api-support/CMakeLists.txt
@@ -0,0 +1,73 @@
+# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# @file CMakeLists.txt
+# @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+# @version 1.0
+#
+
+PKG_SEARCH_MODULE(dpl REQUIRED dpl-efl)
+
+SET(PLUGINS_API_SUPPORT_SOURCES
+ ${CMAKE_CURRENT_SOURCE_DIR}/Plugin.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Object.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/ObjectFactory.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/PluginRegistration.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/PluginRegistry.cpp
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${dpl_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_PLUGINS_API_SUPPORT} SHARED
+ ${PLUGINS_API_SUPPORT_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_API_SUPPORT} PROPERTIES
+ COMPILE_DEFINITIONS LOG_TAG="${LOG_TAG}")
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGIN_API_SUPPORT} PROPERTIES
+ COMPILE_FLAGS -fPIC
+ LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_API_SUPPORT} PROPERTIES
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_PLUGINS_API_SUPPORT}
+ ${dpl_LIBRARIES}
+)
+
+INSTALL(TARGETS ${TARGET_PLUGINS_API_SUPPORT}
+ DESTINATION lib
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+)
+
+INSTALL(FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/ExportedApi.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/Plugin.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/IObject.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/ObjectFactory.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/CallbackSupport.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/tuple.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/PluginSignals.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/SignalSignature.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/PluginRegistration.h
+ DESTINATION include/wrt-plugins-api-support)
diff --git a/src/plugins-api-support/CallbackSupport.h b/src/plugins-api-support/CallbackSupport.h
new file mode 100644
index 0000000..bcaa849
--- /dev/null
+++ b/src/plugins-api-support/CallbackSupport.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file CallbackSupport.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_CALLBACK_SUPPORT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_CALLBACK_SUPPORT_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <dpl/foreach.h>
+
+namespace WrtPluginsApi {
+template<typename Sig>
+class CallbackSupport
+{
+ public:
+ typedef typename Sig::Signature SlotSignature;
+ typedef typename Sig::Type SlotType;
+ typedef std::string GroupType;
+ typedef std::vector<SlotType> SlotList;
+
+ void Connect(const GroupType& group, const SlotType& slot)
+ {
+ auto groupIt = m_slots.find(group);
+ if (m_slots.end() == groupIt) {
+ groupIt = m_slots.insert(std::make_pair(group, SlotList())).first;
+ }
+ groupIt->second.push_back(slot);
+ }
+
+ void Disconnect(const GroupType& group)
+ {
+ m_slots.erase(group);
+ }
+
+ template<typename ... Args>
+ void Invoke(const Args& ... args)
+ {
+ FOREACH(groupIt, m_slots)
+ {
+ FOREACH(slotIt, groupIt->second)
+ {
+ (*slotIt)(args ...);
+ }
+ }
+ }
+
+ template<typename ... Args>
+ void InvokeGroup(const GroupType& group, const Args& ... args)
+ {
+ auto groupIt = m_slots.find(group);
+
+ if (m_slots.end() != groupIt) {
+ FOREACH(slotIt, groupIt->second)
+ {
+ (*slotIt)(args ...);
+ }
+ }
+ }
+
+ private:
+ std::map<GroupType, SlotList> m_slots;
+};
+}
+#endif
diff --git a/src/plugins-api-support/ExportedApi.h b/src/plugins-api-support/ExportedApi.h
new file mode 100644
index 0000000..4a71d95
--- /dev/null
+++ b/src/plugins-api-support/ExportedApi.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *
+ * @file ExportedApi.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_EXPORTED_API_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_EXPORTED_API_H_
+
+#include <PluginRegistration.h>
+
+/**
+ * This file provides definition of entry point to the plugin's shared library
+ * used by wrt.
+ *
+ * Each plugin have to provide 1 symbol which is get by dlsym.
+ * The name of required symbol is specified by 'GetExportedSymbolName' function
+ * The type of this symbol is pointer to ExportedApi struct
+ *
+ * To allow access to your plugin, you have to:
+ *
+ * 1)define 3 functions:
+ * - Register,
+ * - Unregister,
+ * - GetProvidedFeatures
+ * (names are not important)
+ *
+ * 2)define global struct named "dll_api" and initialize it with above functions
+ * *Example:
+ * ExportedApi dll_api = {Register, Unregister, GetProvidedFeatures};
+ *
+ *
+ * Detailed Example how the file with api may looks like file:
+ *
+ * #include <Commons/Exception.h>
+ * #include <Commons/WrtAccess/WrtAccess.h>
+ *
+ * #include <Plugin.h>
+ * #include <ObjectFactory.h>
+ * #include <PluginRegistration.h>
+ * #include <ExportedApi.h>
+ *
+ * #include "JSTest.h"
+ * #include "plugin_config.h"
+ *
+ * #include <dpl/wrt-dao-ro/wrt_db_types.h>
+ *
+ * #define OBJECT_WIDGET "widget"
+ * #define OBJECT_TEST "__test"
+ *
+ * using namespace WrtPlugins::W3C;
+ * using namespace WrtDeviceApis;
+ * using namespace WrtDeviceApis::Commons;
+ * using namespace WrtPluginsApi;
+ *
+ * namespace W3CTest
+ * {
+ *
+ * void on_widget_start_callback(WidgetHandle widgetId)
+ * {
+ *
+ * }
+ *
+ * void on_widget_stop_callback(WidgetHandle widgetId)
+ * {
+ * }
+ *
+ * }
+ *
+ * void Register(PluginRegistration& r)
+ * {
+ * Plugin* plugin = new Plugin();
+ *
+ * auto test = ObjectFactory::createMainObject(
+ * OBJECT_TEST,
+ * WrtPlugins::W3C::JSTest::getClassRef,
+ * OBJECT_WIDGET);
+ *
+ * plugin->AddObject(test);
+ *
+ * r.Connect<OnWidgetStart>(W3CTest::on_widget_start_callback);
+ *
+ * r.Connect<OnWidgetStop>(W3CTest::on_widget_stop_callback);
+ *
+ * r.AddPlugin(*plugin);
+ * }
+ *
+ * void Unregister(PluginRegistration& r, Plugin* plugin)
+ * {
+ * r.DisconnectAll();
+ * delete plugin;
+ * }
+ *
+ * void GetProvidedFeatures(feature_mapping_interface_t *mapping)
+ * {
+ * WrtPlugins::W3C::WidgetTestDeclarations::getMappingInterface(mapping);
+ * }
+ *
+ * ExportedApi dll_api={Register, Unregister, GetProvidedFeatures};
+ *
+ * #undef OBJECT_WIDGET
+ * #undef OBJECT_TEST
+ *
+ *
+ * */
+
+//forward declaration
+struct feature_mapping_interface_s;
+typedef struct feature_mapping_interface_s feature_mapping_interface_t;
+
+extern "C" struct ExportedApi
+{
+ /*
+ * This function is invoked when library is loaded
+ * */
+ void (*Register)(WrtPluginsApi::PluginRegistration&);
+
+ /*
+ * This function is invoked when library is unloaded
+ * */
+ void (*Unregister)(WrtPluginsApi::PluginRegistration&,
+ WrtPluginsApi::Plugin* plugin);
+
+ /*
+ * This function is invoked by wrt-plugins-installer to obtain
+ * info about features,functions,objects provided by plugin
+ * */
+ void (*GetProvidedFeatures)(feature_mapping_interface_t*);
+};
+
+constexpr const char* GetExportedSymbolName()
+{
+ return "dll_api";
+}
+
+#endif
diff --git a/src/plugins-api-support/IObject.h b/src/plugins-api-support/IObject.h
new file mode 100644
index 0000000..4148d91
--- /dev/null
+++ b/src/plugins-api-support/IObject.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file IObject.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_IOBJECT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_IOBJECT_H_
+
+#include <memory>
+#include <list>
+
+extern "C" {
+typedef struct OpaqueJSClass* (*ClassRef)();
+}
+
+namespace WrtPluginsApi {
+enum class IObjectType
+{
+ Object,
+ Function,
+ Interface,
+ InterfaceInstance
+};
+
+enum class IObjectOption
+{
+ Overlayed
+};
+
+class IObject;
+typedef std::shared_ptr<IObject> IObjectPtr;
+
+class IObject
+{
+ public:
+ constexpr static const char* WINDOW_OBJECT()
+ {
+ return "window";
+ }
+
+ virtual void AddChild(const IObjectPtr&) = 0;
+
+ /*
+ * Optional
+ * */
+ virtual void setBoolOption(IObjectOption option, bool value) = 0;
+
+ virtual ~IObject(){}
+};
+
+typedef std::list<IObjectPtr> IObjectsList;
+typedef std::shared_ptr<IObjectsList> IObjectsListPtr;
+}
+#endif
diff --git a/src/plugins-api-support/IObject_cast.h b/src/plugins-api-support/IObject_cast.h
new file mode 100644
index 0000000..105a31d
--- /dev/null
+++ b/src/plugins-api-support/IObject_cast.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file IObject_cast.h
+ * @author
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGINS_API_SUPPORT_CAST_H_
+#define _WRT_PLUGINS_COMMON_PLUGINS_API_SUPPORT_CAST_H_
+
+#include <memory>
+#include <IObject.h>
+#include <Object.h>
+
+namespace WrtPluginsApi {
+inline ObjectPtr CAST(const IObjectPtr& object)
+{
+ return std::dynamic_pointer_cast<Object>(object);
+}
+}
+#endif
diff --git a/src/plugins-api-support/Object.cpp b/src/plugins-api-support/Object.cpp
new file mode 100644
index 0000000..7db93e4
--- /dev/null
+++ b/src/plugins-api-support/Object.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file Object.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include "Object.h"
+
+namespace WrtPluginsApi {
+void Object::AddChild(const IObjectPtr& child)
+{
+ if (!m_children) {
+ m_children = IObjectsListPtr(new IObjectsList);
+ }
+ m_children->push_back(child);
+}
+
+void Object::setBoolOption(IObjectOption option, bool value)
+{
+ if (!m_options) {
+ m_options = ObjectOptionPtr(new ObjectOption);
+ }
+
+ switch (option) {
+ case IObjectOption::Overlayed:
+ m_options->overlayedMode = value;
+ break;
+ default:
+ break;
+ }
+}
+
+IObjectsListPtr Object::GetChildren() const
+{
+ return m_children;
+}
+
+ClassRef Object::GetClass() const
+{
+ return m_classRef;
+}
+
+ClassRef Object::GetClassConstructor() const
+{
+ return m_constructorRef;
+}
+
+const char* Object::GetInterfaceName() const
+{
+ return m_interfaceName;
+}
+
+const char* Object::GetName() const
+{
+ return m_name;
+}
+
+IObjectType Object::GetType() const
+{
+ return m_type;
+}
+
+const char* Object::GetParentName() const
+{
+ return m_parentName;
+}
+
+ObjectOptionPtr Object::GetOptions() const
+{
+ return m_options;
+}
+
+Object::Object(const char* name,
+ ClassRef ref,
+ IObjectType type) :
+ m_name(name),
+ m_classRef(ref),
+ m_parentName(0),
+ m_type(type),
+ m_interfaceRef(0),
+ m_interfaceName(0),
+ m_constructorRef(0)
+{}
+
+Object::Object(const char* name,
+ ClassRef ref,
+ const char* parentName,
+ IObjectType type) :
+ m_name(name),
+ m_classRef(ref),
+ m_parentName(parentName),
+ m_type(type),
+ m_interfaceRef(0),
+ m_interfaceName(0),
+ m_constructorRef(0)
+{}
+
+Object::Object(const char* name,
+ ClassRef interfaceRef,
+ const char* interfaceName,
+ ClassRef constructorRef,
+ const char* parentName,
+ IObjectType type) :
+ m_name(name),
+ m_parentName(parentName),
+ m_type(type),
+ m_interfaceRef(interfaceRef),
+ m_interfaceName(interfaceName),
+ m_constructorRef(constructorRef)
+{}
+
+Object::~Object()
+{}
+}
diff --git a/src/plugins-api-support/Object.h b/src/plugins-api-support/Object.h
new file mode 100644
index 0000000..268a27f
--- /dev/null
+++ b/src/plugins-api-support/Object.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file IObject.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_H_
+
+#include <memory>
+#include <list>
+
+#include <IObject.h>
+#include <dpl/optional_typedefs.h>
+
+namespace WrtPluginsApi {
+class Object;
+typedef std::shared_ptr<Object> ObjectPtr;
+
+struct ObjectOption
+{
+ DPL::OptionalBool overlayedMode;
+};
+typedef std::shared_ptr<ObjectOption> ObjectOptionPtr;
+
+class Object : public IObject
+{
+ public:
+ Object(const char* name,
+ ClassRef ref,
+ IObjectType type = IObjectType::Object);
+
+ Object(const char* name,
+ ClassRef ref,
+ const char* parentName = IObject::WINDOW_OBJECT(),
+ IObjectType type = IObjectType::Object);
+
+ Object(const char* name,
+ ClassRef interfaceRef,
+ const char* interfaceName,
+ ClassRef constructorRef,
+ const char* parentName = IObject::WINDOW_OBJECT(),
+ IObjectType type = IObjectType::Object);
+
+ ~Object();
+
+ void AddChild(const IObjectPtr&);
+
+ void setBoolOption(IObjectOption option, bool value);
+
+ IObjectsListPtr GetChildren() const;
+
+ ClassRef GetClass() const;
+
+ /*
+ * Available only for object with type InterfaceInstance
+ * */
+ ClassRef GetClassConstructor() const;
+
+ const char* GetInterfaceName() const;
+
+ const char* GetName() const;
+
+ IObjectType GetType() const;
+
+ const char* GetParentName() const;
+
+ ObjectOptionPtr GetOptions() const;
+
+ private:
+ const char* m_name;
+ ClassRef m_classRef;
+
+ const char* m_parentName;
+
+ IObjectType m_type;
+
+ ClassRef m_interfaceRef;
+ const char* m_interfaceName;
+ ClassRef m_constructorRef;
+
+ ObjectOptionPtr m_options;
+
+ IObjectsListPtr m_children;
+};
+}
+
+#endif
diff --git a/src/plugins-api-support/ObjectFactory.cpp b/src/plugins-api-support/ObjectFactory.cpp
new file mode 100644
index 0000000..b897399
--- /dev/null
+++ b/src/plugins-api-support/ObjectFactory.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file ObjectFactory.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include "ObjectFactory.h"
+#include "Object.h"
+
+namespace WrtPluginsApi {
+namespace ObjectFactory {
+IObjectPtr createObject(
+ const char* name,
+ ClassRef ref,
+ IObjectType type)
+{
+ return IObjectPtr(new Object(name, ref, type));
+}
+
+IObjectPtr createMainObject(
+ const char* name,
+ ClassRef ref,
+ const char* parentName,
+ IObjectType type)
+{
+ return IObjectPtr(new Object(name, ref, parentName, type));
+}
+
+IObjectPtr createObjectWithInterface(
+ const char* name,
+ ClassRef interfaceRef,
+ const char* interfaceName,
+ ClassRef constructorRef,
+ const char* parentName,
+ IObjectType type)
+{
+ return IObjectPtr(new Object(name,
+ interfaceRef,
+ interfaceName,
+ constructorRef,
+ parentName,
+ type));
+}
+}
+}
diff --git a/src/plugins-api-support/ObjectFactory.h b/src/plugins-api-support/ObjectFactory.h
new file mode 100644
index 0000000..59bff1d
--- /dev/null
+++ b/src/plugins-api-support/ObjectFactory.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file ObjectFactory.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_FACTORY_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_FACTORY_H_
+
+#include <memory>
+#include <IObject.h>
+
+namespace WrtPluginsApi {
+namespace ObjectFactory {
+IObjectPtr createObject(
+ const char* name,
+ ClassRef ref,
+ IObjectType type = IObjectType::Object);
+
+IObjectPtr createMainObject(
+ const char* name,
+ ClassRef ref,
+ const char* parentName = IObject::WINDOW_OBJECT(),
+ IObjectType type = IObjectType::Object);
+
+IObjectPtr createObjectWithInterface(
+ const char* name,
+ ClassRef interfaceRef,
+ const char* interfaceName,
+ ClassRef constructorRef,
+ const char* parentName = IObject::WINDOW_OBJECT(),
+ IObjectType type = IObjectType::Object);
+}
+}
+#endif
diff --git a/src/plugins-api-support/Plugin.cpp b/src/plugins-api-support/Plugin.cpp
new file mode 100644
index 0000000..6303c32
--- /dev/null
+++ b/src/plugins-api-support/Plugin.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file Plugin.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#include "Plugin.h"
+
+namespace WrtPluginsApi {
+void Plugin::AddObject(const IObjectPtr& object)
+{
+ m_objects->push_back(object);
+}
+
+IObjectsListPtr Plugin::GetObjects() const
+{
+ return m_objects;
+}
+
+Plugin::~Plugin()
+{}
+
+Plugin::Plugin() : m_objects(new IObjectsList())
+{}
+}
diff --git a/src/plugins-api-support/Plugin.h b/src/plugins-api-support/Plugin.h
new file mode 100644
index 0000000..5458714
--- /dev/null
+++ b/src/plugins-api-support/Plugin.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file Plugin.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_H_
+
+#include <list>
+#include <IObject.h>
+
+namespace WrtPluginsApi {
+class Plugin
+{
+ public:
+ void AddObject(const IObjectPtr& object);
+
+ IObjectsListPtr GetObjects() const;
+
+ Plugin();
+
+ virtual ~Plugin();
+
+ private:
+ IObjectsListPtr m_objects;
+};
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginRegistration.cpp b/src/plugins-api-support/PluginRegistration.cpp
new file mode 100644
index 0000000..4418e32
--- /dev/null
+++ b/src/plugins-api-support/PluginRegistration.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file PluginRegistration.cpp
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#include "PluginRegistration.h"
+
+#include "PluginRegistrationImpl.h"
+#include "Plugin.h"
+#include <dpl/assert.h>
+
+namespace WrtPluginsApi {
+PluginRegistration::PluginRegistration(Impl* impl) : m_impl(impl)
+{
+ AssertMsg(impl != 0, "impl is NULL");
+}
+
+template<typename SignalSignature>
+void PluginRegistration::Connect(const typename SignalSignature::Type& slot)
+{
+ m_impl->Connect<SignalSignature>(slot);
+}
+
+void PluginRegistration::DisconnectAll()
+{
+ m_impl->DisconnectAll();
+}
+
+void PluginRegistration::AddPlugin(Plugin& plugin)
+{
+ m_impl->AddPlugin(plugin);
+}
+
+#define EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(SignalSignature) \
+ template void PluginRegistration::Connect<SignalSignature>( \
+ const typename SignalSignature::Type &)
+
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnWidgetStart);
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnWidgetStop);
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnFrameLoad);
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnFrameUnload);
+}
diff --git a/src/plugins-api-support/PluginRegistration.h b/src/plugins-api-support/PluginRegistration.h
new file mode 100644
index 0000000..e871a76
--- /dev/null
+++ b/src/plugins-api-support/PluginRegistration.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file PluginRegistration.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_H_
+
+#include <memory>
+#include "Plugin.h"
+#include "PluginSignals.h"
+
+namespace WrtPluginsApi {
+class PluginRegistration
+{
+ public:
+ class Impl;
+
+ explicit PluginRegistration(PluginRegistration::Impl* impl);
+
+ template<typename SignalSignature>
+ void Connect(const typename SignalSignature::Type& slot);
+
+ void DisconnectAll();
+
+ void AddPlugin(Plugin& plugin);
+
+ private:
+ std::unique_ptr<Impl> m_impl;
+};
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginRegistrationImpl.h b/src/plugins-api-support/PluginRegistrationImpl.h
new file mode 100644
index 0000000..5954731
--- /dev/null
+++ b/src/plugins-api-support/PluginRegistrationImpl.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file PluginRegistrationImpl.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_IMPL_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_IMPL_H_
+
+#include <string>
+#include "SignalsSupport.h"
+#include "Plugin.h"
+#include <dpl/log/wrt_log.h>
+
+namespace WrtPluginsApi {
+class PluginRegistration::Impl
+{
+ public:
+ Impl(SignalsSupport& registry, const std::string& libraryName) :
+ m_registry(registry),
+ m_libraryName(libraryName)
+ {}
+
+ void AddPlugin(Plugin& plugin)
+ {
+ m_registry.AddPlugin(m_libraryName, plugin);
+ }
+
+ template<typename T>
+ void Connect(const typename T::Type& slot)
+ {
+ m_registry.Connect<T>(m_libraryName, slot);
+ }
+
+ void DisconnectAll()
+ {
+ m_registry.Disconnect(m_libraryName);
+ }
+
+ private:
+ SignalsSupport& m_registry;
+ std::string m_libraryName;
+};
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginRegistry.cpp b/src/plugins-api-support/PluginRegistry.cpp
new file mode 100644
index 0000000..0a94c23
--- /dev/null
+++ b/src/plugins-api-support/PluginRegistry.cpp
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file PluginRegistry.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#include "PluginRegistry.h"
+#include "PluginRegistration.h"
+#include "PluginRegistrationImpl.h"
+#include "ExportedApi.h"
+
+#include <dlfcn.h>
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include <algorithm>
+
+#include <dpl/log/wrt_log.h>
+#include <dpl/foreach.h>
+#include <dpl/scope_guard.h>
+
+namespace WrtPluginsApi {
+void PluginRegistry::AddPlugin(const std::string& libraryName,
+ Plugin& plugin)
+{
+ WrtLogD("Adding plugin for library: %s", libraryName.c_str());
+
+ auto libraryIt = m_plugins.find(libraryName);
+ if (m_plugins.end() == libraryIt) {
+ m_plugins[libraryName] = &plugin;
+ }
+}
+
+Plugin* PluginRegistry::GetPlugin(const std::string& libraryName)
+{
+ auto it = m_plugins.find(libraryName);
+ if (it == m_plugins.end()) {
+ if (!LoadFromFile(libraryName)) {
+ WrtLogE("Failed to load lib %s", libraryName.c_str());
+ ThrowMsg(PluginNotFound, "Failed to load plugin");
+ }
+
+ return m_plugins[libraryName];
+ }
+
+ return it->second;
+}
+
+void PluginRegistry::RemovePlugin(const std::string& libraryName,
+ Plugin& plugin)
+{
+ auto it = m_plugins.find(libraryName);
+ if (it != m_plugins.end()) {
+ if (&plugin == it->second) {
+ m_plugins.erase(it);
+ }
+ }
+}
+
+void PluginRegistry::UnloadAll()
+{
+ WrtLogD("Unload all plugins");
+
+ typedef void (*UnregisterFunction)(PluginRegistration&, Plugin&);
+
+ FOREACH(libraryIt, m_libraries)
+ {
+ auto pluginIt = m_plugins.find(libraryIt->first);
+ if (m_plugins.end() != pluginIt) {
+ void* handle = dlopen(libraryIt->first.c_str(), RTLD_NOW);
+ if (!handle) {
+ const char* error = (const char*)dlerror();
+ WrtLogE("Error: %s", (error != NULL ? error : "unknown"));
+ continue;
+ }
+ DPL_SCOPE_EXIT(handle) {
+ if (dlclose(handle) != 0) {
+ const char* error = dlerror();
+ if (error != NULL)
+ {
+ std::string errstr{error};
+ WrtLogE("%s", errstr.c_str());
+ }
+ else
+ {
+ WrtLogE("unknown error while closing plug-in library");
+ }
+ }
+ };
+
+ ExportedApi* entryPoint =
+ static_cast<ExportedApi*>
+ (dlsym(handle, GetExportedSymbolName()));
+ if (NULL == entryPoint) {
+ const char* error = (const char*)dlerror();
+ WrtLogE("Error: %s", (error != NULL ? error : "unknown"));
+ continue;
+ }
+ if (entryPoint->Unregister == NULL) {
+ WrtLogE("Error Unregister function not set");
+ continue;
+ }
+
+ PluginRegistration registration(
+ new PluginRegistration::Impl(*this, libraryIt->first));
+
+ entryPoint->Unregister(registration, (pluginIt->second));
+
+ m_plugins.erase(pluginIt);
+ }
+ dlclose(libraryIt->second);
+ }
+}
+
+bool PluginRegistry::LoadFromFile(const std::string& libraryName)
+{
+ void* handle = dlopen(libraryName.c_str(), RTLD_NOW);
+ if (!handle) {
+ const char* error = (const char*)dlerror();
+ WrtLogE("Error: %s", (error != NULL ? error : "unknown"));
+ return false;
+ }
+ m_libraries[libraryName] = handle;
+
+ ExportedApi* entryPoint =
+ static_cast<ExportedApi*>(dlsym(handle, GetExportedSymbolName()));
+ if (NULL == entryPoint) {
+ const char* error = (const char*)dlerror();
+ WrtLogE("Error: %s", (error != NULL ? error : "unknown"));
+ return false;
+ }
+
+ if (entryPoint->Register == NULL) {
+ WrtLogE("Error Register function not set");
+ return false;
+ }
+ if (entryPoint->Unregister == NULL) {
+ WrtLogE("Error Unregister function not set");
+ return false;
+ }
+
+ PluginRegistration registration(
+ new PluginRegistration::Impl(*this, libraryName));
+ entryPoint->Register(registration);
+
+ return true;
+}
+
+PluginRegistry::~PluginRegistry()
+{
+ //TODO discuss ... when the unload should be called
+ // UnloadAll();
+}
+}
diff --git a/src/plugins-api-support/PluginRegistry.h b/src/plugins-api-support/PluginRegistry.h
new file mode 100644
index 0000000..5db1ea4
--- /dev/null
+++ b/src/plugins-api-support/PluginRegistry.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file PluginRegistry.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_LOADING_PLUGIN_REGISTRY_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_LOADING_PLUGIN_REGISTRY_H_
+
+#include <map>
+#include <string>
+#include "SignalsSupport.h"
+#include "Plugin.h"
+#include <dpl/exception.h>
+
+namespace WrtPluginsApi {
+typedef std::list<Plugin*> PluginsList;
+typedef std::shared_ptr<PluginsList> PluginsListPtr;
+typedef std::map< std::string, PluginsListPtr> PluginsSet;
+
+class PluginRegistry : public SignalsSupport
+{
+ public:
+ DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+ DECLARE_EXCEPTION_TYPE(Base, PluginNotFound)
+
+ template <typename T, typename ... Args>
+ void Call(Args ... args)
+ {
+ Invoke<T>(args ...);
+ }
+
+ template <typename T, typename ... Args>
+ void CallGroup(const typename CallbackSupport<T>::GroupType& type,
+ Args ... args)
+ {
+ InvokeGroup<T>(type, args ...);
+ }
+
+ void AddPlugin(const std::string& libraryName, Plugin& plugin);
+
+ /*
+ * @throw PluginNotFound
+ * */
+ Plugin* GetPlugin(const std::string& libraryName);
+
+ void RemovePlugin(const std::string& libraryName, Plugin& plugin);
+
+ void UnloadAll();
+
+ ~PluginRegistry();
+
+ private:
+ bool LoadFromFile(const std::string& libraryName);
+
+ typedef void* Symbol;
+
+ std::map<std::string, Plugin*> m_plugins;
+ std::map<std::string, void*> m_libraries;
+};
+
+typedef std::shared_ptr<PluginRegistry> PluginRegistryPtr;
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginSignals.h b/src/plugins-api-support/PluginSignals.h
new file mode 100644
index 0000000..556d620
--- /dev/null
+++ b/src/plugins-api-support/PluginSignals.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file PluginSignals.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_SIGNALS_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_SIGNALS_H_
+
+#include "SignalSignature.h"
+
+namespace WrtPluginsApi {
+struct OnWidgetStart : SignalSignature<void (int)> {};
+
+struct OnWidgetStop : SignalSignature<void (int)> {};
+
+struct OnFrameLoad : SignalSignature<void (void*)> {};
+
+struct OnFrameUnload : SignalSignature<void (void*)> {};
+}
+
+#endif
diff --git a/src/plugins-api-support/SignalSignature.h b/src/plugins-api-support/SignalSignature.h
new file mode 100644
index 0000000..b43747e
--- /dev/null
+++ b/src/plugins-api-support/SignalSignature.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file SignalSignature.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNAL_SIGNATURE_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNAL_SIGNATURE_H_
+
+#include <functional>
+
+namespace WrtPluginsApi {
+template<typename> struct SignalSignature;
+
+template<typename R, typename ... Args>
+struct SignalSignature<R(Args ...)>
+{
+ typedef R (*Signature)(Args ...);
+ typedef std::function<R(Args ...)> Type;
+};
+}
+
+#endif
diff --git a/src/plugins-api-support/SignalsSupport.h b/src/plugins-api-support/SignalsSupport.h
new file mode 100644
index 0000000..9c47af2
--- /dev/null
+++ b/src/plugins-api-support/SignalsSupport.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file IPluginRegistry.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNALS_SUPPORT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNALS_SUPPORT_H_
+
+#include <tuple>
+#include <string>
+#include "CallbackSupport.h"
+#include "tuple.h"
+#include "PluginSignals.h"
+#include "Plugin.h"
+
+namespace WrtPluginsApi {
+class SignalsSupport
+{
+ public:
+ virtual ~SignalsSupport() {}
+
+ template<typename T>
+ void Connect(const std::string& libraryName, const typename T::Type& slot)
+ {
+ Tuple::get_by_type<CallbackSupport<T> >(m_slots).Connect(libraryName,
+ slot);
+ }
+
+ void Disconnect(const std::string& libraryName)
+ {
+ DisconnectGroup(m_slots, libraryName);
+ }
+
+ virtual void AddPlugin(const std::string& libraryName, Plugin& plugin) = 0;
+
+ protected:
+ template<typename T, typename ... Args>
+ void Invoke(const Args& ... args)
+ {
+ Tuple::get_by_type<CallbackSupport<T> >(m_slots).Invoke(args ...);
+ }
+
+ template<typename T, typename ... Args>
+ void InvokeGroup(const std::string& libraryName, const Args& ... args)
+ {
+ Tuple::get_by_type<CallbackSupport<T> >(m_slots).InvokeGroup(
+ libraryName,
+ args ...);
+ }
+
+ private:
+ template<int N, typename ... Args>
+ void DisconnectSlot(std::tuple<Args ...>& slots,
+ const std::string& libraryName,
+ typename std::enable_if<(N >= 0)>::type* = NULL)
+ {
+ std::get<N>(slots).Disconnect(libraryName);
+ DisconnectSlot<N - 1>(slots, libraryName);
+ }
+
+ template<int N, typename ... Args>
+ void DisconnectSlot(std::tuple<Args ...>& /*slots*/,
+ const std::string& /*libraryName*/,
+ typename std::enable_if<(N == -1)>::type* = NULL)
+ {}
+
+ template<typename ... Args>
+ void DisconnectGroup(std::tuple<Args ...>& slots,
+ const std::string& libraryName)
+ {
+ DisconnectSlot<sizeof ... (Args)-1>(slots, libraryName);
+ }
+
+ std::tuple<CallbackSupport<OnWidgetStart>,
+ CallbackSupport<OnWidgetStop>,
+ CallbackSupport<OnFrameLoad>,
+ CallbackSupport<OnFrameUnload> > m_slots;
+};
+}
+
+#endif
diff --git a/src/plugins-api-support/detail/traits.h b/src/plugins-api-support/detail/traits.h
new file mode 100644
index 0000000..7ab56db
--- /dev/null
+++ b/src/plugins-api-support/detail/traits.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file traits.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_DETAIL_TRAITS_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_DETAIL_TRAITS_H_
+
+namespace WrtPluginsApi {
+namespace Traits {
+namespace Detail {
+template<size_t, typename RequiredType, typename ... TupleArgTypes>
+struct index_of_;
+
+/*
+ * CurrentArgType is not equal to RequiredType, check next tuple's argument
+ */
+template<size_t n,
+ typename RequiredType,
+ typename CurrentArgType,
+ typename ... TupleArgTypes>
+struct index_of_<n, RequiredType, CurrentArgType, TupleArgTypes ...>
+{
+ static const size_t value = index_of_<n + 1,
+ RequiredType,
+ TupleArgTypes ...>::value;
+};
+
+/*
+ * RequiredType found on tuple's args list
+ * return position on tuple's list
+ */
+template<size_t n, typename RequiredType, typename ... TupleArgTypes>
+struct index_of_<n, RequiredType, RequiredType, TupleArgTypes ...>
+{
+ static const size_t value = n;
+};
+
+/*
+ * RequiredType found on last position of tuple's args list
+ * return position on tuple's list
+ */
+template<size_t n, typename RequiredType>
+struct index_of_<n, RequiredType, RequiredType>
+{
+ static const size_t value = n;
+};
+
+/*
+ * RequiredType was not found on tuple args list
+ */
+template<size_t n, typename RequiredType, typename LastArgType>
+struct index_of_<n, RequiredType, LastArgType>
+{
+ static const size_t value = -1;
+};
+}
+}
+}
+
+#endif
diff --git a/src/plugins-api-support/js_types.h b/src/plugins-api-support/js_types.h
new file mode 100644
index 0000000..387c5bc
--- /dev/null
+++ b/src/plugins-api-support/js_types.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file js_types.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 1.0
+ */
+
+#ifndef WRT_PLUGIN_COMMON_API_SUPPORT_JS_TYPES_H_
+#define WRT_PLUGIN_COMMON_API_SUPPORT_JS_TYPES_H_
+
+#include <string>
+
+//forward declaration
+extern "C" {
+typedef struct OpaqueJSContext* JSGlobalContextRef;
+typedef struct OpaqueJSValue* JSObjectRef;
+}
+
+namespace WrtPluginsApi {
+struct JavaScriptObject
+{
+ JSObjectRef instance;
+ std::string name;
+};
+}
+
+#endif
diff --git a/src/plugins-api-support/traits.h b/src/plugins-api-support/traits.h
new file mode 100644
index 0000000..286c510
--- /dev/null
+++ b/src/plugins-api-support/traits.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file traits.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TRAITS_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TRAITS_H_
+
+#include "detail/traits.h"
+
+namespace WrtPluginsApi {
+namespace Traits {
+/**
+ * Gets index of specified type in the type list.
+ */
+template<typename RequiredType, typename ... TupleArgTypes>
+struct index_of
+{
+ static const size_t value = Detail::index_of_<0,
+ RequiredType,
+ TupleArgTypes ...>::value;
+};
+}
+}
+
+#endif
diff --git a/src/plugins-api-support/tuple.h b/src/plugins-api-support/tuple.h
new file mode 100644
index 0000000..ec7c3b3
--- /dev/null
+++ b/src/plugins-api-support/tuple.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file tuple.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TUPLE_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TUPLE_H_
+
+#include <tuple>
+#include "traits.h"
+
+namespace WrtPluginsApi {
+namespace Tuple {
+template<typename T, typename ... Args>
+T& get_by_type(std::tuple<Args ...>& tuple)
+{
+ return std::get<Traits::index_of<T, Args ...>::value>(tuple);
+}
+}
+}
+
+#endif