--- /dev/null
+CMakeCache.txt
+CMakeFiles/
+build-stamp
+cmake_install.cmake
+config.guess
+config.sub
+configure-stamp
+debian/files
+debian/tmp/
+install_manifest.txt
+Makefile
+debian/wrt-plugins-dev.install
+debian/wrt-plugins.install
+debian/wrt-plugins.postinst
+debian/wrt-plugins-common-dbg.debhelper.log
+debian/wrt-plugins-common-dbg.substvars
+debian/wrt-plugins-common-dbg/
+debian/wrt-plugins-common.debhelper.log
+debian/wrt-plugins-common.substvars
+debian/wrt-plugins-common/
+src/Makefile
+
+debian/wrt-plugins-common-dev.debhelper.log
+debian/wrt-plugins-common-dev.install
+debian/wrt-plugins-common-dev.substvars
+debian/wrt-plugins-common-dev/
+debian/wrt-plugins-common.install
+debian/wrt-plugins-common.postinst
+debian/wrt-plugins-common.postinst.debhelper
+debian/wrt-plugins-common.postrm.debhelper
+
+pkgconfigs/*.pc
+
+*~
+*.swp
+cmake_build/*
+
+src/modules/slp2.0/WidgetInterfaceDAO/.widget_interface.db
+src/modules/slp2.0/WidgetInterfaceDAO/.widget_interface.db-journal
+src/modules/slp2.0/WidgetInterfaceDAO/widget_interface_db.sql
+
+/bin
\ No newline at end of file
${dpl_INCLUDE_DIRS}
)
+
+
##############################################################################
+# Build type
+IF(NOT CMAKE_BUILD_TYPE)
+ SET(CMAKE_BUILD_TYPE "Release")
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
# Compiler flags
-SET(CMAKE_BUILD_TYPE Release)
SET(CMAKE_C_FLAGS_PROFILING "-O0 -g -pg")
SET(CMAKE_CXX_FLAGS_PROFILING "-O0 -std=c++0x -g -pg")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -std=c++0x -g")
SET(CMAKE_C_FLAGS_RELEASE "-O2 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -std=c++0x -g")
+SET(CMAKE_CXX_FLAGS_CCOV "-O0 -std=c++0x -g --coverage")
####
OPTION(DPL_LOG "DPL logs status" ON)
MESSAGE(STATUS "Logging disabled for DPL")
ENDIF(DPL_LOG)
+ADD_DEFINITIONS("-fPIC")
ADD_DEFINITIONS("-fvisibility=default") # mark all exported symbols as visible
ADD_DEFINITIONS("-fPIC") # If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding
ADD_DEFINITIONS("-DEXPORT_API=")
#ADD_DEFINITIONS("-Werror")
ADD_DEFINITIONS("-Wextra")
ADD_DEFINITIONS("-Wno-deprecated")
-ADD_DEFINITIONS("-DSEPARATED_SINGLETON_IMPLEMENTATION")
-#ADD_DEFINITIONS("-DW3C_TEST")
#ADD_DEFINITIONS("-DDEVPKG")
##############################################################################
# CMake flags
-IF (W3C_TEST)
- SET(W3C_TEST "ON")
-ENDIF(W3C_TEST)
IF (DEVPKG)
SET(DEVPKG "ON")
ENDIF(DEVPKG)
set(DESTINATION_HEADERS_NON_JS ${DESTINATION_HEADER_PREFIX}/Commons)
set(DESTINATION_HEADERS_JS ${DESTINATION_HEADER_PREFIX}/CommonsJavaScript)
+set(DESTINATION_HEADERS_JS_OVERLAY ${DESTINATION_HEADER_PREFIX}/js-overlay)
################################################################################
# Target platform
configure_and_install_pkg(wrt-plugins-widget-interface-dao.pc)
configure_and_install_pkg(wrt-plugins-widgetdb.pc)
configure_and_install_pkg(wrt-plugins-plugin-manager.pc)
+configure_and_install_pkg(wrt-plugin-loading.pc)
+configure_and_install_pkg(wrt-plugin-js-overlay.pc)
################################################################################
# Cache
# Summary
message(STATUS "PLATFORM = ${PLATFORM}")
-message(STATUS "W3C_TEST = ${W3C_TEST}")
+wrt-plugins-common (0.3.53) unstable; urgency=low
+
+ * Removed a unnecessary dependency.
+ * Add thread pool enum for new tizen download module.
+ * Added new build type for code coverage
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.53
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Wed, 08 Aug 2012 15:42:43 +0900
+
+wrt-plugins-common (0.3.52) unstable; urgency=low
+
+ * Update tag for adding "SEL Verification"
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.52
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Wed, 01 Aug 2012 17:46:57 +0900
+
+wrt-plugins-common (0.3.51) unstable; urgency=low
+
+ * Support for multiple contexts in plugin logic
+ * Cleaned up loading plugin into iframes
+ * Added support for dispatch event and set properties in JS
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.51
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Wed, 01 Aug 2012 13:28:24 +0900
+
+wrt-plugins-common (0.3.50) unstable; urgency=low
+
+ * Re-upload package
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.50
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Tue, 31 Jul 2012 11:35:52 +0900
+
+wrt-plugins-common (0.3.49) unstable; urgency=low
+
+ * Revert "Update dependency".
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.49
+
+ -- Bartlomiej Grzelewski <b.grzelewski@samsung.com> Mon, 30 Jul 2012 15:30:00 +0200
+
+wrt-plugins-common (0.3.48) unstable; urgency=low
+
+ * Re-upload package
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.48
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Mon, 30 Jul 2012 10:09:01 +0900
+
+wrt-plugins-common (0.3.47) unstable; urgency=low
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.47
+
+ -- Leerang Song <leerang.song@samsung.com> Fri, 27 Jul 2012 12:16:45 +0900
+
+wrt-plugins-common (0.3.46-1) unstable; urgency=low
+
+ * Fix tag for auto SR
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.46-1
+
+ -- Zbigniew Kostrzewa <z.kostrzewa@samsung.com> Wed, 25 Jul 2012 15:44:54 +0200
+
+wrt-plugins-common (0.3.46) unstable; urgency=low
+
+ * Upgrade dependencies to wrt-security and security-server
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.46
+
+ -- Zbigniew Kostrzewa <z.kostrzewa@samsung.com> Wed, 25 Jul 2012 15:34:13 +0200
+
+wrt-plugins-common (0.3.45) unstable; urgency=low
+
+ * readFeatures - performance improvement
+ * Upgrade dependencies
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.45
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Wed, 25 Jul 2012 10:02:39 +0900
+
+wrt-plugins-common (0.3.44) natty; urgency=low
+
+ * fix build error in Plugin_property_support
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.44
+
+ -- Taejeong.lee <taejeong.lee@samsung.com> Wed, 18 Jul 2012 19:35:41 +0900
+
+wrt-plugins-common (0.3.43) unstable; urgency=low
+
+ * "window.navigator.theme" property support.
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.43
+
+ -- Taejeong.lee <taejeong.lee@samsung.com> Wed, 18 Jul 2012 17:45:56 +0900
+
+wrt-plugins-common (0.3.42) unstable; urgency=low
+
+ * Fixed CCR(#65374), jira(#WEB-1201)
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.42
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Mon, 16 Jul 2012 11:06:24 +0900
+
+wrt-plugins-common (0.3.41-1) unstable; urgency=low
+
+ * Add tag for auto SR
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.41-1
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Thu, 12 Jul 2012 15:59:21 +0900
+
+wrt-plugins-common (0.3.41) unstable; urgency=low
+
+ * Filesystem copy and move permission check fix
+ * Fix format of debian changelog entry
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.41
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Thu, 12 Jul 2012 14:20:57 +0900
+
+wrt-plugins-common (0.3.40) unstable; urgency=low
+
+ * Revision to prevent a crash when Web process is terminated by OOM
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.40
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Thu, 05 Jul 2012 09:40:36 +0900
+
+wrt-plugins-common (0.3.39) unstable; urgency=low
+
+ * Add TimeUtils API
+ * Change dependency to webkit2
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.39
+
+ -- Tae Jeong Lee <taejeong.lee@samsung.com> Mon, 02 Jul 2012 15:01:03 +0900
+
+wrt-plugins-common (0.3.38) unstable; urgency=low
+
+ * Implementation of InjectedJavascript
+ * Changed ACE client usage to new C-API
+ * Klocwork fixes
+ * Add load and unload event for frame
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.38
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Thu, 28 Jun 2012 16:34:35 +0900
+
+wrt-plugins-common (0.3.37) unstable; urgency=low
+
+ * Seperate js overlay module from widget interface and support new requirment of tizen appservice
+ * clear event listeners for custom event and its JSObject in case of page switch
+ * Fix for w3c-packaging-v9 test
+ * Move classes regarding management of js object to src/Commons
+ * add checking code on event dispatch handler of plugin logic
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.37
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Mon, 11 Jun 2012 15:10:39 +0900
+
+wrt-plugins-common (0.3.36) unstable; urgency=low
+
+ * Removing DSEPARATED_SINGLETON_IMPLEMENTATION flag
+ * Fix generating database for WidgetInterfaceDAO
+ * signalEventByDispatcher() crash fix
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.36
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Thu, 31 May 2012 14:19:20 +0900
+
+wrt-plugins-common (0.3.35) unstable; urgency=low
+
+ * Debianize for wrt-plugins-common_0.3.35
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.35
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Thu, 24 May 2012 18:16:08 +0900
+
+wrt-plugins-common (0.3.34) unstable; urgency=low
+
+ * Debianize for wrt-plugins-common_0.3.34
+ * Include below changes.
+ - [Security] WrtAccess class implementation changed to safe one.
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.34
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Thu, 17 May 2012 18:41:37 +0900
+
+wrt-plugins-common (0.3.33) unstable; urgency=low
+
+ * Fix toLong, toInt, toChar, toSizeT converters
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.33
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Thu, 03 May 2012 10:18:10 +0900
+
+wrt-plugins-common (0.3.32) unstable; urgency=low
+
+ * Debianized for wrt-plugins-common_0.3.32
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.32
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Thu, 19 Apr 2012 15:48:10 +0900
+
+wrt-plugins-common (0.3.31) unstable; urgency=low
+
+ * Debianized for wrt-plugins-common_0.3.31
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.31
+
+ -- Jihoon Chung <jihoon.chung@samsung.com> Mon, 09 Apr 2012 11:41:21 +0900
+
+wrt-plugins-common (0.3.30) unstable; urgency=low
+
+ * Debianized for wrt-plugins-common_0.3.30
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.30
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Mon, 09 Apr 2012 10:25:40 +0900
+
+wrt-plugins-common (0.3.29) unstable; urgency=low
+
+ * Debianized for wrt-plugins-common_0.3.29
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.29
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Fri, 23 Mar 2012 10:15:50 +0900
+
+wrt-plugins-common (0.3.28) unstable; urgency=low
+
+ * Debianized for wrt-plugins-common_0.3.28
+
+ * Git : slp/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.28
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Tue, 20 Mar 2012 20:32:02 +0900
+
wrt-plugins-common (0.3.27) unstable; urgency=low
* Filesystem export API is changed.
Section: devel
Priority: extra
Maintainer: Piotr Fatyga <p.fatyga@samsung.com>, Grzegorz Krawczyk <g.krawczyk@samsung.com>, Zbigniew Kostrzewa <z.kostrzewa@samsung.com>, Taehee Lee <th219.lee@samsung.com>
-Build-Depends: debhelper (>= 5), wrt-dev (>=0.8.27), libwebkit-engine-dev, wrt-commons-dev (>=0.2.6), libmm-player-dev, libmm-sound-dev, libpcre-dev, libglib2.0-dev, iniparser-dev, wrt-security-dev(>= 0.0.12)
+Build-Depends: debhelper (>= 5), libwebkit2-efl-dev, wrt-commons-dev (>=0.2.7), libmm-player-dev, libmm-sound-dev, libpcre-dev, libglib2.0-dev, iniparser-dev, wrt-security-dev(>= 0.0.28)
Uploaders: Hoseon LEE <hoseon46.lee@samsung.com>, Taejeong Lee <taejeong.lee@samsung.com>, Jaehyun Park <jaehyun77.park@samsung.com>
Package: wrt-plugins-common
Architecture: any
Section: libs
-Depends: ${shlibs:Depends}, ${misc:Depends}, wrt, wrt-security(>= 0.0.12)
+Depends: ${shlibs:Depends}, ${misc:Depends}, wrt-security(>= 0.0.28)
Description: Common modules for creation JavaScript's plugins
Package: wrt-plugins-common-dev
Architecture: any
Section: libs
-Depends: wrt-plugins-common (= ${Source-Version}), libwebkit-engine-dev, wrt-commons-dev (>=0.2.6), wrt-dev (>=0.8.27)
+Depends: wrt-plugins-common (= ${Source-Version}), libwebkit2-efl-dev, wrt-commons-dev (>=0.2.7)
Description: Common modules for creation JavaScript's plugins -dev
Package: wrt-plugins-common-dbg
#!/bin/sh
mkdir -p /usr/lib/wrt-plugins
+mkdir -p /usr/etc/wrt/injected-javascript
touch /opt/apps/widget/plugin-installation-required
\ No newline at end of file
-#sbs-git:public/pkgs/w/wrt-plugins-common wrt-plugins-common 0.3.27
+#sbs-git:slp/pkgs/w/wrt-plugins-common wrt-plugins-common 0.3.53
Name: wrt-plugins-common
Summary: wrt-plugins common library
-Version: 0.3.27
+Version: 0.3.53
Release: 1
Group: Development/Libraries
License: Apache License, Version 2.0
-Source0: %{name}-%{version}.tar.gz
+Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
BuildRequires: pkgconfig(dpl-efl)
-BuildRequires: pkgconfig(wrt-plugin-api)
+BuildRequires: pkgconfig(wrt-plugins-types)
BuildRequires: pkgconfig(ace-client)
BuildRequires: pkgconfig(dpl-event-efl)
-BuildRequires: pkgconfig(ewebkit)
+BuildRequires: pkgconfig(ewebkit2)
BuildRequires: pkgconfig(dpl-wrt-dao-ro)
BuildRequires: pkgconfig(dpl-db-efl)
BuildRequires: pkgconfig(libpcrecpp)
-BuildRequires: pkgconfig(wrt-plugin-loading)
BuildRequires: pkgconfig(mm-sound)
BuildRequires: pkgconfig(mm-player)
-BuildRequires: ug-picker-efl
+BuildRequires: pkgconfig(icu-i18n)
Requires: ldconfig
%description
cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DDPL_LOG="ON" \
- -DCMAKE_PROJECT_VERSION=%{version}
+ -DCMAKE_PROJECT_VERSION=%{version} \
+ -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}
make %{?jobs:-j%jobs}
%install
%clean
rm -rf %{buildroot}
-%post
-mkdir -p /usr/lib/wrt-plugins
+%post
+mkdir -p /usr/lib/wrt-plugins
+mkdir -p /usr/etc/wrt/injected-javascript
touch /opt/apps/widget/plugin-installation-required
-%files
+%files
/usr/etc/wrt-plugins/config.dtd
%{_libdir}/*.so
%{_libdir}/*.so.*
%{_libdir}/wrt-plugins/w3c-widget-interface/libwrt-plugins-w3c-widget-interface.so
%attr(644,root,root) %{_libdir}/wrt-plugins/standard-features-list
-%attr(644,root,root) %{_libdir}/wrt-plugins/w3c-widget-interface/config.xml
%attr(644,root,root) /usr/share/wrt-plugins-common/widget_interface_db.sql
%files devel
--- /dev/null
+prefix=/usr
+project_name=@CMAKE_PROJECT_NAME@
+exec_prefix=${prefix}
+includedir=${prefix}/include/${project_name}
+
+Name: wrt-plugin-js-overlay
+Description: header for enum value of supported custom js event types
+Version: @CMAKE_PROJECT_VERSION@
+Requires:
+Libs:
+Cflags: -I${includedir}/js-overlay
--- /dev/null
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: wrt-plugin-loading
+Description: wrt-plugin-loading
+Version: @PROJECT_VERSION@
+Requires: dpl-efl dpl-wrt-dao-ro ewebkit2
+Libs: -lwrt-plugin-loading -L${libdir}
+Cflags: -I${includedir}/wrt-plugin-loading -I${includedir}/wrt-plugins-common
Name: WrtDeviceApis commons with JavaScrpt dependencies
Description: Commons for DeviceApis with JavaScrpt dependencies
Version: @CMAKE_PROJECT_VERSION@
-Requires: dpl-efl ewebkit wrt-plugins-commons
+Requires: dpl-efl ewebkit2 wrt-plugins-commons
Libs: -L${libdir} -lwrt-plugins-commons-javascript
Cflags: -I${includedir}
Name: WebRuntime DeviceApis Plugin Manager module
Description: WebRuntime Plugin Manager module
Version: @CMAKE_PROJECT_VERSION@
-Requires: dpl-efl wrt-plugins-commons wrt-plugins-commons-javascript dpl-wrt-dao-ro ewebkit
+Requires: dpl-efl wrt-plugins-commons wrt-plugins-commons-javascript dpl-wrt-dao-ro ewebkit2
Libs: -L${libdir} -lwrt-plugins-plugin-manager
Cflags: -I${includedir}/PluginManager
${CMAKE_CURRENT_SOURCE_DIR}/modules/API
${CMAKE_CURRENT_SOURCE_DIR}/Commons
${CMAKE_CURRENT_SOURCE_DIR}/CommonsJavaScript
+ ${CMAKE_CURRENT_SOURCE_DIR}/plugin-loading
+ ${CMAKE_CURRENT_SOURCE_DIR}/js-overlay
)
#target names
+set(TARGET_PLUGIN_LOADING_LIB "wrt-plugin-loading")
set(TARGET_COMMONS "wrt-plugins-commons")
set(TARGET_COMMONS_JAVASCRIPT "wrt-plugins-commons-javascript")
+set(TARGET_JS_OVERLAY "wrt-plugins-js-overlay")
+set(PLUGIN_LOADING_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/plugin-loading)
+
+add_subdirectory(plugin-loading)
+add_subdirectory(js-overlay)
add_subdirectory(Commons)
add_subdirectory(CommonsJavaScript)
add_subdirectory(modules)
include_config_file(WrtAccess)
-pkg_search_module(wrt-plugin-api REQUIRED wrt-plugin-api>=0.7.0)
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
pkg_search_module(ace-client REQUIRED ace-client)
pkg_search_module(dpl-event REQUIRED dpl-event-efl)
+pkg_search_module(icu REQUIRED icu-i18n)
set(WRT_COMMONS_DEPENDECIES_INCLUDES
- ${INCLUDE_JS_INDEPENDENT}
${wrt-plugin-api_INCLUDE_DIRS}
${ace-client_INCLUDE_DIRS}
+ ${plugin-types_INCLUDE_DIRS}
+ ${icu_INCLUDE_DIRS}
)
include_directories(${WRT_COMMONS_DEPENDECIES_INCLUDES})
${CMAKE_CURRENT_SOURCE_DIR}/StringBuilder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/StringUtils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ThreadPool.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSObjectDeclaration.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSObject.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/TimeUtils.cpp
#PARENT_SCOPE
)
${LIBS_COMMONS}
${ace-client_LIBRARIES}
${dpl-event_LIBRARIES}
+ ${icu_LIBRARIES}
)
+
set_target_properties(${TARGET_NAME} PROPERTIES
SOVERSION ${CMAKE_PROJECT_API_VERSION}
VERSION ${CMAKE_PROJECT_VERSION}
install_header_file(TypesDeclaration.h)
install_header_file(TypeTraits.h)
install_header_file(plugin_initializer_def.h)
+install_header_file(JSObjectDeclaration.h)
+install_header_file(JSObject.h)
+install_header_file(TimeUtils.h)
install_wrtaccess_header_file(WrtAccess/WrtAccess.h)
void signalEventByDispatcher(const DPL::SharedPtr<TemplateEvent> &event)
{
LogDebug("in");
- DPL::Event::AbstractEventDispatcher *dispatcher =
- ThreadPool::getInstance().getDispatcher(m_threadDispatcher);
- dispatcher->AddEventCall(new SignalEventCall<TemplateEvent>(event));
+ Try {
+ DPL::Event::AbstractEventDispatcher *dispatcher =
+ ThreadPool::getInstance().getDispatcher(m_threadDispatcher);
+ dispatcher->AddEventCall(new SignalEventCall<TemplateEvent>(event));
+ }
+ Catch(DPL::Thread::Exception::UnmanagedThread) {
+ // if called on unmanaged thread,
+ // call signalSynchronousEventFlag() directly
+ LogDebug("signalSynchronousEventFlag() is called"
+ "by unmanaged thread");
+ event->signalSynchronousEventFlag();
+ }
}
virtual ~EventReceiver()
friend class EventRequestReceiver<Super>;
friend class EventAnswerReceiver<Super>;
friend class SignalEventCall<Super>;
+ friend class EventReceiver<Super>;
enum HandlingType
{
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef WRTDEVICEAPIS_FILESYSTEM_SYSTEM_H_
-#define WRTDEVICEAPIS_FILESYSTEM_SYSTEM_H_
-
-namespace WrtDeviceApis {
-namespace Filesystem {
+/**
+ * @file js_object.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
- class Command;
+#include "JSObject.h"
+#include <dpl/log/log.h>
-// TODO Refactor - make it a singleton.
-class System
+JSObject::JSObject(RealObject object) : m_object(object)
{
- public:
- static void run(Command* cmd);
-};
+ if (!object) {
+ LogError("Object is NULL");
+ }
+}
-} //Filesystem
-} //WrtDeviceApis
-
-#endif /* WRTDEVICEAPIS_FILESYSTEM_SYSTEM_H_ */
+JSObject::RealObject JSObject::getObject() const
+{
+ return m_object;
+}
* limitations under the License.
*/
/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ * @file js_object.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
*/
-#ifndef WRTDEVICEAPIS_FILESYSTEM_REMOVECOMMAND_H_
-#define WRTDEVICEAPIS_FILESYSTEM_REMOVECOMMAND_H_
+#ifndef WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_H_
+#define WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_H_
-#include "Command.h"
-#include <Filesystem/IPath.h>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
-namespace WrtDeviceApis {
-namespace Filesystem {
-
-class RemoveCommand : public Command
+class JSObject : private DPL::Noncopyable
{
public:
- explicit RemoveCommand(const Api::IPathPtr& path);
- void setRecursive(bool recursive);
- void setForce(bool force);
+ typedef void* RealObject;
+
+ public:
+ explicit JSObject(RealObject object);
+
+ /**
+ * returns javascript engine object
+ * @throw NullPtrException
+ * */
+ virtual RealObject getObject() const;
- protected:
- std::string prepare();
+ virtual ~JSObject()
+ {
+ }
private:
- Api::IPathPtr m_path;
- bool m_recursive;
- bool m_force;
+ RealObject m_object;
};
-} // Filesystem
-} // WrtDeviceApis
+typedef DPL::SharedPtr<JSObject> JSObjectPtr;
-#endif // WRTDEVICEAPIS_FILESYSTEM_REMOVECOMMAND_H_
+#endif
--- /dev/null
+/*
+ * 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 js_object_declaration.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include "JSObjectDeclaration.h"
+
+JSObjectDeclaration::JSObjectDeclaration(js_entity_definition_ptr_t classD) :
+ m_name(classD->object_name),
+ m_parentName(classD->parent_name),
+ m_interfaceName(classD->interface_name),
+ m_classTemplate(NULL),
+ m_constructorCallback(classD->js_class_constructor_cb)
+{
+ if (NULL != classD->js_class_template_getter_fun)
+ {
+ m_classTemplate = classD->js_class_template_getter_fun();
+ }
+ if(classD->class_options){
+ LogDebug("class options is not a null");
+ m_options = OptionsPtr(new Options(classD->class_options));
+ }
+}
+
+JSObjectDeclaration::~JSObjectDeclaration()
+{
+}
+
+bool JSObjectDeclaration::checkIframesSupported() const{
+ LogDebug("Check iframe supported");
+ if(!m_options ||
+ m_options->getIframeObject() == Options::IFrameObject::None)
+ {
+ LogDebug("Iframe NOT supported for object: " << getName());
+ return false;
+ }
+
+ LogDebug("Iframe supported for object: " << getName());
+
+ return true;
+}
+
+JSObjectDeclaration::Options::ClassType
+ JSObjectDeclaration::Options::getType() const
+{
+ LogDebug("Get type field from declaration's option");
+ Assert(m_options && "Pointer to options is NULL");
+
+ switch(m_options->type){
+ case JS_CLASS: return ClassType::Class;
+ case JS_FUNCTION: return ClassType::Function;
+ case JS_INTERFACE: return ClassType::Interface;
+ default: Assert(0 && "Wrong value of type");
+ }
+}
+
+JSObjectDeclaration::Options::IFrameObject
+ JSObjectDeclaration::Options::getIframeObject() const
+{
+ LogDebug("Get Frame Option");
+ Assert(m_options && "Options object is NULL");
+
+ switch(m_options->iframe_option){
+ case NONE: return IFrameObject::None;
+ case REFERENCE: return IFrameObject::Reference;
+ case CREATE_INSTANCE: return IFrameObject::CreateInstance;
+ default:
+ Assert(0 && "Wrong value of behaviour type");
+ }
+}
+
+JSObjectDeclaration::Options::IFrameNotice
+ JSObjectDeclaration::Options::getIframeNotice() const
+{
+ LogDebug("Get Frame Option");
+ Assert(m_options && "Pointer to options is null");
+
+ switch(m_options->iframe_notice){
+ case NONE_NOTICE: return IFrameNotice::None;
+ case ALWAYS_NOTICE: return IFrameNotice::AlwaysNotice;
+ default:
+ Assert(0 && "Wrong value of notice option");
+ }
+}
+
+JSObjectDeclaration::Options::IFrameOverlay
+ JSObjectDeclaration::Options::getIframeOverlay() const
+{
+ LogDebug("Get Frame Option");
+ Assert(m_options && "Pointer to options is null");
+
+ switch(m_options->iframe_overlay){
+ case IGNORED: return IFrameOverlay::Ignored;
+ case USE_OVERLAYED: return IFrameOverlay::UseOverlayed;
+ case OVERLAYED_BEFORE_ORIGINAL:
+ return IFrameOverlay::OverlayedBeforeOriginal;
+ default:
+ Assert(0 && "Wrong value of overlay option");
+ }
+}
+
+js_function_impl JSObjectDeclaration::Options::getFunctionImpl() const
+{
+ Assert(m_options && "Pointer to options is null");
+ return m_options->function;
+}
+
+void JSObjectDeclaration::Options::invokeCallback(JsContext ctx,
+ ObjectInstance iframe,
+ ObjectInstance object) const
+{
+ LogDebug("JS Object create, notice.");
+ Assert(m_options && m_options->cb && "Empty callback pointer");
+ m_options->cb(ctx, iframe, object);
+}
+
+JSObjectDeclaration::Options::PrivateData
+ JSObjectDeclaration::Options::getPrivateData() const
+{
+ Assert(m_options && m_options->private_data && "empty private data");
+ return m_options->private_data;
+}
--- /dev/null
+/*
+ * 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 js_object_declaration.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
+#define WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
+
+#include <string>
+#include <memory>
+#include <cassert>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <dpl/log/log.h>
+#include <wrt_plugin_export.h>
+
+class JSObjectDeclaration : private DPL::Noncopyable
+{
+ public:
+ typedef const void* ConstClassTemplate;
+ typedef void* ClassTemplate;
+ typedef js_class_constructor_cb_t ConstructorCallback;
+ typedef class_definition_options_t ClassOptions;
+
+
+ class Options : DPL::Noncopyable {
+ public:
+ enum class ClassType{
+ Class,
+ Function,
+ Interface
+ };
+
+ enum class IFrameObject{
+ None,
+ Reference,
+ CreateInstance
+ };
+
+ enum class IFrameNotice{
+ None,
+ AlwaysNotice
+ };
+
+ //only for function
+ enum class IFrameOverlay{
+ Ignored,
+ UseOverlayed,
+ OverlayedBeforeOriginal
+ };
+
+ typedef js_object_instance_t ObjectInstance;
+ typedef java_script_context_t JsContext;
+ typedef void* PrivateData;
+
+ public:
+ ClassType getType() const;
+
+ IFrameObject getIframeObject() const;
+ IFrameNotice getIframeNotice() const;
+ IFrameOverlay getIframeOverlay() const;
+ js_function_impl getFunctionImpl() const;
+
+ void invokeCallback(JsContext ctx,
+ ObjectInstance iframe,
+ ObjectInstance object) const;
+
+ PrivateData getPrivateData() const;
+
+ private:
+ const ClassOptions* m_options;
+
+ private:
+ explicit Options(const ClassOptions* options) : m_options(options)
+ {
+ assert(options && "Dont create empty options");
+ }
+
+ friend class JSObjectDeclaration;
+
+ };
+
+ typedef std::shared_ptr<Options> OptionsPtr;
+
+ public:
+
+ explicit JSObjectDeclaration(js_entity_definition_ptr_t declaration);
+
+ virtual const std::string& getName() const
+ {
+ return m_name;
+ }
+
+ virtual const std::string& getParentName() const
+ {
+ return m_parentName;
+ }
+
+ virtual ConstClassTemplate getClassTemplate() const
+ {
+ return m_classTemplate;
+ }
+
+ virtual const std::string& getInterfaceName() const
+ {
+ return m_interfaceName;
+ }
+
+ virtual ConstructorCallback getConstructorCallback() const
+ {
+ return m_constructorCallback;
+ }
+
+
+ const OptionsPtr getOptions() const{
+ return m_options;
+ }
+
+ bool checkIframesSupported() const;
+
+ virtual ~JSObjectDeclaration();
+
+ private:
+ std::string m_name;
+ std::string m_parentName;
+ std::string m_interfaceName;
+ ConstClassTemplate m_classTemplate;
+ ConstructorCallback m_constructorCallback;
+ OptionsPtr m_options;
+};
+
+typedef DPL::SharedPtr<JSObjectDeclaration> JSObjectDeclarationPtr;
+
+#endif
#include <algorithm>
#include <iterator>
#include <new>
-#include <sstream>
-#include <Commons/Exception.h>
#include "StringUtils.h"
namespace WrtDeviceApis {
}
std::string merge(const std::vector<std::string>& strs,
- std::string::value_type delim)
+ std::string::value_type delim)
{
typedef std::vector<std::string> Strings;
return result;
}
-int toInt(const std::string &text)
+int toInt(const std::string& str)
{
- int result;
- std::stringstream ss(text);
- if (!(ss >> result)) {
- Throw(ConversionException);
- }
- return result;
+ return convertTo<int>(str);
}
}
}
-} // WrtDeviceApisCommon
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+/**
+ * @file StringUtils.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
#ifndef WRTDEVICEAPIS_COMMONS_STRINGUTILS_H_
#define WRTDEVICEAPIS_COMMONS_STRINGUTILS_H_
#include <string>
#include <vector>
+#include <sstream>
+#include <utility>
+#include <Commons/Exception.h>
+#include <Commons/Deprecated.h>
namespace WrtDeviceApis {
namespace Commons {
* @param startStr String to be found at the beginning of str.
* @return true when str starts with startStr, false otherwise.
*/
-bool startsWith(const std::string& str,
- const std::string& startStr);
+bool startsWith(const std::string& str, const std::string& startStr);
/**
* Checks if str ends with startStr
* @param endStr String to be found at the end of str.
* @return true when str starts with startStr, false otherwise.
*/
-bool endsWith(const std::string& str,
- const std::string& endStr);
+bool endsWith(const std::string& str, const std::string& endStr);
/**
* Merges consecutive groups of duplicate characters into one.
* ...
* @endcode
*/
-std::string unique(const std::string& str,
- const char needle);
+std::string unique(const std::string& str, const char needle);
/**
* Checks if supplied string exists in specified array of c-strings.
* @remarks Last element of array should be NULL, otherwise there is no
* way to calculate its number of elements.
*/
-bool inCStringArray(const std::string& needle,
- const char* stack[]);
+bool inCStringArray(const std::string& needle, const char* stack[]);
/**
* Duplicates a string.
}
std::string merge(const std::vector<std::string>& strs,
- std::string::value_type delim);
+ std::string::value_type delim);
std::vector<std::string> split(const std::string& str,
- std::string::value_type delim);
+ std::string::value_type delim);
-int toInt(const std::string &text);
+/**
+ * @deprecated Use convertTo<int>().
+ */
+int toInt(const std::string& str) WRT_PLUGINS_DEPRECATED;
-} // String
+/**
+ * Converts string to specified type.
+ *
+ * @tparam T Type to convert to.
+ * @param str String to convert.
+ * @return Converted value.
+ * @throw ConversionException If conversion fails.
+ *
+ * @remarks T must implement default constructor and an implementation
+ * of input string operator for T must exist.
+ */
+template<typename T>
+T convertTo(const std::string& str)
+{
+ T result;
+ std::istringstream iss(str);
+ if (!(iss >> result)) {
+ Throw(ConversionException);
+ }
+ return std::move(result);
+}
+
+/**
+ * Converts a given value to string.
+ *
+ * @tparam T Type of the value to convert. It is deduced by the compiler.
+ * @param data Value to convert.
+ * @return Value converted to string.
+ * @throw ConversionException If operation fails.
+ *
+ * @remarks Output stream operator for type T must exist.
+ */
+template<typename T>
+std::string parse(const T& data)
+{
+ std::ostringstream oss;
+ if (!(oss << data))
+ {
+ Throw(ConversionException);
+ }
+ return oss.str();
+}
+
+}
+}
}
-} // WrtDeviceApisCommon
-#endif // WRTDEVICEAPIS_COMMONS_STRINGUTILS_H_
+#endif
case ThreadEnum::MEDIACONTENT_THREAD:
thandle = getThreadHandleCreateIfNotExists(ThreadEnum::MEDIACONTENT_THREAD);
break;
+ case ThreadEnum::SE_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::SE_THREAD);
+ break;
// .....
default:
LogError("no case statement for ThreadEnum");
ACCOUNT_THREAD,
NFC_THREAD,
MEDIACONTENT_THREAD,
+ SE_THREAD,
+ DOWNLOAD_THREAD,
//....
size
};
--- /dev/null
+/*
+ * 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 TimeUtils.h
+ * @author Tae-Jeong Lee (taejeong.lee@samsung.com)
+ */
+
+#include "TimeUtils.h"
+#include <unicode/ucal.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+namespace Time {
+
+struct tm* localtime_r(long long int* timep, struct tm* result)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ UCalendar *cal;
+
+ if( !result || !timep )
+ {
+ return NULL;
+ }
+
+ cal = ucal_open(NULL, 0, NULL, UCAL_DEFAULT, &status);
+
+ if(U_FAILURE(status))
+ {
+ return NULL;
+ }
+
+ ucal_setMillis(cal, (*timep * (double)1000.0), &status);
+
+ result->tm_sec = ucal_get(cal, UCAL_SECOND, &status);
+ result->tm_min = ucal_get(cal, UCAL_MINUTE, &status);
+ result->tm_hour = ucal_get(cal, UCAL_HOUR, &status);
+ result->tm_mday = ucal_get(cal, UCAL_DAY_OF_MONTH, &status);
+ result->tm_mon = ucal_get(cal, UCAL_MONTH, &status);
+ result->tm_year = ucal_get(cal, UCAL_YEAR, &status);
+ result->tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
+ result->tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status);
+ result->tm_isdst= ucal_get(cal, UCAL_DST_OFFSET, &status);
+
+ ucal_close(cal);
+
+ if(U_FAILURE(status))
+ {
+ return NULL;
+ }
+ else
+ {
+ return result;
+ }
+}
+
+}
+}
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "System.h"
-#include <stdlib.h>
-#include <string.h>
-#include "Command.h"
+/**
+ * @file TimeUtils.h
+ * @author Tae-Jeong Lee (taejeong.lee@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_TIMEUTILS_H_
+#define WRTDEVICEAPIS_COMMONS_TIMEUTILS_H_
+
+#include <time.h>
namespace WrtDeviceApis {
-namespace Filesystem {
+namespace Commons {
+namespace Time {
-void System::run(Command* cmd)
-{
- cmd->execute();
-}
+struct tm* localtime_r(long long int* timep, struct tm* result);
-} // Filesystem
-} // WrtDeviceApis
+}
+}
+}
+#endif
*/
#include <memory>
+#include <sstream>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
#include <dpl/log/log.h>
#include <dpl/scoped_array.h>
#include <dpl/scoped_resource.h>
#include <dpl/assert.h>
-#include <wrt_plugin_export.h>
#include <Commons/Exception.h>
#include "WrtAccess.h"
-#include <ace-client/ace_client.h>
-#include <dpl/singleton_impl.h>
+#include <ace_api_client.h>
+#include <dpl/singleton_safe_impl.h>
-IMPLEMENT_SINGLETON(WrtDeviceApis::Commons::WrtAccess)
+IMPLEMENT_SAFE_SINGLETON(WrtDeviceApis::Commons::WrtAccess)
-namespace WrtDeviceApis {
-namespace Commons {
+namespace {
+
+/**
+ * Helper class - single parameter and its value
+ */
+struct AceParam
+{
+ const char *name;
+ const char *value;
+
+ AceParam():
+ name(NULL), value(NULL)
+ {}
+
+ AceParam(const char *name, const char *value):
+ name(name), value(value)
+ {}
+};
+
+/**
+ * Helper class - list of params for single dev cap
+ */
+struct AceParamList
+{
+ size_t count;
+ AceParam* param;
+ AceParamList():
+ count(0),
+ param(NULL)
+ {}
+};
struct DeviceCapParamPolicy
{
- typedef AceClient::AceParamList* Type;
+ typedef AceParamList* Type;
static Type NullValue()
{
return NULL;
class ScopedDeviceCapArray : public DPL::ScopedResource<DeviceCapParamPolicy>
{
public:
- explicit ScopedDeviceCapArray(AceClient::AceParamList *ptr =
+ explicit ScopedDeviceCapArray(AceParamList *ptr =
DeviceCapParamPolicy::NullValue()) :
DPL::ScopedResource<DeviceCapParamPolicy>(ptr)
{
}
- AceClient::AceParamList & operator [](std::ptrdiff_t k) const
+ AceParamList & operator [](std::ptrdiff_t k) const
{
Assert(this->m_value != DeviceCapParamPolicy::NullValue() &&
"Dereference of scoped NULL array!");
return this->m_value[k];
}
};
+} // namespace
+
+namespace WrtDeviceApis {
+namespace Commons {
-WrtAccess::WrtAccess()
+WrtAccess::WrtAccess() :
+ m_initialized(false),
+ m_sessionId(GenerateSessionId())
{
- DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
}
WrtAccess::~WrtAccess()
{
}
+WrtAccess::SessionId WrtAccess::GenerateSessionId()
+{
+ const size_t SESSION_ID_LENGTH = 32;
+
+ std::ostringstream pid;
+ pid << static_cast<int> (getpid());
+
+ std::string session_id = pid.str();
+
+ session_id.reserve(session_id.length() + SESSION_ID_LENGTH);
+
+ for (size_t i = 0; i < SESSION_ID_LENGTH; ++i)
+ {
+ int c = random() % 16;
+
+ session_id += (c < 10 ?
+ static_cast<char>('0' + c) :
+ static_cast<char>('A' + c - 10));
+ }
+ return session_id;
+}
+
void WrtAccess::initialize(int widgetId)
{
LogDebug("initialize");
-
if (widgetId < 0)
{
LogDebug("Invalid widget id");
Throw(Exception);
}
-
+ // TODO: implement UI handler
+ ace_return_t ret = ace_client_initialize(NULL);
+ // Assert(ACE_OK == ret); // This is commented because UI handler is not
+ // implemented, ace client will work, but initialization will return
+ // ACE_INVALID_ARGUMENTS
+ m_initialized = true;
m_widgetId = widgetId;
}
-void WrtAccess::deinitialize(int widgetId)
+void WrtAccess::deinitialize(int /*widgetId*/)
{
LogDebug("deinitialize");
+ m_initialized = false;
+ ace_return_t ret = ace_client_shutdown();
+ Assert(ACE_OK == ret);
}
int WrtAccess::getWidgetId() const
bool WrtAccess::checkAccessControl(const AceFunction& aceFunction) const
{
+ Assert(m_initialized && "WrtAccessSingleton needs to be initialized with"
+ "WidgetId during on_widget_start_callback in each plugin");
size_t deviceCount = aceFunction.deviceCapabilities.size();
DPL::ScopedArray <const char *> deviceScopedArray;
if (deviceCount) {
deviceScopedArray.Reset(new const char*[deviceCount]);
- paramsScopedArray.Reset(new AceClient::AceParamList[deviceCount]);
+ paramsScopedArray.Reset(new AceParamList[deviceCount]);
for (size_t i = 0; i < deviceCount; ++i) {
deviceScopedArray[i] =
aceFunction.deviceCapabilities.at(i).devCapParams.size();
paramsScopedArray[i].param =
- new AceClient::AceParam[paramsScopedArray[i].count];
+ new AceParam[paramsScopedArray[i].count];
for (size_t j = 0; j < paramsScopedArray[i].count; ++j) {
paramsScopedArray[i].param[j].name =
}
}
- AceClient::AceRequest aceRequest;
- aceRequest.sessionId = ""; // TODO for now empty session
- aceRequest.widgetHandle = getWidgetId();
- aceRequest.apiFeatures.count = featuresCount;
- aceRequest.apiFeatures.apiFeature = featureScopedArray.Get();
- aceRequest.functionName = aceFunction.name.c_str();
- aceRequest.deviceCapabilities.devcapsCount = deviceCount;
- aceRequest.deviceCapabilities.devCapNames = deviceScopedArray.Get();
- aceRequest.deviceCapabilities.paramsCount = deviceCount;
- aceRequest.deviceCapabilities.params = paramsScopedArray.Get();
-
- return AceClient::AceThinClientSingleton::
- Instance().checkFunctionCall(aceRequest);
+ LogDebug("constructing ACE request");
+
+ ace_request_t aceRequest;
+ aceRequest.session_id = const_cast<const ace_session_id_t>(m_sessionId.c_str());
+ aceRequest.widget_handle = getWidgetId();
+ aceRequest.feature_list.count = featuresCount;
+ aceRequest.feature_list.items = const_cast<ace_string_t*>(featureScopedArray.Get());
+ aceRequest.dev_cap_list.count = deviceCount;
+ aceRequest.dev_cap_list.items = new ace_dev_cap_t[deviceCount];
+
+ const char** devCapNames = deviceScopedArray.Get();
+ AceParamList* paramList = paramsScopedArray.Get();
+
+ unsigned int i;
+ for (i = 0; i < deviceCount; ++i) {
+ aceRequest.dev_cap_list.items[i].name =
+ const_cast<const ace_string_t>(devCapNames[i]);
+ aceRequest.dev_cap_list.items[i].param_list.count = paramList[i].count;
+ aceRequest.dev_cap_list.items[i].param_list.items =
+ new ace_param_t[paramList[i].count];
+ unsigned int j;
+ for (j = 0; j < paramList[i].count; ++j) {
+ aceRequest.dev_cap_list.items[i].param_list.items[j].name =
+ const_cast<ace_string_t>(paramList[i].param[j].name);
+ aceRequest.dev_cap_list.items[i].param_list.items[j].value =
+ const_cast<ace_string_t>(paramList[i].param[j].value);
+ }
+ }
+
+ ace_bool_t aceCheckResult = ACE_FALSE;
+ ace_return_t ret = ace_check_access(&aceRequest, &aceCheckResult);
+
+ for (i = 0; i < deviceCount; ++i) {
+ delete [] aceRequest.dev_cap_list.items[i].param_list.items;
+ }
+ delete [] aceRequest.dev_cap_list.items;
+
+ if (ACE_OK != ret) {
+ LogError("Error in ace check: " << static_cast<int>(ret));
+ return false;
+ }
+ return ACE_TRUE == aceCheckResult;
}
}
#ifndef WRT_PLUGINS_WRT_ACCESS_H_
#define WRT_PLUGINS_WRT_ACCESS_H_
+#include <string>
+
#include <dpl/singleton.h>
#include <Commons/TypesDeclaration.h>
bool checkAccessControl(const AceFunction &aceFunction) const;
private:
+
+ typedef std::string SessionId;
+ SessionId GenerateSessionId();
+
WrtAccess();
virtual ~WrtAccess();
bool m_initialized;
int m_widgetId;
+ SessionId m_sessionId;
friend class DPL::Singleton<WrtAccess>;
};
#define PLUGIN_ON_WIDGET_START(CALLBACK_NAME) extern "C" const on_widget_start_proc PLUGIN_WIDGET_START_PROC EXPORT_SYMBOL = CALLBACK_NAME;
/*
+ * You have to(!) call this macro in your plugin_initializer.cpp(!) file
+ * providing callback that will be called while loading each widget
+ * (for every loaded widget this function will be called)
+ * Example:
+ * plugin_initializer.cpp
+ * void on_widget_init_callback(feature_mapping_interface_t *mapping)
+ * {
+ * //...
+ * }
+ * PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
+ */
+#define PLUGIN_ON_WIDGET_INIT(CALLBACK_NAME) extern "C" \
+const on_widget_init_proc PLUGIN_WIDGET_INIT_PROC EXPORT_SYMBOL = CALLBACK_NAME;
+
+/*
* You have to(!) call this macro in your plugin_initializer.cpp(!) file providing callback that will be called while unloading each widget (for every unloaded widget this function will be called)
* Example:
* void on_widget_stop_callback(int widgetId)
#define PLUGIN_ON_WIDGET_STOP(CALLBACK_NAME) extern "C" const on_widget_stop_proc PLUGIN_WIDGET_STOP_PROC EXPORT_SYMBOL = CALLBACK_NAME;
/*
+ * You have to(!) call this macro in your plugin_initializer.cpp(!) file providing callback that will be called while unloading each page (for every loaded page, including nested page, this function will be called)
+ * Example:
+ * void on_frame_load_callback(java_script_context_t context)
+ * {
+ * //...
+ * }
+ * PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
+ */
+#define PLUGIN_ON_FRAME_LOAD(CALLBACK_NAME) extern "C" const on_frame_load_proc PLUGIN_FRAME_LOAD_PROC EXPORT_SYMBOL = CALLBACK_NAME;
+
+/*
+ * You have to(!) call this macro in your plugin_initializer.cpp(!) file providing callback that will be called while ununloading each page (for every unloaded page, including nested page, this function will be called)
+ * Example:
+ * void on_frame_unload_callback(java_script_context_t context)
+ * {
+ * //...
+ * }
+ * PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
+ */
+#define PLUGIN_ON_FRAME_UNLOAD(CALLBACK_NAME) extern "C" const on_frame_unload_proc PLUGIN_FRAME_UNLOAD_PROC EXPORT_SYMBOL = CALLBACK_NAME;
+
+/*
* You have to(!) define an array of structures in your plugin_initializer.cpp(!) file describing a JS class (class_definition) and it's parent class name (parent_name).
* JS class will be bind to a parent class name (parent_name.jsclass_name).
* Example:
* PLUGIN_CLASS_MAP_END
*
*/
-#define PLUGIN_CLASS_MAP_BEGIN extern "C" const class_definition_t PLUGIN_CLASS_MAP[] EXPORT_SYMBOL = {
-#define PLUGIN_CLASS_MAP_ADD_CLASS(PARENTNAME,CLASSNAME,JSCLASSTEMPLATE,PRIVDATA) {PARENTNAME,CLASSNAME,JSCLASSTEMPLATE,PRIVDATA},
-#define PLUGIN_CLASS_MAP_END {NULL,NULL,NULL,NULL} };
+#define PLUGIN_CLASS_MAP_BEGIN extern "C" const js_entity_definition_t\
+ PLUGIN_CLASS_MAP[] EXPORT_SYMBOL = {
+
+#define PLUGIN_CLASS_MAP_ADD_INTERFACE(PARENTNAME,INTERFACENAME,\
+ JSPRODUCTCLASSTEMPLATE,PRODUCTCONSTRUCTORCB,PRIVDATA) \
+ {PARENTNAME,INTERFACENAME,"",JSPRODUCTCLASSTEMPLATE,\
+ PRODUCTCONSTRUCTORCB,PRIVDATA},
+
+#define PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(PARENTNAME,OBJECTNAME,\
+ INTERFACENAME,PRIVDATA)\
+ {PARENTNAME,OBJECTNAME,INTERFACENAME,NULL,NULL,PRIVDATA},
+
+#define PLUGIN_CLASS_MAP_ADD_CLASS(PARENTNAME,CLASSNAME,JSCLASSTEMPLATE,\
+ PRIVDATA)\
+ {PARENTNAME,CLASSNAME,"",JSCLASSTEMPLATE,NULL,PRIVDATA},
+
+#define PLUGIN_CLASS_MAP_END {NULL,NULL,NULL,NULL,NULL,NULL} };
+
+#define PLUGIN_CLASS_MAP_BEGIN_STATIC static const js_entity_definition_t\
+ PLUGIN_CLASS_MAP[] = {
-#define PLUGIN_CLASS_MAP_BEGIN_STATIC static const class_definition_t PLUGIN_CLASS_MAP[] = {
-#define PLUGIN_GET_CLASS_MAP(CALLBACK_NAME) extern "C" const get_widget_class_map_proc PLUGIN_GET_CLASS_PROC_MAP EXPORT_SYMBOL = CALLBACK_NAME;
+#define PLUGIN_GET_CLASS_MAP(CALLBACK_NAME) extern "C" const\
+ get_widget_entity_map_proc\
+ PLUGIN_GET_CLASS_PROC_MAP EXPORT_SYMBOL = CALLBACK_NAME;
#endif // WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_H_
endmacro()
-#TODO fix it
-pkg_search_module(wrt-plugin-api REQUIRED wrt-plugin-api>=1.1.1)
-pkg_search_module(webkit REQUIRED ewebkit>=0.1.0)
+pkg_search_module(webkit2 REQUIRED ewebkit2)
set(TARGET_NAME ${TARGET_COMMONS_JAVASCRIPT})
include_directories(${DIR_JS_COMMONS}
- ${INCLUDE_JS_INDEPENDENT}
${wrt-plugin-api_INCLUDE_DIRS}
- ${webkit_INCLUDE_DIRS}}
+ ${webkit2_INCLUDE_DIRS}}
)
add_library(${TARGET_NAME} SHARED ${SRCS})
target_link_libraries(${TARGET_NAME}
${LIBS_COMMONS}
- ${webkit_LIBRARIES}
+ ${webkit2_LIBRARIES}
${TARGET_COMMONS}
)
-set_target_properties(${TARGET_NAME} PROPERTIES
+set_target_properties(${TARGET_NAME} PROPERTIES
SOVERSION ${CMAKE_PROJECT_API_VERSION}
VERSION ${CMAKE_PROJECT_VERSION}
)
return JSValueMakeNumber(m_context, arg);
}
+JSValueRef Converter::toJSValueRef(long long int arg)
+{
+ return JSValueMakeNumber(m_context, arg);
+}
+
JSValueRef Converter::toJSValueRef(double arg)
{
return JSValueMakeNumber(m_context, arg);
JSValueRef exception = NULL;
JSStringRef str = JSValueToStringCopy(m_context, arg, &exception);
- if ((NULL == str) || (NULL != exception)) {
+ if (NULL == str) {
ThrowMsg(ConversionException, "Couldn't cast to a string.");
}
size_t jsSize = JSStringGetMaximumUTF8CStringSize(str);
if (jsSize > 0) {
- jsSize = jsSize + 1;
DPL::ScopedArray<char> buffer(new char[jsSize]);
- size_t written = JSStringGetUTF8CString(str, buffer.Get(), jsSize);
- if (written > jsSize) {
- JSStringRelease(str);
- ThrowMsg(ConversionException,
- "Conversion could not be fully performed.");
- }
+ JSStringGetUTF8CString(str, buffer.Get(), jsSize);
result = buffer.Get();
}
JSStringRelease(str);
*/
JSValueRef toJSValueRefLong(const long arg);
+ /**
+ * Converts unsigned long value to JSValueRef.
+ * @param arg long long int value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(long long int arg);
+
/**
* Converts STL string to JSValueRef.
* @param arg STL string to convert.
JSObjectRef onError) :
m_onSuccess(NULL),
m_onError(NULL),
+ m_object(NULL),
m_context(context)
{
LogDebug("entered");
if (m_onError) {
JSValueUnprotect(m_context, m_onError);
}
+
+ if (m_object) {
+ JSValueUnprotect(m_context, m_object);
+ }
}
void JSCallbackManager::setOnSuccess(JSValueRef onSuccess)
{
LogDebug("entered");
- if (onSuccess) {
- if (m_onSuccess != NULL) {
- JSValueUnprotect(m_context, m_onSuccess);
- }
+ if (m_onSuccess != NULL) {
+ JSValueUnprotect(m_context, m_onSuccess);
+ }
+ if (onSuccess) {
m_onSuccess = JSValueToObject(m_context, onSuccess, NULL);
+ } else {
+ m_onSuccess = NULL;
+ }
- if (m_onSuccess != NULL) {
- JSValueProtect(m_context, m_onSuccess);
- }
+ if (m_onSuccess != NULL) {
+ JSValueProtect(m_context, m_onSuccess);
}
}
void JSCallbackManager::setOnError(JSValueRef onError)
{
LogDebug("entered");
- if (onError) {
- if (m_onError != NULL) {
- JSValueUnprotect(m_context, m_onError);
- }
+ if (m_onError != NULL) {
+ JSValueUnprotect(m_context, m_onError);
+ }
+ if (onError) {
m_onError = JSValueToObject(m_context, onError, NULL);
+ } else {
+ m_onError = NULL;
+ }
- if (m_onError != NULL) {
- JSValueProtect(m_context, m_onError);
- }
+ if (m_onError != NULL) {
+ JSValueProtect(m_context, m_onError);
}
}
return m_onError;
}
+void JSCallbackManager::setObject(JSObjectRef object)
+{
+ LogDebug("entered");
+ if (m_object != NULL) {
+ JSValueUnprotect(m_context, m_object);
+ }
+
+ m_object = object;
+
+ if (m_object != NULL) {
+ JSValueProtect(m_context, m_object);
+ }
+}
+
+JSObjectRef JSCallbackManager::getObject() const
+{
+ LogDebug("entered");
+ return m_object;
+}
+
void JSCallbackManager::setContext(JSContextRef context)
{
LogDebug("entered");
JSValueRef getOnSuccess() const;
void setOnError(JSValueRef onError);
JSValueRef getOnError() const;
+ void setObject(JSObjectRef object);
+ JSObjectRef getObject() const;
void callOnSuccess();
void callOnSuccess(JSValueRef obj);
#include <map>
#include <vector>
#include <string>
+#include <string.h>
#include <dpl/noncopyable.h>
#include <dpl/assert.h>
#include <dpl/foreach.h>
#include <Commons/TypesDeclaration.h>
-
+#include <wrt-commons/wrt_plugin_export.h>
namespace WrtDeviceApis {
namespace CommonsJavaScript {
}
}
+ static feature_mapping_t* getFeaturesToDevCapMapping()
+ {
+ feature_mapping_t* mapping = new feature_mapping_t;
+
+ mapping->featuresCount = m_features.size();
+ mapping->features = new feature_devcaps_t[mapping->featuresCount];
+
+ size_t i = 0;
+
+ FOREACH(featureIt, m_features)
+ {
+ mapping->features[i].feature_name =
+ strndup(featureIt->first.c_str(), featureIt->first.size() + 1);
+
+ mapping->features[i].devCaps.devCapsCount =
+ featureIt->second.size();
+
+ mapping->features[i].devCaps.deviceCaps =
+ new char*[mapping->features[i].devCaps.devCapsCount];
+
+ for (size_t j = 0;
+ j < mapping->features[i].devCaps.devCapsCount;
+ ++j)
+ {
+ std::string dc = getDevCapNameById(featureIt->second[j]);
+
+ mapping->features[i].devCaps.deviceCaps[j] =
+ strndup(dc.c_str(), dc.size() + 1);
+ }
+
+ ++i;
+ }
+
+ return mapping;
+ }
+
+ static const devcaps_t* devcapsGetter(pfeature_mapping_t feats,
+ const char* featureName)
+ {
+ Assert(featureName && "Trying to extract info about NULL api feature");
+
+ std::string feature(featureName);
+
+ devcaps_t* ret = NULL;
+
+ for (size_t i = 0; i < feats->featuresCount ; ++i)
+ {
+ Assert(feats->features &&
+ feats->features[i].feature_name &&
+ "NULL api feature in feature mapping");
+
+ std::string feat(feats->features[i].feature_name);
+
+ if (feature == feat)
+ {
+ ret = &(feats->features[i].devCaps);
+ break;
+ }
+ }
+
+ return ret;
+ }
+
+ static void featuresDeinitializer(feature_mapping_t* mapping)
+ {
+ if (mapping)
+ {
+ if (mapping->features)
+ {
+ for (size_t i = 0; i < mapping->featuresCount; ++i)
+ {
+ free(mapping->features[i].feature_name);
+
+ devcaps_t& dc = mapping->features[i].devCaps;
+
+ if (dc.deviceCaps)
+ {
+ for (size_t j = 0; j < dc.devCapsCount; ++j)
+ {
+ free(dc.deviceCaps[j]);
+ }
+
+ delete []dc.deviceCaps;
+ }
+ }
+ delete []mapping->features;
+ }
+ delete mapping;
+ }
+ }
+
+ static void getMappingInterface(feature_mapping_interface_t *mapping)
+ {
+ if (mapping)
+ {
+ mapping->featGetter =
+ StaticDeclarations::getFeaturesToDevCapMapping;
+ mapping->dcGetter = StaticDeclarations::devcapsGetter;
+ mapping->release = StaticDeclarations::featuresDeinitializer;
+ }
+ }
+
private:
static ParamsMap m_params;
static DeviceCapsMaps m_deviceCaps;
--- /dev/null
+# 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 Yunchan Cho (yunchan.cho@samsung.com)
+# @version 1.0
+#
+MACRO(INSTALL_HEADER_FILE HEADER_FILE)
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADERS_JS_OVERLAY})
+ENDMACRO()
+
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
+
+SET(TARGET_NAME ${TARGET_JS_OVERLAY})
+
+SET(SRCS
+ ${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_support.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/js_function_manager.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_addEventListener.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_functions.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/js_iframe_support.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSStorageEvent.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSTizenServiceEvent.cpp
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSClass
+ ${webkit2_INCLUDE_DIRS}
+ ${plugin-types_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ ${webkit2_LIBRARIES}
+ ${TARGET_COMMONS}
+ ${TARGET_COMMONS_JAVASCRIPT}
+ wrt-plugins-tizen-service-event
+)
+
+SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ COMPILE_FLAGS -fPIC
+ LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+INSTALL(TARGETS ${TARGET_NAME}
+ DESTINATION ${DESTINATION_LIB_PREFIX}
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+)
+
+INSTALL_HEADER_FILE(js_overlay_types.h)
+
#include <StorageEvent/IStorageEvent.h>
#include <CommonsJavaScript/Converter.h>
#include <CommonsJavaScript/JSDOMExceptionFactory.h>
-#include "JSPreferences.h"
using namespace WrtDeviceApis;
using namespace WrtDeviceApis::Commons;
--- /dev/null
+/*
+ * 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 JSTizenServiceEvent.cpp
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ */
+
+#include "JSTizenServiceEvent.h"
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::TizenServiceEvent::Api;
+
+#define WIDGET_PLUGIN_NAME "TizenServiceEvent"
+
+#define TIZEN_SERVICE_EVENT_PROPERTY_SCALE "scale"
+#define TIZEN_SERVICE_EVENT_PROPERTY_BUNDLE "__bundle"
+
+#define CATCH_EXCEPTION_CONVERSION \
+ Catch(Commons::ConversionException) {\
+ LogError("Error on conversion");\
+ return JSDOMExceptionFactory::\
+ UnknownException.make(context, exception);\
+ }
+
+#define CATCH_EXCEPTION_NULL_PTR \
+ Catch(Commons::NullPointerException) {\
+ LogError("Error on pointer, null value");\
+ return JSDOMExceptionFactory::\
+ UnknownException.make(context, exception);\
+ }
+
+#define CATCH_EXCEPTION_PLATFORM_ERROR \
+ Catch(Commons::PlatformException){\
+ LogError("PlatformException occured");\
+ return JSDOMExceptionFactory::\
+ UnknownException.make(context, exception);\
+ }
+
+#define CATCH_EXCEPTION_SECURITY \
+ Catch(Commons::SecurityException){\
+ LogError("Security exception occured");\
+ return JSDOMExceptionFactory::\
+ SecurityException.make(context, exception);\
+ }
+
+namespace WrtPlugins {
+namespace Tizen {
+JSClassDefinition JSTizenServiceEvent::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ WIDGET_PLUGIN_NAME,
+ 0,
+ m_property,
+ NULL,
+ initialize,
+ finalize,
+ NULL, //HasProperty,
+ NULL, //GetProperty,
+ NULL, //SetProperty,
+ NULL, //DeleteProperty,
+ NULL, //GetPropertyNames,
+ NULL, //CallAsFunction,
+ NULL, //CallAsConstructor,
+ NULL, //HasInstance,
+ NULL, //ConvertToType,
+};
+
+JSStaticValue JSTizenServiceEvent::m_property[] = {
+ { TIZEN_SERVICE_EVENT_PROPERTY_SCALE, JSTizenServiceEvent::getScale,
+ 0, kJSPropertyAttributeReadOnly },
+ { TIZEN_SERVICE_EVENT_PROPERTY_BUNDLE, JSTizenServiceEvent::getBundle,
+ 0, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSTizenServiceEvent::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSTizenServiceEvent::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+JSClassRef JSTizenServiceEvent::m_jsClassRef = JSClassCreate(JSTizenServiceEvent::getClassInfo());
+
+void JSTizenServiceEvent::initialize(JSContextRef context,
+ JSObjectRef object)
+{
+ LogDebug("entered");
+
+ JSTizenServiceEventPrivateObject* priv =
+ static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(object));
+
+ Assert(priv && "Missing private object");
+}
+
+void JSTizenServiceEvent::finalize(JSObjectRef object)
+{
+ LogDebug("entered");
+ JSTizenServiceEventPrivateObject* priv =
+ static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(object));
+
+ delete priv;
+ LogDebug("private object is realised");
+
+}
+
+JSValueRef JSTizenServiceEvent::getScale(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ LogDebug("entered");
+
+ Try
+ {
+ Converter converter(context);
+ return converter.toJSValueRef(getPrivateObject(object)->getScale());
+ }
+ CATCH_EXCEPTION_CONVERSION
+ CATCH_EXCEPTION_NULL_PTR
+ CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSTizenServiceEvent::getBundle(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ LogDebug("entered");
+
+ Try
+ {
+ Converter converter(context);
+ return converter.toJSValueRef(getPrivateObject(object)->getBundle());
+ }
+ CATCH_EXCEPTION_CONVERSION
+ CATCH_EXCEPTION_NULL_PTR
+ CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_SECURITY
+}
+
+ITizenServiceEventPtr JSTizenServiceEvent::getPrivateObject(JSObjectRef arg)
+{
+ JSTizenServiceEventPrivateObject* priv =
+ static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(arg));
+
+ if (!priv) {
+ LogError("Private object not initialized");
+ ThrowMsg(Commons::NullPointerException,
+ "Private object not initialized");
+ }
+
+ return priv->getObject();
+}
+
+#undef CATCH_EXCEPTION_CONVERSION
+#undef CATCH_EXCEPTION_NULL_PTR
+#undef CATCH_EXCEPTION_PLATFORM_ERROR
+#undef CATCH_EXCEPTION_SECURITY
+
+}
+}
--- /dev/null
+/*
+ * 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 JSTizenServiceEvent.h
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_TIZEN_SERVICE_EVENT_H_
+#define _WRT_PLUGIN_JS_TIZEN_SERVICE_EVENT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+
+namespace WrtPlugins {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<
+ WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr>::Type
+ JSTizenServiceEventPrivateObject;
+
+class JSTizenServiceEvent
+{
+ public:
+ /**
+ * This method initializes this in the JS Engine.
+ */
+ static const JSClassRef getClassRef();
+
+ /**
+ * Gets object's class description.
+ */
+ static const JSClassDefinition* getClassInfo();
+
+ private:
+ /**
+ * The callback invoked when an object is first created.
+ */
+ static void initialize(JSContextRef context,
+ JSObjectRef object);
+
+ /**
+ * The callback invoked when an object is finalized.
+ */
+ static void finalize(JSObjectRef object);
+
+ /**
+ * This structure describes a statically declared value property.
+ */
+ static JSStaticValue m_property[];
+
+ /**
+ * This structure contains properties and callbacks that define a type of object.
+ */
+ static JSClassDefinition m_classInfo;
+
+ static JSClassRef m_jsClassRef;
+
+ // getters for properties
+ static JSValueRef getScale(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef getBundle(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr
+ getPrivateObject(JSObjectRef arg);
+};
+} // Tizen
+} // WrtPlugins
+
+#endif // _WRT_PLUGIN_JS_TIZEN_SERVICE_EVENT_H_
--- /dev/null
+/*
+ * 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 js_function_manager.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @author Yunchan Cho (yunchan.cho@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <dpl/singleton_safe_impl.h>
+#include <js_function_manager.h>
+#include <js_iframe_support.h>
+#include <js_overlay_functions.h>
+#include <js_overlay_addEventListener.h>
+#include <wrt_plugin_export.h>
+
+using namespace WrtPlugins::W3C;
+
+IMPLEMENT_SAFE_SINGLETON(JsFunctionManager)
+
+namespace {
+const char* JSPRINT_NAME = "jsPrint";
+const char* JSGLOBAL_OBJECT = "GLOBAL_OBJECT";
+const char* JSHOOK_NAME = "jsHook";
+const char* ADD_EVENT_LISTENER_NAME = "addEventListener";
+}
+
+namespace JavaScriptFunctions
+{
+//options
+ class_definition_options_t jsHookfunctionsOptions =
+ {
+ JS_FUNCTION,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL,
+ NULL,
+ reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptHookProc)
+ };
+
+ class_definition_options_t jsPrintfunctionsOptions =
+ {
+ JS_FUNCTION,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL,
+ NULL,
+ reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptPrintProc)
+ };
+
+ class_definition_options_t addEventListenerOptions =
+ {
+ JS_FUNCTION,
+ CREATE_INSTANCE,
+ ALWAYS_NOTICE,
+ OVERLAYED_BEFORE_ORIGINAL,
+ IFrameSupport::RegisterAddEventListener,
+ NULL,
+ reinterpret_cast<js_function_impl>(AddEventListenerSupport::AddEventListener)
+ };
+
+ js_entity_definition_t jsPrint =
+ {
+ JSGLOBAL_OBJECT,
+ JSPRINT_NAME,
+ "",
+ NULL,
+ NULL,
+ &jsPrintfunctionsOptions
+ };
+
+ js_entity_definition_t jsHook =
+ {
+ JSGLOBAL_OBJECT,
+ JSHOOK_NAME,
+ "",
+ NULL,
+ NULL,
+ &jsHookfunctionsOptions
+ };
+
+ js_entity_definition_t addEventListener =
+ {
+ JSGLOBAL_OBJECT,
+ ADD_EVENT_LISTENER_NAME,
+ "",
+ NULL,
+ NULL,
+ &addEventListenerOptions
+ };
+ const js_entity_definition_ptr_t jsPrintPtr = &jsPrint;
+ const js_entity_definition_ptr_t jsHookPtr = &jsHook;
+ const js_entity_definition_ptr_t addEventListenerPtr = &addEventListener;
+}
+
+
+bool JsFunctionManager::initialize()
+{
+ LogInfo("JSObjectDeclaration for js functions are intialized");
+ JSObjectDeclarationPtr jsPrintObj(
+ new JSObjectDeclaration(JavaScriptFunctions::jsPrintPtr));
+
+ JSObjectDeclarationPtr jsHookObj(
+ new JSObjectDeclaration(JavaScriptFunctions::jsHookPtr));
+
+ JSObjectDeclarationPtr addEventListenerObj(
+ new JSObjectDeclaration(JavaScriptFunctions::addEventListenerPtr));
+
+ m_functions.push_back(jsPrintObj);
+ m_functions.push_back(jsHookObj);
+ m_functions.push_back(addEventListenerObj);
+
+ return true;
+}
+
+JsFunctionManager::Functions JsFunctionManager::getFunctions()
+{
+ LogInfo("get standard js fucntions");
+ static bool initialized = initialize();
+ (void) initialized;
+ return m_functions;
+}
--- /dev/null
+/*
+ * 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 js_function_manager.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_JS_FUNCTION_MANGER_H_
+#define WRT_SRC_PLUGIN_SERVICE_JS_FUNCTION_MANGER_H_
+
+#include <list>
+#include <dpl/noncopyable.h>
+#include <dpl/singleton.h>
+
+#include <Commons/JSObjectDeclaration.h>
+
+class JsFunctionManager : private DPL::Noncopyable
+{
+ public:
+ typedef std::list<JSObjectDeclarationPtr> Functions;
+
+ public:
+ Functions getFunctions();
+
+ private:
+ JsFunctionManager()
+ {}
+
+ bool initialize();
+
+ private:
+ Functions m_functions;
+
+ friend class DPL::Singleton<JsFunctionManager>;
+};
+
+typedef DPL::Singleton<JsFunctionManager> JsFunctionManagerSingleton;
+
+#endif
+
* @brief
*/
-#include "IFrameSupport.h"
#include <dpl/foreach.h>
#include <dpl/assert.h>
#include <dpl/log/log.h>
+#include <js_iframe_support.h>
namespace WrtPlugins {
namespace W3C {
*
* @file AddEventListenerSupport.cpp
* @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
* @version 0.1
* @brief
*/
-#include "AddEventListenerSupport.h"
#include <string>
#include <dpl/log/log.h>
#include <dpl/foreach.h>
#include <CommonsJavaScript/Converter.h>
+#include <js_overlay_addEventListener.h>
+#include <js_overlay_types.h>
#include "JSStorageEvent.h"
+#include "JSTizenServiceEvent.h"
namespace WrtPlugins {
namespace W3C {
JSContextRef AddEventListenerSupport::m_context = NULL;
-void AddEventListenerSupport::initializeContext(JSContextRef context)
+void AddEventListenerSupport::initialize(JSContextRef context)
{
if(!m_context) m_context = context;
}
-bool AddEventListenerSupport::isInitialized() {return m_context!=NULL;}
+void AddEventListenerSupport::deinitialize()
+{
+ if(!m_context) {
+ LogDebug("Not yet initialized");
+ }
+
+ m_listeners.clear();
+ m_context = NULL;
+}
+
+bool AddEventListenerSupport::isInitialized()
+{
+ return m_context!=NULL;
+}
JSValueRef AddEventListenerSupport::
AddEventListener(JSContextRef context,
std::string eventName = WrtDeviceApis::CommonsJavaScript::
Converter(context).toString(arguments[0]);
+ LogDebug("Event name: " << eventName);
- if(eventName != "storage"){
+ if(eventName != "storage" &&
+ eventName != "appservice"){
LogDebug("Event type not supported");
return JSValueMakeUndefined(context);
}
return JSValueMakeUndefined(context);
}
//add object to Listeners
- CallbackData data = {objectCb, thisObject};
- getIFrameListeners(thisObject)->push_back(data);
+
+ //set event information according to each event type
+ if(eventName == "storage") {
+ CallbackData data = {
+ StorageCustomEvent,
+ objectCb,
+ thisObject};
+ getIFrameListeners(thisObject)->push_back(data);
+ } else if (eventName == "appservice") {
+ CallbackData data = {
+ ServiceCustomEvent,
+ objectCb,
+ thisObject};
+ getIFrameListeners(thisObject)->push_back(data);
+ }
return JSValueMakeUndefined(context);
}
-void AddEventListenerSupport::CallListenersFromDifferentIFrames(
+void AddEventListenerSupport::
+CallStorageListenersFromDifferentIFrames(
JSObjectRef iframe,
const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event)
{
LogDebug("Invoked callbacks");
+ LogInfo("Context: " << m_context);
FOREACH(it, m_listeners)
{
{
LogDebug("Call");
+ if (listener->eventType ==
+ StorageCustomEvent)
+ {
+ JSObjectCallAsFunction(
+ m_context,
+ listener->object,
+ NULL,
+ argc,
+ argv,
+ NULL);
+ }
+ }
+
+ JSValueUnprotect(m_context, eventObject);
+ }
+
+ LogDebug("Done");
+};
+
+void AddEventListenerSupport::
+CallServiceListenersFromIFrame(JSObjectRef iframe,
+ const WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr& event)
+{
+ using namespace WrtPlugins::Tizen;
+ LogDebug("Invoked callbacks");
+
+ IFramesListeners::iterator it = m_listeners.find(iframe);
+ if (it == m_listeners.end()) {
+ LogDebug("This frame object not existed");
+ return;
+ }
+
+ auto eventPriv =
+ new JSTizenServiceEventPrivateObject(m_context, event);
+
+ JSObjectRef eventObject =
+ JSObjectMake(m_context, JSTizenServiceEvent::getClassRef(), eventPriv);
+ const size_t argc = 1;
+ JSValueRef argv[argc] = {eventObject};
+
+ JSValueProtect(m_context, eventObject);
+ FOREACH(listener, *it->second)
+ {
+ if (listener->eventType ==
+ ServiceCustomEvent)
+ {
+ LogDebug("Call");
JSObjectCallAsFunction(
m_context,
listener->object,
- NULL,
+ iframe,
argc,
argv,
NULL);
}
-
- JSValueUnprotect(m_context, eventObject);
}
-
+ JSValueUnprotect(m_context, eventObject);
LogDebug("Done");
};
*/
/**
*
- * @file AddEventListenerSupport.h
+ * @file js_overlay_addEventListener.h
* @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
* @version 0.1
* @brief
*/
#include <memory>
#include <JavaScriptCore/JavaScript.h>
#include <StorageEvent/IStorageEvent.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+#include <js_overlay_types.h>
namespace WrtPlugins {
namespace W3C {
class AddEventListenerSupport
{
public:
- static void initializeContext(JSContextRef context);
+ static void initialize(JSContextRef context);
+ static void deinitialize();
static bool isInitialized();
const JSValueRef arguments[],
JSValueRef* exception);
- static void CallListenersFromDifferentIFrames(
+ static void CallStorageListenersFromDifferentIFrames(
JSObjectRef iframe,
const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event);
+ static void CallServiceListenersFromIFrame(
+ JSObjectRef iframe,
+ const WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr& event);
+
private:
+
struct CallbackData{
+ CustomEventType eventType;
JSObjectRef object;
JSObjectRef thisObject;
};
--- /dev/null
+/*
+ * 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 javascript_functions.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_array.h>
+#include <js_overlay_functions.h>
+
+namespace JSCFunctions {
+
+std::string ConvertJSStringToStdString(JSStringRef value)
+{
+ int nSize = JSStringGetLength(value) + 1;
+ DPL::ScopedArray<char> textStr(new char[nSize]);
+ JSStringGetUTF8CString(value, textStr.Get(), nSize);
+ std::string ret = textStr.Get();
+ return ret;
+}
+
+JSValueRef JavaScriptPrintProc(JSContextRef context,
+ JSObjectRef /*object*/,
+ JSObjectRef /*thisObject*/,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ if (argumentCount == 0 || !JSValueIsString(context, arguments[0])) {
+ LogError("Argument is not string");
+ return JSValueMakeUndefined(context);
+ }
+
+ JSStringRef textRef = JSValueToStringCopy(context, arguments[0], exception);
+ int nSize = JSStringGetLength(textRef) + 1;
+
+ DPL::ScopedArray<char> textStr(new char[nSize]);
+
+ JSStringGetUTF8CString(textRef, textStr.Get(), nSize);
+ LogDebug("\033[00;35m[jsPrint] " << textStr.Get());
+
+ JSStringRelease(textRef);
+ return JSValueMakeBoolean(context, true);
+}
+
+JSValueRef JavaScriptHookProc(
+ JSContextRef context,
+ JSObjectRef /*object*/,
+ JSObjectRef /*thisObject*/,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ bool inError = false;
+ if (argumentCount < 2 ||
+ argumentCount > 3 ||
+ !JSValueIsString(context, arguments[0]) ||
+ !JSValueIsString(context, arguments[1])) {
+
+ inError = true;
+ }
+
+ if (inError) {
+ LogError("*********************************************");
+ LogError("*********************************************");
+ LogError("Cannot print test Result");
+ LogError("*********************************************");
+ LogError("*********************************************");
+ return JSValueMakeUndefined(context);
+ }
+
+ std::string id, result, message;
+ JSStringRef idRef = JSValueToStringCopy(context, arguments[0], exception);
+ id = ConvertJSStringToStdString(idRef);
+ JSStringRelease(idRef);
+ JSStringRef idResult = JSValueToStringCopy(context,
+ arguments[1],
+ exception);
+ result = ConvertJSStringToStdString(idResult);
+ JSStringRelease(idResult);
+
+ if (argumentCount == 3 && !JSValueIsString(context, arguments[2])) {
+ JSStringRef idMessage = JSValueToStringCopy(context,
+ arguments[0],
+ exception);
+ message = ConvertJSStringToStdString(idMessage);
+ JSStringRelease(idMessage);
+ }
+
+ LogDebug("\033[00;35m***********************************************");
+ LogDebug("\033[00;35m***********************************************");
+ LogDebug("\033[00;35m TEST ID: " << id);
+ LogDebug("\033[00;35m RESULT: " << result);
+ LogDebug("\033[00;35m MESSAGE: " << message);
+ LogDebug("\033[00;35m***********************************************");
+ LogDebug("\033[00;35m***********************************************");
+
+ return JSValueMakeBoolean(context, true);
+}
+}
--- /dev/null
+/*
+ * 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 javascript_functions.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_EFL_JAVASCRIPT_FUNCTIONS_H_
+#define WRT_SRC_PLUGIN_SERVICE_EFL_JAVASCRIPT_FUNCTIONS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+
+namespace JSCFunctions {
+JSValueRef JavaScriptPrintProc(
+ JSContextRef context,
+ JSObjectRef /*object*/,
+ JSObjectRef /*thisObject*/,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef * exception);
+JSValueRef JavaScriptHookProc(
+ JSContextRef context,
+ JSObjectRef /*object*/,
+ JSObjectRef /*thisObject*/,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+}
+
+#endif
+
--- /dev/null
+/*
+ * 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 js_overlay_support.cpp
+ * @author
+ * @version 1.0
+ * @brief
+ */
+#include <memory>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <JavaScriptCore/JavaScript.h>
+
+#include <js_overlay_support.h>
+
+namespace JSOverlaySupport
+{
+
+class JSFunctionDispatcher
+{
+ public:
+ struct PrivateData
+ {
+ //required to unprotect object in destructor;
+ JSContextRef context;
+ JSObjectPtr originalFunction;
+ JSObjectPtr overlayFunction;
+ };
+
+ static JSClassRef getClassRef();
+
+ private:
+ static JSClassDefinition m_classInfo;
+
+ private:
+ static void initialize(JSContextRef context, JSObjectRef object);
+
+ static void finalize(JSObjectRef object);
+
+ static JSValueRef callAsFunction(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+};
+
+
+
+JSObjectPtr createWrappedFunction(
+ JSGlobalContextRef ctx,
+ const JSObjectPtr& originalFunction,
+ const JSObjectPtr& overlayFunction,
+ const std::string& name)
+{
+ LogDebug("Creation overlay for function: " << name);
+ JSStringRef name_js = JSStringCreateWithUTF8CString(name.c_str());
+
+ JSFunctionDispatcher::PrivateData* priv =
+ new JSFunctionDispatcher::PrivateData;
+ priv->context = ctx;
+ priv->overlayFunction = overlayFunction;
+ priv->originalFunction = originalFunction;
+
+ auto fun = JSObjectMake(ctx, JSFunctionDispatcher::getClassRef(), priv);
+
+ JSStringRelease(name_js);
+
+ LogDebug("JSValueProtect invoked for: "
+ << overlayFunction->getObject() << " "
+ << originalFunction->getObject() << " Wrapper:"
+ << fun);
+
+ //the value is unprotected in finalize of the JSFunctionDispatcher object
+ JSValueProtect(ctx,
+ static_cast<JSObjectRef>(
+ overlayFunction->getObject()));
+
+ return JSObjectPtr(new JSObject(fun));
+}
+
+
+
+JSClassDefinition JSFunctionDispatcher::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ "IGNORED",
+ 0,
+ 0,
+ 0,
+ initialize,
+ finalize,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ callAsFunction,
+ NULL,
+ NULL,
+ NULL
+};
+
+JSClassRef JSFunctionDispatcher::getClassRef()
+{
+ static auto classRef = JSClassCreate(&m_classInfo);
+ return classRef;
+}
+
+
+void JSFunctionDispatcher::initialize(JSContextRef /*context*/,
+ JSObjectRef /*object*/)
+{
+ LogDebug("Initialize");
+}
+
+void JSFunctionDispatcher::finalize(JSObjectRef object)
+{
+ LogDebug("finalize");
+
+ PrivateData* priv = static_cast<PrivateData*> (JSObjectGetPrivate(object));
+ if(priv)
+ {
+ JSValueUnprotect(priv->context,
+ static_cast<JSObjectRef>(
+ priv->overlayFunction->getObject()));
+ delete priv;
+ }
+}
+
+
+
+JSValueRef JSFunctionDispatcher::callAsFunction(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Dispatcher invoked");
+
+ JSValueRef result = JSValueMakeUndefined(context);
+
+ JSFunctionDispatcher::PrivateData* priv =
+ static_cast<JSFunctionDispatcher::PrivateData*>
+ (JSObjectGetPrivate(object));
+
+ if(!priv)
+ {
+ LogError("Private object is NULL");
+ return result;
+ }
+
+ //call overlayed function
+ if (priv->overlayFunction->getObject())
+ {
+ LogDebug("Overlayed function will be invoked...");
+ result = JSObjectCallAsFunction(
+ context,
+ static_cast<JSObjectRef>(
+ priv->overlayFunction->getObject()),
+ thisObject,
+ argumentCount,
+ arguments,
+ exception);
+ }
+
+ //call original function
+ if (priv->originalFunction->getObject())
+ {
+ LogDebug("Original function will be invoked..");
+ result = JSObjectCallAsFunction(
+ context,
+ static_cast<JSObjectRef>(
+ priv->originalFunction->getObject()),
+ thisObject,
+ argumentCount,
+ arguments,
+ exception);
+ }
+
+ LogDebug("Done");
+ return result;
+}
+
+
+
+
+}
--- /dev/null
+/*
+ * 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 js_function_wrapper.h
+ * @author
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef _JAVASCRIPT_OVERLAY_SUPPORT_H
+#define _JAVASCRIPT_OVERLAY_SUPPORT_H
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <JavaScriptCore/JSObjectRef.h>
+#include <Commons/JSObject.h>
+
+namespace JSOverlaySupport
+{
+JSObjectPtr createWrappedFunction(
+ JSGlobalContextRef ctx,
+ const JSObjectPtr& originalFunction,
+ const JSObjectPtr& overlayFunction,
+ const std::string& name);
+}
+
+#endif
--- /dev/null
+/*
+ * 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 js_overlay_types.h
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_JS_OVERLAY_TYPES_H_
+#define _WRT_PLUGINS_JS_OVERLAY_TYPES_H_
+
+namespace WrtPlugins {
+namespace W3C {
+
+enum CustomEventType {
+ StorageCustomEvent,
+ ServiceCustomEvent,
+};
+
+} // W3C
+} // WrtPlugins
+#endif // _WRT_PLUGINS_JS_OVERLAY_TYPES_H_
include_config_file(Widget)
include_config_file(LocalStorage)
include_config_file(StorageEvent)
+include_config_file(TizenServiceEvent)
include_config_file(WidgetDB)
include_config_file(PluginManager)
#DEPRACATED modules
virtual size_t getStorageSize() const = 0;
/**
- * Get value for key
+ * Get key name for index
*/
- virtual std::string getValueByIndex(size_t index) const = 0;
+ virtual std::string getKeyByIndex(size_t index) const = 0;
/**
* virtual destructor
--- /dev/null
+/*
+ * 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 ITizenServiceEvent.h
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ * @brief Tizen Service event interfece
+ */
+
+#ifndef _WRT_PLUGIN_TIZEN_SERVICE_EVENT_INTERFACE_H_
+#define _WRT_PLUGIN_TIZEN_SERVICE_EVENT_INTERFACE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace TizenServiceEvent {
+namespace Api {
+
+class ITizenServiceEvent
+{
+ public :
+ virtual float getScale() const = 0;
+ virtual std::string getBundle() const = 0;
+
+ virtual void setScale(const float scale) = 0;
+ virtual void setBundle(const std::string &bundle) = 0;
+ virtual ~ITizenServiceEvent() {};
+};
+
+typedef DPL::SharedPtr<ITizenServiceEvent> ITizenServiceEventPtr;
+
+} // Api
+} // TizenServiceEvent
+} // WrtDeviceApis
+
+#endif // _WRT_PLUGIN_TIZEN_SERVICE_EVENT_INTERFACE_H_
* limitations under the License.
*/
/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ *
+ * @file TizenServiceEvent.cpp
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ * @brief Tizen appservice event class implementation
*/
-#ifndef WRTDEVICEAPIS_FILESYSTEM_COPYCOMMAND_H_
-#define WRTDEVICEAPIS_FILESYSTEM_COPYCOMMAND_H_
-
-#include "Command.h"
-#include <Filesystem/IPath.h>
+#include "TizenServiceEvent.h"
namespace WrtDeviceApis {
-namespace Filesystem {
+namespace TizenServiceEvent {
+namespace Api {
+
+TizenServiceEvent::TizenServiceEvent()
+{
+}
-class CopyCommand : public Command
+TizenServiceEvent::~TizenServiceEvent()
{
- public:
- CopyCommand(const Api::IPathPtr& src,
- const Api::IPathPtr& dest);
- void setRecursive(bool recursive);
- void setForce(bool force);
-
- protected:
- std::string prepare();
-
- private:
- Api::IPathPtr m_src;
- Api::IPathPtr m_dest;
- bool m_recursive;
- bool m_force;
-};
+}
+float TizenServiceEvent::getScale() const
+{
+ return m_scale;
}
+
+std::string TizenServiceEvent::getBundle() const
+{
+ return m_bundle;
+}
+
+void TizenServiceEvent::setScale(const float scale)
+{
+ m_scale = scale;
+}
+
+void TizenServiceEvent::setBundle(const std::string& bundle)
+{
+ m_bundle = bundle;
}
-#endif // WRTDEVICEAPIS_FILESYSTEM_COPYCOMMAND_H_
+} // Api
+} // TizenServiceEvent
+} // WrtDeviceApis
--- /dev/null
+/*
+ * 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 TizenServiceEvent.h
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ * @brief Tizen Service event class
+ */
+
+#ifndef _WRT_PLUGIN_TIZEN_SERVICE_EVENT_CLASS_H_
+#define _WRT_PLUGIN_TIZEN_SERVICE_EVENT_CLASS_H_
+
+#include <string>
+#include "ITizenServiceEvent.h"
+
+namespace WrtDeviceApis {
+namespace TizenServiceEvent {
+namespace Api {
+
+class TizenServiceEvent : public ITizenServiceEvent
+{
+ public :
+
+ TizenServiceEvent();
+ ~TizenServiceEvent();
+
+ float getScale() const;
+ std::string getBundle() const;
+
+ void setScale(const float scale);
+ void setBundle(const std::string &bundle);
+
+ private :
+ float m_scale;
+ std::string m_bundle;
+};
+
+} // Api
+} // TizenServiceEvent
+} // WrtDeviceApis
+
+#endif // _WRT_PLUGIN_TIZEN_SERVICE_EVENT_CLASS_H_
--- /dev/null
+get_current_path()
+
+set(API_TIZEN_SERVICE_EVENT_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+ )
+
+set(SRCS_API_TIZEN_SERVICE_EVENT
+ ${CURRENT_PATH}/TizenServiceEvent.cpp
+ PARENT_SCOPE
+)
#ifndef WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_INTERFACE_H_
#define WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_INTERFACE_H_
-#include <map>
+#include <list>
#include <string>
#include <dpl/shared_ptr.h>
class IWidgetFeature
{
public:
- typedef std::map<std::string, std::string> Params;
+ typedef std::pair<std::string, std::string> Param;
+ typedef std::list<Param> Params;
typedef Params::const_iterator ParamsIterator;
public:
set(TARGET_MODULE_LOCALSTORAGE "wrt-plugins-localstorage")
set(TARGET_MODULE_WIDGET_INTERFACE_DAO "wrt-plugins-widget-interface-dao")
set(TARGET_MODULE_STORAGEEVENT "wrt-plugins-storageevent")
+set(TARGET_MODULE_TIZEN_SERVICE_EVENT "wrt-plugins-tizen-service-event")
set(TARGET_MODULE_WIDGETDB "wrt-plugins-widgetdb")
set(TARGET_MODULE_PLUGIN_MANAGER "wrt-plugins-plugin-manager")
add_subdirectory(LocalStorage)
add_subdirectory(WidgetInterfaceDAO)
add_subdirectory(StorageEvent)
+add_subdirectory(TizenServiceEvent)
add_subdirectory(WidgetDB)
add_subdirectory(PluginManager)
set(TARGET_NAME ${TARGET_MODULE_PLUGIN_MANAGER})
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+
include_directories(
${INCLUDES_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER}
+ ${webkit2_INCLUDE_DIRS}}
)
set(SRCS
add_library(${TARGET_NAME} SHARED ${SRCS})
target_link_libraries(${TARGET_NAME}
${LIBS_COMMONS}
+ ${TARGET_PLUGIN_LOADING_LIB}
${TARGET_COMMONS}
${TARGET_COMMONS_JAVASCRIPT}
${LIBS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER}
)
-set_target_properties(${TARGET_NAME} PROPERTIES
+set_target_properties(${TARGET_NAME} PROPERTIES
SOVERSION ${CMAKE_PROJECT_API_VERSION}
VERSION ${CMAKE_PROJECT_VERSION}
)
--- /dev/null
+# 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 Yunchan Cho (yunchan.cho@samsung.com)
+# @version 0.1
+
+set(TARGET_NAME ${TARGET_MODULE_TIZEN_SERVICE_EVENT})
+
+set(SRCS
+ ${SRCS_API_TIZEN_SERVICE_EVENT}
+)
+
+add_library(${TARGET_NAME} STATIC ${SRCS})
--- /dev/null
+/*
+ * 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 AppLauncherManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @author Yujie Zeng (yj.zeng@samsung.com)
+ * @version 0.1
+ */
+
+#include <algorithm>
+#include <vector>
+#include <pcrecpp.h>
+#include <menu_db.h>
+#include <aul.h>
+#include <bundle.h>
+#include <dpl/scoped_free.h>
+#include <dpl/log/log.h>
+#include <commons/StringUtils.h>
+#include <Filesystem/Manager.h>
+#include "AppLauncherManager.h"
+
+using namespace WrtPlugins::Api;
+using namespace WrtPlugins::Api::AppLauncher;
+
+namespace {
+const char* EMPTY_STRING_PATTERN = "^\\s*$";
+const char* EMAIL_PATTERN = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+$";
+//According to RFC1738,any character is possible in http address
+const char* HTTP_ADDRESS_PATTERN = "^(http(s)?://)?\\w+.*$";
+const char* FILE_ADDRESS_PATTERN = "^.*\\..*$";
+
+const char* APPLICATION_ALARM = "org.tizen.clock"; // alarm has been included in clock app
+const char* APPLICATION_BROWSER = "org.tizen.browser";
+const char* APPLICATION_CALCULATOR = "org.tizen.calculator";
+const char* APPLICATION_CALENDAR = "org.tizen.efl-calendar";
+const char* APPLICATION_CAMERA = "org.tizen.camera-app";
+const char* APPLICATION_CONTACTS = "org.tizen.contacts";
+const char* APPLICATION_FILES = "org.tizen.myfile";
+const char* APPLICATION_GAMES = "";
+const char* APPLICATION_MAIL = "org.tizen.email";
+const char* APPLICATION_MEDIAPLAYER = "org.tizen.music-player";
+const char* APPLICATION_MESSAGING = "org.tizen.message";
+const char* APPLICATION_PHONECALL = "org.tizen.dialer";
+const char* APPLICATION_PHONECALL_CALLING = "org.tizen.call";
+const char* APPLICATION_PICTURES = "org.tizen.gallery";
+const char* APPLICATION_PICTURES_IMG_PATH = "org.tizen.image-viewer";
+const char* APPLICATION_PROG_MANAGER = "org.tizen.taskmgr";
+const char* APPLICATION_SETTINGS = "org.tizen.setting";
+const char* APPLICATION_TASKS = "org.tizen.dailybriefing";
+const char* APPLICATION_WIDGET_MANAGER = "org.tizen.wrt-test-ui";
+const char* APPLICATION_WIDGET = "org.tizen.";
+const char* APPLICATION_EMPTY = "";
+
+const char* WIDGET_URI_PREFIX = "widget://";
+
+const int SUCCESS_LAUNCHER = 0;
+const int ERROR_LAUNCHER_INVALID_URI = 1;
+const int ERROR_LAUNCHER_INVALID_PARAMETER = 2;
+const int ERROR_LAUNCHER_EXECUTION_ERROR = 3;
+}
+
+namespace WrtPlugins {
+namespace Platform {
+std::map<Api::AppLauncher::ApplicationType,
+ std::string> AppLauncherManager::m_applicationTypesByPath;
+std::map<Api::AppLauncher::ApplicationType,
+ std::string> AppLauncherManager::m_applicationTypesByName;
+std::vector<std::string> AppLauncherManager::m_installedApplications;
+std::vector<std::string> AppLauncherManager::m_installedApplicationsNames;
+
+AppLauncherManager::AppLauncherManager()
+{
+ LogDebug("entered");
+ static bool initialized = initializeApplicationList();
+ (void) initialized;
+}
+
+AppLauncherManager::~AppLauncherManager()
+{
+ LogDebug("entered");
+}
+
+bool AppLauncherManager::initializeApplicationList()
+{
+ //application paths
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_ALARM,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_BROWSER,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CALCULATOR,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CALENDAR,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CAMERA,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CONTACTS,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_FILES,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_GAMES,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_MAIL,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_MEDIAPLAYER,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_MESSAGING,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_PHONECALL,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_PICTURES,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_PROG_MANAGER,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_SETTINGS,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_TASKS,
+ APPLICATION_EMPTY));
+ m_applicationTypesByPath.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_WIDGET_MANAGER,
+ APPLICATION_EMPTY));
+ //application names
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_ALARM,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_BROWSER,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CALCULATOR,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CALENDAR,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CAMERA,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_CONTACTS,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_FILES,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_GAMES,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_MAIL,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_MEDIAPLAYER,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_MESSAGING,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_PHONECALL,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_PICTURES,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_PROG_MANAGER,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_SETTINGS,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_TASKS,
+ APPLICATION_EMPTY));
+ m_applicationTypesByName.insert(std::pair<ApplicationType,
+ std::string>(
+ APPLICATION_TYPE_WIDGET_MANAGER,
+ APPLICATION_EMPTY));
+
+ bool registered_application = false; // A variable that gets set if the current pkg_name is needed by WAC spec, needless of weather the package is visible or not.
+ app_info info = {};
+ unsigned int count = record_count(COUNT_MENU, &info);
+ LogDebug("number of registered applications: " << count);
+
+ DPL::ScopedFree<app_info> infoAll(static_cast<app_info*>(calloc(
+ count,
+ sizeof(
+ app_info))));
+ if (infoAll.Get()) {
+ if (!record_get(GET_MENU, infoAll.Get())) {
+ LogError("error during executing record_get() function");
+ return false;
+ }
+ for (unsigned int i = 0; i < count; i++) {
+ LogDebug("pkg_name " << infoAll.Get()[i].pkg_name);
+ LogDebug("app_path " << infoAll.Get()[i].app_path);
+ LogDebug("app_name " << infoAll.Get()[i].app_name);
+ registered_application = false;
+ if (infoAll.Get()[i].app_path == NULL ||
+ infoAll.Get()[i].app_name == NULL) {
+ LogDebug("Not Registered.");
+ LogDebug("-----");
+ continue;
+ }
+ if (0 ==
+ strncmp(APPLICATION_ALARM, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_ALARM] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_ALARM] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_BROWSER, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_BROWSER] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_BROWSER] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_CALCULATOR, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_CALCULATOR] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_CALCULATOR] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_CALENDAR, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_CALENDAR] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_CALENDAR] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_CAMERA, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_CAMERA] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_CAMERA] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_CONTACTS, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_CONTACTS] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_CONTACTS] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_FILES, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_FILES] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_FILES] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_GAMES, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_GAMES] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_GAMES] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_MAIL, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_MAIL] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_MAIL] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_MEDIAPLAYER, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_MEDIAPLAYER] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_MEDIAPLAYER] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_MESSAGING, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_MESSAGING] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_PHONECALL, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_PHONECALL] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_PICTURES, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_PICTURES] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_PICTURES] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_PROG_MANAGER, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_PROG_MANAGER] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_PROG_MANAGER] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_SETTINGS, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_SETTINGS] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_SETTINGS] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_TASKS, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_TASKS] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_TASKS] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (0 ==
+ strncmp(APPLICATION_WIDGET_MANAGER, infoAll.Get()[i].pkg_name,
+ NAME_LEN)) {
+ m_applicationTypesByPath[APPLICATION_TYPE_WIDGET_MANAGER] =
+ infoAll.Get()[i].app_path;
+ m_applicationTypesByName[APPLICATION_TYPE_WIDGET_MANAGER] =
+ infoAll.Get()[i].app_name;
+ registered_application = true;
+ }
+ if (infoAll.Get()[i].visible == 0 && registered_application ==
+ false) {
+ LogDebug("Not Registered.");
+ LogDebug("-----");
+ continue;
+ }
+ m_installedApplications.push_back(infoAll.Get()[i].app_path);
+ m_installedApplicationsNames.push_back(infoAll.Get()[i].app_name);
+ LogDebug("Registered.");
+ LogDebug("-----");
+ }
+ }
+ return true;
+}
+
+ApplicationType AppLauncherManager::getRegisteredApplicationType(
+ const std::string &name) const
+{
+ if (!name.empty()) {
+ std::map<ApplicationType, std::string>::const_iterator it;
+ for (it = m_applicationTypesByPath.begin();
+ it != m_applicationTypesByPath.end();
+ ++it) {
+ if (it->second == name) {
+ return it->first;
+ }
+ }
+ }
+ return APPLICATION_TYPE_UNDEFINED;
+}
+
+bool AppLauncherManager::isRegisteredApplication(const std::string &name) const
+{
+ if (name.empty()) {
+ return false;
+ }
+ std::vector<std::string>::const_iterator pos =
+ find(m_installedApplications.begin(),
+ m_installedApplications.end(), name);
+ return pos != m_installedApplications.end();
+}
+
+bool AppLauncherManager::validateHttpAddress(const std::string &value) const
+{
+ if (!pcrecpp::RE(HTTP_ADDRESS_PATTERN).FullMatch(value)) {
+ LogDebug("not valid paterrn of http address");
+ return false;
+ }
+ return true;
+}
+
+bool AppLauncherManager::isFilePath(const std::string &value) const
+{
+ if (!pcrecpp::RE(FILE_ADDRESS_PATTERN).FullMatch(value)) {
+ return false;
+ }
+ return true;
+}
+
+bool AppLauncherManager::validateEmailAddress(const std::string &value) const
+{
+ if (!pcrecpp::RE(EMAIL_PATTERN).FullMatch(value)) {
+ LogDebug("not valid paterrn of email address");
+ return false;
+ }
+ return true;
+}
+
+std::string AppLauncherManager::getRealPath(const std::string &path) const
+{
+ Try
+ {
+ Api::Filesystem::IPathPtr currentPath = Api::Filesystem::IPath::create(
+ path);
+ return currentPath->getFullPath();
+ }
+ Catch(Commons::Exception)
+ {
+ LogError("invalid path");
+ }
+ return std::string();
+}
+
+std::string AppLauncherManager::getPathFromApplicationName(
+ const std::string &applicationName) const
+{
+ if (0 == applicationName.find(WIDGET_URI_PREFIX) && std::string::npos !=
+ applicationName.find("?")) {
+ //uri format is: widget://{widgetId}?wname={WidgetName}
+ LogDebug("found widget:// URI");
+ std::string uri = applicationName;
+ uri.erase(0, strlen(WIDGET_URI_PREFIX)); //remove widget://part
+ std::string widgetId = uri.substr(0, uri.find("?"));
+ uri.erase(0, widgetId.size() + 7); //remove widget id and "?wname=" string, so uri contains only widget name now
+ std::string packageName = APPLICATION_WIDGET + widgetId;
+ LogDebug(
+ "Widget id: " << widgetId << ", widget name: " << uri <<
+ ", package: " << packageName);
+ app_info info = { 0, };
+ strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
+ if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
+ if (info.app_path && info.app_name && uri == info.app_name) {
+ return std::string(info.app_path);
+ }
+ }
+ }
+ for (size_t i = 0; i < m_installedApplicationsNames.size(); ++i) {
+ if (m_installedApplicationsNames[i] == applicationName) {
+ return m_installedApplications[i];
+ }
+ }
+ return std::string();
+}
+
+std::string AppLauncherManager::getPathFromPackageName(
+ const std::string &packageName) const
+{
+ app_info info = { 0, };
+ strncpy(info.pkg_name, packageName.c_str(), NAME_LEN);
+ if (record_get(GET_ONE_RECORD_BY_PKG_NAME, &info)) {
+ LogDebug("pkg_name " << info.pkg_name);
+ LogDebug("app_path " << info.app_path);
+ LogDebug("app_name " << info.app_name);
+ if (info.app_path) {
+ return std::string(info.app_path);
+ }
+ }
+ return std::string();
+}
+
+std::string AppLauncherManager::getPackageNameFromPath(const std::string &path)
+const
+{
+ app_info info = { 0, };
+ strncpy(info.app_path, path.c_str(), PATH_LEN);
+ if (record_get(GET_ONE_RECORD_BY_APP_PATH, &info)) {
+ LogDebug("pkg_name " << info.pkg_name);
+ LogDebug("app_path " << info.app_path);
+ LogDebug("app_name " << info.app_name);
+ if (info.app_path) {
+ return std::string(info.pkg_name);
+ }
+ }
+ return std::string();
+}
+
+int AppLauncherManager::launchApplicationFileInternal(
+ const std::string &uriParameter,
+ const std::vector<std::string> &applicationParams)
+{
+ LogDebug("entered with uriParameter: '" << uriParameter << "'");
+ ApplicationType appType = getRegisteredApplicationType(uriParameter);
+ if (!isRegisteredApplication(uriParameter)) {
+ LogDebug("Its not registered application");
+ return ERROR_LAUNCHER_INVALID_URI;
+ }
+ //try to launch as package using aul
+ std::string packageName = getPackageNameFromPath(uriParameter);
+ if (!packageName.empty()) {
+ LogDebug("executing as package, package name " << packageName);
+ //check parameters for empty or extra spaces
+ std::vector<std::string> params;
+ std::vector<std::string>::const_iterator it;
+ for (it = applicationParams.begin();
+ it != applicationParams.end();
+ ++it) {
+ std::string param(Commons::String::trim(*it));
+ if (param.empty()) {
+ continue;
+ }
+ params.push_back(param);
+ }
+ bundle *kb = NULL;
+ if (params.size() > 0) {
+ if (appType == APPLICATION_TYPE_PHONECALL) {
+ //phone number is provided.
+ //replace package to make a call, not run application with this functionality
+
+ packageName = APPLICATION_PHONECALL_CALLING;
+ kb = bundle_create();
+ if (!kb) {
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ if (bundle_add(kb, "launch-type", "MO") < 0) { // "MO" : normal call, "EMERGENCY" : emergency call
+ bundle_free(kb);
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ if (bundle_add(kb, "number", params.front().c_str()) < 0) {
+ bundle_free(kb);
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ LogDebug("running with number: " << params.front());
+ } else if (appType == APPLICATION_TYPE_BROWSER) {
+ if (!validateHttpAddress(params.front())) {
+ return ERROR_LAUNCHER_INVALID_PARAMETER;
+ }
+ kb = bundle_create();
+ if (!kb) {
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ if (bundle_add(kb, "url", params.front().c_str()) < 0) {
+ bundle_free(kb);
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ LogDebug("running with url: " << params.front().c_str());
+ } else if (appType == APPLICATION_TYPE_MEDIAPLAYER) {
+ LogDebug("opening file: " << getRealPath(params.front()).c_str());
+ int result = aul_open_file(getRealPath(params.front()).c_str());
+ if (result < 0) {
+ LogError("Cannot open file, launch application only");
+ } else {
+ return SUCCESS_LAUNCHER;
+ }
+ } else if (appType == APPLICATION_TYPE_FILES) {
+ struct stat sb;
+ if (stat(getRealPath(params.front()).c_str(), &sb) == -1) {
+ LogError(
+ "The selected path does not exist: " <<
+ getRealPath(params.front()).c_str());
+ } else {
+ if (!S_ISDIR(sb.st_mode)) {
+ LogDebug("opening file: " << getRealPath(
+ params.front()).c_str());
+ int result = aul_open_file(getRealPath(
+ params.front()).c_str());
+ if (result < 0) {
+ LogError(
+ "Cannot open file, launch application only");
+ } else {
+ return SUCCESS_LAUNCHER;
+ }
+ } else {
+ kb = bundle_create();
+ if (!kb) {
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ if (bundle_add(kb, "path",
+ getRealPath(params.front()).c_str()) <
+ 0) {
+ bundle_free(kb);
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ LogDebug("running with folder path: " <<
+ getRealPath(params.front()).c_str());
+ }
+ }
+ } else if (appType == APPLICATION_TYPE_PICTURES) {
+ //open photo with image path
+ //replace package to show only one picture with given image path
+ packageName = APPLICATION_PICTURES_IMG_PATH;
+ kb = bundle_create();
+ if (!kb) {
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ if (bundle_add(kb, "View Mode", "SINGLE") < 0) {
+ bundle_free(kb);
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ if (bundle_add(kb, "Path",
+ getRealPath(params.front()).c_str()) < 0) {
+ bundle_free(kb);
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ LogDebug("running with img file path: " <<
+ getRealPath(params.front()).c_str());
+ }
+ //TODO: add more parameters when needed
+ }
+ int result = aul_launch_app(packageName.c_str(), kb);
+ if (kb) {
+ bundle_free(kb);
+ }
+ if (result > 0) {
+ return SUCCESS_LAUNCHER;
+ }
+ LogError("aul_launch_app result " << result);
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+ }
+ return ERROR_LAUNCHER_EXECUTION_ERROR;
+}
+
+int AppLauncherManager::launchApplicationInternal(
+ const ApplicationUriType uriType,
+ const std::string &uriParameter,
+ const std::vector<std::string> &applicationParams)
+{
+ LogDebug(
+ "entered with uriType: " << uriType << ", uriParameter: " <<
+ uriParameter);
+ if (APPLICATION_URI_TYPE_HTTP == uriType) {
+ std::string application =
+ m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
+ std::vector<std::string> params;
+ if (Commons::String::startsWith(uriParameter, "http://")) {
+ params.push_back(uriParameter);
+ } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
+ {
+ params.push_back("http://" + uriParameter);
+ }
+ return launchApplicationFileInternal(application, params);
+ } else if (APPLICATION_URI_TYPE_HTTPS == uriType) {
+ std::string application =
+ m_applicationTypesByPath[APPLICATION_TYPE_BROWSER];
+ std::vector<std::string> params;
+ if (Commons::String::startsWith(uriParameter, "https://")) {
+ params.push_back(uriParameter);
+ } else if (!pcrecpp::RE(EMPTY_STRING_PATTERN).FullMatch(uriParameter))
+ {
+ params.push_back("https://" + uriParameter);
+ }
+ return launchApplicationFileInternal(application, params);
+ } else if (APPLICATION_URI_TYPE_TEL == uriType) {
+ std::string application =
+ m_applicationTypesByPath[APPLICATION_TYPE_PHONECALL];
+ std::vector<std::string> params;
+ params.push_back(uriParameter);
+ return launchApplicationFileInternal(application, params);
+ } else if (APPLICATION_URI_TYPE_MAILTO == uriType) {
+ std::string application =
+ m_applicationTypesByPath[APPLICATION_TYPE_MAIL];
+ std::vector<std::string> params;
+ params.push_back(uriParameter);
+ return launchApplicationFileInternal(application, params);
+ } else if (APPLICATION_URI_TYPE_SMS == uriType) {
+ std::string application =
+ m_applicationTypesByPath[APPLICATION_TYPE_MESSAGING];
+ std::vector<std::string> params;
+ params.push_back(uriParameter);
+ return launchApplicationFileInternal(application, params);
+ } else if (APPLICATION_URI_TYPE_FILE == uriType) {
+ return launchApplicationFileInternal(uriParameter, applicationParams);
+ } else if (APPLICATION_URI_TYPE_APPLICATION_BY_NAME == uriType) {
+ std::string application = getPathFromApplicationName(uriParameter);
+ return launchApplicationFileInternal(application, applicationParams);
+ } else {
+ return ERROR_LAUNCHER_INVALID_URI;
+ }
+ return SUCCESS_LAUNCHER;
+}
+
+std::string AppLauncherManager::getDefaultApplicationByMimeInternal(
+ const std::string &mime) const
+{
+ LogDebug("entered with mime: " << mime);
+ const int bufferSize = 1024;
+ char buffer[bufferSize] = { 0 };
+ int result = aul_get_defapp_from_mime(mime.c_str(), buffer, bufferSize - 1);
+ if (AUL_R_OK == result) {
+ LogDebug("returning default application");
+ return std::string(buffer);
+ } else {
+ LogError("aul_get_defapp_from_mime failed, error code " << result);
+ Throw(Commons::PlatformException);
+ }
+ return std::string();
+}
+
+void AppLauncherManager::OnRequestReceived(
+ const EventGetDefaultApplicationPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ std::string result = getDefaultApplicationByMimeInternal(event->getMime());
+ event->setApplicationFullPath(result);
+ event->setExceptionCode(Commons::ExceptionCodes::None);
+ }
+ Catch(Commons::PlatformException)
+ {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+}
+
+void AppLauncherManager::OnRequestReceived(
+ const EventGetInstalledApplicationsPtr &event)
+{
+ LogDebug("entered");
+ std::vector<std::string>::const_iterator it1;
+ for (it1 = m_installedApplications.begin();
+ it1 != m_installedApplications.end();
+ ++it1) {
+ event->addApplicationFullPath(*it1);
+ }
+ for (it1 = m_installedApplicationsNames.begin();
+ it1 != m_installedApplicationsNames.end();
+ ++it1) {
+ event->addApplicationName(*it1);
+ }
+ std::map<ApplicationType, std::string>::const_iterator it2;
+ for (it2 = m_applicationTypesByPath.begin();
+ it2 != m_applicationTypesByPath.end();
+ ++it2) {
+ event->addApplicationTypeByPath(*it2);
+ }
+ for (it2 = m_applicationTypesByName.begin();
+ it2 != m_applicationTypesByName.end();
+ ++it2) {
+ event->addApplicationTypeByName(*it2);
+ }
+ event->setExceptionCode(Commons::ExceptionCodes::None);
+}
+
+void AppLauncherManager::OnRequestReceived(
+ const EventLaunchApplicationPtr &event)
+{
+ LogDebug("entered");
+ ApplicationUriType uriType = event->getApplicationUriType();
+ std::string uriParam = event->getApplicationUriParam();
+ std::vector<std::string> parameters = event->getApplicationParameters();
+ int result = launchApplicationInternal(uriType, uriParam, parameters);
+ if (result == SUCCESS_LAUNCHER) {
+ event->setExceptionCode(Commons::ExceptionCodes::None);
+ } else if (result == ERROR_LAUNCHER_INVALID_PARAMETER ||
+ result == ERROR_LAUNCHER_INVALID_URI) {
+ event->setExceptionCode(
+ Commons::ExceptionCodes::InvalidArgumentException);
+ } else {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+}
+}
+}
--- /dev/null
+/*
+ * 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 AppLauncherManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @author Yujie Zeng (yj.zeng@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _SLP20__APPLAUNCHER_MANAGER_H_
+#define _SLP20__APPLAUNCHER_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <vector>
+#include <API/AppLauncher/IAppLauncherManager.h>
+#include <API/AppLauncher/EventGetDefaultApplication.h>
+#include <API/AppLauncher/EventGetInstalledApplications.h>
+#include <API/AppLauncher/EventLaunchApplication.h>
+#include <API/AppLauncher/ApplicationTypes.h>
+
+namespace WrtPlugins {
+namespace Platform {
+class AppLauncherManager : public Api::AppLauncher::IAppLauncherManager
+{
+ public:
+ AppLauncherManager();
+ virtual ~AppLauncherManager();
+ protected:
+ virtual void OnRequestReceived(
+ const Api::AppLauncher::EventGetDefaultApplicationPtr &event);
+ virtual void OnRequestReceived(
+ const Api::AppLauncher::EventGetInstalledApplicationsPtr &event);
+ virtual void OnRequestReceived(
+ const Api::AppLauncher::EventLaunchApplicationPtr &event);
+ virtual bool isRegisteredApplication(const std::string &name) const;
+ virtual Api::AppLauncher::ApplicationType getRegisteredApplicationType(
+ const std::string &name) const;
+ virtual std::string getRealPath(const std::string &path) const;
+ virtual bool validateHttpAddress(const std::string &value) const;
+ virtual bool validateEmailAddress(const std::string &value) const;
+ virtual bool isFilePath(const std::string &value) const;
+
+ private:
+ bool initializeApplicationList();
+ std::string getPathFromApplicationName(const std::string &applicationName)
+ const;
+ std::string getPathFromPackageName(const std::string &packageName) const;
+ std::string getPackageNameFromPath(const std::string &path) const;
+ std::string getDefaultApplicationByMimeInternal(const std::string &mime)
+ const;
+ int launchApplicationInternal(
+ const Api::AppLauncher::ApplicationUriType uriType,
+ const std::string &uriParameter,
+ const std::vector<std::string> &applicationParams);
+ int launchApplicationFileInternal(const std::string &uriParameter,
+ const std::vector<std::string> &applicationParam);
+ static std::map<Api::AppLauncher::ApplicationType,
+ std::string> m_applicationTypesByPath;
+ static std::map<Api::AppLauncher::ApplicationType,
+ std::string> m_applicationTypesByName;
+ static std::vector<std::string> m_installedApplications;
+ static std::vector<std::string> m_installedApplicationsNames;
+};
+
+typedef DPL::SharedPtr<AppLauncherManager> AppLauncherManagerPtr;
+}
+}
+
+#endif /* _SLP20__APPLAUNCHER_MANAGER_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(glib REQUIRED glib-2.0)
+pkg_search_module(aul REQUIRED aul)
+pkg_search_module(pcre REQUIRED libpcrecpp)
+pkg_search_module(dmi REQUIRED desktop-manager-internal)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_APPLAUNCHER
+ ${glib_INCLUDE_DIRS}
+ ${pcre_INCLUDE_DIRS}
+ ${aul_INCLUDE_DIRS}
+ ${dmi_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_APPLAUNCHER
+ ${glib_LIBRARIES}
+ ${pcre_LIBRARIES}
+ ${aul_LIBRARIES}
+ ${dmi_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_APPLAUNCHER
+ ${CURRENT_PATH}/../../API/Filesystem/IManager.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/IPath.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/INode.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/IStream.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventCopy.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventFind.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventResolve.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventMove.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventRemove.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventOpen.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventListNodes.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/EventReadText.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/NodeFilter.cpp
+ ${CURRENT_PATH}/../../API/Filesystem/PathUtils.cpp
+ ${CURRENT_PATH}/../Filesystem/System.cpp
+ ${CURRENT_PATH}/../Filesystem/Manager.cpp
+ ${CURRENT_PATH}/../Filesystem/Utils.cpp
+ ${CURRENT_PATH}/../Filesystem/Path.cpp
+ ${CURRENT_PATH}/../Filesystem/Node.cpp
+ ${CURRENT_PATH}/../Filesystem/Stream.cpp
+ ${CURRENT_PATH}/../Filesystem/NodeFilterMatcher.cpp
+ ${CURRENT_PATH}/AppLauncherManager.cpp
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "Camera.h"
+#include <pthread.h>
+#include <dpl/assert.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <Commons/Exception.h>
+#include <Commons/TypeTraits.h>
+
+
+namespace WrtDeviceApis {
+namespace Camera {
+
+template<typename EventPtr>
+class CameraPrivateData
+{
+public:
+ Camera* camera;
+ EventPtr event;
+};
+
+enum EventTypeId
+{
+ BeginRecordingType,
+ TakePictureType,
+ CreatePreviewType
+};
+
+class OpaquePrivateData
+{
+public:
+ EventTypeId eventTypeId;
+ void* cameraPrivateData;
+};
+
+
+//GetEventTypeId
+template<typename T>
+EventTypeId getEventTypeId(const T& event){ Assert(0); }
+
+template<>
+EventTypeId getEventTypeId<Api::EventBeginRecordingSharedPtr>(
+ const Api::EventBeginRecordingSharedPtr& /*event*/)
+{
+ return BeginRecordingType;
+}
+
+template<>
+EventTypeId getEventTypeId<Api::EventTakePictureSharedPtr>(
+ const Api::EventTakePictureSharedPtr& /*event*/)
+{
+ return TakePictureType;
+}
+
+template<>
+EventTypeId getEventTypeId<Api::EventGetPreviewNodeSharedPtr>(
+ const Api::EventGetPreviewNodeSharedPtr& /*event*/)
+{
+ return CreatePreviewType;
+}
+
+template<typename EventPtr>
+OpaquePrivateData* createPrivateOpaqueData(Camera* camera,
+ const EventPtr& event)
+{
+ //create private opaque data
+ OpaquePrivateData* opaqueData = new OpaquePrivateData;
+
+ CameraPrivateData<EventPtr>* privateData = new CameraPrivateData<EventPtr>;
+ privateData->camera = camera;
+ privateData->event = event;
+
+ opaqueData->eventTypeId = getEventTypeId(event);
+ opaqueData->cameraPrivateData = privateData;
+
+ return opaqueData;
+}
+
+template<typename EventPtr>
+CameraPrivateData<EventPtr>* getPrivateData(void* data)
+{
+ OpaquePrivateData* opaqueData = static_cast<OpaquePrivateData*> (data);
+
+ CameraPrivateData<EventPtr>* privateData =
+ static_cast<CameraPrivateData<EventPtr> *>
+ (opaqueData->cameraPrivateData);
+
+ return privateData;
+}
+
+template<typename EventPtr>
+void deletePrivateData(void* data)
+{
+ OpaquePrivateData* opaqueData = static_cast<OpaquePrivateData*> (data);
+
+ CameraPrivateData<EventPtr>* privateData =
+ static_cast<CameraPrivateData<EventPtr> *>
+ (opaqueData->cameraPrivateData);
+
+ delete privateData;
+ delete opaqueData;
+}
+
+
+template<typename EventType, typename EventArg>
+EventType createEvent(const EventArg& arg1)
+{
+ return EventType(arg1);
+}
+
+
+template<typename EventType>
+class BaseCallbackHandler : private DPL::Noncopyable
+{
+public:
+ explicit BaseCallbackHandler(void* data) :
+ m_camera(NULL)
+ {
+ Assert(data);
+ CameraPrivateData<EventType>* privateData =
+ getPrivateData<EventType>(data);
+ m_camera = privateData->camera;
+ m_event = privateData->event;
+
+ deletePrivateData<EventType>(data);
+ }
+
+ virtual void handleErrorCallback(int error)
+ {
+ LogError("Error: " << error);
+ m_event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ this->post();
+ }
+
+ virtual void handleSuccessCallback(void* data)
+ {
+ setPrivate(data);
+ this->post();
+ }
+
+ virtual void post() = 0;
+
+ virtual ~BaseCallbackHandler(){ }
+
+ protected:
+ virtual void setPrivate(void* /*data*/) {};
+
+protected:
+ Camera* m_camera;
+ EventType m_event;
+};
+
+template<typename EventType>
+class CallbackHandler : public BaseCallbackHandler<EventType>
+{
+ static_assert(WrtDeviceApis::Commons::AlwaysFalse<EventType>::value,
+ "Error, no specialization found for given type");
+
+ public:
+ explicit CallbackHandler(void* data) :
+ BaseCallbackHandler<EventType>(data)
+ {
+ }
+
+ //virtual void post(){ }
+};
+
+template<>
+class CallbackHandler<Api::EventBeginRecordingSharedPtr>
+ : public BaseCallbackHandler<Api::EventBeginRecordingSharedPtr>
+{
+ public:
+ explicit CallbackHandler(void* data) :
+ BaseCallbackHandler(data)
+ {}
+
+ virtual void post(){
+ this->m_camera->setRecordingState(Camera::COMPLETED);
+ this->m_camera->
+ DPL::Event::ControllerEventHandler<JobDoneVideoRecordingEvent>::PostEvent(
+ createEvent<JobDoneVideoRecordingEvent,
+ Api::EventBeginRecordingSharedPtr>(this->m_event));
+ }
+
+ virtual void handleSuccessCallback(void* data)
+ {
+ this->m_camera->setRecordingState(Camera::COMPLETED);
+ BaseCallbackHandler<Api::EventBeginRecordingSharedPtr>::
+ handleSuccessCallback(data);
+ }
+};
+
+template<>
+class CallbackHandler<Api::EventTakePictureSharedPtr>
+ : public BaseCallbackHandler<Api::EventTakePictureSharedPtr>
+{
+ public:
+ explicit CallbackHandler(void* data) :
+ BaseCallbackHandler(data)
+ {}
+
+ virtual void post(){
+ this->m_camera->
+ DPL::Event::ControllerEventHandler<JobDoneTakePictureEvent>::PostEvent(
+ createEvent<JobDoneTakePictureEvent,
+ Api::EventTakePictureSharedPtr>(this->m_event));
+ }
+
+ virtual void setPrivate(void* data)
+ {
+ m_event->getCaptureOptionsRef()->setFileName(static_cast<char*>(data));
+ }
+};
+
+template<>
+class CallbackHandler<Api::EventGetPreviewNodeSharedPtr>
+ : public BaseCallbackHandler<Api::EventGetPreviewNodeSharedPtr>
+{
+ public:
+ explicit CallbackHandler(void* data) :
+ BaseCallbackHandler(data)
+ {}
+
+ virtual void post(){
+ this->m_camera->
+ DPL::Event::ControllerEventHandler<JobDoneCreatePreviewEvent>::PostEvent(
+ createEvent<JobDoneCreatePreviewEvent,
+ Api::EventGetPreviewNodeSharedPtr>(this->m_event));
+ }
+
+ virtual void setPrivate(void* data)
+ {
+ LogDebug("Enter");
+ m_event->setPreviewNode(data);
+ }
+};
+
+Camera::Camera(const Commons::IWrtCameraPtr& wrtCamera) :
+ m_wrtCamera(wrtCamera),
+ m_stateRecordingVideo (Camera::IDLE)
+{
+ CameraJobDoneController::Touch();
+}
+
+Camera::~Camera()
+{
+ LogDebug("enter");
+
+ CameraJobDoneController::SwitchToThread(NULL);
+}
+
+
+void Camera::OnRequestReceived(
+ const Api::EventTakePictureSharedPtr & event)
+{
+ LogDebug("enter");
+
+ event->switchToManualAnswer();
+
+ m_wrtCamera->captureImage(event->getCaptureOptionsRef()->getFileName(),
+ checkHighResolutionRequired(event),
+ camCaptureImageSuccessCallback,
+ camCaptureImageErrorCallback,
+ setPendingOperation,
+ createPrivateOpaqueData(this,event));
+
+ LogDebug("leaving");
+}
+
+void Camera::OnRequestReceived(
+ const Api::EventBeginRecordingSharedPtr & event)
+{
+ LogDebug("enter");
+
+ if (m_stateRecordingVideo != Camera::IDLE) {
+ event->setExceptionCode(Commons::ExceptionCodes::AlreadyInUseException);
+ return;
+ }
+ m_stateRecordingVideo = Camera::PROCESSING;
+
+ //from now on we will have to call answer manually
+ event->switchToManualAnswer();
+
+ m_wrtCamera->startVideoCapture(event->getCaptureOptionsRef()->getFileName(),
+ checkHighResolutionRequired(event),
+ camCaptureVideoSuccessCallback,
+ camCaptureVideoErrorCallback,
+ setPendingOperation,
+ createPrivateOpaqueData(this,event));
+
+ LogDebug("leaving");
+}
+
+void Camera::OnRequestReceived(
+ const Api::EventEndRecordingSharedPtr & event)
+{
+ LogDebug("end request");
+ if (m_stateRecordingVideo == Camera::PROCESSING) {
+ m_wrtCamera->stopVideoCapture();
+ } else {
+ LogDebug("stopVideo has been called but no recording is in progress");
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ }
+}
+
+void Camera::OnRequestReceived(
+ const Api::EventGetPreviewNodeSharedPtr & event)
+{
+ LogDebug("enter");
+
+ event->switchToManualAnswer();
+
+ LogDebug("start createPreview");
+
+ m_wrtCamera->createPreviewNode(camPreviewSuccessCallback,
+ camPreviewErrorCallback,
+ setPendingOperation,
+ createPrivateOpaqueData(this,event));
+ LogDebug("leaving");
+}
+
+void Camera::camCaptureImageSuccessCallback(
+ const char* filename, void* data)
+{
+ LogDebug("*Picture* Captured. !!!");
+
+ CallbackHandler<Api::EventTakePictureSharedPtr> handler(data);
+ handler.handleSuccessCallback(const_cast<char*>(filename));
+}
+
+void Camera::camCaptureVideoSuccessCallback(const char* filename, void* data)
+{
+ LogDebug("*Video* Captured. !!!");
+
+ CallbackHandler<Api::EventBeginRecordingSharedPtr> handler(data);
+ handler.handleSuccessCallback(const_cast<char*>(filename));
+}
+
+void Camera::camPreviewSuccessCallback(
+ Commons::IWrtCamera::CameraPreviewNode node, void* data)
+{
+ LogDebug("enter");
+
+ CallbackHandler<Api::EventGetPreviewNodeSharedPtr> handler(data);
+ handler.handleSuccessCallback(node);
+}
+
+void Camera::camPreviewErrorCallback(int errorCode, void* data)
+{
+ LogDebug("enter");
+
+ CallbackHandler<Api::EventGetPreviewNodeSharedPtr> handler(data);
+ handler.handleErrorCallback(errorCode);
+}
+
+void Camera::camCaptureImageErrorCallback(int errorCode, void* data)
+{
+ LogDebug("enter");
+
+ CallbackHandler<Api::EventTakePictureSharedPtr> handler(data);
+ handler.handleErrorCallback(errorCode);
+}
+
+void Camera::camCaptureVideoErrorCallback(int errorCode, void* data)
+{
+ LogDebug("enter");
+
+ CallbackHandler<Api::EventBeginRecordingSharedPtr> handler(data);
+ handler.handleErrorCallback(errorCode);
+}
+
+void Camera::OnEventReceived(const JobDoneVideoRecordingEvent &event)
+{
+ LogDebug("enter");
+ if (m_stateRecordingVideo == COMPLETED && event.GetArg0()) {
+ EventRequestReceiver<Api::EventBeginRecording>::
+ ManualAnswer(event.GetArg0());
+ //event.Reset();
+ }
+ m_stateRecordingVideo = Camera::IDLE;
+}
+
+void Camera::OnEventReceived(const JobDoneCreatePreviewEvent &event)
+{
+ OnJobDoneReceived(event.GetArg0());
+}
+
+void Camera::OnEventReceived(const JobDoneTakePictureEvent &event)
+{
+ OnJobDoneReceived(event.GetArg0());
+}
+
+void Camera::OnCancelEvent(
+ const Api::EventBeginRecordingSharedPtr& event)
+{
+ LogDebug(__FUNCTION__);
+
+ if (Camera::PROCESSING == m_stateRecordingVideo) {
+ if (event->checkPendingOperation()) {
+ m_wrtCamera->cancelAsyncOperation(event->getPendingOperation());
+ }
+ setRecordingState(Camera::IDLE);
+ } else {
+ LogError("Cancel invoked, but the state is wrong");
+ }
+}
+
+void Camera::OnCancelEvent(const Api::EventTakePictureSharedPtr& event)
+{
+ cancelEvent(event);
+}
+
+void Camera::OnCancelEvent(
+ const Api::EventGetPreviewNodeSharedPtr& event)
+{
+ cancelEvent(event);
+}
+
+void Camera::setRecordingState(CameraState state)
+{
+ m_stateRecordingVideo = state;
+}
+
+void Camera::setPendingOperation(
+ Commons::IWrtCamera::CameraPendingOperation pendingOperation, void* data)
+{
+ LogDebug("Set pending operation callback invoked");
+
+ Assert(data);
+ OpaquePrivateData* opaqueData = static_cast<OpaquePrivateData*> (data);
+ Assert(opaqueData->cameraPrivateData);
+
+ switch (opaqueData->eventTypeId) {
+ case BeginRecordingType:
+ {
+ static_cast<CameraPrivateData<Api::EventBeginRecordingSharedPtr>* > (
+ opaqueData->cameraPrivateData)
+ ->event->setPendingOperation(pendingOperation);
+ break;
+ }
+ case CreatePreviewType:
+ {
+ static_cast<CameraPrivateData<Api::EventGetPreviewNodeSharedPtr>* > (
+ opaqueData->cameraPrivateData)
+ ->event->setPendingOperation(pendingOperation);
+ break;
+ }
+ case TakePictureType:
+ {
+ static_cast<CameraPrivateData<Api::EventGetPreviewNodeSharedPtr>* > (
+ opaqueData->cameraPrivateData)
+ ->event->setPendingOperation(pendingOperation);
+ break;
+ }
+ default:
+ Assert(0);
+ }
+}
+
+
+}
+}
--- /dev/null
+/*
+ * 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.
+ */
+/*
+ * @author Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_CAMERA_H_
+#define WRT_PLUGINS_CAMERA_H_
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/generic_event.h>
+#include <dpl/event/controller.h>
+#include <dpl/type_list.h>
+#include <dpl/shared_ptr.h>
+#include <API/Camera/ICamera.h>
+#include <API/Camera/ICaptureOptions.h>
+#include <API/Camera/EventTakePicture.h>
+#include <API/Camera/EventBeginRecording.h>
+#include <API/Camera/EventEndRecording.h>
+#include <API/Camera/EventGetPreviewNode.h>
+#include <Commons/Dimension.h>
+#include <Commons/WrtWrapper/IWrtCamera.h>
+
+namespace WrtDeviceApis{
+namespace Camera{
+
+DECLARE_GENERIC_EVENT_1(JobDoneTakePictureEvent,
+ Camera::Api::EventTakePictureSharedPtr)
+DECLARE_GENERIC_EVENT_1(JobDoneVideoRecordingEvent,
+ Camera::Api::EventBeginRecordingSharedPtr)
+DECLARE_GENERIC_EVENT_1(JobDoneCreatePreviewEvent,
+ Camera::Api::EventGetPreviewNodeSharedPtr)
+
+
+typedef DPL::TypeListDecl<JobDoneTakePictureEvent,
+ JobDoneVideoRecordingEvent,
+ JobDoneCreatePreviewEvent
+ >::Type JobDoneEvents;
+
+typedef DPL::Event::Controller<JobDoneEvents> CameraJobDoneController;
+
+class Camera: public Api::ICamera,
+ public CameraJobDoneController
+{
+public:
+ enum CameraState{
+ IDLE,
+ PROCESSING,
+ COMPLETED
+ };
+
+public:
+ explicit Camera(const Commons::IWrtCameraPtr& wrtCamera);
+
+ virtual ~Camera();
+
+ virtual void OnRequestReceived(
+ const Api::EventTakePictureSharedPtr &event);
+ virtual void OnRequestReceived(
+ const Api::EventBeginRecordingSharedPtr &event);
+ virtual void OnRequestReceived(
+ const Api::EventEndRecordingSharedPtr &event);
+ virtual void OnRequestReceived(
+ const Api::EventGetPreviewNodeSharedPtr &event);
+
+ virtual void OnEventReceived(const JobDoneVideoRecordingEvent &event);
+ virtual void OnEventReceived(const JobDoneCreatePreviewEvent &event);
+ virtual void OnEventReceived(const JobDoneTakePictureEvent &event);
+
+ void OnCancelEvent(const Api::EventBeginRecordingSharedPtr& event);
+ void OnCancelEvent(const Api::EventTakePictureSharedPtr& event);
+ void OnCancelEvent(const Api::EventGetPreviewNodeSharedPtr& event);
+
+ void setRecordingState(CameraState state);
+
+private:
+ static void camCaptureImageSuccessCallback(const char* filename,
+ void* data);
+ static void camCaptureVideoSuccessCallback(const char* filename,
+ void* data);
+ static void camPreviewSuccessCallback(
+ Commons::IWrtCamera::CameraPreviewNode node, void* data);
+
+ static void camCaptureImageErrorCallback(int errorCode, void* data);
+ static void camCaptureVideoErrorCallback(int errorCode, void* data);
+ static void camPreviewErrorCallback(int errorCode, void* data);
+
+ template<class EventType>
+ bool checkHighResolutionRequired(const EventType& event) const
+ {
+ return event->getCaptureOptionsRef()->getImageResolution()
+ == Api::ICaptureOptions::IMAGE_RESOLUTION_HIGH;
+ }
+
+ template<typename EventData>
+ void OnJobDoneReceived(DPL::SharedPtr<EventData> event)
+ {
+ LogDebug("enter");
+ if (event) {
+ EventRequestReceiver<EventData>::ManualAnswer(event);
+ }
+ LogDebug("post");
+ }
+
+ template<typename EventType>
+ void cancelEvent(const EventType& event)
+ {
+ LogDebug(__FUNCTION__);
+
+ if (event->checkPendingOperation()) {
+ m_wrtCamera->cancelAsyncOperation(event->getPendingOperation());
+ }
+ }
+
+ static void setPendingOperation(
+ Commons::IWrtCamera::CameraPendingOperation pendingOperation, void* data);
+
+private:
+ Commons::IWrtCameraPtr m_wrtCamera;
+
+ CameraState m_stateRecordingVideo;
+};
+
+}
+}
+#endif /* WRTPLUGINSCAMERA_H_ */
--- /dev/null
+/*
+ * 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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <dpl/foreach.h>
+#include "CameraManager.h"
+#include <Commons/Exception.h>
+#include <API/Camera/EventGetCameras.h>
+#include <API/Camera/ICamera.h>
+#include "Camera.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+
+void CameraManager::OnRequestReceived(
+ const Api::EventGetCamerasPtr &event)
+{
+ LogDebug(__FUNCTION__);
+ try
+ {
+ if (m_cameras.empty()) {
+ DPL::Mutex::ScopedLock lock(&m_accessMutex);
+
+ if (m_cameras.empty()) {
+ Commons::IWrtCameraManager::WrtCamerasPtr cameras;
+ cameras = event->
+ getConfiguration()->
+ getWrtWrapper()->
+ getCameraManagerInterface()->
+ getCameras();
+
+ FOREACH(it, *cameras)
+ {
+ Api::ICameraSharedPtr icamera(new Camera(*it));
+ m_cameras.push_back(icamera);
+ }
+ }
+ }
+ event->setCamerasRef(m_cameras,0);
+ LogDebug("Nr of cameras: " << m_cameras.size());
+ }
+ catch(const Commons::Exception &exc)
+ {
+ LogError("Exception has occurred: " << std::hex << exc.getCode());
+ event->setExceptionCode(exc.getCode());
+ }
+}
+
+}
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
*/
-#ifndef WRTDEVICEAPIS_FILESYSTEM_MOVECOMMAND_H_
-#define WRTDEVICEAPIS_FILESYSTEM_MOVECOMMAND_H_
+#ifndef WRT_PLUGINS_CAMERA_MANAGER_H_
+#define WRT_PLUGINS_CAMERA_MANAGER_H_
+
+#include <dpl/mutex.h>
-#include "Command.h"
-#include <Filesystem/IPath.h>
+#include <API/Camera/ICameraManager.h>
+#include <API/Camera/EventGetCameras.h>
namespace WrtDeviceApis {
-namespace Filesystem {
+namespace Camera {
-class MoveCommand : public Command
+class CameraManager : public Api::ICameraManager
{
- public:
- MoveCommand(const Api::IPathPtr& src,
- const Api::IPathPtr& dest);
- void setForce(bool force);
+protected:
+ virtual void OnRequestReceived(
+ const Api::EventGetCamerasPtr &event);
- protected:
- std::string prepare();
-
- private:
- Api::IPathPtr m_src;
- Api::IPathPtr m_dest;
- bool m_force;
+private:
+ DPL::Mutex m_accessMutex;
};
}
}
-
-#endif // WRTDEVICEAPIS_FILESYSTEM_MOVECOMMAND_H_
+#endif /* */
--- /dev/null
+get_current_path()
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CAMERA
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CAMERA
+ ${CURRENT_PATH}/Camera.cpp
+ ${CURRENT_PATH}/CameraManager.cpp
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CAMERA
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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.
+ */
+#include "Manager.h"
+#include <commons/Exception.h>
+
+namespace {
+const bool CLAMSHELL_SUPPORTED = false;
+const bool KEYPAD_SUPPORTED = false;
+} // anonymous
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Device {
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Manager::~Manager()
+{
+}
+
+bool Manager::hasClamshell() const
+{
+ return CLAMSHELL_SUPPORTED;
+}
+
+Api::Device::IClamshell* Manager::getClamshell() const
+{
+ ThrowMsg(Commons::UnsupportedException,
+ "Device is not equipped with clamshell.");
+}
+
+bool Manager::hasKeypad() const
+{
+ return KEYPAD_SUPPORTED;
+}
+
+Api::Device::IKeypad* Manager::getKeypad() const
+{
+ ThrowMsg(Commons::UnsupportedException,
+ "Device is not equipped with keypad.");
+}
+
+std::string Manager::getImei() const
+{
+ Try {
+ return m_imei.getString();
+ }
+ Catch(Commons::ConversionException) {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+Manager::Manager() : m_imei(VCONFKEY_TELEPHONY_IMEI)
+{
+}
+} // Device
+} // Platform
+} // WrtPlugins
--- /dev/null
+/*
+ * 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_DEVICE_MANAGER_H_
+#define WRTDEVICEAPIS_DEVICE_MANAGER_H_
+
+#include <API/Device/IManager.h>
+#include <VConf/Key.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Device {
+class Manager : public Api::Device::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ virtual ~Manager();
+
+ /**
+ * @see WrtPlugins::Api::Device::IManager::hasClamshell()
+ */
+ bool hasClamshell() const;
+
+ /**
+ * @see WrtPlugins::Api::Device::IManager::getClamshell()
+ */
+
+ Api::Device::IClamshell* getClamshell() const;
+
+ /**
+ * @see WrtPlugins::Api::Device::IManager::hasKeypad()
+ */
+ bool hasKeypad() const;
+
+ /**
+ * @see WrtPlugins::Api::Device::IManager::getKeypad()
+ */
+ Api::Device::IKeypad* getKeypad() const;
+
+ /**
+ * @see WrtPlugins::Api::Device::IManager::getImei()
+ */
+ std::string getImei() const;
+
+ protected:
+ Manager();
+
+ private:
+ VConf::Key m_imei;
+};
+} // Device
+} // Platform
+} // WrtPlugins
+
+#endif // WRTDEVICEAPIS_DEVICE_MANAGER_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(devman REQUIRED devman)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_DEVICE
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_VCONF}
+ ${devman_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_DEVICE
+ ${LIBS_PLATFORM_IMPLEMENTATION_VCONF}
+ ${devman_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_DEVICE
+ ${CURRENT_PATH}/Manager.cpp
+ ${SRCS_PLATFORM_IMPLEMENTATION_VCONF}
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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.
+ */
+#include "Manager.h"
+#include <commons/Exception.h>
+#include "Screen.h"
+
+namespace {
+const std::size_t NUMBER_OF_AVAILABLE_SCREENS = 1;
+const std::size_t INDEX_OF_DEFAULT_SCREEN = 1;
+} // anonymous
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Display {
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Api::Display::IScreen* Manager::getScreen(std::size_t index) const
+{
+ if (index == 0) {
+ index = INDEX_OF_DEFAULT_SCREEN;
+ }
+
+ if (index > NUMBER_OF_AVAILABLE_SCREENS) {
+ ThrowMsg(Commons::OutOfRangeException, "Screen is not available.");
+ }
+
+ Screens::iterator it = m_screens.find(index);
+ if (it == m_screens.end()) {
+ Api::Display::IScreen* screen = new Screen(index);
+ m_screens.insert(Screens::value_type(index, screen));
+ return screen;
+ }
+ return it->second;
+}
+
+std::size_t Manager::getScreensCount() const
+{
+ return NUMBER_OF_AVAILABLE_SCREENS;
+}
+
+Manager::~Manager()
+{
+ Screens::iterator it = m_screens.begin();
+ for (; it != m_screens.end(); ++it) {
+ delete it->second;
+ }
+}
+
+Manager::Manager()
+{
+}
+} // Display
+} // Platform
+} // WrtPlugins
--- /dev/null
+/*
+ * 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_DISPLAY_MANAGER_H_
+#define WRTDEVICEAPIS_DISPLAY_MANAGER_H_
+
+#include <map>
+#include <API/Display/IManager.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Display {
+class Manager : public Api::Display::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ ~Manager();
+
+ /**
+ * @see WrtPlugins::Api::Display::IManager::getScreen()
+ */
+ Api::Display::IScreen* getScreen(std::size_t index) const;
+
+ /**
+ * @see WrtPlugins::Api::Display::IManager::getScreensCount()
+ */
+ std::size_t getScreensCount() const;
+
+ protected:
+ typedef std::map<std::size_t, Api::Display::IScreen*> Screens;
+
+ protected:
+ Manager();
+
+ protected:
+ mutable Screens m_screens; ///< Available screen interfaces.
+};
+} // Display
+} // Platform
+} // WrtPlugins
+
+#endif // WRTDEVICEAPIS_DISPLAY_MANAGER_H_
--- /dev/null
+/*
+ * 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.
+ */
+#include "Screen.h"
+#include <stdio.h>
+#include <limits.h>
+#include <algorithm>
+#include <commons/Exception.h>
+#include <API/Display/EventChangeState.h>
+
+// TODO: attach to platform event informing about changed size!
+
+namespace {
+const char* COMMAND_XDPYINFO = "xdpyinfo";
+const char* PATTERN_COLOR_DEPTH = "depth of root window:\\s+(\\d+)\\s+planes";
+const char* PATTERN_SIZE = "dimensions:\\s+(\\d+)x(\\d+)";
+} // anonymous
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Display {
+unsigned short Screen::getColorDepth() const
+{
+ unsigned short colorDepth = 0;
+ if (!getXDpyProperty(PATTERN_COLOR_DEPTH, &colorDepth)) {
+ ThrowMsg(Commons::PlatformException, "Could not read color depth.");
+ }
+ return colorDepth;
+}
+
+Dimension Screen::getSize() const
+{
+ unsigned int width = 0, height = 0;
+ if (!getXDpyProperty(PATTERN_SIZE, &width, &height)) {
+ ThrowMsg(Commons::PlatformException, "Could not read size.");
+ }
+ return Dimension(width, height);
+}
+
+Dimension Screen::getActualSize() const
+{
+ unsigned int width = 0, height = 0;
+ if (!getXDpyProperty(PATTERN_SIZE, &width, &height)) {
+ ThrowMsg(Commons::PlatformException, "Could not read size.");
+ }
+ if (getOrientation() == Api::Display::O_LANDSCAPE) {
+ std::swap(width, height);
+ }
+ return Dimension(width, height);
+}
+
+Api::Display::Orientation Screen::getOrientation() const
+{
+ appcore_rm rot = APPCORE_RM_UNKNOWN;
+ if (appcore_get_rotation_state(&rot) != 0) {
+ ThrowMsg(Commons::PlatformException, "Could not get orientation.");
+ }
+ switch (rot) {
+ case APPCORE_RM_LANDSCAPE_NORMAL:
+ case APPCORE_RM_LANDSCAPE_REVERSE:
+ return Api::Display::O_LANDSCAPE;
+ default:
+ return Api::Display::O_PORTRAIT;
+ }
+}
+
+Api::Display::State Screen::getState() const
+{
+ Try {
+ int state = m_powerState.getInt();
+ switch (state) {
+ case VCONFKEY_PM_STATE_NORMAL:
+ return Api::Display::ST_ON;
+ case VCONFKEY_PM_STATE_LCDDIM:
+ return Api::Display::ST_DIM;
+ default:
+ return Api::Display::ST_OFF;
+ }
+ }
+ Catch(Commons::ConversionException) {
+ ReThrowMsg(Commons::PlatformException,
+ "Could not get device's power state.");
+ }
+}
+
+void Screen::addOnChangeOrientation(
+ const Api::Display::EventChangeOrientationEmitterPtr& emitter)
+{
+ m_onChangeOrientation.attach(emitter);
+ ChangeOrientationEmitters::LockType lock = m_onChangeOrientation.getLock();
+ if (m_onChangeOrientation.size() == 1) {
+ if (appcore_set_rotation_cb(onChangeOrientation, this) != 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Could not attach to platform event.");
+ }
+ }
+}
+
+void Screen::removeOnChangeOrientation(
+ Api::Display::EventChangeOrientationEmitter::IdType id)
+{
+ m_onChangeOrientation.detach(id);
+ ChangeOrientationEmitters::LockType lock = m_onChangeOrientation.getLock();
+ if (m_onChangeOrientation.size() == 0) {
+ if (appcore_unset_rotation_cb() != 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Could not detach from platform event.");
+ }
+ }
+}
+
+void Screen::addOnChangeState(
+ const Api::Display::EventChangeStateEmitterPtr& emitter)
+{
+ m_onChangeState.attach(emitter);
+ ChangeStateEmitters::LockType lock = m_onChangeState.getLock();
+ if (m_onChangeState.size() == 1) {
+ m_powerState.attachCallback(onChangeState, this);
+ }
+}
+
+void Screen::removeOnChangeState(
+ Api::Display::EventChangeStateEmitter::IdType id)
+{
+ m_onChangeState.detach(id);
+ ChangeStateEmitters::LockType lock = m_onChangeState.getLock();
+ if (m_onChangeState.size() == 0) {
+ m_powerState.detachCallback();
+ }
+}
+
+Screen::Screen(std::size_t index) :
+ m_index(index),
+ m_powerState(VCONFKEY_PM_STATE)
+{
+}
+
+bool Screen::getXDpyProperty(const char* pattern,
+ const pcrecpp::Arg& arg1,
+ const pcrecpp::Arg& arg2)
+{
+ FILE* pipe = popen(COMMAND_XDPYINFO, "r");
+ if (pipe == NULL) {
+ ThrowMsg(Commons::PlatformException,
+ "Could not initialize pipe to xdpyinfo.");
+ }
+
+ bool matched = false;
+ pcrecpp::RE re(pattern);
+ char line[LINE_MAX] = { 0 };
+ while (fgets(line, LINE_MAX, pipe)) {
+ if (re.PartialMatch(line, arg1, arg2)) {
+ matched = true;
+ break;
+ }
+ }
+ pclose(pipe);
+
+ return matched;
+}
+
+void Screen::onChangeState(const VConf::Node* /*node*/,
+ void* data)
+{
+ Screen* this_ = static_cast<Screen*>(data);
+ Api::Display::EventChangeStatePtr event(new Api::Display::EventChangeState());
+ Try {
+ event->setState(this_->getState());
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ this_->m_onChangeState.emit(event);
+}
+
+int Screen::onChangeOrientation(appcore_rm rot,
+ void* data)
+{
+ Screen* this_ = static_cast<Screen*>(data);
+ Api::Display::EventChangeOrientationPtr event(
+ new Api::Display::EventChangeOrientation());
+ Try {
+ event->setOrientation(this_->getOrientation());
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ this_->m_onChangeOrientation.emit(event);
+ //TODO check returned value
+ return 0;
+}
+} // Display
+} // Platform
+} // WrtPlugins
+
--- /dev/null
+/*
+ * 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_DISPLAY_SCREEN_H_
+#define WRTDEVICEAPIS_DISPLAY_SCREEN_H_
+
+#include <cstddef>
+#include <pcrecpp.h>
+#include <appcore-common.h>
+#include <platform/commons/Emitters.h>
+#include <API/Display/IScreen.h>
+#include <VConf/Key.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Display {
+class Manager;
+
+class Screen : public Api::Display::IScreen
+{
+ friend class Manager;
+
+ public:
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::getColorDepth()
+ */
+ unsigned short getColorDepth() const;
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::getSize()
+ */
+ Dimension getSize() const;
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::getActualSize()
+ */
+ Dimension getActualSize() const;
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::getOrientation()
+ */
+ Api::Display::Orientation getOrientation() const;
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::getState()
+ */
+ Api::Display::State getState() const;
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::addOnChangeOrientation()
+ */
+ void addOnChangeOrientation(
+ const Api::Display::EventChangeOrientationEmitterPtr& emitter);
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::removeOnChangeOrientation()
+ */
+ void removeOnChangeOrientation(
+ Api::Display::EventChangeOrientationEmitter::IdType id);
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::addOnChangeState()
+ */
+ void addOnChangeState(
+ const Api::Display::EventChangeStateEmitterPtr& emitter);
+
+ /**
+ * @see WrtPlugins::Api::Display::IScreen::removeOnChangeState()
+ */
+ void removeOnChangeState(Api::Display::EventChangeStateEmitter::IdType id);
+
+ protected:
+ typedef Emitters<Api::Display::EventChangeOrientationEmitter>
+ ChangeOrientationEmitters;
+ typedef Emitters<Api::Display::EventChangeStateEmitter> ChangeStateEmitters;
+
+ protected:
+ /**
+ * Gets data matching specified pattern from output of xdpyinfo program.
+ * @param pattern Pattern to search for.
+ * @return Zero or positive value on success, -1 on failure.
+ */
+ static bool getXDpyProperty(const char* pattern,
+ const pcrecpp::Arg& arg1 = pcrecpp::RE::no_arg,
+ const pcrecpp::Arg& arg2 = pcrecpp::RE::no_arg);
+
+ /**
+ * Callback run when device's power state changes.
+ * @param node Node object (unused).
+ * @param data User data.
+ */
+ static void onChangeState(const VConf::Node* node,
+ void* data);
+
+ /**
+ * Callback run when device's orientation changes.
+ * @param rot Rotation mode.
+ * @param data User data.
+ * @return Error code (?) - not specified in documentation.
+ */
+ static int onChangeOrientation(appcore_rm rot,
+ void* data);
+
+ protected:
+ explicit Screen(std::size_t index);
+
+ protected:
+ std::size_t m_index; ///< Index of the screen.
+ ChangeOrientationEmitters m_onChangeOrientation; ///< Change orientation emitters.
+ ChangeStateEmitters m_onChangeState; ///< Change state emitters.
+ VConf::Key m_powerState; ///< Key for power manager state.
+};
+} // Display
+} // Platform
+} // WrtPlugins
+
+#endif // WRTDEVICEAPIS_DISPLAY_SCREEN_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+pkg_search_module(appcore REQUIRED appcore-common)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_DISPLAY
+ ${pcrecpp_INCLUDE_DIRS}
+ ${appcore_INCLUDE_DIRS}
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_VCONF}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_DISPLAY
+ ${pcrecpp_LIBRARIES}
+ ${appcore_LIBRARIES}
+ ${LIBS_PLATFORM_IMPLEMENTATION_VCONF}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_DISPLAY
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/Screen.cpp
+ ${SRCS_PLATFORM_IMPLEMENTATION_VCONF}
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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.
+ */
+/*
+ * @author Bartlomiej Grzelewski
+ */
+
+#include <dpl/log/log.h>
+#include <commons/JSCallbackManager.h>
+#include <vector>
+#include "FeatureManager.h"
+
+using namespace WrtPlugins::Api;
+
+namespace WrtPlugins {
+namespace Platform {
+//static void wrtPlatformCallback(int widgetHandler, JSObjectRef object, void* userParam)
+//{
+// FeatureManager::platformCallback(widgetHandler, static_cast<void*>(object), userParam);
+//}
+
+void FeatureManager::OnRequestReceived(const Api::EventLoadFeaturePtr &event)
+{
+ //TODO commented
+ //EventWrapper *eventWrapper = new EventWrapper(this, event);
+ LogDebug("Call for dynamic feature: " << event->getFeature().c_str());
+ JSCallbackManagerPtr jsCallbackManager =
+ DPL::StaticPointerCast<JSCallbackManager,
+ Platform::IEventPrivateData>(
+ event->getPrivateData());
+ /* TODO uncomment - this function _will_ be available in new wrt-engine API */
+ LogError("*** CRITICAL wrt_dynamic_feature_request is disable!");
+ // wrt_dynamic_feature_request(jsCallbackManager->getContext(), event->getFeature().c_str(), wrtPlatformCallback, eventWrapper);
+}
+
+void FeatureManager::platformCallback(int,
+ void* object,
+ void* userParam)
+{
+ if (object == NULL) {
+ LogError("Request has been rejected.");
+ } else {
+ LogDebug("Request has been approved.");
+ }
+ EventWrapper *eventWrapper = static_cast<EventWrapper*>(userParam);
+ eventWrapper->m_event->setObject(object);
+ eventWrapper->m_event->setStatus((object == 0) ? false : true);
+ eventWrapper->m_featureManager->Platform::EventRequestReceiver<
+ EventLoadFeature>::ManualAnswer(eventWrapper->m_event);
+ delete eventWrapper;
+}
+} // namespace Platform
+} // namespace WrtPlugins
--- /dev/null
+/*
+ * 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.
+ */
+#ifndef _SLP20_FEATUREMANAGER_H_
+#define _SLP20_FEATUREMANAGER_H_
+
+/*
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ */
+
+#include "API/FeatureLoader/IFeatureManager.h"
+
+namespace WrtPlugins {
+namespace Platform {
+class FeatureManager :
+ public Api::IFeatureManager
+{
+ public:
+ FeatureManager()
+ {
+ }
+ virtual ~FeatureManager()
+ {
+ }
+ static void platformCallback(int,
+ void* object,
+ void* userParam);
+ protected:
+ virtual void OnRequestReceived(const Api::EventLoadFeaturePtr &event);
+ private:
+ struct EventWrapper
+ {
+ EventWrapper(FeatureManager *featureManager,
+ const Api::EventLoadFeaturePtr &event) :
+ m_featureManager(featureManager),
+ m_event(event)
+ {
+ }
+
+ ~EventWrapper()
+ {
+ }
+
+ FeatureManager *m_featureManager;
+ Api::EventLoadFeaturePtr m_event;
+ };
+};
+} // namespace Platform
+} // namespace WrtPlugins
+
+#endif // _SLP20_FEATUREMANAGER_H_
--- /dev/null
+get_current_path()
+
+set(SRCS_PLATFORM_IMPLEMENTATION_FEATURE_MANAGER
+ ${CURRENT_PATH}/FeatureManager.cpp
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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 Gallery.cpp
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ */
+
+#include <algorithm>
+#include <commons/Exception.h>
+#include <API/Filesystem/INode.h>
+#include <API/Filesystem/Enums.h>
+#include "Gallery.h"
+
+using namespace std;
+using namespace DPL;
+using namespace WrtPlugins::Api::Gallery;
+using namespace WrtPlugins::Api::Filesystem;
+
+namespace WrtPlugins {
+namespace Platform {
+using namespace Filesystem;
+
+namespace {
+//Map file extension to IMediaItem type
+map<string, IMediaItem::MediaType> &createExtToTypeMap()
+{
+ static map<string, IMediaItem::MediaType> retMap;
+ retMap["jpg"] = IMediaItem::IMAGE;
+ retMap["jpeg"] = IMediaItem::IMAGE;
+ retMap["gif"] = IMediaItem::IMAGE;
+ retMap["bmp"] = IMediaItem::IMAGE;
+ retMap["png"] = IMediaItem::IMAGE;
+ retMap["wav"] = IMediaItem::AUDIO;
+ retMap["mp3"] = IMediaItem::AUDIO;
+ retMap["wmv"] = IMediaItem::VIDEO;
+ retMap["3gp"] = IMediaItem::VIDEO;
+ return retMap;
+}
+
+//Map file extension to MIME type
+map<string, string> &createExtToMimeMap()
+{
+ static map<string, string> retMap;
+ retMap["jpg"] = "image/jpeg";
+ retMap["jpeg"] = "image/jpeg";
+ retMap["gif"] = "image/gif";
+ retMap["bmp"] = "image/bmp";
+ retMap["png"] = "image/png";
+ retMap["wav"] = "audio/wav";
+ retMap["mp3"] = "audio/mpeg3";
+ retMap["wmv"] = "video/x - ms - wmv";
+ retMap["3gp"] = "video/3gpp";
+ return retMap;
+}
+
+bool compareByFilename(const IMediaItemPtr &lpm,
+ const IMediaItemPtr &rpm)
+{
+ return lpm->getFileName().compare(rpm->getFileName()) < 0;
+}
+
+bool compareByFileDate(const IMediaItemPtr &lpm,
+ const IMediaItemPtr &rpm)
+{
+ return lpm->getDate() < rpm->getDate();
+}
+
+bool compareByType(const IMediaItemPtr &lpm,
+ const IMediaItemPtr &rpm)
+{
+ return lpm->getType() < rpm->getType();
+}
+
+class SearchIdObj
+{
+ unsigned long m_id;
+ public:
+ SearchIdObj(unsigned long id) : m_id(id)
+ {
+ }
+ bool operator ()(const IMediaItemPtr &elem)
+ {
+ return elem->getId() == m_id;
+ }
+};
+} //private namespace
+
+map<string,
+ IMediaItem::MediaType> &Gallery::m_extensionToType = createExtToTypeMap();
+map<string, string> &Gallery::m_extensionToMime = createExtToMimeMap();
+
+unsigned int Gallery::getNumberOfItems() const
+{
+ if (!m_opened) {
+ Throw(Commons::PlatformWrongStateException);
+ }
+ //if gallery is opened m_view always stores an object
+ return m_view->size();
+}
+
+std::string Gallery::getName() const
+{
+ LogDebug("Gallery name: " << m_name);
+ return m_name;
+}
+
+void Gallery::open()
+{
+ if (m_opened) {
+ Throw(Commons::PlatformWrongStateException);
+ }
+ m_mediaItems.clear();
+ m_lastId = 0;
+ Path path("/");
+ SharedPtr<INode> node(Node::resolve(path));
+ node->setPermissions(PERM_READ);
+ searchFiles(node);
+ //Destroy previous view and store new one
+ m_view = IMediaItemsSetPtr(new IMediaItemsSet(m_mediaItems));
+ m_opened = true;
+ LogDebug("Gallery contains " << m_mediaItems.size() << " items");
+}
+
+void Gallery::searchFiles(const SharedPtr<INode> &node)
+{
+ if (Api::Filesystem::NT_FILE == node->getType()) {
+ string fileName = node->getPath().getName();
+ size_t dotPos = fileName.find_last_of(".");
+ if (dotPos == string::npos) {
+ //Not supported file
+ return;
+ }
+ string fileExt = fileName.substr(dotPos + 1);
+ //Check if file has supported type
+ map<string, string>::iterator it = m_extensionToMime.find(fileExt);
+ if (it != m_extensionToMime.end()) {
+ IMediaItemPtr mediaItem(new IMediaItem());
+ mediaItem->setId(getFreeId());
+ mediaItem->setFileName(fileName);
+ mediaItem->setType(m_extensionToType[fileExt]);
+ mediaItem->setMimeType(m_extensionToMime[fileExt]);
+ mediaItem->setDate(node->getCreated());
+ m_mediaItems.push_back(mediaItem);
+ }
+ return;
+ }
+
+ //else get recurrent on NT_DIRECTORY
+ NodeList nodes = node->getChildNodes();
+ NodeList::iterator it = nodes.begin(), end = nodes.end();
+ while (it != end) {
+ //Warning: '*it' element will be deleted after out of scope (next iteration)
+ (*it)->setPermissions(PERM_READ);
+ searchFiles(SharedPtr<INode>(*it));
+ ++it;
+ }
+}
+
+unsigned long Gallery::getFreeId()
+{
+ return ++m_lastId;
+}
+
+bool Gallery::isOpen() const
+{
+ return m_opened;
+}
+
+void Gallery::close()
+{
+ if (!m_opened) {
+ Throw(Commons::PlatformWrongStateException);
+ }
+ m_mediaItems.clear();
+ m_view.Reset();
+ m_lastId = 0;
+ m_opened = false;
+}
+
+void Gallery::refresh()
+{
+ if (!m_opened) {
+ Throw(Commons::PlatformWrongStateException);
+ }
+ m_mediaItems.clear();
+ m_view->clear();
+ m_lastId = 0;
+ Path path("/");
+ SharedPtr<Node> node(Node::resolve(path));
+ node->setPermissions(PERM_READ);
+ searchFiles(DynamicPointerCast<INode>(node));
+ changeView(m_viewProperties);
+ LogDebug("Gallery contains " << m_mediaItems.size() << " items");
+}
+
+void Gallery::changeView(const IViewProperties &props)
+{
+ if (!m_opened) {
+ Throw(Commons::PlatformWrongStateException);
+ }
+ m_viewProperties = props;
+ m_view->clear();
+
+ //Copy elements within date period to view struct
+ for (IMediaItemsSetIterator it = m_mediaItems.begin(),
+ end = m_mediaItems.end();
+ it != end; ++it) {
+ if ((m_viewProperties.getStartDate() <= (*it)->getDate()) &&
+ ((*it)->getDate() <= m_viewProperties.getEndDate())) {
+ m_view->push_back(*it);
+ }
+ }
+
+ //sort elements
+ IViewProperties::SortOrder sortOrder[] = {
+ m_viewProperties.getSecondarySortOrder(),
+ m_viewProperties.getPrimarySortOrder()
+ };
+ for (size_t i = 0; i < (sizeof(sortOrder) / sizeof(sortOrder[0])); ++i) {
+ switch (sortOrder[i]) {
+ case IViewProperties::BY_FILEDATE:
+ m_view->sort(compareByFileDate);
+ break;
+ case IViewProperties::BY_FILENAME:
+ m_view->sort(compareByFilename);
+ break;
+ case IViewProperties::BY_TYPE:
+ m_view->sort(compareByType);
+ break;
+ default:
+ break;
+ }
+ }
+
+ //reverse order if necessary
+ if (IViewProperties::DESCENDING == m_viewProperties.getSortOrder()) {
+ m_view->reverse();
+ }
+ LogDebug("View contains " << m_view->size() << " items");
+}
+
+const IMediaItemsSetPtr Gallery::getMediaItems() const
+{
+ if (!m_opened) {
+ Throw(Commons::PlatformWrongStateException);
+ }
+ LogError("View contains " << m_view->size() << " entries");
+ return m_view;
+}
+
+const IMediaItemPtr Gallery::getMediaItemById(unsigned long id) const
+{
+ if (!m_opened) {
+ Throw(Commons::PlatformWrongStateException);
+ }
+ SearchIdObj searchObj(id);
+ IMediaItemsSetConstIterator elem = find_if(
+ m_mediaItems.begin(), m_mediaItems.end(), searchObj);
+ if (elem == m_mediaItems.end()) {
+ Throw(Commons::InvalidArgumentException);
+ }
+ return *elem;
+}
+}
+}
--- /dev/null
+/*
+ * 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.
+ */
+#ifndef WRTDEVICEAPIS_PLATFORM_GALLERY_GALLERY_H_
+#define WRTDEVICEAPIS_PLATFORM_GALLERY_GALLERY_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <map>
+#include <platform/commons/EventReceiver.h>
+#include <API/Gallery/IGallery.h>
+#include <API/Gallery/IMediaItem.h>
+#include <Filesystem/Path.h>
+#include <Filesystem/Node.h>
+
+namespace WrtPlugins {
+namespace Platform {
+class Gallery : public Api::Gallery::IGallery
+{
+ /*
+ * Gallery name
+ */
+ std::string m_name;
+ /*
+ * Stores state of the gallery
+ */
+ bool m_opened;
+ /*
+ * Last ID field is used to give for an MediaItem unique ID
+ */
+ unsigned long m_lastId;
+ /*
+ * Set of all media items found on device
+ */
+ Api::Gallery::IMediaItemsSet m_mediaItems;
+ /*
+ * Set of media items selected by changeView method
+ */
+ Api::Gallery::IMediaItemsSetPtr m_view;
+ /*
+ * Properties to manage view of media items
+ */
+ Api::Gallery::IViewProperties m_viewProperties;
+
+ /*
+ * Map to convert from file extension to media type
+ */
+ static std::map<std::string,
+ Api::Gallery::IMediaItem::MediaType> &m_extensionToType;
+ /*
+ * Map to convert from file extension to MIME type
+ */
+ static std::map<std::string,
+ std::string> &m_extensionToMime;
+
+ /*
+ * Recurrent search files trough whole tree exposed by file manager
+ * \param node - node to start from
+ * \exception - Filesystem related
+ */
+ void searchFiles(const DPL::SharedPtr<Api::Filesystem::INode> &node);
+ /*
+ * Gets free ID
+ */
+ unsigned long getFreeId();
+
+ public:
+ /*
+ * Constructor of the gallery
+ * \param name - the gallery name
+ */
+ Gallery(const std::string &name) :
+ IGallery(),
+ m_name(name),
+ m_opened(false),
+ m_lastId(0)
+ {
+ }
+ /*
+ * Destructor of the gallery
+ */
+ virtual ~Gallery()
+ {
+ }
+
+ /*
+ * Gets number of media items selected by current view
+ * \exception Commons::PlatformWrongStateException when gallery not open
+ * \return number of media items
+ */
+ virtual unsigned int getNumberOfItems() const;
+ /*
+ * Gets name of the gallery
+ * \return name of the gallery
+ */
+ virtual std::string getName() const;
+ /*
+ * Opens the gallery
+ * \exception Commons::PlatformWrongStateException when gallery is already open
+ */
+ virtual void open();
+ /* Gets the current state of the gallery
+ * \return true if the gallery is open
+ */
+ virtual bool isOpen() const;
+ /*
+ * Closes the gallery
+ * \exception Commons::PlatformWrongStateException when gallery is not open
+ */
+ virtual void close();
+ /*
+ * Refreshes files in the gallery
+ * \exception Commons::PlatformWrongStateException when gallery is not open
+ */
+ virtual void refresh();
+ /*
+ * Changes current view with given properties
+ * \param props - view properties
+ * \exception Commons::PlatformWrongStateException when gallery is not open
+ */
+ virtual void changeView(const Api::Gallery::IViewProperties &props);
+ /*
+ * Gets media items selected by current view
+ * \return set of media items
+ * \exception Commons::PlatformWrongStateException when gallery is not open
+ */
+ virtual const Api::Gallery::IMediaItemsSetPtr getMediaItems() const;
+ /*
+ * Gets specified media item
+ * \param id of wanted item
+ * \return an media item
+ * \exception Commons::PlatformWrongStateException when gallery is not open
+ */
+ virtual const Api::Gallery::IMediaItemPtr getMediaItemById(unsigned long id)
+ const;
+};
+} // Platform
+} // WrtPlugins
+
+#endif // WRTDEVICEAPIS_PLATFORM_GALLERY_GALLERY_H_
--- /dev/null
+/*
+ * 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 GalleryRequestManager.cpp
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ */
+
+#include <commons/Exception.h>
+#include <API/Gallery/IGallery.h>
+#include "GalleryRequestManager.h"
+#include "Gallery.h"
+
+using namespace WrtPlugins::Commons;
+using namespace WrtPlugins::Api::Gallery;
+
+namespace WrtPlugins {
+namespace Platform {
+void GalleryRequestManager::OnRequestReceived(
+ const IEventGetGalleriesPtr &event)
+{
+ IGallerySetPtr galleries(new IGallerySet());
+ galleries->push_back(IGalleryPtr(new Gallery("Device")));
+ event->setGalleries(galleries);
+ event->setResult(ExceptionCodes::None);
+}
+
+void GalleryRequestManager::OnRequestReceived(const IEventOpenPtr &event)
+{
+ Try
+ {
+ IGalleryPtr gallery(event->getGallery());
+ gallery->open();
+ event->setResult(ExceptionCodes::None);
+ }
+ Catch(Exception)
+ {
+ LogError("Gallery exception message: " <<
+ _rethrown_exception.GetMessage() <<
+ " Code: " << _rethrown_exception.getCode());
+ event->setResult(_rethrown_exception.getCode());
+ }
+}
+
+void GalleryRequestManager::OnRequestReceived(const IEventRefreshPtr &event)
+{
+ Try
+ {
+ IGalleryPtr gallery(event->getGallery());
+ gallery->refresh();
+ event->setResult(ExceptionCodes::None);
+ }
+ Catch(Exception)
+ {
+ LogError("Gallery exception message: " <<
+ _rethrown_exception.GetMessage() <<
+ " Code: " << _rethrown_exception.getCode());
+ event->setResult(_rethrown_exception.getCode());
+ }
+}
+
+void GalleryRequestManager::OnRequestReceived(const IEventClosePtr &event)
+{
+ Try
+ {
+ IGalleryPtr gallery(event->getGallery());
+ gallery->close();
+ event->setResult(ExceptionCodes::None);
+ }
+ Catch(Exception)
+ {
+ LogError("Gallery exception message: " <<
+ _rethrown_exception.GetMessage() <<
+ " Code: " << _rethrown_exception.getCode());
+ event->setResult(_rethrown_exception.getCode());
+ }
+}
+
+void GalleryRequestManager::OnRequestReceived(const IEventChangeViewPtr &event)
+{
+ Try
+ {
+ IGalleryPtr gallery(event->getGallery());
+ gallery->changeView(event->getProperties());
+ event->setResult(ExceptionCodes::None);
+ }
+ Catch(Exception)
+ {
+ LogError("Gallery exception message: " <<
+ _rethrown_exception.GetMessage() <<
+ " Code: " << _rethrown_exception.getCode());
+ event->setResult(_rethrown_exception.getCode());
+ }
+}
+
+void GalleryRequestManager::OnRequestReceived(
+ const IEventGetMediaItemsPtr &event)
+{
+ Try
+ {
+ IGalleryPtr gallery(event->getGallery());
+ IMediaItemsSetPtr mediaItems(gallery->getMediaItems());
+ event->setMediaItems(mediaItems);
+ event->setResult(ExceptionCodes::None);
+ }
+ Catch(Exception)
+ {
+ LogError("Gallery exception message: " <<
+ _rethrown_exception.GetMessage() <<
+ " Code: " << _rethrown_exception.getCode());
+ event->setResult(_rethrown_exception.getCode());
+ }
+}
+
+void GalleryRequestManager::OnRequestReceived(
+ const IEventGetMediaItemByIdPtr &event)
+{
+ Try
+ {
+ IGalleryPtr gallery(event->getGallery());
+ IMediaItemPtr mediaItem(gallery->getMediaItemById(event->getId()));
+ event->setMediaItem(mediaItem);
+ event->setResult(ExceptionCodes::None);
+ }
+ Catch(Exception)
+ {
+ LogError("Gallery exception message: " <<
+ _rethrown_exception.GetMessage() <<
+ " Code: " << _rethrown_exception.getCode());
+ event->setResult(_rethrown_exception.getCode());
+ }
+}
+}
+}
--- /dev/null
+/*
+ * 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 GalleryRequestManager.h
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRT_PLUGINS_GALLERYREQUESTMANAGER_H_
+#define WRT_PLUGINS_GALLERYREQUESTMANAGER_H_
+
+#include <API/Gallery/IGalleryRequestManager.h>
+
+namespace WrtPlugins {
+namespace Platform {
+class GalleryRequestManager : public Api::Gallery::IGalleryRequestManager
+{
+ public:
+
+ protected:
+ virtual void OnRequestReceived(
+ const Api::Gallery::IEventGetGalleriesPtr &event);
+ virtual void OnRequestReceived(const Api::Gallery::IEventOpenPtr &event);
+ virtual void OnRequestReceived(const Api::Gallery::IEventRefreshPtr &event);
+ virtual void OnRequestReceived(const Api::Gallery::IEventClosePtr &event);
+ virtual void OnRequestReceived(
+ const Api::Gallery::IEventChangeViewPtr &event);
+ virtual void OnRequestReceived(
+ const Api::Gallery::IEventGetMediaItemsPtr &event);
+ virtual void OnRequestReceived(
+ const Api::Gallery::IEventGetMediaItemByIdPtr &event);
+};
+}
+}
+
+#endif //WRT_PLUGINS_GALLERYREQUESTMANAGER_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(libpcrecpp REQUIRED libpcrecpp)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_GALLERY
+ ${CURRENT_PATH}/Gallery.cpp
+ ${CURRENT_PATH}/GalleryRequestManager.cpp
+ PARENT_SCOPE
+)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_GALLERY
+ ${libpcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_GALLERY
+ ${libpcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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.
+ */
+/*
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ */
+
+#include "Geolocation.h"
+#include <cassert>
+#include <API/Geolocation/EventGetCurrentPosition.h>
+#include <commons/Exception.h>
+
+using namespace WrtPlugins::Api::Geolocation;
+using namespace DPL;
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Geolocation {
+namespace {
+static void positionChangedCallback(LocationObject *obj,
+ guint type,
+ gpointer data,
+ gpointer accuracy,
+ Geolocation* this_)
+{
+ if (this_) {
+ this_->positionHasChanged(obj, type, data, accuracy);
+ } else {
+ LogError("Callback private data is NULL.");
+ }
+}
+} //private namespace
+
+Geolocation::Geolocation() :
+ m_location(NULL),
+ m_currentLocationMethod(METHOD_GPS),
+ m_initialized(false)
+{
+ LogDebug("Enter");
+}
+
+Geolocation::~Geolocation()
+{
+ LogDebug("Enter");
+ stop();
+}
+
+void Geolocation::getCurrentPosition(const EventGetCurrentPositionPtr& event)
+{
+ initialize();
+ EventRequestReceiver<EventGetCurrentPosition>::PostRequest(event);
+}
+
+void Geolocation::OnRequestReceived(const EventGetCurrentPositionPtr& event)
+{
+ LogDebug("Entered");
+ gint ret;
+ LocationPosition* pos = NULL;
+ LocationAccuracy* acc = NULL;
+ ret = location_get_position(m_location, &pos, &acc);
+ if (LOCATION_ERROR_NONE != ret) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ } else if (LOCATION_ACCURACY_LEVEL_NONE != acc->level) {
+ location_position_free(pos);
+ location_accuracy_free(acc);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ event->setTimestamp(static_cast<std::time_t>(pos->timestamp));
+ event->setLatitude(static_cast<double>(pos->latitude));
+ event->setLongitude(static_cast<double>(pos->longitude));
+ event->setAltitude(static_cast<double>(pos->altitude));
+ event->setAccuracy(static_cast<double>(acc->horizontal_accuracy));
+ event->setAltitudeAccuracy(static_cast<double>(acc->vertical_accuracy));
+ location_position_free(pos);
+ location_accuracy_free(acc);
+
+ LocationVelocity* velocity = NULL;
+ ret = location_get_velocity(m_location, &velocity, &acc);
+ if (LOCATION_ERROR_NONE != ret) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ } else if (LOCATION_ACCURACY_LEVEL_NONE != acc->level) {
+ location_velocity_free(velocity);
+ location_accuracy_free(acc);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ event->setSpeed(static_cast<double>(velocity->speed));
+ event->setDirection(static_cast<double>(velocity->direction));
+ event->setAltitudeSpeed(static_cast<double>(velocity->climb));
+ event->setMethod(m_currentLocationMethod);
+ location_velocity_free(velocity);
+ location_accuracy_free(acc);
+}
+
+long Geolocation::watchPosition(const EventPositionChangedEmitterPtr& emitter,
+ long timeout,
+ long maximumAge,
+ bool highAccuracy)
+{
+ initialize();
+ m_positionEmitters.attach(emitter);
+ return static_cast<long>(emitter->getId());
+}
+
+void Geolocation::clearWatch(EventPositionChangedEmitter::IdType id)
+{
+ m_positionEmitters.detach(id);
+}
+
+void Geolocation::positionHasChanged(LocationObject *obj,
+ guint type,
+ gpointer data,
+ gpointer accuracy)
+{
+ LogDebug("Enter");
+ if (POSITION_UPDATED != type) {
+ //nothing to do
+ return;
+ }
+
+ //convert data from platform to API form
+ LocationPosition *pos = static_cast<LocationPosition*>(data);
+ LocationAccuracy *acc = static_cast<LocationAccuracy*>(accuracy);
+ LocationVelocity* velocity = NULL;
+
+ EventPositionChangedPtr event(new EventPositionChanged());
+ PositionProperties props;
+ props.altitude = static_cast<double>(pos->altitude);
+ props.latitude = static_cast<double>(pos->latitude);
+ props.longitude = static_cast<double>(pos->longitude);
+ props.timestamp = static_cast<std::time_t>(pos->timestamp);
+ props.accuracy = static_cast<double>(acc->horizontal_accuracy);
+ props.altitudeAccuracy = static_cast<double>(acc->vertical_accuracy);
+
+ gint ret = location_get_velocity(m_location, &velocity, &acc);
+ if (LOCATION_ERROR_NONE != ret) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ } else if (LOCATION_ACCURACY_LEVEL_NONE != acc->level) {
+ location_velocity_free(velocity);
+ location_accuracy_free(acc);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ props.speed = static_cast<double>(velocity->speed);
+ props.direction = static_cast<double>(velocity->direction);
+ props.altitudeSpeed = static_cast<double>(velocity->climb);
+ location_velocity_free(velocity);
+ location_accuracy_free(acc);
+
+ event->setPositionProperties(props);
+ m_positionEmitters.emit(event);
+}
+
+void Geolocation::changeLocationMethod(ApiLocationMethod method)
+{
+ LogDebug("Enter");
+ if (method != m_currentLocationMethod) {
+ m_currentLocationMethod = method;
+ if (m_location) {
+ restart();
+ }
+ }
+}
+
+void Geolocation::initialize()
+{
+ LogDebug("ENTER");
+ if (!m_initialized) {
+ DPL::Mutex::ScopedLock lock(&m_initializationMutex);
+ if (!m_initialized) {
+ if (LOCATION_ERROR_NONE != location_init()) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't init location module.");
+ }
+ m_initialized = true;
+ start();
+ }
+ }
+}
+
+void Geolocation::restart()
+{
+ stop();
+ start();
+}
+
+void Geolocation::start()
+{
+ LogDebug("ENTER");
+ assert(m_initialized && "Geolocation has not been initialized.");
+ if (m_location) {
+ return;
+ }
+
+ m_location = location_new(convertMethodToPlatform(m_currentLocationMethod)); //may return NULL
+ if (NULL == m_location) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't create new location object.");
+ }
+
+ if (LOCATION_ERROR_NONE != location_start(m_location)) {
+ location_free(m_location);
+ m_location = NULL;
+ ThrowMsg(Commons::PlatformException, "Couldn't start localizing.");
+ }
+ m_signalId = g_signal_connect(m_location, "service-updated",
+ G_CALLBACK(positionChangedCallback), this);
+}
+
+void Geolocation::stop()
+{
+ LogDebug("ENTER");
+ if (!m_initialized || !m_location) {
+ return;
+ }
+
+ g_signal_handler_disconnect(m_location, m_signalId);
+ if (LOCATION_ERROR_NONE != location_stop(m_location)) {
+ ThrowMsg(Commons::PlatformException, "Couldn't stop location object.");
+ }
+ if (LOCATION_ERROR_NONE != location_free(m_location)) {
+ ThrowMsg(Commons::PlatformException, "Couldn't free location module.");
+ }
+ m_location = NULL;
+}
+
+LocationMethod Geolocation::convertMethodToPlatform(ApiLocationMethod method)
+const
+{
+ switch (method) {
+ case METHOD_GPS:
+ return LOCATION_METHOD_GPS;
+ case METHOD_AGPS:
+ return LOCATION_METHOD_HYBRID;
+ case METHOD_CPS:
+ return LOCATION_METHOD_CPS;
+ case METHOD_IPS:
+ return LOCATION_METHOD_IPS;
+ case METHOD_WPS:
+ return LOCATION_METHOD_WPS;
+ case METHOD_BEST:
+ return LOCATION_METHOD_HYBRID;
+ }
+ LogError("Unknown location method");
+ return LOCATION_METHOD_HYBRID;
+}
+}
+}
+}
--- /dev/null
+/*
+ * 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.
+ */
+/*
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_PLATFORM_GEOLOCATION_H_
+#define WRTDEVICEAPIS_PLATFORM_GEOLOCATION_H_
+
+#include <map>
+#include <API/Geolocation/IGeolocation.h>
+#include <API/Geolocation/GeolocationFactory.h>
+#include <API/Geolocation/EventPositionChanged.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <location/location.h>
+#include <platform/commons/Emitters.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Geolocation {
+class Geolocation : public Api::Geolocation::IGeolocation
+{
+ LocationObject *m_location;
+ gulong m_signalId;
+ Api::Geolocation::IGeolocation::ApiLocationMethod m_currentLocationMethod;
+
+ friend class WrtPlugins::Api::Geolocation::GeolocationFactory;
+
+ public:
+ virtual ~Geolocation();
+
+ /**
+ * @See: IGelocation::getCurrentPosition
+ */
+ virtual void getCurrentPosition(
+ const Api::Geolocation::EventGetCurrentPositionPtr& event);
+
+ /**
+ * @See: IGelocation::watchPosition
+ */
+ virtual long watchPosition(
+ const Api::Geolocation::EventPositionChangedEmitterPtr& emitter,
+ long timeout,
+ long maximumAge,
+ bool highAccuracy);
+
+ /**
+ * @See: IGelocation::clearWatch
+ */
+ virtual void clearWatch(
+ Api::Geolocation::EventPositionChangedEmitter::IdType id);
+
+ /**
+ * @See: IGelocation::changeLocationMethod
+ */
+ virtual void changeLocationMethod(ApiLocationMethod method);
+
+ /**
+ * Method to run from platform's callback function
+ */
+ void positionHasChanged(LocationObject *obj,
+ guint type,
+ gpointer data,
+ gpointer accuracy);
+
+ protected:
+ Geolocation();
+ virtual void OnRequestReceived(
+ const Api::Geolocation::EventGetCurrentPositionPtr& event);
+
+ private:
+ typedef Emitters<Api::Geolocation::EventPositionChangedEmitter>
+ PositionChangedEmitters;
+
+ void initialize();
+ void start();
+ void stop();
+ void restart();
+ LocationMethod convertMethodToPlatform(ApiLocationMethod method) const;
+
+ PositionChangedEmitters m_positionEmitters;
+ DPL::Mutex m_initializationMutex;
+ bool m_initialized;
+};
+}
+}
+}
+
+#endif /* WRTDEVICEAPIS_PLATFORM_GEOLOCATION_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(location REQUIRED location)
+pkg_search_module(glib REQUIRED glib-2.0)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_GEOLOCATION
+ ${location_INCLUDE_DIRS}
+ ${glib_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_GEOLOCATION
+ ${location_LIBRARIES}
+ ${glib_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_GEOLOCATION
+ ${CURRENT_PATH}/Geolocation.cpp
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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.
+ */
+#include <fstream>
+#include <cassert>
+#include <pcrecpp.h>
+#include <commons/Exception.h>
+#include "Manager.h"
+
+namespace {
+const char* MEMINFO_FILE = "/proc/meminfo";
+const char* MEMORY_TOTAL_PATTERN = "^MemTotal:\\s+(\\d+)\\s*kB$";
+const char* MEMORY_FREE_PATTERN = "^MemFree:\\s+(\\d+)\\s*kB$";
+}
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Memory {
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+unsigned long Manager::getTotal() const
+{
+ return getMeminfoValue(MEMORY_TOTAL_PATTERN);
+}
+
+unsigned long Manager::getFree() const
+{
+ return getMeminfoValue(MEMORY_FREE_PATTERN);
+}
+
+Manager::Manager()
+{
+}
+
+unsigned long Manager::getMeminfoValue(const char* pattern) const
+{
+ assert(pattern && "Pattern not set.");
+
+ std::ifstream file(MEMINFO_FILE);
+ if (!file) {
+ ThrowMsg(Commons::PlatformException, "Memory info file not found.");
+ }
+
+ unsigned long result = 0;
+ bool matched = false;
+ std::string line;
+ while ((std::getline(file, line).rdstate() &
+ (std::ifstream::failbit | std::ifstream::eofbit)) == 0) {
+ if (pcrecpp::RE(pattern).FullMatch(line, &result)) {
+ matched = true;
+ break;
+ }
+ }
+ file.close();
+
+ if (!matched) {
+ ThrowMsg(Commons::UnsupportedException, "Total memory data not found.");
+ }
+
+ return result;
+}
+} // Memory
+} // Platform
+} // WrtPlugins
--- /dev/null
+/*
+ * 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.
+ */
+#ifndef WRTDEVICEAPIS_MEMORY_MANAGER_H_
+#define WRTDEVICEAPIS_MEMORY_MANAGER_H_
+
+#include <API/Memory/IManager.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Memory {
+class Manager : public Api::Memory::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ unsigned long getTotal() const;
+ unsigned long getFree() const;
+
+ private:
+ Manager();
+
+ /**
+ * Reads value from meminfo file looking it up using specified regex pattern.
+ * Function matches each (whole!) line against specified pattern.
+ * @param pattern Perl-like regular expresion used to search through meminfo.
+ * @return Found value.
+ * @throw PlatformException If could not find meminfo file.
+ * @throw UnsupportedException If pattern didn't match any line in meminfo file.
+ */
+ unsigned long getMeminfoValue(const char* pattern) const;
+};
+} // Memory
+} // Platform
+} // WrtPlugins
+
+#endif /* WRTDEVICEAPIS_MEMORY_MANAGER_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_MEMORY
+ ${pcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_MEMORY
+ ${pcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_MEMORY
+ ${CURRENT_PATH}/Manager.cpp
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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.
+ */
+#include "Date.h"
+#include <cstddef>
+#include <commons/Exception.h>
+
+namespace {
+const std::size_t MAX_BUFFER_SIZE = 80;
+} // anonymous
+
+namespace WrtPlugins {
+namespace Platform {
+namespace System {
+Api::System::IDate::Format Date::m_defualtFormat = "%c";
+
+Date::Date()
+{
+ m_timestamp = time(NULL);
+}
+
+std::string Date::toString() const
+{
+ return toString(m_defualtFormat);
+}
+
+std::string Date::toString(const Format& format) const
+{
+ if (format.empty()) {
+ ThrowMsg(Commons::PlatformException, "Format is not set.");
+ }
+
+ char buffer[MAX_BUFFER_SIZE] = { 0 };
+ struct tm* tm = std::localtime(&m_timestamp);
+ if (std::strftime(buffer, MAX_BUFFER_SIZE, format.c_str(), tm) == 0) {
+ ThrowMsg(Commons::PlatformException, "Could not get date string.");
+ }
+
+ return buffer;
+}
+} // System
+} // Platform
+} // WrtPlugins
--- /dev/null
+/*
+ * 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_SYSTEM_DATE_H_
+#define WRTDEVICEAPIS_SYSTEM_DATE_H_
+
+#include <ctime>
+#include <API/System/IDate.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace System {
+class Date : public Api::System::IDate
+{
+ public:
+ Date();
+
+ /**
+ * @see WrtPlugins::Api::System::IDate::toString()
+ */
+ std::string toString() const;
+
+ /**
+ * @see WrtPlugins::Api::System::IDate::toString()
+ */
+ std::string toString(const Format& format) const;
+
+ protected:
+ static Format m_defualtFormat; ///< Default format for to string conversion.
+
+ protected:
+ std::time_t m_timestamp; ///< Timestamp, number of seconds since UNIX epoch.
+};
+} // System
+} // Platform
+} // WrtPlugins
+
+#endif // WRTDEVICEAPIS_SYSTEM_DATE_H_
--- /dev/null
+/*
+ * 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.
+ */
+#include "Environment.h"
+#include <stdlib.h>
+#include <sys/utsname.h>
+#include <stdio.h>
+#include <limits.h>
+extern "C" {
+ #include <iniparser.h>
+}
+#include <pcrecpp.h>
+#include <sstream>
+#include <commons/Exception.h>
+
+namespace {
+const char* VARIABLE_LANGUAGE_NAME = "LANG";
+const char* VENDOR_NAME = "Samsung";
+const char* FILE_INFO_INI = "/etc/info.ini";
+const char* FILE_CPUINFO = "/proc/cpuinfo";
+const char* PATTERN_CPUINFO_HARDWARE = "^Hardware\\s*:\\s+(\\w+)\\s*$";
+} // anonymous
+
+namespace WrtPlugins {
+namespace Platform {
+namespace System {
+// TODO: Most of those values (if not any) doesn't have to be recalculated every
+// time someone request them. Optimalization could be introduced to do it
+// only once, e.g. on first request.
+
+Environment& Environment::getInstance()
+{
+ static Environment instance;
+ return instance;
+}
+
+std::string Environment::getLanguage() const
+{
+ return getVariable(VARIABLE_LANGUAGE_NAME);
+}
+
+std::string Environment::getOsVersion() const
+{
+ struct utsname buf;
+ if (uname(&buf) != 0) {
+ ThrowMsg(Commons::PlatformException, "Could not get uname data.");
+ }
+ return buf.sysname;
+}
+
+std::string Environment::getSoftwareVersion() const
+{
+ dictionary* dict = iniparser_load(FILE_INFO_INI);
+ if (dict == NULL) {
+ ThrowMsg(Commons::PlatformException, "Could not get SW version.");
+ }
+ char* major =
+ iniparser_getstring(dict, ("Version:Major"), const_cast<char*>(""));
+
+ const char* minor =
+ iniparser_getstring(dict, "Version:Minor", const_cast<char*>(""));
+
+ std::stringstream ss;
+ ss << major;
+ if ((*major != '\0') && (*minor != '\0')) {
+ ss << "-";
+ }
+ ss << minor;
+ iniparser_freedict(dict);
+
+ return ss.str();
+}
+
+std::string Environment::getHardwareName() const
+{
+ FILE* file = fopen(FILE_CPUINFO, "r");
+ if (file == NULL) {
+ ThrowMsg(Commons::UnsupportedException, "Could not open cpuinfo file.");
+ }
+
+ std::string result;
+ char line[LINE_MAX] = { 0 };
+ pcrecpp::RE re(PATTERN_CPUINFO_HARDWARE);
+ while (fgets(line, LINE_MAX, file) && !re.FullMatch(line, &result)) {
+ }
+ fclose(file);
+
+ if (result.empty()) {
+ ThrowMsg(Commons::UnsupportedException, "Hardware name not found.");
+ }
+
+ return result;
+}
+
+std::string Environment::getVendorName() const
+{
+ return VENDOR_NAME;
+}
+
+std::string Environment::getVariable(const char* name)
+{
+ char* value = getenv(name);
+ if (value == NULL) {
+ std::stringstream ss;
+ ss << "Could not read variable " << name << ".";
+ ThrowMsg(Commons::PlatformException, ss.str());
+ }
+ return value;
+}
+
+Environment::Environment()
+{
+}
+} // System
+} // Platform
+} // WrtPlugins
--- /dev/null
+/*
+ * 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_SYSTEM_ENVIRONMENT_H_
+#define WRTDEVICEAPIS_SYSTEM_ENVIRONMENT_H_
+
+#include <API/System/IEnvironment.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace System {
+class Environment : public Api::System::IEnvironment
+{
+ public:
+ static Environment& getInstance();
+
+ public:
+ /**
+ * @see WrtPlugins::Api::System::IEnvironment::getLanguage()
+ */
+ std::string getLanguage() const;
+
+ /**
+ * @see WrtPlugins::Api::System::IEnvironment::getOsVersion()
+ */
+ std::string getOsVersion() const;
+
+ /**
+ * @see WrtPlugins::Api::System::IEnvironment::getSoftwareVersion()
+ */
+ std::string getSoftwareVersion() const;
+
+ /**
+ * @see WrtPlugins::Api::System::IEnvironment::getHardwareName()
+ */
+ std::string getHardwareName() const;
+
+ /**
+ * @see WrtPlugins::Api::System::IEnvironment::getVendorName()
+ */
+ std::string getVendorName() const;
+
+ protected:
+ /**
+ * Gets value of specified environment variable.
+ * @param name Name of the variable.
+ * @return Value of the variable.
+ * @throw PlatformException If specified variable doesn't exist.
+ */
+ static std::string getVariable(const char* name);
+
+ protected:
+ Environment();
+};
+} // System
+} // Platform
+} // WrtPlugins
+
+#endif // WRTDEVICEAPIS_SYSTEM_ENVIRONMENT_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(iniparser REQUIRED iniparser)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_SYSTEM
+ ${iniparser_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_SYSTEM
+ ${iniparser_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_SYSTEM
+ ${CURRENT_PATH}/Environment.cpp
+ ${CURRENT_PATH}/Date.cpp
+ PARENT_SCOPE
+)
--- /dev/null
+/*
+ * 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 LogEntryWrapper.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.2
+ */
+
+#include <string>
+#include <dpl/log/log.h>
+#include <pcrecpp.h>
+#include "LogEntryWrapper.h"
+#include "commons/Exception.h"
+
+using namespace WrtPlugins::Api;
+
+namespace WrtPlugins {
+namespace Platform {
+LogEntryWrapper::LogEntryWrapper(CTSvalue *log) :
+ m_logEntry(new LogEntry())
+{
+ LogDebug("entered");
+ convertPlatformStructToAbstractStruct(log);
+}
+
+LogEntryWrapper::~LogEntryWrapper()
+{
+ LogDebug("entered");
+}
+
+bool LogEntryWrapper::matchFilters(const LogFilterPtr &filter)
+{
+ LogDebug("entered");
+ if (!m_logEntry) {
+ Throw(WrtPlugins::Commons::NullPointerException);
+ }
+ if (!filter) {
+ return true;
+ }
+ if (filter->getIdIsSet() && filter->getIdFilter() != m_logEntry->getId()) {
+ return false;
+ }
+ if (filter->getStartTimeIsSet() &&
+ (filter->getStartTimeMinFilter() > m_logEntry->getStartTime() ||
+ filter->getStartTimeMaxFilter() < m_logEntry->getStartTime())) {
+ return false;
+ }
+ if (filter->getDurationIsSet() &&
+ (filter->getDurationMinFilter() > m_logEntry->getDuration() ||
+ filter->getDurationMaxFilter() < m_logEntry->getDuration())) {
+ return false;
+ }
+ if (filter->getPhoneNumberIsSet() &&
+ !pcrecpp::RE(filter->getPhoneNumberFilter()).FullMatch(m_logEntry->
+ getPhoneNumber()))
+ {
+ return false;
+ }
+ if (filter->getDescriptionIsSet() &&
+ !pcrecpp::RE(filter->getDescriptionFilter()).FullMatch(m_logEntry->
+ getDescription()))
+ {
+ return false;
+ }
+ if (filter->getFolderIsSet() &&
+ !filter->checkIfFolderIsSet(m_logEntry->getFolder())) {
+ return false;
+ } else if (m_logEntry->getFolder() == LogEntry::INVALID_FOLDER) {
+ return false;
+ }
+ return true;
+}
+
+bool LogEntryWrapper::convertPlatformStructToAbstractStruct(CTSvalue *log)
+{
+ LogDebug("entered");
+ if (!m_logEntry) {
+ return false;
+ }
+ if (!log) {
+ return true;
+ }
+ const char *charVal =
+ contacts_svc_value_get_str(log, CTS_LIST_PLOG_NUMBER_STR);
+ if (charVal) {
+ LogDebug("phone number " << charVal);
+ m_logEntry->setPhoneNumber(charVal);
+ }
+ charVal = contacts_svc_value_get_str(log, CTS_LIST_PLOG_SHORTMSG_STR);
+ if (charVal) {
+ m_logEntry->setDescription(charVal);
+ }
+ m_logEntry->setDuration(
+ contacts_svc_value_get_int(log, CTS_LIST_PLOG_DURATION_INT));
+ LogDebug("id " <<
+ contacts_svc_value_get_int(log, CTS_LIST_PLOG_DURATION_INT));
+ m_logEntry->setStartTime(
+ contacts_svc_value_get_int(log, CTS_LIST_PLOG_LOG_TIME_INT));
+ m_logEntry->setId(
+ contacts_svc_value_get_int(log, CTS_LIST_PLOG_ID_INT));
+ LogDebug("id " << contacts_svc_value_get_int(log, CTS_LIST_PLOG_ID_INT));
+ switch (contacts_svc_value_get_int(log, CTS_LIST_PLOG_LOG_TYPE_INT)) {
+ case CTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
+ case CTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
+ case CTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
+ case CTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
+ m_logEntry->setFolder(LogEntry::MISSED_CALLS_FOLDER);
+ break;
+ case CTS_PLOG_TYPE_VIDEO_INCOMMING:
+ case CTS_PLOG_TYPE_VOICE_INCOMMING:
+ m_logEntry->setFolder(LogEntry::RECEIVED_CALLS_FOLDER);
+ break;
+ case CTS_PLOG_TYPE_VIDEO_OUTGOING:
+ case CTS_PLOG_TYPE_VOICE_OUTGOING:
+ m_logEntry->setFolder(LogEntry::INITIATED_CALLS_FOLDER);
+ break;
+ default:
+ LogDebug("Invalid folder");
+ m_logEntry->setFolder(LogEntry::INVALID_FOLDER);
+ break;
+ }
+ return true;
+}
+
+Api::LogEntryPtr LogEntryWrapper::getAbstractCall() const
+{
+ return m_logEntry;
+}
+}
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 LogEntryWrapper.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.2
+ */
+
+#ifndef _SLP20_LOG_ENTRY_WRAPPER_H_
+#define _SLP20_LOG_ENTRY_WRAPPER_H_
+
+#include <dpl/shared_ptr.h>
+#include <contacts-svc.h>
+#include <API/Telephony/LogEntry.h>
+#include <API/Telephony/LogFilter.h>
+
+namespace WrtPlugins {
+namespace Platform {
+class LogEntryWrapper
+{
+ public:
+ explicit LogEntryWrapper(CTSvalue *log);
+ virtual ~LogEntryWrapper();
+ bool matchFilters(const Api::LogFilterPtr &filter);
+ Api::LogEntryPtr getAbstractCall() const;
+ private:
+ Api::LogEntryPtr m_logEntry;
+ bool convertPlatformStructToAbstractStruct(CTSvalue *log);
+};
+
+typedef DPL::SharedPtr<LogEntryWrapper> LogEntryWrapperPtr;
+}
+}
+
+#endif /* _SLP20_EVENT_WRAPPER_H_ */
--- /dev/null
+/*
+ * 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 LogManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.2
+ */
+
+#include <dpl/log/log.h>
+#include <contacts-svc.h>
+#include <vector>
+#include "LogManager.h"
+#include "LogEntryWrapper.h"
+
+using namespace WrtPlugins::Api;
+
+namespace WrtPlugins {
+namespace Platform {
+int LogManager::m_instanceCount = 0;
+
+LogManager::LogManager()
+{
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ if (m_instanceCount == 0) {
+ LogDebug("opening calllog DB");
+ if (CTS_SUCCESS != contacts_svc_connect()) {
+ LogError("database not opened");
+ }
+ }
+ m_instanceCount++;
+}
+
+LogManager::~LogManager()
+{
+ LogDebug("entered");
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ m_instanceCount--;
+ if (m_instanceCount == 0) {
+ LogDebug("closing calllog DB");
+ contacts_svc_disconnect();
+ }
+}
+
+void LogManager::OnRequestReceived(const Api::IEventGetNumberOfLogsPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ int result = getNumberOfLogsInternal(event->getFilter());
+ event->setNumberOfLogs(result);
+ }
+ Catch(Commons::Exception)
+ {
+ LogError("Error during searching logs");
+ return;
+ }
+ event->setResult(true);
+}
+
+void LogManager::OnRequestReceived(const Api::IEventFindLogEntriesPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ std::vector<LogEntryPtr> result = findLogEntriesInternal(
+ event->getFilter(), event->getFirstCall(), event->getLastCall());
+ std::vector<LogEntryPtr>::const_iterator it;
+ for (it = result.begin(); it != result.end(); it++) {
+ event->addLog(*it);
+ }
+ }
+ Catch(Commons::Exception)
+ {
+ LogError("Error during searching logs");
+ return;
+ }
+ event->setResult(true);
+}
+
+void LogManager::OnRequestReceived(const Api::IEventDeleteLogEntryPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ if (!event->getFilter() || !event->getFilter()->getIdIsSet()) {
+ return;
+ }
+ deleteLogEntryInternal(event->getFilter()->getIdFilter());
+ }
+ Catch(Commons::Exception)
+ {
+ LogError("Error during deleting log");
+ return;
+ }
+ event->setResult(true);
+}
+
+void LogManager::OnRequestReceived(const Api::IEventClearLogPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ clearLogInternal(event->getFilter());
+ }
+ Catch(Commons::Exception)
+ {
+ LogError("Error during deleting logs");
+ return;
+ }
+ event->setResult(true);
+}
+
+int LogManager::getNumberOfLogsInternal(const LogFilterPtr &filter)
+{
+ LogDebug("entered");
+ if (!filter) {
+ LogWarning("filter is NULL");
+ return 0;
+ }
+ int result = 0;
+ CTSiter *iter = NULL;
+ contacts_svc_get_list(CTS_LIST_GROUPING_PLOG, &iter);
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue *log = contacts_svc_iter_get_info(iter);
+ if (NULL == log) {
+ LogError("funtion returned NULL value");
+ continue;
+ }
+ LogEntryWrapperPtr wrapper(new LogEntryWrapper(log));
+ if (wrapper->matchFilters(filter)) {
+ result++;
+ }
+ contacts_svc_value_free(log);
+ }
+ contacts_svc_iter_remove(iter);
+ return result;
+}
+
+std::vector<Api::LogEntryPtr> LogManager::findLogEntriesInternal(
+ const LogFilterPtr &filter,
+ const int minIndex,
+ const int maxIndex)
+{
+ LogDebug("entered");
+ std::vector<LogEntryPtr> result;
+ CTSiter *iter = NULL;
+ contacts_svc_get_list(CTS_LIST_GROUPING_PLOG, &iter);
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue *log = contacts_svc_iter_get_info(iter);
+ if (NULL == log) {
+ LogError("funtion returned NULL value");
+ continue;
+ }
+ LogEntryWrapperPtr wrapper(new LogEntryWrapper(log));
+ if (wrapper->matchFilters(filter)) {
+ result.push_back(wrapper->getAbstractCall());
+ }
+ contacts_svc_value_free(log);
+ }
+ contacts_svc_iter_remove(iter);
+ return result;
+}
+
+void LogManager::deleteLogEntryInternal(int id) const
+{
+ LogDebug("entered");
+ if (CTS_SUCCESS != contacts_svc_delete_phonelog(CTS_PLOG_DEL_BY_ID, id)) {
+ ThrowMsg(Commons::PlatformException, "Cannot delete log");
+ }
+ return;
+}
+
+void LogManager::clearLogInternal(const LogFilterPtr &filter)
+{
+ LogDebug("entered");
+ CTSiter *iter = NULL;
+ contacts_svc_get_list(CTS_LIST_GROUPING_PLOG, &iter);
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue *log = contacts_svc_iter_get_info(iter);
+ if (NULL == log) {
+ LogError("funtion returned NULL value");
+ continue;
+ }
+ LogEntryWrapperPtr wrapper(new LogEntryWrapper(log));
+ if (wrapper->matchFilters(filter)) {
+ deleteLogEntryInternal(wrapper->getAbstractCall()->getId());
+ }
+ contacts_svc_value_free(log);
+ }
+ contacts_svc_iter_remove(iter);
+ return;
+}
+}
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 LogManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.2
+ */
+
+#ifndef _SLP20__LOG_MANAGER_H_
+#define _SLP20__LOG_MANAGER_H_
+
+#include <vector>
+#include <dpl/mutex.h>
+#include <dpl/shared_ptr.h>
+#include <API/Telephony/ILogManager.h>
+#include <API/Telephony/LogEntry.h>
+#include <API/Telephony/LogFilter.h>
+#include <API/Telephony/IEventGetNumberOfLogs.h>
+#include <API/Telephony/IEventFindLogEntries.h>
+#include <API/Telephony/IEventDeleteLogEntry.h>
+#include <API/Telephony/IEventClearLogs.h>
+
+namespace WrtPlugins {
+namespace Platform {
+class LogManager : public Api::ILogManager
+{
+ public:
+ LogManager();
+ virtual ~LogManager();
+ protected:
+ virtual void OnRequestReceived(
+ const Api::IEventGetNumberOfLogsPtr &event);
+ virtual void OnRequestReceived(
+ const Api::IEventFindLogEntriesPtr &event);
+ virtual void OnRequestReceived(
+ const Api::IEventDeleteLogEntryPtr &event);
+ virtual void OnRequestReceived(
+ const Api::IEventClearLogPtr &event);
+ int getNumberOfLogsInternal(
+ const Api::LogFilterPtr &filter);
+ std::vector<Api::LogEntryPtr> findLogEntriesInternal(
+ const Api::LogFilterPtr &filter,
+ const int minIndex = -1,
+ const int maxIndex = -1);
+ void deleteLogEntryInternal(int id) const;
+ void clearLogInternal(
+ const Api::LogFilterPtr &filter);
+ static int m_instanceCount;
+ DPL::Mutex m_constructorMutex;
+};
+
+typedef DPL::SharedPtr<LogManager> LogManagerPtr;
+}
+}
+
+#endif /* _SLP20__LOG_MANAGER_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(contacts-service REQUIRED contacts-service)
+pkg_search_module(glib REQUIRED glib-2.0)
+pkg_search_module(libpcrecpp REQUIRED libpcrecpp)
+
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_TELEPHONY
+ ${contacts-service_INCLUDE_DIRS}
+ ${glib_INCLUDE_DIRS}
+ ${libpcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_TELEPHONY
+ ${contacts-service_LIBRARIES}
+ ${glib_LIBRARIES}
+ ${libpcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_TELEPHONY
+ ${CURRENT_PATH}/LogManager.cpp
+ ${CURRENT_PATH}/LogEntryWrapper.cpp
+ PARENT_SCOPE
+)
--- /dev/null
+get_current_path()
+
+set(SRCS_PLATFORM_IMPLEMENTATION_UI
+# ${CURRENT_PATH}/Camera.cpp
+ PARENT_SCOPE
+)
+++ /dev/null
-/*
- * 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.
- */
-/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- */
-
-#include "Command.h"
-#include <cstdlib>
-#include <Commons/Exception.h>
-
-namespace WrtDeviceApis {
-namespace Filesystem {
-
-void Command::execute()
-{
- int result = system(prepare().c_str());
- if (-1 != result) {
- if (0 != WIFEXITED(result)) {
- if (0 != WEXITSTATUS(result)) {
- ThrowMsg(Commons::PlatformException, "Command failed.");
- }
- } else {
- ThrowMsg(Commons::PlatformException,
- "Command terminated abnormally.");
- }
- } else {
- ThrowMsg(Commons::PlatformException, "Couldn't launch command.");
- }
-}
-
-}
-}
+++ /dev/null
-/*
- * 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.
- */
-/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- */
-
-#ifndef WRTDEVICEAPIS_FILESYSTEM_COMMAND_H_
-#define WRTDEVICEAPIS_FILESYSTEM_COMMAND_H_
-
-#include <string>
-
-namespace WrtDeviceApis {
-namespace Filesystem {
-
-class Command
-{
- public:
- virtual ~Command()
- {
- }
- void execute();
-
- protected:
- /**
- * Returns command converted into string that has to be safe to be executed
- * using system() function (@see man 3p system).
- * @attention Underlying command has to be passed by absolute path.
- * E.g. use '/bin/cp' instead of just 'cp'.
- * @attention Do not chain a few commands as one.
- * This is wrong: 'cmd1 && cmd2; cmd3'.
- * @return Command string - please ensure that the command is safe to run.
- */
- virtual std::string prepare() = 0;
-};
-
-}
-}
-
-#endif // WRTDEVICEAPIS_FILESYSTEM_COMMAND_H_
+++ /dev/null
-/*
- * 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.
- */
-/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- */
-
-#include "CopyCommand.h"
-#include <sstream>
-
-namespace {
-const char* COMMAND_NAME = "/bin/cp";
-const char* COMMAND_SWITCH_RECURSIVE = "-r";
-const char* COMMAND_SWITCH_FORCE = "-f";
-}
-
-namespace WrtDeviceApis {
-namespace Filesystem {
-
-using namespace Api;
-
-CopyCommand::CopyCommand(const IPathPtr& src,
- const IPathPtr& dest) :
- m_src(src),
- m_dest(dest),
- m_recursive(false),
- m_force(false)
-{
-}
-
-void CopyCommand::setRecursive(bool recursive)
-{
- m_recursive = recursive;
-}
-
-void CopyCommand::setForce(bool force)
-{
- m_force = force;
-}
-
-std::string CopyCommand::prepare()
-{
- std::ostringstream oss;
- oss << COMMAND_NAME;
-
- if (m_recursive) {
- oss << " " << COMMAND_SWITCH_RECURSIVE;
- }
-
- if (m_force) {
- oss << " " << COMMAND_SWITCH_FORCE;
- }
-
- oss << " \"" << m_src->getFullPath().c_str() << "\"";
- oss << " \"" << m_dest->getFullPath().c_str() << "\"";
-
- return oss.str();
-}
-
-}
-}
#include <cstdio>
#include <sstream>
#include <dirent.h>
+#include <ecore-1/Ecore_File.h>
+#include <eina-1/eina/eina_list.h>
#include <dpl/log/log.h>
#include <dpl/scoped_ptr.h>
#include <dpl/errno_string.h>
#include <Commons/Regex.h>
#include <Filesystem/PathUtils.h>
#include "Node.h"
-#include "System.h"
-#include "CopyCommand.h"
-#include "MoveCommand.h"
-#include "RemoveCommand.h"
#include "Utils.h"
namespace {
bool Manager::checkIfOpened(const IPathPtr& path) const
{
+ Assert(path);
NodeListIterator it = m_openedNodes.begin();
for (; it != m_openedNodes.end(); ++it) {
+ Assert(*it);
if (*path == *(*it)->getPath()) {
return true;
}
const EventFindPtr& event)
{
Try {
+ Assert(path && "path is NULL");
+
DIR* dir = opendir(path->getFullPath().c_str());
if (!dir) {
return;
}
}
+void Manager::copyElement(
+ const std::string &src, const std::string &dest, bool recursive) const
+{
+ LogDebug("Copying src: " << src << " to: " << dest);
+
+ //element is a file:
+ if (EINA_TRUE != ecore_file_is_dir(src.c_str())) {
+ if (EINA_TRUE != ecore_file_cp(src.c_str(), dest.c_str())) {
+ ThrowMsg(Commons::PlatformException, "Failed to copy file");
+ }
+ return;
+ }
+ //element is a directory -> create it:
+ if (EINA_TRUE != ecore_file_mkdir(dest.c_str())) {
+ LogDebug("Failed to create destination directory");
+ ThrowMsg(Commons::PlatformException, "Failed to copy directory");
+ }
+ //copy all elements of directory:
+ if (recursive) {
+ Eina_List* list = ecore_file_ls(src.c_str());
+ void* data;
+ EINA_LIST_FREE(list, data)
+ {
+ Try
+ {
+ copyElement((src + '/' + static_cast<char*>(data)).c_str(),
+ (dest + '/' + static_cast<char*>(data)).c_str());
+ }
+ Catch(Commons::PlatformException)
+ {
+ //remove rest of the list
+ EINA_LIST_FREE(list, data)
+ {
+ free(data);
+ }
+ ReThrowMsg(Commons::PlatformException, "Failed to copy element");
+ }
+ free(data);
+ }
+ }
+
+}
+
bool Manager::access(const IPathPtr& path,
int accessType) const
{
{
Try {
INodePtr srcNode = Node::resolve(event->getSource());
- if ((srcNode->getMode() & PERM_READ) == 0) {
+ int requiredAccess;
+ switch (srcNode->getType()) {
+ case NT_DIRECTORY:
+ requiredAccess = AT_EXEC;
+ break;
+ case NT_FILE:
+ requiredAccess = AT_READ;
+ break;
+ }
+ if (!access(srcNode->getPath(), requiredAccess)) {
ThrowMsg(Commons::SecurityException,
- "Not enough permissions to read source node.");
+ "Not enough permissions to copy source node.");
}
IPathPtr src = event->getSource();
IPathPtr dest = event->getDestination();
+
+ Assert(dest);
if (!dest->isAbsolute()) {
dest = src->getPath() + *dest;
}
if (src == dest) {
ThrowMsg(Commons::PlatformException,
- "Destination is same as source.");
+ "Destination is same as source: " <<
+ srcNode->getPath()->getFullPath());
}
INodePtr parent;
"Destination's parent node is not directory.");
}
+ if (!access(parent->getPath(), AT_WRITE)) {
+ ThrowMsg(Commons::SecurityException,
+ "Not enough permissions to copy source node to destination.");
+ }
+
std::string realSrc = src->getFullPath();
std::string realDest = dest->getFullPath();
"No access to platform destination node.");
}
- if (((event->getOptions() & OPT_OVERWRITE) == 0) && (status == 0)) {
- ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
- }
+ if (0 == status) {
+ //no owerwrite flag setted -> exception
+ if ((event->getOptions() & OPT_OVERWRITE) == 0) {
+ ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
+ }
- if (event->checkCancelled()) {
- //file is not copied yet, so we can cancel it now.
- event->setCancelAllowed(true);
- return;
- }
+ if (event->checkCancelled()) {
+ //file is not copied yet, so we can cancel it now.
+ event->setCancelAllowed(true);
+ return;
+ }
- if (event->getOptions() & OPT_OVERWRITE) {
- DPL::ScopedPtr<RemoveCommand> remove(new RemoveCommand(dest));
- remove->setRecursive(true);
- remove->setForce(true);
- System::run(remove.Get());
+ //destination exist. Need to be removed
+ Try {
+ INodePtr node = Node::resolve(event->getDestination());
+ node->remove(event->getOptions());
+ }
+ Catch(Commons::PlatformException) {
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ event->setExceptionCode(
+ Commons::ExceptionCodes::PlatformException);
+ }
+ Catch(Commons::SecurityException) {
+ event->setExceptionCode(
+ Commons::ExceptionCodes::SecurityException);
+ }
}
-
- DPL::ScopedPtr<CopyCommand> copy(new CopyCommand(src, dest));
- copy->setRecursive(true);
- System::run(copy.Get());
+ //Destination is not exist. Start copy now.
+ copyElement(realSrc, realDest);
event->setResult(Node::resolve(dest));
}
- Catch(Commons::PlatformException) {
+ catch (const Commons::PlatformException& ex) {
+ LogError("Exception: " << ex.GetMessage());
event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
}
- Catch(Commons::SecurityException) {
+ catch (const Commons::SecurityException& ex) {
+ LogError("Exception: " << ex.GetMessage());
event->setExceptionCode(Commons::ExceptionCodes::SecurityException);
}
//file is copied already so we don't allow cancelling anymore.
IPathPtr dest = event->getDestination();
INodePtr srcNode = Node::resolve(src);
- if ((srcNode->getMode() & PERM_WRITE) == 0)
- {
+ if (!access(srcNode->getParent()->getPath(), AT_WRITE)) {
ThrowMsg(Commons::SecurityException,
- "Not enough permissions to move source node.");
+ "Not enough permissions to move source node.");
}
+ Assert(dest);
if (!dest->isAbsolute()) {
dest = src->getPath() + *dest;
}
if (src == dest) {
ThrowMsg(Commons::PlatformException,
- "Destination is same as source.");
+ "Destination is same as source: " <<
+ srcNode->getPath()->getFullPath());
}
INodePtr parent;
"Destination's parent node is not directory.");
}
+ if (!access(parent->getPath(), AT_WRITE)) {
+ ThrowMsg(Commons::SecurityException,
+ "Not enough permissions to move source node to destination.");
+ }
+
errno = 0;
struct stat info;
memset(&info, 0, sizeof(info));
{
case EXDEV:
{
- if ((srcNode->getMode() & PERM_READ) == 0)
- {
- ThrowMsg(Commons::SecurityException,
- "Not enough permissions to move source node.");
+ if (0 == status) {
+ //destination exist. Need to be removed
+ Try {
+ INodePtr node = Node::resolve(
+ event->getDestination());
+ node->remove(event->getOptions());
+ }
+ Catch(Commons::PlatformException) {
+ LogError("Exception while removing dest directory");
+ event->setExceptionCode(
+ Commons::ExceptionCodes::PlatformException);
+ }
+ Catch(Commons::SecurityException) {
+ event->setExceptionCode(
+ Commons::ExceptionCodes::SecurityException);
+ }
+ }
+
+ copyElement(src->getFullPath(),
+ dest->getFullPath());
+ //remove source files
+ Try {
+ INodePtr node = Node::resolve(event->getSource());
+ node->remove(event->getOptions());
+ }
+ Catch(Commons::Exception) {
+ LogError("Exception: "
+ << _rethrown_exception.GetMessage());
}
- DPL::ScopedPtr<MoveCommand>
- move(new MoveCommand(src, dest));
- move->setForce(event->getOptions() & OPT_OVERWRITE);
- System::run(move.Get());
break;
}
default:
static void setupLocation(Api::LocationType location,
const char* path);
+ void copyElement(const std::string &src,
+ const std::string &dest,
+ bool recursive = true) const;
+
private:
static Locations m_locations; ///< Paths to default locations.
static const std::size_t m_maxPathLength; ///< Maximum path length.
+++ /dev/null
-/*
- * 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.
- */
-/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- */
-
-#include "MoveCommand.h"
-#include <sstream>
-
-namespace {
-const char* COMMAND_NAME = "/bin/mv";
-const char* COMMAND_SWITCH_FORCE = "-f";
-}
-
-namespace WrtDeviceApis {
-namespace Filesystem {
-
-using namespace Api;
-
-MoveCommand::MoveCommand(const IPathPtr& src,
- const IPathPtr& dest) :
- m_src(src),
- m_dest(dest),
- m_force(false)
-{
-}
-
-void MoveCommand::setForce(bool force)
-{
- m_force = force;
-}
-
-std::string MoveCommand::prepare()
-{
- std::ostringstream oss;
- oss << COMMAND_NAME;
-
- if (m_force) {
- oss << " " << COMMAND_SWITCH_FORCE;
- }
-
- oss << " \"" << m_src->getFullPath().c_str() << "\"";
- oss << " \"" << m_dest->getFullPath().c_str() << "\"";
-
- return oss.str();
-}
-
-}
-}
continue;
}
Try {
+ Assert(m_path);
INodePtr node = Node::resolve(*m_path + entry->d_name);
node->setPermissions(getPermissions()); // inherit access rights
if (NodeFilterMatcher::match(node, filter)) {
ThrowMsg(Commons::SecurityException, "Not enough permissions.");
}
+ Assert(m_path);
+ Assert(path);
IPathPtr childPath = *m_path + *path;
if (exists(childPath)) {
ThrowMsg(Commons::PlatformException, "Node already exists.");
{
LocationPaths roots = IManager::getInstance().getLocationPaths();
for (LocationPaths::iterator it = roots.begin(); it != roots.end(); ++it) {
+ Assert(*it);
+ Assert(m_path);
if (*(*it) == *m_path) {
return INodePtr();
}
void Node::removeAsDirectory(const IPathPtr& path,
bool recursive)
{
+ Assert(path);
if (recursive) {
DIR* dir = opendir(path->getFullPath().c_str());
if (!dir) {
+++ /dev/null
-/*
- * 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.
- */
-/**
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- */
-
-#include "RemoveCommand.h"
-#include <sstream>
-
-namespace {
-const char* COMMAND_NAME = "/bin/rm";
-const char* COMMAND_SWITCH_RECURSIVE = "-r";
-const char* COMMAND_SWITCH_FORCE = "-f";
-}
-
-namespace WrtDeviceApis {
-namespace Filesystem {
-
-using namespace Api;
-
-RemoveCommand::RemoveCommand(const IPathPtr& path) :
- m_path(path),
- m_recursive(false),
- m_force(false)
-{
-}
-
-void RemoveCommand::setRecursive(bool recursive)
-{
- m_recursive = recursive;
-}
-
-void RemoveCommand::setForce(bool force)
-{
- m_force = force;
-}
-
-std::string RemoveCommand::prepare()
-{
- std::ostringstream oss;
- oss << COMMAND_NAME;
-
- if (m_recursive) {
- oss << " " << COMMAND_SWITCH_RECURSIVE;
- }
-
- if (m_force) {
- oss << " " << COMMAND_SWITCH_FORCE;
- }
-
- oss << " \"" << m_path->getFullPath().c_str() << "\"";
-
- return oss.str();
-}
-
-} // Filesystem
-} // WrtDeviceApis
get_current_path()
-pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+pkg_search_module(pcrecpp REQUIRED libpcrecpp
+ ecore REQUIRED ecore-1)
set(INCLUDES_PLATFORM_IMPLEMENTATION_FILESYSTEM
${pcrecpp_INCLUDE_DIRS}
+ ${ecore_INCLUDE_DIRS}
PARENT_SCOPE
)
set(LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM
${pcrecpp_LIBRARIES}
+ ${ecore_LIBRARIES}
PARENT_SCOPE
)
${CURRENT_PATH}/Node.cpp
${CURRENT_PATH}/Path.cpp
${CURRENT_PATH}/Stream.cpp
- ${CURRENT_PATH}/System.cpp
${CURRENT_PATH}/NodeFilterMatcher.cpp
- ${CURRENT_PATH}/Command.cpp
- ${CURRENT_PATH}/CopyCommand.cpp
- ${CURRENT_PATH}/MoveCommand.cpp
- ${CURRENT_PATH}/RemoveCommand.cpp
${CURRENT_PATH}/Utils.cpp
PARENT_SCOPE
)
#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
#include <dpl/wrt-dao-ro/WrtDatabase.h>
#include <plugin_logic.h>
+#include <js_types.h>
#include <dpl/wrt-dao-ro/common_dao_types.h>
#include <Commons/Exception.h>
#include <CommonsJavaScript/Converter.h>
#include <dpl/log/log.h>
#include <dpl/foreach.h>
+
using namespace std;
namespace {
JSObjectRef object,
JSContextRef context) :
m_widgetHandle(widgetHandle),
+ m_objectInstance(object),
m_objectUri(GLOBAL_OBJECT_NAME),
m_shortUri(objectUri),
- m_objectInstance(object),
m_context(context)
{
m_objectUri.append(SEPARATOR).append(objectUri);
continue;
}
- PluginLogic::JavaScriptObject jsObject = {m_objectInstance,
+ JavaScriptObject jsObject = {m_objectInstance,
m_shortUri};
return PluginLogicSingleton::Instance().loadPluginOnDemand(
- handle, jsObject);
+ handle, jsObject, const_cast<JSGlobalContextRef>(m_context));
}
}
LogError("Plugin not loaded");
get_current_path()
pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
-pkg_search_module(wrt-plugin-loading REQUIRED wrt-plugin-loading)
+#pkg_search_module(wrt-plugin-loading REQUIRED wrt-plugin-loading)
set(INCLUDES_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER
${dpl-wrt-dao-ro_INCLUDE_DIRS}
${wrt-plugin-loading_INCLUDE_DIRS}
+ ${PLUGIN_LOADING_DIRS}
PARENT_SCOPE
)
set(LIBS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER
${dpl-wrt-dao-ro_LIBRARIES}
${wrt-plugin-loading_LIBRARIES}
+ ${TARGET_PLUGIN_LOADING_LIB}
PARENT_SCOPE
)
const std::string& paramValue)
{
//LogDebug("entered");
- m_params[paramName] = paramValue;
+ m_params.push_back(std::make_pair(paramName, paramValue));
}
WidgetFeature::~WidgetFeature()
get_current_path()
pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
+pkg_search_module(dpl-utils-efl REQUIRED dpl-utils-efl)
set(INCLUDES_PLATFORM_IMPLEMENTATION_WIDGETDB
${dpl-wrt-dao-ro_INCLUDE_DIRS}
+ ${dpl-utils-efl_INCLUDE_DIRS}
PARENT_SCOPE
)
set(LIBS_PLATFORM_IMPLEMENTATION_WIDGETDB
${dpl-wrt-dao-ro_LDFLAGS}
+ ${dpl-utils-efl_LDFLAGS}
PARENT_SCOPE
)
include_directories(${CURRENT_PATH})
+STRING(REPLACE ";" ":" SQL_GENERATOR_INCLUDE_DIRS "${dpl-db_INCLUDE_DIRS}")
+
ADD_CUSTOM_COMMAND( OUTPUT ${CURRENT_PATH}/widget_interface_db.sql
COMMAND rm -f ${CURRENT_PATH}/.widget_interface.db
COMMAND rm -f ${CURRENT_PATH}/widget_interface_db.sql
- COMMAND gcc -Wall -I${dpl-db_INCLUDE_DIRS} -E ${CURRENT_PATH}/widget_interface_db_sql_generator.h | grep --invert-match "^#" > ${CURRENT_PATH}/widget_interface_db.sql
+ COMMAND CPATH=${SQL_GENERATOR_INCLUDE_DIRS} gcc -Wall -E ${CURRENT_PATH}/widget_interface_db_sql_generator.h | grep --invert-match "^#" > ${CURRENT_PATH}/widget_interface_db.sql
COMMAND sqlite3 ${CURRENT_PATH}/.widget_interface.db ".read ${CURRENT_PATH}/widget_interface_db.sql" || rm -f ${CURRENT_PATH}/.widget_interface.db
DEPENDS ${CURRENT_PATH}/widget_interface_db_sql_generator.h ${CURRENT_PATH}/widget_interface_db
)
return 0;
}
-std::string WidgetInterfaceDAO::getValueByIndex(size_t index) const
+std::string WidgetInterfaceDAO::getKeyByIndex(size_t index) const
{
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::widget_interface;
Properties::Select select(&m_databaseInterface);
select.OrderBy("key");
std::list<DPL::String> list =
- select.GetValueList<Properties::value>();
+ select.GetValueList<Properties::key>();
if (index >= list.size()) {
Throw(Commons::InvalidArgumentException);
}
DPL::Optional<std::string> getValue(const std::string& key) const;
void clear(bool removeReadOnly);
size_t getStorageSize() const;
- std::string getValueByIndex(size_t index) const;
+ std::string getKeyByIndex(size_t index) const;
protected:
int m_widgetHandle;
--- /dev/null
+# 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 Lukasz Marek (l.marek@samsung.com)
+# @version 1.0
+#
+
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
+pkg_search_module(dpl REQUIRED dpl-efl)
+pkg_search_module(dpl-event REQUIRED dpl-event-efl)
+pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+
+#set(PLUGIN_MODULE_SRC_DIR ${PROJECT_SOURCE_DIR}/src/plugin-service)
+
+set(PLUGIN_LOADING_SOURCES
+ ${PLUGIN_LOADING_DIRS}/plugin_logic.cpp
+ ${PLUGIN_LOADING_DIRS}/plugin.cpp
+ ${PLUGIN_LOADING_DIRS}/plugin_model.cpp
+ ${PLUGIN_LOADING_DIRS}/explorer.cpp
+ ${PLUGIN_LOADING_DIRS}/plugin_iframe_support.cpp
+ ${PLUGIN_LOADING_DIRS}/plugin_container_support.cpp
+ ${PLUGIN_LOADING_DIRS}/plugin_property_support.cpp
+ ${PLUGIN_LOADING_DIRS}/javascript_interface.cpp
+ ${PLUGIN_LOADING_DIRS}/js_page_session.cpp
+ # ${PLUGIN_MODULE_SRC_DIR}/wrt_plugin_module.cpp
+)
+
+INCLUDE_DIRECTORIES(
+ # ${PLUGIN_MODULE_SRC_DIR}
+ ${PLUGIN_LOADING_DIRS}
+ ${webkit2_INCLUDE_DIRS}
+ ${plugin-types_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_PLUGIN_LOADING_LIB} SHARED
+ ${PLUGIN_LOADING_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGIN_LOADING_LIB} PROPERTIES
+ COMPILE_FLAGS -fPIC
+ LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGIN_LOADING_LIB} PROPERTIES
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+target_link_libraries(${TARGET_PLUGIN_LOADING_LIB}
+ ${dpl_LIBRARIES}
+ ${dpl-event_LIBRARIES}
+ ${dpl-wrt-dao-ro_LIBRARIES}
+ ${TARGET_COMMONS}
+ ${TARGET_JS_OVERLAY}
+)
+
+INSTALL(TARGETS ${TARGET_PLUGIN_LOADING_LIB}
+ DESTINATION lib
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+)
+
+# For wrt-plugins
+INSTALL(FILES
+ ${PLUGIN_LOADING_DIRS}/plugin_logic.h
+ ${PLUGIN_LOADING_DIRS}/js_types.h
+ DESTINATION include/wrt-plugin-loading)
--- /dev/null
+/*
+ * 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 explorer.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @author Yunchan Cho (yunchan.cho@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/foreach.h>
+#include <dpl/log/log.h>
+#include "explorer.h"
+#include "plugin_property_support.h"
+
+// JS overlay
+#include <js_overlay_support.h>
+#include <js_overlay_types.h>
+#include <js_overlay_addEventListener.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+#include <TizenServiceEvent/TizenServiceEvent.h>
+
+namespace {
+//const char* SEPARATOR = ".";
+const std::string GLOBAL_OBJECT_NAME = "GLOBAL_OBJECT";
+}
+
+using namespace std;
+using namespace PluginModule;
+using namespace WrtPlugins::W3C;
+
+Explorer::Explorer(JSGlobalContextRef context) :
+ m_context(context)
+{
+ if (!context) {
+ LogError("Context is NULL");
+ return;
+ }
+
+ m_globalObject =
+ JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
+
+ LogDebug("Register main frame");
+ //register main frame;
+ m_iframeSupport.registerIframe(m_globalObject);
+
+ m_propertySupport.reset(new WindowPropertySupport(m_context));
+
+ // initialization for use of custom event
+ if (!AddEventListenerSupport::isInitialized())
+ {
+ LogInfo("initialization for use of custom event");
+ AddEventListenerSupport::initialize(context);
+ }
+}
+
+Explorer::~Explorer()
+{
+ // deinitialization for use of custom event
+ if (AddEventListenerSupport::isInitialized()) {
+ LogInfo("deinitialization for use of custom event");
+ AddEventListenerSupport::deinitialize();
+ }
+}
+
+JSObjectPtr Explorer::getJSObjectProperty(const std::string& propertyName,
+ JSObjectPtr object)
+{
+ LogDebug("Get object property " << propertyName);
+ return JavaScriptInterfaceSingleton::Instance().getJSObjectProperty(
+ m_context, object, propertyName);
+}
+
+JSObjectPtr Explorer::getProperty(
+ const string& requestedProperty,
+ JSObjectPtr providedObject)
+{
+ LogDebug("Requested Property: " << requestedProperty);
+
+ if(!providedObject)
+ {
+ LogError("Provided object is empty");
+ return JSObjectPtr();
+ }
+
+ std::string currentObjectName;
+ std::string currentPropertyRequested = requestedProperty;
+ JSObjectPtr currentObject = providedObject;
+
+ while(true)
+ {
+ auto pos = currentPropertyRequested.find(".");
+ if (pos == string::npos)
+ {
+ return getJSObjectProperty(currentPropertyRequested, currentObject);
+ }
+
+ //check if requested object has child
+ currentObjectName = currentPropertyRequested.substr(0,pos);
+
+ if (currentPropertyRequested.size() <= pos+1)
+ {
+ LogError("Wrong name of requested property");
+ return JSObjectPtr();
+ }
+ currentPropertyRequested = currentPropertyRequested.substr(pos+1);
+
+ currentObject = getJSObjectProperty(currentObjectName, currentObject);
+ if(!currentObject)
+ {
+ LogError("Failed to get property: " << currentObjectName);
+ return JSObjectPtr();
+ }
+ }
+}
+
+bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
+ JSGlobalContextRef context)
+{
+ LogDebug("Register to global object");
+
+ bool retValue;
+
+ if (declaration->getParentName() == GLOBAL_OBJECT_NAME)
+ {
+ LogDebug("Connect to Global object");
+ retValue = register_(declaration, m_globalObject, context);
+ }
+ else //PIM support
+ {
+ LogDebug("Connect to NOT global object");
+ //it should be master object name
+ string masterName = declaration->getParentName();
+ auto pos = masterName.find(".");
+ if (string::npos != pos)
+ {
+ LogError("ParentName not allowed");
+ return false;
+ }
+ auto masterObject = getJSObjectProperty(masterName, m_globalObject);
+ if (masterObject->getObject() == 0)
+ {
+ return false;
+ }
+ retValue = registerObject(declaration, masterName, masterObject, context);
+ }
+
+ if (declaration->checkIframesSupported()) {
+ LogDebug("Iframe supported");
+ m_iframeSupport.registerDeclaration(declaration);
+// m_iframeSupport.invokeCallbackForMainFrame(m_context,
+// declaration,
+// newObject);
+ }
+ else {
+ LogDebug("Iframe NOT supported");
+ }
+
+ return retValue;
+}
+
+
+bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
+ const std::string& providedObjectName,
+ JSObjectPtr providedObject,
+ JSGlobalContextRef context)
+{
+ LogDebug("Register object. Provided object name: '" << providedObjectName
+ << "', registration of: '" << declaration->getName() << "'");
+
+ std::string fullParentName = declaration->getParentName();
+ LogDebug("Parent name: " << declaration->getParentName());
+
+ if(fullParentName == providedObjectName)
+ {
+ LogDebug("Provided object match equaly to requested parent");
+ return register_(declaration, providedObject, context);
+ }
+
+ //check if object exists in fullParentName
+ auto pos = fullParentName.find(providedObjectName);
+ if(pos == string::npos)
+ {
+ LogError("Object: " << declaration->getName()
+ << " should be child of: " << declaration->getParentName()
+ << " but you provided object: " << providedObjectName);
+
+ return false;
+ }
+
+ if (fullParentName.size() <= pos+providedObjectName.size()+1)
+ {
+ LogError("Invalid object name");
+ return false;
+ }
+
+ auto currentRequesteProperty =
+ fullParentName.substr(pos+providedObjectName.size()+1);
+
+
+ JSObjectPtr jsObject = getProperty(
+ currentRequesteProperty, providedObject);
+
+ if(!jsObject->getObject())
+ {
+ LogError("Object: '" << declaration->getName()
+ << "' should be child of: '" << declaration->getParentName()
+ << "'. you provided object: '" << providedObjectName
+ << "' but object is null");
+
+ return false;
+ }
+
+ return register_(declaration, jsObject, context);
+}
+
+bool Explorer::register_(const JSObjectDeclarationPtr& declaration,
+ JSObjectPtr parent,
+ JSGlobalContextRef context)
+{
+ LogInfo("Registration object: " << declaration->getParentName() <<
+ "<-" << declaration->getName());
+
+ Assert(parent && "parent object is NULL");
+
+ typedef JSObjectDeclaration::Options JO;
+
+ JSGlobalContextRef gContext = (context==NULL)?m_context:context;
+ JSObjectPtr newObject;
+
+ JSObjectPtr objectInstance = JavaScriptInterfaceSingleton::Instance().
+ createObject(gContext,declaration);
+
+ //function creation
+ if (declaration->getOptions() &&
+ declaration->getOptions()->getType() == JO::ClassType::Function)
+ {
+ LogDebug("Loading function object " << declaration->getName());
+
+ auto type = declaration->getOptions()->getIframeOverlay();
+ if (JO::IFrameOverlay::OverlayedBeforeOriginal == type)
+ {
+ LogDebug("Create overlayed function");
+ JSObjectPtr original =
+ JavaScriptInterfaceSingleton::Instance().
+ getJSObjectProperty(gContext,
+ parent,
+ declaration->getName());
+ newObject = JSOverlaySupport::
+ createWrappedFunction(gContext,
+ original,
+ objectInstance,
+ declaration->getName());
+ }
+ else
+ {
+ LogDebug("create normal function");
+ newObject = objectInstance;
+ }
+ }
+ else //object creation
+ {
+ newObject = objectInstance;
+ }
+
+ JavaScriptInterfaceSingleton::Instance().setObjectProperty(
+ gContext,
+ parent,
+ declaration->getName(),
+ newObject);
+
+ //notice
+ if (declaration->getOptions() &&
+ (declaration->getOptions()->getIframeNotice() ==
+ JO::IFrameNotice::AlwaysNotice))
+ {
+ declaration->getOptions()->invokeCallback(gContext,
+ parent->getObject(),
+ objectInstance->getObject());
+ }
+
+
+ return true;
+}
+
+void Explorer::registerObjectIntoIframe(const JSObjectDeclarationPtr& declaration,
+ JSObjectPtr frameObject,
+ JSGlobalContextRef context)
+{
+ if (declaration->getParentName() == GLOBAL_OBJECT_NAME)
+ {
+ LogDebug("Connect to Global object of IFRAME");
+ register_(declaration, frameObject, context);
+ return;
+ }
+
+ //PIM SUPPORT
+ {
+ LogWarning("Connect to NOT global object of IFRAME");
+ //it should be master object name
+ string masterName = declaration->getParentName();
+ auto pos = masterName.find(".");
+ if (string::npos != pos)
+ {
+ LogError("ParentName not allowed");
+ return;
+ }
+ auto masterObject = getJSObjectProperty(masterName, frameObject);
+ if (!masterObject->getObject())
+ {
+ LogError("Object not exist in frame");
+ return;
+ }
+ register_(declaration, masterObject, context);
+ }
+}
+
+
+void Explorer::loadFrame(JSGlobalContextRef context)
+{
+ LogDebug("Frame attached");
+
+ JSObjectPtr frameObject =
+ JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
+
+ LogDebug("Register main frame");
+ //register main frame;
+
+ if(frameObject->getObject() == m_globalObject->getObject())
+ {
+ // Main page was already loaded from constructor
+ LogDebug("Main page loaded");
+ return;
+ }
+
+ m_iframeSupport.registerIframe(frameObject);
+
+ auto iframeObjects = m_iframeSupport.getIframeObjects();
+
+ FOREACH(object, iframeObjects)
+ {
+ LogDebug("Register object: " << (*object)->getName() );
+
+ registerObjectIntoIframe(*object, frameObject, context);
+ }
+}
+
+void Explorer::unloadFrame(JSGlobalContextRef context)
+{
+ LogDebug("Frame detached");
+
+ JSObjectPtr frameObject =
+ JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
+
+ m_iframeSupport.unregisterIframe(frameObject);
+}
+
+void Explorer::removePluginsFromIframes()
+{
+ LogDebug("Remove plugins from iframes");
+
+ if (m_iframeSupport.hasIframes())
+ {
+ LogDebug("Removing iframes");
+ JavaScriptInterfaceSingleton::Instance().removeIframes(m_context);
+ }
+}
+
+void Explorer::deregisterObject(const JSObjectDeclarationPtr& declaration)
+{
+ LogDebug("Deregister object " << declaration->getName());
+
+ if (GLOBAL_OBJECT_NAME != declaration->getParentName())
+ {
+ LogWarning("Ignored remove property " << declaration->getName());
+ return;
+ }
+
+ JavaScriptInterfaceSingleton::Instance().
+ removeObjectProperty(m_context,
+ m_globalObject,
+ declaration->getName());
+}
+
+void Explorer::cleanIframesData()
+{
+ LogDebug("Clean iframes data");
+ m_iframeSupport.clean();
+}
+
+void Explorer::callEventListeners(CustomEventType eventType)
+{
+ if (eventType == ServiceCustomEvent)
+ {
+ using namespace WrtDeviceApis::TizenServiceEvent::Api;
+
+ // get iframe objects from javascript global context
+ JavaScriptInterface::ObjectsListPtr frameLists =
+ JavaScriptInterfaceSingleton::Instance().getIframesList(m_context);
+
+ // get main frame object from javascript global context
+ JSObjectRef mainFrame = JSContextGetGlobalObject(m_context);
+ frameLists->push_back(JSObjectPtr(new JSObject(mainFrame)));
+
+ // set user data of js callback function for 'appservice' js event
+ ITizenServiceEventPtr event = ITizenServiceEventPtr(new TizenServiceEvent());
+ event->setScale(m_propertySupport->getScale());
+ event->setBundle(m_propertySupport->getBundle());
+
+ // call js callback function for 'appservice' js event on each frame
+ FOREACH(it, *frameLists)
+ {
+ JSObjectRef frame = static_cast<JSObjectRef>((*it).Get()->getObject());
+ AddEventListenerSupport::CallServiceListenersFromIFrame(frame, event);
+ }
+ } else {
+ LogInfo("Not supported custom event type");
+ }
+}
+
+WindowPropertySupport* Explorer::getWindowPropertySupport()
+{
+ return m_propertySupport.get();
+}
--- /dev/null
+/*
+ * 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 explorer.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_EXPLORER_H_
+#define WRT_SRC_PLUGIN_SERVICE_EXPLORER_H_
+
+#include <string>
+
+#include <dpl/noncopyable.h>
+#include <dpl/exception.h>
+#include <dpl/shared_ptr.h>
+
+#include <Commons/JSObject.h>
+#include <Commons/JSObjectDeclaration.h>
+//JSGlobalContextRef
+#include "javascript_interface.h"
+#include "plugin_iframe_support.h"
+#include "plugin_property_support.h"
+
+//JS overlay
+#include <js_overlay_types.h>
+
+using namespace PluginModule;
+using namespace WrtPlugins::W3C;
+
+class Explorer : private DPL::Noncopyable
+{
+ public:
+ explicit Explorer(JSGlobalContextRef context);
+ ~Explorer();
+
+ //register to global frame
+ bool registerObject(const JSObjectDeclarationPtr& declaration,
+ JSGlobalContextRef context);
+
+ bool registerObject (const JSObjectDeclarationPtr& declaration,
+ const std::string& parentObjectName,
+ JSObjectPtr parentObject,
+ JSGlobalContextRef context);
+
+ void deregisterObject(const JSObjectDeclarationPtr& declaration);
+
+ // new load/unload frame API
+ void loadFrame(JSGlobalContextRef context);
+ void unloadFrame(JSGlobalContextRef context);
+
+ void removePluginsFromIframes();
+ void cleanIframesData();
+ void callEventListeners(CustomEventType eventType);
+
+ WindowPropertySupport* getWindowPropertySupport();
+
+ private:
+
+ IframesSupport m_iframeSupport;
+
+ //globalContext
+ JSGlobalContextRef m_context;
+
+ //global object of main frame
+ JSObjectPtr m_globalObject;
+
+ std::unique_ptr<WindowPropertySupport> m_propertySupport;
+
+ private:
+ void registerObjectIntoIframe(const JSObjectDeclarationPtr& declaration,
+ JSObjectPtr parentObject,
+ JSGlobalContextRef context);
+
+ bool register_(const JSObjectDeclarationPtr& declaration,
+ JSObjectPtr parent,
+ JSGlobalContextRef context);
+
+
+ JSObjectPtr getJSObjectProperty(const std::string& propertyName,
+ JSObjectPtr object);
+
+ JSObjectPtr getProperty(
+ const std::string& requestedProperty,
+ JSObjectPtr providedObject);
+};
+
+typedef DPL::SharedPtr<Explorer> ExplorerPtr;
+#endif
--- /dev/null
+/*
+ * 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 plugin_webkit.h
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation file of webkit js plugin
+ * accessing routines in EFL
+ */
+#include <javascript_interface.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_array.h>
+#include <vector>
+#include <dpl/singleton_impl.h>
+#include <string>
+#include <dpl/foreach.h>
+#include <dpl/noncopyable.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <JavaScriptCore/JSObjectRef.h>
+
+IMPLEMENT_SINGLETON(JavaScriptInterface)
+
+#define CHECK_JSVALUE_IS_UNDEFINED_RETURN(context, object, ret) \
+ if (JSValueIsUndefined(context, object)) {\
+ LogError("Object " << #object << " is undefined");\
+ return ret;\
+ }
+
+#define CHECK_JSOBJECT_IS_NULL_RETURN(object, ret) \
+ if (!object) {\
+ LogError("Object " << #object << " is NULL");\
+ return ret;\
+ }
+
+namespace {
+/**
+ * Converts JSStringRef to std::string
+ * */
+std::string toString(const JSStringRef& arg)
+{
+ Assert(arg);
+ std::string result;
+ size_t jsSize = JSStringGetMaximumUTF8CStringSize(arg);
+ if (jsSize > 0) {
+ ++jsSize;
+ DPL::ScopedArray<char> buffer(new char[jsSize]);
+ size_t written = JSStringGetUTF8CString(arg, buffer.Get(), jsSize);
+ if (written > jsSize) {
+ LogError("Conversion could not be fully performed.");
+ return std::string();
+ }
+ result = buffer.Get();
+ }
+
+ return result;
+}
+
+/**
+ * Converts JSValueRef to std::string
+ * */
+std::string toString(JSContextRef ctx, JSValueRef value) {
+ Assert(ctx && value);
+ std::string result;
+ JSStringRef str = JSValueToStringCopy(ctx, value, NULL);
+ result = toString(str);
+ JSStringRelease(str);
+ return result;
+}
+
+JSValueRef getProperty(JSContextRef ctx, JSValueRef value, const char* name) {
+ Assert(ctx && value && name);
+ JSValueRef result = NULL;
+ JSObjectRef obj = JSValueToObject(ctx, value, NULL);
+ if (obj) {
+ JSStringRef str = JSStringCreateWithUTF8CString(name);
+ result = JSObjectGetProperty(ctx, obj, str, NULL);
+ JSStringRelease(str);
+ }
+ return result;
+}
+
+JSValueRef getPropertyObj(JSContextRef ctx, JSObjectRef obj, const char* name) {
+ Assert(ctx && obj && name);
+ JSStringRef str = JSStringCreateWithUTF8CString(name);
+ JSValueRef result = JSObjectGetProperty(ctx, obj, str, NULL);
+ JSStringRelease(str);
+ return result;
+}
+
+JSObjectRef getJSGlobalObject(JSGlobalContextRef context){
+ return JSContextGetGlobalObject(context);
+}
+
+}
+
+typedef JSValueRef (*JSCFunction)(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
+
+void JavaScriptInterface::setObjectProperty(JSGlobalContextRef context,
+ const JSObjectPtr& parentObject,
+ const std::string &propertyName,
+ const JSObjectPtr& propertyObject)
+{
+ LogInfo("Webkit:setting property --" << propertyName << "--");
+
+ //create name
+ JSStringRef name = JSStringCreateWithUTF8CString(propertyName.c_str());
+ //set property
+ JSObjectSetProperty(
+ static_cast<JSGlobalContextRef>(context),
+ static_cast<JSObjectRef>(parentObject->getObject()), name,
+ static_cast<JSObjectRef>(propertyObject->getObject()),
+ kJSPropertyAttributeReadOnly, 0);
+
+ JSStringRelease(name);
+}
+
+void JavaScriptInterface::removeObjectProperty(JSGlobalContextRef context,
+ const JSObjectPtr& parentObject,
+ const std::string &propertyName)
+{
+ if (!context) {
+ //nothing to do -> no context
+ return;
+ }
+ LogDebug("Deleting property --" << propertyName << "--");
+
+ JSStringRef name = JSStringCreateWithUTF8CString(propertyName.c_str());
+ JSObjectDeleteProperty(
+ static_cast<JSGlobalContextRef>(context),
+ static_cast<JSObjectRef>(parentObject->getObject()), name, 0);
+
+ JSStringRelease(name);
+}
+
+JavaScriptInterface::PropertiesList JavaScriptInterface::getObjectPropertiesList(
+ JSGlobalContextRef context,
+ const JSObjectPtr& object) const
+{
+ PropertiesList result;
+ JSPropertyNameArrayRef properties = JSObjectCopyPropertyNames(
+ static_cast<JSGlobalContextRef>(context),
+ static_cast<JSObjectRef>(object->getObject()));
+ std::size_t count = JSPropertyNameArrayGetCount(properties);
+ result.reserve(count);
+ LogDebug("propesties count " << count);
+ for (std::size_t i = 0; i < count; ++i) {
+ JSStringRef property = JSPropertyNameArrayGetNameAtIndex(properties, i);
+ result.push_back(toString(property));
+ }
+ JSPropertyNameArrayRelease(properties);
+ return result;
+}
+
+JSObjectPtr JavaScriptInterface::makeJSFunctionObject(
+ JSGlobalContextRef context,
+ const std::string &name,
+ js_function_impl functionImplementation) const
+{
+ LogDebug("Create JS function");
+ JSStringRef jsFunName = JSStringCreateWithUTF8CString(name.c_str());
+
+ JSObjectRef object = JSObjectMakeFunctionWithCallback(
+ context,
+ jsFunName,
+ reinterpret_cast<JSObjectCallAsFunctionCallback>(
+ functionImplementation));
+
+ JSStringRelease(jsFunName);
+ return JSObjectPtr(new JSObject(static_cast<void*>(object)));
+}
+
+JSObjectPtr JavaScriptInterface::makeJSClassObject(
+ JSGlobalContextRef context,
+ JSObjectDeclaration::ConstClassTemplate classTemplate) const
+{
+ LogDebug("Create JS object");
+ JSObjectRef object = JSObjectMake(
+ context,
+ static_cast<JSClassRef>(
+ const_cast<JSObjectDeclaration::ClassTemplate>(classTemplate)),
+ NULL);
+ return JSObjectPtr(new JSObject(object));
+}
+
+JSObjectPtr JavaScriptInterface::makeJSObjectBasedOnInterface(
+ JSGlobalContextRef context,
+ const std::string &interfaceName) const
+{
+ LogDebug("Create JS object base on interface: " << interfaceName);
+ LogDebug("Context: " << context);
+
+
+ JSObjectPtr jsInterfaceObj = getJSObjectProperty(context,
+ getGlobalObject(context), interfaceName);
+ JSObjectRef object = JSObjectCallAsConstructor(context,
+ static_cast<JSObjectRef>(jsInterfaceObj->getObject()), 0, NULL,
+ NULL);
+ return JSObjectPtr(new JSObject(static_cast<void*>(object)));
+}
+
+JSObjectPtr JavaScriptInterface::makeJSInterface(
+ JSGlobalContextRef context,
+ JSObjectDeclaration::ConstClassTemplate classTemplate,
+ JSObjectDeclaration::ConstructorCallback constructorCallback) const
+{
+ LogDebug("Create JS interface. Context: " << context);
+ JSObjectRef object = JSObjectMakeConstructor(context,
+ static_cast<JSClassRef>(
+ const_cast<JSObjectDeclaration::ClassTemplate>(
+ classTemplate)),
+ reinterpret_cast<JSObjectCallAsConstructorCallback>(
+ constructorCallback)
+ );
+ return JSObjectPtr(new JSObject(static_cast<void*>(object)));
+}
+
+JSObjectPtr JavaScriptInterface::createObject(JSGlobalContextRef context,
+ const JSObjectDeclarationPtr& declaration)
+{
+ typedef JSObjectDeclaration::Options JO;
+
+ if( declaration->getOptions())
+ {
+ switch (declaration->getOptions()->getType())
+ {
+ case JO::ClassType::Function:
+ return makeJSFunctionObject(
+ context,
+ declaration->getName(),
+ declaration->getOptions()->getFunctionImpl());
+
+ case JO::ClassType::Class:
+ if (declaration->getInterfaceName().empty()) {
+ return makeJSClassObject(
+ context,
+ declaration->getClassTemplate());
+ } else {
+ return makeJSObjectBasedOnInterface(
+ context,
+ declaration->getInterfaceName());
+ }
+
+ case JO::ClassType::Interface:
+ return makeJSInterface(
+ context,
+ /* product class template */
+ declaration->getClassTemplate(),
+ declaration->getConstructorCallback());
+
+ default:
+ LogError("Invalid class type. Making empty JS object.");
+ return JSObjectPtr(new JSObject(
+ JSObjectMake(context, NULL, NULL)));
+ }
+ } else {
+ LogDebug("No declaration options");
+ return JSObjectPtr(new JSObject(
+ JSObjectMake(
+ context,
+ static_cast<JSClassRef>(
+ const_cast<JSObjectDeclaration::ClassTemplate>(
+ declaration->getClassTemplate())),
+ NULL)));
+ }
+}
+
+JSObjectPtr JavaScriptInterface::getGlobalObject(JSGlobalContextRef context)
+ const
+{
+ return JSObjectPtr(new JSObject(static_cast<JSObject::RealObject>(
+ JSContextGetGlobalObject(static_cast<JSGlobalContextRef>(context)))));
+}
+
+JSObjectPtr JavaScriptInterface::copyObjectToIframe(
+ JSGlobalContextRef context,
+ const JSObjectPtr& iframe,
+ const std::string& name)
+{
+ LogError("Copy object to iframe: " << name);
+
+ JSGlobalContextRef jsGlobalContext =
+ static_cast<JSGlobalContextRef>(context);
+
+ JSObjectRef globalObject = JSContextGetGlobalObject(jsGlobalContext);
+
+ JSValueRef requestedObject = getPropertyObj(jsGlobalContext,
+ globalObject,
+ name.c_str());
+ CHECK_JSVALUE_IS_UNDEFINED_RETURN(jsGlobalContext,
+ requestedObject,
+ JSObjectPtr());
+
+ JSStringRef requestedObjectStr =
+ JSStringCreateWithUTF8CString(name.c_str());
+
+ JSObjectSetProperty(jsGlobalContext,
+ static_cast<JSObjectRef>(iframe->getObject()),
+ requestedObjectStr,
+ requestedObject,
+ kJSPropertyAttributeReadOnly,
+ NULL);
+
+ JSStringRelease(requestedObjectStr);
+
+ return JSObjectPtr(
+ new JSObject(const_cast<OpaqueJSValue*>(requestedObject)));
+}
+
+JavaScriptInterface::ObjectsListPtr
+JavaScriptInterface::getIframesList(JSGlobalContextRef ctx) const
+{
+ JSGlobalContextRef context = static_cast<JSGlobalContextRef>(ctx);
+
+ LogDebug("get global object");
+ JSObjectRef globalObject = JSContextGetGlobalObject(context);
+
+ ObjectsListPtr retList = getIframesList(context, globalObject);
+
+ return retList;
+}
+
+JavaScriptInterface::ObjectsListPtr
+JavaScriptInterface::getIframesList(JSContextRef context,
+ JSObjectRef globalObject) const
+{
+ JSValueRef frames = getPropertyObj(context, globalObject, "frames");
+ CHECK_JSVALUE_IS_UNDEFINED_RETURN(context, frames, ObjectsListPtr());
+
+ JSObjectRef frames_o = JSValueToObject(context, frames, NULL);
+ CHECK_JSOBJECT_IS_NULL_RETURN(frames_o, ObjectsListPtr());
+
+ JSValueRef len = getPropertyObj(context, frames_o, "length");
+ CHECK_JSVALUE_IS_UNDEFINED_RETURN(context, len, ObjectsListPtr());
+
+ size_t count = JSValueToNumber(context, len, NULL);
+ LogDebug("frames_o.length = " << count);
+
+ ObjectsListPtr retList = ObjectsListPtr(new ObjectsList());
+
+ for (size_t i = 0; i < count; ++i) {
+ std::stringstream ss;
+ ss << i;
+ JSValueRef frame = getPropertyObj(context,
+ frames_o,
+ ss.str().c_str());
+ if (JSValueIsUndefined(context, frame)) {
+ LogError("Selected frame is null: frame[" << i << "]");
+ continue;
+ }
+ JSObjectRef frame_obj = JSValueToObject(context, frame, NULL);
+ if (!frame_obj) {
+ LogError("frame_obj is NULL.");
+ continue;
+ }
+ retList->push_back(JSObjectPtr(new JSObject(frame_obj)));
+ ObjectsListPtr childList = getIframesList(context, frame_obj);
+
+ retList->merge(*childList);
+ LogDebug("Frame Value Pointer: " << frame);
+ LogDebug("Frame Object Pointer: " << frame_obj);
+ }
+
+ return retList;
+}
+
+JSObjectPtr JavaScriptInterface::getJSObjectProperty(JSGlobalContextRef ctx,
+ const JSObjectPtr& frame,
+ const std::string& name) const
+{
+ JSObjectRef frame_js = static_cast<JSObjectRef>(frame->getObject());
+
+ JSValueRef property = getPropertyObj(ctx, frame_js, name.c_str());
+
+ JSObjectRef objProp = JSValueToObject(ctx, property, NULL);
+
+ return JSObjectPtr(new JSObject(objProp));
+}
+
+void JavaScriptInterface::removeIframes(JSGlobalContextRef context)
+{
+ const char* deleteIframesScript =
+ "frame_set = document.getElementsByTagName('iframe');"
+ "len = frame_set.length;"
+ "for(i=0; i< len; i++)"
+ " frame_set[0].parentNode.removeChild(frame_set[0]); ";
+
+ JSGlobalContextRef ctx = static_cast<JSGlobalContextRef>(context);
+
+ JSStringRef script_src = JSStringCreateWithUTF8CString(deleteIframesScript);
+
+ JSEvaluateScript(ctx, script_src, 0, 0, 0, 0);
+
+ JSStringRelease(script_src);
+}
+
+void JavaScriptInterface::invokeGarbageCollector(JSGlobalContextRef context)
+{
+ LogDebug("Garbage collection #1");
+ JSGarbageCollect(context);
+ LogDebug("Garbage collection #2");
+ JSGarbageCollect(context);
+ LogDebug("Garbage collection #3");
+ JSGarbageCollect(context);
+ LogDebug("Garbage collection #4");
+ JSGarbageCollect(context);
+}
--- /dev/null
+/*
+ * 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 JavaScriptInterface.h
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @author Piotr Fatyga (p.fatyga@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef WRT_SRC_PLUGIN_SERVICE_WEBKIT_INTERFACE_H_
+#define WRT_SRC_PLUGIN_SERVICE_WEBKIT_INTERFACE_H_
+
+#include <string>
+#include <vector>
+#include <memory>
+#include <list>
+#include <dpl/noncopyable.h>
+#include <dpl/singleton.h>
+#include <Commons/JSObjectDeclaration.h>
+#include <Commons/JSObject.h>
+
+//forward declaration of JSConectexRef
+extern "C" {
+ typedef const struct OpaqueJSContext* JSContextRef;
+ typedef struct OpaqueJSContext* JSGlobalContextRef;
+ typedef struct OpaqueJSValue* JSObjectRef;
+}
+
+class JavaScriptInterface : DPL::Noncopyable
+{
+ public:
+
+ typedef std::vector<std::string> PropertiesList;
+
+ typedef std::list<JSObjectPtr> ObjectsList;
+ typedef std::shared_ptr<ObjectsList> ObjectsListPtr;
+
+ public:
+ JSObjectPtr getGlobalObject(JSGlobalContextRef context) const;
+
+ // object creation
+ JSObjectPtr createObject(JSGlobalContextRef context,
+ const JSObjectDeclarationPtr& declaration);
+
+ //properties
+ void setObjectProperty(JSGlobalContextRef context,
+ const JSObjectPtr& parentObject,
+ const std::string &propertyName,
+ const JSObjectPtr& propertyObject);
+
+ void removeObjectProperty(JSGlobalContextRef context,
+ const JSObjectPtr& parentObject,
+ const std::string &propertyName);
+
+ PropertiesList getObjectPropertiesList(JSGlobalContextRef context,
+ const JSObjectPtr& object) const;
+
+ JSObjectPtr copyObjectToIframe(JSGlobalContextRef context,
+ const JSObjectPtr& iframe,
+ const std::string& name);
+
+ ObjectsListPtr getIframesList(JSGlobalContextRef context) const;
+
+ void removeIframes(JSGlobalContextRef context);
+
+ void invokeGarbageCollector(JSGlobalContextRef context);
+
+ JSObjectPtr getJSObjectProperty(JSGlobalContextRef ctx,
+ const JSObjectPtr& frame,
+ const std::string& name) const;
+
+ private:
+ JavaScriptInterface()
+ {
+ }
+
+ JSObjectPtr makeJSFunctionObject(
+ JSGlobalContextRef context,
+ const std::string &name,
+ js_function_impl functionImplementation) const;
+ JSObjectPtr makeJSClassObject(
+ JSGlobalContextRef context,
+ JSObjectDeclaration::ConstClassTemplate classTemplate) const;
+ JSObjectPtr makeJSObjectBasedOnInterface(
+ JSGlobalContextRef context,
+ const std::string &interfaceName) const;
+ JSObjectPtr makeJSInterface(
+ JSGlobalContextRef context,
+ JSObjectDeclaration::ConstClassTemplate classTemplate,
+ JSObjectDeclaration::ConstructorCallback constructorCallback) const;
+
+ ObjectsListPtr getIframesList(JSContextRef context,
+ JSObjectRef object) const;
+
+ friend class DPL::Singleton<JavaScriptInterface>;
+};
+
+typedef DPL::Singleton<JavaScriptInterface> JavaScriptInterfaceSingleton;
+
+#endif
--- /dev/null
+/*
+ * 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 plugin_logic.cpp
+ * @author Piotr Fatyga (p.fatyga@samsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation file of plugin and
+ * feature loading routines
+ * @brief This code is intended to work behind view controller
+ */
+
+#include "plugin_logic.h"
+
+#include <dpl/assert.h>
+#include <dpl/scoped_array.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/singleton_impl.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+#include <JavaScriptCore/JavaScript.h>
+
+#include <string>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fstream>
+#include <map>
+#include <list>
+#include <vector>
+#include <algorithm>
+#include <cstring>
+
+#include <wrt_plugin_export.h>
+#include <js_overlay_types.h>
+
+#include "explorer.h"
+#include "plugin.h"
+#include "plugin_model.h"
+#include "javascript_interface.h"
+#include "js_function_manager.h"
+#include "plugin_container_support.h"
+
+#include "js_page_session.h"
+
+using namespace std;
+using namespace WrtDB;
+using namespace WrtPlugins::W3C;
+
+namespace {
+const char *LIBRARY_PATH_SEPARATOR = "/";
+const char* FEATURE_WAC20_DEVICAPIS_NAME = "http://wacapps.net/api/deviceapis";
+}
+
+class JSPageSession::Impl
+{
+ private:
+ typedef std::set<PluginPtr> LoadedPlugins;
+ typedef std::set<JSGlobalContextRef> LoadedContexts;
+
+ private:
+ ///< Widget handle using this session
+ int m_widgetHandle;
+
+ //view for this session
+ JSGlobalContextRef m_context;
+
+ bool m_sessionStarted;
+
+ ///< JS object explorer for this session
+ Explorer* m_objectExplorer;
+
+ PluginContainerSupportPtr m_pluginsSupport;
+
+ ///< All loaded plugins. Each one must be unloaded. Plugins means
+ //set of features connected with such plugin (library)
+ LoadedPlugins m_loadedPlugins;
+
+ // Set of currently loaded web pages' contexts. These contexts are
+ // exactly matching with each frames' global context.
+ LoadedContexts m_loadedContexts;
+
+ private:
+ PluginPtr loadLibrary(PluginModelPtr& pluginModel);
+
+ void loadInjectedJavaScript();
+ void installStandardFeatures();
+ void installRequestedFeatures();
+
+ //returns true if success or false if failed
+ bool installPlugin(PluginModelPtr plugin);
+ bool installPluginOnDemand(PluginModelPtr plugin,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context);
+
+ void unloadPluginsFromSession();
+
+ public:
+ Impl(const PluginContainerSupportPtr& containerSupport);
+ ~Impl();
+
+ // Widget session
+ void startSession(int widgetHandle,
+ JSGlobalContextRef view,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void stopSession();
+
+ void performLibrariesUnload();
+
+ bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context);
+
+ void loadFrame(JSGlobalContextRef context);
+ void unloadFrame(JSGlobalContextRef context);
+
+ void setCustomProperties(double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void dispatchJavaScriptEvent(CustomEventType eventType);
+
+};
+
+
+JSPageSession::Impl::Impl(const PluginContainerSupportPtr& support) :
+ m_sessionStarted(false)
+{
+// DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
+ LogDebug("Initializing Page Session");
+ m_pluginsSupport = support;
+
+ // explicit call to keep singleton's lifetime until calling destructor.
+// JsFunctionManagerSingleton::Instance();
+// JavaScriptInterfaceSingleton::Instance();
+}
+
+JSPageSession::Impl::~Impl()
+{
+ if(m_sessionStarted)
+ {
+ LogError("Must stop widget session before exit!");
+ stopSession();
+ }
+
+ LogDebug("Deinitializing plugin Logic...");
+}
+
+void JSPageSession::Impl::installStandardFeatures()
+{
+ LogInfo("Installing standard widget features...");
+
+ //add standard functions
+ FOREACH(it, JsFunctionManagerSingleton::Instance().getFunctions())
+ {
+ m_objectExplorer->registerObject(*it, NULL);
+ }
+
+ //add standard objects
+ LogDebug("Installing standard extensions...");
+
+ auto standardPlugins = m_pluginsSupport->getStandardPlugins();
+ FOREACH(it, standardPlugins)
+ {
+ //loadFeatureToSession(*it);
+ installPlugin(*it);
+ }
+
+ LogInfo("Standard widget features installed.");
+}
+
+bool JSPageSession::Impl::installPlugin(PluginModelPtr plugin)
+{
+ Assert(plugin && "Plugin Model is NULL");
+ auto library = loadLibrary(plugin);
+
+ LogInfo("Install Plugin '" << library->GetFileName());
+
+
+ if(!library)
+ {
+ LogError("Loading library failed");
+ return false;
+ }
+
+ // Register new class
+ FOREACH(it, *(library->GetClassList()))
+ {
+ if (!m_objectExplorer->registerObject(*it, NULL)) {
+ LogError("Object Registration failed : " << (*it)->getName());
+ }
+ }
+
+ LogDebug("Registered feature.");
+ return true;
+}
+
+void JSPageSession::Impl::installRequestedFeatures()
+{
+ LogInfo("Installing requested widget features...");
+
+ //TODO it have to return LIST NOT SET!!!
+ WidgetDAOReadOnly widgetDao(m_widgetHandle);
+ DbWidgetFeatureSet features = widgetDao.getFeaturesList();
+
+ std::list<std::string> allowedFeatures;
+
+ FOREACH(it, features)
+ {
+ LogInfo("Loading api-feature: " << it->name);
+ if (it->rejected) {
+ LogWarning("Api-feature was rejected by ace. (Api-feature name: "
+ << it->name << ")" );
+ continue;
+ }
+
+ allowedFeatures.push_back(DPL::ToUTF8String(it->name));
+ }
+
+ auto widgetType = widgetDao.getWidgetType();
+
+ //WAC2.0 requirement
+ if (widgetType == APP_TYPE_WAC20)
+ {
+ auto it = find(allowedFeatures.begin(),
+ allowedFeatures.end(),
+ FEATURE_WAC20_DEVICAPIS_NAME);
+
+ if (allowedFeatures.end() == it)
+ {
+ LogInfo("WAC2.0 Deviceapis not declared but added");
+ allowedFeatures.push_front(FEATURE_WAC20_DEVICAPIS_NAME);
+ }
+ }
+
+ PluginContainerSupport::PluginsList allowedPlugins;
+
+ FOREACH(feature, allowedFeatures)
+ {
+ LogDebug("Processing feature: " << *feature);
+
+ auto plugin = m_pluginsSupport->getPluginForFeature(*feature);
+ ImplementedObjectsList implObjs =
+ PluginDAOReadOnly::
+ getImplementedObjectsForPluginHandle(plugin->Handle.Get());
+
+ FOREACH(obj, implObjs)
+ {
+ LogDebug("Processing object: " << *obj);
+ /* This can be optimalized, but would need extra data in database.
+ There should be a list of features that are allowed to be
+ installed at widget start */
+ if (obj->find(".") == obj->rfind(".")) {
+ allowedPlugins.push_back(plugin);
+ LogWarning("Plugin will be added: "
+ << plugin->LibraryName.Get());
+ break;
+ }
+ }
+ }
+
+ FOREACH(plugin, allowedPlugins)
+ {
+ LogDebug("Installation plugin: " << (*plugin)->LibraryName.Get());
+ installPlugin(*plugin);
+ }
+
+ LogInfo("requested features installed.");
+}
+
+bool JSPageSession::Impl::loadPluginOnDemand(
+ const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context)
+{
+ LogDebug("load plugin with feature");
+
+ Assert(parentObject.instance &&
+ !parentObject.name.empty()
+ && "Wrong arguments");
+
+ if (!m_sessionStarted) {
+ LogError("Session not started");
+ return false;
+ }
+// //TODO here may be a bug. if plugin contains feature rejected and accepted
+// LogInfo("Installing feature : " << widgetFeature.name);
+// if (widgetFeature.rejected) {
+// LogWarning("This api-feature was rejected");
+// return;
+// }
+//
+ auto plugin = m_pluginsSupport->getPluginModelById(pluginHandle);
+ if (!plugin) {
+ LogError("Failed to load plugin. plugin handle: " << pluginHandle);
+ return false;
+ }
+
+ return installPluginOnDemand(plugin,parentObject,context);
+}
+
+bool JSPageSession::Impl::installPluginOnDemand(PluginModelPtr plugin,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context)
+{
+ Assert(plugin && "Plugin Model is NULL");
+ auto library = loadLibrary(plugin);
+
+ LogInfo("Install Plugin '" << library->GetFileName());
+
+ if(!library)
+ {
+ LogError("Loading library failed");
+ return false;
+ }
+
+ if(!(parentObject.instance))
+ {
+ LogError("NULL pointer value");
+ return false;
+ }
+
+ JSObjectPtr parent(new JSObject(parentObject.instance));
+
+ if (!parent->getObject())
+ {
+ LogError("NULL pointer value");
+ assert(false);
+ return false;
+ }
+
+ FOREACH(it, *(library->GetClassList()))
+ {
+ bool installationStatus =
+ m_objectExplorer->registerObject(*it,
+ parentObject.name,
+ parent,
+ context);
+
+ if(!installationStatus)
+ {
+ LogError("Object Registration failed : " << (*it)->getName()
+ << "; Parent object name: " << parentObject.name);
+ return false;
+ }
+ }
+
+ LogDebug("Plugin on demand registration completed");
+ return true;
+}
+
+void JSPageSession::Impl::setCustomProperties(double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ LogInfo("set properties of window object " << scaleFactor << ", "
+ << encodedBundle << ", " << theme);
+
+ m_objectExplorer->getWindowPropertySupport()
+ ->setScaleToNavigatorProperty(scaleFactor);
+ m_objectExplorer->getWindowPropertySupport()
+ ->setBundleToWindowProperty(encodedBundle);
+ m_objectExplorer->getWindowPropertySupport()
+ ->setThemeToNavigatorProperty(theme);
+}
+
+void JSPageSession::Impl::dispatchJavaScriptEvent(CustomEventType eventType)
+{
+ // Check if session is already started
+ if (!m_sessionStarted) {
+ LogWarning("Session not started!");
+ return;
+ }
+
+ LogInfo("Request dispatching javascript event");
+ m_objectExplorer->callEventListeners(eventType);
+}
+
+void JSPageSession::Impl::loadInjectedJavaScript()
+{
+ LogInfo("Entered");
+
+ std::string DIR_PATH = "/usr/etc/wrt/injected-javascript";
+ std::string JS_EXTENSION = ".js";
+
+ DIR *dir = opendir(DIR_PATH.c_str());
+
+ if (!dir) {
+ LogError("opendir(\"" << DIR_PATH << "\") error!" );
+ return;
+ }
+
+ struct dirent* libdir;
+ std::list<std::string> jsFiles;
+
+ // make file list from DIR_PATH
+ while ((libdir = readdir(dir)) != 0)
+ {
+ if (strncmp(libdir->d_name, ".", 2) == 0 ||
+ strncmp(libdir->d_name, "..", 3) == 0)
+ {
+ continue;
+ }
+
+ std::string filepath = DIR_PATH;
+ filepath += "/";
+ filepath += libdir->d_name;
+
+ std::string lowercase = filepath;
+ std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(),
+ towlower);
+
+ if( lowercase.rfind(JS_EXTENSION) == std::string::npos ||
+ lowercase.length() !=
+ lowercase.rfind(JS_EXTENSION) + JS_EXTENSION.length() )
+ {
+ LogError("This is not js file" << filepath);
+ continue;
+ }
+
+ struct stat tmp;
+
+ if (stat(filepath.c_str(), &tmp) == -1) {
+ LogError("Failed to open file " << filepath);
+ continue;
+ }
+
+ if (!S_ISREG(tmp.st_mode)) {
+ LogError("This is not a regular file " << filepath);
+ continue;
+ }
+
+ LogInfo("Added : " << filepath);
+ jsFiles.push_back(filepath);
+ }
+
+ closedir(dir);
+
+
+ FOREACH(it, jsFiles)
+ {
+ LogDebug("load file : " << (*it));
+ // load file
+ std::string content;
+ std::ifstream fin(it->c_str());
+
+ while(fin.good())
+ {
+ string line;
+ std::getline(fin, line);
+ content += line + "\n";
+ }
+
+ fin.close();
+ // execute
+ if(!content.empty())
+ {
+ JSValueRef exception = NULL;
+ JSStringRef script =
+ JSStringCreateWithUTF8CString(content.c_str());
+
+ JSEvaluateScript(m_context, script, NULL, NULL, 1, &exception);
+
+ JSStringRelease(script);
+
+ if(exception)
+ {
+ LogDebug("Exception Occured while injecting javascript "
+ "file. : " << *it);
+
+ JSStringRef exceptionJSString =
+ JSValueToStringCopy(m_context, exception, NULL);
+ size_t size =
+ JSStringGetMaximumUTF8CStringSize(exceptionJSString);
+ char* exceptionString = new char[size];
+ JSStringGetUTF8CString(exceptionJSString,
+ exceptionString, size);
+ LogDebug("Exception : " << exceptionString);
+
+ delete [] exceptionString;
+ JSStringRelease(exceptionJSString);
+ }
+ }
+ }
+}
+
+void JSPageSession::Impl::startSession(int widgetHandle,
+ JSGlobalContextRef context,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ LogInfo("Starting widget session...");
+
+ // Check if corresponding session if not already created
+ if (m_sessionStarted) {
+ LogWarning("Session already started!");
+ return;
+ }
+
+ // Create js object explorer object
+ m_objectExplorer = new Explorer(context);
+
+ m_sessionStarted = true;
+ m_widgetHandle = widgetHandle;
+ m_loadedPlugins.clear();
+ m_context = context;
+
+ // Register standard features
+ installStandardFeatures();
+
+ // Register special features
+ installRequestedFeatures();
+
+ // set scale, bundle as window's property
+ setCustomProperties(scaleFactor, encodedBundle, theme);
+
+ // Load injected javascript files
+ loadInjectedJavaScript();
+ LogInfo("Widget session started.");
+}
+
+void JSPageSession::Impl::stopSession()
+{
+ LogInfo("Stopping widget session...");
+
+ if (!m_sessionStarted) {
+ LogWarning("Session not started!");
+ return;
+ }
+
+ unloadPluginsFromSession();
+ m_sessionStarted = false;
+
+ LogInfo("Widget session stopped.");
+}
+
+
+void JSPageSession::Impl::unloadPluginsFromSession()
+{
+ LogDebug("Unload plugins from session");
+
+ m_objectExplorer->removePluginsFromIframes();
+ m_objectExplorer->cleanIframesData();
+
+ // delete js object for overlayed js functions
+ FOREACH(it, JsFunctionManagerSingleton::Instance().getFunctions())
+ {
+ m_objectExplorer->deregisterObject(*it);
+ }
+
+ // delete js object for plugins
+ FOREACH(pluginIt, m_loadedPlugins)
+ {
+ LogDebug("Unregistering plugin " << (*pluginIt)->GetFileName());
+
+ (*pluginIt)->OnWidgetStop(m_widgetHandle);
+ LogDebug("Emitted WidgetStop for plugin: " <<
+ (*pluginIt)->GetFileName());
+
+ FOREACH(it, *((*pluginIt)->GetClassList()))
+ {
+ m_objectExplorer->deregisterObject(*it);
+ }
+ }
+
+ JavaScriptInterfaceSingleton::Instance().invokeGarbageCollector(m_context);
+
+ m_loadedPlugins.clear();
+
+ delete m_objectExplorer;
+ m_objectExplorer = NULL;
+}
+
+
+
+
+void JSPageSession::Impl::performLibrariesUnload()
+{
+#if 0
+ LogDebug("Perform library unload");
+
+ size_t unloadedLibraries = 0;
+
+ FOREACH(pluginIt, m_loadedPlugins)
+ {
+ LogDebug("Preparing library: " << (*pluginIt)->LibraryName.Get());
+
+ PluginPtr plugin = (*pluginIt)->LibraryInstance.Get();
+ if (!plugin) {
+ LogWarning("Library not loaded " << (*pluginIt)->LibraryName.Get());
+ continue;
+ }
+ unloadedLibraries++;
+ (*pluginIt)->LibraryInstance.Set(PluginPtr());
+ }
+
+ LogInfo("unloaded " << unloadedLibraries << " unreferenced libraries!");
+#endif
+}
+
+PluginPtr JSPageSession::Impl::loadLibrary(PluginModelPtr& pluginModel)
+{
+ PluginPtr pluginLib = pluginModel->LibraryInstance.Get();
+ if (!pluginLib)
+ {
+ std::string path = pluginModel->LibraryPath.Get() +
+ std::string(LIBRARY_PATH_SEPARATOR) +
+ pluginModel->LibraryName.Get();
+
+ pluginLib = Plugin::LoadFromFile(path);
+
+ if (!pluginLib)
+ {
+ LogError("Loading library failed");
+ } else
+ {
+ pluginModel->LibraryInstance.Set(pluginLib);
+
+ LogDebug("On widget start");
+ // This is first time for this plugin, start widget Session
+ pluginLib->OnWidgetStart(
+ m_widgetHandle);
+ m_loadedPlugins.insert(pluginLib);
+
+ FOREACH(context, m_loadedContexts)
+ {
+ pluginLib->OnFrameLoad(*context);
+ }
+ }
+ }
+ else
+ {
+ LogDebug("Get from LibraryInstance");
+ LogDebug("On widget start");
+ // This is first time for this plugin, start widget Session
+ pluginLib->OnWidgetStart(
+ m_widgetHandle);
+ m_loadedPlugins.insert(pluginLib);
+
+ FOREACH(context, m_loadedContexts)
+ {
+ pluginLib->OnFrameLoad(*context);
+ }
+ }
+
+ return pluginLib;
+}
+
+
+void JSPageSession::Impl::loadFrame(JSGlobalContextRef context)
+{
+ LogDebug("Load a frame");
+
+ if (!m_sessionStarted) {
+ LogWarning("Session NOT started!");
+ return;
+ }
+
+ m_loadedContexts.insert(context);
+
+ FOREACH(pluginIt, m_loadedPlugins)
+ {
+ LogDebug("load plugin to frame" << (*pluginIt)->GetFileName());
+
+ (*pluginIt)->OnFrameLoad(context);
+ }
+
+ m_objectExplorer->loadFrame(context);
+}
+
+void JSPageSession::Impl::unloadFrame(JSGlobalContextRef context)
+{
+ LogDebug("Unload a frame");
+
+ if (!m_sessionStarted) {
+ LogWarning("Session NOT started!");
+ return;
+ }
+
+ m_loadedContexts.erase(context);
+
+ FOREACH(pluginIt, m_loadedPlugins)
+ {
+ LogDebug("unload plugin to frame" << (*pluginIt)->GetFileName());
+
+ (*pluginIt)->OnFrameUnload(context);
+ }
+
+ m_objectExplorer->unloadFrame(context);
+}
+
+
+void JSPageSession::startSession(int widgetHandle,
+ JSGlobalContextRef ctx,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ m_impl->startSession(widgetHandle, ctx, scaleFactor, encodedBundle, theme);
+}
+
+void JSPageSession::stopSession()
+{
+ m_impl->stopSession();
+}
+
+void JSPageSession::performLibrariesUnload()
+{
+ m_impl->performLibrariesUnload();
+}
+
+bool JSPageSession::loadPluginOnDemand(
+ const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context)
+{
+ return m_impl->loadPluginOnDemand(pluginHandle, parentObject, context);
+}
+
+void JSPageSession::setCustomProperties(double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ m_impl->setCustomProperties(scaleFactor, encodedBundle, theme);
+}
+
+void JSPageSession::dispatchJavaScriptEvent(CustomEventType eventType)
+{
+ m_impl->dispatchJavaScriptEvent(eventType);
+}
+
+void JSPageSession::loadFrame(JSGlobalContextRef context)
+{
+ m_impl->loadFrame(context);
+}
+
+void JSPageSession::unloadFrame(JSGlobalContextRef context)
+{
+ m_impl->unloadFrame(context);
+}
+
+JSPageSession::JSPageSession(const PluginContainerSupportPtr& containerSupport)
+ : m_impl(new JSPageSession::Impl(containerSupport))
+{
+}
+
+JSPageSession::~JSPageSession()
+{
+}
--- /dev/null
+/*
+ * 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 js_page_session.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 1.0
+ */
+#ifndef WRT_PLUGIN_JS_PAGE_SESSION_H_
+#define WRT_PLUGIN_JS_PAGE_SESSION_H_
+
+#include <memory>
+#include <vector>
+#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
+#include <js_overlay_types.h>
+#include "js_types.h"
+
+using namespace WrtPlugins::W3C;
+
+class JSPageSession
+{
+ public:
+ // Widget session
+ void startSession(int widgetHandle,
+ JSGlobalContextRef view,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void stopSession();
+
+ //TODO im not sure if it is needed. I think it should be hidden
+ void performLibrariesUnload();
+ bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context);
+
+ void loadFrame(JSGlobalContextRef context);
+ void unloadFrame(JSGlobalContextRef context);
+
+ // reset custom window properties. (Tizen requirements)
+ void setCustomProperties(double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void dispatchJavaScriptEvent(CustomEventType eventType);
+
+ JSPageSession(const PluginContainerSupportPtr& containerSupport);
+
+ virtual ~JSPageSession();
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> m_impl;
+};
+
+typedef std::shared_ptr<JSPageSession> JSPageSessionPtr;
+
+#endif // PLUGIN_LOGIC_H
--- /dev/null
+/*
+ * 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 js_types.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 1.0
+ */
+
+#ifndef WRT_PLUGIN_JS_TYPES_H_
+#define WRT_PLUGIN_JS_TYPES_H_
+
+//forward declaration of JSConectexRef
+extern "C" {
+ typedef struct OpaqueJSContext* JSGlobalContextRef;
+ typedef struct OpaqueJSValue* JSObjectRef;
+}
+
+struct JavaScriptObject
+{
+ JSObjectRef instance;
+ std::string name;
+};
+
+#endif
--- /dev/null
+/*
+ * 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 plugin.cpp
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation file of plugin
+ */
+#include "plugin.h"
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dlfcn.h>
+
+Plugin::Plugin(const std::string &fileName,
+ void *libHandle,
+ on_widget_start_proc *apiOnWidgetStart,
+ on_widget_init_proc *apiOnWidgetInit,
+ on_widget_stop_proc *apiOnWidgetStop,
+ on_frame_load_proc* apiOnFrameLoad,
+ on_frame_unload_proc* apiOnFrameUnload,
+ const ClassPtrList &apiClassList) :
+ m_fileName(fileName),
+ m_libHandle(libHandle),
+ m_apiOnWidgetStart(apiOnWidgetStart),
+ m_apiOnWidgetInit(apiOnWidgetInit),
+ m_apiOnWidgetStop(apiOnWidgetStop),
+ m_apiOnFrameLoad(apiOnFrameLoad),
+ m_apiOnFrameUnload(apiOnFrameUnload),
+ m_apiClassList(apiClassList)
+{
+}
+
+Plugin::~Plugin()
+{
+ LogInfo("Unloading plugin library: " << m_fileName << "...");
+
+ // Unload library
+ if (dlclose(m_libHandle) != 0) {
+ LogError("Cannot close plugin handle");
+ } else {
+ LogDebug("Library is unloaded");
+ }
+}
+
+PluginPtr Plugin::LoadFromFile(const std::string& fileName)
+{
+ LogDebug("LoadFromFile" << fileName);
+
+ LogDebug("Loading plugin: " << fileName);
+
+ void *dllHandle;
+ dllHandle = dlopen(fileName.c_str(), RTLD_NOW);
+
+ if (dllHandle == NULL) {
+ LogError(
+ "Failed to load plugin: " << fileName << ". Reason: " << dlerror());
+ PluginPtr empty;
+ return empty;
+ }
+
+ // Load new plugin API
+ on_widget_start_proc *onWidgetStartProcPtr = NULL;
+ on_widget_stop_proc *onWidgetStopProcPtr = NULL;
+ on_widget_init_proc *onWidgetInitProcPtr = NULL;
+ on_frame_load_proc *onFrameLoadProcPtr = NULL;
+ on_frame_unload_proc *onFrameUnloadProcPtr = NULL;
+
+ const js_entity_definition_t *rawClassList = NULL;
+ get_widget_entity_map_proc *getWidgetEntityMapProcPtr = NULL;
+
+ onWidgetStartProcPtr =
+ reinterpret_cast<on_widget_start_proc *>(
+ dlsym(dllHandle, PLUGIN_WIDGET_START_PROC_NAME));
+ onWidgetInitProcPtr =
+ reinterpret_cast<on_widget_init_proc *>(
+ dlsym(dllHandle, PLUGIN_WIDGET_INIT_PROC_NAME));
+ onWidgetStopProcPtr =
+ reinterpret_cast<on_widget_stop_proc *>(
+ dlsym(dllHandle, PLUGIN_WIDGET_STOP_PROC_NAME));
+ onFrameLoadProcPtr =
+ reinterpret_cast<on_frame_load_proc *>(
+ dlsym(dllHandle, PLUGIN_FRAME_LOAD_PROC_NAME));
+ onFrameUnloadProcPtr =
+ reinterpret_cast<on_frame_unload_proc *>(
+ dlsym(dllHandle, PLUGIN_FRAME_UNLOAD_PROC_NAME));
+ getWidgetEntityMapProcPtr =
+ reinterpret_cast<get_widget_entity_map_proc *>(
+ dlsym(dllHandle, PLUGIN_GET_CLASS_MAP_PROC_NAME));
+
+ if( getWidgetEntityMapProcPtr )
+ {
+ rawClassList = (*getWidgetEntityMapProcPtr)();
+ LogDebug("rawClassList : " << rawClassList << "by getWidgetClassMapProcPtr()");
+ }
+ else
+ {
+ rawClassList =
+ static_cast<const js_entity_definition_t *>(dlsym(dllHandle,
+ PLUGIN_CLASS_MAP_NAME));
+ LogDebug("rawClassList : " << rawClassList );
+ }
+
+
+ if (NULL == onWidgetStartProcPtr || NULL == onWidgetStopProcPtr ||
+ /*NULL == onWidgetInitProcPtr ||*/ NULL == rawClassList) {
+ LogWarning("#####");
+ LogWarning(
+ "##### Warning: The following plugin does not support new plugin API.");
+ LogWarning(
+ "##### Old plugin API is deprecated. Please update it to new API");
+ LogWarning("#####");
+ LogWarning(
+ "##### Plugin: " << fileName <<
+ " has got deprecated or invalid API");
+ LogWarning("#####");
+
+ // Will not load plugin
+ dlclose(dllHandle);
+
+ PluginPtr empty;
+ return empty;
+ }
+
+ LogInfo("#####");
+ LogInfo("##### Plugin: " << fileName << " supports new plugin API");
+ LogInfo("#####");
+ LogInfo("##### $onWidgetStartProc: " << onWidgetStartProcPtr);
+ LogInfo("##### $onWidgetInitProc: " << onWidgetInitProcPtr);
+ LogInfo("##### $onWidgetStopProc " << onWidgetStopProcPtr);
+ LogInfo("##### $onFrameLoadProc " << onFrameLoadProcPtr);
+ LogInfo("##### $onFrameUnloadProc " << onFrameUnloadProcPtr);
+ LogInfo("##### $classMap: " << reinterpret_cast<const void *>(rawClassList));
+ LogInfo("##### ");
+ LogInfo("##### Class map:");
+
+ const js_entity_definition_t *rawEntityListIterator = rawClassList;
+ ClassPtrList classList(new Plugin::ClassList());
+
+ // Parse all class definitions
+ while (rawEntityListIterator->parent_name != NULL &&
+ rawEntityListIterator->object_name != NULL)
+ {
+ // Logging
+ LogInfo("#####");
+ LogInfo("##### [" << rawEntityListIterator->object_name << "]: ");
+ LogInfo("##### Interface: " <<
+ rawEntityListIterator->interface_name);
+ LogInfo("##### Parent: " << rawEntityListIterator->parent_name);
+
+ // Register class
+ classList->push_back(ClassPtr(new Class(rawEntityListIterator)));
+
+ // Go to next class
+ ++rawEntityListIterator;
+ }
+
+ LogInfo("#####");
+
+ // Load export table
+ LogDebug("Plugin successfuly loaded");
+
+ // Insert to loaded modules list
+
+ PluginPtr instance(new Plugin(fileName,
+ dllHandle,
+ onWidgetStartProcPtr,
+ onWidgetInitProcPtr,
+ onWidgetStopProcPtr,
+ onFrameLoadProcPtr,
+ onFrameUnloadProcPtr,
+ classList));
+
+ return instance;
+}
+
+std::string Plugin::GetFileName() const
+{
+ return m_fileName;
+}
+
+void Plugin::OnWidgetStart(int widgetId)
+{
+ if (NULL != m_apiOnWidgetStart)
+ {
+ (*m_apiOnWidgetStart)(widgetId);
+ }
+ else
+ {
+ LogWarning("OnWidgetStart not set!");
+ }
+}
+
+void Plugin::OnWidgetInit(feature_mapping_interface_t* mapping)
+{
+ Assert(NULL != mapping && "NULL mapping interface provided");
+ if (NULL != m_apiOnWidgetInit)
+ {
+ (*m_apiOnWidgetInit)(mapping);
+ }
+ else
+ {
+ LogWarning("OnWidgetInit not set!");
+ }
+}
+
+void Plugin::OnWidgetStop(int widgetId)
+{
+ if (NULL != m_apiOnWidgetStop)
+ {
+ (*m_apiOnWidgetStop)(widgetId);
+ }
+ else
+ {
+ LogWarning("OnWidgetStop not set!");
+ }
+}
+
+void Plugin::OnFrameLoad(java_script_context_t context)
+{
+ if (NULL != m_apiOnFrameLoad)
+ {
+ (*m_apiOnFrameLoad)(context);
+ }
+ else
+ {
+ LogWarning("OnFrameLoad not set!");
+ }
+}
+
+void Plugin::OnFrameUnload(java_script_context_t context)
+{
+ if (NULL != m_apiOnFrameUnload)
+ {
+ (*m_apiOnFrameUnload)(context);
+ }
+ else
+ {
+ LogWarning("OnFrameUnload not set!");
+ }
+}
+
+const Plugin::ClassPtrList Plugin::GetClassList() const
+{
+ return m_apiClassList;
+}
--- /dev/null
+/*
+ * 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 plugin.h
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation file of plugin
+ */
+#ifndef WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_
+#define WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_
+
+#include <list>
+#include <map>
+#include <string>
+#include <dpl/atomic.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <wrt_plugin_export.h>
+#include <Commons/JSObjectDeclaration.h>
+
+class Plugin;
+typedef DPL::SharedPtr<Plugin> PluginPtr;
+
+class Plugin : private DPL::Noncopyable
+{
+ public:
+ typedef JSObjectDeclaration Class;
+ typedef JSObjectDeclarationPtr ClassPtr;
+ typedef std::list<ClassPtr> ClassList;
+ typedef DPL::SharedPtr<ClassList> ClassPtrList;
+
+ private:
+ ///< Plug-in identifier. Currently plug-in file name is used as the ID
+ std::string m_fileName;
+
+ ///< Handle for the plug-in library. A plug-in is a dynamic loadable library
+ void* m_libHandle;
+
+ // Plugin API
+ on_widget_start_proc* m_apiOnWidgetStart;
+ on_widget_init_proc* m_apiOnWidgetInit;
+ on_widget_stop_proc* m_apiOnWidgetStop;
+ on_frame_load_proc* m_apiOnFrameLoad;
+ on_frame_unload_proc* m_apiOnFrameUnload;
+ const ClassPtrList m_apiClassList;
+
+ Plugin(const std::string &fileName,
+ void *libHandle,
+ on_widget_start_proc* apiOnWidgetStart,
+ on_widget_init_proc* apiOnWidgetInit,
+ on_widget_stop_proc* apiOnWidgetStop,
+ on_frame_load_proc* apiOnFrameLoad,
+ on_frame_unload_proc* apiOnFrameUnload,
+ const ClassPtrList &apiClassList);
+
+ public:
+ virtual ~Plugin();
+
+ // Loading
+ static PluginPtr LoadFromFile(const std::string &fileName);
+
+ // Filename
+ std::string GetFileName() const;
+
+ // API
+ void OnWidgetStart(int widgetId);
+
+ void OnWidgetInit(feature_mapping_interface_t *interface);
+
+ void OnWidgetStop(int widgetId);
+
+ void OnFrameLoad(java_script_context_t context);
+
+ void OnFrameUnload(java_script_context_t context);
+
+ const ClassPtrList GetClassList() const;
+};
+
+#endif // PLUGIN_H
--- /dev/null
+/*
+ * 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 plugin_container_support.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 1.0
+ */
+
+#include "plugin_container_support.h"
+
+#include <fstream>
+
+#include <dpl/foreach.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+namespace {
+const char *STANDARD_FEATURES_LIST_FILE = "standard-features-list";
+}
+
+using namespace WrtDB;
+
+PluginContainerSupport::PluginContainerSupport()
+{
+ // Retrieve plugin model list
+ readPlugins();
+
+ // Retrieve features model list
+ readFeatures();
+
+ // Reading standard features list from file
+ readStandardFeaturesList();
+}
+
+PluginContainerSupport::~PluginContainerSupport()
+{
+ // Remove all plugin models
+ m_pluginModels.clear();
+
+ // Remove all feature models
+ m_featureModels.clear();
+
+ // Clear standard features list
+ m_standardFeatureList.clear();
+}
+
+void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
+{
+ PluginModelPtr model = getPluginModelById(handle);
+
+ if (model) {
+ LogDebug("Model for plugin:" << handle << " already registered");
+ return;
+ }
+
+ LogDebug("Creating Model for plugin: " << handle);
+
+ if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
+ PluginDAOReadOnly::getInstallationStateForHandle(handle))
+ {
+ LogWarning("Failed To CreateModel for handle " << handle);
+ return;
+ }
+
+ model.Reset(new PluginModel(handle));
+
+ LogInfo("Model Created. Handle: " <<
+ handle << ", name: " << model->LibraryName.Get());
+
+ m_pluginModels.insert(model);
+}
+
+void PluginContainerSupport::readPlugins()
+{
+ LogDebug("Retrieving installed plugin list...");
+ PluginHandleList plugins = PluginDAOReadOnly::getPluginHandleList();
+
+ FOREACH(it, plugins)
+ {
+ registerPluginModel(*it);
+ }
+}
+
+void PluginContainerSupport::readFeatures()
+{
+ std::map<FeatureHandle, std::string> featureNames = FeatureDAOReadOnly::GetNames();
+ std::multimap<FeatureHandle, std::string> deviceCapabilities = FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
+
+ FOREACH(pluginIt, m_pluginModels)
+ {
+ PluginModelPtr model = *pluginIt;
+ LogDebug("Analyzing Plugin model: " << model->Handle.Get());
+
+ WrtDB::DbPluginHandle pluginHandle = model->Handle.Get();
+ FeatureHandleListPtr featureHandles = model->FeatureHandles.Get();
+
+ FOREACH(featureIt, *featureHandles)
+ {
+ LogDebug("Analyzing feature: " << *featureIt);
+ FeatureModelPtr model = getFeatureModel(*featureIt);
+ if (model) {
+ LogDebug("Model for feature:" << *featureIt << " already created");
+ continue;
+ }
+
+ LogDebug("Creating Model for feature:" << *featureIt);
+
+ model.Reset(new FeatureModel(*featureIt));
+
+ std::set<std::string> devCapList;
+ auto ret = deviceCapabilities.equal_range(*featureIt);
+ for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++)
+ {
+ devCapList.insert((*devCapIt).second);
+ }
+ model->SetData(featureNames.find(*featureIt)->second, devCapList, pluginHandle);
+ m_featureModels.insert(model);
+ }
+ }
+}
+
+void PluginContainerSupport::readStandardFeaturesList()
+{
+ LogDebug("Reading standard features list from file...");
+
+ std::string path = GlobalConfig::GetDevicePluginPath();
+ path += "/";
+ path += STANDARD_FEATURES_LIST_FILE;
+
+ std::ifstream standardFeatureFile;
+ standardFeatureFile.open(path.c_str(), std::ifstream::in);
+
+ if (!standardFeatureFile.is_open()) {
+ LogError("Reading standard features list from file FAILED.");
+ return;
+ }
+
+ char buffer[1024];
+
+ while (!standardFeatureFile.eof()) {
+ standardFeatureFile.getline(buffer, sizeof(buffer));
+
+ if (buffer[0] == '\0') {
+ break;
+ }
+
+ LogDebug("Standard Feature: <" << buffer << ">");
+ m_standardFeatureList.push_back(std::string(buffer));
+ }
+
+ standardFeatureFile.close();
+}
+
+FeatureModelPtr
+PluginContainerSupport::getFeatureModel(const std::string &name) const
+{
+ FOREACH(iter, m_featureModels)
+ {
+ if ((*iter)->Name.Get() == name) {
+ return *iter;
+ }
+ }
+
+ return FeatureModelPtr();
+}
+
+FeatureModelPtr
+PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
+{
+ FOREACH(iter, m_featureModels)
+ {
+ if ((*iter)->FHandle.Get() == handle) {
+ return *iter;
+ }
+ }
+
+ return FeatureModelPtr();
+}
+
+PluginModelPtr
+PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
+{
+ FOREACH(pluginModel, m_pluginModels)
+ {
+ if ((*pluginModel)->Handle.Get() == handle) {
+ return *pluginModel;
+ }
+ }
+
+ return PluginModelPtr();
+}
+
+PluginModelPtr
+PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
+{
+ LogDebug("");
+ Assert(feature && "Null Ptr for feature model");
+ LogDebug("Feature located in plugin: " << feature->PHandle.Get());
+
+ return getPluginModelById(feature->PHandle.Get());
+}
+
+PluginContainerSupport::FeaturesList
+PluginContainerSupport::getStandardFeatures() const
+{
+ //TODO use move
+ FeaturesList standardFeatures;
+
+ FOREACH(it, m_standardFeatureList)
+ {
+ FeatureModelPtr feature = getFeatureModel(*it);
+ if (!feature) {
+ LogWarning("Feature does not exist in DB " << *it);
+ continue;
+ }
+
+ //TODO maybe it should be sorted
+ standardFeatures.push_back(feature);
+ }
+
+ return standardFeatures;
+}
+
+PluginContainerSupport::PluginsList
+PluginContainerSupport::getStandardPlugins() const
+{
+ PluginsList plugins;
+
+ auto features = getStandardFeatures();
+
+ FOREACH(it, features)
+ {
+ auto plugin = getPluginModel(*it);
+ if(!plugin)
+ {
+ LogError("PluginModel not found");
+ continue;
+ }
+
+ plugins.push_back(plugin);
+ }
+
+ return plugins;
+}
+
+PluginModelPtr
+PluginContainerSupport::getPluginForFeature(const std::string& featureName)
+{
+ return getPluginModel(getFeatureModel(featureName));
+}
--- /dev/null
+/*
+ * 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 plugin_container_support.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 1.0
+ */
+#ifndef PLUGIN_CONTAINER_SUPPORT_H
+#define PLUGIN_CONTAINER_SUPPORT_H
+
+#include <memory>
+#include <set>
+#include <string>
+
+#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
+#include <dpl/wrt-dao-ro/feature_model.h>
+
+#include "plugin_model.h"
+
+class PluginContainerSupport
+{
+public:
+ typedef std::list<WrtDB::FeatureModelPtr> FeaturesList;
+ typedef std::list<PluginModelPtr> PluginsList;
+
+private:
+ // Standard features
+ typedef std::list<std::string> StandardFeatureList;
+
+ // Main feature list. Always equal to DB feature list
+ typedef std::set<WrtDB::FeatureModelPtr> FeatureModelContainer;
+
+ // Main plugin list. Always equal to DB plugin list
+ typedef std::set<PluginModelPtr> PluginModelsContainer;
+
+ StandardFeatureList m_standardFeatureList;
+
+ PluginModelsContainer m_pluginModels;
+
+ FeatureModelContainer m_featureModels;
+
+private:
+ // Reading
+ void readPlugins();
+ void readFeatures();
+ void readStandardFeaturesList();
+
+ // Plugin models
+ void registerPluginModel(WrtDB::DbPluginHandle handle);
+
+
+ WrtDB::FeatureModelPtr getFeatureModel(const std::string &name) const ;
+ WrtDB::FeatureModelPtr getFeatureModel(WrtDB::FeatureHandle handle) const ;
+
+ PluginModelPtr getPluginModel(const WrtDB::FeatureModelPtr &feature) const;
+
+public:
+ PluginContainerSupport();
+
+ FeaturesList getStandardFeatures() const;
+ PluginsList getStandardPlugins() const;
+
+ PluginModelPtr getPluginForFeature(const std::string& featureName);
+
+ PluginModelPtr getPluginModelById(WrtDB::DbPluginHandle handle) const;
+
+ ~PluginContainerSupport();
+};
+
+
+typedef std::shared_ptr<PluginContainerSupport> PluginContainerSupportPtr;
+
+#endif // PLUGIN_CONTAINER_SUPPORT_H
--- /dev/null
+/*
+ * 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 plugin_iframe_support.cpp
+ * @version 1.0
+ * @brief
+ */
+
+#include "plugin_iframe_support.h"
+
+#include <algorithm>
+#include <dpl/foreach.h>
+
+void IframesSupport::registerDeclaration(
+ const JSObjectDeclarationPtr& declaration)
+{
+ LogDebug("Registration iframes-supported plugins " <<
+ declaration->getName());
+
+ if(declaration->getParentName().find('.') != std::string::npos)
+ {
+ LogWarning("The object will not be loaded to iframes");
+ return;
+ }
+ m_iframesObjects.push_back(declaration);
+}
+
+void IframesSupport::registerIframe(const JSObjectPtr& iframe){
+ LogDebug("LoadedIframes size: " << m_loadedIframes.size() );
+
+ m_loadedIframes.insert(iframe);
+}
+
+void IframesSupport::unregisterIframe(const JSObjectPtr& iframe){
+ LogDebug("LoadedIframes size: " << m_loadedIframes.size() );
+
+ auto it_loaded = std::find_if(m_loadedIframes.begin(),
+ m_loadedIframes.end(),
+ std::bind2nd(EqualToJSObjectPtr(), iframe));
+ //object not found, so thats the new iframe
+ if(it_loaded == m_loadedIframes.end()){
+ LogDebug("Nothing to unregister");
+ return;
+ }
+
+ m_loadedIframes.erase(it_loaded);
+}
+
+bool IframesSupport::hasIframes() const
+{
+ return !m_loadedIframes.empty();
+}
+
+IframesSupport::DeclarationsList IframesSupport::getIframeObjects() const
+{
+ return m_iframesObjects;
+}
+
+void IframesSupport::clean()
+{
+ m_iframesObjects.clear();
+ m_loadedIframes.clear();
+}
--- /dev/null
+/*
+ * 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 plugin_iframe_support.h
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef _WRTENGINE_SRC_PLUGINSERVICE_IFRAME_SUPPORT_H_
+#define _WRTENGINE_SRC_PLUGINSERVICE_IFRAME_SUPPORT_H_
+
+#include<list>
+#include<set>
+#include <Commons/JSObjectDeclaration.h>
+#include <Commons/JSObject.h>
+#include "javascript_interface.h"
+
+class IframesSupport
+{
+ public:
+ typedef std::list<JSObjectDeclarationPtr> DeclarationsList;
+
+ public:
+ void registerDeclaration(const JSObjectDeclarationPtr& declaration);
+
+ void registerIframe(const JSObjectPtr& iframe);
+
+ void unregisterIframe(const JSObjectPtr& iframe);
+
+ DeclarationsList getIframeObjects() const;
+
+ bool hasIframes() const;
+
+ void clean();
+
+ private:
+ std::list<JSObjectDeclarationPtr> m_iframesObjects;
+ std::set<JSObjectPtr> m_loadedIframes;
+
+ // used to find matching object from m_loadedIframes
+ struct EqualToJSObjectPtr
+ {
+ typedef JSObjectPtr first_argument_type;
+ typedef JSObjectPtr second_argument_type;
+ typedef bool result_type;
+
+ result_type operator()(const first_argument_type &s1,
+ const second_argument_type &s2) const
+ {
+ return (s1->getObject() == s2->getObject());
+ }
+ };
+};
+
+#endif
--- /dev/null
+/*
+ * 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 plugin_logic.cpp
+ * @author Piotr Fatyga (p.fatyga@samsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation file of plugin and
+ * feature loading routines
+ * @brief This code is intended to work behind view controller
+ */
+
+#include "plugin_logic.h"
+
+#include <dpl/assert.h>
+#include <dpl/scoped_array.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/singleton_impl.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+#include <JavaScriptCore/JavaScript.h>
+
+#include <string>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fstream>
+#include <map>
+#include <list>
+#include <vector>
+#include <algorithm>
+#include <cstring>
+
+#include <wrt_plugin_export.h>
+#include <js_overlay_types.h>
+
+#include "explorer.h"
+#include "plugin.h"
+#include "plugin_model.h"
+#include "javascript_interface.h"
+#include "js_function_manager.h"
+#include "plugin_container_support.h"
+
+#include "js_page_session.h"
+
+using namespace std;
+using namespace WrtDB;
+using namespace WrtPlugins::W3C;
+
+namespace {
+const char *LIBRARY_PATH_SEPARATOR = "/";
+const char* FEATURE_WAC20_DEVICAPIS_NAME = "http://wacapps.net/api/deviceapis";
+}
+
+class PluginLogic::Impl
+{
+ PluginContainerSupportPtr m_pluginsSupport;
+
+ typedef std::map<JSContextRef, JSPageSessionPtr> PagesSessionsSet;
+ PagesSessionsSet m_sessions;
+
+
+ public:
+ Impl();
+ ~Impl();
+
+ // Widget session
+ void startSession(int widgetHandle,
+ JSGlobalContextRef context,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void stopSession(JSGlobalContextRef context);
+
+ void performLibrariesUnload();
+
+ bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context);
+
+ void loadFrame(JSGlobalContextRef context);
+ void unloadFrame(JSGlobalContextRef context);
+
+ void setCustomProperties(JSGlobalContextRef ctx,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void dispatchJavaScriptEvent(JSGlobalContextRef ctx,
+ CustomEventType eventType);
+
+};
+
+IMPLEMENT_SINGLETON(PluginLogic);
+
+PluginLogic::Impl::Impl()
+{
+ DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
+ LogDebug("Initializing Plugin Logic...");
+ m_pluginsSupport = PluginContainerSupportPtr(new PluginContainerSupport());
+
+ // explicit call to keep singleton's lifetime until calling destructor.
+ JsFunctionManagerSingleton::Instance();
+ JavaScriptInterfaceSingleton::Instance();
+}
+
+PluginLogic::Impl::~Impl()
+{
+ FOREACH(it, m_sessions)
+ {
+ LogError("Must stop widget session before exit!");
+ it->second->stopSession();
+ }
+
+ LogDebug("Deinitializing plugin Logic...");
+}
+
+
+void PluginLogic::startSession(int widgetHandle,
+ JSGlobalContextRef ctx,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ m_impl->startSession(widgetHandle, ctx, scaleFactor, encodedBundle, theme);
+}
+
+void PluginLogic::stopSession(JSGlobalContextRef context)
+{
+ m_impl->stopSession(context);
+}
+
+void PluginLogic::performLibrariesUnload()
+{
+ LogError("Libraries unload TURNED OFF");
+// m_impl->performLibrariesUnload();
+}
+
+bool PluginLogic::loadPluginOnDemand(
+ const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context)
+{
+ return m_impl->loadPluginOnDemand(pluginHandle, parentObject, context);
+}
+
+void PluginLogic::loadPluginsIntoIframes(JSGlobalContextRef context)
+{
+ LogError("This function is Deprecated");
+}
+
+void PluginLogic::setCustomProperties(double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ LogError("This function is DEPRECATED");
+}
+
+void PluginLogic::setCustomProperties(JSGlobalContextRef context,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ m_impl->setCustomProperties(context, scaleFactor, encodedBundle, theme);
+}
+
+void PluginLogic::dispatchJavaScriptEvent(CustomEventType eventType)
+{
+ LogError("This function is DEPRECATED");
+}
+
+void PluginLogic::dispatchJavaScriptEvent(JSGlobalContextRef context,
+ CustomEventType eventType)
+{
+ m_impl->dispatchJavaScriptEvent(context, eventType);
+}
+
+void PluginLogic::loadFrame(JSGlobalContextRef context)
+{
+ m_impl->loadFrame(context);
+}
+
+void PluginLogic::unloadFrame(JSGlobalContextRef context)
+{
+ m_impl->unloadFrame(context);
+}
+
+PluginLogic::PluginLogic() : m_impl(new PluginLogic::Impl())
+{
+}
+
+PluginLogic::~PluginLogic()
+{
+}
+
+void PluginLogic::Impl::startSession(int widgetHandle,
+ JSGlobalContextRef context,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ LogInfo("Starting widget session...");
+
+ auto sessionIt = m_sessions.find(context);
+
+ // Check if corresponding session if not already created
+ if (sessionIt != m_sessions.end())
+ {
+ LogWarning("Session already started!");
+ return;
+ }
+
+ auto newSession = JSPageSessionPtr(new JSPageSession(m_pluginsSupport));
+ newSession->startSession(widgetHandle,
+ context,
+ scaleFactor,
+ encodedBundle,
+ theme);
+
+ m_sessions[context] = newSession;
+}
+
+void PluginLogic::Impl::stopSession(JSGlobalContextRef context)
+{
+ LogInfo("Stopping widget session...");
+
+ auto sessionIt = m_sessions.find(context);
+ if (sessionIt == m_sessions.end())
+ {
+ LogError("Session not exist!");
+ return;
+ }
+
+ sessionIt->second->stopSession();
+ m_sessions.erase(sessionIt);
+
+ LogInfo("Widget session stopped.");
+}
+
+bool PluginLogic::Impl::loadPluginOnDemand(
+ const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context
+ )
+{
+ LogInfo("Load plugin on demand");
+
+ auto sessionIt = m_sessions.find(context);
+ if (sessionIt == m_sessions.end())
+ {
+ LogWarning("Session not exist!");
+ return false;
+ }
+
+ return sessionIt->second->loadPluginOnDemand(pluginHandle,
+ parentObject,
+ context);
+}
+
+void PluginLogic::Impl::loadFrame(JSGlobalContextRef context)
+{
+ LogDebug("Load a frame");
+ auto sessionIt = m_sessions.find(context);
+ if (sessionIt == m_sessions.end())
+ {
+ LogWarning("Session not exist!");
+ return;
+ }
+
+ sessionIt->second->loadFrame(context);
+}
+
+void PluginLogic::Impl::unloadFrame(JSGlobalContextRef context)
+{
+ LogDebug("Unload a frame");
+
+ auto sessionIt = m_sessions.find(context);
+ if (sessionIt == m_sessions.end())
+ {
+ LogWarning("Session not exist!");
+ return;
+ }
+
+ sessionIt->second->unloadFrame(context);
+}
+
+void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
+{
+ LogInfo("set properties of window object " << scaleFactor << ", "
+ << encodedBundle << ", " << theme);
+
+ auto sessionIt = m_sessions.find(context);
+ if (sessionIt == m_sessions.end())
+ {
+ LogWarning("Session not exist!");
+ return;
+ }
+
+ sessionIt->second->setCustomProperties(scaleFactor,
+ encodedBundle,
+ theme);
+
+}
+
+void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context,
+ CustomEventType eventType)
+{
+ LogDebug("Dispatch event");
+
+ auto sessionIt = m_sessions.find(context);
+ if (sessionIt == m_sessions.end())
+ {
+ LogWarning("Session not exist!");
+ return;
+ }
+
+ sessionIt->second->dispatchJavaScriptEvent(eventType);
+
+
+}
--- /dev/null
+/*
+ * 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 plugin_logic.h
+ * @author Piotr Fatyga (p.fatyga@samsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation file of plugin and feature
+ * loading routines
+ * @brief This code is intended to work behind view controller
+ */
+#ifndef PLUGIN_LOGIC_H
+#define PLUGIN_LOGIC_H
+
+#include <memory>
+#include <vector>
+#include <set>
+#include <dpl/singleton.h>
+#include <dpl/noncopyable.h>
+#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
+#include <js_overlay_types.h>
+#include <js_types.h>
+#include <Commons/Deprecated.h>
+
+using namespace WrtPlugins::W3C;
+
+
+class PluginLogic : DPL::Noncopyable
+{
+ public:
+ // Widget session
+ void startSession(int widgetHandle,
+ JSGlobalContextRef view,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void stopSession(JSGlobalContextRef context);
+
+ //TODO im not sure if it is needed. I think it should be hidden
+ void performLibrariesUnload();
+ bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context);
+
+ WRT_PLUGINS_DEPRECATED void loadPluginsIntoIframes(
+ JSGlobalContextRef context);
+
+ void loadFrame(JSGlobalContextRef context);
+ void unloadFrame(JSGlobalContextRef context);
+
+ // reset custom window properties. (Tizen requirements)
+ WRT_PLUGINS_DEPRECATED void setCustomProperties(double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ void setCustomProperties(JSGlobalContextRef ctx,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme);
+
+ WRT_PLUGINS_DEPRECATED void dispatchJavaScriptEvent(CustomEventType eventType);
+
+ void dispatchJavaScriptEvent(JSGlobalContextRef ctx,
+ CustomEventType eventType);
+
+ private:
+ PluginLogic();
+ ~PluginLogic();
+
+ class Impl;
+ std::unique_ptr<Impl> m_impl;
+
+ friend class DPL::Singleton<PluginLogic>;
+};
+
+typedef DPL::Singleton<PluginLogic> PluginLogicSingleton;
+
+#endif // PLUGIN_LOGIC_H
--- /dev/null
+/*
+ * 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 plugin_model.cpp
+ * @author Pawel Sikorski (p.sikorski@samgsung.com)
+ * @author Przemyslaw Dobrowolski (p.dobrowolsk@samgsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief This file contains PluginModel, PluginHandle definitions.
+ */
+
+#include "plugin_model.h"
+#include <dpl/event/model_bind_to_dao.h>
+#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
+
+using namespace WrtDB;
+
+template <typename RetType, RetType(PluginDAOReadOnly::*extFun) () const >
+struct BindToPluginDAO :
+ DPL::Event::BindToDAO<PluginModel,
+ RetType,
+ WrtDB::DbPluginHandle,
+ PluginDAOReadOnly,
+ &PluginModel::getHandle,
+ extFun>
+{
+};
+
+template <typename RetType, RetType(*extFun) (WrtDB::DbPluginHandle)>
+struct BindToFeatureDAOStatic :
+ DPL::Event::BindToDAO_Static<PluginModel,
+ RetType,
+ WrtDB::DbPluginHandle,
+ &PluginModel::getHandle,
+ extFun>
+{
+};
+
+PluginModel::PluginModel(const WrtDB::DbPluginHandle& handle) :
+ Handle(this, handle),
+ LibraryName(this,
+ BindToPluginDAO<std::string,
+ &PluginDAOReadOnly::getLibraryName>::Get),
+ LibraryPath(this,
+ BindToPluginDAO<std::string,
+ &PluginDAOReadOnly::getLibraryPath>::Get),
+ FeatureHandles(this,
+ BindToFeatureDAOStatic<FeatureHandleListPtr,
+ FeatureDAOReadOnly::GetFeatureHandleListForPlugin>::Get),
+ LibraryDependencies(this,
+ BindToPluginDAO<PluginHandleSetPtr,
+ &PluginDAOReadOnly::getLibraryDependencies>::Get),
+ LibraryInstance(this, PluginPtr())
+{
+}
+
+WrtDB::DbPluginHandle PluginModel::getHandle() const
+{
+ return Handle.Get();
+}
+
+bool PluginModel::operator< (const PluginModel& obj) const
+{
+ return obj.Handle.Get() < Handle.Get();
+}
--- /dev/null
+/*
+ * 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 plugin_model.h
+ * @author Pawel Sikorski (p.sikorski@samgsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief This file contains PluginModel, PluginHandle definitions.
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_PLUGIN_MODEL_H_
+#define WRT_SRC_PLUGIN_SERVICE_PLUGIN_MODEL_H_
+
+#include <string>
+#include <list>
+#include <dpl/shared_ptr.h>
+#include <dpl/event/model.h>
+#include <dpl/event/property.h>
+
+#include <dpl/wrt-dao-ro/feature_model.h>
+#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
+#include <plugin.h>
+
+class PluginModel;
+
+class PluginModel : public DPL::Event::Model
+{
+ public:
+
+ /**
+ *@brief Plugin handle
+ */
+ DPL::Event::Property<WrtDB::DbPluginHandle, DPL::Event::PropertyReadOnly> Handle;
+
+ /**
+ *@brief LibraryName
+ */
+ DPL::Event::Property<std::string,
+ DPL::Event::PropertyReadOnly,
+ DPL::Event::PropertyStorageDynamicCached> LibraryName;
+
+ /**
+ *@brief Library Path
+ */
+ DPL::Event::Property<std::string,
+ DPL::Event::PropertyReadOnly,
+ DPL::Event::PropertyStorageDynamicCached> LibraryPath;
+
+ /**
+ *@brief Feature set
+ */
+ DPL::Event::Property<WrtDB::FeatureHandleListPtr,
+ DPL::Event::PropertyReadOnly,
+ DPL::Event::PropertyStorageDynamicCached> FeatureHandles;
+
+ /**
+ *@brief Librarydepencies
+ */
+ DPL::Event::Property<WrtDB::PluginHandleSetPtr,
+ DPL::Event::PropertyReadOnly,
+ DPL::Event::PropertyStorageDynamicCached> LibraryDependencies;
+
+ /**
+ *@brief Library instance Low Level
+ * */
+ DPL::Event::Property<PluginPtr,
+ DPL::Event::PropertyReadWrite,
+ DPL::Event::PropertyStorageCached> LibraryInstance;
+
+ public:
+ PluginModel(const WrtDB::DbPluginHandle& handle);
+
+ bool operator< (const PluginModel& obj) const;
+
+ private:
+ WrtDB::DbPluginHandle getHandle() const;
+};
+
+typedef DPL::SharedPtr<PluginModel> PluginModelPtr;
+
+#endif
--- /dev/null
+/*
+ * 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 plugin_property_support.cpp
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#include "plugin_property_support.h"
+#include <dpl/log/log.h>
+
+using namespace PluginModule;
+
+
+const char *NAVIGATOR_PROPERTY_NAME = "navigator";
+const char *SCALE_PROPERTY_NAME = "scale";
+const char *BUNDLE_PROPERTY_NAME = "__bundle";
+const char *THEME_PROPERTY_NAME = "theme";
+
+WindowPropertySupport::WindowPropertySupport(
+ JSGlobalContextRef context):
+ m_scale(0),
+ m_bundle(""),
+ m_theme(""),
+ m_context(context)
+{
+}
+
+WindowPropertySupport::~WindowPropertySupport()
+{
+}
+
+float WindowPropertySupport::getScale() const
+{
+ return m_scale;
+}
+
+std::string WindowPropertySupport::getBundle() const
+{
+ return m_bundle;
+}
+
+std::string WindowPropertySupport::getTheme() const
+{
+ return m_theme;
+}
+
+JSGlobalContextRef WindowPropertySupport::getJSContext() const
+{
+ return m_context;
+}
+
+void WindowPropertySupport::setScaleToNavigatorProperty(const double scale)
+{
+ LogInfo("set window.navigator.scale: " << scale);
+
+ m_scale = scale;
+
+ setPropertyToNavigator(SCALE_PROPERTY_NAME, JSValueMakeNumber(m_context, scale));
+}
+
+void WindowPropertySupport::setBundleToWindowProperty(const char* bundle)
+{
+ LogInfo("set window.__bundle: " << bundle);
+
+ if(bundle)
+ {
+ m_bundle = bundle;
+
+ JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
+
+ setPropertyToWindow(BUNDLE_PROPERTY_NAME,
+ JSValueMakeString(m_context, bundleString));
+
+ JSStringRelease(bundleString);
+ }
+}
+
+
+void WindowPropertySupport::setBundleToNavigatorProperty(const char* bundle)
+{
+ LogInfo("set window.navigator.__bundle: " << bundle);
+
+ if(bundle)
+ {
+ m_bundle = bundle;
+
+ JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
+
+ setPropertyToNavigator(BUNDLE_PROPERTY_NAME,
+ JSValueMakeString(m_context, bundleString));
+
+ JSStringRelease(bundleString);
+ }
+}
+
+void WindowPropertySupport::setThemeToNavigatorProperty(const char* theme)
+{
+ LogInfo("set window.navigator.__theme: " << theme);
+
+ if(theme)
+ {
+ m_theme = theme;
+
+ JSStringRef themeString = JSStringCreateWithUTF8CString(theme);
+
+ setPropertyToNavigator(THEME_PROPERTY_NAME,
+ JSValueMakeString(m_context, themeString));
+
+ JSStringRelease(themeString);
+ }
+}
+
+void WindowPropertySupport::setPropertyToWindow(const char* propertyName,
+ JSValueRef jsValue)
+{
+ if(propertyName)
+ {
+ JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
+
+ JSStringRef propertyNameString =
+ JSStringCreateWithUTF8CString(propertyName);
+ JSObjectSetProperty(m_context,
+ globalObject,
+ propertyNameString,
+ jsValue,
+ kJSPropertyAttributeReadOnly,
+ NULL);
+
+ JSStringRelease(propertyNameString);
+ }
+}
+
+void WindowPropertySupport::setPropertyToNavigator(const char* propertyName,
+ JSValueRef jsValue)
+{
+ if(propertyName)
+ {
+ JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
+
+ JSStringRef navigatorString =
+ JSStringCreateWithUTF8CString(NAVIGATOR_PROPERTY_NAME);
+ JSValueRef navigatorValue = JSObjectGetProperty(m_context,
+ globalObject,
+ navigatorString,
+ NULL);
+
+ JSStringRef propertyNameString =
+ JSStringCreateWithUTF8CString(propertyName);
+ JSObjectSetProperty(m_context,
+ JSValueToObject(m_context, navigatorValue, NULL),
+ propertyNameString,
+ jsValue,
+ kJSPropertyAttributeReadOnly,
+ NULL);
+
+ JSStringRelease(propertyNameString);
+ JSStringRelease(navigatorString);
+ }
+}
+
--- /dev/null
+/*
+ * 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 plugin_property_support.h
+ * @author Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef _PLUGIN_LOGIC_PROPERTY_SUPPORT_H_
+#define _PLUGIN_LOGIC_PROPERTY_SUPPORT_H_
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace PluginModule {
+
+class WindowPropertySupport
+{
+ public:
+ float getScale() const;
+ std::string getBundle() const;
+ std::string getTheme() const;
+ JSGlobalContextRef getJSContext() const;
+
+ void setScaleToNavigatorProperty(const double scale);
+ void setBundleToWindowProperty(const char* bundle);
+ void setBundleToNavigatorProperty(const char* bundle);
+ void setThemeToNavigatorProperty(const char* theme);
+
+ explicit WindowPropertySupport(JSGlobalContextRef m_context);
+ ~WindowPropertySupport();
+
+ private:
+ float m_scale;
+ std::string m_bundle; // string of base64 encoded bundle
+ std::string m_theme;
+ JSGlobalContextRef m_context;
+
+ void setPropertyToWindow(const char* propertyName, JSValueRef jsValue);
+ void setPropertyToNavigator(const char* propertyName, JSValueRef jsValue);
+};
+
+} // namespace PluginModule
+
+#endif // _PLUGIN_LOGIC_PROPERTY_SUPPORT_H_
#
set(TARGET_NAME "wrt-plugins-w3c-widget-interface")
-pkg_search_module(webkit REQUIRED ewebkit>=0.1.0)
-pkg_search_module(wrt-plugin-api REQUIRED wrt-plugin-api>=0.7.0)
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
set(SRCS
${SRCS_COMMONS}
JSWidget.cpp
JSPreferences.cpp
- JSStorageEvent.cpp
plugin_initializer.cpp
- IFrameSupport.cpp
- AddEventListenerSupport.cpp
+ plugin_config.cpp
)
-IF(W3C_TEST)
-set(SRCS
- ${SRCS}
- JSTest.cpp
- Test.cpp
-)
-ENDIF(W3C_TEST)
-
-include_directories( ${API_WIDGET_PATH}
+include_directories(
+ ${API_WIDGET_PATH}
+ ${webkit2_INCLUDE_DIRS}
+ ${plugin-types_INCLUDE_DIRS}
# ${API_STORAGE_EVENT_PATH}
# ${API_LOCALSTORAGE_PATH}
- ${webkit_INCLUDE_DIRS}
- ${wrt-plugin-api_INCLUDE_DIRS}
)
add_library(${TARGET_NAME} SHARED ${SRCS})
${LIBS_COMMON}
${TARGET_COMMONS}
${TARGET_COMMONS_JAVASCRIPT}
+ ${TARGET_JS_OVERLAY}
wrt-plugins-widget
wrt-plugins-localstorage
wrt-plugins-storageevent
)
INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${STANDARD_FILE_DESTINATION}/w3c-widget-interface)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${STANDARD_FILE_DESTINATION}/w3c-widget-interface)
#include <CommonsJavaScript/JSDOMExceptionFactory.h>
#include <StorageEvent/StorageEventMgr.h>
#include <StorageEvent/IStorageEvent.h>
-#include "IFrameSupport.h"
-#include "AddEventListenerSupport.h"
+#include <js-overlay/js_iframe_support.h>
+#include <js-overlay/js_overlay_addEventListener.h>
using namespace std;
using namespace WrtDeviceApis;
void JSPreferences::initialize(JSContextRef context,
JSObjectRef object)
{
- LogDebug("entered");
-
- if( !AddEventListenerSupport::isInitialized())
- {
- AddEventListenerSupport::initializeContext(context);
- }
+ LogDebug("entered. Context: " << context);
LocalStoragePrivateData* priv =
static_cast<LocalStoragePrivateData*>(JSObjectGetPrivate(object));
Assert(iframe && "Iframe is NULL");
AddEventListenerSupport::
- CallListenersFromDifferentIFrames(iframe, event);
+ CallStorageListenersFromDifferentIFrames(iframe, event);
LogDebug("end");
return JSValueMakeNull(context);
Assert(iframe && "Iframe is NULL");
AddEventListenerSupport::
- CallListenersFromDifferentIFrames(iframe, event);
+ CallStorageListenersFromDifferentIFrames(iframe, event);
LogDebug("end");
IStorageEventPtr storageEvent = getStorageEvent();
AddEventListenerSupport::
- CallListenersFromDifferentIFrames(iframe, storageEvent);
+ CallStorageListenersFromDifferentIFrames(iframe, storageEvent);
LogDebug("end");
size_t n = converter.toSizeT(arguments[0]);
- std::string value = getIStorage(thisObject)->getValueByIndex(n);
+ std::string value = getIStorage(thisObject)->getKeyByIndex(n);
LogDebug("end");
Assert(iframe && "Iframe is NULL");
AddEventListenerSupport::
- CallListenersFromDifferentIFrames(iframe, event);
+ CallStorageListenersFromDifferentIFrames(iframe, event);
LogDebug("end");
+++ /dev/null
-/*
- * 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 JSTest.cpp
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- * @version 0.1
- */
-
-#include <dpl/log/log.h>
-#include <dpl/assert.h>
-#include <CommonsJavaScript/Converter.h>
-#include <Commons/Exception.h>
-#include "JSTest.h"
-#include "Test.h"
-
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-#define CLASS_NAME "Test"
-
-namespace WrtPlugins {
-namespace W3C {
-
-JSClassDefinition JSTest::m_classInfo =
-{
- 0,
- kJSClassAttributeNone,
- CLASS_NAME,
- 0,
- NULL,
- m_functions,
- initialize,
- finalize,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-JSStaticFunction JSTest::m_functions[] = {
- { "setEvaluator", JSTest::setEvaluator, kJSPropertyAttributeNone },
- { "run", JSTest::run, kJSPropertyAttributeNone },
- { 0, 0, 0 }
-};
-
-const JSClassRef JSTest::getClassRef() {
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-const JSClassDefinition* JSTest::getClassInfo() {
- return &m_classInfo;
-}
-
-JSClassRef JSTest::m_jsClassRef = JSClassCreate(JSTest::getClassInfo());
-
-void JSTest::initialize(JSContextRef context, JSObjectRef object) {
- LogDebug("ENTER");
-
- Test* priv = static_cast<Test*>(JSObjectGetPrivate(object));
- if (!priv) {
- priv = new Test();
- JSObjectSetPrivate(object, static_cast<void*>(priv));
- }
- priv->setContext(context);
-}
-
-void JSTest::finalize(JSObjectRef object) {
- LogDebug("ENTER");
- delete static_cast<Test*>(JSObjectGetPrivate(object));
-}
-
-JSValueRef JSTest::setEvaluator(JSContextRef context,
- JSObjectRef object,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- LogDebug("ENTER");
-
- Assert(argumentCount >= 1 && "Not enough arguments.");
-
- try {
- JSObjectRef evaluator = CommonsJavaScript::Converter(context).toJSObjectRef(arguments[0]);
- getPrivateObject(thisObject)->setEvaluator(evaluator);
- }
- catch (const Commons::Exception& ex) {
- LogError("Exception: " << ex.DumpToString());
- }
-
- return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSTest::run(JSContextRef context,
- JSObjectRef object,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
-{
- LogDebug("ENTER");
-
- try {
- double timeout = 0.0;
- if (argumentCount >= 1) {
- timeout = CommonsJavaScript::Converter(context).toDouble(arguments[0]);
- }
-
- getPrivateObject(thisObject)->run(timeout);
- }
- catch (const Commons::Exception& ex) {
- LogError("Exception: " << ex.DumpToString());
- }
-
- return JSValueMakeUndefined(context);
-}
-
-Test* JSTest::getPrivateObject(JSObjectRef thisObject) {
- Test* priv = static_cast<Test*>(JSObjectGetPrivate(thisObject));
- Assert(priv && "Private object not available.");
-
- return priv;
-}
-
-}
-}
+++ /dev/null
-/*
- * 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 JSTest.h
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- * @version 0.1
- * @brief
- */
-
-#ifndef WRT_PLUGIN_JS_WIDGET_TEST_H_
-#define WRT_PLUGIN_JS_WIDGET_TEST_H_
-
-#include <JavaScriptCore/JavaScript.h>
-
-namespace WrtPlugins {
-namespace W3C {
-
-class Test;
-
-class JSTest {
- public:
- static const JSClassRef getClassRef();
-
- static const JSClassDefinition* getClassInfo();
-
- private:
- static void initialize(JSContextRef context, JSObjectRef object);
-
- static void finalize(JSObjectRef object);
-
- static JSClassDefinition m_classInfo;
-
- static JSStaticFunction m_functions[];
-
- static JSClassRef m_jsClassRef;
-
- static JSValueRef setEvaluator(JSContextRef context,
- JSObjectRef object,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static JSValueRef run(JSContextRef context,
- JSObjectRef object,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception);
-
- static Test* getPrivateObject(JSObjectRef thisObject);
-};
-
-}
-}
-
-#endif
#include <CommonsJavaScript/JSDOMExceptionFactory.h>
#include "JSPreferences.h"
#include <Widget/IWidget.h>
-#include "IFrameSupport.h"
#include <LocalStorage/LocalStorageMgr.h>
#include <Commons/WrtAccess/WrtAccess.h>
+#include <js-overlay/js_iframe_support.h>
#define CATCH_EXCEPTION_NO_MODIFABLE \
NULL, //DeleteProperty,
NULL, //GetPropertyNames,
NULL, //CallAsFunction,
- NULL, //CallAsConstructor,
+ callAsConstructor,
NULL, //HasInstance,
NULL, //ConvertToType,
};
JSClassRef JSWidget::m_jsClassRef = JSClassCreate(JSWidget::getClassInfo());
+JSContextRef JSWidget::m_globalContext = NULL;
+
void JSWidget::initialize(JSContextRef context,
JSObjectRef object)
{
- LogDebug("entered");
- LogError("object " << object);
+ LogDebug("entered. Context : " << context);
+ LogDebug("Object: " << object);
JSWidgetPrivateObject* priv =
static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
JSWidgetPrivateObject* priv =
static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
- JSValueUnprotect(priv->getContext(), priv->getObject()->preferencesObject);
+ JSValueUnprotect(priv->getContext(),
+ priv->getObject()->preferencesObject);
delete priv;
- LogDebug("private object is realised");
+ LogDebug("private object is released");
+}
+
+void JSWidget::acquireGlobalContext(java_script_context_t global_context,
+ js_object_instance_t iframe,
+ js_object_instance_t object)
+{
+ IFrameSupport::RegisterWidget(global_context, iframe, object);
+ if (!m_globalContext) {
+ m_globalContext = static_cast<JSContextRef>(global_context);
+ LogInfo("Global context acquired.");
+ } else {
+ LogInfo("Global context already set.");
+ }
}
JSValueRef JSWidget::getAuthor(JSContextRef context,
{
Try {
Converter converter(context);
- return converter.toJSValueRef(getIWidget(object)->getHeight());
+ unsigned int height = getIWidget(object)->getHeight();
+ if (0 == height) {
+ height = 1;
+ }
+ return converter.toJSValueRef(height);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
{
Try {
Converter converter(context);
- return converter.toJSValueRef(getIWidget(object)->getWidth());
+ unsigned int width = getIWidget(object)->getWidth();
+ if (0 == width) {
+ width = 1;
+ }
+ return converter.toJSValueRef(width);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
Converter converter(context);
std::string key = converter.toString(propertyName);
- if(key=="preferences"){
+ if (key == "preferences") {
return true;
}
}
Catch(Commons::PlatformException){
LogError("PlatformException occured");
}
-
return false;
}
{
LogDebug("Object: " << object);
- Try{
+ Try {
Converter converter(context);
std::string key = converter.toString(propertyName);
- if(key=="preferences"){
+ if (key=="preferences") {
Converter converter(context);
JSObjectRef pref = getPreferences(object);
if (!pref)
return false;
}
+JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("widget constructor");
+ if (!m_globalContext) {
+ LogError("Global context not set. Creating 'widget' object with "
+ "local context!");
+ return JSObjectMake(context, JSWidget::getClassRef(), NULL);
+ }
+ return JSObjectMake(m_globalContext, JSWidget::getClassRef(), NULL);
+}
+
#undef CATCH_EXCEPTION_NO_MODIFABLE
#undef CATCH_EXCEPTION_CONVERSION
#undef CATCH_EXCEPTION_NULL_PTR
#include <JavaScriptCore/JavaScript.h>
#include <CommonsJavaScript/PrivateObject.h>
+#include <wrt_plugin_export.h>
namespace WrtPlugins {
namespace W3C {
*/
static const JSClassDefinition* getClassInfo();
+ static JSObjectRef callAsConstructor(JSContextRef context,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
+ /**
+ * This function will acquire global context which is used later to
+ * keep JSValueProtect/Unprotect functionality working.
+ * This is workaround for JSCore semantic: when an object is created with
+ * JSObjectMakeConstructor a context passed to createCallback function
+ * is different (shorter lifecycle) than global context, so JSValueUnprotect
+ * called in finalize may fail because of invalid context.
+ */
+ static void acquireGlobalContext(java_script_context_t global_context,
+ js_object_instance_t iframe,
+ js_object_instance_t object);
+
private:
/**
* The callback invoked when an object is first created.
static JSClassRef m_jsClassRef;
+ /**
+ * Global context acquired by acquireGlobalContext() function.
+ */
+ static JSContextRef m_globalContext;
+
// getters for properties
static JSValueRef getAuthor(JSContextRef context,
JSObjectRef object,
JSStringRef propertyName,
JSValueRef value,
JSValueRef* exception);
+
};
}
}
+++ /dev/null
-/*
- * 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 Test.cpp
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- * @version 1.0
- * @date 09/13/2011 08:31:09 AM
- * @brief
- */
-
-#include <unistd.h>
-#include <signal.h>
-#include <cstdlib>
-#include <cstdio>
-#include <dpl/log/log.h>
-#include <dpl/assert.h>
-#include <JavaScriptCore/JavaScript.h>
-#include <Commons/WrtWrapper/WrtWrappersMgr.h>
-#include <WidgetDB/WidgetDBMgr.h>
-#include <WidgetDB/IWidgetDB.h>
-#include "Test.h"
-
-using namespace WrtDeviceApis;
-//using namespace WrtDeviceApis::Commons;
-//using namespace WrtDeviceApis::CommonsJavaScript;
-
-namespace WrtPlugins {
-namespace W3C {
-
-Test::Test()
- : m_context(NULL),
- m_evaluator(NULL)
-{
- DPL::Event::ControllerEventHandler<FinishEvent>::Touch();
-}
-
-void Test::run(double timeout) {
- PostTimedEvent(FinishEvent(), timeout);
-}
-
-void Test::setEvaluator(JSObjectRef evaluator) {
- m_evaluator = evaluator;
-}
-
-void Test::setContext(JSContextRef context) {
- m_context = context;
-}
-
-void Test::OnEventReceived(const FinishEvent& event) {
- LogDebug("ENTER");
-
- Result result = Result::Success;
- if (m_evaluator && m_context) {
- JSValueRef eval = JSObjectCallAsFunction(m_context,
- m_evaluator,
- NULL,
- 0,
- NULL,
- NULL);
- if (eval) {
- if (JSValueIsBoolean(m_context, eval)) {
- if (!JSValueToBoolean(m_context, eval)) {
- result = Result::Fail;
- }
- }
- else {
- LogError("Evaluator returned value of wrong type.");
- result = Result::Exception;
- }
- }
- else {
- LogError("Evaluator did not return any value.");
- result = Result::Exception;
- }
- }
-
-
- FILE* output = fdopen(4, "w");
- if (output) {
- Commons::IWrtWrapperPtr wrt =
- Commons::WrtWrappersMgr::getInstance().getWrtWrapper(m_context);
- WidgetDB::Api::IWidgetDBPtr widgetDB =
- WidgetDB::Api::getWidgetDB(wrt->getWidgetId());
-
- fprintf(output,
- "%d\t%s\t%s\n",
- wrt->getWidgetId(),
- widgetDB->getConfigValue(
- WidgetDB::Api::ConfigAttribute::NAME).c_str(),
- resultToString(result).c_str());
- fclose(output);
- } else {
- LogInfo("Output descriptor not created.");
- }
-
- pid_t pid = getpid();
- LogDebug("Sending SIGINT to " << pid);
- if (kill(pid, SIGINT) != 0) {
- LogError("Sending SIGINT failed.");
- }
-}
-
-std::string Test::resultToString(Result result) {
- switch (result) {
- case Result::Success: return "OK";
- case Result::Fail: return "FAIL";
- case Result::Exception: return "EXCEPTION";
- default:
- Assert(false && "Unsupported result type.");
- }
-}
-
-}
-}
+++ /dev/null
-/*
- * 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 Test.h
- * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
- * @version 1.0
- * @date 09/13/2011 08:24:44 AM
- * @brief
- */
-
-#ifndef WRTPLUGINS_W3C_TEST_H_
-#define WRTPLUGINS_W3C_TEST_H_
-
-#include <string>
-#include <dpl/generic_event.h>
-#include <dpl/event/controller.h>
-#include <dpl/type_list.h>
-#include <JavaScriptCore/JavaScript.h>
-
-namespace WrtPlugins {
-namespace W3C {
-
-DECLARE_GENERIC_EVENT_0(FinishEvent)
-
-class Test : public DPL::Event::Controller<DPL::TypeListDecl<FinishEvent>::Type> {
- public:
- Test();
-
- void run(double timeout = 0.0);
- void setEvaluator(JSObjectRef evaluator);
- void setContext(JSContextRef context);
-
- protected:
- void OnEventReceived(const FinishEvent& event);
-
- private:
- enum class Result {
- Success,
- Fail,
- Exception
- };
-
- private:
- std::string resultToString(Result result);
-
- private:
- JSContextRef m_context;
- JSObjectRef m_evaluator;
-};
-
-}
-}
-#endif
+++ /dev/null
-<?xml version="1.0" ?>
-<!DOCTYPE plugin-properties SYSTEM "/usr/etc/wrt-plugins/config.dtd">
-<plugin-properties>
- <library-name>libwrt-plugins-w3c-widget-interface.so</library-name>
- <feature-install-uri>xxx</feature-install-uri>
- <feature-key-cn>SAMSUNG plugin group</feature-key-cn>
- <feature-root-cn>SAMSUNG certificate authority</feature-root-cn>
- <feature-root-fingerprint>AAAABBBBCCCCDDDEEEE0000</feature-root-fingerprint>
-
- <api-feature>
- <name>http://w3cWidgetInterface.com/w3c-widget-interface</name>
- <Object name="widget">
- </Object>
- <Object name="preferences">
- <Function name="setItem" />
- <Function name="getItem" />
- <Function name="removeItem" />
- <Function name="clear" />
- <Function name="key" />
- </Object>
- </api-feature>
-
-</plugin-properties>
-
--- /dev/null
+/*
+ * 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.
+ */
+#include "plugin_config.h"
+
+namespace WrtPlugins {
+namespace W3C {
+
+template <>
+WidgetDeclarations::ParamsMap WidgetDeclarations::m_params =
+ WrtPlugins::W3C::WidgetDeclarations::ParamsMap();
+
+template <>
+WidgetDeclarations::DeviceCapsMaps WidgetDeclarations::m_deviceCaps =
+ WrtPlugins::W3C::WidgetDeclarations::DeviceCapsMaps();
+
+
+template <>
+WidgetDeclarations::FeaturesMap WidgetDeclarations::m_features =
+{
+ {
+ "http://w3cWidgetInterface.com/w3c-widget-interface",
+ {
+ }
+ }
+};
+
+template <>
+WidgetDeclarations::FunctionsMap WidgetDeclarations::m_functions =
+ WrtPlugins::W3C::WidgetDeclarations::FunctionsMap();
+
+} // namespace Wac2_0
+} // namespace WrtPlugins
--- /dev/null
+/*
+ * 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.
+ */
+#ifndef _WIDGET_PLUGIN_CONFIG_H_
+#define _WIDGET_PLUGIN_CONFIG_H_
+
+#include <Security/StaticDeclaration.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+enum class WidgetParamId {
+};
+
+enum class WidgetDeviceCapId {
+};
+
+enum class WidgetFunctionId {
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::StaticDeclarations <
+ WidgetParamId,
+ WidgetDeviceCapId,
+ WidgetFunctionId> WidgetDeclarations;
+
+}
+}
+
+#endif // _WIDGET_PLUGIN_CONFIG_H_
#include <Commons/plugin_initializer_def.h>
#include <Commons/WrtAccess/WrtAccess.h>
+#include <js-overlay/js_overlay_addEventListener.h>
+#include <js-overlay/js_iframe_support.h>
#include "JSWidget.h"
#include "JSPreferences.h"
-#include "JSTest.h"
-#include "IFrameSupport.h"
-#include "AddEventListenerSupport.h"
+#include "plugin_config.h"
#define OBJECT_WIDGET "widget"
+#define INTERFACE_WIDGET_NAME "Widget"
#define OBJECT_PREFERENCES "preferences"
-#define OBJECT_TEST "__test"
using namespace WrtPlugins::W3C;
using namespace WrtDeviceApis;
ALWAYS_NOTICE,
USE_OVERLAYED, //ignored
IFrameSupport::RegisterWidget,
+ NULL,
NULL
};
-class_definition_options_t AddEventListenerOptions =
+class_definition_options_t WidgetInterfaceOptions =
{
- JS_FUNCTION,
+ JS_INTERFACE,
CREATE_INSTANCE,
ALWAYS_NOTICE,
- OVERLAYED_BEFORE_ORIGINAL,
- IFrameSupport::RegisterAddEventListener,
+ USE_OVERLAYED, //ignored
+ JSWidget::acquireGlobalContext,
+ NULL,
NULL
};
};
+void on_widget_init_callback(feature_mapping_interface_t *mapping)
+{
+ LogDebug("[W3C\\widget] on_widget_init_callback");
+
+ WrtPlugins::W3C::WidgetDeclarations::getMappingInterface(mapping);
+}
+
void on_widget_start_callback(int widgetId)
{
LogDebug("[W3C\\widget] on_widget_start_callback (" << widgetId << ")");
PLUGIN_ON_WIDGET_START(on_widget_start_callback)
PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
PLUGIN_CLASS_MAP_BEGIN
-PLUGIN_CLASS_MAP_ADD_CLASS (WRT_JS_EXTENSION_OBJECT_GLOBAL,
+PLUGIN_CLASS_MAP_ADD_INTERFACE(
+ WRT_JS_EXTENSION_OBJECT_GLOBAL,
+ INTERFACE_WIDGET_NAME,
+ (js_class_template_getter)WrtPlugins::W3C::JSWidget::getClassRef,
+ reinterpret_cast<js_class_constructor_cb_t>(WrtPlugins::W3C::JSWidget::callAsConstructor),
+ &Options::WidgetInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(
+ WRT_JS_EXTENSION_OBJECT_GLOBAL,
+ OBJECT_WIDGET,
+ INTERFACE_WIDGET_NAME,
+ &Options::WidgetOptions)
+
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_GLOBAL,
OBJECT_WIDGET,
- WrtPlugins::W3C::JSWidget::getClassRef(),
+ (js_class_template_getter)WrtPlugins::W3C::JSWidget::getClassRef,
&Options::WidgetOptions)
-//PLUGIN_CLASS_MAP_ADD_CLASS(OBJECT_WIDGET,
-// OBJECT_PREFERENCES,
-// WrtPlugins::W3C::JSPreferences::getClassRef(),
-// NULL)
-//Function::AddEventListener
-PLUGIN_CLASS_MAP_ADD_CLASS (WRT_JS_EXTENSION_OBJECT_GLOBAL,
- "addEventListener",
- (const void*)
- AddEventListenerSupport::AddEventListener,
- &Options::AddEventListenerOptions)
-#ifdef W3C_TEST
-PLUGIN_CLASS_MAP_ADD_CLASS(OBJECT_WIDGET,
- OBJECT_TEST,
- WrtPlugins::W3C::JSTest::getClassRef(),
- NULL)
-#endif // W3C_TEST
PLUGIN_CLASS_MAP_END
#undef OBJECT_WIDGET