--- /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.
+#
+cmake_minimum_required(VERSION 2.6)
+
+IF("${CMAKE_PROJECT_NAME}" STREQUAL "")
+ SET(CMAKE_PROJECT_NAME wrt-plugins-common)
+ENDIF("${CMAKE_PROJECT_NAME}" STREQUAL "")
+
+set(PACKAGE_NAME ${CMAKE_PROJECT_NAME})
+
+project(${CMAKE_PROJECT_NAME})
+
+################################################################################
+# Required platform modules
+
+include(FindPkgConfig)
+
+pkg_search_module(dpl REQUIRED dpl-efl>=1.0.0)
+
+include_directories(
+ ${dpl_INCLUDE_DIRS}
+)
+
+
+#
+# Logs
+#
+OPTION(DPL_LOG "DPL logs status" ON)
+
+IF(DPL_LOG)
+ MESSAGE(STATUS "Logging enabled for DPL")
+ ADD_DEFINITIONS("-DDPL_LOGS_ENABLED")
+ELSE(DPL_LOG)
+ MESSAGE(STATUS "Logging disabled for DPL")
+ENDIF(DPL_LOG)
+
+
+###############################################################################
+# Set build type (Release by default)
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE Release)
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+
+##############################################################################
+# Compiler flags
+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")
+####
+
+ADD_DEFINITIONS("-fvisibility=default") # mark all exported symbols as visible
+ADD_DEFINITIONS("-DEXPORT_API=")
+ADD_DEFINITIONS("-Wall")
+ADD_DEFINITIONS("-Werror")
+ADD_DEFINITIONS("-Wextra")
+ADD_DEFINITIONS("-Wno-deprecated")
+
+#disable default singleton implementation
+ADD_DEFINITIONS("-DSEPARATED_SINGLETON_IMPLEMENTATION")
+
+################################################################################
+# Miscellaneous variables
+
+set(CONFIG_FILE_NAME "config.cmake")
+set(LIBS_COMMONS ${dpl_LDFLAGS} )
+
+set(DESTINATION_LIB_PREFIX lib)
+set(DESTINATION_HEADER_PREFIX include/${PROJECT_NAME})
+
+set(DESTINATION_HEADERS_NON_JS ${DESTINATION_HEADER_PREFIX}/Commons)
+set(DESTINATION_HEADERS_JS ${DESTINATION_HEADER_PREFIX}/CommonsJavaScript)
+
+################################################################################
+# Target platform
+
+if (NOT DEFINED PLATFORM)
+ set(PLATFORM "tizen")
+endif ()
+
+################################################################################
+# Macros used for including plugins from AL.
+
+
+function(add_subdir NAME)
+ message(STATUS "Building: ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}")
+ add_subdirectory(${NAME})
+endfunction()
+
+################################################################################
+# Subdirectories
+
+add_subdirectory(src)
+add_subdirectory(tests)
+
+################################################################################
+# PKGCONFIG
+
+set(PKGCONFIG_DIR ${PROJECT_SOURCE_DIR}/pkgconfigs)
+
+macro(configure_and_install_pkg PKG_FILE)
+ CONFIGURE_FILE(${PKGCONFIG_DIR}/${PKG_FILE}.in
+ ${PKGCONFIG_DIR}/${PKG_FILE} @ONLY)
+ INSTALL(FILES ${PKGCONFIG_DIR}/${PKG_FILE} DESTINATION lib/pkgconfig)
+endmacro(configure_and_install_pkg)
+
+configure_and_install_pkg(wrt-plugins-commons-javascript.pc)
+configure_and_install_pkg(wrt-plugins-commons.pc)
+configure_and_install_pkg(wrt-plugins-filesystem.pc)
+configure_and_install_pkg(wrt-plugins-camera.pc)
+configure_and_install_pkg(wrt-plugins-messaging.pc)
+configure_and_install_pkg(wrt-plugins-calendar.pc)
+configure_and_install_pkg(wrt-plugins-haptics.pc)
+configure_and_install_pkg(wrt-plugins-contact.pc)
+configure_and_install_pkg(wrt-plugins-mmplayer.pc)
+configure_and_install_pkg(wrt-plugins-widget.pc)
+configure_and_install_pkg(wrt-plugins-cpu.pc)
+configure_and_install_pkg(wrt-plugins-accelerometer.pc)
+configure_and_install_pkg(wrt-plugins-task.pc)
+configure_and_install_pkg(wrt-plugins-orientation.pc)
+configure_and_install_pkg(wrt-plugins-radio.pc)
+configure_and_install_pkg(wrt-plugins-power.pc)
+configure_and_install_pkg(wrt-plugins-profile.pc)
+configure_and_install_pkg(wrt-plugins-localstorage.pc)
+configure_and_install_pkg(wrt-plugins-systeminfo.pc)
+configure_and_install_pkg(wrt-plugins-widget_interface_dao.pc)
+configure_and_install_pkg(wrt-plugins-storageevent.pc)
+configure_and_install_pkg(wrt-plugins-widgetdb.pc)
+configure_and_install_pkg(wrt-plugins-plugin-manager.pc)
+
+################################################################################
+# Cache
+
+set(PLATFORM "${PLATFORM}" CACHE STRING "Target platform" FORCE)
+set(CMAKE_CONFIG_FILE_NAME "${CMAKE_CONFIG_FILE_NAME}" CACHE
+ STRING "CMake configuration file name." FORCE)
+
+
+################################################################################
+# Summary
+
+message(STATUS "PLATFORM = ${PLATFORM}")
--- /dev/null
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
--- /dev/null
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
\ No newline at end of file
--- /dev/null
+#!/bin/bash
+
+echo Performing clean
+
+function clean {
+ rm -rf CMakeCache.txt
+ rm -rf CMakeFiles
+ rm -rf cmake_install.cmake
+ rm -rf Makefile
+ rm -rf install_manifest.txt
+
+ for i in `ls`; do
+ if [ -d $i ]; then
+ cd $i;
+ clean;
+ cd ..
+ fi
+ done
+ }
+
+ clean
+
+
+
--- /dev/null
+Debian folder (rules, control etc.)
--- /dev/null
+The Debian Package wrt-plugins-common
+----------------------------
+
--- /dev/null
+wrt-plugins-common (0.3.15) unstable; urgency=low
+
+ * Boilerplate update
+
+ * Git : tizen2/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.15
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com> Thu, 23 Feb 2012 16:16:14 +0900
+
+wrt-plugins-common (0.3.14) unstable; urgency=low
+
+ * debianize
+
+ * Git : tizen2/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.14
+
+ -- Yunchan Cho <yunchan.cho@samsung.com> Wed, 22 Feb 2012 17:06:07 +0900
+
+wrt-plugins-common (0.3.13) unstable; urgency=low
+
+ * Updated wrt-plugins-common version
+
+ * Git : tizen2/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.13
+
+ -- Hoseon LEE <hoseon46.lee@samsung.com> Wed, 22 Feb 2012 15:13:13 +0900
+
+wrt-plugins-common (0.3.12) unstable; urgency=low
+
+ * Init changelog
+
+ * Git : tizen2/pkgs/w/wrt-plugins-common
+ * Tag : wrt-plugins-common_0.3.12
+
+ -- Hoseon LEE <hoseon46.lee@samsung.com> Wed, 15 Feb 2012 17:56:14 +0900
--- /dev/null
+Source: wrt-plugins-common
+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.6), libwebkit-engine-dev, wrt-commons-dev (>=0.2.6), libmm-player-dev, libmm-sound-dev, libpcre-dev, libdbus-1-dev, libslp-sensor-dev, email-service-dev, libslp-msg-service-dev (>=0.5.0), libslp-calendar-dev, libglib2.0-dev, capi-telephony-network-info-dev, libdevman-dev, libcontacts-service-dev, libdownload-agent-dev, libvconf-dev, libslp-pm-dev, iniparser-dev, libslp-tapi-dev
+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 (>=0.8.6)
+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
+Description: Common modules for creation JavaScript's plugins -dev
+
+Package: wrt-plugins-common-dbg
+Architecture: any
+Section: debug
+Depends: ${shlibs:Depends}, ${misc:Depends}, wrt-plugins-common (= ${Source-Version})
+Description: Common modules for creation JavaScript's plugins - debug
--- /dev/null
+usr/bin
+usr/sbin
--- /dev/null
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+
+# These are used for cross-compiling and for saving the configure script
+# from having to guess our platform (since we know it already)
+DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+PACKAGE_VERSION ?= $(shell sed -n "1 p" debian/changelog | sed 's/.*(\(.*\)).*/\1/')
+PACKAGE_API_VERSION ?= $(shell sed -n "1 p" debian/changelog | sed 's/.*([0-9]*.\([0-9]*\).*).*/\1/')
+PROJECT_NAME ?= wrt-plugins-common
+
+CFLAGS ?= -Wall -g -fvisibility=default -fPIC
+CXXFLAGS ?= -Wall -g -fPIC
+PREFIX ?= /usr
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+ CXXFLAGS += -O0
+else
+ CFLAGS += -O2
+ CXXFLAGS += -O2
+endif
+
+ifeq (,$(findstring no,$(DPL_LOG)))
+ DPL_LOGS_STATUS = "ON"
+else
+ DPL_LOGS_STATUS = "OFF"
+endif
+
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -Wl,--hash-style=both -Wl,--version-script=$(CURDIR)/wrt-plugins-common.map
+
+ifdef DEVPKG
+ CMAKEFLAGS += -DDEVPKG="$(DEVPKG)"
+endif
+
+
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build
+
+#configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ # Add here commands to configure the package.
+ mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && \
+ CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
+ cmake ${SRCDIR} \
+ ${CMAKEFLAGS}\
+ -DBUILD_TYPE="${TARGET}" \
+ -DCMAKE_INSTALL_PREFIX="${PREFIX}" \
+ -DCMAKE_BUILD_TYPE="$(BUILD_TYPE)" \
+ -DCMAKE_PACKAGE_VERSION="$(PACKAGE_API_VERSION)" \
+ -DCMAKE_PROJECT_NAME="$(PROJECT_NAME)" \
+ -DDPL_LOG=$(DPL_LOGS_STATUS) ..
+
+build: build-stamp
+
+build-stamp: configure-stamp
+ dh_testdir
+
+ # Add here commands to compile the package.
+ cd $(CMAKE_BUILD_DIR) && $(MAKE) -j5
+
+ #docbook-to-man debian/ncurses.sgml > ncurses.1
+
+ for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+ cat $$f > $${f%.in}; \
+ sed -i -e "s#@PREFIX@#$(PREFIX)/lib#g" $${f%.in}; \
+ sed -i -e "s#@PREFIX_INCLUDE@#$(PREFIX)/include#g" $${f%.in}; \
+ done
+
+ for f in `find $(CURDIR)/pkgconfigs/ -name "*.in"`; do \
+ cat $$f > $${f%.in}; \
+ sed -i -e "s#@VERSION@#$(PACKAGE_VERSION)#g" $${f%.in}; \
+ sed -i -e "s#@PROJECT_NAME@#$(PROJECT_NAME)#g" $${f%.in}; \
+ done
+
+
+ touch $@
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+ rm -rf $(CMAKE_BUILD_DIR)
+# -$(MAKE) distclean
+ ./clean.sh
+
+ifneq "$(wildcard /usr/share/misc/config.sub)" ""
+ cp -f /usr/share/misc/config.sub config.sub
+endif
+ifneq "$(wildcard /usr/share/misc/config.guess)" ""
+ cp -f /usr/share/misc/config.guess config.guess
+endif
+
+ for f in `find $(CURDIR)/ -name "*.pc"`; do \
+ rm -f $${f%.pc}; \
+ done
+
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/ncurses.
+ cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_install --sourcedir=debian/tmp
+# dh_installmenu
+# dh_installdebconf
+# dh_installlogrotate
+# dh_installemacsen
+# dh_installpam
+# dh_installmime
+# dh_python
+# dh_installinit
+# dh_installcron
+# dh_installinfo
+ dh_installman
+ dh_link
+ dh_strip --dbg-package=wrt-plugins-common-dbg
+ dh_compress
+ dh_fixperms
+# dh_perl
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
--- /dev/null
+
+@PREFIX_INCLUDE@/*
--- /dev/null
+
+@PREFIX@/*
+
+/usr/share/wrt-plugins-common/widget_interface_db.sql
--- /dev/null
+#!/usr/bin/env python
+# 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.
+#
+
+import os
+import re
+
+
+def countLines(path):
+ with open(path) as f:
+ return len(f.readlines())
+
+# RETURNS: (
+# short description (string or None)
+# long decsription (array of strings or None)
+# options: stop
+def parseDescr(lines):
+ if len(lines) == 0:
+ return (None, None, False)
+ linesRest = None
+ if re.match( r"!!!options!!!", lines[0] ):
+ optStop = True
+ linesRest = lines[1:]
+ else:
+ optStop = False
+ linesRest = lines
+ if len(linesRest) == 0:
+ return(None,None,optStop)
+ short = linesRest[0].rstrip()
+ long = []
+ for l in linesRest[1:]:
+ ll = l.rstrip()
+ if re.search( r"\S", ll ):
+ long.append( ll )
+ if len(long) == 0:
+ long = None
+
+ return (short, long, optStop)
+
+# RETURNS a tree with nodes like: (
+# path (string)
+# short description (string or None)
+# long decsription (array of strings or None)
+# LOC (integer)
+# list of subdirs (child nodes like this one)
+def parseDir(path):
+ short = None
+ long = None
+ optStop = False
+ try:
+ with open( path+'/DESCRIPTION' ) as f:
+ short, long, optStop = parseDescr( f.readlines() )
+ except IOError:
+ pass
+ dirs = []
+ cntLines = 0
+ for fname in os.listdir(path):
+ if fname != '.git' and os.path.isdir(path+'/'+fname):
+ subdir = parseDir(path+'/'+fname)
+ if optStop == False:
+ dirs.append(subdir)
+ (dummy0, dummy1, dummy2, subLines, dummy4) = subdir
+ cntLines += subLines
+
+ if os.path.isfile(path+'/'+fname) \
+ and not os.path.islink(path+'/'+fname):
+ cntLines += countLines(path+'/'+fname)
+
+ return path, short, long, cntLines, dirs
+
+##### PRINT AS a sort of CSV delimited by '|'
+
+# indent is a number (0..)
+def printTabSub(tree,indent):
+ path, short, long, loc, subdirs = tree
+ p = re.sub(r"^\./", '', path)
+ m = re.search(r"/([^/]*$)", p)
+ if m != None: p = m.groups()[0]
+ if short == None:
+ print '%s%s|%d|' % (" "*indent, p, loc)
+ else:
+ print '%s%s|%d|%s' % (" "*indent, p, loc, short)
+ for dir in subdirs:
+ printTabSub(dir, indent+1)
+
+def printTab(tree):
+ printTabSub(tree,0)
+
+def printTabWoMain(tree):
+ path, short, long, loc, dirs = tree
+ for dir in dirs:
+ printTabSub(dir, 0)
+
+
+##### MAIN
+
+tree = parseDir('.')
+printTabWoMain(tree)
+
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Calendar module
+Description: WebRuntime Calendar module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-accelerometer
+Cflags: -I${includedir}/Accelerometer
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Calendar module
+Description: WebRuntime Calendar module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-calendar
+Cflags: -I${includedir}/Calendar
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Camera module
+Description: WebRuntime Camera module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-camera
+Cflags: -I${includedir}/Camera
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WrtDeviceApis commons with JavaScrpt dependencies
+Description: Commons for DeviceApis with JavaScrpt dependencies
+Version: @VERSION@
+Requires: dpl-efl ewebkit wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-commons-javascript
+Cflags: -I${includedir}
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WrtDeviceApis commons
+Description: Commons for DeviceApis
+Version: @VERSION@
+Requires: dpl-efl
+Libs: -L${libdir} -lwrt-plugins-commons
+Cflags: -I${includedir}
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Contact module
+Description: WebRuntime Contact module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-contact
+Cflags: -I${includedir}/Contact
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Cpu module
+Description: WebRuntime Cpu module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-cpu
+Cflags: -I${includedir}/Cpu
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Filesystem module
+Description: WebRuntime Filesystem module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-filesystem
+Cflags: -I${includedir}/Filesystem
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Haptics module
+Description: WebRuntime Haptics module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-haptics
+Cflags: -I${includedir}/Haptics
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis LocalStorage module
+Description: WebRuntime LocalStorage module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-localstorage
+Cflags: -I${includedir}/LocalStorage
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Messaging module
+Description: WebRuntime Messaging module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons wrt-plugins-filesystem
+Libs: -L${libdir} -lwrt-plugins-messaging
+Cflags: -I${includedir}/Messaging
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis MMPlayer module
+Description: WebRuntime MMPlayer module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-mmplayer
+Cflags: -I${includedir}/MMPlayer
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Orientation module
+Description: WebRuntime Orientation module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-orientation
+Cflags: -I${includedir}/Orientation
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Plugin Manager module
+Description: WebRuntime Plugin Manager module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons wrt-plugins-commons-javascript dpl-wrt-dao-ro ewebkit
+Libs: -L${libdir} -lwrt-plugins-plugin-manager
+Cflags: -I${includedir}/PluginManager
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Camera module
+Description: WebRuntime Camera module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-power
+Cflags: -I${includedir}/Power
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Profile module
+Description: WebRuntime Profile module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-profile
+Cflags: -I${includedir}/Profile
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Radio module
+Description: WebRuntime Radio module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-radio
+Cflags: -I${includedir}/Radio
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis StorageEvent module
+Description: WebRuntime StorageEvent module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-storageevent
+Cflags: -I${includedir}/StorageEvent
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis SystemInfo module
+Description: WebRuntime SystemInfo module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-systeminfo
+Cflags: -I${includedir}/SystemInfo
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Camera module
+Description: WebRuntime Camera module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-task -lwrt-plugins-filesystem
+Cflags: -I${includedir}/Task
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Widget module
+Description: WebRuntime Widget module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-widget
+Cflags: -I${includedir}/Widget
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Widget Interface module
+Description: WebRuntime Widget Interface module
+Version: @VERSION@
+Requires: dpl-efl dpl-db-efl wrt-plugins-commons wrt-dao-ro wrt-plugins-localstorage
+Libs: -L${libdir} -lwrt-plugins-widget-interface-dao
+Cflags: -I${includedir}/WidgetInterfaceDAO
--- /dev/null
+prefix=/usr
+project_name=@PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib/
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis WidgetDB module
+Description: WebRuntime WidgetDB module
+Version: @VERSION@
+Requires: dpl-efl wrt-plugins-commons
+Libs: -L${libdir} -lwrt-plugins-widgetdb
+Cflags: -I${includedir}/WidgetDB
--- /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.
+#
+# Includes CMake configuration file (*.cmake), preserving appropriate paths.
+macro(include_config_file INCLUDED_CONFIG_FILE_PATH)
+ get_filename_component(CURRENT_CONFIG_FILE_PATH ${CMAKE_CURRENT_LIST_FILE} PATH)
+ include(${CURRENT_CONFIG_FILE_PATH}/${INCLUDED_CONFIG_FILE_PATH}/${CONFIG_FILE_NAME} OPTIONAL)
+endmacro()
+
+# Gets actual path for CMake configuration file (*.cmake).
+# By default, if no argument is passed, current path will be set to variable
+# named CURRENT_PATH.
+# @param [Optional] Name of the variable to set with current path.
+macro(get_current_path)
+ set(VARIABLE "CURRENT_PATH")
+ if (${ARGC} GREATER 0)
+ set(VARIABLE ${ARGV0})
+ endif ()
+ get_filename_component(${VARIABLE} ${CMAKE_CURRENT_LIST_FILE} PATH)
+endmacro()
+
+set(HOST_ARCH $ENV{DEB_HOST_ARCH})
+if("${HOST_ARCH}" MATCHES "armel")
+ set(HOST_ARCH "armel")
+endif()
+
+#include directories
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/modules/API)
+
+#target names
+set(TARGET_COMMONS "wrt-plugins-commons")
+set(TARGET_COMMONS_JAVASCRIPT "wrt-plugins-commons-javascript")
+
+add_subdirectory(Commons)
+add_subdirectory(CommonsJavaScript)
+add_subdirectory(modules)
--- /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.
+ */
+/*
+ * Copyright (c) 2003-2007, Bicom Systems Ltd.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Bicom Systems Ltd nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Denis Komadaric,
+ * Bicom Systems Ltd.
+ */
+#include <ctype.h>
+#include "Exception.h"
+#include "Base64.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+const std::string Base64::chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/";
+
+bool Base64::is_base64(unsigned char c)
+{
+ return (isalnum(c) || (c == '+') || (c == '/'));
+}
+
+std::string Base64::encode(unsigned char* data,
+ std::size_t num)
+{
+ std::string ret;
+ int i = 0;
+ int j = 0;
+ unsigned char char_array_3[3];
+ unsigned char char_array_4[4];
+
+ while (num--) {
+ char_array_3[i++] = *(data++);
+ if (i == 3) {
+ char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
+ char_array_4[1] =
+ ((char_array_3[0] &
+ 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] =
+ ((char_array_3[1] &
+ 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[3] = char_array_3[2] & 0x3f;
+
+ for (i = 0; i < 4; ++i) {
+ ret += chars[char_array_4[i]];
+ }
+ i = 0;
+ }
+ }
+
+ if (i != 0) {
+ for (j = i; j < 3; ++j) {
+ char_array_3[j] = '\0';
+ }
+
+ char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
+ char_array_4[1] =
+ ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] =
+ ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[3] = char_array_3[2] & 0x3f;
+
+ for (j = 0; (j < i + 1); ++j) {
+ ret += chars[char_array_4[j]];
+ }
+
+ while ((i++ < 3)) {
+ ret += '=';
+ }
+ }
+
+ return ret;
+}
+
+std::string Base64::decode(const std::string& str)
+{
+ if (!is_base64_string(str)) {
+ ThrowMsg(InvalidArgumentException,
+ "Invalid length of base64 string.");
+ }
+ int in_len = str.size();
+ int i = 0;
+ int j = 0;
+ int in_ = 0;
+ unsigned char char_array_4[4], char_array_3[3];
+ std::string ret;
+
+ while (in_len-- && (str[in_] != '=')) {
+ if (!is_base64(str[in_])) {
+ ThrowMsg(InvalidArgumentException,
+ "Invalid characters in base64 string.");
+ }
+ char_array_4[i++] = str[in_];
+ in_++;
+ if (i == 4) {
+ for (i = 0; i < 4; ++i) {
+ char_array_4[i] = chars.find(char_array_4[i]);
+ }
+
+ char_array_3[0] =
+ (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
+ char_array_3[1] =
+ ((char_array_4[1] &
+ 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+ char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+
+ for (i = 0; i < 3; ++i) {
+ ret += char_array_3[i];
+ }
+ i = 0;
+ }
+ }
+
+ if (i != 0) {
+ for (j = i; j < 4; ++j) {
+ char_array_4[j] = 0;
+ }
+
+ for (j = 0; j < 4; ++j) {
+ char_array_4[j] = chars.find(char_array_4[j]);
+ }
+
+ char_array_3[0] =
+ (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
+ char_array_3[1] =
+ ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+ char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+
+ for (j = 0; (j < i - 1); ++j) {
+ ret += char_array_3[j];
+ }
+ }
+
+ return ret;
+}
+
+bool Base64::is_base64_string(const std::string& str)
+{
+ return ((str.size() % 4) == 0);
+}
+
+}
+} //WrtDeviceApisCommon
--- /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_COMMONS_BASE64_H_
+#define WRTDEVICEAPIS_COMMONS_BASE64_H_
+
+#include <string>
+#include <cstddef>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class Base64
+{
+ public:
+ static std::string encode(unsigned char* data,
+ std::size_t num);
+ static std::string decode(const std::string& str);
+
+ private:
+ static bool is_base64(unsigned char c);
+ static bool is_base64_string(const std::string& str);
+
+ private:
+ static const std::string chars;
+}; // Base64
+
+}
+} // WrtDeviceApisCommon
+
+#endif /* WRTDEVICEAPIS_COMMONS_BASE64_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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADERS_NON_JS})
+endmacro()
+
+macro(install_wrtwrapper_header_file HEADER_FILE)
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADERS_NON_JS}/WrtWrapper)
+endmacro()
+
+macro(install_widget_configuration_header_file HEADER_FILE)
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADERS_NON_JS}/WidgetConfiguration)
+endmacro()
+
+macro(install_widget_interface_dao_header_file HEADER_FILE)
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADERS_NON_JS}/WidgetInterfaceDAO)
+endmacro()
+
+include_config_file(WrtWrapper)
+include_config_file(WidgetConfiguration)
+
+pkg_search_module(wrt-plugin-api REQUIRED wrt-plugin-api>=0.7.0)
+pkg_search_module(wrt-ace-client REQUIRED wrt-ace-client)
+pkg_search_module(dpl-event REQUIRED dpl-event-efl)
+
+set(WRT_COMMONS_DEPENDECIES_INCLUDES
+ ${INCLUDE_JS_INDEPENDENT}
+ ${wrt-plugin-api_INCLUDE_DIRS}
+ ${wrt-ace-client_INCLUDE_DIRS}
+ )
+
+include_directories(${WRT_COMMONS_DEPENDECIES_INCLUDES})
+
+set(TARGET_NAME ${TARGET_COMMONS})
+
+set(SRCS
+ ${SRCS_WRT_WRAPPER}
+ ${SRCS_WIDGET_CONFIGURATION}
+ ${CMAKE_CURRENT_SOURCE_DIR}/Base64.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/FunctionDefinition.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Regex.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/RegexUtils.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/StringBuilder.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/StringUtils.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/ThreadPool.cpp
+ #PARENT_SCOPE
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${wrt-ace-client_LIBRARIES}
+ ${dpl-event_LIBRARIES}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX})
+
+install_header_file(FunctionDeclaration.h)
+install_header_file(FunctionDefinition.h)
+install_header_file(Base64.h)
+install_header_file(Deprecated.h)
+install_header_file(Dimension.h)
+install_header_file(Emitters.h)
+install_header_file(EventListener.h)
+install_header_file(EventReceiver.h)
+install_header_file(Exception.h)
+install_header_file(IEvent.h)
+install_header_file(IExternEventCanceler.h)
+install_header_file(ListenerEventEmitter.h)
+install_header_file(ListenerEvent.h)
+install_header_file(Range.h)
+install_header_file(Regex.h)
+install_header_file(RegexPatterns.h)
+install_header_file(RegexUtils.h)
+install_header_file(StaticAssert.h)
+install_header_file(StringBuilder.h)
+install_header_file(StringUtils.h)
+install_header_file(ThreadPool.h)
+install_header_file(TypesDeclaration.h)
+install_header_file(TypeTraits.h)
+install_header_file(plugin_initializer_def.h)
+install_wrtwrapper_header_file(WrtWrapper/IWrtCamera.h)
+install_wrtwrapper_header_file(WrtWrapper/IWrtCameraManager.h)
+install_wrtwrapper_header_file(WrtWrapper/IWrtWrapper.h)
+install_wrtwrapper_header_file(WrtWrapper/WrtWrappersMgr.h)
+install_widget_configuration_header_file(WidgetConfiguration/WidgetConfiguration.h)
+install_widget_configuration_header_file(WidgetConfiguration/ConfigurationSupport.h)
--- /dev/null
+Common code
--- /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_COMMONS_DEPRECATED_H_
+#define WRTDEVICEAPIS_COMMONS_DEPRECATED_H_
+
+#define WRT_PLUGINS_DEPRECATED __attribute__((deprecated))
+
+#endif /* WRTDEVICEAPIS_COMMONS_DEPRECATED_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)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_DIMENSION_H_
+#define WRTDEVICEAPIS_COMMONS_DIMENSION_H_
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * Encapsulates width and height of a component.
+ */
+class Dimension
+{
+ public:
+ /**
+ * Type of dimension's values.
+ */
+ typedef unsigned int ValueType;
+
+ public:
+ /**
+ * Creates an instance of Dimension with specified width and height.
+ * @param width Specified width.
+ * @param height Specified height.
+ */
+ Dimension(ValueType width,
+ ValueType height) :
+ m_width(width),
+ m_height(height)
+ {
+ }
+
+ ValueType getWidth() const
+ {
+ return m_width;
+ }
+
+ ValueType getHeight() const
+ {
+ return m_height;
+ }
+
+ void setSize(ValueType width,
+ ValueType height)
+ {
+ m_width = width;
+ m_height = height;
+ }
+
+ private:
+ ValueType m_width;
+ ValueType m_height;
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_DIMENSION_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)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_EMITTERS_H_
+#define WRTDEVICEAPIS_COMMONS_EMITTERS_H_
+
+#include <cstddef>
+#include <map>
+#include <memory>
+#include <dpl/mutex.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEventEmitter.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * Manages listener events emitters.
+ * Template parameter should be class that derives from @see ListenerEvent.
+ */
+template<class EmitterClass>
+class Emitters
+{
+ public:
+ typedef EmitterClass EmitterType;
+ typedef DPL::SharedPtr<EmitterType> EmitterPtrType;
+ typedef typename EmitterType::IdType EmitterIdType;
+ typedef typename EmitterType::EventType EventType;
+ typedef typename EmitterType::EventPtrType EventPtrType;
+ typedef std::auto_ptr<DPL::Mutex::ScopedLock> LockType;
+
+ public:
+ ~Emitters()
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ m_emitters.clear();
+ }
+
+ /**
+ * Attaches emitter.
+ * @param emitter Emitter.
+ * @remarks Thread-safe. Do not use it in the scope of getLock() result.
+ */
+ void attach(const EmitterPtrType& emitter)
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ m_emitters[emitter->getId()] = emitter;
+ }
+
+ /**
+ * Detaches emitter.
+ * @param id Id of an emitter.
+ * @return True when emitter was found and successfully detached,
+ * false otherwise.
+ * @remarks Thread-safe. Do not use it in the scope of getLock() result.
+ */
+ bool detach(const EmitterIdType id)
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ return (m_emitters.erase(id) > 0);
+ }
+
+ /**
+ * Emits event through all emitters.
+ * @param event Event to emit.
+ * @remarks Thread-safe. Do not use it in the scope of getLock() result.
+ */
+ void emit(const EventPtrType& event)
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ for (Iterator it = m_emitters.begin(); it != m_emitters.end(); ++it) {
+ it->second->emit(event);
+ }
+ }
+
+ /**
+ * Emits event through those emitters that when passed to predicate result in
+ * returning true by it.
+ * @param event Event to emit.
+ * @param pred Predicate - a callable object (function, functor) that takes
+ * an argument of type EmitterPtrType and returns boolean value.
+ */
+ template<typename Predicate>
+ void emitIf(const EventPtrType& event,
+ Predicate pred)
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ for (Iterator it = m_emitters.begin(); it != m_emitters.end(); ++it) {
+ if (bool(pred(it->second))) {
+ it->second->emit(event);
+ }
+ }
+ }
+
+ /**
+ * Checks whether emitter of supplied id is attached.
+ * @param emitter Emitter.
+ * @return True when emitter has been found, false otherwise.
+ * @remarks Can be used within scope of getLock() call.
+ */
+ bool isAttached(const EmitterIdType id) const
+ {
+ return (m_emitters.count(id) > 0);
+ }
+
+ /**
+ * Returns number of attached emitters.
+ * @return Number of emitters.
+ * @remarks Can be used within scope of getLock() call.
+ */
+ std::size_t size() const
+ {
+ return m_emitters.size();
+ }
+
+ /**
+ * Lock this object.
+ * This lock will be automatically released when out of scope (unless someone
+ * copies it). Do not use in the same scope as other API of this class.
+ * @return Lock object.
+ * @remarks Provided to allow locking emitters in scope of some client
+ * code.
+ */
+ LockType getLock()
+ {
+ return LockType(new DPL::Mutex::ScopedLock(&m_mtx));
+ }
+
+ private:
+ typedef std::map<EmitterIdType, EmitterPtrType> Map;
+ typedef typename Map::iterator Iterator;
+ typedef typename Map::const_iterator ConstIterator;
+
+ private:
+ DPL::Mutex m_mtx; ///< Synchronizes operation on this object.
+ Map m_emitters; ///< Emitters container.
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_EMITTERS_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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONS_EVENT_LISTENER_H_
+#define WRTDEVICEAPIS_COMMONS_EVENT_LISTENER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include <Commons/EventReceiver.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * Base class for listeners.
+ * Object that is to act as listener should dervie from this class and implement
+ * OnAnswerReceived() function.
+ */
+template<class TemplateEvent>
+class EventListener : private EventReceiver<TemplateEvent>
+{
+ public:
+ EventListener(ThreadEnum::Enumeration threadType) :
+ EventReceiver<TemplateEvent>(threadType)
+ {
+ }
+
+ virtual void onAnswerReceived(const DPL::SharedPtr<TemplateEvent>& event) =
+ 0;
+
+ void postAnswer(const DPL::SharedPtr<TemplateEvent>& event)
+ {
+ DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::PostEvent(
+ event);
+ }
+
+ protected:
+ void OnEventReceived(const DPL::SharedPtr<TemplateEvent> &event)
+ {
+ onAnswerReceived(event);
+ }
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif /* WRTDEVICEAPIS_COMMONS_EVENT_LISTENER_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef WRTDEVICEAPIS_COMMONS_EVENT_RECEIVER_H_
+#define WRTDEVICEAPIS_COMMONS_EVENT_RECEIVER_H_
+
+#include <assert.h>
+#include <dpl/event/thread_event_dispatcher.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/event/controller.h>
+#include <dpl/type_list.h>
+#include <dpl/event/abstract_event_call.h>
+#include <dpl/log/log.h>
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+template<class TemplateEvent>
+class SignalEventCall : public DPL::Event::AbstractEventCall
+{
+ DPL::SharedPtr<TemplateEvent> m_event;
+ public:
+
+ SignalEventCall(const DPL::SharedPtr<TemplateEvent> &event) : m_event(event)
+ {
+ }
+ virtual void Call()
+ {
+ LogDebug("signaling in SignalEventCall");
+ m_event->signalSynchronousEventFlag();
+ }
+};
+
+
+template<class TemplateEvent>
+class EventReceiver :
+ protected DPL::Event::Controller<
+ typename DPL::TypeListDecl<DPL::SharedPtr<TemplateEvent> >::Type>
+{
+ DPL::Event::ThreadEventDispatcher m_threadDispatcher;
+ protected:
+
+ EventReceiver(ThreadEnum::Enumeration threadType)
+ {
+ DPL::Thread *thread =
+ ThreadPool::getInstance().getThreadRef(threadType);
+ DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::
+ Touch();
+ DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::
+ SwitchToThread(thread);
+ }
+
+ void signalEventByDispatcher(const DPL::SharedPtr<TemplateEvent> &event)
+ {
+ LogDebug("in");
+ DPL::Event::AbstractEventDispatcher *dispatcher =
+ ThreadPool::getInstance().getDispatcher(m_threadDispatcher);
+ dispatcher->AddEventCall(new SignalEventCall<TemplateEvent>(event));
+ }
+
+ virtual ~EventReceiver()
+ {
+ DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::
+ SwitchToThread(NULL);
+ }
+};
+
+
+template<class TemplateEvent>
+class EventRequestReceiver : private EventReceiver<TemplateEvent>
+{
+ public:
+ EventRequestReceiver(ThreadEnum::Enumeration threadType) : EventReceiver<
+ TemplateEvent>(threadType)
+ {
+ }
+ virtual void OnRequestReceived(const DPL::SharedPtr<TemplateEvent> &event)
+ = 0;
+
+ /*
+ *
+ * @argument delaySeconds - event will be received not sooner than after delay (in seconds)
+ */
+ void PostRequest(const DPL::SharedPtr<TemplateEvent> &event,
+ double delaySeconds = 0.0)
+ {
+ LogDebug(__FUNCTION__);
+ {
+ DPL::Mutex::ScopedLock lock(&event->m_stateMutex);
+ assert(TemplateEvent::STATE_INITIAL == event->m_state);
+ event->m_state = TemplateEvent::STATE_REQUEST_SEND;
+ }
+ LogDebug("state changed to STATE_REQUEST_SEND. Now posting");
+
+ if (TemplateEvent::HANDLING_SYNCHRONOUS == event->getHandlingType() &&
+ !event->m_synchronousEventFlag) {
+ event->m_synchronousEventFlag = new DPL::WaitableEvent();
+ }
+
+ if (0.0 == delaySeconds) {
+ DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::
+ PostEvent(event);
+ } else {
+ DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::
+ PostTimedEvent(event, delaySeconds);
+ }
+ LogDebug("Event posted.");
+ switch (event->getHandlingType()) {
+ case TemplateEvent::HANDLING_NOT_SET:
+ assert(0);
+ break;
+ case TemplateEvent::HANDLING_SYNCHRONOUS:
+ LogDebug("It's synchronous call - waiting for answer...");
+ event->waitForAnswer();
+ LogDebug("...answer received");
+ break;
+ }
+ }
+
+ void OnEventReceived(const DPL::SharedPtr<TemplateEvent> &event)
+ {
+ LogDebug(__FUNCTION__);
+ {
+ DPL::Mutex::ScopedLock lock(&event->m_stateMutex);
+ if (event->m_cancelled) {
+ event->handleCancel();
+ event->m_cancelAllowed = true;
+ event->signalCancelStatusFlag();
+ event->signalFinishedFlag();
+ return;
+ } else {
+ assert(
+ TemplateEvent::STATE_REQUEST_SEND == event->m_state &&
+ "Wrong state!");
+ }
+ event->m_state = TemplateEvent::STATE_REQUEST_RECEIVED;
+ }
+ LogDebug("calling OnRequestReceived");
+ OnRequestReceived(event);
+ event->signalCancelStatusFlag();
+ //After Controller ends processing it should call it to signal that work is done
+ {
+ DPL::Mutex::ScopedLock lock(&event->m_stateMutex);
+
+ if (event->m_cancelled) {
+ //if cancel was not handled in OnRequestReceived when we should
+ //process as if it was not cancelled at all.
+ if (event->m_cancelAllowed) {
+ event->handleCancel();
+ event->signalFinishedFlag();
+ return;
+ }
+ }
+ //when event is not in manual answer mode we will answer now
+ if (TemplateEvent::HANDLING_ASYNCHRONOUS_MANUAL_ANSWER !=
+ event->m_handlingType &&
+ TemplateEvent::HANDLING_SYNCHRONOUS_MANUAL_ANSWER !=
+ event->m_handlingType) {
+ event->m_state = TemplateEvent::STATE_ANSWER_SEND;
+ }
+ }
+ LogDebug("choosing the answer method");
+ switch (event->m_handlingType) {
+ case TemplateEvent::HANDLING_NOT_SET:
+ assert(0);
+ break;
+ case TemplateEvent::HANDLING_SYNCHRONOUS:
+ //event->Signal();
+ signalEventByDispatcher(event);
+ break;
+ case TemplateEvent::HANDLING_ASYNCHRONOUS:
+ ///TODO check - shouldn't it be in signalEventByDispatcher?
+ if (NULL != event->m_remoteController) {
+ event->m_remoteController->PostAnswer(event);
+ }
+ //event->Signal();
+ signalEventByDispatcher(event);
+ break;
+ //when event is in manual answer mode we do nothing - the answer will be send explicit from the code
+ case TemplateEvent::HANDLING_SYNCHRONOUS_MANUAL_ANSWER:
+ case TemplateEvent::HANDLING_ASYNCHRONOUS_MANUAL_ANSWER:
+ LogDebug("Manual answer is set so do nothing.");
+ break;
+ }
+ }
+
+ virtual void ManualAnswer(const DPL::SharedPtr<TemplateEvent> &event)
+ {
+ LogDebug(__FUNCTION__);
+ assert(
+ event->m_handlingType ==
+ TemplateEvent::HANDLING_ASYNCHRONOUS_MANUAL_ANSWER ||
+ event->m_handlingType ==
+ TemplateEvent::HANDLING_SYNCHRONOUS_MANUAL_ANSWER);
+ {
+ DPL::Mutex::ScopedLock lock(&event->m_stateMutex);
+ if (event->m_cancelled) {
+ //if cancel was not handled in OnRequestReceived when we should
+ //process as if it was not cancelled at all.
+ if (event->m_cancelAllowed) {
+ event->handleCancel();
+ event->signalCancelStatusFlag();
+ event->signalFinishedFlag();
+ return;
+ }
+ }
+ event->m_state = TemplateEvent::STATE_ANSWER_SEND;
+ }
+ switch (event->m_handlingType) {
+ case TemplateEvent::HANDLING_SYNCHRONOUS_MANUAL_ANSWER:
+ //event->Signal();
+ signalEventByDispatcher(event);
+ break;
+ case TemplateEvent::HANDLING_ASYNCHRONOUS_MANUAL_ANSWER:
+ //event->Signal();
+ if (NULL != event->m_remoteController) {
+ event->m_remoteController->PostAnswer(event);
+ }
+ signalEventByDispatcher(event);
+ break;
+ default:
+ break;
+ }
+ }
+};
+
+
+template<class TemplateEvent>
+class EventAnswerReceiver : private EventReceiver<TemplateEvent>
+{
+ public:
+ EventAnswerReceiver(ThreadEnum::Enumeration threadType) : EventReceiver<
+ TemplateEvent>(threadType)
+ {
+ }
+
+ virtual void OnAnswerReceived(const DPL::SharedPtr<TemplateEvent> &event) =
+ 0;
+
+ //it should be hidden outside, but I can't do it! I can't! :|
+ void PostAnswer(const DPL::SharedPtr<TemplateEvent> &event)
+ {
+ LogDebug(__FUNCTION__);
+ event->signalCancelStatusFlag();
+ DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::PostEvent(
+ event);
+ }
+
+ void OnEventReceived(const DPL::SharedPtr<TemplateEvent> &event)
+ {
+ LogDebug("EventAnswerReceiver: answer received");
+ //check if it can be processed and set the state
+ {
+ LogDebug("checking the state");
+ DPL::Mutex::ScopedLock lock(&event->m_stateMutex);
+
+ //in case someone changed it to synchronous call, we don't process it
+ if (TemplateEvent::STATE_CHANGED_TO_SYNCHRONOUS ==
+ event->m_state || TemplateEvent::STATE_ENDED ==
+ event->m_state) {
+ LogDebug(
+ "Handling probably changed to synchronous meanwhile. Will not process it..");
+ return;
+ }
+ //we should get cancelled or answer_send state here
+ assert(
+ TemplateEvent::STATE_ANSWER_SEND == event->m_state &&
+ "Wrong state!");
+
+ if (event->m_cancelled && event->m_cancelAllowed) {
+ event->handleCancel();
+ event->signalFinishedFlag();
+ return;
+ }
+ event->m_state = TemplateEvent::STATE_ANSWER_RECEIVED;
+ }
+ LogDebug("calling OnAnswerReceived");
+ OnAnswerReceived(event);
+
+ LogDebug("changing the state");
+ {
+ DPL::Mutex::ScopedLock lock(&event->m_stateMutex);
+ assert(TemplateEvent::STATE_ANSWER_RECEIVED == event->m_state);
+ event->m_state = TemplateEvent::STATE_ENDED;
+ delete event->m_cancelStatusFlag;
+ event->m_cancelStatusFlag = NULL;
+ //if someone is waiting
+ event->signalFinishedFlag();
+ }
+ LogDebug("leaving");
+ }
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif /* WRTDEVICEAPIS_COMMONS_EVENT_RECEIVER_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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONS_EXCEPTION_H_
+#define WRTDEVICEAPIS_COMMONS_EXCEPTION_H_
+
+#include <dpl/exception.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+#define PLUGINS_DECLARE_EXCEPTION_TYPE(BaseClass, Class) \
+ class Class : \
+ public BaseClass \
+ { \
+ ExceptionCodes::Enumeration m_code; \
+ public: \
+ virtual ExceptionCodes::Enumeration getCode() const { return m_code; } \
+ Class(const char *path, \
+ const char *function, \
+ int line, \
+ const std::string & message = std::string()) : \
+ BaseClass(path, function, line, message) \
+ { \
+ BaseClass::m_className = # Class; \
+ m_code = ExceptionCodes::Class; \
+ } \
+ \
+ Class(const char *path, \
+ const char *function, \
+ int line, \
+ const DPL::Exception & reason, \
+ const std::string & message = std::string()) : \
+ BaseClass(path, function, line, reason, message) \
+ { \
+ BaseClass::m_className = # Class; \
+ m_code = ExceptionCodes::Class; \
+ } \
+ };
+
+class ExceptionCodes
+{
+ public:
+ enum Enumeration
+ {
+ None,
+ Exception,
+ InvalidArgumentException,
+ ConversionException,
+ NullPointerException,
+ UnknownException,
+ PlatformException,
+ OutOfRangeException,
+ EventCancelledException,
+ EventWrongStateException,
+ SecurityException,
+ UnsupportedException,
+ PlatformWrongStateException,
+ PendingOperationException,
+ AlreadyInUseException,
+ CameraCaptureException,
+ CameraLiveVideoException,
+ LocalStorageValueNoModifableException,
+ NotFoundException
+ };
+};
+
+/**
+ * General exception.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(DPL::Exception, Exception)
+
+/**
+ * Thrown when passed argument is not of expected type.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, InvalidArgumentException)
+
+/**
+ * Thrown when type conversion is not possible.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, ConversionException)
+
+/**
+ * Thrown when trying to operate on an object which is set to NULL.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, NullPointerException)
+
+/**
+ * Thrown when unknown error occured.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, UnknownException)
+
+/**
+ * Thrown when platform function returned error code or threw an exception.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PlatformException)
+
+/**
+ * Thrown when trying to access out of range element from array
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, OutOfRangeException)
+
+/**
+ * Thrown when trying to operate on cancelled event
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventCancelledException)
+
+/**
+ * Thrown when trying to operate on event in wrong state
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventWrongStateException)
+
+/**
+ * Thrown when trying to perform some action w/o proper permissions.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, SecurityException)
+
+/**
+ * Thrown when trying to perform action that is not supported by current platform.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, UnsupportedException)
+
+/**
+ * Thrown when trying to perform action on platform in wrong state.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PlatformWrongStateException)
+
+/**
+ * Thrown when trying to perform asynchronous action on JS object
+ * that already executes other asynchronous operation.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PendingOperationException)
+
+/**
+ * Thrown when used camera is already in use.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, AlreadyInUseException)
+
+/**
+ * Thrown when unpredicted error occurs while a picture or video is being captured
+ * or if endRecording is called while no video is currently captured.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, CameraCaptureException)
+
+/**
+ * camera live video cannot be provided.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, CameraLiveVideoException)
+
+/**
+ * Error trying to modify read only value
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, LocalStorageValueNoModifableException)
+
+/**
+ * Thrown when object is not found.
+ */
+PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, NotFoundException)
+
+}
+} // WrtDeviceApisCommon
+
+#endif /* WRTDEVICEAPIS_COMMONS_EXCEPTION_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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONS_FUNCTION_DECLARATION_
+#define WRTDEVICEAPIS_COMMONS_FUNCTION_DECLARATION_
+
+#include <string>
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <Commons/WrtWrapper/WrtWrappersMgr.h>
+#include <Commons/Exception.h>
+#include <Commons/TypesDeclaration.h>
+#include <Commons/TypeTraits.h>
+
+#define ACE_DECLARE_FUNCTION(function_definition) \
+ extern WrtDeviceApis::Commons::AceFunction ace_ ## function_definition
+
+#define ACE_DECLARE_PARAM(param_definition) \
+ extern WrtDeviceApis::Commons::AceDeviceCapParam ace_param_ ## \
+ param_definition
+
+class DevCapFinder
+{
+ public:
+ explicit DevCapFinder(const std::string& devcap) : m_searchFor(devcap)
+ {
+ }
+ explicit DevCapFinder(const char* devcap) : m_searchFor(devcap)
+ {
+ }
+ bool operator()(const WrtDeviceApis::Commons::AceDeviceCapability& dc) const
+ {
+ return m_searchFor == dc.devCapName;
+ }
+
+ private:
+ std::string m_searchFor;
+};
+
+#define ACE_ADD_DEV_CAP_PARAM(dev_caps_list, dev_cap_name, param) \
+ do { \
+ WrtDeviceApis::Commons::AceDeviceCaps::iterator devcapit = \
+ std::find_if(dev_caps_list.begin(), \
+ dev_caps_list.end(), \
+ DevCapFinder(dev_cap_name)); \
+ if (devcapit == dev_caps_list.end()) \
+ { \
+ ThrowMsg( \
+ WrtDeviceApis::Commons::InvalidArgumentException, \
+ "Trying to set a param that doesn't exist: " << \
+ dev_cap_name); \
+ } \
+ else \
+ { \
+ LogInfo("Setting dev cap " << dev_cap_name << " param: " << \
+ param.name << " to value " << param.value); \
+ devcapit->devCapParams.push_back(param); \
+ } \
+ } while (0)
+
+/*
+ * Macro must be run inside plugin function. Plugin function must follow this declaration:
+ * plugin_example_function(JScontextRef cotext, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception);
+ * where context, arguments, argumentsCount, exception are fixed and could not be change.
+ * */
+
+#define DECLARE_FUNCTION_GETTER(Plugin_Module) \
+ WrtDeviceApis::Commons::AceFunction get ## Plugin_Module ## FunctionData( \
+ const std::string & functionId);
+
+#define DEFINE_FUNCTION_GETTER(Plugin_Module, FunctionMap) \
+ WrtDeviceApis::Commons::AceFunction get ## Plugin_Module ## FunctionData( \
+ const std::string & functionId) \
+ { \
+ WrtDeviceApis::Commons::FunctionMapping::const_iterator it = \
+ FunctionMap.find(functionId); \
+ if (it == FunctionMap.end()) \
+ { \
+ std::string errorMsg(); \
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, \
+ "Function with id " << functionId << "not found"); \
+ } \
+ return it->second; \
+ }
+
+typedef WrtDeviceApis::Commons::AceFunction (&AceFunctionGetter)(const std::string&);
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+enum class AceSecurityStatus
+{
+ AccessGranted,
+ AccessDenied,
+ InternalError
+};
+
+template <typename ... Args>
+class DefaultArgsVerifier
+{
+ public:
+ void operator()(AceFunction& aceFunction, Args && ... args) const
+ {
+ static_assert(
+ WrtDeviceApis::Commons::AlwaysFalse<Args ...>::value,
+ "Please provide a specialization for these argument types!");
+ }
+};
+
+template <>
+class DefaultArgsVerifier<>
+{
+ public:
+ void operator()(AceFunction& /*aceFunction*/) const
+ {
+ }
+};
+
+template <typename FunctionGetter,
+ typename ArgumentsVerifier,
+ typename ... Args>
+AceSecurityStatus aceCheckAccess(
+ JavaScriptContext globalContext,
+ const FunctionGetter& f,
+ const char* functionName,
+ Args && ... args)
+{
+ AceFunction aceFunction = f(functionName);
+
+ ArgumentsVerifier argsVerify;
+ argsVerify(aceFunction, args ...);
+
+ IWrtWrapperPtr wrapper =
+ WrtWrappersMgr::getInstance().getWrtWrapper(globalContext);
+ if (!wrapper) {
+ LogError("Wrapper doesn't exist.");
+ return AceSecurityStatus::InternalError;
+ }
+ if (!(wrapper->checkAccess(aceFunction))) {
+ LogDebug("Function is not allowed to run");
+ return AceSecurityStatus::AccessDenied;
+ }
+ LogDebug("Function accepted!");
+
+ return AceSecurityStatus::AccessGranted;
+}
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_FUNCTION_DECLARARION_
--- /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 "FunctionDefinition.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+int aceAddDeviceCap(const AceDeviceCapability& cap,
+ AceDeviceCaps &instance)
+{
+ instance.push_back(cap);
+ return 0;
+}
+
+int aceAddApiFeature(const AceFeature& apiFeature,
+ AceFeatures& instance)
+{
+ instance.push_back(apiFeature);
+ return 0;
+}
+
+}
+} // WrtDeviceApisCommon
--- /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_COMMONS_FUNCTION_DEFINITION_
+#define WRTDEVICEAPIS_COMMONS_FUNCTION_DEFINITION_
+
+#include <map>
+#include <string>
+#include <Commons/FunctionDeclaration.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * Creates an empty device cap list. Additional device-caps may be added by
+ * ACE_CREATE_DEVICE_CAP and ACE_ADD_DEVICE_CAP macros
+ */
+#define ACE_CREATE_DEVICE_CAPS_LIST(device) \
+ WrtDeviceApis::Commons::AceDeviceCaps ace_ ## device
+
+/**
+ * Creates an empty api features list. Additional api features may be added by
+ * ACE_CREATE_FEATURE and ACE_ADD_API_FEATURE macros
+ */
+#define ACE_CREATE_FEATURE_LIST(apifeature) \
+ WrtDeviceApis::Commons::AceFeatures ace_ ## apifeature
+
+/**
+ * Creates a device capability which should be later added to device cap list
+ */
+#define ACE_CREATE_DEVICE_CAP(device_cap_id, cap_id) \
+ WrtDeviceApis::Commons::AceDeviceCapability ace_ ## device_cap_id = \
+ AceDeviceCapability(cap_id, WrtDeviceApis::Commons::AceDeviceCapParams());
+
+/**
+ * Create an api feature which should be later added to api features list
+ */
+#define ACE_CREATE_FEATURE(feature_id, feature_api) \
+ WrtDeviceApis::Commons::AceFeature ace_ ## feature_id = { feature_api };
+
+/**
+ * Adds an existing device-cap created by ACE_CREATE_DEVICE_CAP macro to
+ * device cap list
+ */
+#define ACE_ADD_DEVICE_CAP(device, device_cap_id) \
+ WrtDeviceApis::Commons::aceAddDeviceCap(ace_ ## device_cap_id, ace_ ## device)
+
+/**
+ * Adds an existing api feature created by ACE_CREATE_FEATURE macro to
+ * api feature list
+ */
+#define ACE_ADD_API_FEATURE(apifeature, feature_id) \
+ WrtDeviceApis::Commons::aceAddApiFeature(ace_ ## feature_id, \
+ ace_ ## apifeature)
+
+/**
+ * Creates a function definition with given id that uses provided api feature
+ * and device capability lists
+ */
+#define ACE_CREATE_FUNCTION(function_id, function_name, feature_id, device) \
+ { function_name, ace_ ## feature_id, ace_ ## device }
+
+// Support for param:name begin
+#define ACE_CREATE_PARAM(param_definition, param_name, position) \
+ static WrtDeviceApis::Commons::AceDeviceCapParam ace_param_ ## \
+ param_definition = \
+ { std::string(param_name), position };
+
+// Support for param:name end
+
+typedef std::map <std::string, AceFunction> FunctionMapping;
+
+int aceAddDeviceCap(const AceDeviceCapability& cap,
+ AceDeviceCaps& instance);
+int aceAddApiFeature(const AceFeature& apiFeature,
+ AceFeatures& instance);
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_FUNCTION_DEFINITION
--- /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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_IEVENT_H_
+#define WRTDEVICEAPIS_COMMONS_IEVENT_H_
+
+#include <assert.h>
+#include <dpl/event/controller.h>
+#include <dpl/mutex.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/Exception.h>
+#include <Commons/EventReceiver.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class IEventPrivateData
+{
+ public:
+ virtual ~IEventPrivateData()
+ {
+ }
+};
+
+
+class IEventController
+{
+ DPL::SharedPtr<IEventPrivateData> m_privateData;
+ public:
+ virtual void waitTillProcessed() = 0;
+ virtual void waitForAnswer() = 0;
+ virtual bool cancelRequest()
+ {
+ return false;
+ }
+ virtual bool changeCallToSynchronous() = 0;
+ virtual ~IEventController()
+ {
+ }
+
+ void setPrivateData(
+ const DPL::SharedPtr<IEventPrivateData> &privateData)
+ {
+ m_privateData = privateData;
+ }
+ const DPL::SharedPtr<IEventPrivateData>& getPrivateData()
+ {
+ return m_privateData;
+ }
+};
+typedef DPL::SharedPtr<IEventController> IEventControllerPtr;
+
+
+// CRTP pattern
+template<class Super>
+class IEvent : /*private DPL::WaitableEvent, */ public IEventController
+{
+ public:
+ friend class EventRequestReceiver<Super>;
+ friend class EventAnswerReceiver<Super>;
+ friend class SignalEventCall<Super>;
+
+ enum HandlingType
+ {
+ HANDLING_NOT_SET = -1,
+ HANDLING_SYNCHRONOUS = 0,
+ HANDLING_ASYNCHRONOUS = 1,
+ HANDLING_SYNCHRONOUS_MANUAL_ANSWER = 2,
+ HANDLING_ASYNCHRONOUS_MANUAL_ANSWER = 3
+ };
+
+ enum State
+ {
+ STATE_INITIAL,
+ STATE_REQUEST_SEND,
+ STATE_REQUEST_RECEIVED,
+ STATE_ANSWER_SEND,
+ STATE_ANSWER_RECEIVED,
+ STATE_ENDED,
+ STATE_CHANGED_TO_SYNCHRONOUS
+ };
+
+ private:
+ void handleCancel()
+ {
+ clearOnCancel();
+ m_state = STATE_ENDED;
+ m_exceptionCode = Commons::ExceptionCodes::EventCancelledException;
+ //if someone is waiting
+ signalSynchronousEventFlag();
+ }
+ protected:
+ DPL::Mutex m_stateMutex;
+ State m_state;
+ HandlingType m_handlingType;
+ EventAnswerReceiver< Super > *m_remoteController;
+ Commons::ExceptionCodes::Enumeration m_exceptionCode;
+ DPL::WaitableEvent *m_synchronousEventFlag;
+ DPL::WaitableEvent *m_finishedFlag;
+ DPL::WaitableEvent *m_cancelStatusFlag;
+ bool m_cancelled;
+ bool m_cancelAllowed;
+
+ IEvent() :
+ m_state(STATE_INITIAL),
+ m_handlingType(HANDLING_NOT_SET),
+ m_remoteController(NULL),
+ m_exceptionCode(Commons::ExceptionCodes::None),
+ m_synchronousEventFlag(NULL),
+ m_finishedFlag(NULL),
+ m_cancelStatusFlag(NULL),
+ m_cancelled(false),
+ m_cancelAllowed(false)
+ {
+ }
+
+ virtual void waitForAnswer()
+ {
+ assert(HANDLING_SYNCHRONOUS == m_handlingType);
+ DPL::WaitForSingleHandle(m_synchronousEventFlag->GetHandle());
+ {
+ DPL::Mutex::ScopedLock lock(&m_stateMutex);
+ m_state = STATE_ENDED;
+ }
+ signalFinishedFlag();
+ LogDebug("deleting m_processEvent");
+ delete m_synchronousEventFlag;
+ m_synchronousEventFlag = NULL;
+ }
+
+ void signalFinishedFlag()
+ {
+ if (m_finishedFlag) {
+ m_finishedFlag->Signal();
+ }
+ }
+
+ DPL::WaitableEvent &getFinishedFlag()
+ {
+ if (!m_finishedFlag) {
+ m_finishedFlag = new DPL::WaitableEvent();
+ }
+ return *m_finishedFlag;
+ }
+
+ void signalCancelStatusFlag()
+ {
+ LogDebug("signaling cancel");
+ getCancelStatusFlag().Signal();
+ }
+
+ DPL::WaitableEvent &getCancelStatusFlag()
+ {
+ if (!m_cancelStatusFlag) {
+ m_cancelStatusFlag = new DPL::WaitableEvent();
+ }
+ return *m_cancelStatusFlag;
+ }
+
+ void signalSynchronousEventFlag()
+ {
+ if (m_synchronousEventFlag) {
+ m_synchronousEventFlag->Signal();
+ }
+ }
+
+ public:
+
+ /*
+ * Gets the answer receiver pointer.
+ */
+ EventAnswerReceiver< Super > * getAnswerReceiverRef() const
+ {
+ return m_remoteController;
+ }
+
+ virtual ~IEvent()
+ {
+ delete m_cancelStatusFlag;
+ delete m_finishedFlag;
+ delete m_synchronousEventFlag;
+ }
+
+ virtual bool changeCallToSynchronous()
+ {
+ return setForSynchronousCall();
+ }
+
+ virtual void waitTillProcessed()
+ {
+ DPL::WaitForSingleHandle(getFinishedFlag().GetHandle());
+ delete m_finishedFlag;
+ m_finishedFlag = NULL;
+ }
+
+ virtual void clearOnCancel()
+ {
+ }
+
+ Commons::ExceptionCodes::Enumeration getExceptionCode() const
+ {
+ return m_exceptionCode;
+ }
+ void setExceptionCode(Commons::ExceptionCodes::Enumeration exceptionCode)
+ {
+ m_exceptionCode = exceptionCode;
+ }
+
+ short getHandlingType() const
+ {
+ return m_handlingType;
+ }
+
+ virtual bool setForSynchronousCall()
+ {
+ DPL::Mutex::ScopedLock lock(&m_stateMutex);
+ if (m_cancelled) {
+ return false;
+ }
+ switch (m_state) {
+ case STATE_ANSWER_SEND:
+ m_state = STATE_CHANGED_TO_SYNCHRONOUS;
+ break;
+ case STATE_ANSWER_RECEIVED:
+ case STATE_ENDED:
+ return false;
+ default:
+ break;
+ }
+ m_handlingType = HANDLING_SYNCHRONOUS;
+ return true;
+ }
+
+ virtual bool setForAsynchronousCall(
+ EventAnswerReceiver< Super > *remoteController)
+ {
+ DPL::Mutex::ScopedLock lock(&m_stateMutex);
+ if (m_cancelled) {
+ return false;
+ }
+ switch (m_state) {
+ case STATE_ANSWER_SEND:
+ case STATE_ANSWER_RECEIVED:
+ case STATE_ENDED:
+ return false;
+ default:
+ break;
+ }
+ m_handlingType = HANDLING_ASYNCHRONOUS;
+ m_remoteController = remoteController;
+ return true;
+ }
+
+ /*
+ * Normally, after invoking OnRequestReceived in RequestReceiver, the answer is being send automatically (after flow leaves OnRequestReceived).
+ * After calling this function, the answer is not being send automatically, you need to call ManualAnswer to send event back.
+ * It works both in asynchronous and synchronous handling type.
+ */
+ virtual bool switchToManualAnswer()
+ {
+ assert(
+ m_handlingType == HANDLING_ASYNCHRONOUS || m_handlingType ==
+ HANDLING_SYNCHRONOUS);
+
+ DPL::Mutex::ScopedLock lock(&m_stateMutex);
+ if (m_cancelled) {
+ return false;
+ }
+ switch (m_state) {
+ case STATE_ANSWER_SEND:
+ case STATE_ANSWER_RECEIVED:
+ case STATE_ENDED:
+ return false;
+ default:
+ break;
+ }
+
+ switch (m_handlingType) {
+ case HANDLING_ASYNCHRONOUS:
+ m_handlingType = HANDLING_ASYNCHRONOUS_MANUAL_ANSWER;
+ break;
+ case HANDLING_SYNCHRONOUS:
+ m_handlingType = HANDLING_SYNCHRONOUS_MANUAL_ANSWER;
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+
+ bool checkCancelled()
+ {
+ //DPL::Mutex::ScopedLock lock(&m_stateMutex);
+ return m_cancelled;
+ }
+
+ void tryCancelled()
+ {
+ //DPL::Mutex::ScopedLock lock(&m_stateMutex);
+ if (m_cancelled) {
+ Throw(Commons::EventCancelledException);
+ }
+ }
+
+ bool getCancelAllowed() const
+ {
+ return m_cancelAllowed;
+ }
+
+ void setCancelAllowed(bool cancelAllowed)
+ {
+ m_cancelAllowed = cancelAllowed;
+ }
+
+ bool cancelRequest()
+ {
+ LogDebug("trying to cancel");
+ assert(
+ HANDLING_ASYNCHRONOUS == m_handlingType ||
+ HANDLING_ASYNCHRONOUS_MANUAL_ANSWER == m_handlingType);
+ {
+ DPL::Mutex::ScopedLock lock(&m_stateMutex);
+ if (m_cancelled) {
+ return false;
+ }
+ switch (m_state) {
+ case STATE_INITIAL:
+ assert(0);
+ case STATE_ANSWER_SEND:
+ LogDebug("cancelling");
+ m_cancelled = true;
+ delete m_cancelStatusFlag;
+ m_cancelStatusFlag = NULL;
+ return m_cancelAllowed;
+ case STATE_ANSWER_RECEIVED:
+ case STATE_ENDED:
+ return false;
+ default:
+ break;
+ }
+ LogDebug("cancelling");
+ m_cancelled = true;
+ }
+ LogDebug("waiting for cancel flag");
+ DPL::WaitForSingleHandle(getCancelStatusFlag().GetHandle());
+ delete m_cancelStatusFlag;
+ m_cancelStatusFlag = NULL;
+ return m_cancelAllowed;
+ }
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif /* WRTDEVICEAPIS_COMMONS_IEVENT_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
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_IEXTERN_EVENT_CANCELER_H_
+#define WRTDEVICEAPIS_COMMONS_IEXTERN_EVENT_CANCELER_H_
+
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * This class is related to JSPendingOperation object.
+ *
+ * It is interface for controllers which want to perform
+ * an additional accation when the PendingOberation object
+ * is canceled.
+ * */
+template<class TemplateEvent>
+class IExternEventCanceler
+{
+ public:
+ virtual void OnCancelEvent(const DPL::SharedPtr<TemplateEvent>& event) = 0;
+
+ virtual ~IExternEventCanceler()
+ {
+ }
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_IEXTERN_EVENT_CANCELER_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)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_LISTENER_EVENT_H_
+#define WRTDEVICEAPIS_COMMONS_LISTENER_EVENT_H_
+
+#include <dpl/mutex.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <Commons/Exception.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+template<class EventClass>
+class ListenerEventEmitter;
+
+/**
+ * This is base class for events that should act as signals between abstract
+ * layer and layer that uses it (e.g. JS layer in WRT plugins).
+ * Such event is created by specific event emitter from abstract layer
+ * and passed asynchronously to object that acts as event listener.
+ * Template parameter should be class of an event which derives from
+ * this class (co called CRTP pattern).
+ */
+template<class Derived>
+class ListenerEvent
+{
+ friend class ListenerEventEmitter<Derived>;
+
+ public:
+ typedef IEventPrivateData PrivateDataType;
+ typedef DPL::SharedPtr<PrivateDataType> PrivateDataTypePtr;
+
+ public:
+ virtual ~ListenerEvent()
+ {
+ delete m_mtx;
+ }
+
+ /**
+ * Gets exception code.
+ * @return Exception code.
+ */
+ Commons::ExceptionCodes::Enumeration getExceptionCode() const
+ {
+ DPL::Mutex::ScopedLock lock(m_mtx);
+ return m_code;
+ }
+
+ /**
+ * Sets exception code.
+ * @param code Exception code.
+ * @throw EventWrongStateExeption When event has already been emitted.
+ */
+ void setExceptionCode(Commons::ExceptionCodes::Enumeration code)
+ {
+ DPL::Mutex::ScopedLock lock(m_mtx);
+ m_code = code;
+ }
+
+ /**
+ * Gets event's private data.
+ * @return Private data (use DPL cast to proper object).
+ */
+ const PrivateDataTypePtr& getPrivateData() const
+ {
+ DPL::Mutex::ScopedLock lock(m_mtx);
+ return m_privateData;
+ }
+
+ protected:
+ ListenerEvent() :
+ m_mtx(new DPL::Mutex()),
+ m_code(Commons::ExceptionCodes::None)
+ {
+ }
+
+ ListenerEvent(const ListenerEvent &ths) :
+ m_mtx(new DPL::Mutex()),
+ m_code(ths.m_code),
+ m_privateData(ths.m_privateData)
+ {
+ }
+
+ ListenerEvent& operator=(const ListenerEvent &other)
+ {
+ if (this != &other) {
+ m_mtx = new DPL::Mutex();
+ m_code = other.m_code;
+ m_privateData = other.m_privateData;
+ }
+ return *this;
+ }
+
+ /**
+ * Sets event's private data.
+ * Event's private data object has to implement @see IEventPrivateData interface.
+ * @param data Private data.
+ * @throw EventWrongStateExeption When event has already been emitted.
+ */
+ void setPrivateData(const PrivateDataTypePtr& data)
+ {
+ DPL::Mutex::ScopedLock lock(m_mtx);
+ m_privateData = data;
+ }
+
+ protected:
+ mutable DPL::Mutex *m_mtx;
+ Commons::ExceptionCodes::Enumeration m_code; ///< Exception code.
+ PrivateDataTypePtr m_privateData; ///< Private data.
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_LISTENER_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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_LISTENER_EVENT_EMITTER_H_
+#define WRTDEVICEAPIS_COMMONS_LISTENER_EVENT_EMITTER_H_
+
+#include <stdint.h>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/mutex.h>
+#include <Commons/EventListener.h>
+#include <Commons/ListenerEvent.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+template<class EmitterClass>
+class Emitters;
+
+/**
+ * Creates listener events in the abstraction layer in response to some
+ * asynchronous action.
+ * To enable passing events from abstract layer to layer that uses it, first
+ * proper event emitter should be registered in abstract layer by the layer
+ * that uses it. Then when some action happens in abstract layer event should be
+ * created and passed to this emitter's emit() function. Then emitter passes
+ * this event to proper listener.
+ * Template parameter should be class that derives from @see ListenerEvent.
+ */
+template<class EventClass>
+class ListenerEventEmitter : private DPL::Noncopyable
+{
+ public:
+ typedef EventClass EventType;
+ typedef DPL::SharedPtr<EventType> EventPtrType;
+ typedef ListenerEventEmitter<EventType> Type;
+ typedef typename ListenerEvent<EventType>::PrivateDataType
+ EventPrivateDataType;
+ typedef typename ListenerEvent<EventType>::PrivateDataTypePtr
+ EventPrivateDataTypePtr;
+ typedef EventListener<EventType> ListenerType;
+ typedef uintptr_t IdType;
+
+ /**
+ * Empty (NULL) value of emitter's Id.
+ */
+ static const IdType emptyId;
+
+ public:
+ ListenerEventEmitter() : m_listener(NULL)
+ {
+ }
+
+ public:
+ virtual ~ListenerEventEmitter()
+ {
+ }
+
+ /**
+ * Sets event's private data.
+ * Event's private data object has to implement @see IEventPrivateData interface.
+ * @param data Private data.
+ * @remarks Practically private dat should be only set at object creation and
+ * not chaged during this object lifetime.
+ */
+ virtual void setEventPrivateData(const EventPrivateDataTypePtr& data)
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ m_privateData = data;
+ }
+
+ /**
+ * Gets event's private data.
+ * @return Private data.
+ */
+ virtual EventPrivateDataTypePtr getEventPrivateData()
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ return m_privateData;
+ }
+
+ /**
+ * Sets listener.
+ * Object set as listener has to implement @see EventListener interface.
+ * @param listener Listener object.
+ * @remarks Doesn't take ownership over this object.
+ * It's suggested to use singletons to have one listener for all
+ * events (no dynamic allocation overhead).
+ */
+ virtual void setListener(ListenerType* listener)
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ m_listener = listener;
+ }
+
+ /**
+ * Emits event.
+ * @param event Event to emit.
+ */
+ virtual void emit(const EventPtrType& event)
+ {
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ EventPtrType copy(new EventType(*event.Get()));
+ if (m_listener) {
+ copy->setPrivateData(m_privateData);
+ m_listener->postAnswer(copy);
+ }
+ }
+
+ /**
+ * Gets id.
+ * @return Event's id.
+ * @remarks Id is implemented as value of `this` pointer.
+ */
+ virtual IdType getId()
+ {
+ return reinterpret_cast<IdType>(this);
+ }
+
+ protected:
+ DPL::Mutex m_mtx; ///< Mutex for thread-safety.
+ ListenerType* m_listener; ///< Event listener object.
+ EventPrivateDataTypePtr m_privateData; ///< Private data.
+};
+
+template<class EventClass>
+const typename ListenerEventEmitter<EventClass>::IdType ListenerEventEmitter<
+ EventClass>::emptyId = 0;
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_LISTENER_EVENT_EMITTER_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)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_RANGE_H_
+#define WRTDEVICEAPIS_COMMONS_RANGE_H_
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * Stores data describing a range of values.
+ */
+template<typename Type>
+struct Range
+{
+ /**
+ * Type of value.
+ */
+ typedef Type ValueType;
+
+ /**
+ * Value representing minimum.
+ */
+ ValueType min;
+
+ /**
+ * Value representing maximum.
+ */
+ ValueType max;
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_RANGE_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 <pcrecpp.h>
+#include "Regex.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+bool validate(const std::string &pattern,
+ const std::string &value,
+ unsigned int options)
+{
+ pcrecpp::RE_Options pcreOpt;
+ if (options & VALIDATE_MATCH_CASELESS) {
+ pcreOpt.set_caseless(true);
+ }
+ pcrecpp::RE re(pattern, pcreOpt);
+ if (options & VALIDATE_MATCH_FULL) {
+ return re.FullMatch(value);
+ }
+ return re.PartialMatch(value);
+}
+
+std::string filter(const std::string &pattern,
+ const std::string &value)
+{
+ pcrecpp::RE re(pattern);
+ std::string ret = static_cast<std::string>(value);
+ re.GlobalReplace("", &ret);
+ return ret;
+}
+
+std::string toUpper(const std::string &value)
+{
+ pcrecpp::RE re(LOWER_P);
+ std::string ret = static_cast<std::string>(value);
+ re.GlobalReplace(UPPER_P, &ret);
+ return ret;
+}
+
+}
+} // WrtDeviceApisCommon
--- /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_COMMONS_REGEX_H_
+#define WRTDEVICEAPIS_COMMONS_REGEX_H_
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+const unsigned int VALIDATE_MATCH_CASELESS = 0x0001; //use when you want to make caseless match
+const unsigned int VALIDATE_MATCH_FULL = 0x0002; //use when you want supplied text matches a supplied pattern exactly
+const std::string LOWER_P = "p";
+const std::string UPPER_P = "P";
+
+/**
+ * Validates value against pattern
+ * @param pattern Regexp pattern
+ * @param value String to validate
+ * @param options Modifiers for a match.
+ * @return True when value is matched against pattern
+ */
+bool validate(const std::string &pattern,
+ const std::string &value,
+ unsigned int options = 0);
+
+/**
+ * Filter value against pattern(Any character except "0-9+#*Pp" will be removed from value)
+ * @param pattern Regexp pattern
+ * @param value String to be filtered
+ * @return filtered value
+ */
+std::string filter(const std::string &pattern,
+ const std::string &value);
+
+/**
+ * Replace character "p" in value by "P"
+ * @param value String to be replaced
+ * @return replaced value
+ */
+std::string toUpper(const std::string &value);
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_REGEX_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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONS_REGEX_PATTERNS_H_
+#define WRTDEVICEAPIS_COMMONS_REGEX_PATTERNS_H_
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+const std::string PATTERN_PHONE_NUMBER_FILTER("[^0-9+#*Pp]");
+const std::string PATTERN_PHONE_NUMBER("^[0-9#+*]+$");
+const std::string PATTERN_PHONE_NUMBER_P("^\\+?[0-9#*Pp]*[0-9][0-9#*Pp]*$");
+const std::string PATTERN_PHONE_NUMBER_PW("^[0-9#+*PpWw]+$");
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_REGEX_PATTERNS_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 "RegexUtils.h"
+#include <pcrecpp.h>
+#include "StringUtils.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+std::string addStartPositionMark(const std::string &value)
+{
+ if (!String::startsWith(value, "^") && !String::startsWith(value, ".*")) {
+ return "^" + value;
+ }
+ return value;
+}
+
+std::string addEndPositionMark(const std::string &value)
+{
+ if ((!String::endsWith(value, "$") || String::endsWith(value, "\\$")) &&
+ !String::endsWith(value, ".*")) {
+ return value + "$";
+ }
+ return value;
+}
+
+std::string addStartAndEndPositionMark(const std::string &value)
+{
+ return addEndPositionMark(addStartPositionMark(value));
+}
+
+std::string preparePercent(const std::string& str)
+{
+ std::string result = escape(str);
+ pcrecpp::RE("(([^\\\\])\\*|^()\\*)").GlobalReplace("\\2\\\\*", &result);
+ pcrecpp::RE("(([^\\\\])%|^()%)").GlobalReplace("\\2.*", &result);
+ return result;
+}
+
+std::string prepareAsterisk(const std::string& str)
+{
+ std::string result = escape(str);
+ // Replaces single wildcard "*" with version more compliant with Perl
+ // regular exrepssions, i.e. ".*".
+ pcrecpp::RE("(([^\\\\])\\*|^()\\*)").GlobalReplace("\\2.*", &result);
+ return result;
+}
+
+std::string escape(const std::string& str)
+{
+ std::string result = str;
+ // Escape standard regular expressions' metacharacters,
+ // i.e.: \, ., -, +, ?, (, ), [, ], ^, $, |
+ const char* metas = "(\\.|\\-|\\+|\\?|\\(|\\)|\\[|\\]|\\^|\\$|\\|"
+ "|(\\\\[^\\*\\%]|\\\\$))"; // \*, \% won't get additional '\'
+ pcrecpp::RE(metas).GlobalReplace("\\\\\\1", &result);
+ return result;
+}
+
+}
+} // WrtDeviceApisCommon
--- /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_COMMONS_REGEX_UTILS_H_
+#define WRTDEVICEAPIS_COMMONS_REGEX_UTILS_H_
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * Adds ^ character at the beginning in proper way
+ * @param value Regexp pattern
+ * @return Proper regular expression's pattern.
+ */
+std::string addStartPositionMark(const std::string &value);
+
+/**
+ * Adds $ character at the end in proper way
+ * @param value Regexp pattern
+ * @return Proper regular expression's pattern.
+ */
+std::string addEndPositionMark(const std::string &value);
+
+/**
+ * Adds ^ character at the beginning and $ the end in proper way
+ * @param value Regexp pattern
+ * @return Proper regular expression's pattern.
+ */
+std::string addStartAndEndPositionMark(const std::string &value);
+
+/**
+ * Converts typical string with wildcard '%' to proper perl-like regular
+ * expression's pattern.
+ * @param str String that came from JS.
+ * @return Proper regular expression's pattern.
+ * @remarks Calling it twice will (probably?) cause double escaping.
+ */
+std::string preparePercent(const std::string& str);
+
+/**
+ * Converts typical string with wildcard '*' to proper perl-like regular
+ * expression's pattern.
+ * @param str String that came from JS.
+ * @return Proper regular expression's pattern.
+ * @remarks Calling it twice will (probably?) cause double escaping.
+ */
+std::string prepareAsterisk(const std::string& str);
+
+/**
+ * Escapes regex special characters.
+ * @param str String to escape.
+ * @return String with regex special characters escaped.
+ */
+std::string escape(const std::string& str);
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_REGEX_UTILS_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 StaticAssert.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_STATIC_ASSERT_H
+#define WRTDEVICEAPIS_COMMONS_STATIC_ASSERT_H
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+template<bool>
+struct CompileTimeChecker
+{
+ CompileTimeChecker(...);
+};
+
+template<>
+struct CompileTimeChecker<false> {};
+
+#define STATIC_CHECK(expr, msg) \
+ { \
+ class ERROR_ ## msg {}; \
+ CompileTimeChecker<(expr)!= 0>((ERROR_ ## msg())); \
+ }
+
+/**
+ * Define used to inform about errors in compilation time
+ * useful in templates
+ * @param msg - message to be displayed,
+ * msg have to be a valid C++ identifier,
+ * other way reported errors will be meaningless
+ * @param C - instance of object which caused problem
+ * error generated by compiler display type of C
+ * */
+#define STATIC_ERROR(msg, C) \
+ { \
+ C->_ ## msg(); \
+ }
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_STATIC_ASSERT_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 <sstream>
+#include "Exception.h"
+#include "StringBuilder.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class StringBuilderImpl
+{
+ public:
+ StringBuilderImpl() : m_counter(1)
+ {
+ }
+
+ void append(const std::string& str)
+ {
+ if (!(m_ss << str)) {
+ m_ss.clear();
+ ThrowMsg(PlatformException, "Couldn't append string.");
+ }
+ }
+
+ void append(const StringBuilderImpl* impl)
+ {
+ if (!(m_ss << impl->m_ss)) {
+ m_ss.clear();
+ ThrowMsg(PlatformException,
+ "Couldn't append string builder.");
+ }
+ }
+
+ void addRef()
+ {
+ ++m_counter;
+ }
+
+ void deref()
+ {
+ if (0 == --m_counter) {
+ delete this;
+ }
+ }
+
+ StringBuilderImpl* clone()
+ {
+ if (1 == m_counter) {
+ return this;
+ }
+
+ --m_counter;
+
+ StringBuilderImpl* result = new StringBuilderImpl();
+ result->m_ss << m_ss;
+ return result;
+ }
+
+ std::string toString() const
+ {
+ return m_ss.str();
+ }
+
+ private:
+ std::stringstream m_ss;
+ unsigned int m_counter;
+};
+
+StringBuilder::StringBuilder() : m_impl(new StringBuilderImpl())
+{
+}
+
+StringBuilder::~StringBuilder()
+{
+ m_impl->deref();
+}
+
+StringBuilder::StringBuilder(const StringBuilder& other)
+{
+ other.m_impl->addRef();
+ m_impl = other.m_impl;
+}
+
+StringBuilder & StringBuilder::operator=(const StringBuilder& other)
+{
+ if (this == &other) { return *this; }
+
+ other.m_impl->addRef();
+
+ m_impl->deref();
+ m_impl = other.m_impl;
+
+ return *this;
+}
+
+StringBuilder& StringBuilder::append(const std::string& str)
+{
+ m_impl = m_impl->clone();
+ m_impl->append(str);
+ return *this;
+}
+
+StringBuilder& StringBuilder::append(const StringBuilder& builder)
+{
+ m_impl = m_impl->clone();
+ m_impl->append(builder.m_impl);
+ return *this;
+}
+
+std::string StringBuilder::toString() const
+{
+ return m_impl->toString();
+}
+
+}
+} // WrtDeviceApisCommon
--- /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_COMMONS_STRINGBUILDER_H_
+#define WRTDEVICEAPIS_COMMONS_STRINGBUILDER_H_
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class StringBuilderImpl;
+
+class StringBuilder
+{
+ public:
+ StringBuilder();
+ StringBuilder(const StringBuilder& other);
+ ~StringBuilder();
+
+ StringBuilder& operator=(const StringBuilder& other);
+
+ StringBuilder& append(const std::string& str);
+ StringBuilder& append(const StringBuilder& builder);
+ std::string toString() const;
+
+ private:
+ StringBuilderImpl* m_impl;
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_STRINGBUILDER_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 <cstring>
+#include <algorithm>
+#include <iterator>
+#include <new>
+#include <sstream>
+#include <Commons/Exception.h>
+#include "StringUtils.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+namespace String {
+
+std::string lTrim(const std::string& str)
+{
+ std::string result = str;
+ result.erase(result.begin(),
+ std::find_if(result.begin(), result.end(),
+ std::not1(std::ptr_fun<int, int>(std::isspace))));
+ return result;
+}
+
+std::string rTrim(const std::string& str)
+{
+ std::string result = str;
+ result.erase(std::find_if(result.rbegin(), result.rend(),
+ std::not1(std::ptr_fun<int, int>(
+ std::isspace))).base(), result.end());
+ return result;
+}
+
+std::string trim(const std::string& str)
+{
+ return lTrim(rTrim(str));
+}
+
+bool startsWith(const std::string& str,
+ const std::string& startStr)
+{
+ return str.find(startStr) == 0;
+}
+
+bool endsWith(const std::string& str,
+ const std::string& endStr)
+{
+ std::size_t pos = str.rfind(endStr);
+ if (pos == std::string::npos) {
+ return false;
+ }
+ return pos == str.length() - endStr.length();
+}
+
+std::string unique(const std::string& str,
+ const char needle)
+{
+ std::string result = str;
+
+ std::string::size_type pos = 0;
+ while ((pos = result.find_first_of(needle, pos)) < std::string::npos) {
+ std::string::size_type last = result.find_first_not_of(needle, pos);
+ if (last == std::string::npos) {
+ last = result.size();
+ }
+ if (last - pos > 1) {
+ result.erase(pos + 1, last - pos - 1);
+ }
+ pos = last;
+ }
+
+ return result;
+}
+
+bool inCStringArray(const std::string& needle,
+ const char* stack[])
+{
+ while (*stack) {
+ if (needle == *stack) {
+ return true;
+ }
+ ++stack;
+ }
+ return false;
+}
+
+char* strdup(const char* str)
+{
+ char* result = ::strdup(str);
+ if (NULL == result) {
+ throw std::bad_alloc();
+ }
+ return result;
+}
+
+std::string merge(const std::vector<std::string>& strs,
+ std::string::value_type delim)
+{
+ typedef std::vector<std::string> Strings;
+
+ std::ostringstream ss;
+ if (!strs.empty()) {
+ for (Strings::size_type i = 0; i < strs.size() - 1; ++i) {
+ ss << strs[i] << delim;
+ }
+ ss << strs.at(strs.size() - 1);
+ }
+ return ss.str();
+}
+
+std::vector<std::string> split(const std::string& str,
+ std::string::value_type delim)
+{
+ std::vector<std::string> result;
+ std::string::size_type begin = 0, end = 0;
+ while ((end = str.find_first_of(delim, begin))) {
+ std::string part = (std::string::npos == end ?
+ str.substr(begin) :
+ str.substr(begin, end - begin));
+ if (!part.empty()) {
+ result.push_back(part);
+ }
+ if (std::string::npos == end) { break; }
+ begin = end + 1;
+ }
+ return result;
+}
+
+int toInt(const std::string &text)
+{
+ int result;
+ std::stringstream ss(text);
+ if (!(ss >> result)) {
+ Throw(ConversionException);
+ }
+ return result;
+}
+
+}
+}
+} // WrtDeviceApisCommon
--- /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_COMMONS_STRINGUTILS_H_
+#define WRTDEVICEAPIS_COMMONS_STRINGUTILS_H_
+
+#include <string>
+#include <vector>
+
+namespace WrtDeviceApis {
+namespace Commons {
+namespace String {
+
+/**
+ * Removes spaces from begining of the string.
+ * @param str String to remove spaces from.
+ * @return String with spaces removed.
+ */
+std::string lTrim(const std::string& str);
+
+/**
+ * Removes spaces from end of the string.
+ * @param str String to remove spaces from.
+ * @return String with spaces removed.
+ */
+std::string rTrim(const std::string& str);
+
+/**
+ * Removes spaces from begining and end of the string.
+ * @param str String to remove spaces from.
+ * @return String with spaces removed.
+ */
+std::string trim(const std::string& str);
+
+/**
+ * Checks if str starts with startStr
+ * @param str String to be searched.
+ * @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);
+
+/**
+ * Checks if str ends with startStr
+ * @param str String to be searched.
+ * @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);
+
+/**
+ * Merges consecutive groups of duplicate characters into one.
+ * @param str String to remove characters from.
+ * @param needle Character for which groups of duplicates to merge.
+ * @return String with group of duplicate characters merged.
+ * @code
+ * ...
+ * std::string str = "Aala maa kota";
+ * std::string uniq = unique(str, 'a');
+ * uniq == "Ala ma kota";
+ * ...
+ * @endcode
+ */
+std::string unique(const std::string& str,
+ const char needle);
+
+/**
+ * Checks if supplied string exists in specified array of c-strings.
+ * @param needle String to verify.
+ * @param stack Array of c-strings which last element should be NULL.
+ * @return True if string exists in array, false otherwise.
+ * @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[]);
+
+/**
+ * Duplicates a string.
+ * @param str String to duplicate.
+ * @return String copy.
+ * @throw std::bad_alloc If allocation fails.
+ * @remarks Ownership passed to the caller. String has to be deallocated using
+ * free() function.
+ */
+char* strdup(const char* str);
+inline char* strdup(const std::string& str)
+{
+ return strdup(str.c_str());
+}
+
+std::string merge(const std::vector<std::string>& strs,
+ std::string::value_type delim);
+
+std::vector<std::string> split(const std::string& str,
+ std::string::value_type delim);
+
+int toInt(const std::string &text);
+
+} // String
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_STRINGUTILS_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.
+ */
+/*
+ * ControllersFactory.cpp
+ *
+ * Created on: 2010-06-28
+ * Author: kmajewski
+ */
+
+#include <assert.h>
+
+#include <dpl/log/log.h>
+#include <dpl/thread.h>
+
+#include "ThreadPool.h"
+#include "Exception.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+ThreadPool &ThreadPool::getInstance()
+{
+ static ThreadPool theInstance;
+ return theInstance;
+}
+
+DPL::Event::AbstractEventDispatcher *ThreadPool::getDispatcher(
+ DPL::Event::ThreadEventDispatcher &callingThreadDispatcher)
+{
+ DPL::Thread *currentThread = DPL::Thread::GetCurrentThread();
+ //if we are in main thread
+ if (NULL == currentThread) {
+ return &DPL::Event::GetMainEventDispatcherInstance();
+ }
+ callingThreadDispatcher.SetThread(currentThread);
+ return &callingThreadDispatcher;
+}
+
+ThreadPool::ThreadPool()
+{
+}
+
+ThreadPool::~ThreadPool()
+{
+ for (ThreadHandleMap::const_iterator it = m_threadHandlers.begin(); it
+ != m_threadHandlers.end(); ++it)
+ {
+ delete (*it).second;
+ }
+}
+
+DPL::Thread* ThreadPool::getThreadHandleCreateIfNotExists(
+ ThreadEnum::Enumeration type)
+{
+ DPL::Mutex::ScopedLock lock(&m_threadHandlersMutex);
+ ThreadHandleMap::iterator element = m_threadHandlers.find(type);
+
+ //if element does not exists in the map
+ if (m_threadHandlers.end() == element) {
+ DPL::Thread* newThread = new DPL::Thread();
+ m_threadHandlers.insert(
+ m_threadHandlers.begin(),
+ std::pair<ThreadEnum::Enumeration,DPL::Thread*>(type, newThread));
+ newThread->Run();
+ return newThread;
+ }
+ return (*element).second;
+}
+
+DPL::Thread *ThreadPool::getThreadRef(ThreadEnum::Enumeration type)
+{
+ DPL::Thread *thandle = NULL;
+ if (type < 0 || type >= ThreadEnum::size) {
+ Throw(InvalidArgumentException);
+ }
+ /* we could stay with
+ * getThreadHandleCreateIfNotExists(type);
+ * but by switch we can attach actually one thread to more than one ThreadEnums
+ */
+ switch (type) {
+ case ThreadEnum::NULL_THREAD:
+ thandle = NULL;
+ break;
+ case ThreadEnum::CAMERA_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::CAMERA_THREAD);
+ break;
+ case ThreadEnum::CALENDAR_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::CALENDAR_THREAD);
+ break;
+ case ThreadEnum::TELEPHONY_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::TELEPHONY_THREAD);
+ break;
+ case ThreadEnum::APPLAUNCHER_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(
+ ThreadEnum::APPLAUNCHER_THREAD);
+ break;
+ case ThreadEnum::APPCONFIG_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::APPCONFIG_THREAD);
+ break;
+ case ThreadEnum::MESSAGING_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(type);
+ break;
+ case ThreadEnum::FILESYSTEM_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(
+ ThreadEnum::FILESYSTEM_THREAD);
+ break;
+ case ThreadEnum::GALLERY_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::GALLERY_THREAD);
+ break;
+ case ThreadEnum::CONTACT_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::CONTACT_THREAD);
+ break;
+ case ThreadEnum::MMPLAYER_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::MMPLAYER_THREAD);
+ break;
+ case ThreadEnum::BONDI_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::BONDI_THREAD);
+ break;
+ case ThreadEnum::GEOLOCATION_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(
+ ThreadEnum::GEOLOCATION_THREAD);
+ break;
+ case ThreadEnum::DEVICESTATUS_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(
+ ThreadEnum::DEVICESTATUS_THREAD);
+ break;
+ case ThreadEnum::PROFILE_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(type);
+ break;
+ case ThreadEnum::HAPTICS_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(type);
+ break;
+ case ThreadEnum::ACCELEROMETER_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(
+ ThreadEnum::ACCELEROMETER_THREAD);
+ break;
+ case ThreadEnum::ORIENTATION_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(
+ ThreadEnum::ORIENTATION_THREAD);
+ break;
+ case ThreadEnum::TASK_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::TASK_THREAD);
+ break;
+ case ThreadEnum::POWER_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::POWER_THREAD);
+ break;
+ case ThreadEnum::PLUGIN_TEMPLETE_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::PLUGIN_TEMPLETE_THREAD);
+ break;
+ case ThreadEnum::BLUETOOTH_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::BLUETOOTH_THREAD);
+ break;
+ case ThreadEnum::APPLICATION_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::APPLICATION_THREAD);
+ break;
+ case ThreadEnum::GYROSCOPE_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::GYROSCOPE_THREAD);
+ break;
+ case ThreadEnum::CLOCK_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::CLOCK_THREAD);
+ break;
+ case ThreadEnum::SYSTEMINFO_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::SYSTEMINFO_THREAD);
+ break;
+ case ThreadEnum::CALLHISTORY_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::CALLHISTORY_THREAD);
+ break;
+ case ThreadEnum::ACCOUNT_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::CALLHISTORY_THREAD);
+ break;
+ case ThreadEnum::NFC_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::NFC_THREAD);
+ break;
+ case ThreadEnum::MEDIACONTENT_THREAD:
+ thandle = getThreadHandleCreateIfNotExists(ThreadEnum::MEDIACONTENT_THREAD);
+ break;
+ // .....
+ default:
+ LogError("no case statement for ThreadEnum");
+ Throw(InvalidArgumentException);
+ }
+ return thandle;
+}
+
+}
+} // WrtDeviceApisCommon
--- /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.
+ */
+/*
+ * ControllersFactory.h
+ *
+ * Created on: 2010-06-28
+ * Author: kmajewski
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_THREADPOOL_H_
+#define WRTDEVICEAPIS_COMMONS_THREADPOOL_H_
+
+#include <map>
+#include <dpl/thread.h>
+#include <dpl/event/main_event_dispatcher.h>
+#include <dpl/event/thread_event_dispatcher.h>
+#include <dpl/event/event_support.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class ThreadEnum
+{
+ private:
+ ThreadEnum()
+ {
+ }
+ public:
+ enum Enumeration
+ {
+ NULL_THREAD = 0,
+ CAMERA_THREAD,
+ CALENDAR_THREAD,
+ TELEPHONY_THREAD,
+ APPLAUNCHER_THREAD,
+ MESSAGING_THREAD,
+ FILESYSTEM_THREAD,
+ UI_THREAD,
+ APPCONFIG_THREAD,
+ GALLERY_THREAD,
+ CONTACT_THREAD,
+ MMPLAYER_THREAD,
+ BONDI_THREAD,
+ GEOLOCATION_THREAD,
+ DEVICESTATUS_THREAD,
+ PROFILE_THREAD,
+ HAPTICS_THREAD,
+ ACCELEROMETER_THREAD,
+ ORIENTATION_THREAD,
+ TASK_THREAD,
+ POWER_THREAD,
+ PLUGIN_TEMPLETE_THREAD,
+ BLUETOOTH_THREAD,
+ APPLICATION_THREAD,
+ GYROSCOPE_THREAD,
+ CLOCK_THREAD,
+ SYSTEMINFO_THREAD,
+ CALLHISTORY_THREAD,
+ ACCOUNT_THREAD,
+ NFC_THREAD,
+ MEDIACONTENT_THREAD,
+ //....
+ size
+ };
+};
+
+
+class ThreadPool : private DPL::Noncopyable
+{
+ private:
+ typedef std::map<ThreadEnum::Enumeration, DPL::Thread*> ThreadHandleMap;
+ ThreadHandleMap m_threadHandlers;
+ DPL::Mutex m_threadHandlersMutex;
+
+ DPL::Thread *getThreadHandleCreateIfNotExists(ThreadEnum::Enumeration type);
+
+ //DPL::MainEventDispatcher m_mainEventDispatcher;
+
+ ThreadPool();
+ public:
+ ~ThreadPool();
+
+ /*
+ * @throws: WrtDeviceApis::Commons::InvalidArgumentException
+ */
+ DPL::Thread * getThreadRef(ThreadEnum::Enumeration type);
+
+ /*
+ * Get proper dispatcher for current calling thread
+ */
+ DPL::Event::AbstractEventDispatcher *getDispatcher(
+ DPL::Event::ThreadEventDispatcher &callingThreadDispatcher);
+
+ static ThreadPool& getInstance();
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_THREADPOOL_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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONS_TYPE_TRAITS_H_
+#define WRTDEVICEAPIS_COMMONS_TYPE_TRAITS_H_
+
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+template<typename T>
+struct IsNull
+{
+ static bool value(const T&)
+ {
+ return false;
+ }
+};
+
+template<typename T>
+struct IsNull<T*>
+{
+ static bool value(T* ptr)
+ {
+ return ptr == NULL;
+ }
+};
+
+template<typename Class>
+struct IsNull<DPL::SharedPtr<Class> >
+{
+ static bool value(const DPL::SharedPtr<Class>& ptr)
+ {
+ return ptr.Get() == NULL;
+ }
+};
+
+template<typename ... T>
+struct AlwaysFalse
+{
+ static const bool value = false;
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif // WRTDEVICEAPIS_COMMONS_TYPE_TRAITS_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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONS_TYPES_DECLARATION_
+#define WRTDEVICEAPIS_COMMONS_TYPES_DECLARATION_
+
+#include <string>
+#include <vector>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+struct AceFeature
+{
+ AceFeature(const std::string& featName) : name(featName) {}
+ std::string name;
+};
+
+typedef std::vector <AceFeature> AceFeatures;
+
+struct AceDeviceCapParam
+{
+ AceDeviceCapParam(const std::string& parName,
+ const std::string& parVal) : name(parName),
+ value(parVal)
+ {
+ }
+
+ std::string name;
+ std::string value;
+};
+
+typedef std::vector <AceDeviceCapParam> AceDeviceCapParams;
+
+struct AceDeviceCapability
+{
+ AceDeviceCapability() {}
+ AceDeviceCapability(const std::string& name,
+ const AceDeviceCapParams& params) :
+ devCapName(name),
+ devCapParams(params)
+ {
+ }
+
+ std::string devCapName;
+ AceDeviceCapParams devCapParams;
+};
+
+typedef std::vector <AceDeviceCapability> AceDeviceCaps;
+
+struct AceFunction
+{
+ std::string name;
+ AceFeatures features;
+ AceDeviceCaps deviceCapabilities;
+};
+} // namespace Commons
+} // namespace WrtDeviceApis
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_DEVICEAPIS_COMMONS_CONFIGURATION_SUPPORT_H_
+#define WRT_DEVICEAPIS_COMMONS_CONFIGURATION_SUPPORT_H_
+
+#include <Commons/WidgetConfiguration/WidgetConfiguration.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class ConfigurationSupport
+{
+ public:
+ virtual WidgetConfigurationPtr getConfiguration() const
+ {
+ return m_configuration;
+ }
+
+ virtual void setConfiguration(const WidgetConfigurationPtr& config)
+ {
+ m_configuration = config;
+ }
+
+ virtual ~ConfigurationSupport()
+ {
+ }
+
+ protected:
+ WidgetConfigurationPtr m_configuration;
+};
+
+}
+}
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <Commons/WrtWrapper/WrtWrappersMgr.h>
+#include "WidgetConfiguration.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+WidgetConfigurationPtr WidgetConfiguration::create(
+ const JavaScriptContext context)
+{
+ Try
+ {
+ WidgetConfigurationPtr config(new WidgetConfiguration);
+ config->m_wrtWrapper =WrtDeviceApis::Commons::
+ WrtWrappersMgr::getInstance().getWrtWrapper(context);
+
+ return config;
+ }
+ Catch(Commons::InvalidArgumentException)
+ {
+ LogError("Wrt wrapper doesnt exist, check plugin_initializer.cpp file");
+ Assert(false);
+ }
+}
+
+IWrtWrapperPtr WidgetConfiguration::getWrtWrapper() const
+{
+ return m_wrtWrapper;
+}
+
+}
+}
--- /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_WIDGET_CONFIGURATION_H_
+#define WRT_PLUGINS_WIDGET_CONFIGURATION_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/WrtWrapper/IWrtWrapper.h>
+#include <Commons/plugin_initializer_def.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+struct WidgetConfiguration;
+typedef DPL::SharedPtr<WidgetConfiguration> WidgetConfigurationPtr;
+
+struct WidgetConfiguration
+{
+ IWrtWrapperPtr getWrtWrapper() const;
+
+ /**
+ * @thrown Commons::InvalidArgumentsException if wrapper doesnt exist
+ * TODO temporary Assert is used
+ * */
+ static WidgetConfigurationPtr create(const JavaScriptContext context);
+
+ private:
+ WidgetConfiguration()
+ {
+ }
+
+ private:
+ IWrtWrapperPtr m_wrtWrapper;
+};
+
+
+}
+}
+
+#endif
--- /dev/null
+get_current_path()
+
+set(SRCS_WIDGET_CONFIGURATION
+ ${CURRENT_PATH}/WidgetConfiguration.cpp
+)
--- /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_WRT_CAMERA_INTERFACE_H_
+#define WRT_PLUGINS_WRT_CAMERA_INTERFACE_H_
+
+#include<string>
+
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class IWrtCamera{
+
+public:
+ typedef int CameraPendingOperation;
+ typedef void (*SetPendingOperationCb)(CameraPendingOperation,
+ void* user_data);
+
+ typedef void* CameraPreviewNode;
+ typedef void (*CameraCaptureSuccessCb)(const char* filename, void* data);
+ typedef void (*CameraPreviewSuccessCb)(CameraPreviewNode node, void* data);
+ typedef void (*CameraErrorCb)(int errorCode, void*);
+
+public:
+ virtual void createPreviewNode(CameraPreviewSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data) = 0;
+
+ virtual void captureImage(const std::string& filename,
+ bool highRes,
+ CameraCaptureSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data) = 0;
+
+ virtual void startVideoCapture(const std::string& filename,
+ bool highRes,
+ CameraCaptureSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data) = 0;
+
+ virtual void stopVideoCapture() = 0;
+
+ virtual void cancelAsyncOperation(
+ const IWrtCamera::CameraPendingOperation& pendingOperation) = 0;
+
+ /**
+ * virtual destructor
+ */
+ virtual ~IWrtCamera(){}
+};
+
+typedef DPL::SharedPtr<IWrtCamera> IWrtCameraPtr;
+
+}
+} // WrtDeviceApisCommon
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_WRT_CAMERA_MANAGER_INTERFACE_H_
+#define WRT_PLUGINS_WRT_CAMERA_MANAGER_INTERFACE_H_
+
+#include <string>
+#include <list>
+#include <dpl/shared_ptr.h>
+#include <Commons/WrtWrapper/IWrtCamera.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class IWrtCameraManager
+{
+
+public:
+
+ typedef std::list<IWrtCameraPtr> WrtCameras;
+ typedef DPL::SharedPtr<WrtCameras> WrtCamerasPtr;
+
+public:
+
+ virtual WrtCamerasPtr getCameras() = 0;
+
+ /**
+ * virtual destructor
+ */
+ virtual ~IWrtCameraManager(){}
+};
+
+typedef DPL::SharedPtr<IWrtCameraManager> IWrtCameraManagerPtr;
+
+}
+} // WrtDeviceApisCommon
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_WRT_ENGINE_WRAPPER_INTERFACE_H_
+#define WRT_PLUGINS_WRT_ENGINE_WRAPPER_INTERFACE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/TypesDeclaration.h>
+#include <Commons/WrtWrapper/IWrtCameraManager.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class IWrtWrapper
+{
+
+ public:
+
+ virtual ~IWrtWrapper()
+ {
+ }
+
+ /*
+ * Get widgetId
+ * @throw Exception::PlatformException if platform error
+ * @throw Exception::SecurityException if wrt forbiden using this function
+ * */
+ virtual int getWidgetId() const = 0;
+
+ /*
+ * Get call permission for platform function.
+ * */
+ virtual bool checkAccess(const AceFunction &aceFunction)
+ const = 0;
+
+
+ /**
+ * Returns shared pointer to camera interface
+ * */
+ virtual IWrtCameraManagerPtr getCameraManagerInterface() const = 0;
+};
+
+typedef DPL::SharedPtr<IWrtWrapper> IWrtWrapperPtr;
+
+}
+} // WrtDeviceApisCommon
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "WrtCamera.h"
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+WrtCamera::WrtCamera(int widgetId,
+ const engine_interface_t* interface,
+ CameraInstance camera,
+ camera_type /*type*/) :
+ m_widgetId(widgetId),
+ m_wrt(interface),
+ m_camera(camera)
+{
+ if (!interface) {
+ LogError("Pointer to interface is NULL");
+ }
+}
+
+void WrtCamera::createPreviewNode(CameraPreviewSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data)
+{
+ if (!m_wrt ||
+ !m_wrt->wrt_camera_create_preview_node)
+ {
+ LogError("Error: Security error");
+ Throw(SecurityException);
+ }
+
+ if (m_wrt->wrt_camera_create_preview_node(
+ m_widgetId,
+ m_camera,
+ successCallback,
+ errorCallback,
+ setPendingOperationCb,
+ user_data))
+ {
+ LogError("Error: Platform error when create_preview_node");
+ Throw(PlatformException);
+ }
+}
+
+void WrtCamera::captureImage(const std::string& filename,
+ bool highRes,
+ CameraCaptureSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data)
+{
+ if (!m_wrt ||
+ !m_wrt->wrt_camera_capture_image)
+ {
+ LogError("Error: Security error");
+ Throw(SecurityException);
+ }
+
+ if (m_wrt->wrt_camera_capture_image(
+ m_widgetId,
+ m_camera,
+ filename.c_str(),
+ highRes,
+ successCallback,
+ errorCallback,
+ setPendingOperationCb,
+ user_data))
+ {
+ LogError("Error: Platform error when capture_image");
+ Throw(PlatformException);
+ }
+}
+
+void WrtCamera::startVideoCapture(const std::string& filename,
+ bool highRes,
+ CameraCaptureSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data)
+{
+ if (!m_wrt ||
+ !m_wrt->wrt_camera_start_video_capture)
+ {
+ LogError("Error: Security error");
+ Throw(SecurityException);
+ }
+
+ if (m_wrt->wrt_camera_start_video_capture(
+ m_widgetId,
+ m_camera,
+ filename.c_str(),
+ highRes,
+ successCallback,
+ errorCallback,
+ setPendingOperationCb,
+ user_data))
+ {
+ LogError("Error: Platform error when start video");
+ Throw(PlatformException);
+ }
+}
+
+void WrtCamera::stopVideoCapture()
+{
+ if (!m_wrt ||
+ !m_wrt->wrt_camera_stop_video_capture)
+ {
+ LogError("Error: Security error");
+ Throw(SecurityException);
+ }
+
+ if (m_wrt->wrt_camera_stop_video_capture(m_widgetId, m_camera)) {
+ LogError("Error: Platform error when start video");
+ Throw(PlatformException);
+ }
+}
+
+void WrtCamera::cancelAsyncOperation (
+ const IWrtCamera::CameraPendingOperation& pendingOperation)
+{
+ if (!m_wrt ||
+ !m_wrt->wrt_camera_cancel_async_operation)
+ {
+ LogError("Error: Security error");
+ Throw(SecurityException);
+ }
+
+ if (m_wrt->wrt_camera_cancel_async_operation(m_widgetId,
+ m_camera,
+ pendingOperation))
+ {
+ LogError("Error: Platform error when start video");
+ Throw(PlatformException);
+ }
+}
+
+WrtCamera::~WrtCamera()
+{
+ if (!m_wrt ||
+ !m_wrt->wrt_camera_remove_camera)
+ {
+ LogError("Error: Security error");
+ Throw(SecurityException);
+ }
+
+ if (m_wrt->wrt_camera_remove_camera(m_widgetId, m_camera)) {
+ LogError("Error: Platform error when removing camera");
+ //DPL::Assert(0);
+ // Throw(PlatformException);
+ }
+
+ LogDebug("Camera instance removed");
+}
+
+}
+} // WrtDeviceApisCommon
--- /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_WRT_CAMERA_H_
+#define WRT_PLUGINS_WRT_CAMERA_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <wrt_plugin_export.h>
+#include "IWrtCamera.h"
+//#include <API/Camera/ICamera.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class WrtCamera : public IWrtCamera
+{
+
+public:
+ typedef void* CameraInstance;
+
+public:
+ WrtCamera(int widgetId,
+ const engine_interface_t* interface,
+ CameraInstance camera,
+ camera_type type);
+
+ virtual void createPreviewNode(CameraPreviewSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data);
+
+ virtual void captureImage(const std::string& filename,
+ bool highRes,
+ CameraCaptureSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data);
+
+ virtual void startVideoCapture(const std::string& filename,
+ bool highRes,
+ CameraCaptureSuccessCb successCallback,
+ CameraErrorCb errorCallback,
+ SetPendingOperationCb setPendingOperationCb,
+ void* user_data);
+
+ virtual void stopVideoCapture();
+
+ virtual void cancelAsyncOperation(const CameraPendingOperation& operation);
+
+ /**
+ * virtual destructor
+ */
+ virtual ~WrtCamera();
+
+private:
+ int m_widgetId;
+
+ const engine_interface_t* m_wrt;
+
+ CameraInstance m_camera;
+};
+
+typedef DPL::SharedPtr<WrtCamera> WrtCameraPtr;
+
+}
+} // WrtDeviceApisCommon
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "WrtCameraManager.h"
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "WrtCamera.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+WrtCameraManager::WrtCameraManager(int widgetId,
+ const engine_interface_t* interface)
+ : m_widgetId(widgetId)
+{
+ m_wrt = interface;
+
+ if (!interface) {
+ LogError("Pointer to interface is NULL");
+ }
+
+ m_cameras = WrtCamerasPtr(new WrtCameras);
+}
+
+
+IWrtCameraManager::WrtCamerasPtr WrtCameraManager::getCameras()
+{
+ static bool initialized = initialize();
+ (void)initialized;
+
+ return m_cameras;
+}
+
+bool WrtCameraManager::initialize()
+{
+ if (!m_wrt ||
+ !m_wrt->wrt_camera_get_cameras ||
+ !m_wrt->wrt_camera_free_webkit_cameras)
+ {
+ LogError("Error: Security error");
+ Throw(SecurityException);
+ }
+
+ webkit_cameras_array *array = m_wrt->wrt_camera_get_cameras(m_widgetId);
+ if (NULL == array) {
+ LogError("Error: Platform error when get_cameras");
+ Throw(PlatformException);
+ }
+
+ for (size_t i = 0; i < array->size; ++i) {
+ m_cameras->push_back(
+ IWrtCameraPtr(new WrtCamera(m_widgetId,
+ m_wrt,
+ array->webkit_cameras[i].camera,
+ array->webkit_cameras[i].type)));
+ }
+ return true;
+
+
+
+
+}
+
+}
+} // WrtDeviceApisCommon
--- /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_WRT_CAMERA_MANAGER_H_
+#define WRT_PLUGINS_WRT_CAMERA_MANAGER_H_
+
+#include <wrt_plugin_export.h>
+#include "IWrtCameraManager.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class WrtCameraManager : public IWrtCameraManager
+{
+
+public:
+ WrtCameraManager(int widgetId, const engine_interface_t* interface);
+
+ virtual WrtCamerasPtr getCameras();
+
+private:
+ bool initialize();
+
+private:
+ int m_widgetId;
+
+ const engine_interface_t* m_wrt;
+
+ WrtCamerasPtr m_cameras;
+};
+
+}
+} // WrtDeviceApisCommon
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <memory>
+
+#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 "WrtWrapper.h"
+#include "WrtCameraManager.h"
+#include <ace-client/ace_client.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+struct DeviceCapParamPolicy
+{
+ typedef AceClient::AceParamList* Type;
+ static Type NullValue()
+ {
+ return NULL;
+ }
+ static void Destroy(Type ptr)
+ {
+ if (ptr) {
+ delete[] ptr->param;
+ }
+ delete[] ptr;
+ }
+};
+
+/**
+ * Helper class - modified ScopedArray for ace_param_list_t
+ */
+class ScopedDeviceCapArray : public DPL::ScopedResource<DeviceCapParamPolicy>
+{
+ public:
+ explicit ScopedDeviceCapArray(AceClient::AceParamList *ptr =
+ DeviceCapParamPolicy::NullValue()) :
+ DPL::ScopedResource<DeviceCapParamPolicy>(ptr)
+ {
+ }
+
+ AceClient::AceParamList & operator [](std::ptrdiff_t k) const
+ {
+ Assert(this->m_value != DeviceCapParamPolicy::NullValue() &&
+ "Dereference of scoped NULL array!");
+ Assert(k >= 0 && "Negative array index");
+
+ return this->m_value[k];
+ }
+};
+
+WrtWrapper::WrtWrapper(int widgetId,
+ const engine_interface_t* interface) :
+ m_widgetId(widgetId)
+{
+ m_wrt = interface;
+
+ if (!interface) {
+ LogError("Pointer to interface is NULL");
+ }
+
+ m_cameraManager = IWrtCameraManagerPtr(
+ new WrtCameraManager(widgetId, interface));
+}
+
+WrtWrapper::~WrtWrapper()
+{
+ LogDebug("entered");
+}
+
+int WrtWrapper::getWidgetId() const
+{
+ LogDebug("entered");
+ return m_widgetId;
+}
+
+bool WrtWrapper::checkAccess(const AceFunction& aceFunction) const
+{
+ size_t deviceCount = aceFunction.deviceCapabilities.size();
+
+ DPL::ScopedArray <const char *> deviceScopedArray;
+ ScopedDeviceCapArray paramsScopedArray;
+
+ if (deviceCount) {
+ deviceScopedArray.Reset(new const char*[deviceCount]);
+ paramsScopedArray.Reset(new AceClient::AceParamList[deviceCount]);
+
+ for (size_t i = 0; i < deviceCount; ++i) {
+ deviceScopedArray[i] =
+ aceFunction.deviceCapabilities.at(i).devCapName.c_str();
+ paramsScopedArray[i].count =
+ aceFunction.deviceCapabilities.at(i).devCapParams.size();
+
+ paramsScopedArray[i].param =
+ new AceClient::AceParam[paramsScopedArray[i].count];
+
+ for (size_t j = 0; j < paramsScopedArray[i].count; ++j) {
+ paramsScopedArray[i].param[j].name =
+ aceFunction.deviceCapabilities.at(i).
+ devCapParams[j].name.c_str();
+ paramsScopedArray[i].param[j].value =
+ aceFunction.deviceCapabilities.at(i).
+ devCapParams[j].value.c_str();
+ }
+ }
+ }
+
+ size_t featuresCount = aceFunction.features.size();
+
+ DPL::ScopedArray <const char*> featureScopedArray;
+ if (featuresCount) {
+ featureScopedArray.Reset(new const char*[featuresCount]);
+
+ for (size_t i = 0; i < featuresCount; ++i) {
+ featureScopedArray[i] =
+ aceFunction.features.at(i).name.c_str();
+ }
+ }
+
+ 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);
+}
+
+IWrtCameraManagerPtr WrtWrapper::getCameraManagerInterface() const
+{
+ return m_cameraManager;
+}
+
+}
+} // WrtDeviceApisCommon
--- /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_WRT_ENGINE_WRAPPER_H_
+#define WRT_PLUGINS_WRT_ENGINE_WRAPPER_H_
+
+#include <wrt_plugin_export.h>
+#include "IWrtWrapper.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class WrtWrapper : public IWrtWrapper
+{
+ public:
+ friend class WrtWrappersMgr;
+
+ public:
+
+ virtual ~WrtWrapper();
+
+ virtual int getWidgetId() const;
+
+ virtual bool checkAccess(const AceFunction &aceFunction) const;
+
+ virtual IWrtCameraManagerPtr getCameraManagerInterface() const;
+
+ private:
+
+ WrtWrapper(int widgetId, const engine_interface_t* interface);
+
+ private:
+ int m_widgetId;
+
+ const engine_interface_t* m_wrt;
+
+ IWrtCameraManagerPtr m_cameraManager;
+};
+
+}
+} // WrtDeviceApisCommon
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "WrtWrapper.h"
+#include "WrtWrappersMgr.h"
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+WrtWrappersMgr::WrtWrappersMgr()
+{
+ DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
+}
+
+WrtWrappersMgr::~WrtWrappersMgr()
+{
+}
+
+IWrtWrapperPtr WrtWrappersMgr::registerWrapper(
+ int widgetId,
+ JavaScriptContext context,
+ const engine_interface_t* interface)
+{
+ LogDebug("entered");
+ if (!context || !interface) {
+ Throw(InvalidArgumentException);
+ }
+
+ if (isWrapperRegistered(context)) {
+ return getWrtWrapper(context);
+ }
+
+ LogDebug("creation wrapper for id: " << widgetId);
+ IWrtWrapperPtr wrapper(new WrtWrapper(widgetId, interface));
+
+ addWrapper(context, wrapper);
+
+ return wrapper;
+}
+
+void WrtWrappersMgr::removeWrapper(int widgetId)
+{
+ LogDebug("entered");
+ RegisteredWrappersIterator it = m_wrappers.begin();
+
+ for (; it != m_wrappers.end(); ++it) {
+ if (it->second->getWidgetId() == widgetId) {
+ m_wrappers.erase(it);
+ return;
+ }
+ }
+ Throw(InvalidArgumentException);
+}
+
+void WrtWrappersMgr::removeWrapper(JavaScriptContext context)
+{
+ LogDebug("entered");
+ RegisteredWrappersIterator it = m_wrappers.find(context);
+
+ if (it == m_wrappers.end()) {
+ Throw(InvalidArgumentException);
+ }
+
+ m_wrappers.erase(it);
+}
+
+WrtWrappersMgr& WrtWrappersMgr::getInstance()
+{
+ LogDebug("entered");
+
+ static WrtWrappersMgr instance;
+ return instance;
+}
+
+IWrtWrapperPtr WrtWrappersMgr::getWrapper(const JavaScriptContext context)
+const
+{
+ LogDebug("entered");
+ RegisteredWrappersConstIterator it = m_wrappers.find(context);
+
+ if (it == m_wrappers.end()) {
+ Throw(OutOfRangeException);
+ }
+
+ return it->second;
+}
+
+IWrtWrapperPtr WrtWrappersMgr::getWrtWrapper(const JavaScriptContext context)
+const
+{
+ LogDebug("entered");
+
+ IWrtWrapperPtr wrapper;
+
+ Try {
+ wrapper = getWrapper(context);
+ }
+ Catch(OutOfRangeException){
+ Throw(InvalidArgumentException);
+ }
+
+ return wrapper;
+}
+
+void WrtWrappersMgr::addWrapper(JavaScriptContext context,
+ IWrtWrapperPtr wrapper)
+{
+ LogDebug("entered");
+ m_wrappers.insert(std::make_pair(context, wrapper));
+}
+
+bool WrtWrappersMgr::isWrapperRegistered(JavaScriptContext context) const
+{
+ LogDebug("entered");
+ RegisteredWrappersConstIterator it = m_wrappers.find(context);
+
+ if (it == m_wrappers.end()) {
+ return false;
+ }
+ return true;
+}
+
+}
+} // WrtDeviceApisCommon
--- /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
+ * @version 0.1
+ * @brief This file provide factory to create wrapper for api from wrt
+ */
+
+#ifndef WRT_PLUGINS_WRT_WRAPPERS_MGR_INTERFACE_H_
+#define WRT_PLUGINS_WRT_WRAPPERS_MGR_INTERFACE_H_
+
+#include <map>
+#include <dpl/noncopyable.h>
+#include <Commons/plugin_initializer_def.h>
+#include <Commons/WrtWrapper/IWrtWrapper.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class WrtWrappersMgr : private DPL::Noncopyable
+{
+ typedef std::map<JavaScriptContext, IWrtWrapperPtr> RegisteredWrappers;
+ typedef RegisteredWrappers::iterator RegisteredWrappersIterator;
+ typedef RegisteredWrappers::const_iterator RegisteredWrappersConstIterator;
+
+ public:
+
+ static WrtWrappersMgr& getInstance();
+
+ /*
+ * creates wrt wrappers for widgetId
+ * @throw Exception::Exception if creation fail
+ * @throw Exception::InvalidArgumentException if arguments are wrong
+ * if Wrapper exist
+ * */
+ virtual IWrtWrapperPtr registerWrapper(int widgetId,
+ JavaScriptContext context,
+ const engine_interface_t* interface);
+
+ /*
+ * removes previously created wrapper
+ * @throw Exception::InvalidArgumentException if creation fail
+ * if widget is not registered
+ * */
+ virtual void removeWrapper(int widgetId);
+
+ /*
+ * removes previously created wrapper
+ * @throw Exception::InvalidArgumentException if creation fail
+ * if widget is not registered
+ * */
+ virtual void removeWrapper(JavaScriptContext context);
+
+ /*
+ * a get previously created wrapper
+ * @throw Exception::InvalidArgumentException if creation fail
+ * if wrapper is not registered
+ * */
+ virtual IWrtWrapperPtr getWrtWrapper(const JavaScriptContext context) const;
+
+ virtual bool isWrapperRegistered(JavaScriptContext context) const;
+
+ virtual ~WrtWrappersMgr();
+
+ private:
+ WrtWrappersMgr();
+
+ IWrtWrapperPtr getWrapper(const JavaScriptContext context) const;
+
+ void addWrapper(JavaScriptContext context,
+ IWrtWrapperPtr wrapper);
+
+ RegisteredWrappers m_wrappers;
+};
+
+}
+} // WrtDeviceApisCommon
+
+#endif
--- /dev/null
+get_current_path()
+
+set(SRCS_WRT_WRAPPER
+ ${CURRENT_PATH}/WrtWrappersMgr.cpp
+ ${CURRENT_PATH}/WrtWrapper.cpp
+ ${CURRENT_PATH}/WrtCamera.cpp
+ ${CURRENT_PATH}/WrtCameraManager.cpp
+)
--- /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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief This is a file that you provides interface for wrt-engine while loading and using plugin
+ * If you are a plugin developer you need to plugin_initializer.cpp in your module and provide implementation for macros below
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_H_
+#define WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_H_
+
+#include <wrt_plugin_export.h>
+
+typedef java_script_context_t JavaScriptContext;
+
+#define EXPORT_SYMBOL __attribute__((__visibility__("default")))
+
+//DEFINES FOR GLOBAL OBJECTS AVAILABLE IN JAVASCRIPT
+/**
+ * each object which declare this object as parent
+ * will ba available as global object in javascript
+ */
+#define WRT_JS_EXTENSION_OBJECT_GLOBAL "GLOBAL_OBJECT"
+
+/**
+ * global object bondi
+ * */
+#define WRT_JS_EXTENSION_OBJECT_BONDI "bondi"
+
+/**
+ * global object Widget
+ * */
+#define WRT_JS_EXTENSION_OBJECT_WIDGET "Widget"
+
+/**
+ * global object deviceapis
+ * */
+#define WRT_JS_EXTENSION_OBJECT_DEVICEAPIS "deviceapis"
+
+/**
+ * global object tizen
+ * */
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+
+
+
+
+//HAVE TO BE IMPLEMENTED IN EVERY PLUGIN
+/*
+ * 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_start_callback(int widgetId, JSContextRef context, const engine_interface_t *interface)
+ * {
+ * //...
+ * }
+ * PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+ */
+#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 unloading each widget (for every unloaded widget this function will be called)
+ * Example:
+ * void on_widget_stop_callback(int widgetId)
+ * {
+ * //...
+ * }
+ * PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+ */
+#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(!) 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_initializer.cpp
+ * PLUGIN_CLASS_MAP_BEGIN
+ * PLUGIN_CLASS_MAP_ADD_CLASS("bondi",WrtPluginBondi::JSICameraManager::getClassInfo())
+ * PLUGIN_CLASS_MAP_ADD_CLASS("bondi",WrtPluginBondi::JSICameraAnotherClass::getClassInfo())
+ * 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_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;
+
+#endif // WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADERS_JS})
+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)
+
+set(TARGET_NAME ${TARGET_COMMONS_JAVASCRIPT})
+
+include_directories(${DIR_JS_COMMONS}
+ ${INCLUDE_JS_INDEPENDENT}
+ ${wrt-plugin-api_INCLUDE_DIRS}
+ ${webkit_INCLUDE_DIRS}}
+ )
+
+
+set(SRCS
+ ${CMAKE_CURRENT_SOURCE_DIR}/Converter.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/ScopedJSStringRef.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSCallbackManager.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSUtils.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/ScopedJSStringRef.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Validator.cpp
+ # wrapper for simple version of aceCheckAcces
+ ${CMAKE_CURRENT_SOURCE_DIR}/Security/SecurityFunctionDeclaration.cpp
+ #ECMA Script Exception
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSDOMException.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/DOMExceptionData.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSDOMExceptionFactory.cpp
+ #Pending Operation support
+ ${CMAKE_CURRENT_SOURCE_DIR}/JSPendingOperation.cpp
+)
+
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${webkit_LIBRARIES}
+ ${TARGET_COMMONS}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX})
+
+#utils
+install_header_file(PrivateObject.h)
+#tools
+install_header_file(Converter.h)
+install_header_file(Validator.h)
+install_header_file(JSUtils.h)
+install_header_file(ScopedJSStringRef.h)
+#callback manager
+install_header_file(JSCallbackManager.h)
+#exceptions
+install_header_file(JSDOMException.h)
+install_header_file(JSDOMExceptionFactory.h)
+install_header_file(DOMExceptionData.h)
+install_header_file(SecurityExceptions.h)
+#static declarations
+install_header_file(Security/StaticDeclaration.h)
+install_header_file(Security/SecurityFunctionDeclaration.h)
+#pending operation
+install_header_file(SupportPendingOperation.h)
+install_header_file(Utils.h)
+install_header_file(JSPendingOperation.h)
+install_header_file(JSPendingOperationPrivateObject.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 <sstream>
+#include <limits>
+#include <dpl/scoped_array.h>
+#include <dpl/scoped_free.h>
+#include "ScopedJSStringRef.h"
+#include "Converter.h"
+#include <dpl/log/log.h>
+
+using namespace WrtDeviceApis::Commons;
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+Converter::Converter(JSContextRef context) : m_context(context)
+{
+}
+
+Converter::~Converter()
+{
+}
+
+JSObjectRef Converter::toJSObjectRef(const JSValueRef& arg)
+{
+ if (!arg) {
+ Throw(NullPointerException);
+ }
+ JSValueRef exception = NULL;
+ JSObjectRef result = JSValueToObject(m_context, arg, &exception);
+ if ((NULL == result) || (NULL != exception)) {
+ ThrowMsg(ConversionException, "Couldn't convert to a JS Object.");
+ }
+ return result;
+}
+
+bool Converter::toBool(const JSValueRef& arg)
+{
+ return JSValueToBoolean(m_context, arg);
+}
+
+unsigned char Converter::toUChar(const JSValueRef& arg)
+{
+ return static_cast<unsigned char>(toChar(arg));
+}
+
+char Converter::toChar(const JSValueRef& arg)
+{
+ double tmp = toNumber_(arg);
+ return (isNan(tmp) ? 0 : static_cast<char>(tmp));
+}
+
+int Converter::toInt(const JSValueRef& arg)
+{
+ double tmp = toNumber_(arg);
+ return (isNan(tmp) ? 0 : static_cast<int>(tmp));
+}
+
+int Converter::toInt(const std::string &arg)
+{
+ return static_cast<int>(toNumber_(arg));
+}
+
+long Converter::toLong(const JSValueRef& arg)
+{
+ double tmp = toNumber_(arg);
+ return (isNan(tmp) ? 0 : static_cast<long>(tmp));
+}
+
+unsigned long Converter::toULong(const JSValueRef& arg)
+{
+ return static_cast<unsigned long>(toLong(arg));
+}
+
+std::size_t Converter::toSizeT(const JSValueRef& arg)
+{
+ double tmp = toNumber_(arg);
+ return (isNan(tmp) ? 0 : static_cast<std::size_t>(tmp));
+}
+
+std::size_t Converter::toSizeT(const JSStringRef& arg)
+{
+ return static_cast<std::size_t>(toNumber_(arg));
+}
+
+double Converter::toDouble(const JSValueRef& arg)
+{
+ return toNumber_(arg);
+}
+
+std::string Converter::toString(int arg)
+{
+ return toString_(arg);
+}
+
+std::string Converter::toString(unsigned long arg)
+{
+ return toString_(arg);
+}
+
+std::string Converter::toString(long arg)
+{
+ return toString_(arg);
+}
+
+std::string Converter::toString(std::size_t arg)
+{
+ return toString_(arg);
+}
+
+std::string Converter::toString(const JSValueRef& arg)
+{
+ return toString_(arg);
+}
+
+std::string Converter::tryString(const JSValueRef& arg)
+{
+ if (!JSValueIsString(m_context, arg) &&
+ !JSValueIsNumber(m_context, arg) &&
+ !JSValueIsBoolean(m_context, arg)) {
+ ThrowMsg(ConversionException,
+ "Argument is not convertable to JS String.");
+ }
+
+ return toString_(arg);
+}
+
+std::string Converter::toDateString(const JSValueRef& arg)
+{
+ if (!JSValueIsObject(m_context, arg)) {
+ ThrowMsg(ConversionException, "Argument is not JS Date.");
+ }
+
+ return toString_(arg);
+}
+
+std::string Converter::toString(const JSStringRef& arg)
+{
+ std::string result;
+ size_t jsSize = JSStringGetMaximumUTF8CStringSize(arg);
+ if (jsSize > 0) {
+ jsSize = jsSize + 1;
+ DPL::ScopedArray<char> buffer(new char[jsSize]);
+ size_t written = JSStringGetUTF8CString(arg, buffer.Get(), jsSize);
+ if (written > jsSize) {
+ ThrowMsg(ConversionException,
+ "Conversion could not be fully performed.");
+ }
+ result = buffer.Get();
+ }
+
+ return result;
+}
+
+time_t Converter::toDateTimeT(const JSValueRef& arg)
+{
+ struct tm tm = toDateTm(arg);
+ return mktime(&tm);
+}
+
+tm Converter::toDateTm(const JSValueRef& arg)
+{
+ std::string stringDate = toDateString(arg);
+ struct tm result;
+ char* currentLocale = setlocale(LC_TIME, NULL);
+ if (currentLocale == NULL) {
+ ThrowMsg(ConversionException, "Couldn't get current locale.");
+ }
+ DPL::ScopedFree<char> currentLocaleCopy(strdup(currentLocale));
+ if (setlocale(LC_TIME, "C") == NULL) {
+ ThrowMsg(ConversionException, "Couldn't set POSIX locale.");
+ }
+ if (strptime(stringDate.c_str(), "%a %b %d %Y %T", &result) == NULL) {
+ ThrowMsg(ConversionException, "Couldn't convert supplied date.");
+ }
+ if (setlocale(LC_TIME, currentLocaleCopy.Get()) == NULL) {
+ ThrowMsg(ConversionException, "Couldn't set previous locale back.");
+ }
+ //strptime function doesn't affect tm_isdst flag.
+ //It may cause -1hr conversion error. Setting it to -1 informs that
+ //there is no information about daylight saving time.
+ result.tm_isdst = -1;
+ return result;
+}
+
+std::vector<unsigned char> Converter::toVectorOfUChars(const JSValueRef& arg)
+{
+ return toVectorOfT_(arg, &Converter::toUChar);
+}
+
+std::vector<char> Converter::toVectorOfChars(const JSValueRef& arg)
+{
+ return toVectorOfT_(arg, &Converter::toChar);
+}
+
+std::vector<int> Converter::toVectorOfInts(const JSValueRef& arg)
+{
+ return toVectorOfT_(arg, &Converter::toInt);
+}
+
+std::vector<std::string> Converter::toVectorOfStrings(const JSValueRef& arg)
+{
+ return toVectorOfT_(arg, &Converter::toString);
+}
+
+std::vector<time_t> Converter::toVectorOfTimeT(const JSValueRef& arg) {
+ return toVectorOfT_(arg, &Converter::toDateTimeT);
+}
+
+JSValueRef Converter::toJSValueRef(bool arg)
+{
+ return JSValueMakeBoolean(m_context, arg);
+}
+
+JSValueRef Converter::toJSValueRef(int arg)
+{
+ return JSValueMakeNumber(m_context, arg);
+}
+
+JSValueRef Converter::toJSValueRef(unsigned int arg)
+{
+ return JSValueMakeNumber(m_context, arg);
+}
+
+JSValueRef Converter::toJSValueRef(unsigned long arg)
+{
+ return JSValueMakeNumber(m_context, arg);
+}
+
+JSValueRef Converter::toJSValueRefLong(const long arg) {
+ return JSValueMakeNumber(m_context, arg);
+}
+
+JSValueRef Converter::toJSValueRef(double arg)
+{
+ return JSValueMakeNumber(m_context, arg);
+}
+
+JSValueRef Converter::toJSValueRef(const std::string& arg)
+{
+ JSValueRef result = NULL;
+ JSStringRef jsString = JSStringCreateWithUTF8CString(arg.c_str());
+ result = JSValueMakeString(m_context, jsString);
+ JSStringRelease(jsString);
+ return result;
+}
+
+JSValueRef Converter::toJSValueRef(const tm& arg)
+{
+ JSValueRef args[6];
+ args[0] = JSValueMakeNumber(m_context, arg.tm_year + 1900);
+ args[1] = JSValueMakeNumber(m_context, arg.tm_mon);
+ args[2] = JSValueMakeNumber(m_context, arg.tm_mday);
+ args[3] = JSValueMakeNumber(m_context, arg.tm_hour);
+ args[4] = JSValueMakeNumber(m_context, arg.tm_min);
+ args[5] = JSValueMakeNumber(m_context, arg.tm_sec);
+
+ JSValueRef exception = NULL;
+ JSObjectRef result = JSObjectMakeDate(m_context, 6, args, &exception);
+ if (NULL != exception) {
+ ThrowMsg(ConversionException, "Couldn't convert to a JS Date.");
+ }
+
+ return result;
+}
+
+JSValueRef Converter::toJSValueRef(const time_t arg)
+{
+ struct tm *tminfo = localtime(&arg);
+ return toJSValueRef(*tminfo);
+}
+
+JSValueRef Converter::toJSValueRef(const std::vector<std::string>& arg)
+{
+ return toJSValueRef_(arg);
+}
+
+JSValueRef Converter::toJSValueRef(const char* arg)
+{
+ return toJSValueRef(std::string(arg));
+}
+
+JSValueRef Converter::toJSValueRef(const std::vector<int>& arg) {
+ return toJSValueRef_(arg);
+}
+
+JSValueRef Converter::toJSValueRef(const std::vector<time_t>& arg) {
+ return toJSValueRef_(arg);
+}
+
+JSValueRef Converter::toJSValueRef(JSValueRef arg)
+{
+ return arg;
+}
+
+JSValueRef Converter::toJSValueRef(const std::vector<JSValueRef>& arg)
+{
+ return toJSValueRef_(arg);
+}
+
+JSStringRef Converter::toJSStringRef(const std::string& arg)
+{
+ return JSStringCreateWithUTF8CString(arg.c_str());
+}
+
+double Converter::toNumber_(const JSStringRef& arg)
+{
+ return toNumber_(toString(arg));
+}
+
+double Converter::toNumber_(const std::string& arg)
+{
+ double result;
+ std::stringstream ss(arg);
+ if (!(ss >> result)) {
+ Throw(ConversionException);
+ }
+ return result;
+}
+
+double Converter::toNumber_(const JSValueRef& arg)
+{
+ JSValueRef exception = NULL;
+ double result = JSValueToNumber(m_context, arg, &exception);
+ if (NULL != exception) {
+ ThrowMsg(ConversionException, "Couldn't convert to a number.");
+ }
+ return result;
+}
+
+std::string Converter::toString_(const JSValueRef& arg)
+{
+ std::string result;
+
+ JSValueRef exception = NULL;
+ JSStringRef str = JSValueToStringCopy(m_context, arg, &exception);
+ if ((NULL == str) || (NULL != exception)) {
+ 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.");
+ }
+ result = buffer.Get();
+ }
+ JSStringRelease(str);
+ return result;
+}
+
+bool Converter::isNan(double value) const
+{
+ // This should work unless -ffast-math (GCC) option is used.
+ STATIC_CHECK(std::numeric_limits<double>::is_iec559,
+ NOT_IEEE754_REPRESENTATION);
+ return (value != value);
+}
+
+} // CommonsJavaScript
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_CONVERTER_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_CONVERTER_H_
+
+#include <ctime>
+#include <cstddef>
+#include <string>
+#include <vector>
+#include <list>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/Exception.h>
+#include <Commons/StaticAssert.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+class Converter : private DPL::Noncopyable
+{
+ public:
+ explicit Converter(JSContextRef context);
+ virtual ~Converter();
+
+ /**
+ * Converts JSValueRef to JSObjectRef.
+ * @param arg JSValueRef object to convert.
+ * @return JSObjectRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSObjectRef toJSObjectRef(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef object to boolean value.
+ * @param arg JSValueRef object to convert.
+ * @return Boolean value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ bool toBool(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef object to unsigned char value.
+ * @param arg JSValueRef object to convert.
+ * @return Unsigned char value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ unsigned char toUChar(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef object to char value.
+ * @param arg JSValueRef object to convert.
+ * @return Char value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ char toChar(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to integer value.
+ * @param arg JSValueRef object to convert.
+ * @return Integer value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ int toInt(const JSValueRef& arg);
+
+ /**
+ * Converts string to integer value.
+ * @param arg string to convert.
+ * @return Integer value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ int toInt(const std::string& arg);
+
+ /**
+ * Converts JSvalueRef to long integer value.
+ * @param arg JSValueRef object to convert.
+ * @return Long integer value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ long toLong(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to unsigned long value.
+ * @param arg JSValueRef object to convert.
+ * @return Unsigned long value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ unsigned long toULong(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to double value.
+ * @param arg JSValueRef object to convert.
+ * @return Double value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ double toDouble(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to size_t value.
+ * @param arg JSValueRef object to convert.
+ * @return Size_t value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::size_t toSizeT(const JSValueRef& arg);
+
+ /**
+ * Converts JSStringRef to size_t value.
+ * @param arg JSStringRef object to convert.
+ * @return Size_t value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::size_t toSizeT(const JSStringRef& arg);
+
+ /**
+ * Converts int to STL string.
+ * @param arg int to convert.
+ * @return STL string.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::string toString(int arg);
+
+ std::string toString(unsigned long arg);
+
+ std::string toString(long arg);
+
+ std::string toString(std::size_t arg);
+
+ /**
+ * Converts JSValueRef to STL string.
+ * @param arg JSValueRef to convert.
+ * @return STL string.
+ * @throw ConversionException Thrown when conversion fails.
+ * @remarks If one wants to convert JS Date object to a string then
+ * toDateString() should be used.
+ */
+ std::string toString(const JSValueRef& arg);
+
+ /**
+ * Converts JSStringRef to STL string.
+ * @param arg JSStringRef to convert.
+ * @return STL string.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::string toString(const JSStringRef& arg);
+
+ /**
+ * Converts JSSValueRef to STL string if
+ * arg is one of: String, Number, Bool
+ * @param arg JSValueReg to convert.
+ * @return STL string.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::string tryString(const JSValueRef& arg);
+
+ /**
+ * Converts JS Date object to STL string.
+ * @param arg JS Date object to convert.
+ * @return STL string.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::string toDateString(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to time_t value.
+ * @param arg JSValueRef to convert.
+ * @return time_t value.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ time_t toDateTimeT(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to tm struct.
+ * @param arg JSValueRef to convert.
+ * @return tm struct.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ tm toDateTm(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to vector<unsigned char>.
+ * @param arg JSValueRef to convert.
+ * @return vector<unsigned char>.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::vector<unsigned char> toVectorOfUChars(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to vector<char>.
+ * @param arg JSValueRef to convert.
+ * @return vector<char>.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::vector<char> toVectorOfChars(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to vector<int>.
+ * @param arg JSValueRef to convert.
+ * @return vector<int>.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::vector<int> toVectorOfInts(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to vector of string.
+ * @param arg JSValueRef to convert.
+ * @return std::vector<std::string>
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::vector<std::string> toVectorOfStrings(const JSValueRef& arg);
+
+ /**
+ * Converts JSValueRef to vector of time_t.
+ * @param arg JSValueRef to convert.
+ * @return std::vector<std::time_t>
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ std::vector<std::time_t> toVectorOfTimeT(const JSValueRef& arg);
+
+ /**
+ * Converts boolean value to JSValueRef.
+ * @param arg Boolean value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(bool arg);
+
+ /**
+ * Converts integer value to JSValueRef.
+ * @param arg Integer value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(int arg);
+
+ /**
+ * Converts unsigned integer value to JSValueRef.
+ * @param arg Unsigned integer value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(unsigned int arg);
+
+ /**
+ * Converts double value to JSValueRef.
+ * @param arg Double value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(double arg);
+
+ /**
+ * Converts unsigned long value to JSValueRef.
+ * @param arg unsigned long value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(unsigned long arg);
+
+ /**
+ * Converts long value to JSValueRef.
+ * @param arg long value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRefLong(const long arg);
+
+ /**
+ * Converts STL string to JSValueRef.
+ * @param arg STL string to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const std::string& arg);
+
+ /**
+ * Converts char sequence to JSValueRef.
+ * @param arg char sequence to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const char* arg);
+
+ /**
+ * Converts time_t value to JSValueRef.
+ * @param arg time_t value to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const time_t arg);
+
+ /**
+ * Converts tm struct to JSValueRef.
+ * @param arg tm struct to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const tm& arg);
+
+ /**
+ * Converts STL vector of integer to JSValueRef.
+ * @param arg STL vector of integer to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const std::vector<int>& arg);
+
+ /**
+ * Converts STL vector of time_t to JSValueRef.
+ * @param arg STL vector of time_t to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const std::vector<time_t>& arg);
+
+ /**
+ * Converts STL vector of string to JSStringRef.
+ * @param arg STL string to convert.
+ * @return JSValueRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const std::vector<std::string>& arg);
+
+ /**
+ * Converts JSValueRef to JSValueRef
+ * @param JSValueRef js value which is returned
+ * @return JSValueRef - parameter
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(JSValueRef arg);
+
+ /**
+ * Converts std::vector to JSValueRef
+ * @param arg vecotr of JSValueRefs
+ * @return JSValueRef - js array
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSValueRef toJSValueRef(const std::vector<JSValueRef>& arg);
+
+ /**
+ * Template specialization to catch errors caused
+ * by wrong usage of general template or
+ * implicit conversions from SharedPtr to
+ * specialized type
+ * */
+ template<class Class>
+ JSValueRef toJSValueRef(const DPL::SharedPtr<Class>& c)
+ {
+ STATIC_ERROR(ERROR_INVALID_IMPLICIT_CONVERSION, c)
+ //above macro causes compilation error
+ return static_cast<JSValueRef>(NULL);
+ }
+
+ /**
+ * Converts STL string to JSStringRef.
+ * @param arg STL string to convert.
+ * @return JSStringRef object.
+ * @throw ConversionException Thrown when conversion fails.
+ */
+ JSStringRef toJSStringRef(const std::string& arg);
+
+ protected:
+ bool isNan(double value) const;
+
+ double toNumber_(const JSValueRef& arg);
+
+ double toNumber_(const JSStringRef& arg);
+
+ double toNumber_(const std::string& arg);
+
+ template<typename T, class Derived>
+ std::vector<T> toVectorOfT_(const JSValueRef& arg,
+ T (Derived::*f)(const JSValueRef &),
+ Derived* object)
+ {
+ if (JSValueIsNull(m_context,
+ arg) || JSValueIsUndefined(m_context, arg)) {
+ return std::vector<T>();
+ }
+
+ if (!JSIsArrayValue(m_context, arg)) {
+ ThrowMsg(Commons::ConversionException, "Argument is not an JS array.");
+ }
+
+ std::vector<T> result;
+ JSObjectRef objArg = toJSObjectRef(arg);
+ for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); ++i) {
+ JSValueRef element = JSGetArrayElement(m_context, objArg, i);
+ result.push_back((object->*f)(element));
+ }
+ return result;
+ }
+
+ template<typename T>
+ std::vector<T> toVectorOfT_(const JSValueRef& arg,
+ T (Converter::*f)(const JSValueRef &))
+ {
+ if (JSValueIsNull(m_context,
+ arg) || JSValueIsUndefined(m_context, arg)) {
+ return std::vector<T>();
+ }
+
+ if (!JSIsArrayValue(m_context, arg)) {
+ ThrowMsg(Commons::ConversionException, "Argument is not an JS array.");
+ }
+
+ std::vector<T> result;
+ JSObjectRef objArg = toJSObjectRef(arg);
+ for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); ++i) {
+ JSValueRef element = JSGetArrayElement(m_context, objArg, i);
+ result.push_back((this->*f)(element));
+ }
+ return result;
+ }
+
+ template<class T, class Derived>
+ JSValueRef toJSValueRef_(const std::vector<T>& arg,
+ JSValueRef (Derived::*f)(const T &),
+ Derived* object)
+ {
+ JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+
+ if (NULL == jsResult) {
+ ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Could not create js array object");
+ }
+
+ for (std::size_t i = 0; i < arg.size(); ++i) {
+ JSValueRef tmpVal = (object->*f)(arg[i]);
+ if (!JSSetArrayElement(m_context, jsResult, i, tmpVal)) {
+ ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+ "Could not insert value into js array");
+ }
+ }
+
+ return jsResult;
+ }
+
+ template<class T>
+ JSValueRef toJSValueRef_(const std::vector<T>& arg)
+ {
+ JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+
+ if (NULL == jsResult) {
+ ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+ "Could not create js array object");
+ }
+
+ for (std::size_t i = 0; i < arg.size(); ++i) {
+ JSValueRef tmpVal = toJSValueRef(arg[i]);
+ if (!JSSetArrayElement(m_context, jsResult, i, tmpVal)) {
+ ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+ "Could not insert value into js array");
+ }
+ }
+
+ return jsResult;
+ }
+
+ template<class T>
+ JSValueRef toJSValueRef_(const std::list<T>& arg)
+ {
+ JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+
+ if (NULL == jsResult) {
+ ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Could not create js array object");
+ }
+
+ typename std::list<T>::const_iterator it = arg.begin();
+ for (std::size_t i = 0; it != arg.end(); ++i, ++it) {
+ JSValueRef tmpVal = toJSValueRef(*it);
+ if (!JSSetArrayElement(m_context, jsResult, i, tmpVal)) {
+ ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+ "Could not insert value into js array");
+ }
+ }
+
+ return jsResult;
+ }
+
+ template<class T, class Derived>
+ JSValueRef toJSValueRef_(const std::list<T>& arg,
+ JSValueRef (Derived::*f)(const T &),
+ Derived* object)
+ {
+ JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+
+ if (NULL == jsResult) {
+ ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Could not create js array object");
+ }
+
+ typename std::list<T>::const_iterator it = arg.begin();
+ for (std::size_t i = 0; it != arg.end(); ++i, ++it) {
+ JSValueRef tmpVal = (object->*f)(*it);
+ if (!JSSetArrayElement(m_context, jsResult, i, tmpVal)) {
+ ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+ "Could not insert value into js array");
+ }
+ }
+
+ return jsResult;
+ }
+
+ std::string toString_(const JSValueRef& arg);
+
+ template<typename T>
+ std::string toString_(const T& arg)
+ {
+ std::stringstream ss;
+ if (!(ss << arg)) {
+ ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Could not convert to string.");
+ }
+ return ss.str();
+ }
+
+ protected:
+ JSContextRef m_context;
+};
+
+template<class C>
+class ConverterFactory : private DPL::Noncopyable
+{
+ public:
+ /**
+ * Converter type which deletes itself when gets out of scope.
+ */
+ typedef DPL::SharedPtr<C> ConverterType;
+
+ public:
+ /**
+ * Gets converter object.
+ * @param context JavaScript context the conversion will be performed in.
+ * @param[out] exception JavaScript value for storing exception.
+ * @return Converter object.
+ */
+ static ConverterType getConverter(JSContextRef context)
+ {
+ C* convert = new C(context);
+ return ConverterType(convert);
+ }
+
+ private:
+ ConverterFactory();
+};
+
+typedef ConverterFactory<Converter> BasicConverterFactory;
+
+typedef BasicConverterFactory::ConverterType BasicConverter;
+
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_COMMONSJAVASCRIPT_CONVERTER_H_ */
--- /dev/null
+Common code
--- /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 "DOMExceptionData.h"
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+DOMExceptionData::DOMExceptionData(int code,
+ const std::string& message) :
+ m_code(code),
+ m_message(message)
+{
+}
+
+int DOMExceptionData::getCode() const
+{
+ return m_code;
+}
+
+std::string DOMExceptionData::getMessage() const
+{
+ return m_message;
+}
+
+} // CommonsJavaScript
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_DOM_EXCEPTION_DATA_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_DOM_EXCEPTION_DATA_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+class DOMExceptionData
+{
+ public:
+ explicit DOMExceptionData(int code,
+ const std::string& message = std::string());
+
+ int getCode() const;
+ std::string getMessage() const;
+
+ private:
+ int m_code;
+ std::string m_message;
+};
+
+typedef DPL::SharedPtr<DOMExceptionData> DOMExceptionDataPtr;
+
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif // WRT_DOM_EXCEPTION_DATA_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 JSCalendar.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "JSCallbackManager.h"
+#include <dpl/log/log.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+JSCallbackManagerPtr JSCallbackManager::createObject(JSContextRef context,
+ JSValueRef onSuccess,
+ JSValueRef onError,
+ bool acceptJSNullAsOnSuccess,
+ bool acceptJSNullAsOnError)
+{
+ LogDebug("entered");
+ JSObjectRef l_onSuccess = NULL;
+ JSObjectRef l_onError = NULL;
+
+ LogDebug("onSuccessCallback ptr=" << onSuccess);
+ LogDebug("onErrorCallback ptr=" << onError);
+ if (NULL != onSuccess &&
+ (!acceptJSNullAsOnSuccess || !JSValueIsNull(context, onSuccess))) {
+ l_onSuccess = JSValueToObject(context, onSuccess, NULL);
+ if (!l_onSuccess ||
+ !JSObjectIsFunction(context, l_onSuccess)) {
+ ThrowMsg(Commons::InvalidArgumentException,
+ "success callback is not a function");
+ }
+ } else {
+ LogWarning("onSuccessCallback is NULL and is not registred");
+ }
+ if (NULL != onError &&
+ (!acceptJSNullAsOnError || !JSValueIsNull(context, onError))) {
+ l_onError = JSValueToObject(context, onError, NULL);
+ if (!l_onError ||
+ !JSObjectIsFunction(context, l_onError)) {
+ ThrowMsg(Commons::InvalidArgumentException,
+ "error callback is not a function");
+ }
+ } else {
+ LogWarning("onErrorCallback is NULL and is not registred");
+ }
+ return JSCallbackManagerPtr(new JSCallbackManager(context, l_onSuccess,
+ l_onError));
+}
+
+JSCallbackManager::JSCallbackManager(JSContextRef context,
+ JSObjectRef onSuccess,
+ JSObjectRef onError) :
+ m_onSuccess(NULL),
+ m_onError(NULL),
+ m_context(context)
+{
+ LogDebug("entered");
+
+ setOnSuccess(onSuccess);
+ setOnError(onError);
+}
+
+JSCallbackManager::~JSCallbackManager()
+{
+ LogDebug("entered");
+
+ if (m_onSuccess) {
+ JSValueUnprotect(m_context, m_onSuccess);
+ }
+
+ if (m_onError) {
+ JSValueUnprotect(m_context, m_onError);
+ }
+}
+
+void JSCallbackManager::setOnSuccess(JSValueRef onSuccess)
+{
+ LogDebug("entered");
+ if (onSuccess) {
+ if (m_onSuccess != NULL) {
+ JSValueUnprotect(m_context, m_onSuccess);
+ }
+
+ m_onSuccess = JSValueToObject(m_context, onSuccess, NULL);
+
+ if (m_onSuccess != NULL) {
+ JSValueProtect(m_context, m_onSuccess);
+ }
+ }
+}
+
+JSValueRef JSCallbackManager::getOnSuccess() const
+{
+ LogDebug("entered");
+ return m_onSuccess;
+}
+
+void JSCallbackManager::setOnError(JSValueRef onError)
+{
+ LogDebug("entered");
+ if (onError) {
+ if (m_onError != NULL) {
+ JSValueUnprotect(m_context, m_onError);
+ }
+
+ m_onError = JSValueToObject(m_context, onError, NULL);
+
+ if (m_onError != NULL) {
+ JSValueProtect(m_context, m_onError);
+ }
+ }
+}
+
+JSValueRef JSCallbackManager::getOnError() const
+{
+ LogDebug("entered");
+ return m_onError;
+}
+
+void JSCallbackManager::setContext(JSContextRef context)
+{
+ LogDebug("entered");
+ m_context = context;
+}
+
+void JSCallbackManager::callOnSuccess()
+{
+ LogDebug("entered");
+ if (m_onSuccess == NULL) {
+ LogDebug("Success callback is not set");
+ return;
+ }
+ makeCallback(m_context, NULL, m_onSuccess, NULL, 0);
+}
+
+void JSCallbackManager::callOnSuccess(JSValueRef obj)
+{
+ LogDebug("entered");
+ if (m_onSuccess == NULL) {
+ LogDebug("Success callback is not set");
+ return;
+ }
+ JSValueRef objParam[1] = { obj };
+ makeCallback(m_context, NULL, m_onSuccess, objParam, 1);
+}
+
+void JSCallbackManager::callOnSuccess(JSValueRef obj[],
+ int paramCount)
+{
+ LogDebug("entered");
+ if (m_onSuccess == NULL) {
+ LogDebug("Success callback is not set");
+ return;
+ }
+ makeCallback(m_context, NULL, m_onSuccess, obj, paramCount);
+}
+
+void JSCallbackManager::callOnError()
+{
+ LogDebug("entered");
+ if (m_onError == NULL) {
+ LogDebug("Error callback is not set");
+ return;
+ }
+ makeCallback(m_context, NULL, m_onError, NULL, 0);
+}
+
+void JSCallbackManager::callOnError(JSValueRef obj)
+{
+ LogDebug("entered");
+ if (m_onError == NULL) {
+ LogDebug("Error callback is not set");
+ return;
+ }
+ JSValueRef objParam[1] = { obj };
+ makeCallback(m_context, NULL, m_onError, objParam, 1);
+}
+
+void JSCallbackManager::callOnError(JSValueRef obj[],
+ int paramCount)
+{
+ LogDebug("entered");
+ if (m_onError == NULL) {
+ LogDebug("Error callback is not set");
+ return;
+ }
+ makeCallback(m_context, NULL, m_onError, obj, paramCount);
+}
+
+void JSCallbackManager::makeCallback(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef callback,
+ JSValueRef argv[],
+ unsigned argc)
+{
+ LogDebug("entered");
+
+ if (callback == NULL) {
+ LogError("callback is NULL");
+ return;
+ }
+
+ if (JSObjectIsFunction(context, callback)) {
+ if (argc == 0) {
+ LogDebug("Calling object directly, no arguments");
+ JSObjectCallAsFunction(context, callback, object, 0, NULL, NULL);
+ } else {
+ LogDebug("Calling object directly, one argument");
+ JSObjectCallAsFunction(context, callback, object, argc, argv, NULL);
+ }
+ return;
+ }
+}
+
+}
+}
--- /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 JSCallbackManager.h
+ * @author Lukasz Marek (l.marel@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_CALLBACK_MANAGER_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_CALLBACK_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+class JSCallbackManager;
+typedef DPL::SharedPtr<JSCallbackManager> JSCallbackManagerPtr;
+
+class JSCallbackManager : public WrtDeviceApis::Commons::IEventPrivateData
+{
+ private:
+ JSCallbackManager()
+ {
+ }
+
+ /**
+ * Used to create JSCallbackManagerPtr object by factory method createObject
+ */
+ JSCallbackManager(JSContextRef context,
+ JSObjectRef onSuccess,
+ JSObjectRef onError);
+
+ public:
+
+ //JSCallbackManager( JSContextRef context, JSValueRef onSuccess, JSValueRef onError );
+
+ /**
+ * Create JSCallbackManagerPtr object witch checking callback parameters
+ * if callbacks are NULL it was programmer intention to not use callback and no exception will be rised
+ * if callbacks are some object but not a function it will rise exception
+ * @param[in] context - global context
+ * @param[in] onSuccess - success callback (may be NULL if not needed)
+ * @param[in] onError - error callback (may be NULL if not needed)
+ * @param[in] acceptJSNullAsOnSuccess - converts JSNull on onSuccess to NULL when true
+ * @param[in] acceptJSNullAsOnError - converts JSNull on onError to NULL when true
+ * @throw Commons::InvalidArgumentException - if callback is not null and is not a js function
+ */
+ static JSCallbackManagerPtr createObject(
+ JSContextRef context,
+ JSValueRef onSuccess = NULL,
+ JSValueRef onError = NULL,
+ bool acceptJSNullAsOnSuccess = false,
+ bool acceptJSNullAsOnError = false);
+
+ virtual ~JSCallbackManager();
+
+ void setContext(JSContextRef context);
+
+ JSContextRef getContext() const
+ {
+ return m_context;
+ }
+
+ void setOnSuccess(JSValueRef onSuccess);
+ JSValueRef getOnSuccess() const;
+ void setOnError(JSValueRef onError);
+ JSValueRef getOnError() const;
+
+ void callOnSuccess();
+ void callOnSuccess(JSValueRef obj);
+ void callOnSuccess(JSValueRef obj[], int paramCount);
+
+ void callOnError();
+ void callOnError(JSValueRef obj);
+ void callOnError(JSValueRef obj[], int paramCount);
+
+ private:
+ void makeCallback(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef callback,
+ JSValueRef argv[],
+ unsigned argc);
+
+ JSObjectRef m_onSuccess;
+ JSObjectRef m_onError;
+ JSContextRef m_context;
+ JSObjectRef m_object;
+};
+
+bool isCallback(JSContextRef ctx,
+ JSValueRef value,
+ JSValueRef* exception);
+}
+}
+
+#endif // WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_CALLBACK_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 "JSDOMException.h"
+
+#include <dpl/log/log.h>
+
+#include "Converter.h"
+
+namespace {
+const char* PLUGIN_NAME = "DOMException";
+const char* PROPERTY_CODE = "code";
+const char* PROPERTY_MESSAGE = "message";
+
+struct Error
+{
+ const char* name;
+ const unsigned short value;
+};
+// This array CAN'T be left empty!
+const Error PROPERTY_ERROR[] = {
+ { "UNKNOWN_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::UNKNOWN_ERR },
+ { "INDEX_SIZE_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::INDEX_SIZE_ERR },
+ { "DOMSTRING_SIZE_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::DOMSTRING_SIZE_ERR },
+ { "HIERARCHY_REQUEST_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::
+ HIERARCHY_REQUEST_ERR },
+ { "WRONG_DOCUMENT_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::WRONG_DOCUMENT_ERR },
+ { "INVALID_CHARACTER_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::
+ INVALID_CHARACTER_ERR },
+ { "NO_DATA_ALLOWED_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::
+ NO_DATA_ALLOWED_ERR },
+ { "NO_MODIFICATION_ALLOWED_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::
+ NO_MODIFICATION_ALLOWED_ERR },
+ { "NOT_FOUND_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::NOT_FOUND_ERR },
+ { "NOT_SUPPORTED_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::NOT_SUPPORTED_ERR },
+ { "INUSE_ATTRIBUTE_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::
+ INUSE_ATTRIBUTE_ERR },
+ { "INVALID_STATE_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::INVALID_STATE_ERR },
+ { "SYNTAX_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::SYNTAX_ERR },
+ { "INVALID_MODIFICATION_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::
+ INVALID_MODIFICATION_ERR },
+ { "NAMESPACE_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::NAMESPACE_ERR },
+ { "INVALID_ACCESS_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::INVALID_ACCESS_ERR },
+ { "VALIDATION_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::VALIDATION_ERR },
+ { "TYPE_MISMATCH_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::TYPE_MISMATCH_ERR },
+ { "SECURITY_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::SECURITY_ERR },
+ { "NETWORK_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::NETWORK_ERR },
+ { "ABORT_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::ABORT_ERR },
+ { "TIMEOUT_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::TIMEOUT_ERR },
+ { "INVALID_VALUES_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::INVALID_VALUES_ERR },
+ { "IO_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::IO_ERR },
+ { "QUOTA_EXCEEDED_ERR",
+ WrtDeviceApis::CommonsJavaScript::JSDOMException::QUOTA_EXCEEDED_ERR }
+};
+} // namespace
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+JSClassRef JSDOMException::m_classRef = NULL;
+
+JSClassDefinition JSDOMException::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ PLUGIN_NAME,
+ 0,
+ m_properties,
+ NULL, //__function,
+ initialize,
+ finalize,
+ hasProperty,
+ getProperty,
+ NULL, //SetProperty,
+ NULL, //DeleteProperty,
+ getPropertyNames,
+ NULL, //CallAsFunction,
+ NULL, //CallAsConstructor,
+ hasInstance,
+ NULL, //ConvertToType,
+};
+
+JSStaticValue JSDOMException::m_properties[] = {
+ { PROPERTY_CODE, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+ { PROPERTY_MESSAGE, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+const JSClassDefinition* JSDOMException::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+JSClassRef JSDOMException::getClassRef()
+{
+ if (!m_classRef) {
+ m_classRef = JSClassCreate(&m_classInfo);
+ }
+ return m_classRef;
+}
+
+void JSDOMException::initialize(JSContextRef /*context*/,
+ JSObjectRef /*object*/)
+{
+}
+
+void JSDOMException::finalize(JSObjectRef object)
+{
+ PrivateObject* privateObject =
+ static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+ if (privateObject) {
+ JSObjectSetPrivate(object, NULL);
+ delete privateObject;
+ }
+}
+
+bool JSDOMException::hasProperty(JSContextRef /*context*/,
+ JSObjectRef /*object*/,
+ JSStringRef propertyName)
+{
+ const size_t size = sizeof(PROPERTY_ERROR) / sizeof(PROPERTY_ERROR[0]);
+ for (size_t i = 0; i < size; ++i) {
+ if (JSStringIsEqualToUTF8CString(propertyName,
+ PROPERTY_ERROR[i].name)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+JSValueRef JSDOMException::getStaticProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* /*exception*/)
+{
+ PrivateObject* privateObject =
+ static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+ if (!privateObject) {
+ LogError("Private object is not set.");
+ return JSValueMakeUndefined(context);
+ }
+
+ Converter converter(context);
+ try {
+ if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CODE)) {
+ return converter.toJSValueRef(privateObject->getObject()->getCode());
+ } else if (JSStringIsEqualToUTF8CString(propertyName,
+ PROPERTY_MESSAGE)) {
+ return converter.toJSValueRef(
+ privateObject->getObject()->getMessage());
+ }
+ }
+ catch (const Commons::ConversionException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSDOMException::getProperty(JSContextRef context,
+ JSObjectRef /*object*/,
+ JSStringRef propertyName,
+ JSValueRef* /*exception*/)
+{
+ Converter converter(context);
+ try {
+ std::string prop = converter.toString(propertyName);
+
+ const size_t size = sizeof(PROPERTY_ERROR) / sizeof(PROPERTY_ERROR[0]);
+ for (size_t i = 0; i < size; ++i) {
+ if (prop == PROPERTY_ERROR[i].name) {
+ return converter.toJSValueRef(PROPERTY_ERROR[i].value);
+ }
+ }
+ }
+ catch (const Commons::ConversionException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+void JSDOMException::getPropertyNames(
+ JSContextRef /*context*/,
+ JSObjectRef /*object*/,
+ JSPropertyNameAccumulatorRef accumulator)
+{
+ const size_t size = sizeof(PROPERTY_ERROR) / sizeof(PROPERTY_ERROR[0]);
+ for (size_t i = 0; i < size; ++i) {
+ JSPropertyNameAccumulatorAddName(accumulator,
+ JSStringCreateWithUTF8CString(
+ PROPERTY_ERROR[i].name));
+ }
+}
+
+bool JSDOMException::hasInstance(JSContextRef context,
+ JSObjectRef /*constructor*/,
+ JSValueRef possibleInstance,
+ JSValueRef* /*exception*/)
+{
+ return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+} // CommonsJavaScript
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_DOM_EXCEPTION_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_DOM_EXCEPTION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/DOMExceptionData.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+class JSDOMException
+{
+ public:
+ typedef PrivateObjectT<DOMExceptionDataPtr>::Type PrivateObject;
+
+ public:
+ static const unsigned short UNKNOWN_ERR = 0;
+ static const unsigned short INDEX_SIZE_ERR = 1;
+ static const unsigned short DOMSTRING_SIZE_ERR = 2;
+ static const unsigned short HIERARCHY_REQUEST_ERR = 3;
+ static const unsigned short WRONG_DOCUMENT_ERR = 4;
+ static const unsigned short INVALID_CHARACTER_ERR = 5;
+ static const unsigned short NO_DATA_ALLOWED_ERR = 6;
+ static const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7;
+ static const unsigned short NOT_FOUND_ERR = 8;
+ static const unsigned short NOT_SUPPORTED_ERR = 9;
+ static const unsigned short INUSE_ATTRIBUTE_ERR = 10;
+ static const unsigned short INVALID_STATE_ERR = 11;
+ static const unsigned short SYNTAX_ERR = 12;
+ static const unsigned short INVALID_MODIFICATION_ERR = 13;
+ static const unsigned short NAMESPACE_ERR = 14;
+ static const unsigned short INVALID_ACCESS_ERR = 15;
+ static const unsigned short VALIDATION_ERR = 16;
+ static const unsigned short TYPE_MISMATCH_ERR = 17;
+ static const unsigned short SECURITY_ERR = 18;
+ static const unsigned short NETWORK_ERR = 19;
+ static const unsigned short ABORT_ERR = 20;
+ static const unsigned short TIMEOUT_ERR = 21;
+ static const unsigned short INVALID_VALUES_ERR = 22;
+ static const unsigned short IO_ERR = 100;
+
+ //TODO INVALID_VALUES_ERR has the same error code ??
+ static const unsigned short QUOTA_EXCEEDED_ERR = 22;
+
+ public:
+ static 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);
+
+ /**
+ * The callback invoked when getting a property's value.
+ */
+ static bool hasProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName);
+
+ /**
+ * The callback invoked when getting a property's value.
+ */
+ static JSValueRef getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ /**
+ * The callback invoked when getting a property's value.
+ */
+ static JSValueRef getStaticProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static void getPropertyNames(JSContextRef context,
+ JSObjectRef object,
+ JSPropertyNameAccumulatorRef accumulator);
+
+ /**
+ * The callback invoked when an object is used as the target of an 'instanceof' expression.
+ */
+ static bool hasInstance(JSContextRef context,
+ JSObjectRef constructor,
+ JSValueRef possibleInstance,
+ JSValueRef* exception);
+
+ /**
+ * This structure contains properties and callbacks that define a type of object.
+ */
+ static JSClassDefinition m_classInfo;
+
+ /**
+ * This structure describes a statically declared value property.
+ */
+ static JSStaticValue m_properties[];
+
+ static JSClassRef m_classRef;
+};
+
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#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.
+ */
+#include "JSDOMExceptionFactory.h"
+
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+
+#include "JSUtils.h"
+#include "DOMExceptionData.h"
+#include "JSDOMException.h"
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+#define DEFINE_JS_EXCEPTION_FACTORY(Class, Code) \
+ JSDOMExceptionFactory JSDOMExceptionFactory::Class(Code)
+
+DEFINE_JS_EXCEPTION_FACTORY(UnknownException, JSDOMException::UNKNOWN_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(IndexSizeException, JSDOMException::INDEX_SIZE_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(DomstringSizeException,
+ JSDOMException::DOMSTRING_SIZE_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(HierarchyRequestException,
+ JSDOMException::HIERARCHY_REQUEST_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(WrongDocumentException,
+ JSDOMException::WRONG_DOCUMENT_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(InvalidCharacterException,
+ JSDOMException::INVALID_CHARACTER_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(NoDataAllowedException,
+ JSDOMException::NO_DATA_ALLOWED_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(NoModificationAllowedException,
+ JSDOMException::NO_MODIFICATION_ALLOWED_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(NotFoundException, JSDOMException::NOT_FOUND_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(NotSupportedException,
+ JSDOMException::NOT_SUPPORTED_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(InuseAttributeException,
+ JSDOMException::INUSE_ATTRIBUTE_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(InvalidStateException,
+ JSDOMException::INVALID_STATE_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(SyntaxException, JSDOMException::SYNTAX_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(InvalidModificationException,
+ JSDOMException::INVALID_MODIFICATION_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(NamespaceException, JSDOMException::NAMESPACE_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(InvalidAccessException,
+ JSDOMException::INVALID_ACCESS_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(ValidationException, JSDOMException::VALIDATION_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(TypeMismatchException,
+ JSDOMException::TYPE_MISMATCH_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(SecurityException, JSDOMException::SECURITY_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(NetworkException, JSDOMException::NETWORK_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(AbortException, JSDOMException::ABORT_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(TimeoutException, JSDOMException::TIMEOUT_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(InvalidValuesException,
+ JSDOMException::INVALID_VALUES_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(IOException, JSDOMException::IO_ERR);
+DEFINE_JS_EXCEPTION_FACTORY(QuotaExceededException,
+ JSDOMException::QUOTA_EXCEEDED_ERR);
+
+JSDOMExceptionFactory::JSDOMExceptionFactory(int code) : m_code(code)
+{
+}
+
+JSValueRef JSDOMExceptionFactory::make(JSContextRef context,
+ JSValueRef* exception,
+ const std::string& message)
+{
+ Assert(exception && "Exception object can't be NULL.");
+ JSDOMException::PrivateObject::ObjectType data(new DOMExceptionData(m_code,
+ message));
+ *exception = JSUtils::makeObject(context,
+ JSDOMException::getClassRef(),
+ data);
+ return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSDOMExceptionFactory::make(JSContextRef context,
+ const std::string& message)
+{
+ JSDOMException::PrivateObject::ObjectType data(new DOMExceptionData(m_code,
+ message));
+ return JSUtils::makeObject(context,
+ JSDOMException::getClassRef(), data);
+}
+
+} // CommonsJavaScript
+} // 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.
+ */
+#ifndef WRT_DOM_EXCEPTION_FACTORY_H_
+#define WRT_DOM_EXCEPTION_FACTORY_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+#define DECLARE_JS_EXCEPTION_FACTORY(Class) static JSDOMExceptionFactory Class
+
+class JSDOMExceptionFactory : public DPL::Noncopyable
+{
+ public:
+ DECLARE_JS_EXCEPTION_FACTORY(UnknownException);
+ DECLARE_JS_EXCEPTION_FACTORY(IndexSizeException);
+ DECLARE_JS_EXCEPTION_FACTORY(DomstringSizeException);
+ DECLARE_JS_EXCEPTION_FACTORY(HierarchyRequestException);
+ DECLARE_JS_EXCEPTION_FACTORY(WrongDocumentException);
+ DECLARE_JS_EXCEPTION_FACTORY(InvalidCharacterException);
+ DECLARE_JS_EXCEPTION_FACTORY(NoDataAllowedException);
+ DECLARE_JS_EXCEPTION_FACTORY(NoModificationAllowedException);
+ DECLARE_JS_EXCEPTION_FACTORY(NotFoundException);
+ DECLARE_JS_EXCEPTION_FACTORY(NotSupportedException);
+ DECLARE_JS_EXCEPTION_FACTORY(InuseAttributeException);
+ DECLARE_JS_EXCEPTION_FACTORY(InvalidStateException);
+ DECLARE_JS_EXCEPTION_FACTORY(SyntaxException);
+ DECLARE_JS_EXCEPTION_FACTORY(InvalidModificationException);
+ DECLARE_JS_EXCEPTION_FACTORY(NamespaceException);
+ DECLARE_JS_EXCEPTION_FACTORY(InvalidAccessException);
+ DECLARE_JS_EXCEPTION_FACTORY(ValidationException);
+ DECLARE_JS_EXCEPTION_FACTORY(TypeMismatchException);
+ DECLARE_JS_EXCEPTION_FACTORY(SecurityException);
+ DECLARE_JS_EXCEPTION_FACTORY(NetworkException);
+ DECLARE_JS_EXCEPTION_FACTORY(AbortException);
+ DECLARE_JS_EXCEPTION_FACTORY(TimeoutException);
+ DECLARE_JS_EXCEPTION_FACTORY(InvalidValuesException);
+ DECLARE_JS_EXCEPTION_FACTORY(IOException);
+ DECLARE_JS_EXCEPTION_FACTORY(QuotaExceededException);
+
+ public:
+ explicit JSDOMExceptionFactory(int code);
+
+ /**
+ * Creates exception object.
+ * @param context JS context of the exception.
+ * @param[out] exception Result object to which exception will be assigned.
+ * @return JS undefined value.
+ * @code
+ * JSValueRef JSClass::getProperty(JSContextRef context,
+ * JSObjectRef object,
+ * JSStringRef propertyName,
+ * JSValueRef* exception)
+ * {
+ * ...
+ * return JSExceptionFactory::InvalidArgumentException.make(context, exception);
+ * ...
+ * }
+ * @endcode
+ */
+ JSValueRef make(JSContextRef context,
+ JSValueRef* exception,
+ const std::string& message = std::string());
+
+ /**
+ * Creates exception object.
+ * @param context JS context of the exception.
+ * @return JS exception object.
+ * @code
+ * JSObjectRef jsError = JSExceptionFactory::InvalidArgumentException.make(context);
+ * @endcode
+ */
+ JSObjectRef make(JSContextRef context,
+ const std::string& message = std::string());
+
+ private:
+ int m_code;
+};
+
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#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 JSPendingOperation.cpp
+ * @author Pete Cole (peter.cole@partner.samsung.com)
+ * @version 0.1
+ * 0.2 k.majewski@samsung.com
+ * @brief Implementation of the JSPendingOperation class
+ */
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "JSPendingOperation.h"
+#include "JSPendingOperationPrivateObject.h"
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+namespace {
+const char* PLUGIN_NAME = "PendingOperation";
+}
+
+JSClassRef JSPendingOperation::m_classRef = NULL;
+
+JSClassDefinition JSPendingOperation::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ PLUGIN_NAME,
+ 0,
+ NULL,
+ m_functions,
+ initialize,
+ finalize,
+ NULL, //hasProperty,
+ NULL, //GetProperty,
+ NULL, //SetProperty,
+ NULL, //DeleteProperty,
+ NULL, //getPropertyNames,
+ NULL,
+ NULL,
+ NULL,
+ NULL, //ConvertToType,
+};
+
+JSStaticFunction JSPendingOperation::m_functions[] = {
+ { "cancel", cancel, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+JSClassRef JSPendingOperation::getClassRef()
+{
+ if (!m_classRef) {
+ m_classRef = JSClassCreate(&m_classInfo);
+ }
+ return m_classRef;
+}
+
+void JSPendingOperation::initialize(JSContextRef /*context*/,
+ JSObjectRef object)
+{
+ assert(NULL != JSObjectGetPrivate(object));
+}
+
+void JSPendingOperation::finalize(JSObjectRef object)
+{
+ delete static_cast<IJSPendingOperationPrivateObject *>(
+ JSObjectGetPrivate(object));
+}
+
+JSValueRef JSPendingOperation::cancel(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ (void) object;
+ (void) argumentCount;
+ (void) arguments;
+ (void) exception;
+ LogDebug(__FUNCTION__);
+ IJSPendingOperationPrivateObject *priv =
+ static_cast<IJSPendingOperationPrivateObject *>(
+ JSObjectGetPrivate(thisObject));
+ assert(NULL != priv);
+ bool cancelResult = priv->cancel();
+ LogDebug("cancel result : " << cancelResult);
+ return JSValueMakeBoolean(context, cancelResult);
+}
+} // CommonsJavaScript
+} // 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 JSPendingOperation.h
+ * @author Pete Cole (peter.cole@partner.samsung.com)
+ * @version 0.1
+ * 0.2 k.majewski@samsung.com
+ * @brief Declaration of the JSPendingOperation class
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_PENDINGOPERATION_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_PENDINGOPERATION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+//typedef Commons::PrivateObjectT<IJSPendingOperationPrivateObject*>::Type PendingOperationPrivateObject;
+
+class JSPendingOperation
+{
+ public:
+ /*
+ * This initializes this JS class in the JS Engine.
+ */
+ static JSClassRef getClassRef();
+
+ 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 contains properties and callbacks that define a type of object.
+ */
+ static JSClassDefinition m_classInfo;
+
+ /**
+ * This structure describes a statically declared function property.
+ */
+ static JSStaticFunction m_functions[];
+
+ static JSClassRef m_classRef;
+
+ /**
+ * Cancel the pending operation, if it has yet not completed.
+ */
+ static JSValueRef cancel(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+};
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif // _JS_WAC_PENDINGOPERATION_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_PENDING_OPERATION_PRIVATE_OBJECT_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_PENDING_OPERATION_PRIVATE_OBJECT_H_
+
+#include <cassert>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/IExternEventCanceler.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+class IJSPendingOperationPrivateObject
+{
+ public:
+ explicit IJSPendingOperationPrivateObject(
+ const DPL::SharedPtr<Commons::IEventController>
+ &event) :
+ m_event(event)
+ {
+ assert(NULL != m_event);
+ }
+
+ virtual bool cancel()
+ {
+ LogDebug("PendingOperation tries to cancel the request");
+ return m_event->cancelRequest();
+ }
+
+ virtual ~IJSPendingOperationPrivateObject()
+ {
+ }
+
+ protected:
+ DPL::SharedPtr<Commons::IEventController> m_event;
+};
+
+/*
+ * This class implements private object for JavaScript PendingOperation
+ * with support to external cancel function.
+ *
+ * When the cancel() method is invoked on PendingOperation,
+ * the OnCancelEvent(<EventType>) method is invoked on user object
+ * with apropriate * arguments.
+ * It allows user to perform an additional action when PendingOperation
+ * is destroyed.
+ *
+ * The Object which want to handle OnCancelEvent have to inherit from
+ * Platform::IExternEventCanceler<EventType>.
+ *
+ * The cancel's handler have to be passed as second argument
+ * */
+template<class TemplateEvent>
+class IJSExtCancelPendingOperationPrivateObject :
+ public IJSPendingOperationPrivateObject
+{
+ public:
+ IJSExtCancelPendingOperationPrivateObject(
+ const DPL::SharedPtr< TemplateEvent> &event,
+ const DPL::SharedPtr<
+ Commons::IExternEventCanceler<TemplateEvent> > & cancel) :
+ IJSPendingOperationPrivateObject(
+ DPL::StaticPointerCast<Commons::IEventController>(event)),
+ m_canceler(cancel)
+ {
+ assert(NULL != m_canceler);
+ }
+
+ virtual bool cancel()
+ {
+ bool result = IJSPendingOperationPrivateObject::cancel();
+ if (!result) {
+ LogDebug("Controller can not cancel event, trying platform cancel");
+ } else {
+ return result;
+ }
+
+ if (m_canceler) {
+ LogDebug("Calling extern cancel");
+ m_canceler->OnCancelEvent(
+ DPL::StaticPointerCast<TemplateEvent>(m_event));
+ }
+
+ return result;
+ }
+
+ virtual ~IJSExtCancelPendingOperationPrivateObject()
+ {
+ }
+
+ protected:
+ DPL::SharedPtr< Commons::IExternEventCanceler<TemplateEvent> > m_canceler;
+};
+}
+}
+#endif /* _JS_WAC_PENDING_OPERATION_PRIVATE_OBJECT_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 "Converter.h"
+#include "ScopedJSStringRef.h"
+#include "JSUtils.h"
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+using namespace WrtDeviceApis::Commons;
+
+
+bool JSUtils::hasProperty(JSStaticValue* properties,
+ JSStringRef name)
+{
+ JSStaticValue* property = properties;
+ while (property->name) {
+ if (JSStringIsEqualToUTF8CString(name, property->name)) {
+ return true;
+ }
+ ++property;
+ }
+ return false;
+}
+
+JSValueRef JSUtils::getJSProperty(JSContextRef context,
+ JSValueRef jsValue,
+ const std::string &name,
+ JSValueRef *exception)
+{
+ ScopedJSStringRef jsPropName(JSStringCreateWithUTF8CString(name.c_str()));
+ Converter converter(context);
+ JSObjectRef jsObject = converter.toJSObjectRef(jsValue);
+ if (JSObjectHasProperty(context, jsObject, jsPropName.get())) {
+ return JSObjectGetProperty(context, jsObject,
+ jsPropName.get(), exception);
+ }
+ return NULL;
+}
+
+JSValueRef JSUtils::getJSProperty(JSContextRef context,
+ JSObjectRef object,
+ const std::string& name)
+{
+ Converter converter(context);
+ Try {
+ ScopedJSStringRef propName(converter.toJSStringRef(name));
+ if (JSObjectHasProperty(context, object, propName.get())) {
+ JSValueRef result = JSObjectGetProperty(context,
+ object,
+ propName.get(),
+ NULL);
+ if (!JSValueIsUndefined(context, result)) {
+ return result;
+ }
+ }
+ }
+ Catch(ConversionException) {
+ }
+ return NULL;
+}
+
+JSValueRef JSUtils::getJSPropertyOrUndefined(JSContextRef context,
+ JSObjectRef object,
+ const std::string& name)
+{
+ Converter converter(context);
+ Try {
+ ScopedJSStringRef propName(converter.toJSStringRef(name));
+ if (JSObjectHasProperty(context, object, propName.get())) {
+ return JSObjectGetProperty(context, object, propName.get(), NULL);
+ }
+ }
+ Catch(ConversionException) {
+ }
+ return JSValueMakeUndefined(context);
+}
+} // CommonsJavaScript
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_JSUTILS_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_JSUTILS_H_
+
+#include <string>
+#include <dpl/log/log.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+class JSUtils
+{
+ public:
+ static bool hasProperty(JSStaticValue* properties,
+ JSStringRef name);
+
+ /**
+ * Gets a property from JSObject if exists
+ * @return JSValueRef if property exists, NULL if not
+ */
+ static JSValueRef getJSProperty(JSContextRef context,
+ JSValueRef jsValue,
+ const std::string &name,
+ JSValueRef* exception = NULL);
+
+ static JSValueRef getJSProperty(JSContextRef context,
+ JSObjectRef object,
+ const std::string& name);
+
+ static JSValueRef getJSPropertyOrUndefined(JSContextRef context,
+ JSObjectRef object,
+ const std::string& name);
+
+ template<class C>
+ static JSObjectRef makeObject(JSContextRef context,
+ JSClassRef classRef,
+ C data)
+ {
+ typedef typename PrivateObjectT<C>::Type Private;
+
+ Private* priv = new Private(context, data);
+ JSObjectRef object = JSObjectMake(context, classRef, priv);
+ if (!object) {
+ ThrowMsg(Commons::NullPointerException, "Could not create JS object.");
+ }
+
+ return object;
+ }
+
+ static JSObjectRef makeObject(JSContextRef context,
+ JSClassRef classRef)
+ {
+ typedef PrivateObjectT<void>::Type Private;
+
+ Private* priv = new Private(context);
+ JSObjectRef object = JSObjectMake(context, classRef, priv);
+ if (!object) {
+ ThrowMsg(Commons::NullPointerException, "Could not create JS object.");
+ }
+
+ return object;
+ }
+}; // JSUtils
+
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif /* WRTPLUGINS_COMMONS_JSUTILS_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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_PRIVATEOBJECT_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_PRIVATEOBJECT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/noncopyable.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <Commons/TypeTraits.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+template<class T>
+struct NoAcquire
+{
+ void acquire(T*)
+ {
+ }
+ protected:
+ ~NoAcquire()
+ {
+ }
+};
+
+template<class T>
+struct AcquireByProtect
+{
+ void acquire(T* object)
+ {
+ Assert(object && "Object passed to protect can't be NULL.");
+ JSValueProtect(object->getContext(), object->getObject());
+ }
+ protected:
+ ~AcquireByProtect()
+ {
+ }
+};
+
+template<class T>
+struct NoRelease
+{
+ void release(T* object)
+ {
+ (void)object;
+ }
+ protected:
+ ~NoRelease()
+ {
+ }
+};
+
+template<class T>
+struct ReleaseByDelete
+{
+ void release(T* object)
+ {
+ delete object->getObject();
+ }
+ protected:
+ ~ReleaseByDelete()
+ {
+ }
+};
+
+template<class T>
+struct ReleaseByUnprotect
+{
+ void release(T* object)
+ {
+ Assert(object && "Object passed to unprotect can't be NULL.");
+ JSValueUnprotect(object->getContext(), object->getObject());
+ }
+ protected:
+ ~ReleaseByUnprotect()
+ {
+ }
+};
+
+template<class T>
+struct NoOwnership : protected NoAcquire<T>,
+ protected NoRelease<T>
+{
+ protected:
+ ~NoOwnership()
+ {
+ }
+};
+
+template<class T>
+struct OwnershipByAcquisition : protected NoAcquire<T>,
+ protected ReleaseByDelete<T>
+{
+ protected:
+ ~OwnershipByAcquisition()
+ {
+ }
+};
+
+template<class T>
+struct OwnershipByProtection : protected AcquireByProtect<T>,
+ protected ReleaseByUnprotect<T>
+{
+ protected:
+ ~OwnershipByProtection()
+ {
+ }
+};
+
+template<class PrivateClass,
+ template <class> class OwnershipPolicy = OwnershipByAcquisition>
+class PrivateObject : public DPL::Noncopyable,
+ protected OwnershipPolicy<PrivateObject<PrivateClass, OwnershipPolicy> >
+{
+ public:
+ typedef PrivateClass ObjectType;
+
+ public:
+ /**
+ * Creates storage object for JS private data.
+ * @param context JS (root/global) context.
+ * @param object Object to store.
+ * @throw NullPointerException When object is pointer and is set to NULL.
+ */
+ PrivateObject(JSContextRef context,
+ const PrivateClass& object) :
+ m_context(context),
+ m_object(object)
+ {
+ Assert(NULL != m_context && "Context is NULL.");
+ Assert(!Commons::IsNull<PrivateClass>::value(object) && "Object is NULL.");
+ acquire(this);
+ }
+
+ /**
+ * Destroys instance of the object.
+ */
+ virtual ~PrivateObject()
+ {
+ release(this);
+ }
+
+ /**
+ * Gets stored JS context.
+ * @return JavaScript context.
+ */
+ virtual JSContextRef getContext() const
+ {
+ return m_context;
+ }
+
+ /**
+ * Gets stored object.
+ * @return Stored object.
+ */
+ virtual PrivateClass getObject() const
+ {
+ return m_object;
+ }
+
+ protected:
+ JSContextRef m_context; ///< JS context.
+ PrivateClass m_object; ///< Stored object.
+};
+
+/**
+ * Specialization for type void.
+ */
+template<>
+class PrivateObject<void, NoOwnership> : private DPL::Noncopyable
+{
+ public:
+ /**
+ * Creates storage object for JS private data.
+ * @param context JS (root/global) context.
+ * @remarks Takes ownership over stored object.
+ */
+ explicit PrivateObject(JSContextRef context) : m_context(context)
+ {
+ Assert(NULL != m_context && "Context is NULL.");
+ }
+
+ /**
+ * Destroys instance of the object.
+ */
+ virtual ~PrivateObject()
+ {
+ }
+
+ /**
+ * Gets stored JS context.
+ * @return JavaScript context.
+ */
+ virtual JSContextRef getContext() const
+ {
+ return m_context;
+ }
+
+ protected:
+ JSContextRef m_context;
+};
+
+template<class C>
+struct PrivateObjectT
+{
+ typedef PrivateObject<C, NoOwnership> Type;
+};
+
+template<class C>
+struct PrivateObjectT<C*>
+{
+ typedef PrivateObject<C*, OwnershipByAcquisition> Type;
+};
+
+template<>
+struct PrivateObjectT<JSObjectRef>
+{
+ typedef PrivateObject<JSObjectRef, NoOwnership> Type;
+};
+
+template<>
+struct PrivateObjectT<void>
+{
+ typedef PrivateObject<void, NoOwnership> Type;
+};
+
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif /* PRIVATEOBJECT_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 "ScopedJSStringRef.h"
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+ScopedJSStringRef::ScopedJSStringRef(JSStringRef ref) : m_ref(ref)
+{
+}
+
+ScopedJSStringRef::~ScopedJSStringRef()
+{
+ if (m_ref != NULL) {
+ JSStringRelease(m_ref);
+ }
+}
+
+JSStringRef ScopedJSStringRef::get() const
+{
+ return m_ref;
+}
+} // CommonsJavaScript
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_SCOPEDJSSTRINGREF_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_SCOPEDJSSTRINGREF_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/noncopyable.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+/**
+ * Takes ownership over JSStringRef object to call JSSTringRelease on it
+ * when this object goes out of scope.
+ */
+class ScopedJSStringRef : private DPL::Noncopyable
+{
+ public:
+ /**
+ * Creates this class instance.
+ * @param ref JSStringRef to take ownership.
+ * @remarks Takes ownership.
+ */
+ ScopedJSStringRef(JSStringRef ref);
+
+ /**
+ * Destroys instance.
+ * @remarks Releases stored JSStringRef.
+ */
+ ~ScopedJSStringRef();
+
+ /**
+ * Gets stored JSStringRef.
+ * @return JSStringRef object.
+ * @remarks Doesn't pass ownership to caller.
+ */
+ JSStringRef get() const;
+
+ private:
+ JSStringRef m_ref;
+};
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_COMMONSJAVASCRIPT_SCOPEDJSSTRINGREF_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 "SecurityFunctionDeclaration.h"
+#include <JavaScriptCore/JavaScript.h>
+
+namespace WrtDeviceApis {
+
+namespace CommonsJavaScript {
+
+
+AceSecurityStatus aceCheckAccessSimple(
+ JSContextRef globalContext,
+ WrtDeviceApis::Commons::AceFunction aceFunction)
+{
+ return aceCheckAccess2<DefaultArgsVerifier<>>(globalContext,
+ aceFunction);
+}
+
+}
+
+}
\ 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.
+ */
+#ifndef _FUNCTION_DECLARATION_
+#define _FUNCTION_DECLARATION_
+
+#include <string>
+#include <Commons/WrtWrapper/WrtWrappersMgr.h>
+#include <Commons/Exception.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/TypesDeclaration.h>
+#include <Commons/TypeTraits.h>
+#include <dpl/log/log.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+enum class AceSecurityStatus
+{
+ AccessGranted,
+ AccessDenied,
+ InternalError
+};
+
+template <typename ... Args>
+class DefaultArgsVerifier
+{
+ public:
+ void operator()(WrtDeviceApis::Commons::AceFunction& aceFunction,
+ Args && ... args) const
+ {
+ static_assert(
+ WrtDeviceApis::Commons::AlwaysFalse<Args ...>::value,
+ "Please provide a specialization for these argument types!");
+ }
+};
+
+template <>
+class DefaultArgsVerifier<>
+{
+ public:
+ void operator()(WrtDeviceApis::Commons::AceFunction& /*aceFunction*/) const
+ {
+ }
+};
+
+template <typename ArgumentsVerifier,
+ typename ... Args>
+AceSecurityStatus aceCheckAccess2(JSContextRef globalContext,
+ WrtDeviceApis::Commons::AceFunction aceFunction,
+ Args && ... args)
+{
+ ArgumentsVerifier argsVerify;
+ argsVerify(aceFunction, args ...);
+
+ Try {
+ WrtDeviceApis::Commons::IWrtWrapperPtr wrapper =
+ WrtDeviceApis::Commons::WrtWrappersMgr::getInstance().getWrtWrapper(
+ globalContext);
+
+ if (!(wrapper->checkAccess(aceFunction))) {
+ LogDebug("Function is not allowed to run");
+ return AceSecurityStatus::AccessDenied;
+ }
+ }
+ Catch(WrtDeviceApis::Commons::OutOfRangeException) {
+ LogError("Wrapper doesn't exist.");
+ return AceSecurityStatus::InternalError;
+ }
+
+ LogDebug("Function accepted!");
+
+ return AceSecurityStatus::AccessGranted;
+}
+
+
+
+//The simplest version
+AceSecurityStatus aceCheckAccessSimple(JSContextRef globalContext,
+ WrtDeviceApis::Commons::AceFunction aceFunction);
+
+}
+}
+
+#endif // _FUNCTION_DECLARARION_
--- /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 _WRTPLUGINS_COMMONS_SRC_COMMONS_STATICDECLARATIOS_H_
+#define _WRTPLUGINS_COMMONS_SRC_COMMONS_STATICDECLARATIOS_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <dpl/noncopyable.h>
+#include <dpl/assert.h>
+#include <dpl/foreach.h>
+#include <Commons/TypesDeclaration.h>
+
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+template<typename ParamType,
+ typename DeviceCapType,
+ typename FunctionType>
+class StaticDeclarations : public DPL::Noncopyable
+{
+ struct FunctionTriplet {
+ const char* name;
+ std::vector<DeviceCapType> devCaps;
+ std::vector<const char*> features;
+ };
+ public:
+
+
+ typedef typename std::map<ParamType, const char*> ParamsMap;
+
+ typedef std::map<DeviceCapType,
+ std::pair<const char*,
+ std::vector<ParamType> > > DeviceCapsMaps;
+
+ typedef std::map<FunctionType, FunctionTriplet > FunctionsMap;
+
+ typedef std::map<FunctionType, WrtDeviceApis::Commons::AceFunction>
+ AceFunctionsMap;
+
+ typedef std::map<std::string, std::vector<DeviceCapType> > FeaturesMap;
+
+ static const std::string getParamName(const ParamType& paramId)
+ {
+ auto it = m_params.find(paramId);
+
+ Assert(it != m_params.end() && "No such paramId");
+
+ return it->second;
+ }
+
+ /**
+ * Returns set of device capabilities WITHOUT params
+ * for given device capability id
+ * */
+ static WrtDeviceApis::Commons::AceDeviceCapability
+ getDeviceCapabilityWithoutParams(const DeviceCapType& devCapsId)
+ {
+ WrtDeviceApis::Commons::AceDeviceCapability deviceCap;
+ auto it = m_deviceCaps.find(devCapsId);
+
+ Assert(it != m_deviceCaps.end() && "No such device cap");
+
+ deviceCap.devCapName = it->second.first;
+
+ return deviceCap;
+ }
+
+ /**
+ * Returns set of device capabilities with set params
+ * for given device capability id
+ * */
+ static WrtDeviceApis::Commons::AceDeviceCapability
+ getDeviceCapability(const DeviceCapType& devCapsId)
+ {
+ auto it = m_deviceCaps.find(devCapsId);
+
+ Assert(it != m_deviceCaps.end() && "No such dev-cap found");
+
+ WrtDeviceApis::Commons::AceDeviceCapability deviceCap;
+ deviceCap.devCapName = it->second.first;
+
+ FOREACH(paramIt, it->second.second)
+ {
+ WrtDeviceApis::Commons::AceDeviceCapParam param(
+ getParamName(*paramIt),
+ std::string());
+
+ deviceCap.devCapParams.push_back(param);
+ }
+
+ return deviceCap;
+ }
+
+ static void addDeviceCapabilty(
+ const DeviceCapType& devCapsId,
+ WrtDeviceApis::Commons::AceFunction& aceFunction)
+ {
+ aceFunction.deviceCapabilities.push_back(
+ getDeviceCapability(devCapsId));
+ }
+
+ /**
+ * Returns names of device-capabilities base on capability id
+ */
+ static std::string getDevCapNameById(DeviceCapType devCapId)
+ {
+ auto it = m_deviceCaps.find(devCapId);
+ Assert(it != m_deviceCaps.end() && "No such devcapid found!");
+ return it->second.first;
+ }
+
+ /**
+ * Sets parameter value for given paramId
+ */
+ static bool setParamValue(WrtDeviceApis::Commons::AceFunction& function,
+ ParamType paramId,
+ DeviceCapType devCapId,
+ const std::string& value)
+ {
+ //get name of the deviceCaps
+ std::string devCapName = getDevCapNameById(devCapId) ;
+ std::string paramName = getParamName(paramId);
+
+ //search throw all the device capabilities
+ FOREACH(devCapIt, function.deviceCapabilities) {
+ if(devCapIt->devCapName == devCapName) {
+ //device capability has been found
+ //check params
+ FOREACH(devParamIt, devCapIt->devCapParams) {
+ if(devParamIt->name == paramName) {
+ devParamIt->value = value;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+ /**
+ * Return struct Commons::AceFunction with set function name
+ *
+ * To set device capabilities you may use setDeviceCap function
+ * To set param value function you may use setParamValue Function
+ * */
+ static WrtDeviceApis::Commons::AceFunction getEmptyFunction(
+ const FunctionType& functionId)
+ {
+ WrtDeviceApis::Commons::AceFunction function;
+ auto it = m_functions.find(functionId);
+ Assert(it != m_functions.end() && "No such a function");
+ function.name = it->second.first;
+
+ return function;
+ };
+
+ /**
+ * The most useful Function
+ * Return Commons::AceFunction with filled all required fields:
+ * name, device caps and proper param namespace
+ *
+ * To set param value function you may use setParamValue function
+ * */
+ static WrtDeviceApis::Commons::AceFunction getSecurityFunction(
+ const FunctionType& functionId)
+ {
+ WrtDeviceApis::Commons::AceFunction function;
+ auto it = m_functions.find(functionId);
+ Assert(it != m_functions.end() && "No such function found!");
+
+ function.name = it->second.name;
+
+ FOREACH (featIt, it->second.features)
+ function.features.push_back(std::string(*featIt));
+
+ FOREACH(devCapIt, it->second.devCaps) {
+ function.deviceCapabilities.push_back(
+ getDeviceCapability(*devCapIt));
+ }
+ return function;
+ };
+
+ /**
+ * To create static map
+ * */
+ static void createStaticAceFunctions()
+ {
+ FOREACH(functionIt, m_functions)
+ {
+ m_aceFunctions[functionIt->first] =
+ getSecurityFunction(functionIt->first);
+ }
+ }
+
+private:
+ static ParamsMap m_params;
+ static DeviceCapsMaps m_deviceCaps;
+ static FunctionsMap m_functions;
+ static AceFunctionsMap m_aceFunctions;
+
+ static FeaturesMap m_features;
+};
+
+}
+}
+
+#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.
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_SECURITYEXCEPTIONS_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_SECURITYEXCEPTIONS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "JSDOMExceptionFactory.h"
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+/**
+ * synchronously checks access status and throws JS Security exception if
+ * necessary
+ */
+#define SYNC_ACCESS_STATUS_HANDLER(status, context, exception) \
+ do { \
+ switch (status) \
+ { \
+ case AceSecurityStatus::InternalError: \
+ return JSDOMExceptionFactory::UnknownException.make( \
+ context, exception); \
+ break; \
+ \
+ case AceSecurityStatus::AccessDenied: \
+ return JSDOMExceptionFactory::SecurityException.make( \
+ context, exception); \
+ break; \
+ \
+ default: \
+ break; \
+ } \
+ } while (0)
+
+/**
+ * checks access status and returns an error through JSCallbackManager if
+ * necessary
+ */
+#define ASYNC_CBM_ACCESS_STATUS_HANDLER(status, context, cbm) \
+ do { \
+ switch (status) \
+ { \
+ case AceSecurityStatus::InternalError: \
+ cbm->callOnError(JSDOMExceptionFactory::UnknownException.make( \
+ context)); \
+ return JSValueMakeNull(context); \
+ \
+ case AceSecurityStatus::AccessDenied: \
+ cbm->callOnError(JSDOMExceptionFactory::SecurityException.make( \
+ context)); \
+ return JSValueMakeNull(context); \
+ \
+ default: \
+ break; \
+ } \
+ } while (0)
+
+}
+}
+#endif /*WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_SECURITYEXCEPTIONS_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
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_SUPPORT_PENDING_OPERATION_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_SUPPORT_PENDING_OPERATION_H_
+
+#include <dpl/optional.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+template<typename T>
+class SupportPendingOperation
+{
+public:
+ virtual T getPendingOperation() const {
+ return *m_operation;
+ }
+
+ virtual void setPendingOperation(const T& operation){
+ m_operation = operation;
+ }
+
+ bool checkPendingOperation() const{
+ return !m_operation.IsNull();
+ }
+
+ virtual ~SupportPendingOperation(){}
+
+protected:
+ DPL::Optional<T> m_operation;
+};
+
+}
+}
+
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+/**
+ * Creates pending operation object.
+ * @param context Global context.
+ * @param event Event or other object enclosed in shared ptr and convertible
+ * to @see WrtDeviceApis::Commons::IEventController.
+ * @return Pending operation object.
+ */
+template<typename EventType>
+JSObjectRef makePendingOperation(JSContextRef context,
+ const DPL::SharedPtr<EventType>& event)
+{
+ Commons::IEventControllerPtr eventController =
+ DPL::StaticPointerCast<Commons::IEventController>(event);
+ IJSPendingOperationPrivateObject* pendingOperation =
+ new IJSPendingOperationPrivateObject(eventController);
+ return JSObjectMake(context,
+ JSPendingOperation::getClassRef(), pendingOperation);
+}
+
+template<typename EventType>
+JSObjectRef makeExtCancelSupportedPendingOperation(
+ JSContextRef context,
+ const DPL::SharedPtr<EventType>& event,
+ const DPL::SharedPtr<Commons::IExternEventCanceler<EventType> >&
+ cancel)
+{
+ IJSPendingOperationPrivateObject* pendingOperation =
+ new IJSExtCancelPendingOperationPrivateObject<EventType>(event, cancel);
+
+ return JSObjectMake(context,
+ JSPendingOperation::getClassRef(),
+ pendingOperation);
+}
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_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 "Validator.h"
+#include <list>
+#include <dpl/assert.h>
+#include "ScopedJSStringRef.h"
+#include "Converter.h"
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+Validator::Validator(JSContextRef context,
+ JSValueRef* exception) :
+ m_context(context),
+ m_exception(exception)
+{
+ Assert(NULL != m_context && "Context cannot be NULL.");
+}
+
+Validator::~Validator()
+{
+}
+
+bool Validator::isDate(const JSValueRef& arg)
+{
+ if (JSValueIsNull(m_context,
+ arg) ||
+ JSValueIsUndefined(m_context,
+ arg) || !JSValueIsObject(m_context, arg)) {
+ return false;
+ }
+ Converter converter(m_context);
+ Try
+ {
+ converter.toDateTm(arg);
+ }
+ Catch(Commons::ConversionException)
+ {
+ return false;
+ }
+ return true;
+}
+
+bool
+Validator::isCallback(const JSValueRef& arg)
+{
+ Converter converter(m_context);
+ return !JSValueIsNull(m_context, arg) &&
+ !JSValueIsUndefined(m_context, arg) &&
+ JSObjectIsFunction(m_context, converter.toJSObjectRef(arg));
+}
+
+bool
+Validator::checkArrayKeys(const std::vector<std::string> &allowed,
+ JSValueRef argument)
+{
+ if (argument == NULL) {
+ return true;
+ }
+ if (!JSValueIsObject(m_context, argument)) {
+ return false;
+ }
+ JSObjectRef jsOptions = JSValueToObject(m_context, argument, NULL);
+ if (jsOptions == NULL) {
+ return false;
+ }
+ JSPropertyNameArrayRef jsProps = JSObjectCopyPropertyNames(m_context,
+ jsOptions);
+ if (jsProps == NULL) {
+ // No properties found; and empty array.
+ return true;
+ }
+ size_t nCount = JSPropertyNameArrayGetCount(jsProps);
+ bool found;
+
+ std::list<JSStringRef> allowedJS;
+ for (size_t j = 0; j < allowed.size(); j++) {
+ allowedJS.push_back(JSStringCreateWithUTF8CString(allowed[j].c_str()));
+ }
+
+ for (size_t i = 0; i < nCount; i++) {
+ found = false;
+ for (std::list<JSStringRef>::const_iterator it = allowedJS.begin();
+ it != allowedJS.end();
+ it++) {
+ if (JSStringIsEqual(*it,
+ JSPropertyNameArrayGetNameAtIndex(jsProps,
+ i))) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ for (size_t j = 0; j < allowed.size(); j++) {
+ JSStringRelease(allowedJS.front());
+ allowedJS.pop_front();
+ }
+ JSPropertyNameArrayRelease(jsProps);
+ return false;
+ }
+ }
+
+ for (size_t j = 0; j < allowed.size(); j++) {
+ JSStringRelease(allowedJS.front());
+ allowedJS.pop_front();
+ }
+ JSPropertyNameArrayRelease(jsProps);
+ return true;
+}
+
+bool Validator::isNullOrUndefined(const JSValueRef& arg)
+{
+ return (JSValueIsNull(m_context, arg) ||
+ JSValueIsUndefined(m_context, arg));
+}
+
+} // CommonsJavaScript
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_VALIDATOR_H_
+#define WRTDEVICEAPIS_COMMONSJAVASCRIPT_VALIDATOR_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace CommonsJavaScript {
+
+class Validator : private DPL::Noncopyable
+{
+ public:
+ explicit Validator(JSContextRef context,
+ JSValueRef* exception = NULL);
+ virtual ~Validator();
+
+ /**
+ * Checks if arg is a Date.
+ * @param arg JSValueRef to check.
+ * @return true when object is a date, false otherwise
+ */
+ bool isDate(const JSValueRef& arg);
+
+ /**
+ * Checks if arg is a callback function.
+ * @param arg JSValueRef to check.
+ * @return true when object is a callback function, false otherwise
+ */
+ bool isCallback(const JSValueRef& arg);
+
+ /**
+ * Checks if arg have allowed properties.
+ * @param allowed allowed property names.
+ * @param arg JSValueRef to check.
+ * @return true when object's properties are subset of allowed
+ */
+ bool checkArrayKeys(const std::vector<std::string> &allowed,
+ JSValueRef argument);
+
+ bool isNullOrUndefined(const JSValueRef& arg);
+
+ protected:
+ JSContextRef m_context;
+ JSValueRef* m_exception;
+};
+
+template<class C>
+class ValidatorFactory : private DPL::Noncopyable
+{
+ public:
+ /**
+ * Validator type which deletes itself when gets out of scope.
+ */
+ typedef DPL::SharedPtr<C> ValidatorType;
+
+ public:
+ /**
+ * Gets converter object.
+ * @param context JavaScript context the conversion will be performed in.
+ * @param[out] exception JavaScript value for storing exception.
+ * @return Converter object.
+ */
+ static ValidatorType getValidator(JSContextRef context,
+ JSValueRef* exception = NULL)
+ {
+ C* convert = new C(context, exception);
+ return ValidatorType(convert);
+ }
+
+ private:
+ ValidatorFactory();
+};
+
+typedef ValidatorFactory<Validator> BasicValidatorFactory;
+typedef BasicValidatorFactory::ValidatorType BasicValidator;
+
+} // CommonsJavaScript
+} // WrtDeviceApis
+
+#endif /* _VALIDATOR_H_ */
--- /dev/null
+Main source folder
--- /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 AccelerationProperties.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ACCELEROMETER_ACCELERATION_PROPERTIES_H_
+#define WRTDEVICEAPIS_ACCELEROMETER_ACCELERATION_PROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+struct AccelerationProperties
+{
+ double xAxis;
+ double yAxis;
+ double zAxis;
+ AccelerationProperties() :
+ xAxis(0.0),
+ yAxis(0.0),
+ zAxis(0.0)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<AccelerationProperties> AccelerationPropertiesPtr;
+} // Accelerometer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_ACCELEROMETER_ACCELERATION_PROPERTIES_H_
\ 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 AccelerometerFactory.cpp
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <Accelerometer/Accelerometer.h>
+#include <Accelerometer/AccelerometerFactory.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+IAccelerometerPtr AccelerometerFactory::getAccelerometers()
+{
+ return IAccelerometerPtr(new Accelerometer());
+}
+
+AccelerometerFactory& AccelerometerFactory::getInstance()
+{
+ static AccelerometerFactory theInstance;
+ return theInstance;
+}
+
+AccelerometerFactory::AccelerometerFactory()
+{
+}
+}
+}
+}
--- /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 AccelerometerFactory.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief This class provide factory to create Accelerometer
+ */
+
+#ifndef WRTDEVICEAPIS_ACCELEROMETERFACTORY_H_
+#define WRTDEVICEAPIS_ACCELEROMETERFACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include <Accelerometer/IAccelerometer.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+class AccelerometerFactory : DPL::Noncopyable
+{
+ public:
+ IAccelerometerPtr getAccelerometers();
+
+ static AccelerometerFactory& getInstance();
+
+ protected:
+ AccelerometerFactory();
+};
+}
+}
+}
+
+#endif //WRTDEVICEAPIS_ACCELEROMETERFACTORY_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 EventAccelerationChanged.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ACCELEROMETER_EVENT_ACCELERATION_CHANGED_H_
+#define WRTDEVICEAPIS_ACCELEROMETER_EVENT_ACCELERATION_CHANGED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include <Accelerometer/AccelerationProperties.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+class EventAccelerationChanged :
+ public Commons::ListenerEvent<EventAccelerationChanged>
+{
+ private:
+ AccelerationProperties m_props;
+
+ public:
+ AccelerationProperties getAccelerationProperties() const
+ {
+ return m_props;
+ }
+ void setAccelerationProperties(const AccelerationProperties &props)
+ {
+ m_props = props;
+ }
+
+ EventAccelerationChanged()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventAccelerationChanged> EventAccelerationChangedPtr;
+typedef Commons::ListenerEventEmitter<EventAccelerationChanged>
+ EventAccelerationChangedEmitter;
+typedef DPL::SharedPtr<EventAccelerationChangedEmitter>
+ EventAccelerationChangedEmitterPtr;
+} // Accelerometer
+} // Api
+} // WrtDeviceApis
+
+#endif //WRTDEVICEAPIS_ACCELEROMETER_EVENT_ACCELERATION_CHANGED_H_
\ 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 EventGetCurrentAcceleration.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ACCELEROMETER_EVENT_GET_CURRENT_ACCELERATION_H_
+#define WRTDEVICEAPIS_ACCELEROMETER_EVENT_GET_CURRENT_ACCELERATION_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Accelerometer/AccelerationProperties.h>
+#include <Accelerometer/IAccelerometer.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+class EventGetCurrentAcceleration :
+ public Commons::IEvent<EventGetCurrentAcceleration>
+{
+ private:
+ AccelerationProperties m_props;
+ public:
+ void setXAxis(double xAxis)
+ {
+ m_props.xAxis = xAxis;
+ }
+ void setYAxis(double yAxis)
+ {
+ m_props.yAxis = yAxis;
+ }
+ void setZAxis(double zAxis)
+ {
+ m_props.zAxis = zAxis;
+ }
+
+ double getXAxis() const
+ {
+ return m_props.xAxis;
+ }
+ double getYAxis() const
+ {
+ return m_props.yAxis;
+ }
+ double getZAxis() const
+ {
+ return m_props.zAxis;
+ }
+
+ AccelerationProperties getAccelerationProperties() const
+ {
+ return m_props;
+ }
+
+ EventGetCurrentAcceleration()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetCurrentAcceleration>
+EventGetCurrentAccelerationPtr;
+} // Accelerometer
+} // Api
+} // WrtDeviceApis
+
+#endif //WRTDEVICEAPIS_API_ACCELEROMETER_EVENT_GET_CURRENT_ACCELERATION_H_
\ 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 IAccelerometer.cpp
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <Accelerometer/IAccelerometer.h>
+#include <Accelerometer/EventGetCurrentAcceleration.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+IAccelerometer::IAccelerometer() :
+ EventRequestReceiver<EventGetCurrentAcceleration>(
+ Commons::ThreadEnum::ACCELEROMETER_THREAD)
+{
+}
+
+IAccelerometer::~IAccelerometer()
+{
+}
+
+}
+}
+}
--- /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 IAccelerometer.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_IACCELEROMETER_H_
+#define WRTDEVICEAPIS_IACCELEROMETER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include <Accelerometer/EventAccelerationChanged.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+class EventGetCurrentAcceleration;
+typedef DPL::SharedPtr<EventGetCurrentAcceleration>
+ EventGetCurrentAccelerationPtr;
+
+class IAccelerometer :
+ public Commons::EventRequestReceiver<EventGetCurrentAcceleration>
+{
+ public:
+ virtual ~IAccelerometer();
+
+ /**
+ * Gets current acceleration
+ * @param event @see WrtDeviceApis::Api::Accelerometer::EventGetCurrentAcceleration.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void getCurrentAcceleration(
+ const EventGetCurrentAccelerationPtr& event) = 0;
+
+ /**
+ * Requests sensor module to receive continuously update of current
+ * acceleration if the acceleration is significantly changed
+ * @param emitter @see WrtDeviceApis::Api::Accelerometer::EventAccelerationChanged.
+ * @param minNotificationInterval
+ * @return An ID of created subscription
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual long watchAcceleration(
+ const EventAccelerationChangedEmitterPtr& emitter,
+ long minNotificationInterval) = 0;
+
+ /**
+ * Stopping periodic acceleration updates started with watchAcceleration
+ * @param id An Id of listener subscription.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void clearWatch(EventAccelerationChangedEmitter::IdType id) = 0;
+
+ protected:
+ IAccelerometer();
+
+ virtual void OnRequestReceived(const EventGetCurrentAccelerationPtr& event)
+ = 0;
+};
+
+typedef DPL::SharedPtr<IAccelerometer> IAccelerometerPtr;
+}
+}
+}
+
+#endif /* WRTDEVICEAPIS_API_IACCELEROMETER_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 "ISensor.h"
+#include <Accelerometer/Sensor.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+ISensor& ISensor::getInstance()
+{
+ return Accelerometer::Sensor::getInstance();
+}
+
+ISensor::~ISensor()
+{
+}
+} // Accelerometer
+} // Api
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_ACCELEROMETER_ISENSOR_H_
+#define WRTDEVICEAPIS_ACCELEROMETER_ISENSOR_H_
+
+#include <dpl/noncopyable.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+namespace Api {
+
+class ISensor : private DPL::Noncopyable
+{
+ public:
+ /**
+ * Gets instance of accelerometer sensor.
+ * @return Accelerometer sensor interface.
+ * @throw UnsupportedException If platform does not support it.
+ */
+ static ISensor& getInstance();
+
+ public:
+ virtual ~ISensor() = 0;
+
+ /**
+ * Gets value on X-axis.
+ * @return Value on X-axis.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual double getX() const = 0;
+
+ /**
+ * Gets value on Y-axis.
+ * @return Value on Y-axis.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual double getY() const = 0;
+
+ /**
+ * Gets value on Z-axis.
+ * @return Value on Z-axis.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual double getZ() const = 0;
+};
+} // Accelerometer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_ACCELEROMETER_ISENSOR_H_
--- /dev/null
+get_current_path()
+
+set(API_ACCELEROMETER_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_ACCELEROMETER
+ ${CURRENT_PATH}/ISensor.cpp
+ ${CURRENT_PATH}/AccelerometerFactory.cpp
+ ${CURRENT_PATH}/IAccelerometer.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_config_file(Calendar)
+include_config_file(Camera)
+include_config_file(Filesystem)
+include_config_file(Messaging)
+include_config_file(Haptics)
+include_config_file(Contact)
+include_config_file(MMPlayer)
+include_config_file(Cpu)
+include_config_file(Power)
+include_config_file(Accelerometer)
+include_config_file(Profile)
+include_config_file(Widget)
+include_config_file(Radio)
+include_config_file(Orientation)
+include_config_file(Task)
+include_config_file(SystemInfo)
+include_config_file(LocalStorage)
+include_config_file(StorageEvent)
+include_config_file(WidgetDB)
+include_config_file(PluginManager)
+#DEPRACATED modules
+#include_config_file(Networking)
+#include_config_file(Geolocation)
+#include_config_file(Display)
+#include_config_file(Gallery)
+#include_config_file(Telephony)
+#include_config_file(FeatureLoader)
+#include_config_file(AppLauncher)
+#include_config_file(Device)
+#include_config_file(Memory)
+#include_config_file(System)
+#include_config_file(UI)
--- /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 Event.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "CalendarEvent.h"
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+CalendarEvent::CalendarEvent() :
+ m_calendarId(UNDEFINED_CALENDAR_ID),
+ m_recurrence(UNDEFINED_RECURRENCE),
+ m_status(UNDEFINED_STATUS),
+ m_alarmType(UNDEFINED_ALARM_TYPE),
+ m_categories(new CategoryList()),
+ m_interval(1)
+{
+}
+
+CalendarEvent::~CalendarEvent()
+{
+}
+
+bool CalendarEvent::getIdIsSet() const
+{
+ return !m_id.IsNull();
+}
+
+bool CalendarEvent::getAlarmTimeIsSet() const
+{
+ return !m_alarmTime.IsNull();
+}
+
+bool CalendarEvent::getExpiresIsSet() const
+{
+ return !m_expires.IsNull();
+}
+
+int CalendarEvent::getCalendarId() const
+{
+ return m_calendarId;
+}
+
+void CalendarEvent::setCalendarId(int value)
+{
+ m_calendarId = value;
+}
+
+int CalendarEvent::getId() const
+{
+ return *m_id;
+}
+
+void CalendarEvent::setId(int value)
+{
+ m_id = value;
+}
+
+void CalendarEvent::resetId()
+{
+ m_id = DPL::Optional<int>();
+}
+
+std::string CalendarEvent::getDescription() const
+{
+ return m_description;
+}
+
+void CalendarEvent::setDescription(const std::string &value)
+{
+ m_description = value;
+}
+
+std::string CalendarEvent::getSubject() const
+{
+ return m_subject;
+}
+
+void CalendarEvent::setSubject(const std::string &value)
+{
+ m_subject = value;
+}
+
+time_t CalendarEvent::getStartTime() const
+{
+ return m_startTime;
+}
+
+void CalendarEvent::setStartTime(time_t value)
+{
+ m_startTime = value;
+}
+
+time_t CalendarEvent::getEndTime() const
+{
+ return m_endTime;
+}
+
+void CalendarEvent::setEndTime(time_t value)
+{
+ m_endTime = value;
+}
+
+std::string CalendarEvent::getLocation() const
+{
+ return m_location;
+}
+
+void CalendarEvent::setLocation(const std::string &value)
+{
+ m_location = value;
+}
+
+CalendarEvent::EventRecurrence CalendarEvent::getRecurrence() const
+{
+ return m_recurrence == UNDEFINED_RECURRENCE ? NO_RECURRENCE : m_recurrence;
+}
+
+void CalendarEvent::setRecurrence(EventRecurrence value)
+{
+ m_recurrence = value;
+}
+
+CalendarEvent::EventStatus CalendarEvent::getStatus() const
+{
+ return m_status == UNDEFINED_STATUS ? TENTATIVE_STATUS : m_status;
+}
+
+void CalendarEvent::setStatus(EventStatus value)
+{
+ m_status = value;
+}
+
+time_t CalendarEvent::getAlarmTime() const
+{
+ return *m_alarmTime;
+}
+
+void CalendarEvent::setAlarmTime(time_t value)
+{
+ m_alarmTime = value;
+}
+
+void CalendarEvent::resetAlarmTime()
+{
+ m_alarmTime = DPL::Optional<std::time_t>();
+}
+
+CalendarEvent::EventAlarmType CalendarEvent::getAlarmType() const
+{
+ return m_alarmType == UNDEFINED_ALARM_TYPE ? NO_ALARM : m_alarmType;
+}
+
+void CalendarEvent::setAlarmType(EventAlarmType value)
+{
+ m_alarmType = value;
+}
+
+CategoryListPtr CalendarEvent::getCategories() const
+{
+ return m_categories;
+}
+void CalendarEvent::setCategories(const CategoryListPtr &value)
+{
+ m_categories = value;
+}
+
+time_t CalendarEvent::getExpires() const
+{
+ return *m_expires;
+}
+
+void CalendarEvent::setExpires(time_t value)
+{
+ m_expires = value;
+}
+
+void CalendarEvent::resetExpires()
+{
+ m_expires = DPL::Optional<std::time_t>();
+}
+
+int CalendarEvent::getInterval() const
+{
+ return m_interval;
+}
+
+void CalendarEvent::setInterval(int value)
+{
+ if (m_interval < 1) {
+ LogError("invalid interval");
+ ThrowMsg(Commons::InvalidArgumentException, "interval less than 1");
+ }
+ m_interval = value;
+}
+
+void CalendarEvent::display() const
+{
+ LogDebug("m_id " << m_id);
+ LogDebug("m_calendarId " << m_calendarId);
+ LogDebug("m_description " << m_description);
+ LogDebug("m_subject " << m_subject);
+ LogDebug("m_startTime " << m_startTime);
+ LogDebug("m_endTime " << m_endTime);
+ LogDebug("m_location " << m_location);
+ LogDebug("m_recurrence " << m_recurrence);
+ LogDebug("m_status " << m_status);
+ if (!m_alarmTime.IsNull()) {
+ LogDebug("m_alarmTime " << *m_alarmTime);
+ }
+ LogDebug("m_alarmType " << m_alarmType);
+ if (!m_expires.IsNull()) {
+ LogDebug("m_expires" << *m_expires);
+ }
+ LogDebug("m_categories size " << m_categories->size());
+ for (size_t i = 0; i < m_categories->size(); ++i) {
+ LogDebug("category" << i << " " << m_categories->at(i));
+ }
+}
+
+bool CalendarEvent::validate() const
+{
+ if (m_alarmType == INVALID_ALARM_TYPE) {
+ LogError("Incorrect alarm type value detected");
+ return false;
+ }
+ if (m_recurrence == INVALID_RECURRENCE) {
+ LogError("Incorrect recurrence value detected");
+ return false;
+ }
+ if (m_status == INVALID_STATUS) {
+ LogError("Incorrect status value detected");
+ return false;
+ }
+ return true;
+}
+
+}
+}
+}
\ 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 CalendarEvent.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_CALENDAR_EVENT_H_
+#define WRTDEVICEAPIS_CALENDAR_CALENDAR_EVENT_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+typedef std::vector<std::string> CategoryList;
+typedef DPL::SharedPtr<CategoryList> CategoryListPtr;
+
+/* This object represents a single calendar event */
+class CalendarEvent
+{
+ public:
+
+ static const int UNDEFINED_CALENDAR_ID = -1;
+
+ typedef enum
+ {
+ NO_RECURRENCE, //The calendar entry occurs once
+ DAILY_RECURRENCE, //The calendar entry occurs every day
+ WEEKLY_RECURRENCE, //The calendar entry occurs every week e.g. every Monday
+ MONTHLY_RECURRENCE, //The calendar entry occurs every month e.g. every 3rd day of month
+ YEARLY_RECURRENCE, //The calendar entry occurs every year e.g. every June 1st
+ WEEKDAY_RECURRENCE, //The calendar entry occurs Mon-Fri every week
+ MONTHLY_ON_DAY_RECURRENCE, //The calendar entry occurs on the same weekday or weekend every month, e.g., every second Tuesday each month.
+ INVALID_RECURRENCE = 10000,
+ UNDEFINED_RECURRENCE /* should be used only to mark a fact filter is not set */
+ } EventRecurrence;
+
+ typedef enum
+ {
+ TENTATIVE_STATUS,
+ CONFIRMED_STATUS,
+ CANCELLED_STATUS,
+ INVALID_STATUS = 10000,
+ UNDEFINED_STATUS /* should be used only to mark a fact filter is not set */
+ } EventStatus;
+
+ typedef enum
+ {
+ NO_ALARM,
+ SILENT_ALARM,
+ SOUND_ALARM,
+ INVALID_ALARM_TYPE = 10000,
+ UNDEFINED_ALARM_TYPE /* should be used only to mark a fact filter is not set */
+ } EventAlarmType;
+
+ CalendarEvent();
+ virtual ~CalendarEvent();
+
+ int getId() const;
+ void setId(int value);
+ void resetId();
+
+ int getCalendarId() const;
+ void setCalendarId(int value);
+
+ std::string getDescription() const;
+ void setDescription(const std::string &value);
+
+ std::string getSubject() const;
+ void setSubject(const std::string &value);
+
+ time_t getStartTime() const;
+ void setStartTime(time_t value);
+
+ time_t getEndTime() const;
+ void setEndTime(time_t value);
+
+ std::string getLocation() const;
+ void setLocation(const std::string &value);
+
+ EventRecurrence getRecurrence() const;
+ void setRecurrence(EventRecurrence value);
+
+ EventStatus getStatus() const;
+ void setStatus(EventStatus value);
+
+ time_t getAlarmTime() const;
+ void setAlarmTime(time_t value);
+ void resetAlarmTime();
+
+ EventAlarmType getAlarmType() const;
+ void setAlarmType(EventAlarmType value);
+
+ CategoryListPtr getCategories() const;
+ void setCategories(const CategoryListPtr &value);
+
+ time_t getExpires() const;
+ void setExpires(time_t value);
+ void resetExpires();
+
+ int getInterval() const;
+ void setInterval(int value);
+
+ void display() const;
+ bool validate() const;
+
+ bool getIdIsSet() const;
+ bool getAlarmTimeIsSet() const;
+ bool getExpiresIsSet() const;
+
+ protected:
+ DPL::Optional<int> m_id;
+ int m_calendarId;
+ std::string m_description;
+ std::string m_subject;
+ std::time_t m_startTime;
+ std::time_t m_endTime;
+ std::string m_location;
+ EventRecurrence m_recurrence;
+ EventStatus m_status;
+ DPL::Optional<std::time_t> m_alarmTime;
+ EventAlarmType m_alarmType;
+ CategoryListPtr m_categories;
+ DPL::Optional<std::time_t> m_expires;
+ int m_interval;
+};
+
+typedef DPL::SharedPtr<CalendarEvent> CalendarEventPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_CALENDAR_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.
+ */
+#include "CalendarFactory.h"
+#include "ICalendarManager.h"
+#include "ICalendar.h"
+#include <Calendar/CalendarManager.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+ICalendarManagerPtr CalendarFactory::createCalendarManagerObject()
+{
+ ICalendarManagerPtr result(new CalendarManager());
+ return result;
+}
+
+ICalendarPtr CalendarFactory::createCalendarObject()
+{
+ ICalendarPtr result(new Calendar());
+ return result;
+}
+
+CalendarFactory& CalendarFactory::getInstance()
+{
+ static CalendarFactory theInstance;
+ return theInstance;
+}
+
+}
+}
+}
\ 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 ICalendarFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_CALENDAR_FACTORY_H_
+#define WRTDEVICEAPIS_CALENDAR_CALENDAR_FACTORY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Calendar/ICalendarManager.h>
+#include <Calendar/ICalendar.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class CalendarFactory : private DPL::Noncopyable
+{
+ private:
+ CalendarFactory()
+ {
+ }
+ public:
+ static CalendarFactory& getInstance();
+ ICalendarManagerPtr createCalendarManagerObject();
+ ICalendarPtr createCalendarObject();
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_CALENDAR_FACTORY_H_
\ 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.
+ */
+/*
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_IEVENT_ADD_EVENT_H_
+#define WRTDEVICEAPIS_CALENDAR_IEVENT_ADD_EVENT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Calendar/CalendarEvent.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class EventAddEvent : public Commons::IEvent<EventAddEvent>
+{
+ CalendarEventPtr m_eventAdd;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setEvent(CalendarEventPtr value)
+ {
+ m_eventAdd = value;
+ }
+ CalendarEventPtr getEvent() const
+ {
+ return m_eventAdd;
+ }
+ EventAddEvent() : m_eventAdd(NULL),
+ m_result(false)
+ {
+ LogDebug("entered");
+ }
+ ~EventAddEvent()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventAddEvent> EventAddEventPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_IEVENT_ADD_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.
+ */
+/*
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_IEVENT_CREATE_EVENT_H_
+#define WRTDEVICEAPIS_CALENDAR_IEVENT_CREATE_EVENT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Calendar/CalendarEvent.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class EventCreateEvent : public Commons::IEvent<EventCreateEvent>
+{
+ CalendarEventPtr m_event;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setEvent(CalendarEventPtr value)
+ {
+ m_event = value;
+ }
+ CalendarEventPtr getEvent() const
+ {
+ return m_event;
+ }
+ EventCreateEvent() : m_event(NULL),
+ m_result(false)
+ {
+ }
+ ~EventCreateEvent()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventCreateEvent> EventCreateEventPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_IEVENT_CREATE_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.
+ */
+/*
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_IEVENT_DELETE_EVENT_H_
+#define WRTDEVICEAPIS_CALENDAR_IEVENT_DELETE_EVENT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Calendar/CalendarEvent.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class EventDeleteEvent : public Commons::IEvent<EventDeleteEvent>
+{
+ CalendarEventPtr m_event;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setEvent(CalendarEventPtr value)
+ {
+ m_event = value;
+ }
+ CalendarEventPtr getEvent() const
+ {
+ return m_event;
+ }
+ EventDeleteEvent() : m_event(NULL),
+ m_result(false)
+ {
+ }
+ ~EventDeleteEvent()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventDeleteEvent> EventDeleteEventPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_IEVENT_DELETE_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.
+ */
+#include "EventFilter.h"
+#include <dpl/log/log.h>
+
+/**
+ * @file EventFilter.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+EventFilter::EventFilter()
+{
+}
+
+EventFilter::~EventFilter()
+{
+}
+
+std::string EventFilter::getIdFilter() const
+{
+ return *m_id;
+}
+
+void EventFilter::setIdFilter(const std::string &value)
+{
+ m_id = value;
+}
+
+int EventFilter::getCalendarIdFilter() const
+{
+ return *m_calendarId;
+}
+
+void EventFilter::setCalendarIdFilter(int value)
+{
+ m_calendarId = value;
+}
+
+std::string EventFilter::getDescriptionFilter() const
+{
+ return *m_description;
+}
+
+void EventFilter::setDescriptionFilter(const std::string &value)
+{
+ m_description = value;
+}
+
+std::string EventFilter::getSubjectFilter() const
+{
+ return *m_subject;
+}
+
+void EventFilter::setSubjectFilter(const std::string &value)
+{
+ m_subject = value;
+}
+
+time_t EventFilter::getStartTimeMinFilter() const
+{
+ return *m_startTimeMin;
+}
+
+time_t EventFilter::getStartTimeMaxFilter() const
+{
+ return *m_startTimeMax;
+}
+
+void EventFilter::setStartTimeMinFilter(time_t value)
+{
+ m_startTimeMin = value;
+}
+
+void EventFilter::setStartTimeMaxFilter(time_t value)
+{
+ m_startTimeMax = value;
+}
+
+void EventFilter::setStartTimeFilter(time_t value)
+{
+ setStartTimeMinFilter(value);
+ setStartTimeMaxFilter(value);
+}
+
+time_t EventFilter::getEndTimeMinFilter() const
+{
+ return *m_endTimeMin;
+}
+
+time_t EventFilter::getEndTimeMaxFilter() const
+{
+ return *m_endTimeMax;
+}
+
+void EventFilter::setEndTimeMinFilter(time_t value)
+{
+ m_endTimeMin = value;
+}
+
+void EventFilter::setEndTimeMaxFilter(time_t value)
+{
+ m_endTimeMax = value;
+}
+
+void EventFilter::setEndTimeFilter(time_t value)
+{
+ setEndTimeMinFilter(value);
+ setEndTimeMaxFilter(value);
+}
+
+std::string EventFilter::getLocationFilter() const
+{
+ return *m_location;
+}
+
+void EventFilter::setLocationFilter(const std::string &value)
+{
+ m_location = value;
+}
+
+std::vector<CalendarEvent::EventRecurrence> EventFilter::getRecurrenceFilter()
+const
+{
+ return m_recurrence;
+}
+
+void EventFilter::addRecurrenceFilter(CalendarEvent::EventRecurrence value)
+{
+ m_recurrence.push_back(value);
+}
+
+std::vector<CalendarEvent::EventStatus> EventFilter::getStatusFilter() const
+{
+ return m_status;
+}
+
+void EventFilter::addStatusFilter(CalendarEvent::EventStatus value)
+{
+ m_status.push_back(value);
+}
+
+time_t EventFilter::getAlarmTimeMinFilter() const
+{
+ return *m_alarmTimeMin;
+}
+
+time_t EventFilter::getAlarmTimeMaxFilter() const
+{
+ return *m_alarmTimeMax;
+}
+
+void EventFilter::setAlarmTimeMinFilter(time_t value)
+{
+ m_alarmTimeMin = value;
+}
+
+void EventFilter::setAlarmTimeMaxFilter(time_t value)
+{
+ m_alarmTimeMax = value;
+}
+
+void EventFilter::setAlarmTimeFilter(time_t value)
+{
+ setAlarmTimeMinFilter(value);
+ setAlarmTimeMaxFilter(value);
+}
+
+std::vector<CalendarEvent::EventAlarmType> EventFilter::getAlarmTypeFilter()
+const
+{
+ return m_alarmType;
+}
+
+void EventFilter::addAlarmTypeFilter(CalendarEvent::EventAlarmType value)
+{
+ m_alarmType.push_back(value);
+}
+
+std::string EventFilter::getCategoryFilter() const
+{
+ return *m_category;
+}
+
+void EventFilter::setCategoryFilter(const std::string &category)
+{
+ m_category = category;
+}
+
+bool EventFilter::getIdIsSet() const
+{
+ return !m_id.IsNull();
+}
+
+bool EventFilter::getCalendarIdIsSet() const
+{
+ return !m_calendarId.IsNull();
+}
+
+bool EventFilter::getDescriptionIsSet() const
+{
+ return !m_description.IsNull();
+}
+
+bool EventFilter::getSubjectIsSet() const
+{
+ return !m_subject.IsNull();
+}
+
+bool EventFilter::getStartTimeMinIsSet() const
+{
+ return !m_startTimeMin.IsNull();
+}
+
+bool EventFilter::getStartTimeMaxIsSet() const
+{
+ return !m_startTimeMax.IsNull();
+}
+
+bool EventFilter::getEndTimeMinIsSet() const
+{
+ return !m_endTimeMin.IsNull();
+}
+
+bool EventFilter::getEndTimeMaxIsSet() const
+{
+ return !m_endTimeMax.IsNull();
+}
+
+bool EventFilter::getLocationIsSet() const
+{
+ return !m_location.IsNull();
+}
+
+bool EventFilter::getRecurrenceIsSet() const
+{
+ return !m_recurrence.empty();
+}
+
+bool EventFilter::getStatusIsSet() const
+{
+ return !m_status.empty();
+}
+
+bool EventFilter::getAlarmTimeMinIsSet() const
+{
+ return !m_alarmTimeMin.IsNull();
+}
+
+bool EventFilter::getAlarmTimeMaxIsSet() const
+{
+ return !m_alarmTimeMax.IsNull();
+}
+
+bool EventFilter::getAlarmTypeIsSet() const
+{
+ return !m_alarmType.empty();
+}
+
+bool EventFilter::getCategoryIsSet() const
+{
+ return !m_category.IsNull();
+}
+
+}
+}
+}
\ 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 EventFilter.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_IEVENT_FILTER_H_
+#define WRTDEVICEAPIS_CALENDAR_IEVENT_FILTER_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <dpl/optional.h>
+#include <Calendar/CalendarEvent.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class EventFilter
+{
+ public:
+
+ EventFilter();
+ virtual ~EventFilter();
+
+ std::string getIdFilter() const;
+ void setIdFilter(const std::string &value);
+
+ int getCalendarIdFilter() const;
+ void setCalendarIdFilter(int value);
+
+ std::string getDescriptionFilter() const;
+ void setDescriptionFilter(const std::string &value);
+
+ std::string getSubjectFilter() const;
+ void setSubjectFilter(const std::string &value);
+
+ std::time_t getStartTimeMinFilter() const;
+ std::time_t getStartTimeMaxFilter() const;
+ void setStartTimeMinFilter(std::time_t value);
+ void setStartTimeMaxFilter(std::time_t value);
+ void setStartTimeFilter(std::time_t value);
+
+ std::time_t getEndTimeMinFilter() const;
+ std::time_t getEndTimeMaxFilter() const;
+ void setEndTimeMinFilter(std::time_t value);
+ void setEndTimeMaxFilter(std::time_t value);
+ void setEndTimeFilter(std::time_t value);
+
+ std::string getLocationFilter() const;
+ void setLocationFilter(const std::string &value);
+
+ std::vector<CalendarEvent::EventRecurrence> getRecurrenceFilter() const;
+ void addRecurrenceFilter(CalendarEvent::EventRecurrence value);
+
+ std::vector<CalendarEvent::EventStatus> getStatusFilter() const;
+ void addStatusFilter(CalendarEvent::EventStatus value);
+
+ std::time_t getAlarmTimeMinFilter() const;
+ std::time_t getAlarmTimeMaxFilter() const;
+ void setAlarmTimeMinFilter(std::time_t value);
+ void setAlarmTimeMaxFilter(std::time_t value);
+ void setAlarmTimeFilter(std::time_t value);
+
+ std::vector<CalendarEvent::EventAlarmType> getAlarmTypeFilter() const;
+ void addAlarmTypeFilter(CalendarEvent::EventAlarmType value);
+
+ std::string getCategoryFilter() const;
+ void setCategoryFilter(const std::string &category);
+
+ bool getIdIsSet() const;
+ bool getCalendarIdIsSet() const;
+ bool getDescriptionIsSet() const;
+ bool getSubjectIsSet() const;
+ bool getStartTimeMinIsSet() const;
+ bool getStartTimeMaxIsSet() const;
+ bool getEndTimeMinIsSet() const;
+ bool getEndTimeMaxIsSet() const;
+ bool getLocationIsSet() const;
+ bool getRecurrenceIsSet() const;
+ bool getStatusIsSet() const;
+ bool getAlarmTimeMinIsSet() const;
+ bool getAlarmTimeMaxIsSet() const;
+ bool getAlarmTypeIsSet() const;
+ bool getCategoryIsSet() const;
+
+ protected:
+ DPL::Optional<std::string> m_id;
+ DPL::Optional<int> m_calendarId;
+ DPL::Optional<std::string> m_description;
+ DPL::Optional<std::string> m_subject;
+ DPL::Optional<std::time_t> m_startTimeMin;
+ DPL::Optional<std::time_t> m_startTimeMax;
+ DPL::Optional<std::time_t> m_endTimeMin;
+ DPL::Optional<std::time_t> m_endTimeMax;
+ DPL::Optional<std::string> m_location;
+ std::vector<CalendarEvent::EventRecurrence> m_recurrence;
+ std::vector<CalendarEvent::EventStatus> m_status;
+ std::vector<CalendarEvent::EventAlarmType> m_alarmType;
+ DPL::Optional<std::time_t> m_alarmTimeMin;
+ DPL::Optional<std::time_t> m_alarmTimeMax;
+ DPL::Optional<std::string> m_category;
+};
+
+typedef DPL::SharedPtr<EventFilter> EventFilterPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_IEVENT_FILTER_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_IEVENT_FIND_EVENTS_H_
+#define WRTDEVICEAPIS_CALENDAR_IEVENT_FIND_EVENTS_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Calendar/CalendarEvent.h>
+#include <Calendar/EventFilter.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class EventFindEvents : public Commons::IEvent<EventFindEvents>
+{
+ /* user is responsible to free objects inside list */
+ std::vector<CalendarEventPtr> m_events; //OUTPUT: result list
+ bool m_result; //OUTPUT: operation result
+ EventFilterPtr m_filter; //INPUT: filters
+ int m_firstEvent; //INPUT: index of first found event to include on list
+ int m_lastEvent; //INPUT: index of last found event to include on list
+ public:
+ void setFirstEvent(int value)
+ {
+ m_firstEvent = value;
+ }
+ int getFirstEvent() const
+ {
+ return m_firstEvent;
+ }
+ void setLastEvent(int value)
+ {
+ m_lastEvent = value;
+ }
+ int getLastEvent() const
+ {
+ return m_lastEvent;
+ }
+ void setFilter(EventFilterPtr value)
+ {
+ m_filter = value;
+ }
+ EventFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void addEvent(CalendarEventPtr value)
+ {
+ m_events.push_back(value);
+ }
+ std::vector<CalendarEventPtr> getEvents()
+ {
+ return m_events;
+ }
+ EventFindEvents() : m_result(false),
+ m_firstEvent(0),
+ m_lastEvent(-1)
+ {
+ }
+ ~EventFindEvents()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventFindEvents> EventFindEventsPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_IEVENT_FIND_EVENTS_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_IEVENT_GET_CALENDARS_H_
+#define WRTDEVICEAPIS_CALENDAR_IEVENT_GET_CALENDARS_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Calendar/ICalendar.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class EventGetCalendars : public Commons::IEvent<EventGetCalendars>
+{
+ std::vector<ICalendarPtr> m_calendars;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void addCalendar(ICalendarPtr value)
+ {
+ m_calendars.push_back(value);
+ }
+ std::vector<ICalendarPtr> getCalendars() const
+ {
+ return m_calendars;
+ }
+ EventGetCalendars() : m_result(false)
+ {
+ }
+ ~EventGetCalendars()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetCalendars> EventGetCalendarsPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_IEVENT_UPDATE_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.
+ */
+/*
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_IEVENT_UPDATE_EVENT_H_
+#define WRTDEVICEAPIS_CALENDAR_IEVENT_UPDATE_EVENT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Calendar/CalendarEvent.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class EventUpdateEvent : public Commons::IEvent<EventUpdateEvent>
+{
+ CalendarEventPtr m_event;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setEvent(CalendarEventPtr value)
+ {
+ m_event = value;
+ }
+ CalendarEventPtr getEvent() const
+ {
+ return m_event;
+ }
+
+ EventUpdateEvent() : m_event(NULL),
+ m_result(false)
+ {
+ }
+ ~EventUpdateEvent()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventUpdateEvent> EventUpdateEventPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_IEVENT_UPDATE_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 ICalendar.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "ICalendar.h"
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+ICalendar::ICalendar() :
+ Commons::EventRequestReceiver<EventAddEvent>(
+ Commons::ThreadEnum::CALENDAR_THREAD),
+ Commons::EventRequestReceiver<EventDeleteEvent>(
+ Commons::ThreadEnum::CALENDAR_THREAD),
+ Commons::EventRequestReceiver<EventUpdateEvent>(
+ Commons::ThreadEnum::CALENDAR_THREAD),
+ Commons::EventRequestReceiver<EventFindEvents>(
+ Commons::ThreadEnum::CALENDAR_THREAD),
+ Commons::EventRequestReceiver<EventCreateEvent>(
+ Commons::ThreadEnum::CALENDAR_THREAD),
+ m_id(0),
+ m_accountId(0),
+ m_type(DEVICE_CALENDAR)
+{
+}
+
+ICalendar::~ICalendar()
+{
+}
+
+void ICalendar::createEvent(const EventCreateEventPtr &event)
+{
+ Commons::EventRequestReceiver<EventCreateEvent>::PostRequest(event);
+}
+
+void ICalendar::addEvent(const EventAddEventPtr &event)
+{
+ Commons::EventRequestReceiver<EventAddEvent>::PostRequest(event);
+}
+
+void ICalendar::updateEvent(const EventUpdateEventPtr &event)
+{
+ Commons::EventRequestReceiver<EventUpdateEvent>::PostRequest(event);
+}
+
+void ICalendar::deleteEvent(const EventDeleteEventPtr &event)
+{
+ Commons::EventRequestReceiver<EventDeleteEvent>::PostRequest(event);
+}
+
+void ICalendar::findEvents(const EventFindEventsPtr &event)
+{
+ Commons::EventRequestReceiver<EventFindEvents>::PostRequest(event);
+}
+
+}
+}
+}
--- /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 ICalendar.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_ICALENDAR_H_
+#define WRTDEVICEAPIS_CALENDAR_ICALENDAR_H_
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Calendar/CalendarEvent.h>
+#include <Calendar/EventFilter.h>
+#include <Calendar/EventAddEvent.h>
+#include <Calendar/EventCreateEvent.h>
+#include <Calendar/EventDeleteEvent.h>
+#include <Calendar/EventFindEvents.h>
+#include <Calendar/EventUpdateEvent.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class ICalendar :
+ public Commons::EventRequestReceiver<EventAddEvent>,
+ public Commons::EventRequestReceiver<EventDeleteEvent>,
+ public Commons::EventRequestReceiver<EventUpdateEvent>,
+ public Commons::EventRequestReceiver<EventFindEvents>,
+ public Commons::EventRequestReceiver<EventCreateEvent>
+{
+ public:
+
+ typedef enum
+ {
+ SIM_CALENDAR,
+ DEVICE_CALENDAR
+ } CalendarType;
+
+ ICalendar();
+ virtual ~ICalendar();
+ virtual void createEvent(const EventCreateEventPtr &event);
+ virtual void addEvent(const EventAddEventPtr &event);
+ virtual void updateEvent(const EventUpdateEventPtr &event);
+ virtual void deleteEvent(const EventDeleteEventPtr &event);
+ virtual void findEvents(const EventFindEventsPtr &event);
+
+ virtual std::string getName() const
+ {
+ return m_name;
+ }
+ virtual void setName(const std::string &value)
+ {
+ m_name = value;
+ }
+ virtual CalendarType getType() const
+ {
+ return m_type;
+ }
+ virtual void setType(const CalendarType value)
+ {
+ m_type = value;
+ }
+ virtual int getId() const
+ {
+ return m_id;
+ }
+ virtual void setId(const int value)
+ {
+ m_id = value;
+ }
+ virtual int getAccountId() const
+ {
+ return m_accountId;
+ }
+ virtual void setAccountId(const int value)
+ {
+ m_accountId = value;
+ }
+ protected:
+ int m_id;
+ int m_accountId;
+ std::string m_name;
+ CalendarType m_type;
+
+ virtual void OnRequestReceived(const EventAddEventPtr &event) = 0;
+ virtual void OnRequestReceived(const EventDeleteEventPtr &event) = 0;
+ virtual void OnRequestReceived(const EventUpdateEventPtr &event) = 0;
+ virtual void OnRequestReceived(const EventFindEventsPtr &event) = 0;
+ virtual void OnRequestReceived(const EventCreateEventPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<ICalendar> ICalendarPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_ICALENDAR_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 ICalendarManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "ICalendarManager.h"
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+ICalendarManager::ICalendarManager() :
+ Commons::EventRequestReceiver<EventGetCalendars>(
+ Commons::ThreadEnum::CALENDAR_THREAD)
+{
+}
+
+ICalendarManager::~ICalendarManager()
+{
+}
+
+void ICalendarManager::getCalendars(const EventGetCalendarsPtr &event)
+{
+ LogDebug("entered");
+ PostRequest(event);
+}
+
+}
+}
+}
--- /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 ICalendarManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_ICALENDAR_MANAGER_H_
+#define WRTDEVICEAPIS_CALENDAR_ICALENDAR_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Calendar/ICalendar.h>
+#include <Calendar/EventGetCalendars.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+namespace Api {
+
+class ICalendarManager :
+ public Commons::EventRequestReceiver<EventGetCalendars>
+{
+ public:
+ ICalendarManager();
+ virtual ~ICalendarManager();
+ virtual void getCalendars(const EventGetCalendarsPtr &event);
+ protected:
+ virtual void OnRequestReceived(const EventGetCalendarsPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<ICalendarManager> ICalendarManagerPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_ICALENDAR_MANAGER_H_
--- /dev/null
+get_current_path()
+
+set(API_CALENDAR_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_CALENDAR
+ ${CURRENT_PATH}/CalendarEvent.cpp
+ ${CURRENT_PATH}/CalendarFactory.cpp
+ ${CURRENT_PATH}/EventFilter.cpp
+ ${CURRENT_PATH}/ICalendar.cpp
+ ${CURRENT_PATH}/ICalendarManager.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 "CameraFactory.h"
+#include "ICameraManager.h"
+#include <Camera-Webkit/CameraManager.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+ICameraManager& CameraFactory::getCameraManagerObject()
+{
+ static WrtDeviceApis::Camera::CameraManager camManagerInstance;
+ return camManagerInstance;
+}
+
+CameraFactory& CameraFactory::getInstance()
+{
+ static CameraFactory theInstance;
+ return theInstance;
+}
+
+}
+}
+}
--- /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.
+ */
+/*
+ * Created on: 2010-06-28
+ * Author: kmajewski
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_CAMERAFACTORY_H_
+#define WRTDEVICEAPIS_CAMERA_CAMERAFACTORY_H_
+
+#include "ICameraManager.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class CameraFactory : private DPL::Noncopyable
+{
+ private:
+ /**
+ * Private constructor to provide singleton
+ */
+ CameraFactory()
+ {}
+
+ public:
+
+ /**
+ * Get camera manager
+ */
+ ICameraManager& getCameraManagerObject();
+
+ /**
+ * Get singleton instance
+ */
+ static CameraFactory& getInstance();
+};
+
+}
+}
+}
+#endif /* WRTPLUGINSCAMERAFACTORY_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_IEVENTBEGINRECORDING_H_
+#define WRTDEVICEAPIS_CAMERA_IEVENTBEGINRECORDING_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "ICaptureOptions.h"
+#include "SupportCameraPendingOperation.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class EventBeginRecording :
+ public WrtDeviceApis::Commons::IEvent<EventBeginRecording>,
+ public SupportCameraPendingOperation
+{
+public:
+ /*
+ * Sets the capture options that will be used while taking picture.
+ * EventTakePicture will take ownership of the object
+ * (it will delete it when will not be needed any more)
+ */
+ void setCaptureOptionsRef(const ICaptureOptionsPtr &captureOptions)
+ {
+ m_captureOptions = captureOptions;
+ }
+
+ explicit EventBeginRecording() : m_captureOptions(NULL)
+ {
+ }
+
+ ICaptureOptionsPtr getCaptureOptionsRef() const {return m_captureOptions;}
+
+private:
+ ICaptureOptionsPtr m_captureOptions;
+};
+
+typedef DPL::SharedPtr<EventBeginRecording> EventBeginRecordingSharedPtr;
+
+}
+}
+}
+#endif /* WRTPLUGINSIEVENTBEGINRECORDING_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_IEVENTENDRECORDING_H_
+#define WRTDEVICEAPIS_CAMERA_API_IEVENTENDRECORDING_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class EventEndRecording :
+ public WrtDeviceApis::Commons::IEvent<EventEndRecording>
+{
+};
+
+typedef DPL::SharedPtr<EventEndRecording> EventEndRecordingSharedPtr;
+
+}
+}
+}
+#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.
+ */
+/*
+ * @author Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTPLUGINSIEVENTGETCAMERAS_H_
+#define WRTPLUGINSIEVENTGETCAMERAS_H_
+
+#include <vector>
+#include <cstddef>
+#include <dpl/shared_ptr.h>
+#include <Commons/Exception.h>
+#include <Commons/IEvent.h>
+#include "ICamera.h"
+#include <Commons/WidgetConfiguration/ConfigurationSupport.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class EventGetCameras :
+ public WrtDeviceApis::Commons::ConfigurationSupport,
+ public WrtDeviceApis::Commons::IEvent<EventGetCameras>
+{
+public:
+ EventGetCameras() : m_defaultCameraIndex(0) {}
+
+ void setCamerasRef(const std::vector< ICameraSharedPtr > &cameras,
+ std::size_t defaultCameraIndex)
+ {
+ m_cameras = cameras;
+ m_defaultCameraIndex = defaultCameraIndex;
+ }
+
+ ICameraSharedPtr getCamera(std::size_t index)
+ {
+ if (index >= m_cameras.size() || m_cameras.size() == 0) {
+ Throw(Commons::InvalidArgumentException);
+ }
+ return m_cameras[index];
+ }
+
+ ICameraSharedPtr getDefaultCamera()
+ {
+ if (m_cameras.empty()) {
+ LogError("There are no cameras to choose from");
+ Throw(Commons::OutOfRangeException);
+ }
+ if (m_defaultCameraIndex >= m_cameras.size()) {
+ LogError("Default camera index is out of range");
+ Throw(Commons::InvalidArgumentException);
+ }
+ return m_cameras[m_defaultCameraIndex];
+ }
+
+ std::size_t getNumberOfCameras(){ return m_cameras.size(); }
+
+private:
+ std::vector< ICameraSharedPtr > m_cameras;
+ std::size_t m_defaultCameraIndex;
+};
+
+typedef DPL::SharedPtr<EventGetCameras> EventGetCamerasPtr;
+}
+}
+}
+#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.
+ */
+/*
+ * @author Karol Majewski (k.majewski@samsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_EVENTGETPREVIEWNODE_H_
+#define WRTDEVICEAPIS_CAMERA_API_EVENTGETPREVIEWNODE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "SupportCameraPendingOperation.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class EventGetPreviewNode :
+ public WrtDeviceApis::Commons::IEvent<EventGetPreviewNode>,
+ public SupportCameraPendingOperation
+{
+public:
+ typedef void* PreviewNode;
+
+public:
+ EventGetPreviewNode() : m_node(NULL){}
+
+ void setPreviewNode(PreviewNode node) {m_node = node;}
+
+ PreviewNode getPreviewNode() const {return m_node;}
+
+private:
+ PreviewNode m_node;
+};
+
+typedef DPL::SharedPtr<EventGetPreviewNode> EventGetPreviewNodeSharedPtr;
+
+}
+}
+}
+#endif // WRTDEVICEAPIS_CAMERA_API_EVENTGETPREVIEWNODE_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_IEVENTTAKEPICTURE_H_
+#define WRTDEVICEAPIS_CAMERA_API_IEVENTTAKEPICTURE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "ICaptureOptions.h"
+#include "SupportCameraPendingOperation.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class EventTakePicture :
+ public WrtDeviceApis::Commons::IEvent<EventTakePicture>,
+ public SupportCameraPendingOperation
+{
+ private:
+ ICaptureOptionsPtr m_captureOptions;
+
+ public:
+ /*
+ * Sets the capture options that will be used while taking picture.
+ * EventTakePicture will take ownership of the object
+ * (it will delete it when will not be needed any more)
+ */
+ void setCaptureOptionsRef(const ICaptureOptionsPtr &captureOptions)
+ {
+ m_captureOptions = captureOptions;
+ }
+
+ ICaptureOptionsPtr getCaptureOptionsRef() const { return m_captureOptions;}
+};
+
+typedef DPL::SharedPtr<EventTakePicture> EventTakePictureSharedPtr;
+
+}
+}
+}
+#endif /* WRTPLUGINSIEVENTTAKEPICTURE_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_ICAMERA_H_
+#define WRTDEVICEAPIS_CAMERA_API_ICAMERA_H_
+
+#include <string>
+#include <unistd.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/IExternEventCanceler.h>
+#include "EventBeginRecording.h"
+#include "EventEndRecording.h"
+#include "EventTakePicture.h"
+#include "EventGetPreviewNode.h"
+
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+typedef Commons::EventRequestReceiver<EventTakePicture>
+ EventSupportTakePicture;
+typedef Commons::EventRequestReceiver<EventBeginRecording>
+ EventSupportBeginRecording;
+typedef Commons::EventRequestReceiver<EventEndRecording>
+ EventSupportEndRecording;
+typedef Commons::EventRequestReceiver<EventGetPreviewNode>
+ EventSupportGetPreviewNode;
+
+typedef Commons::IExternEventCanceler<EventBeginRecording>
+ SupportCancelRecording;
+typedef Commons::IExternEventCanceler<EventTakePicture>
+ SupportCancelTakePicture;
+typedef Commons::IExternEventCanceler<EventGetPreviewNode>
+ SupportCancelGetPreview;
+typedef Commons::ThreadEnum Thread;
+
+class ICamera : public EventSupportTakePicture,
+ public EventSupportBeginRecording,
+ public EventSupportEndRecording,
+ public EventSupportGetPreviewNode,
+ public SupportCancelRecording,
+ public SupportCancelTakePicture,
+ public SupportCancelGetPreview
+{
+public:
+ ICamera() :
+ EventSupportTakePicture(Thread::CAMERA_THREAD),
+ EventSupportBeginRecording(Thread::CAMERA_THREAD),
+ EventSupportEndRecording(Thread::CAMERA_THREAD),
+ EventSupportGetPreviewNode(Thread::CAMERA_THREAD)
+ {
+ }
+
+ virtual std::string getDescription() const
+ {
+ return "";
+ }
+
+ /**
+ * Takes picture
+ */
+ void takePicture(const EventTakePictureSharedPtr &event)
+ {
+ EventSupportTakePicture::PostRequest(event);
+ }
+
+ /**
+ * Begins recording
+ */
+ virtual void beginRecording(const EventBeginRecordingSharedPtr &event)
+ {
+ EventSupportBeginRecording::PostRequest(event);
+ }
+
+ /**
+ * Ends recording
+ */
+ virtual void endRecording(const EventEndRecordingSharedPtr &event,
+ double delay = 0.0)
+ {
+ EventSupportEndRecording::PostRequest(event,delay);
+ }
+
+ /**
+ * Requests preview window
+ */
+ void createPreview(const EventGetPreviewNodeSharedPtr &event)
+ {
+ EventSupportGetPreviewNode::PostRequest(event);
+ }
+
+ virtual void OnCancelEvent(const EventBeginRecordingSharedPtr& /*event*/) {}
+ virtual void OnCancelEvent(const EventTakePictureSharedPtr& /*event*/) {}
+ virtual void OnCancelEvent(const EventGetPreviewNodeSharedPtr& /*event*/) {}
+
+ virtual void OnRequestReceived(
+ const EventTakePictureSharedPtr &event) = 0;
+ virtual void OnRequestReceived(
+ const EventBeginRecordingSharedPtr &event) = 0;
+ virtual void OnRequestReceived(
+ const EventEndRecordingSharedPtr &event) = 0;
+ virtual void OnRequestReceived(
+ const EventGetPreviewNodeSharedPtr &event) = 0;
+
+ virtual ~ICamera()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<ICamera> ICameraSharedPtr;
+
+}
+}
+}
+#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.
+ */
+/*
+ * @author Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_ICAMERAFEATURE_H_
+#define WRTDEVICEAPIS_CAMERA_API_ICAMERAFEATURE_H_
+
+#include <string>
+#include "IFeatureValue.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class ICameraFeature
+{
+ enum Types
+ {
+ //camera feature is represented by an interval.
+ FEATURETYPE_INTERVAL = 0,
+ //camera feature is represented binary.
+ FEATURETYPE_BINARY = 1,
+ //camera feature is represented by an enumeration.
+ FEATURETYPE_ENUMERATION = 2
+ };
+
+ private:
+ //A optional description of the feature.
+ std::string m_description;
+
+ //The unique feature identifier.
+ long m_id;
+
+ //The type of the camera feature.
+ Types m_type;
+
+ //The current value of the camera feature.
+ IFeatureValue m_value;
+
+ //The default value of the camera feature.
+ IFeatureValue m_default;
+
+ //A set of feature values that represents the allowed feature configurations
+ //IFeatureValue *m_possibleValues;
+
+ public:
+ ICameraFeature();
+ virtual ~ICameraFeature();
+};
+
+}
+}
+}
+#endif /* WRTPLUGINSICAMERAFEATURE_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_ICAMERAMANAGER_H_
+#define WRTDEVICEAPIS_CAMERA_API_ICAMERAMANAGER_H_
+
+#include <vector>
+#include <dpl/log/log.h>
+#include <Commons/ThreadPool.h>
+#include <Commons/EventReceiver.h>
+#include "EventGetCameras.h"
+#include "ICamera.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+typedef Commons::EventRequestReceiver<EventGetCameras>
+ EventSupportGetCameras;
+
+class ICameraManager : public EventSupportGetCameras
+{
+public:
+ /**
+ * Gets cameras
+ */
+ virtual void getCameras(const EventGetCamerasPtr &event)
+ {
+ LogDebug(__FUNCTION__);
+ PostRequest(event);
+ }
+
+ virtual ~ICameraManager() {}
+
+protected:
+ ICameraManager() : EventSupportGetCameras(Thread::CAMERA_THREAD)
+ {}
+
+ virtual void OnRequestReceived(const EventGetCamerasPtr &event) = 0;
+
+protected:
+ std::vector< ICameraSharedPtr > m_cameras;
+};
+
+}//namespace
+}//namespace
+}//namespace
+
+#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.
+ */
+/*
+ * @author Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_ICAPTUREOPTIONS_H_
+#define WRTDEVICEAPIS_CAMERA_API_ICAPTUREOPTIONS_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class ICaptureOptions
+{
+ public:
+
+ /**
+ * Available attributes
+ */
+ enum AttributesFlags
+ {
+ SETTED_WIDTH = 1 << 0,
+ SETTED_HEIGHT = 1 << 1,
+ SETTED_FRAME_RATE = 1 << 2,
+ SETTED_MAX_BITRATE = 1 << 3,
+ SETTED_FILE_NAME = 1 << 4,
+ SETTED_IMAGE_RESOLUTION = 1 << 5
+ };
+
+ /**
+ * Available picture details levels
+ */
+ enum ImageResolution
+ {
+ IMAGE_RESOLUTION_HIGH,
+ IMAGE_RESOLUTION_LOW,
+ IMAGE_RESOLUTION_DEFAULT
+ };
+
+ ICaptureOptions() :
+ m_settedFlags(0),
+ m_width(0),
+ m_height(0),
+ m_frameRate(0.0),
+ m_imageResolution(IMAGE_RESOLUTION_DEFAULT),
+ m_maximumBitrate(0),
+ m_overwrite(true)
+ {
+ }
+
+ virtual ~ICaptureOptions()
+ {
+ }
+
+ /**
+ * Check for attribute correctness
+ */
+ bool isAttributeValid(const AttributesFlags flag) const
+ {
+ return (flag & m_settedFlags) == flag;
+ }
+
+ /**
+ * Gets frame rate
+ */
+ float getFrameRate() const
+ {
+ return m_frameRate;
+ }
+
+ /**
+ * Gets height
+ */
+ unsigned short getHeight() const
+ {
+ return m_height;
+ }
+
+ /**
+ * Gets video maximum bitrate
+ */
+ unsigned long getMaximumBitrate() const
+ {
+ return m_maximumBitrate;
+ }
+
+ /**
+ * Gets image resolution
+ */
+ ImageResolution getImageResolution() const
+ {
+ return m_imageResolution;
+ }
+
+ /**
+ * Gets filename
+ */
+ std::string getFileName() const
+ {
+ return m_capturedFileName;
+ }
+
+ /**
+ * Gets width
+ */
+ unsigned short getWidth() const
+ {
+ return m_width;
+ }
+
+ /**
+ * Gets whether output file should be overwritten if already exists.
+ * @return True if should be overwritten, false otherwise.
+ */
+ bool getOverwrite() const
+ {
+ return m_overwrite;
+ }
+
+ /**
+ * Sets video frame rate
+ */
+ void setFrameRate(float frameRate)
+ {
+ this->m_frameRate = frameRate;
+ setFlag(SETTED_FRAME_RATE);
+ }
+
+ /**
+ * Sets height
+ */
+ void setHeight(unsigned short height)
+ {
+ this->m_height = height;
+ setFlag(SETTED_HEIGHT);
+ }
+
+ /**
+ * Sets video maximum bitrate
+ */
+ void setMaximumBitrate(unsigned long maximumBitrate)
+ {
+ this->m_maximumBitrate = maximumBitrate;
+ setFlag(SETTED_MAX_BITRATE);
+ }
+
+ /**
+ * Sets image resolution
+ */
+ void setImageResolution(ImageResolution imageResolution)
+ {
+ this->m_imageResolution = imageResolution;
+ setFlag(SETTED_IMAGE_RESOLUTION);
+ }
+
+ /**
+ * Sets filename
+ */
+ void setFileName(const std::string &fileName)
+ {
+ this->m_capturedFileName = fileName;
+ setFlag(SETTED_FILE_NAME);
+ }
+
+ /**
+ * Sets width
+ */
+ void setWidth(unsigned short width)
+ {
+ this->m_width = width;
+ setFlag(SETTED_WIDTH);
+ }
+
+ /**
+ * Sets if output file should be overwritten if already exists.
+ * @param overwrite
+ */
+ void setOverwrite(bool overwrite)
+ {
+ m_overwrite = overwrite;
+ }
+
+ private:
+
+ unsigned short m_settedFlags;
+
+ void setFlag(AttributesFlags flag)
+ {
+ m_settedFlags = m_settedFlags | flag;
+ }
+
+ //The desired width of the video or picture
+ unsigned short m_width;
+
+ //The desired height of the video or picture.
+ unsigned short m_height;
+
+ //The desired frame rate for video records.
+ float m_frameRate;
+
+ //The desired resolution of a picture.
+ ImageResolution m_imageResolution;
+
+ //The desired name of file with captured data
+ std::string m_capturedFileName;
+
+ //The desired maximum bit rate of the recorded video media.
+ unsigned long m_maximumBitrate;
+
+ /**
+ * Indicates whether file should be overwritten if already exists.
+ */
+ bool m_overwrite;
+};
+
+typedef DPL::SharedPtr<ICaptureOptions> ICaptureOptionsPtr;
+
+}
+}
+}
+#endif /* WRTPLUGINSICAPTUREOPTIONS_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_IFEATUREVALUE_H_
+#define WRTDEVICEAPIS_CAMERA_API_IFEATUREVALUE_H_
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+class IFeatureValue
+{
+ public:
+ enum IdType
+ {
+ ZOOM,
+ NO_ZOOM,
+ CONTRAST,
+ BRIGHTNESS,
+ COLORTEMPERATURE,
+ NIGHTMODE,
+ MANUALFOCUS,
+ FOCUS,
+ LIGHT,
+ FLASH
+ };
+ private:
+ //The feature value identifier.
+ unsigned short m_id;
+
+ //An optional description of the feature value.
+ std::string m_description;
+
+ public:
+ IFeatureValue();
+ virtual ~IFeatureValue();
+};
+
+}
+}
+}
+#endif /* WRTPLUGINSIFEATUREVALUE_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
+ */
+
+#ifndef WRTDEVICEAPIS_CAMERA_API_SUPPORT_CAMERA_PENDING_OPERATION_H_
+#define WRTDEVICEAPIS_CAMERA_API_SUPPORT_CAMERA_PENDING_OPERATION_H_
+
+#include <CommonsJavaScript/SupportPendingOperation.h>
+#include <Commons/WrtWrapper/IWrtCamera.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+namespace Api {
+
+typedef WrtDeviceApis::CommonsJavaScript::SupportPendingOperation
+ <Commons::IWrtCamera::CameraPendingOperation> SupportCameraPendingOperation;
+
+}
+}
+}
+
+#endif
--- /dev/null
+get_current_path()
+
+set(API_CAMERA_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_CAMERA
+ ${CURRENT_PATH}/CameraFactory.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 Contact.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ *
+ */
+
+#include "Contact.h"
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+Contact::Contact() :
+ //initialize fields
+ m_id(-1),
+ m_fullNameIsSet(false),
+ m_firstNameIsSet(false),
+ m_lastNameIsSet(false),
+ m_phoneticNameIsSet(false),
+ m_companyIsSet(false),
+ m_titleIsSet(false),
+ m_photoUriIsSet(false),
+ m_ringTonePathIsSet(false)
+{
+ LogDebug("entered");
+}
+
+Contact::~Contact()
+{
+ //nothing to do in destructor
+ LogDebug("entered");
+}
+
+int Contact::getId() const
+{
+ //return id of contact
+ return m_id;
+}
+
+void Contact::setId(int value)
+{
+ //set new id of contact
+ m_id = value;
+}
+
+std::string Contact::getFullName() const
+{
+ //return fullname
+ //when fullname is not set then return concatendation of first name and last name
+ return m_fullName.empty() ? m_firstName + " " + m_lastName : m_fullName;
+}
+
+void Contact::setFullName(const std::string &value)
+{
+ //set fullname value
+ m_fullName = value;
+ //mark full name as set
+ m_fullNameIsSet = true;
+}
+
+std::string Contact::getFirstName() const
+{
+ //return first name
+ return m_firstName;
+}
+
+void Contact::setFirstName(const std::string &value)
+{
+ //set first name
+ m_firstName = value;
+ //mark first name as set
+ m_firstNameIsSet = true;
+}
+
+std::string Contact::getLastName() const
+{
+ //return last name
+ return m_lastName;
+}
+
+void Contact::setLastName(const std::string &value)
+{
+ //set last name
+ m_lastName = value;
+ //mark last name as set
+ m_lastNameIsSet = true;
+}
+
+const std::vector<std::string> &Contact::getNickNames() const
+{
+ //returns nicknames array
+ return m_nicknames;
+}
+
+void Contact::setNickNames(const std::vector<std::string> &value)
+{
+ //set new nicknames
+ m_nicknames = value;
+}
+
+std::string Contact::getPhoneticName() const
+{
+ //return phoneticName
+ return m_phoneticName;
+}
+
+void Contact::setPhoneticName(const std::string &value)
+{
+ //set new phoneticName
+ m_phoneticName = value;
+ m_phoneticNameIsSet = true;
+}
+
+const std::vector<ContactAddressPtr> &Contact::getAddresses() const
+{
+ //return addresses array
+ return m_addresses;
+}
+
+void Contact::setAddresses(const std::vector<ContactAddressPtr> &value)
+{
+ //set new addresses
+ m_addresses = value;
+}
+
+std::string Contact::getPhotoUri() const
+{
+ //return photo uri
+ return m_photoUri;
+}
+
+void Contact::setPhotoUri(const std::string &value)
+{
+ //set new photo uri
+ m_photoUri = value;
+ //mark photo uri as set
+ m_photoUriIsSet = true;
+}
+
+std::string Contact::getRingTonePath() const
+{
+ //return ring tone
+ return m_ringTonePath;
+}
+
+void Contact::setRingTonePath(const std::string &value)
+{
+ //set new ring tone
+ m_ringTonePath = value;
+ //mark ringtone as set
+ m_ringTonePathIsSet = true;
+}
+
+const std::vector<ContactPhoneNumberPtr> &Contact::getPhoneNumbers() const
+{
+ //return phone numbers
+ return m_phoneNumbers;
+}
+
+void Contact::setPhoneNumbers(const std::vector<ContactPhoneNumberPtr> &value)
+{
+ //set new phone numbers
+ m_phoneNumbers = value;
+}
+
+const std::vector<ContactEmailPtr> &Contact::getEmails() const
+{
+ //return emails
+ return m_emails;
+}
+
+void Contact::setEmails(const std::vector<ContactEmailPtr> &value)
+{
+ //set new emails
+ m_emails = value;
+}
+
+std::string Contact::getCompany() const
+{
+ //return company
+ return m_company;
+}
+
+void Contact::setCompany(const std::string &value)
+{
+ //set new company
+ m_company = value;
+ //mark company as set
+ m_companyIsSet = true;
+}
+
+std::string Contact::getTitle() const
+{
+ //return title
+ return m_title;
+}
+
+void Contact::setTitle(const std::string &value)
+{
+ //set new title
+ m_title = value;
+ //mark title as set
+ m_titleIsSet = true;
+}
+
+const std::vector<std::string> &Contact::getGroups() const
+{
+ //returns groups
+ return m_groups;
+}
+
+void Contact::setGroups(const std::vector<std::string> &value)
+{
+ //set new groups
+ m_groups = value;
+}
+
+bool Contact::getIdIsSet() const
+{
+ //return true when id is set
+ return m_id != -1;
+}
+
+bool Contact::getFullNameIsSet() const
+{
+ //return true when fullname is set
+ return m_fullNameIsSet;
+}
+
+bool Contact::getFirstNameIsSet() const
+{
+ //return true when first name is set
+ return m_firstNameIsSet;
+}
+
+bool Contact::getLastNameIsSet() const
+{
+ //return true when last name is set
+ return m_lastNameIsSet;
+}
+
+bool Contact::getCompanyIsSet() const
+{
+ //return true when company is set
+ return m_companyIsSet;
+}
+
+bool Contact::getTitleIsSet() const
+{
+ //return true when title is set
+ return m_titleIsSet;
+}
+
+bool Contact::getPhotoIsSet() const
+{
+ //return true when photo uri is set
+ return m_photoUriIsSet;
+}
+
+bool Contact::getRingPathIsSet() const
+{
+ //return true when ring tone is set
+ return m_ringTonePathIsSet;
+}
+
+bool Contact::getNicknameIsSet() const
+{
+ //return true when nicknames is set
+ return m_nicknames.size() != 0;
+}
+
+bool Contact::getPhoneticIsSet() const
+{
+ //return true when phoneticName is set
+ return m_phoneticNameIsSet;
+}
+
+bool Contact::getAddressIsSet() const
+{
+ //return true when addressess are set
+ return m_addresses.size() != 0;
+}
+
+bool Contact::getPhoneNumberIsSet() const
+{
+ //return true when phone numbers are set
+ return m_phoneNumbers.size() != 0;
+}
+
+bool Contact::getEmailIsSet() const
+{
+ //return true when emails are set
+ return m_emails.size() != 0;
+}
+
+void Contact::clear()
+{
+ LogDebug("entered");
+ //clear all fields
+ m_id = -1;
+ m_fullName.clear();
+ m_firstName.clear();
+ m_lastName.clear();
+ m_nicknames.clear();
+ m_addresses.clear();
+ m_photoUri.clear();
+ m_phoneNumbers.clear();
+ m_emails.clear();
+ m_company.clear();
+ m_title.clear();
+ m_groups.clear();
+ //mark fields as not set
+ m_fullNameIsSet = false;
+ m_firstNameIsSet = false;
+ m_lastNameIsSet = false;
+ m_phoneticNameIsSet = false;
+ m_companyIsSet = false;
+ m_titleIsSet = false;
+ m_photoUriIsSet = false;
+ m_ringTonePathIsSet = false;
+}
+
+ContactPtr Contact::clone()
+{
+ //clone object
+ //use defaul copy constructor
+ ContactPtr result(new Contact(*this));
+ std::vector<ContactAddressPtr> addresses;
+ std::vector<ContactPhoneNumberPtr> phoneNumbers;
+ std::vector<ContactEmailPtr> emails;
+ //clone internal representation of addresses
+ for (std::size_t i = 0; i < m_addresses.size(); ++i) {
+ addresses.push_back(m_addresses[i]->clone());
+ }
+ result->setAddresses(addresses);
+ //clone internal representation of phone numbers
+ for (std::size_t i = 0; i < m_phoneNumbers.size(); ++i) {
+ phoneNumbers.push_back(m_phoneNumbers[i]->clone());
+ }
+ result->setPhoneNumbers(phoneNumbers);
+ //clone internal representation of emails
+ for (std::size_t i = 0; i < m_emails.size(); ++i) {
+ emails.push_back(m_emails[i]->clone());
+ }
+ result->setEmails(emails);
+ return result;
+}
+
+}
+}
+}
\ 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 Contact.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Contact/ContactAddress.h>
+#include <Contact/ContactEmail.h>
+#include <Contact/ContactPhoneNumber.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+class Contact;
+
+typedef DPL::SharedPtr<Contact> ContactPtr;
+
+/* This object represents a single contact in address book */
+class Contact
+{
+ public:
+ Contact();
+ ~Contact();
+
+ int getId() const;
+ void setId(int value);
+
+ std::string getFullName() const;
+ void setFullName(const std::string &value);
+
+ std::string getFirstName() const;
+ void setFirstName(const std::string &value);
+
+ std::string getLastName() const;
+ void setLastName(const std::string &value);
+
+ const std::vector<std::string> &getNickNames() const;
+ void setNickNames(const std::vector<std::string> &value);
+
+ std::string getPhoneticName() const;
+ void setPhoneticName(const std::string &value);
+
+ const std::vector<ContactAddressPtr> &getAddresses() const;
+ void setAddresses(const std::vector<ContactAddressPtr> &value);
+
+ std::string getPhotoUri() const;
+ void setPhotoUri(const std::string &value);
+
+ std::string getRingTonePath() const;
+ void setRingTonePath(const std::string &value);
+
+ const std::vector<ContactPhoneNumberPtr> &getPhoneNumbers() const;
+ void setPhoneNumbers(const std::vector<ContactPhoneNumberPtr> &value);
+
+ const std::vector<ContactEmailPtr> &getEmails() const;
+ void setEmails(const std::vector<ContactEmailPtr> &value);
+
+ std::string getCompany() const;
+ void setCompany(const std::string &value);
+
+ std::string getTitle() const;
+ void setTitle(const std::string &value);
+
+ const std::vector<std::string> &getGroups() const;
+ void setGroups(const std::vector<std::string> &value);
+
+ void clear();
+ ContactPtr clone();
+
+ bool getIdIsSet() const;
+ bool getFullNameIsSet() const;
+ bool getFirstNameIsSet() const;
+ bool getLastNameIsSet() const;
+ bool getCompanyIsSet() const;
+ bool getTitleIsSet() const;
+ bool getPhotoIsSet() const;
+ bool getNicknameIsSet() const;
+ bool getPhoneticIsSet() const;
+ bool getAddressIsSet() const;
+ bool getPhoneNumberIsSet() const;
+ bool getEmailIsSet() const;
+ bool getRingPathIsSet() const;
+
+ private:
+ int m_id;
+ std::string m_fullName; //display name e.g. m_firstName + m_lastName
+ std::string m_firstName;
+ std::string m_lastName;
+ std::vector<std::string> m_nicknames;
+ std::string m_phoneticName;
+ std::vector<ContactAddressPtr> m_addresses;
+ std::string m_photoUri;
+ std::string m_ringTonePath;
+ std::vector<ContactPhoneNumberPtr> m_phoneNumbers;
+ std::vector<ContactEmailPtr> m_emails;
+ std::string m_company;
+ std::string m_title;
+ std::vector<std::string> m_groups;
+
+ bool m_fullNameIsSet;
+ bool m_firstNameIsSet;
+ bool m_lastNameIsSet;
+ bool m_phoneticNameIsSet;
+ bool m_companyIsSet;
+ bool m_titleIsSet;
+ bool m_photoUriIsSet;
+ bool m_ringTonePathIsSet;
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_CONTACT_H_
\ 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 ContactEmail.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ *
+ */
+
+#include <algorithm>
+#include "ContactAddress.h"
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+ContactAddress::ContactAddress() :
+ //initialize fields
+ m_id(-1),
+ m_countryIsSet(false),
+ m_regionIsSet(false),
+ m_countyIsSet(false),
+ m_cityIsSet(false),
+ m_streetIsSet(false),
+ m_streetNumberIsSet(false),
+ m_premisesIsSet(false),
+ m_additionalInformationIsSet(false),
+ m_postalCodeIsSet(false)
+{
+ //nothing to do
+}
+
+ContactAddress::~ContactAddress()
+{
+ //nothing to do
+}
+
+bool ContactAddress::compareTo(const ContactAddressPtr &address,
+ bool includeId,
+ bool includeTypes) const
+{
+ //compare basic fields
+ if ((!includeId || m_id == address->getId()) &&
+ m_country == address->getCountry() &&
+ m_region == address->getRegion() &&
+ m_county == address->getCounty() &&
+ m_city == address->getCity() &&
+ m_street == address->getStreet() &&
+ m_streetNumber == address->getStreetNumber() &&
+ m_premises == address->getPremises() &&
+ m_additionalInformation == address->getAdditionalInformation() &&
+ m_postalCode == address->getPostalCode()) {
+ //if not include fields then addresses are equal
+ if (!includeTypes) {
+ return true;
+ }
+ //if types have different sizes then addresses are different
+ if (m_types.size() != address->getTypes().size()) {
+ return false;
+ }
+ //compare each type
+ for (size_t i = 0; i < address->getTypes().size(); i++) {
+ if (!isTypeOf(address->getTypes()[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
+ContactAddressPtr ContactAddress::clone() const
+{
+ //clone object by using copy constructors
+ return ContactAddressPtr(new ContactAddress(*this));
+}
+
+std::string ContactAddress::getAsSingleString() const
+{
+ std::string fullAddress;
+ //add street and street number when not empty
+ if (!m_street.empty()) {
+ fullAddress = m_street;
+ if (!m_streetNumber.empty()) {
+ fullAddress += " " + m_streetNumber;
+ }
+ }
+ //add city and postal code when not empty
+ if (!m_city.empty()) {
+ if (!fullAddress.empty()) {
+ fullAddress += " ";
+ }
+ if (!m_postalCode.empty()) {
+ fullAddress += m_postalCode + " " + m_city;
+ } else {
+ fullAddress += m_city;
+ }
+ }
+ //add country when not empty
+ if (!m_country.empty()) {
+ if (!fullAddress.empty()) {
+ fullAddress += " " + m_country;
+ } else {
+ fullAddress = m_country;
+ }
+ }
+ if (!fullAddress.empty()) {
+ return fullAddress;
+ }
+ //when no data on detailed fields, then return free form field
+ return m_address;
+}
+
+std::string ContactAddress::getAddress() const
+{
+ //return free form field for address
+ return m_address;
+}
+
+void ContactAddress::setAddress(const std::string &value)
+{
+ //set free form field for address
+ m_address = value;
+}
+
+int ContactAddress::getId() const
+{
+ //return id of address record
+ return m_id;
+}
+
+void ContactAddress::setId(int value)
+{
+ //set id of address record
+ m_id = value;
+}
+
+std::string ContactAddress::getCountry() const
+{
+ //return country
+ return m_country;
+}
+
+void ContactAddress::setCountry(const std::string &value)
+{
+ //set new contry
+ m_country = value;
+ //mark country as set
+ m_countryIsSet = true;
+}
+
+std::string ContactAddress::getRegion() const
+{
+ //return region
+ return m_region;
+}
+
+void ContactAddress::setRegion(const std::string &value)
+{
+ //set new region
+ m_region = value;
+ //mark region as set
+ m_regionIsSet = true;
+}
+
+std::string ContactAddress::getCounty() const
+{
+ //return county
+ return m_county;
+}
+
+void ContactAddress::setCounty(const std::string &value)
+{
+ //set new county
+ m_county = value;
+ //set county as set
+ m_countyIsSet = true;
+}
+
+std::string ContactAddress::getCity() const
+{
+ //return city
+ return m_city;
+}
+
+void ContactAddress::setCity(const std::string &value)
+{
+ //set new city
+ m_city = value;
+ //set city as marked
+ m_cityIsSet = true;
+}
+
+std::string ContactAddress::getStreet() const
+{
+ //return street
+ return m_street;
+}
+
+void ContactAddress::setStreet(const std::string &value)
+{
+ //set street
+ m_street = value;
+ //mark streen as set
+ m_streetIsSet = true;
+}
+
+std::string ContactAddress::getStreetNumber() const
+{
+ //return street number
+ return m_streetNumber;
+}
+
+void ContactAddress::setStreetNumber(const std::string &value)
+{
+ //set street number
+ m_streetNumber = value;
+ //mark streen number as set
+ m_streetNumberIsSet = true;
+}
+
+std::string ContactAddress::getPremises() const
+{
+ //return premises
+ return m_premises;
+}
+
+void ContactAddress::setPremises(const std::string &value)
+{
+ //set premises
+ m_premises = value;
+ //mark premises as set
+ m_premisesIsSet = true;
+}
+
+std::string ContactAddress::getAdditionalInformation() const
+{
+ //return additional information
+ return m_additionalInformation;
+}
+
+void ContactAddress::setAdditionalInformation(const std::string &value)
+{
+ //set additional information
+ m_additionalInformation = value;
+ //mark additional information as set
+ m_additionalInformationIsSet = true;
+}
+
+std::string ContactAddress::getPostalCode() const
+{
+ //returns postal code
+ return m_postalCode;
+}
+
+void ContactAddress::setPostalCode(const std::string &value)
+{
+ //set new postal code
+ m_postalCode = value;
+ //mark postal code as set
+ m_postalCodeIsSet = true;
+}
+
+std::vector<ContactAddress::ContactAddressType> ContactAddress::getTypes()
+const
+{
+ //return address types
+ return m_types;
+}
+
+void ContactAddress::addType(const ContactAddressType value)
+{
+ //add new type to set
+ m_types.push_back(value);
+}
+
+void ContactAddress::setTypes(const std::vector<ContactAddressType> &value)
+{
+ //set types
+ m_types = value;
+}
+
+bool ContactAddress::isTypeOf(const ContactAddressType value) const
+{
+ //return true when address is type of type passed as argument
+ return std::find(m_types.begin(), m_types.end(), value) != m_types.end();
+}
+
+void ContactAddress::setTypeFilter(const ContactAddressType value)
+{
+ //clear existing types and add new one
+ m_types.clear();
+ m_types.push_back(value);
+}
+
+ContactAddress::ContactAddressType ContactAddress::getTypeFilter() const
+{
+ //return first type or undefined when non set
+ return m_types.size() == 0 ? CONTACT_ADDRESS_TYPE_PREF : m_types[0];
+}
+
+bool ContactAddress::getCountryIsSet() const
+{
+ //returns true when contry is set
+ return m_countryIsSet;
+}
+
+bool ContactAddress::getRegionIsSet() const
+{
+ //returns true when region is set
+ return m_regionIsSet;
+}
+
+bool ContactAddress::getCountyIsSet() const
+{
+ //returns true when county is set
+ return m_countyIsSet;
+}
+
+bool ContactAddress::getCityIsSet() const
+{
+ //returns true when city is set
+ return m_cityIsSet;
+}
+
+bool ContactAddress::getStreetIsSet() const
+{
+ //returns true when street is set
+ return m_streetIsSet;
+}
+
+bool ContactAddress::getStreetNumberIsSet() const
+{
+ //returns true when street number is set
+ return m_streetNumberIsSet;
+}
+
+bool ContactAddress::getPremisesIsSet() const
+{
+ //returns true when premises is set
+ return m_premisesIsSet;
+}
+
+bool ContactAddress::getAdditionalInformationIsSet() const
+{
+ //returns true when additional information is set
+ return m_additionalInformationIsSet;
+}
+
+bool ContactAddress::getPostalCodeIsSet() const
+{
+ //returns true when postal code is set
+ return m_postalCodeIsSet;
+}
+
+}
+}
+}
\ 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 ContactEmail.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_ADDRESS_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_ADDRESS_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+class ContactAddress;
+
+typedef DPL::SharedPtr<ContactAddress> ContactAddressPtr;
+typedef std::vector<ContactAddressPtr> ContactAddressPtrList;
+
+/* This object represents an address data of a contact */
+class ContactAddress
+{
+ public:
+
+ typedef enum
+ {
+ CONTACT_ADDRESS_TYPE_WORK,
+ CONTACT_ADDRESS_TYPE_PREF,
+ CONTACT_ADDRESS_TYPE_HOME
+ } ContactAddressType;
+
+ ContactAddress();
+ ~ContactAddress();
+
+ int getId() const;
+ void setId(int value);
+
+ std::string getCountry() const;
+ void setCountry(const std::string &value);
+
+ std::string getRegion() const;
+ void setRegion(const std::string &value);
+
+ std::string getCounty() const;
+ void setCounty(const std::string &value);
+
+ std::string getCity() const;
+ void setCity(const std::string &value);
+
+ std::string getStreet() const;
+ void setStreet(const std::string &value);
+
+ std::string getStreetNumber() const;
+ void setStreetNumber(const std::string &value);
+
+ std::string getPremises() const;
+ void setPremises(const std::string &value);
+
+ std::string getAdditionalInformation() const;
+ void setAdditionalInformation(const std::string &value);
+
+ std::string getPostalCode() const;
+ void setPostalCode(const std::string &value);
+
+ std::vector<ContactAddressType> getTypes() const;
+ void addType(const ContactAddressType value);
+ void setTypes(const std::vector<ContactAddressType> &value);
+ bool isTypeOf(const ContactAddressType value) const;
+ void setTypeFilter(const ContactAddressType value);
+ ContactAddressType getTypeFilter() const;
+
+ //returns m_country, ..., m_postalCode
+ //fields concatenated into single string
+ std::string getAsSingleString() const;
+ std::string getAddress() const;
+ void setAddress(const std::string &value);
+
+ bool compareTo(const ContactAddressPtr &address,
+ bool includeId = false,
+ bool includeTypes = false) const;
+ ContactAddressPtr clone() const;
+
+ bool getCountryIsSet() const;
+ bool getRegionIsSet() const;
+ bool getCountyIsSet() const;
+ bool getCityIsSet() const;
+ bool getStreetIsSet() const;
+ bool getStreetNumberIsSet() const;
+ bool getPremisesIsSet() const;
+ bool getAdditionalInformationIsSet() const;
+ bool getPostalCodeIsSet() const;
+
+ private:
+ int m_id;
+ std::string m_country;
+ std::string m_region;
+ std::string m_county;
+ std::string m_city;
+ std::string m_street;
+ std::string m_streetNumber;
+ std::string m_premises;
+ std::string m_additionalInformation;
+ std::string m_postalCode;
+ std::vector<ContactAddressType> m_types;
+
+ //this field is free form fieldand should not be used.
+ //it holds data used by Jil standard, but fields
+ //m_country, ..., m_postalCode should be used instead
+ std::string m_address;
+
+ bool m_countryIsSet;
+ bool m_regionIsSet;
+ bool m_countyIsSet;
+ bool m_cityIsSet;
+ bool m_streetIsSet;
+ bool m_streetNumberIsSet;
+ bool m_premisesIsSet;
+ bool m_additionalInformationIsSet;
+ bool m_postalCodeIsSet;
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_CONTACT_ADDRESS_H_
\ 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 ContactEmail.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "ContactEmail.h"
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+ContactEmail::ContactEmail()
+{
+}
+
+ContactEmail::~ContactEmail()
+{
+}
+
+std::string ContactEmail::getEmail() const
+{
+ return m_email;
+}
+
+void ContactEmail::setEmail(const std::string &value)
+{
+ m_email = value;
+}
+
+std::vector<ContactEmail::ContactEmailType> ContactEmail::getTypes() const
+{
+ return m_types;
+}
+
+void ContactEmail::addType(ContactEmailType value)
+{
+ m_types.push_back(value);
+}
+
+void ContactEmail::setTypes(const std::vector<ContactEmailType> value)
+{
+ m_types = value;
+}
+
+bool ContactEmail::isTypeOf(ContactEmailType value) const
+{
+ return std::find(m_types.begin(), m_types.end(), value) != m_types.end();
+}
+
+ContactEmail::ContactEmailType ContactEmail::getTypeFilter() const
+{
+ return m_types.size() == 0 ? CONTACT_EMAIL_TYPE_PREF : m_types[0];
+}
+
+void ContactEmail::setTypeFilter(ContactEmailType value)
+{
+ m_types.clear();
+ m_types.push_back(value);
+}
+
+ContactEmailPtr ContactEmail::clone() const
+{
+ return ContactEmailPtr(new ContactEmail(*this));
+}
+
+}
+}
+}
--- /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 ContactEmail.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_EMAIL_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_EMAIL_H_
+
+#include <algorithm>
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+class ContactEmail;
+
+typedef DPL::SharedPtr<ContactEmail> ContactEmailPtr;
+typedef std::vector<ContactEmailPtr> ContactEmailPtrList;
+
+/* This object represents an email data of a contact */
+class ContactEmail
+{
+ public:
+
+ typedef enum
+ {
+ CONTACT_EMAIL_TYPE_PREF,
+ CONTACT_EMAIL_TYPE_WORK,
+ CONTACT_EMAIL_TYPE_HOME
+ } ContactEmailType;
+
+ ContactEmail();
+ ~ContactEmail();
+ std::string getEmail() const;
+ void setEmail(const std::string &value);
+ std::vector<ContactEmailType> getTypes() const;
+ void addType(ContactEmailType value);
+ void setTypes(const std::vector<ContactEmailType> value);
+ bool isTypeOf(ContactEmailType value) const;
+ //methods to use when object is used as filter, not email data container
+ ContactEmailType getTypeFilter() const;
+ void setTypeFilter(ContactEmailType value);
+ ContactEmailPtr clone() const;
+ private:
+ std::string m_email;
+ std::vector<ContactEmailType> m_types;
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_CONTACT_EMAIL_H_
\ 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 ContactFactory.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "ContactFactory.h"
+#include <Contact/ContactManager.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+IContactManagerPtr ContactFactory::createContactManager()
+{
+ static IContactManagerPtr result(new ContactManager());
+ return result;
+}
+
+ContactFactory& ContactFactory::getInstance()
+{
+ static ContactFactory theInstance;
+ return theInstance;
+}
+
+}
+} // Api
+} // 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 ContactFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_FACTORY_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_FACTORY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Contact/IContactManager.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+class ContactFactory : private DPL::Noncopyable
+{
+ private:
+ ContactFactory()
+ {
+ }
+ public:
+ static ContactFactory& getInstance();
+ IContactManagerPtr createContactManager();
+};
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif //WRTDEVICEAPIS_CONTACT_CONTACT_FACTORY_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 ContactFilter.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "ContactFilter.h"
+
+namespace {
+const int CONTACT_FILTER_UNDEFINED_CONTACT_ID = -1;
+}
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+ContactFilter::ContactFilter() :
+ m_id(CONTACT_FILTER_UNDEFINED_CONTACT_ID),
+ m_fullNameIsSet(false),
+ m_firstNameIsSet(false),
+ m_lastNameIsSet(false),
+ m_phoneticNameIsSet(false),
+ m_companyIsSet(false),
+ m_titleIsSet(false),
+ m_groupIsSet(false)
+{
+}
+
+ContactFilter::~ContactFilter()
+{
+}
+
+int ContactFilter::getIdFilter() const
+{
+ return m_id;
+}
+
+void ContactFilter::setIdFilter(int value)
+{
+ m_id = value;
+}
+
+bool ContactFilter::getIdIsSet() const
+{
+ return m_id != CONTACT_FILTER_UNDEFINED_CONTACT_ID;
+}
+
+std::string ContactFilter::getFullNameFilter() const
+{
+ return m_fullName;
+}
+
+void ContactFilter::setFullNameFilter(const std::string &value)
+{
+ m_fullName = value;
+ m_fullNameIsSet = true;
+}
+
+bool ContactFilter::getFullNameIsSet() const
+{
+ return m_fullNameIsSet;
+}
+
+std::string ContactFilter::getFirstNameFilter() const
+{
+ return m_firstName;
+}
+
+void ContactFilter::setFirstNameFilter(const std::string &value)
+{
+ m_firstName = value;
+ m_firstNameIsSet = true;
+}
+
+bool ContactFilter::getFirstNameIsSet() const
+{
+ return m_firstNameIsSet;
+}
+
+std::string ContactFilter::getLastNameFilter() const
+{
+ return m_lastName;
+}
+
+void ContactFilter::setLastNameFilter(const std::string &value)
+{
+ m_lastName = value;
+ m_lastNameIsSet = true;
+}
+
+bool ContactFilter::getLastNameIsSet() const
+{
+ return m_lastNameIsSet;
+}
+
+std::string ContactFilter::getPhoneticNameFilter() const
+{
+ return m_phoneticName;
+}
+
+void ContactFilter::setPhoneticNameFilter(const std::string &value)
+{
+ m_phoneticName = value;
+ m_phoneticNameIsSet = true;
+}
+
+bool ContactFilter::getPhoneticNameIsSet() const
+{
+ return m_phoneticNameIsSet;
+}
+
+std::string ContactFilter::getCompanyFilter() const
+{
+ return m_company;
+}
+
+void ContactFilter::setCompanyFilter(const std::string &value)
+{
+ m_company = value;
+ m_companyIsSet = true;
+}
+
+bool ContactFilter::getCompanyIsSet() const
+{
+ return m_companyIsSet;
+}
+
+std::string ContactFilter::getTitleFilter() const
+{
+ return m_title;
+}
+
+void ContactFilter::setTitleFilter(const std::string &value)
+{
+ m_title = value;
+ m_titleIsSet = true;
+}
+
+bool ContactFilter::getTitleIsSet() const
+{
+ return m_titleIsSet;
+}
+
+const std::vector<ContactPhoneNumberPtr> &ContactFilter::getPhoneNumberFilter()
+const
+{
+ return m_phoneNumber;
+}
+
+void ContactFilter::setPhoneNumberFilter(
+ const std::vector<ContactPhoneNumberPtr> &value)
+{
+ m_phoneNumber = value;
+}
+
+bool ContactFilter::getPhoneNumberIsSet() const
+{
+ return m_phoneNumber.size() != 0;
+}
+
+const std::vector<ContactEmailPtr> &ContactFilter::getEmailFilter() const
+{
+ return m_email;
+}
+
+void ContactFilter::setEmailFilter(const std::vector<ContactEmailPtr> &value)
+{
+ m_email = value;
+}
+
+bool ContactFilter::getEmailIsSet() const
+{
+ return m_email.size() != 0;
+}
+
+const std::vector<std::string> &ContactFilter::getNickNameFilter()
+{
+ return m_nickname;
+}
+
+void ContactFilter::setNickNameFilter(const std::vector<std::string> &value)
+{
+ m_nickname = value;
+}
+
+bool ContactFilter::getNickNameIsSet() const
+{
+ return m_nickname.size() != 0;
+}
+
+const std::vector<ContactAddressPtr> &ContactFilter::getAddressFilter()
+{
+ return m_address;
+}
+
+void ContactFilter::setAddressFilter(
+ const std::vector<ContactAddressPtr> &value)
+{
+ m_address = value;
+}
+
+bool ContactFilter::getAddressIsSet() const
+{
+ return m_address.size() != 0;
+}
+
+std::string ContactFilter::getGroupFilter() const
+{
+ return m_group;
+}
+
+void ContactFilter::setGroupFilter(const std::string &value)
+{
+ m_group = value;
+ m_groupIsSet = true;
+}
+
+bool ContactFilter::getGroupIsSet() const
+{
+ return m_groupIsSet;
+}
+
+}
+}
+}
--- /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 ContactFilter.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_FILTER_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_FILTER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Contact/Contact.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* This class is used as filter while searching contacts */
+class ContactFilter
+{
+ public:
+
+ ContactFilter();
+ virtual ~ContactFilter();
+
+ int getIdFilter() const;
+ void setIdFilter(int value);
+
+ std::string getFullNameFilter() const;
+ void setFullNameFilter(const std::string &value);
+
+ std::string getFirstNameFilter() const;
+ void setFirstNameFilter(const std::string &value);
+
+ std::string getLastNameFilter() const;
+ void setLastNameFilter(const std::string &value);
+
+ std::string getPhoneticNameFilter() const;
+ void setPhoneticNameFilter(const std::string &value);
+
+ std::string getCompanyFilter() const;
+ void setCompanyFilter(const std::string &value);
+
+ std::string getTitleFilter() const;
+ void setTitleFilter(const std::string &value);
+
+ const std::vector<ContactPhoneNumberPtr> &getPhoneNumberFilter() const;
+ void setPhoneNumberFilter(const std::vector<ContactPhoneNumberPtr> &value);
+
+ const std::vector<ContactEmailPtr> &getEmailFilter() const;
+ void setEmailFilter(const std::vector<ContactEmailPtr> &value);
+
+ const std::vector<std::string> &getNickNameFilter();
+ void setNickNameFilter(const std::vector<std::string> &value);
+
+ const std::vector<ContactAddressPtr> &getAddressFilter();
+ void setAddressFilter(const std::vector<ContactAddressPtr> &value);
+
+ std::string getGroupFilter() const;
+ void setGroupFilter(const std::string &value);
+
+ bool getIdIsSet() const;
+ bool getFullNameIsSet() const;
+ bool getFirstNameIsSet() const;
+ bool getLastNameIsSet() const;
+ bool getPhoneticNameIsSet() const;
+
+ bool getCompanyIsSet() const;
+ bool getTitleIsSet() const;
+ bool getPhoneNumberIsSet() const;
+ bool getEmailIsSet() const;
+ bool getNickNameIsSet() const;
+
+ bool getAddressIsSet() const;
+ bool getGroupIsSet() const;
+
+ protected:
+ int m_id;
+ std::string m_fullName; //display name e.g. m_firstName + m_lastName
+ std::string m_firstName;
+ std::string m_lastName;
+ std::string m_phoneticName;
+
+ std::string m_company;
+ std::string m_title;
+ std::vector<ContactPhoneNumberPtr> m_phoneNumber;
+ std::vector<ContactEmailPtr> m_email;
+ std::vector<std::string> m_nickname;
+
+ std::vector<ContactAddressPtr> m_address;
+ std::string m_group;
+
+ bool m_fullNameIsSet;
+ bool m_firstNameIsSet;
+ bool m_lastNameIsSet;
+ bool m_phoneticNameIsSet;
+ bool m_companyIsSet;
+ bool m_titleIsSet;
+ bool m_groupIsSet;
+};
+
+typedef DPL::SharedPtr<ContactFilter> ContactFilterPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_CONTACT_FILTER_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 ContactPhoneNumber.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "ContactPhoneNumber.h"
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+ContactPhoneNumber::ContactPhoneNumber()
+{
+}
+
+ContactPhoneNumber::~ContactPhoneNumber()
+{
+}
+
+std::string ContactPhoneNumber::getNumber() const
+{
+ return m_number;
+}
+
+void ContactPhoneNumber::setNumber(const std::string &value)
+{
+ m_number = value;
+}
+
+std::vector<ContactPhoneNumber::ContactPhoneNumberType> ContactPhoneNumber::
+ getTypes() const
+{
+ return m_types;
+}
+
+void ContactPhoneNumber::addType(const ContactPhoneNumberType value)
+{
+ m_types.push_back(value);
+}
+
+void ContactPhoneNumber::setTypes(
+ const std::vector<ContactPhoneNumberType> value)
+{
+ m_types = value;
+}
+
+bool ContactPhoneNumber::isTypeOf(
+ ContactPhoneNumber::ContactPhoneNumberType value) const
+{
+ return std::find(m_types.begin(), m_types.end(), value) != m_types.end();
+}
+
+ContactPhoneNumber::ContactPhoneNumberType ContactPhoneNumber::getTypeFilter()
+const
+{
+ return m_types.size() == 0 ? CONTACT_PHONE_NUMBER_TYPE_PREF : m_types[0];
+}
+
+void ContactPhoneNumber::setTypeFilter(
+ ContactPhoneNumber::ContactPhoneNumberType value)
+{
+ m_types.clear();
+ m_types.push_back(value);
+}
+
+ContactPhoneNumberPtr ContactPhoneNumber::clone() const
+{
+ return ContactPhoneNumberPtr(new ContactPhoneNumber(*this));
+}
+
+}
+}
+}
\ 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 ContactPhoneNumber.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_PHONE_NUMBER_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_PHONE_NUMBER_H_
+
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+class ContactPhoneNumber;
+
+typedef DPL::SharedPtr<ContactPhoneNumber> ContactPhoneNumberPtr;
+typedef std::vector<ContactPhoneNumberPtr> ContactPhoneNumberPtrList;
+typedef DPL::SharedPtr<ContactPhoneNumberPtrList> ContactPhoneNumberPtrListPtr;
+
+/* This object represents a phone number data of a contact */
+class ContactPhoneNumber
+{
+ public:
+
+ typedef enum
+ {
+ CONTACT_PHONE_NUMBER_TYPE_WORK,
+ CONTACT_PHONE_NUMBER_TYPE_PREF,
+ CONTACT_PHONE_NUMBER_TYPE_HOME,
+ CONTACT_PHONE_NUMBER_TYPE_VOICE,
+ CONTACT_PHONE_NUMBER_TYPE_FAX,
+ CONTACT_PHONE_NUMBER_TYPE_MSG,
+ CONTACT_PHONE_NUMBER_TYPE_CELL,
+ CONTACT_PHONE_NUMBER_TYPE_PAGER,
+ CONTACT_PHONE_NUMBER_TYPE_BBS,
+ CONTACT_PHONE_NUMBER_TYPE_MODEM,
+ CONTACT_PHONE_NUMBER_TYPE_CAR,
+ CONTACT_PHONE_NUMBER_TYPE_ISDN,
+ CONTACT_PHONE_NUMBER_TYPE_VIDEO,
+ CONTACT_PHONE_NUMBER_TYPE_PCS
+ } ContactPhoneNumberType;
+
+ ContactPhoneNumber();
+ ~ContactPhoneNumber();
+ std::string getNumber() const;
+ void setNumber(const std::string &value);
+ std::vector<ContactPhoneNumberType> getTypes() const;
+ void addType(const ContactPhoneNumberType value);
+ void setTypes(const std::vector<ContactPhoneNumberType> value);
+ bool isTypeOf(ContactPhoneNumberType value) const;
+ //methods to use when object is used as filter, not email data container
+ ContactPhoneNumberType getTypeFilter() const;
+ void setTypeFilter(ContactPhoneNumberType value);
+ ContactPhoneNumberPtr clone() const;
+
+ private:
+ std::string m_number;
+ std::vector<ContactPhoneNumberType> m_types;
+};
+
+}
+}
+}
+
+#endif
\ 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.
+ */
+/*
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_ADD_CONTACT_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_ADD_CONTACT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Contact/Contact.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while adding new contact */
+class EventAddContact : public Commons::IEvent<EventAddContact>
+{
+ bool m_result;
+ ContactPtr m_contact;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setContact(const ContactPtr &contact)
+ {
+ m_contact = contact;
+ }
+ ContactPtr getContact() const
+ {
+ return m_contact;
+ }
+
+ EventAddContact() : m_result(false),
+ m_contact(NULL)
+ {
+ }
+ virtual ~EventAddContact()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventAddContact> EventAddContactPtr;
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_ADD_CONTACT_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_ADD_GROUP_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_ADD_GROUP_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while adding new group */
+class EventAddGroup : public Commons::IEvent<EventAddGroup>
+{
+ bool m_result;
+ std::string m_groupName;
+ public:
+ void setGroupName(const std::string &value)
+ {
+ m_groupName = value;
+ }
+ std::string getGroupName() const
+ {
+ return m_groupName;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+
+ EventAddGroup() : m_result(false)
+ {
+ }
+ virtual ~EventAddGroup()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventAddGroup> EventAddGroupPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_ADD_GROUP_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_DELETE_CONTACT_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_DELETE_CONTACT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Contact/ContactFilter.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while deleting contact */
+class EventDeleteContact : public Commons::IEvent<
+ EventDeleteContact>
+{
+ ContactFilterPtr m_filter;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setFilter(const ContactFilterPtr &contact)
+ {
+ m_filter = contact;
+ }
+ ContactFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ EventDeleteContact() : m_filter(NULL),
+ m_result(false)
+ {
+ }
+ virtual ~EventDeleteContact()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventDeleteContact> EventDeleteContactPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_DELETE_CONTACT_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_DELETE_GROUP_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_DELETE_GROUP_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while deleting a group */
+class EventDeleteGroup : public Commons::IEvent<EventDeleteGroup>
+{
+ bool m_result;
+ std::string m_groupName;
+ public:
+ void setGroupName(const std::string &value)
+ {
+ m_groupName = value;
+ }
+ std::string getGroupName() const
+ {
+ return m_groupName;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+
+ EventDeleteGroup() : m_result(false)
+ {
+ }
+ ~EventDeleteGroup()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventDeleteGroup> EventDeleteGroupPtr;
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_DELETE_GROUP_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_EXPORT_VCARD_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_EXPORT_VCARD_H_
+
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Contact/Contact.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while exporting VCard file */
+class EventExportVCard : public Commons::IEvent<EventExportVCard>
+{
+ bool m_result;
+ std::vector<std::string> m_pathToFiles;
+ std::vector<ContactPtr> m_contacts;
+ public:
+ void setContacts(const std::vector<ContactPtr> &value)
+ {
+ m_contacts = value;
+ }
+ std::vector<ContactPtr> getContacts() const
+ {
+ return m_contacts;
+ }
+ void setPathToFiles(const std::vector<std::string> &value)
+ {
+ m_pathToFiles = value;
+ }
+ std::vector<std::string> getPathToFiles() const
+ {
+ return m_pathToFiles;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+
+ EventExportVCard() : m_result(false)
+ {
+ }
+ virtual ~EventExportVCard()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventExportVCard> EventExportVCardPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_EXPORT_VCARD_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_FIND_CONTACT_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_FIND_CONTACT_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Contact/ContactFilter.h>
+#include <Contact/Contact.h>
+#include <Contact/IContactEventPrivateData.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while searching contacts */
+class EventFindContacts : public Commons::IEvent<EventFindContacts>
+{
+ bool m_result;
+ std::vector<ContactPtr> m_contacts;
+ ContactFilterPtr m_filter;
+ int m_startIndex;
+ int m_endIndex;
+ //this variable allows to use only one type per contact objects (check Contact object and contained subobjects)
+ //e.g. if contact has the same email as PREF and WORK, we can get 2 record with 1 type in each record, or singe record with 2 types within it.
+ bool m_useSingleTypes;
+
+ //this variable is not revelant to perform operation,
+ //but allows to store additional data to finish further operations in callback function.
+ IContactEventPrivateDataPtr m_privateData;
+ public:
+ void setContactEventPrivateData(const IContactEventPrivateDataPtr &value)
+ {
+ m_privateData = value;
+ }
+ IContactEventPrivateDataPtr getContactEventPrivateData() const
+ {
+ return m_privateData;
+ }
+ void setStartIndex(int value)
+ {
+ m_startIndex = value;
+ }
+ int getStartIndex() const
+ {
+ return m_startIndex;
+ }
+ void setEndIndex(int value)
+ {
+ m_endIndex = value;
+ }
+ int getEndIndex() const
+ {
+ return m_endIndex;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setUseSignleTypes(bool value)
+ {
+ m_useSingleTypes = value;
+ }
+ bool getUseSignleTypes() const
+ {
+ return m_useSingleTypes;
+ }
+ void setFilter(const ContactFilterPtr &filter)
+ {
+ m_filter = filter;
+ }
+ ContactFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ void addContact(const ContactPtr &contact)
+ {
+ m_contacts.push_back(contact);
+ }
+ const std::vector<ContactPtr> &getContacts() const
+ {
+ return m_contacts;
+ }
+ void setContacts(const std::vector<ContactPtr> &value)
+ {
+ m_contacts = value;
+ }
+
+ EventFindContacts() : m_result(false),
+ m_filter(NULL),
+ m_startIndex(-1),
+ m_endIndex(-1),
+ m_useSingleTypes(true)
+ {
+ }
+ virtual ~EventFindContacts()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventFindContacts> EventFindContactsPtr;
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_FIND_CONTACT_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_FIND_GROUP_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_FIND_GROUP_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while searching group */
+class EventFindGroup : public Commons::IEvent<EventFindGroup>
+{
+ bool m_result;
+ std::string m_groupName; //can be used as regular expressions mask or empty for all groups
+ std::vector<std::string> m_foundGroups;
+ public:
+ void addFoundGroup(const std::string &value)
+ {
+ m_foundGroups.push_back(value);
+ }
+ const std::vector<std::string> &getFoundGroups() const
+ {
+ return m_foundGroups;
+ }
+ void setFoundGroups(const std::vector<std::string> &value)
+ {
+ m_foundGroups = value;
+ }
+ void setGroupName(const std::string &value)
+ {
+ m_groupName = value;
+ }
+ std::string getGroupName() const
+ {
+ return m_groupName;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ EventFindGroup() : m_result(false)
+ {
+ }
+ virtual ~EventFindGroup()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventFindGroup> EventFindGroupPtr;
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_FIND_GROUP_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_GET_ADDRESSBOOKITEM_COUNT_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_GET_ADDRESSBOOKITEM_COUNT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while getting address books count */
+class EventGetAddressBookItemCount :
+ public Commons::IEvent<EventGetAddressBookItemCount>
+{
+ bool m_result;
+ unsigned int m_numberOfAddressBookItems;
+ public:
+ void setNumberOfAddressBookItems(unsigned int value)
+ {
+ m_numberOfAddressBookItems = value;
+ }
+ unsigned int getNumberOfAddressBookItems() const
+ {
+ return m_numberOfAddressBookItems;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+
+ EventGetAddressBookItemCount() : m_result(false),
+ m_numberOfAddressBookItems(0)
+ {
+ }
+ virtual ~EventGetAddressBookItemCount()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetAddressBookItemCount>
+EventGetAddressBookItemCountPtr;
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_GET_ADDRESSBOOKITEM_COUNT_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_GET_PHONEBOOKS_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_GET_PHONEBOOKS_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Contact/IAddressBook.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while getting address books */
+class EventGetAddressBooks : public Commons::IEvent<EventGetAddressBooks>
+{
+ bool m_result;
+ std::vector<IAddressBookObjectPtr> m_books;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void addAddressBook(const IAddressBookObjectPtr &addressBook)
+ {
+ m_books.push_back(addressBook);
+ }
+ const std::vector<IAddressBookObjectPtr> &getBooks() const
+ {
+ return m_books;
+ }
+
+ EventGetAddressBooks() : m_result(false)
+ {
+ }
+ virtual ~EventGetAddressBooks()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetAddressBooks> EventGetAddressBooksPtr;
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_GET_PHONEBOOKS_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 EventGetOwnerInfo.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_GET_OWNER_INFO_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_GET_OWNER_INFO_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Contact/Contact.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while getting phone's owner data */
+class EventGetOwnerInfo : public Commons::IEvent<EventGetOwnerInfo>
+{
+ bool m_result;
+ bool m_dataFound;
+ ContactPtr m_ownerInfo;
+ public:
+ void setOwnerInfo(const ContactPtr &value)
+ {
+ m_ownerInfo = value;
+ }
+ ContactPtr getOwnerInfo() const
+ {
+ return m_ownerInfo;
+ }
+ void setDataFound(bool value)
+ {
+ m_dataFound = value;
+ }
+ bool getDataFound() const
+ {
+ return m_dataFound;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ EventGetOwnerInfo() :
+ m_result(false),
+ m_dataFound(false)
+ {
+ }
+ virtual ~EventGetOwnerInfo()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetOwnerInfo> EventGetOwnerInfoPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_GET_OWNER_INFO_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_EVENT_UPDATE_CONTACT_H_
+#define WRTDEVICEAPIS_CONTACT_EVENT_UPDATE_CONTACT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Contact/Contact.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* Event sent while updating contact */
+class EventUpdateContact : public Commons::IEvent<
+ EventUpdateContact>
+{
+ bool m_result;
+ ContactPtr m_contact;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setContact(const ContactPtr &contact)
+ {
+ m_contact = contact;
+ }
+ ContactPtr getContact() const
+ {
+ return m_contact;
+ }
+ EventUpdateContact() : m_result(false),
+ m_contact(NULL)
+ {
+ }
+ virtual ~EventUpdateContact()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventUpdateContact> EventUpdateContactPtr;
+
+}
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CONTACT_EVENT_UPDATE_CONTACT_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 IAddressBook.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "IAddressBook.h"
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+IAddressBookObject::IAddressBookObject(BookType type) :
+ //initialize all receivers to work on CONTACT_THREAD thread
+ Commons::EventRequestReceiver<EventAddContact>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventUpdateContact>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventFindContacts>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventDeleteContact>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventGetAddressBookItemCount>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventAddGroup>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventDeleteGroup>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventFindGroup>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventExportVCard>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ m_bookType(type)
+{
+ //Nothing to do
+ LogDebug("entered");
+}
+
+IAddressBookObject::~IAddressBookObject()
+{
+ //Nothing to do
+ LogDebug("entered");
+}
+
+IAddressBookObject::BookType IAddressBookObject::getType() const
+{
+ //return address book type: sim or device
+ return m_bookType;
+}
+
+void IAddressBookObject::addContact(const EventAddContactPtr &event)
+{
+ Commons::EventRequestReceiver< EventAddContact >::PostRequest(event);
+}
+
+void IAddressBookObject::updateContact(const EventUpdateContactPtr &event)
+{
+ Commons::EventRequestReceiver< EventUpdateContact >::PostRequest(event);
+}
+
+void IAddressBookObject::deleteContact(const EventDeleteContactPtr &event)
+{
+ Commons::EventRequestReceiver< EventDeleteContact >::PostRequest(event);
+}
+
+void IAddressBookObject::findContacts(const EventFindContactsPtr &event)
+{
+ Commons::EventRequestReceiver< EventFindContacts >::PostRequest(event);
+}
+
+void IAddressBookObject::getNumberOfContact(
+ const EventGetAddressBookItemCountPtr &event)
+{
+ Commons::EventRequestReceiver< EventGetAddressBookItemCount >::PostRequest(
+ event);
+}
+
+void IAddressBookObject::addGroup(const EventAddGroupPtr &event)
+{
+ Commons::EventRequestReceiver< EventAddGroup >::PostRequest(event);
+}
+
+void IAddressBookObject::deleteGroup(const EventDeleteGroupPtr &event)
+{
+ Commons::EventRequestReceiver< EventDeleteGroup >::PostRequest(event);
+}
+
+void IAddressBookObject::findGroup(const EventFindGroupPtr &event)
+{
+ Commons::EventRequestReceiver< EventFindGroup >::PostRequest(event);
+}
+
+void IAddressBookObject::exportToVCard(const EventExportVCardPtr &event)
+{
+ Commons::EventRequestReceiver< EventExportVCard >::PostRequest(event);
+}
+
+}
+}
+}
--- /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 IAddressBook.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_IADDRESSBOOK_H_
+#define WRTDEVICEAPIS_CONTACT_IADDRESSBOOK_H_
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Contact/EventAddContact.h>
+#include <Contact/EventDeleteContact.h>
+#include <Contact/EventFindContacts.h>
+#include <Contact/EventUpdateContact.h>
+#include <Contact/EventGetAddressBookItemCount.h>
+#include <Contact/EventAddGroup.h>
+#include <Contact/EventDeleteGroup.h>
+#include <Contact/EventFindGroup.h>
+#include <Contact/EventExportVCard.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+class IAddressBookObject :
+ public Commons::EventRequestReceiver<EventAddContact>,
+ public Commons::EventRequestReceiver<EventUpdateContact>,
+ public Commons::EventRequestReceiver<EventFindContacts>,
+ public Commons::EventRequestReceiver<EventDeleteContact>,
+ public Commons::EventRequestReceiver<EventGetAddressBookItemCount>,
+ public Commons::EventRequestReceiver<EventAddGroup>,
+ public Commons::EventRequestReceiver<EventDeleteGroup>,
+ public Commons::EventRequestReceiver<EventFindGroup>,
+ public Commons::EventRequestReceiver<EventExportVCard>,
+ public IContactEventPrivateData
+{
+ public:
+ typedef enum
+ {
+ SIMBook,
+ PhoneBook
+ } BookType;
+
+ virtual ~IAddressBookObject();
+ explicit IAddressBookObject(BookType type);
+
+ virtual void addContact(const EventAddContactPtr &event);
+ virtual void updateContact(const EventUpdateContactPtr &event);
+ virtual void findContacts(const EventFindContactsPtr &event);
+ virtual void deleteContact(const EventDeleteContactPtr &event);
+ virtual void getNumberOfContact(
+ const EventGetAddressBookItemCountPtr &event);
+ virtual void addGroup(const EventAddGroupPtr &event);
+ virtual void deleteGroup(const EventDeleteGroupPtr &event);
+ virtual void findGroup(const EventFindGroupPtr &event);
+ virtual void exportToVCard(const EventExportVCardPtr &event);
+
+ virtual BookType getType() const;
+ virtual std::string getName() const = 0;
+ virtual void setName(const std::string &value) = 0;
+
+ protected:
+ BookType m_bookType;
+
+ virtual void OnRequestReceived(const EventAddContactPtr &event) = 0;
+ virtual void OnRequestReceived(const EventUpdateContactPtr &event) = 0;
+ virtual void OnRequestReceived(const EventDeleteContactPtr &event) = 0;
+ virtual void OnRequestReceived(const EventFindContactsPtr &event) = 0;
+ virtual void OnRequestReceived(
+ const EventGetAddressBookItemCountPtr &event) = 0;
+ virtual void OnRequestReceived(const EventAddGroupPtr &event) = 0;
+ virtual void OnRequestReceived(const EventDeleteGroupPtr &event) = 0;
+ virtual void OnRequestReceived(const EventFindGroupPtr &event) = 0;
+ virtual void OnRequestReceived(const EventExportVCardPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IAddressBookObject> IAddressBookObjectPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_IADDRESSBOOK_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 ContactEventPrivateData.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_EVENT_PRIVATE_DATA_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_EVENT_PRIVATE_DATA_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+/* This is base class for objects stored as private data inside some contact events */
+class IContactEventPrivateData
+{
+};
+
+typedef DPL::SharedPtr<IContactEventPrivateData> IContactEventPrivateDataPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_CONTACT_EVENT_PRIVATE_DATA_H_
\ 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 IContactManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <Commons/ThreadPool.h>
+#include "IContactManager.h"
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+IContactManager::IContactManager() :
+ //initialize all receivers to work on CONTACT_THREAD thread
+ Commons::EventRequestReceiver<EventGetAddressBooks>(
+ Commons::ThreadEnum::CONTACT_THREAD),
+ Commons::EventRequestReceiver<EventGetOwnerInfo>(
+ Commons::ThreadEnum::CONTACT_THREAD)
+{
+ //Nothing to do
+}
+
+IContactManager::~IContactManager()
+{
+ //Nothing to do
+}
+
+void IContactManager::getOwnerInfo(const EventGetOwnerInfoPtr &event)
+{
+ Commons::EventRequestReceiver<EventGetOwnerInfo>::PostRequest(event);
+}
+
+void IContactManager::getAddressBooks(const EventGetAddressBooksPtr &event)
+{
+ Commons::EventRequestReceiver< EventGetAddressBooks >::PostRequest(event);
+}
+
+}
+}
+}
--- /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 IContactManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_ICONTACT_MANAGER_H_
+#define WRTDEVICEAPIS_CONTACT_ICONTACT_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Contact/EventGetAddressBooks.h>
+#include <Contact/EventGetOwnerInfo.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+namespace Api {
+
+class IContactManager :
+ public Commons::EventRequestReceiver<EventGetAddressBooks>,
+ public Commons::EventRequestReceiver<EventGetOwnerInfo>
+{
+ public:
+ IContactManager();
+ virtual ~IContactManager();
+ virtual void getAddressBooks(const EventGetAddressBooksPtr &event);
+ virtual void getOwnerInfo(const EventGetOwnerInfoPtr &event);
+ protected:
+ virtual void OnRequestReceived(const EventGetAddressBooksPtr &event) = 0;
+ virtual void OnRequestReceived(const EventGetOwnerInfoPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IContactManager> IContactManagerPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_ICALENDAR_MANAGER_H_
--- /dev/null
+get_current_path()
+
+set(API_CONTACT_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_CONTACT
+ ${CURRENT_PATH}/Contact.cpp
+ ${CURRENT_PATH}/ContactFilter.cpp
+ ${CURRENT_PATH}/ContactAddress.cpp
+ ${CURRENT_PATH}/ContactEmail.cpp
+ ${CURRENT_PATH}/ContactPhoneNumber.cpp
+ ${CURRENT_PATH}/ContactFactory.cpp
+ ${CURRENT_PATH}/IAddressBook.cpp
+ ${CURRENT_PATH}/IContactManager.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 <Cpu/Manager.h>
+#include "IManager.h"
+
+namespace WrtDeviceApis {
+namespace Cpu {
+namespace Api {
+
+IManager& IManager::getInstance()
+{
+ return Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+
+} // Cpu
+} // Api
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_CPU_IMANAGER_H_
+#define WRTDEVICEAPIS_CPU_IMANAGER_H_
+
+#include <cstddef>
+#include <dpl/noncopyable.h>
+#include <Cpu/IUnit.h>
+
+namespace WrtDeviceApis {
+namespace Cpu {
+namespace Api {
+
+class IManager : private DPL::Noncopyable
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets interface to CPU.
+ * @param index Index of CPU to get (1-based).
+ * @return Interface to CPU.
+ * @throw PlatformException If platform error occurs.
+ * @throw OutOfRangeException If index is greater than available CPUs.
+ * @remarks On some platforms passing 0 as index may return unit object
+ * that gives avarage data for all CPUs. If such interface is
+ * not supported then NULL is returned.
+ * @remarks Ownership is NOT passed to the caller.
+ */
+ virtual IUnit* getUnit(std::size_t index) const = 0;
+
+ /**
+ * Gets number of available CPUs.
+ * @return Number of CPUs.
+ */
+ virtual std::size_t getUnitsCount() const = 0;
+};
+
+} // Api
+} // Cpu
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CPU_IMANAGER_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 "IUnit.h"
+
+namespace WrtDeviceApis {
+namespace Cpu {
+namespace Api {
+
+IUnit::~IUnit()
+{
+}
+
+} // Cpu
+} // Api
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_CPU_IUNIT_H_
+#define WRTDEVICEAPIS_CPU_IUNIT_H_
+
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Cpu {
+namespace Api {
+
+class IUnit
+{
+ public:
+ virtual ~IUnit() = 0;
+
+ /**
+ * Gets processor utilization percent.
+ * @return CPU utilization percent.
+ */
+ virtual unsigned int getUtilizationPercent() const = 0;
+};
+
+typedef DPL::SharedPtr<IUnit> IUnitPtr;
+
+} // Api
+} // Cpu
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CPU_IUNIT_H_
--- /dev/null
+get_current_path()
+
+set(API_CPU_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_CPU
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/IUnit.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 AppLauncherFactory.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <AppLauncher/AppLauncherManager.h>
+#include "AppLauncherFactory.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+IAppLauncherManagerPtr AppLauncherFactory::createAppLauncherManagerObject()
+{
+ IAppLauncherManagerPtr result(new WrtPlugins::Platform::AppLauncherManager());
+ return result;
+}
+
+AppLauncherFactory& AppLauncherFactory::getInstance()
+{
+ static AppLauncherFactory theInstance;
+ return theInstance;
+}
+}
+}
+}
\ 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 ApplauncherFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _ABSTRACT_LAYER_APPLAUNCHER_FACTORY_H_
+#define _ABSTRACT_LAYER_APPLAUNCHER_FACTORY_H_
+
+#include <dpl/shared_ptr.h>
+#include "IAppLauncherManager.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+class AppLauncherFactory : private DPL::Noncopyable
+{
+ private:
+ AppLauncherFactory()
+ {
+ }
+ public:
+ static AppLauncherFactory& getInstance();
+ IAppLauncherManagerPtr createAppLauncherManagerObject();
+};
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_APPLAUNCHER_FACTORY_H_ */
\ 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 ApplauncherFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _ABSTRACT_LAYER_APPLICATION_TYPES_H_
+#define _ABSTRACT_LAYER_APPLICATION_TYPES_H_
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+typedef enum
+{
+ APPLICATION_TYPE_UNDEFINED,
+ APPLICATION_TYPE_ALARM,
+ APPLICATION_TYPE_BROWSER,
+ APPLICATION_TYPE_CALCULATOR,
+ APPLICATION_TYPE_CALENDAR,
+ APPLICATION_TYPE_CAMERA,
+ APPLICATION_TYPE_CONTACTS,
+ APPLICATION_TYPE_FILES,
+ APPLICATION_TYPE_GAMES,
+ APPLICATION_TYPE_MAIL,
+ APPLICATION_TYPE_MEDIAPLAYER,
+ APPLICATION_TYPE_MESSAGING,
+ APPLICATION_TYPE_PHONECALL,
+ APPLICATION_TYPE_PICTURES,
+ APPLICATION_TYPE_PROG_MANAGER,
+ APPLICATION_TYPE_SETTINGS,
+ APPLICATION_TYPE_TASKS,
+ APPLICATION_TYPE_WIDGET_MANAGER
+} ApplicationType;
+
+typedef enum
+{
+ APPLICATION_URI_TYPE_UNDEFINED,
+ APPLICATION_URI_TYPE_HTTP,
+ APPLICATION_URI_TYPE_HTTPS,
+ APPLICATION_URI_TYPE_TEL,
+ APPLICATION_URI_TYPE_MAILTO,
+ APPLICATION_URI_TYPE_SMS,
+ APPLICATION_URI_TYPE_FILE,
+ APPLICATION_URI_TYPE_APPLICATION_BY_NAME
+} ApplicationUriType;
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_APPLICATION_TYPES_H_ */
\ 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 EventGetDefaultApplication.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _ABSTRACT_LAYER_EVENT_GET_DEFAULT_APPLICATION_H_
+#define _ABSTRACT_LAYER_EVENT_GET_DEFAULT_APPLICATION_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+#include <commons/EventReceiver.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+/* this event is sent when default application is get */
+class EventGetDefaultApplication : public WrtPlugins::Platform::IEvent<
+ EventGetDefaultApplication>
+{
+ std::string m_applicationFullPath;
+ std::string m_applicationName;
+ std::string m_mime;
+ public:
+ void setMime(const std::string &value)
+ {
+ m_mime = value;
+ }
+ std::string getMime() const
+ {
+ return m_mime;
+ }
+ void setApplicationFullPath(const std::string &value)
+ {
+ m_applicationFullPath = value;
+ }
+ std::string getApplicationFullPath() const
+ {
+ return m_applicationFullPath;
+ }
+ void setApplicationName(const std::string &value)
+ {
+ m_applicationName = value;
+ }
+ std::string getApplicationName() const
+ {
+ return m_applicationName;
+ }
+ virtual void clearOnCancel()
+ {
+ }
+ EventGetDefaultApplication()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetDefaultApplication>
+EventGetDefaultApplicationPtr;
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_EVENT_GET_DEFAULT_APPLICATION_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 IEventGetInstalledApplications.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _ABSTRACT_LAYER_EVENT_GET_INSTALLED_APPLICATIONS_H_
+#define _ABSTRACT_LAYER_EVENT_GET_INSTALLED_APPLICATIONS_H_
+
+#include <string>
+#include <vector>
+#include <map>
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+#include <commons/EventReceiver.h>
+#include "ApplicationTypes.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+/* This event is sent when list of installed applications is get */
+class EventGetInstalledApplications : public WrtPlugins::Platform::IEvent<
+ EventGetInstalledApplications>
+{
+ std::vector<std::string> m_applicationFullPaths;
+ std::vector<std::string> m_applicationNames;
+ std::map<ApplicationType, std::string> m_applicationTypesPath;
+ std::map<ApplicationType, std::string> m_applicationTypesName;
+ public:
+ void addApplicationTypeByName(const std::pair<ApplicationType,
+ std::string> &value)
+ {
+ m_applicationTypesName.insert(value);
+ }
+ const std::map<ApplicationType,
+ std::string> &getApplicationTypesByName() const
+ {
+ return m_applicationTypesName;
+ }
+ void addApplicationTypeByPath(const std::pair<ApplicationType,
+ std::string> &value)
+ {
+ m_applicationTypesPath.insert(value);
+ }
+ const std::map<ApplicationType,
+ std::string> &getApplicationTypesByPath() const
+ {
+ return m_applicationTypesPath;
+ }
+ void addApplicationFullPath(const std::string &value)
+ {
+ m_applicationFullPaths.push_back(value);
+ }
+ const std::vector<std::string> &getApplicationFullPaths() const
+ {
+ return m_applicationFullPaths;
+ }
+ void addApplicationName(const std::string &value)
+ {
+ m_applicationNames.push_back(value);
+ }
+ const std::vector<std::string> &getApplicationNames() const
+ {
+ return m_applicationNames;
+ }
+ virtual void clearOnCancel()
+ {
+ }
+ EventGetInstalledApplications()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetInstalledApplications>
+EventGetInstalledApplicationsPtr;
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_INSTALLED_APPLICATIONS_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 IEventLaunchApplication.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _ABSTRACT_LAYER_IEVENT_LAUNCH_APPLICATION_H_
+#define _ABSTRACT_LAYER_IEVENT_LAUNCH_APPLICATION_H_
+
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+#include <commons/EventReceiver.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+/* this event is sent when application is launched */
+class EventLaunchApplication : public WrtPlugins::Platform::IEvent<
+ EventLaunchApplication>
+{
+ //Uri type. http://, file://, sms:, mailto: etc
+ ApplicationUriType m_applicationUriType;
+ // used as param to uriType, for example http address, path to file, phone number, etc
+ std::string m_applicationUriParam;
+ //optional parameters for file://
+ std::vector<std::string> m_applicationParameters;
+ public:
+ void addApplicationParameter(const std::string &value)
+ {
+ m_applicationParameters.push_back(value);
+ }
+ std::vector<std::string> getApplicationParameters() const
+ {
+ return m_applicationParameters;
+ }
+ void setApplicationUriType(const ApplicationUriType value)
+ {
+ m_applicationUriType = value;
+ }
+ ApplicationUriType getApplicationUriType() const
+ {
+ return m_applicationUriType;
+ }
+ void setApplicationUriParam(const std::string &value)
+ {
+ m_applicationUriParam = value;
+ }
+ std::string getApplicationUriParam() const
+ {
+ return m_applicationUriParam;
+ }
+ virtual void clearOnCancel()
+ {
+ }
+ EventLaunchApplication() : m_applicationUriType(
+ APPLICATION_URI_TYPE_UNDEFINED)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventLaunchApplication> EventLaunchApplicationPtr;
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IEVENT_LAUNCH_APPLICATION_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 IAppLauncherManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "IAppLauncherManager.h"
+#include <commons/ThreadPool.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+IAppLauncherManager::IAppLauncherManager() :
+ EventRequestReceiverGetDefaultApplication(Platform::ThreadEnum::
+ APPLAUNCHER_THREAD),
+ EventRequestReceiverGetInstalledApplications(Platform::ThreadEnum::
+ APPLAUNCHER_THREAD),
+ EventRequestReceiverLaunchApplication(Platform::ThreadEnum::
+ APPLAUNCHER_THREAD)
+{
+}
+
+IAppLauncherManager::~IAppLauncherManager()
+{
+}
+
+void IAppLauncherManager::getDefaultApplication(
+ const EventGetDefaultApplicationPtr &event)
+{
+ EventRequestReceiverGetDefaultApplication::PostRequest(event);
+}
+
+void IAppLauncherManager::getInstalledApplications(
+ const EventGetInstalledApplicationsPtr &event)
+{
+ EventRequestReceiverGetInstalledApplications::PostRequest(event);
+}
+
+void IAppLauncherManager::launchApplication(
+ const EventLaunchApplicationPtr &event)
+{
+ EventRequestReceiverLaunchApplication::PostRequest(event);
+}
+}
+}
+}
--- /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 IAppLauncherManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _ABSTRACT_LAYER_IAPP_LAUNCHER_MANAGER_H_
+#define _ABSTRACT_LAYER_IAPP_LAUNCHER_MANAGER_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include "EventGetDefaultApplication.h"
+#include "EventGetInstalledApplications.h"
+#include "EventLaunchApplication.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace AppLauncher {
+typedef Platform::EventRequestReceiver< EventGetDefaultApplication >
+EventRequestReceiverGetDefaultApplication;
+typedef Platform::EventRequestReceiver< EventGetInstalledApplications >
+EventRequestReceiverGetInstalledApplications;
+typedef Platform::EventRequestReceiver< EventLaunchApplication >
+EventRequestReceiverLaunchApplication;
+
+class IAppLauncherManager : public EventRequestReceiverGetDefaultApplication,
+ public EventRequestReceiverGetInstalledApplications,
+ public EventRequestReceiverLaunchApplication
+{
+ public:
+ IAppLauncherManager();
+ virtual ~IAppLauncherManager();
+ virtual void getDefaultApplication(
+ const EventGetDefaultApplicationPtr &event);
+ virtual void getInstalledApplications(
+ const EventGetInstalledApplicationsPtr &event);
+ virtual void launchApplication(const EventLaunchApplicationPtr &event);
+ protected:
+ virtual void OnRequestReceived(const EventGetDefaultApplicationPtr &event)
+ = 0;
+ virtual void OnRequestReceived(
+ const EventGetInstalledApplicationsPtr &event) = 0;
+ virtual void OnRequestReceived(const EventLaunchApplicationPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IAppLauncherManager> IAppLauncherManagerPtr;
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IAPP_LAUNCHER_MANAGER_H_ */
--- /dev/null
+get_current_path()
+set(SRCS_PLATFORM_API_APPLAUNCHER
+ ${CURRENT_PATH}/AppLauncherFactory.cpp
+ ${CURRENT_PATH}/IAppLauncherManager.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)
+ */
+
+#ifndef WRTPLUGINS_DEVICE_ENUMS_H_
+#define WRTPLUGINS_DEVICE_ENUMS_H_
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+enum ClamshellState
+{
+ CSS_OPEN,
+ CSS_CLOSE
+};
+
+enum KeypadLightState
+{
+ KLS_ON,
+ KLS_OFF
+};
+} // Device
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DEVICE_ENUMS_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 "EventClamshellStateChange.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+EventClamshellStateChange::EventClamshellStateChange() : m_state(CSS_CLOSE)
+{
+}
+
+EventClamshellStateChange::~EventClamshellStateChange()
+{
+}
+
+ClamshellState EventClamshellStateChange::getState() const
+{
+ return m_state;
+}
+
+void EventClamshellStateChange::setState(ClamshellState state)
+{
+ m_state = state;
+}
+} // Device
+} // Api
+} // 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 WRTPLUGINS_DEVICE_EVENTCLAMSHELLSTATECHANGE_H_
+#define WRTPLUGINS_DEVICE_EVENTCLAMSHELLSTATECHANGE_H_
+
+#include <dpl/shared_ptr.h>
+#include <platform/commons/ListenerEvent.h>
+#include <platform/commons/ListenerEventEmitter.h>
+#include "Enums.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+/**
+ * Event emitted when screen orientation changes.
+ */
+class EventClamshellStateChange : public Platform::ListenerEvent<
+ EventClamshellStateChange>
+{
+ public:
+ EventClamshellStateChange();
+ virtual ~EventClamshellStateChange();
+
+ /**
+ * Gets clamshell's state.
+ * @return State of the clamshell.
+ */
+ ClamshellState getState() const;
+
+ /**
+ * Sets clamshell's state.
+ * @param state State of the clamshell.
+ */
+ void setState(ClamshellState state);
+
+ protected:
+ ClamshellState m_state;
+};
+
+typedef DPL::SharedPtr<EventClamshellStateChange> EventClamshellStateChangePtr;
+typedef Platform::ListenerEventEmitter<EventClamshellStateChange>
+EventClamshellStateChangeEmitter;
+typedef DPL::SharedPtr<EventClamshellStateChangeEmitter>
+EventClamshellStateChangeEmitterPtr;
+} // Device
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DEVICE_EVENTCLAMSHELLSTATECHANGE_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 "IClamshell.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+IClamshell::~IClamshell()
+{
+}
+} // Device
+} // Api
+} // 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 WRTPLUGINS_DEVICE_ICLAMSHELL_H_
+#define WRTPLUGINS_DEVICE_ICLAMSHELL_H_
+
+#include <dpl/noncopyable.h>
+#include "EventClamshellStateChange.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+class IClamshell : private DPL::Noncopyable
+{
+ public:
+ virtual ~IClamshell() = 0;
+
+ /**
+ * Adds on change state event emitter.
+ * @param emitter On change state event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void addOnStateChange(
+ const EventClamshellStateChangeEmitterPtr& emitter) = 0;
+
+ /**
+ * Removes on change state emitter.
+ * @param id Id of an event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void removeOnStateChange(
+ EventClamshellStateChangeEmitter::IdType id) = 0;
+};
+} // Device
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DEVICE_ICLAMSHELL_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 "IKeypad.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+IKeypad::~IKeypad()
+{
+}
+} // Device
+} // Api
+} // 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 WRTPLUGINS_DEVICE_IKEYPAD_H_
+#define WRTPLUGINS_DEVICE_IKEYPAD_H_
+
+#include <dpl/noncopyable.h>
+#include "Enums.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+class IKeypad : private DPL::Noncopyable
+{
+ public:
+ virtual ~IKeypad();
+
+ /**
+ * Gets state of keypad's backlight.
+ * @return State of keypad's backlight.
+ */
+ virtual KeypadLightState getLightState() const = 0;
+};
+} // Device
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DEVICE_IKEYPAD_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 "IManager.h"
+#include <Device/Manager.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+IManager& IManager::getInstance()
+{
+ return Platform::Device::Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+} // Device
+} // Api
+} // 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 WRTPLUGINS_DEVICE_IMANAGER_H_
+#define WRTPLUGINS_DEVICE_IMANAGER_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Device {
+class IClamshell;
+class IKeypad;
+
+class IManager : private DPL::Noncopyable
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets if device is equipped with clamshell.
+ * @return True if clamshell is supported, false otherwise.
+ */
+ virtual bool hasClamshell() const = 0;
+
+ /**
+ * Gets clamshell interface.
+ * @return Clamshell interface.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks Ownership does NOT follow caller.
+ */
+ virtual IClamshell* getClamshell() const = 0;
+
+ /**
+ * Gets if device is equipped with keypad.
+ * @return True if keypad is present, false otherwise.
+ */
+ virtual bool hasKeypad() const = 0;
+
+ /**
+ * Gets keypad interface.
+ * @return Keypad interface.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks Ownership does NOT follow caller.
+ */
+ virtual IKeypad* getKeypad() const = 0;
+
+ /**
+ * Gets IMEI number.
+ * @return IMEI number.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual std::string getImei() const = 0;
+};
+} // Device
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DEVICE_IMANAGER_H_
--- /dev/null
+get_current_path()
+
+set(SRCS_PLATFORM_API_DEVICE
+ ${CURRENT_PATH}/EventClamshellStateChange.cpp
+ ${CURRENT_PATH}/IClamshell.cpp
+ ${CURRENT_PATH}/IKeypad.cpp
+ ${CURRENT_PATH}/IManager.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)
+ */
+
+#ifndef WRTPLUGINS_DISPLAY_ENUMS_H_
+#define WRTPLUGINS_DISPLAY_ENUMS_H_
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+enum State
+{
+ ST_ON,
+ ST_DIM,
+ ST_OFF
+};
+
+enum Orientation
+{
+ O_PORTRAIT,
+ O_LANDSCAPE
+};
+} // Display
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DISPLAY_ENUMS_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 "EventChangeOrientation.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+EventChangeOrientation::EventChangeOrientation() : m_orientation(O_PORTRAIT)
+{
+}
+
+EventChangeOrientation::~EventChangeOrientation()
+{
+}
+
+Orientation EventChangeOrientation::getOrientation() const
+{
+ return m_orientation;
+}
+
+void EventChangeOrientation::setOrientation(Orientation orientation)
+{
+ m_orientation = orientation;
+}
+} // Display
+} // Api
+} // 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 WRTPLUGINS_DISPLAY_EVENTCHANGEORIENTATION_H_
+#define WRTPLUGINS_DISPLAY_EVENTCHANGEORIENTATION_H_
+
+#include <dpl/shared_ptr.h>
+#include <platform/commons/ListenerEvent.h>
+#include <platform/commons/ListenerEventEmitter.h>
+#include "Enums.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+/**
+ * Event emitted when screen orientation changes.
+ */
+class EventChangeOrientation : public Platform::ListenerEvent<
+ EventChangeOrientation>
+{
+ public:
+ EventChangeOrientation();
+ virtual ~EventChangeOrientation();
+
+ /**
+ * Gets screen's orientation.
+ * @return Orientation.
+ */
+ Orientation getOrientation() const;
+
+ /**
+ * Sets screen's orientation.
+ * @param orientation Orientation.
+ */
+ void setOrientation(Orientation orientation);
+
+ protected:
+ Orientation m_orientation;
+};
+
+typedef DPL::SharedPtr<EventChangeOrientation> EventChangeOrientationPtr;
+typedef Platform::ListenerEventEmitter<EventChangeOrientation>
+EventChangeOrientationEmitter;
+typedef DPL::SharedPtr<EventChangeOrientationEmitter>
+EventChangeOrientationEmitterPtr;
+} // Display
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DISPLAY_EVENTCHANGEORIENTATION_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 "EventChangeState.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+EventChangeState::EventChangeState() : m_state(ST_OFF)
+{
+}
+
+EventChangeState::~EventChangeState()
+{
+}
+
+State EventChangeState::getState() const
+{
+ return m_state;
+}
+
+void EventChangeState::setState(State state)
+{
+ m_state = state;
+}
+} // Display
+} // Api
+} // 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 WRTPLUGINS_DISPLAY_EVENTCHANGESTATE_H_
+#define WRTPLUGINS_DISPLAY_EVENTCHANGESTATE_H_
+
+#include <dpl/shared_ptr.h>
+#include <platform/commons/ListenerEvent.h>
+#include <platform/commons/ListenerEventEmitter.h>
+#include "Enums.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+/**
+ * Event emitted when screen changes its state.
+ */
+class EventChangeState : public Platform::ListenerEvent<EventChangeState>
+{
+ public:
+ EventChangeState();
+ virtual ~EventChangeState();
+
+ /**
+ * Gets screen's state.
+ * @return State of the screen.
+ */
+ State getState() const;
+
+ /**
+ * Sets screen's state.
+ * @param state State of the screen.
+ */
+ void setState(State state);
+
+ protected:
+ State m_state; ///< State of the screen.
+};
+
+typedef DPL::SharedPtr<EventChangeState> EventChangeStatePtr;
+typedef Platform::ListenerEventEmitter<EventChangeState>
+EventChangeStateEmitter;
+typedef DPL::SharedPtr<EventChangeStateEmitter> EventChangeStateEmitterPtr;
+} // Display
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DISPLAY_EVENTCHANGESTATE_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 "IManager.h"
+#include <Display/Manager.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+IManager& IManager::getInstance()
+{
+ return Platform::Display::Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+} // Display
+} // Api
+} // 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 WRTPLUGINS_DISPLAY_IMANAGER_H_
+#define WRTPLUGINS_DISPLAY_IMANAGER_H_
+
+#include <cstddef>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+class IScreen;
+
+class IManager
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets interface to specified screen.
+ * @param index Index of a screen to get (1-based)
+ * @return Screen interface.
+ * @throw UnsupportedException If current platform doesn't support it.
+ * @throw OutOfRangeException If specified screen doesn't exist.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks On some platforms passing 0 as screen index may result in returning
+ * some global screen interface. Other may return default screen.
+ * @remarks Ownership is NOT passed to the caller.
+ */
+ virtual IScreen* getScreen(std::size_t index) const = 0;
+
+ /**
+ * Gets number of supported screens.
+ * @return Screens count.
+ */
+ virtual std::size_t getScreensCount() const = 0;
+};
+} // Display
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DISPLAY_IMANAGER_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 "IScreen.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+IScreen::~IScreen()
+{
+}
+} // Display
+} // Api
+} // 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 WRTPLUGINS_DISPLAY_ISCREEN_H_
+#define WRTPLUGINS_DISPLAY_ISCREEN_H_
+
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <platform/commons/Dimension.h>
+#include "EventChangeOrientation.h"
+#include "EventChangeState.h"
+#include "Enums.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Display {
+class IScreen : private DPL::Noncopyable
+{
+ public:
+ virtual ~IScreen() = 0;
+
+ /**
+ * Gets color depth.
+ * @return Color depth (in bits per pixel).
+ */
+ virtual unsigned short getColorDepth() const = 0;
+
+ /**
+ * Gets screen's real size (in pixels).
+ * @return Screen's real size.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks "Real size" means that temporary screen modifications like e.g.
+ * changing orientation are not taken into account.
+ */
+ virtual Platform::Dimension getSize() const = 0;
+
+ /**
+ * Gets screen's actual size (in pixels).
+ * @return Screen's actual size.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks Convenience method that takes into account any temporary screen
+ * modifications like e.g. changing orientation.
+ */
+ virtual Platform::Dimension getActualSize() const = 0;
+
+ /**
+ * Gets screen's orientation.
+ * @return Orientation.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual Orientation getOrientation() const = 0;
+
+ /**
+ * Gets screen state.
+ * @return State of the screen.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual State getState() const = 0;
+
+ /**
+ * Adds on change size event emitter.
+ * @param emitter On change size event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void addOnChangeOrientation(
+ const EventChangeOrientationEmitterPtr& emitter) = 0;
+
+ /**
+ * Removes on change size emitter.
+ * @param id Id of an event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void removeOnChangeOrientation(
+ EventChangeOrientationEmitter::IdType id) = 0;
+
+ /**
+ * Adds on change state event emitter.
+ * @param emitter On change state event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void addOnChangeState(const EventChangeStateEmitterPtr& emitter) =
+ 0;
+
+ /**
+ * Removes on change state emitter.
+ * @param id Id of an event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void removeOnChangeState(EventChangeStateEmitter::IdType id) = 0;
+};
+
+typedef DPL::SharedPtr<IScreen> IScreenPtr;
+} // Display
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DISPLAY_ISCREEN_H_
--- /dev/null
+get_current_path()
+
+set(SRCS_PLATFORM_API_DISPLAY
+ ${CURRENT_PATH}/EventChangeOrientation.cpp
+ ${CURRENT_PATH}/EventChangeState.cpp
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/IScreen.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.
+ */
+#ifndef _IEVENT_LOAD_FEATURE_
+#define _IEVENT_LOAD_FEATURE_
+
+/*
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ */
+
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtPlugins {
+namespace Api {
+class EventLoadFeature : public WrtPlugins::Platform::IEvent<EventLoadFeature>
+{
+ public:
+ explicit EventLoadFeature(const std::string &feature) :
+ m_success(false),
+ m_feature(feature),
+ m_object(0)
+ {
+ }
+
+ ~EventLoadFeature()
+ {
+ LogDebug(__FUNCTION__);
+ }
+
+ const std::string getFeature() const
+ {
+ return m_feature;
+ }
+
+ const bool isSuccess() const
+ {
+ return m_success;
+ }
+
+ void setStatus(bool status)
+ {
+ m_success = status;
+ }
+
+ void* getObject() const
+ {
+ return m_object;
+ }
+
+ void setObject(void* jsObject)
+ {
+ m_object = jsObject;
+ }
+
+ virtual void clearOnCancel()
+ {
+ }
+ private:
+ bool m_success;
+ std::string m_feature;
+ void *m_object;
+};
+
+typedef DPL::SharedPtr<EventLoadFeature> EventLoadFeaturePtr;
+} // namespace Api
+} // namespace WrtPlugins
+
+#endif // _IEVENT_LOAD_FEATURE_
--- /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 (b.grzelewski@samsung.com)
+ */
+#include "FeatureManagerFactory.h"
+#include <FeatureLoader/FeatureManager.h>
+
+namespace WrtPlugins {
+namespace Api {
+IFeatureManagerPtr FeatureManagerFactory::createFeatureManager()
+{
+ return IFeatureManagerPtr(new WrtPlugins::Platform::FeatureManager());
+}
+} // namespace Api
+} // 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 _FEATUREMANAGERFACTORY_H_
+#define _FEATUREMANAGERFACTORY_H_
+
+/*
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ */
+
+#include "IFeatureManager.h"
+
+namespace WrtPlugins {
+namespace Api {
+class FeatureManagerFactory :
+ private DPL::Noncopyable
+{
+ public:
+ static FeatureManagerFactory& getInstance()
+ {
+ static FeatureManagerFactory instance;
+ return instance;
+ }
+
+ IFeatureManagerPtr createFeatureManager();
+
+ private:
+ FeatureManagerFactory()
+ {
+ }
+ ~FeatureManagerFactory()
+ {
+ }
+};
+} // namespace Api
+} // namespace WrtPlugins
+
+#endif // _FEATUREMANAGERFACTORY_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: Bartlomiej Grzelewski <b.grzelewski@samsung.com>
+ */
+
+#include "IFeatureManager.h"
+#include <commons/ThreadPool.h>
+
+namespace WrtPlugins {
+namespace Api {
+IFeatureManager::IFeatureManager() :
+ Platform::EventRequestReceiver<EventLoadFeature>(Platform::ThreadEnum::
+ BONDI_THREAD)
+{
+}
+
+IFeatureManager::~IFeatureManager()
+{
+}
+
+void IFeatureManager::loadFeature(const EventLoadFeaturePtr &event)
+{
+ Platform::EventRequestReceiver<EventLoadFeature>::PostRequest(event);
+}
+} // namespace Api
+} // 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 _IFEATUREMANAGER_H_
+#define _IFEATUREMANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include "EventLoadFeature.h"
+
+namespace WrtPlugins {
+namespace Api {
+class IFeatureManager :
+ public Platform::EventRequestReceiver<EventLoadFeature>
+{
+ public:
+ IFeatureManager();
+ virtual ~IFeatureManager();
+
+ /**
+ * This fuction is used to load API feature whan widget is already started.
+ */
+
+ virtual void loadFeature(const EventLoadFeaturePtr &event);
+ protected:
+ virtual void OnRequestReceived(const EventLoadFeaturePtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IFeatureManager> IFeatureManagerPtr;
+} // namespace Api
+} // namespace WrtPlugins
+
+#endif // _IFEATUREMANAGER_H_
--- /dev/null
+get_current_path()
+set(SRCS_PLATFORM_API_FEATURE_MANAGER
+ ${CURRENT_PATH}/IFeatureManager.cpp
+ ${CURRENT_PATH}/FeatureManagerFactory.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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IEVENT_CHANGEVIEW_H_
+#define WRT_PLUGINS_IEVENT_CHANGEVIEW_H_
+
+#include <commons/Exception.h>
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IEventChangeView : public WrtPlugins::Platform::IEvent<IEventChangeView>
+{
+ Commons::ExceptionCodes::Enumeration m_result;
+ IViewProperties m_props;
+ IGalleryPtr m_gallery;
+
+ public:
+ IEventChangeView() : m_result(Commons::ExceptionCodes::None)
+ {
+ LogDebug("entered");
+ }
+
+ void setResult(const Commons::ExceptionCodes::Enumeration &value)
+ {
+ m_result = value;
+ }
+ Commons::ExceptionCodes::Enumeration getResult() const
+ {
+ return m_result;
+ }
+ IViewProperties &getProperties()
+ {
+ return m_props;
+ }
+ void setProperties(const IViewProperties &props)
+ {
+ m_props = props;
+ }
+ void setGallery(const IGalleryPtr &gallery)
+ {
+ m_gallery = gallery;
+ }
+ IGalleryPtr getGallery() const
+ {
+ return m_gallery;
+ }
+};
+
+typedef DPL::SharedPtr<IEventChangeView> IEventChangeViewPtr;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IEVENT_CHANGEVIEW_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IEVENT_CLOSE_H_
+#define WRT_PLUGINS_IEVENT_CLOSE_H_
+
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IEventClose : public WrtPlugins::Platform::IEvent<IEventClose>
+{
+ Commons::ExceptionCodes::Enumeration m_result;
+ IGalleryPtr m_gallery;
+
+ public:
+ void setResult(Commons::ExceptionCodes::Enumeration value)
+ {
+ m_result = value;
+ }
+ Commons::ExceptionCodes::Enumeration getResult() const
+ {
+ return m_result;
+ }
+ void setGallery(const IGalleryPtr &gallery)
+ {
+ m_gallery = gallery;
+ }
+ IGalleryPtr getGallery() const
+ {
+ return m_gallery;
+ }
+
+ IEventClose() : m_result(Commons::ExceptionCodes::None)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventClose> IEventClosePtr;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IEVENT_CLOSE_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IEVENT_GET_GALLERIES_H_
+#define WRT_PLUGINS_IEVENT_GET_GALLERIES_H_
+
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IEventGetGalleries : public WrtPlugins::Platform::IEvent<
+ IEventGetGalleries>
+{
+ Commons::ExceptionCodes::Enumeration m_result;
+ IGallerySetPtr m_galleries;
+ public:
+ void setResult(
+ const Commons::ExceptionCodes::Enumeration &value)
+ {
+ m_result = value;
+ }
+ Commons::ExceptionCodes::Enumeration getResult() const
+ {
+ return m_result;
+ }
+ IGallerySetPtr getGalleries()
+ {
+ return m_galleries;
+ }
+ void setGalleries(const IGallerySetPtr &galleries)
+ {
+ m_galleries = galleries;
+ }
+
+ IEventGetGalleries() : m_result(Commons::ExceptionCodes::None),
+ m_galleries(NULL)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventGetGalleries> IEventGetGalleriesPtr;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IEVENT_GET_GALLERIES_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IEVENT_GET_MEDIA_ITEM_BY_ID_H_
+#define WRT_PLUGINS_IEVENT_GET_MEDIA_ITEM_BY_ID_H_
+
+#include <commons/Exception.h>
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IEventGetMediaItemById : public WrtPlugins::Platform::IEvent<
+ IEventGetMediaItemById>
+{
+ Commons::ExceptionCodes::Enumeration m_result;
+ unsigned long m_id;
+ IGalleryPtr m_gallery;
+ IMediaItemPtr m_mediaItem;
+
+ public:
+ void setResult(const Commons::ExceptionCodes::Enumeration &value)
+ {
+ m_result = value;
+ }
+ Commons::ExceptionCodes::Enumeration getResult() const
+ {
+ return m_result;
+ }
+ int getId() const
+ {
+ return m_id;
+ }
+ void setId(unsigned long id)
+ {
+ m_id = id;
+ }
+ void setGallery(const IGalleryPtr &gallery)
+ {
+ m_gallery = gallery;
+ }
+ IGalleryPtr getGallery() const
+ {
+ return m_gallery;
+ }
+ void setMediaItem(const IMediaItemPtr &mediaItem)
+ {
+ m_mediaItem = mediaItem;
+ }
+ IMediaItemPtr getMediaItem() const
+ {
+ return m_mediaItem;
+ }
+
+ IEventGetMediaItemById() : m_result(Commons::ExceptionCodes::None),
+ m_id(0)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventGetMediaItemById> IEventGetMediaItemByIdPtr;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IEVENT_GET_MEDIA_ITEM_BY_ID_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IEVENT_GET_MEDIA_ITEMS_H_
+#define WRT_PLUGINS_IEVENT_GET_MEDIA_ITEMS_H_
+
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IEventGetMediaItems : public WrtPlugins::Platform::IEvent<
+ IEventGetMediaItems>
+{
+ Commons::ExceptionCodes::Enumeration m_result;
+ IGalleryPtr m_gallery;
+ IMediaItemsSetPtr m_mediaItems;
+
+ public:
+ void setResult(
+ const Commons::ExceptionCodes::Enumeration &value)
+ {
+ m_result = value;
+ }
+ Commons::ExceptionCodes::Enumeration getResult() const
+ {
+ return m_result;
+ }
+ void setGallery(const IGalleryPtr &gallery)
+ {
+ m_gallery = gallery;
+ }
+ IGalleryPtr getGallery() const
+ {
+ return m_gallery;
+ }
+ IMediaItemsSetPtr getMediaItems() const
+ {
+ return m_mediaItems;
+ }
+ void setMediaItems(const IMediaItemsSetPtr &mediaItems)
+ {
+ m_mediaItems = mediaItems;
+ }
+
+ IEventGetMediaItems() : m_result(Commons::ExceptionCodes::None)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventGetMediaItems> IEventGetMediaItemsPtr;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IEVENT_GET_MEDIA_ITEMS_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IEVENT_OPEN_H_
+#define WRT_PLUGINS_IEVENT_OPEN_H_
+
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IEventOpen : public WrtPlugins::Platform::IEvent<IEventOpen>
+{
+ Commons::ExceptionCodes::Enumeration m_result;
+ IGalleryPtr m_gallery;
+
+ public:
+ void setResult(
+ const Commons::ExceptionCodes::Enumeration &value)
+ {
+ m_result = value;
+ }
+ Commons::ExceptionCodes::Enumeration getResult() const
+ {
+ return m_result;
+ }
+ void setGallery(const IGalleryPtr &gallery)
+ {
+ m_gallery = gallery;
+ }
+ IGalleryPtr getGallery() const
+ {
+ return m_gallery;
+ }
+
+ IEventOpen() : m_result(Commons::ExceptionCodes::None)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventOpen> IEventOpenPtr;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IEVENT_OPEN_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IEVENT_REFRESH_H_
+#define WRT_PLUGINS_IEVENT_REFRESH_H_
+
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IEventRefresh : public WrtPlugins::Platform::IEvent<IEventRefresh>
+{
+ Commons::ExceptionCodes::Enumeration m_result;
+ IGalleryPtr m_gallery;
+
+ public:
+ void setResult(const Commons::ExceptionCodes::Enumeration &value)
+ {
+ m_result = value;
+ }
+ Commons::ExceptionCodes::Enumeration getResult() const
+ {
+ return m_result;
+ }
+ void setGallery(const IGalleryPtr &gallery)
+ {
+ m_gallery = gallery;
+ }
+ IGalleryPtr getGallery() const
+ {
+ return m_gallery;
+ }
+
+ IEventRefresh() : m_result(Commons::ExceptionCodes::None)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventRefresh> IEventRefreshPtr;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IEVENT_OPEN_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 "IGallery.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+IGallery::IGallery()
+{
+}
+
+IGallery::~IGallery()
+{
+}
+} // Gallery
+} // Api
+} // 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 WRTPLUGINS_GALLERY_IGALLERY_H_
+#define WRTPLUGINS_GALLERY_IGALLERY_H_
+
+#include <list>
+#include <dpl/shared_ptr.h>
+#include <commons/Exception.h>
+#include <platform/commons/EventReceiver.h>
+#include "IMediaItem.h"
+#include "IViewProperties.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IGallery
+{
+ public:
+ virtual ~IGallery() = 0;
+
+ virtual unsigned int getNumberOfItems() const = 0;
+ virtual std::string getName() const = 0;
+ virtual void open() = 0;
+ virtual bool isOpen() const = 0;
+ virtual void close() = 0;
+ virtual void refresh() = 0;
+ virtual void changeView(const IViewProperties &props) = 0;
+ virtual const IMediaItemsSetPtr getMediaItems() const = 0;
+ virtual const IMediaItemPtr getMediaItemById(unsigned long id) const =
+ 0;
+
+ protected:
+ IGallery();
+};
+
+typedef DPL::SharedPtr<IGallery> IGalleryPtr;
+typedef std::list<IGalleryPtr> IGallerySet;
+typedef DPL::SharedPtr<IGallerySet> IGallerySetPtr;
+typedef std::list<IGalleryPtr>::iterator IGallerySetIterator;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_GALLERY_IGALLERY_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 IGalleryRequestManager.cpp
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ */
+
+#include <Gallery/GalleryRequestManager.h>
+#include "IGalleryRequestManager.h"
+
+using namespace WrtPlugins::Platform;
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+void IGalleryRequestManager::getGalleries(const IEventGetGalleriesPtr &event)
+{
+ EventRequestReceiver< IEventGetGalleries >::PostRequest(event);
+}
+
+void IGalleryRequestManager::open(const IEventOpenPtr &event)
+{
+ EventRequestReceiver< IEventOpen >::PostRequest(event);
+}
+
+void IGalleryRequestManager::refresh(const IEventRefreshPtr &event)
+{
+ EventRequestReceiver< IEventRefresh >::PostRequest(event);
+}
+
+void IGalleryRequestManager::close(const IEventClosePtr &event)
+{
+ EventRequestReceiver< IEventClose >::PostRequest(event);
+}
+
+void IGalleryRequestManager::changeView(const IEventChangeViewPtr &event)
+{
+ EventRequestReceiver< IEventChangeView >::PostRequest(event);
+}
+
+void IGalleryRequestManager::getMediaItems(const IEventGetMediaItemsPtr &event)
+{
+ EventRequestReceiver< IEventGetMediaItems >::PostRequest(event);
+}
+
+void IGalleryRequestManager::getMediaItemById(
+ const IEventGetMediaItemByIdPtr &event)
+{
+ EventRequestReceiver< IEventGetMediaItemById >::PostRequest(event);
+}
+//======== GalleryFactory
+
+IGalleryRequestManagerPtr GalleryFactory::getGalleryManager()
+{
+ static IGalleryRequestManagerPtr result(
+ new WrtPlugins::Platform::GalleryRequestManager());
+ return result;
+}
+
+GalleryFactory& GalleryFactory::getInstance()
+{
+ static GalleryFactory theInstance;
+ return theInstance;
+}
+}
+}
+}
--- /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 IGalleryRequestManager.h
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRT_PLUGINS_IGALLERY_REQUEST_MANAGER_H_
+#define WRT_PLUGINS_IGALLERY_REQUEST_MANAGER_H_
+
+#include <API/Gallery/IEventGetGalleries.h>
+#include <API/Gallery/IEventOpen.h>
+#include <API/Gallery/IEventRefresh.h>
+#include <API/Gallery/IEventClose.h>
+#include <API/Gallery/IEventChangeView.h>
+#include <API/Gallery/IEventGetMediaItems.h>
+#include <API/Gallery/IEventGetMediaItemById.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+typedef Platform::EventRequestReceiver<IEventGetGalleries> ERRGetGalleries;
+typedef Platform::EventRequestReceiver<IEventOpen> ERROpen;
+typedef Platform::EventRequestReceiver<IEventRefresh> ERRRefresh;
+typedef Platform::EventRequestReceiver<IEventClose> ERRClose;
+typedef Platform::EventRequestReceiver<IEventChangeView> ERRChangeView;
+typedef Platform::EventRequestReceiver<IEventGetMediaItems> ERRGetMediaItems;
+typedef Platform::EventRequestReceiver<IEventGetMediaItemById>
+ERRGetMediaItemById;
+
+class IGalleryRequestManager :
+ public ERRGetGalleries,
+ public ERROpen,
+ public ERRRefresh,
+ public ERRClose,
+ public ERRChangeView,
+ public ERRGetMediaItems,
+ public ERRGetMediaItemById
+{
+ public:
+ IGalleryRequestManager() :
+ ERRGetGalleries(Platform::ThreadEnum::GALLERY_THREAD),
+ ERROpen(Platform::ThreadEnum::GALLERY_THREAD),
+ ERRRefresh(Platform::ThreadEnum::GALLERY_THREAD),
+ ERRClose(Platform::ThreadEnum::GALLERY_THREAD),
+ ERRChangeView(Platform::ThreadEnum::GALLERY_THREAD),
+ ERRGetMediaItems(Platform::ThreadEnum::GALLERY_THREAD),
+ ERRGetMediaItemById(Platform::ThreadEnum::GALLERY_THREAD)
+ {
+ }
+
+ virtual ~IGalleryRequestManager()
+ {
+ }
+
+ virtual void getGalleries(const IEventGetGalleriesPtr &event);
+ virtual void open(const IEventOpenPtr &event);
+ virtual void refresh(const IEventRefreshPtr &event);
+ virtual void close(const IEventClosePtr &event);
+ virtual void changeView(const IEventChangeViewPtr &event);
+ virtual void getMediaItems(const IEventGetMediaItemsPtr &event);
+ virtual void getMediaItemById(const IEventGetMediaItemByIdPtr &event);
+
+ protected:
+ virtual void OnRequestReceived(const IEventGetGalleriesPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventOpenPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventRefreshPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventClosePtr &event) = 0;
+ virtual void OnRequestReceived(const IEventChangeViewPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventGetMediaItemsPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventGetMediaItemByIdPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IGalleryRequestManager> IGalleryRequestManagerPtr;
+
+class GalleryFactory : private DPL::Noncopyable
+{
+ protected:
+ GalleryFactory()
+ {
+ }
+ public:
+ static GalleryFactory& getInstance();
+ IGalleryRequestManagerPtr getGalleryManager();
+};
+}
+}
+}
+
+#endif //WRT_PLUGINS_IGALLERY_REQUEST_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.
+ */
+/*
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_IMEDIA_ITEM_H_
+#define WRT_PLUGINS_IMEDIA_ITEM_H_
+
+#include <string>
+#include <list>
+#include <dpl/shared_ptr.h>
+#include <dpl/log/log.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IMediaItem
+{
+ public:
+ typedef enum
+ {
+ AUDIO,
+ VIDEO,
+ IMAGE,
+ UNDEFINED
+ } MediaType;
+
+ private:
+ unsigned long m_id;
+ MediaType m_type;
+ std::string m_mimeType;
+ std::string m_fileName;
+ unsigned long m_date;
+
+ public:
+ IMediaItem() : m_id(0),
+ m_type(UNDEFINED),
+ m_date(0)
+ {
+ }
+ virtual ~IMediaItem()
+ {
+ }
+
+ virtual const std::string &getFileName() const
+ {
+ return m_fileName;
+ }
+ virtual unsigned long getId() const
+ {
+ return m_id;
+ }
+ virtual const std::string &getMimeType() const
+ {
+ return m_mimeType;
+ }
+ virtual MediaType getType() const
+ {
+ return m_type;
+ }
+ virtual unsigned long getDate() const
+ {
+ return m_date;
+ }
+
+ virtual void setFileName(const std::string &fileName)
+ {
+ m_fileName = fileName;
+ }
+ virtual void setId(unsigned long id)
+ {
+ m_id = id;
+ }
+ virtual void setMimeType(const std::string &mimeType)
+ {
+ m_mimeType = mimeType;
+ }
+ virtual void setType(MediaType type)
+ {
+ m_type = type;
+ }
+ virtual void setDate(unsigned long date)
+ {
+ m_date = date;
+ }
+};
+
+typedef DPL::SharedPtr<IMediaItem> IMediaItemPtr;
+typedef std::list<IMediaItemPtr> IMediaItemsSet;
+typedef DPL::SharedPtr<IMediaItemsSet> IMediaItemsSetPtr;
+typedef std::list<IMediaItemPtr>::iterator IMediaItemsSetIterator;
+typedef std::list<IMediaItemPtr>::const_iterator IMediaItemsSetConstIterator;
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRT_PLUGINS_IMEDIA_ITEM_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 <commons/Exception.h>
+#include "IViewProperties.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+IViewProperties::SortType IViewProperties::getSortOrder() const
+{
+ return m_order;
+}
+
+std::string IViewProperties::getMetaTag() const
+{
+ return m_metaTag;
+}
+
+IViewProperties::SortOrder IViewProperties::getPrimarySortOrder() const
+{
+ return m_primarySortOrder;
+}
+
+IViewProperties::SortOrder IViewProperties::getSecondarySortOrder() const
+{
+ return m_secondarySortOrder;
+}
+
+unsigned long IViewProperties::getStartDate() const
+{
+ return m_startDate;
+}
+
+unsigned long IViewProperties::getEndDate() const
+{
+ return m_endDate;
+}
+
+void IViewProperties::setSortOrder(IViewProperties::SortType order)
+{
+ if (order < ASCENDING || order > DESCENDING) {
+ Throw(Commons::InvalidArgumentException);
+ }
+ m_order = order;
+}
+
+void IViewProperties::setMetaTag(const std::string &metaTag)
+{
+ m_metaTag = metaTag;
+}
+
+void IViewProperties::setPrimarySortOrder(
+ IViewProperties::SortOrder primarySortOrder)
+{
+ if (primarySortOrder < NONE || primarySortOrder > BY_TYPE) {
+ Throw(Commons::InvalidArgumentException);
+ }
+ m_primarySortOrder = primarySortOrder;
+}
+
+void IViewProperties::setSecondarySortOrder(
+ IViewProperties::SortOrder secondarySortOrder)
+{
+ if (secondarySortOrder < NONE || secondarySortOrder > BY_TYPE) {
+ Throw(Commons::InvalidArgumentException);
+ }
+ m_secondarySortOrder = secondarySortOrder;
+}
+
+void IViewProperties::setStartDate(long startDate)
+{
+ m_startDate = startDate;
+}
+
+void IViewProperties::setEndDate(long endDate)
+{
+ m_endDate = endDate;
+}
+
+IViewProperties::IViewProperties() :
+ m_order(ASCENDING),
+ m_primarySortOrder(NONE),
+ m_secondarySortOrder(NONE),
+ m_startDate(0),
+ m_endDate(0)
+{
+}
+} // Gallery
+} // Api
+} // 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 WRTPLUGINS_GALLERY_IVIEWPROPERTIES_H_
+#define WRTPLUGINS_GALLERY_IVIEWPROPERTIES_H_
+
+#include <string>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Gallery {
+class IViewProperties
+{
+ public:
+ typedef enum
+ {
+ NONE,
+ BY_FILENAME,
+ BY_FILEDATE,
+ BY_TYPE,
+ //Not supported:
+ // BY_TITLE,
+ // BY_AUTHOR,
+ // BY_ALBUM,
+ BY_DATE
+ } SortOrder;
+
+ typedef enum
+ {
+ ASCENDING,
+ DESCENDING
+ } SortType;
+
+ private:
+ SortType m_order;
+ SortOrder m_primarySortOrder;
+ SortOrder m_secondarySortOrder;
+ long m_startDate;
+ long m_endDate;
+ std::string m_metaTag;
+
+ public:
+ SortType getSortOrder() const;
+ std::string getMetaTag() const;
+ SortOrder getPrimarySortOrder() const;
+ SortOrder getSecondarySortOrder() const;
+ unsigned long getStartDate() const;
+ unsigned long getEndDate() const;
+
+ void setSortOrder(SortType order);
+ void setMetaTag(const std::string &metaTag);
+ void setPrimarySortOrder(SortOrder primarySortOrder);
+ void setSecondarySortOrder(SortOrder secondarySortOrder);
+ void setStartDate(long startDate);
+ void setEndDate(long endDate);
+
+ IViewProperties();
+};
+} // Gallery
+} // Api
+} // WrtPlugins
+
+#endif //WRTPLUGINS_GALLERY_IVIEWPROPERTIES_H_
--- /dev/null
+get_current_path()
+
+set(SRCS_PLATFORM_API_GALLERY
+ ${CURRENT_PATH}/IGallery.cpp
+ ${CURRENT_PATH}/IGalleryRequestManager.cpp
+ ${CURRENT_PATH}/IViewProperties.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 Wojciech Bielawski (w.bielawski@samsung.com)
+ */
+
+#ifndef WRTPLUGINS_API_GEOLOCATION_EVENT_GET_CURRENT_LOCATION_H_
+#define WRTPLUGINS_API_GEOLOCATION_EVENT_GET_CURRENT_LOCATION_H_
+
+#include "PositionProperties.h"
+#include "IGeolocation.h"
+
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Geolocation {
+class EventGetCurrentPosition : public WrtPlugins::Platform::IEvent<
+ EventGetCurrentPosition>
+{
+ private:
+ PositionProperties m_props;
+ IGeolocation::ApiLocationMethod m_method;
+
+ public:
+ void setTimestamp(std::time_t timestamp)
+ {
+ m_props.timestamp = timestamp;
+ }
+ void setLatitude(double latitude)
+ {
+ m_props.latitude = latitude;
+ }
+ void setLongitude(double longitude)
+ {
+ m_props.longitude = longitude;
+ }
+ void setAltitude(double altitude)
+ {
+ m_props.altitude = altitude;
+ }
+ void setAccuracy(double accuracy)
+ {
+ m_props.accuracy = accuracy;
+ }
+ void setAltitudeAccuracy(double accuracy)
+ {
+ m_props.altitudeAccuracy = accuracy;
+ }
+ void setSpeed(double speed)
+ {
+ m_props.speed = speed;
+ }
+ void setDirection(double direction)
+ {
+ m_props.direction = direction;
+ }
+ void setAltitudeSpeed(double climb)
+ {
+ m_props.altitudeSpeed = climb;
+ }
+ void setMethod(IGeolocation::ApiLocationMethod method)
+ {
+ m_method = method;
+ }
+
+ std::time_t getTimestamp() const
+ {
+ return m_props.timestamp;
+ }
+ double getLatitude() const
+ {
+ return m_props.latitude;
+ }
+ double getLongitude() const
+ {
+ return m_props.longitude;
+ }
+ double getAltitude() const
+ {
+ return m_props.altitude;
+ }
+ double getAccuracy() const
+ {
+ return m_props.accuracy;
+ }
+ double getAltitudeAccuracy() const
+ {
+ return m_props.altitudeAccuracy;
+ }
+ double getSpeed() const
+ {
+ return m_props.speed;
+ }
+ double getDirection() const
+ {
+ return m_props.direction;
+ }
+ double getAltitudeSpeed() const
+ {
+ return m_props.altitudeSpeed;
+ }
+ IGeolocation::ApiLocationMethod getMethod() const
+ {
+ return m_method;
+ }
+ PositionProperties getPositionProperties() const
+ {
+ return m_props;
+ }
+
+ EventGetCurrentPosition()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetCurrentPosition> EventGetCurrentPositionPtr;
+} // Geolocation
+} // Api
+} // WrtPlugins
+
+#endif //WRTPLUGINS_API_GEOLOCATION_EVENT_GET_CURRENT_LOCATION_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ */
+
+#ifndef WRTPLUGINS_API_GEOLOCATION_EVENT_POSITION_CHANGED_H_
+#define WRTPLUGINS_API_GEOLOCATION_EVENT_POSITION_CHANGED_H_
+
+#include "PositionProperties.h"
+#include <commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <platform/commons/ListenerEvent.h>
+#include <platform/commons/ListenerEventEmitter.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Geolocation {
+class EventPositionChanged : public Platform::ListenerEvent<
+ EventPositionChanged>
+{
+ private:
+ PositionProperties m_props;
+
+ public:
+ PositionProperties getPositionProperties() const
+ {
+ return m_props;
+ }
+ void setPositionProperties(const PositionProperties &props)
+ {
+ m_props = props;
+ }
+
+ EventPositionChanged()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventPositionChanged> EventPositionChangedPtr;
+typedef Platform::ListenerEventEmitter<EventPositionChanged>
+EventPositionChangedEmitter;
+typedef DPL::SharedPtr<EventPositionChangedEmitter>
+EventPositionChangedEmitterPtr;
+} // Geolocation
+} // Api
+} // WrtPlugins
+
+#endif //WRTPLUGINS_API_GEOLOCATION_EVENT_POSITION_CHANGED_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ */
+
+#include "GeolocationFactory.h"
+#include <Geolocation/Geolocation.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Geolocation {
+IGeolocationPtr GeolocationFactory::getLocalizer()
+{
+ return IGeolocationPtr(new Platform::Geolocation::Geolocation());
+}
+
+GeolocationFactory& GeolocationFactory::getInstance()
+{
+ static GeolocationFactory theInstance;
+ return theInstance;
+}
+
+GeolocationFactory::GeolocationFactory()
+{
+}
+}
+}
+}
--- /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)
+ */
+
+#ifndef WRTPLUGINS_API_GEOLOCATIONFACTORY_H_
+#define WRTPLUGINS_API_GEOLOCATIONFACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "IGeolocation.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Geolocation {
+class GeolocationFactory : DPL::Noncopyable
+{
+ public:
+ IGeolocationPtr getLocalizer();
+
+ static GeolocationFactory& getInstance();
+
+ protected:
+ GeolocationFactory();
+};
+}
+}
+}
+
+#endif //WRTPLUGINS_API_GEOLOCATIONFACTORY_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ */
+
+#include "IGeolocation.h"
+#include "EventGetCurrentPosition.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Geolocation {
+using namespace Platform;
+
+IGeolocation::IGeolocation() :
+ EventRequestReceiver<EventGetCurrentPosition>(ThreadEnum::
+ GEOLOCATION_THREAD)
+{
+}
+
+IGeolocation::~IGeolocation()
+{
+}
+}
+}
+}
--- /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)
+ */
+
+#ifndef WRTPLUGINS_API_IGEOLOCATION_H_
+#define WRTPLUGINS_API_IGEOLOCATION_H_
+
+#include "EventPositionChanged.h"
+
+#include <dpl/shared_ptr.h>
+#include <platform/commons/ThreadPool.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Geolocation {
+class EventGetCurrentPosition;
+typedef DPL::SharedPtr<EventGetCurrentPosition> EventGetCurrentPositionPtr;
+
+class IGeolocation :
+ public Platform::EventRequestReceiver<EventGetCurrentPosition>
+{
+ public:
+ typedef enum
+ {
+ METHOD_GPS,
+ METHOD_AGPS,
+ METHOD_CPS,
+ METHOD_IPS,
+ METHOD_WPS,
+ METHOD_BEST
+ } ApiLocationMethod;
+
+ virtual ~IGeolocation();
+
+ /**
+ * Gets current position
+ * @param event @see WrtPlugins::Api::Geolocation::EventGetCurrentPosition.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void getCurrentPosition(const EventGetCurrentPositionPtr& event) =
+ 0;
+
+ /**
+ * Requests location module to receive continuously update of current
+ * position if the position is significantly changed
+ * @param emitter @see WrtPlugins::Api::Geolocation::EventPositionChanged.
+ * @param timeout
+ * @param maximumAge
+ * @param highAccuracy
+ * @return An ID of created subscription
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual long watchPosition(const EventPositionChangedEmitterPtr& emitter,
+ long timeout,
+ long maximumAge,
+ bool highAccuracy) = 0;
+
+ /**
+ * Stopping periodic location updates started with watchPosition
+ * @param id An Id of listener subscription.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void clearWatch(EventPositionChangedEmitter::IdType id) = 0;
+
+ /**
+ * Choses location method
+ * @param method A location method
+ * @exception Commons::PlatformException when platform error occurs
+ * @remarks does nothing when executed with the same method as currently used
+ */
+ virtual void changeLocationMethod(ApiLocationMethod method) = 0;
+
+ protected:
+ IGeolocation();
+
+ virtual void OnRequestReceived(const EventGetCurrentPositionPtr& event) = 0;
+};
+
+typedef DPL::SharedPtr<IGeolocation> IGeolocationPtr;
+}
+}
+}
+
+#endif /* WRTPLUGINS_API_IGEOLOCATION_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ */
+
+#ifndef WRTPLUGINS_API_GEOLOCATION_POSITION_PROPERTIES_H_
+#define WRTPLUGINS_API_GEOLOCATION_POSITION_PROPERTIES_H_
+
+#include <ctime>
+#include <dpl/shared_ptr.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Geolocation {
+struct PositionProperties
+{
+ std::time_t timestamp;
+ double latitude;
+ double longitude;
+ double altitude;
+ double accuracy;
+ double altitudeAccuracy;
+ double speed;
+ double direction;
+ double altitudeSpeed;
+
+ PositionProperties() :
+ timestamp(NULL),
+ latitude(0.0),
+ altitude(0.0),
+ accuracy(0.0),
+ altitudeAccuracy(0.0),
+ speed(0.0),
+ direction(0.0),
+ altitudeSpeed(0.0)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<PositionProperties> PositionPropertiesPtr;
+} // Geolocation
+} // Api
+} // WrtPlugins
+
+#endif //WRTPLUGINS_API_GEOLOCATION_POSITION_PROPERTIES_H_
--- /dev/null
+get_current_path()
+set(SRCS_PLATFORM_API_GEOLOCATION
+ ${CURRENT_PATH}/GeolocationFactory.cpp
+ ${CURRENT_PATH}/IGeolocation.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 <Memory/Manager.h>
+#include "IManager.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace Memory {
+IManager& IManager::getInstance()
+{
+ return Platform::Memory::Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+} // Memory
+} // Api
+} // 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 WRTPLUGINS_MEMORY_IMANAGER_H_
+#define WRTPLUGINS_MEMORY_IMANAGER_H_
+
+#include <dpl/noncopyable.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace Memory {
+class IManager : public DPL::Noncopyable
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets total memory.
+ * @return Total memory.
+ * @throw UnsupportedException If not supported by current platform.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual unsigned long getTotal() const = 0;
+
+ /**
+ * Gets free (available) memory.
+ * @return Free memory.
+ * @throw UnsupportedException If not supported by current platform.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual unsigned long getFree() const = 0;
+};
+} // Memory
+} // Api
+} // WrtPlugins
+
+#endif /* WRTPLUGINS_MEMORY_IMANAGER_H_ */
--- /dev/null
+get_current_path()
+
+set(SRCS_PLATFORM_API_MEMORY
+ ${CURRENT_PATH}/IManager.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 "IDate.h"
+
+namespace WrtPlugins {
+namespace Api {
+namespace System {
+IDate::~IDate()
+{
+}
+} // System
+} // Api
+} // 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 WRTPLUGINS_SYSTEM_IDATE_H_
+#define WRTPLUGINS_SYSTEM_IDATE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace System {
+/**
+ * Date class.
+ * Creating an Date object with default (parameterless) ctor makes object
+ * with current date/time values.
+ */
+class IDate
+{
+ public:
+ /**
+ * Represents format for date to string conversions.
+ */
+ typedef std::string Format;
+
+ public:
+ virtual ~IDate() = 0;
+
+ /**
+ * Gets date converted to string using default format.
+ * @return Date string.
+ */
+ virtual std::string toString() const = 0;
+
+ /**
+ * Gets date converted to string using specified format.
+ * @param format Format.
+ * @return Date string.
+ */
+ virtual std::string toString(const Format& format) const = 0;
+};
+
+typedef DPL::SharedPtr<IDate> IDatePtr;
+} // System
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_SYSTEM_IDATE_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 "IEnvironment.h"
+#include <System/Environment.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace System {
+IEnvironment& IEnvironment::getInstance()
+{
+ return Platform::System::Environment::getInstance();
+}
+
+IEnvironment::~IEnvironment()
+{
+}
+} // System
+} // Api
+} // 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 WRTPLUGINS_SYSTEM_IENVIRONMENT_H_
+#define WRTPLUGINS_SYSTEM_IENVIRONMENT_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+
+namespace WrtPlugins {
+namespace Api {
+namespace System {
+class IEnvironment : private DPL::Noncopyable
+{
+ public:
+ static IEnvironment& getInstance();
+
+ public:
+ /**
+ * Gets language code for current locale.
+ * @return Language code (ISO-639-1).
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks For Linux-based platforms this could be contents of LANG
+ * environment variable.
+ */
+ virtual std::string getLanguage() const = 0;
+
+ /**
+ * Gets version of the operation system.
+ * @return Operating system version.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks On UNIX/Linux-based system this could be versions of kernel.
+ */
+ virtual std::string getOsVersion() const = 0;
+
+ /**
+ * Gets version of software.
+ * @return Software version.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks On some platform this could be the same as OsVersion.
+ */
+ virtual std::string getSoftwareVersion() const = 0;
+
+ /**
+ * Gets name of hardware.
+ * @return Hardware name.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual std::string getHardwareName() const = 0;
+
+ /**
+ * Gets name of the vendor.
+ * @return Vendor's name.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks This could be either vendor of kernel, software or device.
+ */
+ virtual std::string getVendorName() const = 0;
+
+ public:
+ virtual ~IEnvironment() = 0;
+};
+} // System
+} // Api
+} // WrtPlugins
+
+#endif // WRTPLUGINS_SYSTEM_IENVIRONMENT_H_
--- /dev/null
+get_current_path()
+
+set(SRCS_PLATFORM_API_SYSTEM
+ ${CURRENT_PATH}/IEnvironment.cpp
+ ${CURRENT_PATH}/IDate.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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _ABSTRACT_LAYER_IEVENT_CLEAR_LOGS_H_
+#define _ABSTRACT_LAYER_IEVENT_CLEAR_LOGS_H_
+
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+#include "LogEntry.h"
+#include "LogFilter.h"
+
+namespace WrtPlugins {
+namespace Api {
+class IEventClearLog : public WrtPlugins::Platform::IEvent<IEventClearLog>
+{
+ bool m_result;
+ LogFilterPtr m_filter;
+ public:
+ void setFilter(LogFilterPtr value)
+ {
+ m_filter = value;
+ }
+ LogFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ virtual void clearOnCancel()
+ {
+ }
+ IEventClearLog() : m_result(false)
+ {
+ }
+ ~IEventClearLog()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventClearLog> IEventClearLogPtr;
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IEVENT_CLEAR_LOGS_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _ABSTRACT_LAYER_IEVENT_DELETE_LOG_ENTRY_H_
+#define _ABSTRACT_LAYER_IEVENT_DELETE_LOG_ENTRY_H_
+
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+#include "LogEntry.h"
+#include "LogFilter.h"
+
+namespace WrtPlugins {
+namespace Api {
+class IEventDeleteLogEntry : public WrtPlugins::Platform::IEvent<
+ IEventDeleteLogEntry>
+{
+ bool m_result;
+ LogFilterPtr m_filter;
+ public:
+ void setFilter(LogFilterPtr value)
+ {
+ m_filter = value;
+ }
+ LogFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ virtual void clearOnCancel()
+ {
+ }
+ IEventDeleteLogEntry() : m_result(false)
+ {
+ }
+ ~IEventDeleteLogEntry()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventDeleteLogEntry> IEventDeleteLogEntryPtr;
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IEVENT_DELETE_LOG_ENTRY_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _ABSTRACT_LAYER_IEVENT_FIND_LOG_ENTRIES_H_
+#define _ABSTRACT_LAYER_IEVENT_FIND_LOG_ENTRIES_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+#include "LogEntry.h"
+#include "LogFilter.h"
+
+namespace WrtPlugins {
+namespace Api {
+class IEventFindLogEntries : public WrtPlugins::Platform::IEvent<
+ IEventFindLogEntries>
+{
+ bool m_result;
+ std::vector<Api::LogEntryPtr> m_logs;
+ LogFilterPtr m_filter;
+ int m_firstCall;
+ int m_lastCall;
+ public:
+ void setFirstCall(int value)
+ {
+ m_firstCall = value;
+ }
+ int getFirstCall() const
+ {
+ return m_firstCall;
+ }
+ void setLastCall(int value)
+ {
+ m_lastCall = value;
+ }
+ int getLastCall() const
+ {
+ return m_lastCall;
+ }
+ void setFilter(LogFilterPtr value)
+ {
+ m_filter = value;
+ }
+ LogFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ std::vector<Api::LogEntryPtr> getLogs() const
+ {
+ return m_logs;
+ }
+ void addLog(Api::LogEntryPtr log)
+ {
+ m_logs.push_back(log);
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ virtual void clearOnCancel()
+ {
+ }
+ IEventFindLogEntries() : m_result(false),
+ m_firstCall(0),
+ m_lastCall(-1)
+ {
+ }
+ ~IEventFindLogEntries()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventFindLogEntries> IEventFindLogEntriesPtr;
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IEVENT_FIND_LOG_ENTRIES_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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef _ABSTRACT_LAYER_IEVENT_GET_NUMBER_OF_LOGS_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_NUMBER_OF_LOGS_H_
+
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+#include "LogEntry.h"
+#include "LogFilter.h"
+
+namespace WrtPlugins {
+namespace Api {
+class IEventGetNumberOfLogs : public WrtPlugins::Platform::IEvent<
+ IEventGetNumberOfLogs>
+{
+ bool m_result;
+ int m_numberOfLogs;
+ LogFilterPtr m_filter;
+ public:
+ void setFilter(LogFilterPtr value)
+ {
+ m_filter = value;
+ }
+ LogFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ void setNumberOfLogs(int value)
+ {
+ m_numberOfLogs = value;
+ }
+ int getNumberOfLogs() const
+ {
+ return m_numberOfLogs;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ virtual void clearOnCancel()
+ {
+ }
+ IEventGetNumberOfLogs() : m_result(false),
+ m_numberOfLogs(0)
+ {
+ }
+ ~IEventGetNumberOfLogs()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventGetNumberOfLogs> IEventGetNumberOfLogsPtr;
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_NUMBER_OF_LOGS_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 ILogManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <commons/ThreadPool.h>
+#include "ILogManager.h"
+
+namespace WrtPlugins {
+namespace Api {
+ILogManager::ILogManager() :
+ EventRequestReceiverGetNumberOfLogs(Platform::ThreadEnum::TELEPHONY_THREAD),
+ EventRequestReceiverFindLogEntries(Platform::ThreadEnum::TELEPHONY_THREAD),
+ EventRequestReceiverDeleteLogEntry(Platform::ThreadEnum::TELEPHONY_THREAD),
+ EventRequestReceiverClearLogs(Platform::ThreadEnum::TELEPHONY_THREAD)
+{
+}
+
+ILogManager::~ILogManager()
+{
+}
+
+void ILogManager::getNumberOfLogs(const IEventGetNumberOfLogsPtr &event)
+{
+ EventRequestReceiverGetNumberOfLogs::PostRequest(event);
+}
+
+void ILogManager::findLogEntries(const IEventFindLogEntriesPtr &event)
+{
+ EventRequestReceiverFindLogEntries::PostRequest(event);
+}
+
+void ILogManager::deleteLogEntry(const IEventDeleteLogEntryPtr &event)
+{
+ EventRequestReceiverDeleteLogEntry::PostRequest(event);
+}
+
+void ILogManager::clearLogs(const IEventClearLogPtr &event)
+{
+ EventRequestReceiverClearLogs::PostRequest(event);
+}
+}
+}
--- /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 ILogManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _ABSTRACT_LAYER_ILOG_MANAGER_H_
+#define _ABSTRACT_LAYER_ILOG_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include "LogEntry.h"
+#include "IEventClearLogs.h"
+#include "IEventDeleteLogEntry.h"
+#include "IEventFindLogEntries.h"
+#include "IEventGetNumberOfLogs.h"
+
+namespace WrtPlugins {
+namespace Api {
+typedef Platform::EventRequestReceiver< IEventGetNumberOfLogs >
+EventRequestReceiverGetNumberOfLogs;
+typedef Platform::EventRequestReceiver< IEventFindLogEntries >
+EventRequestReceiverFindLogEntries;
+typedef Platform::EventRequestReceiver< IEventDeleteLogEntry >
+EventRequestReceiverDeleteLogEntry;
+typedef Platform::EventRequestReceiver< IEventClearLog >
+EventRequestReceiverClearLogs;
+
+class ILogManager : public EventRequestReceiverGetNumberOfLogs,
+ public EventRequestReceiverFindLogEntries,
+ public EventRequestReceiverDeleteLogEntry,
+ public EventRequestReceiverClearLogs
+{
+ public:
+ ILogManager();
+ virtual ~ILogManager();
+ virtual void getNumberOfLogs(const IEventGetNumberOfLogsPtr &event);
+ virtual void findLogEntries(const IEventFindLogEntriesPtr &event);
+ virtual void deleteLogEntry(const IEventDeleteLogEntryPtr &event);
+ virtual void clearLogs(const IEventClearLogPtr &event);
+ protected:
+ virtual void OnRequestReceived(
+ const IEventGetNumberOfLogsPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventFindLogEntriesPtr &event)
+ = 0;
+ virtual void OnRequestReceived(const IEventDeleteLogEntryPtr &event)
+ = 0;
+ virtual void OnRequestReceived(const IEventClearLogPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<ILogManager> ILogManagerPtr;
+}
+}
+
+#endif /* _ABSTRACT_LAYER_ILOG_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.
+ */
+/**
+ * @file LogEntry.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "LogEntry.h"
+#include <dpl/log/log.h>
+
+namespace WrtPlugins {
+namespace Api {
+LogEntry::LogEntry() :
+ m_id(UNDEFINED_LOG_ENTRY_ID),
+ m_startTime(0),
+ m_duration(0),
+ m_folder(LogEntry::INVALID_FOLDER)
+{
+}
+
+LogEntry::~LogEntry()
+{
+}
+
+int LogEntry::getId() const
+{
+ return m_id;
+}
+
+void LogEntry::setId(int value)
+{
+ m_id = value;
+}
+
+std::string LogEntry::getPhoneNumber() const
+{
+ return m_phoneNumber;
+}
+
+void LogEntry::setPhoneNumber(const std::string &value)
+{
+ m_phoneNumber = value;
+}
+
+std::time_t LogEntry::getStartTime() const
+{
+ return m_startTime;
+}
+
+void LogEntry::setStartTime(std::time_t value)
+{
+ m_startTime = value;
+}
+
+int LogEntry::getDuration() const
+{
+ return m_duration;
+}
+
+void LogEntry::setDuration(int value)
+{
+ m_duration = value;
+}
+
+LogEntry::LogFolder LogEntry::getFolder() const
+{
+ return m_folder;
+}
+
+void LogEntry::setFolder(LogFolder value)
+{
+ m_folder = value;
+}
+
+std::string LogEntry::getDescription() const
+{
+ return m_description;
+}
+
+void LogEntry::setDescription(const std::string &value)
+{
+ m_description = value;
+}
+
+void LogEntry::display()
+{
+ LogDebug("m_id " << m_id);
+ LogDebug("m_duration " << m_duration);
+ LogDebug("m_startTime " << m_startTime);
+ LogDebug("m_phoneNumber " << m_phoneNumber);
+ LogDebug("m_folder " << m_folder);
+ LogDebug("m_description " << m_description);
+}
+}
+}
\ 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 LogEntry.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _ABSTRACT_LAYER_CALENDAR_EVENT_H_
+#define _ABSTRACT_LAYER_CALENDAR_EVENT_H_
+
+#include <ctime>
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtPlugins {
+namespace Api {
+const int UNDEFINED_LOG_ENTRY_ID = -1;
+
+class LogEntry
+{
+ public:
+
+ typedef enum
+ {
+ RECEIVED_CALLS_FOLDER,
+ REJECTED_CALLS_FOLDER,
+ MISSED_CALLS_FOLDER,
+ INITIATED_CALLS_FOLDER,
+ INVALID_FOLDER = 10000,
+ UNDEFINED_FOLDER /* should be used only to mark a fact filter is not set */
+ } LogFolder;
+
+ LogEntry();
+ virtual ~LogEntry();
+
+ int getId() const;
+ void setId(int value);
+
+ std::string getPhoneNumber() const;
+ void setPhoneNumber(const std::string &value);
+
+ std::time_t getStartTime() const;
+ void setStartTime(std::time_t value);
+
+ int getDuration() const;
+ void setDuration(int value);
+
+ LogFolder getFolder() const;
+ void setFolder(LogFolder value);
+
+ std::string getDescription() const;
+ void setDescription(const std::string &value);
+
+ void display();
+
+ protected:
+ int m_id;
+ std::string m_phoneNumber;
+ std::time_t m_startTime;
+ int m_duration;
+ LogFolder m_folder;
+ std::string m_description;
+};
+
+typedef DPL::SharedPtr<LogEntry> LogEntryPtr;
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CALENDAR_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 LogFilter.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <ctime>
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include "LogFilter.h"
+
+namespace WrtPlugins {
+namespace Api {
+LogFilter::LogFilter() :
+ m_id(LOG_FILTER_UNDEFINED_ID),
+ m_phoneNumber(""),
+ m_startTimeMin(LOG_FILTER_UNDEFINED_TIME_T_MEMBERS),
+ m_startTimeMax(LOG_FILTER_UNDEFINED_TIME_T_MEMBERS),
+ m_durationMin(LOG_FILTER_UNDEFINED_DURATION),
+ m_durationMax(LOG_FILTER_UNDEFINED_DURATION),
+ m_phoneNumberIsSet(false),
+ m_descriptionIsSet(false)
+{
+}
+
+LogFilter::~LogFilter()
+{
+}
+
+int
+LogFilter::getIdFilter() const
+{
+ return m_id;
+}
+
+void
+LogFilter::setIdFilter(int value)
+{
+ m_id = value;
+}
+
+std::string
+LogFilter::getPhoneNumberFilter() const
+{
+ return m_phoneNumber;
+}
+
+void
+LogFilter::setPhoneNumberFilter(const std::string &value)
+{
+ m_phoneNumberIsSet = true;
+ m_phoneNumber = value;
+}
+
+time_t
+LogFilter::getStartTimeMinFilter() const
+{
+ return m_startTimeMin;
+}
+
+time_t
+LogFilter::getStartTimeMaxFilter() const
+{
+ return m_startTimeMax;
+}
+
+void
+LogFilter::setStartTimeMinFilter(time_t value)
+{
+ m_startTimeMin = value;
+}
+
+void
+LogFilter::setStartTimeMaxFilter(time_t value)
+{
+ m_startTimeMax = value;
+}
+
+void
+LogFilter::setStartTimeFilter(time_t value)
+{
+ setStartTimeMinFilter(value);
+ setStartTimeMaxFilter(value);
+}
+
+int
+LogFilter::getDurationMinFilter() const
+{
+ return m_durationMin;
+}
+
+int
+LogFilter::getDurationMaxFilter() const
+{
+ return m_durationMax;
+}
+
+void
+LogFilter::setDurationMinFilter(int value)
+{
+ m_durationMin = value;
+}
+
+void
+LogFilter::setDurationMaxFilter(int value)
+{
+ m_durationMax = value;
+}
+
+void
+LogFilter::setDurationFilter(int value)
+{
+ setDurationMinFilter(value);
+ setDurationMaxFilter(value);
+}
+
+std::list<LogEntry::LogFolder>
+LogFilter::getFolderFilter() const
+{
+ return m_folder;
+}
+
+void
+LogFilter::addFolderFilter(LogEntry::LogFolder value)
+{
+ m_folder.push_back(value);
+}
+
+std::string
+LogFilter::getDescriptionFilter() const
+{
+ return m_description;
+}
+void
+LogFilter::setDescriptionFilter(const std::string &value)
+{
+ m_description = value;
+ m_descriptionIsSet = true;
+}
+
+bool
+LogFilter::getIdIsSet() const
+{
+ return m_id != LOG_FILTER_UNDEFINED_ID;
+}
+
+bool
+LogFilter::getPhoneNumberIsSet() const
+{
+ return m_phoneNumberIsSet;
+}
+
+bool
+LogFilter::getStartTimeIsSet() const
+{
+ return m_startTimeMin != LOG_FILTER_UNDEFINED_TIME_T_MEMBERS;
+}
+
+bool
+LogFilter::getDurationIsSet() const
+{
+ return m_durationMin != LOG_FILTER_UNDEFINED_DURATION;
+}
+
+bool
+LogFilter::getFolderIsSet() const
+{
+ LogDebug("entered");
+ return m_folder.size() != 0;
+}
+
+bool
+LogFilter::getDescriptionIsSet() const
+{
+ return m_descriptionIsSet;
+}
+
+bool
+LogFilter::checkIfFolderIsSet(LogEntry::LogFolder folder) const
+{
+ LogDebug("entered");
+ std::list<LogEntry::LogFolder>::const_iterator result =
+ std::find(m_folder.begin(), m_folder.end(), folder);
+ return result != m_folder.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 LogFilter.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _ABSTRACT_LAYER_LOG_FILTER_H_
+#define _ABSTRACT_LAYER_LOG_FILTER_H_
+
+#include <ctime>
+#include <list>
+#include <dpl/shared_ptr.h>
+#include "LogEntry.h"
+
+namespace WrtPlugins {
+namespace Api {
+const int LOG_FILTER_UNDEFINED_ID = -1;
+const int LOG_FILTER_UNDEFINED_TIME_T_MEMBERS = -1;
+const int LOG_FILTER_UNDEFINED_DURATION = -1;
+
+class LogFilter
+{
+ public:
+
+ LogFilter();
+ virtual ~LogFilter();
+
+ int getIdFilter() const;
+ void setIdFilter(int value);
+
+ std::string getPhoneNumberFilter() const;
+ void setPhoneNumberFilter(const std::string &value);
+
+ time_t getStartTimeMinFilter() const;
+ time_t getStartTimeMaxFilter() const;
+ void setStartTimeMinFilter(time_t value);
+ void setStartTimeMaxFilter(time_t value);
+ void setStartTimeFilter(time_t value);
+
+ int getDurationMinFilter() const;
+ int getDurationMaxFilter() const;
+ void setDurationMinFilter(int value);
+ void setDurationMaxFilter(int value);
+ void setDurationFilter(int value);
+
+ std::list<LogEntry::LogFolder> getFolderFilter() const;
+ void addFolderFilter(LogEntry::LogFolder value);
+
+ std::string getDescriptionFilter() const;
+ void setDescriptionFilter(const std::string &value);
+
+ bool getIdIsSet() const;
+ bool getPhoneNumberIsSet() const;
+ bool getStartTimeIsSet() const;
+ bool getDurationIsSet() const;
+ bool getFolderIsSet() const;
+ bool checkIfFolderIsSet(LogEntry::LogFolder folder) const;
+ bool getDescriptionIsSet() const;
+
+ protected:
+ int m_id;
+ std::string m_phoneNumber;
+ time_t m_startTimeMin;
+ time_t m_startTimeMax;
+ int m_durationMin;
+ int m_durationMax;
+ std::list<LogEntry::LogFolder> m_folder;
+ std::string m_description;
+
+ bool m_phoneNumberIsSet;
+ bool m_descriptionIsSet;
+};
+
+typedef DPL::SharedPtr<LogFilter> LogFilterPtr;
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IEVENT_FILTER_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 "TelephonyFactory.h"
+#include <Telephony/LogManager.h>
+
+namespace WrtPlugins {
+namespace Api {
+ILogManagerPtr TelephonyFactory::createLogManagerObject()
+{
+ ILogManagerPtr result(new WrtPlugins::Platform::LogManager());
+ return result;
+}
+
+TelephonyFactory& TelephonyFactory::getInstance()
+{
+ static TelephonyFactory theInstance;
+ return theInstance;
+}
+}
+}
--- /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 TelephonyFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef _ABSTRACT_LAYER_TELEPHONY_FACTORY_H_
+#define _ABSTRACT_LAYER_TELEPHONY_FACTORY_H_
+
+#include <dpl/shared_ptr.h>
+#include "ILogManager.h"
+
+namespace WrtPlugins {
+namespace Api {
+class TelephonyFactory : private DPL::Noncopyable
+{
+ private:
+ TelephonyFactory()
+ {
+ }
+ public:
+ static TelephonyFactory& getInstance();
+ ILogManagerPtr createLogManagerObject();
+};
+}
+}
+
+#endif /* _ABSTRACT_LAYER_TELEPHONY_FACTORY_H_ */
\ No newline at end of file
--- /dev/null
+get_current_path()
+set(SRCS_PLATFORM_API_TELEPHONY
+ ${CURRENT_PATH}/TelephonyFactory.cpp
+ ${CURRENT_PATH}/LogFilter.cpp
+ ${CURRENT_PATH}/LogEntry.cpp
+ ${CURRENT_PATH}/ILogManager.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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTPLUGINSUIIPREFERENCES_H_
+#define WRTPLUGINSUIIPREFERENCES_H_
+
+#include <dpl/event/controller.h>
+#include <commons/ThreadPool.h>
+#include <commons/EventReceiver.h>
+#include "IPreferencesEvents.h"
+
+namespace WrtPlugins {
+namespace Api {
+//============================================================
+class IPreferences : public Platform::EventRequestReceiver< IEventSetWallpaper >,
+ public Platform::EventRequestReceiver< IEventSetCallRingtone >,
+ public Platform::EventRequestReceiver< IEventSetMessageRingtone >
+{
+ protected:
+ IPreferences() : Platform::EventRequestReceiver< IEventSetWallpaper >(
+ Platform::ThreadEnum::UI_THREAD),
+ Platform::EventRequestReceiver< IEventSetCallRingtone >(Platform::
+ ThreadEnum
+ ::UI_THREAD),
+ Platform::EventRequestReceiver< IEventSetMessageRingtone >(Platform::
+ ThreadEnum
+ ::
+ UI_THREAD)
+ {
+ }
+
+ virtual void OnRequestReceived(
+ const DPL::SharedPtr<IEventSetWallpaper> &event) = 0;
+ virtual void OnRequestReceived(
+ const DPL::SharedPtr<IEventSetCallRingtone> &event) = 0;
+ virtual void OnRequestReceived(
+ const DPL::SharedPtr<IEventSetMessageRingtone> &event) = 0;
+ public:
+ virtual void setWallpaper(DPL::SharedPtr<IEventSetWallpaper> &event)
+ {
+ PostRequest(event);
+ }
+ virtual void setCallRingtone(DPL::SharedPtr<IEventSetCallRingtone> &event)
+ {
+ PostRequest(event);
+ }
+ virtual void setMessageRingtone(
+ DPL::SharedPtr<IEventSetMessageRingtone> &event)
+ {
+ PostRequest(event);
+ }
+
+ virtual ~IPreferences()
+ {
+ }
+};
+//============================================================
+} //namespace
+} //namespace
+
+#endif /* WRTPLUGINSUIIPREFERENCES_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTPLUGINSUIIEVENTS_H_
+#define WRTPLUGINSUIIEVENTS_H_
+
+#include <dpl/shared_ptr.h>
+#include <commons/IEvent.h>
+
+namespace WrtPlugins {
+namespace Api {
+//=========================================================================
+class IEventSetWallpaper : public WrtPlugins::Platform::IEvent<
+ IEventSetWallpaper>
+{
+ public:
+ IEventSetWallpaper()
+ {
+ }
+
+ virtual ~IEventSetWallpaper()
+ {
+ }
+};
+typedef DPL::SharedPtr<IEventSetWallpaper> IEventSetWallpaperPtr;
+//=========================================================================
+class IEventSetCallRingtone : public WrtPlugins::Platform::IEvent<
+ IEventSetCallRingtone>
+{
+ public:
+ IEventSetCallRingtone()
+ {
+ }
+
+ virtual ~IEventSetCallRingtone()
+ {
+ }
+};
+typedef DPL::SharedPtr<IEventSetCallRingtone> IEventSetCallRingtonePtr;
+//=========================================================================
+class IEventSetMessageRingtone : public WrtPlugins::Platform::IEvent<
+ IEventSetMessageRingtone>
+{
+ public:
+ IEventSetMessageRingtone()
+ {
+ }
+
+ virtual ~IEventSetMessageRingtone()
+ {
+ }
+};
+typedef DPL::SharedPtr<IEventSetMessageRingtone> IEventSetMessageRingtonePtr;
+//=========================================================================
+}
+}
+
+#endif /* WRTPLUGINSUIIEVENTS_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.
+ */
+/*
+ * CameraController.cpp
+ *
+ * Created on: 2010-06-28
+ * Author: kmajewski
+ */
+
+#include "UIFactory.h"
+
+namespace WrtPlugins {
+namespace Api {
+UIFactory& UIFactory::getInstance()
+{
+ static UIFactory theInstance;
+ return theInstance;
+}
+}
+}
--- /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.
+ */
+/*
+ * CameraController.h
+ *
+ * Created on: 2010-06-28
+ * Author: kmajewski
+ */
+
+#ifndef WRTPLUGINSUIFACTORY_H_
+#define WRTPLUGINSUIFACTORY_H_
+
+#include <dpl/noncopyable.h>
+
+namespace WrtPlugins {
+namespace Api {
+class UIFactory : private DPL::Noncopyable
+{
+ private:
+ UIFactory()
+ {
+ }
+ public:
+ static UIFactory& getInstance();
+};
+}
+}
+#endif /* WRTPLUGINSUIFACTORY_H_ */
--- /dev/null
+get_current_path()
+set(SRCS_PLATFORM_API_UI
+ ${CURRENT_PATH}/UIFactory.cpp
+
+ PARENT_SCOPE
+)
--- /dev/null
+!!!options!!! stop
+Platform independent platform API
--- /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_FILESYSTEM_ENUMS_H_
+#define WRTDEVICEAPIS_FILESYSTEM_ENUMS_H_
+
+#include <string>
+#include <map>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+enum LocationType
+{
+ LT_APPS,
+ LT_DOCUMENTS,
+ LT_DOWNLOADS,
+ LT_GAMES,
+ LT_IMAGES,
+ LT_OTHERS,
+ LT_ROOT,
+ LT_SDCARD,
+ LT_SOUNDS,
+ LT_TEMP,
+ LT_VIDEOS
+};
+
+enum NodeType
+{
+ NT_DIRECTORY,
+ NT_FILE
+};
+
+enum AccessMode
+{
+ AM_READ = 0x0001,
+ AM_WRITE = 0x0002,
+ AM_APPEND = 0x0004
+};
+
+/**
+ * Used in @see IManager::access().
+ */
+enum AccessType
+{
+ AT_EXISTS = 0x0000, //!< AT_EXISTS - checks for existence
+ AT_READ = 0x0001, //!< AT_READ - checks for read access
+ AT_WRITE = 0x0002, //!< AT_WRITE - checks for write access
+ AT_EXEC = 0x0004 //!< AT_EXEC - checks for execution access
+};
+
+enum Permissions
+{
+ PERM_NONE = 0x0000,
+ PERM_READ = 0x0001,
+ PERM_WRITE = 0x0002
+};
+
+enum PlatformMode
+{
+ PM_USER_READ = 0x0100,
+ PM_USER_WRITE = 0x0080,
+ PM_USER_EXEC = 0x0040,
+ PM_GROUP_READ = 0x0020,
+ PM_GROUP_WRITE = 0x0010,
+ PM_GROUP_EXEC = 0x0008,
+ PM_OTHER_READ = 0x0004,
+ PM_OTHER_WRITE = 0x0002,
+ PM_OTHER_EXEC = 0x0001,
+ PM_NONE = 0x0000
+};
+
+enum Options
+{
+ OPT_NONE = 0x0000,
+ OPT_OVERWRITE = 0x0001,
+ OPT_RECURSIVE = 0x0002
+};
+
+enum FindFilter
+{
+ FF_NAME,
+ FF_CREATED,
+ FF_MODIFIED,
+ FF_SIZE
+};
+typedef std::map<FindFilter, std::string> FiltersMap;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_FILESYSTEM_ENUMS_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 "EventCopy.h"
+#include <dpl/assert.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+EventCopy::EventCopy(const IPathPtr& src,
+ const IPathPtr& dest) :
+ m_src(src),
+ m_dest(dest),
+ m_options(OPT_NONE)
+{
+ Assert(src && "Source path not set.");
+ Assert(dest && "Destination path not set.");
+}
+
+IPathPtr EventCopy::getDestination() const
+{
+ return m_dest;
+}
+
+IPathPtr EventCopy::getSource() const
+{
+ return m_src;
+}
+
+INodePtr EventCopy::getResult() const
+{
+ return m_result;
+}
+
+void EventCopy::setResult(const INodePtr& node)
+{
+ m_result = node;
+}
+
+int EventCopy::getOptions() const
+{
+ return m_options;
+}
+
+void EventCopy::setOptions(int options)
+{
+ m_options = options;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_EVENTCOPY_H_
+#define WRTDEVICEAPIS_FILESYSTEM_EVENTCOPY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INode.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventCopy : public Commons::IEvent<EventCopy>
+{
+ public:
+ /**
+ * Creates new event object.
+ * @param src Path to source node.
+ * @param dest Path to destination node.
+ * @return New object.
+ */
+ EventCopy(const IPathPtr& src,
+ const IPathPtr& dest);
+
+ /**
+ * Gets destination path.
+ * @return Destination path.
+ */
+ IPathPtr getDestination() const;
+
+ /**
+ * Gets source path.
+ * @return Source path.
+ */
+ IPathPtr getSource() const;
+
+ /**
+ * Gets result node.
+ * @return Result node.
+ */
+ INodePtr getResult() const;
+
+ /**
+ * Sets result node.
+ * @param node Result node.
+ */
+ void setResult(const INodePtr& node);
+
+ /**
+ * Gets options.
+ * @return Options.
+ */
+ int getOptions() const;
+
+ /**
+ * Sets options.
+ * @param options Options.
+ */
+ void setOptions(int options);
+
+ private:
+ IPathPtr m_src; ///< Source path.
+ IPathPtr m_dest; ///< Destination path.
+ INodePtr m_result; ///< Result node.
+ int m_options; ///< Options for copy action @see WrtDeviceApis::Api::Filesystem::Options.
+};
+
+typedef DPL::SharedPtr<EventCopy> EventCopyPtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_EVENTCOPY_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 "EventFind.h"
+
+#include <Filesystem/Path.h>
+#include "INode.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+EventFind::EventFind(const IPathPtr& path) : m_path(path)
+{
+}
+
+IPathPtr EventFind::getPath() const
+{
+ return m_path;
+}
+
+NodeList EventFind::getResult() const
+{
+ return m_nodes;
+}
+
+void EventFind::addResult(const INodePtr& node)
+{
+ m_nodes.push_back(node);
+}
+
+void EventFind::setResult(const NodeList& nodes)
+{
+ m_nodes = nodes;
+}
+
+void EventFind::addFilter(FindFilter name,
+ const std::string& value)
+{
+ m_filters.insert(std::pair<FindFilter, std::string>(name, value));
+}
+
+FiltersMap EventFind::getFilters() const
+{
+ return m_filters;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_IEVENTFILESYSTEMFIND_H_
+#define WRTDEVICEAPIS_IEVENTFILESYSTEMFIND_H_
+
+#include <list>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INodeTypes.h"
+#include "Enums.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventFind : public Commons::IEvent<EventFind>
+{
+ public:
+ /**
+ * Creates new event object.
+ * @param path Start path.
+ * @return New object.
+ */
+ explicit EventFind(const IPathPtr& path);
+
+ /**
+ * Gets start path.
+ * @return Path to start searching from.
+ */
+ IPathPtr getPath() const;
+
+ /**
+ * Gets found nodes.
+ * @return Nodes.
+ */
+ NodeList getResult() const;
+
+ /**
+ * Adds found node.
+ * @param node Found node.
+ */
+ void addResult(const INodePtr& node);
+
+ /**
+ * Sets found nodes.
+ * @param nodes Nodes.
+ */
+ void setResult(const NodeList& nodes);
+
+ /**
+ * Adds find filter.
+ * @param name Filter name.
+ * @param value Filter value.
+ */
+ void addFilter(FindFilter name,
+ const std::string& value);
+
+ /**
+ * Gets all filters.
+ * @return Filters.
+ */
+ FiltersMap getFilters() const;
+
+ private:
+ IPathPtr m_path; ///< Start path.
+ NodeList m_nodes; ///< Resolved nodes.
+ FiltersMap m_filters; ///< Search filters.
+};
+
+typedef DPL::SharedPtr<EventFind> EventFindPtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_IEVENTFILESYSTEMFIND_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 "EventListNodes.h"
+#include <dpl/assert.h>
+#include "INode.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+EventListNodes::EventListNodes(const INodePtr& node) : m_node(node)
+{
+ Assert(m_node && "Node can't be NULL.");
+}
+
+INodePtr EventListNodes::getNode() const
+{
+ return m_node;
+}
+
+NodeFilterPtr EventListNodes::getFilter() const
+{
+ return m_filter;
+}
+
+void EventListNodes::setFilter(const NodeFilterPtr& filter)
+{
+ m_filter = filter;
+}
+
+NodeList EventListNodes::getResult() const
+{
+ return m_list;
+}
+
+void EventListNodes::setResult(const NodeList& list)
+{
+ m_list = list;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_EVENTLISTNODES_H_
+#define WRTDEVICEAPIS_FILESYSTEM_EVENTLISTNODES_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "INodeTypes.h"
+#include "NodeFilter.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventListNodes : public Commons::IEvent<EventListNodes>
+{
+ public:
+ /**
+ * Creates new event object.
+ * @param path Node to list children for.
+ * @return New object.
+ */
+ explicit EventListNodes(const INodePtr& node);
+
+ /**
+ * Gets parent node.
+ * @return Parent node.
+ */
+ INodePtr getNode() const;
+
+ /**
+ * Gets filter.
+ * @return Filter.
+ */
+ NodeFilterPtr getFilter() const;
+
+ /**
+ * Sets filter.
+ * @param filter Filter to list only specific nodes.
+ */
+ void setFilter(const NodeFilterPtr& filter);
+
+ /**
+ * Gets nodes.
+ * @return Nodes list.
+ */
+ NodeList getResult() const;
+
+ /**
+ * Sets nodes list.
+ * @param list Nodes list.
+ */
+ void setResult(const NodeList& list);
+
+ private:
+ NodeList m_list; ///< List of child nodes.
+ INodePtr m_node; ///< Node to list children for.
+ NodeFilterPtr m_filter; ///< Filter.
+};
+
+typedef DPL::SharedPtr<EventListNodes> EventListNodesPtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_EVENTLISTNODES_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 "EventMove.h"
+#include <dpl/assert.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+EventMove::EventMove(const IPathPtr& src,
+ const IPathPtr& dest) :
+ m_src(src),
+ m_dest(dest),
+ m_options(OPT_NONE)
+{
+ Assert(src && "Source path not set.");
+ Assert(dest && "Destination path not set.");
+}
+
+IPathPtr EventMove::getDestination() const
+{
+ return m_dest;
+}
+
+IPathPtr EventMove::getSource() const
+{
+ return m_src;
+}
+
+INodePtr EventMove::getResult() const
+{
+ return m_result;
+}
+
+void EventMove::setResult(const INodePtr& node)
+{
+ m_result = node;
+}
+
+int EventMove::getOptions() const
+{
+ return m_options;
+}
+
+void EventMove::setOptions(int options)
+{
+ m_options = options;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_EVENTMOVE_H_
+#define WRTDEVICEAPIS_FILESYSTEM_EVENTMOVE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INode.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventMove : public Commons::IEvent<EventMove>
+{
+ public:
+ /**
+ * Creates new event object.
+ * @param src Source path.
+ * @param dest Destination path.
+ * @return New object.
+ */
+ EventMove(const IPathPtr& src,
+ const IPathPtr& dest);
+
+ /**
+ * Gets destination path.
+ * @return Destination path.
+ */
+ IPathPtr getDestination() const;
+
+ /**
+ * Gets source path.
+ * @return Source path.
+ */
+ IPathPtr getSource() const;
+
+ /**
+ * Gets result node.
+ * @return Result node.
+ */
+ INodePtr getResult() const;
+
+ /**
+ * Sets result node.
+ * @param node Result node.
+ */
+ void setResult(const INodePtr& node);
+
+ /**
+ * Gets options.
+ * @return Options.
+ */
+ int getOptions() const;
+
+ /**
+ * Sets options.
+ * @param options Options.
+ */
+ void setOptions(int options);
+
+ private:
+ IPathPtr m_src; ///< Source path.
+ IPathPtr m_dest; ///< Destination path.
+ INodePtr m_result; ///< Result node.
+ int m_options; ///< Options for copy action @see WrtDeviceApis::Api::Filesystem::Options.
+};
+
+typedef DPL::SharedPtr<EventMove> EventMovePtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_EVENTMOVE_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 "EventOpen.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+EventOpen::EventOpen(int mode) : m_mode(mode)
+{
+}
+
+int EventOpen::getMode() const
+{
+ return m_mode;
+}
+
+IStreamPtr EventOpen::getResult() const
+{
+ return m_stream;
+}
+
+void EventOpen::setResult(const IStreamPtr& stream)
+{
+ m_stream = stream;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_EVENTOPEN_H_
+#define WRTDEVICEAPIS_FILESYSTEM_EVENTOPEN_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IStream.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventOpen : public Commons::IEvent<EventOpen>
+{
+ public:
+ /**
+ * Creates new event object.
+ * @param mode Mode to open the node in.
+ * @return New object.
+ */
+ explicit EventOpen(int mode);
+
+ /**
+ * Gets mode.
+ * @return Mode.
+ */
+ int getMode() const;
+
+ /**
+ * Gets result stream.
+ * @return Result stream.
+ */
+ IStreamPtr getResult() const;
+
+ /**
+ * Sets result stream.
+ * @param stream Result stream.
+ */
+ void setResult(const IStreamPtr& stream);
+
+ private:
+ int m_mode; ///< Mode.
+ IStreamPtr m_stream; ///< Opened stream.
+};
+
+typedef DPL::SharedPtr<EventOpen> EventOpenPtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_EVENTOPEN_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 "EventReadText.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+std::string EventReadText::getResult() const
+{
+ return m_result;
+}
+
+void EventReadText::setResult(const std::string& result)
+{
+ m_result = result;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_EVENTREADTEXT_H_
+#define WRTDEVICEAPIS_FILESYSTEM_EVENTREADTEXT_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventReadText : public Commons::IEvent<EventReadText>
+{
+ public:
+ /**
+ * Gets read text.
+ * @return Text.
+ */
+ std::string getResult() const;
+
+ /**
+ * Sets read text.
+ * @param result Text.
+ */
+ void setResult(const std::string& result);
+
+ private:
+ std::string m_result; ///< Read text.
+};
+
+typedef DPL::SharedPtr<EventReadText> EventReadTextPtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_EVENTREADTEXT_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 "EventRemove.h"
+#include <dpl/assert.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+EventRemove::EventRemove(const IPathPtr& path) :
+ m_path(path),
+ m_options(OPT_NONE)
+{
+ Assert(m_path && "Path is not set.");
+}
+
+IPathPtr EventRemove::getPath() const
+{
+ return m_path;
+}
+
+int EventRemove::getOptions() const
+{
+ return m_options;
+}
+
+void EventRemove::setOptions(int options)
+{
+ m_options = options;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_EVENTREMOVE_H_
+#define WRTDEVICEAPIS_FILESYSTEM_EVENTREMOVE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "INode.h"
+#include "Enums.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventRemove : public Commons::IEvent<EventRemove>
+{
+ public:
+ /**
+ * Creates new event object.
+ * @param path Path to the node to remove.
+ * @return New object.
+ */
+ explicit EventRemove(const IPathPtr& path);
+
+ /**
+ * Gets path to the node to remove.
+ * @return Path.
+ */
+ IPathPtr getPath() const;
+
+ /**
+ * Gets options.
+ * @return Options.
+ */
+ int getOptions() const;
+
+ /**
+ * Sets options.
+ * @param options Options.
+ */
+ void setOptions(int options);
+
+ private:
+ IPathPtr m_path; ///< Source path.
+ int m_options; ///< Options for remove action @see WrtDeviceApis::Api::Filesystem::Options.
+};
+
+typedef DPL::SharedPtr<EventRemove> EventRemovePtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_EVENTREMOVE_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 "EventResolve.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+EventResolve::EventResolve(const IPathPtr& path) : m_path(path)
+{
+}
+
+IPathPtr EventResolve::getPath() const
+{
+ return m_path;
+}
+
+INodePtr EventResolve::getResult() const
+{
+ return m_node;
+}
+
+void EventResolve::setResult(const INodePtr& node)
+{
+ m_node = node;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_EVENTRESOLVE_H_
+#define WRTDEVICEAPIS_FILESYSTEM_EVENTRESOLVE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INode.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class EventResolve : public Commons::IEvent<EventResolve>
+{
+ public:
+ /**
+ * Creates new event object.
+ * @param path Path to the node to resolve.
+ * @return New object.
+ */
+ explicit EventResolve(const IPathPtr& path);
+
+ /**
+ * Gets path of the node to resolve.
+ * @return Path to resolve.
+ */
+ IPathPtr getPath() const;
+
+ /**
+ * Gets resolved node.
+ * NULL if none found. Check exception code.
+ * @return Resolved node or NULL.
+ */
+ INodePtr getResult() const;
+
+ /**
+ * Sets resolved node.
+ * @param node Resolved node.
+ */
+ void setResult(const INodePtr& node);
+
+ private:
+ IPathPtr m_path; ///< Path to the requested node.
+ INodePtr m_node; ///< Resolved node.
+};
+
+typedef DPL::SharedPtr<EventResolve> EventResolvePtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_EVENTRESOLVE_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 <Filesystem/Manager.h>
+#include <Commons/ThreadPool.h>
+#include "IManager.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+IManager& IManager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+IManager::IManager() :
+ Commons::EventRequestReceiver<EventResolve>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD),
+ Commons::EventRequestReceiver<EventCopy>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD),
+ Commons::EventRequestReceiver<EventMove>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD),
+ Commons::EventRequestReceiver<EventRemove>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD),
+ Commons::EventRequestReceiver<EventFind>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD)
+{
+}
+
+IManager::~IManager()
+{
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_IMANAGER_H_
+#define WRTDEVICEAPIS_FILESYSTEM_IMANAGER_H_
+
+#include <vector>
+#include <string>
+#include <cstddef>
+#include <dpl/noncopyable.h>
+#include <Commons/EventReceiver.h>
+#include <Filesystem/EventResolve.h>
+#include <Filesystem/EventCopy.h>
+#include <Filesystem/EventMove.h>
+#include <Filesystem/EventRemove.h>
+#include <Filesystem/EventFind.h>
+#include <Filesystem/Enums.h>
+#include <Filesystem/INode.h>
+#include <Filesystem/IPath.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+typedef std::vector<IPathPtr> LocationPaths;
+typedef std::vector<LocationType> LocationTypes;
+
+class IManager :
+ public Commons::EventRequestReceiver<EventResolve>,
+ public Commons::EventRequestReceiver<EventCopy>,
+ public Commons::EventRequestReceiver<EventMove>,
+ public Commons::EventRequestReceiver<EventRemove>,
+ public Commons::EventRequestReceiver<EventFind>
+{
+ public:
+ static IManager& getInstance();
+
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets base path.
+ * @return Valid path or empty shared pointer.
+ */
+ virtual IPathPtr getBasePath() const = 0;
+
+ /**
+ * Gets path for specified location type.
+ * @param type Location type @see WrtDeviceApis::Api::Filesystem::LocationType.
+ * @return Valid path or empty shared pointer.
+ */
+ virtual IPathPtr getLocationPath(LocationType type) const = 0;
+
+ /**
+ * Gets paths to default locations.
+ * @return Paths to predefined virtual locations.
+ */
+ virtual LocationPaths getLocationPaths() const = 0;
+
+ /**
+ * Gets locations supported by platform.
+ * @return Supported locations.
+ */
+ virtual LocationTypes getLocations() const = 0;
+
+ /**
+ * Gets filesystem node.
+ * @param event Get node event @see Api::Filesystem::EventGetNode.
+ * @remarks Asynchronous.
+ */
+ virtual void getNode(const EventResolvePtr& event) = 0;
+
+ /**
+ * Gets maximum length of filesystem path.
+ * @return Maximum path length.
+ */
+ virtual std::size_t getMaxPathLength() const = 0;
+
+ /**
+ * Copies node to specified destination.
+ * @param event Copy node event @see Api::Filesystem::EventCopy.
+ * @remarks Asynchronous.
+ */
+ virtual void copy(const EventCopyPtr& event) = 0;
+
+ /**
+ * Moves node to specified destination.
+ * @param event Move node event @see Api::Filesystem::EventMove.
+ * @remarks Asynchronous.
+ */
+ virtual void move(const EventMovePtr& event) = 0;
+
+ /**
+ * Removes node.
+ * @param event Remove node event @see Api::Filesystem::EventRemove.
+ * @remarks Asynchronous.
+ */
+ virtual void remove(const EventRemovePtr& event) = 0;
+
+ /**
+ * Finds nodes.
+ * @param event Find nodes event @see Api::Filesystem::EventFind.
+ * @remarks Asynchronous.
+ */
+ virtual void find(const EventFindPtr& event) = 0;
+
+ /**
+ * Checks if node at specified path has supplied access rights.
+ * @param path Path to the node.
+ * @param accessType Access right(s) to check @see AccessType. Multiple values
+ * can be passed using OR operator.
+ * @return True if specified node has supplied access rights, false otherwise.
+ */
+ virtual bool access(const IPathPtr& path,
+ int accessType) const = 0;
+
+ virtual void addOpenedNode(const INodePtr& node) = 0;
+ virtual void removeOpenedNode(const INodePtr& node) = 0;
+ virtual bool checkIfOpened(const IPathPtr& path) const = 0;
+
+ protected:
+ IManager();
+
+ virtual void OnRequestReceived(const EventResolvePtr& event) = 0;
+ virtual void OnRequestReceived(const EventCopyPtr& event) = 0;
+ virtual void OnRequestReceived(const EventMovePtr& event) = 0;
+ virtual void OnRequestReceived(const EventRemovePtr& event) = 0;
+ virtual void OnRequestReceived(const EventFindPtr& event) = 0;
+}; // IManager
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_IMANAGER_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 "INode.h"
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+INode::INode() :
+ Commons::EventRequestReceiver<EventListNodes>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD),
+ Commons::EventRequestReceiver<EventOpen>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD),
+ Commons::EventRequestReceiver<EventReadText>(
+ Commons::ThreadEnum::FILESYSTEM_THREAD)
+{
+}
+
+INode::~INode()
+{
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_INODE_H_
+#define WRTDEVICEAPIS_FILESYSTEM_INODE_H_
+
+#include <string>
+#include <vector>
+#include <ctime>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/EventReceiver.h>
+#include "EventListNodes.h"
+#include "EventOpen.h"
+#include "EventReadText.h"
+#include "Enums.h"
+#include "IPath.h"
+#include "IStream.h"
+#include "INodeTypes.h"
+#include "NodeFilter.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class INode :
+ public Commons::EventRequestReceiver<EventListNodes>,
+ public Commons::EventRequestReceiver<EventOpen>,
+ public Commons::EventRequestReceiver<EventReadText>
+{
+ public:
+ typedef std::vector<std::string> NameList;
+ typedef NameList::iterator NodeListIterator;
+
+ public:
+ virtual ~INode() = 0;
+
+ /**
+ * Gets direct child of this node.
+ * @param path Path to the child node.
+ * @return Ptr to the child node.
+ * @remarks Ownership passed to the caller.
+ */
+ virtual INodePtr getChild(const IPathPtr& path) = 0;
+
+ /**
+ * Gets path of current node.
+ * @return Node's path.
+ */
+ virtual IPathPtr getPath() const = 0;
+
+ /**
+ * Gets type of current node.
+ * @return Node's type.
+ */
+ virtual NodeType getType() const = 0;
+
+ /**
+ * Gets permissions of the virtual node (not real filesystem node).
+ * @return Node's permissions.
+ */
+ virtual int getPermissions() const = 0;
+
+ /**
+ * Sets permissions on the virtual node (not real filesystem node).
+ * @param perms Node's permissions @see Api::Filesystem::Permissions.
+ */
+ virtual void setPermissions(int perms) = 0;
+
+ /**
+ * Gets list of names of direct child nodes.
+ * @return Names of child nodes.
+ */
+ virtual NameList getChildNames() const = 0;
+
+ /**
+ * Gets list of direct child nodes.
+ * @return Child nodes.
+ * @remarks Ownership passed to the caller.
+ * @deprecated
+ */
+ virtual NodeList getChildNodes(const NodeFilterPtr& filter =
+ NodeFilterPtr()) const /* WRT_PLUGINS_DEPRECATED */ = 0;
+
+ /**
+ * Gets list of direct descendant nodes.
+ * @param event Get child nodes event.
+ */
+ virtual void getChildNodes(const EventListNodesPtr& event) = 0;
+
+ /**
+ * Gets stream for this node.
+ * @param mode @see Api::Filesystem::AccessMode.
+ * @return Stream connected with current node.
+ * @deprecated Use async version of thi method instead.
+ */
+ virtual IStreamPtr open(int mode) = 0;
+
+ /**
+ * Gets stream for this node.
+ * @param mode @see Api::Filesystem::AccessMode.
+ * @return Stream connected with current node.
+ */
+ virtual void open(const EventOpenPtr& event) = 0;
+
+ /**
+ * Removes underlying filesystem node.
+ * @param options Removal options (by default removal is recursive).
+ * @remarks Synchronous.
+ * Valid options:
+ * - OPT_RECURSIVE - remove node recursively.
+ */
+ virtual void remove(int options = OPT_RECURSIVE) = 0;
+
+ /**
+ * Creates child of current node.
+ * @param path Path to the node to create.
+ * @param type Type of the node @see Api::Filesystem::NodeType.
+ * @param options Additional options see remarks (no options by default).
+ * @return Ptr to newly created node.
+ * @remarks
+ * Valid options:
+ * - OPT_RECURSIVE - attempt to create all necessary sub-directories
+ */
+ virtual INodePtr createChild(const IPathPtr& path,
+ NodeType type,
+ int options = OPT_NONE) = 0;
+
+ /**
+ * Gets size of this node.
+ * @return Size.
+ */
+ virtual std::size_t getSize() const = 0;
+
+ /**
+ * Gets creation date of this node.
+ * @return Date.
+ */
+ virtual std::time_t getCreated() const = 0;
+
+ /**
+ * Gets last modification date of this node.
+ * @return Date.
+ */
+ virtual std::time_t getModified() const = 0;
+
+ /**
+ * Gets parent of this node.
+ * @return Parent node or NULL if no parent (e.g. in case of a root node).
+ */
+ virtual INodePtr getParent() const = 0;
+
+ /**
+ * Gets platform permissions.
+ * @return Platform permissions (set of flags from @see Permissions enum).
+ */
+ virtual int getMode() const = 0;
+
+ /**
+ * Reads whole file as text.
+ * @param event Read file event.
+ */
+ virtual void read(const EventReadTextPtr& event) = 0;
+
+ virtual std::string toUri(int widgetId) const = 0;
+
+ protected:
+ INode();
+};
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_FILESYSTEM_INODE_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)
+ */
+
+#ifndef WRTDEVICEAPIS_FILESYSTEM_INODETYPES_H_
+#define WRTDEVICEAPIS_FILESYSTEM_INODETYPES_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class INode;
+
+typedef DPL::SharedPtr<INode> INodePtr;
+
+typedef std::vector<INodePtr> NodeList;
+typedef NodeList::iterator NodeListIterator;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_INODETYPES_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 <Filesystem/Path.h>
+#include "IPath.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+IPathPtr IPath::create(const std::string& str)
+{
+ return Path::create(str);
+}
+
+IPath::SeparatorType IPath::getSeparator()
+{
+ return Path::getSeparator();
+}
+
+IPath::~IPath()
+{
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_IPATH_H_
+#define WRTDEVICEAPIS_FILESYSTEM_IPATH_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api{
+
+class IPath;
+typedef DPL::SharedPtr<IPath> IPathPtr;
+
+class IPath
+{
+ public:
+ typedef char SeparatorType;
+
+ public:
+ /**
+ * Creates path object from specified string.
+ * @param str Path string.
+ * @return Path.
+ * @throw InvalidArgumentException If supplied string is not a valid path.
+ * @throw PlatformException If error in platform occurs.
+ * @remarks Ownership passed to the caller.
+ */
+ static IPathPtr create(const std::string& str);
+
+ /**
+ * Gets separator used by current platform.
+ * @return Path separator.
+ */
+ static SeparatorType getSeparator();
+
+ public:
+ virtual ~IPath() = 0;
+
+ /**
+ * Gets full path.
+ * @return Full path.
+ */
+ virtual std::string getFullPath() const = 0;
+
+ /**
+ * Gets base path (full path w/o name).
+ * @return Base path
+ */
+ virtual std::string getPath() const = 0;
+
+ /**
+ * Gets the last part of path.
+ * @return Path's name.
+ * @return Last part is typically name of a directory or file.
+ */
+ virtual std::string getName() const = 0;
+
+ /**
+ * Appends path specified as string to current path.
+ * @param path Path to append.
+ * @return Current path object.
+ */
+ virtual IPathPtr append(const std::string& path) = 0;
+
+ /**
+ * Appends path specified as path object to current path.
+ * @param path Path to append.
+ * @return Current path object.
+ */
+ virtual IPathPtr append(const IPathPtr& path) = 0;
+
+ /**
+ * Checks if path is abolute.
+ * @return True if absolute, false if relative.
+ */
+ virtual bool isAbsolute() const = 0;
+
+ /**
+ * Clones this object.
+ * @return Independent copy.
+ */
+ virtual IPathPtr clone() const = 0;
+};
+
+inline const IPathPtr operator+(const IPath& lhs,
+ const IPath& rhs)
+{
+ return IPath::create(lhs.getFullPath())->append(rhs.getFullPath());
+}
+
+inline const IPathPtr operator+(const IPath& lhs,
+ const std::string& rhs)
+{
+ return IPath::create(lhs.getFullPath())->append(rhs);
+}
+
+inline const IPathPtr operator+(const std::string& lhs,
+ const IPath& rhs)
+{
+ return IPath::create(lhs)->append(rhs.getFullPath());
+}
+
+inline bool operator==(const IPath& lhs, const IPath& rhs)
+{
+ return (lhs.getFullPath() == rhs.getFullPath());
+}
+
+inline bool operator==(const IPath& lhs, const std::string& rhs)
+{
+ return (lhs.getFullPath() == rhs);
+}
+
+inline bool operator==(const std::string& lhs, const IPath& rhs)
+{
+ return (lhs == rhs.getFullPath());
+}
+
+inline bool operator!=(const IPath& lhs, const IPath& rhs)
+{
+ return (lhs.getFullPath() != rhs.getFullPath());
+}
+
+inline bool operator!=(const IPath& lhs, const std::string& rhs)
+{
+ return (lhs.getFullPath() != rhs);
+}
+
+inline bool operator!=(const std::string& lhs, const IPath& rhs)
+{
+ return (lhs != rhs.getFullPath());
+}
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_IPATH_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 "IStream.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+IStream::~IStream()
+{
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_
+#define WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_
+
+#include <cstddef>
+#include <string>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+class IStream;
+typedef DPL::SharedPtr<IStream> IStreamPtr;
+
+class IStream : private DPL::Noncopyable
+{
+ public:
+ virtual ~IStream() = 0;
+
+ virtual IStreamPtr write(bool arg) = 0;
+ virtual IStreamPtr write(unsigned char arg) = 0;
+ virtual IStreamPtr write(char arg) = 0;
+ virtual IStreamPtr write(int arg) = 0;
+ virtual IStreamPtr write(double arg) = 0;
+ virtual IStreamPtr write(const std::string& arg) = 0;
+
+ virtual IStreamPtr read(bool& arg) = 0;
+ virtual IStreamPtr read(unsigned char& arg) = 0;
+ virtual IStreamPtr read(char& arg) = 0;
+ virtual IStreamPtr read(int& arg) = 0;
+ virtual IStreamPtr read(double& arg) = 0;
+ virtual IStreamPtr read(std::string& arg) = 0;
+
+ /**
+ * Gets characters from stream.
+ * @param num Number of characters to read.
+ * @return Pointer to read buffer.
+ * @throw PlatformException if stream is closed, EOF is set or write-only.
+ * @remarks Passes ownership to the caller.
+ */
+ virtual char* getChars(std::size_t num) = 0;
+
+ /**
+ * Gets bytes from stream.
+ * @param num Number of bytes to read.
+ * @return Pointer to read buffer.
+ * @remarks Passes ownership to the caller.
+ * @throw PlatformException if stream is closed, EOF is set or write-only.
+ */
+ virtual unsigned char* getBytes(std::size_t num) = 0;
+
+ /**
+ * Gets number of bytes read by last getBytes() or getChars() operation.
+ * @return Number of read bytes.
+ * @throw PlatformException if stream is closed or write-only.
+ */
+ virtual std::size_t getCount() const = 0;
+
+ /**
+ * Reads line of characters from stream (till '\n' character).
+ * @return Read line.
+ */
+ virtual std::string getLine() = 0;
+
+ /**
+ * Checks whether stream is open.
+ * @return True if stream is open, false otherwsie.
+ */
+ virtual bool isOpen() const = 0;
+
+ /**
+ * Checks whether End-Of-Line character occured.
+ * @return True if EOF flag was set, false otherwise.
+ */
+ virtual bool isEof() const = 0;
+
+ /**
+ * Closes stream.
+ */
+ virtual void close() = 0;
+
+ /**
+ * Gets current position in stream.
+ * @return Position or -1 if fails.
+ */
+ virtual long getPosition() const = 0;
+
+ /**
+ * Sets current position in stream.
+ * @param position Position to set.
+ */
+ virtual void setPosition(long position) = 0;
+
+ /**
+ * Gets mode stream was opened in.
+ * @return Mode @see Api::Filesystem::AccessMode.
+ */
+ virtual int getMode() const = 0;
+
+ /**
+ * Gets stream's size.
+ * @return Size or -1 if unavailable (e.g. stream is write-only).
+ */
+ virtual long getSize() const = 0;
+};
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_FILESYSTEM_ISTREAM_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 "NodeFilter.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+OptionalString NodeFilter::getName() const
+{
+ return m_name;
+}
+
+void NodeFilter::setName(const OptionalString& name)
+{
+ m_name = name;
+}
+
+OptionalDate NodeFilter::getMinCreated() const
+{
+ return m_created.min;
+}
+
+void NodeFilter::setMinCreated(const OptionalDate& date)
+{
+ m_created.min = date;
+}
+
+OptionalDate NodeFilter::getMaxCreated() const
+{
+ return m_created.max;
+}
+
+void NodeFilter::setMaxCreated(const OptionalDate& date)
+{
+ m_created.max = date;
+}
+
+void NodeFilter::setCreated(const OptionalDate& date)
+{
+ m_created.min = m_created.max = date;
+}
+
+OptionalDate NodeFilter::getMinModified() const
+{
+ return m_modified.min;
+}
+
+void NodeFilter::setMinModified(const OptionalDate& date)
+{
+ m_modified.min = date;
+}
+
+OptionalDate NodeFilter::getMaxModified() const
+{
+ return m_modified.max;
+}
+
+void NodeFilter::setMaxModified(const OptionalDate& date)
+{
+ m_modified.max = date;
+}
+
+void NodeFilter::setModified(const OptionalDate& date)
+{
+ m_modified.min = m_modified.max = date;
+}
+
+OptionalSize NodeFilter::getMinSize() const
+{
+ return m_size.min;
+}
+
+void NodeFilter::setMinSize(const OptionalSize& size)
+{
+ m_size.min = size;
+}
+
+OptionalSize NodeFilter::getMaxSize() const
+{
+ return m_size.max;
+}
+
+void NodeFilter::setMaxSize(const OptionalSize& size)
+{
+ m_size.max = size;
+}
+
+void NodeFilter::setSize(const OptionalSize& size)
+{
+ m_size.min = m_size.max = size;
+}
+
+} // API
+} // Filesystem
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_FILESYSTEM_NODEFILTER_H_
+#define WRTDEVICEAPIS_FILESYSTEM_NODEFILTER_H_
+
+#include <ctime>
+#include <cstddef>
+#include <string>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/Range.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+
+typedef DPL::Optional<std::string> OptionalString;
+typedef DPL::Optional<std::time_t> OptionalDate;
+typedef DPL::Optional<std::size_t> OptionalSize;
+
+class NodeFilter
+{
+ public:
+ OptionalString getName() const;
+ void setName(const OptionalString& name);
+
+ OptionalDate getMinCreated() const;
+ void setMinCreated(const OptionalDate& date);
+
+ OptionalDate getMaxCreated() const;
+ void setMaxCreated(const OptionalDate& date);
+
+ void setCreated(const OptionalDate& date);
+
+ OptionalDate getMinModified() const;
+ void setMinModified(const OptionalDate& date);
+
+ OptionalDate getMaxModified() const;
+ void setMaxModified(const OptionalDate& date);
+
+ void setModified(const OptionalDate& date);
+
+ OptionalSize getMinSize() const;
+ void setMinSize(const OptionalSize& size);
+
+ OptionalSize getMaxSize() const;
+ void setMaxSize(const OptionalSize& size);
+
+ void setSize(const OptionalSize& size);
+
+ private:
+ OptionalString m_name;
+ Commons::Range<OptionalDate> m_created;
+ Commons::Range<OptionalDate> m_modified;
+ Commons::Range<OptionalSize> m_size;
+};
+
+typedef DPL::SharedPtr<NodeFilter> NodeFilterPtr;
+
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_NODEFILTER_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 "PathUtils.h"
+#include <dpl/log/log.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+namespace PathUtils {
+
+PathList getParts(const IPathPtr& path)
+{
+ PathList result;
+ IPath::SeparatorType separator = path->getSeparator();
+ std::string fullPath = path->getFullPath();
+ std::string::size_type pos = 0;
+ while ((pos = fullPath.find(separator, pos + 1)) != std::string::npos) {
+ result.push_back(IPath::create(fullPath.substr(0, pos)));
+ }
+ return result;
+}
+
+} // PathUtils
+} // API
+} // Filesystem
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_FILESYSTEM_PATHUTILS_H_
+#define WRTDEVICEAPIS_FILESYSTEM_PATHUTILS_H_
+
+#include <vector>
+#include "IPath.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+namespace Api {
+namespace PathUtils {
+
+typedef std::vector<IPathPtr> PathList;
+typedef PathList::iterator PathListIterator;
+
+/**
+ * Gets sub-paths of supplied path.
+ * The supplied path is not included.
+ * @param path
+ * @return List of paths.
+ */
+PathList getParts(const IPathPtr& path);
+
+} // PathUtils
+} // API
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_PATHUTILS_H_
--- /dev/null
+get_current_path()
+
+set(API_FILESYSTEM_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_FILESYSTEM
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/IPath.cpp
+ ${CURRENT_PATH}/IStream.cpp
+ ${CURRENT_PATH}/EventResolve.cpp
+ ${CURRENT_PATH}/EventCopy.cpp
+ ${CURRENT_PATH}/EventMove.cpp
+ ${CURRENT_PATH}/EventRemove.cpp
+ ${CURRENT_PATH}/EventFind.cpp
+ ${CURRENT_PATH}/EventListNodes.cpp
+ ${CURRENT_PATH}/EventOpen.cpp
+ ${CURRENT_PATH}/EventReadText.cpp
+ ${CURRENT_PATH}/INode.cpp
+ ${CURRENT_PATH}/NodeFilter.cpp
+ ${CURRENT_PATH}/PathUtils.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 EventPlayBeep.h
+ * @author Hoseon LEE (hoseon46.lee@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_HAPTICS_EVENTPLAYBEEP_H_
+#define WRTDEVICEAPIS_HAPTICS_EVENTPLAYBEEP_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+class EventPlayBeep;
+
+typedef DPL::SharedPtr<EventPlayBeep> EventPlayBeepPtr;
+
+/*
+ *
+ */
+class EventPlayBeep : public Commons::IEvent<EventPlayBeep>
+{
+ public:
+ explicit EventPlayBeep(const long duration,
+ const int volume) :
+ m_duration(duration),
+ m_volume(volume)
+ {
+ }
+
+ long getDuration() const
+ {
+ return m_duration;
+ }
+
+ int getVolume() const
+ {
+ return m_volume;
+ }
+
+ private:
+ const long m_duration;
+ const int m_volume;
+};
+} // Api
+} // Haptics
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_HAPTICS_EVENTPLAYBEEP_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 EventStartMotor.h
+ * @author Hoseon LEE (hoseon46.lee@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_HAPTICS_EVENTSTARTVIBRATER_H_
+#define WRTDEVICEAPIS_HAPTICS_EVENTSTARTVIBRATER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "HapticPattern.h"
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+class EventStartMotor;
+
+typedef DPL::SharedPtr<EventStartMotor> EventStartMotorPtr;
+
+/*
+ *
+ */
+class EventStartMotor : public Commons::IEvent<EventStartMotor>
+{
+ public:
+ explicit EventStartMotor(const long duration,
+ const HapticPatternPtr& pattern) :
+ m_duration(duration),
+ m_pattern(pattern)
+ {
+ }
+
+ long getDuration() const
+ {
+ return m_duration;
+ }
+
+ const HapticPatternPtr getPatternRef() const
+ {
+ return m_pattern;
+ }
+
+ private:
+ const long m_duration;
+ const HapticPatternPtr m_pattern;
+};
+} // Apis
+} // Haptics
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_HAPTICS_EVENTSTARTVIBRATER_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 HapticPattern.cpp
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "HapticPattern.h"
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+void HapticPattern::addInterval(unsigned long duration,
+ bool vibrate)
+{
+ if (0 == duration) {
+ return;
+ }
+
+ // empty sequence
+ if (0 == m_sequence.size()) {
+ m_startsActive = vibrate;
+ m_sequence.push_back(duration);
+ return;
+ }
+
+ // check if last interval is action or pause
+ bool lastVibrates = m_startsActive ^ ((m_sequence.size() & 0x1) == 0);
+
+ if (lastVibrates == vibrate) {
+ *m_sequence.rbegin() += duration; // extend last interval
+ } else {
+ m_sequence.push_back(duration); // add new interval
+ }
+}
+
+bool HapticPattern::isActive(size_t interval) const
+{
+ if (interval >= m_sequence.size()) {
+ ThrowMsg(Commons::OutOfRangeException,
+ "Interval index is out of haptic sequence range");
+ }
+
+ return m_startsActive ^ ((interval & 0x1) != 0);
+}
+
+unsigned long HapticPattern::duration(size_t interval) const
+{
+ if (interval >= m_sequence.size()) {
+ return 0;
+ }
+
+ return m_sequence[interval];
+}
+} // Api
+} // Haptics
+} // 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 HapticPattern.h
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_HAPTIC_HAPTICPATTERN_H_
+#define WRTDEVICEAPIS_HAPTIC_HAPTICPATTERN_H_
+
+#include <vector>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+/*
+ *
+ */
+class HapticPattern : public DPL::Noncopyable
+{
+ public:
+ // adds another interval to the sequence
+ void addInterval(unsigned long duration,
+ bool active);
+
+ // sequence length
+ size_t length() const
+ {
+ return m_sequence.size();
+ }
+
+ // returns true if during given interval the haptic action is on
+ // throws Commons::OutOfRangeException
+ bool isActive(size_t interval) const;
+
+ // returns duration of given interval
+ unsigned long duration(size_t interval) const;
+
+ private:
+ // If true, the sequence starts with haptic action (not pause)
+ bool m_startsActive;
+
+ // A sequence of action/pause intervals
+ std::vector<unsigned long> m_sequence;
+};
+
+typedef DPL::SharedPtr<HapticPattern> HapticPatternPtr;
+} // Api
+} // Haptics
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_HAPTIC_HAPTICPATTERN_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 <Haptics/Manager.h>
+#include "IManager.h"
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+IManager& IManager::getInstance()
+{
+ return Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+} // Api
+} // Haptics
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_HAPTICS_IMANAGER_H_
+#define WRTDEVICEAPIS_HAPTICS_IMANAGER_H_
+
+#include <cstddef>
+#include <dpl/noncopyable.h>
+#include "IMotor.h"
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+class IManager : public DPL::Noncopyable
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets specified haptic motor.
+ * @param index Index of a motor to get (1-based).
+ * @return Haptic motor.
+ * @throw OutOfRangeException If index is greater than available motors.
+ * @throw UnsupportedException If current platform doesn't support it.
+ * @remarks On some platforms passing 0 as index may return motor object
+ * which represents all available motors as one.
+ */
+ virtual IMotor* getMotor(std::size_t index) const = 0;
+
+ /**
+ * Gets number of available haptic motors.
+ * @return Number of motors.
+ */
+ virtual std::size_t getMotorsCount() const = 0;
+};
+} // Api
+} // Haptics
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_HAPTICS_IMANAGER_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 "IMotor.h"
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+IMotor::~IMotor()
+{
+}
+} // Api
+} // Hpatics
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_HAPTICS_IMOTOR_H_
+#define WRTDEVICEAPIS_HAPTICS_IMOTOR_H_
+
+#include <dpl/shared_ptr.h>
+#include "HapticPattern.h"
+#include "EventStartMotor.h"
+#include "EventPlayBeep.h"
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+class IMotor
+{
+ public:
+ virtual ~IMotor() = 0;
+
+ /**
+ * Runs this haptic motor.
+ * Result of this operation might be different for different motor types,
+ * e.g. it may cause phone to vibrate.
+ * @param duration Number of miliseconds action should last.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void run(unsigned long duration) = 0;
+
+ /**
+ * Runs vibration pattern on this haptic motor.
+ * Result of this operation might be different for different motor types,
+ * e.g. it may cause phone to vibrate.
+ * @param pattern sequence of haptic actions.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void run(const HapticPatternPtr& pattern) = 0;
+
+ /**
+ * Runs vibration with event.
+ * Result of this operation might be different for different motor types,
+ * e.g. it may cause phone to vibrate.
+ * @param The event argument is event included duration & pattern.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void run(const EventStartMotorPtr& event) = 0;
+
+ /**
+ * Stops this haptic motor.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void stopMotor() = 0;
+
+ /**
+ * Cancel this haptic motor.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void stopVibration() = 0;
+
+ /**
+ run beep in motor
+ e.g. it may cause phone to beep.
+ @param volume
+ @duration duration Number of miliseconds action should last.
+ **/
+ virtual int playBeep(unsigned long duration,
+ int volume) = 0;
+
+ /**
+ run beep in motor
+ e.g. it may cause phone to beep.
+ @param event
+ **/
+ virtual void playBeep(const EventPlayBeepPtr& event) = 0;
+
+ /**
+ stop beep in motor
+ e.g. it may cause phone to stop beep.
+ **/
+ virtual void stopBeep() = 0;
+};
+
+typedef DPL::SharedPtr<IMotor> IMotorPtr;
+} // Api
+} // Haptics
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_HAPTICS_IMOTOR_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)
+ */
+
+#ifndef WRTDEVICEAPIS_HAPTICS_TYPES_H_
+#define WRTDEVICEAPIS_HAPTICS_TYPES_H_
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace Api {
+/**
+ * Type representing feedback level.
+ */
+typedef unsigned short Feedback;
+
+/**
+ * Value representing feedback turned off.
+ */
+const Feedback NO_FEEDBACK = 0;
+
+/**
+ * Value representing the lowest feedback level.
+ */
+const Feedback FEEDBACK_MIN = 1;
+
+/**
+ * Value representing the highest volume level.
+ */
+const Feedback FEEDBACK_MAX = 100;
+} // Api
+} // Haptics
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_HAPTICS_TYPES_H_
--- /dev/null
+get_current_path()
+
+set(API_HAPTICS_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+ )
+
+set(SRCS_API_HAPTICS
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/IMotor.cpp
+ ${CURRENT_PATH}/HapticPattern.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)
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Local storage interface file
+ */
+
+#ifndef WRTDEVICEAPIS_LOCALSTORAGE_LOCAL_STORAGE_INTERFACE_H_
+#define WRTDEVICEAPIS_LOCALSTORAGE_LOCAL_STORAGE_INTERFACE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <dpl/optional.h>
+
+namespace WrtDeviceApis {
+namespace LocalStorage {
+namespace Api {
+
+class ILocalStorage
+{
+ public:
+
+ /**
+ * Save pair key/value in local storage
+ * @param key
+ * @param value
+ * @param readOnly - if true, the value will be read only
+ * otherwise the value will be modificable
+ */
+ virtual void setItem(const std::string& key,
+ const std::string& value,
+ bool readOnly) = 0;
+
+ /**
+ * Remove pair key/value from local storage
+ */
+ virtual void removeItem(const std::string& key) = 0;
+
+ /**
+ * Get value for key
+ *
+ */
+ virtual DPL::Optional<std::string> getValue(
+ const std::string& key) const = 0;
+
+ /**
+ * Clears the local storage
+ * @param removeReadOnly - true -remove all elements
+ * false - ommit items which have read only flag set
+ */
+ virtual void clear(bool removeReadOnly) = 0;
+
+ /**
+ * Get number of elements in local storage
+ * @param removeReadOnly - true -remove all elements
+ * false - ommit items which have read only flag set
+ */
+ virtual size_t getStorageSize() const = 0;
+
+ /**
+ * Get value for key
+ */
+ virtual std::string getValueByIndex(size_t index) const = 0;
+
+ /**
+ * virtual destructor
+ */
+ virtual ~ILocalStorage()
+ {
+ }
+
+};
+
+typedef DPL::SharedPtr<ILocalStorage> ILocalStoragePtr;
+
+} // Api
+} // LocalStorage
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_LOCALSTORAGE_LOACA_STORAGE_INTERFACE_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 LocalStorageMgr.cpp
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "LocalStorageMgr.h"
+#include <WidgetInterfaceDAO/WidgetInterfaceDAO.h>
+
+namespace WrtDeviceApis {
+namespace LocalStorage {
+namespace Api {
+
+ILocalStoragePtr getLocalStorage(int widgetId)
+{
+ return ILocalStoragePtr(new WrtDeviceApis::WidgetInterfaceDAO(widgetId));
+}
+
+} // Api
+} // LocalStorage
+} // 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 LocalStorageMgr.h
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_LOCALSTORAGE_LOCAL_STORAGE_FACTORY_H
+#define WRTDEVICEAPIS_LOCALSTORAGE_LOCAL_STORAGE_FACTORY_H
+
+#include <LocalStorage/ILocalStorage.h>
+
+namespace WrtDeviceApis {
+namespace LocalStorage {
+namespace Api {
+
+ILocalStoragePtr getLocalStorage(int widgetId);
+
+} // Api
+} // LocalStorage
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_LOCALSTORAGE_LOCAL_STORAGE_FACTORY_H
+
--- /dev/null
+get_current_path()
+
+set(API_LOCALSTORAGE_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+ )
+
+set(SRCS_API_LOCALSTORAGE
+ ${CURRENT_PATH}/LocalStorageMgr.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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_GET_VOLUME_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_GET_VOLUME_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventGetVolume : public Commons::IEvent<EventGetVolume>
+{
+ private:
+ /**
+ * The volume is stored as a value in rage 0-10
+ */
+ int m_volume;
+
+ public:
+ /**
+ * Getters and setters
+ */
+ int getVolume() const
+ {
+ return m_volume;
+ }
+ void setVolume(int volume)
+ {
+ m_volume = volume;
+ }
+
+ EventGetVolume()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetVolume> EventGetVolumePtr;
+
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_GET_VOLUME_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_ISPLAYING_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_ISPLAYING_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <MMPlayer/IMMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventIsPlaying : public Commons::IEvent<EventIsPlaying>
+{
+ private:
+ IMMPlayerPtr m_player;
+ bool m_isPlaying;
+
+ public:
+ /**
+ * Getters and setters
+ */
+ IMMPlayerPtr getPlayer() const
+ {
+ return m_player;
+ }
+ void setIsPlaying(bool isPlaying)
+ {
+ m_isPlaying = isPlaying;
+ }
+ bool getIsPlaying() const
+ {
+ return m_isPlaying;
+ }
+
+ explicit EventIsPlaying(const IMMPlayerPtr &player) :
+ m_player(player),
+ m_isPlaying(false)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventIsPlaying> EventIsPlayingPtr;
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_ISPLAYING_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.
+ */
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_ON_STATE_CHANGE_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_ON_STATE_CHANGE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventOnStateChange : public Commons::ListenerEvent<EventOnStateChange>
+{
+ public:
+ typedef enum
+ {
+ BEGIN,
+ OPENED,
+ STOPPED,
+ PLAYING,
+ COMPLETED,
+ PAUSED,
+ RESUMED
+ } PlayerStates;
+ private:
+ PlayerStates m_playerState;
+
+ public:
+ EventOnStateChange() : m_playerState(BEGIN)
+ {
+ }
+ explicit EventOnStateChange(const PlayerStates state) : m_playerState(state)
+ {
+ }
+ virtual ~EventOnStateChange()
+ {
+ }
+
+ /**
+ * Getters and setters
+ */
+ void setPlayerState(const PlayerStates state)
+ {
+ m_playerState = state;
+ }
+ PlayerStates getPlayerState() const
+ {
+ return m_playerState;
+ }
+};
+
+typedef DPL::SharedPtr<EventOnStateChange> EventOnStateChangePtr;
+typedef Commons::ListenerEventEmitter<EventOnStateChange>
+ EventOnStateChangeEmitter;
+typedef DPL::SharedPtr<EventOnStateChangeEmitter> EventOnStateChangeEmitterPtr;
+} //MMPlayer
+} //Api
+} //WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_ON_STATE_CHANGE_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_OPEN_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_OPEN_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Commons/WrtWrapper/IWrtWrapper.h>
+#include <MMPlayer/IMMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventOpen : public Commons::IEvent<EventOpen>
+{
+ private:
+ IMMPlayerPtr m_player;
+ std::string m_filename;
+ Commons::IWrtWrapperPtr m_wrtWrapper;
+
+ public:
+ /**
+ * Getters
+ */
+ IMMPlayerPtr getPlayer() const
+ {
+ return m_player;
+ }
+ std::string getFilename() const
+ {
+ return m_filename;
+ }
+ Commons::IWrtWrapperPtr getWrtWrapper() const
+ {
+ return m_wrtWrapper;
+ }
+
+ EventOpen(const IMMPlayerPtr &player,
+ const std::string &filename,
+ const Commons::IWrtWrapperPtr &wrapper = Commons::IWrtWrapperPtr()) :
+ m_player(player),
+ m_filename(filename),
+ m_wrtWrapper(wrapper)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventOpen> EventOpenPtr;
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_OPEN_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_PAUSE_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_PAUSE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <MMPlayer/IMMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventPause : public Commons::IEvent<EventPause>
+{
+ private:
+ IMMPlayerPtr m_player;
+
+ public:
+ /**
+ * Getter
+ */
+ IMMPlayerPtr getPlayer() const
+ {
+ return m_player;
+ }
+
+ explicit EventPause(const IMMPlayerPtr &player) : m_player(player)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventPause> EventPausePtr;
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_PAUSE_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_PLAY_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_PLAY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <MMPlayer/IMMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventPlay : public Commons::IEvent<EventPlay>
+{
+ private:
+ IMMPlayerPtr m_player;
+ unsigned int m_repeatTimes;
+
+ public:
+ /**
+ * Getters
+ */
+ IMMPlayerPtr getPlayer() const
+ {
+ return m_player;
+ }
+ unsigned int getRepeatTimes() const
+ {
+ return m_repeatTimes;
+ }
+
+ explicit EventPlay(const IMMPlayerPtr &player,
+ unsigned int repeatTimes) :
+ m_player(player),
+ m_repeatTimes(repeatTimes)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventPlay> EventPlayPtr;
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_PLAY_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_RESUME_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_RESUME_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <MMPlayer/IMMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventResume : public Commons::IEvent<EventResume>
+{
+ private:
+ IMMPlayerPtr m_player;
+
+ public:
+ /**
+ * Getter
+ */
+ IMMPlayerPtr getPlayer() const
+ {
+ return m_player;
+ }
+
+ explicit EventResume(const IMMPlayerPtr &player) : m_player(player)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventResume> EventResumePtr;
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_RESUME_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_SET_WINDOW_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_SET_WINDOW_H_
+
+#include <dpl/shared_ptr.h>
+#include <MMPlayer/IMMPlayer.h>
+#include <Commons/IEvent.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventSetWindow : public Commons::IEvent<EventSetWindow>
+{
+ private:
+ IMMPlayerPtr m_player;
+ int m_posX;
+ int m_posY;
+ int m_width;
+ int m_height;
+
+ public:
+ /**
+ * Getter
+ */
+ IMMPlayerPtr getPlayer() const
+ {
+ return m_player;
+ }
+
+ EventSetWindow(const IMMPlayerPtr &player,
+ int posX,
+ int posY,
+ int width,
+ int height) :
+ m_player(player),
+ m_posX(posX),
+ m_posY(posY),
+ m_width(width),
+ m_height(height)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventSetWindow> EventSetWindowPtr;
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_SET_WINDOW_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 Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_MMPLAYER_EVENT_STOP_H_
+#define WRTDEVICEAPIS_MMPLAYER_EVENT_STOP_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <MMPlayer/IMMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class EventStop : public Commons::IEvent<EventStop>
+{
+ private:
+ IMMPlayerPtr m_player;
+
+ public:
+ /**
+ * Getter
+ */
+ IMMPlayerPtr getPlayer() const
+ {
+ return m_player;
+ }
+
+ explicit EventStop(const IMMPlayerPtr &player) : m_player(player)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventStop> EventStopPtr;
+} // MMPlayer
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_MMPLAYER_EVENT_STOP_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.
+ */
+#ifndef WRTDEVICEAPIS_MMPLAYER_IMMPlayer_H_
+#define WRTDEVICEAPIS_MMPLAYER_IMMPlayer_H_
+
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <MMPlayer/EventOnStateChange.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class IMMPlayer : DPL::Noncopyable
+{
+ public:
+ virtual ~IMMPlayer()
+ {
+ }
+
+ /**
+ * Sets on player state change event emitter.
+ * @param emitter On player state change event emitter.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void setEmitter(const EventOnStateChangeEmitterPtr& emitter) = 0;
+
+ /**
+ * Gets on player state change event emitter.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual EventOnStateChangeEmitterPtr getEmitter() = 0;
+
+ /**
+ * Removes on state change event emitter.
+ */
+ virtual void clearEmitter() = 0;
+
+ /**
+ * Gets how many times opened file will be played since now
+ */
+ virtual unsigned int getRepeatTimes() const = 0;
+
+ /**
+ * Sets how many times opened file should be played
+ */
+ virtual void setRepeatTimes(unsigned int count) = 0;
+
+ protected:
+ IMMPlayer()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IMMPlayer> IMMPlayerPtr;
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_MMPLAYER_IMMPlayer_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 "IManager.h"
+#include <MMPlayer/Manager.h>
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+using namespace Commons;
+
+IManager& IManager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+IManager::IManager() :
+ EventRequestReceiver<EventOpen>(ThreadEnum::MMPLAYER_THREAD),
+ EventRequestReceiver<EventPlay>(ThreadEnum::MMPLAYER_THREAD),
+ EventRequestReceiver<EventPause>(ThreadEnum::MMPLAYER_THREAD),
+ EventRequestReceiver<EventResume>(ThreadEnum::MMPLAYER_THREAD),
+ EventRequestReceiver<EventStop>(ThreadEnum::MMPLAYER_THREAD),
+ EventRequestReceiver<EventIsPlaying>(ThreadEnum::MMPLAYER_THREAD),
+ EventRequestReceiver<EventSetWindow>(ThreadEnum::MMPLAYER_THREAD),
+ EventRequestReceiver<EventGetVolume>(ThreadEnum::MMPLAYER_THREAD)
+{
+}
+
+IManager::~IManager()
+{
+}
+
+}
+}
+}
--- /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_MMPLAYER_IMANAGER_H_
+#define WRTDEVICEAPIS_MMPLAYER_IMANAGER_H_
+
+#include <dpl/noncopyable.h>
+#include <MMPlayer/EventOpen.h>
+#include <MMPlayer/EventPlay.h>
+#include <MMPlayer/EventPause.h>
+#include <MMPlayer/EventResume.h>
+#include <MMPlayer/EventStop.h>
+#include <MMPlayer/EventIsPlaying.h>
+#include <MMPlayer/EventSetWindow.h>
+#include <MMPlayer/EventGetVolume.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class IManager :
+ public Commons::EventRequestReceiver<EventOpen>,
+ public Commons::EventRequestReceiver<EventPlay>,
+ public Commons::EventRequestReceiver<EventPause>,
+ public Commons::EventRequestReceiver<EventResume>,
+ public Commons::EventRequestReceiver<EventStop>,
+ public Commons::EventRequestReceiver<EventIsPlaying>,
+ public Commons::EventRequestReceiver<EventSetWindow>,
+ public Commons::EventRequestReceiver<EventGetVolume>
+{
+ public:
+ static IManager &getInstance();
+ virtual ~IManager();
+
+ /**
+ * Opens a file
+ * @param event @see WrtDeviceApis::Api::MMPlayer::EventOpen.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void openFile(const EventOpenPtr& event) = 0;
+ /**
+ * Plays current file. If file is already playing player starts from the beginning
+ * @param event @see WrtDeviceApis::Api::MMPlayer::EventPlay.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void play(const EventPlayPtr& event) = 0;
+ /**
+ * Pauses current playing file. If no file is currently playing noting happens
+ * @param event @see WrtDeviceApis::Api::MMPlayer::EventPause.
+ * @exception Commons::PlatformException when platform error occurs
+ * @exception Commons::InvalidArgumentException when fileName is empty
+ */
+ virtual void pause(const EventPausePtr& event) = 0;
+ /**
+ * Resumes after pause. If file is not paused nothing happens
+ * @param event @see WrtDeviceApis::Api::MMPlayer::EventResume.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void resume(const EventResumePtr& event) = 0;
+ /**
+ * Stops current playing file. If file is not playing nothing happens
+ * @param event @see WrtDeviceApis::Api::MMPlayer::EventStop.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void stop(const EventStopPtr& event) = 0;
+ /**
+ * Sets window for video files
+ * @param event @see WrtDeviceApis::Api::MMPlayer::EventSetWindow.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void setWindow(const EventSetWindowPtr& event) = 0;
+ /**
+ * Returns current playing state
+ * @param event @see WrtDeviceApis::Api::MMPlayer::EventIsPlaying.
+ * @return True if player is in playing state
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void isPlaying(const EventIsPlayingPtr& event) = 0;
+ /**
+ * Returns current playing state
+ * @param [out] event @see WrtDeviceApis::Api::MMPlayer::EventIsPlaying.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void getVolume(const EventGetVolumePtr& event) = 0;
+
+ protected:
+ IManager();
+
+ virtual void OnRequestReceived(const EventOpenPtr& event) = 0;
+ virtual void OnRequestReceived(const EventPlayPtr& event) = 0;
+ virtual void OnRequestReceived(const EventPausePtr& event) = 0;
+ virtual void OnRequestReceived(const EventResumePtr& event) = 0;
+ virtual void OnRequestReceived(const EventStopPtr& event) = 0;
+ virtual void OnRequestReceived(const EventIsPlayingPtr& event) = 0;
+ virtual void OnRequestReceived(const EventSetWindowPtr& event) = 0;
+ virtual void OnRequestReceived(const EventGetVolumePtr& event) = 0;
+};
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_MMPLAYER_IMANAGER_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 "MMPlayerFactory.h"
+#include "IMMPlayer.h"
+#include <MMPlayer/MMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+IMMPlayerPtr MMPlayerFactory::getNewPlayer()
+{
+ return IMMPlayerPtr(new MMPlayer());
+}
+
+MMPlayerFactory& MMPlayerFactory::getInstance()
+{
+ static MMPlayerFactory theInstance;
+ return theInstance;
+}
+
+MMPlayerFactory::MMPlayerFactory()
+{
+}
+
+}
+}
+}
--- /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_MMPLAYER_MMPLAYERFACTORY_H_
+#define WRTDEVICEAPIS_MMPLAYER_MMPLAYERFACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include <MMPlayer/IMMPlayer.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+namespace Api {
+
+class MMPlayerFactory : DPL::Noncopyable
+{
+ public:
+ IMMPlayerPtr getNewPlayer();
+ static MMPlayerFactory& getInstance();
+
+ protected:
+ MMPlayerFactory();
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_MMPLAYER_MMPLAYERFACTORY_H_
--- /dev/null
+get_current_path()
+
+set(API_MMPLAYER_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_MMPLAYER
+ ${CURRENT_PATH}/MMPlayerFactory.cpp
+ ${CURRENT_PATH}/IManager.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 AttachmentFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Messaging/Attachment.h>
+#include "AttachmentFactory.h"
+#include "Attachments.h"
+#include <Messaging/Attachment.h>
+
+using namespace WrtDeviceApis::Commons;
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+
+IAttachmentPtr AttachmentFactory::createAttachment(const std::string& fullPath,
+ bool isVirtualPath)
+{
+ LogDebug("enter");
+ IAttachmentPtr attachment(new Attachment(fullPath, isVirtualPath));
+ if (!attachment->getIsCreatedProperly()) {
+ ThrowMsg(Commons::InvalidArgumentException,
+ "Attachment couldn't be created");
+ }
+ return attachment;
+}
+
+}
+}
+}
--- /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 AttachmentFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef ATTACHMENTFACTORY_H
+#define ATTACHMENTFACTORY_H
+
+#include <string>
+#include "IAttachment.h"
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+//--------------------------------------------------------------------------
+
+class AttachmentFactory
+{
+ public:
+
+ /**
+ * Generate attachment object
+ * @param[in] fullPath path to file
+ * @param[in] isVirtualPath false when path is real file system path, true when it's path on file system exposed to user
+ */
+ static IAttachmentPtr createAttachment(const std::string& fullPath,
+ bool isVirtualPath);
+};
+
+}
+}
+}
+
+#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 IAttachment.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "Attachments.h"
+#include "AttachmentFactory.h"
+
+extern "C" {
+#include <sys/stat.h>
+#include <stdlib.h>
+}
+
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+//--------------------------------------------------------------------------
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+
+Attachments::Attachments() :
+ m_validAttachments(false)
+{
+ LogDebug("enter");
+}
+
+Attachments::~Attachments()
+{
+ LogDebug("enter");
+}
+
+IAttachmentPtr Attachments::appendAttachment(const std::string& fullPath,
+ bool isVirtualPath)
+{
+ LogDebug("enter, fullPath=" << fullPath);
+ IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+ fullPath,
+ isVirtualPath);
+ m_validAttachments = false;
+ m_attachments.push_back(tmpAttach);
+ return tmpAttach;
+}
+
+void Attachments::appendAttachment(const IAttachmentPtr& attachment)
+{
+ LogDebug("enter");
+ m_validAttachments = false;
+ m_attachments.push_back(attachment);
+}
+
+void Attachments::appendAttachments(const vector<IAttachmentPtr>& attachments)
+{
+ LogDebug("enter");
+ back_insert_iterator< vector<IAttachmentPtr> >biit(m_attachments);
+ copy(attachments.begin(), attachments.end(), biit);
+}
+
+size_t Attachments::getAttachmentsCount() const
+{
+ LogDebug("enter");
+ return m_attachments.size();
+}
+
+IAttachmentPtr Attachments::getAttachment(const size_t index) const
+{
+ LogDebug("enter");
+ if (index >= m_attachments.size()) {
+ ThrowMsg(OutOfRangeException, "Trying to get attachment out of range");
+ }
+ return m_attachments[index];
+}
+
+void Attachments::removeAttachment(const size_t index)
+{
+ LogDebug("enter");
+ if (index >= m_attachments.size()) {
+ ThrowMsg(OutOfRangeException, "Trying to get attachment out of range");
+ }
+ m_validAttachments = false;
+ m_attachments.erase(m_attachments.begin() + index);
+}
+
+void Attachments::removeAttachment(const IAttachmentPtr& attachment)
+{
+ m_attachments.erase(
+ remove(m_attachments.begin(), m_attachments.end(), attachment),
+ m_attachments.end());
+}
+
+vector<IAttachmentPtr> Attachments::getAttachments() const
+{
+ LogDebug("enter");
+ return m_attachments;
+}
+
+vector<string> Attachments::getAttachmentsFullPaths() const
+{
+ vector<string> retVal;
+
+ for (size_t i = 0; i < m_attachments.size(); i++) {
+ retVal.push_back(m_attachments[i]->getFullPath());
+ }
+ return retVal;
+}
+
+vector<string> Attachments::getAttachmentsShortNames() const
+{
+ vector<string> retVal;
+
+ for (size_t i = 0; i < m_attachments.size(); i++) {
+ retVal.push_back(m_attachments[i]->getShortName());
+ }
+ return retVal;
+}
+
+void Attachments::setAttachments(const vector<string>& attachments,
+ bool isVirtualPath)
+{
+ vector<string>::const_iterator it = attachments.begin();
+
+ m_attachments.clear();
+ while (it != attachments.end()) {
+ appendAttachment(*it, isVirtualPath);
+ ++it;
+ }
+}
+
+void Attachments::setAttachments(const vector<IAttachmentPtr>& attachments)
+{
+ m_attachments = attachments;
+ m_validAttachments = false;
+}
+
+bool Attachments::isAttachmentsValid() const
+{
+ return m_validAttachments;
+}
+
+void Attachments::setAttachmentsValidity(bool state)
+{
+ m_validAttachments = state;
+}
+
+const vector<IAttachmentPtr>& Attachments::getAttachmentsRef() const
+{
+ return m_attachments;
+}
+
+void Attachments::saveAttachment(const string& /*destFileName*/,
+ const IAttachmentPtr& /*attachment*/)
+{
+ // possible move it as a virtual function - to be clarified
+ LogError("N/A");
+ //TODO
+}
+
+void Attachments::setAttachmentWithExpand(const size_t index,
+ const std::string& fullPath,
+ bool isVirtualPath)
+{
+ // expand if needed
+ if (index >= m_attachments.size()) {
+ m_attachments.resize(index + 1); // resize with empty ptr
+ }
+ IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+ fullPath,
+ isVirtualPath);
+ m_attachments[index] = tmpAttach;
+ m_validAttachments = false;
+}
+
+void Attachments::reverse()
+{
+ std::reverse(m_attachments.begin(), m_attachments.end());
+}
+
+void Attachments::insertAttachment(const size_t index,
+ const std::string& fullPath,
+ bool isVirtualPath)
+{
+ IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+ fullPath,
+ isVirtualPath);
+ m_attachments.insert(m_attachments.begin() + index, tmpAttach);
+ m_validAttachments = false;
+}
+
+void Attachments::insertAttachmentWithExpand(const size_t index,
+ const std::string& fullPath,
+ bool isVirtualPath)
+{
+ // expand if needed
+ if (index >= m_attachments.size()) {
+ m_attachments.resize(index); // resize with empty ptr
+ }
+ IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+ fullPath,
+ isVirtualPath);
+ m_attachments.insert(m_attachments.begin() + index, tmpAttach);
+ m_validAttachments = false;
+}
+
+}
+}
+}
+
--- /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 Attachments.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef ATTACHMENTS_H
+#define ATTACHMENTS_H
+
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "IMessagingTypes.h"
+#include "IAttachment.h"
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+//--------------------------------------------------------------------------
+
+class Attachments
+{
+ std::vector<IAttachmentPtr> m_attachments;
+
+ public: // fields
+
+ private:
+
+ bool m_validAttachments;
+
+ public: // methods
+
+ Attachments();
+
+ virtual ~Attachments();
+
+ /**
+ * method for append attachment into list
+ * @param[in] fullPath - path for attachment
+ * @return AttachmentPtr - if file exist create attachment object
+ * it is possible to modify name, etc.
+ * @throw InvalidArgumentException - if file not exist
+ */
+ IAttachmentPtr appendAttachment(const std::string& fullPath,
+ bool isVirtualPath);
+
+ /**
+ * method for append attachment into list
+ * @param[in] attachment - attachment to be added
+ */
+ void appendAttachment(const IAttachmentPtr& attachment);
+
+ /**
+ * method for append attachments list
+ * @param[in] attachments - attachment list
+ */
+ void appendAttachments(const std::vector<IAttachmentPtr>& attachments);
+
+ /**
+ * get attachment count
+ * @return attachment count
+ */
+ size_t getAttachmentsCount() const;
+
+ /**
+ * get attachment object at index
+ * @param[in] index - index of attachment to get
+ * @return attachment object
+ * @throw OutOfRangeException if index is out of range
+ */
+ IAttachmentPtr getAttachment(const size_t index) const;
+
+ /**
+ * remove attachment at the index
+ * @param[in] index - index of attachment to get
+ * @return void
+ * @throw OutOfRangeException if index is out of range
+ */
+ void removeAttachment(const size_t index);
+
+ /**
+ * remove attachment at the index
+ * @param[in] attachment - AttachmentPtr object
+ * @return void
+ * @throw OutOfRangeException if index is out of range
+ */
+ void removeAttachment(const IAttachmentPtr& attachment);
+
+ /**
+ * get all attachments vector
+ * @return attachment vector
+ */
+ std::vector<IAttachmentPtr> getAttachments() const;
+
+ /**
+ * get all attachments full path vector
+ * @return attachment path vector
+ */
+ std::vector<std::string> getAttachmentsFullPaths() const;
+
+ /**
+ * get all attachments names vector
+ * @return attachment names vector
+ */
+ std::vector<std::string> getAttachmentsShortNames() const;
+
+ /**
+ * get all attachments vector reference
+ * @return attachment vector
+ */
+ const std::vector<IAttachmentPtr>& getAttachmentsRef() const;
+
+ /**
+ * set attachments
+ * @param[in] attachments - vector of and attachments full path
+ * @throw InvalidArgumentException - if file not exist
+ */
+ void setAttachments(const std::vector<std::string>& attachments,
+ bool isVirtualPath);
+
+ /**
+ * set attachmentsPtr
+ * @param[in] attachments - vector of AttachmentPtr
+ */
+ void setAttachments(const std::vector<IAttachmentPtr>& attachments);
+
+ /**
+ * check if attachments are modified and need update in platform
+ * @return bool
+ */
+ bool isAttachmentsValid() const;
+
+ /**
+ * setting validity after update
+ * @param[in] state - state for validity to set
+ */
+ void setAttachmentsValidity(bool state);
+
+ /**
+ * saving attachment file to selected destination file
+ * @param[in] destFileName - destination file to save attachment
+ * @param[in] attachment - attachment to be saved
+ */
+ void saveAttachment(const std::string& destFileName,
+ const IAttachmentPtr& attachment);
+
+ /**
+ * sets attachment at given position and expands array if needed
+ * @param[in] index - position
+ * @param[in] fullPath - path for attachment
+ * @throw InvalidArgumentException - if file not exist
+ */
+ void setAttachmentWithExpand(const size_t index,
+ const std::string& fullPath,
+ bool isVirtualPath);
+
+ /**
+ * The reverse() method reverses the order of the elements in an array
+ * (makes the last element first, and the first element last).
+ */
+ void reverse();
+
+ /**
+ * Creates new attachment and inserts it at given position
+ * @param[in] index position
+ * @param[in] fullPath - path for attachment
+ * @param[in] isVirtualPath - true if path is virtual
+ * @throw InvalidArgumentException - if file not exist
+ */
+ void insertAttachment(const size_t index,
+ const std::string& fullPath,
+ bool isVirtualPath);
+
+ /**
+ * Creates new attachment and inserts it at given position and expands array if needed
+ * @param[in] index position
+ * @param[in] fullPath - path for attachment
+ * @param[in] isVirtualPath - true if path is virtual
+ * @throw InvalidArgumentException - if file not exist
+ */
+ void insertAttachmentWithExpand(const size_t index,
+ const std::string& fullPath,
+ bool isVirtualPath);
+};
+
+typedef DPL::SharedPtr<Attachments> AttachmentsPtr;
+
+}
+}
+}
+
+#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 BccRecipient.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "BccRecipient.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+
+BccRecipient::BccRecipient() :
+ m_bccRecipients(new Recipients())
+{
+}
+
+BccRecipient::~BccRecipient()
+{
+}
+
+void BccRecipient::setBccValidity(bool state)
+{
+ m_bccRecipients->setValid(state);
+}
+
+bool BccRecipient::getBccValidity() const
+{
+ return m_bccRecipients->isValid();
+}
+
+Recipients BccRecipient::getBccRecipients() const
+{
+ return *m_bccRecipients;
+}
+
+void BccRecipient::setBccRecipients(const Recipients& value)
+{
+ *m_bccRecipients = value;
+}
+
+void BccRecipient::appendBccRecipients(const std::string & value)
+{
+ m_bccRecipients->appendRecipient(value);
+}
+
+void BccRecipient::appendBccRecipients(const Recipients& value)
+{
+ *m_bccRecipients += value;
+}
+
+void BccRecipient::removeBccRecipients(const Recipients& value)
+{
+ *m_bccRecipients -= value;
+}
+
+RecipientsPtr BccRecipient::getBccRecipientsPtr() const
+{
+ return m_bccRecipients;
+}
+
+}
+}
+}
--- /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 BccRecipient.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef BCCRECIPIENT_H
+#define BCCRECIPIENT_H
+
+#include <string>
+#include "Recipient.h"
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+
+class BccRecipient
+{
+ private: // fields
+
+ RecipientsPtr m_bccRecipients;
+
+ public:
+
+ BccRecipient();
+
+ virtual ~BccRecipient();
+
+ void setBccValidity(bool state);
+
+ bool getBccValidity() const;
+
+ Recipients getBccRecipients() const;
+
+ RecipientsPtr getBccRecipientsPtr() const;
+
+ void appendBccRecipients(const std::string & value);
+
+ void appendBccRecipients(const Recipients& value);
+
+ void removeBccRecipients(const Recipients& value);
+
+ void setBccRecipients(const Recipients& value);
+};
+
+}
+}
+}
+
+#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 Body.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "Body.h"
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+
+Body::Body() :
+ m_body(""),
+ m_validBody(false)
+{
+}
+
+Body::~Body()
+{
+}
+
+void Body::setBody(const std::string& value)
+{
+ m_body = value;
+ m_validBody = false;
+}
+
+std::string Body::getBody() const
+{
+ return m_body;
+}
+
+const std::string& Body::getBodyRef() const
+{
+ return m_body;
+}
+
+bool Body::isBodyValid() const
+{
+ return m_validBody;
+}
+
+void Body::setBodyValidity(bool state)
+{
+ m_validBody = state;
+}
+
+}
+}
+}
--- /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 Body.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef BODY_H
+#define BODY_H
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+//--------------------------------------------------------------------------
+
+class Body
+{
+ private: // fields
+
+ /**
+ * body value
+ */
+ std::string m_body;
+
+ /**
+ * information if abstract message body has been changed and need update
+ * in low level
+ */
+ bool m_validBody;
+
+ public: // methods
+
+ Body();
+
+ virtual ~Body();
+
+ /**
+ * setter of body value
+ */
+ void setBody(const std::string& value);
+
+ /**
+ * getter of body value
+ */
+ std::string getBody() const;
+
+ /**
+ * getter of body value
+ */
+ const std::string& getBodyRef() const;
+
+ /**
+ * check body validity
+ * */
+ bool isBodyValid() const;
+
+ /**
+ * set body validity
+ * */
+ void setBodyValidity(bool state);
+};
+
+}
+}
+}
+
+#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 CallbackNumber.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <dpl/log/log.h>
+#include "CallbackNumber.h"
+#include "CallbackNumber.h"
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+
+CallbackNumber::CallbackNumber() :
+ m_callbackNumber(""),
+ m_validCallbackNumber(false)
+{
+}
+
+CallbackNumber::~CallbackNumber()
+{
+}
+
+void CallbackNumber::setCallbackNumber(const std::string& value)
+{
+ LogDebug("set callbackNumber=" << value);
+ m_callbackNumber = value;
+ m_validCallbackNumber = false;
+}
+
+std::string CallbackNumber::getCallbackNumber() const
+{
+ return m_callbackNumber;
+}
+
+const std::string& CallbackNumber::getCallbackNumberRef() const
+{
+ return m_callbackNumber;
+}
+
+bool CallbackNumber::isCallbackNumberValid() const
+{
+ return m_validCallbackNumber;
+}
+
+void CallbackNumber::setCallbackNumberValidity(bool state)
+{
+ m_validCallbackNumber = state;
+}
+}
+}
+}
--- /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 CallbackNumber.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef CALLBACKNUMBER_H
+#define CALLBACKNUMBER_H
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+//--------------------------------------------------------------------------
+
+class CallbackNumber
+{
+ private: // fields
+
+ /**
+ * CallbackNumber value
+ */
+ std::string m_callbackNumber;
+
+ /**
+ * information if abstract message body has been changed and need update
+ * in low level
+ */
+ bool m_validCallbackNumber;
+
+ public: // methods
+
+ CallbackNumber();
+
+ virtual ~CallbackNumber();
+
+ /**
+ * setter of CallbackNumber value
+ */
+ void setCallbackNumber(const std::string& value);
+
+ /**
+ * getter of CallbackNumber value
+ */
+ std::string getCallbackNumber() const;
+
+ /**
+ * getter of CallbackNumber value
+ */
+ const std::string& getCallbackNumberRef() const;
+
+ /**
+ * check CallbackNumber validity
+ * */
+ bool isCallbackNumberValid() const;
+
+ /**
+ * set CallbackNumber validity
+ * */
+ void setCallbackNumberValidity(bool state);
+};
+}
+}
+}
+#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 CcRecipient.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "CcRecipient.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+CcRecipient::CcRecipient() :
+ m_ccRecipients(new Recipients())
+{
+}
+
+CcRecipient::~CcRecipient()
+{
+}
+
+void CcRecipient::setCcValidity(bool state)
+{
+ m_ccRecipients->setValid(state);
+}
+
+bool CcRecipient::getCcValidity(void) const
+{
+ return m_ccRecipients->isValid();
+}
+
+Recipients CcRecipient::getCcRecipients() const
+{
+ return *m_ccRecipients;
+}
+
+RecipientsPtr CcRecipient::getCcRecipientsPtr() const
+{
+ return m_ccRecipients;
+}
+
+void CcRecipient::appendCcRecipients(const std::string & value)
+{
+ m_ccRecipients->appendRecipient(value);
+}
+
+void CcRecipient::appendCcRecipients(const Recipients& value)
+{
+ *m_ccRecipients += value;
+}
+
+void CcRecipient::removeCcRecipients(const Recipients& value)
+{
+ *m_ccRecipients -= value;
+}
+
+void CcRecipient::setCcRecipients(const Recipients& value)
+{
+ *m_ccRecipients = value;
+}
+
+}
+}
+}
--- /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 CcRecipient.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef CCRECIPIENT_H
+#define CCRECIPIENT_H
+
+#include <string>
+#include "Recipient.h"
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+//--------------------------------------------------------------------------
+
+class CcRecipient
+{
+ private: // fields
+
+ RecipientsPtr m_ccRecipients;
+
+ public:
+
+ CcRecipient();
+
+ virtual ~CcRecipient();
+
+ void setCcValidity(bool state);
+
+ bool getCcValidity(void) const;
+
+ Recipients getCcRecipients() const;
+
+ RecipientsPtr getCcRecipientsPtr() const;
+
+ void appendCcRecipients(const std::string & value);
+
+ void appendCcRecipients(const Recipients& value);
+
+ void removeCcRecipients(const Recipients& value);
+
+ void setCcRecipients(const Recipients& value);
+};
+}
+}
+}
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+#include <sstream>
+#include <Commons/Exception.h>
+#include "EmailAccountInfo.h"
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+EmailAccountInfo::EmailAccountInfo(int id,
+ const std::string& name,
+ const std::string& address) :
+ m_name(name),
+ m_address(address)
+{
+ std::stringstream stream;
+ stream << id;
+ if (stream.fail()) {
+ ThrowMsg(Commons::UnknownException,
+ "Couldn't convert e-mail account id");
+ }
+ m_id = stream.str();
+}
+
+EmailAccountInfo::EmailAccountInfo(const std::string& id,
+ const std::string& name,
+ const std::string& address) :
+ m_id(id),
+ m_name(name),
+ m_address(address)
+{
+}
+
+int EmailAccountInfo::getIntId() const
+{
+ int result = 0;
+ std::stringstream stream(m_id);
+ stream >> result;
+ if (stream.fail()) {
+ ThrowMsg(Commons::UnknownException,
+ "Couldn't convert e-mail account id");
+ }
+ return result;
+}
+
+std::string EmailAccountInfo::getId() const
+{
+ return m_id;
+}
+
+std::string EmailAccountInfo::getName() const
+{
+ return m_name;
+}
+
+std::string EmailAccountInfo::getAddress() const
+{
+ return m_address;
+}
+
+bool EmailAccountInfo::operator==(const EmailAccountInfo& account) const
+{
+ return (m_id == account.m_id &&
+ m_name == account.m_name &&
+ m_address == account.m_address);
+}
+}}
+}
--- /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_MESSAGING_EMAILACCOUNTINFO_H_
+#define WRTDEVICEAPIS_MESSAGING_EMAILACCOUNTINFO_H_
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging{
+namespace Api {
+class EmailAccountInfo
+{
+ public:
+ EmailAccountInfo(int id,
+ const std::string& name,
+ const std::string& address);
+
+ EmailAccountInfo(const std::string& id,
+ const std::string& name,
+ const std::string& address);
+
+ int getIntId() const;
+
+ std::string getId() const;
+
+ std::string getName() const;
+
+ std::string getAddress() const;
+
+ bool operator==(const EmailAccountInfo& account) const;
+
+ private:
+ std::string m_id;
+ std::string m_name;
+ std::string m_address;
+};
+}
+}
+}
+#endif // WRTDEVICEAPIS_MESSAGING_EMAILACCOUNTINFO_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 "EmitterMessageReceived.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+MessageFilterPtr EmitterMessageReceived::getFilter() const
+{
+ return m_filter;
+}
+
+void EmitterMessageReceived::setFilter(const MessageFilterPtr& filter)
+{
+ m_filter = filter;
+}
+}} // Api
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_MESSAGING_EMITTERMESSAGERECEIVED_H_
+#define WRTDEVICEAPIS_MESSAGING_EMITTERMESSAGERECEIVED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "EventMessageReceived.h"
+#include "MessageFilter.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class EmitterMessageReceived : public Commons::ListenerEventEmitter<
+ EventMessageReceived>
+{
+ public:
+ virtual MessageFilterPtr getFilter() const;
+ virtual void setFilter(const MessageFilterPtr& filter);
+
+ private:
+ MessageFilterPtr m_filter;
+};
+
+typedef DPL::SharedPtr<EmitterMessageReceived> EmitterMessageReceivedPtr;
+} // Api
+} // WrtDeviceApis
+}
+#endif // WRTDEVICEAPIS_MESSAGING_EMITTERMESSAGERECEIVED_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 EventDeleteMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef EVENTDELETEMESSAGE_H
+#define EVENTDELETEMESSAGE_H
+
+#include <dpl/shared_ptr.h>
+
+#include <Commons/IEvent.h>
+#include "IMessaging.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class EventDeleteMessage;
+
+typedef DPL::SharedPtr<EventDeleteMessage> EventDeleteMessagePtr;
+
+class EventDeleteMessage :
+ public WrtDeviceApis::Commons::IEvent<EventDeleteMessage>
+{
+ public:
+
+ IMessagePtr msg;
+
+ virtual void clearOnCancel()
+ {
+ }
+};
+}
+}}
+#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 EventFindMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef EVENTFINDMESSAGE_H
+#define EVENTFINDMESSAGE_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IMessage.h"
+#include "MessageFilter.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class EventFindMessage;
+
+typedef DPL::SharedPtr<EventFindMessage> EventFindMessagePtr;
+
+class EventFindMessage :
+ public WrtDeviceApis::Commons::IEvent<EventFindMessage>
+{
+ public:
+
+ // input parameters
+ MessageFilterPtr messageFilter;
+ std::vector<MessageType> messageTypes;
+ std::vector<FolderType> folderTypes;
+
+ //output parameter
+ std::vector<Api::IMessagePtr> msgs;
+
+ virtual void clearOnCancel()
+ {
+ }
+};
+}
+}}
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+#include "EventMessageReceived.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+EventMessageReceived::~EventMessageReceived()
+{
+}
+
+const IMessagePtr EventMessageReceived::getMessage() const
+{
+ return m_message;
+}
+
+void EventMessageReceived::setMessage(const IMessagePtr& message)
+{
+ m_message = message;
+}
+}} // Api
+} // 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 EventReceiveMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef WRTDEVICEAPIS_MESSAGING_EVENTMESSAGERECEIVED_H_
+#define WRTDEVICEAPIS_MESSAGING_EVENTMESSAGERECEIVED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include "IMessage.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class EventMessageReceived : public Commons::ListenerEvent<
+ EventMessageReceived>
+{
+ public:
+ virtual ~EventMessageReceived();
+
+ const IMessagePtr getMessage() const;
+ void setMessage(const IMessagePtr& message);
+
+ private:
+ IMessagePtr m_message;
+};
+
+typedef DPL::SharedPtr<EventMessageReceived> EventMessageReceivedPtr;
+} // Api
+} // WrtDeviceApis
+}
+#endif // WRTDEVICEAPIS_MESSAGING_EVENTMESSAGERECEIVED_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 EventOnSendingFailed.h
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef EVENTONSENDINGFAILED_H_
+#define EVENTONSENDINGFAILED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/EventListener.h>
+#include <Commons/ListenerEventEmitter.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+/*
+ *
+ */
+class EventOnSendingFailed : public Commons::ListenerEvent<
+ EventOnSendingFailed>
+{
+ public:
+ typedef enum
+ {
+ NO_NETWORKING,
+ NO_CONNECTION,
+ BAD_PAYLOAD,
+ UNKNOWN
+ } ErrorCode;
+
+ EventOnSendingFailed()
+ {
+ }
+
+ void setError(ErrorCode error)
+ {
+ m_error = error;
+ }
+
+ ErrorCode getError() const
+ {
+ return m_error;
+ }
+
+ private:
+ ErrorCode m_error;
+};
+
+typedef DPL::SharedPtr<EventOnSendingFailed> EventOnSendingFailedPtr;
+typedef Commons::ListenerEventEmitter<EventOnSendingFailed>
+EventOnSendingFailedEmitter;
+typedef DPL::SharedPtr<EventOnSendingFailedEmitter>
+EventOnSendingFailedEmitterPtr;
+} // Api
+} // WrtDeviceApis
+}
+#endif /* EVENTONSENDINGFAILED_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 EventSendMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef EVENTSENDMESSAGE_H
+#define EVENTSENDMESSAGE_H
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+#include <Commons/IEvent.h>
+#include "IMessaging.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class EventSendMessage;
+
+typedef DPL::SharedPtr<EventSendMessage> EventSendMessagePtr;
+
+class EventSendMessage :
+ public WrtDeviceApis::Commons::IEvent<EventSendMessage>
+{
+public:
+ struct RecipientSendResult
+ {
+ RecipientSendResult(const std::string& recipient, bool send)
+ : recipient(recipient),
+ send(send)
+ { }
+ std::string recipient;
+ bool send;
+ };
+
+ explicit EventSendMessage(const IMessagePtr& message)
+ : m_message(message),
+ m_store(false)
+ { }
+
+ IMessagePtr getMessage() const
+ {
+ return m_message;
+ }
+
+ bool getStore() const
+ {
+ return m_store;
+ }
+
+ void setStore(bool store)
+ {
+ m_store = store;
+ }
+
+ void addRecipientSendResult(const std::string& recipient, bool send)
+ {
+ m_results.push_back(RecipientSendResult(recipient, send));
+ }
+
+ void addRecipientsSendResult(const std::vector<std::string>& recipients,
+ bool send)
+ {
+ for_each(recipients.begin(),
+ recipients.end(),
+ [&m_results, &send](const std::string& recipient)
+ {
+ m_results.push_back(RecipientSendResult(recipient, send));
+ });
+ }
+
+ std::vector<RecipientSendResult> getRecipientSendResults() const
+ {
+ return m_results;
+ }
+
+ private:
+ IMessagePtr m_message;
+ bool m_store;
+ std::vector<RecipientSendResult> m_results;
+};
+}
+}}
+#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 EventUpdateMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef EVENTUPDATEMESSAGE_H
+#define EVENTUPDATEMESSAGE_H
+
+#include <dpl/shared_ptr.h>
+
+#include <Commons/IEvent.h>
+#include "IMessaging.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class EventUpdateMessage;
+
+typedef DPL::SharedPtr<EventUpdateMessage> EventUpdateMessagePtr;
+
+class EventUpdateMessage :
+ public WrtDeviceApis::Commons::IEvent<EventUpdateMessage>
+{
+ public:
+
+ IMessagePtr msg;
+
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef Commons::EventAnswerReceiver< Api::EventUpdateMessage >
+EventUpdateMessageAnswerReceiver;
+}
+}}
+#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 From.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "From.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+From::From() :
+ m_from(""),
+ m_validFrom(false)
+{
+}
+
+From::~From()
+{
+}
+
+void From::setFrom(const std::string& value)
+{
+ m_from = value;
+ m_validFrom = false;
+}
+
+std::string From::getFrom() const
+{
+ return m_from;
+}
+
+const std::string& From::getFromRef() const
+{
+ return m_from;
+}
+
+void From::setFromValidity(bool val)
+{
+ m_validFrom = val;
+}
+
+bool From::getFromValidity() const
+{
+ return m_validFrom;
+}
+}}
+}
--- /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 From.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef FROM_H
+#define FROM_H
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class From
+{
+ private: // fields
+
+ /**
+ * from value
+ */
+ std::string m_from;
+
+ /**
+ * information if abstract message from has been changed and need update
+ * in low level
+ */
+ bool m_validFrom;
+
+ public: // methods
+
+ From();
+
+ virtual ~From();
+
+ /**
+ * setter of from value
+ */
+ void setFrom(const std::string& value);
+
+ /**
+ * getter of from value
+ */
+ std::string getFrom() const;
+
+ const std::string& getFromRef() const;
+
+ void setFromValidity(bool val);
+
+ bool getFromValidity() const;
+};
+}
+}
+}
+#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 IAttachment.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <dpl/errno_string.h>
+#include <Commons/Exception.h>
+#include "IAttachment.h"
+
+extern "C" {
+#include <sys/stat.h>
+#include <stdlib.h>
+}
+
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+//--------------------------------------------------------------------------
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IAttachment::IAttachment() :
+ m_validAttachment(false)
+{
+}
+
+void IAttachment::init(const string& fullPath,
+ bool isVirtualPath)
+{
+ Try
+ {
+ struct stat buffer;
+ std::string l_fullPath;
+
+ if (isVirtualPath) {
+ LogDebug("translating path");
+ l_fullPath = getRealPath(fullPath);
+ } else {
+ l_fullPath = fullPath;
+ }
+
+ LogDebug("real path " << l_fullPath);
+
+ char buff[PATH_MAX + 1];
+ if (NULL == realpath(l_fullPath.c_str(), buff)) {
+ std::string errnoString = DPL::GetErrnoString();
+ LogError("get full path problem " << errnoString);
+ ThrowMsg(InvalidArgumentException,
+ "get full path problem " << errnoString);
+ }
+ if (-1 == lstat(buff, &buffer)) {
+ LogError("Attachment file not exist");
+ ThrowMsg(InvalidArgumentException, "Attachment file not exist");
+ }
+ if (!S_ISREG(buffer.st_mode)) {
+ LogError("Attachment file not exist");
+ ThrowMsg(InvalidArgumentException, "Attachment file not exist");
+ }
+ m_fileSize = buffer.st_size;
+ m_attachFullPath = l_fullPath;
+ makeShortName();
+ m_isCreatedProperly = true;
+ }
+
+ Catch(Commons::Exception) {
+ LogError("attachment not created properly");
+ m_isCreatedProperly = false;
+ }
+}
+
+IAttachment::~IAttachment()
+{
+ LogDebug("enter");
+}
+
+string IAttachment::getShortName() const
+{
+ return m_attachShortName;
+}
+
+string IAttachment::getFullPath() const
+{
+ return m_attachFullPath;
+}
+
+unsigned int IAttachment::getFileSize() const
+{
+ return m_fileSize;
+}
+
+std::string IAttachment::getMimeType() const
+{
+ return m_mimeType;
+}
+
+void IAttachment::setMimeType(const std::string &mimeType)
+{
+ m_mimeType = mimeType;
+}
+
+bool IAttachment::getIsCreatedProperly() const
+{
+ return m_isCreatedProperly;
+}
+
+void IAttachment::rename(const string& newName)
+{
+ // path for attachment is still not changed
+ m_attachShortName = newName;
+ m_validAttachment = false;
+}
+
+void IAttachment::makeShortName()
+{
+ size_t pos;
+ // find position of last occurence of / sign (get only file name from all path
+ pos = m_attachFullPath.find_last_of("/");
+ if ((pos + 1) >= m_attachFullPath.size()) {
+ LogError("Problem with short name creation");
+ Throw(InvalidArgumentException);
+ }
+ m_attachShortName = m_attachFullPath.substr(pos + 1);
+}
+
+}
+}
+}
--- /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 IAttachment.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IATTACHMENT_H
+#define IATTACHMENT_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "IMessagingTypes.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IAttachment;
+typedef DPL::SharedPtr<IAttachment> IAttachmentPtr;
+
+//--------------------------------------------------------------------------
+
+class IAttachment
+{
+ protected: // fields
+
+ /**
+ * value of attachment full path name
+ */
+ std::string m_attachFullPath;
+
+ /**
+ * value of attachment short name used to display in message
+ */
+ std::string m_attachShortName;
+
+ /**
+ * value of attachment file size
+ */
+ unsigned int m_fileSize;
+
+ /**
+ * value of attachment mime type
+ */
+ std::string m_mimeType;
+
+ /**
+ * information if abstract message attachment has been changed and need
+ * update in low level
+ * only name may be changed, not path
+ */
+ bool m_validAttachment;
+
+ bool m_isCreatedProperly;
+
+ public: // methods
+
+ explicit IAttachment();
+
+ void init(const std::string& fullPath,
+ bool isVirtualPath);
+
+ virtual ~IAttachment();
+
+ /**
+ * getter of attachment name (only name without path) value
+ */
+ std::string getShortName() const;
+
+ /**
+ * getter of attachment name (full path) value
+ */
+ std::string getFullPath() const;
+
+ /**
+ * getter of attachment size
+ */
+ unsigned int getFileSize() const;
+
+ /**
+ * getter of attachment mime type
+ */
+ std::string getMimeType() const;
+
+ /**
+ * setter of attachment mime type
+ */
+ void setMimeType(const std::string &mimeType);
+
+ /**
+ * getter of attachment valid
+ */
+ bool getIsCreatedProperly() const;
+
+ /**
+ * rename short name value of attachment
+ */
+ void rename(const std::string& newName);
+
+ private:
+
+ void makeShortName();
+
+ virtual std::string getRealPath(const std::string &path) const = 0;
+};
+}
+}
+}
+#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 IBinarySms.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "IBinarySms.h"
+#include <dpl/log/log.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IBinarySms::IBinarySms(const std::string& id) :
+ IMessage(BINARYSMS, id)
+{
+ LogDebug("enter");
+}
+
+IBinarySms::~IBinarySms()
+{
+ LogDebug("enter");
+}
+}}
+}
--- /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 IBinarySms.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IBINARYSMS_H
+#define IBINARYSMS_H
+
+#include "IMessage.h"
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class IBinarySms;
+typedef DPL::SharedPtr<IBinarySms> IBinarySmsPtr;
+
+class IBinarySms :
+ virtual public IMessage
+{
+ public: // fields
+
+ public: // methods
+
+ explicit IBinarySms(const std::string& id = "");
+
+ virtual ~IBinarySms();
+};
+}
+}
+}
+#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 IEmail.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "IEmail.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IEmail::IEmail(const string& id) : IMessage(EMAIL, id)
+{
+ LogInfo("enter");
+}
+
+IEmail::~IEmail()
+{
+ LogInfo("enter");
+}
+
+IEmail & IEmail::operator <<(const VirtualMessage& msg)
+{
+ setBody(msg.getBodyRef());
+ setFolderType(msg.getCurrentFolder());
+ setCurrentUserFolder(msg.getCurrentUserFolder());
+ setFrom(msg.getFromRef());
+ setDateTime(msg.getDateTime());
+ setSourceAddress(msg.getSourceAddress());
+ setToRecipients(msg.getToRecipients());
+
+ setAttachments(msg.getAttachments());
+ setBccRecipients(msg.getBccRecipients());
+ setCcRecipients(msg.getCcRecipients());
+ setSubject(msg.getSubjectRef());
+
+ return *this;
+}
+}}
+}
--- /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 IEmail.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IEMAIL_H
+#define IEMAIL_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "VirtualMessage.h"
+#include "IMessage.h"
+#include "Subject.h"
+#include "ToRecipient.h"
+#include "CcRecipient.h"
+#include "BccRecipient.h"
+#include "Attachments.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IEmail : virtual public IMessage,
+ public CcRecipient,
+ public BccRecipient,
+ public Attachments
+{
+ public:
+ explicit IEmail(const std::string& id = "");
+
+ virtual ~IEmail();
+
+ IEmail & operator <<(const VirtualMessage& msg);
+
+ virtual int getAccountId() const = 0;
+};
+
+typedef DPL::SharedPtr<IEmail> IEmailPtr;
+}
+}
+}
+#endif // IEMAIL_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 IEmailAccount.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <algorithm>
+#include <Commons/Exception.h>
+#include "IEmailAccount.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IEmailAccount::IEmailAccount() :
+ m_currentAccount("", "", ""),
+ m_validAccount(false)
+{
+}
+
+IEmailAccount::~IEmailAccount()
+{
+}
+
+void IEmailAccount::setCurrentEmailAccount(const EmailAccountInfo& account)
+{
+ std::vector<EmailAccountInfo> accounts = getEmailAccounts();
+ if (std::find(accounts.begin(), accounts.end(),
+ account) != accounts.end()) {
+ m_currentAccount = account;
+ } else {
+ ThrowMsg(Commons::InvalidArgumentException,
+ "Wrong account name, account not exist");
+ }
+}
+
+EmailAccountInfo IEmailAccount::getCurrentEmailAccount() const
+{
+ return m_currentAccount;
+}
+
+bool IEmailAccount::isCurrentAccountValid() const
+{
+ return m_validAccount;
+}
+
+void IEmailAccount::setCurrentAccountValid(bool state)
+{
+ m_validAccount = state;
+}
+}}
+}
--- /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 EmailAccount.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IEMAILACCOUNT_H
+#define IEMAILACCOUNT_H
+
+#include <vector>
+#include "EmailAccountInfo.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IEmailAccount
+{
+ public:
+ IEmailAccount();
+
+ virtual ~IEmailAccount();
+
+ /**
+ * get avialable emails accounts
+ */
+ virtual std::vector<EmailAccountInfo> getEmailAccounts() const = 0;
+
+ /**
+ * setter of current email account value
+ */
+ void setCurrentEmailAccount(const EmailAccountInfo& value);
+
+ /**
+ * getter of current email account value
+ */
+ EmailAccountInfo getCurrentEmailAccount() const;
+
+ /**
+ * check validity state
+ */
+ bool isCurrentAccountValid() const;
+
+ /**
+ * setter for validity state
+ */
+ void setCurrentAccountValid(bool state);
+
+ private:
+
+ /**
+ * abstract value of current email account
+ */
+ EmailAccountInfo m_currentAccount;
+
+ /**
+ * information if abstract message current account has been changed
+ * and need update in low level
+ */
+ bool m_validAccount;
+};
+}
+}
+}
+#endif // IEMAILACCOUNT_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 IMessage.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "IMessage.h"
+#include "EventSendMessage.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IMessage::IMessage(const MessageType msgType,
+ const string& id) :
+ m_id(id),
+ m_msgType(msgType),
+ m_readStatus(false),
+ m_validReadStatus(false),
+ m_folder(DRAFTBOX),
+ m_requestReceiver(NULL),
+ m_sendMessageEvent(NULL)
+{
+ LogDebug("message creation, msgId=" << m_id << ", msgType=" << m_msgType);
+
+ //initialize dateTime of message
+ time_t rawtime;
+ time(&rawtime);
+ tm* local = localtime(&rawtime);
+ if (local) {
+ m_dateTime = *local;
+ } else {
+ LogError("Failed to initialize message dateTime");
+ }
+}
+
+IMessage::~IMessage()
+{
+ LogDebug("destroying message, msgId=" << m_id << ", msgType=" << m_msgType);
+}
+
+string IMessage::getId() const
+{
+ return m_id;
+}
+
+const string& IMessage::getIdRef() const
+{
+ return m_id;
+}
+
+MessageType IMessage::getMessageType() const
+{
+ return m_msgType;
+}
+
+struct tm IMessage::getDateTime() const
+{
+ return m_dateTime;
+}
+
+string IMessage::convertId(int arg) const
+{
+ ostringstream stream;
+ stream << arg;
+ return stream.str();
+}
+
+int IMessage::convertId(const string& arg) const
+{
+ int retVal = 0;
+ istringstream(arg) >> retVal;
+ return retVal;
+}
+
+void IMessage::setId(const string& value)
+{
+ m_id = value;
+}
+
+void IMessage::setDateTime(const tm dateTime)
+{
+ m_dateTime = dateTime;
+}
+
+void IMessage::setReadStatus(bool state)
+{
+ m_validReadStatus = false;
+ m_readStatus = state;
+}
+
+void IMessage::setSize(int size)
+{
+ m_size = size;
+}
+
+int IMessage::getSize() const
+{
+ return m_size;
+}
+
+bool IMessage::isRead() const
+{
+ return m_readStatus;
+}
+
+bool IMessage::isReadStatusValid() const
+{
+ return m_validReadStatus;
+}
+
+void IMessage::setReadStatusValidity(bool valid)
+{
+ m_validReadStatus = valid;
+}
+
+FolderType IMessage::getCurrentFolder() const
+{
+ return m_folder;
+}
+
+void IMessage::setFolderType(FolderType folder)
+{
+ m_folder = folder;
+}
+
+string IMessage::getCurrentUserFolder() const
+{
+ if (m_folder != USERDEFINED_FOLDER) {
+ LogError("folder is not user folder type");
+ Throw(Commons::UnknownException);
+ }
+ return m_userFolderName;
+}
+
+void IMessage::setCurrentUserFolder(const std::string& arg)
+{
+ m_userFolderName = arg;
+}
+
+bool IMessage::validatePhoneNumber(std::string& number)
+{
+ LogDebug("testing number=" << number);
+ pcrecpp::RE re("[^0-9#\\+\\*]?");
+ re.GlobalReplace("", &number);
+ if (number.empty()) {
+ LogError("wrong phoneNumber=" << number);
+ return false;
+ }
+ LogDebug("phoneNumber=" << number);
+
+ return true;
+}
+
+bool IMessage::validateEmailAddr(const Recipients& addr)
+{
+ for (size_t i = 0; i < addr.getRecipientSize(); i++) {
+ if (false == validateEmailAddr(addr.getRecipient(i))) {
+ LogError("wrong email address");
+ return false;
+ }
+ }
+ return true;
+}
+
+bool IMessage::validateEmailAddr(const std::string& email)
+{
+ if (email.empty()) {
+ return false;
+ }
+ pcrecpp::RE re(
+ "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}"
+ "\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\"
+ ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"
+ );
+ if (re.FullMatch(email)) {
+ LogDebug("emailAddress=" << email);
+ return true;
+ }
+ LogError("wrong emailAddress=" << email);
+ return false;
+}
+
+void IMessage::setEmitter(const EventOnSendingFailedEmitterPtr& emitter)
+{
+ m_emitter = emitter;
+}
+
+EventOnSendingFailedEmitterPtr IMessage::getEmitter() const
+{
+ return m_emitter;
+}
+
+void IMessage::setSendMessageEvent(const EventSendMessagePtr &event)
+{
+ m_sendMessageEvent = event;
+}
+
+EventSendMessagePtr IMessage::getSendMessageEvent() const
+{
+ return m_sendMessageEvent;
+}
+
+void IMessage::setRequestReceiver(ReqReceiverMessage* reqReceiver)
+{
+ m_requestReceiver = reqReceiver;
+}
+
+ReqReceiverMessage* IMessage::getRequestReceiver() const
+{
+ return m_requestReceiver;
+}
+}}
+}
--- /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 IMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IMESSAGE_H
+#define IMESSAGE_H
+
+#include <string>
+#include <ctime>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include "IMessagingTypes.h"
+#include "ToRecipient.h"
+#include "Body.h"
+#include "From.h"
+#include "SourceAddress.h"
+#include "MessagePriority.h"
+#include "CallbackNumber.h"
+#include "ValidityPeriodHours.h"
+#include "Subject.h"
+#include "EventOnSendingFailed.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class EventSendMessage;
+typedef DPL::SharedPtr<EventSendMessage> EventSendMessagePtr;
+
+//--------------------------------------------------------------------------
+
+class IMessage;
+typedef DPL::SharedPtr<IMessage> IMessagePtr;
+
+//--------------------------------------------------------------------------
+
+class ReqReceiverMessage;
+
+//--------------------------------------------------------------------------
+
+class IMessage :
+ public DPL::EnableSharedFromThis<IMessage>,
+ public ToRecipient,
+ public Body,
+ public From,
+ public SourceAddress,
+ public MessagePriority,
+ public CallbackNumber,
+ public ValidityPeriodHours,
+ public Subject
+{
+ private: // fields
+
+ /**
+ * id of message
+ */
+ std::string m_id;
+
+ /**
+ * message type value
+ */
+ const MessageType m_msgType;
+
+ /**
+ * Message creation date time
+ */
+ struct tm m_dateTime;
+
+ /**
+ * Message read status
+ */
+ bool m_readStatus;
+
+ /**
+ * Read status validity.
+ */
+ bool m_validReadStatus;
+
+ /**
+ * Message size in bytes
+ */
+ int m_size;
+
+ /**
+ * Message current folder
+ */
+ FolderType m_folder;
+
+ /**
+ * User folder name
+ */
+ std::string m_userFolderName;
+
+ /*
+ * Event emitter. Used when there is one global callback function
+ */
+ EventOnSendingFailedEmitterPtr m_emitter;
+
+ /*
+ * Request receiver. Used when there are callback funtions assigned at function executing scope
+ */
+ ReqReceiverMessage *m_requestReceiver;
+
+ /*
+ * SendMessage event. Used when there are callback funtions assigned at function executing scope
+ */
+ EventSendMessagePtr m_sendMessageEvent;
+
+ protected:
+ void setSize(int size);
+
+ public: // methods
+
+ /**
+ * constructor of abstraction message
+ * @param[in] msgType - type of message according to MessageType
+ * @param[in] id - id of message, if id is empty, new message will be
+ * created, othercase message will be read from low
+ * level message
+ */
+ explicit IMessage(const MessageType msgType,
+ const std::string& id = "");
+
+ virtual ~IMessage();
+
+ /**
+ * method is used to send message specyfied type
+ * @throw PlatformException Thrown when sending fail
+ */
+ virtual void send() = 0;
+
+ /**
+ * method is used to cancel sending message
+ * @throw PlatformException Thrown when sending fail
+ */
+ virtual void sendCancel() = 0;
+
+ /**
+ * method used to update all fields in lower level
+ * @param[in] draftsOnly - if true only draft messages can be
+ * fully updated. Other messages can only have read flag changed
+ * @throw PlatformException Thrown when update fail
+ */
+ virtual void update(bool draftsOnly = false) = 0;
+
+ /**
+ * method used to read all data from low level message
+ * @throw PlatformException Thrown when reading message fail
+ */
+ virtual void readAllData() = 0;
+
+ /**
+ * method used to get current storage folder
+ */
+ virtual FolderType getCurrentFolder() const;
+
+ /**
+ * method used to get current user folder name
+ */
+ virtual std::string getCurrentUserFolder() const;
+
+ /**
+ * method used to set current user folder name
+ */
+ void setCurrentUserFolder(const std::string& arg);
+
+ /**
+ * method used to move message to new folder
+ * @param[in] newFolder - destination folder
+ * @throw PlatformException Thrown when move message to folder fail
+ */
+ virtual void moveToFolder(const FolderType newFolder) = 0;
+
+ /**
+ * method used to move message to user defined new folder
+ * @param[in] newFolder - users destination folder
+ * @throw PlatformException Thrown when move message to folder fail
+ */
+ virtual void moveToFolder(const std::string& newFolder) = 0;
+
+ /**
+ * method used to copy message to new folder (create new message with
+ * new message id)
+ * @param[in] newFolder - destination folder
+ * @throw PlatformException Thrown when copy message to folder fail
+ */
+ virtual void copyToFolder(const FolderType newFolder) = 0;
+
+ /**
+ * method used to copy message to user defined new folder
+ * @param[in] newFolder - users destination folder
+ * @throw PlatformException Thrown when move message to folder fail
+ */
+ virtual void copyToFolder(const std::string& newFolder) = 0;
+
+ /**
+ * method used to identify message type
+ */
+ MessageType getMessageType() const;
+
+ /**
+ * method used to get message id
+ */
+ std::string getId() const;
+
+ /**
+ * method used to get message size
+ */
+ int getSize() const;
+
+ /**
+ * method used to get message id
+ */
+ virtual const std::string& getIdRef() const;
+
+ /**
+ * used for get tm struct
+ */
+ struct tm getDateTime() const;
+
+ /**
+ * Is message already been read
+ */
+ virtual bool isRead() const;
+
+ /**
+ * Is message already been read
+ */
+ virtual void setReadStatus(bool state);
+
+ /**
+ * Returns true if read status is valid
+ */
+ bool isReadStatusValid() const;
+
+ /**
+ * Sets read status validity
+ */
+ void setReadStatusValidity(bool valid);
+
+ /**
+ * Remove message
+ * @throw PlatformException Thrown when remove message fail
+ */
+ virtual void remove() = 0;
+
+ /**
+ * convert id from int to string
+ */
+ virtual std::string convertId(int arg) const;
+
+ /**
+ * convert id from string to int
+ */
+ virtual int convertId(const std::string& arg) const;
+
+ /**
+ * set message id
+ */
+ void setId(const std::string& id);
+
+ /**
+ * set date time
+ */
+ void setDateTime(const tm dateTime);
+
+ /**
+ * set current folder
+ */
+ virtual void setFolderType(FolderType folder);
+
+ /**
+ * validate phone number, if fail return false
+ * if number contains wrong characters, then cut them
+ */
+ bool validatePhoneNumber(std::string& number);
+
+ /**
+ * validate email address, if fail return false
+ */
+ bool validateEmailAddr(const Recipients& addr);
+
+ /**
+ * validate email address, if fail return false
+ */
+ bool validateEmailAddr(const std::string& email);
+
+ /*
+ * Sets event emitter
+ */
+ void setEmitter(const EventOnSendingFailedEmitterPtr& emitter);
+
+ /*
+ * Gets event emitter
+ */
+ EventOnSendingFailedEmitterPtr getEmitter() const;
+
+ void setSendMessageEvent(const EventSendMessagePtr &event);
+
+ EventSendMessagePtr getSendMessageEvent() const;
+
+ void setRequestReceiver(ReqReceiverMessage* reqReceiver);
+
+ ReqReceiverMessage* getRequestReceiver() const;
+};
+}
+}
+}
+#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 IMessaging.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "IMessaging.h"
+#include <Messaging/Messaging.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IMessaging& IMessaging::getInstance()
+{
+ return Messaging::getInstance();
+}
+
+IMessaging::~IMessaging()
+{
+}
+}}
+}
--- /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 IMessaging.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IMESSAGING_H
+#define IMESSAGING_H
+
+#include <dpl/shared_ptr.h>
+#include "IMessagingTypes.h"
+#include "ISms.h"
+#include "IBinarySms.h"
+#include "IMms.h"
+#include "IEmail.h"
+#include "VirtualMessage.h"
+#include "MessageFactory.h"
+#include "IEmailAccount.h"
+#include "MessageFilter.h"
+#include "EmitterMessageReceived.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IMessaging : private DPL::Noncopyable,
+ public IEmailAccount
+{
+ public:
+ static IMessaging& getInstance();
+
+ public:
+ virtual ~IMessaging() = 0;
+
+ virtual void getNumberOfMessages(MessageType msgType,
+ FolderType folder,
+ int* readed,
+ int* unReaded) = 0;
+
+ virtual std::vector<IMessagePtr> findMessages(
+ const std::vector<MessageType>& msgTypes,
+ FolderType folder,
+ const Api::MessageFilterPtr& filter) = 0;
+
+ virtual std::vector<IMessagePtr> findMessages(
+ const std::vector<MessageType>& msgTypes,
+ const std::string &folder,
+ const Api::MessageFilterPtr& filter) = 0;
+
+ virtual std::vector<std::string> getMessageIds(MessageType msgType,
+ FolderType folder) = 0;
+
+ virtual void createFolder(MessageType msgType,
+ const std::string& userFolder) = 0;
+
+ virtual void deleteFolder(MessageType msgType,
+ const std::string& userFolder) = 0;
+
+ virtual std::vector<std::string> getFolderNames(MessageType msgType) = 0;
+
+ virtual void addOnMessageReceived(const EmitterMessageReceivedPtr& emitter)
+ = 0;
+
+ virtual void removeOnMessageReceived(EmitterMessageReceived::IdType id) = 0;
+
+ virtual void fetchEmailHeaders() = 0;
+};
+}
+}
+}
+#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 IMessagingTypes.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IMESSAGINGTYPES_H
+#define IMESSAGINGTYPES_H
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+enum MessageType
+{
+ SMS,
+ BINARYSMS,
+ MMS,
+ EMAIL,
+ VIRTUAL_MESSAGE,
+ MESSAGETYPE_COUNT
+};
+
+//--------------------------------------------------------------------------
+
+enum FolderType
+{
+ INBOX,
+ OUTBOX,
+ SENTBOX,
+ DRAFTBOX,
+ SPAMBOX,
+ ALL_FOLDERS,
+ USERDEFINED_FOLDER,
+ FOLDERTYPE_COUNT
+};
+
+//--------------------------------------------------------------------------
+
+enum AddressType
+{
+ TO_ADDRESS,
+ CC_ADDRESS,
+ BCC_ADDRESS,
+ ADDRESS_COUNT
+};
+}
+}
+
+}
+#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 IMms.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "IMms.h"
+#include "ValidityPeriodHours.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IMms::IMms(const string& id) :
+ IMessage(MMS, id),
+ m_mmsType(MULTIPART_MIXED)
+{
+ LogInfo("enter");
+}
+
+IMms::~IMms()
+{
+ LogInfo("enter");
+}
+
+IMms::MMSType IMms::getMmsType() const
+{
+ return m_mmsType;
+}
+
+void IMms::setMmsType(MMSType type)
+{
+ m_mmsType = type;
+}
+
+IMms & IMms::operator <<(const VirtualMessage& msg)
+{
+ setBody(msg.getBodyRef());
+ setFolderType(msg.getCurrentFolder());
+ setCurrentUserFolder(msg.getCurrentUserFolder());
+ setFrom(msg.getFromRef());
+ setDateTime(msg.getDateTime());
+ setSourceAddress(msg.getSourceAddress());
+ setToRecipients(msg.getToRecipients());
+ setValidityPeriodHours(msg.getValidityPeriodHours());
+
+ setAttachments(msg.getAttachments());
+ setBccRecipients(msg.getBccRecipients());
+ setCcRecipients(msg.getCcRecipients());
+ setSubject(msg.getSubjectRef());
+
+ return *this;
+}
+}}
+}
--- /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 IMms.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IMMS_H
+#define IMMS_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "VirtualMessage.h"
+#include "IMessage.h"
+#include "Subject.h"
+#include "ToRecipient.h"
+#include "CcRecipient.h"
+#include "BccRecipient.h"
+#include "Attachments.h"
+#include "IMmsSlides.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IMms;
+typedef DPL::SharedPtr<IMms> IMmsPtr;
+
+class IMms :
+ virtual public IMessage,
+ virtual public IMmsSlides,
+ public CcRecipient,
+ public BccRecipient,
+ public Attachments
+{
+ public: // fields
+
+ enum MMSType
+ {
+ MULTIPART_MIXED = 0,
+ MULTIPART_RELATED = 1
+ };
+
+ public: // methods
+
+ explicit IMms(const std::string& id = "");
+
+ virtual ~IMms();
+
+ /**
+ * geter for mms type
+ * */
+ virtual MMSType getMmsType() const;
+
+ /**
+ * seter for mms type
+ * */
+ virtual void setMmsType(MMSType type);
+
+ IMms & operator <<(const VirtualMessage& msg);
+
+ private:
+ MMSType m_mmsType;
+};
+}
+}
+}
+#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 IMmsSlide.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IMMSSLIDE_H
+#define IMMSSLIDE_H
+
+#include <dpl/shared_ptr.h>
+
+#include "IMmsSlideProperties.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IMmsSlide;
+typedef DPL::SharedPtr<IMmsSlide> IMmsSlidePtr;
+
+class IMmsSlide :
+ public IMmsSlidePropertyImage,
+ public IMmsSlidePropertyAudio,
+ public IMmsSlidePropertyText,
+ public IMmsSlidePropertyVideo
+{
+ public:
+ typedef unsigned long Ulong;
+
+ public: // methods
+
+ virtual ~IMmsSlide()
+ {
+ }
+
+ /**
+ * Get duration
+ */
+ virtual Ulong getDuration() const = 0;
+
+ /**
+ * Set duration
+ * @param[in] - value in miliseconds
+ */
+ virtual void setDuration(Ulong duration) = 0;
+};
+}
+}
+}
+#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 IMmsSlideProperties.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef IMMS_SLIDE_PROPERTIES_H
+#define IMMS_SLIDE_PROPERTIES_H
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IMmsSlidePropertyImage
+{
+ public:
+ typedef unsigned long Ulong;
+
+ public:
+
+ virtual ~IMmsSlidePropertyImage()
+ {
+ }
+
+ /**
+ * get image filename
+ * */
+ virtual const std::string& getImageFilename() const = 0;
+
+ /**
+ * get image filename
+ * @param[in] picture filename
+ * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+ * @throw MMS_VIDEO_SLIDE_ERROR
+ * */
+ virtual void setImageFilename(const std::string& filename) = 0;
+
+ /**
+ * get imageBegin
+ * begining of image presentation within a slide in milisecond
+ * */
+ virtual Ulong getImageBegin() const = 0;
+
+ /**
+ * set imageBegin;
+ * begining of image presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setImageBegin(Ulong value) = 0;
+
+ /**
+ * get imageEnd
+ * end of image presentation within a slide in milisecond
+ * */
+ virtual Ulong getImageEnd() const = 0;
+
+ /**
+ * set imageBegin;
+ * end of image presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setImageEnd(Ulong value) = 0;
+};
+
+//--------------------------------------------------------------------------
+
+class IMmsSlidePropertyAudio
+{
+ public:
+ typedef unsigned long Ulong;
+
+ public:
+
+ virtual ~IMmsSlidePropertyAudio()
+ {
+ }
+
+ /**
+ * get audio filename
+ * */
+ virtual const std::string& getAudioFilename() const = 0;
+
+ /**
+ * get audio filename
+ * @param[in] audio filename
+ * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+ * @throw MMS_VIDEO_SLIDE_ERROR
+ * */
+ virtual void setAudioFilename(const std::string& filename) = 0;
+
+ /**
+ * get audio begin
+ * begining of image presentation within a slide in milisecond
+ * */
+ virtual Ulong getAudioBegin() const = 0;
+
+ /**
+ * set audio begin;
+ * begining of audio presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setAudioBegin(Ulong value) = 0;
+
+ /**
+ * get audioEnd
+ * end of audio presentation within a slide in milisecond
+ * */
+ virtual Ulong getAudioEnd() const = 0;
+
+ /**
+ * set audioEnd;
+ * end of audio presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setAudioEnd(Ulong value) = 0;
+};
+
+//--------------------------------------------------------------------------
+
+class IMmsSlidePropertyText
+{
+ public:
+ typedef unsigned long Ulong;
+
+ public:
+
+ virtual ~IMmsSlidePropertyText()
+ {
+ }
+
+ /**
+ * get text filename
+ * */
+ virtual const std::string& getTextFilename() const = 0;
+
+ /**
+ * get text filename
+ * @param[in] text filename
+ * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+ * @throw MMS_VIDEO_SLIDE_ERROR
+ * */
+ virtual void setTextFilename(const std::string& filename) = 0;
+
+ /**
+ * get text begin
+ * begining of text presentation within a slide in milisecond
+ * */
+ virtual Ulong getTextBegin() const = 0;
+
+ /**
+ * set text begin;
+ * begining of text presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setTextBegin(Ulong value) = 0;
+
+ /**
+ * get textEnd
+ * end of text presentation within a slide in milisecond
+ * */
+ virtual Ulong getTextEnd() const = 0;
+
+ /**
+ * set textEnd;
+ * end of text presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setTextEnd(Ulong value) = 0;
+};
+
+//--------------------------------------------------------------------------
+
+class IMmsSlidePropertyVideo
+{
+ public:
+ typedef unsigned long Ulong;
+
+ public:
+
+ virtual ~IMmsSlidePropertyVideo()
+ {
+ }
+
+ /**
+ * get video filename
+ * */
+ virtual const std::string& getVideoFilename() const = 0;
+
+ /**
+ * get video filename
+ * @param[in] vdeo filename
+ * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+ * @throw MMS_VIDEO_SLIDE_ERROR
+ * */
+ virtual void setVideoFilename(const std::string& filename) = 0;
+
+ /**
+ * get video begin
+ * begining of video presentation within a slide in milisecond
+ * */
+ virtual Ulong getVideoBegin() const = 0;
+
+ /**
+ * set video begin;
+ * begining of video presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setVideoBegin(Ulong value) = 0;
+
+ /**
+ * get videoEnd
+ * end of video presentation within a slide in milisecond
+ * */
+ virtual Ulong getVideoEnd() const = 0;
+
+ /**
+ * set videoEnd;
+ * end of video presentation within a slide in milisecond
+ * @param[in] - value in miliseconds
+ * */
+ virtual void setVideoEnd(Ulong value) = 0;
+};
+}
+}
+}
+#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 IMmsSlides.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef IMMS_SLIDES_H
+#define IMMS_SLIDES_H
+
+#include <vector>
+
+#include "IMmsSlide.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class IMmsSlides
+{
+ public:
+
+ virtual ~IMmsSlides()
+ {
+ }
+
+ /**
+ * create empty slide
+ * @return shared pointer to created IMmsSlide
+ * */
+ virtual IMmsSlidePtr createEmptySlide() const = 0;
+
+ /**
+ * check data validity
+ * @return true if slides are valid
+ * or false if one or more slide need update
+ * */
+ virtual bool checkSlidesValidity() const = 0;
+
+ /**
+ * set data validity
+ * */
+ virtual void setSlidesValidity(bool state) = 0;
+
+ /**
+ * set slides
+ * */
+ virtual void setSlides(const std::vector<IMmsSlidePtr>& slides) = 0;
+
+ /**
+ * add slide to mms object
+ * */
+ virtual void addSlide(const IMmsSlidePtr& slide) = 0;
+
+ /**
+ * get slide count
+ * @return number of slides in mms
+ * */
+ virtual size_t getSlideCount() const = 0;
+
+ /**
+ * get slide by number
+ * @return shared pointer to IMmsSlide
+ * @throw INVALID_ARGUMENT_EXCEPTION
+ * if argument is wrong
+ * */
+ virtual IMmsSlidePtr getSlide(size_t nb) const = 0;
+
+ /**
+ * get slides
+ * @return vector of slides from Mms
+ * */
+ virtual std::vector<IMmsSlidePtr> getSlides() const = 0;
+
+ /**
+ * replace slide
+ * @throw INVALID_ARGUMENT_EXCEPTION
+ * if argument is wrong
+ * */
+ virtual void replaceSlide(size_t pos,
+ const IMmsSlidePtr& slide) = 0;
+
+ /**
+ * remove slide
+ * @throw INVALID_ARGUMENT_EXCEPTION
+ * if argument is wrong
+ * */
+ virtual void removeSlide(size_t pos) = 0;
+};
+}
+}
+}
+#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 ISms.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "ISms.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+ISms::ISms(const string& id) :
+ IMessage(SMS, id)
+{
+ LogInfo("enter");
+}
+
+ISms::~ISms()
+{
+ LogInfo("enter");
+}
+
+ISms & ISms::operator <<(const VirtualMessage& msg)
+{
+ setBody(msg.getBodyRef());
+ setFolderType(msg.getCurrentFolder());
+ setCurrentUserFolder(msg.getCurrentUserFolder());
+ setFrom(msg.getFromRef());
+ setDateTime(msg.getDateTime());
+ setSourceAddress(msg.getSourceAddress());
+ setToRecipients(msg.getToRecipients());
+ setCallbackNumber(getCallbackNumberRef());
+ setValidityPeriodHours(msg.getValidityPeriodHours());
+
+ return *this;
+}
+}}
+}
--- /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 ISms.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef ISMS_H
+#define ISMS_H
+
+#include "IMessage.h"
+#include "CallbackNumber.h"
+#include "VirtualMessage.h"
+#include "ValidityPeriodHours.h"
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class ISms;
+typedef DPL::SharedPtr<ISms> ISmsPtr;
+
+class ISms :
+ virtual public IMessage
+{
+ public: // fields
+
+ public: // methods
+
+ explicit ISms(const std::string& id = "");
+
+ virtual ~ISms();
+
+ ISms & operator <<(const VirtualMessage& msg);
+};
+}
+}
+}
+#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 MessageEventPrivateData.h
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef MESSAGEEVENTPRIVATEDATA_H_
+#define MESSAGEEVENTPRIVATEDATA_H_
+
+#include <platform/commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IMessage.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+/*
+ * I cannot put IMessagePtr directly in EventOnSendingFailed because the IMessage contains an emitter based on this event
+ * and I get recurring include dependency and I don't want to mix standard pointers with shared pointers.
+ */
+class MessageEventPrivateData : public Platform::IEventPrivateData
+{
+ public:
+ explicit MessageEventPrivateData(const IMessagePtr& message) : m_message(
+ message)
+ {
+ }
+
+ IMessagePtr GetMessage() const
+ {
+ return m_message;
+ }
+
+ private:
+ IMessagePtr m_message;
+};
+
+typedef DPL::SharedPtr<MessageEventPrivateData> MessageEventPrivateDataPtr;
+} // Api
+} // WrtDeviceApis
+}
+#endif /* MESSAGEEVENTPRIVATEDATA_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 MessageFactory.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Messaging/Sms.h>
+#include <Messaging/BinarySms.h>
+#include <Messaging/Mms.h>
+#include <Messaging/Email.h>
+#include "MessageFactory.h"
+
+using namespace WrtDeviceApis::Commons;
+
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+IMessagePtr MessageFactory::createMessage(const MessageType msgType,
+ const std::string& id)
+{
+ LogInfo("enter");
+ IMessage* retVal = NULL;
+ switch (msgType) {
+ case SMS:
+ LogDebug("creation sms message");
+ retVal = new Sms(id);
+ break;
+
+ case BINARYSMS:
+ LogDebug("creation binary sms message");
+ retVal = new BinarySms(id);
+ break;
+
+ case MMS:
+ LogDebug("creation mms message");
+ retVal = new Mms(id);
+ break;
+
+ case EMAIL:
+ LogDebug("creation email message");
+ retVal = new Email(id);
+ break;
+
+ default:
+ LogError("creation error, unknown message type");
+ break;
+ }
+ return IMessagePtr(retVal);
+}
+
+IMessagePtr MessageFactory::createMessage(const MessageType msgType,
+ const int id)
+{
+ std::ostringstream stream;
+ stream << id;
+ std::string idStr = stream.str();
+ return createMessage(msgType, idStr);
+}
+
+IMessagePtr MessageFactory::createVirtualMessage()
+{
+ return IMessagePtr(new VirtualMessage());
+}
+
+VirtualMessagePtr MessageFactory::convertToVirtualMessage(IMessagePtr msg)
+{
+ VirtualMessagePtr tmp = DPL::DynamicPointerCast<VirtualMessage >(msg);
+ if (!tmp) {
+ ThrowMsg(ConversionException,
+ "Conversion IMessage to VirtualMessagePtr error");
+ }
+ return tmp;
+}
+
+ISmsPtr MessageFactory::convertToSms(IMessagePtr msg)
+{
+ ISmsPtr tmp = DPL::DynamicPointerCast<ISms >(msg);
+ if (!tmp) {
+ ThrowMsg(ConversionException, "Conversion IMessage to ISms error");
+ }
+ return tmp;
+}
+
+IBinarySmsPtr MessageFactory::convertToBinarySms(IMessagePtr msg)
+{
+ IBinarySmsPtr tmp = DPL::DynamicPointerCast<IBinarySms >(msg);
+ if (!tmp) {
+ ThrowMsg(ConversionException, "Conversion IMessage to IBinarySms error");
+ }
+ return tmp;
+}
+
+IMmsPtr MessageFactory::convertToMms(IMessagePtr msg)
+{
+ IMmsPtr tmp = DPL::DynamicPointerCast<IMms >(msg);
+ if (!tmp) {
+ ThrowMsg(ConversionException, "Conversion IMessage to IMms error");
+ }
+ return tmp;
+}
+
+IEmailPtr MessageFactory::convertToEmail(IMessagePtr msg)
+{
+ IEmailPtr tmp = DPL::DynamicPointerCast<IEmail >(msg);
+ if (!tmp) {
+ ThrowMsg(ConversionException, "Conversion IMessage to IEmail error");
+ }
+ return tmp;
+}
+}
+}
+}
--- /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 MessageFactory.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef MESSAGEFACTORY_H
+#define MESSAGEFACTORY_H
+
+#include <string>
+#include "IMessaging.h"
+#include "IMessage.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class MessageFactory
+{
+ public:
+
+ /**
+ * Generate message specyfied type
+ * @param[in] msgType type of message to create
+ * @param[in] id if id is set, then is trying to read existing message
+ * from storage by specyfid if
+ */
+ static IMessagePtr createMessage(const MessageType msgType,
+ const std::string& id = "");
+
+ /**
+ * Generate message specyfied type
+ * @param[in] msgType type of message to create
+ * @param[in] int id
+ * from storage by specyfid if
+ */
+ static IMessagePtr createMessage(const MessageType msgType,
+ const int id);
+
+ /**
+ * Generate virtual message specyfied type, without platform projection
+ * @param[in] msgType type of message to create
+ */
+ static IMessagePtr createVirtualMessage();
+
+ /**
+ * Convert abstract message (IMessage) to virtual message
+ * @param[in] msg - pointer to message to convert
+ * @throw ConversionException if conversion fail
+ */
+ static VirtualMessagePtr convertToVirtualMessage(IMessagePtr msg);
+
+ /**
+ * Convert abstract message (IMessage) to abstract sms (ISms)
+ * @param[in] msg - pointer to message to convert
+ * @throw ConversionException if conversion fail
+ */
+ static ISmsPtr convertToSms(IMessagePtr msg);
+
+ /**
+ * Convert abstract message (IMessage) to abstract binary sms (IBinarySms)
+ * @param[in] msg - pointer to message to convert
+ * @throw ConversionException if conversion fail
+ */
+ static IBinarySmsPtr convertToBinarySms(IMessagePtr msg);
+
+ /**
+ * Convert abstract message (IMessage) to abstract Mms (IMms)
+ * @param[in] msg - pointer to message to convert
+ * @throw ConversionException if conversion fail
+ */
+ static IMmsPtr convertToMms(IMessagePtr msg);
+
+ /**
+ * Convert abstract message (IMessage) to abstract email (IEmail)
+ * @param[in] msg - pointer to message to convert
+ * @throw ConversionException if conversion fail
+ */
+ static IEmailPtr convertToEmail(IMessagePtr msg);
+};
+}
+}
+}
+#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 MessageFilter.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "MessageFilter.h"
+#include <dpl/log/log.h>
+#include <Commons/RegexUtils.h>
+#include <ctime>
+
+namespace {
+const time_t MKTIME_ERROR = static_cast<time_t>(-1);
+const int YEAR_OFFSET = 1900;
+}
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+MessageFilter::MessageFilter() :
+ m_msgIdCheck(false),
+ m_startTimeCheck(false),
+ m_endTimeCheck(false),
+ m_toCheck(false),
+ m_ccCheck(false),
+ m_bccCheck(false),
+ m_subjectCheck(false),
+ m_bodyCheck(false),
+ m_isReadCheck(false),
+ m_fromCheck(false),
+ m_messagePriorityCheck(false)
+{
+ LogDebug("message filter creation");
+}
+
+MessageFilter::~MessageFilter()
+{
+}
+
+void MessageFilter::setMsgId(const std::string& value)
+{
+ m_msgId = value;
+ m_msgIdCheck = true;
+}
+
+void MessageFilter::setTo(const Recipients& value)
+{
+ m_to = value;
+ m_toCheck = true;
+}
+
+void MessageFilter::setCc(const Recipients& value)
+{
+ m_cc = value;
+ m_ccCheck = true;
+}
+
+void MessageFilter::setBcc(const Recipients& value)
+{
+ m_bcc = value;
+ m_bccCheck = true;
+}
+
+void MessageFilter::setSubject(const std::string& value)
+{
+ m_subject = value;
+ m_subjectCheck = true;
+}
+
+void MessageFilter::setBody(const std::string& value)
+{
+ m_body = value;
+ m_bodyCheck = true;
+}
+
+void MessageFilter::setFrom(const string& value)
+{
+ m_from = value;
+ m_fromCheck = true;
+}
+
+void MessageFilter::setStartTime(const time_t& value)
+{
+ m_startTime = value;
+ m_startTimeCheck = true;
+}
+
+void MessageFilter::setEndTime(const time_t& value)
+{
+ m_endTime = value;
+ m_endTimeCheck = true;
+}
+
+void MessageFilter::setIsRead(bool value)
+{
+ m_isRead = value;
+ m_isReadCheck = true;
+}
+
+void MessageFilter::setMessagePriority(const MessagePriority::Priority& value)
+{
+ m_messagePriority = value;
+ m_messagePriorityCheck = true;
+}
+
+pcrecpp::RE MessageFilter::reCreate(const std::string& value) const
+{
+ // conversion example:
+ // ^$ <- (empty string)
+ // ^a$ <- a
+ // ^a.* <- a%
+ // .*a$ <- %a
+ // .*a.* <- %a%
+ // ^\..*a.* <- .%a%
+
+ string tmpRe;
+ if (!value.empty()) {
+ tmpRe = Commons::preparePercent(value);
+ }
+ return pcrecpp::RE(tmpRe);
+}
+
+bool MessageFilter::idCheck(const std::string& value) const
+{
+ if (m_msgIdCheck) {
+ pcrecpp::RE l_re = reCreate(m_msgId);
+ if (!l_re.FullMatch(value)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool MessageFilter::timeCheck(tm value) const
+{
+ if (value.tm_year > YEAR_OFFSET) {
+ value.tm_year -= YEAR_OFFSET;
+ }
+ time_t time = mktime(&value);
+ if (MKTIME_ERROR == time) {
+ return false;
+ }
+
+ return (!m_startTimeCheck ||
+ time >= m_startTime) && (!m_endTimeCheck || time <= m_endTime);
+}
+
+bool MessageFilter::bodyCheck(const std::string& value) const
+{
+ if (m_bodyCheck) {
+ pcrecpp::RE l_re = reCreate(m_body);
+ if (!l_re.FullMatch(value)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool MessageFilter::toCheck(const Recipients& value) const
+{
+ if (m_toCheck) {
+ return recipientCheck(m_to, value);
+ }
+ return true;
+}
+
+bool MessageFilter::ccCheck(const Recipients& value) const
+{
+ if (m_ccCheck) {
+ return recipientCheck(m_cc, value);
+ }
+ return true;
+}
+
+bool MessageFilter::bccCheck(const Recipients& value) const
+{
+ if (m_bccCheck) {
+ return recipientCheck(m_bcc, value);
+ }
+ return true;
+}
+
+bool MessageFilter::recipientCheck(const Recipients& filter,
+ const Recipients& value) const
+{
+ size_t vsize = value.getRecipientSize();
+
+ // every filter element must have at least one match
+ for (size_t i = 0; i < filter.getRecipientSize(); i++) {
+ pcrecpp::RE l_re = reCreate(filter.getRecipient(i));
+
+ bool match = false;
+
+ // go through all message recipients to find matching one
+ for (size_t v = 0; v < vsize; ++v) {
+ if (l_re.PartialMatch(value.getRecipient(v))) {
+ match = true;
+ break;
+ }
+ }
+
+ if (!match) {
+ // none of supplied message recipients was matching this filter element
+ return false;
+ }
+ }
+ return true;
+}
+
+bool MessageFilter::fromCheck(const std::string& value) const
+{
+ if (m_fromCheck) {
+ pcrecpp::RE l_re = reCreate(m_from);
+ if (!l_re.FullMatch(value)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool MessageFilter::subjectCheck(const std::string & value) const
+{
+ if (m_subjectCheck) {
+ pcrecpp::RE l_re = reCreate(m_subject);
+ if (!l_re.FullMatch(value)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool MessageFilter::isReadCheck(bool value) const
+{
+ if (m_isReadCheck) {
+ return (m_isRead == value);
+ }
+ return true;
+}
+
+bool MessageFilter::priorityCheck(MessagePriority::Priority value) const
+{
+ if (m_messagePriorityCheck) {
+ return (m_messagePriority == value);
+ }
+ return true;
+}
+
+bool MessageFilter::isValid() const
+{
+ if (m_msgIdCheck || m_startTimeCheck || m_endTimeCheck || m_toCheck ||
+ m_ccCheck || m_bccCheck || m_subjectCheck || m_bodyCheck || m_isRead ||
+ m_isReadCheck || m_fromCheck || m_messagePriorityCheck) {
+ return true;
+ }
+
+ return false;
+}
+
+bool MessageFilter::compare(const ISmsPtr & msg) const
+{
+ if (m_ccCheck ||
+ m_bccCheck ||
+ m_subjectCheck ||
+ m_messagePriorityCheck) {
+ // sms do not support this properties, so find has no effect
+ return false;
+ }
+
+ return (
+ idCheck(msg->getId()) &&
+ bodyCheck(msg->getBody()) &&
+ toCheck(msg->getToRecipients()) &&
+ isReadCheck(msg->isRead()) &&
+ timeCheck(msg->getDateTime()) &&
+ fromCheck(msg->getFrom())
+ );
+}
+
+bool MessageFilter::compare(const IMmsPtr & msg) const
+{
+ if (m_ccCheck ||
+ m_bccCheck ||
+ m_messagePriorityCheck) {
+ // mms do not support this properties, so find has no effect
+ return false;
+ }
+
+ return (
+ idCheck(msg->getId()) &&
+ subjectCheck(msg->getSubject()) &&
+ bodyCheck(msg->getBody()) &&
+ toCheck(msg->getToRecipients()) &&
+ isReadCheck(msg->isRead()) &&
+ timeCheck(msg->getDateTime()) &&
+ fromCheck(msg->getFrom())
+ );
+}
+
+bool MessageFilter::compare(const IEmailPtr & msg) const
+{
+ return (
+ idCheck(msg->getId()) &&
+ subjectCheck(msg->getSubject()) &&
+ bodyCheck(msg->getBody()) &&
+ fromCheck(msg->getFrom()) &&
+ toCheck(msg->getToRecipients()) &&
+ ccCheck(msg->getCcRecipients()) &&
+ bccCheck(msg->getBccRecipients()) &&
+ isReadCheck(msg->isRead()) &&
+ priorityCheck(msg->getPriority()) &&
+ timeCheck(msg->getDateTime())
+ );
+}
+}}
+}
--- /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 MessageFilter.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef MESSAGEFILTER_H
+#define MESSAGEFILTER_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <pcrecpp.h>
+
+#include "MessagePriority.h"
+#include "Recipient.h"
+#include "ISms.h"
+#include "IMms.h"
+#include "IEmail.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class MessageFilter;
+
+typedef DPL::SharedPtr<MessageFilter> MessageFilterPtr;
+
+class MessageFilter
+{
+ private: // fields
+
+ std::string m_msgId;
+ bool m_msgIdCheck;
+
+ time_t m_startTime;
+ bool m_startTimeCheck;
+
+ time_t m_endTime;
+ bool m_endTimeCheck;
+
+ Recipients m_to;
+ bool m_toCheck;
+
+ Recipients m_cc;
+ bool m_ccCheck;
+
+ Recipients m_bcc;
+ bool m_bccCheck;
+
+ std::string m_subject;
+ bool m_subjectCheck;
+
+ std::string m_body;
+ bool m_bodyCheck;
+
+ bool m_isRead;
+ bool m_isReadCheck;
+
+ std::string m_from;
+ bool m_fromCheck;
+
+ MessagePriority::Priority m_messagePriority;
+ bool m_messagePriorityCheck;
+
+ public: // methods
+
+ /**
+ * constructor of messageFilter
+ */
+ MessageFilter();
+
+ virtual ~MessageFilter();
+
+ void setMsgId(const std::string& value);
+
+ void setTo(const Recipients& value); // the same as destination address
+
+ void setCc(const Recipients& value);
+
+ void setBcc(const Recipients& value);
+
+ void setSubject(const std::string& value);
+
+ void setBody(const std::string& value);
+
+ void setFrom(const std::string& value); //email account from email was sent
+
+ void setStartTime(const time_t& value);
+
+ void setEndTime(const time_t& value);
+
+ void setIsRead(bool value);
+
+ void setMessagePriority(const MessagePriority::Priority& value);
+
+ bool isValid() const;
+
+ bool compare(const ISmsPtr& msg) const;
+
+ bool compare(const IMmsPtr& msg) const;
+
+ bool compare(const IEmailPtr& msg) const;
+
+ private:
+ pcrecpp::RE reCreate(const std::string& value) const;
+
+ bool idCheck(const std::string& value) const;
+
+ bool timeCheck(tm value) const;
+
+ bool bodyCheck(const std::string& value) const;
+
+ bool toCheck(const Recipients& value) const;
+
+ bool ccCheck(const Recipients& value) const;
+
+ bool bccCheck(const Recipients& value) const;
+
+ bool recipientCheck(const Recipients& filter,
+ const Recipients& value) const;
+
+ bool fromCheck(const std::string& value) const;
+
+ bool subjectCheck(const std::string& value) const;
+
+ bool isReadCheck(bool value) const;
+
+ bool priorityCheck(MessagePriority::Priority value) const;
+};
+}
+}
+}
+#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 MessagePriority.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "MessagePriority.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+MessagePriority::MessagePriority() :
+ m_priority(NORMAL),
+ m_validPriority(false)
+{
+}
+
+void MessagePriority::setPriority(MessagePriority::Priority value)
+{
+ m_priority = value;
+ m_validPriority = false;
+}
+
+MessagePriority::Priority MessagePriority::getPriority() const
+{
+ return m_priority;
+}
+
+bool MessagePriority::isPriorityValid() const
+{
+ return m_validPriority;
+}
+
+void MessagePriority::setPriorityValid(bool state)
+{
+ m_validPriority = state;
+}
+}}
+}
--- /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 MessagePriority.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef MESSAGEPRIORITY_H
+#define MESSAGEPRIORITY_H
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class MessagePriority
+{
+ public:
+ enum Priority
+ {
+ LOW,
+ NORMAL,
+ HIGH
+ };
+
+ public:
+ MessagePriority();
+
+ /**
+ * setter of MessagePriority value
+ */
+ void setPriority(Priority value);
+
+ /**
+ * getter of MessagePriority value
+ */
+ Priority getPriority() const;
+
+ /**
+ * check MessagePriority validity
+ * */
+ bool isPriorityValid() const;
+
+ /**
+ * set MessagePriority validity
+ * */
+ void setPriorityValid(bool state);
+
+ private:
+ /**
+ * MessagePriority value
+ */
+ Priority m_priority;
+
+ /**
+ * information if abstract message MessagePriority has been changed and need update
+ * in low level
+ */
+ bool m_validPriority;
+};
+}
+}
+}
+#endif // MESSAGEPRIORITY_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 MmsSlide.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "MmsSlide.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+MmsSlide::MmsSlide() : m_duration(0)
+{
+}
+
+MmsSlide::~MmsSlide()
+{
+}
+
+unsigned long MmsSlide::getDuration() const
+{
+ return m_duration;
+}
+
+void MmsSlide::setDuration(Ulong duration)
+{
+ m_duration = duration;
+}
+
+const std::string& MmsSlide::getImageFilename() const
+{
+ return m_image.getFilename();
+}
+
+void MmsSlide::setImageFilename(const std::string& filename)
+{
+ m_image.setFilename(filename);
+}
+
+unsigned long MmsSlide::getImageBegin() const
+{
+ return m_image.getStartTime();
+}
+
+void MmsSlide::setImageBegin(Ulong value)
+{
+ m_image.setStartTime(value);
+}
+
+unsigned long MmsSlide::getImageEnd() const
+{
+ return m_image.getEndTime();
+}
+
+void MmsSlide::setImageEnd(Ulong value)
+{
+ m_image.setEndTime(value);
+}
+
+const std::string& MmsSlide::getAudioFilename() const
+{
+ return m_audio.getFilename();
+}
+
+void MmsSlide::setAudioFilename(const std::string& filename)
+{
+ m_audio.setFilename(filename);
+}
+
+unsigned long MmsSlide::getAudioBegin() const
+{
+ return m_audio.getStartTime();
+}
+
+void MmsSlide::setAudioBegin(Ulong value)
+{
+ m_audio.setStartTime(value);
+}
+
+unsigned long MmsSlide::getAudioEnd() const
+{
+ return m_audio.getEndTime();
+}
+
+void MmsSlide::setAudioEnd(Ulong value)
+{
+ m_audio.setEndTime(value);
+}
+
+const std::string& MmsSlide::getTextFilename() const
+{
+ return m_text.getFilename();
+}
+
+void MmsSlide::setTextFilename(const std::string& filename)
+{
+ m_text.setFilename(filename);
+}
+
+unsigned long MmsSlide::getTextBegin() const
+{
+ return m_text.getStartTime();
+}
+
+void MmsSlide::setTextBegin(Ulong value)
+{
+ m_text.setStartTime(value);
+}
+
+unsigned long MmsSlide::getTextEnd() const
+{
+ return m_text.getEndTime();
+}
+
+void MmsSlide::setTextEnd(Ulong value)
+{
+ m_text.setEndTime(value);
+}
+
+const std::string& MmsSlide::getVideoFilename() const
+{
+ return m_video.getFilename();
+}
+
+void MmsSlide::setVideoFilename(const std::string& filename)
+{
+ m_video.setFilename(filename);
+}
+
+unsigned long MmsSlide::getVideoBegin() const
+{
+ return m_video.getStartTime();
+}
+
+void MmsSlide::setVideoBegin(Ulong value)
+{
+ m_video.setStartTime(value);
+}
+
+unsigned long MmsSlide::getVideoEnd() const
+{
+ return m_video.getEndTime();
+}
+
+void MmsSlide::setVideoEnd(Ulong value)
+{
+ m_video.setEndTime(value);
+}
+}}
+}
--- /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 MmsSlide.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef MMS_SLIDE_H
+#define MMS_SLIDE_H
+
+#include "IMmsSlide.h"
+#include "MmsSlideProperty.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class MmsSlide : public virtual IMmsSlide
+{
+ public:
+ MmsSlide();
+
+ virtual ~MmsSlide();
+
+ //duration
+ virtual Ulong getDuration() const;
+ virtual void setDuration(Ulong duration);
+
+ //image
+ virtual const std::string& getImageFilename() const;
+ virtual void setImageFilename(const std::string& filename);
+ virtual Ulong getImageBegin() const;
+ virtual void setImageBegin(Ulong value);
+ virtual Ulong getImageEnd() const;
+ virtual void setImageEnd(Ulong value);
+
+ //audio
+ virtual const std::string& getAudioFilename() const;
+ virtual void setAudioFilename(const std::string& filename);
+ virtual Ulong getAudioBegin() const;
+ virtual void setAudioBegin(Ulong value);
+ virtual Ulong getAudioEnd() const;
+ virtual void setAudioEnd(Ulong value);
+
+ //text
+ virtual const std::string& getTextFilename() const;
+ virtual void setTextFilename(const std::string& filename);
+ virtual Ulong getTextBegin() const;
+ virtual void setTextBegin(Ulong value);
+ virtual Ulong getTextEnd() const;
+ virtual void setTextEnd(Ulong value);
+
+ //video
+ virtual const std::string& getVideoFilename() const;
+ virtual void setVideoFilename(const std::string& filename);
+ virtual Ulong getVideoBegin() const;
+ virtual void setVideoBegin(Ulong value);
+ virtual Ulong getVideoEnd() const;
+ virtual void setVideoEnd(Ulong value);
+
+ private:
+ Ulong m_duration;
+
+ MmsSlideProperty m_image;
+ MmsSlideProperty m_audio;
+ MmsSlideProperty m_text;
+ MmsSlideProperty m_video;
+};
+}
+}}
+#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 MmsSlideProperty.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "MmsSlideProperty.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+MmsSlideProperty::MmsSlideProperty() :
+ m_filename(""),
+ m_startTime(0),
+ m_endTime(0)
+{
+}
+
+MmsSlideProperty::~MmsSlideProperty()
+{
+}
+
+const std::string& MmsSlideProperty::getFilename() const
+{
+ return m_filename;
+}
+
+unsigned long MmsSlideProperty::getStartTime() const
+{
+ return m_startTime;
+}
+
+unsigned long MmsSlideProperty::getEndTime() const
+{
+ return m_endTime;
+}
+
+void MmsSlideProperty::setFilename(const std::string& value)
+{
+ m_filename = value;
+}
+
+void MmsSlideProperty::setStartTime(Ulong value)
+{
+ m_startTime = value;
+}
+
+void MmsSlideProperty::setEndTime(Ulong value)
+{
+ m_endTime = value;
+}
+}}
+}
--- /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 MmsSlideProperty.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef MMS_SLIDE_PROPERTY_H
+#define MMS_SLIDE_PROPERTY_H
+
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class MmsSlideProperty
+{
+ private:
+ typedef unsigned long Ulong;
+
+ private:
+
+ std::string m_filename;
+
+ Ulong m_startTime;
+
+ Ulong m_endTime;
+
+ public:
+
+ MmsSlideProperty();
+
+ virtual ~MmsSlideProperty();
+
+ /**
+ * getters for filename
+ * */
+ virtual const std::string& getFilename() const;
+
+ /**
+ * getters for startTime
+ * */
+ virtual Ulong getStartTime() const;
+
+ /**
+ * getters for endTime
+ * */
+ virtual Ulong getEndTime() const;
+
+ /**
+ * setters for filename
+ * */
+ virtual void setFilename(const std::string& value);
+
+ /**
+ * setters for start time
+ * */
+ virtual void setStartTime(Ulong value);
+
+ /**
+ * setters for end time
+ * */
+ virtual void setEndTime(Ulong value);
+};
+}
+}
+}
+#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 MmsSlides.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "MmsSlides.h"
+#include "MmsSlide.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+MmsSlides::MmsSlides() : m_valid(false)
+{
+}
+
+MmsSlides::~MmsSlides()
+{
+}
+
+bool MmsSlides::checkSlidesValidity() const
+{
+ return m_valid;
+}
+
+void MmsSlides::setSlidesValidity(bool state)
+{
+ m_valid = state;
+}
+
+void MmsSlides::setSlides(const std::vector<IMmsSlidePtr>& slides)
+{
+ m_slides = slides;
+}
+
+IMmsSlidePtr MmsSlides::createEmptySlide() const
+{
+ IMmsSlide* slide = NULL;
+ slide = new MmsSlide;
+
+ return IMmsSlidePtr(slide);
+}
+
+void MmsSlides::addSlide(const IMmsSlidePtr& slide)
+{
+ m_slides.push_back(slide);
+}
+
+size_t MmsSlides::getSlideCount() const
+{
+ return m_slides.size();
+}
+
+IMmsSlidePtr MmsSlides::getSlide(size_t nb) const
+{
+ if (nb >= m_slides.size()) {
+ //TODO -exception?
+ }
+ return m_slides[nb];
+}
+
+std::vector<IMmsSlidePtr> MmsSlides::getSlides() const
+{
+ return m_slides;
+}
+
+void MmsSlides::replaceSlide(size_t pos,
+ const IMmsSlidePtr& slide)
+{
+ if (pos >= m_slides.size()) {
+ //TODO
+ } else {
+ //m_slides.erase(m_slides.begin()+pos);
+ m_slides[pos] = slide;
+ }
+}
+
+void MmsSlides::removeSlide(size_t /*pos*/)
+{
+}
+
+}
+}
+}
--- /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 MmsSlides.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef MMS_SLIDES_H
+#define MMS_SLIDES_H
+
+#include "IMmsSlides.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class MmsSlides :
+ virtual public IMmsSlides
+{
+ public:
+
+ MmsSlides();
+
+ virtual ~MmsSlides();
+
+ virtual IMmsSlidePtr createEmptySlide() const;
+
+ virtual bool checkSlidesValidity() const;
+
+ virtual void setSlidesValidity(bool state);
+
+ virtual void setSlides(const std::vector<IMmsSlidePtr>& slides);
+
+ virtual void addSlide(const IMmsSlidePtr& slide);
+
+ virtual size_t getSlideCount() const;
+
+ virtual IMmsSlidePtr getSlide(size_t nb) const;
+
+ virtual std::vector<IMmsSlidePtr> getSlides() const;
+
+ virtual void replaceSlide(size_t pos,
+ const IMmsSlidePtr& slide);
+
+ virtual void removeSlide(size_t pos);
+
+ private:
+
+ bool m_valid;
+
+ std::vector<IMmsSlidePtr> m_slides;
+};
+}
+}}
+#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 Recipient.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <algorithm>
+#include <sstream>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "Recipient.h"
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+
+
+namespace {
+const static string emptyString;
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+Recipients::Recipients() :
+ m_validRecipients(false)
+{
+}
+
+Recipients::Recipients(const vector<string>& value) :
+ m_validRecipients(false)
+{
+ m_recipients = value;
+}
+
+Recipients::~Recipients()
+{
+}
+
+bool Recipients::isValid() const
+{
+ return m_validRecipients;
+}
+
+void Recipients::setValid(bool state)
+{
+ m_validRecipients = state;
+}
+
+void Recipients::setRecipients(const vector<string>& value)
+{
+ m_recipients = value;
+ m_validRecipients = false;
+}
+
+void Recipients::setRecipients(const std::string& value)
+{
+ vector<string> tmp = split(value, ';');
+ setRecipients(tmp);
+}
+
+void Recipients::setRecipient(const size_t index,
+ const string& value)
+{
+ if (index >= m_recipients.size()) {
+ Throw(OutOfRangeException);
+ return;
+ }
+ m_recipients[index] = value;
+ m_validRecipients = false;
+}
+
+void Recipients::setRecipientWithExpand(const size_t index,
+ const std::string& value)
+{
+ if (index >= m_recipients.size()) {
+ m_recipients.resize(index + 1, emptyString);
+ }
+ m_recipients[index] = value;
+ m_validRecipients = false;
+}
+
+vector<string> Recipients::getRecipients() const
+{
+ return m_recipients;
+}
+
+const vector<string>& Recipients::getRecipientsRef() const
+{
+ return m_recipients;
+}
+
+string Recipients::getRecipient(const size_t index) const
+{
+ if (index >= m_recipients.size()) {
+ Throw(OutOfRangeException);
+ return "";
+ }
+ return m_recipients[index];
+}
+
+void Recipients::appendRecipient(const string & value)
+{
+ vector<string> tmp = split(value, ';');
+ m_recipients.insert(m_recipients.end(), tmp.begin(), tmp.end());
+ m_validRecipients = false;
+}
+
+void Recipients::removeRecipient(const size_t position)
+{
+ if (position >= m_recipients.size()) {
+ Throw(Commons::OutOfRangeException);
+ } else {
+ m_recipients.erase(m_recipients.begin() + position);
+ m_validRecipients = false;
+ }
+}
+
+void Recipients::removeRecipient(const string & value)
+{
+ m_recipients.erase(
+ remove(m_recipients.begin(), m_recipients.end(), value),
+ m_recipients.end());
+ m_validRecipients = false;
+}
+
+string Recipients::join(char delimiter) const
+{
+ string retVal;
+ for (size_t i = 0; i < m_recipients.size(); i++) {
+ retVal += m_recipients[i] + delimiter;
+ }
+ return retVal;
+}
+
+vector<string> Recipients::split(const string& input,
+ char delimiter)
+{
+ vector<string> ret;
+ stringstream stream(input);
+ string item;
+ while (getline(stream, item, delimiter)) {
+ ret.push_back(item);
+ }
+ return ret;
+}
+
+size_t Recipients::getRecipientSize() const
+{
+ return m_recipients.size();
+}
+
+bool Recipients::operator !=(const Recipients& arg) const
+{
+ if (m_recipients == arg.m_recipients) {
+ return true;
+ }
+ return false;
+}
+
+Recipients & Recipients::operator +=(const Recipients& val)
+{
+ const vector<string>& tmp = val.getRecipientsRef();
+ m_recipients.insert(m_recipients.end(), tmp.begin(), tmp.end());
+ m_validRecipients = false;
+ return *this;
+}
+
+Recipients & Recipients::operator -=(const Recipients& val)
+{
+ //check if recipients are inside list
+ vector<string> l_recipients = m_recipients;
+ vector<string> l_toDelete = val.getRecipients();
+ sort(l_recipients.begin(), l_recipients.end());
+ sort(l_toDelete.begin(), l_toDelete.end());
+ if (!includes(l_recipients.begin(), l_recipients.end(), l_toDelete.begin(),
+ l_toDelete.end())) {
+ LogError("lack of recipient to delete from main variable");
+ Throw(Commons::InvalidArgumentException);
+ }
+ //delete recipients
+ vector<string>::const_iterator it = l_toDelete.begin();
+ const vector<string>::const_iterator endIt = l_toDelete.end();
+ while (it != endIt) {
+ m_recipients.erase(
+ remove(m_recipients.begin(),
+ m_recipients.end(), *it), m_recipients.end());
+ ++it;
+ }
+ m_validRecipients = false;
+ return *this;
+}
+}}
+}
--- /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 Recipient.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef RECIPIENT_H
+#define RECIPIENT_H
+
+#include "IMessagingTypes.h"
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class Recipients
+{
+ private: // fields
+
+ /**
+ * recipient value
+ */
+ std::vector<std::string> m_recipients;
+
+ bool m_validRecipients;
+
+ public: // methods
+
+ Recipients();
+
+ explicit Recipients(const std::vector<std::string>& value);
+
+ virtual ~Recipients();
+
+ /**
+ * information if abstract message to recipient has been changed and
+ * need update in low level
+ */
+ bool isValid() const;
+
+ void setValid(bool state);
+
+ /**
+ * setter of recipient value
+ */
+ void setRecipients(const std::vector<std::string>& value);
+
+ void setRecipients(const std::string& value);
+
+ void setRecipient(const size_t index,
+ const std::string& value);
+
+ void setRecipientWithExpand(const size_t index,
+ const std::string& value);
+
+ /**
+ * getter of recipient value
+ */
+ std::vector<std::string> getRecipients() const;
+
+ const std::vector<std::string>& getRecipientsRef() const;
+
+ std::string getRecipient(const size_t index) const;
+
+ void appendRecipient(const std::string & value);
+
+ void removeRecipient(const size_t position);
+
+ void removeRecipient(const std::string & value);
+
+ size_t getRecipientSize() const;
+
+ bool operator !=(const Recipients& arg) const;
+
+ Recipients & operator +=(const Recipients& val);
+
+ Recipients & operator -=(const Recipients& val);
+
+ std::string join(char delimiter = ';') const;
+
+ private:
+
+ std::vector<std::string> split(const std::string& input,
+ char delimiter);
+};
+
+typedef DPL::SharedPtr<Recipients> RecipientsPtr;
+}
+}
+}
+#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 ReqReceiverMessage.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "ReqReceiverMessage.h"
+#include <vector>
+#include <dpl/singleton_impl.h>
+#include <Commons/Exception.h>
+#include "IMessaging.h"
+#include "IMessage.h"
+
+using namespace std;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+IMPLEMENT_SINGLETON(WrtDeviceApis::Messaging::Api::ReqReceiverMessage)
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+
+ReqReceiverMessage::ReqReceiverMessage() :
+ EventSendMessageReqReceiver(Commons::ThreadEnum::MESSAGING_THREAD),
+ EventUpdateMessageReqReceiver(Commons::ThreadEnum::MESSAGING_THREAD),
+ EventDeleteMessageReqReceiver(Commons::ThreadEnum::MESSAGING_THREAD),
+ EventFindMessageReqReceiver(Commons::ThreadEnum::MESSAGING_THREAD)
+{
+ LogDebug("create receiver for messaging");
+}
+
+ReqReceiverMessage::~ReqReceiverMessage()
+{
+}
+
+void ReqReceiverMessage::sendMessage(const EventSendMessagePtr& event)
+{
+ LogDebug("enter");
+ EventSendMessageReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::updateMessage(const EventUpdateMessagePtr& event)
+{
+ LogDebug("enter");
+ EventUpdateMessageReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::deleteMessage(const EventDeleteMessagePtr& event)
+{
+ LogDebug("enter");
+ EventDeleteMessageReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::findMessage(const EventFindMessagePtr& event)
+{
+ LogDebug("enter");
+ EventFindMessageReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventSendMessagePtr& event)
+{
+ LogDebug("enter");
+
+ Try {
+ IMessagePtr msg = event->getMessage();
+ //this prevents calling BONDI, WAC2.0 callback immidiately after leaving this function
+ //callback will be called after receving Commons callback.
+ msg->setRequestReceiver(this);
+ msg->setSendMessageEvent(event);
+ if (!event->checkCancelled()) {
+ event->setCancelAllowed(false);
+ event->switchToManualAnswer();
+ msg->send();
+ } else {
+ event->setCancelAllowed(true);
+ }
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ Commons::EventRequestReceiver< EventSendMessage >::ManualAnswer(event);
+ }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventUpdateMessagePtr& event)
+{
+ LogDebug("enter");
+
+ Try {
+ IMessagePtr msg = event->msg;
+ if (!event->checkCancelled()) {
+ event->setCancelAllowed(false);
+ msg->update(true);
+ } else {
+ event->setCancelAllowed(true);
+ }
+ }
+ Catch(Commons::PlatformException) {
+ LogError("Commons exception");
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventDeleteMessagePtr& event)
+{
+ LogDebug("enter");
+
+ Try {
+ IMessagePtr msg = event->msg;
+ msg->remove();
+ }
+ Catch(Commons::PlatformException) {
+ LogError("Commons exception");
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventFindMessagePtr& event)
+{
+ LogDebug("enter");
+
+ Try {
+ if (!event->checkCancelled()) {
+ vector<IMessagePtr> msgs;
+ for (size_t i = 0; i < event->folderTypes.size(); i++) {
+ vector<IMessagePtr> tmp =
+ IMessaging::getInstance().findMessages(
+ event->messageTypes,
+ event->folderTypes[i],
+ event->messageFilter);
+ msgs.insert(msgs.end(), tmp.begin(), tmp.end());
+ }
+ event->msgs = msgs;
+ }
+ //this is only searching so can be cancelled at any time
+ event->setCancelAllowed(true);
+ }
+ Catch(Commons::PlatformException) {
+ LogError("Commons exception");
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ }
+}
+}}
+}
--- /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 ReqReceiverMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef REQRECEIVERMESSAGE_H
+#define REQRECEIVERMESSAGE_H
+
+#include <dpl/singleton.h>
+
+#include "EventSendMessage.h"
+#include "EventUpdateMessage.h"
+#include "EventDeleteMessage.h"
+#include "EventFindMessage.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+typedef Commons::EventRequestReceiver<EventSendMessage>
+EventSendMessageReqReceiver;
+typedef Commons::EventRequestReceiver<EventUpdateMessage>
+EventUpdateMessageReqReceiver;
+typedef Commons::EventRequestReceiver<EventDeleteMessage>
+EventDeleteMessageReqReceiver;
+typedef Commons::EventRequestReceiver<EventFindMessage>
+EventFindMessageReqReceiver;
+
+class ReqReceiverMessage : public EventSendMessageReqReceiver,
+ public EventUpdateMessageReqReceiver,
+ public EventDeleteMessageReqReceiver,
+ public EventFindMessageReqReceiver
+{
+ public:
+ ReqReceiverMessage();
+
+ ~ReqReceiverMessage();
+
+ void sendMessage(const EventSendMessagePtr& event);
+
+ void updateMessage(const EventUpdateMessagePtr& event);
+
+ void deleteMessage(const EventDeleteMessagePtr& event);
+
+ void findMessage(const EventFindMessagePtr& event);
+
+ protected:
+ void OnRequestReceived(const EventSendMessagePtr& event);
+
+ void OnRequestReceived(const EventUpdateMessagePtr& event);
+
+ void OnRequestReceived(const EventDeleteMessagePtr& event);
+
+ void OnRequestReceived(const EventFindMessagePtr& event);
+};
+
+typedef DPL::Singleton<ReqReceiverMessage> ReqReceiverMessageSingleton;
+}
+}
+}
+#endif // REQRECEIVERMESSAGE_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 SourceAddress.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <dpl/log/log.h>
+#include "Commons/Exception.h"
+#include "SourceAddress.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+SourceAddress::SourceAddress() :
+ m_validSourceAddress(false)
+{
+}
+
+SourceAddress::~SourceAddress()
+{
+}
+
+void SourceAddress::setSourceAddressValidity(bool state)
+{
+ m_validSourceAddress = state;
+}
+
+bool SourceAddress::getSourceAddressValidity() const
+{
+ return m_validSourceAddress;
+}
+
+std::string SourceAddress::getSourceAddress() const
+{
+ return m_sourceAddress;
+}
+
+void SourceAddress::setSourceAddress(const Recipients& value)
+{
+ if (value.getRecipientSize() != 1) {
+ LogError("wrong source address value");
+ Throw(Commons::InvalidArgumentException);
+ }
+ m_sourceAddress = value.getRecipient(0);
+ m_validSourceAddress = false;
+}
+
+void SourceAddress::setSourceAddress(const std::string& value)
+{
+ m_sourceAddress = value;
+ m_validSourceAddress = false;
+}
+}}
+}
--- /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 SourceAddress.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef SOURCEADDRESS_H
+#define SOURCEADDRESS_H
+
+#include "Recipient.h"
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class SourceAddress
+{
+ private: // fields
+
+ std::string m_sourceAddress;
+
+ bool m_validSourceAddress;
+
+ public:
+
+ SourceAddress();
+
+ virtual ~SourceAddress();
+
+ void setSourceAddressValidity(bool state);
+
+ bool getSourceAddressValidity() const;
+
+ std::string getSourceAddress() const;
+
+ void setSourceAddress(const Recipients& value);
+
+ void setSourceAddress(const std::string& value);
+};
+}
+}
+}
+#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 Subject.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "Subject.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+Subject::Subject() :
+ m_subject(""),
+ m_validSubject(false)
+{
+}
+
+Subject::~Subject()
+{
+}
+
+void Subject::setSubject(const string& value)
+{
+ m_validSubject = false;
+ m_subject = value;
+}
+
+string Subject::getSubject() const
+{
+ return m_subject;
+}
+
+const std::string& Subject::getSubjectRef() const
+{
+ return m_subject;
+}
+
+bool Subject::isSubjectValid() const
+{
+ return m_validSubject;
+}
+
+void Subject::setSubjectValidity(bool state)
+{
+ m_validSubject = state;
+}
+}}
+}
--- /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 Subject.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef SUBJECT_H
+#define SUBJECT_H
+
+#include <string>
+#include "IMessagingTypes.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class Subject
+{
+ private: // fields
+ /**
+ * abstract subject value of message
+ */
+ std::string m_subject;
+
+ /**
+ * information if abstract message body has been changed and need update
+ * in low level
+ */
+ bool m_validSubject;
+
+ public: // methods
+
+ Subject();
+
+ virtual ~Subject();
+
+ /**
+ * setter of subject value
+ */
+ void setSubject(const std::string& value);
+
+ /**
+ * getter of subject value
+ */
+ std::string getSubject() const;
+
+ /**
+ * getter of subject value
+ */
+ const std::string& getSubjectRef() const;
+
+ /**
+ * check validity state
+ */
+ bool isSubjectValid() const;
+
+ /**
+ * setter for validity state
+ */
+ void setSubjectValidity(bool state);
+};
+}
+}
+}
+#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 ToRecipient.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <dpl/log/log.h>
+#include "ToRecipient.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+ToRecipient::ToRecipient() :
+ m_toRecipients(new Recipients())
+{
+}
+
+ToRecipient::~ToRecipient()
+{
+}
+
+void ToRecipient::setToValidity(bool state)
+{
+ m_toRecipients->setValid(state);
+}
+
+bool ToRecipient::getToValidity() const
+{
+ return m_toRecipients->isValid();
+}
+
+Recipients ToRecipient::getToRecipients() const
+{
+ return *m_toRecipients;
+}
+
+RecipientsPtr ToRecipient::getToRecipientsPtr() const
+{
+ return m_toRecipients;
+}
+
+void ToRecipient::appendToRecipients(const string & value)
+{
+ m_toRecipients->appendRecipient(value);
+}
+
+void ToRecipient::appendToRecipients(const Recipients& value)
+{
+ LogDebug("enter, recipientCount=" << value.getRecipientSize());
+ *m_toRecipients += value;
+}
+
+void ToRecipient::removeToRecipients(const Recipients& value)
+{
+ *m_toRecipients -= value;
+}
+
+void ToRecipient::setToRecipients(const Recipients& value)
+{
+ *m_toRecipients = value;
+}
+}}
+}
--- /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 ToRecipient.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef TORECIPIENT_H
+#define TORECIPIENT_H
+
+#include "Recipient.h"
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+class ToRecipient
+{
+ private: // fields
+
+ RecipientsPtr m_toRecipients;
+
+ public:
+
+ ToRecipient();
+
+ virtual ~ToRecipient();
+
+ void setToValidity(bool state);
+
+ bool getToValidity() const;
+
+ Recipients getToRecipients() const;
+
+ RecipientsPtr getToRecipientsPtr() const;
+
+ void appendToRecipients(const std::string & value);
+
+ void appendToRecipients(const Recipients& value);
+
+ void removeToRecipients(const Recipients& value);
+
+ void setToRecipients(const Recipients& value);
+};
+}
+}
+}
+#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 ValidityPeriodHours.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "ValidityPeriodHours.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+ValidityPeriodHours::ValidityPeriodHours() :
+ m_validityPeriodHours(0),
+ m_validValidityPeriodHours(false)
+{
+}
+
+ValidityPeriodHours::~ValidityPeriodHours()
+{
+}
+
+void ValidityPeriodHours::setValidityPeriodHours(int value)
+{
+ m_validityPeriodHours = value;
+ m_validValidityPeriodHours = false;
+}
+
+int ValidityPeriodHours::getValidityPeriodHours() const
+{
+ return m_validityPeriodHours;
+}
+
+bool ValidityPeriodHours::isValidityPeriodHoursValid() const
+{
+ return m_validValidityPeriodHours;
+}
+
+void ValidityPeriodHours::setValidityPeriodHoursValidity(bool state)
+{
+ m_validValidityPeriodHours = state;
+}
+}}
+}
--- /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 ValidityPeriodHours.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef VALIDITYPERIODHOURS_H
+#define VALIDITYPERIODHOURS_H
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class ValidityPeriodHours
+{
+ private: // fields
+
+ /**
+ * ValidityPeriodHours value
+ */
+ int m_validityPeriodHours;
+
+ /**
+ * information if abstract message ValidityPeriodHours has been changed and need update
+ * in low level
+ */
+ bool m_validValidityPeriodHours;
+
+ public: // methods
+
+ ValidityPeriodHours();
+
+ virtual ~ValidityPeriodHours();
+
+ /**
+ * setter of ValidityPeriodHours value
+ */
+ void setValidityPeriodHours(int value);
+
+ /**
+ * getter of ValidityPeriodHours value
+ */
+ int getValidityPeriodHours() const;
+
+ /**
+ * check ValidityPeriodHours validity
+ * */
+ bool isValidityPeriodHoursValid() const;
+
+ /**
+ * set ValidityPeriodHours validity
+ * */
+ void setValidityPeriodHoursValidity(bool state);
+};
+}
+}
+}
+#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 VirtualMessage.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <dpl/log/log.h>
+#include "Commons/Exception.h"
+#include "IMessage.h"
+#include "VirtualMessage.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+VirtualMessage::VirtualMessage() :
+ IMessage(VIRTUAL_MESSAGE, "")
+{
+}
+
+VirtualMessage::~VirtualMessage()
+{
+}
+
+void VirtualMessage::send()
+{
+}
+
+void VirtualMessage::sendCancel()
+{
+}
+
+void VirtualMessage::update(bool /*draftsOnly*/)
+{
+}
+
+void VirtualMessage::readAllData()
+{
+}
+
+void VirtualMessage::moveToFolder(const FolderType /*newFolder*/)
+{
+}
+
+void VirtualMessage::moveToFolder(const std::string& /*newFolder*/)
+{
+}
+
+void VirtualMessage::copyToFolder(const FolderType /*newFolder*/)
+{
+}
+
+void VirtualMessage::copyToFolder(const std::string& /*newFolder*/)
+{
+}
+
+void VirtualMessage::remove()
+{
+}
+}}
+}
--- /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 VirtualMessage.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef IVIRTUALMESSAGE_H
+#define IVIRTUALMESSAGE_H
+
+#include <string>
+#include <ctime>
+#include <dpl/shared_ptr.h>
+#include "IMessage.h"
+#include "Subject.h"
+#include "CcRecipient.h"
+#include "BccRecipient.h"
+#include "Attachments.h"
+#include "CallbackNumber.h"
+#include "ValidityPeriodHours.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace Api {
+//--------------------------------------------------------------------------
+
+class VirtualMessage;
+typedef DPL::SharedPtr<VirtualMessage> VirtualMessagePtr;
+
+class VirtualMessage :
+ public IMessage,
+ public CcRecipient,
+ public BccRecipient,
+ public Attachments
+{
+ public:
+ VirtualMessage();
+
+ virtual ~VirtualMessage();
+
+ void send();
+
+ void sendCancel();
+
+ void update(bool draftsOnly = false);
+
+ void readAllData();
+
+ void moveToFolder(const FolderType newFolder);
+
+ void moveToFolder(const std::string& newFolder);
+
+ void copyToFolder(const FolderType newFolder);
+
+ void copyToFolder(const std::string& newFolder);
+
+ void remove();
+};
+}
+}
+}
+#endif
--- /dev/null
+get_current_path()
+
+set(API_MESSAGING_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+ )
+
+set(SRCS_API_MESSAGING
+ ${CURRENT_PATH}/Attachments.cpp
+ ${CURRENT_PATH}/IAttachment.cpp
+ ${CURRENT_PATH}/AttachmentFactory.cpp
+ ${CURRENT_PATH}/BccRecipient.cpp
+ ${CURRENT_PATH}/Body.cpp
+ ${CURRENT_PATH}/CcRecipient.cpp
+ ${CURRENT_PATH}/From.cpp
+ ${CURRENT_PATH}/IBinarySms.cpp
+ ${CURRENT_PATH}/IEmail.cpp
+ ${CURRENT_PATH}/IMessage.cpp
+ ${CURRENT_PATH}/IMessaging.cpp
+ ${CURRENT_PATH}/IMms.cpp
+ ${CURRENT_PATH}/MmsSlide.cpp
+ ${CURRENT_PATH}/MmsSlides.cpp
+ ${CURRENT_PATH}/MmsSlideProperty.cpp
+ ${CURRENT_PATH}/ISms.cpp
+ ${CURRENT_PATH}/MessageFactory.cpp
+ ${CURRENT_PATH}/Recipient.cpp
+ ${CURRENT_PATH}/Subject.cpp
+ ${CURRENT_PATH}/ToRecipient.cpp
+ ${CURRENT_PATH}/ReqReceiverMessage.cpp
+ ${CURRENT_PATH}/EmailAccountInfo.cpp
+ ${CURRENT_PATH}/IEmailAccount.cpp
+ ${CURRENT_PATH}/MessageFilter.cpp
+ ${CURRENT_PATH}/SourceAddress.cpp
+ ${CURRENT_PATH}/CallbackNumber.cpp
+ ${CURRENT_PATH}/ValidityPeriodHours.cpp
+ ${CURRENT_PATH}/MessagePriority.cpp
+ ${CURRENT_PATH}/VirtualMessage.cpp
+ ${CURRENT_PATH}/EventMessageReceived.cpp
+ ${CURRENT_PATH}/EmitterMessageReceived.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 "EventConnected.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+} // Api
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_EVENTCONNECTED_H_
+#define WRTDEVICEAPIS_NETWORKING_EVENTCONNECTED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "IConnection.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+/* TODO */
+class EventConnected : public Commons::ListenerEvent<EventConnected>
+{
+ private:
+ IConnectionPtr m_connection;
+};
+
+typedef DPL::SharedPtr<EventConnected> EventConnectedPtr;
+typedef Commons::ListenerEventEmitter<EventConnected> EventConnectedEmitter;
+typedef DPL::SharedPtr<EventConnectedEmitter> EventConnectedEmitterPtr;
+} // Api
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_EVENTCONNECTED_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 "EventDisconnected.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+} // Api
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_EVENTDISCONNECTED_H_
+#define WRTDEVICEAPIS_NETWORKING_EVENTDISCONNECTED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "IConnection.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+/* TODO */
+class EventDisconnected : public Commons::ListenerEvent<EventDisconnected>
+{
+ private:
+ IConnectionPtr m_connection;
+};
+
+typedef DPL::SharedPtr<EventDisconnected> EventDisconnectedPtr;
+typedef Commons::ListenerEventEmitter<EventDisconnected>
+EventDisconnectedEmitter;
+typedef DPL::SharedPtr<EventDisconnectedEmitter> EventDisconnectedEmitterPtr;
+} // Api
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_EVENTDISCONNECTED_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 "IAdapter.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+IAdapter::~IAdapter()
+{
+}
+} // Api
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_IADAPTER_H_
+#define WRTDEVICEAPIS_NETWORKING_IADAPTER_H_
+
+#include <list>
+#include <dpl/noncopyable.h>
+#include "IConnection.h"
+#include "EventConnected.h"
+#include "EventDisconnected.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+class IAdapter : public DPL::Noncopyable
+{
+ public:
+ /**
+ * Adapter type.
+ */
+ enum Type
+ {
+ T_ETHERNET, //!< T_ETHERNET
+ T_WIFI //!< T_WIFI
+ };
+
+ public:
+ virtual ~IAdapter() = 0;
+
+ /**
+ * Checks whether network adapter has active connection.
+ * @return True when connected, false otherwsie.
+ */
+ virtual bool isConnected() const = 0;
+
+ /**
+ * Gets active connection.
+ * @return Active connection or NULL if not connected.
+ */
+ virtual IConnectionPtr getConnection() const = 0;
+
+ /**
+ * Sets on connected event emitter.
+ * @param event Event emitter.
+ */
+ virtual void addOnConnected(const EventConnectedEmitterPtr& emitter) = 0;
+
+ /**
+ * Removes on connected event emitter.
+ * @param id Emitters id.
+ */
+ virtual void removeOnConnected(EventConnectedEmitter::IdType id) = 0;
+
+ /**
+ * Sets on disconnected event emitter.
+ * @param emitter Event emitter.
+ */
+ virtual void addOnDisconnected(const EventDisconnectedEmitterPtr& emitter)
+ = 0;
+
+ /**
+ * Removes on disconnected event emitter.
+ * @param id Emitters id.
+ */
+ virtual void removeOnDisconnected(EventDisconnectedEmitter::IdType id) = 0;
+
+ /**
+ * Gets type of an adapter
+ * @return type Type of an adapter
+ */
+ virtual Type getAdapterType() const = 0;
+};
+
+typedef std::list<IAdapter*> AdaptersSet;
+typedef std::list<IAdapter*>::iterator AdaptersSetIterator;
+} // Api
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_IADAPTER_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 "IConnection.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+IConnection::~IConnection()
+{
+}
+} // Api
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_ICONNECTION_H_
+#define WRTDEVICEAPIS_NETWORKING_ICONNECTION_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+class IConnection : public DPL::Noncopyable
+{
+ public:
+ virtual ~IConnection() = 0;
+
+ /**
+ * Gets connection name.
+ * @return Connection's name.
+ */
+ virtual std::string getName() const = 0;
+};
+
+typedef DPL::SharedPtr<IConnection> IConnectionPtr;
+} // Api
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_ICONNECTION_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 <Networking/Manager.h>
+#include "IManager.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+IManager& IManager::getInstance()
+{
+ return Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+} // Api
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_IMANAGER_H_
+#define WRTDEVICEAPIS_NETWORKING_IMANAGER_H_
+
+#include <dpl/noncopyable.h>
+#include "IAdapter.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+namespace Api {
+class IManager : private DPL::Noncopyable
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets specfied adapter.
+ * @param type Adapter type @see IAdapter::Type.
+ * @return Interface to network adapter, NULL if current platform does not
+ * support such network adapter.
+ * @throw PlatformException If platform error occured.
+ */
+ virtual IAdapter* getAdapter(IAdapter::Type type) const = 0;
+
+ /**
+ * Adds to given set all available on platform adapters
+ * @param [out] list of interfaces to network adapters
+ */
+ virtual void getAvailableAdapters(AdaptersSet *retSet) const = 0;
+};
+} // Api
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_IMANAGER_H_
--- /dev/null
+get_current_path()
+
+set(API_NETWORKING_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_NETWORKING
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/IAdapter.cpp
+ ${CURRENT_PATH}/IConnection.cpp
+ ${CURRENT_PATH}/EventConnected.cpp
+ ${CURRENT_PATH}/EventDisconnected.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 EventGetCurrentOrientation.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ORIENTATION_EVENT_GET_CURRENT_ORIENTATION_H_
+#define WRTDEVICEAPIS_ORIENTATION_EVENT_GET_CURRENT_ORIENTATION_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Orientation/OrientationProperties.h>
+#include <Orientation/IOrientation.h>
+
+namespace WrtDeviceApis {
+namespace Orientation {
+namespace Api {
+
+class EventGetCurrentOrientation :
+ public Commons::IEvent<EventGetCurrentOrientation>
+{
+ private:
+ OrientationProperties m_props;
+ public:
+ void setAlpha(double alpha)
+ {
+ m_props.alpha = alpha;
+ }
+ void setBeta(double beta)
+ {
+ m_props.beta = beta;
+ }
+ void setGamma(double gamma)
+ {
+ m_props.gamma = gamma;
+ }
+
+ double getAlpha() const
+ {
+ return m_props.alpha;
+ }
+ double getBeta() const
+ {
+ return m_props.beta;
+ }
+ double getGamma() const
+ {
+ return m_props.gamma;
+ }
+
+ OrientationProperties getOrientationProperties() const
+ {
+ return m_props;
+ }
+
+ EventGetCurrentOrientation()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventGetCurrentOrientation>
+EventGetCurrentOrientationPtr;
+} // Orientation
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_ORIENTATION_EVENT_GET_CURRENT_ORIENTATION_H_
\ 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 EventOrientationChanged.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ORIENTATION_EVENT_ORIENTATION_CHANGED_H_
+#define WRTDEVICEAPIS_ORIENTATION_EVENT_ORIENTATION_CHANGED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include <Orientation/OrientationProperties.h>
+
+namespace WrtDeviceApis {
+namespace Orientation {
+namespace Api {
+
+class EventOrientationChanged :
+ public Commons::ListenerEvent<EventOrientationChanged>
+{
+ private:
+ OrientationProperties m_props;
+
+ public:
+ OrientationProperties getOrientationProperties() const
+ {
+ return m_props;
+ }
+ void setOrientationProperties(const OrientationProperties &props)
+ {
+ m_props = props;
+ }
+
+ EventOrientationChanged()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<EventOrientationChanged> EventOrientationChangedPtr;
+typedef Commons::ListenerEventEmitter<EventOrientationChanged>
+ EventOrientationChangedEmitter;
+typedef DPL::SharedPtr<EventOrientationChangedEmitter>
+ EventOrientationChangedEmitterPtr;
+} // Orientation
+} // Api
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_ORIENTATION_EVENT_ORIENTATION_CHANGED_H_
\ 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 IOrientation.cpp
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "IOrientation.h"
+#include "EventGetCurrentOrientation.h"
+
+namespace WrtDeviceApis {
+namespace Orientation {
+namespace Api {
+
+IOrientation::IOrientation() :
+ EventRequestReceiver<EventGetCurrentOrientation>(
+ Commons::ThreadEnum::ORIENTATION_THREAD)
+{
+}
+
+IOrientation::~IOrientation()
+{
+}
+
+}
+}
+}
--- /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 IOrientation.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ORIENTATION_IORIENTATION_H_
+#define WRTDEVICEAPIS_ORIENTATION_IORIENTATION_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include <Orientation/EventOrientationChanged.h>
+
+namespace WrtDeviceApis {
+namespace Orientation {
+namespace Api {
+
+class EventGetCurrentOrientation;
+typedef DPL::SharedPtr<EventGetCurrentOrientation>
+ EventGetCurrentOrientationPtr;
+
+class IOrientation :
+ public Commons::EventRequestReceiver<EventGetCurrentOrientation>
+{
+ public:
+ virtual ~IOrientation();
+
+ /**
+ * Gets current orientation
+ * @param event @see WrtDeviceApis::Api::Orientation::EventGetCurrentOrientation.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void getCurrentOrientation(
+ const EventGetCurrentOrientationPtr& event) = 0;
+
+ /**
+ * Requests sensor module to receive continuously update of current
+ * orientation if the orientation is significantly changed
+ * @param emitter @see WrtDeviceApis::Api::Orientation::EventOrientationChanged.
+ * @param minNotificationInterval
+ * @return An ID of created subscription
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual long watchOrientation(
+ const EventOrientationChangedEmitterPtr& emitter,
+ long minNotificationInterval) = 0;
+
+ /**
+ * Stopping periodic orientation updates started with watchOrientation
+ * @param id An Id of listener subscription.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void clearWatch(EventOrientationChangedEmitter::IdType id) = 0;
+
+ protected:
+ IOrientation();
+
+ virtual void OnRequestReceived(const EventGetCurrentOrientationPtr& event)
+ = 0;
+};
+
+typedef DPL::SharedPtr<IOrientation> IOrientationPtr;
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_ORIENTATION_IORIENTATION_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 OrientationFactory.cpp
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief This class provide factory to create Orientation
+ */
+
+#include <Orientation/Orientation.h>
+#include "OrientationFactory.h"
+
+namespace WrtDeviceApis {
+namespace Orientation {
+namespace Api {
+
+IOrientationPtr OrientationFactory::getOrientations()
+{
+ return IOrientationPtr(new Orientation());
+}
+
+OrientationFactory& OrientationFactory::getInstance()
+{
+ static OrientationFactory theInstance;
+ return theInstance;
+}
+
+OrientationFactory::OrientationFactory()
+{
+}
+}
+}
+}
--- /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 OrientationFactory.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ORIENTATION_ORIENTATIONFACTORY_H_
+#define WRTDEVICEAPIS_ORIENTATION_ORIENTATIONFACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include <Orientation/IOrientation.h>
+
+namespace WrtDeviceApis {
+namespace Orientation {
+namespace Api {
+
+class OrientationFactory : DPL::Noncopyable
+{
+ public:
+ IOrientationPtr getOrientations();
+
+ static OrientationFactory& getInstance();
+
+ protected:
+ OrientationFactory();
+};
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_ORIENTATION_ORIENTATIONFACTORY_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 OrientationProperties.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ORIENTATION_PROPERTIES_H_
+#define WRTDEVICEAPIS_ORIENTATION_PROPERTIES_H_
+
+#include <ctime>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Orientation {
+namespace Api {
+
+struct OrientationProperties
+{
+ double alpha;
+ double beta;
+ double gamma;
+ OrientationProperties() :
+ alpha(0.0),
+ beta(0.0),
+ gamma(0.0)
+ {
+ }
+};
+
+typedef DPL::SharedPtr<OrientationProperties> OrientationPropertiesPtr;
+} // Orientation
+} // Api
+} // WrtDeviceApis
+
+#endif //WRTDEVICEAPIS_ORIENTATION_PROPERTIES_H_
\ No newline at end of file
--- /dev/null
+get_current_path()
+
+set(API_ORIENTATION_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_ORIENTATION
+ ${CURRENT_PATH}/OrientationFactory.cpp
+ ${CURRENT_PATH}/IOrientation.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 IPluginManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_PLUGINMANAGER_IPLUGINMANAGER_H_
+#define WRTDEVICEAPIS_PLUGINMANAGER_IPLUGINMANAGER_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace WrtDeviceApis {
+namespace PluginManager {
+namespace Api {
+
+class IPluginManager
+{
+ public:
+ typedef std::vector<std::string> PropertyList;
+
+ virtual ~IPluginManager() {}
+ virtual bool hasChild(const std::string &name) const = 0;
+ virtual bool loadChild(const std::string &name) const = 0;
+
+ virtual JSValueRef getProperty(const std::string &name) const = 0;
+ virtual bool setProperty(const std::string &name,
+ JSValueRef value) = 0;
+ virtual bool deleteProperty(const std::string &name) = 0;
+
+ virtual PropertyList getProperties() const = 0;
+ virtual void addPropertiesToList(
+ JSPropertyNameAccumulatorRef propertyNames) const = 0;
+};
+
+typedef DPL::SharedPtr<IPluginManager> IPluginManagerPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_PLUGINMANAGER_IPLUGINMANAGER_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 PluginManagerFactory.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include "PluginManagerFactory.h"
+#include <PluginManager/PluginManager.h>
+
+namespace WrtDeviceApis {
+namespace PluginManager {
+namespace Api {
+
+PluginManagerFactory::PluginManagerFactory()
+{
+}
+
+PluginManagerFactory& PluginManagerFactory::getInstance()
+{
+ static PluginManagerFactory instance;
+ return instance;
+}
+
+IPluginManagerPtr PluginManagerFactory::getPluginManager(
+ int widgetHandle,
+ const std::string &objectUri,
+ JSContextRef context) const
+{
+ return IPluginManagerPtr(new PluginManager(widgetHandle, objectUri, context));
+}
+
+}
+}
+}
\ 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 PluginManagerFactory.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_PLUGIN_MANAGER_FACTORY_H_
+#define WRTDEVICEAPIS_PLUGIN_MANAGER_FACTORY_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <PluginManager/IPluginManager.h>
+
+namespace WrtDeviceApis {
+namespace PluginManager {
+namespace Api {
+
+class PluginManagerFactory : private DPL::Noncopyable
+{
+public:
+ static PluginManagerFactory& getInstance();
+ IPluginManagerPtr getPluginManager(
+ int widgetHandle,
+ const std::string &objectUri,
+ JSContextRef context) const;
+private:
+ PluginManagerFactory();
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_PLUGIN_MANAGER_FACTORY_H_
\ No newline at end of file
--- /dev/null
+get_current_path()
+
+set(API_PLUGIN_MANAGER_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_PLUGIN_MANAGER
+ ${CURRENT_PATH}/PluginManagerFactory.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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_ENUMS_H_
+#define WRTDEVICEAPIS_POWER_ENUMS_H_
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+enum BacklightStatus
+{
+ BACKLIGHT_DIM,
+ BACKLIGHT_NORMAL,
+ BACKLIGHT_OFF,
+ INVALID_STATUS = 10000,
+ UNDEFINED_STATUS
+};
+
+} // Api
+} // Power
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_POWER_ENUMS_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 "EventCharging.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+EventCharging::EventCharging()
+{
+}
+
+EventCharging::~EventCharging()
+{
+}
+
+} // Api
+} // Power
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_EVENTCHARGING_H_
+#define WRTDEVICEAPIS_POWER_EVENTCHARGING_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+/**
+ * Event emitted when batter charging state changes, i.e. phone gets plugged
+ * or unplugged from charger.
+ */
+class EventCharging : public Commons::ListenerEvent<EventCharging>
+{
+ public:
+ EventCharging();
+ virtual ~EventCharging();
+};
+
+typedef DPL::SharedPtr<EventCharging> EventChargingPtr;
+typedef Commons::ListenerEventEmitter<EventCharging> EventChargingEmitter;
+typedef DPL::SharedPtr<EventChargingEmitter> EventChargingEmitterPtr;
+
+} // Api
+} // Power
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_POWER_EVENTCHARGING_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 EventLight.h
+ * @author Hoseon LEE (Hoseon46.lee@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_POWER_EVENTLIGHT_H_
+#define WRTDEVICEAPIS_POWER_EVENTLIGHT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Power/Enums.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+class EventLight;
+
+typedef DPL::SharedPtr<EventLight> EventLightPtr;
+
+/*
+ *
+ */
+class EventLight : public Commons::IEvent<EventLight>
+{
+ public:
+ explicit EventLight(const BacklightStatus status,
+ const long duration) :
+ m_status(status),
+ m_duration(duration)
+ {
+ }
+
+ BacklightStatus getStatus() const
+ {
+ return m_status;
+ }
+
+ long getDuration() const
+ {
+ return m_duration;
+ }
+
+ private:
+ const BacklightStatus m_status;
+ const long m_duration;
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_POWER_EVENTLIGHT_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 "EventLow.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+EventLow::EventLow() : m_result(0)
+{
+}
+
+EventLow::~EventLow()
+{
+}
+
+unsigned int EventLow::getResult() const
+{
+ return m_result;
+}
+
+void EventLow::setResult(unsigned int result)
+{
+ m_result = result;
+}
+
+} // Api
+} // Power
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_EVENTLOW_H_
+#define WRTDEVICEAPIS_POWER_EVENTLOW_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+/**
+ * Events emitted when battery reaches low power level.
+ */
+class EventLow : public Commons::ListenerEvent<EventLow>
+{
+ public:
+ EventLow();
+ virtual ~EventLow();
+
+ /**
+ * Gets remaining battery power (in percents).
+ * @return Remaining battery power.
+ * @remarks Read on the side that receives this event.
+ */
+ unsigned int getResult() const;
+
+ /**
+ * Sets remaining battery power.
+ * @param result Remining battery power.
+ * @remarks Set on the side that emits this event.
+ */
+ void setResult(unsigned int result);
+
+ private:
+ unsigned int m_result; ///< Remaining battery power (in percents).
+};
+
+typedef DPL::SharedPtr<EventLow> EventLowPtr;
+typedef Commons::ListenerEventEmitter<EventLow> EventLowEmitter;
+typedef DPL::SharedPtr<EventLowEmitter> EventLowEmitterPtr;
+
+} // Api
+} // Power
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_POWER_EVENTLOW_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 "EventRemaining.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+EventRemaining::EventRemaining() : m_result(0)
+{
+}
+
+EventRemaining::~EventRemaining()
+{
+}
+
+unsigned int EventRemaining::getResult() const
+{
+ return m_result;
+}
+
+void EventRemaining::setResult(unsigned int result)
+{
+ m_result = result;
+}
+
+} // Api
+} // Power
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_EVENTREMAINING_H_
+#define WRTDEVICEAPIS_POWER_EVENTREMAINING_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+/**
+ * Event emitted when remaining battery power changes.
+ */
+class EventRemaining : public Commons::ListenerEvent<EventRemaining>
+{
+ public:
+ EventRemaining();
+ virtual ~EventRemaining();
+
+ /**
+ * Gets remaining battery power (in percents).
+ * @return Remaining battery power.
+ * @remarks Read on the side that receives this event.
+ */
+ unsigned int getResult() const;
+
+ /**
+ * Sets remaining battery power.
+ * @param result Remining battery power.
+ * @remarks Set on the side that emits this event.
+ */
+ void setResult(unsigned int result);
+
+ private:
+ unsigned int m_result; ///< Remaining battery power (in percents).
+};
+
+typedef DPL::SharedPtr<EventRemaining> EventRemainingPtr;
+typedef Commons::ListenerEventEmitter<EventRemaining> EventRemainingEmitter;
+typedef DPL::SharedPtr<EventRemainingEmitter> EventRemainingEmitterPtr;
+
+} // Api
+} // Power
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_POWER_EVENTREMAINING_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 "IBacklight.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+IBacklight::~IBacklight()
+{
+}
+
+} // Api
+} // Power
+} // 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 IBacklight.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_POWER_IBACKALIGHT_H_
+#define WRTDEVICEAPIS_POWER_IBACKALIGHT_H_
+
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <Power/EventLight.h>
+#include <Power/Enums.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+/**
+ * Represents battery unit on the device.
+ */
+class IBacklight : private DPL::Noncopyable
+{
+ public:
+ virtual ~IBacklight() = 0;
+
+ /**
+ * @see Api::Power::IBacklight::changeState()
+ */
+ virtual int changeState(BacklightStatus state,
+ unsigned int timeout) = 0;
+
+ /**
+ * @see Api::Power::IBacklight::changeState()
+ */
+ virtual void changeState(const EventLightPtr& event) = 0;
+};
+
+typedef DPL::SharedPtr<IBacklight> IBacklightPtr;
+
+} // Api
+} // Power
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_POWER_IBACKALIGHT_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 "IBattery.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+IBattery::~IBattery()
+{
+}
+
+} // Api
+} // Power
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_IBATTERY_H_
+#define WRTDEVICEAPIS_POWER_IBATTERY_H_
+
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <Power/EventCharging.h>
+#include <Power/EventRemaining.h>
+#include <Power/EventLow.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+/**
+ * Represents battery unit on the device.
+ */
+class IBattery : private DPL::Noncopyable
+{
+ public:
+ virtual ~IBattery() = 0;
+
+ /**
+ * Gets information whether battery is charging.
+ * @return True if battery is charging, false otherwsie.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual bool isCharging() const = 0;
+
+ /**
+ * Gets remaining charge level (in percents).
+ * @return Percent of remaining charge level.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual unsigned int getRemaining() const = 0;
+
+ /**
+ * Adds on battery being charged event emitter.
+ * @param emitter On battery being charged event emitter.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void addOnCharging(const EventChargingEmitterPtr& emitter) = 0;
+
+ /**
+ * Removes charging event emitter.
+ * @param id Id of an event emitter.
+ */
+ virtual void removeOnCharging(EventChargingEmitter::IdType id) = 0;
+
+ /**
+ * Adds battery level remaining event emitter.
+ * @param emitter Battery level remaining event emitter.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void addOnRemaining(const EventRemainingEmitterPtr& emitter) = 0;
+
+ /**
+ * Removes remaining event emitter.
+ * @param id Id of an event emitter.
+ */
+ virtual void removeOnRemaining(EventRemainingEmitter::IdType id) = 0;
+
+ /**
+ * Adds battery on low level event emitter.
+ * @param emitter Battery on low level event emitter.
+ * @throw PlatformException If platform error occurs.
+ */
+ virtual void addOnLow(const EventLowEmitterPtr& emitter) = 0;
+
+ /**
+ * Removes on low level event emitter.
+ * @param id Id of an event emitter.
+ */
+ virtual void removeOnLow(EventLowEmitter::IdType id) = 0;
+};
+
+typedef DPL::SharedPtr<IBattery> IBatteryPtr;
+
+} // Api
+} // Power
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_POWER_IBATTERY_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 <Power/Manager.h>
+#include "IManager.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+IManager& IManager::getInstance()
+{
+ return Manager::getInstance();
+}
+
+IManager::IManager()
+{
+}
+
+IManager::~IManager()
+{
+}
+} // Power
+} // Api
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_IMANAGER_H_
+#define WRTDEVICEAPIS_POWER_IMANAGER_H_
+
+#include <cstddef>
+#include <dpl/noncopyable.h>
+#include <Power/IBattery.h>
+#include <Power/IBacklight.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+namespace Api {
+
+class IManager : private DPL::Noncopyable
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets interface to battery.
+ * @param index Index of battery to get (1-based).
+ * @return Interface to battery.
+ * @throw PlatformException If platform error occurs.
+ * @throw OutOfRangeException If index is greater than available batteries.
+ * @remarks Ownership over result (IBattery*) is NOT passed to caller.
+ */
+ virtual IBattery* getBattery(std::size_t index) const = 0;
+
+ /**
+ * Gets number of available batteries.
+ * @return Number of batteries.
+ */
+ virtual std::size_t getBatteriesCount() const = 0;
+
+ virtual IBacklightPtr getBacklight(void) = 0;
+
+ virtual std::size_t getBacklightCount() const = 0;
+
+ /**
+ * Release resources.
+ */
+ virtual void Release() = 0;
+
+ protected:
+ IManager();
+};
+
+} // Api
+} // Power
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_POWER_IMANAGER_H_
--- /dev/null
+get_current_path()
+
+set(API_POWER_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_POWER
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/IBattery.cpp
+ ${CURRENT_PATH}/IBacklight.cpp
+ ${CURRENT_PATH}/EventCharging.cpp
+ ${CURRENT_PATH}/EventRemaining.cpp
+ ${CURRENT_PATH}/EventLow.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)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_ENUMS_H_
+#define WRTDEVICEAPIS_PROFILE_ENUMS_H_
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+enum RingtoneScope
+{
+ RS_CALL,
+ RS_SMS,
+ RS_MMS,
+ RS_EMAIL
+};
+} // Api
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_ENUMS_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 EventSetWallpaper.h
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_EVENTSETWALLPAPER_H_
+#define WRTDEVICEAPIS_PROFILE_EVENTSETWALLPAPER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+class EventSetWallpaper;
+
+typedef DPL::SharedPtr<EventSetWallpaper> EventSetWallpaperPtr;
+
+/*
+ *
+ */
+class EventSetWallpaper : public Commons::IEvent<EventSetWallpaper>
+{
+ public:
+ explicit EventSetWallpaper(const std::string& path) : m_path(path)
+ {
+ }
+
+ const std::string& getPathRef() const
+ {
+ return m_path;
+ }
+
+ private:
+ const std::string m_path;
+};
+} // Api
+} // Profile
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_PROFILE_EVENTSETWALLPAPER_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 "IDesktop.h"
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+IDesktop::~IDesktop()
+{
+}
+} // Api
+} // Profile
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_IDESKTOP_H_
+#define WRTDEVICEAPIS_PROFILE_IDESKTOP_H_
+
+#include <dpl/shared_ptr.h>
+#include <Filesystem/IPath.h>
+#include "EventSetWallpaper.h"
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+class IDesktop
+{
+ public:
+ /**
+ * Index of default desktop.
+ */
+ static const std::size_t DEFAULT = 0;
+
+ public:
+ virtual ~IDesktop() = 0;
+
+ /**
+ * Gets path to wallpaper for current desktop.
+ * @return Path to wallpaper.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportException If platform doesn't support such feature.
+ */
+ virtual Filesystem::Api::IPathPtr getWallpaper() const = 0;
+
+ /**
+ * Sets wallpaper for current desktop.
+ * @param path Path to wallpaper.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportException If platform doesn't support such feature.
+ */
+ virtual void setWallpaper(const Filesystem::Api::IPathPtr& path) = 0;
+
+ /**
+ * Sets wallpaper for current desktop (async version)
+ * @param path Path to wallpaper.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportException If platform doesn't support such feature.
+ */
+ virtual void setWallpaper(const EventSetWallpaperPtr& event) = 0;
+};
+
+typedef DPL::SharedPtr< IDesktop > IDesktopPtr;
+} // Api
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_IDESKTOP_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 "IManager.h"
+#include <Profile/Manager.h>
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+IManager& IManager::getInstance()
+{
+ return Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+} // Api
+} // Profile
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_IMANAGER_H_
+#define WRTDEVICEAPIS_PROFILE_IMANAGER_H_
+
+#include <cstddef>
+#include "IDesktop.h"
+#include "IRingtone.h"
+#include "Enums.h"
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+class IManager
+{
+ public:
+ static IManager& getInstance();
+
+ typedef enum
+ {
+ NORMAL, SILENT, DRIVING, MEETING, OUTDOOR, FLIGHT
+ } ProfileType;
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Gets desktop settings interface for current profile.
+ * @param index 1-based index
+ * @return Desktop interface (or NULL if 0 is passed and general desktop is not supported).
+ * @throw PlatformException If error in platform occurs.
+ * @throw OutOfRangeException If desktop doesn't exist.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @remarks Passing IDesktop::DEFAULT as index results in returning default
+ * desktop interface (or first one if platform doesn't distinct them).
+ * @remarks Ownership is NOT passed to the caller.
+ */
+ virtual IDesktopPtr getDesktop(std::size_t index) const = 0;
+
+ /**
+ * Gets number of available desktops on current platform.
+ * @return Number of desktops.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual std::size_t getDesktopCount() const = 0;
+
+ /**
+ * Gets ringtone interface for specific type of received message.
+ * @param scope Received message/call type.
+ * @return Ringtone interface.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @remarks Some platforms may not distinct between different types of messages
+ * as far as ringtone settings are concerned, e.g. they may assign
+ * SMS, MMS and EMAIL the same ringtone settings.
+ * @remarks Ownership is NOT passed to the caller.
+ */
+ virtual IRingtone* getRingtone(RingtoneScope scope) const = 0;
+
+ /**
+ * Returns profile setting.
+ * @return ProfileType enum.
+ * @throw ConversionException
+ * @throw OutOfRangeException
+ */
+ virtual ProfileType getProfileType() const = 0;
+
+ /**
+ * Returns system volume value.
+ * @return system volume as int.
+ * @throw ConversionException
+ */
+ virtual int getSystemVolume() const = 0;
+
+ /**
+ * Release resources.
+ */
+ virtual void Release() const = 0;
+ virtual int getVibrateType() const = 0;
+};
+} // Api
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_IMANAGER_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 "IRingtone.h"
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+IRingtone::~IRingtone()
+{
+}
+} // Api
+} // Profile
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_IRINGTONE_H_
+#define WRTDEVICEAPIS_PROFILE_IRINGTONE_H_
+
+#include <Filesystem/IPath.h>
+#include <Haptics/Types.h>
+#include <Profile/Types.h>
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+class IRingtone
+{
+ public:
+ virtual ~IRingtone() = 0;
+
+ /**
+ * Gets volume level.
+ * @return Volume value.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportedException If platform doesn't support this feature.
+ * @remarks Different platforms may have different ranges of values.
+ */
+ virtual Volume getVolume() const = 0;
+
+ /**
+ * Sets volume level.
+ * @param level Volume value.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportedException If platform doesn't support this feature.
+ * @remarks Different platforms may respect different ranges of values.
+ */
+ virtual void setVolume(Volume level) = 0;
+
+ /**
+ * Gets path to ringtone audio file.
+ * @return File path.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportedException If platform doesn't support this feature.
+ */
+ virtual Filesystem::Api::IPathPtr getAudio() const = 0;
+
+ /**
+ * Sets path to ringtone audio file.
+ * @param path File path.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportedException If platform doesn't support this feature.
+ */
+ virtual void setAudio(const Filesystem::Api::IPathPtr& path) = 0;
+
+ /**
+ * Gets haptics level.
+ * @return Haptics intensity.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportedException If platform doesn't support this feature.
+ * @remarks Different platforms may have different ranges of values.
+ */
+ virtual Haptics::Api::Feedback getHaptics() const = 0;
+
+ /**
+ * Sets haptics level.
+ * @param level Haptics intensity.
+ * @throw PlatformException If error in platform occurs.
+ * @throw UnsupportedException If platform doesn't support this feature.
+ * @remarks Different platforms may respect different ranges of values.
+ */
+ virtual void setHaptics(Haptics::Api::Feedback level) = 0;
+};
+} // Api
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_IRINGTONE_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)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_TYPES_H_
+#define WRTDEVICEAPIS_PROFILE_TYPES_H_
+
+namespace WrtDeviceApis {
+namespace Profile {
+namespace Api {
+/**
+ * Type representing volume level.
+ */
+typedef unsigned short Volume;
+
+/**
+ * Value representing volume turned off (mute).
+ */
+const Volume NO_VOLUME = 0;
+
+/**
+ * Value representing the lowest volume level.
+ */
+const Volume VOLUME_MIN = 1;
+
+/**
+ * Value representing the highest volume level.
+ */
+const Volume VOLUME_MAX = 100;
+
+} // Api
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_TYPES_H_
--- /dev/null
+get_current_path()
+
+set(API_PROFILE_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_PROFILE
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/IDesktop.cpp
+ ${CURRENT_PATH}/IRingtone.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>
+ */
+
+#ifndef WRTDEVICEAPIS_RADIO_ENUMS_H_
+#define WRTDEVICEAPIS_RADIO_ENUMS_H_
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+/**
+ * Type of signal source.
+ */
+enum SourceType
+{
+ ST_UNKNOWN, //!< ST_UNKNOWN
+ ST_CDMA, //!< ST_CDMA
+ ST_GSM, //!< ST_GSM
+ ST_LTE, //!< ST_LTE
+ ST_TDSCDMA, //!< ST_TDSCDMA
+ ST_WCDMA //!< ST_WCDMA
+};
+} // Api
+} // Radio
+} // WrtDeviceapis
+
+#endif // WRTDEVICEAPIS_RADIO_ENUMS_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 "EventSourceTypeChange.h"
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+EventSourceTypeChange::EventSourceTypeChange() : m_type(ST_UNKNOWN)
+{
+}
+
+SourceType EventSourceTypeChange::getType() const
+{
+ return m_type;
+}
+
+void EventSourceTypeChange::setType(SourceType type)
+{
+ m_type = type;
+}
+} // Api
+} // Radio
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_DEVICE_EVENTSOURCETYPECHANGE_H_
+#define WRTDEVICEAPIS_DEVICE_EVENTSOURCETYPECHANGE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "Enums.h"
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+/**
+ * Event emitted when screen orientation changes.
+ */
+class EventSourceTypeChange : public Commons::ListenerEvent<
+ EventSourceTypeChange>
+{
+ public:
+ EventSourceTypeChange();
+
+ /**
+ * Gets signal source's type.
+ * @return Type of the signal source.
+ */
+ SourceType getType() const;
+
+ /**
+ * Sets signal source's type.
+ * @param type Type of the signal source..
+ */
+ void setType(SourceType type);
+
+ protected:
+ SourceType m_type;
+};
+
+typedef DPL::SharedPtr<EventSourceTypeChange> EventSourceTypeChangePtr;
+typedef Commons::ListenerEventEmitter<EventSourceTypeChange>
+EventSourceTypeChangeEmitter;
+typedef DPL::SharedPtr<EventSourceTypeChangeEmitter>
+EventSourceTypeChangeEmitterPtr;
+} // Api
+} // Radio
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_DEVICE_EVENTSOURCETYPECHANGE_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 <Radio/Manager.h>
+#include "IManager.h"
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+IManager& IManager::getInstance()
+{
+ return Manager::getInstance();
+}
+
+IManager::~IManager()
+{
+}
+} // Api
+} // Radio
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa <z.kostrzewa@samsung.com>
+ */
+
+#ifndef WRTDEVICEAPIS_RADIO_IMANAGER_H_
+#define WRTDEVICEAPIS_RADIO_IMANAGER_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include "Types.h"
+#include "ISource.h"
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+class IManager : public DPL::Noncopyable
+{
+ public:
+ static IManager& getInstance();
+
+ public:
+ virtual ~IManager() = 0;
+
+ /**
+ * Checks whether radio is enabled.
+ * @return True if radio is enabled, false otherwise.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual bool isEnabled() const = 0;
+
+ /**
+ * Checks whether roaming is turned on.
+ * @return True when roaming is on, false otherwise.
+ */
+ virtual bool isRoaming() const = 0;
+
+ /**
+ * Gets interface of currently connected source.
+ * @return Interface of radio source.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual ISource* getSource() const = 0;
+
+ /**
+ * Gets signal strength.
+ * @return Signal strength (in percents).
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual Strength getSignalStrength() const = 0;
+
+ /**
+ * Gets Mobile Country Code
+ * @return Mobile Country Code string.
+ */
+ virtual std::string getMcc() const = 0;
+
+ /**
+ * Gets Mobile Network Code
+ * @return Mobile Country Code string.
+ */
+ virtual std::string getMnc() const = 0;
+
+ /**
+ * Checks whether telephony H/W is turend on.
+ * @return true when on, false otherwise.
+ */
+ virtual bool isHardwareOn() const = 0;
+};
+} // Api
+} // Radio
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_RADIO_IMANAGER_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 "ISource.h"
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+ISource::~ISource()
+{
+}
+} // Api
+} // Radio
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa <z.kostrzewa@samsung.com>
+ */
+
+#ifndef WRTDEVICEAPIS_RADIO_ISOURCE_H_
+#define WRTDEVICEAPIS_RADIO_ISOURCE_H_
+
+#include "Enums.h"
+#include "EventSourceTypeChange.h"
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+class ISource
+{
+ public:
+ virtual ~ISource() = 0;
+
+ /**
+ * Gets whether device is connected to some signal source.
+ * @return True if connected, false otherwise.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual bool isConnected() const = 0;
+
+ /**
+ * Gets type of the signal source.
+ * @return Type of the source.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual SourceType getType() const = 0;
+
+ /**
+ * Adds on type change emitter.
+ * @param emitter On type change event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void addOnTypeChange(const EventSourceTypeChangeEmitterPtr& emitter)
+ = 0;
+
+ /**
+ * Removes on type change emitter.
+ * @param id Id of an event emitter.
+ * @throw UnsupportedException If platform doesn't support it.
+ * @throw PlatformException If error in platform occurs.
+ */
+ virtual void removeOnTypeChange(EventSourceTypeChangeEmitter::IdType id) =
+ 0;
+};
+} // Api
+} // Radio
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_RADIO_ISOURCE_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>
+ */
+
+#ifndef WRTDEVICEAPIS_RADIO_TYPES_H_
+#define WRTDEVICEAPIS_RADIO_TYPES_H_
+
+namespace WrtDeviceApis {
+namespace Radio {
+namespace Api {
+typedef unsigned int Strength;
+} // Api
+} // Radio
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_RADIO_TYPES_H_
--- /dev/null
+get_current_path()
+
+set(API_RADIO_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+ )
+
+set(SRCS_API_RADIO
+ ${CURRENT_PATH}/IManager.cpp
+ ${CURRENT_PATH}/ISource.cpp
+ ${CURRENT_PATH}/EventSourceTypeChange.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 IStorageEvent.h
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Storage event interfece
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_STORAGE_EVENT_INTERFACE_H
+#define WRTDEVICEAPIS_COMMONS_STORAGE_EVENT_INTERFACE_H
+
+#include <dpl/optional_typedefs.h>
+#include <dpl/shared_ptr.h>
+#include <LocalStorage/ILocalStorage.h>
+
+namespace WrtDeviceApis {
+namespace StorageEvent {
+namespace Api {
+
+class IStorageEvent
+{
+ public :
+
+ virtual std::string getKey() const = 0;
+ virtual DPL::OptionalString getOldValue() const = 0;
+ virtual DPL::OptionalString getNewValue() const = 0;
+ virtual std::string getUrl() const = 0;
+ virtual LocalStorage::Api::ILocalStoragePtr getStorageArea() const = 0;
+
+ virtual void setKey(const std::string &inKey) = 0;
+ virtual void setOldValue(const std::string &inValue) = 0;
+ virtual void setNewValue(const std::string &inValue) = 0;
+ virtual void setUrl(const std::string &inUrl) = 0;
+ virtual void setStorageArea(
+ const LocalStorage::Api::ILocalStoragePtr &inStorageArea) = 0;
+};
+
+typedef DPL::SharedPtr<IStorageEvent> IStorageEventPtr;
+
+} // Api
+} // StorageEvent
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_COMMONS_STORAGE_EVENT_INTERFACE_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 StorageEvent.cpp
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Storage event class implementation
+ */
+
+#include "StorageEvent.h"
+
+namespace WrtDeviceApis {
+namespace StorageEvent {
+namespace Api {
+
+StorageEvent::StorageEvent() :
+ m_storageArea(NULL) {}
+
+StorageEvent::StorageEvent(
+ const LocalStorage::Api::ILocalStoragePtr &storageArea) :
+ m_storageArea(storageArea) {}
+
+std::string StorageEvent::getKey() const
+{
+ return m_key;
+}
+
+DPL::OptionalString StorageEvent::getOldValue() const
+{
+ return m_oldValue;
+}
+
+DPL::OptionalString StorageEvent::getNewValue() const
+{
+ return m_newValue;
+}
+std::string StorageEvent::getUrl() const
+{
+ return m_url;
+}
+
+LocalStorage::Api::ILocalStoragePtr StorageEvent::getStorageArea() const
+{
+ return m_storageArea;
+}
+
+void StorageEvent::setKey(const std::string &inKey)
+{
+ m_key = inKey;
+}
+
+void StorageEvent::setOldValue(const std::string &inValue)
+{
+ m_oldValue = DPL::FromUTF8String(inValue);
+}
+
+void StorageEvent::setNewValue(const std::string &inValue)
+{
+ m_newValue = DPL::FromUTF8String(inValue);
+}
+
+void StorageEvent::setUrl(const std::string &inUrl)
+{
+ m_url = inUrl;
+}
+
+void StorageEvent::setStorageArea(
+ const LocalStorage::Api::ILocalStoragePtr &inStorageArea)
+{
+ m_storageArea = inStorageArea;
+}
+
+} // Api
+} // StorageEvent
+} // 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 StorageEvent.h
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Storage event class
+ */
+
+#ifndef WRTDEVICEAPIS_STORAGEEVENT_STORAGE_EVENT_H
+#define WRTDEVICEAPIS_STORAGEEVENT_STORAGE_EVENT_H
+
+#include <dpl/optional_typedefs.h>
+#include "IStorageEvent.h"
+
+namespace WrtDeviceApis {
+namespace StorageEvent {
+namespace Api {
+
+class StorageEvent : public IStorageEvent
+{
+ public :
+
+ StorageEvent();
+ explicit StorageEvent(
+ const LocalStorage::Api::ILocalStoragePtr &storageArea);
+
+ std::string getKey() const;
+ DPL::OptionalString getOldValue() const;
+ DPL::OptionalString getNewValue() const;
+ std::string getUrl() const;
+ LocalStorage::Api::ILocalStoragePtr getStorageArea() const;
+
+ void setKey(const std::string &inKey);
+ void setOldValue(const std::string &inValue);
+ void setNewValue(const std::string &inValue);
+ void setUrl(const std::string &inUrl);
+ void setStorageArea(
+ const LocalStorage::Api::ILocalStoragePtr &inStorageArea);
+
+ private :
+ std::string m_key;
+ DPL::OptionalString m_oldValue;
+ DPL::OptionalString m_newValue;
+ std::string m_url;
+ LocalStorage::Api::ILocalStoragePtr m_storageArea;
+};
+
+} // Api
+} // StorageEvent
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_STORAGEEVENT_STORAGE_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 StorageEventMgr.cpp
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Storage event getter
+ */
+
+#include "StorageEventMgr.h"
+#include "StorageEvent.h"
+
+namespace WrtDeviceApis {
+namespace StorageEvent {
+namespace Api {
+
+IStorageEventPtr getStorageEvent()
+{
+ return IStorageEventPtr(new StorageEvent());
+}
+
+} // Api
+} // StorageEvent
+} // 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 StorageEventMgr.h
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Storage event interfece
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_STORAGE_EVENT_MGR_H
+#define WRTDEVICEAPIS_COMMONS_STORAGE_EVENT_MGR_H
+
+#include "IStorageEvent.h"
+
+namespace WrtDeviceApis {
+namespace StorageEvent {
+namespace Api {
+
+IStorageEventPtr getStorageEvent();
+
+} // Api
+} // StorageEvent
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_COMMONS_STORAGE_EVENT_MGR_H
+
--- /dev/null
+get_current_path()
+
+set(API_STORAGE_EVENT_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+ )
+
+set(SRCS_API_STORAGE_EVENT
+ ${CURRENT_PATH}/StorageEventMgr.cpp
+ ${CURRENT_PATH}/StorageEvent.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 Taejeong Lee <taejeong.lee@samsung.com>
+ */
+
+#include <SystemInfo/SystemInfo.h>
+#include "ISystemInfo.h"
+
+namespace WrtDeviceApis {
+namespace SystemInfo {
+namespace Api {
+ISystemInfo& ISystemInfo::getInstance()
+{
+ return SystemInfo::getInstance();
+}
+
+ISystemInfo::~ISystemInfo()
+{
+}
+} // Api
+} // SystemInfo
+} // 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.
+ */
+/**
+ * @author Taejeong Lee <taejeong.lee@samsung.com>
+ */
+
+#ifndef WRTDEVICEAPIS_SYSTEMINFO_INTERFACE_H_
+#define WRTDEVICEAPIS_SYSTEMINFO_INTERFACE_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace SystemInfo {
+namespace Api {
+class ISystemInfo : public DPL::Noncopyable
+{
+ public:
+ static ISystemInfo& getInstance();
+
+ public:
+ virtual ~ISystemInfo() = 0;
+ virtual string getDeviceModelName() = 0;
+ virtual string getDeviceVersion() = 0;
+};
+} // Api
+} // SystemInfo
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_SYSTEMINFO_INTERFACE_H_
\ No newline at end of file
--- /dev/null
+get_current_path()
+
+set(API_SYSTEMINFO_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+ )
+
+set(SRCS_API_SYSTEMINFO
+ ${CURRENT_PATH}/ISystemInfo.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 CalendarTask.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#include "CalendarTask.h"
+#include <dpl/log/log.h>
+
+namespace {
+const int UNDEFINED_TASK_ID = -1;
+}
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+CalendarTask::CalendarTask() :
+ m_id(UNDEFINED_TASK_ID),
+ m_taskId(UNDEFINED_TASK_ID),
+ m_dueDate(UNDEFINED_TASK_TIME_T_VALUE),
+ m_status(UNDEFINED_STATUS),
+ m_priority(UNDEFINED_PRIORITY),
+ m_descriptionIsSet(false),
+ m_subjectIsSet(false)
+{
+}
+
+CalendarTask::~CalendarTask()
+{
+}
+
+bool CalendarTask::getIdIsSet() const
+{
+ return m_id != UNDEFINED_TASK_ID;
+}
+
+bool CalendarTask::getTaskIdIsSet() const
+{
+ return m_taskId != UNDEFINED_TASK_ID;
+}
+
+bool CalendarTask::getDescriptionIsSet() const
+{
+ return m_descriptionIsSet;
+}
+
+bool CalendarTask::getSubjectIsSet() const
+{
+ return m_subjectIsSet;
+}
+
+bool CalendarTask::getDueDateIsSet() const
+{
+ return m_dueDate >= 0;
+}
+
+bool CalendarTask::getStatusIsSet() const
+{
+ return m_status != UNDEFINED_STATUS;
+}
+
+bool CalendarTask::getPriorityIsSet() const
+{
+ return m_priority != UNDEFINED_PRIORITY;
+}
+
+int CalendarTask::getTaskId() const
+{
+ return m_taskId;
+}
+
+void CalendarTask::setTaskId(int value)
+{
+ m_taskId = value;
+}
+
+int CalendarTask::getId() const
+{
+ return m_id;
+}
+
+void CalendarTask::setId(int value)
+{
+ m_id = value;
+}
+
+std::string CalendarTask::getDescription() const
+{
+ return m_description;
+}
+
+void CalendarTask::setDescription(const std::string &value)
+{
+ m_descriptionIsSet = true;
+ m_description = value;
+}
+
+std::string CalendarTask::getSubject() const
+{
+ return m_subject;
+}
+
+void CalendarTask::setSubject(const std::string &value)
+{
+ m_subjectIsSet = true;
+ m_subject = value;
+}
+
+time_t CalendarTask::getDueDate() const
+{
+ return m_dueDate > 0 ? m_dueDate : 0;
+}
+
+void CalendarTask::setDueDate(time_t value)
+{
+ m_dueDate = value;
+}
+
+CalendarTask::TaskStatus CalendarTask::getStatus() const
+{
+ return m_status == UNDEFINED_STATUS ? STATUS_NEEDS_ACTION : m_status;
+}
+
+void CalendarTask::setStatus(TaskStatus value)
+{
+ m_status = value;
+}
+
+CalendarTask::TaskPriority CalendarTask::getPriority() const
+{
+ return m_priority == UNDEFINED_PRIORITY ? LOW_PRIORITY : m_priority;
+}
+
+void CalendarTask::setPriority(TaskPriority value)
+{
+ m_priority = value;
+}
+
+void CalendarTask::display() const
+{
+ LogDebug("m_id " << m_id);
+ LogDebug("m_calendarId " << m_taskId);
+ LogDebug("m_description " << m_description);
+ LogDebug("m_subject " << m_subject);
+ LogDebug("m_dueDate " << m_dueDate);
+ LogDebug("m_status " << m_status);
+ LogDebug("m_priority " << m_priority);
+}
+
+bool CalendarTask::validate() const
+{
+ if (m_dueDate == -1) {
+ LogError("Incorrect due time value detected");
+ return false;
+ }
+ if (m_status == CalendarTask::INVALID_STATUS) {
+ LogError("Incorrect status value detected");
+ return false;
+ }
+ if (m_priority == CalendarTask::INVALID_PRIORITY) {
+ LogError("Incorrect priority value detected");
+ return false;
+ }
+ return 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 CalendarTask.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_CALENDAR_TASK_H_
+#define WRTDEVICEAPIS_TASK_CALENDAR_TASK_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+//typedef std::vector<std::string> CategoryList;
+//typedef DPL::SharedPtr<CategoryList> CategoryListPtr;
+
+//typedef std::vector<unsigned short> StatusList;
+//typedef DPL::SharedPtr<CategoryList> StatusListPtr;
+//typedef std::vector<unsigned short> PriorityList;
+//typedef DPL::SharedPtr<CategoryList> PriorityListPtr;
+
+/* This object represents a single calendar event */
+class CalendarTask
+{
+ public:
+ typedef enum
+ {
+ STATUS_COMPLETED,
+ STATUS_NEEDS_ACTION,
+ STATUS_CANCELLED,
+ STATUS_IN_PROCESS,
+ INVALID_STATUS = 10000,
+ UNDEFINED_STATUS /* should be used only to mark a fact filter is not set */
+ } TaskStatus;
+
+ typedef enum
+ {
+ HIGH_PRIORITY,
+ MEDIUM_PRIORITY,
+ LOW_PRIORITY,
+ INVALID_PRIORITY = 10000,
+ UNDEFINED_PRIORITY /* should be used only to mark a fact filter is not set */
+ } TaskPriority;
+
+ typedef enum
+ {
+ UNDEFINED_TASK_TIME_T_VALUE = -2,
+ INVALID_TASK_TIME_T_VALUE = -1
+ } TaskTimeTValues;
+
+ typedef enum
+ {
+ UNDEFINED_TASK_ID = -1
+ } TaskIdValues;
+
+ CalendarTask();
+ virtual ~CalendarTask();
+
+ int getId() const;
+ void setId(int value);
+
+ int getTaskId() const;
+ void setTaskId(int value);
+
+ std::string getDescription() const;
+ void setDescription(const std::string &value);
+
+ std::string getSubject() const;
+ void setSubject(const std::string &value);
+
+ time_t getDueDate() const;
+ void setDueDate(time_t value);
+
+ TaskStatus getStatus() const;
+ void setStatus(TaskStatus value);
+
+ TaskPriority getPriority() const;
+ void setPriority(TaskPriority value);
+
+ void display() const;
+ bool validate() const;
+
+ bool getIdIsSet() const;
+ bool getTaskIdIsSet() const;
+ bool getDescriptionIsSet() const;
+ bool getSubjectIsSet() const;
+ bool getDueDateIsSet() const;
+ bool getStatusIsSet() const;
+ bool getPriorityIsSet() const;
+
+ protected:
+ int m_id;
+ int m_taskId;
+ std::string m_description;
+ std::string m_subject;
+ time_t m_dueDate;
+ TaskStatus m_status;
+ TaskPriority m_priority;
+
+ bool m_descriptionIsSet;
+ bool m_subjectIsSet;
+};
+
+typedef DPL::SharedPtr<CalendarTask> CalendarTaskPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_TASK_CALENDAR_TASK_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 IEventAddTask.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_IEVENT_ADD_TASK_H_
+#define WRTDEVICEAPIS_TASK_IEVENT_ADD_TASK_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Task/CalendarTask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class IEventAddTask : public Commons::IEvent<IEventAddTask>
+{
+ CalendarTaskPtr m_taskAdd;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setTask(CalendarTaskPtr value)
+ {
+ m_taskAdd = value;
+ }
+ CalendarTaskPtr getTask() const
+ {
+ return m_taskAdd;
+ }
+ IEventAddTask() :
+ m_taskAdd(NULL),
+ m_result(false)
+ {
+ LogDebug("entered");
+ }
+ ~IEventAddTask()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventAddTask> IEventAddTaskPtr;
+
+}
+}
+}
+#endif // WRTDEVICEAPIS_TASK_IEVENT_ADD_TASK_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 IEventCreateTask.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_IEVENT_CREATE_TASK_H_
+#define WRTDEVICEAPIS_TASK_IEVENT_CREATE_TASK_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Task/CalendarTask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class IEventCreateTask : public Commons::IEvent<IEventCreateTask>
+{
+ CalendarTaskPtr m_task;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setTask(CalendarTaskPtr value)
+ {
+ m_task = value;
+ }
+ CalendarTaskPtr getTask() const
+ {
+ return m_task;
+ }
+
+ IEventCreateTask() :
+ m_task(NULL),
+ m_result(false)
+ {
+ }
+ ~IEventCreateTask()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventCreateTask> IEventCreateTaskPtr;
+
+}
+}
+}
+#endif // WRTDEVICEAPIS_TASK_IEVENT_CREATE_TASK_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 IEventDeleteTask.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_IEVENT_DELETE_TASK_H_
+#define WRTDEVICEAPIS_TASK_IEVENT_DELETE_TASK_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Task/CalendarTask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class IEventDeleteTask : public Commons::IEvent<IEventDeleteTask>
+{
+ CalendarTaskPtr m_task;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setTask(CalendarTaskPtr value)
+ {
+ m_task = value;
+ }
+ CalendarTaskPtr getTask() const
+ {
+ return m_task;
+ }
+ IEventDeleteTask() :
+ m_task(NULL),
+ m_result(false)
+ {
+ }
+ ~IEventDeleteTask()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventDeleteTask> IEventDeleteTaskPtr;
+
+}
+}
+}
+#endif // WRTDEVICEAPIS_TASK_IEVENT_DELETE_TASK_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 IEventFindTasks.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_IEVENT_FIND_TASKS_H_
+#define WRTDEVICEAPIS_TASK_IEVENT_FIND_TASKS_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Task/CalendarTask.h>
+#include <Task/TaskFilter.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class IEventFindTasks : public Commons::IEvent<IEventFindTasks>
+{
+ /* user is responsible to free objects inside list */
+ std::vector<CalendarTaskPtr> m_tasks; //OUTPUT: result list
+ bool m_result; //OUTPUT: operation result
+ TaskFilterPtr m_filter; //INPUT: filters
+ int m_firstTask; //INPUT: index of first found event to include on list
+ int m_lastTask; //INPUT: index of last found event to include on list
+ public:
+ void setFirstTask(int value)
+ {
+ m_firstTask = value;
+ }
+ int getFirstTask() const
+ {
+ return m_firstTask;
+ }
+ void setLastTask(int value)
+ {
+ m_lastTask = value;
+ }
+ int getLastTask() const
+ {
+ return m_lastTask;
+ }
+ void setFilter(TaskFilterPtr value)
+ {
+ m_filter = value;
+ }
+ TaskFilterPtr getFilter() const
+ {
+ return m_filter;
+ }
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void addTask(CalendarTaskPtr value)
+ {
+ m_tasks.push_back(value);
+ }
+ std::vector<CalendarTaskPtr> getTasks()
+ {
+ return m_tasks;
+ }
+ IEventFindTasks() : m_result(false),
+ m_firstTask(0),
+ m_lastTask(-1)
+ {
+ }
+ ~IEventFindTasks()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventFindTasks> IEventFindTasksPtr;
+
+}
+}
+}
+#endif // WRTDEVICEAPIS_TASK_IEVENT_FIND_TASKS_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 IEventGetTasks.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_IEVENT_GET_TASKS_H_
+#define WRTDEVICEAPIS_TASK_IEVENT_GET_TASKS_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Task/ITask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class IEventGetTasks : public Commons::IEvent<IEventGetTasks>
+{
+ std::vector<ITaskPtr> m_tasks;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void addTask(ITaskPtr value)
+ {
+ m_tasks.push_back(value);
+ }
+ std::vector<ITaskPtr> getTasks() const
+ {
+ return m_tasks;
+ }
+ IEventGetTasks() :
+ m_result(false)
+ {
+ }
+ ~IEventGetTasks()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventGetTasks> IEventGetTasksPtr;
+
+}
+}
+}
+#endif // WRTDEVICEAPIS_TASK_IEVENT_UPDATE_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 IEventUpdateTask.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_IEVENT_UPDATE_TASK_H_
+#define WRTDEVICEAPIS_TASK_IEVENT_UPDATE_TASK_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Task/CalendarTask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class IEventUpdateTask : public Commons::IEvent<IEventUpdateTask>
+{
+ CalendarTaskPtr m_task;
+ bool m_result;
+ public:
+ void setResult(bool value)
+ {
+ m_result = value;
+ }
+ bool getResult() const
+ {
+ return m_result;
+ }
+ void setTask(CalendarTaskPtr value)
+ {
+ m_task = value;
+ }
+ CalendarTaskPtr getTask() const
+ {
+ return m_task;
+ }
+
+ IEventUpdateTask() :
+ m_task(NULL),
+ m_result(false)
+ {
+ }
+ ~IEventUpdateTask()
+ {
+ }
+ virtual void clearOnCancel()
+ {
+ }
+};
+
+typedef DPL::SharedPtr<IEventUpdateTask> IEventUpdateTaskPtr;
+
+}
+}
+}
+#endif // WRTDEVICEAPIS_TASK_IEVENT_UPDATE_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 ITask.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#include "ITask.h"
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+//thread pool
+ITask::ITask() :
+ Commons::EventRequestReceiver<IEventAddTask>(
+ Commons::ThreadEnum::TASK_THREAD),
+ Commons::EventRequestReceiver<IEventDeleteTask>(
+ Commons::ThreadEnum::TASK_THREAD),
+ Commons::EventRequestReceiver<IEventUpdateTask>(
+ Commons::ThreadEnum::TASK_THREAD),
+ Commons::EventRequestReceiver<IEventFindTasks>(
+ Commons::ThreadEnum::TASK_THREAD),
+ Commons::EventRequestReceiver<IEventCreateTask>(
+ Commons::ThreadEnum::TASK_THREAD),
+ m_id(0),
+ m_accountId(0),
+ m_type(DEVICE_TASK)
+{
+}
+
+ITask::~ITask()
+{
+}
+
+void ITask::createTask(IEventCreateTaskPtr &event)
+{
+ Commons::EventRequestReceiver<IEventCreateTask>::PostRequest(event);
+}
+
+void ITask::addTask(IEventAddTaskPtr &event)
+{
+ Commons::EventRequestReceiver<IEventAddTask>::PostRequest(event);
+}
+
+void ITask::updateTask(IEventUpdateTaskPtr &event)
+{
+ Commons::EventRequestReceiver<IEventUpdateTask>::PostRequest(event);
+}
+
+void ITask::deleteTask(IEventDeleteTaskPtr &event)
+{
+ Commons::EventRequestReceiver<IEventDeleteTask>::PostRequest(event);
+}
+
+void ITask::findTasks(IEventFindTasksPtr &event)
+{
+ Commons::EventRequestReceiver<IEventFindTasks>::PostRequest(event);
+}
+
+}
+}
+}
--- /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 ITask.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_ITASK_H_
+#define WRTDEVICEAPIS_TASK_ITASK_H_
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Task/CalendarTask.h>
+#include <Task/TaskFilter.h>
+#include <Task/IEventAddTask.h>
+#include <Task/IEventCreateTask.h>
+#include <Task/IEventDeleteTask.h>
+#include <Task/IEventFindTasks.h>
+#include <Task/IEventUpdateTask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class ITask : public Commons::EventRequestReceiver< IEventAddTask >,
+ public Commons::EventRequestReceiver< IEventDeleteTask>,
+ public Commons::EventRequestReceiver< IEventUpdateTask>,
+ public Commons::EventRequestReceiver< IEventFindTasks>,
+ public Commons::EventRequestReceiver< IEventCreateTask>
+{
+ public:
+
+ typedef enum
+ {
+ SIM_TASK,
+ DEVICE_TASK
+ } TaskType;
+
+ ITask();
+ virtual ~ITask();
+ virtual void createTask(IEventCreateTaskPtr &event);
+ virtual void addTask(IEventAddTaskPtr &event);
+ virtual void updateTask(IEventUpdateTaskPtr &event);
+ virtual void deleteTask(IEventDeleteTaskPtr &event);
+ virtual void findTasks(IEventFindTasksPtr &event);
+
+ virtual std::string getName() const
+ {
+ return m_name;
+ }
+ virtual void setName(const std::string &value)
+ {
+ m_name = value;
+ }
+ virtual TaskType getType() const
+ {
+ return m_type;
+ }
+ virtual void setType(const TaskType value)
+ {
+ m_type = value;
+ }
+ virtual int getId() const
+ {
+ return m_id;
+ }
+ virtual void setId(const int value)
+ {
+ m_id = value;
+ }
+ virtual int getAccountId() const
+ {
+ return m_accountId;
+ }
+ virtual void setAccountId(const int value)
+ {
+ m_accountId = value;
+ }
+ protected:
+ int m_id;
+ int m_accountId;
+ std::string m_name;
+ TaskType m_type;
+
+ virtual void OnRequestReceived(const IEventAddTaskPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventDeleteTaskPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventUpdateTaskPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventFindTasksPtr &event) = 0;
+ virtual void OnRequestReceived(const IEventCreateTaskPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<ITask> ITaskPtr;
+
+}
+}
+}
+
+#endif //WRTDEVICEAPIS_TASK_ITASK_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 ITaskManager.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#include "ITaskManager.h"
+#include <Commons/ThreadPool.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+ITaskManager::ITaskManager() :
+ Commons::EventRequestReceiver< IEventGetTasks>(
+ Commons::ThreadEnum::TASK_THREAD)
+{
+}
+
+ITaskManager::~ITaskManager()
+{
+}
+
+void ITaskManager::getTasks(const IEventGetTasksPtr &event)
+{
+ LogDebug("entered");
+ PostRequest(event);
+}
+
+}
+}
+}
--- /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 ITaskManager.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_ITASK_MANAGER_H_
+#define WRTDEVICEAPIS_TASK_ITASK_MANAGER_H_
+
+#include <Task/ITask.h>
+#include <Task/IEventGetTasks.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class ITaskManager : public Commons::EventRequestReceiver< IEventGetTasks >
+{
+ public:
+ ITaskManager();
+ virtual ~ITaskManager();
+ virtual void getTasks(const IEventGetTasksPtr &event);
+ protected:
+ virtual void OnRequestReceived(const IEventGetTasksPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<ITaskManager> ITaskManagerPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_TASK_ITASK_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.
+ */
+/**
+ * @file TaskFactory.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#include "TaskFactory.h"
+#include "ITaskManager.h"
+#include "ITask.h"
+#include <Task/TaskManager.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+ITaskManagerPtr TaskFactory::createTaskManagerObject()
+{
+ ITaskManagerPtr result(new TaskManager());
+ return result;
+}
+
+ITaskPtr TaskFactory::createTaskObject()
+{
+ ITaskPtr result(new Task());
+ return result;
+}
+
+TaskFactory& TaskFactory::getInstance()
+{
+ static TaskFactory theInstance;
+ return theInstance;
+}
+
+}
+}
+}
\ 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 TaskFactory.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_TASK_FACTORY_H_
+#define WRTDEVICEAPIS_TASK_TASK_FACTORY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Task/ITaskManager.h>
+#include <Task/ITask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+class TaskFactory : private DPL::Noncopyable
+{
+ private:
+ TaskFactory()
+ {
+ }
+ public:
+ static TaskFactory& getInstance();
+ ITaskManagerPtr createTaskManagerObject();
+ ITaskPtr createTaskObject();
+};
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_TASK_TASK_FACTORY_H_
\ 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 TaskFilter.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#include "TaskFilter.h"
+#include <dpl/log/log.h>
+
+/**
+ * @file TaskFilter.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+TaskFilter::TaskFilter() :
+ m_id(TASK_FILTER_UNDEFINED_ID),
+ m_taskId(TASK_FILTER_UNDEFINED_TASK_ID),
+ m_dueDateMin(TASK_FILTER_UNDEFINED_TIME_T_MEMBERS),
+ m_dueDateMax(TASK_FILTER_UNDEFINED_TIME_T_MEMBERS),
+ // m_priority(CalendarTask::UNDEFINED_PRIORITY),
+ // m_status(CalendarTask::UNDEFINED_STATUS),
+ m_status(new StatusList()),
+ m_priority(new PriorityList()),
+ m_descriptionIsSet(false),
+ m_subjectIsSet(false),
+ m_locationIsSet(false)
+{
+}
+
+TaskFilter::~TaskFilter()
+{
+}
+
+int TaskFilter::getIdFilter() const
+{
+ return m_id;
+}
+
+void TaskFilter::setIdFilter(int value)
+{
+ m_id = value;
+}
+
+int TaskFilter::getTaskIdFilter() const
+{
+ return m_taskId;
+}
+
+void TaskFilter::setTaskIdFilter(int value)
+{
+ m_taskId = value;
+}
+
+std::string TaskFilter::getDescriptionFilter() const
+{
+ return m_description;
+}
+
+void TaskFilter::setDescriptionFilter(const std::string &value)
+{
+ m_description = value;
+ m_descriptionIsSet = true;
+}
+
+std::string TaskFilter::getSubjectFilter() const
+{
+ return m_subject;
+}
+
+void TaskFilter::setSubjectFilter(const std::string &value)
+{
+ m_subject = value;
+ m_subjectIsSet = true;
+}
+
+time_t TaskFilter::getDueDateMinFilter() const
+{
+ return m_dueDateMin;
+}
+
+time_t TaskFilter::getDueDateMaxFilter() const
+{
+ return m_dueDateMax;
+}
+
+void TaskFilter::setDueDateMinFilter(time_t value)
+{
+ m_dueDateMin = value;
+}
+
+void TaskFilter::setDueDateMaxFilter(time_t value)
+{
+ m_dueDateMax = value;
+}
+
+void TaskFilter::setDueDateFilter(time_t value)
+{
+ setDueDateMinFilter(value);
+ setDueDateMaxFilter(value);
+}
+
+PriorityListPtr TaskFilter::getPriorityFilter() const
+{
+ return m_priority;
+}
+void TaskFilter::setPriorityFilter(const PriorityListPtr &value)
+{
+ m_priority = value;
+}
+
+StatusListPtr TaskFilter::getStatusFilter() const
+{
+ return m_status;
+}
+void TaskFilter::setStatusFilter(const StatusListPtr &value)
+{
+ m_status = value;
+}
+
+//CalendarTask::TaskPriority TaskFilter::getPriorityFilter() const
+//{
+// return m_priority;
+//}
+
+//void TaskFilter::setPriorityFilter(CalendarTask::TaskPriority value )
+//{
+// m_priority = value;
+//}
+
+//CalendarTask::TaskStatus TaskFilter::getStatusFilter() const
+//{
+// return m_status;
+//}
+
+//void TaskFilter::setStatusFilter(CalendarTask::TaskStatus value )
+//{
+// m_status = value;
+//}
+
+bool TaskFilter::getIdIsSet() const
+{
+ return m_id != TASK_FILTER_UNDEFINED_ID;
+}
+
+bool TaskFilter::getTaskIdIsSet() const
+{
+ return m_taskId != TASK_FILTER_UNDEFINED_TASK_ID;
+}
+
+bool TaskFilter::getDescriptionIsSet() const
+{
+ return m_descriptionIsSet;
+}
+
+bool TaskFilter::getSubjectIsSet() const
+{
+ return m_subjectIsSet;
+}
+
+bool TaskFilter::getDueDateIsSet() const
+{
+ return (m_dueDateMin != TASK_FILTER_UNDEFINED_TIME_T_MEMBERS ||
+ m_dueDateMax != TASK_FILTER_UNDEFINED_TIME_T_MEMBERS);
+}
+
+//bool TaskFilter::getPriorityIsSet() const
+//{
+// return m_priority != CalendarTask::UNDEFINED_PRIORITY;
+//}
+
+//bool TaskFilter::getStatusIsSet() const
+//{
+// return m_status != CalendarTask::UNDEFINED_STATUS;
+//}
+
+bool TaskFilter::getPriorityIsSet() const
+{
+ if (m_priority) {
+ return m_priority->size() > 0;
+ }
+ return false;
+}
+
+bool TaskFilter::getStatusIsSet() const
+{
+ if (m_status) {
+ return m_status->size() > 0;
+ }
+ return false;
+}
+
+}
+}
+}
--- /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 TaskFilter.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_TASK_FILTER_H_
+#define WRTDEVICEAPIS_TASK_TASK_FILTER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Task/CalendarTask.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+namespace Api {
+
+const int TASK_FILTER_UNDEFINED_ID = -1;
+const int TASK_FILTER_UNDEFINED_TASK_ID = -1;
+const int TASK_FILTER_UNDEFINED_TIME_T_MEMBERS = -1;
+
+typedef std::vector<CalendarTask::TaskStatus> StatusList;
+typedef DPL::SharedPtr<StatusList> StatusListPtr;
+
+typedef std::vector<CalendarTask::TaskPriority> PriorityList;
+typedef DPL::SharedPtr<PriorityList> PriorityListPtr;
+
+class TaskFilter
+{
+ public:
+
+ TaskFilter();
+ virtual ~TaskFilter();
+
+ int getIdFilter() const;
+ void setIdFilter(int value);
+
+ int getTaskIdFilter() const;
+ void setTaskIdFilter(int value);
+
+ std::string getDescriptionFilter() const;
+ void setDescriptionFilter(const std::string &value);
+
+ std::string getSubjectFilter() const;
+ void setSubjectFilter(const std::string &value);
+
+ time_t getDueDateMinFilter() const;
+ time_t getDueDateMaxFilter() const;
+ void setDueDateMinFilter(time_t value);
+ void setDueDateMaxFilter(time_t value);
+ void setDueDateFilter(time_t value);
+
+ //CalendarTask::TaskPriority getPriorityFilter() const;
+ // void setPriorityFilter(CalendarTask::TaskPriority value );
+
+ // CalendarTask::TaskStatus getStatusFilter() const;
+ // void setStatusFilter(CalendarTask::TaskStatus value );
+
+ PriorityListPtr getPriorityFilter() const;
+ void setPriorityFilter(const PriorityListPtr &value);
+
+ StatusListPtr getStatusFilter() const;
+ void setStatusFilter(const StatusListPtr &value);
+
+ bool getIdIsSet() const;
+ bool getTaskIdIsSet() const;
+ bool getDescriptionIsSet() const;
+ bool getSubjectIsSet() const;
+ bool getDueDateIsSet() const;
+ bool getPriorityIsSet() const;
+ bool getStatusIsSet() const;
+
+ protected:
+ int m_id;
+ int m_taskId;
+ std::string m_description;
+ std::string m_subject;
+ time_t m_dueDateMin;
+ time_t m_dueDateMax;
+ StatusListPtr m_status;
+ PriorityListPtr m_priority;
+ //CalendarTask::TaskStatus m_status;
+ //CalendarTask::TaskPriority m_priority;
+
+ bool m_descriptionIsSet;
+ bool m_subjectIsSet;
+ bool m_locationIsSet;
+};
+
+typedef DPL::SharedPtr<TaskFilter> TaskFilterPtr;
+
+}
+}
+}
+
+#endif // WRTDEVICEAPIS_TASK_EVENT_FILTER_H_
--- /dev/null
+get_current_path()
+
+set(API_TASK_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_TASK
+ ${CURRENT_PATH}/CalendarTask.cpp
+ ${CURRENT_PATH}/TaskFactory.cpp
+ ${CURRENT_PATH}/TaskFilter.cpp
+ ${CURRENT_PATH}/ITask.cpp
+ ${CURRENT_PATH}/ITaskManager.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 IWidget.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef INTERFACE_WIDGET_CONFIG_INFO_H
+#define INTERFACE_WIDGET_CONFIG_INFO_H
+
+#include <string>
+
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis{
+namespace Widget{
+namespace Api {
+
+class IWidget;
+typedef DPL::SharedPtr<IWidget> IWidgetPtr;
+
+class IWidget
+{
+ public: // methods
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getAuthor() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getAuthorEmail() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getAuthorHref() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getDescription() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getId() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getName() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getShortName() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual std::string getVersion() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual unsigned int getHeight() const = 0;
+
+ /**
+ * getter for property from widget config xml
+ * @throw Commons::PlatformException if problem with platform occured
+ * @throw Commons::NullPointerException if problem with platform occured
+ * @throw Commons::SecurityException if wrt forbiden using this function
+ * */
+ virtual unsigned int getWidth() const = 0;
+
+ virtual ~IWidget()
+ {
+ }
+};
+
+}
+}
+}
+
+#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 WidgetFactory.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "WidgetFactory.h"
+
+#include <Widget/Widget.h>
+
+namespace WrtDeviceApis {
+namespace Widget {
+namespace Api {
+
+IWidgetPtr WidgetFactory::createWidget(const Commons::IWrtWrapperPtr& wrapper)
+{
+ return IWidgetPtr(new WrtDeviceApis::Widget::Widget(wrapper));
+}
+
+}
+}
+}
--- /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 WidgetFactory.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef _WIDGET_FACTORY_H
+#define _WIDGET_FACTORY_H
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <Commons/WrtWrapper/IWrtWrapper.h>
+#include <Widget/IWidget.h>
+
+namespace WrtDeviceApis {
+namespace Widget {
+namespace Api {
+
+class WidgetFactory : private DPL::Noncopyable
+{
+ public:
+
+ /**
+ * Create widget
+ * @param[in] id of the widget
+ */
+ static IWidgetPtr createWidget(const Commons::IWrtWrapperPtr& wrapper);
+
+ private:
+ WidgetFactory()
+ {
+ }
+};
+
+}
+}
+}
+
+#endif
--- /dev/null
+get_current_path()
+
+set(API_WIDGET_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_WIDGET
+ ${CURRENT_PATH}/WidgetFactory.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 IWidgetDB.h
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Widget interface to access WRT DB
+ */
+
+#ifndef WRTDEVICEAPIS_WIDGETDB_IWIDGETDB_H_
+#define WRTDEVICEAPIS_WIDGETDB_IWIDGETDB_H_
+
+#include "IWidgetFeature.h"
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+namespace Api {
+
+class IWidgetDB;
+typedef DPL::SharedPtr<IWidgetDB> IWidgetDBPtr;
+
+typedef std::vector<IWidgetFeaturePtr> Features;
+
+enum class ConfigAttribute {
+ ID,
+ VERSION,
+ DESCRIPTION,
+ LICENSE,
+ LICENSE_HREF,
+ AUTHOR_NAME,
+ AUTHOR_HREF,
+ AUTHOR_EMAIL,
+ NAME,
+ SHORT_NAME,
+ ICON,
+ ACCESS_NETWORK,
+ WIDTH,
+ HEIGHT,
+ INSTALL_PATH,
+ PUBLIC_STORAGE_PATH
+};
+
+enum class InstallationStatus
+{
+ STATUS_INSTALLED,
+ STATUS_LATEST,
+ STATUS_UNINSTALLED
+};
+
+
+class IWidgetDB
+{
+ public:
+
+ virtual int getWidgetId() const = 0;
+
+ virtual std::string getLanguage() const = 0;
+
+ virtual std::string getConfigValue(ConfigAttribute attribute) const = 0;
+
+ virtual std::string getUserAgent() const = 0;
+
+ virtual InstallationStatus checkInstallationStatus(
+ const std::string& gid,
+ const std::string& name,
+ const std::string& version) const = 0;
+
+ virtual Features getWidgetFeatures() const = 0;
+
+ virtual Features getRegisteredFeatures() const = 0;
+
+ virtual std::string getWidgetInstallationPath() const = 0;
+
+ virtual std::string getWidgetPersistentStoragePath() const = 0;
+
+ virtual std::string getWidgetTemporaryStoragePath() const = 0;
+
+ virtual ~IWidgetDB()
+ {
+ }
+
+};
+
+} // Api
+} // WidgetDB
+} // WrtDeviceApis
+
+#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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_INTERFACE_H_
+#define WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_INTERFACE_H_
+
+#include <map>
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+namespace Api {
+
+class IWidgetFeature
+{
+ public:
+ typedef std::map<std::string, std::string> Params;
+ typedef Params::const_iterator ParamsIterator;
+
+ public:
+
+ virtual ~IWidgetFeature()
+ {
+ }
+
+ virtual std::string getName() const = 0;
+
+ virtual bool isRequired() const = 0;
+
+ virtual Params getParams() const = 0;
+
+ virtual void addParam(const std::string& paramName,
+ const std::string& paramValue) = 0;
+
+ virtual bool isRequestedByWidget() const = 0;
+};
+
+typedef DPL::SharedPtr<IWidgetFeature> IWidgetFeaturePtr;
+
+} // Api
+} // WidgetDB
+} // WrtDeviceApis
+
+#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 IWidgetDBMgr.cpp
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <WidgetDB/WidgetDB.h>
+#include "IWidgetDB.h"
+#include "WidgetDBMgr.h"
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+namespace Api {
+
+IWidgetDBPtr getWidgetDB(int widgetId)
+{
+ return IWidgetDBPtr(new WrtDeviceApis::WidgetDB::WidgetDB(widgetId));
+}
+
+} // Api
+} // WidgetDB
+} // 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 IWidgetDB.h
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief Widget interface to access WRT DB
+ */
+
+#ifndef WRTDEVICEAPIS_WIDGETDB_WIDGETDB_MGR_H
+#define WRTDEVICEAPIS_WIDGETDB_WIDGETDB_MGR_H
+
+#include "IWidgetDB.h"
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+namespace Api {
+
+IWidgetDBPtr getWidgetDB(int widgetId);
+
+} // Api
+} // WidgetDB
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_WIDGETDB_WIDGETDB_MGR_H
+
--- /dev/null
+get_current_path()
+
+set(API_WIDGETDB_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_API_WIDGETDB
+ ${CURRENT_PATH}/WidgetDBMgr.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_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${PLATFORM}
+)
+
+add_subdirectory(API)
+add_subdirectory(${PLATFORM})
+add_subdirectory(packages)
--- /dev/null
+Platform abstraction
--- /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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_ACCELEROMETER_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Accelerometer)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_ACCELEROMETER})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_ACCELEROMETER}
+)
+
+set(SRCS
+ ${SRCS_API_ACCELEROMETER}
+ ${SRCS_PLATFORM_IMPLEMENTATION_ACCELEROMETER}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_ACCELEROMETER}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(AccelerationProperties.h)
+install_header_file(AccelerometerFactory.h)
+install_header_file(EventAccelerationChanged.h)
+install_header_file(EventGetCurrentAcceleration.h)
+install_header_file(IAccelerometer.h)
+install_header_file(ISensor.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.
+#
+
+set(TARGET_MODULE_FILESYSTEM "wrt-plugins-filesystem")
+set(TARGET_MODULE_CAMERA "wrt-plugins-camera")
+set(TARGET_MODULE_CALENDAR "wrt-plugins-calendar")
+set(TARGET_MODULE_MESSAGING "wrt-plugins-messaging")
+set(TARGET_MODULE_HAPTICS "wrt-plugins-haptics")
+set(TARGET_MODULE_CONTACT "wrt-plugins-contact")
+set(TARGET_MODULE_MMPLAYER "wrt-plugins-mmplayer")
+set(TARGET_MODULE_CPU "wrt-plugins-cpu")
+set(TARGET_MODULE_ACCELEROMETER "wrt-plugins-accelerometer")
+set(TARGET_MODULE_WIDGET "wrt-plugins-widget")
+set(TARGET_MODULE_TASK "wrt-plugins-task")
+set(TARGET_MODULE_ORIENTATION "wrt-plugins-orientation")
+set(TARGET_MODULE_RADIO "wrt-plugins-radio")
+set(TARGET_MODULE_POWER "wrt-plugins-power")
+set(TARGET_MODULE_PROFILE "wrt-plugins-profile")
+set(TARGET_MODULE_SYSTEMINFO "wrt-plugins-systeminfo")
+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_WIDGETDB "wrt-plugins-widgetdb")
+set(TARGET_MODULE_PLUGIN_MANAGER "wrt-plugins-plugin-manager")
+
+add_subdirectory(Filesystem)
+add_subdirectory(Camera)
+add_subdirectory(Calendar)
+add_subdirectory(Messaging)
+add_subdirectory(Haptics)
+add_subdirectory(Contact)
+add_subdirectory(MMPlayer)
+add_subdirectory(Cpu)
+add_subdirectory(Accelerometer)
+add_subdirectory(Widget)
+add_subdirectory(Task)
+add_subdirectory(Orientation)
+add_subdirectory(Radio)
+add_subdirectory(Power)
+add_subdirectory(Profile)
+add_subdirectory(SystemInfo)
+add_subdirectory(LocalStorage)
+add_subdirectory(WidgetInterfaceDAO)
+add_subdirectory(StorageEvent)
+add_subdirectory(WidgetDB)
+add_subdirectory(PluginManager)
--- /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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_CALENDAR_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Calendar)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_CALENDAR})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_CALENDAR}
+)
+
+set(SRCS
+ ${SRCS_API_CALENDAR}
+ ${SRCS_PLATFORM_IMPLEMENTATION_CALENDAR}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_CALENDAR}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(ICalendar.h)
+install_header_file(ICalendarManager.h)
+install_header_file(CalendarEvent.h)
+install_header_file(CalendarFactory.h)
+install_header_file(EventAddEvent.h)
+install_header_file(EventCreateEvent.h)
+install_header_file(EventDeleteEvent.h)
+install_header_file(EventFilter.h)
+install_header_file(EventFindEvents.h)
+install_header_file(EventGetCalendars.h)
+install_header_file(EventUpdateEvent.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_CAMERA_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Camera)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_CAMERA})
+
+pkg_search_module(wrt-plugin-api REQUIRED wrt-plugin-api>=0.7.0)
+
+include_directories( ${wrt-plugin-api_INCLUDE_DIRS})
+
+set(SRCS
+ ${SRCS_API_CAMERA}
+ ${SRCS_PLATFORM_IMPLEMENTATION_CAMERA}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(CameraFactory.h)
+install_header_file(EventBeginRecording.h)
+install_header_file(EventEndRecording.h)
+install_header_file(EventGetCameras.h)
+install_header_file(EventGetPreviewNode.h)
+install_header_file(EventTakePicture.h)
+install_header_file(ICamera.h)
+install_header_file(ICameraFeature.h)
+install_header_file(ICameraManager.h)
+install_header_file(ICaptureOptions.h)
+install_header_file(IFeatureValue.h)
+install_header_file(SupportCameraPendingOperation.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_CONTACT_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Contact)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_CONTACT})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_CONTACT}
+)
+
+set(SRCS
+ ${SRCS_API_CONTACT}
+ ${SRCS_PLATFORM_IMPLEMENTATION_CONTACT}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_CONTACT}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(ContactAddress.h)
+install_header_file(ContactEmail.h)
+install_header_file(ContactFactory.h)
+install_header_file(ContactFilter.h)
+install_header_file(Contact.h)
+install_header_file(ContactPhoneNumber.h)
+install_header_file(EventAddContact.h)
+install_header_file(EventAddGroup.h)
+install_header_file(EventDeleteContact.h)
+install_header_file(EventDeleteGroup.h)
+install_header_file(EventExportVCard.h)
+install_header_file(EventFindContacts.h)
+install_header_file(EventFindGroup.h)
+install_header_file(EventGetAddressBookItemCount.h)
+install_header_file(EventGetAddressBooks.h)
+install_header_file(EventGetOwnerInfo.h)
+install_header_file(EventUpdateContact.h)
+install_header_file(IAddressBook.h)
+install_header_file(IContactEventPrivateData.h)
+install_header_file(IContactManager.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_CPU_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Cpu)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_CPU})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_CPU}
+)
+
+set(SRCS
+ ${SRCS_API_CPU}
+ ${SRCS_PLATFORM_IMPLEMENTATION_CPU}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_CPU}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(IManager.h)
+install_header_file(IUnit.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_FILESYSTEM_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Filesystem)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_FILESYSTEM})
+
+set(SRCS
+ ${SRCS_API_FILESYSTEM}
+ ${SRCS_PLATFORM_IMPLEMENTATION_FILESYSTEM}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(IManager.h)
+install_header_file(INode.h)
+install_header_file(INodeTypes.h)
+install_header_file(IPath.h)
+install_header_file(IStream.h)
+install_header_file(EventResolve.h)
+install_header_file(EventCopy.h)
+install_header_file(EventMove.h)
+install_header_file(EventRemove.h)
+install_header_file(EventFind.h)
+install_header_file(EventListNodes.h)
+install_header_file(EventOpen.h)
+install_header_file(EventReadText.h)
+install_header_file(Enums.h)
+install_header_file(NodeFilter.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_HAPTICS_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Haptics)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_HAPTICS})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_HAPTICS}
+)
+
+set(SRCS
+ ${SRCS_API_HAPTICS}
+ ${SRCS_PLATFORM_IMPLEMENTATION_HAPTICS}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_HAPTICS}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(EventPlayBeep.h)
+install_header_file(EventStartMotor.h)
+install_header_file(HapticPattern.h)
+install_header_file(IManager.h)
+install_header_file(IMotor.h)
+install_header_file(Types.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_LOCALSTORAGE_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/LocalStorage)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_LOCALSTORAGE})
+
+set(SRCS
+ ${SRCS_API_LOCALSTORAGE}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${TARGET_MODULE_WIDGET_INTERFACE_DAO}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(ILocalStorage.h)
+install_header_file(LocalStorageMgr.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_MMPLAYER_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/MMPlayer)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_MMPLAYER})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_MMPLAYER}
+)
+
+set(SRCS
+ ${SRCS_API_MMPLAYER}
+ ${SRCS_PLATFORM_IMPLEMENTATION_MMPLAYER}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_MMPLAYER}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(EventGetVolume.h)
+install_header_file(EventIsPlaying.h)
+install_header_file(EventOnStateChange.h)
+install_header_file(EventOpen.h)
+install_header_file(EventPause.h)
+install_header_file(EventPlay.h)
+install_header_file(EventResume.h)
+install_header_file(EventSetWindow.h)
+install_header_file(EventStop.h)
+install_header_file(IManager.h)
+install_header_file(IMMPlayer.h)
+install_header_file(MMPlayerFactory.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_MESSAGING_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Messaging)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_MESSAGING})
+
+include_directories(${INCLUDES_MESSAGING_DIRECTORIES})
+
+set(SRCS
+ ${SRCS_API_MESSAGING}
+ ${SRCS_IMPLEMENTATION_MESSAGING}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${LIBS_IMPLEMENTATION_MESSAGING}
+ ${TARGET_COMMONS}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(AttachmentFactory.h)
+install_header_file(Attachments.h)
+install_header_file(BccRecipient.h)
+install_header_file(Body.h)
+install_header_file(CallbackNumber.h)
+install_header_file(CcRecipient.h)
+install_header_file(EmailAccountInfo.h)
+install_header_file(EmitterMessageReceived.h)
+install_header_file(EventDeleteMessage.h)
+install_header_file(EventFindMessage.h)
+install_header_file(EventMessageReceived.h)
+install_header_file(EventOnSendingFailed.h)
+install_header_file(EventSendMessage.h)
+install_header_file(EventUpdateMessage.h)
+install_header_file(From.h)
+install_header_file(IAttachment.h)
+install_header_file(IBinarySms.h)
+install_header_file(IEmailAccount.h)
+install_header_file(IEmail.h)
+install_header_file(IMessage.h)
+install_header_file(IMessaging.h)
+install_header_file(IMessagingTypes.h)
+install_header_file(IMms.h)
+install_header_file(IMmsSlide.h)
+install_header_file(IMmsSlideProperties.h)
+install_header_file(IMmsSlides.h)
+install_header_file(ISms.h)
+install_header_file(MessageEventPrivateData.h)
+install_header_file(MessageFactory.h)
+install_header_file(MessageFilter.h)
+install_header_file(MessagePriority.h)
+install_header_file(MmsSlide.h)
+install_header_file(MmsSlideProperty.h)
+install_header_file(MmsSlides.h)
+install_header_file(Recipient.h)
+install_header_file(ReqReceiverMessage.h)
+install_header_file(SourceAddress.h)
+install_header_file(Subject.h)
+install_header_file(ToRecipient.h)
+install_header_file(ValidityPeriodHours.h)
+install_header_file(VirtualMessage.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_NETWORKING_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Networking)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_NETWORKING})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_NETWORKING}
+)
+
+set(SRCS
+ ${SRCS_API_NETWORKING}
+ ${SRCS_IMPLEMENTATION_NETWORKING}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_NETWORKING}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(EventConnected.h)
+install_header_file(EventDisconnected.h)
+install_header_file(IAdapter.h)
+install_header_file(IConnection.h)
+install_header_file(IManager.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_ORIENTATION_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Orientation)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_ORIENTATION})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_ORIENTATION}
+)
+
+set(SRCS
+ ${SRCS_API_ORIENTATION}
+ ${SRCS_PLATFORM_IMPLEMENTATION_ORIENTATION}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_ORIENTATION}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(EventGetCurrentOrientation.h)
+install_header_file(EventOrientationChanged.h)
+install_header_file(IOrientation.h)
+install_header_file(OrientationFactory.h)
+install_header_file(OrientationProperties.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 CMakeLists.txt
+# @author Lukasz Marek (l.marek@samsung.com)
+# @version 1.0
+#
+
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_PLUGIN_MANAGER_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/PluginManager)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_PLUGIN_MANAGER})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER}
+)
+
+set(SRCS
+ ${SRCS_API_PLUGIN_MANAGER}
+ ${SRCS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${TARGET_COMMONS_JAVASCRIPT}
+ ${LIBS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER}
+)
+
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(PluginManagerFactory.h)
+install_header_file(IPluginManager.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_POWER_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Power)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_POWER})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_POWER}
+)
+
+set(SRCS
+ ${SRCS_API_POWER}
+ ${SRCS_PLATFORM_IMPLEMENTATION_POWER}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_POWER}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(Enums.h)
+install_header_file(EventCharging.h)
+install_header_file(EventLight.h)
+install_header_file(EventLow.h)
+install_header_file(EventRemaining.h)
+install_header_file(IBacklight.h)
+install_header_file(IBattery.h)
+install_header_file(IManager.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_PROFILE_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Profile)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_PROFILE})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_PROFILE}
+)
+
+set(SRCS
+ ${SRCS_API_PROFILE}
+ ${SRCS_PLATFORM_IMPLEMENTATION_PROFILE}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_PROFILE}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(EventSetWallpaper.h)
+install_header_file(IDesktop.h)
+install_header_file(IRingtone.h)
+install_header_file(Types.h)
+install_header_file(IManager.h)
+install_header_file(Enums.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_RADIO_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Radio)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_RADIO})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_RADIO}
+)
+
+set(SRCS
+ ${SRCS_API_RADIO}
+ ${SRCS_PLATFORM_IMPLEMENTATION_RADIO}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_RADIO}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(Enums.h)
+install_header_file(EventSourceTypeChange.h)
+install_header_file(IManager.h)
+install_header_file(ISource.h)
+install_header_file(Types.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_STORAGE_EVENT_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/StorageEvent)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_STORAGEEVENT})
+
+set(SRCS
+ ${SRCS_API_STORAGE_EVENT}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${TARGET_MODULE_LOCALSTORAGE}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(IStorageEvent.h)
+install_header_file(StorageEventMgr.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_SYSTEMINFO_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/SystemInfo)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_SYSTEMINFO})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_SYSTEMINFO}
+)
+
+set(SRCS
+ ${SRCS_API_SYSTEMINFO}
+ ${SRCS_PLATFORM_IMPLEMENTATION_SYSTEMINFO}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+#add_library(${TARGET_NAME} STATIC ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_SYSTEMINFO}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(ISystemInfo.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_TASK_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Task)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_TASK})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_TASK}
+)
+
+set(SRCS
+ ${SRCS_API_TASK}
+ ${SRCS_PLATFORM_IMPLEMENTATION_TASK}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_TASK}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+
+install_header_file(CalendarTask.h)
+install_header_file(IEventAddTask.h)
+install_header_file(IEventCreateTask.h)
+install_header_file(IEventDeleteTask.h)
+install_header_file(IEventFindTasks.h)
+install_header_file(IEventGetTasks.h)
+install_header_file(IEventUpdateTask.h)
+install_header_file(ITask.h)
+install_header_file(ITaskManager.h)
+install_header_file(TaskFactory.h)
+install_header_file(TaskFilter.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_WIDGET_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/Widget)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_WIDGET})
+
+set(SRCS
+ ${SRCS_API_WIDGET}
+ ${SRCS_IMPLEMENTATION_WIDGET}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${TARGET_MODULE_WIDGETDB}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(IWidget.h)
+install_header_file(WidgetFactory.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.
+#
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_WIDGETDB_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/WidgetDB)
+endmacro()
+
+set(TARGET_NAME ${TARGET_MODULE_WIDGETDB})
+
+include_directories(
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_WIDGETDB}
+)
+
+set(SRCS
+ ${SRCS_API_WIDGETDB}
+ ${SRCS_PLATFORM_IMPLEMENTATION_WIDGETDB}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${TARGET_COMMONS}
+ ${LIBS_PLATFORM_IMPLEMENTATION_WIDGETDB}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(IWidgetDB.h)
+install_header_file(IWidgetFeature.h)
+install_header_file(WidgetDBMgr.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.
+#
+
+macro(install_header_file HEADER_FILE)
+ INSTALL(FILES ${API_WIDGET_INTERFACE_PATH}/${HEADER_FILE}
+ DESTINATION ${DESTINATION_HEADER_PREFIX}/WidgetInterfaceDAO)
+endmacro()
+
+pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
+pkg_search_module(dpl-db REQUIRED dpl-db-efl)
+
+include_directories(
+ ${WIDGET_INTERFACE_INCLUDE_DIRS}
+ ${dpl-wrt-dao-ro_INCLUDE_DIRS}
+ ${dpl-db_INCLUDE_DIRS})
+
+set(TARGET_NAME ${TARGET_MODULE_WIDGET_INTERFACE_DAO})
+
+set(SRCS
+ ${SRCS_WIDGET_INTERFACE_DAO}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+ ${LIBS_COMMONS}
+ ${dpl-db_LIBRARIES}
+ ${dpl-wrt-dao-ro_LIBRARIES}
+)
+set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
+ ${DESTINATION_LIB_PREFIX})
+
+install_header_file(WidgetInterfaceDAO.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 Accelerometer.cpp
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <cassert>
+#include <Accelerometer/EventGetCurrentAcceleration.h>
+#include <Commons/Exception.h>
+#include "Accelerometer.h"
+
+using namespace DPL;
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+
+using namespace Api;
+
+namespace {
+/**
+ * Callback method called by platform as interval time.
+ * @param event_type Platform accelerometer evet type
+ * @param event Platform sensor event data
+ * @param this_ User data pointer.
+ */
+static void accelerationChangedCallback(unsigned int event_type,
+ sensor_event_data_t *event,
+ void *watcher_ptr)
+{
+ LogDebug("Callback accelerationChangedCallback.");
+ if (watcher_ptr) {
+ if (event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME &&
+ event != NULL) {
+ ((Accelerometer::Watcher*)watcher_ptr)->accelerationHasChanged(
+ event);
+ }
+ } else {
+ LogError("Callback private data is NULL.");
+ }
+}
+} //private namespace
+
+Accelerometer::Accelerometer() :
+ m_handle(-1),
+ m_initialized(false),
+ m_isWatch(false)
+{
+ LogDebug("Platform::Accelerometer Enter");
+}
+
+Accelerometer::~Accelerometer()
+{
+ LogDebug("Platform::~Accelerometer Enter");
+
+ if (m_initialized == true) {
+ stop(m_handle);
+ }
+
+ LogDebug("All watchers : (" << m_watchers.size() << ")");
+ std::vector<WatcherPtr>::iterator it;
+ for (it = m_watchers.begin(); it != m_watchers.end(); ++it) {
+ stop((*it)->getHandle(), true);
+ }
+ m_watchers.clear();
+ LogDebug("All watchers were cleared. (" << m_watchers.size() << ")");
+}
+
+void Accelerometer::getCurrentAcceleration(
+ const EventGetCurrentAccelerationPtr& event)
+{
+ if (m_initialized == false) {
+ m_handle = initialize();
+ start(m_handle);
+ m_initialized = true;
+ }
+ EventRequestReceiver<EventGetCurrentAcceleration>::PostRequest(event);
+}
+
+void Accelerometer::OnRequestReceived(
+ const EventGetCurrentAccelerationPtr& event)
+{
+ LogDebug("Enter");
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ /**
+ *Invoke platform API sf_get_data gets raw data from a sensor with connecting the sensor-server.
+ * The type of sensor is supplied and return data is stored in the output parameter values [].
+ */
+ if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 3)) {
+ LogError("Can't get current Acceleration. ");
+ Throw(Commons::PlatformException);
+ return;
+ }
+ event->setXAxis(static_cast<double>(data.values[0]));
+ event->setYAxis(static_cast<double>(data.values[1]));
+ event->setZAxis(static_cast<double>(data.values[2]));
+}
+
+long Accelerometer::watchAcceleration(
+ const EventAccelerationChangedEmitterPtr& emitter,
+ long minNotificationInterval)
+{
+ LogDebug("Enter");
+ int new_handle = initialize();
+
+ event_condition_t* condition = NULL;
+ event_condition_t conditionData;
+
+ if (minNotificationInterval > 0) {
+ conditionData.cond_op = CONDITION_EQUAL;
+ conditionData.cond_value1 = minNotificationInterval;
+ condition = &conditionData;
+ }
+
+ /**
+ * Invoke platform API sf_register_event registers a user defined callback function with a connected sensor for a particular event.
+ **This callback function will be called when there is a change in the state of respective sensor.
+ **cb_data will be the parameter used during the callback call.
+ **Callback interval can be adjusted using even_contion_t argument.
+ */
+
+ WatcherPtr watcher(new Watcher(new_handle, emitter));
+
+ int sensor_state = sf_register_event(
+ watcher->getHandle(),
+ ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME, condition,
+ accelerationChangedCallback, watcher.Get());
+ if (sensor_state < 0) {
+ stop(watcher->getHandle());
+ Throw(Commons::PlatformException);
+ }
+
+ start(watcher->getHandle());
+
+ m_isWatch = true;
+ m_watchers.push_back(watcher);
+ LogDebug("Watcher is added. (" << m_watchers.size() << ")");
+ watcher->getCurrentAccelerationForWatch();
+
+ return static_cast<long>(emitter->getId());
+}
+
+void Accelerometer::clearWatch(EventAccelerationChangedEmitter::IdType id)
+{
+ LogDebug("Enter");
+
+ std::vector<WatcherPtr>::iterator it;
+ for (it = m_watchers.begin(); it != m_watchers.end(); ++it) {
+ if (id == (*it)->getEmitter()->getId()) {
+ stop((*it)->getHandle(), true);
+
+ m_watchers.erase(it);
+ LogDebug("Watcher is removed. (" << m_watchers.size() << ")");
+
+ if (m_watchers.size() == 0) {
+ m_isWatch = false;
+ }
+ break;
+ }
+ }
+}
+
+void Accelerometer::getCurrentAccelerationForWatch(void)
+{
+ LogDebug("Enter");
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 3)) {
+ Throw(Commons::PlatformException);
+ }
+
+ EventAccelerationChangedPtr event(new EventAccelerationChanged());
+ AccelerationProperties props;
+ props.xAxis = static_cast<double>(data.values[0]);
+ props.yAxis = static_cast<double>(data.values[1]);
+ props.zAxis = static_cast<double>(data.values[2]);
+
+ event->setAccelerationProperties(props);
+
+ m_AccelerationEmitters.emit(event);
+}
+
+void Accelerometer::accelerationHasChanged(sensor_event_data_t *sensorEvent)
+{
+ LogDebug("Enter");
+ sensor_data_t *sensor_data = NULL;
+ sensor_data = (sensor_data_t *)sensorEvent->event_data;
+ if (sensor_data == NULL ||
+ (sensor_data->values_num < 3)) {
+ LogError("Can't get current Acceleration. ");
+ Throw(Commons::PlatformException);
+ return;
+ }
+
+ EventAccelerationChangedPtr event(new EventAccelerationChanged());
+ AccelerationProperties props;
+ props.xAxis = static_cast<double>(sensor_data->values[0]);
+ props.yAxis = static_cast<double>(sensor_data->values[1]);
+ props.zAxis = static_cast<double>(sensor_data->values[2]);
+ LogDebug(
+ "xAxis:" << sensor_data->values[0] << ",yAxis:" <<
+ sensor_data->values[1] << ",zAxis:" << sensor_data->values[2]);
+
+ event->setAccelerationProperties(props);
+
+ m_AccelerationEmitters.emit(event);
+}
+
+int Accelerometer::initialize()
+{
+ LogDebug("Enter");
+ DPL::Mutex::ScopedLock lock(&m_initializationMutex);
+ int handle = sf_connect(ACCELEROMETER_SENSOR);
+
+ if (handle < 0) {
+ LogError("Could not connect with accelerometer sensor.");
+ Throw(Commons::UnsupportedException);
+ }
+
+ return handle;
+}
+
+void Accelerometer::restart(int& handle)
+{
+ stop(handle);
+ start(handle);
+}
+
+void Accelerometer::start(int handle)
+{
+ LogDebug("Enter");
+ if (sf_start(handle, 0) < 0) {
+ LogError("Could not start communication with sensor.");
+ if (handle >= 0) {
+ sf_disconnect(handle);
+ Throw(Commons::UnsupportedException);
+ }
+ }
+}
+
+void Accelerometer::stop(int& handle,
+ bool isWatcherHandle)
+{
+ LogDebug("Enter");
+
+ if (handle >= 0) {
+ if (isWatcherHandle == true) {
+ LogError("unregister event sensor.");
+ sf_unregister_event(handle,
+ ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME);
+ }
+ sf_stop(handle);
+ sf_disconnect(handle);
+ handle = -1;
+ }
+}
+
+//Watcher's
+void Accelerometer::Watcher::getCurrentAccelerationForWatch()
+{
+ LogDebug("Enter");
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 3)) {
+ Throw(Commons::PlatformException);
+ }
+
+ EventAccelerationChangedPtr event(new EventAccelerationChanged());
+ AccelerationProperties props;
+ props.xAxis = static_cast<double>(data.values[0]);
+ props.yAxis = static_cast<double>(data.values[1]);
+ props.zAxis = static_cast<double>(data.values[2]);
+
+ event->setAccelerationProperties(props);
+
+ emit(event);
+}
+
+//Watcher's
+void Accelerometer::Watcher::accelerationHasChanged(
+ sensor_event_data_t *sensorEvent)
+{
+ LogDebug("Enter");
+ sensor_data_t *sensor_data = NULL;
+ sensor_data = (sensor_data_t *)sensorEvent->event_data;
+ if (sensor_data == NULL ||
+ (sensor_data->values_num < 3)) {
+ LogError("Can't get current Acceleration. ");
+ Throw(Commons::PlatformException);
+ return;
+ }
+
+ EventAccelerationChangedPtr event(new EventAccelerationChanged());
+ AccelerationProperties props;
+ props.xAxis = static_cast<double>(sensor_data->values[0]);
+ props.yAxis = static_cast<double>(sensor_data->values[1]);
+ props.zAxis = static_cast<double>(sensor_data->values[2]);
+ LogDebug(
+ "xAxis:" << sensor_data->values[0] << ",yAxis:" <<
+ sensor_data->values[1] << ",zAxis:" << sensor_data->values[2]);
+
+ event->setAccelerationProperties(props);
+
+ emit(event);
+}
+
+}
+}
--- /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 Accelerometer.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ACCELEROMETER_ACCELEROMETER_H_
+#define WRTDEVICEAPIS_ACCELEROMETER_ACCELEROMETER_H_
+
+#include <map>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <sensor.h>
+#include <sensor_accel.h>
+#include <Accelerometer/IAccelerometer.h>
+#include <Accelerometer/AccelerometerFactory.h>
+#include <Accelerometer/EventAccelerationChanged.h>
+#include <Commons/Emitters.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+
+class Accelerometer : public Api::IAccelerometer
+{
+ int m_handle;
+ gulong m_signalId;
+
+ /**
+ * @See: IgetCurrentAcceleration
+ */
+ friend class Api::AccelerometerFactory;
+
+ public:
+ class Watcher
+ {
+ private:
+ int m_handle;
+ Api::EventAccelerationChangedEmitterPtr m_emitter;
+
+ public:
+ Watcher(
+ int handle,
+ const Api::EventAccelerationChangedEmitterPtr&
+ emitter) :
+ m_handle(handle),
+ m_emitter(emitter)
+ {
+ }
+
+ int& getHandle()
+ {
+ return m_handle;
+ }
+
+ Api::EventAccelerationChangedEmitterPtr getEmitter()
+ {
+ return m_emitter;
+ }
+
+ void emit(const Api::EventAccelerationChangedPtr& event)
+ {
+ m_emitter->emit(event);
+ }
+ void getCurrentAccelerationForWatch();
+ void accelerationHasChanged(sensor_event_data_t *sensorEvent);
+ };
+ typedef DPL::SharedPtr<Watcher> WatcherPtr;
+
+ public:
+ virtual ~Accelerometer();
+
+ /**
+ * @See: IgetCurrentAcceleration
+ */
+ virtual void getCurrentAcceleration(
+ const Api::EventGetCurrentAccelerationPtr& event);
+
+ /**
+ * @See: IwatchAcceleration
+ */
+ virtual long watchAcceleration(
+ const Api::EventAccelerationChangedEmitterPtr&
+ emitter,
+ long minNotificationInterval);
+
+ /**
+ * @See: IclearWatch
+ */
+ virtual void clearWatch(
+ Api::EventAccelerationChangedEmitter::IdType id);
+
+ /**
+ * Method to run from platform's callback function
+ */
+ void accelerationHasChanged(sensor_event_data_t *sensorEvent);
+
+ /**
+ * Method to run currentAcceleration for watch function
+ */
+
+ void getCurrentAccelerationForWatch();
+
+ protected:
+ Accelerometer();
+ virtual void OnRequestReceived(
+ const Api::EventGetCurrentAccelerationPtr& event);
+
+ private:
+ typedef Commons::Emitters<Api::EventAccelerationChangedEmitter>
+ AccelerationChangedEmitters;
+
+ /**
+ * Initialize accelerometer sensor. This method returns when platform error occurs.
+ */
+ int initialize();
+
+ /**
+ * Start accelerometer sensor. This method sends a start command to sensor server.
+ */
+ void start(int handle);
+
+ /**
+ * Stop accelerometer sensor. This method sends a stop command to sensor server.
+ */
+ void stop(int& handle, bool isWatcherHandle = false);
+
+ /**
+ * Method to restart accelerometer sensor server.
+ */
+ void restart(int& handle);
+
+ AccelerationChangedEmitters m_AccelerationEmitters;
+ DPL::Mutex m_initializationMutex;
+ bool m_initialized;
+ bool m_isWatch;
+
+ std::vector<WatcherPtr> m_watchers;
+};
+
+}
+}
+
+#endif // WRTDEVICEAPIS_ACCELEROMETER_ACCELEROMETER_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 "Sensor.h"
+#include <sensor.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+
+Sensor& Sensor::getInstance()
+{
+ static Sensor instance;
+ return instance;
+}
+
+double Sensor::getX() const
+{
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 1))
+ {
+ Throw(Commons::PlatformException);
+ }
+ return data.values[0];
+}
+
+double Sensor::getY() const
+{
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 2))
+ {
+ Throw(Commons::PlatformException);
+ }
+ return data.values[1];
+}
+
+double Sensor::getZ() const
+{
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 3))
+ {
+ Throw(Commons::PlatformException);
+ }
+ return data.values[2];
+}
+
+Sensor::Sensor()
+{
+ m_handle = sf_connect(ACCELEROMETER_SENSOR);
+ if (m_handle < 0) {
+ LogError("Could not connect with accelerometer sensor.");
+ } else if (sf_start(m_handle, 0) < 0) {
+ LogError("Could not start communication with sensor.");
+ }
+}
+
+Sensor::~Sensor()
+{
+ if (m_handle >= 0) {
+ sf_stop(m_handle);
+ sf_disconnect(m_handle);
+ }
+}
+
+} // Accelerometer
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_ACCELEROMETER_SENSOR_H_
+#define WRTDEVICEAPIS_ACCELEROMETER_SENSOR_H_
+
+#include <Accelerometer/ISensor.h>
+
+namespace WrtDeviceApis {
+namespace Accelerometer {
+
+class Sensor : public Api::ISensor
+{
+ public:
+ /**
+ * @see WrtDeviceApis::Api::ISensor::getInstance()
+ */
+ static Sensor& getInstance();
+
+ public:
+ ~Sensor();
+
+ /**
+ * @see WrtDeviceApis::Api::ISensor::getX()
+ */
+ double getX() const;
+
+ /**
+ * @see WrtDeviceApis::Api::ISensor::getY()
+ */
+ double getY() const;
+
+ /**
+ * @see WrtDeviceApis::Api::ISensor::getZ()
+ */
+ double getZ() const;
+
+ private:
+ Sensor();
+
+ private:
+ int m_handle; ///< Sensor handle.
+};
+
+} // Accelerometer
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_ACCELEROMETER_SENSOR_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(sensor REQUIRED sensor)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_ACCELEROMETER
+ ${sensor_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_ACCELEROMETER
+ ${sensor_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_ACCELEROMETER
+ ${CURRENT_PATH}/Sensor.cpp
+ ${CURRENT_PATH}/Accelerometer.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.
+#
+###############################################################################
+# In this section please add modules that shouldn't be visible directly
+# beyond wac/ subdirectory, i.e. platform wrappers specific for wac -
+# - used only as helpers in AL for wac platform implementation. VConf
+# is a good example, its used i.e. in Power/Battery. Unfortunately order in
+# in which this modules and AL modules are included is significant, i.e. VConf
+# needs to be included before Power as there are some CMake variables set that
+# are used in Power config.cmake file.
+
+include_config_file(VConf)
+include_config_file(DBus)
+
+
+################################################################################
+
+include_config_file(Calendar)
+include_config_file(Camera-Webkit)
+include_config_file(Contact)
+include_config_file(Filesystem)
+include_config_file(Messaging)
+include_config_file(Haptics)
+include_config_file(Cpu)
+include_config_file(Power)
+include_config_file(MMPlayer)
+include_config_file(Accelerometer)
+include_config_file(Profile)
+include_config_file(Widget)
+include_config_file(Radio)
+include_config_file(Orientation)
+include_config_file(Task)
+include_config_file(SystemInfo)
+include_config_file(LocalStorage)
+include_config_file(WidgetInterfaceDAO)
+add_subdirectory(WidgetInterfaceDAO)
+include_config_file(WidgetDB)
+include_config_file(PluginManager)
+#DEPRACATED MODULES
+#include_config_file(Networking)
+#include_config_file(Geolocation)
+#include_config_file(FeatureLoader)
+##include_config_file(Camera)
+##include_config_file(Telephony)
+#include_config_file(Display)
+#include_config_file(Gallery)
+##include_config_file(AppLauncher)
+#include_config_file(Device)
+#include_config_file(Memory)
+#include_config_file(PhoneBook)
+#include_config_file(UI)
+#include_config_file(System)
--- /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 Calendar.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <calendar-svc-provider.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include "Calendar.h"
+#include "CalendarManager.h"
+
+namespace WrtDeviceApis {
+namespace Calendar {
+
+using namespace Api;
+
+Calendar::Calendar()
+{
+ LogDebug("entered");
+}
+
+Calendar::~Calendar()
+{
+ LogDebug("entered");
+}
+
+void Calendar::OnRequestReceived(const EventAddEventPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ if (!event->getEvent()) {
+ ThrowMsg(Commons::NullPointerException, "event parameter is NULL");
+ }
+ if (event->getEvent()->getIdIsSet()) {
+ LogWarning("adding event that is already added");
+ event->getEvent()->resetId();
+ }
+ DPL::ScopedPtr<EventWrapper> eventWrapper(
+ new EventWrapper(event->getEvent()));
+ eventWrapper->convertAbstractEventToPlatformEvent();
+ if (event->checkCancelled()) {
+ event->setCancelAllowed(true);
+ event->setResult(true);
+ return;
+ }
+ eventWrapper->saveEvent();
+ event->setResult(true);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during adding event" << ex.DumpToString());
+ event->setResult(false);
+ }
+ event->setCancelAllowed(false);
+}
+
+void Calendar::OnRequestReceived(const EventDeleteEventPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ if (!event->getEvent()) {
+ ThrowMsg(Commons::NullPointerException, "event parameter is NULL");
+ }
+ if (!event->getEvent()->getIdIsSet()) {
+ ThrowMsg(Commons::InvalidArgumentException,
+ "Cannot delete non-existing event.");
+ }
+ DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(
+ event->getEvent()));
+ eventWrapper->convertAbstractEventToPlatformEvent();
+ if (event->checkCancelled()) {
+ event->setCancelAllowed(true);
+ event->setResult(true);
+ return;
+ }
+ eventWrapper->deleteEvent();
+ event->setResult(true);
+ }
+ catch (const Commons::NotFoundException &ex)
+ {
+ LogError("event doesn't exist");
+ event->setResult(false);
+ event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during deleting event " << ex.DumpToString());
+ event->setResult(false);
+ }
+ event->setCancelAllowed(false);
+}
+
+void Calendar::OnRequestReceived(const EventUpdateEventPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ if (!event->getEvent()) {
+ ThrowMsg(Commons::NullPointerException, "event parameter is NULL");
+ }
+ if (!event->getEvent()->getIdIsSet()) {
+ ThrowMsg(
+ Commons::InvalidArgumentException,
+ "Cannot update non-existing event. Event needs adding or ID is wrong");
+ }
+ DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(
+ event->getEvent()));
+ eventWrapper->convertAbstractEventToPlatformEvent();
+ if (event->checkCancelled()) {
+ event->setCancelAllowed(true);
+ event->setResult(true);
+ return;
+ }
+ eventWrapper->saveEvent();
+ event->setResult(true);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during updating event " << ex.DumpToString());
+ event->setResult(false);
+ }
+ event->setCancelAllowed(false);
+}
+
+void Calendar::OnRequestReceived(const EventFindEventsPtr &event)
+{
+ LogDebug("entered");
+ const EventFilterPtr &filter = event->getFilter();
+ cal_struct *platformEvent = NULL;
+ cal_iter *iter = NULL;
+ int foundCnt = 0;
+ event->setResult(true);
+
+ try {
+ if (CAL_SUCCESS !=
+ calendar_svc_get_all(0, 0, CAL_STRUCT_SCHEDULE, &iter)) {
+ ThrowMsg(Commons::PlatformException, "Can't get all records");
+ }
+ //TODO: currently platform starts iteration with below function
+ // It's possible that current approach will change to be familiar with std iterators
+
+ while (CAL_SUCCESS == calendar_svc_iter_next(iter)) {
+ event->tryCancelled();
+ if (CAL_SUCCESS !=
+ calendar_svc_iter_get_info(iter, &platformEvent)) {
+ ThrowMsg(Commons::PlatformException, "Can't get event info.");
+ }
+ //getting ID
+ int eventId = calendar_svc_struct_get_int(platformEvent,
+ CAL_VALUE_INT_INDEX);
+ if (CAL_SUCCESS != calendar_svc_struct_free(&platformEvent)) {
+ LogError("Can't free calendar event struct.");
+ }
+
+ DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper());
+ eventWrapper->loadEvent(eventId);
+ if (!filter || eventWrapper->matchFilters(filter)) {
+ if (foundCnt >= event->getFirstEvent() &&
+ (event->getLastEvent() == -1 || foundCnt <=
+ event->getLastEvent())) {
+ event->addEvent(eventWrapper->getAbstractEvent());
+ }
+ foundCnt++;
+ }
+ }
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Exception: " << ex.DumpToString());
+ event->setResult(false);
+ }
+ //According to example in calendar-svc-provider.h it's not needed to pass here
+ //iter set on first element
+ calendar_svc_iter_remove(&iter);
+ event->setCancelAllowed(true);
+}
+
+void Calendar::OnRequestReceived(const EventCreateEventPtr &event)
+{
+ LogDebug("entered");
+ Try
+ {
+ event->setEvent(CalendarEventPtr(new CalendarEvent()));
+ event->setResult(event->getEvent().Get() != NULL);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during creating an event " << ex.DumpToString());
+ event->setResult(false);
+ }
+}
+
+}
+}
--- /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 Calendar.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_CALENDAR_H_
+#define WRTDEVICEAPIS_CALENDAR_CALENDAR_H_
+
+#include <list>
+#include "Calendar/ICalendar.h"
+#include "EventWrapper.h"
+
+namespace WrtDeviceApis {
+namespace Calendar {
+
+class Calendar : public Api::ICalendar
+{
+ public:
+ Calendar();
+ virtual ~Calendar();
+ protected:
+ virtual void OnRequestReceived(const Api::EventAddEventPtr &event);
+ virtual void OnRequestReceived(const Api::EventDeleteEventPtr &event);
+ virtual void OnRequestReceived(const Api::EventUpdateEventPtr &event);
+ virtual void OnRequestReceived(const Api::EventFindEventsPtr &event);
+ virtual void OnRequestReceived(const Api::EventCreateEventPtr &event);
+};
+
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_CALENDAR_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 CalendarManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ */
+
+#include "CalendarManager.h"
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <calendar-svc-provider.h>
+#include <calendar-svc-errors.h>
+#include <vector>
+#include <Commons/StringUtils.h>
+
+namespace {
+const int ID_ALL_ACCOUNTS = 0;
+const char* SERVICE_PROVIDER_NAME = "phone";
+}
+
+namespace WrtDeviceApis {
+namespace Calendar {
+
+using namespace Api;
+
+int CalendarManager::m_instanceCount = 0;
+
+CalendarManager::CalendarManager()
+{
+ LogDebug("entered");
+ /* wac platform doesn't support calendar manager.
+ * This implementation have to implement it on its own.
+ * One calendar have to be created and stored for further use.
+ */
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ if (m_instanceCount == 0) {
+ LogDebug("opening calendar DB");
+ if (CAL_SUCCESS != calendar_svc_connect()) {
+ ThrowMsg(Commons::PlatformException,
+ "Calendar DB initialization failed");
+ }
+ }
+ m_instanceCount++;
+}
+
+CalendarManager::~CalendarManager()
+{
+ LogDebug("entered");
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ m_instanceCount--;
+ if (m_instanceCount == 0) {
+ LogDebug("closing calendar DB");
+ if (CAL_SUCCESS != calendar_svc_close()) {
+ LogError("Calendar database not clearly closed.");
+ }
+ }
+}
+
+int CalendarManager::getAccountId()
+{
+ return ID_ALL_ACCOUNTS;
+}
+
+const char *CalendarManager::getServiceProviderName()
+{
+ return SERVICE_PROVIDER_NAME;
+}
+
+void CalendarManager::OnRequestReceived(const EventGetCalendarsPtr &event)
+{
+ static std::vector<ICalendarPtr> calendars;
+ Try
+ {
+ if (calendars.empty()) {
+ cal_iter *iter = NULL;
+ if (CAL_SUCCESS !=
+ calendar_svc_get_all(getAccountId(), 0, CAL_STRUCT_CALENDAR,
+ &iter)) {
+ event->setResult(false);
+ return;
+ }
+ cal_struct *calendar = NULL;
+ while (CAL_SUCCESS == calendar_svc_iter_next(iter)) {
+ if (event->checkCancelled()) {
+ break;
+ }
+ if (CAL_SUCCESS ==
+ calendar_svc_iter_get_info(iter, &calendar)) {
+ const char* name = calendar_svc_struct_get_str(
+ calendar,
+ CAL_TABLE_TXT_NAME);
+ const char* id = calendar_svc_struct_get_str(
+ calendar,
+ CAL_TABLE_TXT_CALENDAR_ID);
+ if (name != NULL && id != NULL) {
+ LogDebug(
+ "got calendar, id=" << id << ", name: " << name);
+ ICalendarPtr newCalendar(new Calendar());
+ newCalendar->setName(name);
+ newCalendar->setId(Commons::String::toInt(id));
+ newCalendar->setAccountId(getAccountId());
+ newCalendar->setType(Calendar::DEVICE_CALENDAR);
+ calendars.push_back(newCalendar);
+ } else {
+ LogError("calendar contains invalid parameters");
+ }
+ } else {
+ LogError("cannot get calendar");
+ }
+ }
+ calendar_svc_iter_remove(&iter);
+ }
+ if (!event->checkCancelled()) {
+ std::vector<ICalendarPtr>::const_iterator it = calendars.begin();
+ for (; it != calendars.end(); ++it) {
+ event->addCalendar(*it);
+ }
+ event->setResult(true);
+ }
+ }
+ Catch(Commons::Exception)
+ {
+ LogError("error occuered during obtaining data");
+ event->setResult(false);
+ }
+ event->setCancelAllowed(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 CalendarManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_CALENDAR_MANAGER_H_
+#define WRTDEVICEAPIS_CALENDAR_CALENDAR_MANAGER_H_
+
+#include <vector>
+#include <list>
+#include <dpl/mutex.h>
+#include <Calendar/ICalendarManager.h>
+#include "Calendar.h"
+
+namespace WrtDeviceApis {
+namespace Calendar {
+
+class CalendarManager : public Api::ICalendarManager
+{
+ public:
+ CalendarManager();
+ virtual ~CalendarManager();
+ static int getAccountId();
+ static const char* getServiceProviderName();
+ protected:
+ virtual void OnRequestReceived(const Api::EventGetCalendarsPtr &event);
+
+ private:
+ static int m_instanceCount;
+ DPL::Mutex m_constructorMutex;
+};
+}
+}
+
+#endif // WRTDEVICEAPIS_CALENDAR_CALENDAR_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.
+ */
+/**
+ * @file EventWrapper.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <string.h>
+#include <algorithm>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "EventWrapper.h"
+#include "Calendar.h"
+
+namespace {
+const char weekDays[] = "0111110";
+const int NEW_EVENT_ID = -1;
+}
+
+namespace WrtDeviceApis {
+namespace Calendar {
+
+using namespace Api;
+
+EventWrapper::EventWrapper() :
+ m_platformEvent(NULL),
+ m_abstractEvent(NULL)
+{
+ LogDebug("entered");
+ m_abstractEvent = CalendarEventPtr(new CalendarEvent());
+ if (!m_abstractEvent) {
+ ThrowMsg(Commons::UnknownException, "abstract object is not created");
+ }
+}
+
+EventWrapper::EventWrapper(const CalendarEventPtr &event) :
+ m_platformEvent(NULL),
+ m_abstractEvent(event)
+{
+ LogDebug("entered");
+}
+
+EventWrapper::~EventWrapper()
+{
+ LogDebug("entered");
+ freePlatformEvent();
+}
+
+int EventWrapper::getIDFromPlatformEvent() const
+{
+ LogDebug("Entered");
+ if (m_platformEvent == NULL) {
+ ThrowMsg(Commons::NullPointerException, "m_platformEvent is not set");
+ }
+
+ return calendar_svc_struct_get_int(m_platformEvent, CAL_VALUE_INT_INDEX);
+}
+
+void EventWrapper::saveEvent()
+{
+ LogDebug("entered");
+ //Check if platform struct is set.
+ //It could be set here, but forcing user to do it manually can help to avoid problems.
+ if (m_platformEvent == NULL) {
+ ThrowMsg(Commons::NullPointerException, "m_platformEvent is not set");
+ }
+
+ int eventID = getIDFromPlatformEvent();
+ LogDebug("eventID: " << eventID);
+
+ displayPlatformEvent();
+
+ //insert new record or update existing one
+ if (eventID < 0) { //insert new event
+ int returnValue = calendar_svc_insert(m_platformEvent);
+ if (CAL_SUCCESS > returnValue) {
+ LogError("Can't insert new event, error code: " << returnValue);
+ ThrowMsg(Commons::PlatformException, "Can't insert new event.");
+ }
+ m_abstractEvent->setId(returnValue);
+ LogInfo("New calendar event inserted");
+ } else { //update
+ if (CAL_SUCCESS != calendar_svc_update(m_platformEvent)) {
+ ThrowMsg(Commons::PlatformException, "Can't update new event.");
+ }
+ LogDebug("Calendar event updated");
+ }
+}
+
+void EventWrapper::loadEvent(int id)
+{
+ LogDebug("Entered. ID of event to load: " << id);
+ freePlatformEvent();
+ int errorCode = calendar_svc_get(CAL_STRUCT_SCHEDULE,
+ id,
+ NULL,
+ &m_platformEvent);
+ if (CAL_SUCCESS > errorCode) {
+ LogError(
+ "Can't get event with ID = " << id << ", error code: " <<
+ errorCode);
+ ThrowMsg(
+ Commons::PlatformException,
+ "Can't get event with ID = " << id << ", error code: " <<
+ errorCode);
+ }
+ convertPlatformEventToAbstractEvent();
+ displayAbstractEvent();
+}
+
+bool EventWrapper::matchFilters(EventFilterPtr filter)
+{
+ LogDebug("Entered");
+ if (!filter) {
+ return true;
+ }
+ if (!m_abstractEvent) {
+ ThrowMsg(Commons::NullPointerException,
+ "abstractEvent object is not set");
+ }
+
+ LogDebug("---new event to match---");
+ m_abstractEvent->display();
+
+ if (filter->getIdIsSet() && m_abstractEvent->getIdIsSet()) {
+ std::stringstream ss;
+ if (!(ss << m_abstractEvent->getId())) {
+ LogDebug("rejected by id");
+ return false;
+ }
+ if (!pcrecpp::RE(filter->getIdFilter()).FullMatch(ss.str())) {
+ LogDebug("rejected by id " << filter->getIdFilter());
+ return false;
+ }
+ }
+ if (filter->getCalendarIdIsSet()) {
+ if (m_abstractEvent->getCalendarId() !=
+ filter->getCalendarIdFilter()) {
+ LogDebug("rejected by calendar id " << filter->getCalendarIdFilter());
+ return false;
+ }
+ }
+ if (filter->getDescriptionIsSet()) {
+ if (!pcrecpp::RE(filter->getDescriptionFilter()).FullMatch(
+ m_abstractEvent->getDescription())) {
+ LogDebug("rejected by description " << filter->getDescriptionFilter());
+ return false;
+ }
+ }
+ if (filter->getSubjectIsSet()) {
+ if (!pcrecpp::RE(filter->getSubjectFilter()).FullMatch(m_abstractEvent
+ ->getSubject()))
+ {
+ LogDebug("rejected by subject " << filter->getSubjectFilter());
+ return false;
+ }
+ }
+ if (filter->getStartTimeMinIsSet() && m_abstractEvent->getStartTime() <
+ filter->getStartTimeMinFilter()) {
+ LogDebug("rejected by start time min " << filter->getStartTimeMinFilter());
+ return false;
+ }
+ if (filter->getStartTimeMaxIsSet() && m_abstractEvent->getStartTime() >
+ filter->getStartTimeMaxFilter()) {
+ LogDebug("rejected by start time max " << filter->getStartTimeMaxFilter());
+ return false;
+ }
+ if (filter->getEndTimeMinIsSet() && m_abstractEvent->getEndTime() <
+ filter->getEndTimeMinFilter()) {
+ LogDebug("rejected by end time min " << filter->getEndTimeMinFilter());
+ return false;
+ }
+ if (filter->getEndTimeMaxIsSet() && m_abstractEvent->getEndTime() >
+ filter->getEndTimeMaxFilter()) {
+ LogDebug("rejected by end time max " << filter->getEndTimeMaxFilter());
+ return false;
+ }
+ if (filter->getLocationIsSet()) {
+ if (!pcrecpp::RE(filter->getLocationFilter()).FullMatch(m_abstractEvent
+ ->
+ getLocation()))
+ {
+ LogDebug("rejected by location " << filter->getLocationFilter());
+ return false;
+ }
+ }
+ if (filter->getRecurrenceIsSet()) {
+ const std::vector<CalendarEvent::EventRecurrence> &filterVal =
+ filter->getRecurrenceFilter();
+ if (std::find(filterVal.begin(), filterVal.end(),
+ m_abstractEvent->getRecurrence()) == filterVal.end()) {
+ LogDebug("rejected by recurrence");
+ return false;
+ }
+ }
+ if (filter->getStatusIsSet()) {
+ const std::vector<CalendarEvent::EventStatus> &filterVal =
+ filter->getStatusFilter();
+ if (std::find(filterVal.begin(), filterVal.end(),
+ m_abstractEvent->getStatus()) == filterVal.end()) {
+ LogDebug("rejected by status");
+ return false;
+ }
+ }
+ if (filter->getAlarmTimeMinIsSet() && m_abstractEvent->getAlarmTime() <
+ filter->getAlarmTimeMinFilter()) {
+ LogDebug("rejected by alarm time min " << filter->getAlarmTimeMinFilter());
+ return false;
+ }
+ if (filter->getAlarmTimeMinIsSet() && m_abstractEvent->getAlarmTime() >
+ filter->getAlarmTimeMaxFilter()) {
+ LogDebug("rejected by alarm time max " << filter->getAlarmTimeMaxFilter());
+ return false;
+ }
+ if (filter->getAlarmTypeIsSet()) {
+ const std::vector<CalendarEvent::EventAlarmType> &filterVal =
+ filter->getAlarmTypeFilter();
+ if (std::find(filterVal.begin(), filterVal.end(),
+ m_abstractEvent->getAlarmType()) == filterVal.end()) {
+ LogDebug("rejected by alarm type");
+ return false;
+ }
+ }
+ if (filter->getCategoryIsSet()) {
+ CategoryListPtr categories = m_abstractEvent->getCategories();
+ bool found = false;
+ for (std::size_t i = 0; i < categories->size(); ++i) {
+ if (pcrecpp::RE(filter->getCategoryFilter()).FullMatch(categories->
+ at(i)))
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ LogDebug("rejectedy by category");
+ return false;
+ }
+ }
+ return true;
+}
+
+void EventWrapper::deleteEvent()
+{
+ LogDebug("entered");
+ if (m_platformEvent == NULL) {
+ ThrowMsg(Commons::NullPointerException,
+ "Failed to delete event in calendar (m_platformEvent==NULL)");
+ }
+ int eventID = getIDFromPlatformEvent();
+ LogDebug("eventID: " << eventID);
+ if (eventID < 0) {
+ ThrowMsg(
+ Commons::InvalidArgumentException,
+ "Failed to delete event in calendar (event is not saved in calendar)");
+ }
+ cal_struct *event = NULL;
+ int error = calendar_svc_get(CAL_STRUCT_SCHEDULE, eventID, NULL, &event);
+ if (event) {
+ calendar_svc_struct_free(&event);
+ }
+ if (CAL_SUCCESS != error) {
+ ThrowMsg(
+ Commons::NotFoundException,
+ "Can't delete calendar event, event doesn't exist. Error code "
+ << error);
+ }
+ error = calendar_svc_delete(CAL_STRUCT_SCHEDULE, eventID);
+ if (CAL_SUCCESS != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Can't delete calendar event. Error code " << error);
+ }
+ LogDebug("event deleted");
+ m_abstractEvent->resetId();
+ setIDToPlatformEvent();
+}
+
+cal_struct *EventWrapper::getPlatformEvent() const
+{
+ return m_platformEvent;
+}
+
+CalendarEventPtr EventWrapper::getAbstractEvent() const
+{
+ return m_abstractEvent;
+}
+
+void EventWrapper::freePlatformEvent()
+{
+ LogDebug("entered");
+ if (m_platformEvent != NULL) {
+ if (CAL_SUCCESS != calendar_svc_struct_free(&m_platformEvent)) {
+ LogError("Can't free calendar event struct.");
+ }
+ m_platformEvent = NULL;
+ }
+}
+
+cal_struct *EventWrapper::convertAbstractEventToPlatformEvent()
+{
+ LogDebug("entered");
+ freePlatformEvent();
+ m_platformEvent = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "cannot create platform event");
+ }
+ setDescriptionToPlatformEvent();
+ setSubjectToPlatformEvent();
+ setStartTimeToPlatformEvent();
+ setEndTimeToPlatformEvent();
+ setLocationToPlatformEvent();
+ setAlarmToPlatformEvent();
+ setRecurrenceToPlatformEvent();
+ setStatusToPlatformEvent();
+ setCategoriesToPlatformEvent();
+ setIDToPlatformEvent();
+ setExpiresToPlatformEvent();
+ setIntervalToPlatformEvent();
+ return getPlatformEvent();
+}
+
+void EventWrapper::setDescriptionToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
+ CAL_VALUE_TXT_DESCRIPTION,
+ m_abstractEvent->
+ getDescription().c_str()))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set event description.");
+ }
+}
+
+void EventWrapper::setSubjectToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
+ CAL_VALUE_TXT_SUMMARY,
+ m_abstractEvent->getSubject()
+ .c_str())) {
+ ThrowMsg(Commons::PlatformException, "Can't set event subject.");
+ }
+}
+
+void EventWrapper::setStartTimeToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+
+ time_t time = m_abstractEvent->getStartTime();
+ if (time == 0) {
+ time = m_abstractEvent->getEndTime();
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_time(m_platformEvent,
+ CAL_VALUE_GMT_START_DATE_TIME,
+ CAL_TZ_FLAG_GMT, time)) {
+ ThrowMsg(Commons::PlatformException, "Can't set event start time.");
+ }
+}
+
+void EventWrapper::setEndTimeToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+
+ time_t time = m_abstractEvent->getEndTime();
+ if (time == 0) {
+ time = m_abstractEvent->getStartTime();
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_time(m_platformEvent,
+ CAL_VALUE_GMT_END_DATE_TIME,
+ CAL_TZ_FLAG_GMT, time)) {
+ ThrowMsg(Commons::PlatformException, "Can't set event end time.");
+ }
+}
+
+void EventWrapper::setLocationToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformEvent,
+ CAL_VALUE_TXT_LOCATION,
+ m_abstractEvent->getLocation()
+ .c_str())) {
+ ThrowMsg(Commons::PlatformException, "Can't set event location.");
+ }
+}
+
+void EventWrapper::setRecurrenceToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ bool ret = false;
+ switch (m_abstractEvent->getRecurrence()) {
+ case CalendarEvent::NO_RECURRENCE:
+ ret = (CAL_SUCCESS == calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_TERM,
+ CAL_REPEAT_NONE));
+ break;
+ case CalendarEvent::DAILY_RECURRENCE:
+ ret = (CAL_SUCCESS == calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_TERM,
+ CAL_REPEAT_EVERY_DAY))
+ &&
+ (CAL_SUCCESS == calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_OCCURRENCES,
+ 0));
+ break;
+ case CalendarEvent::WEEKLY_RECURRENCE:
+ {
+ char weekDay[] = "0000000";
+ time_t date = m_abstractEvent->getStartTime();
+ tm* time = localtime(&date);
+ if (!time) {
+ LogError("localtime failed");
+ ret = -1;
+ break;
+ }
+
+ int days = time->tm_wday;
+ if (days < 0 || days > 6) {
+ LogError("invalid week day");
+ ret = -1;
+ } else {
+ weekDay[days] = '1';
+ ret = (CAL_SUCCESS == calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_TERM,
+ CAL_REPEAT_EVERY_WEEK))
+ &&
+ (CAL_SUCCESS == calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_OCCURRENCES,
+ 0)) &&
+ (CAL_SUCCESS == calendar_svc_struct_set_str(m_platformEvent,
+ CAL_VALUE_TXT_WEEK_FLAG,
+ weekDay));
+ }
+ }
+ break;
+ case CalendarEvent::MONTHLY_ON_DAY_RECURRENCE:
+ {
+ char weekDay[] = "0000000";
+ time_t date = m_abstractEvent->getStartTime();
+ int days = localtime(&date)->tm_wday;
+ if (days < 0 || days > 6) {
+ LogError("invalid week day");
+ ret = -1;
+ } else {
+ weekDay[days] = '1';
+ ret = (CAL_SUCCESS == calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_REPEAT_OCCURRENCES,
+ 0)) &&
+ (CAL_SUCCESS == calendar_svc_struct_set_str(
+ m_platformEvent,
+ CAL_VALUE_TXT_WEEK_FLAG,
+ weekDay));
+ }
+ }
+ break;
+ case CalendarEvent::MONTHLY_RECURRENCE:
+ ret = (CAL_SUCCESS == calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_REPEAT_TERM,
+ CAL_REPEAT_EVERY_MONTH)) &&
+ (CAL_SUCCESS == calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_REPEAT_OCCURRENCES,
+ 0));
+ break;
+ case CalendarEvent::WEEKDAY_RECURRENCE:
+ ret = (CAL_SUCCESS == calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_REPEAT_TERM,
+ CAL_REPEAT_EVERY_WEEK)) &&
+ (CAL_SUCCESS == calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_REPEAT_OCCURRENCES,
+ 0)) &&
+ (CAL_SUCCESS == calendar_svc_struct_set_str(
+ m_platformEvent,
+ CAL_VALUE_TXT_WEEK_FLAG,
+ weekDays));
+ break;
+ case CalendarEvent::YEARLY_RECURRENCE:
+ ret = (CAL_SUCCESS == calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_REPEAT_TERM,
+ CAL_REPEAT_EVERY_YEAR)) &&
+ (CAL_SUCCESS == calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_REPEAT_OCCURRENCES,
+ 0));
+ break;
+ case CalendarEvent::INVALID_RECURRENCE:
+ case CalendarEvent::UNDEFINED_RECURRENCE:
+ default:
+ LogError("invalid reccurence " << m_abstractEvent->getRecurrence());
+ ret = 0;
+ break;
+ }
+ if (!ret) {
+ ThrowMsg(Commons::PlatformException, "Can't set event recurrence.");
+ }
+}
+
+void EventWrapper::setAlarmToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+
+ GList* list = NULL;
+
+ if (m_abstractEvent->getAlarmTimeIsSet()) {
+
+ //set alarm's type
+ cal_alert_type_t alarmType = CAL_ALERT_MELODY;
+ switch (m_abstractEvent->getAlarmType()) {
+ case CalendarEvent::NO_ALARM:
+ alarmType = CAL_ALERT_MUTE;
+ break;
+ case CalendarEvent::SOUND_ALARM:
+ alarmType = CAL_ALERT_MELODY;
+ break;
+ case CalendarEvent::SILENT_ALARM:
+ alarmType = CAL_ALERT_VIBRATION;
+ break;
+ default:
+ ThrowMsg(Commons::UnknownException, "wrong alarm type");
+ break;
+ }
+
+ //create new alarm
+ cal_value* alarm = calendar_svc_value_new(CAL_VALUE_LST_ALARM);
+ if (NULL == alarm) {
+ ThrowMsg(Commons::PlatformException, "Can't set alarm.");
+ }
+
+ if (CAL_SUCCESS != calendar_svc_value_set_time(
+ alarm,
+ CAL_VALUE_GMT_ALARMS_TIME,
+ CAL_TZ_FLAG_GMT,
+ m_abstractEvent->getAlarmTime()) ||
+ CAL_SUCCESS != calendar_svc_value_set_int(
+ alarm,
+ CAL_VALUE_INT_ALARMS_TICK,
+ 0) ||
+ CAL_SUCCESS != calendar_svc_value_set_int(
+ alarm,
+ CAL_VALUE_INT_ALARMS_TICK_UNIT,
+ CAL_SCH_TIME_UNIT_SPECIFIC) ||
+ CAL_SUCCESS != calendar_svc_value_set_int(
+ alarm,
+ CAL_VALUE_INT_ALARMS_TYPE,
+ alarmType))
+ {
+ calendar_svc_value_free(&alarm);
+ ThrowMsg(Commons::PlatformException, "Can't set alarm.");
+ }
+
+ //add alarm to list
+ list = g_list_prepend(list, alarm);
+ }
+
+ //store alarms list
+ if (CAL_SUCCESS != calendar_svc_struct_store_list(
+ m_platformEvent,
+ CAL_VALUE_LST_ALARM,
+ list))
+ {
+ ThrowMsg(Commons::PlatformException, "cannot save the alarms");
+ }
+
+}
+
+void EventWrapper::setStatusToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ int status = 0;
+ switch (m_abstractEvent->getStatus()) {
+ case CalendarEvent::TENTATIVE_STATUS:
+ status = 1;
+ break;
+ case CalendarEvent::CANCELLED_STATUS:
+ status = 2;
+ break;
+ case CalendarEvent::CONFIRMED_STATUS:
+ default:
+ status = 0;
+ break;
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_MEETING_STATUS,
+ status)) {
+ ThrowMsg(Commons::PlatformException, "Can't set event ID.");
+ }
+}
+
+void EventWrapper::setCategoriesToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ GList *categoryList = NULL;
+ cal_value* category = NULL;
+ Try
+ {
+ for (size_t i = 0; i < m_abstractEvent->getCategories()->size(); ++i) {
+ LogDebug("adding category " <<
+ m_abstractEvent->getCategories()->at(i));
+ category = calendar_svc_value_new(CAL_VALUE_LST_MEETING_CATEGORY);
+ if (NULL == category) {
+ LogError("error during creating category");
+ ThrowMsg(Commons::PlatformException,
+ "Cannot create category object");
+ }
+ if (CAL_SUCCESS !=
+ calendar_svc_value_set_str(category, "category_name",
+ m_abstractEvent->getCategories()->at(
+ i).c_str())) {
+ LogError("error during setting category name");
+ calendar_svc_value_free(&category);
+ ThrowMsg(Commons::PlatformException, "Cannot set category name");
+ }
+ //Order of categories is lost during saving, so we don't need to reverse this list.
+ categoryList = g_list_prepend(categoryList, category);
+ }
+
+ calendar_svc_struct_store_list(m_platformEvent,
+ CAL_VALUE_LST_MEETING_CATEGORY,
+ categoryList);
+ }
+ Catch(Commons::PlatformException)
+ {
+ LogError("error during setting categories");
+ calendar_svc_struct_store_list(m_platformEvent,
+ CAL_VALUE_LST_MEETING_CATEGORY,
+ NULL);
+ for (; categoryList; categoryList = g_list_next(categoryList)) {
+ category = static_cast<cal_value*>(categoryList->data);
+ calendar_svc_value_free(&category);
+ }
+ g_list_free(categoryList);
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+void EventWrapper::setIDToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ if (m_abstractEvent->getIdIsSet()) {
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_INDEX,
+ m_abstractEvent->getId()))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set event ID.");
+ }
+ } else {
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(
+ m_platformEvent,
+ CAL_VALUE_INT_INDEX,
+ NEW_EVENT_ID))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set event ID.");
+ }
+ }
+}
+
+void EventWrapper::setExpiresToPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ if (m_abstractEvent->getExpiresIsSet()) {
+ int errorCode = calendar_svc_struct_set_time(
+ m_platformEvent,
+ CAL_VALUE_GMT_REPEAT_END_DATE,
+ CAL_TZ_FLAG_GMT,
+ m_abstractEvent->getExpires());
+ if (CAL_SUCCESS != errorCode) {
+ LogError(
+ "Can't set CAL_VALUE_GMT_REPEAT_END_DATE, error: " <<
+ errorCode);
+ ThrowMsg(Commons::PlatformException, "Can't set expires.");
+ }
+ }
+}
+
+void EventWrapper::setIntervalToPlatformEvent()
+{
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_INTERVAL,
+ m_abstractEvent->getInterval()))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set interval.");
+ }
+}
+
+CalendarEventPtr EventWrapper::convertPlatformEventToAbstractEvent()
+{
+ LogDebug("entered");
+ setDescriptionFromPlatformEvent();
+ setSubjectFromPlatformEvent();
+ setStartTimeFromPlatformEvent();
+ setEndTimeFromPlatformEvent();
+ setLocationFromPlatformEvent();
+ setRecurrenceFromPlatformEvent();
+ setAlarmFromPlatformEvent();
+ setStatusFromPlatformEvent();
+ setCategoriesFromPlatformEvent();
+ setIDFromPlatformEvent();
+ setExpiresFromPlatformEvent();
+ setIntervalFromPlatformEvent();
+ return getAbstractEvent();
+}
+
+void EventWrapper::setDescriptionFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ const char *description = calendar_svc_struct_get_str(
+ m_platformEvent,
+ CAL_VALUE_TXT_DESCRIPTION);
+ if (description) {
+ m_abstractEvent->setDescription(description);
+ }
+}
+
+void EventWrapper::setSubjectFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ const char *summary = calendar_svc_struct_get_str(m_platformEvent,
+ CAL_VALUE_TXT_SUMMARY);
+ if (summary) {
+ m_abstractEvent->setSubject(summary);
+ }
+}
+
+void EventWrapper::setStartTimeFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ time_t startTime = calendar_svc_struct_get_time(
+ m_platformEvent,
+ CAL_VALUE_GMT_START_DATE_TIME,
+ CAL_TZ_FLAG_GMT);
+ m_abstractEvent->setStartTime(startTime);
+}
+
+void EventWrapper::setEndTimeFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ time_t endTime = calendar_svc_struct_get_time(m_platformEvent,
+ CAL_VALUE_GMT_END_DATE_TIME,
+ CAL_TZ_FLAG_GMT);
+ m_abstractEvent->setEndTime(endTime);
+}
+
+void EventWrapper::setLocationFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ const char* location = calendar_svc_struct_get_str(m_platformEvent,
+ CAL_VALUE_TXT_LOCATION);
+ if (location) {
+ m_abstractEvent->setLocation(location);
+ }
+}
+
+void EventWrapper::setRecurrenceFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ int recurrence = calendar_svc_struct_get_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_TERM);
+ switch (recurrence) {
+ case CAL_REPEAT_NONE:
+ m_abstractEvent->setRecurrence(CalendarEvent::NO_RECURRENCE);
+ break;
+ case CAL_REPEAT_EVERY_DAY:
+ m_abstractEvent->setRecurrence(CalendarEvent::DAILY_RECURRENCE);
+ break;
+ case CAL_REPEAT_EVERY_WEEK:
+ {
+ const char *daysFlag = calendar_svc_struct_get_str(
+ m_platformEvent,
+ CAL_VALUE_TXT_WEEK_FLAG);
+ if (daysFlag && strncmp(daysFlag, weekDays, 7) == 0) {
+ m_abstractEvent->setRecurrence(CalendarEvent::WEEKDAY_RECURRENCE);
+ } else {
+ m_abstractEvent->setRecurrence(CalendarEvent::WEEKLY_RECURRENCE);
+ }
+ }
+ break;
+ case CAL_REPEAT_EVERY_MONTH:
+ {
+ const char *daysFlag = calendar_svc_struct_get_str(
+ m_platformEvent,
+ CAL_VALUE_TXT_WEEK_FLAG);
+ if (!daysFlag || strnlen(daysFlag, 7) == 0) {
+ m_abstractEvent->setRecurrence(CalendarEvent::MONTHLY_RECURRENCE);
+ } else {
+ m_abstractEvent->setRecurrence(
+ CalendarEvent::MONTHLY_ON_DAY_RECURRENCE);
+ }
+ }
+ break;
+ case CAL_REPEAT_EVERY_YEAR:
+ m_abstractEvent->setRecurrence(CalendarEvent::YEARLY_RECURRENCE);
+ break;
+ default:
+ LogWarning("unknown recurrence");
+ m_abstractEvent->setRecurrence(CalendarEvent::NO_RECURRENCE);
+ break;
+ }
+}
+
+void EventWrapper::setAlarmFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+
+ GList* list = NULL;
+ calendar_svc_struct_get_list(m_platformEvent, CAL_VALUE_LST_ALARM, &list);
+ if (NULL == list) {
+ //no alarms
+ m_abstractEvent->resetAlarmTime();
+ return;
+ }
+
+ cal_value* alarm = static_cast<cal_value*>(list->data);
+ if (NULL == alarm) {
+ //no alarms
+ m_abstractEvent->resetAlarmTime();
+ return;
+ }
+
+ cal_sch_remind_tick_unit_t tickUnit =
+ static_cast<cal_sch_remind_tick_unit_t>(calendar_svc_value_get_int(
+ alarm,
+ CAL_VALUE_INT_ALARMS_TICK_UNIT));
+
+ if (CAL_SCH_TIME_UNIT_OFF == tickUnit) {
+ //no alarm
+ m_abstractEvent->resetAlarmTime();
+ return;
+ }
+ else if (CAL_SCH_TIME_UNIT_SPECIFIC == tickUnit) {
+ m_abstractEvent->setAlarmTime(calendar_svc_value_get_time(
+ alarm, CAL_VALUE_GMT_ALARMS_TIME, CAL_TZ_FLAG_GMT));
+ }
+ else {
+ int tick = calendar_svc_value_get_int(alarm,
+ CAL_VALUE_INT_ALARMS_TICK);
+ time_t startTime = m_abstractEvent->getStartTime();
+ switch(tickUnit) {
+ case CAL_SCH_TIME_UNIT_MIN:
+ /* tick contains number of minutes to substract */
+ startTime -= tick * 60;
+ break;
+ case CAL_SCH_TIME_UNIT_HOUR:
+ /* tick contains number of hours to substract */
+ startTime -= tick * 60 * 60;
+ break;
+ case CAL_SCH_TIME_UNIT_DAY:
+ /* tick contains number of days to substract */
+ startTime -= tick * 60 * 60 * 24;
+ break;
+ case CAL_SCH_TIME_UNIT_WEEK:
+ /* tick contains number of weeks to substract */
+ startTime -= tick * 60 * 60 * 24 * 7;
+ break;
+ case CAL_SCH_TIME_UNIT_MONTH: {
+ /* tick contains number of months to substract */
+ struct tm *t = localtime(&startTime);
+ t->tm_mon -= tick;
+ int tmpDay = t->tm_mday;
+ startTime = mktime(t);
+ if (tmpDay != t->tm_mday) {
+ //previous month is shorter than current
+ //corrent day and month
+ t->tm_mday = tmpDay - t->tm_mday;
+ --t->tm_mon;
+ startTime = mktime(t);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ m_abstractEvent->setAlarmTime(startTime);
+ }
+
+ cal_alert_type_t alarmType = static_cast<cal_alert_type_t>(
+ calendar_svc_value_get_int(alarm, CAL_VALUE_INT_ALARMS_TYPE));
+ switch (alarmType) {
+ case CAL_ALERT_VIBRATION:
+ m_abstractEvent->setAlarmType(CalendarEvent::SILENT_ALARM);
+ break;
+ case CAL_ALERT_MELODY:
+ case CAL_ALERT_INCREASING_MELODY:
+ case CAL_ALERT_VIBRATION_THEN_MELODY:
+ case CAL_ALERT_VIBMELODY:
+ case CAL_ALERT_VIB_INCREASING_MELODY:
+ m_abstractEvent->setAlarmType(CalendarEvent::SOUND_ALARM);
+ break;
+ case CAL_ALERT_MUTE:
+ default:
+ m_abstractEvent->setAlarmType(CalendarEvent::NO_ALARM);
+ break;
+ }
+}
+
+void EventWrapper::setStatusFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ int status = calendar_svc_struct_get_int(m_platformEvent,
+ CAL_VALUE_INT_MEETING_STATUS);
+ switch (status) {
+ case 1:
+ m_abstractEvent->setStatus(CalendarEvent::TENTATIVE_STATUS);
+ break;
+ case 2:
+ m_abstractEvent->setStatus(CalendarEvent::CANCELLED_STATUS);
+ break;
+ case 0:
+ default:
+ m_abstractEvent->setStatus(CalendarEvent::CONFIRMED_STATUS);
+ break;
+ }
+}
+void EventWrapper::setCategoriesFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ m_abstractEvent->getCategories()->clear();
+ GList *categoryList = NULL;
+ if (CAL_SUCCESS !=
+ calendar_svc_struct_get_list(m_platformEvent,
+ CAL_VALUE_LST_MEETING_CATEGORY,
+ &categoryList)) {
+ LogError("cannot read category list");
+ return;
+ }
+ cal_value* category = NULL;
+ for (; categoryList; categoryList = g_list_next(categoryList)) {
+ category = static_cast<cal_value*>(categoryList->data);
+ char* categoryName = calendar_svc_value_get_str(category,
+ "category_name");
+ if (NULL == categoryName) {
+ LogError("cannot read category name");
+ return;
+ }
+ m_abstractEvent->getCategories()->push_back(categoryName);
+ }
+}
+
+void EventWrapper::setIDFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ m_abstractEvent->setId(getIDFromPlatformEvent());
+}
+
+void EventWrapper::setExpiresFromPlatformEvent()
+{
+ if (!m_platformEvent) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ time_t expires = calendar_svc_struct_get_time(m_platformEvent,
+ CAL_VALUE_GMT_REPEAT_END_DATE,
+ CAL_TZ_FLAG_GMT);
+ m_abstractEvent->setExpires(expires);
+}
+
+void EventWrapper::setIntervalFromPlatformEvent()
+{
+ int interval = calendar_svc_struct_get_int(m_platformEvent,
+ CAL_VALUE_INT_REPEAT_INTERVAL);
+ m_abstractEvent->setInterval(interval);
+}
+
+void EventWrapper::displayAbstractEvent()
+{
+ m_abstractEvent->display();
+}
+
+void EventWrapper::displayPlatformEvent()
+{
+ LogDebug("event id: " << calendar_svc_struct_get_int(m_platformEvent,
+ CAL_VALUE_INT_INDEX));
+ LogDebug("event start time: " << calendar_svc_struct_get_time(
+ m_platformEvent, CAL_VALUE_GMT_START_DATE_TIME,
+ CAL_TZ_FLAG_GMT));
+ LogDebug("event end time: " << calendar_svc_struct_get_time(m_platformEvent,
+ CAL_VALUE_GMT_END_DATE_TIME,
+ CAL_TZ_FLAG_GMT));
+ LogDebug("event location: " << calendar_svc_struct_get_str(m_platformEvent,
+ CAL_VALUE_TXT_LOCATION));
+ LogDebug("event summary: " << calendar_svc_struct_get_str(m_platformEvent,
+ CAL_VALUE_TXT_SUMMARY));
+ LogDebug("event description: " << calendar_svc_struct_get_str(
+ m_platformEvent, CAL_VALUE_TXT_DESCRIPTION));
+}
+}
+}
--- /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 EventWrapper.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CALENDAR_EVENT_WRAPPER_H_
+#define WRTDEVICEAPIS_CALENDAR_EVENT_WRAPPER_H_
+
+#include <string>
+#include <calendar-svc-provider.h>
+#include <dpl/shared_ptr.h>
+#include <Calendar/CalendarEvent.h>
+#include <Calendar/EventFilter.h>
+
+namespace WrtDeviceApis {
+namespace Calendar {
+
+class EventWrapper
+{
+ public:
+ EventWrapper();
+ explicit EventWrapper(const Api::CalendarEventPtr &event);
+ virtual ~EventWrapper();
+ cal_struct *convertAbstractEventToPlatformEvent();
+ Api::CalendarEventPtr convertPlatformEventToAbstractEvent();
+ cal_struct *getPlatformEvent() const;
+ Api::CalendarEventPtr getAbstractEvent() const;
+ void freePlatformEvent();
+ void saveEvent();
+ void loadEvent(int id);
+ void deleteEvent();
+ bool matchFilters(Api::EventFilterPtr filter);
+
+ protected:
+ int getIDFromPlatformEvent() const;
+ void setDescriptionToPlatformEvent();
+ void setSubjectToPlatformEvent();
+ void setStartTimeToPlatformEvent();
+ void setEndTimeToPlatformEvent();
+ void setLocationToPlatformEvent();
+ void setRecurrenceToPlatformEvent();
+ void setAlarmToPlatformEvent();
+ void setStatusToPlatformEvent();
+ void setCategoriesToPlatformEvent();
+ void setIDToPlatformEvent();
+ void setExpiresToPlatformEvent();
+ void setIntervalToPlatformEvent();
+
+ void setDescriptionFromPlatformEvent();
+ void setSubjectFromPlatformEvent();
+ void setStartTimeFromPlatformEvent();
+ void setEndTimeFromPlatformEvent();
+ void setLocationFromPlatformEvent();
+ void setRecurrenceFromPlatformEvent();
+ void setAlarmFromPlatformEvent();
+ void setStatusFromPlatformEvent();
+ void setCategoriesFromPlatformEvent();
+ void setIDFromPlatformEvent();
+ void setExpiresFromPlatformEvent();
+ void setIntervalFromPlatformEvent();
+ private:
+ void displayAbstractEvent(); //only for debugging
+ void displayPlatformEvent(); //only for debugging
+
+ cal_struct *m_platformEvent;
+ Api::CalendarEventPtr m_abstractEvent;
+};
+
+typedef DPL::SharedPtr<EventWrapper> EventWrapperPtr;
+}
+}
+#endif // WRTDEVICEAPIS_CALENDAR_EVENT_WRAPPER_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(calendar REQUIRED calendar)
+pkg_search_module(glib REQUIRED glib-2.0)
+pkg_search_module(libpcrecpp REQUIRED libpcrecpp)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CALENDAR
+ ${calendar_INCLUDE_DIRS}
+ ${glib_INCLUDE_DIRS}
+ ${libpcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CALENDAR
+ ${calendar_LIBRARIES}
+ ${glib_LIBRARIES}
+ ${libpcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CALENDAR
+ ${CURRENT_PATH}/Calendar.cpp
+ ${CURRENT_PATH}/CalendarManager.cpp
+ ${CURRENT_PATH}/EventWrapper.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());
+ }
+}
+
+}
+}
--- /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_MANAGER_H_
+#define WRT_PLUGINS_CAMERA_MANAGER_H_
+
+#include <dpl/mutex.h>
+
+#include <API/Camera/ICameraManager.h>
+#include <API/Camera/EventGetCameras.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+
+class CameraManager : public Api::ICameraManager
+{
+protected:
+ virtual void OnRequestReceived(
+ const Api::EventGetCamerasPtr &event);
+
+private:
+ DPL::Mutex m_accessMutex;
+};
+
+}
+}
+#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.
+ */
+/*
+ * @file AddressBook.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#include <ctime>
+#include <cstdlib>
+#include <cstddef>
+#include <fstream>
+#include <sstream>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include <Contact/IAddressBook.h>
+#include <Contact/Contact.h>
+#include <Filesystem/Manager.h>
+#include "AddressBook.h"
+#include "ContactWrapper.h"
+
+namespace WrtDeviceApis {
+namespace Contact {
+
+using namespace Api;
+
+bool AddressBook::m_isDaInit = false;
+
+AddressBook::AddressBook(IAddressBookObject::BookType type) :
+ IAddressBookObject(type)
+{
+ LogDebug("entered");
+ //platform layer seems to not support different storage types yet
+ /*
+ if ( type == IAddressBookObject::PhoneBook ) {
+ LogDebug("PhoneBook");
+ }
+ else if ( type == IAddressBookObject::SIMBook ) {
+ LogDebug("SIMBook");
+ }
+ else {
+ LogError("wrong book type");
+ }
+ */
+
+ setDaClientIdByDaInit();
+}
+
+AddressBook::~AddressBook()
+{
+ LogDebug("entered");
+ unsetDaClientIdByDaDeinit();
+}
+
+std::string AddressBook::getName() const
+{
+ //return address book name
+ return m_name;
+}
+
+void AddressBook::setName(const std::string &value)
+{
+ //set address book name
+ m_name = value;
+}
+
+void AddressBook::daNotifyCb(user_notify_info_t *notify_info,
+ void *user_data)
+{
+ if (notify_info == NULL) {
+ LogDebug("notify_info is NULL!!");
+ return;
+ }
+
+ if (notify_info->state == DA_STATE_FAILED || notify_info->state ==
+ DA_STATE_CANCELED) {
+ if (user_data != NULL) {
+ DownImgInfo *downImgInfo;
+ downImgInfo = static_cast<DownImgInfo*>(user_data);
+ (downImgInfo->getWaitableEvent())->Signal();
+ }
+ }
+}
+
+void AddressBook::daGetDdInfoCb(user_dd_info_t* /*dd_info*/,
+ void* /*user_data*/)
+{
+ /* Empty CB */
+ LogDebug("Entered!");
+}
+
+void AddressBook::daUpdateDownloadInfoCb(user_download_info_t *download_info,
+ void *user_data)
+{
+ LogDebug("Entered!");
+
+ if (download_info != NULL && user_data != NULL) {
+ if (download_info->saved_path) {
+ LogDebug(
+ "download_info->saved_path : " << download_info->saved_path);
+ DownImgInfo *downImgInfo = static_cast<DownImgInfo*>(user_data);
+ std::string savedPath = download_info->saved_path;
+ downImgInfo->setdownloadedImgPath(savedPath);
+ (downImgInfo->getWaitableEvent())->Signal();
+ }
+ }
+}
+
+void AddressBook::setDaClientIdByDaInit(void)
+{
+ LogDebug("Entered!! m_isDaInit: " << m_isDaInit);
+ if (m_isDaInit) {
+ LogDebug("DaInit already done!");
+ return;
+ }
+ m_isDaInit = true;
+
+ int da_ret = DA_INVALID_ID;
+ da_client_cb_t da_cb;
+ memset(&da_cb, 0, sizeof(da_client_cb_t));
+
+ da_cb.user_noti_cb = &daNotifyCb;
+ da_cb.send_dd_info_cb = &daGetDdInfoCb;
+ da_cb.update_dl_info_cb = &daUpdateDownloadInfoCb;
+ da_ret = da_init(&da_cb, DA_DOWNLOAD_MANAGING_METHOD_AUTO);
+
+ if (da_ret != DA_RESULT_OK) {
+ LogDebug("Error during da_init() da_ret: " << da_ret);
+ }
+}
+
+void AddressBook::unsetDaClientIdByDaDeinit(void)
+{
+ LogDebug("Entered!! m_isDaInit: " << m_isDaInit);
+ if(m_isDaInit) {
+ da_deinit();
+ m_isDaInit = false;
+ }
+}
+
+std::string AddressBook::getRealPath(const std::string &path) const
+{
+ //translate provided path to real filesystem path
+ Try
+ {
+ LogDebug("path : " << path);
+ if (Commons::validate("^(http(s)?://)?\\w+.*$",
+ path,
+ Commons::VALIDATE_MATCH_CASELESS))
+ {
+ // if path is URL then Img will be downloaded.
+ LogDebug("path is URL. Start Image download!");
+ return downloadImage(path);
+ } else {
+ //translate provided path to real filesystem path
+ Filesystem::Api::IPathPtr currentPath =
+ Filesystem::Api::IPath::create(path);
+ return currentPath->getFullPath();
+ }
+ }
+ Catch(Commons::Exception)
+ {
+ //probably path doesn't exist
+ LogError("invalid path");
+ }
+ //on error return empty string
+ return std::string();
+}
+
+std::string AddressBook::downloadImage(const std::string &imgUrl) const
+{
+ try
+ {
+ LogDebug("URL : " << imgUrl);
+
+ DownImgInfo downImgInfo;
+ int da_ret = DA_INVALID_ID;
+ int download_id = -1;
+
+ DPL::WaitableEvent waitableEvent;
+ downImgInfo.setWaitableEvent(&waitableEvent);
+ da_ret = da_start_download_with_extension(
+ imgUrl.c_str(), &download_id,
+ DA_FEATURE_USER_DATA,
+ static_cast<void*>(&
+ downImgInfo),
+ NULL);
+ if (da_ret != DA_RESULT_OK) {
+ ThrowMsg(
+ Commons::PlatformException,
+ "Error during da_start_download_with_extension() da_ret: "
+ << da_ret);
+ }
+ DPL::WaitForSingleHandle(waitableEvent.GetHandle());
+ waitableEvent.Reset();
+
+ if ((downImgInfo.getdownloadedImgPath()).empty()) {
+ ThrowMsg(Commons::Exception, "Download is Fail!");
+ }
+ return downImgInfo.getdownloadedImgPath();
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Probably invalid URL. " << ex.GetMessage());
+ }
+ //on error return empty string(file path)
+ return std::string();
+}
+
+std::vector<std::string> AddressBook::internalExportToVCard(
+ const std::vector<ContactPtr> &contacts) const
+{
+ //container for result files
+ std::vector<std::string> result;
+ //path for currently exporting contact
+ std::string path;
+ //platform stream
+ char *vcard_stream;
+ //contact to export
+ CTSstruct *contact;
+ //streams
+ std::fstream outputFile;
+ std::stringstream name;
+ //get current time to create unique file names
+ std::time_t t = std::time(0);
+ //iterate over all contacts to export
+ for (std::size_t i = 0; i < contacts.size(); ++i) {
+ //create new file name for current contact
+ name.clear();
+ name << "/Others/contacts_" << i << "_" << t << ".vcf";
+ //translate path for real filesystem
+ path = getRealPath(name.str());
+ if (path.empty()) {
+ LogError("Cannot convert path to real file system path");
+ return std::vector<std::string>();
+ }
+ LogDebug("filename: " << path);
+ Try
+ {
+ //check if file exists and return if does
+ if (Filesystem::Manager::fileExists(path)) {
+ LogError("File already exists");
+ return std::vector<std::string>();
+ }
+ }
+ Catch(Commons::PlatformException)
+ {
+ //error during check, return
+ LogError("Cannot validate if file exists.");
+ return std::vector<std::string>();
+ }
+ //create and open new file
+ outputFile.open(path.c_str(), std::fstream::out | std::fstream::app);
+ if (!outputFile.fail()) {
+ //when failes is created then continue with processing a contact
+ //convert file into platform struct
+ ContactWrapperPtr wrapper(new ContactWrapper(m_bookType));
+ wrapper->setAbstractContact(contacts[i]);
+ contact = wrapper->getPlatformContact();
+ //call API function to get VCard stresm
+ if (CTS_SUCCESS ==
+ contacts_svc_get_vcard_from_contact(contact,
+ &vcard_stream)) {
+ //save results to file
+ outputFile.write(vcard_stream, strlen(vcard_stream));
+ }
+ //add file to results
+ result.push_back(name.str());
+ } else {
+ //return if cannot create file
+ LogError("cannot open file");
+ return std::vector<std::string>();
+ }
+ //close file
+ outputFile.close();
+ }
+ //return file names
+ return result;
+}
+
+void AddressBook::internalAddGroup(const std::string &groupName) const
+{
+ LogDebug("entered");
+ //dont add group when already exists
+ if (getGroupId(groupName) != -1) {
+ LogWarning("group already exists");
+ return;
+ }
+ //create plaform struct describing group
+ CTSvalue *group = contacts_svc_value_new(CTS_VALUE_GROUP);
+ if (group) {
+ //set group name
+ contacts_svc_value_set_str(group,
+ CTS_GROUP_VAL_NAME_STR,
+ groupName.c_str());
+ //set default ring tone
+ contacts_svc_value_set_str(group, CTS_GROUP_VAL_RINGTONE_STR, "");
+ //try to add new group
+ if (contacts_svc_insert_group(0, group) < CTS_SUCCESS) {
+ //failed, free data and throw exception
+ contacts_svc_value_free(group);
+ LogError("contacts_svc_insert_group() Failed");
+ ThrowMsg(Commons::PlatformException,
+ "Error during executing contacts_svc_insert_group()");
+ }
+ //success, free data
+ contacts_svc_value_free(group);
+ } else {
+ //throw exception
+ ThrowMsg(Commons::PlatformException, "Group object not created");
+ }
+}
+
+void AddressBook::internalDeleteGroup(const std::string &groupName) const
+{
+ LogDebug("entered");
+ int groupId = getGroupId(groupName);
+ if (groupId != -1) {
+ LogDebug("deleting group, id " << groupId);
+ if (CTS_SUCCESS != contacts_svc_delete_group(groupId)) {
+ ThrowMsg(Commons::PlatformException,
+ "Error during deleting a group");
+ }
+ }
+}
+
+int AddressBook::getGroupId(const std::string &groupName)
+{
+ LogDebug("entered with group name " << groupName);
+ CTSiter *iter = NULL;
+ if (CTS_SUCCESS == contacts_svc_get_list(CTS_LIST_ALL_GROUP, &iter)) {
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue *group = contacts_svc_iter_get_info(iter);
+ if (group) {
+ const char *foundGroupName = contacts_svc_value_get_str(
+ group,
+ CTS_LIST_GROUP_NAME_STR);
+ if (foundGroupName && groupName == foundGroupName) {
+ int groupId = contacts_svc_value_get_int(
+ group,
+ CTS_LIST_GROUP_ID_INT);
+ contacts_svc_value_free(group);
+ contacts_svc_iter_remove(iter);
+ return groupId;
+ }
+ contacts_svc_value_free(group);
+ }
+ }
+ contacts_svc_iter_remove(iter);
+ }
+ return -1;
+}
+
+std::vector<std::string> AddressBook::internalFindGroup(
+ const std::string &groupName) const
+{
+ LogDebug("entered with group filter: " << groupName);
+ std::vector<std::string> result;
+ CTSiter *iter = NULL;
+ if (CTS_SUCCESS == contacts_svc_get_list(CTS_LIST_ALL_GROUP, &iter)) {
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue *group = contacts_svc_iter_get_info(iter);
+ if (group) {
+ const char *foundGroupName = contacts_svc_value_get_str(
+ group,
+ CTS_LIST_GROUP_NAME_STR);
+ if (foundGroupName) {
+ if (groupName.empty() ||
+ Commons::validate(groupName,
+ foundGroupName,
+ Commons::VALIDATE_MATCH_CASELESS))
+ {
+ LogDebug("found group " << foundGroupName);
+ result.push_back(foundGroupName);
+ }
+ }
+ contacts_svc_value_free(group);
+ }
+ }
+ contacts_svc_iter_remove(iter);
+ }
+ return result;
+}
+
+void AddressBook::internalAddContact(const ContactPtr &newContact) const
+{
+ LogDebug("entered");
+
+ //translate provided path to real filesystem path
+ if (newContact->getPhotoIsSet()) {
+ std::string realpath = getRealPath(newContact->getPhotoUri());
+ newContact->setPhotoUri(realpath);
+ }
+
+ ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType));
+ contactWrapper->setAbstractContact(newContact);
+ CTSstruct* contact = contactWrapper->getPlatformContact();
+ if (!contact) {
+ LogError("Error during converting contact object");
+ ThrowMsg(Commons::PlatformException,
+ "Error during converting contact object");
+ }
+ int id = contacts_svc_insert_contact(0, contact);
+ if (id < 0) {
+ LogError("error code " << id);
+ ThrowMsg(Commons::PlatformException,
+ "Error during executing contacts_svc_insert_contact()");
+ }
+ newContact->setId(id);
+}
+
+void AddressBook::internalUpdateContact(const Api::ContactPtr &updatedContact)
+const
+{
+ LogDebug("entered");
+ if (!updatedContact) {
+ ThrowMsg(Commons::PlatformException, "Contact is NULL");
+ }
+ if (!updatedContact->getIdIsSet()) {
+ ThrowMsg(Commons::PlatformException, "Contact is not saved yet");
+ }
+ LogDebug("update contact with id " << updatedContact->getId());
+ ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType));
+ contactWrapper->setAbstractContact(updatedContact);
+ CTSstruct* contact = contactWrapper->getPlatformContact();
+ if (!contact) {
+ LogError("Error during converting contact object");
+ ThrowMsg(Commons::PlatformException,
+ "Error during converting contact object");
+ }
+ if (CTS_SUCCESS != contacts_svc_update_contact(contact)) {
+ ThrowMsg(Commons::PlatformException,
+ "Error during executing contacts_svc_update_contact()");
+ }
+ LogDebug("update successful");
+}
+
+ContactPtr AddressBook::internalFindContactById(int id) const
+{
+ LogDebug("entered with id " << id);
+ CTSstruct *contact = NULL;
+ int errorCode = contacts_svc_get_contact(id, &contact);
+ if (CTS_SUCCESS == errorCode) {
+ ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType));
+ contactWrapper->setPlatformContact(contact);
+ ContactPtr contact = contactWrapper->getAbstractContact();
+ if (!contact) {
+ ThrowMsg(Commons::PlatformException,
+ "Error during converting contact object");
+ }
+ return contact;
+ } else if (CTS_ERR_DB_RECORD_NOT_FOUND == errorCode) {
+ LogWarning("record not found");
+ return ContactPtr(NULL);
+ } else {
+ ThrowMsg(Commons::PlatformException,
+ "Error during executing contacts_svc_get_contact()");
+ }
+}
+
+std::vector<ContactPtr> AddressBook::internalFindContactByFilter(
+ const ContactFilterPtr &filter,
+ int startIndex,
+ int endIndex,
+ bool caseSensitive) const
+{
+ LogDebug("entered");
+ std::vector<ContactPtr> result;
+ int count = 0;
+ CTSvalue *platformContact = NULL;
+ CTSiter *iter = NULL;
+ if (CTS_SUCCESS == contacts_svc_get_list(CTS_LIST_ALL_CONTACT, &iter)) {
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ platformContact = contacts_svc_iter_get_info(iter);
+ if (platformContact) {
+ int contactId = contacts_svc_value_get_int(
+ platformContact,
+ CTS_LIST_CONTACT_ID_INT);
+ ContactPtr contact = internalFindContactById(contactId);
+ /*Compare the contact to the filter*/
+ if (contact && matchToFilter(filter, contact, caseSensitive)) {
+ LogDebug("found contact by filter");
+ if (count >= startIndex) {
+ result.push_back(contact);
+ }
+ ++count;
+ }
+ contacts_svc_value_free(platformContact);
+ if (endIndex != -1 && count > endIndex) {
+ contacts_svc_iter_remove(iter);
+ return result;
+ }
+ }
+ }
+ contacts_svc_iter_remove(iter);
+ }
+ return result;
+}
+
+std::vector<ContactPtr> AddressBook::internalFindContactByGroup(
+ const std::string &groupName) const
+{
+ LogDebug("entered with group: " << groupName);
+ std::vector<ContactPtr> result;
+ CTSvalue *platformContact = NULL;
+ CTSiter *iter = NULL;
+ if (CTS_SUCCESS == contacts_svc_get_list(CTS_LIST_ALL_CONTACT, &iter)) {
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ platformContact = contacts_svc_iter_get_info(iter);
+ if (platformContact) {
+ int contactId = contacts_svc_value_get_int(
+ platformContact,
+ CTS_LIST_CONTACT_ID_INT);
+ ContactPtr contact = internalFindContactById(contactId);
+ if (contact) {
+ std::vector<std::string>::const_iterator found =
+ find(contact->getGroups().begin(),
+ contact->getGroups().end(), groupName);
+ if (found != contact->getGroups().end()) {
+ LogDebug("found contact in group");
+ result.push_back(contact);
+ }
+ }
+ contacts_svc_value_free(platformContact);
+ }
+ }
+ contacts_svc_iter_remove(iter);
+ }
+ return result;
+}
+
+void AddressBook::internalDeleteContactById(int id) const
+{
+ LogDebug("entered with id " << id);
+ if (id != -1) {
+ CTSstruct *contact = NULL;
+ /*If the contact is not existed, throw NotFoundException*/
+ if (CTS_SUCCESS != contacts_svc_get_contact(id, &contact)) {
+ ThrowMsg(Commons::NotFoundException,
+ "Can't delete contact, contact doesn't exist. Error code");
+ }
+
+ if (CTS_SUCCESS != contacts_svc_delete_contact(id)) {
+ ThrowMsg(Commons::PlatformException,
+ "Error during executing contacts_svc_delete_contact()");
+ }
+ }
+}
+
+unsigned int AddressBook::internalGetNumberOfContacts() const
+{
+ LogDebug("entered");
+ int result = contacts_svc_count_with_int(
+ CTS_GET_COUNT_CONTACTS_IN_ADDRESSBOOK,
+ 0);
+ if (result < 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Error during executing contacts_svc_count_with_int()");
+ }
+ return result;
+}
+
+std::vector<ContactPtr> AddressBook::mergeRecords(
+ const std::vector<ContactPtr> &contacts) const
+{
+ LogDebug("entered");
+ std::vector<ContactPtr> merged;
+ std::vector<ContactPtr>::const_iterator it;
+ for (it = contacts.begin(); it != contacts.end(); ++it) {
+ ContactPtr copy = (*it)->clone();
+ /*Merge types of emails with the same email address*/
+ copy->setEmails(mergeEmails(copy->getEmails()));
+ /*Merge types of phonenumbers with the same number*/
+ copy->setPhoneNumbers(mergePhoneNumbers(copy->getPhoneNumbers()));
+ /*Merge types of addresses with the same address info*/
+ copy->setAddresses(mergeAddresses(copy->getAddresses()));
+ merged.push_back(copy);
+ }
+ return merged;
+}
+
+std::vector<ContactEmailPtr> AddressBook::mergeEmails(
+ const std::vector<ContactEmailPtr> &emails) const
+{
+ LogDebug("entered");
+ std::vector<ContactEmailPtr> merged;
+ std::vector<ContactEmailPtr>::const_iterator it;
+ std::vector<ContactEmailPtr>::const_iterator mergedIt;
+ std::vector<ContactEmail::ContactEmailType>::const_iterator typesIt;
+ bool found;
+ for (it = emails.begin(); it != emails.end(); ++it) {
+ found = false;
+ for (mergedIt = merged.begin(); mergedIt != merged.end(); ++mergedIt) {
+ if ((*mergedIt)->getEmail() == (*it)->getEmail()) {
+ LogDebug("found the same email " << (*mergedIt)->getEmail());
+ //the same emails, check types and add if needed
+ const std::vector<ContactEmail::ContactEmailType> &types =
+ (*it)->getTypes();
+ for (typesIt = types.begin(); typesIt != types.end();
+ ++typesIt) {
+ if (!(*mergedIt)->isTypeOf(*typesIt)) {
+ (*mergedIt)->addType(*typesIt);
+ LogInfo("merged email type " << *typesIt);
+ }
+ }
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ LogInfo("copy email");
+ merged.push_back((*it)->clone());
+ }
+ }
+ return merged;
+}
+
+std::vector<ContactPhoneNumberPtr> AddressBook::mergePhoneNumbers(
+ const std::vector<ContactPhoneNumberPtr> &phoneNumbers) const
+{
+ LogDebug("entered");
+ std::vector<ContactPhoneNumberPtr> merged;
+ std::vector<ContactPhoneNumberPtr>::const_iterator it;
+ std::vector<ContactPhoneNumberPtr>::const_iterator mergedIt;
+ std::vector<ContactPhoneNumber::ContactPhoneNumberType>::const_iterator
+ typesIt;
+ bool found;
+ for (it = phoneNumbers.begin(); it != phoneNumbers.end(); ++it) {
+ found = false;
+ for (mergedIt = merged.begin(); mergedIt != merged.end(); ++mergedIt) {
+ if ((*mergedIt)->getNumber() == (*it)->getNumber()) {
+ LogDebug(
+ "found the same phone number " << (*mergedIt)->getNumber());
+ //the same emails, check types and add if needed
+ const std::vector<ContactPhoneNumber::ContactPhoneNumberType> &
+ types = (*it)->getTypes();
+ for (typesIt = types.begin(); typesIt != types.end();
+ ++typesIt) {
+ if (!(*mergedIt)->isTypeOf(*typesIt)) {
+ LogInfo("merged phone type " << *typesIt);
+ (*mergedIt)->addType(*typesIt);
+ }
+ }
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ LogInfo("copy phone");
+ merged.push_back((*it)->clone());
+ }
+ }
+ return merged;
+}
+
+std::vector<ContactAddressPtr> AddressBook::mergeAddresses(
+ const std::vector<ContactAddressPtr> &addresses) const
+{
+ LogDebug("entered");
+ std::vector<ContactAddressPtr> merged;
+ std::vector<ContactAddressPtr>::const_iterator it;
+ std::vector<ContactAddressPtr>::const_iterator mergedIt;
+ std::vector<ContactAddress::ContactAddressType>::const_iterator typesIt;
+ bool found;
+ for (it = addresses.begin(); it != addresses.end(); ++it) {
+ found = false;
+ for (mergedIt = merged.begin(); mergedIt != merged.end(); ++mergedIt) {
+ if ((*mergedIt)->compareTo((*it))) {
+ LogDebug("found the same address");
+ //the same emails, check types and add if needed
+ const std::vector<ContactAddress::ContactAddressType> &types =
+ (*it)->getTypes();
+ for (typesIt = types.begin(); typesIt != types.end();
+ ++typesIt) {
+ if (!(*mergedIt)->isTypeOf(*typesIt)) {
+ LogInfo("merged address type " << *typesIt);
+ (*mergedIt)->addType(*typesIt);
+ }
+ }
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ LogInfo("copy address");
+ merged.push_back((*it)->clone());
+ }
+ }
+ return merged;
+}
+
+bool AddressBook::matchToFilter(const ContactFilterPtr &filter,
+ const ContactPtr &contact,
+ bool caseSensitive) const
+{
+ LogDebug("entered");
+ if (!contact) {
+ //no object provided
+ return false;
+ }
+ if (!filter) {
+ //pass all when no filter
+ return true;
+ }
+ unsigned int matchOptions =
+ caseSensitive ? 0 : Commons::VALIDATE_MATCH_CASELESS;
+ if (filter->getFullNameIsSet()) {
+ if (!Commons::validate(filter->getFullNameFilter(),
+ contact->getFullName(),
+ matchOptions))
+ {
+ LogDebug("rejected FullName");
+ return false;
+ }
+ }
+ if (filter->getFirstNameIsSet()) {
+ if (!Commons::validate(filter->getFirstNameFilter(),
+ contact->getFirstName(),
+ matchOptions))
+ {
+ LogDebug("rejected First Name");
+ return false;
+ }
+ }
+ if (filter->getLastNameIsSet()) {
+ if (!Commons::validate(filter->getLastNameFilter(),
+ contact->getLastName(),
+ matchOptions))
+ {
+ LogDebug("rejected Last Name");
+ return false;
+ }
+ }
+ if (filter->getCompanyIsSet()) {
+ if (!Commons::validate(filter->getCompanyFilter(),
+ contact->getCompany(),
+ matchOptions))
+ {
+ LogDebug("rejected company");
+ return false;
+ }
+ }
+ if (filter->getTitleIsSet()) {
+ if (!Commons::validate(filter->getTitleFilter(),
+ contact->getTitle(),
+ matchOptions))
+ {
+ LogDebug("rejected title");
+ return false;
+ }
+ }
+ if (filter->getPhoneticNameIsSet()) {
+ if (!Commons::validate(filter->getPhoneticNameFilter(),
+ contact->getPhoneticName(),
+ matchOptions))
+ {
+ LogDebug("rejected PhoneticName");
+ return false;
+ }
+ }
+ if (!matchToFilterEmail(filter, contact, caseSensitive)) {
+ return false;
+ }
+ if (!matchToFilterAddress(filter, contact, caseSensitive)) {
+ return false;
+ }
+ if (!matchToFilterPhoneNumber(filter, contact, caseSensitive)) {
+ return false;
+ }
+ if (!matchToFilterNickname(filter, contact, caseSensitive)) {
+ return false;
+ }
+ return true;
+}
+
+bool AddressBook::matchToFilterAddress(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const
+{
+ if (filter->getAddressIsSet()) {
+ bool found;
+ unsigned int matchOptions =
+ caseSensitive ? 0 : Commons::VALIDATE_MATCH_CASELESS;
+ LogDebug("filtering by address");
+ const std::vector<ContactAddressPtr> &addressFilter =
+ filter->getAddressFilter();
+ const std::vector<ContactAddressPtr> &addresses = contact->getAddresses();
+ for (std::size_t i = 0; i < addressFilter.size(); ++i) {
+ found = false;
+ const std::vector<ContactAddress::ContactAddressType> &
+ addrFilterTypes = addressFilter[i]->getTypes();
+ for (std::size_t j = 0; j < addresses.size(); ++j) {
+ if (!addrFilterTypes.empty()) {
+ if (!addresses[j]->isTypeOf(addressFilter[i]->getTypeFilter()))
+ {
+ LogDebug("rejected by Type!");
+ continue;
+ }
+ }
+ if (addressFilter[i]->getCountryIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getCountry(),
+ addresses[j]->getCountry(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getRegionIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getRegion(),
+ addresses[j]->getRegion(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getCountyIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getCounty(),
+ addresses[j]->getCounty(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getCityIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getCity(),
+ addresses[j]->getCity(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getStreetIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getStreet(),
+ addresses[j]->getStreet(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getStreetNumberIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getStreetNumber(),
+ addresses[j]->getStreetNumber(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getPremisesIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getPremises(),
+ addresses[j]->getPremises(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getAdditionalInformationIsSet()) {
+ if (!Commons::validate(
+ addressFilter[i]->getAdditionalInformation(),
+ addresses[j]->getAdditionalInformation(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ if (addressFilter[i]->getPostalCodeIsSet()) {
+ if (!Commons::validate(addressFilter[i]->getPostalCode(),
+ addresses[j]->getPostalCode(),
+ matchOptions))
+ {
+ LogDebug("rejected by address");
+ continue;
+ //return false;
+ }
+ }
+ found = true;
+ break;
+ }
+ if (!found) {
+ LogDebug("rejected by address");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool AddressBook::matchToFilterEmail(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const
+{
+ if (filter->getEmailIsSet()) {
+ bool found;
+ unsigned int matchOptions =
+ caseSensitive ? 0 : Commons::VALIDATE_MATCH_CASELESS;
+ LogDebug("filtering by email");
+ const std::vector<ContactEmailPtr> &emailFilter =
+ filter->getEmailFilter();
+ const std::vector<ContactEmailPtr> &emails = contact->getEmails();
+ for (std::size_t i = 0; i < emailFilter.size(); ++i) {
+ found = false;
+ const std::vector<ContactEmail::ContactEmailType> &emailFilterTypes
+ = emailFilter[i]->getTypes();
+ for (std::size_t j = 0; j < emails.size(); ++j) {
+ if (!emailFilterTypes.empty()) {
+ if (!emails[j]->isTypeOf(emailFilter[i]->getTypeFilter()))
+ {
+ LogDebug("type error!!!");
+ continue;
+ }
+ }
+ if (!Commons::validate(emailFilter[i]->getEmail(),
+ emails[j]->getEmail(),
+ matchOptions))
+ {
+ LogDebug("rejected by email, different email");
+ continue;
+ }
+ found = true;
+ break;
+ }
+ if (!found) {
+ LogDebug("rejected by email, not found email");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool AddressBook::matchToFilterPhoneNumber(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const
+{
+ if (filter->getPhoneNumberIsSet()) {
+ bool found;
+ unsigned int matchOptions =
+ caseSensitive ? 0 : Commons::VALIDATE_MATCH_CASELESS;
+ LogDebug("filtering by phone number");
+ const std::vector<ContactPhoneNumberPtr> &phoneNumberFilter =
+ filter->getPhoneNumberFilter();
+ const std::vector<ContactPhoneNumberPtr> &phoneNumber =
+ contact->getPhoneNumbers();
+ for (std::size_t i = 0; i < phoneNumberFilter.size(); ++i) {
+ found = false;
+ const std::vector<ContactPhoneNumber::ContactPhoneNumberType> &
+ phoneNumberFilterTypes = phoneNumberFilter[i]->getTypes();
+ for (std::size_t j = 0; j < phoneNumber.size(); ++j) {
+ if (!phoneNumberFilterTypes.empty()) {
+ if (!phoneNumber[j]->isTypeOf(phoneNumberFilter[i]->
+ getTypeFilter()))
+ {
+ LogDebug("rejected by phone type");
+ continue;
+ }
+ }
+ if (!Commons::validate(phoneNumberFilter[i]->getNumber(),
+ phoneNumber[j]->getNumber(),
+ matchOptions))
+ {
+ LogDebug("rejected by phone number");
+ continue;
+ }
+ found = true;
+ break;
+ }
+ if (!found) {
+ LogDebug("rejected by phone number");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool AddressBook::matchToFilterNickname(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const
+{
+ if (filter->getNickNameIsSet()) {
+ bool found;
+ unsigned int matchOptions =
+ caseSensitive ? 0 : Commons::VALIDATE_MATCH_CASELESS;
+ LogDebug("filtering by nickname");
+ const std::vector<std::string> &nicknameFilter =
+ filter->getNickNameFilter();
+ const std::vector<std::string> &nickname = contact->getNickNames();
+ for (std::size_t i = 0; i < nicknameFilter.size(); ++i) {
+ found = false;
+ for (std::size_t j = 0; j < nickname.size(); ++j) {
+ if (!Commons::validate(nicknameFilter[i],
+ nickname[j],
+ matchOptions))
+ {
+ continue;
+ }
+ found = true;
+ break;
+ }
+ if (!found) {
+ LogDebug("rejected by nickname");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+//**************************************
+//* Events *
+//**************************************
+
+void AddressBook::OnRequestReceived(const Api::EventAddContactPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ const ContactPtr &contact = event->getContact();
+ if (contact) {
+ internalAddContact(contact);
+ event->setResult(true);
+ }
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during adding contact.");
+ LogError(ex.GetMessage());
+ }
+}
+
+void AddressBook::OnRequestReceived(const Api::EventUpdateContactPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ const ContactPtr &contact = event->getContact();
+ if (contact) {
+ internalUpdateContact(contact);
+ event->setResult(true);
+ }
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during updating contact.");
+ LogError(ex.GetMessage());
+ }
+}
+
+void AddressBook::OnRequestReceived(const Api::EventDeleteContactPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ const ContactFilterPtr &filter = event->getFilter();
+ if (filter && filter->getIdIsSet()) {
+ internalDeleteContactById(filter->getIdFilter());
+ event->setResult(true);
+ }
+ }
+ catch (const Commons::NotFoundException &ex)
+ {
+ LogError("Contact doesn't exist");
+ event->setResult(false);
+ event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during deleting contact.");
+ LogError(ex.GetMessage());
+ event->setResult(false);
+ }
+}
+
+void AddressBook::OnRequestReceived(const Api::EventFindContactsPtr &event)
+{
+ LogDebug("entered");
+ ContactFilterPtr filter = event->getFilter();
+ try
+ {
+ if (filter && filter->getIdIsSet()) {
+ LogDebug("searching for contact by id");
+ ContactPtr contact = internalFindContactById(filter->getIdFilter());
+ if (contact) {
+ event->addContact(contact);
+ }
+ event->setResult(true);
+ } else if (filter && filter->getGroupIsSet()) {
+ LogDebug("searching for contact by group");
+ const std::vector<ContactPtr> &contacts =
+ internalFindContactByGroup(filter->getGroupFilter());
+ event->setContacts(contacts);
+ event->setResult(true);
+ } else {
+ LogDebug("searching for contact by filter");
+ const std::vector<ContactPtr> &contacts =
+ internalFindContactByFilter(filter,
+ event->getStartIndex(),
+ event->getEndIndex(), false);
+ event->setContacts(contacts);
+ event->setResult(true);
+ }
+ if (!event->getUseSignleTypes()) {
+ const std::vector<ContactPtr> &contacts = event->getContacts();
+ std::vector<ContactPtr> merged = mergeRecords(contacts);
+ event->setContacts(merged);
+ }
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during getting contact.");
+ LogError(ex.GetMessage());
+ }
+}
+
+void AddressBook::OnRequestReceived(
+ const Api::EventGetAddressBookItemCountPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ unsigned int count = internalGetNumberOfContacts();
+ event->setNumberOfAddressBookItems(count);
+ event->setResult(true);
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during getting contact.");
+ LogError(ex.GetMessage());
+ }
+}
+
+void AddressBook::OnRequestReceived(const Api::EventAddGroupPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ internalAddGroup(event->getGroupName());
+ event->setResult(true);
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during adding group.");
+ LogError(ex.GetMessage());
+ }
+}
+
+void AddressBook::OnRequestReceived(const Api::EventDeleteGroupPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ internalDeleteGroup(event->getGroupName());
+ event->setResult(true);
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during getting contact.");
+ LogError(ex.GetMessage());
+ }
+}
+
+void AddressBook::OnRequestReceived(const Api::EventFindGroupPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ std::vector<std::string> groups = internalFindGroup(event->getGroupName());
+ event->setFoundGroups(groups);
+ event->setResult(true);
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during getting groups.");
+ LogError(ex.GetMessage());
+ }
+}
+
+void AddressBook::OnRequestReceived(const Api::EventExportVCardPtr &event)
+{
+ LogDebug("entered");
+ try
+ {
+ const std::vector<ContactPtr> &contacts = event->getContacts();
+ LogDebug("number of contacts to export: " << contacts.size());
+ if (contacts.size() == 0) {
+ event->setResult(true);
+ return;
+ }
+ std::vector<std::string> paths = internalExportToVCard(contacts);
+ if (paths.size() > 0) {
+ event->setResult(true);
+ event->setPathToFiles(paths);
+ }
+ }
+ catch (const Commons::PlatformException &ex)
+ {
+ LogError("Error during getting groups.");
+ LogError(ex.GetMessage());
+ }
+}
+}
+}
+
--- /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 AddressBook.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_
+#define WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_
+
+#include <string>
+#include <vector>
+#include <contacts-svc.h>
+#include <download-agent-interface.h>
+#include <Contact/IAddressBook.h>
+#include <Contact/Contact.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+
+class AddressBook : public Api::IAddressBookObject
+{
+ private:
+ class DownImgInfo
+ {
+ private:
+ DPL::WaitableEvent* m_waitableEvent;
+ std::string m_downloadedImgPath;
+
+ public:
+ DownImgInfo() : m_waitableEvent(NULL)
+ {
+ }
+ void setWaitableEvent (DPL::WaitableEvent* waitableEvent)
+ {
+ m_waitableEvent = waitableEvent;
+ }
+ DPL::WaitableEvent* getWaitableEvent (void) const
+ {
+ return m_waitableEvent;
+ }
+ void setdownloadedImgPath (const std::string &downloadedImgPath)
+ {
+ m_downloadedImgPath = downloadedImgPath;
+ }
+ std::string getdownloadedImgPath (void) const
+ {
+ return m_downloadedImgPath;
+ }
+ };
+
+ public:
+ explicit AddressBook(Api::IAddressBookObject::BookType type);
+ virtual ~AddressBook();
+ //get name of AddressBook
+ std::string getName() const;
+ //set name of AddressBook
+ void setName(const std::string &value);
+ //get group id or -1 when no group found
+ static int getGroupId(const std::string &groupName);
+
+ protected:
+ void OnRequestReceived(const Api::EventAddContactPtr &event);
+ void OnRequestReceived(const Api::EventUpdateContactPtr &event);
+ void OnRequestReceived(const Api::EventDeleteContactPtr &event);
+ void OnRequestReceived(const Api::EventFindContactsPtr &event);
+ void OnRequestReceived(const Api::EventGetAddressBookItemCountPtr &event);
+ void OnRequestReceived(const Api::EventAddGroupPtr &event);
+ void OnRequestReceived(const Api::EventDeleteGroupPtr &event);
+ void OnRequestReceived(const Api::EventFindGroupPtr &event);
+ void OnRequestReceived(const Api::EventExportVCardPtr &event);
+
+ //exports contacts to files and returns paths to it or empty list on error.
+ std::vector<std::string> internalExportToVCard(
+ const std::vector<Api::ContactPtr> &contacts) const;
+ //checks if abstract object matches a filter
+ bool matchToFilter(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const;
+ void internalAddGroup(const std::string &groupName) const;
+ void internalDeleteGroup(const std::string &groupName) const;
+ std::vector<std::string> internalFindGroup(const std::string &groupName)
+ const;
+ void internalAddContact(const Api::ContactPtr &newContact) const;
+ void internalUpdateContact(const Api::ContactPtr &updatedContact) const;
+ Api::ContactPtr internalFindContactById(int id) const;
+ std::vector<Api::ContactPtr> internalFindContactByFilter(
+ const Api::ContactFilterPtr &filter,
+ int startIndex = -1,
+ int endIndex = -1,
+ bool caseSensitive = true) const;
+ std::vector<Api::ContactPtr> internalFindContactByGroup(
+ const std::string &groupName) const;
+ void internalDeleteContactById(int id) const;
+ unsigned int internalGetNumberOfContacts() const;
+ bool internalSetContactGroups(int id,
+ const std::vector<std::string> &groups) const;
+ std::vector<Api::ContactPtr> mergeRecords(
+ const std::vector<Api::ContactPtr> &contacts) const;
+ std::vector<Api::ContactEmailPtr> mergeEmails(
+ const std::vector<Api::ContactEmailPtr> &emails) const;
+ std::vector<Api::ContactPhoneNumberPtr> mergePhoneNumbers(
+ const std::vector<Api::ContactPhoneNumberPtr> &phoneNumbers) const;
+ std::vector<Api::ContactAddressPtr> mergeAddresses(
+ const std::vector<Api::ContactAddressPtr> &addresses) const;
+
+ std::string m_name;
+ private:
+ std::string getRealPath(const std::string &path) const;
+ std::string downloadImage(const std::string &imgUrl) const;
+ bool matchToFilterAddress(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const;
+ bool matchToFilterEmail(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const;
+ bool matchToFilterPhoneNumber(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const;
+ bool matchToFilterNickname(const Api::ContactFilterPtr &filter,
+ const Api::ContactPtr &contact,
+ bool caseSensitive) const;
+ static void daNotifyCb(user_notify_info_t *notify_info,
+ void *user_data);
+ static void daGetDdInfoCb(user_dd_info_t *dd_info,
+ void *user_data);
+ static void daUpdateDownloadInfoCb(user_download_info_t *download_info,
+ void *user_data);
+ static void setDaClientIdByDaInit(void);
+ static void unsetDaClientIdByDaDeinit(void);
+
+ static bool m_isDaInit;
+};
+}
+}
+
+#endif /* WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_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 ContactManager.cpp
+ * @author Lukasz Marek(l.marek@samsung.com)
+ * @version 0.1
+ *
+ */
+
+#include <dpl/log/log.h>
+#include <contacts-svc.h>
+#include <Contact/IAddressBook.h>
+#include <Contact/Contact.h>
+#include "ContactManager.h"
+#include "AddressBook.h"
+
+namespace {
+const char *DEVICE_ADDRESSBOOK = "DEVICE AddressBook";
+const char *SIM_ADDRESSBOOK = "SIM AddressBook";
+}
+
+namespace WrtDeviceApis {
+namespace Contact {
+
+using namespace Api;
+
+//initialize static variables
+int ContactManager::m_instanceCount = 0;
+bool ContactManager::m_opened = false;
+
+ContactManager::ContactManager() :
+ //create sim and device address books
+ m_deviceBook(new AddressBook(IAddressBookObject::PhoneBook)),
+ m_simBook(new AddressBook(IAddressBookObject::SIMBook))
+{
+ LogDebug("entered");
+ //set address book names
+ m_deviceBook->setName(DEVICE_ADDRESSBOOK);
+ m_simBook->setName(SIM_ADDRESSBOOK);
+ //protect for pararel execution
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ if (m_instanceCount == 0) {
+ //when it is first instance then open connection to database
+ if (contacts_svc_connect() == CTS_SUCCESS) {
+ //contacts database is opened properly
+ LogDebug("contacts database is opened properly");
+ m_opened = true;
+ } else {
+ //error during opening contacts database
+ LogError("error during opening contacts database");
+ }
+ }
+ //increase counter of instances
+ m_instanceCount++;
+}
+
+ContactManager::~ContactManager()
+{
+ LogDebug("entered");
+ //protect for pararel execution
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ //decrease counter of instances
+ m_instanceCount--;
+ if (m_instanceCount == 0) {
+ //when it is last instance then clse connection to database
+ if (contacts_svc_disconnect() != CTS_SUCCESS) {
+ //error during closing contacts database
+ LogError("error during closing contacts database");
+ }
+ m_opened = false;
+ }
+}
+
+void ContactManager::OnRequestReceived(const EventGetAddressBooksPtr &event)
+{
+ LogDebug("entered");
+ if (m_opened) {
+ //when database is opened then add addressbooks to result...
+ event->addAddressBook(m_deviceBook);
+ event->addAddressBook(m_simBook);
+ //... and set result as success
+ event->setResult(true);
+ } else {
+ //when database is not opened then set result as failed
+ event->setResult(false);
+ }
+}
+
+void ContactManager::OnRequestReceived(const Api::EventGetOwnerInfoPtr &event)
+{
+ LogDebug("entered");
+ //TODO: platform doesn't support owner information, returning empty object now.
+ event->setOwnerInfo(ContactPtr(new Contact()));
+ event->setDataFound(false);
+ //set result as success anyway to inform receiver it's not execution error
+ event->setResult(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 ContactManager.h
+ * @author Lukasz Marek(l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_MANAGER_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_MANAGER_H_
+
+#include <dpl/mutex.h>
+#include <Contact/IContactManager.h>
+#include "AddressBook.h"
+
+namespace WrtDeviceApis {
+namespace Contact {
+
+class ContactManager : public Api::IContactManager
+{
+ public:
+ ContactManager();
+ virtual ~ContactManager();
+ protected:
+ virtual void OnRequestReceived(const Api::EventGetAddressBooksPtr &event);
+ virtual void OnRequestReceived(const Api::EventGetOwnerInfoPtr &event);
+ private:
+ Api::IAddressBookObjectPtr m_deviceBook;
+ Api::IAddressBookObjectPtr m_simBook;
+
+ static int m_instanceCount;
+ static bool m_opened;
+ DPL::Mutex m_constructorMutex;
+};
+}
+}
+
+#endif /* WRTDEVICEAPIS_CONTACT_CONTACT_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.
+ */
+/**
+ * @file ContactWrapper.cpp
+ * @author Lukasz Marek(l.marek@samsung.com)
+ * @author Yujie Zeng(yj.zengk@samsung.com)
+ * @version 0.1
+ */
+
+#include <vector>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "ContactWrapper.h"
+#include "AddressBook.h"
+
+namespace {
+// Custom Type Name
+const char* CONTACT_ATTRIBUTE_PHONETIC_NAME = "phoneticName";
+}
+
+namespace WrtDeviceApis {
+namespace Contact {
+
+using namespace Api;
+
+ContactWrapper::ContactWrapper(IAddressBookObject::BookType /*type*/) :
+ m_abstractContact(NULL),
+ m_platformContact(NULL)
+{
+ LogDebug("entered");
+ //platform layer seems to not support different storage types yet
+ /*
+ if ( type == IAddressBookObject::PhoneBook ) {
+ }
+ else if ( type == IAddressBookObject::SIMBook ) {
+ }
+ else {
+ LogError("invalid storage type");
+ }
+ */
+}
+
+ContactWrapper::~ContactWrapper()
+{
+ LogDebug("entered");
+ freePlatformObject();
+}
+
+void ContactWrapper::freePlatformObject()
+{
+ if (m_platformContact) {
+ contacts_svc_struct_free(m_platformContact);
+ m_platformContact = NULL;
+ }
+}
+
+void ContactWrapper::freeAbstractObject()
+{
+ m_abstractContact = ContactPtr(NULL);
+}
+
+Api::ContactPtr ContactWrapper::getAbstractContact() const
+{
+ return m_abstractContact;
+}
+
+void ContactWrapper::setAbstractContact(const ContactPtr &contact)
+{
+ m_abstractContact = contact;
+ convertToPlatformObject();
+}
+
+CTSstruct* ContactWrapper::getPlatformContact() const
+{
+ return m_platformContact;
+}
+
+void ContactWrapper::setPlatformContact(CTSstruct* contact)
+{
+ freePlatformObject();
+ m_platformContact = contact;
+ convertToAbstractObject();
+}
+
+bool ContactWrapper::convertToPlatformObject()
+{
+ LogDebug("entered");
+ freePlatformObject();
+ if (!m_abstractContact) {
+ LogError("abstract object is not set");
+ return false;
+ }
+ //if abstrat object has id set then we have to read existing object and update it
+ if (m_abstractContact->getIdIsSet()) {
+ LogDebug("reading existing contact");
+ contacts_svc_get_contact(m_abstractContact->getId(), &m_platformContact);
+ }
+ //if no id is set then create new platform object
+ else {
+ LogDebug("creating new contact");
+ m_platformContact = contacts_svc_struct_new(CTS_STRUCT_CONTACT);
+ }
+ if (!m_platformContact) {
+ LogError("contact structure not created properly");
+ return false;
+ }
+ try
+ {
+ //store name
+ if (!convertToPlatformBaseData()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting base data");
+ }
+ //store address
+ if (!convertToPlatformAddressObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting address object");
+ }
+ //store email
+ if (!convertToPlatformEmailObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting email object");
+ }
+ //store phone
+ if (!convertToPlatformPhoneObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting phone object");
+ }
+ //nickname
+ if (!convertToPlatformNicknameObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting nickname object");
+ }
+ //phoneticName
+ if (!convertToPlatformPhoneticnameObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting Phoneticname object");
+ }
+ //group
+ if (!convertToPlatformGroupObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting group object");
+ }
+ }
+ catch (const Commons::UnknownException &ex)
+ {
+ LogError(ex.GetMessage());
+ freePlatformObject();
+ return false;
+ }
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractObject()
+{
+ LogDebug("entered");
+ freeAbstractObject();
+ if (!m_platformContact) {
+ return false;
+ }
+ CTSvalue *value = NULL;
+ //store id
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE,
+ &value)) {
+ return false;
+ }
+ m_abstractContact = ContactPtr(new Contact());
+ m_abstractContact->setId(contacts_svc_value_get_int(
+ value, CTS_BASE_VAL_ID_INT));
+ const char *charValue = contacts_svc_value_get_str(
+ value,
+ CTS_BASE_VAL_IMG_PATH_STR);
+ if (charValue) {
+ m_abstractContact->setPhotoUri(charValue);
+ }
+ charValue = contacts_svc_value_get_str(value,
+ CTS_BASE_VAL_RINGTONE_PATH_STR);
+ if (charValue) {
+ m_abstractContact->setRingTonePath(charValue);
+ }
+ try
+ {
+ //store base information
+ if (!convertToAbstractBaseData()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting base data");
+ }
+ //store address
+ if (!convertToAbstractAddressObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting address object");
+ }
+ //store email
+ if (!convertToAbstractEmailObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting email object");
+ }
+ //store phone
+ if (!convertToAbstractPhoneObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting phone object");
+ }
+ //nickname
+ if (!convertToAbstractNicknameObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting nickname object");
+ }
+ //phoneticName
+ if (!convertToAbstractPhoneticnameObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting phoneticName object");
+ }
+ //group
+ if (!convertToAbstractGroupObject()) {
+ ThrowMsg(Commons::UnknownException,
+ "error during converting group object");
+ }
+ }
+ catch (const Commons::UnknownException &ex)
+ {
+ LogError(ex.GetMessage());
+ freeAbstractObject();
+ return false;
+ }
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractBaseData()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ CTSvalue *value = NULL;
+ int errorCode;
+ const char *charValue = NULL;
+ errorCode = contacts_svc_struct_get_value(m_platformContact,
+ CTS_CF_NAME_VALUE,
+ &value);
+ if (CTS_SUCCESS == errorCode) {
+ if (value) {
+ charValue = contacts_svc_value_get_str(value,
+ CTS_NAME_VAL_FIRST_STR);
+ if (charValue) {
+ m_abstractContact->setFirstName(charValue);
+ }
+ charValue = contacts_svc_value_get_str(value, CTS_NAME_VAL_LAST_STR);
+ if (charValue) {
+ m_abstractContact->setLastName(charValue);
+ }
+ charValue = contacts_svc_value_get_str(value,
+ CTS_NAME_VAL_DISPLAY_STR);
+ if (charValue) {
+ m_abstractContact->setFullName(charValue);
+ }
+ charValue = contacts_svc_value_get_str(value,
+ CTS_NAME_VAL_PREFIX_STR);
+ if (charValue) {
+ m_abstractContact->setTitle(charValue);
+ }
+ } else {
+ return false;
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ value = NULL;
+ errorCode = contacts_svc_struct_get_value(m_platformContact,
+ CTS_CF_COMPANY_VALUE,
+ &value);
+ if (CTS_SUCCESS == errorCode) {
+ if (value) {
+ charValue = contacts_svc_value_get_str(value,
+ CTS_COMPANY_VAL_NAME_STR);
+ if (charValue) {
+ m_abstractContact->setCompany(charValue);
+ }
+ } else {
+ return false;
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractAddressObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ GSList *addressList = NULL;
+ const char *charValue = NULL;
+ std::vector<ContactAddressPtr> addresses;
+ int errorCode = contacts_svc_struct_get_list(m_platformContact,
+ CTS_CF_POSTAL_ADDR_LIST,
+ &addressList);
+ if (CTS_SUCCESS == errorCode) {
+ for (; addressList; addressList = g_slist_next(addressList)) {
+ ContactAddressPtr address(new ContactAddress());
+ addresses.push_back(address);
+ int type = contacts_svc_value_get_int(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_TYPE_INT);
+ //TODO "no enumeration for address type. Temporarly use email type"
+ switch (type) {
+ case CTS_ADDR_TYPE_NONE:
+ address->addType(ContactAddress::CONTACT_ADDRESS_TYPE_PREF);
+ break;
+ case CTS_ADDR_TYPE_HOME:
+ address->addType(ContactAddress::CONTACT_ADDRESS_TYPE_HOME);
+ break;
+ case CTS_ADDR_TYPE_WORK:
+ address->addType(ContactAddress::CONTACT_ADDRESS_TYPE_WORK);
+ break;
+ default:
+ LogError("invalid address type");
+ address->addType(ContactAddress::CONTACT_ADDRESS_TYPE_PREF);
+ break;
+ }
+ //TODO "no place to store: county, premises, additional information in platform struct"
+ #if 0
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data), );
+ if (charValue) {
+ address->setCounty(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data), );
+ if (charValue) {
+ address->setPremises(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data), );
+ if (charValue) {
+ address->setAdditionalInformation(charValue);
+ }
+ #endif
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_COUNTRY_STR);
+ if (charValue) {
+ address->setCountry(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_REGION_STR);
+ if (charValue) {
+ address->setRegion(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_LOCALITY_STR);
+ if (charValue) {
+ address->setCity(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_STREET_STR);
+ if (charValue) {
+ address->setStreet(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_POBOX_STR);
+ if (charValue) {
+ address->setStreetNumber(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_POSTALCODE_STR);
+ if (charValue) {
+ address->setPostalCode(charValue);
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(addressList->data),
+ CTS_POSTAL_VAL_EXTENDED_STR);
+ if (charValue) {
+ address->setAddress(charValue);
+ }
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ m_abstractContact->setAddresses(addresses);
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractEmailObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ GSList *emailList = NULL;
+ const char *charValue = NULL;
+ std::vector<ContactEmailPtr> emails;
+ int errorCode = contacts_svc_struct_get_list(m_platformContact,
+ CTS_CF_EMAIL_LIST,
+ &emailList);
+ if (CTS_SUCCESS == errorCode) {
+ for (; emailList; emailList = g_slist_next(emailList)) {
+ ContactEmailPtr email(new ContactEmail());
+ emails.push_back(email);
+ int type = contacts_svc_value_get_int(
+ static_cast<CTSvalue*>(emailList->data),
+ CTS_EMAIL_VAL_TYPE_INT);
+ switch (type) {
+ case CTS_EMAIL_TYPE_NONE:
+ email->addType(ContactEmail::CONTACT_EMAIL_TYPE_PREF);
+ break;
+ case CTS_EMAIL_TYPE_HOME:
+ email->addType(ContactEmail::CONTACT_EMAIL_TYPE_HOME);
+ break;
+ case CTS_EMAIL_TYPE_WORK:
+ email->addType(ContactEmail::CONTACT_EMAIL_TYPE_WORK);
+ break;
+ default:
+ LogError("invalid phone type");
+ email->addType(ContactEmail::CONTACT_EMAIL_TYPE_PREF);
+ break;
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(emailList->data),
+ CTS_EMAIL_VAL_ADDR_STR);
+ if (charValue) {
+ email->setEmail(charValue);
+ }
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ m_abstractContact->setEmails(emails);
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractPhoneObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ GSList *phoneList = NULL;
+ const char *charValue = NULL;
+ std::vector<ContactPhoneNumberPtr> phoneNumbers;
+ int errorCode = contacts_svc_struct_get_list(m_platformContact,
+ CTS_CF_NUMBER_LIST,
+ &phoneList);
+ if (CTS_SUCCESS == errorCode) {
+ for (; phoneList; phoneList = g_slist_next(phoneList)) {
+ ContactPhoneNumberPtr phoneNumber(new ContactPhoneNumber());
+ phoneNumbers.push_back(phoneNumber);
+ int type = contacts_svc_value_get_int(
+ static_cast<CTSvalue*>(phoneList->data),
+ CTS_NUM_VAL_TYPE_INT);
+ switch (type) {
+ case CTS_NUM_TYPE_WORK:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_WORK);
+ break;
+ case CTS_NUM_TYPE_NONE:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_PREF);
+ break;
+ case CTS_NUM_TYPE_HOME:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_HOME);
+ break;
+ case CTS_NUM_TYPE_FAX:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_FAX);
+ break;
+ case CTS_NUM_TYPE_CELL:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_CELL);
+ break;
+ case CTS_NUM_TYPE_PAGER:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_PAGER);
+ break;
+ case CTS_NUM_TYPE_CAR:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_CAR);
+ break;
+ case CTS_NUM_TYPE_VOICE:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_VOICE);
+ break;
+ case CTS_NUM_TYPE_MSG:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_MSG);
+ break;
+ case CTS_NUM_TYPE_BBS:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_BBS);
+ break;
+ case CTS_NUM_TYPE_MODEM:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_MODEM);
+ break;
+ case CTS_NUM_TYPE_ISDN:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_ISDN);
+ break;
+ case CTS_NUM_TYPE_VIDEO:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_VIDEO);
+ break;
+ case CTS_NUM_TYPE_PCS:
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_PCS);
+ break;
+ default:
+ LogError("invalid phone type");
+ phoneNumber->addType(
+ ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_PREF);
+ break;
+ }
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(phoneList->data),
+ CTS_NUM_VAL_NUMBER_STR);
+ if (charValue) {
+ phoneNumber->setNumber(charValue);
+ }
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ m_abstractContact->setPhoneNumbers(phoneNumbers);
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractNicknameObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ GSList *nicknNameList = NULL;
+ const char *charValue = NULL;
+ std::vector<std::string> nickNames;
+ int errorCode = contacts_svc_struct_get_list(m_platformContact,
+ CTS_CF_NICKNAME_LIST,
+ &nicknNameList);
+ if (CTS_SUCCESS == errorCode) {
+ for (; nicknNameList; nicknNameList = g_slist_next(nicknNameList)) {
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(nicknNameList->data),
+ CTS_NICKNAME_VAL_NAME_STR);
+ if (charValue) {
+ nickNames.push_back(charValue);
+ }
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ m_abstractContact->setNickNames(nickNames);
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractPhoneticnameObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ CTSvalue *value = NULL;
+ int errorCode;
+ int structFieldType = 0;
+ const char *charValue = NULL;
+
+ structFieldType = getCustomTypeInContactsSvc(
+ CONTACT_ATTRIBUTE_PHONETIC_NAME);
+ if (structFieldType < CTS_SUCCESS) {
+ LogError("Phonetic name struct type is not found!!");
+ return false;
+ }
+
+ errorCode =
+ contacts_svc_struct_get_value(m_platformContact,
+ static_cast<cts_struct_field>(
+ structFieldType), &value);
+ if (CTS_SUCCESS == errorCode) {
+ if (value) {
+ charValue = contacts_svc_value_get_str(value,
+ CTS_EXTEND_VAL_DATA2_STR);
+ if (charValue) {
+ m_abstractContact->setPhoneticName(charValue);
+ }
+ } else {
+ return false;
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ return true;
+}
+
+bool ContactWrapper::convertToAbstractGroupObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ GSList *groupList = NULL;
+ const char *charValue = NULL;
+ std::vector<std::string> groups;
+ int errorCode = contacts_svc_struct_get_list(m_platformContact,
+ CTS_CF_GROUPREL_LIST,
+ &groupList);
+ if (CTS_SUCCESS == errorCode) {
+ for (; groupList; groupList = g_slist_next(groupList)) {
+ charValue = contacts_svc_value_get_str(
+ static_cast<CTSvalue*>(groupList->data),
+ CTS_GROUPREL_VAL_NAME_STR);
+ if (charValue) {
+ groups.push_back(charValue);
+ }
+ }
+ } else if (CTS_ERR_NO_DATA != errorCode) {
+ return false;
+ }
+ m_abstractContact->setGroups(groups);
+ return true;
+}
+
+bool ContactWrapper::convertToPlatformNicknameObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ const std::vector<std::string> &nicknames =
+ m_abstractContact->getNickNames();
+
+ if (nicknames.size() == 0) {
+ return true;
+ }
+
+ CTSvalue *nickname = NULL;
+ bool properlyCreated = true;
+ GSList *nicknameList = NULL;
+ //mark existing items to delete them.
+
+ if (CTS_SUCCESS ==
+ contacts_svc_struct_get_list(m_platformContact, CTS_CF_NICKNAME_LIST,
+ &nicknameList)) {
+ GSList *nicknameListSave = nicknameList;
+ for (; nicknameList; nicknameList = g_slist_next(nicknameList)) {
+ CTSvalue* nickname = static_cast<CTSvalue*>(nicknameList->data);
+ contacts_svc_value_set_bool(nickname,
+ CTS_NICKNAME_VAL_DELETE_BOOL,
+ true);
+ }
+ nicknameList = nicknameListSave;
+ }
+ //add new items
+ for (std::size_t i = 0; i < nicknames.size(); ++i) {
+ nickname = contacts_svc_value_new(CTS_VALUE_NICKNAME);
+ if (nickname) {
+ if (CTS_SUCCESS ==
+ contacts_svc_value_set_str(nickname, CTS_NICKNAME_VAL_NAME_STR,
+ nicknames[i].c_str())) {
+ nicknameList = g_slist_append(nicknameList, nickname);
+ } else {
+ contacts_svc_value_free(nickname);
+ properlyCreated = false;
+ break;
+ }
+ } else {
+ properlyCreated = false;
+ break;
+ }
+ }
+
+ if (properlyCreated) {
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_store_list(m_platformContact,
+ CTS_CF_NICKNAME_LIST,
+ nicknameList)) {
+ properlyCreated = false;
+ }
+ }
+
+ return properlyCreated;
+}
+
+bool ContactWrapper::convertToPlatformPhoneticnameObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ CTSvalue *value = NULL;
+ int structFieldType = 0;
+
+ structFieldType = getCustomTypeInContactsSvc(
+ CONTACT_ATTRIBUTE_PHONETIC_NAME);
+ if (structFieldType < CTS_SUCCESS) {
+ LogError("Phonetic name struct type is not found!!");
+ return false;
+ }
+
+ /**
+ *If phonetic name information is not existed, add phonetic name information
+ *If phonetic name information is existed,update phonetic name information
+ */
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_get_value(m_platformContact,
+ static_cast<cts_struct_field>(
+ structFieldType), &value)) {
+ value = contacts_svc_value_new(CTS_VALUE_EXTEND);
+ if (!value) {
+ return false;
+ }
+ }
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_EXTEND_VAL_DATA2_STR,
+ m_abstractContact->getPhoneticName().c_str())
+ ||
+ CTS_SUCCESS !=
+ contacts_svc_struct_store_value(m_platformContact,
+ static_cast<cts_struct_field>(
+ structFieldType), value)) {
+ contacts_svc_value_free(value);
+ return false;
+ }
+ contacts_svc_value_free(value);
+
+ LogDebug("RETURN TRUE!!!");
+ return true;
+}
+
+bool ContactWrapper::convertToPlatformGroupObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ const std::vector<std::string> &groups =
+ m_abstractContact->getGroups();
+ if (groups.size() == 0) {
+ return true;
+ }
+ CTSvalue *group = NULL;
+ bool properlyCreated = true;
+ GSList *groupList = NULL;
+ //mark existing items to delete them.
+ if (CTS_SUCCESS ==
+ contacts_svc_struct_get_list(m_platformContact, CTS_CF_GROUPREL_LIST,
+ &groupList)) {
+ GSList *groupListSave = groupList;
+ for (; groupList; groupList = g_slist_next(groupList)) {
+ LogDebug("clearing group list");
+ CTSvalue* delgroup = static_cast<CTSvalue*>(groupList->data);
+ contacts_svc_value_set_bool(delgroup,
+ CTS_GROUPREL_VAL_DELETE_BOOL,
+ true);
+ }
+ groupList = groupListSave;
+ }
+ //add new items
+ for (std::size_t i = 0; i < groups.size(); ++i) {
+ group = contacts_svc_value_new(CTS_VALUE_GROUP_RELATION);
+ if (group) {
+ int groupId = -1;
+ //groupId = AddressBook::getGroupId(groups[i]);
+
+ CTSiter *iter = NULL;
+ if (CTS_SUCCESS ==
+ contacts_svc_get_list(CTS_LIST_ALL_GROUP, &iter)) {
+ while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue *findgroup = contacts_svc_iter_get_info(iter);
+ if (findgroup) {
+ const char *foundGroupName = contacts_svc_value_get_str(
+ findgroup,
+ CTS_LIST_GROUP_NAME_STR);
+ if (foundGroupName && groups[i] == foundGroupName) {
+ groupId = contacts_svc_value_get_int(
+ findgroup,
+ CTS_LIST_GROUP_ID_INT);
+ }
+ }
+ }
+ contacts_svc_iter_remove(iter);
+ }
+ LogDebug("group id " << groupId);
+ if (groupId != -1) {
+ if (CTS_SUCCESS ==
+ contacts_svc_value_set_int(group, CTS_GROUPREL_VAL_ID_INT,
+ groupId)) {
+ groupList = g_slist_append(groupList, group);
+ } else {
+ contacts_svc_value_free(group);
+ properlyCreated = false;
+ break;
+ }
+ } else {
+ contacts_svc_value_free(group);
+ properlyCreated = false;
+ break;
+ }
+ } else {
+ properlyCreated = false;
+ break;
+ }
+ }
+ if (properlyCreated) {
+ LogDebug("storing group list");
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_store_list(m_platformContact,
+ CTS_CF_GROUPREL_LIST,
+ groupList)) {
+ properlyCreated = false;
+ }
+ }
+ for (; groupList; groupList = g_slist_next(groupList)) {
+ contacts_svc_value_free(static_cast<CTSvalue*>(groupList->data));
+ }
+ g_slist_free(groupList);
+ return properlyCreated;
+}
+
+bool ContactWrapper::convertToPlatformPhoneObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ int type;
+ const std::vector<ContactPhoneNumberPtr> &phoneNumbers =
+ m_abstractContact->getPhoneNumbers();
+ if (phoneNumbers.size() == 0) {
+ return true;
+ }
+ bool properlyCreated = true;
+ CTSvalue *number = NULL;
+ GSList *numberList = NULL;
+ //mark existing items to delete them.
+ if (CTS_SUCCESS ==
+ contacts_svc_struct_get_list(m_platformContact, CTS_CF_NUMBER_LIST,
+ &numberList)) {
+ GSList *numberListSave = numberList;
+ for (; numberList; numberList = g_slist_next(numberList)) {
+ LogDebug("clearing phone list");
+ CTSvalue* number = static_cast<CTSvalue*>(numberList->data);
+ contacts_svc_value_set_bool(number, CTS_NUM_VAL_DELETE_BOOL, true);
+ }
+ numberList = numberListSave;
+ }
+ //add new items
+ for (std::size_t i = 0; i < phoneNumbers.size(); ++i) {
+ std::vector<ContactPhoneNumber::ContactPhoneNumberType> types =
+ phoneNumbers[i]->getTypes();
+ for (std::size_t j = 0; j < types.size(); ++j)
+ {
+ number = contacts_svc_value_new(CTS_VALUE_NUMBER);
+ if (number) {
+ if(types.size() > 0)
+ {
+ switch (types[j]) {
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_WORK:
+ type = CTS_NUM_TYPE_WORK;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_PREF:
+ type = CTS_NUM_TYPE_NONE;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_HOME:
+ type = CTS_NUM_TYPE_HOME;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_FAX:
+ type = CTS_NUM_TYPE_FAX;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_CELL:
+ type = CTS_NUM_TYPE_CELL;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_PAGER:
+ type = CTS_NUM_TYPE_PAGER;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_CAR:
+ type = CTS_NUM_TYPE_CAR;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_BBS:
+ type = CTS_NUM_TYPE_BBS;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_MODEM:
+ type = CTS_NUM_TYPE_MODEM;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_ISDN:
+ type = CTS_NUM_TYPE_ISDN;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_VIDEO:
+ type = CTS_NUM_TYPE_VIDEO;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_PCS:
+ type = CTS_NUM_TYPE_PCS;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_VOICE:
+ type = CTS_NUM_TYPE_VOICE;
+ break;
+ case ContactPhoneNumber::CONTACT_PHONE_NUMBER_TYPE_MSG:
+ type = CTS_NUM_TYPE_MSG;
+ break;
+ default:
+ LogError("invalid phone type");
+ type = CTS_NUM_TYPE_NONE;
+ break;
+ }
+ }
+ else
+ {
+ type = CTS_NUM_TYPE_NONE;
+ }
+ if (CTS_SUCCESS ==
+ contacts_svc_value_set_str(number, CTS_NUM_VAL_NUMBER_STR,
+ phoneNumbers[i]->getNumber().
+ c_str()) &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_bool(number,
+ CTS_NUM_VAL_DEFAULT_BOOL,
+ type == CTS_NUM_TYPE_NONE) &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_int(number, CTS_NUM_VAL_TYPE_INT,
+ type)) {
+ numberList = g_slist_append(numberList, number);
+ } else {
+ contacts_svc_value_free(number);
+ properlyCreated = false;
+ break;
+ }
+ } else {
+ properlyCreated = false;
+ break;
+ }
+ }
+ if (!properlyCreated) {
+ break;
+ }
+ }
+ if (properlyCreated) {
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_store_list(m_platformContact,
+ CTS_CF_NUMBER_LIST,
+ numberList)) {
+ properlyCreated = false;
+ }
+ }
+ for (; numberList; numberList = g_slist_next(numberList)) {
+ contacts_svc_value_free(static_cast<CTSvalue*>(numberList->data));
+ }
+ g_slist_free(numberList);
+ return properlyCreated;
+}
+
+bool ContactWrapper::convertToPlatformEmailObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ int type;
+ const std::vector<ContactEmailPtr> &emails =
+ m_abstractContact->getEmails();
+ if (emails.size() == 0) {
+ return true;
+ }
+ CTSvalue *email = NULL;
+ bool properlyCreated = true;
+ GSList *emailList = NULL;
+ //mark existing items to delete them.
+ if (CTS_SUCCESS ==
+ contacts_svc_struct_get_list(m_platformContact, CTS_CF_EMAIL_LIST,
+ &emailList)) {
+ GSList *emailListSave = emailList;
+ for (; emailList; emailList = g_slist_next(emailList)) {
+ LogDebug("clearing email list");
+ CTSvalue* email = static_cast<CTSvalue*>(emailList->data);
+ contacts_svc_value_set_bool(email, CTS_EMAIL_VAL_DELETE_BOOL, true);
+ }
+ emailList = emailListSave;
+ }
+ //add new items
+ for (std::size_t i = 0; i < emails.size(); ++i) {
+ std::vector<ContactEmail::ContactEmailType> types =
+ emails[i]->getTypes();
+ for (std::size_t j = 0; j < types.size(); ++j)
+ {
+ email = contacts_svc_value_new(CTS_VALUE_EMAIL);
+ if(email)
+ {
+ if(types.size() > 0)
+ {
+ switch (types[j]) {
+ case ContactEmail::CONTACT_EMAIL_TYPE_HOME:
+ type = CTS_EMAIL_TYPE_HOME;
+ break;
+ case ContactEmail::CONTACT_EMAIL_TYPE_WORK:
+ type = CTS_EMAIL_TYPE_WORK;
+ break;
+ case ContactEmail::CONTACT_EMAIL_TYPE_PREF:
+ type = CTS_EMAIL_TYPE_NONE;
+ break;
+ default:
+ LogError("invalid phone type");
+ type = CTS_EMAIL_TYPE_NONE;
+ break;
+ }
+ }
+ else
+ {
+ type = CTS_EMAIL_TYPE_NONE;
+ }
+ if (CTS_SUCCESS ==
+ contacts_svc_value_set_int(email, CTS_EMAIL_VAL_TYPE_INT,
+ type) &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(email, CTS_EMAIL_VAL_ADDR_STR,
+ emails[i]->getEmail().c_str()))
+ {
+ emailList = g_slist_append(emailList, email);
+ } else {
+ contacts_svc_value_free(email);
+ properlyCreated = false;
+ break;
+ }
+ }
+ else
+ {
+ properlyCreated = false;
+ break;
+ }
+ }
+
+ if (!properlyCreated) {
+ break;
+ }
+ }
+ if (properlyCreated) {
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_store_list(m_platformContact, CTS_CF_EMAIL_LIST,
+ emailList)) {
+ properlyCreated = false;
+ }
+ }
+ for (; emailList; emailList = g_slist_next(emailList)) {
+ contacts_svc_value_free(static_cast<CTSvalue*>(emailList->data));
+ }
+ g_slist_free(emailList);
+ return properlyCreated;
+}
+
+bool ContactWrapper::convertToPlatformAddressObject()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ int type;
+ const std::vector<ContactAddressPtr> &addresses =
+ m_abstractContact->getAddresses();
+ if (addresses.size() == 0) {
+ return true;
+ }
+ CTSvalue *address = NULL;
+ bool properlyCreated = true;
+ GSList *addressList = NULL;
+ //mark existing items to delete them.
+ if (CTS_SUCCESS ==
+ contacts_svc_struct_get_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST,
+ &addressList)) {
+ GSList *addressListSave = addressList;
+ for (; addressList; addressList = g_slist_next(addressList)) {
+ LogDebug("clearing address list");
+ CTSvalue* address = static_cast<CTSvalue*>(addressList->data);
+ contacts_svc_value_set_bool(address,
+ CTS_POSTAL_VAL_DELETE_BOOL,
+ true);
+ }
+ addressList = addressListSave;
+ }
+ //add new items
+ for (std::size_t i = 0; i < addresses.size(); ++i) {
+ std::vector<ContactAddress::ContactAddressType> types =
+ addresses[i]->getTypes();
+ for (std::size_t j = 0; j < types.size(); ++j) {
+ address = contacts_svc_value_new(CTS_VALUE_POSTAL);
+ if (address) {
+ //TODO "no place to store: county, premises, additional information in platform struct"
+ switch (types[j]) {
+ case ContactAddress::CONTACT_ADDRESS_TYPE_PREF:
+ type = CTS_ADDR_TYPE_NONE;
+ break;
+ case ContactAddress::CONTACT_ADDRESS_TYPE_WORK:
+ type = CTS_ADDR_TYPE_WORK;
+ break;
+ case ContactAddress::CONTACT_ADDRESS_TYPE_HOME:
+ type = CTS_ADDR_TYPE_HOME;
+ break;
+ default:
+ LogError("invalid address type");
+ type = CTS_EMAIL_TYPE_NONE;
+ break;
+ }
+ //CTS_SUCCESS == contacts_svc_value_set_str(address, , addresses[i]->getCounty().c_str()) &&
+ //CTS_SUCCESS == contacts_svc_value_set_str(address, , addresses[i]->getPremises().c_str()) &&
+ //CTS_SUCCESS == contacts_svc_value_set_str(address, , addresses[i]->getAdditionalInformation().c_str()) &&
+ if (CTS_SUCCESS ==
+ contacts_svc_value_set_int(address, CTS_POSTAL_VAL_TYPE_INT,
+ type) &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(address,
+ CTS_POSTAL_VAL_COUNTRY_STR,
+ addresses[i]->getCountry().c_str())
+ &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(address,
+ CTS_POSTAL_VAL_REGION_STR,
+ addresses[i]->getRegion().c_str())
+ &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(address,
+ CTS_POSTAL_VAL_LOCALITY_STR,
+ addresses[i]->getCity().c_str())
+ &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(address,
+ CTS_POSTAL_VAL_STREET_STR,
+ addresses[i]->getStreet().c_str())
+ &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(address,
+ CTS_POSTAL_VAL_POBOX_STR,
+ addresses[i]->getStreetNumber().
+ c_str()) &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(address,
+ CTS_POSTAL_VAL_POSTALCODE_STR,
+ addresses[i]->getPostalCode().
+ c_str()) &&
+ CTS_SUCCESS ==
+ contacts_svc_value_set_str(address,
+ CTS_POSTAL_VAL_EXTENDED_STR,
+ addresses[i]->
+ getAdditionalInformation().
+ c_str())) {
+ addressList = g_slist_append(addressList, address);
+ } else {
+ contacts_svc_value_free(address);
+ properlyCreated = false;
+ break;
+ }
+ } else {
+ properlyCreated = false;
+ break;
+ }
+ }
+ if (!properlyCreated) {
+ break;
+ }
+ }
+ if (properlyCreated) {
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_store_list(m_platformContact,
+ CTS_CF_POSTAL_ADDR_LIST,
+ addressList)) {
+ properlyCreated = false;
+ }
+ }
+ for (; addressList; addressList = g_slist_next(addressList)) {
+ contacts_svc_value_free(static_cast<CTSvalue*>(addressList->data));
+ }
+ g_slist_free(addressList);
+ return properlyCreated;
+}
+
+bool ContactWrapper::convertToPlatformBaseData()
+{
+ LogDebug("entered");
+ if (NULL == m_abstractContact) {
+ LogError("you should create empty abstract contact object first");
+ return false;
+ }
+
+ if (NULL == m_platformContact) {
+ LogError("you should provide platform contact object first");
+ return false;
+ }
+
+ /**
+ *If name information is not existed, add name information
+ * If name information is existed,update name information
+ */
+ CTSvalue *value = NULL;
+
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_get_value(m_platformContact, CTS_CF_NAME_VALUE,
+ &value)) {
+ CTSvalue *value = contacts_svc_value_new(CTS_VALUE_NAME);
+ if (value) {
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_FIRST_STR,
+ m_abstractContact->getFirstName().
+ c_str()) ||
+ CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_LAST_STR,
+ m_abstractContact->getLastName().
+ c_str()) ||
+ CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_DISPLAY_STR,
+ m_abstractContact->getFullName().
+ c_str()) ||
+ CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_PREFIX_STR,
+ m_abstractContact->getTitle().c_str())
+ ||
+ CTS_SUCCESS !=
+ contacts_svc_struct_store_value(m_platformContact,
+ CTS_CF_NAME_VALUE, value)) {
+ contacts_svc_value_free(value);
+ return false;
+ }
+ contacts_svc_value_free(value);
+ } else {
+ return false;
+ }
+ } else {
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_FIRST_STR,
+ m_abstractContact->getFirstName().c_str())
+ ||
+ CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_LAST_STR,
+ m_abstractContact->getLastName().c_str())
+ ||
+ CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_DISPLAY_STR,
+ m_abstractContact->getFullName().c_str())
+ ||
+ CTS_SUCCESS !=
+ contacts_svc_value_set_str(value, CTS_NAME_VAL_PREFIX_STR,
+ m_abstractContact->getTitle().c_str()))
+ {
+ contacts_svc_value_free(value);
+ return false;
+ }
+ contacts_svc_value_free(value);
+ }
+
+ /**
+ *If photo and ringtone uri information is not existed, add the information
+ * If photo and ringtone uri is existed,update the information
+ */
+ CTSvalue *baseinfo = NULL;
+ if (CTS_SUCCESS !=
+ contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE,
+ &baseinfo)) {
+ baseinfo = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO);
+ if (baseinfo) {
+ if (m_abstractContact->getPhotoIsSet()) {
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(baseinfo,
+ CTS_BASE_VAL_IMG_PATH_STR,
+ m_abstractContact->getPhotoUri()
+ .c_str())) {
+ contacts_svc_value_free(baseinfo);
+ return false;
+ }
+ }
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(baseinfo,
+ CTS_BASE_VAL_RINGTONE_PATH_STR,
+ m_abstractContact->getRingTonePath()
+ .c_str()) ||
+ CTS_SUCCESS !=
+ contacts_svc_struct_store_value(m_platformContact,
+ CTS_CF_BASE_INFO_VALUE,
+ baseinfo)) {
+ contacts_svc_value_free(baseinfo);
+ return false;
+ }
+
+ contacts_svc_value_free(baseinfo);
+ } else {
+ return false;
+ }
+ } else {
+ const char * oldimgpath = NULL;
+ oldimgpath = contacts_svc_value_get_str(baseinfo,
+ CTS_BASE_VAL_IMG_PATH_STR);
+
+ std::string stroldimgpath = "";
+ if (NULL != oldimgpath) {
+ stroldimgpath = static_cast<std::string>(oldimgpath);
+ }
+
+ std::string strnewimgpath = m_abstractContact->getPhotoUri();
+ if (stroldimgpath != strnewimgpath) {
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_IMG_PATH_STR,
+ strnewimgpath.c_str())) {
+ contacts_svc_value_free(value);
+ return false;
+ }
+ }
+
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_RINGTONE_PATH_STR,
+ m_abstractContact->getRingTonePath().
+ c_str())) {
+ return false;
+ }
+ contacts_svc_value_free(value);
+ }
+
+ //save company information
+ CTSvalue *company = NULL;
+ company = contacts_svc_value_new(CTS_VALUE_COMPANY);
+ if (company) {
+ if (CTS_SUCCESS !=
+ contacts_svc_value_set_str(company, CTS_COMPANY_VAL_NAME_STR,
+ m_abstractContact->getCompany().c_str())
+ ||
+ CTS_SUCCESS !=
+ contacts_svc_struct_store_value(m_platformContact,
+ CTS_CF_COMPANY_VALUE,
+ company)) {
+ contacts_svc_value_free(company);
+ return false;
+ }
+ contacts_svc_value_free(value);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+int ContactWrapper::getCustomTypeInContactsSvc(const std::string &typeName)
+const
+{
+ int structFieldType = -1;
+
+ LogDebug("typeName : " << typeName);
+ structFieldType = contacts_svc_find_custom_type(CTS_TYPE_CLASS_EXTEND_DATA,
+ const_cast<char*>(typeName.
+ c_str()));
+ if (CTS_ERR_DB_RECORD_NOT_FOUND == structFieldType) {
+ LogDebug("CTS_ERR_DB_RECORD_NOT_FOUND!!");
+ structFieldType = contacts_svc_insert_custom_type(
+ CTS_TYPE_CLASS_EXTEND_DATA,
+ const_cast<char*>(typeName.c_str()));
+ if (CTS_SUCCESS > structFieldType) {
+ LogDebug("Create fail");
+ }
+ } else if (CTS_SUCCESS > structFieldType) {
+ LogDebug("contacts_svc_find_custom_type is fail");
+ }
+
+ LogDebug("structFieldType : " << structFieldType);
+ return structFieldType;
+}
+
+void ContactWrapper::printPlatformObject()
+{
+ LogDebug("entered");
+}
+
+void ContactWrapper::printAbstractObject()
+{
+ LogDebug("entered");
+}
+}
+}
--- /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 ContactManager.h
+ * @author Lukasz Marek(l.marek@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_CONTACT_CONTACT_WRAPPER_H_
+#define WRTDEVICEAPIS_CONTACT_CONTACT_WRAPPER_H_
+
+#include <string>
+#include <list>
+#include <contacts-svc.h>
+#include <Contact/Contact.h>
+#include <Contact/IAddressBook.h>
+
+namespace WrtDeviceApis {
+namespace Contact {
+
+class ContactWrapper
+{
+ public:
+ explicit ContactWrapper(Api::IAddressBookObject::BookType type);
+ virtual ~ContactWrapper();
+ Api::ContactPtr getAbstractContact() const;
+ void setAbstractContact(const Api::ContactPtr &contact);
+ CTSstruct* getPlatformContact() const;
+ //WARNING: calling this function will cause to store pointer inside private field
+ //Structure will be freed by this class when is not needed anymore.
+ //User should not modify nor free passed pointer.
+ void setPlatformContact(CTSstruct* contact);
+
+ protected:
+ bool convertToPlatformObject();
+ bool convertToAbstractObject();
+
+ Api::ContactPtr m_abstractContact;
+ CTSstruct* m_platformContact;
+
+ private:
+ void freePlatformObject();
+ void freeAbstractObject();
+ bool convertToPlatformBaseData();
+ bool convertToPlatformAddressObject();
+ bool convertToPlatformEmailObject();
+ bool convertToPlatformPhoneObject();
+ bool convertToPlatformNicknameObject();
+ bool convertToPlatformPhoneticnameObject();
+ bool convertToPlatformGroupObject();
+ bool convertToAbstractBaseData();
+ bool convertToAbstractAddressObject();
+ bool convertToAbstractEmailObject();
+ bool convertToAbstractPhoneObject();
+ bool convertToAbstractNicknameObject();
+ bool convertToAbstractPhoneticnameObject();
+ bool convertToAbstractGroupObject();
+ int getCustomTypeInContactsSvc(const std::string &typeName) const;
+ //for debug purpose only
+ void printPlatformObject();
+ //for debug purpose only
+ void printAbstractObject();
+};
+
+typedef DPL::SharedPtr<ContactWrapper> ContactWrapperPtr;
+
+}
+}
+
+#endif // WRTDEVICEAPIS_CONTACT_CONTACT_WRAPPER_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(contacts-service REQUIRED contacts-service)
+pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+pkg_search_module(libdownload-agent REQUIRED libdownload-agent)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CONTACT
+ ${contacts-service_INCLUDE_DIRS}
+ ${pcrecpp_INCLUDE_DIRS}
+ ${libdownload-agent_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CONTACT
+ ${contacts-service_LIBRARIES}
+ ${pcrecpp_LIBRARIES}
+ ${libdownload-agent_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CONTACT
+ ${CURRENT_PATH}/ContactManager.cpp
+ ${CURRENT_PATH}/AddressBook.cpp
+ ${CURRENT_PATH}/ContactWrapper.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 "Manager.h"
+#include <Commons/Exception.h>
+
+namespace {
+const std::size_t NUMBER_OF_AVAILABLE_CPUS = 1;
+}
+
+namespace WrtDeviceApis {
+namespace Cpu {
+
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Api::IUnit* Manager::getUnit(std::size_t index) const
+{
+ if (index > NUMBER_OF_AVAILABLE_CPUS) {
+ Throw(Commons::OutOfRangeException);
+ }
+
+ Units::const_iterator it = m_units.find(index);
+ if (it != m_units.end()) {
+ return it->second;
+ }
+ return (m_units[index] = new Unit(index));
+}
+
+std::size_t Manager::getUnitsCount() const
+{
+ return NUMBER_OF_AVAILABLE_CPUS;
+}
+
+Manager::Manager()
+{
+}
+
+} // Cpu
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_CPU_MANAGER_H_
+#define WRTDEVICEAPIS_CPU_MANAGER_H_
+
+#include <cstddef>
+#include <map>
+#include <Cpu/IManager.h>
+#include "Unit.h"
+
+namespace WrtDeviceApis {
+namespace Cpu {
+
+class Manager : public Api::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ Api::IUnit* getUnit(std::size_t index) const;
+ std::size_t getUnitsCount() const;
+
+ private:
+ typedef std::map<std::size_t, Api::IUnit*> Units;
+
+ private:
+ Manager();
+
+ private:
+ mutable Units m_units;
+};
+
+} // Cpu
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CPU_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 <unistd.h>
+#include <stdio.h>
+#include <fstream>
+#include <sstream>
+#include <pcrecpp.h>
+#include <Commons/Exception.h>
+#include "Unit.h"
+
+namespace {
+const unsigned int GET_STATS_TIMEOUT = 1; // in seconds
+const char* STAT_FILE = "/proc/stat";
+const char* CPU_PATTERN_PREFIX = "^cpu";
+const char* CPU_PATTERN_POSTFIX = "\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)";
+}
+
+namespace WrtDeviceApis {
+namespace Cpu {
+
+Unit::Unit(std::size_t index) : m_index(index)
+{
+ std::ostringstream oss(CPU_PATTERN_PREFIX);
+ if (m_index > 0) {
+ oss << m_index - 1;
+ }
+ oss << CPU_PATTERN_POSTFIX;
+ m_utilizationPattern = oss.str();
+}
+
+unsigned int Unit::getUtilizationPercent() const
+{
+ UtilizationStats usage0 = getUtilization();
+ sleep(GET_STATS_TIMEOUT);
+ UtilizationStats usage1 = getUtilization();
+
+ unsigned sum0 = usage0.m_user + usage0.m_nice + usage0.m_system +
+ usage0.m_idle;
+ unsigned sum1 = usage1.m_user + usage1.m_nice + usage1.m_system +
+ usage1.m_idle;
+
+ unsigned percent =
+ (100 -
+ ((usage1.m_idle -
+ usage0.m_idle) / (double) (sum1 - sum0)) * 100);
+
+ return percent;
+}
+
+Unit::UtilizationStats Unit::getUtilization() const
+{
+ std::ifstream file(STAT_FILE);
+ if (!file) {
+ ThrowMsg(Commons::UnsupportedException,
+ "Could not open statistics file.");
+ }
+
+ UtilizationStats result;
+ memset(&result, 0, sizeof(UtilizationStats));
+ bool matched = false;
+ std::string line;
+ while (!file.eof() && !!std::getline(file, line)) {
+ if (pcrecpp::RE(m_utilizationPattern.c_str()).FullMatch(
+ line,
+ &result.m_user,
+ &result.m_nice,
+ &result.m_system,
+ &result.m_idle))
+ {
+ matched = true;
+ break;
+ }
+ }
+ file.close();
+
+ if (!matched) {
+ ThrowMsg(Commons::UnsupportedException, "Total memory data not found.");
+ }
+
+ return result;
+}
+
+} // Cpu
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_CPU_UNIT_H_
+#define WRTDEVICEAPIS_CPU_UNIT_H_
+
+#include <string>
+#include <Cpu/IUnit.h>
+
+namespace WrtDeviceApis {
+namespace Cpu {
+
+class Manager;
+
+class Unit : public Api::IUnit
+{
+ friend class Manager;
+
+ public:
+ unsigned int getUtilizationPercent() const;
+
+ private:
+ /**
+ * Stores processor utilization statistics.
+ */
+ struct UtilizationStats
+ {
+ unsigned int m_user;
+ unsigned int m_nice;
+ unsigned int m_system;
+ unsigned int m_idle;
+ };
+
+ private:
+ explicit Unit(std::size_t index);
+
+ /**
+ * Gets processor utilization statistics.
+ * @return Processor utilization statistics.
+ * @throw UnsupportedException If data could not be retrieved.
+ */
+ UtilizationStats getUtilization() const;
+
+ private:
+ std::size_t m_index; ///< Index of CPU interface to represent.
+
+ /**
+ * Regex pattern used to get processor utilization statistics from
+ * stat file.
+ */
+ std::string m_utilizationPattern;
+};
+
+} // Cpu
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_CPU_UNIT_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CPU
+ ${pcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CPU
+ ${pcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CPU
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/Unit.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 "Connection.h"
+#include <cassert>
+#include <algorithm>
+#include <Commons/Exception.h>
+#include <dpl/log/log.h>
+#include "Message.h"
+
+namespace WrtDeviceApis {
+namespace DBus {
+Connection::Connection() :
+ m_connection(NULL),
+ m_messageDispatcher(NULL),
+ m_connected(false)
+{
+ dbus_error_init(&m_error);
+ m_messageDispatcher = new MessageDispatcher(this);
+}
+
+Connection::~Connection()
+{
+ assert(!m_connected && "DBus connection has not been closed.");
+ delete m_messageDispatcher;
+ if (dbus_error_is_set(&m_error)) {
+ dbus_error_free(&m_error);
+ }
+}
+
+void Connection::open(DBusBusType bus)
+{
+ if (m_connected) { return; }
+
+ m_connection = dbus_bus_get(bus, &m_error);
+ if (!m_connection || dbus_error_is_set(&m_error)) {
+ std::string message = m_error.message;
+ dbus_error_free(&m_error);
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't attach to DBus system bus: " << message);
+ }
+
+ dbus_connection_set_exit_on_disconnect(m_connection, FALSE);
+
+ for (FilterSetIterator it = m_filters.begin(); it != m_filters.end();
+ ++it) {
+ addFilterInternal(*it);
+ }
+
+ if (!dbus_connection_set_watch_functions(m_connection, addWatch,
+ removeWatch, toggleWatch, this,
+ NULL)) {
+ ThrowMsg(Commons::PlatformException, "Couldn't set-up watch functions.");
+ }
+
+ if (!dbus_connection_add_filter(m_connection, filterMessage, this, NULL)) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't set signal handler callback.");
+ }
+
+ m_connected = true;
+}
+
+void Connection::close()
+{
+ LogDebug("ENTER");
+ if (!m_connected) { return; }
+
+ dbus_connection_remove_filter(m_connection, filterMessage, this);
+
+ // Calls removeWatch() automagically.
+ if (!dbus_connection_set_watch_functions(m_connection, NULL, NULL, NULL,
+ NULL, NULL)) {
+ DPL::Mutex::ScopedLock lock(&m_watchesMutex);
+ WatchSetIterator it = m_watches.begin();
+ for (; it != m_watches.end(); ++it) {
+ if (it->second->isEnabled()) {
+ m_messageDispatcher->removeDescriptor(it->second->getHandle(),
+ it->second->getType());
+ }
+ }
+ m_watches.clear();
+ }
+
+ // TODO: think how to handle exception on filter removal; 1 - do nothing (now),
+ // 2 - remove the buggy one but throw an exception, 3 - remove the buggy one
+ // and don't throw any exception
+ for (FilterSetIterator it = m_filters.begin(); it != m_filters.end();
+ ++it) {
+ removeFilterInternal(*it);
+ }
+
+ dbus_connection_unref(m_connection);
+
+ m_connected = false;
+}
+
+void Connection::addFilter(const std::string& rule)
+{
+ if (m_connected) {
+ addFilterInternal(rule);
+ }
+ m_filters.insert(rule);
+}
+
+void Connection::removeFilter(const std::string& rule)
+{
+ if (m_connected) {
+ removeFilterInternal(rule);
+ }
+ m_filters.erase(rule);
+}
+
+void Connection::setWorkerThread(DPL::Thread* thread)
+{
+ assert(!m_connected && "Connection has already been established.");
+ m_messageDispatcher->SwitchToThread(thread);
+}
+
+void Connection::addFilterInternal(const std::string& rule)
+{
+ assert(m_connection && "Connection has to be established first.");
+ dbus_bus_add_match(m_connection, rule.c_str(), &m_error);
+ if (dbus_error_is_set(&m_error)) {
+ std::string message = m_error.message;
+ dbus_error_free(&m_error);
+ ThrowMsg(Commons::InvalidArgumentException, "Invalid rule: " << message);
+ }
+}
+
+void Connection::removeFilterInternal(const std::string& rule)
+{
+ assert(m_connection && "Connection has to be established first.");
+ dbus_bus_remove_match(m_connection, rule.c_str(), &m_error);
+ if (dbus_error_is_set(&m_error)) {
+ std::string message = m_error.message;
+ dbus_error_free(&m_error);
+ ThrowMsg(Commons::InvalidArgumentException, "Invalid rule: " << message);
+ }
+}
+
+dbus_bool_t Connection::addWatch(DBusWatch* watch, void* data)
+{
+ LogDebug("ENTER");
+ assert(data && "Connection should be passed as user data.");
+ Connection* this_ = static_cast<Connection*>(data);
+ WatchPtr wrapper(new Watch(watch));
+ if (wrapper->isEnabled()) {
+ this_->m_messageDispatcher->addDescriptor(wrapper->getHandle(),
+ wrapper->getType());
+ }
+ DPL::Mutex::ScopedLock lock(&this_->m_watchesMutex);
+ this_->m_watches[wrapper->getHandle()] = wrapper;
+ return TRUE;
+}
+
+void Connection::removeWatch(DBusWatch* watch, void* data)
+{
+ LogDebug("ENTER");
+ assert(data && "Connection should be passed as user data.");
+ Connection* this_ = static_cast<Connection*>(data);
+ Watch wrapper(watch);
+ if (wrapper.isEnabled()) {
+ this_->m_messageDispatcher->removeDescriptor(wrapper.getHandle(),
+ wrapper.getType());
+ }
+ DPL::Mutex::ScopedLock lock(&this_->m_watchesMutex);
+ this_->m_watches.erase(wrapper.getHandle());
+}
+
+void Connection::toggleWatch(DBusWatch* watch, void* data)
+{
+ LogDebug("ENTER");
+ assert(data && "Connection should be passed as user data.");
+ Connection* this_ = static_cast<Connection*>(data);
+ Watch wrapper(watch);
+ if (wrapper.isEnabled()) {
+ this_->m_messageDispatcher->addDescriptor(wrapper.getHandle(),
+ wrapper.getType());
+ } else {
+ this_->m_messageDispatcher->removeDescriptor(wrapper.getHandle(),
+ wrapper.getType());
+ }
+}
+
+DBusHandlerResult Connection::filterMessage(DBusConnection* /*connection*/,
+ DBusMessage* message,
+ void* data)
+{
+ LogDebug("ENTER");
+ if (data) {
+ Connection* this_ = static_cast<Connection*>(data);
+ MessagePtr msg;
+ if (message) {
+ LogInfo(
+ "DBUS message received from interface: " <<
+ dbus_message_get_interface(message));
+ msg.Reset(new Message(message));
+ } else {
+ LogError("DBus message not set, this should not happen!");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ LogDebug("____HERE");
+ FilterSetIterator it = this_->m_filters.begin();
+ for (; it != this_->m_filters.end(); ++it) {
+ // TODO: extend following matching procedure to check not only
+ // interface's name.
+ if ((*it).find(msg->getInterface()) != std::string::npos) {
+ LogDebug("______emitting...");
+ MessageEvent event(msg);
+ this_->EmitEvent(event);
+ LogDebug("______done");
+ }
+ }
+ } else {
+ LogError("User-data not set, this should not happen!");
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+Connection::MessageDispatcher::MessageDispatcher(Connection* connection)
+ : m_connection(connection)
+{
+ assert(m_connection && "Connection cannot be NULL.");
+ DPL::Event::ControllerEventHandler<AddDescriptorEvent>::Touch();
+ DPL::Event::ControllerEventHandler<RemoveDescriptorEvent>::Touch();
+}
+
+Connection::MessageDispatcher::~MessageDispatcher()
+{
+ SwitchToThread(NULL);
+}
+
+void Connection::MessageDispatcher::addDescriptor(DPL::WaitableHandle handle,
+ DPL::WaitMode::Type mode)
+{
+ LogDebug("ENTER");
+ AddDescriptorEvent event(handle, mode);
+ DPL::Event::ControllerEventHandler<AddDescriptorEvent>::PostSyncEvent(event);
+}
+
+void Connection::MessageDispatcher::removeDescriptor(DPL::WaitableHandle handle,
+ DPL::WaitMode::Type mode)
+{
+ LogDebug("ENTER");
+ RemoveDescriptorEvent event(handle, mode);
+ DPL::Event::ControllerEventHandler<RemoveDescriptorEvent>::PostSyncEvent(event);
+}
+
+void Connection::MessageDispatcher::OnEventReceived(
+ const AddDescriptorEvent& event)
+{
+ LogDebug("ENTER");
+ DPL::WaitableHandleWatchSupport::InheritedContext()->AddWaitableHandleWatch(
+ this,
+ event.GetArg0(),
+ event.GetArg1());
+}
+
+void Connection::MessageDispatcher::OnEventReceived(
+ const RemoveDescriptorEvent& event)
+{
+ LogDebug("ENTER");
+ DPL::WaitableHandleWatchSupport::InheritedContext()->
+ RemoveWaitableHandleWatch(this, event.GetArg0(), event.GetArg1());
+}
+
+void Connection::MessageDispatcher::OnWaitableHandleEvent(
+ DPL::WaitableHandle waitableHandle,
+ DPL::WaitMode::Type mode)
+{
+ LogDebug("ENTER");
+ {
+ DPL::Mutex::ScopedLock lock(&m_connection->m_watchesMutex);
+ WatchSetIterator it = m_connection->m_watches.find(waitableHandle);
+ if (it != m_connection->m_watches.end()) {
+ unsigned int flags =
+ (mode == DPL::WaitMode::Write ? DBUS_WATCH_WRITABLE
+ : DBUS_WATCH_READABLE);
+ while (!dbus_watch_handle(it->second->get(), flags)) {
+ LogError("Too few memory!");
+ // TODO: add some check-point to not loop infinitely
+ }
+ }
+ // TODO: not sure if there is point in dispatching connection when watch not found?
+ }
+ dbus_connection_ref(m_connection->m_connection);
+ while (dbus_connection_dispatch(m_connection->m_connection) ==
+ DBUS_DISPATCH_DATA_REMAINS) {
+ }
+ dbus_connection_unref(m_connection->m_connection);
+}
+
+Connection::Watch::Watch(DBusWatch* watch) : m_watch(watch)
+{
+ assert(m_watch && "Watch cannot be NULL.");
+}
+
+DPL::WaitableHandle Connection::Watch::getHandle() const
+{
+ return dbus_watch_get_unix_fd(m_watch);
+}
+
+DPL::WaitMode::Type Connection::Watch::getType() const
+{
+ if ((dbus_watch_get_flags(m_watch) & DBUS_WATCH_WRITABLE) != 0) {
+ return DPL::WaitMode::Write;
+ }
+ return DPL::WaitMode::Read;
+}
+
+bool Connection::Watch::isEnabled() const
+{
+ return (TRUE == dbus_watch_get_enabled(m_watch));
+}
+
+DBusWatch* Connection::Watch::get() const
+{
+ return m_watch;
+}
+} // DBus
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_DBUS_CONNECTION_H_
+#define WRTDEVICEAPIS_DBUS_CONNECTION_H_
+
+#include <string>
+#include <map>
+#include <set>
+#include <dbus/dbus.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/generic_event.h>
+#include <dpl/event/event_support.h>
+#include <dpl/event/event_listener.h>
+#include <dpl/waitable_event.h>
+#include <dpl/thread.h>
+#include <dpl/noncopyable.h>
+#include <dpl/event/controller.h>
+#include <dpl/type_list.h>
+#include <dpl/mutex.h>
+#include "MessageEvent.h"
+
+namespace WrtDeviceApis {
+namespace DBus {
+class Connection : public DPL::Event::EventSupport<MessageEvent>
+{
+ public:
+ typedef DPL::Event::EventListener<MessageEvent> EventListener;
+
+ public:
+ Connection();
+ ~Connection();
+
+ void open(DBusBusType bus);
+ void close();
+ void addFilter(const std::string& rule);
+ void removeFilter(const std::string& rule);
+ void setWorkerThread(DPL::Thread* thread);
+
+ private:
+ DECLARE_GENERIC_EVENT_2(AddDescriptorEvent,
+ DPL::WaitableHandle,
+ DPL::WaitMode::Type)
+
+ DECLARE_GENERIC_EVENT_2(RemoveDescriptorEvent,
+ DPL::WaitableHandle,
+ DPL::WaitMode::Type)
+
+ class MessageDispatcher :
+ public DPL::Event::Controller<DPL::TypeListDecl<
+ AddDescriptorEvent,
+ RemoveDescriptorEvent>::Type>,
+ private DPL::WaitableHandleWatchSupport::WaitableHandleListener
+ {
+ public:
+ explicit MessageDispatcher(Connection* connection);
+ ~MessageDispatcher();
+ void addDescriptor(DPL::WaitableHandle handle,
+ DPL::WaitMode::Type mode);
+ void removeDescriptor(DPL::WaitableHandle handle,
+ DPL::WaitMode::Type mode);
+
+ protected:
+ void OnEventReceived(const AddDescriptorEvent& event);
+ void OnEventReceived(const RemoveDescriptorEvent& event);
+ void OnWaitableHandleEvent(DPL::WaitableHandle waitableHandle,
+ DPL::WaitMode::Type mode);
+
+ private:
+ Connection* m_connection;
+ };
+
+ class Watch : private DPL::Noncopyable
+ {
+ public:
+ explicit Watch(DBusWatch* watch);
+
+ inline DPL::WaitableHandle getHandle() const;
+ inline DPL::WaitMode::Type getType() const;
+ inline bool isEnabled() const;
+ inline DBusWatch* get() const;
+
+ private:
+ DBusWatch* m_watch;
+ };
+ typedef DPL::SharedPtr<Watch> WatchPtr;
+
+ typedef std::map<DPL::WaitableHandle, WatchPtr> WatchSet;
+ typedef WatchSet::iterator WatchSetIterator;
+
+ typedef std::set<std::string> FilterSet;
+ typedef FilterSet::iterator FilterSetIterator;
+
+ private:
+ static dbus_bool_t addWatch(DBusWatch* watch,
+ void* data);
+ static void removeWatch(DBusWatch* watch,
+ void* data);
+ static void toggleWatch(DBusWatch* watch,
+ void* data);
+ static DBusHandlerResult filterMessage(DBusConnection* connection,
+ DBusMessage* message,
+ void* data);
+
+ private:
+ void addFilterInternal(const std::string& rule);
+ void removeFilterInternal(const std::string& rule);
+
+ private:
+ DBusConnection* m_connection;
+ DBusError m_error;
+
+ MessageDispatcher* m_messageDispatcher;
+ bool m_connected;
+ FilterSet m_filters;
+ WatchSet m_watches;
+ DPL::Mutex m_watchesMutex;
+};
+
+typedef DPL::SharedPtr<Connection> ConnectionPtr;
+} // DBus
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_DBUS_CONNECTION_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 "Message.h"
+#include <cassert>
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace DBus {
+Message::Message(DBusMessage* message) : m_message(message)
+{
+ assert(m_message && "Message cannot be NULL.");
+ addRef();
+}
+
+Message::Message(int type)
+{
+ m_message = dbus_message_new(type);
+ if (!m_message) {
+ ThrowMsg(Commons::PlatformException, "Out of memory.");
+ }
+ addRef();
+}
+
+Message::~Message()
+{
+ unref();
+}
+
+int Message::getType() const
+{
+ return dbus_message_get_type(m_message);
+}
+
+std::string Message::getInterface() const
+{
+ const char* interface = dbus_message_get_interface(m_message);
+ return (interface ? interface : std::string());
+}
+
+std::string Message::getPath() const
+{
+ const char* path = dbus_message_get_path(m_message);
+ return (path ? path : std::string());
+}
+
+bool Message::isSignal(const std::string& name) const
+{
+ return (dbus_message_is_signal(m_message,
+ getInterface().c_str(),
+ name.c_str())
+ == TRUE);
+}
+
+Message::ReadIterator Message::getReadIterator() const
+{
+ return ReadIterator(new ReadIterator_(m_message));
+}
+
+void Message::addRef()
+{
+ m_message = dbus_message_ref(m_message);
+}
+
+void Message::unref()
+{
+ dbus_message_unref(m_message);
+}
+
+Message::ReadIterator_::ReadIterator_(DBusMessage* message)
+{
+ assert(message && "Message cannot be NULL.");
+ m_valid = dbus_message_iter_init(message, &m_iterator);
+}
+
+bool Message::ReadIterator_::next()
+{
+ if (!m_valid) {
+ Throw(Commons::OutOfRangeException);
+ }
+ return (m_valid = (dbus_message_iter_next(&m_iterator) == TRUE));
+}
+
+bool Message::ReadIterator_::isValid() const
+{
+ return m_valid;
+}
+
+int Message::ReadIterator_::getArgType() const
+{
+ if (!m_valid) {
+ Throw(Commons::OutOfRangeException);
+ }
+ return dbus_message_iter_get_arg_type(&m_iterator);
+}
+
+int Message::ReadIterator_::getInt() const
+{
+ return static_cast<int>(getArgBasic<dbus_int32_t>(DBUS_TYPE_INT32));
+}
+
+std::string Message::ReadIterator_::getString() const
+{
+ return getArgBasic<const char*>(DBUS_TYPE_STRING);
+}
+
+template<typename T>
+T Message::ReadIterator_::getArgBasic(int type) const
+{
+ if (getArgType() != type) {
+ ThrowMsg(Commons::ConversionException, "Type mismatch.");
+ }
+
+ if (!m_valid) {
+ Throw(Commons::OutOfRangeException);
+ }
+
+ T result;
+ dbus_message_iter_get_basic(&m_iterator, &result);
+ return result;
+}
+} // DBus
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_DBUS_MESSAGE_H_
+#define WRTDEVICEAPIS_DBUS_MESSAGE_H_
+
+#include <string>
+#include <dbus/dbus.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/optional.h>
+#include <dpl/noncopyable.h>
+
+namespace WrtDeviceApis {
+namespace DBus {
+class Message : private DPL::Noncopyable
+{
+ private:
+ class ReadIterator_;
+
+ public:
+ typedef DPL::SharedPtr<ReadIterator_> ReadIterator;
+
+ public:
+ explicit Message(DBusMessage* message);
+ explicit Message(int type);
+ ~Message();
+
+ int getType() const;
+ std::string getInterface() const;
+ std::string getPath() const;
+ bool isSignal(const std::string& name) const;
+ ReadIterator getReadIterator() const;
+
+ private:
+ // It doesn't need to be non-copyable - DBusMessageIter doesn't require it.
+ class ReadIterator_
+ {
+ public:
+ explicit ReadIterator_(DBusMessage* message);
+
+ bool next();
+ bool isValid() const;
+
+ int getArgType() const;
+
+ int getInt() const;
+ std::string getString() const;
+
+ private:
+ template<typename T>
+ T getArgBasic(int type) const;
+
+ private:
+ mutable DBusMessageIter m_iterator;
+ bool m_valid;
+ };
+
+ private:
+ inline void addRef();
+ inline void unref();
+
+ private:
+ DBusMessage* m_message;
+};
+
+typedef DPL::SharedPtr<Message> MessagePtr;
+} // DBus
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_DBUS_MESSAGE_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)
+ */
+
+#ifndef WRTDEVICEAPIS_DBUS_MESSAGEEVENT_H_
+#define WRTDEVICEAPIS_DBUS_MESSAGEEVENT_H_
+
+#include <dpl/generic_event.h>
+#include "Message.h"
+
+namespace WrtDeviceApis {
+namespace DBus {
+DECLARE_GENERIC_EVENT_1(MessageEvent, MessagePtr)
+} // DBus
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_DBUS_MESSAGEEVENT_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(dbus REQUIRED dbus-1)
+
+set(INCLUDES_IMPLEMENTATION_DBUS
+ ${dbus_INCLUDE_DIRS}
+)
+
+set(LIBS_IMPLEMENTATION_DBUS
+ ${dbus_LIBRARIES}
+)
+
+set(SRCS_IMPLEMENTATION_DBUS
+ ${CURRENT_PATH}/Connection.cpp
+ ${CURRENT_PATH}/Message.cpp
+)
--- /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 Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#include "AttributeInfo.h"
+#include <commons/Exception.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Camera {
+namespace AttributeInfo {
+ArrayOfInt toArrayOfInt(MMHandleType handle,
+ const char* name)
+{
+ ArrayOfInt result;
+ MMCamAttrsInfo info = {};
+ if (mm_camcorder_get_attribute_info(handle, name, &info) < 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while reading attribute info.");
+ } else {
+ if ((MM_CAM_ATTRS_TYPE_INT != info.type) ||
+ (MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY != info.validity_type)) {
+ ThrowMsg(Commons::ConversionException, "Unable to convert.");
+ }
+ result.assign(info.int_array.array,
+ info.int_array.array + info.int_array.count);
+ }
+ return result;
+}
+} // AttributeInfo
+} // Camera
+} // 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_CAMERA_ATTRIBUTEINFO_H_
+#define WRTDEVICEAPIS_CAMERA_ATTRIBUTEINFO_H_
+
+#include <vector>
+#include <mm_camcorder.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Camera {
+namespace AttributeInfo {
+typedef std::vector<int> ArrayOfInt;
+
+ArrayOfInt toArrayOfInt(MMHandleType handle,
+ const char* name);
+} // AttributeInfo
+} // Camera
+} // Platform
+} // WrtPlugins
+
+#endif // WRTDEVICEAPIS_CAMERA_ATTRIBUTEINFO_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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "Camera.h"
+#include <pthread.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dpl/assert.h>
+#include <dpl/shared_ptr.h>
+#include "mm_camcorder.h"
+#include <commons/Exception.h>
+#include "AttributeInfo.h"
+
+namespace {
+const unsigned int DEFAULT_CAPTURE_WIDTH = 640;
+const unsigned int DEFAULT_CAPTURE_HEIGHT = 480;
+} // namespace
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Camera {
+//.............................................................................
+Camera::Camera() :
+ m_camcorderHandle(NULL)
+{
+ m_camcorderPreset.videodev_type = MM_VIDEO_DEVICE_NONE,
+ m_camcorderPreset.reserved[0] = 0;
+ m_camcorderPreset.reserved[1] = 0;
+ m_camcorderPreset.reserved[2] = 0;
+ m_camcorderPreset.reserved[3] = 0;
+
+ pthread_mutex_init(&m_stateMutex, NULL);
+ m_state = IDLE;
+ DPL::Event::ControllerEventHandler<JobDoneEvent >::Touch();
+}
+//.............................................................................
+void Camera::init(MMCamPreset preset)
+{
+ LogDebug("Creating camcorder");
+ memcpy(&m_camcorderPreset, &preset, sizeof(m_camcorderPreset));
+ int err = mm_camcorder_create(&m_camcorderHandle, &m_camcorderPreset);
+
+ logCamcorderState();
+ if (err != MM_ERROR_NONE) {
+ LogError("Creating camcorder's failed !!! " << err);
+ Throw(Commons::UnknownException);
+ }
+}
+//.............................................................................
+Camera::~Camera()
+{
+ LogDebug(__FUNCTION__);
+
+ DPL::Event::ControllerEventHandler<JobDoneEvent >::SwitchToThread(NULL);
+
+ m_state = PROCESSING;
+ pthread_mutex_lock(&m_stateMutex);
+ {
+ m_state = PROCESSING;
+
+ mm_camcorder_set_message_callback(m_camcorderHandle, NULL, NULL);
+ mm_camcorder_capture_stop(m_camcorderHandle);
+ mm_camcorder_stop(m_camcorderHandle);
+ }
+ pthread_mutex_unlock(&m_stateMutex);
+
+ unRealizeCamcoder();
+ mm_camcorder_destroy(m_camcorderHandle);
+ pthread_mutex_destroy(&m_stateMutex);
+}
+//.............................................................................
+void Camera::tryIsInvalidParameterError(int errorCode)
+{
+ switch (errorCode) {
+ case MM_ERROR_COMMON_INVALID_ATTRTYPE:
+ case MM_ERROR_COMMON_INVALID_PERMISSION:
+ case MM_ERROR_COMMON_OUT_OF_ARRAY:
+ case MM_ERROR_COMMON_OUT_OF_RANGE:
+ case MM_ERROR_COMMON_ATTR_NOT_EXIST:
+ LogDebug("Invalid Parameter error");
+ Throw(Commons::InvalidArgumentException);
+ }
+ LogDebug("it's not Invalid Parameter error");
+}
+//.............................................................................
+int Camera::lockCameraMutex(Camera *camera)
+{
+ LogDebug("Trying to lock camera mutex");
+ pthread_mutex_lock(&(camera->m_stateMutex));
+ LogDebug(".. - locked");
+
+ if (Camera::PROCESSING == camera->m_state) {
+ LogWarning(
+ "Camera object is being killed or performing some locked operations, but it's receiving the message ");
+ pthread_mutex_unlock(&(camera->m_stateMutex));
+ return -1;
+ }
+
+ if (Camera::IDLE == camera->m_state) {
+ LogWarning(
+ "Message has been received, but no one is listening any more");
+ pthread_mutex_unlock(&(camera->m_stateMutex));
+ return -1;
+ }
+
+ return 0;
+}
+//.............................................................................
+void Camera::unlockCameraMutex(Camera *camera)
+{
+ LogDebug("Unlocking camera mutex");
+ pthread_mutex_unlock(&(camera->m_stateMutex));
+}
+//.............................................................................
+/* Body of the callback function msg_callback */
+int Camera::camcorderMessageCallback(int msg_type,
+ void *msg_param,
+ void *user_param)
+{
+ LogDebug(__FUNCTION__);
+ int error;
+
+ MMMessageParamType *m = static_cast<MMMessageParamType *>(msg_param);
+ Platform::Camera::Camera *igcamera =
+ static_cast<Platform::Camera::Camera *>(user_param);
+
+ switch (msg_type) {
+ case MM_MESSAGE_WARNING:
+ LogWarning("*MSG* Warning occured " << std::hex << m->code);
+ break;
+ //lack of break is intended; treating all these messages as error.
+ case MM_MESSAGE_CAMCORDER_MAX_SIZE: /**< Maximum size, camcorder waits for user's order (cam_commit/cancel).*/
+ case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE: /**< No free space, camcorder waits for user's order (cam_commit/cancel).*/
+ case MM_MESSAGE_CAMCORDER_TIME_LIMIT: /**< Time limit, camcorder waits for user's order (cam_commit/cancel)*/
+ LogError("Unexpected camcorder message: " << std::hex << msg_type);
+ LogInfo("Force camcorder to commit caputured data");
+ mm_camcorder_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_unrealize(igcamera->m_camcorderHandle);
+ igcamera->DPL::Event::ControllerEventHandler<JobDoneEvent>::PostEvent(
+ JobDoneEvent());
+ break;
+
+ case MM_MESSAGE_CAMCORDER_ERROR:
+ if (Camera::lockCameraMutex(igcamera) < 0) {
+ return -1;
+ }
+ LogError("*MSG* Error's occured. " << std::hex << m->code);
+
+ switch (igcamera->getState()) {
+ case Camera::CAPTURING_IMAGE:
+ igcamera->m_eventTakePicture->setExceptionCode(
+ Commons::ExceptionCodes::UnknownException);
+ break;
+ case Camera::CAPTURING_VIDEO:
+ igcamera->m_eventBeginRecording->setExceptionCode(
+ Commons::ExceptionCodes::UnknownException);
+ break;
+ default:
+ break;
+ }
+ mm_camcorder_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_unrealize(igcamera->m_camcorderHandle);
+ mm_camcorder_set_message_callback(igcamera->m_camcorderHandle,
+ NULL,
+ NULL);
+ igcamera->DPL::Event::ControllerEventHandler<JobDoneEvent>::PostEvent(
+ JobDoneEvent());
+ Camera::unlockCameraMutex(igcamera);
+ break;
+
+ case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
+ if (Camera::lockCameraMutex(igcamera) < 0) {
+ return -1;
+ }
+
+ LogDebug(
+ "*MSG* State changed " << std::hex << m->state.previous <<
+ "->" << std::hex << m->state.current);
+ //2->3
+ if (MM_CAMCORDER_STATE_PREPARE == m->state.current &&
+ MM_CAMCORDER_STATE_READY == m->state.previous) {
+ LogDebug("MM_CAMCORDER_STATE_READY->MM_CAMCORDER_STATE_PREPARE ");
+ switch (igcamera->getState()) {
+ case Camera::CAPTURING_IMAGE:
+ error = mm_camcorder_capture_start(igcamera->m_camcorderHandle);
+ if (error != MM_ERROR_NONE) {
+ LogError(
+ "m_camcorderHandle capture start failed " <<
+ std::hex << error);
+ igcamera->m_eventTakePicture->setExceptionCode(
+ Commons::ExceptionCodes::UnknownException);
+ igcamera->DPL::Event::ControllerEventHandler<JobDoneEvent>::
+ PostEvent(JobDoneEvent());
+ mm_camcorder_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_unrealize(igcamera->m_camcorderHandle);
+ }
+ break;
+ case Camera::CAPTURING_VIDEO:
+ LogDebug("CAPTURING_VIDEO " << igcamera->m_camcorderHandle);
+ error = mm_camcorder_record(igcamera->m_camcorderHandle);
+ if (error != MM_ERROR_NONE) {
+ LogError(
+ "m_camcorderHandle record start failed " <<
+ std::hex << error);
+ igcamera->m_eventBeginRecording->setExceptionCode(
+ Commons::ExceptionCodes::UnknownException);
+ igcamera->DPL::Event::ControllerEventHandler<JobDoneEvent>::
+ PostEvent(JobDoneEvent());
+ mm_camcorder_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_unrealize(igcamera->m_camcorderHandle);
+ }
+ break;
+ default:
+ break;
+ }
+ LogDebug("Done.");
+ }
+ //3->4
+ if (MM_CAMCORDER_STATE_CAPTURING == m->state.previous &&
+ MM_CAMCORDER_STATE_PREPARE == m->state.current) {
+ /* Capture Stop */
+ LogDebug(
+ "MM_CAMCORDER_STATE_CAPTURING->MM_CAMCORDER_STATE_PREPARE => stopping capture");
+ error = mm_camcorder_capture_stop(igcamera->m_camcorderHandle);
+ if (error != MM_ERROR_NONE) {
+ LogError(
+ "m_camcorderHandle capture stopfailed " << std::hex <<
+ error);
+ }
+ igcamera->logCamcorderState();
+ mm_camcorder_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_unrealize(igcamera->m_camcorderHandle);
+ }
+
+ if (MM_CAMCORDER_STATE_RECORDING == m->state.previous &&
+ MM_CAMCORDER_STATE_PREPARE == m->state.current) {
+ /* Record Stop */
+ LogDebug(
+ "MM_CAMCORDER_STATE_CAPTURING->MM_CAMCORDER_STATE_PREPARE => stopping recording");
+
+ /// ...
+ mm_camcorder_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_unrealize(igcamera->m_camcorderHandle);
+ }
+
+ Camera::unlockCameraMutex(igcamera);
+ break;
+ case MM_MESSAGE_CAMCORDER_CAPTURED:
+ if (Camera::lockCameraMutex(igcamera) < 0) {
+ return -1;
+ }
+ LogDebug("*MSG* Captured. !!!");
+ if (Camera::CAPTURING_VIDEO == igcamera->getState() ||
+ Camera::CAPTURING_IMAGE == igcamera->getState()) {
+ mm_camcorder_capture_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_stop(igcamera->m_camcorderHandle);
+ mm_camcorder_unrealize(igcamera->m_camcorderHandle);
+ igcamera->DPL::Event::ControllerEventHandler<JobDoneEvent>::PostEvent(
+ JobDoneEvent());
+ }
+ Camera::unlockCameraMutex(igcamera);
+ break;
+ default:
+ LogDebug(
+ "*MSG* Message received. MMMessageID = " << std::hex <<
+ msg_type);
+ break;
+ }
+ return true;
+}
+//.............................................................................
+void Camera::OnEventReceived(const JobDoneEvent &event)
+{
+ //if we received this event it means that we are (should be) in PROCESSING state and we need to send back the answer
+ //we need to check which one
+
+ LogDebug("JobDoneEvent received");
+ if (-1 == Camera::lockCameraMutex(this)) {
+ return;
+ }
+ if (m_eventTakePicture) {
+ Platform::EventRequestReceiver< Api::Camera::EventTakePicture >::
+ ManualAnswer(m_eventTakePicture);
+ m_eventTakePicture.Reset();
+ } else if (m_eventBeginRecording) {
+ Platform::EventRequestReceiver< Api::Camera::EventBeginRecording >::
+ ManualAnswer(m_eventBeginRecording);
+ m_eventBeginRecording.Reset();
+ } else if (NULL != m_eventEndRecording.Get()) {
+ Platform::EventRequestReceiver< Api::Camera::EventEndRecording>::
+ ManualAnswer(m_eventEndRecording);
+ m_eventEndRecording.Reset();
+ } else if (m_eventRequestLiveVideo) {
+ Platform::EventRequestReceiver< Api::Camera::EventRequestLiveVideo>::
+ ManualAnswer(m_eventRequestLiveVideo);
+ m_eventRequestLiveVideo.Reset();
+ } else {
+ LogError("This part should not be reached");
+ assert(0);
+ }
+ setState(Camera::IDLE);
+ Camera::unlockCameraMutex(this);
+ LogDebug("camera is idle now..");
+}
+//.............................................................................
+void Camera::OnRequestReceived(
+ const Api::Camera::EventTakePictureSharedPtr & event)
+{
+ int err;
+ LogDebug(__FUNCTION__);
+
+ pthread_mutex_lock(&m_stateMutex);
+ //check is camera idle and can take a picture and camera object is not currently being destructed
+ if (Camera::IDLE != m_state) {
+ pthread_mutex_unlock(&m_stateMutex);
+ event->setExceptionCode(Commons::ExceptionCodes::AlreadyInUseException);
+ return;
+ }
+
+ try
+ {
+ m_state = Camera::CAPTURING_IMAGE;
+ reInitializeCamcorderForPicture(event->getCaptureOptionsRef());
+ }
+ catch (const Commons::Exception &exc)
+ {
+ m_state = Camera::IDLE;
+ pthread_mutex_unlock(&m_stateMutex);
+ LogDebug("error's occured - invoking error callback");
+ event->setExceptionCode(exc.getCode());
+ return;
+ }
+
+ //from now on we will have to call answer manually
+ event->switchToManualAnswer();
+ m_eventTakePicture = event;
+ LogDebug("setting message callback");
+ mm_camcorder_set_message_callback(m_camcorderHandle,
+ Camera::camcorderMessageCallback,
+ this);
+
+ /* start receiving the input video stream */
+ LogDebug("mm_camcorder_start");
+ err = mm_camcorder_start(m_camcorderHandle);
+ if (err != MM_ERROR_NONE) {
+ LogError("starting camcorder failed " << std::hex << err);
+ mm_camcorder_set_message_callback(m_camcorderHandle, NULL, NULL);
+ m_state = Camera::IDLE;
+ pthread_mutex_unlock(&m_stateMutex);
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ Platform::EventRequestReceiver< Api::Camera::EventTakePicture >::
+ ManualAnswer(event);
+ return;
+ }
+ pthread_mutex_unlock(&m_stateMutex);
+ LogDebug("leaving");
+}
+//.............................................................................
+void Camera::OnRequestReceived(
+ const Api::Camera::EventBeginRecordingSharedPtr & event)
+{
+ int err;
+ LogDebug(__FUNCTION__);
+
+ pthread_mutex_lock(&m_stateMutex);
+ //check is camera idle and can record
+ if (Camera::IDLE != m_state) {
+ pthread_mutex_unlock(&m_stateMutex);
+ event->setExceptionCode(Commons::ExceptionCodes::AlreadyInUseException);
+ return;
+ }
+
+ try
+ {
+ m_state = Camera::CAPTURING_VIDEO;
+ reInitializeCamcorderForVideo(event->getCaptureOptionsRef());
+ }
+ catch (const Commons::Exception &exc)
+ {
+ m_state = Camera::IDLE;
+ pthread_mutex_unlock(&m_stateMutex);
+ LogDebug("error's occured - invoking error callback");
+ event->setExceptionCode(exc.getCode());
+ return;
+ }
+
+ //from now on we will have to call answer manually
+ event->switchToManualAnswer();
+ m_eventBeginRecording = event;
+ LogDebug("setting message callback");
+ mm_camcorder_set_message_callback(m_camcorderHandle,
+ Camera::camcorderMessageCallback,
+ this);
+
+ /* start receiving the input video stream */
+ LogDebug("mm_camcorder_start");
+ err = mm_camcorder_start(m_camcorderHandle);
+ if (err != MM_ERROR_NONE) {
+ LogError("starting camcorder failed " << std::hex << err);
+ mm_camcorder_set_message_callback(m_camcorderHandle, NULL, NULL);
+ m_state = Camera::IDLE;
+ pthread_mutex_unlock(&m_stateMutex);
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ Platform::EventRequestReceiver<Api::Camera::EventBeginRecording>::
+ ManualAnswer(event);
+ return;
+ }
+ pthread_mutex_unlock(&m_stateMutex);
+}
+//.............................................................................
+void Camera::OnRequestReceived(
+ const Api::Camera::EventEndRecordingSharedPtr & event)
+{
+ LogDebug("end request");
+ pthread_mutex_lock(&m_stateMutex);
+ if (m_state == Camera::CAPTURING_VIDEO) {
+ logCamcorderState();
+ int error = mm_camcorder_commit(m_camcorderHandle);
+ switch (error) {
+ case MM_ERROR_NONE:
+ break;
+ case MM_ERROR_CAMCORDER_INVALID_STATE:
+ LogError("MM_ERROR_CAMCORDER_INVALID_STATE's occured");
+ break;
+ default:
+ //capturing video is in progress but we have an error
+ LogError(
+ "mm_camcorder_commit error occured " << std::hex <<
+ error << " stopping it");
+ mm_camcorder_cancel(m_camcorderHandle);
+ mm_camcorder_stop(m_camcorderHandle);
+ mm_camcorder_unrealize(m_camcorderHandle);
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ m_state = Camera::IDLE;
+ break;
+ }
+ } else {
+ LogDebug("stopVideo has been called but no recording is in progress");
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ }
+ pthread_mutex_unlock(&m_stateMutex);
+}
+//.............................................................................
+void Camera::OnRequestReceived(
+ const DPL::SharedPtr<Api::Camera::EventRequestLiveVideo> & event)
+{
+ ///TODO Not supported
+ event->setExceptionCode(Commons::ExceptionCodes::UnsupportedException);
+}
+//.............................................................................
+void Camera::logCamcorderState()
+{
+ MMCamcorderStateType state;
+ int retValue = mm_camcorder_get_state(m_camcorderHandle, &state);
+ if (MM_ERROR_NONE == retValue) {
+ LogDebug("camcorder's state: " << std::hex << state);
+ } else {
+ LogDebug("getting camcorder's state's failed: " << std::hex << retValue);
+ }
+}
+//.............................................................................
+std::string Camera::getDescription() const
+{
+ std::string desc;
+ char *err_attr_name = NULL;
+ char *description = NULL;
+ int size = 0;
+
+ if (mm_camcorder_get_attributes(m_camcorderHandle, &err_attr_name,
+ "camera-device-name", &description, &size,
+ NULL) < 0) {
+ LogError("GetDescription problem ");
+ if (err_attr_name) {
+ LogError("mm_camcorder_get_attributes " << err_attr_name);
+ }
+ std::ostringstream oss;
+ oss << m_camcorderPreset.videodev_type;
+ desc.assign(oss.str());
+ } else {
+ desc.assign(description);
+ }
+ if (err_attr_name) {
+ LogDebug("free err_attr_name");
+ free(err_attr_name);
+ }
+ LogDebug("desc" << desc);
+ return desc;
+}
+//.............................................................................
+int Camera::camcorderVideoCaptureCallback(MMCamcorderCaptureDataType *src,
+ MMCamcorderCaptureDataType *thumb,
+ void *data)
+{
+ LogDebug(__FUNCTION__);
+ Platform::Camera::Camera *camera =
+ static_cast<Platform::Camera::Camera *>(data);
+
+ if (Camera::CAPTURING_IMAGE != camera->getState()) {
+ return 1;
+ }
+
+ assert(src->format == MM_PIXEL_FORMAT_ENCODED);
+
+ printf(
+ "MM_PIXEL_FORMAT_ENCODED src->data=%p src->length=%d, src->width=%d, src->heigtht=%d \n\n",
+ src->data,
+ src->length,
+ src->width,
+ src->height);
+ std::string fileName =
+ camera->m_eventTakePicture->getCaptureOptionsRef()->getFileName();
+
+ FILE* fp = fopen(fileName.c_str(), "w+");
+ if (fp == NULL) {
+ LogError("file opening error!!");
+ return -1;
+ } else {
+ LogDebug("open success");
+ if (fwrite(src->data, src->length, 1, fp) != 1) {
+ LogError("file writing error!!");
+ fclose(fp);
+ return -1;
+ }
+ LogDebug("success");
+ }
+ fclose(fp);
+ return 0;
+}
+//.............................................................................
+void Camera::setCaptureOptions(
+ const Api::Camera::ICaptureOptionsPtr &captureOptions)
+{
+ LogDebug("enter");
+
+ if (NULL == captureOptions) {
+ return;
+ }
+ bool ret = realizeCamcoder();
+ if (ret == FALSE) {
+ LogError("Realize camcoreder failed");
+ return;
+ }
+
+ char *err_attr_name = NULL;
+ int retValue = 0;
+
+ if (captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_WIDTH)) {
+ LogDebug("setting width");
+ short width = captureOptions->getWidth();
+ retValue = mm_camcorder_set_attributes(m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_CAPTURE_WIDTH,
+ width,
+ NULL);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug("couldn't set width attribute " << std::hex << retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+ }
+
+ if (captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_HEIGHT)) {
+ LogDebug("setting height");
+ short height = captureOptions->getHeight();
+ retValue = mm_camcorder_set_attributes(m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_CAPTURE_HEIGHT,
+ height,
+ NULL);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug("couldn't set height attribute " << std::hex << retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+ }
+
+ if (captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_FRAME_RATE)) {
+ LogDebug("setting frame rate");
+ short frameRate = captureOptions->getFrameRate();
+ retValue = mm_camcorder_set_attributes(m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_CAMERA_FPS,
+ frameRate,
+ NULL);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug(
+ "couldn't set frameRate attribute " << std::hex <<
+ retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+ }
+
+ if (captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_MAX_BITRATE)) {
+ unsigned long bitrate = captureOptions->getMaximumBitrate();
+ LogDebug("setting max bitrate: " << bitrate);
+ retValue = mm_camcorder_set_attributes(m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_AUDIO_ENCODER_BITRATE,
+ bitrate,
+ MMCAM_VIDEO_ENCODER_BITRATE,
+ bitrate,
+ NULL);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug("couldn't set bitrate attribute " << std::hex << retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+ }
+
+ if (captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_IMAGE_RESOLUTION)) {
+ LogDebug("setting image resolution");
+ Api::Camera::ICaptureOptions::ImageResolution imageResolution =
+ captureOptions->getImageResolution();
+
+ //getting possible range of this argument
+ MMCamAttrsInfo info;
+ retValue = mm_camcorder_get_attribute_info(m_camcorderHandle,
+ MMCAM_IMAGE_ENCODER_QUALITY,
+ &info);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug(
+ "couldn't get MMCAM_IMAGE_ENCODER_QUALITY resolution attribute info"
+ << std::hex << retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+
+ assert(MM_CAM_ATTRS_VALID_TYPE_INT_RANGE == info.validity_type);
+ int quality = 0;
+ switch (imageResolution) {
+ case Api::Camera::ICaptureOptions::IMAGE_RESOLUTION_LOW:
+ quality = info.int_range.min;
+ break;
+ case Api::Camera::ICaptureOptions::IMAGE_RESOLUTION_HIGH:
+ quality = info.int_range.max;
+ break;
+ case Api::Camera::ICaptureOptions::IMAGE_RESOLUTION_DEFAULT:
+ quality = info.int_range.def;
+ break;
+ default:
+ break;
+ }
+ retValue = mm_camcorder_set_attributes(m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_IMAGE_ENCODER_QUALITY,
+ quality,
+ NULL);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug(
+ "couldn't set image quality attribute " << std::hex <<
+ retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+
+ if (!captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_WIDTH) &&
+ !captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_HEIGHT) &&
+ (Api::Camera::ICaptureOptions::IMAGE_RESOLUTION_DEFAULT !=
+ captureOptions->getImageResolution())) {
+ Resolution res = getCaptureResolution(
+ Api::Camera::ICaptureOptions::IMAGE_RESOLUTION_LOW ==
+ captureOptions->getImageResolution()
+ );
+ LogDebug("Resolution: " << res.getWidth() << "x" << res.getHeight());
+ retValue = mm_camcorder_set_attributes(m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_CAPTURE_WIDTH,
+ res.getWidth(),
+ MMCAM_CAPTURE_HEIGHT,
+ res.getHeight(),
+ NULL);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug(
+ "couldn't set image resolution attribute " <<
+ std::hex << retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+ }
+ }
+
+ ///"you can't set a file name with "MMCAM_TARGET_FILENAME" when capturing still image"
+ if (captureOptions->isAttributeValid(Api::Camera::ICaptureOptions::
+ SETTED_FILE_NAME)) {
+ LogDebug("setting target filename");
+ std::string fileName = captureOptions->getFileName();
+ /*
+ * Not using Api::Filesystem::IManager::access() intentionally - to not
+ * introduce dependencies between Camera and Filesystem modules for such
+ * a minor feature. What's more it allows for a small optimization - only
+ * one access() call is needed when in case of Filesystem::IManager::access()
+ * two would be required (no way to get to `errno` variable).
+ */
+ errno = 0;
+ if (access(fileName.c_str(), W_OK) != 0) {
+ if (ENOENT != errno) {
+ ThrowMsg(Commons::PlatformException,
+ "Can't write to specified file.");
+ }
+ } else if (!captureOptions->getOverwrite()) {
+ ThrowMsg(
+ Commons::PlatformException,
+ "Output file already exists but overwrite has not been set.");
+ }
+
+ if (Camera::CAPTURING_VIDEO == m_state) {
+ retValue = mm_camcorder_set_attributes(m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_TARGET_FILENAME,
+ fileName.c_str(),
+ fileName.length() *
+ sizeof(char),
+ NULL);
+ if (retValue < 0) {
+ free(err_attr_name);
+ LogDebug(
+ "couldn't set file name attribute " << std::hex <<
+ retValue);
+ Throw(Commons::InvalidArgumentException);
+ }
+ }
+ }
+}
+//.............................................................................
+int Camera::reInitializeCamcorderForPicture(
+ const Api::Camera::ICaptureOptionsPtr &captureOptions)
+{
+ int err;
+ /*"However, you have to set every attribute to fit to video mode, but it's tiresome.
+ So, I recommend to you to call destroy also.
+ Like this, MMCamcorderStop() -> MMCamcorderUnrealize() ->
+ MMCamcorderDestroy() -> MMCamcorderCreate()..
+ get a new handle -> MMCamcorderRealize() ->
+ set MM_CAMCORDER_MODE_VIDEO -> MMCamcorderStart()"*/
+ LogDebug("Reinitializing camcorder for picture capturing");
+ mm_camcorder_stop(m_camcorderHandle);
+ mm_camcorder_unrealize(m_camcorderHandle);
+ mm_camcorder_destroy(m_camcorderHandle);
+
+ err = mm_camcorder_create(&m_camcorderHandle, &m_camcorderPreset);
+ if (err < 0) {
+ LogError("creating camcorder has failed " << std::hex << err);
+ Throw(Commons::UnknownException);
+ }
+
+ char *err_attr_name = NULL;
+ err = mm_camcorder_set_attributes(
+ m_camcorderHandle, &err_attr_name,
+ MMCAM_MODE, MM_CAMCORDER_MODE_IMAGE,
+ MMCAM_IMAGE_ENCODER, MM_IMAGE_CODEC_JPEG,
+ MMCAM_CAMERA_FORMAT, MM_PIXEL_FORMAT_YUYV,
+ MMCAM_CAMERA_FPS, 30,
+ MMCAM_DISPLAY_ROTATION, MM_DISPLAY_ROTATION_NONE,
+ MMCAM_CAPTURE_FORMAT, MM_PIXEL_FORMAT_ENCODED,
+ MMCAM_CAPTURE_WIDTH, DEFAULT_CAPTURE_WIDTH,
+ MMCAM_CAPTURE_HEIGHT, DEFAULT_CAPTURE_HEIGHT,
+ MMCAM_CAPTURE_COUNT, 1,
+ MMCAM_DISPLAY_VISIBLE, false,
+ NULL);
+
+ if (err != 0) {
+ LogError("error: " << err_attr_name);
+ free(err_attr_name);
+ Throw(Commons::InvalidArgumentException);
+ }
+ mm_camcorder_set_video_capture_callback(
+ m_camcorderHandle,
+ (mm_camcorder_video_capture_callback) Camera::
+ camcorderVideoCaptureCallback,
+ static_cast<void*>(this));
+ setCaptureOptions(captureOptions);
+ return 0;
+}
+//.............................................................................
+int Camera::reInitializeCamcorderForVideo(
+ const Api::Camera::ICaptureOptionsPtr &captureOptions)
+{
+ /*"However, you have to set every attribute to fit to video mode, but it's tiresome.
+ So, I recommend to you to call destroy also.
+ Like this, MMCamcorderStop() -> MMCamcorderUnrealize() ->
+ MMCamcorderDestroy() -> MMCamcorderCreate()..
+ get a new handle -> MMCamcorderRealize() ->
+ set MM_CAMCORDER_MODE_VIDEO -> MMCamcorderStart()"*/
+
+ LogDebug("Reinitializing camcorder for video capturing");
+
+ mm_camcorder_stop(m_camcorderHandle);
+ mm_camcorder_unrealize(m_camcorderHandle);
+ mm_camcorder_destroy(m_camcorderHandle);
+ mm_camcorder_create(&m_camcorderHandle, &m_camcorderPreset);
+
+ int err;
+ char *err_attr_name = NULL;
+
+ err = mm_camcorder_set_attributes((MMHandleType)m_camcorderHandle,
+ &err_attr_name,
+ MMCAM_MODE,
+ MM_CAMCORDER_MODE_VIDEO,
+ MMCAM_AUDIO_DEVICE,
+ MM_AUDIO_DEVICE_MIC,
+ MMCAM_AUDIO_ENCODER,
+ MM_AUDIO_CODEC_AAC,
+ MMCAM_VIDEO_ENCODER,
+ MM_VIDEO_CODEC_MPEG4,
+ MMCAM_FILE_FORMAT,
+ MM_FILE_FORMAT_3GP,
+ MMCAM_CAMERA_WIDTH,
+ 640,
+ MMCAM_CAMERA_HEIGHT,
+ 480,
+ MMCAM_CAMERA_FORMAT,
+ MM_PIXEL_FORMAT_NV12,
+ MMCAM_CAMERA_FPS,
+ 30,
+ MMCAM_DISPLAY_ROTATION,
+ MM_DISPLAY_ROTATION_NONE,
+ MMCAM_AUDIO_SAMPLERATE,
+ 44100,
+ MMCAM_AUDIO_CHANNEL,
+ 2,
+ MMCAM_AUDIO_INPUT_ROUTE,
+ MM_AUDIOROUTE_CAPTURE_NORMAL,
+ NULL);
+
+ if (err != 0) {
+ LogError("error: " << err_attr_name);
+ free(err_attr_name);
+ Throw(Commons::InvalidArgumentException);
+ }
+
+ setCaptureOptions(captureOptions);
+
+ return 0;
+}
+//.............................................................................
+bool Camera::realizeCamcoder()
+{
+ LogDebug(__FUNCTION__);
+ MMCamcorderStateType state;
+ int ret = mm_camcorder_get_state(m_camcorderHandle, &state);
+ if (MM_CAMCORDER_STATE_NULL == state) {
+ LogDebug("camcorder is not realized - realizing..");
+ ret = mm_camcorder_realize(m_camcorderHandle);
+ if (MM_ERROR_NONE != ret) {
+ LogError(
+ "realizing the camcorder handle failed " << std::hex <<
+ ret);
+ Throw(Commons::UnknownException);
+ }
+ return true;
+ } else {
+ LogDebug("camcorder's been already realized");
+ }
+ return false;
+}
+//.............................................................................
+int Camera::unRealizeCamcoder()
+{
+ if (!m_camcorderHandle) {
+ return -1;
+ }
+ MMCamcorderStateType state;
+ int ret = mm_camcorder_get_state(m_camcorderHandle, &state);
+ if (MM_CAMCORDER_STATE_READY == state) {
+ ret = mm_camcorder_unrealize(m_camcorderHandle);
+ if (MM_ERROR_NONE != ret) {
+ LogError(
+ "unrealizing the camcorder handle's failed " <<
+ std::hex << ret);
+ Throw(Commons::UnknownException);
+ }
+ }
+ return MM_ERROR_NONE;
+}
+//.............................................................................
+Camera::Resolution Camera::getCaptureResolution(bool low) const
+{
+ Assert(m_camcorderHandle && "Camcorder handle is not valid.");
+ Resolution result(DEFAULT_CAPTURE_WIDTH, DEFAULT_CAPTURE_HEIGHT);
+ try {
+ AttributeInfo::ArrayOfInt captureWidth =
+ AttributeInfo::toArrayOfInt(m_camcorderHandle, MMCAM_CAPTURE_WIDTH);
+
+ AttributeInfo::ArrayOfInt captureHeight =
+ AttributeInfo::toArrayOfInt(m_camcorderHandle, MMCAM_CAPTURE_HEIGHT);
+
+ if (!captureWidth.empty() && !captureHeight.empty()) {
+ if (low) {
+ result.setSize(captureWidth.front(), captureHeight.front());
+ } else {
+ result.setSize(captureWidth.back(), captureHeight.back());
+ }
+ }
+ }
+ catch (const Commons::Exception& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ LogDebug("Falling back to default resolution.");
+ }
+ 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.
+ */
+/*
+ * @author Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTPLUGINSCAMERA_H_
+#define WRTPLUGINSCAMERA_H_
+
+#include <string>
+#include <mm_types.h>
+#include <mm_error.h>
+#include <mm_camcorder.h>
+#include <dpl/log/log.h>
+#include <dpl/generic_event.h>
+#include <dpl/event/controller.h>
+#include <dpl/type_list.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/EventRequestLiveVideo.h>
+#include <platform/commons/Dimension.h>
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Camera {
+DECLARE_GENERIC_EVENT_0(JobDoneEvent)
+//=============================================================================
+class Camera : public Api::Camera::ICamera,
+ public DPL::Event::Controller<DPL::TypeListDecl<JobDoneEvent>::Type >
+{
+ public:
+ enum CameraState
+ {
+ IDLE, //camera is ready to take action
+ PROCESSING, //camera object is under destruction or performing some inner operations - can't change the state
+ CAPTURING_IMAGE, //image capture is in progress
+ CAPTURING_VIDEO //video capture is in progress
+ };
+
+ private:
+ typedef Dimension Resolution;
+
+ private:
+
+ /*setting some default attributes for camcorder*/
+ void setDefaultAttributes();
+ /*
+ * Sets camcorder attributes based on capture options
+ */
+ void setCaptureOptions(
+ const Api::Camera::ICaptureOptionsPtr &captureOptions);
+
+ /*
+ * checks if given error code means invalid parameter
+ */
+ void tryIsInvalidParameterError(int errorCode);
+
+ MMCamPreset m_camcorderPreset;
+
+ MMHandleType m_camcorderHandle;
+
+ /*
+ * Current camera state
+ */
+ CameraState m_state;
+
+ /*
+ * Mutex for m_state
+ */
+ pthread_mutex_t m_stateMutex;
+
+ int reInitializeCamcorderForPicture(
+ const Api::Camera::ICaptureOptionsPtr &captureOptions);
+
+ int reInitializeCamcorderForVideo(
+ const Api::Camera::ICaptureOptionsPtr &captureOptions);
+
+ /*
+ * Wrapper for realizing camcorder
+ */
+ bool realizeCamcoder();
+
+ /*
+ * Wrapper for unrealizing camcorder
+ */
+ int unRealizeCamcoder();
+
+ /* Body of the callback function msg_callback */
+ static int camcorderMessageCallback(int msg_type,
+ void *msg_param,
+ void *user_param);
+
+ static int camcorderVideoCaptureCallback(MMCamcorderCaptureDataType *src,
+ MMCamcorderCaptureDataType *thumb,
+ void *data);
+
+ CameraState getState() const
+ {
+ return m_state;
+ }
+
+ void setState(CameraState newState)
+ {
+ m_state = newState;
+ }
+
+ static int lockCameraMutex(Camera *camera);
+
+ static void unlockCameraMutex(Camera *camera);
+
+ /* logs current camcorder state*/
+ void logCamcorderState();
+
+ Resolution getCaptureResolution(bool low) const;
+
+ Api::Camera::EventTakePictureSharedPtr m_eventTakePicture;
+ Api::Camera::EventBeginRecordingSharedPtr m_eventBeginRecording;
+ Api::Camera::EventEndRecordingSharedPtr m_eventEndRecording;
+ Api::Camera::EventRequestLiveVideoSharedPtr m_eventRequestLiveVideo;
+
+ public:
+ Camera();
+ void init(MMCamPreset preset);
+ virtual ~Camera();
+
+ virtual void OnRequestReceived(
+ const Api::Camera::EventTakePictureSharedPtr &event);
+ virtual void OnRequestReceived(
+ const Api::Camera::EventBeginRecordingSharedPtr &event);
+ virtual void OnRequestReceived(
+ const Api::Camera::EventEndRecordingSharedPtr &event);
+ virtual void OnRequestReceived(
+ const Api::Camera::EventRequestLiveVideoSharedPtr &event);
+ virtual void OnEventReceived(const JobDoneEvent &event);
+
+ virtual std::string getDescription() const;
+};
+//=============================================================================
+}
+}
+}
+#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 Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "CameraManager.h"
+#include "mm_camcorder.h"
+#include <commons/Exception.h>
+#include <API/Camera/EventGetCameras.h>
+#include <API/Camera/ICamera.h>
+#include "Camera.h"
+
+namespace WrtPlugins {
+namespace Platform {
+namespace Camera {
+//.............................................................................
+void CameraManager::OnRequestReceived(
+ const Api::Camera::EventGetCamerasPtr &event)
+{
+ LogDebug(__FUNCTION__);
+ try
+ {
+ DPL::Mutex::ScopedLock lock(&m_accessMutex);
+ {
+ if (m_cameras.empty()) {
+ for (int i = (MM_VIDEO_DEVICE_NONE + 1);
+ i < MM_VIDEO_DEVICE_NUM;
+ ++i) {
+ LogDebug(
+ "current camera i=" << i <<
+ " (mm_video_device_num: " << MM_VIDEO_DEVICE_NUM);
+ MMCamPreset cam_info;
+ cam_info.videodev_type = static_cast<MMVideoDeviceType>(i);
+ Camera *icamera = new Camera();
+ m_cameras.push_back(Api::Camera::ICameraSharedPtr(icamera));
+ icamera->init(cam_info);
+ }
+ }
+ event->setCamerasRef(m_cameras, MM_VIDEO_DEVICE_CAMERA0);
+ }
+ LogDebug("Nr of cameras: " << m_cameras.size());
+ return;
+ }
+ catch (Commons::Exception &exc)
+ {
+ LogError("Exception has occurred: " << std::hex << exc.getCode());
+ event->setExceptionCode(exc.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.
+ */
+/*
+ * @author Karol Majewski (k.majewski@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTPLUGINSCAMERAMANAGER_H_
+#define WRTPLUGINSCAMERAMANAGER_H_
+
+#include <dpl/log/log.h>
+#include <dpl/mutex.h>
+
+#include <API/Camera/ICameraManager.h>
+#include <API/Camera/EventGetCameras.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+
+class CameraManager : public Camera::Api::ICameraManager
+{
+ private:
+ DPL::Mutex m_accessMutex;
+ public:
+ explicit CameraManager()
+ {
+ }
+ virtual ~CameraManager()
+ {
+ }
+ protected:
+ virtual void OnRequestReceived(
+ const Camera::Api::EventGetCamerasPtr &event);
+};
+
+}
+}
+#endif /* WRTPLUGINSCAMERAMANAGER_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(mm_camcorder REQUIRED mm-camcorder)
+#pkg_search_module(mmutil_imgp REQUIRED mmutil-imgp)
+#pkg_search_module(mmutil_jpeg REQUIRED mmutil-jpeg)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CAMERA
+ ${mm_camcorder_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CAMERA
+ ${CURRENT_PATH}/Camera.cpp
+ ${CURRENT_PATH}/CameraManager.cpp
+ ${CURRENT_PATH}/AttributeInfo.cpp
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CAMERA
+ ${mm_camcorder_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.
+ */
+#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
+!!!options!!! stop
+API implementation for tizen platform
--- /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();
+}
+
+}
+}
--- /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_COPYCOMMAND_H_
+#define WRTDEVICEAPIS_FILESYSTEM_COPYCOMMAND_H_
+
+#include "Command.h"
+#include <Filesystem/IPath.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class CopyCommand : public Command
+{
+ 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;
+};
+
+}
+}
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_COPYCOMMAND_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 "Manager.h"
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <pcrecpp.h>
+#include <ctime>
+#include <cstdio>
+#include <sstream>
+#include <dirent.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include <dpl/errno_string.h>
+#include <Commons/Exception.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 {
+const char* PATH_ROOT = "/opt/media";
+const char* PATH_DOWNLOADS = "/opt/media/Downloads";
+const char* PATH_DOCUMENTS = "/opt/media/Documents";
+const char* PATH_SOUNDS = "/opt/media/Music";
+const char* PATH_IMAGES = "/opt/media/Images";
+const char* PATH_VIDEOS = "/opt/media/Videos";
+const char* PATH_SDCARD = "/opt/storage/sdcard";
+}
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+using namespace Api;
+
+Manager::Locations Manager::m_locations;
+const std::size_t Manager::m_maxPathLength = 256;
+NodeList Manager::m_openedNodes;
+
+bool Manager::fileExists(const std::string &file)
+{
+ errno = 0;
+ struct stat info;
+ memset(&info, 0, sizeof(struct stat));
+ int status = lstat(file.c_str(), &info);
+ if (status == 0) {
+ return true;
+ } else if (errno == ENOENT) {
+ return false;
+ }
+ ThrowMsg(Commons::PlatformException, "Cannot stat file.");
+}
+
+void Manager::addOpenedNode(const INodePtr& node)
+{
+ NodeListIterator it = m_openedNodes.begin();
+ for (; it != m_openedNodes.end(); ++it) {
+ if (node.Get() == (*it).Get()) {
+ //node is added already
+ return;
+ }
+ }
+ m_openedNodes.push_back(node);
+}
+
+void Manager::removeOpenedNode(const INodePtr& node)
+{
+ NodeListIterator it = m_openedNodes.begin();
+ for (; it != m_openedNodes.end(); ++it) {
+ if ((*it).Get() == node.Get()) {
+ m_openedNodes.erase(it);
+ break;
+ }
+ }
+}
+
+bool Manager::checkIfOpened(const IPathPtr& path) const
+{
+ NodeListIterator it = m_openedNodes.begin();
+ for (; it != m_openedNodes.end(); ++it) {
+ if (*path == *(*it)->getPath()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+Manager::Manager()
+{
+ static bool initialized = init();
+ (void) initialized;
+}
+
+Manager::~Manager()
+{
+}
+
+IPathPtr Manager::getBasePath() const
+{
+ Locations::const_iterator it = m_locations.find(LT_ROOT);
+ if (it == m_locations.end()) {
+ ThrowMsg(Commons::PlatformException, "Base path not available.");
+ }
+ return it->second;
+}
+
+IPathPtr Manager::getLocationPath(LocationType type) const
+{
+ Locations::const_iterator it = m_locations.find(type);
+ if (it != m_locations.end()) {
+ return it->second->clone();
+ }
+ return IPathPtr();
+}
+
+LocationPaths Manager::getLocationPaths() const
+{
+ LocationPaths result;
+ Locations::const_iterator it = m_locations.begin();
+ for (; it != m_locations.end(); ++it) {
+ result.push_back(it->second->clone());
+ }
+ return result;
+}
+
+LocationTypes Manager::getLocations() const
+{
+ LocationTypes result;
+ Locations::const_iterator it = m_locations.begin();
+ for (; it != m_locations.end(); ++it) {
+ result.push_back(it->first);
+ }
+ return result;
+}
+
+void Manager::getNode(const EventResolvePtr& event)
+{
+ EventRequestReceiver<EventResolve>::PostRequest(event);
+}
+
+std::size_t Manager::getMaxPathLength() const
+{
+ return m_maxPathLength;
+}
+
+void Manager::copy(const EventCopyPtr& event)
+{
+ EventRequestReceiver<EventCopy>::PostRequest(event);
+}
+
+void Manager::move(const EventMovePtr& event)
+{
+ EventRequestReceiver<EventMove>::PostRequest(event);
+}
+
+void Manager::remove(const EventRemovePtr& event)
+{
+ EventRequestReceiver<EventRemove>::PostRequest(event);
+}
+
+void Manager::find(const EventFindPtr& event)
+{
+ EventRequestReceiver<EventFind>::PostRequest(event);
+}
+
+void Manager::find(const IPathPtr& path,
+ const FiltersMap& filters,
+ NodeList& result,
+ const EventFindPtr& event)
+{
+ Try {
+ DIR* dir = opendir(path->getFullPath().c_str());
+ if (!dir) {
+ return;
+ }
+
+ errno = 0;
+ struct dirent* entry = NULL;
+ while ((entry = readdir(dir))) {
+ if (event && event->checkCancelled()) {
+ break;
+ }
+ if (!strncmp(entry->d_name, ".",
+ 1) || !strncmp(entry->d_name, "..", 2)) {
+ continue;
+ }
+ IPathPtr childPath = *path + entry->d_name;
+ struct stat info;
+ memset(&info, 0, sizeof(struct stat));
+ if (lstat(childPath->getFullPath().c_str(), &info) == 0) {
+ if (matchFilters(entry->d_name, info, filters)) {
+ result.push_back(Node::resolve(childPath));
+ }
+ if (S_ISDIR(info.st_mode)) {
+ find(childPath, filters, result, event);
+ }
+ }
+ }
+
+ if (errno != 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while reading directory.");
+ }
+
+ if (closedir(dir) != 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Could not close platform node.");
+ }
+ }
+ Catch(Commons::Exception) {
+ }
+}
+
+bool Manager::access(const IPathPtr& path,
+ int accessType) const
+{
+ int amode = 0;
+ if (accessType & AT_EXISTS) { amode |= F_OK; }
+ if (accessType & AT_READ) { amode |= R_OK; }
+ if (accessType & AT_WRITE) { amode |= W_OK; }
+ if (accessType & AT_EXEC) { amode |= X_OK; }
+ return (::access(path->getFullPath().c_str(), amode) == 0);
+}
+
+bool Manager::matchFilters(const std::string& name,
+ const struct stat& info,
+ const FiltersMap& filters)
+{
+ FiltersMap::const_iterator it = filters.begin();
+ for (; it != filters.end(); ++it) {
+ if (it->first == FF_NAME) {
+ if (!pcrecpp::RE(it->second).PartialMatch(name)) { return false; }
+ } else if (it->first == FF_SIZE) {
+ std::size_t size;
+ std::stringstream ss(it->second);
+ ss >> size;
+ if (!ss ||
+ (size != static_cast<size_t>(info.st_size))) { return false; }
+ } else if (it->first == FF_CREATED) {
+ std::time_t created;
+ std::stringstream ss(it->second);
+ ss >> created;
+ if (!ss || (created != info.st_ctime)) { return false; }
+ } else if (it->first == FF_MODIFIED) {
+ std::time_t modified;
+ std::stringstream ss(it->second);
+ ss >> modified;
+ if (!ss || (modified != info.st_mtime)) { return false; }
+ }
+ }
+ return true;
+}
+
+void Manager::OnRequestReceived(const EventResolvePtr& event)
+{
+ try {
+ event->setResult(Node::resolve(event->getPath()));
+ }
+ catch (const Commons::PlatformException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ event->setCancelAllowed(true);
+}
+
+void Manager::OnRequestReceived(const EventCopyPtr& event)
+{
+ Try {
+ INodePtr srcNode = Node::resolve(event->getSource());
+ if ((srcNode->getMode() & PERM_READ) == 0) {
+ ThrowMsg(Commons::SecurityException,
+ "Not enough permissions to read source node.");
+ }
+
+ IPathPtr src = event->getSource();
+ IPathPtr dest = event->getDestination();
+ if (!dest->isAbsolute()) {
+ dest = src->getPath() + *dest;
+ }
+
+ if (src == dest) {
+ ThrowMsg(Commons::PlatformException,
+ "Destination is same as source.");
+ }
+
+ INodePtr parent;
+ Try {
+ parent = Node::resolve(IPath::create(dest->getPath()));
+ }
+ Catch(Commons::PlatformException) {
+ ReThrowMsg(Commons::PlatformException,
+ "Could not get destination's parent node.");
+ }
+
+ if (parent->getType() != NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException,
+ "Destination's parent node is not directory.");
+ }
+
+ std::string realSrc = src->getFullPath();
+ std::string realDest = dest->getFullPath();
+
+ errno = 0;
+ struct stat info;
+ memset(&info, 0, sizeof(struct stat));
+ int status = lstat(realDest.c_str(), &info);
+ if ((status != 0) && (errno != ENOENT)) {
+ ThrowMsg(Commons::PlatformException,
+ "No access to platform destination node.");
+ }
+
+ if (((event->getOptions() & OPT_OVERWRITE) == 0) && (status == 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->getOptions() & OPT_OVERWRITE) {
+ DPL::ScopedPtr<RemoveCommand> remove(new RemoveCommand(dest));
+ remove->setRecursive(true);
+ remove->setForce(true);
+ System::run(remove.Get());
+ }
+
+ DPL::ScopedPtr<CopyCommand> copy(new CopyCommand(src, dest));
+ copy->setRecursive(true);
+ System::run(copy.Get());
+
+ event->setResult(Node::resolve(dest));
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ Catch(Commons::SecurityException) {
+ event->setExceptionCode(Commons::ExceptionCodes::SecurityException);
+ }
+ //file is copied already so we don't allow cancelling anymore.
+ event->setCancelAllowed(false);
+}
+
+void Manager::OnRequestReceived(const EventMovePtr& event)
+{
+ try {
+ IPathPtr src = event->getSource();
+ IPathPtr dest = event->getDestination();
+
+ INodePtr srcNode = Node::resolve(src);
+ if ((srcNode->getMode() & PERM_WRITE) == 0)
+ {
+ ThrowMsg(Commons::SecurityException,
+ "Not enough permissions to move source node.");
+ }
+
+ if (!dest->isAbsolute()) {
+ dest = src->getPath() + *dest;
+ }
+
+ if (src == dest) {
+ ThrowMsg(Commons::PlatformException,
+ "Destination is same as source.");
+ }
+
+ INodePtr parent;
+ Try {
+ parent = Node::resolve(IPath::create(dest->getPath()));
+ }
+ Catch(Commons::PlatformException) {
+ ReThrowMsg(Commons::PlatformException,
+ "Could not get destination's parent node.");
+ }
+
+ if (parent->getType() != NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException,
+ "Destination's parent node is not directory.");
+ }
+
+ errno = 0;
+ struct stat info;
+ memset(&info, 0, sizeof(info));
+ int status = lstat(dest->getFullPath().c_str(), &info);
+ if ((status != 0) && (errno != ENOENT)) {
+ ThrowMsg(Commons::PlatformException,
+ "No access to platform destination node.");
+ }
+
+ if ((0 == (event->getOptions() & OPT_OVERWRITE)) && (0 == status)) {
+ ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
+ }
+
+ if (event->checkCancelled()) {
+ //file is not moved yet, so we can cancel it now.
+ event->setCancelAllowed(true);
+ return;
+ }
+
+ errno = 0;
+ if (0 != ::rename(src->getFullPath().c_str(),
+ dest->getFullPath().c_str()))
+ {
+ int error = errno;
+ switch (error)
+ {
+ case EXDEV:
+ {
+ if ((srcNode->getMode() & PERM_READ) == 0)
+ {
+ ThrowMsg(Commons::SecurityException,
+ "Not enough permissions to move source node.");
+ }
+ DPL::ScopedPtr<MoveCommand>
+ move(new MoveCommand(src, dest));
+ move->setForce(event->getOptions() & OPT_OVERWRITE);
+ System::run(move.Get());
+ break;
+ }
+ default:
+ ThrowMsg(Commons::PlatformException,
+ "Error on rename: " << DPL::GetErrnoString(error));
+ break;
+ }
+ }
+
+ event->setResult(Node::resolve(dest));
+ }
+ catch (const Commons::PlatformException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ catch (const Commons::SecurityException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::SecurityException);
+ }
+ event->setCancelAllowed(false);
+}
+
+void Manager::OnRequestReceived(const EventRemovePtr& event)
+{
+ if (!event->checkCancelled()) {
+ Try {
+ INodePtr node = Node::resolve(event->getPath());
+ 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);
+ }
+ event->setCancelAllowed(false);
+ } else {
+ event->setCancelAllowed(true);
+ }
+}
+
+void Manager::OnRequestReceived(const EventFindPtr& event)
+{
+ try {
+ NodeList result;
+ find(event->getPath(), event->getFilters(), result, event);
+ event->setResult(result);
+ }
+ catch (const Commons::Exception& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ event->setCancelAllowed(true);
+}
+
+bool Manager::init()
+{
+ m_locations[LT_ROOT] = IPath::create(PATH_ROOT);
+ m_locations[LT_SDCARD] = IPath::create(PATH_SDCARD);
+ setupLocation(LT_DOWNLOADS, PATH_DOWNLOADS);
+ setupLocation(LT_DOCUMENTS, PATH_DOCUMENTS);
+ setupLocation(LT_SOUNDS, PATH_SOUNDS);
+ setupLocation(LT_IMAGES, PATH_IMAGES);
+ setupLocation(LT_VIDEOS, PATH_VIDEOS);
+
+ return true;
+}
+
+void Manager::setupLocation(LocationType location,
+ const char* path)
+{
+ if (!nodeExists(path)) {
+ try {
+ makePath(path, 0755);
+ }
+ catch (const Commons::PlatformException& ex) {
+ LogError("Exception: " << ex.DumpToString());
+ return;
+ }
+ }
+ m_locations[location] = IPath::create(path);
+}
+
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_
+#define WRTDEVICEAPIS_FILESYSTEM_MANAGER_H_
+
+#include <map>
+#include <vector>
+#include <cstddef>
+#include <dpl/shared_ptr.h>
+#include <Filesystem/IManager.h>
+#include <Filesystem/IPath.h>
+#include "Node.h"
+#include "Path.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class Manager : public Api::IManager
+{
+ public:
+ /**
+ * Checks if file exists.
+ * @param real file path.
+ * @return true when file exists, false otherwise.
+ * @throw PlatformException If unable to validate if file exists.
+ */
+ static bool fileExists(const std::string &file);
+
+ public:
+ Manager();
+ ~Manager();
+
+ Api::IPathPtr getBasePath() const;
+
+ Api::IPathPtr getLocationPath(Api::LocationType type) const;
+
+ Api::LocationPaths getLocationPaths() const;
+
+ Api::LocationTypes getLocations() const;
+
+ void getNode(const Api::EventResolvePtr& event);
+
+ std::size_t getMaxPathLength() const;
+
+ void copy(const Api::EventCopyPtr& event);
+
+ void move(const Api::EventMovePtr& event);
+
+ void remove(const Api::EventRemovePtr& event);
+
+ void find(const Api::EventFindPtr& event);
+
+ /**
+ * Finds files in the filesystem whish match specified filters.
+ * @param path Starting path.
+ * @param filter Filters @see FindFilters.
+ * @param result List with found files.
+ * @param event DPL event, if set then search process can be cancelled
+ * @remarks For filter FF_NAME value is treated as perl like regex pattern.
+ * Use @Regex::escpae() if you want to treat it as normal string.
+ */
+ void find(const Api::IPathPtr& path,
+ const Api::FiltersMap& filter,
+ Api::NodeList& result,
+ const Api::EventFindPtr& event = Api::EventFindPtr(NULL));
+
+ /**
+ * @warning Operates on specified as it is - it DOES NOT take its real path.
+ * This is because all filesystem operation will probably change
+ * their approach to real path and will allow to refer to nodes
+ * only by virtual roots.
+ */
+ bool access(const Api::IPathPtr& path,
+ int accessType) const;
+
+ void addOpenedNode(const Api::INodePtr& node);
+ void removeOpenedNode(const Api::INodePtr& node);
+ bool checkIfOpened(const Api::IPathPtr& path) const;
+
+ protected:
+ bool matchFilters(const std::string& name,
+ const struct stat& info,
+ const Api::FiltersMap& filter);
+
+ void OnRequestReceived(const Api::EventResolvePtr& event);
+ void OnRequestReceived(const Api::EventCopyPtr& event);
+ void OnRequestReceived(const Api::EventMovePtr& event);
+ void OnRequestReceived(const Api::EventRemovePtr& event);
+ void OnRequestReceived(const Api::EventFindPtr& event);
+
+ private:
+ typedef std::map<Api::LocationType, Api::IPathPtr> Locations;
+
+ private:
+ /**
+ * Initializes statics of Manager class.
+ * Used only internally.
+ * @return True on success, false otherwsie.
+ */
+ static bool init();
+
+ static void setupLocation(Api::LocationType location,
+ const char* path);
+
+ private:
+ static Locations m_locations; ///< Paths to default locations.
+ static const std::size_t m_maxPathLength; ///< Maximum path length.
+ static Api::NodeList m_openedNodes; ///< List of nodes that has opened streams.
+};
+
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_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.
+ */
+/**
+ * @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();
+}
+
+}
+}
--- /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_MOVECOMMAND_H_
+#define WRTDEVICEAPIS_FILESYSTEM_MOVECOMMAND_H_
+
+#include "Command.h"
+#include <Filesystem/IPath.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class MoveCommand : public Command
+{
+ public:
+ MoveCommand(const Api::IPathPtr& src,
+ const Api::IPathPtr& dest);
+ void setForce(bool force);
+
+ protected:
+ std::string prepare();
+
+ private:
+ Api::IPathPtr m_src;
+ Api::IPathPtr m_dest;
+ bool m_force;
+};
+
+}
+}
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_MOVECOMMAND_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 "Node.h"
+#include <algorithm>
+#include <memory>
+#include <typeinfo>
+#include <sys/types.h>
+#include <cstdio>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+#include <pcrecpp.h>
+#include <sstream>
+#include <Commons/Exception.h>
+#include <Filesystem/PathUtils.h>
+#include <Filesystem/Enums.h>
+#include "Manager.h"
+#include "NodeFilterMatcher.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+using namespace Api;
+
+INodePtr Node::resolve(const IPathPtr& path)
+{
+ struct stat info;
+ if (lstat(path->getFullPath().c_str(), &info) != 0) {
+ LogError("File: " << path->getFullPath().c_str());
+ ThrowMsg(Commons::PlatformException,
+ "Node does not exist or access denied.");
+ }
+
+ if (!S_ISDIR(info.st_mode) & !S_ISREG(info.st_mode)) {
+ ThrowMsg(Commons::PlatformException,
+ "Platform node is of unsupported type.");
+ }
+
+ NodeType type = S_ISDIR(info.st_mode) ? NT_DIRECTORY : NT_FILE;
+ NodePtr result(new Node(path, type));
+ return DPL::StaticPointerCast<INode>(result);
+}
+
+IPathPtr Node::getPath() const
+{
+ return IPath::create(m_path->getFullPath());
+}
+
+INodePtr Node::getChild(const IPathPtr& path)
+{
+ if (m_type != NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException, "Not a directory.");
+ }
+ return Node::resolve(*m_path + *path);
+}
+
+NodeType Node::getType() const
+{
+ return m_type;
+}
+
+int Node::getPermissions() const
+{
+ return m_perms;
+}
+
+void Node::setPermissions(int perms)
+{
+ m_perms = perms;
+}
+
+Node::NameList Node::getChildNames() const
+{
+ if (m_type != NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException, "Node is not directory.");
+ }
+
+ if ((m_perms & PERM_READ) == 0) {
+ ThrowMsg(Commons::SecurityException, "No permission.");
+ }
+
+ DIR* dir = opendir(m_path->getFullPath().c_str());
+ if (!dir) {
+ ThrowMsg(Commons::PlatformException,
+ "Node has been deleted from platform.");
+ }
+
+ NameList result;
+ errno = 0;
+ struct dirent *entry = NULL;
+ while ((entry = readdir(dir))) {
+ if (!strncmp(entry->d_name, ".",
+ 1) || !strncmp(entry->d_name, "..", 2)) {
+ continue;
+ }
+ result.push_back(entry->d_name);
+ }
+ if (errno != 0) {
+ ThrowMsg(Commons::PlatformException, "Error while reading directory.");
+ }
+
+ if (closedir(dir) != 0) {
+ ThrowMsg(Commons::PlatformException, "Could not close platform node.");
+ }
+
+ return result;
+}
+
+NodeList Node::getChildNodes(const NodeFilterPtr& filter) const
+{
+ if (m_type != NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException, "Node is not directory.");
+ }
+
+ if ((m_perms & PERM_READ) == 0) {
+ ThrowMsg(Commons::SecurityException, "No permission.");
+ }
+
+ DIR* dir = opendir(m_path->getFullPath().c_str());
+ if (!dir) {
+ ThrowMsg(Commons::PlatformException,
+ "Node has been deleted from platform.");
+ }
+
+ errno = 0;
+ NodeList result;
+ struct dirent *entry = NULL;
+ while ((entry = readdir(dir))) {
+ if (!strncmp(entry->d_name, ".",
+ 1) || !strncmp(entry->d_name, "..", 2)) {
+ continue;
+ }
+ Try {
+ INodePtr node = Node::resolve(*m_path + entry->d_name);
+ node->setPermissions(getPermissions()); // inherit access rights
+ if (NodeFilterMatcher::match(node, filter)) {
+ result.push_back(node);
+ }
+ }
+ Catch(Commons::PlatformException) {
+ }
+ }
+
+ if (errno != 0) {
+ ThrowMsg(Commons::PlatformException, "Error while reading directory.");
+ }
+
+ if (closedir(dir) != 0) {
+ ThrowMsg(Commons::PlatformException, "Could not close platform node.");
+ }
+
+ return result;
+}
+
+void Node::getChildNodes(const EventListNodesPtr& event)
+{
+ LogDebug("ENTER");
+ EventRequestReceiver<EventListNodes>::PostRequest(event);
+}
+
+INodePtr Node::createChild(
+ const IPathPtr& path,
+ NodeType type,
+ int options)
+{
+ if (m_type != NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException, "Parent node is not a directory.");
+ }
+
+ if ((m_perms & PERM_WRITE) == 0) {
+ ThrowMsg(Commons::SecurityException, "Not enough permissions.");
+ }
+
+ IPathPtr childPath = *m_path + *path;
+ if (exists(childPath)) {
+ ThrowMsg(Commons::PlatformException, "Node already exists.");
+ }
+
+ NodePtr result;
+ switch (type) {
+ case NT_FILE:
+ result.Reset(createAsFile(childPath, options));
+ break;
+ case NT_DIRECTORY:
+ result.Reset(createAsDirectory(childPath, options));
+ break;
+ default:
+ ThrowMsg(Commons::PlatformException, "Unsupported node type.");
+ }
+ if (!!result) {
+ result->m_perms = m_perms;
+ } else {
+ ThrowMsg(Commons::PlatformException, "Node creation error");
+ }
+
+ return DPL::StaticPointerCast<INode>(result);
+}
+
+IStreamPtr Node::open(int mode)
+{
+ if (m_type == NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException,
+ "Cannot attach stream to directory.");
+ }
+
+ if (((mode & AM_READ) && ((m_perms & PERM_READ) == 0)) ||
+ (((mode & AM_WRITE) ||
+ (mode & AM_APPEND)) && ((m_perms & PERM_WRITE) == 0))) {
+ ThrowMsg(Commons::SecurityException, "Not enough permissions.");
+ }
+
+ DPL::Mutex::ScopedLock lock(&m_openStreamsMutex);
+ StreamPtr stream(new Stream(SharedFromThis(), mode));
+ m_openStreams.insert(stream);
+ IManager::getInstance().addOpenedNode(DPL::StaticPointerCast<INode>(
+ SharedFromThis()));
+ return DPL::StaticPointerCast<IStream>(stream);
+}
+
+void Node::open(const EventOpenPtr& event)
+{
+ LogDebug("ENTER");
+ EventRequestReceiver<EventOpen>::PostRequest(event);
+}
+
+void Node::remove(int options)
+{
+ switch (m_type) {
+ case NT_FILE:
+ removeAsFile(m_path);
+ break;
+ case NT_DIRECTORY:
+ removeAsDirectory(m_path, (options & OPT_RECURSIVE));
+ break;
+ }
+}
+
+std::size_t Node::getSize() const
+{
+ if (m_type == NT_DIRECTORY) {
+ ThrowMsg(Commons::PlatformException,
+ "Getting size for directories is not supported.");
+ }
+
+ struct stat info = stat(m_path);
+ if (!S_ISREG(info.st_mode)) {
+ ThrowMsg(Commons::PlatformException,
+ "Specified node is not a regular file.");
+ }
+
+ return info.st_size;
+}
+
+std::time_t Node::getCreated() const
+{
+ return stat(m_path).st_ctime;
+}
+
+std::time_t Node::getModified() const
+{
+ return stat(m_path).st_mtime;
+}
+
+// TODO Optimize it, maybe store a flag indicating that node is a root.
+INodePtr Node::getParent() const
+{
+ LocationPaths roots = IManager::getInstance().getLocationPaths();
+ for (LocationPaths::iterator it = roots.begin(); it != roots.end(); ++it) {
+ if (*(*it) == *m_path) {
+ return INodePtr();
+ }
+ }
+ return Node::resolve(IPath::create(m_path->getPath()));
+}
+
+int Node::getMode() const
+{
+ int result = 0;
+ struct stat info = stat(m_path);
+ if (info.st_mode & S_IRUSR) { result |= PM_USER_READ; }
+ if (info.st_mode & S_IWUSR) { result |= PM_USER_WRITE; }
+ if (info.st_mode & S_IXUSR) { result |= PM_USER_EXEC; }
+ if (info.st_mode & S_IRGRP) { result |= PM_GROUP_READ; }
+ if (info.st_mode & S_IWGRP) { result |= PM_GROUP_WRITE; }
+ if (info.st_mode & S_IXGRP) { result |= PM_GROUP_EXEC; }
+ if (info.st_mode & S_IROTH) { result |= PM_OTHER_READ; }
+ if (info.st_mode & S_IWOTH) { result |= PM_OTHER_WRITE; }
+ if (info.st_mode & S_IXOTH) { result |= PM_OTHER_EXEC; }
+ return result;
+}
+
+void Node::read(const EventReadTextPtr& event)
+{
+ LogDebug("ENTER");
+ EventRequestReceiver<EventReadText>::PostRequest(event);
+}
+
+void Node::onStreamClose(const StreamPtr& stream)
+{
+ {
+ DPL::Mutex::ScopedLock lock(&m_openStreamsMutex);
+ m_openStreams.erase(stream);
+ }
+ if (m_openStreams.empty()) {
+ IManager::getInstance().removeOpenedNode(DPL::StaticPointerCast<INode>(
+ SharedFromThis()));
+ }
+}
+
+bool Node::exists(const IPathPtr& path)
+{
+ struct stat info;
+ memset(&info, 0, sizeof(struct stat));
+ int status = lstat(path->getFullPath().c_str(), &info);
+ if ((status == 0) || ((status != 0) && (errno != ENOENT))) {
+ return true;
+ }
+ return false;
+}
+
+struct stat Node::stat(const IPathPtr& path)
+{
+ struct stat result;
+ memset(&result, 0, sizeof(struct stat));
+ if (::stat(path->getFullPath().c_str(),
+ &result) != 0)
+ {
+ LogError("File: " << path->getFullPath().c_str());
+ ThrowMsg(Commons::PlatformException, "Node does not exist or no access");
+ }
+ return result;
+}
+
+Node::Node(const IPathPtr& path,
+ NodeType type) :
+ m_path(path),
+ m_type(type),
+ m_perms(PERM_NONE)
+{
+}
+
+Node* Node::createAsFile(const IPathPtr& path,
+ int /* options */)
+{
+ LogDebug("ENTER");
+ createAsFileInternal(path);
+ return new Node(path, NT_FILE);
+}
+
+void Node::createAsFileInternal(const IPathPtr& path)
+{
+ LogDebug("ENTER");
+ FILE* file = std::fopen(path->getFullPath().c_str(), "wb");
+ if (!file) {
+ ThrowMsg(Commons::PlatformException,
+ "Platform node could not be created.");
+ }
+ std::fclose(file);
+}
+
+Node* Node::createAsDirectory(const IPathPtr& path,
+ int options)
+{
+ if (options & OPT_RECURSIVE) {
+ PathUtils::PathList parts = PathUtils::getParts(path);
+ PathUtils::PathListIterator it = parts.begin();
+ for (; it != parts.end(); ++it) {
+ if (!exists(*it)) { createAsDirectoryInternal(*it); }
+ }
+ }
+ createAsDirectoryInternal(path);
+ return new Node(path, NT_DIRECTORY);
+}
+
+void Node::createAsDirectoryInternal(const IPathPtr& path)
+{
+ if (mkdir(path->getFullPath().c_str(), S_IRWXU | S_IRWXG | S_IROTH |
+ S_IXOTH) != 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Platform node could not be created.");
+ }
+}
+
+void Node::removeAsFile(const IPathPtr& path)
+{
+ DPL::Mutex::ScopedLock lock(&m_openStreamsMutex);
+ if (!m_openStreams.empty()) {
+ ThrowMsg(Commons::PlatformException, "Node is locked for I/O.");
+ }
+ if (IManager::getInstance().checkIfOpened(path)) {
+ ThrowMsg(Commons::PlatformException, "Node is locked for I/O.");
+ }
+
+ if (unlink(path->getFullPath().c_str()) != 0) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while removing platform node.");
+ }
+}
+
+void Node::removeAsDirectory(const IPathPtr& path,
+ bool recursive)
+{
+ if (recursive) {
+ DIR* dir = opendir(path->getFullPath().c_str());
+ if (!dir) {
+ LogError("File: " << path->getFullPath().c_str());
+ ThrowMsg(Commons::PlatformException,
+ "Node does not exist or access denied.");
+ }
+ errno = 0;
+ struct dirent *entry = NULL;
+ while ((entry = readdir(dir))) {
+ if (!strncmp(entry->d_name, ".",
+ 1) || !strncmp(entry->d_name, "..", 2)) {
+ continue;
+ }
+ IPathPtr subPath = *path + entry->d_name;
+ struct stat info;
+ memset(&info, 0, sizeof(struct stat));
+ if (lstat(subPath->getFullPath().c_str(), &info) == 0) {
+ Try {
+ if (S_ISDIR(info.st_mode)) {
+ removeAsDirectory(subPath, true);
+ } else if (S_ISREG(info.st_mode)) {
+ removeAsFile(subPath);
+ }
+ }
+ Catch(Commons::PlatformException) {
+ }
+ // TODO: Not sure if above exception should be swallowed.
+ }
+ }
+ closedir(dir);
+ }
+
+ errno = 0;
+ if (rmdir(path->getFullPath().c_str()) != 0) {
+ if (errno == EEXIST) {
+ ThrowMsg(Commons::PlatformException, "Node has child nodes.");
+ }
+ ThrowMsg(Commons::PlatformException,
+ "Error while removing platform node.");
+ }
+}
+
+void Node::OnRequestReceived(const EventListNodesPtr& event)
+{
+ try {
+ NodeList list = event->getNode()->getChildNodes(event->getFilter());
+ event->setResult(list);
+ }
+ catch (const Commons::PlatformException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ catch (const Commons::SecurityException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::SecurityException);
+ }
+}
+
+void Node::OnRequestReceived(const EventOpenPtr& event)
+{
+ if (!event->checkCancelled()) {
+ try {
+ IStreamPtr result = open(event->getMode());
+ event->setResult(result);
+ }
+ catch (const Commons::PlatformException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ catch (const Commons::SecurityException& ex) {
+ LogError("Exception: " << ex.GetMessage());
+ event->setExceptionCode(Commons::ExceptionCodes::SecurityException);
+ }
+ //event can be cancelled before executing this code.
+ //when it comes here we doesn't allow it anymore
+ event->setCancelAllowed(false);
+ } else {
+ event->setCancelAllowed(true);
+ }
+}
+
+void Node::OnRequestReceived(const EventReadTextPtr& event)
+{
+ Try {
+ event->setResult(readText());
+ LogDebug("LEAVIN GRACEFULLY");
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ Catch(Commons::SecurityException) {
+ event->setExceptionCode(Commons::ExceptionCodes::SecurityException);
+ }
+ //this function doesn't change state of the platform,
+ //so we can allow to cancel it and discard results.
+ event->setCancelAllowed(true);
+}
+
+std::string Node::readText()
+{
+ if (m_type != NT_FILE) {
+ ThrowMsg(Commons::PlatformException, "Node is not a file.");
+ }
+
+ if ((m_perms & PERM_READ) == 0) {
+ ThrowMsg(Commons::SecurityException, "No permission.");
+ }
+
+ std::stringstream result;
+ DPL::SharedPtr<Stream> stream(new Stream(SharedFromThis(), AM_READ));
+ while (!stream->isEof()) {
+ result << stream->getLine();
+ if(!stream->isEof())
+ result << '\n';
+ }
+ stream->close();
+ return result.str();
+}
+
+std::string Node::toUri(int /*widgetId*/) const
+{
+ // TODO I believe moving this feature to WrtWrapper would make more sense.
+ return "file://" + m_path->getFullPath();
+}
+
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_NODE_H_
+#define WRTDEVICEAPIS_FILESYSTEM_NODE_H_
+
+#include <ctime>
+#include <cstddef>
+#include <sys/stat.h>
+#include <set>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include <dpl/mutex.h>
+
+#include <Filesystem/Enums.h>
+#include <Filesystem/INode.h>
+#include "Path.h"
+#include "Stream.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class Node :
+ public Api::INode,
+ public DPL::EnableSharedFromThis<Node>
+{
+ public:
+ static Api::INodePtr resolve(const Api::IPathPtr& path);
+
+ public:
+ Api::IPathPtr getPath() const;
+ Api::NodeType getType() const;
+ int getPermissions() const;
+ void setPermissions(int perms);
+ std::size_t getSize() const;
+ std::time_t getCreated() const;
+ std::time_t getModified() const;
+ Api::INodePtr getParent() const;
+ int getMode() const;
+
+ Api::INodePtr getChild(const Api::IPathPtr& path);
+ NameList getChildNames() const;
+ Api::NodeList getChildNodes(
+ const Api::NodeFilterPtr& filter = Api::NodeFilterPtr()) const;
+ void getChildNodes(const Api::EventListNodesPtr& event);
+ Api::INodePtr createChild(const Api::IPathPtr & path,
+ Api::NodeType,
+ int options);
+ Api::IStreamPtr open(int mode);
+ void open(const Api::EventOpenPtr& event);
+ void remove(int options);
+ void read(const Api::EventReadTextPtr& event);
+
+ void onStreamClose(const StreamPtr& stream);
+
+ private:
+ typedef std::set<StreamPtr> StreamList;
+
+ private:
+ static bool exists(const Api::IPathPtr& path);
+ static struct stat stat(const Api::IPathPtr& path);
+
+ private:
+ Node(const Api::IPathPtr& path, Api::NodeType type);
+
+ Node* createAsFile(const Api::IPathPtr& path,
+ int options);
+ void createAsFileInternal(const Api::IPathPtr& path);
+
+ Node* createAsDirectory(const Api::IPathPtr& path,
+ int options);
+ void createAsDirectoryInternal(const Api::IPathPtr& path);
+
+ void removeAsFile(const Api::IPathPtr& path);
+ void removeAsDirectory(const Api::IPathPtr& path,
+ bool recursive);
+
+ void OnRequestReceived(const Api::EventListNodesPtr& event);
+ void OnRequestReceived(const Api::EventOpenPtr& event);
+
+ void OnRequestReceived(const Api::EventReadTextPtr& event);
+ std::string readText();
+
+ std::string toUri(int widgetId) const;
+
+ private:
+ Api::IPathPtr m_path;
+ Api::NodeType m_type;
+ int m_perms;
+ StreamList m_openStreams;
+ mutable DPL::Mutex m_openStreamsMutex;
+};
+
+typedef DPL::SharedPtr<Node> NodePtr;
+
+} // Filesystem
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_FILESYSTEM_NODE_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 "NodeFilterMatcher.h"
+
+#include <pcrecpp.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+using namespace Api;
+
+bool NodeFilterMatcher::match(const INodePtr& value,
+ const NodeFilterPtr& filter)
+{
+ if (filter) {
+ if (!matchString(value->getPath()->getName(), filter->getName())) {
+ return false;
+ }
+
+ if (!matchRange(value->getCreated(),
+ filter->getMinCreated(),
+ filter->getMaxCreated())) {
+ return false;
+ }
+
+ if (!matchRange(value->getModified(),
+ filter->getMinModified(),
+ filter->getMaxModified())) {
+ return false;
+ }
+
+ if (!matchRange(value->getSize(),
+ filter->getMinSize(),
+ filter->getMaxSize())) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool NodeFilterMatcher::matchString(const std::string& value,
+ const OptionalString& filter)
+{
+ if (!filter.IsNull()) {
+ return pcrecpp::RE(*filter).PartialMatch(value);
+ }
+ return true;
+}
+
+template<typename Type>
+bool NodeFilterMatcher::matchRange(const Type& value,
+ const DPL::Optional<Type>& min,
+ const DPL::Optional<Type>& max)
+{
+ if ((!min.IsNull() && (value < *min)) ||
+ (!max.IsNull() && (value > *max))) {
+ return false;
+ }
+ return true;
+}
+
+} // Filesystem
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_FILESYSTEM_NODEFILTERMATCHER_H_
+#define WRTDEVICEAPIS_FILESYSTEM_NODEFILTERMATCHER_H_
+
+#include <string>
+#include <dpl/optional.h>
+#include <Filesystem/INode.h>
+#include <Filesystem/NodeFilter.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class NodeFilterMatcher
+{
+ public:
+ static bool match(const Api::INodePtr& value,
+ const Api::NodeFilterPtr& filter);
+
+ private:
+ static bool matchString(const std::string& value,
+ const Api::OptionalString& filter);
+
+ template<typename Type>
+ static bool matchRange(const Type& value,
+ const DPL::Optional<Type>& min,
+ const DPL::Optional<Type>& max);
+
+ private:
+ NodeFilterMatcher();
+};
+
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_NODEFILTERMATCHER_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 <memory>
+#include <algorithm>
+#include <iterator>
+#include <stdlib.h>
+#include <limits.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <Commons/StringUtils.h>
+#include "Path.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+using namespace Api;
+
+const Path::SeparatorType Path::m_pathSeparator = '/';
+
+IPathPtr Path::create(const std::string& path)
+{
+ DPL::SharedPtr<Path> result(new Path());
+ result->reset(path);
+ return DPL::StaticPointerCast<IPath>(result);
+}
+
+std::string Path::getFullPath() const
+{
+ return m_fullPath;
+}
+
+std::string Path::getPath() const
+{
+ return m_path;
+}
+
+std::string Path::getName() const
+{
+ return m_name;
+}
+
+IPathPtr Path::append(const std::string& path)
+{
+ reset(m_fullPath + m_pathSeparator + path);
+ return DPL::StaticPointerCast<IPath>(SharedFromThis());
+}
+
+IPathPtr Path::append(const IPathPtr& path)
+{
+ reset(m_fullPath + m_pathSeparator + path->getFullPath());
+ return DPL::StaticPointerCast<IPath>(SharedFromThis());
+}
+
+bool Path::isAbsolute() const
+{
+ return (!m_fullPath.empty() && (m_fullPath[0] == m_pathSeparator));
+}
+
+IPath::SeparatorType Path::getSeparator()
+{
+ return m_pathSeparator;
+}
+
+bool Path::isValid(const std::string& str)
+{
+ return !str.empty();
+}
+
+IPathPtr Path::clone() const
+{
+ return Path::create(m_fullPath);
+}
+
+Path::Path()
+{
+}
+
+void Path::reset(const std::string& str)
+{
+ if (!isValid(str)) {
+ ThrowMsg(Commons::InvalidArgumentException,
+ "Not a valid path: " + str + ".");
+ }
+
+ std::string tmp = Commons::String::unique(Commons::String::trim(
+ str), m_pathSeparator);
+ std::string::size_type pos = tmp.find_last_of(m_pathSeparator);
+ if (pos == std::string::npos) {
+ m_fullPath = m_name = tmp;
+ m_path.clear();
+ } else {
+ if (0 == pos) {
+ m_fullPath = m_path = m_pathSeparator;
+ } else {
+ m_fullPath = m_path = tmp.substr(0, pos);
+ m_fullPath += m_pathSeparator;
+ }
+ m_name = tmp.substr(pos + 1);
+ m_fullPath += m_name;
+ }
+}
+
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_PATH_H_
+#define WRTDEVICEAPIS_FILESYSTEM_PATH_H_
+
+#include <string>
+#include <vector>
+#include <dpl/enable_shared_from_this.h>
+#include <Filesystem/IPath.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class Path : public Api::IPath,
+ public DPL::EnableSharedFromThis<Path>
+{
+ public:
+ static Api::IPathPtr create(const std::string& path);
+ static Api::IPath::SeparatorType getSeparator();
+
+ public:
+ std::string getFullPath() const;
+ std::string getPath() const;
+ std::string getName() const;
+ Api::IPathPtr append(const std::string& path);
+ Api::IPathPtr append(const Api::IPathPtr& path);
+ bool isAbsolute() const;
+ Api::IPathPtr clone() const;
+
+ private:
+ /**
+ * Checks whether specified string is a valid path.
+ * @param path String to verify.
+ * @return True when string is a valid path, false otherwise.
+ */
+ static bool isValid(const std::string& str);
+
+ private:
+ Path();
+ void reset(const std::string& str);
+
+ private:
+ static const SeparatorType m_pathSeparator; ///< Path separator.
+
+ private:
+ std::string m_fullPath; ///< Full path.
+ std::string m_path; ///< Base path.
+ std::string m_name; ///< Last part of the path.
+};
+
+} // Filesystem
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_FILESYSTEM_PATH_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 "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
--- /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_REMOVECOMMAND_H_
+#define WRTDEVICEAPIS_FILESYSTEM_REMOVECOMMAND_H_
+
+#include "Command.h"
+#include <Filesystem/IPath.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class RemoveCommand : public Command
+{
+ public:
+ explicit RemoveCommand(const Api::IPathPtr& path);
+ void setRecursive(bool recursive);
+ void setForce(bool force);
+
+ protected:
+ std::string prepare();
+
+ private:
+ Api::IPathPtr m_path;
+ bool m_recursive;
+ bool m_force;
+};
+
+} // Filesystem
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_FILESYSTEM_REMOVECOMMAND_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 "Stream.h"
+#include <stdio.h>
+#include <new>
+#include <dpl/assert.h>
+#include <dpl/scoped_array.h>
+#include <Commons/Exception.h>
+#include "Manager.h"
+#include "Node.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+using namespace Api;
+
+Stream::Stream(const NodePtr& parent,
+ int mode) :
+ m_parent(parent),
+ m_mode(mode)
+{
+ Assert(m_parent && "Stream needs to have parent.");
+
+ std::ios_base::openmode mode_ = std::ios_base::binary;
+ if (mode & AM_READ) { mode_ |= std::ios_base::in; }
+ if (mode & AM_WRITE) { mode_ |= std::ios_base::out; } else if (mode &
+ AM_APPEND) {
+ mode_ |= (std::ios_base::app | std::ios_base::out);
+ }
+
+ m_stream.open(m_parent->getPath()->getFullPath().c_str(), mode_);
+ if (!m_stream) {
+ ThrowMsg(Commons::PlatformException, "Could not open stream.");
+ }
+}
+
+Stream::~Stream()
+{
+ close();
+}
+
+IStreamPtr Stream::write(bool arg)
+{
+ return write_(arg);
+}
+
+IStreamPtr Stream::write(unsigned char arg)
+{
+ return write_(arg);
+}
+
+IStreamPtr Stream::write(char arg)
+{
+ return write_(arg);
+}
+
+IStreamPtr Stream::write(int arg)
+{
+ return write_(arg);
+}
+
+IStreamPtr Stream::write(double arg)
+{
+ return write_(arg);
+}
+
+IStreamPtr Stream::write(const std::string& arg)
+{
+ return write_(arg);
+}
+
+IStreamPtr Stream::read(bool& arg)
+{
+ return read_(arg);
+}
+
+IStreamPtr Stream::read(unsigned char& arg)
+{
+ return read_(arg);
+}
+
+IStreamPtr Stream::read(char& arg)
+{
+ return read_(arg);
+}
+
+IStreamPtr Stream::read(int& arg)
+{
+ return read_(arg);
+}
+
+IStreamPtr Stream::read(double& arg)
+{
+ return read_(arg);
+}
+
+IStreamPtr Stream::read(std::string& arg)
+{
+ return read_(arg);
+}
+
+char* Stream::getChars(std::size_t num)
+{
+ checkForReading();
+
+ std::size_t maxChars = num + 1;
+ DPL::ScopedArray<char> result;
+ Try {
+ result.Reset(new char[maxChars]);
+ }
+ Catch(std::bad_alloc) {
+ ThrowMsg(Commons::PlatformException, "Couldn't allocate output buffer.");
+ }
+ if (m_stream.get(result.Get(), maxChars).bad()) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while reading from the stream.");
+ }
+
+ return result.Release();
+}
+
+unsigned char* Stream::getBytes(std::size_t num)
+{
+ checkForReading();
+
+ DPL::ScopedArray<char> buffer;
+ Try {
+ buffer.Reset(new char[num]);
+ }
+ Catch(std::bad_alloc) {
+ ThrowMsg(Commons::PlatformException, "Couldn't allocate output buffer.");
+ }
+ if (m_stream.read(buffer.Get(), num).bad()) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while reading from the stream.");
+ }
+
+ return static_cast<unsigned char*>(static_cast<void*>(buffer.Release()));
+}
+
+std::size_t Stream::getCount() const
+{
+ if (!isOpen()) {
+ ThrowMsg(Commons::PlatformException, "Stream is closed.");
+ }
+
+ if (!isReadable()) {
+ ThrowMsg(Commons::PlatformException, "Stream is not readable.");
+ }
+
+ return m_stream.gcount();
+}
+
+std::string Stream::getLine()
+{
+ checkForReading();
+
+ std::string result;
+ std::getline(m_stream, result);
+
+ return result;
+}
+
+bool Stream::isOpen() const
+{
+ return m_stream.is_open();
+}
+
+bool Stream::isEof() const
+{
+ return m_stream.eof();
+}
+
+void Stream::close()
+{
+ if (isOpen()) {
+ m_stream.close();
+ m_parent->onStreamClose(SharedFromThis());
+ }
+}
+
+int Stream::getMode() const
+{
+ return m_mode;
+}
+
+long Stream::getPosition() const
+{
+ return static_cast<long>(m_stream.tellg());
+}
+
+void Stream::setPosition(long position)
+{
+ if (m_stream.rdstate() & std::ios_base::eofbit) {
+ m_stream.clear();
+ }
+ if (!(m_stream.seekg(position)) || !(m_stream.seekp(position))) {
+ ThrowMsg(Commons::PlatformException, "Could not set position.");
+ }
+}
+
+long Stream::getSize() const
+{
+ std::fstream::streampos pos = m_stream.tellg();
+ if (pos == -1) {
+ return -1;
+ }
+
+ if (!m_stream.seekg(0, std::_S_end)) {
+ return -1;
+ }
+
+ long result = m_stream.tellg();
+ m_stream.seekg(pos, std::_S_beg);
+
+ return (result == -1 ? result : result + 1);
+}
+
+template<typename T>
+IStreamPtr Stream::write_(T arg)
+{
+ checkForWriting();
+
+ if (!(m_stream << arg)) {
+ LogError("Error while writing to the stream.");
+ ThrowMsg(Commons::PlatformException,
+ "Error while writing to the stream.");
+ }
+ m_stream.flush();
+
+ return DPL::StaticPointerCast<IStream>(SharedFromThis());
+}
+
+template<typename T>
+IStreamPtr Stream::read_(T& arg)
+{
+ checkForReading();
+
+ if (!(m_stream >> arg)) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while reading from the stream.");
+ }
+
+ return DPL::StaticPointerCast<IStream>(SharedFromThis());
+}
+
+bool Stream::isReadable() const
+{
+ return (m_mode & AM_READ);
+}
+
+bool Stream::isWriteable() const
+{
+ return ((m_mode & AM_WRITE) || (m_mode & AM_APPEND));
+}
+
+void Stream::checkForReading() const
+{
+ if (!isOpen()) {
+ ThrowMsg(Commons::PlatformException, "Stream is closed.");
+ }
+
+ if (isEof()) {
+ ThrowMsg(Commons::PlatformException, "Stream is marked as EOF.");
+ }
+
+ if (!isReadable()) {
+ ThrowMsg(Commons::PlatformException, "Stream is not readable.");
+ }
+}
+
+void Stream::checkForWriting() const
+{
+ if (!isOpen()) {
+ LogError("Stream is closed.");
+ ThrowMsg(Commons::PlatformException, "Stream is closed.");
+ }
+
+ if (!isWriteable()) {
+ LogError("Stream is not writeable.");
+ ThrowMsg(Commons::PlatformException, "Stream is not writeable.");
+ }
+}
+
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_STREAM_H_
+#define WRTDEVICEAPIS_FILESYSTEM_STREAM_H_
+
+#include <cstddef>
+#include <fstream>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include <Filesystem/IStream.h>
+#include <Filesystem/Enums.h>
+#include <Filesystem/INode.h>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+class Node;
+typedef DPL::SharedPtr<Node> NodePtr;
+
+class Stream :
+ public Api::IStream,
+ public DPL::EnableSharedFromThis<Stream>
+{
+ friend class Node;
+
+ public:
+ ~Stream();
+
+ Api::IStreamPtr write(bool arg);
+ Api::IStreamPtr write(unsigned char arg);
+ Api::IStreamPtr write(char arg);
+ Api::IStreamPtr write(int arg);
+ Api::IStreamPtr write(double arg);
+ Api::IStreamPtr write(const std::string& arg);
+
+ Api::IStreamPtr read(bool& arg);
+ Api::IStreamPtr read(unsigned char& arg);
+ Api::IStreamPtr read(char& arg);
+ Api::IStreamPtr read(int& arg);
+ Api::IStreamPtr read(double& arg);
+ Api::IStreamPtr read(std::string& arg);
+
+ /**
+ * @throw PlatformException If unable to read from the stream.
+ */
+ unsigned char* getBytes(std::size_t num);
+
+ std::size_t getCount() const;
+
+ /**
+ * @throw PlatformException If unable to read from the stream.
+ */
+ char* getChars(std::size_t num);
+
+ std::string getLine();
+
+ bool isOpen() const;
+ bool isEof() const;
+
+ void close();
+
+ long getPosition() const;
+ void setPosition(long position);
+
+ int getMode() const;
+
+ long getSize() const;
+
+ private:
+ template<typename T>
+ Api::IStreamPtr read_(T& arg);
+ template<typename T>
+ Api::IStreamPtr write_(T arg);
+
+ inline bool isReadable() const;
+ inline bool isWriteable() const;
+ void checkForReading() const;
+ void checkForWriting() const;
+
+ private:
+ Stream(const NodePtr& parent,
+ int mode);
+
+ private:
+ NodePtr m_parent;
+ int m_mode;
+ mutable std::fstream m_stream;
+};
+
+typedef DPL::SharedPtr<Stream> StreamPtr;
+
+} // Filesystem
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_FILESYSTEM_STREAM_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 "System.h"
+#include <stdlib.h>
+#include <string.h>
+#include "Command.h"
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+void System::run(Command* cmd)
+{
+ cmd->execute();
+}
+
+} // Filesystem
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_FILESYSTEM_SYSTEM_H_
+#define WRTDEVICEAPIS_FILESYSTEM_SYSTEM_H_
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+ class Command;
+
+// TODO Refactor - make it a singleton.
+class System
+{
+ public:
+ static void run(Command* cmd);
+};
+
+} //Filesystem
+} //WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_FILESYSTEM_SYSTEM_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 Utils.cpp
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ * @version 1.0
+ */
+
+#include <sys/stat.h>
+#include <cerrno>
+#include <cstring>
+#include <cstdlib>
+#include <unistd.h>
+#include <Commons/Exception.h>
+#include "Utils.h"
+
+namespace {
+int try_mkdir(const char* path,
+ mode_t mode)
+{
+ struct stat st;
+ int err = 0;
+
+ if (::stat(path, &st) != 0) {
+ if (::mkdir(path, mode) != 0) {
+ err = -1;
+ }
+ } else if (!S_ISDIR(st.st_mode)) {
+ errno = ENOTDIR;
+ err = -1;
+ }
+
+ return err;
+}
+
+int mkpath(const char* path,
+ mode_t mode)
+{
+ char* copy = ::strdup(path);
+ if (NULL == copy) {
+ return -1;
+ }
+
+ int err = 0;
+ char* ptr = copy;
+ char* slash = NULL;
+
+ while ((0 == err) && (NULL != (slash = ::strchr(ptr, '/')))) {
+ if (slash != ptr) {
+ *slash = '\0';
+ err = try_mkdir(copy, mode);
+ *slash = '/';
+ }
+ ptr = slash + 1;
+ }
+
+ if (0 == err) {
+ err = try_mkdir(path, mode);
+ }
+
+ ::free(copy);
+ return err;
+}
+}
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+bool nodeExists(const std::string& path)
+{
+ struct stat info;
+ if (stat(path.c_str(), &info) == 0) {
+ if (S_ISDIR(info.st_mode)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void makePath(const std::string& path,
+ mode_t mode)
+{
+ if (mkpath(path.c_str(), mode) == -1) {
+ ThrowMsg(Commons::PlatformException, "Couldn't create path: " << path);
+ }
+}
+
+}
+}
--- /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 Utils.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ * @version 1.0
+ */
+
+#ifndef WRTDEVICEAPIS_FILESYSTEM_UTILS_H_
+#define WRTDEVICEAPIS_FILESYSTEM_UTILS_H_
+
+#include <sys/types.h>
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Filesystem {
+
+bool nodeExists(const std::string& path);
+
+void makePath(const std::string& path, mode_t mode);
+
+}
+}
+
+#endif
--- /dev/null
+get_current_path()
+
+pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_FILESYSTEM
+ ${pcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM
+ ${pcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_FILESYSTEM
+ ${CURRENT_PATH}/Manager.cpp
+ ${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
+)
--- /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 <Commons/Exception.h>
+#include "Manager.h"
+
+namespace {
+const std::size_t NUMBER_OF_AVAILABLE_MOTORS = 2;
+} // anonymous
+
+namespace WrtDeviceApis {
+namespace Haptics {
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Motor* Manager::getMotor(std::size_t index) const
+{
+ switch (index) {
+ case 0:
+ return new Motor(DEV_IDX_ALL);
+ case 1:
+ return new Motor(DEV_IDX_0);
+ case 2:
+ return new Motor(DEV_IDX_1);
+ }
+ ThrowMsg(Commons::OutOfRangeException, "Motor unavailable.");
+}
+
+std::size_t Manager::getMotorsCount() const
+{
+ return NUMBER_OF_AVAILABLE_MOTORS;
+}
+
+Manager::Manager()
+{
+}
+} // Haptics
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_HAPTICS_MANAGER_H_
+#define WRTDEVICEAPIS_HAPTICS_MANAGER_H_
+
+#include <cstddef>
+#include <Haptics/IManager.h>
+#include "Motor.h"
+
+namespace WrtDeviceApis {
+namespace Haptics {
+class Manager : public Api::IManager
+{
+ public:
+
+ /**
+ * Gets class definition getInstance.
+ * @remarks set before.
+ * @return Class Manager instance.
+ */
+
+ static Manager& getInstance();
+
+ public:
+
+ /**
+ * Gets Motor pointer which find by index
+ * @remarks set before.
+ * @return Class Motor pointer
+ */
+ Motor* getMotor(std::size_t index) const;
+
+ /**
+ * Gets Motors Count
+ * @remarks set before.
+ * @return size_t type
+ */
+
+ std::size_t getMotorsCount() const;
+
+ private:
+ Manager();
+};
+} // Haptics
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_HAPTICS_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.
+ */
+/*
+ * @file Motor.cpp
+ * @modify Lileiming (leiming.li@samsung.com)
+ * @version 0.1
+ * @brief add function run_beep &stop_beep
+ */
+
+#include <Commons/Exception.h>
+#include <VConf/Key.h>
+#include <sys/utsname.h>
+#include <fstream>
+#include "Motor.h"
+#include <mmf/mm_sound_private.h>
+
+namespace WrtDeviceApis {
+namespace Haptics {
+namespace {
+const int INVALID_BEEP_HANDLER = -1;
+}
+
+Motor::Motor(haptic_dev_idx index) :
+ EventHapticActionReqReceiver(Commons::ThreadEnum::HAPTICS_THREAD),
+ EventStartMotorReqReceiver(Commons::ThreadEnum::HAPTICS_THREAD),
+ EventPlayBeepReqReceiver(Commons::ThreadEnum::HAPTICS_THREAD),
+ m_beepHandle(INVALID_BEEP_HANDLER)
+{
+ m_device = device_haptic_open(index, 0);
+ if (m_device < 0) {
+ ThrowMsg(Commons::PlatformException, "Could not open haptic device.");
+ }
+}
+
+Motor::~Motor()
+{
+ if (device_haptic_close(m_device) < 0) {
+ LogDebug("Could not close haptic device.");
+ }
+}
+
+int Motor::playBeep(unsigned long duration,
+ int /*volume*/)
+{
+ int retMmSound = -1;
+
+ retMmSound = mm_sound_play_tone(MM_SOUND_TONE_PROP_BEEP, VOLUME_TYPE_SYSTEM, 1, duration, &m_beepHandle);
+// retMmSound = mm_sound_play_beep(VOLUME_TYPE_SYSTEM, duration, &m_beepHandle);
+ if (retMmSound < 0) {
+ m_beepHandle = INVALID_BEEP_HANDLER;
+ ThrowMsg(Commons::PlatformException, "Play Beep is Failed!");
+ }
+
+ return retMmSound;
+}
+
+void Motor::playBeep(const Api::EventPlayBeepPtr& event)
+{
+ EventPlayBeepReqReceiver::PostRequest(event);
+}
+
+void Motor::stopBeep()
+{
+ if (m_beepHandle == INVALID_BEEP_HANDLER) {
+ LogError("m_beepHandle is wrong!!");
+ ThrowMsg(Commons::PlatformException, "m_beepHandle is wrong!!");
+ }
+ if (mm_sound_stop_sound(m_beepHandle) != 0) {
+ LogError("mm_sound_stop_sound FAIL!!");
+ ThrowMsg(Commons::PlatformException, "mm_sound_stop_sound FAIL!!");
+ }
+ m_beepHandle = INVALID_BEEP_HANDLER;
+}
+
+void Motor::run(unsigned long duration)
+{
+ if (device_haptic_play_monotone(m_device, duration) != 0) {
+ ThrowMsg(Commons::PlatformException, "Could not run haptic motor.");
+ }
+}
+
+void Motor::run(const Api::HapticPatternPtr& pattern)
+{
+ LogInfo("Entered!");
+
+ m_pattern.Reset();
+ if (!pattern || 0 == pattern->length()) {
+ return; // nothing to do
+ }
+ m_current = 0;
+ m_pattern = pattern;
+ if (m_event) {
+ LogDebug("Wait current event! And then run Next pattern!");
+ return;
+ }
+ runNextPattern();
+}
+
+void Motor::run(const Api::EventStartMotorPtr& event)
+{
+ EventStartMotorReqReceiver::PostRequest(event);
+}
+
+void Motor::stopMotor()
+{
+ if (device_haptic_stop_play(m_device) != 0) {
+ LogError("Haptic motor stop fail!");
+ ThrowMsg(Commons::PlatformException, "Could not stop haptic motor.");
+ }
+}
+
+void Motor::stopVibration()
+{
+ LogDebug("Entered!");
+
+ /* Stop pattern */
+ if (m_pattern) {
+ m_current = m_pattern->length();
+ }
+
+ /* Stop Motor */
+ stopMotor();
+}
+
+void Motor::OnRequestReceived(const EventHapticActionPtr& event)
+{
+ LogInfo("Haptic action event received");
+
+ DPL::Mutex::ScopedLock lock(&m_patternMutex);
+ if (event->checkCancelled()) {
+ LogWarning("Haptic pattern canceled by another one");
+ return; // event has been canceled by another Motor::run -> nothing to do
+ }
+
+ runNextPattern();
+}
+
+void Motor::OnRequestReceived(const Api::EventStartMotorPtr& event)
+{
+ LogInfo("Start motor event received");
+ try
+ {
+ if (event == NULL) {
+ LogError("Event is NULL!");
+ ThrowMsg(Commons::PlatformException, "Event is NULL!!");
+ }
+
+ unsigned long duration = 0;
+ Api::HapticPatternPtr patternPtr = event->getPatternRef();
+ size_t patternLength = patternPtr->length();
+
+ if (event->getDuration() > 0) {
+ // Ignore duration if duration is lower than 0
+ duration = event->getDuration();
+ }
+
+ if ((duration > 0) && (patternLength == 0)) {
+ // run motor during duration
+ run(duration);
+ } else if ((duration == 0) && (patternLength > 0)) {
+ // run motor by pattern
+ run(patternPtr);
+ } else if ((duration > 0) && (patternLength > 0)) {
+ // run motor by pattern during duration
+ arragePattern(patternPtr, duration);
+ run(patternPtr);
+ } else {
+ LogDebug("duration is 0 and pattern is null!!! Do Nothing!");
+ }
+ }
+ catch (Commons::PlatformException) {
+ LogError("platform exception");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+}
+
+void Motor::OnRequestReceived(const Api::EventPlayBeepPtr& event)
+{
+ LogInfo("Play beep event received");
+ try
+ {
+ if (event == NULL) {
+ LogError("event is NULL!");
+ ThrowMsg(Commons::PlatformException, "Event is NULL!!");
+ }
+
+ LogDebug(
+ "duration: " << event->getDuration() << ", volume: " <<
+ event->getVolume());
+ if (event->getDuration() <= 0) {
+ LogDebug("duration is less than 0!! Do Nothing!");
+ return;
+ }
+ if (playBeep(static_cast<unsigned long>(event->getDuration()),
+ event->getVolume()) < 0) {
+ LogError("playBeep returned error!!");
+ ThrowMsg(Commons::PlatformException, "Play Beep is Failed!");
+ }
+ }
+ catch (Commons::PlatformException) {
+ LogError("platform exception");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+}
+
+void Motor::runNextPattern()
+{
+ // always stop the motor
+ LogInfo("stopping motor");
+ stopMotor();
+
+ if (m_current >= m_pattern->length()) {
+ m_event.Reset();
+ m_pattern.Reset();
+ LogInfo("end of pattern");
+ return; // end of pattern
+ }
+
+ unsigned long duration = m_pattern->duration(m_current);
+
+ bool active = false;
+ Try {
+ active = m_pattern->isActive(m_current);
+ }
+ Catch(Commons::OutOfRangeException) {
+ LogError("Platform sequence size exceeded. Finishing.");
+ m_event.Reset();
+ m_pattern.Reset();
+ return;
+ }
+
+ // action
+ if (active) {
+ LogInfo("haptic action for " << duration << "ms");
+ run(duration);
+ }
+ // pause
+ else {
+ LogInfo("pausing for " << duration << "ms");
+ }
+
+ LogInfo("post request delayed for " << duration << "ms");
+ m_current++;
+ m_event = EventHapticActionPtr(new EventHapticAction());
+ m_event->setForAsynchronousCall(NULL); // not interested in answer
+
+ // post delayed event
+ EventHapticActionReqReceiver::PostRequest(m_event, duration / 1000.0);
+}
+
+void Motor::arragePattern(Api::HapticPatternPtr& patternPtr,
+ const unsigned long duration)
+{
+ LogInfo("Entered!!");
+
+ if (patternPtr == NULL) {
+ LogError("patternPtr is NULL");
+ return;
+ }
+
+ size_t patternLength = patternPtr->length();
+ unsigned long totalPatternDuration = 0;
+ unsigned long repeatCnt = 0;
+ unsigned long addingCnt = 0;
+ size_t currentInterval = 0;
+
+ for (size_t i = 0; i < patternLength; i++) {
+ totalPatternDuration += patternPtr->duration(i);
+ }
+ if ((duration % totalPatternDuration) == 0) {
+ repeatCnt = (duration / totalPatternDuration);
+ } else {
+ repeatCnt = (duration / totalPatternDuration) + 1;
+ }
+ addingCnt = repeatCnt - 1;
+
+ /* Repeat pattern during duration */
+ for (unsigned long i = 0; i < addingCnt; i++) {
+ for (currentInterval = 0;
+ currentInterval < patternLength;
+ currentInterval++) {
+ patternPtr->addInterval(patternPtr->duration(
+ currentInterval),
+ patternPtr->isActive(currentInterval));
+ }
+ }
+}
+} // Haptics
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_HAPTICS_MOTOR_H_
+#define WRTDEVICEAPIS_HAPTICS_MOTOR_H_
+
+#include <cstddef>
+#include <devman_haptic.h>
+#include <dpl/mutex.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Haptics/IMotor.h>
+
+namespace WrtDeviceApis {
+namespace Haptics {
+// Dummy event for asynchronous haptic motor schedule
+class EventHapticAction : public Commons::IEvent<EventHapticAction>
+{
+};
+typedef DPL::SharedPtr<EventHapticAction> EventHapticActionPtr;
+typedef Commons::EventRequestReceiver<EventHapticAction> EventHapticActionReqReceiver;
+typedef Commons::EventRequestReceiver<Api::EventStartMotor> EventStartMotorReqReceiver;
+typedef Commons::EventRequestReceiver<Api::EventPlayBeep> EventPlayBeepReqReceiver;
+
+class Motor :
+ public Api::IMotor,
+ public EventHapticActionReqReceiver,
+ public EventStartMotorReqReceiver,
+ public EventPlayBeepReqReceiver
+{
+ public:
+ explicit Motor(haptic_dev_idx index);
+ virtual ~Motor();
+
+ /**
+ * Run vibrate for duration.
+ * @param duration is unsigned long and value in milliseconds..
+ * @return none
+ */
+ void run(unsigned long duration);
+
+ /**
+ * Run vibrate for given pattern .
+ * @param The pattern argument is a DOMString composed by '.' and '_' chars.
+ * @return none
+ */
+ void run(const Api::HapticPatternPtr& pattern);
+
+ /**
+ * Run vibrate for given event .
+ * @param The event argument is event included duration & pattern.
+ * @return none
+ */
+ void run(const Api::EventStartMotorPtr& event);
+
+ /**
+ * stop motor for vibrating device
+ * @param none
+ * @return none
+ */
+ void stopMotor();
+
+ /**
+ * stop vibration. (pattern and motor)
+ * @param none
+ * @return none
+ */
+ void stopVibration();
+
+ /**
+ * Run notify for given duration and volume.if volume!=0 beep device,volume=0&vibrate open vibrate device
+ * @param duration value is unsigned long in millsecond.
+ * @param volume value is 0~7
+ * @return none
+ */
+ int playBeep(unsigned long duration,
+ int volume);
+
+ /**
+ * Run notify for given duration and volume.if volume!=0 beep device,volume=0&vibrate open vibrate device
+ * @param duration value is unsigned long in millsecond.
+ * @param volume value is 0~7
+ * @return none
+ */
+ void playBeep(const Api::EventPlayBeepPtr& event);
+
+ /**
+ * stop beep/vibrate/light-on device
+ * @param none
+ * @return none
+ */
+ void stopBeep();
+
+ protected:
+ void OnRequestReceived(const EventHapticActionPtr& event);
+ void OnRequestReceived(const Api::EventStartMotorPtr& event);
+ void OnRequestReceived(const Api::EventPlayBeepPtr& event);
+
+ private:
+ void runNextPattern();
+ void arragePattern(Api::HapticPatternPtr& patternPtr,
+ const unsigned long duration);
+
+ private:
+ int m_device; ///< Platform haptic device handle.
+ int m_beepHandle; ///< Platform beep handle.
+ Api::HapticPatternPtr m_pattern; // haptic action pattern
+ EventHapticActionPtr m_event; // haptic action scheduling event
+ size_t m_current; // current haptic action pattern interval
+ DPL::Mutex m_patternMutex;
+};
+} // Haptics
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_HAPTICS_MOTOR_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(haptic REQUIRED devman_haptic)
+#pkg_search_module(appcore REQUIRED appcore-common)
+#pkg_search_module(avsystem REQUIRED avsystem)
+pkg_search_module(mm-sound REQUIRED mm-sound)
+#pkg_search_module(audiosessionmgr REQUIRED audio-session-mgr)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_HAPTICS
+ ${haptic_INCLUDE_DIRS}
+ # ${appcore_INCLUDE_DIRS}
+ # ${avsystem_INCLUDE_DIRS}
+ ${mm-sound_INCLUDE_DIRS}
+ # ${audiosessionmgr_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_HAPTICS
+ ${haptic_LIBRARIES}
+ #${appcore_LIBRARIES}
+ #${avsystem_LIBRARIES}
+ ${mm-sound_LIBRARIES}
+ #${audiosessionmgr_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_HAPTICS
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/Motor.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 "MMPlayer.h"
+#include <mmf/mm.h>
+#include <mm_player.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+
+using namespace Api;
+
+MMPlayer::MMPlayer() :
+ Commons::EventListener<EventOnEOS>(Commons::ThreadEnum::NULL_THREAD),
+ m_player(0),
+ m_currentState(STATE_UNDEFINED),
+ m_repeatTimes(0)
+{
+ Try {
+ init();
+ } Catch(Commons::Exception) {
+ LogError("Unknown exception while constructing MMPlayer");
+ }
+}
+
+MMPlayer::~MMPlayer()
+{
+ LogInfo("Enter");
+ finalize();
+}
+
+MMHandleType MMPlayer::getHandler() const
+{
+ return m_player;
+}
+
+void MMPlayer::setEmitter(const EventOnStateChangeEmitterPtr& emitter)
+{
+ LogDebug("Enter");
+ DPL::Mutex::ScopedLock lock(&m_emitterMtx);
+ m_onStateChangeEmitter = emitter;
+}
+
+EventOnStateChangeEmitterPtr MMPlayer::getEmitter()
+{
+ DPL::Mutex::ScopedLock lock(&m_emitterMtx);
+ return m_onStateChangeEmitter;
+}
+
+void MMPlayer::clearEmitter()
+{
+ LogDebug("Enter");
+ DPL::Mutex::ScopedLock lock(&m_emitterMtx);
+ m_onStateChangeEmitter.Reset();
+}
+
+int MMPlayer::onStateChange(int message,
+ void *param,
+ void* data)
+{
+ LogInfo("Enter");
+ static DPL::Mutex playerMtx;
+ MMPlayer *this_ = static_cast<MMPlayer*>(data);
+ if (this_) {
+ EventOnStateChangePtr event(new EventOnStateChange());
+ { //Separated block to avoid deadlock when this_->m_emitterMtx will be locked
+ DPL::Mutex::ScopedLock lock(&playerMtx);
+ switch (message) {
+ case MM_MESSAGE_ERROR:
+ {
+ MMMessageParamType* type =
+ static_cast<MMMessageParamType*>(param);
+ if (type && (MM_MSG_UNION_CODE == type->union_type)) {
+ LogError(
+ "Error from platform, code: " << std::hex <<
+ type->code);
+ }
+ event->setPlayerState(EventOnStateChange::BEGIN);
+ break;
+ }
+
+ case MM_MESSAGE_BEGIN_OF_STREAM:
+ LogInfo("Begin of stream");
+ event->setPlayerState(EventOnStateChange::PLAYING);
+ break;
+
+ case MM_MESSAGE_END_OF_STREAM:
+ LogInfo("End of stream");
+ event->setPlayerState(EventOnStateChange::COMPLETED);
+
+ // mm_player_stop should be executed outside the callback
+ {
+ EventOnEOSPtr eventEOS(new EventOnEOS());
+ if (this_->m_onEOSEmitter) {
+ this_->m_onEOSEmitter->emit(eventEOS);
+ } else {
+ LogError("EOS emitter not set");
+ }
+ }
+ break;
+
+ case MM_MESSAGE_STATE_INTERRUPTED:
+ // since platform reports always param->union_type == 0, only what can be done is to use field code
+ // and pray it won't be changed right before demo
+ {
+ MMMessageParamType* type =
+ static_cast<MMMessageParamType*>(param);
+ LogInfo("Player callback message: " << std::hex << message);
+ if (type && (MM_MSG_UNION_CODE == type->union_type)) {
+ LogError("Code: " << std::hex << type->code);
+ if (MM_PLAYER_STATE_PAUSED == type->code) {
+ LogInfo("Sending pause event");
+ event->setPlayerState(EventOnStateChange::PAUSED);
+ } else {
+ return 0;
+ }
+ }
+ }
+ break;
+
+ default:
+ LogInfo("Player callback message: " << std::hex << message);
+ MMMessageParamType* type =
+ static_cast<MMMessageParamType*>(param);
+ if (type && (MM_MSG_UNION_CODE == type->union_type)) {
+ LogInfo("Code: " << type->code);
+ }
+ return 0;
+ }
+ }
+
+ DPL::Mutex::ScopedLock lock(&this_->m_emitterMtx);
+ if (this_->m_onStateChangeEmitter) {
+ this_->m_onStateChangeEmitter->emit(event);
+ }
+ return 0;
+ }
+ return -1;
+}
+
+void MMPlayer::init()
+{
+ LogDebug("Enter");
+ int err = mm_player_create(&m_player);
+ if (MM_ERROR_NONE != err || !m_player) {
+ LogError("Can't create player");
+ Throw(Commons::PlatformException);
+ }
+
+ err = mm_player_set_message_callback(m_player,
+ MMPlayer::onStateChange,
+ this);
+ if (MM_ERROR_NONE != err) {
+ LogDebug("Can't set player's callback. Error code: " << std::hex << err);
+ mm_player_destroy(m_player);
+ ThrowMsg(Commons::PlatformException, "Can't set player's callback.");
+ }
+ //Set emmiter for EOS event
+ m_onEOSEmitter.Reset(new EventOnEOSEmitter());
+ m_onEOSEmitter->setListener(this);
+}
+
+void MMPlayer::finalize()
+{
+ LogDebug("Enter");
+ //if the music is playing, stop music.
+ if (MM_PLAYER_STATE_PLAYING == getState()) {
+ LogInfo("Sending stop request");
+ int err = mm_player_stop(m_player);
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't stop player. Error code: " << std::hex << err);
+ }
+ }
+
+ int err = mm_player_set_message_callback(m_player, NULL, NULL);
+ if (MM_ERROR_NONE != err) {
+ LogDebug("Can't set player's callback. Error code: " << std::hex << err);
+ }
+ err = mm_player_destroy(m_player);
+ if (MM_ERROR_NONE != err) {
+ LogError(
+ "There were some problems during player destruction. Error code: "
+ << std::hex << err);
+ }
+}
+
+MMPlayerStateType MMPlayer::getState() const
+{
+ MMPlayerStateType state;
+ int err = mm_player_get_state(m_player, &state);
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't get player status. Error code: " << std::hex << err);
+ ThrowMsg(Commons::PlatformException, "Can't get player status.");
+ }
+ LogInfo("Current player state: " << static_cast<int>(state));
+ return state;
+}
+
+void MMPlayer::onAnswerReceived(const EventOnEOSPtr& /*event*/)
+{
+ LogInfo("Enter");
+ int err = mm_player_stop(m_player);
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't stop player. Error code: " << std::hex << err);
+ }
+ LogInfo("Repeat " << m_repeatTimes << " more time" <<
+ ((m_repeatTimes == 1) ? "" : "s"));
+ if (m_repeatTimes > 0) {
+ --m_repeatTimes;
+ int err = mm_player_start(m_player);
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't start play. Error code: " << std::hex << err);
+ }
+ }
+}
+
+unsigned int MMPlayer::getRepeatTimes() const
+{
+ return m_repeatTimes;
+}
+
+void MMPlayer::setRepeatTimes(unsigned int count)
+{
+ m_repeatTimes = count;
+}
+
+}
+}
--- /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_MMPLAYER_MMPLAYER_H_
+#define WRTDEVICEAPIS_MMPLAYER_MMPLAYER_H_
+
+#include <mmf/mm.h>
+#include <mm_player.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/mutex.h>
+#include <MMPlayer/IMMPlayer.h>
+#include <MMPlayer/MMPlayerFactory.h>
+#include <MMPlayer/EventOnStateChange.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+/**
+ * Event to send from callback when end of stream will be reported -> mm_player_stop should be executed
+ */
+class EventOnEOS : public Commons::ListenerEvent<EventOnEOS>
+{
+};
+
+typedef DPL::SharedPtr<EventOnEOS> EventOnEOSPtr;
+typedef Commons::ListenerEventEmitter<EventOnEOS> EventOnEOSEmitter;
+typedef DPL::SharedPtr<EventOnEOSEmitter> EventOnEOSEmitterPtr;
+
+class MMPlayer :
+ public Api::IMMPlayer,
+ public Commons::EventListener<EventOnEOS>
+{
+ friend class Api::MMPlayerFactory;
+
+ public:
+ typedef enum
+ {
+ STATE_OPENED,
+ STATE_STOPPED,
+ STATE_PLAYING,
+ STATE_PAUSED,
+ STATE_COMPLETED,
+ STATE_UNDEFINED
+ } MMPLAYER_STATES;
+
+ private:
+ MMHandleType m_player;
+ MMPLAYER_STATES m_currentState;
+ unsigned int m_repeatTimes;
+
+ /**
+ * MMPlayer constructor
+ * \exception Commons::PlatformException when platform error occurs
+ */
+ explicit MMPlayer();
+
+ public:
+ /**
+ * MMPlayer destructor
+ */
+ virtual ~MMPlayer();
+
+ /**
+ * Gets handler to platform player type
+ */
+ virtual MMHandleType getHandler() const;
+
+ /**
+ * @See Api::MMPlayer::IMMPlayer::setEmitter
+ */
+ virtual void setEmitter(
+ const Api::EventOnStateChangeEmitterPtr& emitter);
+ /**
+ * @See Api::MMPlayer::IMMPlayer::getEmitter
+ */
+ Api::EventOnStateChangeEmitterPtr getEmitter();
+ /**
+ * @See Api::MMPlayer::IMMPlayer::clearEmitter
+ */
+ virtual void clearEmitter();
+
+ /**
+ * Gets player state
+ */
+ virtual MMPlayerStateType getState() const;
+
+ /**
+ * Used to recieve EventOnEOS
+ */
+ virtual void onAnswerReceived(const EventOnEOSPtr& event);
+
+ virtual unsigned int getRepeatTimes() const;
+
+ virtual void setRepeatTimes(unsigned int count);
+
+ private:
+ /**
+ * Callback method called by platform when player state changes.
+ * @param message Platform message
+ * @param param Platform parameter
+ * @param data User data.
+ */
+ static int onStateChange(int message,
+ void* param,
+ void* data);
+
+ /**
+ * Initialize player
+ * @throw Commons::PlatformException when platform error occures
+ */
+ void init();
+ /**
+ * Finalize player
+ */
+ void finalize();
+
+ DPL::Mutex m_emitterMtx;
+ Api::EventOnStateChangeEmitterPtr m_onStateChangeEmitter;
+ EventOnEOSEmitterPtr m_onEOSEmitter;
+};
+
+typedef DPL::SharedPtr<MMPlayer> MMPlayerPtr;
+
+}
+}
+
+#endif // WRTDEVICEAPIS_MMPLAYER_MMPLAYER_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 "Manager.h"
+#include <mmf/mm.h>
+#include <mm_sound.h>
+#include <mm_player.h>
+#include <WidgetDB/WidgetDBMgr.h>
+#include <MMPlayer/EventOnStateChange.h>
+#include "MMPlayer.h"
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+
+using namespace Api;
+
+Manager::Manager()
+{
+}
+
+Manager::~Manager()
+{
+}
+
+void Manager::openFile(const EventOpenPtr& event)
+{
+ EventRequestReceiver<EventOpen>::PostRequest(event);
+}
+
+void Manager::play(const EventPlayPtr& event)
+{
+ EventRequestReceiver<EventPlay>::PostRequest(event);
+}
+
+void Manager::pause(const EventPausePtr& event)
+{
+ EventRequestReceiver<EventPause>::PostRequest(event);
+}
+
+void Manager::resume(const EventResumePtr& event)
+{
+ EventRequestReceiver<EventResume>::PostRequest(event);
+}
+
+void Manager::stop(const EventStopPtr& event)
+{
+ EventRequestReceiver<EventStop>::PostRequest(event);
+}
+
+void Manager::setWindow(const EventSetWindowPtr& event)
+{
+ EventRequestReceiver<EventSetWindow>::PostRequest(event);
+}
+
+void Manager::isPlaying(const EventIsPlayingPtr& event)
+{
+ EventRequestReceiver<EventIsPlaying>::PostRequest(event);
+}
+
+void Manager::getVolume(const EventGetVolumePtr& event)
+{
+ EventRequestReceiver<EventGetVolume>::PostRequest(event);
+}
+
+void Manager::OnRequestReceived(const EventOpenPtr& event)
+{
+ LogDebug("Entered");
+
+ string fullName = event->getFilename();
+ MMPlayerPtr player = DPL::DynamicPointerCast<MMPlayer>(event->getPlayer());
+ if (!player) {
+ LogError("MMPlayerPtr cast error");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+
+ int err;
+ if (MM_PLAYER_STATE_NULL != player->getState()) {
+ err = mm_player_unrealize(player->getHandler());
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't unrealize player. Error code: " << std::hex << err);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ }
+
+ if (!fullName.length()) {
+ event->setExceptionCode(
+ Commons::ExceptionCodes::InvalidArgumentException);
+ return;
+ }
+
+ //Check if current installation path should be added
+ if ((fullName[0] != '/') && (fullName.find("://") == string::npos)) {
+ try {
+ std::string installationPath;
+ Commons::IWrtWrapperPtr wrapper = event->getWrtWrapper();
+ if (!wrapper) {
+ LogError("Wrt API not accessible. Can't get installation path.");
+ event->setExceptionCode(
+ Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+
+ WidgetDB::Api::IWidgetDBPtr widgetDB = WidgetDB::Api::getWidgetDB(
+ wrapper->getWidgetId());
+ installationPath = widgetDB->getConfigValue(
+ WidgetDB::Api::ConfigAttribute::INSTALL_PATH);
+
+ LogInfo("Config attribute: " << installationPath);
+ fullName.insert(0, installationPath);
+ } catch (const Commons::Exception &ex) {
+ LogError("Obtaining config info failed");
+ event->setExceptionCode(ex.getCode());
+ return;
+ }
+ }
+
+ LogDebug("Opening file: " << fullName);
+ char *errorBuffer = NULL;
+ err = mm_player_set_attribute(
+ player->getHandler(), &errorBuffer, "profile_uri",
+ fullName.c_str(), fullName.length(), NULL);
+ if (MM_ERROR_NONE != err) {
+ LogError(
+ "Setting attribute error. Code: " << std::hex << err <<
+ ". Message: " << errorBuffer);
+ free(errorBuffer);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+
+ err = mm_player_realize(player->getHandler());
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't realize player. Error code:" << std::hex << err);
+ if (static_cast<int>(MM_ERROR_PLAYER_INVALID_URI) == err) {
+ LogDebug("x");
+ event->setExceptionCode(
+ Commons::ExceptionCodes::InvalidArgumentException);
+ } else {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ return;
+ }
+
+ if (player->getEmitter()) {
+ EventOnStateChangePtr eventStateChanged(new EventOnStateChange(
+ EventOnStateChange::OPENED));
+ player->getEmitter()->emit(eventStateChanged);
+ }
+}
+
+void Manager::OnRequestReceived(const EventPlayPtr& event)
+{
+ LogDebug("Entered");
+
+ MMPlayerPtr player = DPL::DynamicPointerCast<MMPlayer>(event->getPlayer());
+ if (!player) {
+ LogError("MMPlayerPtr cast error");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+
+ //Check if player currently plays media
+ if (MM_PLAYER_STATE_PLAYING == player->getState() || 0 ==
+ event->getRepeatTimes()) {
+ LogDebug("already playing");
+ return;
+ }
+ player->setRepeatTimes(event->getRepeatTimes() - 1);
+
+ int err = mm_player_start(player->getHandler());
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't start play. Error code: " << std::hex << err);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ //Event onStateChange will be emitted trough platform callback
+}
+
+void Manager::OnRequestReceived(const EventPausePtr& event)
+{
+ LogDebug("Entered");
+
+ MMPlayerPtr player = DPL::DynamicPointerCast<MMPlayer>(event->getPlayer());
+ if (!player) {
+ LogError("MMPlayerPtr cast error");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ if (MM_PLAYER_STATE_PLAYING != player->getState()) {
+ return;
+ }
+
+ int err = mm_player_pause(player->getHandler());
+ if (MM_ERROR_NONE != err) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ if (player->getEmitter()) {
+ EventOnStateChangePtr eventStateChanged(new EventOnStateChange(
+ EventOnStateChange::PAUSED));
+ player->getEmitter()->emit(eventStateChanged);
+ }
+}
+
+void Manager::OnRequestReceived(const EventResumePtr& event)
+{
+ LogDebug("Entered");
+
+ MMPlayerPtr player = DPL::DynamicPointerCast<MMPlayer>(event->getPlayer());
+ if (!player) {
+ LogError("MMPlayerPtr cast error");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ if (MM_PLAYER_STATE_PAUSED != player->getState()) {
+ return;
+ }
+
+ int err = mm_player_resume(player->getHandler());
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't resume player. Error code: " << std::hex << err);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ if (player->getEmitter()) {
+ EventOnStateChangePtr eventStateChanged(new EventOnStateChange(
+ EventOnStateChange::RESUMED));
+ player->getEmitter()->emit(eventStateChanged);
+ }
+}
+
+void Manager::OnRequestReceived(const EventStopPtr& event)
+{
+ LogDebug("Entered");
+
+ MMPlayerPtr player = DPL::DynamicPointerCast<MMPlayer>(event->getPlayer());
+ if (!player) {
+ LogError("MMPlayerPtr cast error");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ if (MM_PLAYER_STATE_PLAYING != player->getState() &&
+ MM_PLAYER_STATE_PAUSED != player->getState()) {
+ return;
+ }
+
+ int err = mm_player_stop(player->getHandler());
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't stop player. Error code: " << std::hex << err);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+
+ if (player->getEmitter()) {
+ EventOnStateChangePtr eventStateChanged(new EventOnStateChange(
+ EventOnStateChange::STOPPED));
+ player->getEmitter()->emit(eventStateChanged);
+ }
+}
+
+void Manager::OnRequestReceived(const EventSetWindowPtr& /*event*/)
+{
+ LogDebug("Entered");
+ LogError("Not implemented");
+ //TODO: set display parameter, when xID will be available
+}
+
+void Manager::OnRequestReceived(const EventIsPlayingPtr& event)
+{
+ LogDebug("Entered");
+
+ MMPlayerPtr player = DPL::DynamicPointerCast<MMPlayer>(event->getPlayer());
+ Try
+ {
+ if (!player) {
+ LogError("MMPlayerPtr cast error");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ event->setIsPlaying(MM_PLAYER_STATE_PLAYING == player->getState());
+ }
+ Catch(Commons::PlatformException)
+ {
+ LogError("Can't get player status.");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+}
+
+void Manager::OnRequestReceived(const EventGetVolumePtr& event)
+{
+ LogDebug("Entered");
+ unsigned int volume = 0;
+ int steps = 0;
+
+ int err = mm_sound_volume_get_step(VOLUME_TYPE_MEDIA, &steps);
+ if (MM_ERROR_NONE != err) {
+ LogError(
+ "Can't get volume steps count. Error code: " << std::hex <<
+ err);
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ return;
+ }
+ LogInfo("Volume steps count: " << steps);
+ try
+ {
+ err = mm_sound_volume_get_value(VOLUME_TYPE_MEDIA, &volume);
+ if (MM_ERROR_NONE != err) {
+ LogError(
+ "Can't get player's volume. Error code: " << std::hex <<
+ err);
+ Throw(Commons::UnknownException);
+ }
+ LogInfo("Platform player's volume: " << volume);
+ if (steps > 1) {
+ event->setVolume((10.0 * volume) / (steps - 1));
+ } else {
+ LogError("no steps defined");
+ event->setVolume(0);
+ }
+ }
+ catch (const Commons::UnknownException &ex)
+ {
+ LogError("Can't scale the volume");
+ 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.
+ */
+#ifndef WRTDEVICEAPIS_MMPLAYER_MANAGER_H_
+#define WRTDEVICEAPIS_MMPLAYER_MANAGER_H_
+
+#include <MMPlayer/IManager.h>
+
+namespace WrtDeviceApis {
+namespace MMPlayer {
+
+class Manager : public Api::IManager
+{
+ public:
+ Manager();
+ virtual ~Manager();
+
+ /**
+ * Opens a file
+ * @param event @see WrtDeviceApis::Api::EventOpen.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void openFile(const Api::EventOpenPtr& event);
+ /**
+ * Plays current file. If file is already playing player starts from the beginning
+ * @param event @see WrtDeviceApis::Api::EventPlay.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void play(const Api::EventPlayPtr& event);
+ /**
+ * Pauses current playing file. If no file is currently playing noting happens
+ * @param event @see WrtDeviceApis::Api::EventPause.
+ * @exception Commons::PlatformException when platform error occurs
+ * @exception Commons::InvalidArgumentException when fileName is empty
+ */
+ virtual void pause(const Api::EventPausePtr& event);
+ /**
+ * Resumes after pause. If file is not paused nothing happens
+ * @param event @see WrtDeviceApis::Api::EventResume.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void resume(const Api::EventResumePtr& event);
+ /**
+ * Stops current playing file. If file is not playing nothing happens
+ * @param event @see WrtDeviceApis::Api::EventStop.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void stop(const Api::EventStopPtr& event);
+ /**
+ * Sets window for video files
+ * @param event @see WrtDeviceApis::Api::EventSetWindow.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void setWindow(const Api::EventSetWindowPtr& event);
+ /**
+ * Returns current playing state
+ * @param event @see WrtDeviceApis::Api::EventIsPlaying.
+ * @return True if player is in playing state
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void isPlaying(const Api::EventIsPlayingPtr& event);
+ /**
+ * Returns current playing state
+ * @param [out] event @see WrtDeviceApis::Api::EventIsPlaying.
+ * @exception Commons::PlatformException when platform error occurs
+ */
+ virtual void getVolume(const Api::EventGetVolumePtr& event);
+
+ protected:
+ virtual void OnRequestReceived(const Api::EventOpenPtr& event);
+ virtual void OnRequestReceived(const Api::EventPlayPtr& event);
+ virtual void OnRequestReceived(const Api::EventPausePtr& event);
+ virtual void OnRequestReceived(const Api::EventResumePtr& event);
+ virtual void OnRequestReceived(const Api::EventStopPtr& event);
+ virtual void OnRequestReceived(const Api::EventSetWindowPtr& event);
+ virtual void OnRequestReceived(const Api::EventIsPlayingPtr& event);
+ virtual void OnRequestReceived(const Api::EventGetVolumePtr& event);
+};
+
+}
+}
+
+#endif // WRTDEVICEAPIS_MMPLAYER_MANAGER_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(mmsound REQUIRED mm-sound)
+pkg_search_module(mmplayer REQUIRED mm-player)
+pkg_search_module(libpcrecpp REQUIRED libpcrecpp)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_MMPLAYER
+ ${mmplayer_INCLUDE_DIRS}
+ ${mmsound_INCLUDE_DIRS}
+ ${libpcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_MMPLAYER
+ ${mmplayer_LIBRARIES}
+ ${mmsound_LIBRARIES}
+ ${libpcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_MMPLAYER
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/MMPlayer.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 Attachment.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Filesystem/Manager.h>
+#include "Attachment.h"
+
+extern "C" {
+#include <sys/stat.h>
+#include <stdlib.h>
+}
+
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+//--------------------------------------------------------------------------
+namespace WrtDeviceApis {
+namespace Messaging {
+
+Attachment::Attachment(const string& fullPath,
+ bool isVirtualPath)
+{
+ LogDebug("entered");
+ init(fullPath, isVirtualPath);
+}
+
+std::string Attachment::getRealPath(const std::string &path) const
+{
+ Try
+ {
+ Filesystem::Api::IPathPtr currentPath = Filesystem::Api::IPath::create(
+ path);
+ return currentPath->getFullPath();
+ }
+
+ Catch(Commons::Exception) {
+ LogError("invalid path");
+ ReThrow(Commons::InvalidArgumentException);
+ }
+}
+}
+}
+
--- /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 Attachment.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef MESSAGE_ATTACHMENT_H
+#define MESSAGE_ATTACHMENT_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <API/Messaging/IAttachment.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+//--------------------------------------------------------------------------
+
+class Attachment : public Api::IAttachment
+{
+ public:
+
+ explicit Attachment(const std::string& fullPath,
+ bool isVirtualPath);
+
+ private:
+
+ virtual std::string getRealPath(const std::string &path) const;
+};
+}
+}
+
+#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 BinarySms.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "BinarySms.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+using namespace WrtDeviceApis::Messaging;
+using namespace WrtDeviceApis::Messaging::Api;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+BinarySms::BinarySms(const string& id) :
+ IMessage(Api::BINARYSMS, id)
+{
+ LogDebug("enter");
+
+ LogDebug("m_id=" << getIdRef());
+ LogDebug("m_msgType=" << getMessageType());
+}
+
+BinarySms::~BinarySms()
+{
+ LogDebug("enter");
+}
+
+void BinarySms::update(bool /*draftsOnly*/)
+{
+ LogDebug("updating m_id=" << getIdRef());
+}
+
+void BinarySms::readAllData()
+{
+ //#warning "TODO"
+}
+
+void BinarySms::moveToFolder(const FolderType /*newFolder*/)
+{
+ //#warning "TODO"
+}
+
+void BinarySms::moveToFolder(const string& /*newFolder*/)
+{
+ //#warning "TODO"
+}
+
+void BinarySms::copyToFolder(const FolderType /*newFolder*/)
+{
+ //#warning "TODO"
+}
+
+void BinarySms::copyToFolder(const string& /*newFolder*/)
+{
+ //#warning "TODO"
+}
+
+void BinarySms::remove()
+{
+ //#warning "TODO"
+}
+
+void BinarySms::send()
+{
+ //#warning "TODO"
+}
+
+void BinarySms::sendCancel()
+{
+ //#warning "TODO"
+}
+}
+}
--- /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 BinarySms.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef BINARY_SMS_H
+#define BINARY_SMS_H
+
+#include <API/Messaging/IBinarySms.h>
+#include <string>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class BinarySms :
+ public Api::IBinarySms
+{
+ public:
+
+ explicit BinarySms(const std::string& id = "");
+
+ virtual ~BinarySms();
+
+ // implementation of interface of IMessage class
+ virtual void update(bool draftsOnly = false);
+
+ virtual void readAllData();
+
+ virtual void moveToFolder(const Api::FolderType newFolder);
+
+ virtual void moveToFolder(const std::string& newFolder);
+
+ virtual void copyToFolder(const Api::FolderType newFolder);
+
+ virtual void copyToFolder(const std::string& newFolder);
+
+ virtual void remove();
+
+ virtual void send();
+
+ virtual void sendCancel();
+};
+}
+}
+
+#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 CallbackMgr.cpp
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "CallbackMgr.h"
+#include <dpl/log/log.h>
+#include <dpl/singleton_impl.h>
+#include "ISendingObserver.h"
+#include "MsgServiceHandleMgr.h"
+
+extern "C" {
+#include <MapiTransport.h>
+#include <MapiControl.h>
+#include <MapiMessage.h>
+}
+
+IMPLEMENT_SINGLETON(WrtDeviceApis::Messaging::CallbackMgr)
+
+namespace WrtDeviceApis {
+namespace Messaging {
+
+CallbackMgr::CallbackMgr()
+{
+ LogInfo("enter");
+ // register callback once per process
+ if (NULL == MsgGetCommonHandle()) {
+ LogError("Unable to open handle");
+ } else {
+ if (msg_reg_sent_status_callback(MsgGetCommonHandle(), sendCallback,
+ static_cast<void*>(this)) !=
+ MSG_SUCCESS) {
+ LogError("callback registration error");
+ } else {
+ LogDebug("callback registred succesfully");
+ }
+ }
+}
+
+CallbackMgr::~CallbackMgr()
+{
+ LogInfo("enter");
+}
+
+MSG_ERROR_T CallbackMgr::registerAndSend(SendingFunction sendingFn,
+ const msg_message_t& message,
+ ISendingObserver* observer)
+{
+ LogDebug("trying to send message, msgId=" << msg_get_message_id(message));
+
+ MSG_SENDINGOPT_S pSendOpt;
+ memset(&pSendOpt, 0, sizeof(MSG_SENDINGOPT_S));
+ MSG_REQUEST_S req;
+ memset(&req, 0, sizeof(MSG_REQUEST_S));
+ req.reqId = 0;
+ req.msg = message;
+ req.sendOpt = pSendOpt;
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ MSG_ERROR_T err = (*sendingFn)(MsgGetCommonHandle(), &req);
+ if (err == MSG_SUCCESS) {
+ if (observer) {
+ m_sendRequests[req.reqId] = observer;
+ observer->setSendigRequestId(req.reqId);
+ observer->setRecipient(msg_get_ith_address(message, 0));
+ }
+ }
+ return err;
+}
+
+void CallbackMgr::unregister(int reqId)
+{
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+
+ SendReqMap::iterator it = m_sendRequests.find(reqId);
+ if (it == m_sendRequests.end()) {
+ LogWarning("No matching request found");
+ return;
+ }
+ LogInfo("Matching send request found!");
+ m_sendRequests.erase(it);
+}
+
+void CallbackMgr::sendCallback(MSG_HANDLE_T /*handle*/,
+ MSG_SENT_STATUS_S *sent_status,
+ void *user_param)
+{
+ LogInfo(
+ "callback received. Req id = " << sent_status->reqId <<
+ " Status = " << (int)sent_status->status);
+ CallbackMgr* instance = static_cast<CallbackMgr*>(user_param);
+ if (!instance) {
+ LogError("Empty user data!");
+ return;
+ }
+
+ instance->call(sent_status);
+}
+
+void CallbackMgr::call(MSG_SENT_STATUS_S *sent_status)
+{
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+
+ SendReqMap::iterator it = m_sendRequests.find(sent_status->reqId);
+ if (it == m_sendRequests.end()) {
+ LogWarning("No matching request found");
+ return;
+ }
+ LogInfo("Matching send request found!");
+
+ // call it
+ it->second->sendingCallback(sent_status);
+
+ m_sendRequests.erase(it);
+}
+}
+}
+
--- /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 CallbackMgr.h
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef CALLBACKMGR_H_
+#define CALLBACKMGR_H_
+
+#include <map>
+#include <dpl/singleton.h>
+#include <dpl/mutex.h>
+
+extern "C" {
+#include <MsgTypes.h>
+#include <MsgTransportTypes.h>
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class ISendingObserver;
+
+/*
+ *
+ */
+class CallbackMgr
+{
+ protected:
+ CallbackMgr();
+
+ static void sendCallback(MSG_HANDLE_T handle,
+ MSG_SENT_STATUS_S *sent_status,
+ void *user_param);
+
+ void call(MSG_SENT_STATUS_S *sent_status);
+
+ public:
+ ~CallbackMgr();
+
+ typedef int (*SendingFunction)(MSG_HANDLE_T, MSG_REQUEST_S*);
+
+ // register for sending callback
+ MSG_ERROR_T registerAndSend(SendingFunction sendingFn,
+ const msg_message_t& message,
+ ISendingObserver* observer);
+
+ // unregister callback
+ void unregister(int reqId);
+
+ private:
+ DPL::Mutex m_mutex;
+
+ typedef std::map<MSG_REQUEST_ID_T, ISendingObserver*> SendReqMap;
+ SendReqMap m_sendRequests;
+};
+
+typedef DPL::Singleton<CallbackMgr> CallbackMgrSingleton;
+}
+}
+
+#endif /* CALLBACKMGR_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 Email.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <cstdio>
+#include <cstddef>
+#include <ctime>
+#include <emf-types.h>
+#include <Emf_Mapi.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dpl/scoped_fclose.h>
+#include <dpl/scoped_ptr.h>
+#include <Commons/Exception.h>
+#include <Commons/StringUtils.h>
+#include <API/Messaging/MessageFactory.h>
+#include <API/Messaging/EmailAccountInfo.h>
+#include "Messaging.h"
+#include "Email.h"
+#include "EmailService.h"
+#include "EmailUtils.h"
+#include "EmailConverter.h"
+#include "MailSender.h"
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+using namespace std;
+using namespace WrtDeviceApis::Messaging;
+using namespace WrtDeviceApis::Messaging::Api;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace {
+//#define USE_OUTBOX
+
+#ifdef USE_OUTBOX
+const Api::FolderType DEFAULT_FOLDER = Api::OUTBOX;
+//const char* DEFAULT_FOLDER_NAME = EMF_OUTBOX_NAME;
+#else
+const Api::FolderType DEFAULT_FOLDER = Api::DRAFTBOX;
+//const char* DEFAULT_FOLDER_NAME = EMF_DRAFTBOX_NAME;
+#endif
+}
+
+Email::Email(const string& id) : IMessage(Api::EMAIL, id)
+{
+ LOG_ENTER
+
+ try {
+ if (getIdRef().empty()) {
+ create();
+ }
+ // always read the message (after creation some of attributes change
+ // i.e. body->plain)
+ reload();
+ }
+ catch (const Commons::PlatformException& ex) {
+ LogError("Exception: " << ex.DumpToString());
+ }
+
+ LOG_EXIT
+}
+
+Email::~Email()
+{
+ LogDebug("ENTER");
+}
+
+void Email::send()
+{
+ LOG_ENTER
+
+ update();
+
+ MailSender::getInstance().send(
+ Api::MessageFactory::convertToEmail(SharedFromThis())
+ );
+
+ LOG_EXIT
+}
+
+void Email::sendCancel()
+{
+ LOG_ENTER
+
+ MailSender::getInstance().cancel(getIntId());
+
+ LOG_EXIT
+}
+
+void Email::update(bool draftsOnly)
+{
+ LOG_ENTER
+
+ DPL::Mutex::ScopedLock mx(&m_updateMutex);
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail is NULL.");
+ }
+
+ if (!draftsOnly || (getCurrentFolder() == Api::DRAFTBOX)) {
+ updateBody();
+ updateSubject();
+ updateRecipients();
+ updateFrom();
+ updateAttachments();
+ updatePriority();
+ } else {
+ LogWarning("Updating only read status. Folder: " << getCurrentFolder());
+ }
+ updateReadStatus();
+
+ int error = email_update_message(getIntId(), m_mail.Get());
+ if (EMF_ERROR_NONE != error) {
+ LogWarning("Nothing to update or error. [" << error << "]");
+ }
+
+ LOG_EXIT
+}
+
+int Email::getAccountId() const
+{
+ return m_accountId;
+}
+
+void Email::readAllData()
+{
+ reload();
+}
+
+void Email::moveToFolder(const Api::FolderType newFolder)
+{
+ LOG_ENTER
+
+ moveToFolder(EmailConverter::toMailboxName(newFolder));
+
+ LOG_EXIT
+}
+
+void Email::moveToFolder(const string& newFolder)
+{
+ update();
+
+ int accountId = Messaging::getInstance().getEmailAccountId(getFromRef());
+ ScopedMailbox mailbox(
+ EmailService::createMailbox(accountId, newFolder.c_str())
+ );
+
+ int mailId = getIntId();
+
+ int error = email_move_mail_to_mailbox(&mailId, 1, mailbox.Get());
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(
+ Commons::PlatformException,
+ "Couldn't move mail to folder: " << newFolder << ". [" <<
+ error << "]");
+ }
+}
+
+void Email::copyToFolder(const FolderType newFolder)
+{
+ LOG_ENTER
+
+ copyToFolder(EmailConverter::toMailboxName(newFolder));
+
+ LOG_EXIT
+}
+
+void Email::copyToFolder(const string& newFolder)
+{
+ LOG_ENTER
+
+ update();
+
+ int accountId = Messaging::getInstance().getEmailAccountId(getFromRef());
+
+ ScopedMail mail(EmailService::cloneMail(m_mail.Get()));
+ ScopedMailbox mailbox(
+ EmailService::createMailbox(accountId, newFolder.c_str())
+ );
+
+ int mailId = EmailService::addMailToMailbox(mail.Get(), mailbox.Get());
+ // TODO Is following check necessary?
+ if (0 == mailId) {
+ ThrowMsg(Commons::PlatformException, "Cloned mail didn't get new id.");
+ }
+
+ LOG_EXIT
+}
+
+void Email::remove()
+{
+ EmailService::deleteMail(m_accountId, getIntId());
+}
+
+void Email::create()
+{
+ LOG_ENTER
+
+ EmailAccountInfo account = IMessaging::getInstance().getCurrentEmailAccount();
+ ScopedMail mail(EmailService::createMail(account));
+ ScopedMailbox mailbox(
+ EmailService::getMailboxByType(account.getIntId(),
+ EMF_MAILBOX_TYPE_DRAFT)
+ );
+ setId(convertId(EmailService::addMailToMailbox(mail.Get(), mailbox.Get())));
+ setFolderType(Api::DRAFTBOX);
+
+ LOG_EXIT
+}
+
+void Email::reload()
+{
+ LOG_ENTER
+
+ EmailAccountInfo account = Messaging::getInstance().getCurrentEmailAccount();
+
+ m_mail.Reset(EmailService::readMail(account.getIntId(), getIntId()));
+
+ if (m_mail->head) { readHeader(); }
+ if (m_mail->body) { readBody(); }
+ if (m_mail->info) { readInfo(); }
+
+ m_mailbox.Reset(
+ EmailService::getMailboxByMailId(account.getIntId(), getIntId())
+ );
+ setFolderType(EmailConverter::toFolderType(m_mailbox->mailbox_type));
+
+ LOG_EXIT
+}
+
+void Email::readHeader()
+{
+ LOG_ENTER
+
+ Assert(m_mail && m_mail->head && "Header is NULL.");
+
+ if (m_mail->head->subject) {
+ setSubject(m_mail->head->subject);
+ }
+
+ if (m_mail->head->to) {
+ appendToRecipients(EmailUtils::stripAddressLine(m_mail->head->to));
+ }
+
+ if (m_mail->head->cc) {
+ appendCcRecipients(EmailUtils::stripAddressLine(m_mail->head->cc));
+ }
+
+ if (m_mail->head->bcc) {
+ appendBccRecipients(EmailUtils::stripAddressLine(m_mail->head->bcc));
+ }
+
+ time_t rawtime;
+ time(&rawtime);
+ struct tm tmpTime = *(localtime(&rawtime));
+ tmpTime.tm_year = m_mail->head->datetime.year;
+ tmpTime.tm_mon = m_mail->head->datetime.month;
+ tmpTime.tm_mday = m_mail->head->datetime.day;
+ tmpTime.tm_hour = m_mail->head->datetime.hour;
+ tmpTime.tm_min = m_mail->head->datetime.minute;
+ tmpTime.tm_sec = m_mail->head->datetime.second;
+ mktime(&tmpTime);
+ setDateTime(tmpTime);
+
+ if (m_mail->head->from) {
+ Recipients from;
+ from.setRecipients(m_mail->head->from);
+ setSourceAddress(from);
+ setSourceAddressValidity(true); //not needed to update in platform
+ }
+
+ LOG_EXIT
+}
+
+void Email::readBody()
+{
+ LOG_ENTER
+
+ Assert(m_mail && m_mail->body && "Body is NULL.");
+
+ if (m_mail->body->plain) {
+ DPL::ScopedFClose file(::fopen(m_mail->body->plain, "r"));
+ if (!file) {
+ ThrowMsg(Commons::PlatformException,
+ "Cannot read body file: " << m_mail->body->plain);
+ }
+ fseek(file.Get(), 0, SEEK_END);
+ long int size = ftell(file.Get());
+ fseek(file.Get(), 0, SEEK_SET);
+ DPL::ScopedPtr<char> data(new char[size + 1]);
+ memset(data.Get(), 0, size + 1);
+ fread(data.Get(), 1, size, file.Get());
+ setBody(data.Get());
+ }
+
+ if (m_mail->body->attachment && m_mail->body->attachment_num > 0) {
+ LogDebug("reading attachments");
+ emf_attachment_info_t* attach = m_mail->body->attachment;
+ for (int i = 0; i < m_mail->body->attachment_num; ++i) {
+ if (!attach) {
+ ThrowMsg(Commons::PlatformException,
+ "Attachment list shorter than expected.");
+ }
+ try {
+ IAttachmentPtr tmpAtt = appendAttachment(attach->savename,
+ false);
+ tmpAtt->rename(attach->name);
+ attach = attach->next;
+ }
+ catch (const Commons::Exception& ex) {
+ LogError("Error while trying to append attachment " <<
+ attach->savename << ": " << ex.DumpToString());
+ }
+ }
+ }
+
+ LOG_EXIT
+}
+
+void Email::readInfo()
+{
+ LOG_ENTER
+
+ Assert(m_mail && m_mail->info && "Info is NULL.");
+
+ setReadStatus(m_mail->info->flags.seen == 1);
+
+ m_accountId = m_mail->info->account_id;
+
+ setPriority(
+ EmailConverter::toMessagePriority(
+ m_mail->info->extra_flags.priority
+ )
+ );
+ setSize(m_mail->info->rfc822_size);
+
+ LOG_EXIT
+}
+
+void Email::updateBody()
+{
+ LOG_ENTER
+
+ if (isBodyValid()) { return; }
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail is NULL.");
+ }
+
+ if (!m_mail->body) {
+ ThrowMsg(Commons::PlatformException, "Body is NULL.");
+ }
+ if (!m_mail->body->plain) {
+ ThrowMsg(Commons::PlatformException, "Body file is NULL.");
+ }
+ if (!m_mail->info) {
+ ThrowMsg(Commons::PlatformException, "Info is NULL.");
+ }
+
+ FILE* f = fopen(m_mail->body->plain, "w");
+ if (NULL != f) {
+ fprintf(f, getBodyRef().c_str());
+ fclose(f);
+ }
+ m_mail->info->body_downloaded = true;
+ setBodyValidity(true);
+
+ LOG_EXIT
+}
+
+void Email::updateSubject()
+{
+ LOG_ENTER
+
+ if (isSubjectValid()) { return; }
+
+ LogDebug("update subject, msgId=" << getIdRef());
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail not allocated.");
+ }
+
+ if (!m_mail->head) {
+ m_mail->head = EmailService::alloc<emf_mail_head_t>();
+ }
+
+ m_mail->head->subject = Commons::String::strdup(getSubjectRef());
+ setSubjectValidity(true);
+
+ LOG_EXIT
+}
+
+void Email::updateReadStatus()
+{
+ LOG_ENTER
+
+ if (isReadStatusValid()) { return; }
+
+ LogDebug("update read, msgId=" << getIdRef());
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail not allocated.");
+ }
+
+ if (!m_mail->info) {
+ EmailService::alloc<emf_mail_info_t>();
+ }
+
+ m_mail->info->flags.seen = isRead();
+ setReadStatusValidity(true);
+
+ LOG_EXIT
+}
+
+void Email::updateRecipients()
+{
+ LOG_ENTER
+
+ if (getToValidity() && getCcValidity() && getBccValidity()) { return; }
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail is NULL.");
+ }
+
+ if (!m_mail->head) {
+ m_mail->head = EmailService::alloc<emf_mail_head_t>();
+ }
+
+ if (!getToValidity()) {
+ std::string addressLine = EmailUtils::formatAddressLine(getToRecipients());
+ if (m_mail->head->to) {
+ free(m_mail->head->to);
+ }
+ m_mail->head->to = Commons::String::strdup(addressLine);
+ setToValidity(true);
+ }
+
+ if (!getCcValidity()) {
+ std::string addressLine = EmailUtils::formatAddressLine(getCcRecipients());
+ if (m_mail->head->cc) {
+ free(m_mail->head->cc);
+ }
+ m_mail->head->cc = Commons::String::strdup(addressLine);
+ setCcValidity(true);
+ }
+
+ if (!getBccValidity()) {
+ std::string addressLine = EmailUtils::formatAddressLine(
+ getBccRecipients());
+ if (m_mail->head->bcc) {
+ free(m_mail->head->bcc);
+ }
+ m_mail->head->bcc = Commons::String::strdup(addressLine);
+ setBccValidity(true);
+ }
+
+ LOG_EXIT
+}
+
+void Email::updateFrom()
+{
+ LOG_ENTER
+
+ if (getFromValidity()) { return; }
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail is NULL.");
+ }
+
+ if (!m_mail->info) {
+ EmailService::alloc<emf_mail_info_t>();
+ }
+
+ m_mail->info->account_id = Messaging::getInstance().getEmailAccountId(
+ getFrom());
+ // TODO Update m_mail->head->from as well
+
+ setFromValidity(true);
+
+ LOG_EXIT
+}
+
+void Email::updateAttachments()
+{
+ LOG_ENTER
+
+ if (isAttachmentsValid()) { return; }
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail is NULL.");
+ }
+
+ emf_attachment_info_t* attachment = NULL;
+ Try {
+ LogDebug("update attachments, msgId=" << getIdRef());
+
+ if (!m_mail->body) {
+ m_mail->body = EmailService::alloc<emf_mail_body_t>();
+ } else {
+ m_mail->body->attachment_num = 0;
+ if (NULL != m_mail->body->attachment) {
+ EmailService::freeAttachment(m_mail->body->attachment);
+ m_mail->body->attachment = NULL;
+ }
+ }
+
+ std::size_t attachmentSize = getAttachmentsCount();
+ if (attachmentSize > 0) {
+ if (!m_mail->info) {
+ ThrowMsg(Commons::PlatformException, "Mail info is NULL.");
+ }
+
+ for (std::size_t i = 0; i < attachmentSize; ++i) {
+ IAttachmentPtr att = getAttachment(i);
+ if (!att) {
+ continue;
+ }
+
+ LogDebug("updating attachment=" << att->getShortName());
+
+ attachment = EmailService::alloc<emf_attachment_info_t>();
+ attachment->name = Commons::String::strdup(att->getShortName());
+ attachment->savename = Commons::String::strdup(
+ att->getFullPath()
+ );
+ attachment->downloaded = true;
+ attachment->next = NULL;
+
+ int error = email_add_attachment(m_mailbox.Get(),
+ m_mail->info->uid,
+ attachment);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while adding attachment. [" << error << "]");
+ }
+
+ EmailService::freeAttachment(attachment);
+ }
+
+ setAttachmentsValidity(true);
+ }
+ }
+ Catch(Commons::PlatformException) {
+ EmailService::freeAttachment(attachment);
+ throw;
+ }
+
+ LOG_EXIT
+}
+
+void Email::updatePriority()
+{
+ LOG_ENTER
+
+ if (isPriorityValid()) { return; }
+
+ if (!m_mail) {
+ ThrowMsg(Commons::PlatformException, "Mail not allocated.");
+ }
+
+ if (!m_mail->info) {
+ m_mail->info = EmailService::alloc<emf_mail_info_t>();
+ }
+
+ m_mail->info->extra_flags.priority = EmailConverter::toMailPriority(
+ getPriority());
+ setPriorityValid(true);
+
+ LOG_EXIT
+}
+
+int Email::getIntId() const
+{
+ return convertId(getIdRef());
+}
+}
+}
--- /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 Email.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef EMAIL_H
+#define EMAIL_H
+
+#include <string>
+#include <dpl/mutex.h>
+#include <API/Messaging/IEmail.h>
+#include <API/Messaging/IMessagingTypes.h>
+
+#include "ScopedMail.h"
+#include "ScopedMailbox.h"
+
+// The email service library
+extern "C" {
+//temporary solution for email-service problem (compilation break)
+#ifndef NOW_REVERT
+//#define NOW_REVERT
+#endif
+#ifndef SUPPORT_CONTACT_ON_SIM
+//#define SUPPORT_CONTACT_ON_SIM
+#endif
+#ifndef _A_PROJECT_
+#define _A_PROJECT_
+#endif
+
+#ifndef _PREVIEW_IN_MAILIST
+#define _PREVIEW_IN_MAILIST
+#endif
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class Email : public Api::IEmail
+{
+ public:
+ explicit Email(const std::string& id = std::string());
+
+ virtual ~Email();
+
+ virtual void send();
+
+ virtual void sendCancel();
+
+ // implementation of interface of IMessage class
+ virtual void update(bool draftsOnly = false);
+
+ virtual void readAllData();
+
+ virtual void moveToFolder(const Api::FolderType newFolder);
+
+ virtual void moveToFolder(const std::string& newFolder);
+
+ virtual void copyToFolder(const Api::FolderType newFolder);
+
+ virtual void copyToFolder(const std::string& newFolder);
+
+ virtual void remove();
+
+ virtual int getAccountId() const;
+
+ private:
+ void create();
+
+ void reload();
+
+ void readHeader();
+
+ void readBody();
+
+ void readInfo();
+
+ void updateBody();
+
+ void updateRecipients();
+
+ void updateFrom();
+
+ void updateAttachments();
+
+ void updateSubject();
+
+ void updateReadStatus();
+
+ void updatePriority();
+
+ int getIntId() const;
+
+ private:
+ DPL::Mutex m_updateMutex;
+ int m_accountId;
+ ScopedMail m_mail;
+ ScopedMailbox m_mailbox;
+};
+}
+}
+
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+#include <dpl/log/log.h>
+
+#include <Commons/Exception.h>
+
+#include "EmailConverter.h"
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace EmailConverter {
+
+emf_mail_priority_t toMailPriority(Api::MessagePriority::Priority priority)
+{
+ LOG_ENTER
+ switch (priority) {
+ case Api::MessagePriority::LOW: return EMF_MAIL_PRIORITY_LOW;
+ case Api::MessagePriority::NORMAL: return EMF_MAIL_PRIORITY_NORMAL;
+ case Api::MessagePriority::HIGH: return EMF_MAIL_PRIORITY_HIGH;
+ default:
+ ThrowMsg(Commons::PlatformException,
+ "Unsupported priority: " << priority);
+ }
+}
+
+Api::MessagePriority::Priority toMessagePriority(emf_mail_priority_t priority)
+{
+ LOG_ENTER
+ switch (priority) {
+ case EMF_MAIL_PRIORITY_LOW: return Api::MessagePriority::LOW;
+ case EMF_MAIL_PRIORITY_NORMAL: return Api::MessagePriority::NORMAL;
+ case EMF_MAIL_PRIORITY_HIGH: return Api::MessagePriority::HIGH;
+ default:
+ // TODO Think it through, log is enough or exception should be thrown.
+ // ThrowMsg(Commons::PlatformException,
+ // "Unsupported platform priority: " << priority);
+ LogWarning("Unsupported platform priority");
+ }
+
+ // TODO Fix this. What to return if non-existing priority returned by platform.
+ return Api::MessagePriority::NORMAL;
+}
+
+Api::MessagePriority::Priority toMessagePriority(unsigned char priority)
+{
+ return toMessagePriority(static_cast<emf_mail_priority_t>(priority));
+}
+
+emf_mailbox_type_e toMailboxType(Api::FolderType folder)
+{
+ LOG_ENTER
+ switch (folder) {
+ case Api::INBOX: return EMF_MAILBOX_TYPE_INBOX;
+ case Api::OUTBOX: return EMF_MAILBOX_TYPE_OUTBOX;
+ case Api::SENTBOX: return EMF_MAILBOX_TYPE_SENTBOX;
+ case Api::DRAFTBOX: return EMF_MAILBOX_TYPE_DRAFT;
+ case Api::SPAMBOX: return EMF_MAILBOX_TYPE_SPAMBOX;
+ case Api::ALL_FOLDERS: return EMF_MAILBOX_TYPE_ALL_EMAILS;
+ case Api::USERDEFINED_FOLDER: return EMF_MAILBOX_TYPE_USER_DEFINED;
+ default:
+ ThrowMsg(Commons::PlatformException, "Conversion failed.");
+ }
+}
+
+const char* toMailboxName(Api::FolderType folder)
+{
+ LOG_ENTER
+ switch (folder) {
+ case Api::INBOX: return EMF_INBOX_NAME;
+ case Api::OUTBOX: return EMF_OUTBOX_NAME;
+ case Api::SENTBOX: return EMF_SENTBOX_NAME;
+ case Api::DRAFTBOX: return EMF_DRAFTBOX_NAME;
+ case Api::SPAMBOX: return EMF_SPAMBOX_NAME;
+ default:
+ ThrowMsg(Commons::PlatformException,
+ "Mailbox not found. Folder: " << folder);
+ }
+}
+
+Api::FolderType toFolderType(emf_mailbox_type_e mailboxType)
+{
+ LOG_ENTER
+ switch (mailboxType) {
+ case EMF_MAILBOX_TYPE_INBOX: return Api::INBOX;
+ case EMF_MAILBOX_TYPE_OUTBOX: return Api::OUTBOX;
+ case EMF_MAILBOX_TYPE_SENTBOX: return Api::SENTBOX;
+ case EMF_MAILBOX_TYPE_DRAFT: return Api::DRAFTBOX;
+ case EMF_MAILBOX_TYPE_SPAMBOX: return Api::SPAMBOX;
+ case EMF_MAILBOX_TYPE_ALL_EMAILS: return Api::ALL_FOLDERS;
+ case EMF_MAILBOX_TYPE_USER_DEFINED: return Api::USERDEFINED_FOLDER;
+ default:
+ ThrowMsg(Commons::PlatformException, "Conversion failed.");
+ }
+}
+}
+}
+}
--- /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 WAC_MESSAGING_EMAILCONVERTER_H_
+#define WAC_MESSAGING_EMAILCONVERTER_H_
+
+#include <emf-types.h>
+
+#include <API/Messaging/MessagePriority.h>
+#include <API/Messaging/IMessagingTypes.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace EmailConverter {
+emf_mail_priority_t toMailPriority(Api::MessagePriority::Priority priority);
+
+Api::MessagePriority::Priority toMessagePriority(emf_mail_priority_t priority);
+Api::MessagePriority::Priority toMessagePriority(unsigned char priority);
+
+emf_mailbox_type_e toMailboxType(Api::FolderType folder);
+
+const char* toMailboxName(Api::FolderType folder);
+
+Api::FolderType toFolderType(emf_mailbox_type_e mailboxType);
+}
+}
+}
+
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+#include <string>
+#include <sstream>
+
+#include <dpl/assert.h>
+#include <dpl/scoped_free.h>
+
+#include <Emf_Mapi.h>
+
+#include <Commons/Exception.h>
+#include "EmailUtils.h"
+#include "EmailService.h"
+#include "ScopedMail.h"
+#include "ScopedMailbox.h"
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace EmailService {
+emf_mail_t* createMail(const Api::EmailAccountInfo& account)
+{
+ LOG_ENTER
+ ScopedMail result(alloc<emf_mail_t>());
+
+ result->info = alloc<emf_mail_info_t>();
+ result->info->account_id = account.getIntId();
+ result->info->flags.draft = 1;
+ result->info->extra_flags.priority = EMF_MAIL_PRIORITY_NORMAL;
+
+ result->head = alloc<emf_mail_head_t>();
+ std::string from = EmailUtils::formatAddress(account.getAddress(),
+ account.getName());
+ result->head->from = strdup(from.c_str());
+
+ result->body = alloc<emf_mail_body_t>();
+ std::string bodyFile = tmpnam(NULL);
+ // TODO: change following two lines to some (not implemented yet) call
+ // to Filesystem module (e.g. Filesystem::IManager::getInstance().touch(PATH)).
+ FILE* f = fopen(bodyFile.c_str(), "w");
+ fclose(f);
+ result->body->plain = strdup(bodyFile.c_str());
+
+ LOG_EXIT
+ return result.Release();
+}
+
+emf_mail_t* readMail(int accountId,
+ int mailId)
+{
+ LOG_ENTER
+ emf_mail_t* result = NULL;
+
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0, sizeof(emf_mailbox_t));
+ mailbox.account_id = accountId;
+
+ int error = email_get_mail(&mailbox, mailId, &result);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't find message " << mailId << ". [" << error << "]");
+ }
+
+ LOG_EXIT
+ return result;
+}
+
+void deleteMail(int accountId,
+ int mailId)
+{
+ LOG_ENTER
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0, sizeof(emf_mailbox_t));
+ mailbox.account_id = accountId;
+
+ int error = email_delete_message(&mailbox, &mailId, 1, 0);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Error while deleting mail. [" << error << "]");
+ }
+ LOG_EXIT
+}
+
+emf_mailbox_t* getMailboxByType(int accountId,
+ emf_mailbox_type_e type)
+{
+ LOG_ENTER
+ emf_mailbox_t* result = NULL;
+
+ int error = email_get_mailbox_by_mailbox_type(accountId, type, &result);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't retrieve mailbox. [" << error << "]");
+ }
+
+ LOG_ENTER
+ return result;
+}
+
+int addMailToMailbox(emf_mail_t* mail,
+ emf_mailbox_t* mailbox)
+{
+ LOG_ENTER
+ Assert(mail && mailbox);
+
+ int error = email_add_message(mail, mailbox, 1);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't add message to mailbox. [" << error << "]");
+ }
+
+ LOG_EXIT
+ return mail->info->uid;
+}
+
+void freeAttachment(emf_attachment_info_t* attachment)
+{
+ LOG_ENTER
+ if (NULL == attachment) { return; }
+
+ int error = email_free_attachment_info(&attachment);
+ if (EMF_ERROR_NONE != error) {
+ LogWarning("Couldn't free attachment. [" << error << "]");
+ }
+ LOG_ENTER
+}
+
+emf_mailbox_t* createMailbox(int accountId,
+ const char* name)
+{
+ LOG_ENTER
+ emf_mailbox_t* result = alloc<emf_mailbox_t>();
+ result->account_id = accountId;
+ result->name = (NULL != name ? strdup(name) : NULL);
+
+ LOG_EXIT
+ return result;
+}
+
+// TODO This clonning is not efficent.
+emf_mail_t* cloneMail(const emf_mail_t* mail)
+{
+ LOG_ENTER
+ emf_mail_t* result = readMail(mail->info->account_id, mail->info->uid);
+ result->info->uid = 0;
+
+ LOG_EXIT
+ return result;
+}
+
+emf_mailbox_t* getMailboxByMailId(int accountId,
+ int mailId)
+{
+ LOG_ENTER
+ char* mailboxName = NULL;
+ int error = email_get_mailbox_name_by_mail_id(mailId, &mailboxName);
+ // Platform may allocate mailboxName and yet return an error code.
+ DPL::ScopedFree<char> freeGuard(mailboxName);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't get mailbox name. [" << error << "]");
+ }
+
+ emf_mailbox_t* result = NULL;
+ error = email_get_mailbox_by_name(accountId, mailboxName, &result);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't get mailbox. [" << error << "]");
+ }
+
+ LOG_EXIT
+ 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WAC_MESSAGING_EMAILSERVICE_H_
+#define WAC_MESSAGING_EMAILSERVICE_H_
+
+#include <cstring>
+#include <cstdlib>
+#include <new>
+
+#include <emf-types.h>
+
+#include <API/Messaging/EmailAccountInfo.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace EmailService {
+
+template<typename T>
+T* alloc()
+{
+ T* result = static_cast<T*>(::malloc(sizeof(T)));
+ if (NULL == result) {
+ throw std::bad_alloc();
+ }
+ ::memset(result, 0, sizeof(*result));
+ return result;
+}
+
+emf_mail_t* createMail(const WrtDeviceApis::Messaging::Api::EmailAccountInfo& account);
+
+emf_mail_t* readMail(int accountId,
+ int mailId);
+
+emf_mailbox_t* getMailboxByType(int accountId,
+ emf_mailbox_type_e type);
+
+int addMailToMailbox(emf_mail_t* mail,
+ emf_mailbox_t* mailbox);
+
+void deleteMail(int accountId,
+ int mailId);
+
+void freeAttachment(emf_attachment_info_t* attachment);
+
+emf_mailbox_t* createMailbox(int accountId,
+ const char* name);
+
+emf_mail_t* cloneMail(const emf_mail_t* mail);
+
+emf_mailbox_t* getMailboxByMailId(int accountId,
+ int mailId);
+}
+}
+}
+
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+#include <sstream>
+#include <pcrecpp.h>
+
+#include <Commons/Exception.h>
+#include <Commons/StringBuilder.h>
+#include <Commons/StringUtils.h>
+#include "EmailUtils.h"
+
+namespace {
+const char* EMAIL_ADDRESS_REGEX =
+ "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}";
+
+using WrtDeviceApis::Commons::StringBuilder;
+
+const std::string EMAIL_ADDRESS_REGEX_GROUP =
+ StringBuilder()
+ .append("(")
+ .append(EMAIL_ADDRESS_REGEX)
+ .append(")")
+ .toString();
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace EmailUtils {
+std::string formatAddress(const std::string& address,
+ const std::string& name)
+{
+ if (address.empty()) {
+ ThrowMsg(Commons::PlatformException, "Address is empty.");
+ }
+
+ std::stringstream ss;
+ if (!name.empty()) {
+ ss << "\"" << name << "\" ";
+ }
+ ss << "<" << address << ">";
+
+ return ss.str();
+}
+
+std::string formatAddressLine(const Api::Recipients& recipients)
+{
+ std::string result;
+ for (size_t i = 0; i < recipients.getRecipientSize(); ++i) {
+ result += formatAddress(recipients.getRecipient(i)) + ";";
+ }
+ return result;
+}
+
+std::string stripAddress(const std::string& address)
+{
+ std::string result;
+ pcrecpp::RE re(EMAIL_ADDRESS_REGEX_GROUP);
+ if (!re.PartialMatch(address, &result)) {
+ ThrowMsg(Commons::PlatformException, "Couldn't discover email address");
+ }
+ return result;
+}
+
+Api::Recipients stripAddressLine(const std::string& addressLine)
+{
+ typedef std::vector<std::string> Addresses;
+
+ Api::Recipients result;
+ Addresses addresses = Commons::String::split(addressLine, ';');
+ for (Addresses::iterator it = addresses.begin();
+ it != addresses.end();
+ ++it) {
+ result.appendRecipient(stripAddress(*it));
+ }
+ 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WAC_MESSAGING_EMAILUTILS_H_
+#define WAC_MESSAGING_EMAILUTILS_H_
+
+#include <string>
+
+#include <API/Messaging/Recipient.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+namespace EmailUtils {
+/**
+ * Formats address as: "Name" <address>.
+ * @param address E-mail address.
+ * @param name Name, omitted if empty.
+ * @return Formatted address.
+ */
+std::string formatAddress(const std::string& address,
+ const std::string& name = std::string());
+
+/**
+ * Formats multiple addresses as: "Name1" <address1>;"Name2" <address2>...
+ * @param recipients Recipients to build address line from.
+ * @return Formatted addresses.
+ */
+std::string formatAddressLine(const Api::Recipients& recipients);
+
+/**
+ * Extracts bare e-mail address.
+ * @param address Address to strip.
+ * @return E-mail address.
+ */
+std::string stripAddress(const std::string& address);
+
+/**
+ * Extracts recipients bare e-mail addresses.
+ * @param addressLine Address line to split and strip.
+ * @return Recipients.
+ */
+Api::Recipients stripAddressLine(const std::string& addressLine);
+}
+}
+}
+
+#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 ISendingObserver.h
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef ISENDINGOBSERVER_H_
+#define ISENDINGOBSERVER_H_
+
+#include "CallbackMgr.h"
+
+extern "C" {
+#include <MsgTransportTypes.h>
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+/*
+ *
+ */
+class ISendingObserver
+{
+ public:
+ ISendingObserver() : m_reqId(0)
+ {
+ }
+
+ virtual ~ISendingObserver()
+ {
+ if (m_reqId) {
+ CallbackMgrSingleton::Instance().unregister(m_reqId);
+ }
+ }
+
+ void setSendigRequestId(int id)
+ {
+ m_reqId = id;
+ }
+
+ void setRecipient(const char* arg)
+ {
+ m_recipient = arg;
+ }
+
+ std::string getRecipient() const
+ {
+ return m_recipient;
+ }
+
+ virtual void sendingCallback(MSG_SENT_STATUS_S *sent_status) = 0;
+
+ private:
+ int m_reqId;
+ std::string m_recipient;
+};
+}
+}
+
+#endif /* ISENDINGOBSERVER_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 MailNotifier.cpp
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#include <string>
+#include <emf-types.h>
+#include <Commons/ThreadPool.h>
+#include "MailNotifier.h"
+#include "StorageChangeMessage.h"
+#include "NetworkStatus.h"
+
+namespace {
+const std::string DBUS_INTERFACE_STORAGE_CHANGE = "User.Email.StorageChange";
+const std::string DBUS_FILTER_STORAGE_CHANGE =
+ "type='signal',interface='" + DBUS_INTERFACE_STORAGE_CHANGE + "'";
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+
+MailNotifier::MailNotifier() : m_connection(new DBus::Connection())
+{
+ m_connection->AddListener(this);
+ m_connection->addFilter(DBUS_FILTER_STORAGE_CHANGE);
+ m_connection->open(DBUS_BUS_SYSTEM);
+}
+
+MailNotifier::~MailNotifier()
+{
+ m_connection->RemoveListener(this);
+ m_connection->close();
+}
+
+void MailNotifier::setWorkerThread(DPL::Thread* thread)
+{
+ m_connection->SwitchListenerToThread(this, thread);
+}
+
+void MailNotifier::OnEventReceived(const DBus::MessageEvent& event)
+{
+ LogDebug("ENTER");
+ DBus::MessagePtr message = event.GetArg0();
+ if (message->getInterface() == DBUS_INTERFACE_STORAGE_CHANGE)
+ {
+ onStorageChange(message);
+ }
+}
+
+void MailNotifier::onStorageChange(const DBus::MessagePtr& message)
+{
+ LogDebug("ENTER");
+ StorageChangeMessage sc = StorageChangeMessage::parse(message);
+ int mailId = sc.getMailId();
+ switch (sc.getType())
+ {
+ case NOTI_MAIL_ADD:
+ LogDebug("NOTI_MAIL_ADD [mail id = " << mailId << "]");
+ m_incomming.push_back(mailId);
+ break;
+
+ case NOTI_MAIL_UPDATE:
+ LogDebug("NOTI_MAIL_UPDATE [mail id: " << mailId << "]");
+ if (sc.getExtra() == UPDATE_PARTIAL_BODY_DOWNLOAD)
+ {
+ auto it = std::find(m_incomming.begin(), m_incomming.end(), mailId);
+ if (m_incomming.end() != it)
+ {
+ m_incomming.erase(it);
+ DPL::Event::EventSupport<EmailReceivedEvent>::EmitEvent(
+ EmailReceivedEvent(mailId));
+ }
+ }
+ break;
+ }
+}
+
+}
+}
--- /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 MailNotifier.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef SRC_MODULES_TIZEN_MESSAGING_MAILNOTIFIER_H_
+#define SRC_MODULES_TIZEN_MESSAGING_MAILNOTIFIER_H_
+
+#include <dpl/thread.h>
+#include <dpl/generic_event.h>
+#include <dpl/event/event_support.h>
+#include <dpl/event/event_listener.h>
+#include <API/Messaging/IMessage.h>
+#include <DBus/Connection.h>
+#include <DBus/Message.h>
+#include <DBus/MessageEvent.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+
+DECLARE_GENERIC_EVENT_1(EmailReceivedEvent, int);
+
+class MailNotifier : public DPL::Event::EventSupport<EmailReceivedEvent>,
+ private DPL::Event::EventListener<DBus::MessageEvent>
+{
+public:
+ MailNotifier();
+ virtual ~MailNotifier();
+
+ void setWorkerThread(DPL::Thread* thread);
+
+protected:
+ virtual void OnEventReceived(const DBus::MessageEvent& event);
+
+ virtual void onStorageChange(const DBus::MessagePtr& message);
+
+private:
+ DBus::ConnectionPtr m_connection;
+ std::vector<int> m_incomming;
+};
+
+}
+}
+
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+#include <utility>
+#include <emf-types.h>
+#include <Emf_Mapi_Network.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <Commons/ThreadPool.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include <API/Messaging/EventSendMessage.h>
+#include <API/Messaging/EventOnSendingFailed.h>
+#include "MailSender.h"
+#include "NetworkStatus.h"
+#include "Messaging.h"
+
+namespace {
+const char* DBUS_FILTER_NETWORK_STATUS =
+ "type='signal',interface='User.Email.NetworkStatus'";
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+MailSender& MailSender::getInstance()
+{
+ static MailSender instance;
+ return instance;
+}
+
+void MailSender::send(const Api::IEmailPtr& mail)
+{
+ Assert(mail && "Mail must not be NULL.");
+
+ int mailId = mail->convertId(mail->getIdRef());
+ SendRequestsIterator it = m_requests.find(mailId);
+ if (m_requests.end() != it) {
+ ThrowMsg(Commons::PlatformException,
+ "Email: " << mailId << " already requested to be send.");
+ }
+
+ sendInternal(mail);
+}
+
+void MailSender::cancel(int mailId)
+{
+ SendRequestsIterator it = m_requests.find(mailId);
+ if (m_requests.end() == it) {
+ ThrowMsg(Commons::PlatformException,
+ "Email: " << mailId << " not found.");
+ }
+
+ cancelInternal(it->second);
+}
+
+// TODO Copied from former solution, refactor it.
+void MailSender::OnEventReceived(const DBus::MessageEvent& event)
+{
+ LogDebug("HERE");
+ NetworkStatusPtr msg(new NetworkStatus(event.GetArg0()));
+ int mailId = msg->getMailId();
+
+ SendRequestsIterator it = m_requests.find(mailId);
+ if (m_requests.end() != it) {
+ switch (msg->getStatus()) {
+ case NOTI_SEND_START:
+ LogInfo("Start sending e-mail: " << mailId);
+ break;
+
+ case NOTI_SEND_FINISH:
+ {
+ const Api::IEmailPtr& mail = it->second.mail;
+ Api::EventSendMessageReqReceiver* requestReceiver =
+ mail->getRequestReceiver();
+ if (requestReceiver)
+ {
+ Api::EventSendMessagePtr event = mail->getSendMessageEvent();
+ event->addRecipientsSendResult(
+ mail->getToRecipientsPtr()->getRecipientsRef(),
+ true);
+ event->addRecipientsSendResult(
+ mail->getCcRecipientsPtr()->getRecipientsRef(),
+ true);
+ event->addRecipientsSendResult(
+ mail->getBccRecipientsPtr()->getRecipientsRef(),
+ true);
+ requestReceiver->ManualAnswer(event);
+ }
+ LogInfo("E-mail sent: " << mailId);
+ m_requests.erase(mailId);
+ break;
+ }
+
+ case NOTI_SEND_FAIL:
+ {
+ const Api::IEmailPtr& mail = it->second.mail;
+ Api::EventOnSendingFailedEmitterPtr emitter = mail->getEmitter();
+ Api::EventSendMessageReqReceiver *requestReceiver =
+ mail->getRequestReceiver();
+ if (emitter) {
+ Api::EventOnSendingFailedPtr event(
+ new Api::EventOnSendingFailed()
+ );
+ switch (msg->getErrorCode()) {
+ case EMF_ERROR_NO_SIM_INSERTED:
+ case EMF_ERROR_FLIGHT_MODE:
+ event->setError(
+ Api::EventOnSendingFailed::NO_NETWORKING
+ );
+ break;
+
+ case EMF_ERROR_SMTP_SEND_FAILURE:
+ case EMF_ERROR_NO_SUCH_HOST:
+ case EMF_ERROR_CONNECTION_FAILURE:
+ case EMF_ERROR_CONNECTION_BROKEN:
+ case EMF_ERROR_INVALID_SERVER:
+ case EMF_ERROR_NO_RESPONSE:
+ event->setError(
+ Api::EventOnSendingFailed::NO_CONNECTION
+ );
+ break;
+
+ default:
+ event->setError(Api::EventOnSendingFailed::UNKNOWN);
+ }
+ emitter->emit(event);
+ }
+ else if (requestReceiver)
+ {
+ Api::EventSendMessagePtr event = mail->getSendMessageEvent();
+ event->addRecipientsSendResult(
+ mail->getToRecipientsPtr()->getRecipientsRef(),
+ false);
+ event->addRecipientsSendResult(
+ mail->getCcRecipientsPtr()->getRecipientsRef(),
+ false);
+ event->addRecipientsSendResult(
+ mail->getBccRecipientsPtr()->getRecipientsRef(),
+ false);
+ event->setExceptionCode(
+ Commons::ExceptionCodes::UnknownException
+ );
+ requestReceiver->ManualAnswer(event);
+ }
+ LogInfo("Sending e-mail: " << mailId <<
+ " failed with error: " << msg->getErrorCode());
+ m_requests.erase(mailId);
+ break;
+ }
+ }
+ }
+}
+
+MailSender::MailSender() :
+ m_dbusThread(new DPL::Thread()),
+ m_dbus(new DBus::Connection())
+{
+ m_dbusThread->Run();
+
+ m_dbus->setWorkerThread(m_dbusThread.Get());
+ m_dbus->AddListener(this);
+ m_dbus->SwitchAllListenersToThread(
+ Commons::ThreadPool::getInstance().getThreadRef(Commons::ThreadEnum::MESSAGING_THREAD)
+ );
+ m_dbus->addFilter(DBUS_FILTER_NETWORK_STATUS);
+ m_dbus->open(DBUS_BUS_SYSTEM);
+}
+
+MailSender::~MailSender()
+{
+ m_dbus->RemoveListener(this);
+ m_dbus->close();
+
+ m_dbusThread->Quit();
+}
+
+void MailSender::sendInternal(const Api::IEmailPtr& mail)
+{
+ int mailId = mail->convertId(mail->getIdRef());
+
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0, sizeof(emf_mailbox_t));
+ mailbox.account_id =
+ Messaging::getInstance().getEmailAccountId(mail->getFromRef());
+ // TODO remove ugly casting.
+ mailbox.name = (char*)EMF_SENTBOX_NAME;
+
+ emf_option_t options;
+ memset(&options, 0, sizeof(emf_option_t));
+ options.keep_local_copy = 1;
+
+ m_requests.insert(std::make_pair(mailId, SendRequestData(mail)));
+
+ int error = email_send_mail(&mailbox,
+ mailId,
+ &options,
+ &m_requests.at(mailId).handle);
+ if (EMF_ERROR_NONE != error) {
+ m_requests.erase(mailId);
+ ThrowMsg(Commons::PlatformException,
+ "Failed to initialize send request. [" << error << "]");
+ }
+}
+
+void MailSender::cancelInternal(const SendRequestData& data)
+{
+ int mailId = data.mail->convertId(data.mail->getIdRef());
+
+ int error = email_cancel_job(data.mail->getAccountId(), data.handle);
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't cancel sending for email: " <<
+ data.mail->getIdRef());
+ }
+
+ m_requests.erase(mailId);
+}
+}
+}
--- /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 MAILSENDER_H_
+#define MAILSENDER_H_
+
+#include <map>
+#include <dpl/event/event_listener.h>
+#include <dpl/thread.h>
+#include <dpl/scoped_ptr.h>
+#include <DBus/Connection.h>
+#include <DBus/MessageEvent.h>
+#include <API/Messaging/IEmail.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+// TODO Not thread-safe, make it.
+class MailSender : private DPL::Event::EventListener<DBus::MessageEvent>
+{
+ public:
+ static MailSender& getInstance();
+
+ public:
+ void send(const Api::IEmailPtr& mail);
+ void cancel(int mailId);
+
+ protected:
+ void OnEventReceived(const DBus::MessageEvent& event);
+
+ private:
+ struct SendRequestData
+ {
+ unsigned int handle;
+ Api::IEmailPtr mail;
+
+ explicit SendRequestData(const Api::IEmailPtr& mail) :
+ handle(0),
+ mail(mail)
+ {
+ }
+ };
+
+ typedef std::map<int, SendRequestData> SendRequests;
+ typedef SendRequests::iterator SendRequestsIterator;
+
+ private:
+ MailSender();
+ ~MailSender();
+
+ void sendInternal(const Api::IEmailPtr& data);
+ void cancelInternal(const SendRequestData& data);
+
+ private:
+ DPL::ScopedPtr<DPL::Thread> m_dbusThread;
+ DBus::ConnectionPtr m_dbus;
+ SendRequests m_requests;
+};
+}
+}
+
+#endif // MAILSENDER_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 Messaging.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include <emf-types.h>
+#include <Emf_Mapi.h>
+
+#include <Commons/Exception.h>
+#include <Commons/StringUtils.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_free.h>
+#include "Messaging.h"
+#include "Sms.h"
+#include "Mms.h"
+#include "BinarySms.h"
+#include "Email.h"
+#include "EmailConverter.h"
+#include "EmailService.h"
+#include "NetworkStatus.h"
+
+extern "C" {
+#include <MapiStorage.h>
+#include <MapiControl.h>
+#include <MsgMmsTypes.h>
+#include <MapiTransport.h>
+#include <MapiMessage.h>
+}
+
+#include <Commons/ThreadPool.h>
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+using namespace WrtDeviceApis::Messaging;
+using namespace WrtDeviceApis::Messaging::Api;
+using namespace std;
+
+namespace {
+const int MESSAGE_FIND_LIMIT = 100;
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+
+int Messaging::m_currentEmailAccountId = 0;
+DPL::Atomic Messaging::m_objCounter;
+
+Messaging& Messaging::getInstance()
+{
+ static Messaging instance;
+ return instance;
+}
+
+Messaging::Messaging() :
+ m_onMessageReceivedHandleMgr(NULL),
+ m_mailNotifier(new MailNotifier())
+{
+ Try
+ {
+ const vector<Api::EmailAccountInfo> accounts = getEmailAccounts();
+ LogDebug("Number of emails account=" << accounts.size());
+ if (accounts.size() > 0) {
+ // set default email account - first from the list
+ setCurrentEmailAccount(accounts[0]);
+ } else {
+ LogError("no default email account set");
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("No email accounts available");
+ }
+
+ Catch(Commons::InvalidArgumentException) {
+ LogError("No email accounts available");
+ //current email not configured, skipped
+ }
+
+ Catch(Commons::UnknownException) {
+ LogError("unknown error");
+ }
+
+ // Begin service for email management ?? pmi question if it should be added before email actions
+ if (0 == m_objCounter) {
+ int error = email_service_begin();
+ if (EMF_ERROR_NONE != error) {
+ LogError("email_service_begin() returned error " << error);
+ } else {
+ LogInfo("email_service_begin() executed without error");
+ }
+ }
+ ++m_objCounter;
+
+ m_mailNotifier->AddListener(this);
+}
+
+Messaging::~Messaging()
+{
+ m_mailNotifier->RemoveListener(this);
+
+ if (!--m_objCounter) {
+ int error = email_service_end();
+ if (EMF_ERROR_NONE != error) {
+ LogError("email_service_end() returned error " << error);
+ } else {
+ LogDebug("email_service_end() executed without error");
+ }
+ }
+}
+
+void Messaging::getNumberOfMessages(MessageType msgType,
+ FolderType folder,
+ int* readed,
+ int* unReaded)
+{
+ if (NULL == readed ||
+ NULL == unReaded) {
+ LogError("output pointers are NULL");
+ Throw(Commons::InvalidArgumentException);
+ }
+ *readed = 0;
+ *unReaded = 0;
+ if (Api::SMS == msgType) {
+ getNumberOfSms(folder, readed, unReaded);
+ } else if (Api::MMS == msgType) {
+ getNumberOfMms(folder, readed, unReaded);
+ } else if (Api::EMAIL == msgType) {
+ getNumberOfEmails(folder, readed, unReaded);
+ } else {
+ LogError("wrong message type");
+ Throw(Commons::PlatformException);
+ }
+}
+
+vector<IMessagePtr> Messaging::findMessages(const vector<MessageType>& msgTypes,
+ const string &folder,
+ const MessageFilterPtr& filter)
+{
+ LogDebug("enter");
+ vector<IMessagePtr> retVal;
+ back_insert_iterator< vector<IMessagePtr> > biit(retVal);
+ vector<MessageType>::const_iterator it = msgTypes.begin();
+ for (; it != msgTypes.end(); ++it) {
+ LogDebug("Finding messages (" << *it << ") in folder: " << folder);
+ vector<IMessagePtr> result;
+
+ switch (*it) {
+ case SMS:
+ {
+ FolderType folderEnum = Sms::toFolder(folder);
+ result = findSms(folderEnum, filter);
+ break;
+ }
+ case MMS:
+ {
+ FolderType folderEnum = Mms::toFolder(folder);
+ result = findMms(folderEnum, filter);
+ break;
+ }
+ case EMAIL:
+ {
+ result = findEmail(folder, filter);
+ break;
+ }
+ default:
+ LogError("message type unknown");
+ Throw(Commons::PlatformException);
+ }
+ LogDebug("Found: " << result.size());
+ copy(result.begin(), result.end(), biit);
+ }
+
+ return retVal;
+}
+
+vector<IMessagePtr> Messaging::findMessages(const vector<MessageType>& msgTypes,
+ FolderType folder,
+ const Api::MessageFilterPtr& filter)
+{
+ LogDebug("enter");
+ vector<IMessagePtr> retVal;
+ back_insert_iterator< vector<IMessagePtr> > biit(retVal);
+ vector<MessageType>::const_iterator it = msgTypes.begin();
+ for (; it != msgTypes.end(); ++it) {
+ LogDebug("Finding messages (" << *it << ") in folder: " << folder);
+ vector<IMessagePtr>(Messaging::*findFnPtr)(Api::FolderType folder,
+ const Api::MessageFilterPtr
+ & filter) = NULL;
+
+ switch (*it) {
+ case SMS:
+ {
+ findFnPtr = &Messaging::findSms;
+ break;
+ }
+ case MMS:
+ {
+ findFnPtr = &Messaging::findMms;
+ break;
+ }
+ case EMAIL:
+ {
+ findFnPtr = &Messaging::findEmail;
+ break;
+ }
+ default:
+ LogError("message type unknown");
+ Throw(Commons::PlatformException);
+ }
+ vector<IMessagePtr> result = (this->*findFnPtr)(folder, filter);
+ LogDebug("Found: " << result.size());
+ copy(result.begin(), result.end(), biit);
+ }
+
+ return retVal;
+}
+
+vector<string> Messaging::getMessageIds(MessageType msgType,
+ FolderType folder)
+{
+ switch (msgType) {
+ case SMS:
+ return getSmsIds(folder);
+ case MMS:
+ return getMmsIds(folder);
+ case EMAIL:
+ return getEmailIds(folder);
+ default:
+ LogError("not supported message type");
+ Throw(Commons::InvalidArgumentException);
+ }
+}
+
+vector<string> Messaging::getSmsIds(FolderType folder)
+{
+ vector<string> retVal;
+ msg_message_t msg = msg_new_message();
+ MSG_LIST_S folder_list_view = { 0, NULL };
+
+ Try
+ {
+ const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+ MSG_ERROR_T res = MSG_ERR_UNKNOWN;
+ const MSG_FOLDER_ID_T platformFolder = convertFolderToPlatform(folder);
+ res = msg_get_folder_view_list(
+ MsgGetCommonHandle(), platformFolder, &sort_rules,
+ &folder_list_view);
+
+ if (MSG_SUCCESS != res) {
+ LogError("msg_Get_folder_view_list failed" << res);
+ Throw(Commons::PlatformException);
+ }
+
+ for (int i = 0; i < folder_list_view.nCount; i++) {
+ if (MSG_TYPE_SMS ==
+ msg_get_message_type(folder_list_view.msgInfo[i])) {
+ int l_msgId = msg_get_message_id(folder_list_view.msgInfo[i]);
+ ostringstream stream;
+ stream << l_msgId;
+ retVal.push_back(stream.str());
+ }
+ }
+
+ msg_release_message_list(&folder_list_view);
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("Problem with message creation, cleaning");
+ if (folder_list_view.nCount) {
+ msg_release_message_list(&folder_list_view);
+ }
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ throw;
+ }
+
+ return retVal;
+}
+
+vector<string> Messaging::getMmsIds(FolderType folder)
+{
+ vector<string> retVal;
+ msg_message_t msg = msg_new_message();
+ MSG_LIST_S folder_list_view = { 0, NULL };
+
+ Try
+ {
+ const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+ MSG_ERROR_T res = MSG_ERR_UNKNOWN;
+ const MSG_FOLDER_ID_T platformFolder = convertFolderToPlatform(folder);
+ res = msg_get_folder_view_list(
+ MsgGetCommonHandle(), platformFolder, &sort_rules,
+ &folder_list_view);
+
+ if (MSG_SUCCESS != res) {
+ LogError("msg_Get_folder_view_list failed" << res);
+ Throw(Commons::PlatformException);
+ }
+
+ for (int i = 0; i < folder_list_view.nCount; i++) {
+ if (MSG_TYPE_MMS ==
+ msg_get_message_type(folder_list_view.msgInfo[i])) {
+ int l_msgId = msg_get_message_id(folder_list_view.msgInfo[i]);
+ ostringstream stream;
+ stream << l_msgId;
+ retVal.push_back(stream.str());
+ }
+ }
+
+ msg_release_message_list(&folder_list_view);
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("Problem with message creation, cleaning");
+ if (folder_list_view.nCount) {
+ msg_release_message_list(&folder_list_view);
+ }
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ throw;
+ }
+
+ return retVal;
+}
+
+vector<string> Messaging::getEmailIds(FolderType /*folder*/)
+{
+ vector<string> retVal;
+
+ //TODO
+ LogError("TODO");
+ Throw(Commons::UnknownException);
+
+ return retVal;
+}
+
+vector<EmailAccountInfo> Messaging::getEmailAccounts() const
+{
+ emf_account_t* accounts = NULL;
+ int count = 0;
+ Try {
+ if (!email_get_account_list(&accounts, &count)) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't get e-mail accounts.");
+ }
+
+ if (0 == count) {
+ ThrowMsg(Commons::PlatformException, "No e-mail account found.");
+ }
+
+ vector<Api::EmailAccountInfo> result;
+ for (int i = 0; i < count; ++i) {
+ Api::EmailAccountInfo account(accounts[i].account_id,
+ accounts[i].user_name,
+ accounts[i].email_addr);
+ result.push_back(account);
+ }
+
+ if (accounts != NULL) {
+ email_free_account(&accounts, count);
+ }
+
+ return result;
+ }
+ Catch(Commons::PlatformException) {
+ if (accounts != NULL) {
+ email_free_account(&accounts, count);
+ }
+ throw;
+ }
+}
+
+int Messaging::getEmailAccountId(const std::string& account)
+{
+ int retVal = 0;
+ string tmpAccount = account;
+ emf_account_t *pAccountArray = NULL;
+ int iCount = 0;
+
+ Try
+ {
+ if (account.empty()) {
+ tmpAccount = getCurrentEmailAccount().getAddress();
+ if (tmpAccount.empty()) {
+ LogError(
+ "current email account is not set, possible that no account created");
+ Throw(Commons::PlatformException);
+ }
+ }
+
+ if (!email_get_account_list(&pAccountArray, &iCount)) {
+ LogError("email_get_account_list error");
+ Throw(Commons::PlatformException);
+ }
+
+ if (0 == iCount) {
+ LogError("no email account exist");
+ Throw(Commons::PlatformException);
+ }
+
+ for (int i = 0; i < iCount; i++) {
+ string tmp = pAccountArray[i].email_addr;
+ if (tmp == tmpAccount) {
+ m_currentEmailAccountId = pAccountArray[i].account_id;
+ retVal = m_currentEmailAccountId;
+ break;
+ }
+ }
+
+ if (0 == m_currentEmailAccountId) {
+ LogError("wrong email account ID");
+ Throw(Commons::PlatformException);
+ }
+
+ if (pAccountArray != NULL) {
+ LogDebug("free account, ptr=" << pAccountArray);
+ email_free_account(&pAccountArray, iCount);
+ }
+
+ if (0 == retVal) {
+ LogError("no email account created");
+ Throw(Commons::PlatformException);
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("exception catch, platform exception");
+ if (pAccountArray != NULL) {
+ email_free_account(&pAccountArray, iCount);
+ }
+ throw;
+ }
+
+ return retVal;
+}
+
+void Messaging::fetchEmailHeaders()
+{
+ emf_mailbox_t *mailbox = NULL;
+ unsigned handle = 0;
+ mailbox = static_cast<emf_mailbox_t*>(calloc(sizeof (emf_mailbox_t), 1));
+ if (!mailbox) {
+ LogError("calloc failed");
+ return;
+ }
+ mailbox->account_id = m_currentEmailAccountId;
+ mailbox->name = strdup(EMF_INBOX_NAME);
+ if (EMF_ERROR_NONE != email_sync_header(mailbox, &handle)) {
+ LogError("email_sync_header failed");
+ }
+ email_free_mailbox(&mailbox, 1);
+}
+
+int Messaging::convertFolderToPlatform(const FolderType folder)
+{
+ MSG_FOLDER_ID_T platfromFolderId;
+ switch (folder) {
+ case INBOX:
+ platfromFolderId = MSG_INBOX_ID;
+ break;
+ case DRAFTBOX:
+ platfromFolderId = MSG_DRAFT_ID;
+ break;
+ case OUTBOX:
+ platfromFolderId = MSG_OUTBOX_ID;
+ break;
+ case SENTBOX:
+ platfromFolderId = MSG_SENTBOX_ID;
+ break;
+ case SPAMBOX:
+
+ default:
+ LogError("Invalid folder: " << folder);
+ Throw(Commons::PlatformException);
+ }
+
+ return platfromFolderId;
+}
+
+int Messaging::convertFolderToPlatform(const std::string &folder)
+{
+ MSG_FOLDER_LIST_S folderList = { 0, NULL };
+ int result = 0;
+ Try
+ {
+ if (MSG_SUCCESS !=
+ msg_get_folder_list(MsgGetCommonHandle(), &folderList)) {
+ LogError("msg_get_folder_list error");
+ Throw(Commons::PlatformException);
+ }
+ for (int i = 0; i < folderList.nCount; ++i) {
+ if (MSG_FOLDER_TYPE_USER_DEF ==
+ folderList.folderInfo[i].folderType &&
+ NULL != folderList.folderInfo[i].folderName &&
+ folder == folderList.folderInfo[i].folderName) {
+ result = folderList.folderInfo[i].folderId;
+ break;
+ }
+ }
+ }
+ Catch(Commons::PlatformException) {
+ if (folderList.nCount) {
+ msg_release_folder_list(&folderList);
+ }
+ throw;
+ }
+ if (folderList.nCount) {
+ msg_release_folder_list(&folderList);
+ }
+ return result;
+}
+
+void Messaging::addOnMessageReceived(
+ const Api::EmitterMessageReceivedPtr& emitter)
+{
+ LogDebug("ENTER");
+ m_onMessageReceived.attach(emitter);
+ EmittersMessageReceived::LockType lock = m_onMessageReceived.getLock();
+ if (m_onMessageReceived.size() == 1) {
+ m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(
+ new MsgServiceHandleMgr());
+ int err;
+
+ err = msg_reg_sms_message_callback(
+ m_onMessageReceivedHandleMgr->getHandle(),
+ onSmsReceived,
+ 0,
+ this);
+ if (err != MSG_SUCCESS) {
+ LogError("Couldn't register on SMS received callback, err=" << err);
+ }
+ err = msg_reg_mms_conf_message_callback(
+ m_onMessageReceivedHandleMgr->getHandle(),
+ onMmsReceived,
+ NULL,
+ this);
+ if (err != MSG_SUCCESS) {
+ LogError("Couldn't register on MMS received callback, err=" << err);
+ }
+ }
+}
+
+void Messaging::removeOnMessageReceived(Api::EmitterMessageReceived::IdType id)
+{
+ LogDebug("ENTER");
+ m_onMessageReceived.detach(id);
+ EmittersMessageReceived::LockType lock = m_onMessageReceived.getLock();
+ if (m_onMessageReceived.size() == 0) {
+ m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(NULL);
+ }
+}
+
+void Messaging::OnEventReceived(const EmailReceivedEvent& event)
+{
+ LogDebug("Received email: " << event.GetArg0());
+ EventMessageReceivedPtr jsEvent(new EventMessageReceived());
+ IMessagePtr msg = MessageFactory::createMessage(EMAIL, event.GetArg0());
+
+ IEmailPtr email = MessageFactory::convertToEmail(msg);
+ jsEvent->setMessage(msg);
+ m_onMessageReceived.emitIf(jsEvent,
+ MessageFilterMatcher<Api::IEmailPtr>(email));
+}
+
+void Messaging::onSmsReceived(MSG_HANDLE_T /*handle*/,
+ msg_message_t msg,
+ void* data)
+{
+ LogDebug("ENTER");
+ Messaging* this_ = static_cast<Messaging*>(data);
+ if (this_) {
+ Try {
+ IMessagePtr message = MessageFactory::createMessage(
+ SMS,
+ msg_get_message_id(
+ msg));
+ ISmsPtr sms = MessageFactory::convertToSms(message);
+ EventMessageReceivedPtr event(new EventMessageReceived());
+ event->setMessage(message);
+ this_->m_onMessageReceived.emitIf(event,
+ MessageFilterMatcher<Api::ISmsPtr>(
+ sms));
+ }
+ Catch(Commons::ConversionException) {
+ LogError("Couldn't convert message to sms.");
+ }
+ }
+}
+
+void Messaging::onMmsReceived(MSG_HANDLE_T /*handle*/,
+ msg_message_t msg,
+ void* data)
+{
+ LogDebug("ENTER");
+ Messaging* this_ = static_cast<Messaging*>(data);
+ if (this_) {
+ Try {
+ IMessagePtr message = MessageFactory::createMessage(
+ MMS,
+ msg_get_message_id(
+ msg));
+ IMmsPtr mms = MessageFactory::convertToMms(message);
+ EventMessageReceivedPtr event(new EventMessageReceived());
+ event->setMessage(message);
+ this_->m_onMessageReceived.emitIf(event,
+ MessageFilterMatcher<Api::IMmsPtr>(
+ mms));
+ }
+ Catch(Commons::ConversionException) {
+ LogError("Couldn't convert message to mms.");
+ }
+ }
+}
+
+void Messaging::getNumberOfEmails(Api::FolderType folder,
+ int* read,
+ int* unread)
+{
+ LOG_ENTER
+
+ emf_mailbox_t mailbox;
+ memset(&mailbox, 0, sizeof(emf_mailbox_t));
+ mailbox.account_id = 0; // means for all accounts
+ mailbox.name = Commons::String::strdup(
+ EmailConverter::toMailboxName(folder)
+ );
+
+ int error = email_count_message(&mailbox, read, unread);
+ free(mailbox.name);
+
+ if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't get number of emails. [" << error << "]");
+ }
+
+ LOG_EXIT
+}
+
+void Messaging::getNumberOfSms(Api::FolderType folder,
+ int* read,
+ int* unread)
+{
+ getNumberOfSmsMms(folder, read, unread, SMS);
+}
+
+void Messaging::getNumberOfMms(Api::FolderType folder,
+ int* read,
+ int* unread)
+{
+ getNumberOfSmsMms(folder, read, unread, MMS);
+}
+
+void Messaging::getNumberOfSmsMms(Api::FolderType folder,
+ int* read,
+ int* unread,
+ Api::MessageType msgType)
+{
+ MSG_LIST_S folderListView = { 0, NULL };
+
+ *read = 0;
+ *unread = 0;
+
+ Try
+ {
+ MSG_MESSAGE_TYPE_T msgTypePlatform;
+ if (SMS == msgType) {
+ msgTypePlatform = MSG_TYPE_SMS;
+ } else if (MMS == msgType) {
+ msgTypePlatform = MSG_TYPE_MMS;
+ } else {
+ LogError("no supported message type in this method");
+ Throw(Commons::PlatformException);
+ }
+
+ MSG_FOLDER_ID_T msgFolderId;
+ switch (folder) {
+ case INBOX:
+ msgFolderId = MSG_INBOX_ID;
+ break;
+ case OUTBOX:
+ msgFolderId = MSG_OUTBOX_ID;
+ break;
+ case SPAMBOX:
+ msgFolderId = MSG_SPAMBOX_ID;
+ break;
+ case SENTBOX:
+ msgFolderId = MSG_SENTBOX_ID;
+ break;
+ case DRAFTBOX:
+ msgFolderId = MSG_DRAFT_ID;
+ break;
+ default:
+ LogError("wrong folder type");
+ Throw(Commons::PlatformException);
+ break;
+ }
+
+ const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+ if (msg_get_folder_view_list(MsgGetCommonHandle(), msgFolderId,
+ &sort_rules,
+ &folderListView) != MSG_SUCCESS) {
+ LogDebug("msg_get_folder_view_list empty or failed, msgFolderId=" <<
+ (int) msgFolderId);
+ Throw(Commons::PlatformException);
+ }
+ // go thtough all message to check type of message
+ LogDebug("msgCount=" << (int) folderListView.nCount);
+ for (int msg_cnt = 0; msg_cnt < folderListView.nCount; msg_cnt++) {
+ LogDebug("msgMainType=" <<
+ msg_get_message_type(folderListView.msgInfo[msg_cnt]) <<
+ ", searching for = " << (int) msgTypePlatform);
+ if (msgTypePlatform == msg_get_message_type(
+ folderListView.msgInfo[msg_cnt])) {
+ if (msg_is_read(folderListView.msgInfo[msg_cnt])) {
+ (*read)++;
+ } else {
+ (*unread)++;
+ }
+ }
+ }
+ msg_release_message_list(&folderListView);
+
+ LogDebug("readed=" << *read << ", unReaded=" << *unread);
+ }
+
+ Catch(Commons::PlatformException) {
+ if (folderListView.nCount) {
+ msg_release_message_list(&folderListView);
+ }
+ throw;
+ }
+}
+
+vector<Api::IMessagePtr> Messaging::findSms(Api::FolderType folder,
+ const Api::MessageFilterPtr& filter)
+{
+ vector<Api::IMessagePtr> retVal;
+ msg_message_t msg = msg_new_message();
+ MSG_LIST_S folder_list_view = { 0, NULL };
+
+ Try
+ {
+ const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+ MSG_ERROR_T res = MSG_ERR_UNKNOWN;
+ const MSG_FOLDER_ID_T platformFolder = convertFolderToPlatform(folder);
+ res = msg_get_folder_view_list(
+ MsgGetCommonHandle(), platformFolder, &sort_rules,
+ &folder_list_view);
+
+ if (MSG_SUCCESS != res) {
+ LogError("msg_get_folder_view_list failed " << res);
+ Throw(Commons::PlatformException);
+ }
+
+ for (int i = 0; i < folder_list_view.nCount; i++) {
+ if (MSG_TYPE_SMS ==
+ msg_get_message_type(folder_list_view.msgInfo[i])) {
+ int l_msgId = msg_get_message_id(folder_list_view.msgInfo[i]);
+ Api::IMessagePtr msg = MessageFactory::createMessage(SMS,
+ l_msgId);
+ // invalid or null filter = empty filter
+ if (!filter || !filter->isValid() ||
+ filter->compare(MessageFactory::convertToSms(msg))) {
+ retVal.push_back(msg);
+ }
+ }
+ }
+
+ msg_release_message_list(&folder_list_view);
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("Problem with message creation, cleaning");
+ if (folder_list_view.nCount) {
+ msg_release_message_list(&folder_list_view);
+ }
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ throw;
+ }
+
+ return retVal;
+}
+
+vector<Api::IMessagePtr> Messaging::findMms(Api::FolderType folder,
+ const Api::MessageFilterPtr& filter)
+{
+ vector<Api::IMessagePtr> retVal;
+ msg_message_t msg = msg_new_message();
+ MSG_LIST_S folder_list_view = { 0, NULL };
+
+ Try
+ {
+ const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+ MSG_ERROR_T res = MSG_ERR_UNKNOWN;
+ const MSG_FOLDER_ID_T platformFolder = convertFolderToPlatform(folder);
+ res = msg_get_folder_view_list(
+ MsgGetCommonHandle(), platformFolder, &sort_rules,
+ &folder_list_view);
+
+ if (MSG_SUCCESS != res) {
+ LogError("msg_Get_folder_view_list failed" << res);
+ Throw(Commons::PlatformException);
+ }
+
+ for (int i = 0; i < folder_list_view.nCount; i++) {
+ if (MSG_TYPE_MMS ==
+ msg_get_message_type(folder_list_view.msgInfo[i])) {
+ int l_msgId = msg_get_message_id(folder_list_view.msgInfo[i]);
+ Api::IMessagePtr msg =
+ MessageFactory::createMessage(MMS, l_msgId);
+ // invalid or null filter = empty filter
+ if (!filter || !filter->isValid() ||
+ filter->compare(MessageFactory::convertToMms(msg))) {
+ retVal.push_back(msg);
+ }
+ }
+ }
+
+ msg_release_message_list(&folder_list_view);
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("Problem with message creation, cleaning");
+ if (folder_list_view.nCount) {
+ msg_release_message_list(&folder_list_view);
+ }
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ throw;
+ }
+
+ return retVal;
+}
+
+void Messaging::createFolder(MessageType msgType,
+ const string& userFolder)
+{
+ switch (msgType) {
+ case Api::SMS:
+ case Api::MMS:
+ createMsgServiceFolder(userFolder);
+ break;
+ case Api::EMAIL:
+ createEmailFolder(userFolder);
+ break;
+ default:
+ LogError("msg not supported");
+ Throw(Commons::UnknownException);
+ }
+}
+
+void Messaging::createMsgServiceFolder(const std::string& userFolder)
+{
+ if (userFolder.length() > MAX_FOLDER_NAME_SIZE) {
+ LogError("folder name to long");
+ Throw(Commons::PlatformException);
+ }
+
+ MSG_FOLDER_INFO_S folderInfo;
+
+ folderInfo.folderId = 0;
+ strncpy(folderInfo.folderName, userFolder.c_str(), userFolder.length());
+
+ folderInfo.folderType = MSG_FOLDER_TYPE_USER_DEF;
+
+ if (msg_add_folder(MsgGetCommonHandle(), &folderInfo) != MSG_SUCCESS) {
+ LogError("msg_add_folder failed");
+ Throw(Commons::PlatformException);
+ }
+}
+
+void Messaging::createEmailFolder(const std::string& /*userFolder*/)
+{
+ //TODO
+ LogError("TODO");
+ Throw(Commons::UnknownException);
+}
+
+void Messaging::deleteFolder(MessageType msgType,
+ const string& userFolder)
+{
+ switch (msgType) {
+ case Api::SMS:
+ case Api::MMS:
+ deleteMsgServiceFolder(userFolder);
+ break;
+ case Api::EMAIL:
+ deleteEmailFolder(userFolder);
+ break;
+ default:
+ LogError("msg not supported");
+ Throw(Commons::UnknownException);
+ }
+}
+
+void Messaging::deleteMsgServiceFolder(const string& userFolder)
+{
+ Try
+ {
+ int platformFolderId = convertFolderToPlatform(userFolder);
+ if (MSG_SUCCESS !=
+ msg_delete_folder(MsgGetCommonHandle(), platformFolderId)) {
+ LogError("msg_get_folder_list failed");
+ Throw(Commons::PlatformException);
+ }
+ }
+ Catch(Commons::PlatformException) {
+ throw;
+ }
+}
+
+void Messaging::deleteEmailFolder(const string& /*userFolder*/)
+{
+ //TODO
+ LogError("TODO");
+ Throw(Commons::UnknownException);
+}
+
+vector<string> Messaging::getFolderNames(MessageType msgType)
+{
+ switch (msgType) {
+ case Api::SMS:
+ case Api::MMS:
+ return getFolderNamesMsgService();
+ case Api::EMAIL:
+ return getFolderNamesEmail();
+ default:
+ LogError("msg not supported");
+ Throw(Commons::UnknownException);
+ }
+}
+
+vector<string> Messaging::getFolderNamesMsgService()
+{
+ vector<string> retVal;
+ MSG_FOLDER_LIST_S msgFolderList = { 0, NULL }; // output data
+
+ Try
+ {
+ if (msg_get_folder_list(MsgGetCommonHandle(),
+ &msgFolderList) != MSG_SUCCESS) {
+ LogError("msg_get_folder_list failed");
+ Throw(Commons::PlatformException);
+ }
+
+ LogDebug("number of folder=" << msgFolderList.nCount);
+ for (int i = 0; i < msgFolderList.nCount; i++) {
+ LogDebug("folderName=" << msgFolderList.folderInfo[i].folderName);
+ LogDebug("folderId=" << (int) msgFolderList.folderInfo[i].folderId);
+ LogDebug(
+ "folderType=" <<
+ (int) msgFolderList.folderInfo[i].folderType);
+ retVal.push_back(msgFolderList.folderInfo[i].folderName);
+ }
+ (void) msg_release_folder_list(&msgFolderList);
+ }
+
+ Catch(Commons::PlatformException) {
+ if (msgFolderList.nCount) {
+ (void) msg_release_folder_list(&msgFolderList);
+ }
+ throw;
+ }
+ return retVal;
+}
+
+vector<string> Messaging::getFolderNamesEmail()
+{
+ vector<string> retVal;
+
+ string tmpStr;
+ emf_mailbox_t* mailboxes = NULL;
+ int mailboxesCount;
+ string emailAccountName;
+ Api::EmailAccountInfo account = getCurrentEmailAccount();
+
+ Try
+ {
+ if (!email_get_mailbox_list(account.getIntId(), -1, &mailboxes,
+ &mailboxesCount) || !mailboxes) {
+ LogError("error during get mailboxes");
+ }
+ for (int i = 0; i < mailboxesCount; i++) {
+ retVal.push_back(mailboxes->name);
+ LogDebug("mailbox found, name=" << mailboxes->name);
+ mailboxes++;
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ // nothing to clean, re-throw exception
+ throw;
+ }
+
+ return retVal;
+}
+
+vector<Api::IMessagePtr> Messaging::findEmail(const std::string &folder,
+ const Api::MessageFilterPtr& filter)
+{
+ vector<Api::IMessagePtr> retVal;
+
+ Api::EmailAccountInfo account = getCurrentEmailAccount();
+ if (account.getId().empty()) {
+ LogWarning("No valid email accounts. Skipping");
+ return retVal;
+ }
+
+ int accountId = account.getIntId();
+
+ // number of found emails
+ int count = 0;
+ // start index
+ int startIndex = 0;
+
+ do {
+ emf_mail_list_item_t* results = NULL;
+ int err = email_get_mail_list_ex(accountId,
+ folder.c_str(),
+ EMF_LIST_TYPE_NORMAL,
+ startIndex,
+ MESSAGE_FIND_LIMIT,
+ EMF_SORT_DATETIME_HIGH,
+ &results,
+ &count);
+ DPL::ScopedFree<emf_mail_list_item_t> autoFree(results);
+ (void)autoFree;
+ if (EMF_ERROR_MAIL_NOT_FOUND == err || results == NULL) {
+ LogWarning("No emails found in mailbox: " << folder);
+ break;
+ } else if (EMF_ERROR_NONE != err) {
+ LogError(
+ "Unable to get mail list for mailbox: " << folder <<
+ ", Error: " << err);
+ Throw(Commons::PlatformException);
+ }
+
+ // apply filter
+ for (int i = 0; i < count; ++i) {
+ Api::IMessagePtr msg = MessageFactory::createMessage(
+ EMAIL,
+ results[i].
+ mail_id);
+ if (!filter ||
+ filter->compare(MessageFactory::convertToEmail(msg))) {
+ retVal.push_back(msg);
+ }
+ }
+
+ startIndex += count;
+ }
+ while (count >= MESSAGE_FIND_LIMIT);
+
+ return retVal;
+}
+
+vector<Api::IMessagePtr> Messaging::findEmail(Api::FolderType folder,
+ const Api::MessageFilterPtr& filter)
+{
+ vector<Api::IMessagePtr> result;
+
+ Api::EmailAccountInfo account = getCurrentEmailAccount();
+ if (account.getId().empty()) {
+ LogWarning("No valid email accounts.");
+ return result;
+ }
+
+ string name;
+ try {
+ name = EmailConverter::toMailboxName(folder);
+ }
+ catch (const Commons::PlatformException& ex) {
+ LogWarning(ex.DumpToString());
+ return result;
+ }
+
+ int accountId = account.getIntId();
+ int startIndex = 0;
+ int count = 0;
+ do {
+ emf_mail_list_item_t* messages = NULL;
+ int error = email_get_mail_list_ex(accountId,
+ name.c_str(),
+ EMF_LIST_TYPE_NORMAL,
+ startIndex,
+ MESSAGE_FIND_LIMIT,
+ EMF_SORT_DATETIME_HIGH,
+ &messages,
+ &count);
+ DPL::ScopedFree<emf_mail_list_item_t> freeGuard(messages);
+ if ((EMF_ERROR_MAIL_NOT_FOUND == error) || (NULL == messages)) {
+ LogWarning("No emails found in mailbox: " << name);
+ break;
+ } else if (EMF_ERROR_NONE != error) {
+ ThrowMsg(Commons::PlatformException,
+ "Couldn't get mail list from mailbox: " << name <<
+ ". [" << error << "]");
+ }
+
+ for (int i = 0; i < count; ++i) {
+ Api::IMessagePtr msg =
+ MessageFactory::createMessage(EMAIL, messages[i].mail_id);
+ if (!filter ||
+ filter->compare(MessageFactory::convertToEmail(msg))) {
+ result.push_back(msg);
+ }
+ }
+
+ startIndex += count;
+ }
+ while (count >= MESSAGE_FIND_LIMIT);
+
+ 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 Messaging.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef MESSAGING_H
+#define MESSAGING_H
+
+#include <memory>
+#include <vector>
+#include <string>
+#include <dpl/atomic.h>
+#include <dpl/thread.h>
+extern "C" {
+#include <MsgTypes.h>
+}
+#include <dpl/event/event_listener.h>
+#include <API/Messaging/IMessaging.h>
+#include <API/Messaging/IMessage.h>
+#include <API/Messaging/EmailAccountInfo.h>
+#include <Commons/Emitters.h>
+#include <DBus/Connection.h>
+#include <DBus/MessageEvent.h>
+#include "MsgServiceHandleMgr.h"
+#include "MailNotifier.h"
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class Messaging : public Api::IMessaging,
+ private DPL::Event::EventListener<EmailReceivedEvent>
+{
+ public:
+ static Messaging& getInstance();
+
+ public:
+ virtual ~Messaging();
+
+ virtual void getNumberOfMessages(Api::MessageType msgType,
+ Api::FolderType folder,
+ int* readed,
+ int* unReaded);
+
+ virtual std::vector<Api::IMessagePtr> findMessages(
+ const std::vector<Api::MessageType>& msgTypes,
+ Api::FolderType folder,
+ const Api::MessageFilterPtr& filter);
+
+ virtual std::vector<Api::IMessagePtr> findMessages(
+ const std::vector<Api::MessageType>& msgTypes,
+ const std::string &folder,
+ const Api::MessageFilterPtr& filter);
+
+ virtual std::vector<std::string> getMessageIds(Api::MessageType msgType,
+ Api::FolderType folder);
+
+ virtual void createFolder(Api::MessageType msgType,
+ const std::string& userFolder);
+
+ virtual void deleteFolder(Api::MessageType msgType,
+ const std::string& userFolder);
+
+ virtual std::vector<std::string> getFolderNames(Api::MessageType msgType);
+
+ virtual std::vector<Api::EmailAccountInfo> getEmailAccounts() const;
+
+ int getEmailAccountId(const std::string& account);
+
+ void fetchEmailHeaders();
+
+ static int convertFolderToPlatform(const Api::FolderType folder);
+
+ /**
+ * Gets folder id by given folder name.
+ * @return Folder id or 0 if not found
+ * @throw PlatformException on platform error.
+ */
+ static int convertFolderToPlatform(const std::string &folder);
+
+ void addOnMessageReceived(const Api::EmitterMessageReceivedPtr& emitter);
+
+ void removeOnMessageReceived(Api::EmitterMessageReceived::IdType id);
+
+ public:
+ static int m_currentEmailAccountId;
+
+ static DPL::Atomic m_objCounter;
+
+ protected:
+ void OnEventReceived(const EmailReceivedEvent& event);
+
+ private:
+ typedef Commons::Emitters<Api::EmitterMessageReceived> EmittersMessageReceived;
+
+ template<class MessageType>
+ struct MessageFilterMatcher
+ {
+ public:
+ MessageFilterMatcher(const MessageType& message) : m_message(message)
+ {
+ }
+
+ bool operator()(const EmittersMessageReceived::EmitterPtrType& emitter)
+ const
+ {
+ if (!m_message) {
+ return false;
+ }
+ if (!emitter->getFilter()) {
+ return true;
+ }
+ return emitter->getFilter()->compare(m_message);
+ }
+
+ private:
+ MessageType m_message;
+ };
+
+ private:
+ Messaging();
+
+ static void onSmsReceived(MSG_HANDLE_T handle,
+ msg_message_t msg,
+ void* data);
+ static void onMmsReceived(MSG_HANDLE_T handle,
+ msg_message_t msg,
+ void* data);
+
+ private:
+
+ void getNumberOfEmails(Api::FolderType folder,
+ int* read,
+ int* unread);
+
+ void getNumberOfSms(Api::FolderType folder,
+ int* read,
+ int* unread);
+
+ void getNumberOfMms(Api::FolderType folder,
+ int* read,
+ int* unread);
+
+ void getNumberOfSmsMms(Api::FolderType folder,
+ int* read,
+ int* unread,
+ Api::MessageType msgType);
+
+ virtual std::vector<Api::IMessagePtr> findSms(Api::FolderType folder,
+ const Api::MessageFilterPtr& filter);
+
+ virtual std::vector<Api::IMessagePtr> findMms(Api::FolderType folder,
+ const Api::MessageFilterPtr& filter);
+
+ virtual std::vector<Api::IMessagePtr> findEmail(Api::FolderType folder,
+ const Api::MessageFilterPtr& filter);
+
+ virtual std::vector<Api::IMessagePtr> findEmail(const std::string &folder,
+ const Api::MessageFilterPtr& filter);
+
+ std::vector<std::string> getSmsIds(Api::FolderType folder);
+
+ std::vector<std::string> getMmsIds(Api::FolderType folder);
+
+ std::vector<std::string> getEmailIds(Api::FolderType folder);
+
+ void createMsgServiceFolder(const std::string& userFolder);
+
+ void createEmailFolder(const std::string& userFolder);
+
+ void deleteMsgServiceFolder(const std::string& userFolder);
+
+ void deleteEmailFolder(const std::string& userFolder);
+
+ std::vector<std::string> getFolderNamesMsgService();
+
+ std::vector<std::string> getFolderNamesEmail();
+
+ private:
+ EmittersMessageReceived m_onMessageReceived;
+ MsgServiceHandleMgrPtr m_onMessageReceivedHandleMgr;
+ std::unique_ptr<MailNotifier> m_mailNotifier;
+};
+}
+}
+
+#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 Mms.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "Mms.h"
+
+#include <vector>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include "Messaging.h"
+#include "CallbackMgr.h"
+#include "MsgServiceHandleMgr.h"
+
+extern "C" {
+#include <MapiControl.h>
+#include <MapiMessage.h>
+#include <MapiStorage.h>
+}
+
+namespace {
+const char* TEXT_AREA = "Text";
+const char* TEXT_FILE_EXTENSION = ".txt";
+const int WHITE_COLOR = 0xffffff;
+const int BLACK_COLOR = 0x000000;
+const int ROOT_LAYOUT_WIDTH = 100;
+const int ROOT_LAYOUT_HEIGHT = 100;
+const char* EMPTY_ID = "0";
+}
+
+using namespace std;
+using namespace WrtDeviceApis::Messaging;
+using namespace WrtDeviceApis::Messaging::Api;
+
+namespace WrtDeviceApis {
+namespace Messaging {
+Mms::Mms(const string& id) :
+ IMessage(MMS, id),
+ m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
+ m_messageData(NULL)
+{
+ LogDebug("enter");
+ LogDebug("m_id=" << getIdRef());
+ LogDebug("m_msgType=" << getMessageType());
+ if (getIdRef().empty()) {
+ createNewMessage();
+ } else {
+ readExistingMessage();
+ }
+}
+
+Mms::~Mms()
+{
+ LogDebug("enter");
+
+ if (m_messageData) {
+ // release platform message structure
+ msg_release_message(&m_messageData);
+ }
+
+ //remove tmp file
+ //trying to remove file, return value is skipped
+ if (!m_bodyFilePath.empty()) {
+ LogDebug("remove tmp file=" << m_bodyFilePath);
+ (void) ::remove(m_bodyFilePath.c_str());
+ }
+}
+
+void Mms::createNewMessage()
+{
+ if (m_messageData) {
+ msg_release_message(&m_messageData);
+ m_messageData = NULL;
+ }
+ m_messageData = msg_new_message();
+
+ MSG_SENDINGOPT_S sendOpt;
+ memset(&sendOpt, 0, sizeof(MSG_SENDINGOPT_S));
+
+ sendOpt.bSetting = false;
+
+ // initialize platform message structure
+ msg_set_message_id(m_messageData, 0); // It should be set 0
+ msg_set_folder_id(m_messageData, MSG_DRAFT_ID);
+ msg_set_message_type(m_messageData, MSG_TYPE_MMS);
+ msg_set_storage_id(m_messageData, MSG_STORAGE_PHONE);
+ msg_set_subject(m_messageData, "");
+ msg_set_read_status(m_messageData, false);
+ msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
+ msg_set_direction_info(m_messageData, MSG_DIRECTION_TYPE_MO);
+ msg_set_priority_info(m_messageData, MSG_MESSAGE_PRIORITY_NORMAL);
+
+ tm dateT = getDateTime();
+ msg_set_time(m_messageData, mktime(&dateT));
+
+ setMmsType(MULTIPART_MIXED);
+ setReadStatus(false);
+
+ LogDebug("Message created successfully, Id: " << getIdRef());
+}
+
+void Mms::readExistingMessage()
+{
+ LogDebug("entered");
+
+ if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
+ ThrowMsg(Commons::PlatformException, "Empty id.");
+ }
+
+ Try {
+ MSG_SENDINGOPT_S option;
+ option.bSetting = false;
+
+ // release old data
+ msg_release_message(&m_messageData);
+ m_messageData = NULL;
+ // crate new structure
+ m_messageData = msg_new_message();
+
+ // trying to get message from platform
+ if (MSG_SUCCESS != msg_get_message(
+ MsgGetCommonHandle(), convertId(getIdRef()), m_messageData,
+ &option)) {
+ LogError("get message error");
+ Throw(Commons::PlatformException);
+ }
+ LogDebug("message found with msgId=" << getIdRef());
+
+ // read all mms dat to abstraction layer
+ readRecipientList(m_messageData);
+ readPriority(m_messageData);
+ readSubject(m_messageData);
+ readBodyAndAttachments(m_messageData);
+ readFolder(m_messageData);
+ readDateTime(m_messageData);
+ readReadStatus(m_messageData);
+ }
+ Catch(Commons::Exception) {
+ // nothing to do
+ }
+}
+
+void Mms::readDateTime(msg_message_t& messageData)
+{
+ tm* time = localtime(msg_get_time(messageData));
+ if (!time) {
+ LogError("localtime failed");
+ Throw(Commons::PlatformException);
+ }
+ setDateTime(*time);
+}
+
+void Mms::readReadStatus(msg_message_t& messageData)
+{
+ setReadStatus(msg_is_read(messageData));
+}
+
+void Mms::readFolder(msg_message_t& messageData)
+{
+ switch (msg_get_folder_id(messageData)) {
+ case MSG_INBOX_ID:
+ setFolderType(Api::INBOX);
+ break;
+ case MSG_OUTBOX_ID:
+ setFolderType(Api::OUTBOX);
+ break;
+ case MSG_SENTBOX_ID:
+ setFolderType(Api::SENTBOX);
+ break;
+ case MSG_DRAFT_ID:
+ setFolderType(Api::DRAFTBOX);
+ break;
+ case MSG_SPAMBOX_ID:
+ setFolderType(Api::SPAMBOX);
+ break;
+ default:
+ ThrowMsg(Commons::PlatformException, "Unsupported folder id.");
+ }
+}
+
+void Mms::readPriority(msg_message_t& messageData)
+{
+ switch (msg_get_priority_info(messageData)) {
+ case MSG_MESSAGE_PRIORITY_LOW:
+ setPriority(MessagePriority::LOW);
+ break;
+ case MSG_MESSAGE_PRIORITY_NORMAL:
+ setPriority(MessagePriority::NORMAL);
+ break;
+ case MSG_MESSAGE_PRIORITY_HIGH:
+ setPriority(MessagePriority::HIGH);
+ break;
+ default:
+ LogError("Wrong priority type");
+ ThrowMsg(Commons::PlatformException, "Wrong priority type");
+ }
+}
+
+void Mms::readRecipientList(msg_message_t& messageData)
+{
+ std::string phoneNumber;
+ int recipientCount = msg_get_address_count(messageData);
+ LogDebug("Recipient count " << recipientCount);
+ for (int i = 0; i < recipientCount; ++i) {
+ int type = msg_get_direction_info(messageData);
+
+ if (MSG_DIRECTION_TYPE_MT == type) {
+ phoneNumber = msg_get_ith_address(messageData, i);
+ if (validatePhoneNumber(phoneNumber)) {
+ setSourceAddress(phoneNumber);
+ setFrom(phoneNumber);
+ }
+ LogDebug("phone number: " << phoneNumber);
+ } else if (MSG_DIRECTION_TYPE_MO == type) {
+ switch (msg_get_ith_recipient_type(messageData, i)) {
+ case MSG_RECIPIENTS_TYPE_TO:
+ appendToRecipients(msg_get_ith_address(messageData, i));
+ break;
+ case MSG_RECIPIENTS_TYPE_CC:
+ appendCcRecipients(msg_get_ith_address(messageData, i));
+ break;
+ case MSG_RECIPIENTS_TYPE_BCC:
+ appendBccRecipients(msg_get_ith_address(messageData, i));
+ break;
+ default:
+ LogError("Wrong type of recipient");
+ ThrowMsg(Commons::PlatformException, "Wrong type of recipient");
+ }
+ } else {
+ LogError("Wrong type of recipient");
+ ThrowMsg(Commons::PlatformException, "Wrong type of recipient");
+ }
+ }
+}
+
+void Mms::readSubject(msg_message_t& messageData)
+{
+ setSubject(msg_get_subject(messageData));
+}
+
+void Mms::readBodyAndAttachments(msg_message_t& messageData)
+{
+ //TODO
+ MMS_MESSAGE_DATA_S msgBody;
+ memset(&msgBody, 0, sizeof(MMS_MESSAGE_DATA_S));
+ msg_mms_get_message_body(messageData, &msgBody);
+
+ //if any page then multipart is related type
+ if (msgBody.pageCnt > 0) {
+ setMmsType(MULTIPART_RELATED);
+ } else {
+ setMmsType(MULTIPART_MIXED);
+ }
+
+ LogDebug("page count: " << msgBody.pageCnt);
+
+ for (int p = 0; p < msgBody.pageCnt; ++p) {
+ LogDebug("page " << p);
+ MMS_PAGE_S *page = msg_mms_get_page(p);
+ if (!page) {
+ LogError("returned page is null, continue");
+ continue;
+ }
+ for (int m = 0; m < page->mediaCnt; ++m) {
+ LogDebug("media file " << m);
+ MMS_MEDIA_S* media = msg_mms_get_media(page, m);
+ if (!media) {
+ LogError("returned media is null, continue");
+ continue;
+ }
+ if (0 == p && MMS_SMIL_MEDIA_TEXT == media->mediatype) {
+ //text value on first page goes to body attribute
+ LogDebug("setting body from " << media->szFilePath);
+ FILE* f = NULL;
+ f = fopen(media->szFilePath, "r");
+ if (!f) {
+ LogError("cannot read file with body" << media->szFilePath);
+ ThrowMsg(Commons::PlatformException,
+ "Cannot read file with body");
+ }
+ fseek(f, 0, SEEK_END);
+ long int size = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ char* data = new (nothrow) char[size + 1];
+ if (data) {
+ memset(data, 0, size + 1);
+ fread(data, 1, size, f);
+ setBody(data);
+ delete[] data;
+ } else {
+ LogError("body is not set");
+ }
+ LogDebug("message body: '" << getBody() << "'");
+ fclose(f);
+ } else {
+ LogDebug("adding attachment " << media->szFilePath);
+ IAttachmentPtr attachment = appendAttachment(media->szFilePath,
+ false);
+ if (NULL != media->szFileName &&
+ strnlen(media->szFileName, MSG_FILENAME_LEN_MAX) > 0) {
+ LogDebug("renaming to " << media->szFileName);
+ attachment->rename(media->szFileName);
+ } else if (MMS_SMIL_MEDIA_TEXT == media->mediatype) {
+ std::stringstream newName;
+ newName << "body_page_" << p + 1 << ".txt";
+ LogDebug("renaming to " << newName.str());
+ attachment->rename(newName.str());
+ }
+ }
+ }
+ }
+
+ LogDebug("attachment count: " << msgBody.attachCnt);
+ for (int a = 0; a < msgBody.attachCnt; ++a) {
+ MMS_ATTACH_S* attachment = msg_mms_get_attachment(a);
+ if (!attachment) {
+ LogError("attachment is null, continue");
+ continue;
+ }
+ IAttachmentPtr att = appendAttachment(attachment->szFilePath, false);
+ if (NULL != attachment->szFileName &&
+ strnlen(attachment->szFileName, MSG_FILENAME_LEN_MAX) > 0) {
+ LogDebug("renaming to " << attachment->szFileName);
+ att->rename(attachment->szFileName);
+ }
+ }
+}
+
+void Mms::update(bool draftsOnly)
+{
+ LogDebug("updating m_id=" << getIdRef());
+
+ if (!m_messageData) {
+ //error if platform message not exists
+ LogError("message can not be updated");
+ Throw(Commons::PlatformException);
+ }
+
+ //update mms data from abstraction
+ if (!draftsOnly || getCurrentFolder() == Api::DRAFTBOX) {
+ updateSubject();
+ updateBodyAndAttachments();
+ updateRecipientList();
+ updatePriority();
+ }
+ updateReadStatus();
+}
+
+void Mms::updatePriority()
+{
+ if (isPriorityValid()) {
+ return;
+ }
+ int priority = -1;
+ LogInfo("MMS updating priority");
+
+ //set priority in platform
+ switch (getPriority()) {
+ case MessagePriority::LOW:
+ priority = MSG_MESSAGE_PRIORITY_LOW;
+ break;
+ case MessagePriority::NORMAL:
+ priority = MSG_MESSAGE_PRIORITY_NORMAL;
+ break;
+ case MessagePriority::HIGH:
+ priority = MSG_MESSAGE_PRIORITY_HIGH;
+ break;
+ default:
+ LogError("Wrong priority");
+ Throw(Commons::PlatformException);
+ }
+ if (MSG_SUCCESS !=
+ msg_set_priority_info(m_messageData, MSG_MESSAGE_PRIORITY_LOW)) {
+ LogError("Error during setting priority");
+ Throw(Commons::PlatformException);
+ }
+}
+
+void Mms::updateRecipientList()
+{
+ // check if abstraction recipient value has been changed
+ if (getToRecipients().isValid() &&
+ getBccRecipients().isValid() &&
+ getCcRecipients().isValid()) {
+ return;
+ }
+
+ LogInfo("MMS updating platform recipients");
+
+ // reset addresses in platform structure
+ msg_reset_address(m_messageData);
+
+ vector<string> to = getToRecipients().getRecipients();
+ vector<string> cc = getCcRecipients().getRecipients();
+ vector<string> bcc = getBccRecipients().getRecipients();
+
+ // update addresses in platform structure
+ if (to.size()) {
+ LogInfo("updating to");
+ for (size_t i = 0; i < to.size(); i++) {
+ if (msg_get_address_count(m_messageData) >= MAX_TO_ADDRESS_CNT) {
+ LogError("max number of recipient exceeded");
+ break;
+ }
+ LogDebug("adding to[" << i << "]=" << to[i]);
+ if (msg_add_address(m_messageData, to[i].c_str(),
+ MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS) {
+ LogError("problem with adding to address");
+ ThrowMsg(Commons::PlatformException,
+ "Problem with adding to address");
+ }
+ }
+ }
+
+ if (cc.size()) {
+ LogInfo("updating cc");
+ for (size_t i = 0; i < cc.size(); i++) {
+ if (msg_get_address_count(m_messageData) >= MAX_TO_ADDRESS_CNT) {
+ LogError("max number of recipient exceeded");
+ break;
+ }
+ LogDebug("adding cc[" << i << "]=" << cc[i]);
+ if (msg_add_address(m_messageData, cc[i].c_str(),
+ MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS) {
+ LogError("problem with adding cc address");
+ ThrowMsg(Commons::PlatformException,
+ "Problem with adding cc address");
+ }
+ }
+ }
+
+ if (bcc.size()) {
+ LogInfo("updating bcc");
+ for (size_t i = 0; i < bcc.size(); i++) {
+ if (msg_get_address_count(m_messageData) >= MAX_TO_ADDRESS_CNT) {
+ LogError("max number of recipient exceeded");
+ break;
+ }
+ LogDebug("adding bcc[" << i << "]=" << bcc[i]);
+ if (msg_add_address(m_messageData, bcc[i].c_str(),
+ MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS) {
+ LogError("problem with adding bcc address");
+ ThrowMsg(Commons::PlatformException,
+ "Problem with adding bcc address");
+ }
+ }
+ }
+
+ setToValidity(true);
+ setCcValidity(true);
+ setBccValidity(true);
+}
+
+void Mms::updateSubject()
+{
+ // check if abstraction subject value has been changed
+ if (isSubjectValid()) {
+ return;
+ }
+ LogInfo("updating platform subject: " << getSubjectRef());
+ if (MSG_SUCCESS !=
+ msg_set_subject(m_messageData, getSubjectRef().c_str())) {
+ LogError("problem with setting subject");
+ ThrowMsg(Commons::PlatformException, "Problem with setting subject");
+ }
+ setSubjectValidity(true);
+}
+
+void Mms::updateBodyAndAttachments()
+{
+ // check if attachment or body source address value has been changed
+ if (isAttachmentsValid() && isBodyValid()) {
+ return;
+ }
+ MMS_MESSAGE_DATA_S *mmsData = NULL;
+ LogInfo("updating platform body and attachment");
+
+ Try
+ {
+ if (getMessageType() != MMS) {
+ LogError("Wrong msg type");
+ ThrowMsg(Commons::PlatformException, "Wrong msg type");
+ }
+ mmsData = msg_mms_create_message();
+ if (!mmsData) {
+ LogError("create message body failed");
+ ThrowMsg(Commons::PlatformException, "create message body failed");
+ }
+
+ //body
+ if (!getBodyRef().empty()) {
+ FILE* f = NULL;
+ f = fopen(m_bodyFilePath.c_str(), "w");
+ if (!f) {
+ LogError("cannot create file with body" << m_bodyFilePath);
+ ThrowMsg(Commons::PlatformException,
+ "cannot create file with body");
+ }
+ LogDebug("body file: " << m_bodyFilePath);
+ fprintf(f, getBodyRef().c_str());
+ fclose(f);
+ if (!msg_mms_set_rootlayout(mmsData, ROOT_LAYOUT_WIDTH,
+ ROOT_LAYOUT_HEIGHT, WHITE_COLOR)) {
+ LogError("cannot create root layout");
+ ThrowMsg(Commons::PlatformException,
+ "cannot create root layout");
+ }
+ if (!msg_mms_add_region(mmsData, TEXT_AREA, 0, 0, ROOT_LAYOUT_WIDTH,
+ ROOT_LAYOUT_HEIGHT, WHITE_COLOR)) {
+ LogError("cannot create region");
+ ThrowMsg(Commons::PlatformException, "cannot create region");
+ }
+ MMS_PAGE_S* page = msg_mms_add_page(mmsData, 0);
+ if (!page) {
+ LogError("cannot create page");
+ ThrowMsg(Commons::PlatformException, "cannot create page");
+ }
+ MMS_MEDIA_S* media = msg_mms_add_media(page,
+ MMS_SMIL_MEDIA_TEXT,
+ TEXT_AREA,
+ const_cast<char*>(
+ m_bodyFilePath.c_str()));
+ if (!media) {
+ LogError("cannot create media");
+ ThrowMsg(Commons::PlatformException, "cannot create media");
+ }
+ media->sMedia.sText.nColor = BLACK_COLOR;
+ media->sMedia.sText.nSize = MMS_SMIL_FONT_SIZE_NORMAL;
+ }
+
+ //attachments
+ struct stat buffer;
+ int errnum = 0;
+ for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
+ Api::IAttachmentPtr att = getAttachment(i);
+ if (!att) {
+ continue;
+ }
+
+ LogDebug("Add attachment=" << att->getFullPath());
+ //checking file
+ errnum = stat(att->getFullPath().c_str(), &buffer);
+ if (errnum) {
+ LogError("Opening file: " <<
+ att->getFullPath().c_str() <<
+ " " << strerror(errnum));
+ ThrowMsg(Commons::PlatformException,
+ "cannot open attachment file");
+ }
+
+ //this function should return valid pointer
+ if (!msg_mms_add_attachment(mmsData,
+ const_cast<char*>(att->getFullPath().
+ c_str()))) {
+ LogError("add attachment failed");
+ ThrowMsg(Commons::PlatformException, "add attachment failed");
+ }
+ LogDebug("Attachment added");
+
+ //reset errno
+ errnum = 0;
+ }
+
+ if (MSG_SUCCESS != msg_mms_set_message_body(m_messageData, mmsData)) {
+ LogError("set message body error");
+ ThrowMsg(Commons::PlatformException, "set message body error");
+ }
+
+ msg_mms_destroy_message(mmsData);
+ setAttachmentsValidity(true);
+ setBodyValidity(true);
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("Platform error");
+ if (mmsData) {
+ msg_mms_destroy_message(mmsData);
+ }
+ throw;
+ }
+}
+
+void Mms::updateReadStatus()
+{
+ if (isReadStatusValid()) {
+ return;
+ }
+
+ LogInfo("updating platform read status: " << isRead());
+ if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
+ LogError("problem with setting subject");
+ ThrowMsg(Commons::PlatformException, "Problem with setting subject");
+ }
+
+ setReadStatusValidity(true);
+}
+
+void Mms::readAllData()
+{
+ readExistingMessage();
+}
+
+void Mms::moveToFolder(const FolderType newFolder)
+{
+ update();
+
+ Try
+ {
+ MSG_FOLDER_ID_T platfromFolderId = Messaging::convertFolderToPlatform(
+ newFolder);
+
+ if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
+ platfromFolderId) != MSG_SUCCESS) {
+ ThrowMsg(Commons::PlatformException, "Error during movinf message");
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("remove message error");
+ throw;
+ }
+}
+
+void Mms::moveToFolder(const string& newFolder)
+{
+ update();
+
+ Try
+ {
+ MSG_FOLDER_ID_T platfromFolderId = Messaging::convertFolderToPlatform(
+ newFolder);
+
+ if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
+ platfromFolderId) != MSG_SUCCESS) {
+ LogError("msg_move_msg_to_folder error");
+ ThrowMsg(Commons::PlatformException, "msg_move_msg_to_folder error");
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("remove message error");
+ throw;
+ }
+}
+
+void Mms::copyToFolder(const FolderType newFolder)
+{
+ update();
+
+ msg_message_t msg = msg_new_message();
+
+ Try
+ {
+ MSG_SENDINGOPT_S option;
+ memset(&option, 0, sizeof(MSG_SENDINGOPT_S));
+ option.option.smsSendOpt.bReplyPath = true;
+ if (MSG_SUCCESS ==
+ msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
+ &option)) {
+ const MSG_FOLDER_ID_T platfromFolderId =
+ Messaging::convertFolderToPlatform(newFolder);
+ msg_set_message_id(msg, 0);
+ msg_set_folder_id(msg, platfromFolderId);
+
+ int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
+ if (error != MSG_SUCCESS) {
+ LogError("msg_add_message failed, error code=" << error);
+ ThrowMsg(Commons::PlatformException, "msg_add_message failed");
+ }
+ }
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("remove message error");
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ throw;
+ }
+}
+
+void Mms::copyToFolder(const string& newFolder)
+{
+ update();
+
+ msg_message_t msg = msg_new_message();
+
+ Try
+ {
+ MSG_SENDINGOPT_S option;
+ memset(&option, 0, sizeof(MSG_SENDINGOPT_S));
+ option.option.smsSendOpt.bReplyPath = true;
+ if (MSG_SUCCESS ==
+ msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
+ &option)) {
+ const MSG_FOLDER_ID_T platfromFolderId =
+ Messaging::convertFolderToPlatform(newFolder);
+ msg_set_message_id(msg, 0);
+ msg_set_folder_id(msg, platfromFolderId);
+
+ int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
+ if (error != MSG_SUCCESS) {
+ LogError("msg_add_message failed, error code=" << error);
+ ThrowMsg(Commons::PlatformException, "msg_add_message failed");
+ }
+ }
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("remove message error");
+ if (msg) {
+ msg_release_message(&msg);
+ }
+ throw;
+ }
+}
+
+void Mms::remove()
+{
+ LogDebug("delete m_id=" << getIdRef());
+
+ Try
+ {
+ if (this->getIdRef().empty()) {
+ LogError("existing msgId is zero, remove msg not done");
+ ThrowMsg(Commons::PlatformException,
+ "existing msgId is zero, remove msg not done");
+ }
+
+ if (MSG_SUCCESS !=
+ msg_delete_message(MsgGetCommonHandle(),
+ convertId(getIdRef()))) {
+ LogError("Failed to delete Message");
+ ThrowMsg(Commons::PlatformException, "Failed to delete Message");
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("platform error occurs");
+ }
+}
+
+void Mms::send()
+{
+ LogDebug("sending message, id=" << getIdRef());
+ Try
+ {
+ //prepare for sending sms/mms
+ update();
+
+ LogDebug("Start Sending Message...");
+ LogDebug("msgId=" << msg_get_message_id(m_messageData));
+ LogDebug("subject: " << msg_get_subject(m_messageData));
+ LogDebug("recipient count: " << msg_get_address_count(m_messageData));
+ for (int i = 0; i < msg_get_address_count(m_messageData); ++i) {
+ LogDebug("recipient[" << i << "]: " <<
+ msg_get_ith_address(m_messageData, i));
+ }
+
+ LogDebug("trying to send mms");
+ MSG_ERROR_T err = CallbackMgrSingleton::Instance().registerAndSend(
+ msg_mms_send_message,
+ m_messageData,
+ this);
+ if (err != MSG_SUCCESS) {
+ LogError("Sending Message (submit request) failed!!! err=" << err);
+ setSendingStatusFailed();
+ return;
+ }
+
+ LogDebug("Sending Message request is submitted!");
+ }
+ Catch(Commons::PlatformException) {
+ LogError("message is not send, manually run callback");
+ setSendingStatusFailed();
+ }
+}
+
+void Mms::sendingCallback(MSG_SENT_STATUS_S *sent_status)
+{
+ LogInfo(
+ "sendingCallback callback received. Req id = " <<
+ sent_status->reqId << " Status = " << (int)sent_status->status);
+ if (MSG_NETWORK_SEND_SUCCESS == sent_status->status) {
+ LogDebug("sending ok");
+ setSendingStatusOk();
+ } else {
+ LogError("sending failed: " <<
+ static_cast<unsigned int>(sent_status->status));
+ setSendingStatusFailed();
+ }
+}
+
+void Mms::sendCancel()
+{
+ LogDebug("sending message, id=" << getIdRef());
+ //#warning "TODO"
+}
+
+void Mms::setSendingStatusOk()
+{
+ ReqReceiverMessage *requestReceiver = getRequestReceiver();
+ if (requestReceiver)
+ {
+ LogInfo("calling JS success callback");
+ EventSendMessagePtr event = getSendMessageEvent();
+ event->addRecipientsSendResult(getToRecipientsPtr()->getRecipientsRef(),
+ true);
+ event->setExceptionCode(Commons::ExceptionCodes::None);
+ requestReceiver->Commons::EventRequestReceiver<EventSendMessage>::
+ ManualAnswer(event);
+ }
+}
+
+void Mms::setSendingStatusFailed()
+{
+ EventOnSendingFailedEmitterPtr emitter = getEmitter();
+ if (emitter)
+ {
+ EventOnSendingFailedPtr event(new EventOnSendingFailed);
+ event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
+ emitter->emit(event);
+ }
+ else
+ {
+ ReqReceiverMessage *requestReceiver = getRequestReceiver();
+ if (requestReceiver)
+ {
+ LogError("calling JS error callback");
+ EventSendMessagePtr event = getSendMessageEvent();
+ event->addRecipientsSendResult(
+ getToRecipientsPtr()->getRecipientsRef(),
+ false);
+ event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+ requestReceiver->Commons::EventRequestReceiver<EventSendMessage>
+ ::ManualAnswer(event);
+ }
+ }
+}
+
+Api::FolderType Mms::toFolder(const std::string &folder)
+{
+ if (folder == "INBOX") {
+ return INBOX;
+ } else if (folder == "OUTBOX") {
+ return OUTBOX;
+ } else if (folder == "SENTBOX") {
+ return SENTBOX;
+ } else if (folder == "DRAFTBOX") {
+ return DRAFTBOX;
+ }
+ ThrowMsg(Commons::PlatformException, "Invalid folder");
+}
+}
+}
--- /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 Mms.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef MMS_H
+#define MMS_H
+
+#include <API/Messaging/IMms.h>
+#include <API/Messaging/MmsSlides.h>
+#include "MmsSlide.h"
+#include "ISendingObserver.h"
+
+extern "C" {
+#include <MsgTypes.h>
+#include <MapiTransport.h>
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class Mms : public Api::IMms,
+ public ISendingObserver,
+ public Api::MmsSlides
+{
+ public:
+ explicit Mms(const std::string& id = "");
+
+ ~Mms();
+
+ // implementation of interface of IMessage class
+ virtual void update(bool draftsOnly = false);
+
+ virtual void readAllData();
+
+ virtual void moveToFolder(const Api::FolderType newFolder);
+
+ virtual void moveToFolder(const std::string& newFolder);
+
+ virtual void copyToFolder(const Api::FolderType newFolder);
+
+ virtual void copyToFolder(const std::string& newFolder);
+
+ virtual void remove();
+
+ virtual void send();
+
+ virtual void sendingCallback(MSG_SENT_STATUS_S *sent_status);
+
+ virtual void sendCancel();
+
+ void setSendingStatusOk();
+
+ void setSendingStatusFailed();
+
+ static Api::FolderType toFolder(const std::string &folder);
+
+ private:
+
+ void updatePriority();
+
+ void updateRecipientList();
+
+ void updateSubject();
+
+ void updateBodyAndAttachments();
+
+ void updateReadStatus();
+
+ void readPriority(msg_message_t& messageData);
+
+ void readRecipientList(msg_message_t& messageData);
+
+ void readSubject(msg_message_t& messageData);
+
+ void readBodyAndAttachments(msg_message_t& messageData);
+
+ void readFolder(msg_message_t& messageData);
+
+ void readDateTime(msg_message_t& messageData);
+
+ void readReadStatus(msg_message_t& messageData);
+
+ void createNewMessage();
+
+ void readExistingMessage();
+
+ private:
+
+ std::string m_bodyFilePath;
+
+ msg_message_t m_messageData;
+};
+
+typedef DPL::SharedPtr<Mms> MmsPtr;
+}
+}
+
+#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 MmsSlide.cpp
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
--- /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 MmsSlide.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WAC_MMS_SLIDE_H
+#define WAC_MMS_SLIDE_H
+
+#include <API/Messaging/IMmsSlide.h>
+#include <API/Messaging/MmsSlide.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class MmsSlide :
+ public virtual Api::IMmsSlide,
+ public Api::MmsSlide
+{
+};
+}
+}
+#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 MsgServiceHandleMgr.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "MsgServiceHandleMgr.h"
+#include <dpl/singleton_impl.h>
+
+IMPLEMENT_SINGLETON(WrtDeviceApis::Messaging::MsgServiceHandle)
--- /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 CallbackMgr.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef MSGSERVICEHANDLEMGR_H
+#define MSGSERVICEHANDLEMGR_H
+
+#include <dpl/singleton.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/thread.h>
+#include <Commons/Exception.h>
+
+extern "C" {
+#include <MapiControl.h>
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+/*
+ * Class used for msg service handle manager
+ */
+class MsgServiceHandleMgr
+{
+ public:
+ MsgServiceHandleMgr() : m_msgHandle(NULL)
+ {
+ LogInfo("enter");
+ // open one handle per all messaging
+ if (MSG_SUCCESS != msg_open_msg_handle(&m_msgHandle)) {
+ LogError("Unable to open handle");
+ Throw(Commons::PlatformException);
+ }
+ }
+
+ public:
+ ~MsgServiceHandleMgr()
+ {
+ LogInfo("enter");
+ if (!!m_msgHandle) {
+ msg_close_msg_handle(&m_msgHandle);
+ }
+ }
+
+ MSG_HANDLE_T getHandle() const
+ {
+ if (!m_msgHandle) {
+ LogError("Messaging handle not initialized");
+ Throw(Commons::PlatformException);
+ }
+ return m_msgHandle;
+ }
+
+ private:
+ MSG_HANDLE_T m_msgHandle;
+};
+
+typedef DPL::SharedPtr<MsgServiceHandleMgr> MsgServiceHandleMgrPtr;
+typedef DPL::ThreadLocalVariable<MsgServiceHandleMgrPtr> TlvMsgServiceHandleMgr;
+
+class MsgServiceHandle
+{
+ protected:
+ MsgServiceHandle()
+ {
+ }
+
+ public:
+ ~MsgServiceHandle()
+ {
+ }
+
+ MSG_HANDLE_T getHandle()
+ {
+ if (m_tlvHandleMgr.IsNull()) {
+ m_tlvHandleMgr = MsgServiceHandleMgrPtr(new MsgServiceHandleMgr());
+ }
+ return (*m_tlvHandleMgr)->getHandle();
+ }
+
+ private:
+ TlvMsgServiceHandleMgr m_tlvHandleMgr;
+};
+
+typedef DPL::Singleton<MsgServiceHandle> MsgServiceHandleSingleton;
+
+#define MsgGetCommonHandle() MsgServiceHandleSingleton::Instance().getHandle()
+}
+}
+
+#endif /* MSGSERVICEHANDLEMGR_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 <dpl/assert.h>
+#include <Commons/Exception.h>
+#include "NetworkStatus.h"
+
+namespace {
+const char* DBUS_INTERFACE_NETWORK_STATUS = "User.Email.NetworkStatus";
+const int DBUS_MESSAGE_PARAMETERS_NUMBER = 5;
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+NetworkStatus::NetworkStatus(const DBus::MessagePtr& message)
+{
+ Assert(message->getInterface() == DBUS_INTERFACE_NETWORK_STATUS);
+ initialize(message);
+}
+
+int NetworkStatus::getStatus() const
+{
+ return m_status;
+}
+
+int NetworkStatus::getAccountId() const
+{
+ return m_accountId;
+}
+
+std::string NetworkStatus::getSource() const
+{
+ return m_source;
+}
+
+int NetworkStatus::getMailId() const
+{
+ return m_mailId;
+}
+
+int NetworkStatus::getErrorCode() const
+{
+ return m_errorCode;
+}
+
+void NetworkStatus::initialize(const DBus::MessagePtr& message)
+{
+ DBus::Message::ReadIterator it = message->getReadIterator();
+ for (int i = 0; i < DBUS_MESSAGE_PARAMETERS_NUMBER; it->next(), ++i) {
+ if (!it->isValid()) {
+ ThrowMsg(Commons::PlatformException, "Missing some properties.");
+ }
+
+ switch (i) {
+ case 0: m_status = it->getInt();
+ break;
+ case 1: m_accountId = it->getInt();
+ break;
+ case 2: m_source = it->getString();
+ break;
+ case 3: m_mailId = it->getInt();
+ break;
+ case 4: m_errorCode = it->getInt();
+ break;
+ }
+ }
+}
+}
+}
--- /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 NETWORKSTATUS_H_
+#define NETWORKSTATUS_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <DBus/Message.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class NetworkStatus : private DPL::Noncopyable
+{
+ public:
+ explicit NetworkStatus(const DBus::MessagePtr& message);
+
+ int getStatus() const;
+ int getAccountId() const;
+ std::string getSource() const;
+ int getMailId() const;
+ int getErrorCode() const;
+
+ private:
+ void initialize(const DBus::MessagePtr& message);
+
+ private:
+ int m_status;
+ int m_accountId;
+ /*
+ * Not sure what it stores. According to source code of Email application
+ * it can contain string "ACTIVESYNC" or name of the file which stores body.
+ */
+ std::string m_source;
+ int m_mailId;
+ int m_errorCode;
+};
+
+typedef DPL::SharedPtr<NetworkStatus> NetworkStatusPtr;
+}
+}
+
+#endif // NETWORKSTATUS_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)
+ */
+
+#ifndef WAC_MESSAGING_SCOPEDMAIL_H_
+#define WAC_MESSAGING_SCOPEDMAIL_H_
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include <emf-types.h>
+#include <Emf_Mapi_Message.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+struct ScopedMailPolicy
+{
+ typedef emf_mail_t* Type;
+
+ static Type NullValue()
+ {
+ return NULL;
+ }
+
+ static void Destroy(Type mail)
+ {
+ if (NullValue() != mail) {
+ int error = email_free_mail(&mail, 1);
+ if (EMF_ERROR_NONE != error) {
+ LogError("Failed to destroy mail: " << error);
+ }
+ }
+ }
+};
+
+typedef DPL::ScopedPtr<emf_mail_t, ScopedMailPolicy> ScopedMail;
+}
+}
+
+#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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WAC_MESSAGING_SCOPEDMAILBOX_H_
+#define WAC_MESSAGING_SCOPEDMAILBOX_H_
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include <emf-types.h>
+#include <Emf_Mapi_Message.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+struct ScopedMailboxPolicy
+{
+ typedef emf_mailbox_t* Type;
+
+ static Type NullValue()
+ {
+ return NULL;
+ }
+
+ static void Destroy(Type mailbox)
+ {
+ if (NullValue() != mailbox) {
+ int error = email_free_mailbox(&mailbox, 1);
+ if (EMF_ERROR_NONE != error) {
+ LogError("Failed to destroy mailbox: " << error);
+ }
+ }
+ }
+};
+
+typedef DPL::ScopedPtr<emf_mailbox_t, ScopedMailboxPolicy> ScopedMailbox;
+}
+}
+
+#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 Sms.cpp
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#include "Sms.h"
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include "Messaging.h"
+#include "CallbackMgr.h"
+#include "MsgServiceHandleMgr.h"
+
+extern "C" {
+#include <MapiStorage.h>
+#include <MapiMessage.h>
+}
+
+using namespace std;
+using namespace WrtDeviceApis::Messaging;
+using namespace WrtDeviceApis::Messaging::Api;
+
+namespace {
+const char* EMPTY_ID = "0";
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+Sms::Sms(const string& id) :
+ IMessage(SMS, id),
+ m_messageData(NULL)
+{
+ LogDebug("enter");
+ LogDebug("m_id=" << getIdRef());
+ LogDebug("m_msgType=" << getMessageType());
+
+ if (getIdRef().empty()) {
+ createNewMessage();
+ } else {
+ readExistingMessage();
+ }
+
+ Touch();
+}
+
+Sms::~Sms()
+{
+ LogDebug("enter");
+
+ if (m_messageData) {
+ // release platform message structure
+ msg_release_message(&m_messageData);
+ }
+}
+
+void Sms::update(bool draftsOnly)
+{
+ LogDebug("updating m_id=" << getIdRef());
+
+ if (!m_messageData) {
+ //error if platform message not exists
+ LogError("message can not be updated");
+ Throw(Commons::PlatformException);
+ }
+
+ //update all sms data
+ if (!draftsOnly || getCurrentFolder() == Api::DRAFTBOX) {
+ updateBody();
+ updateFrom();
+ updateTo();
+ updateSourceAddress();
+ }
+ updateReadStatus();
+}
+
+void Sms::readAllData()
+{
+ readExistingMessage();
+}
+
+void Sms::moveToFolder(const FolderType newFolder)
+{
+ update();
+
+ Try
+ {
+ const MSG_FOLDER_ID_T platfromFolderId =
+ Messaging::convertFolderToPlatform(newFolder);
+
+ //call platform api to move message to other folder
+ if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
+ platfromFolderId) != MSG_SUCCESS) {
+ Throw(Commons::PlatformException);
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("remove message error");
+ throw;
+ }
+}
+
+void Sms::moveToFolder(const std::string& /*newFolder*/)
+{
+ update();
+ //TODO
+}
+
+void Sms::copyToFolder(const FolderType newFolder)
+{
+ update();
+
+ msg_message_t msg = msg_new_message();
+
+ Try
+ {
+ MSG_SENDINGOPT_S option;
+ memset(&option, 0, sizeof(MSG_SENDINGOPT_S));
+ option.option.smsSendOpt.bReplyPath = true;
+ // trying to get message from platform
+ if (MSG_SUCCESS ==
+ msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
+ &option))
+ {
+ const MSG_FOLDER_ID_T platfromFolderId =
+ Messaging::convertFolderToPlatform(newFolder);
+ // new id will me set (initialize to 0)
+ msg_set_message_id(msg, 0);
+ msg_set_folder_id(msg, platfromFolderId);
+
+ // trying to add message
+ int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
+ if (error != MSG_SUCCESS) {
+ LogError("msg_add_message failed, error code=" << error);
+ Throw(Commons::PlatformException);
+ }
+
+ //releasing platform message structure
+ msg_release_message(&msg);
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("remove message error");
+ if (msg) {
+ //releasing platform message structure
+ msg_release_message(&msg);
+ }
+ throw;
+ }
+}
+
+void Sms::copyToFolder(const std::string& /*newFolder*/)
+{
+ update();
+ //TODO
+}
+
+void Sms::send()
+{
+ LogDebug("sending message, id=" << getIdRef());
+
+ //prepare for sending sms
+ update();
+
+ // split the message
+ LogDebug("Start Sending Message...");
+ LogDebug("msgId=" << msg_get_message_id(m_messageData));
+ LogDebug("subject: " << msg_get_subject(m_messageData));
+ LogDebug("recipient count: " << msg_get_address_count(m_messageData));
+
+ SendRequest req;
+
+ for (int i = 0; i < msg_get_address_count(m_messageData); ++i) {
+ if (MSG_RECIPIENTS_TYPE_TO !=
+ msg_get_ith_recipient_type(m_messageData, i))
+ {
+ continue;
+ }
+ msg_message_t msg = createNewCopyOfPLatformMsg(m_messageData);
+
+ // remove all addresses except ith
+ msg_reset_address(msg);
+ const char* to = msg_get_ith_address(m_messageData, i);
+ msg_add_address(msg, to, MSG_RECIPIENTS_TYPE_TO);
+
+ LogDebug("recipient: " << msg_get_ith_address(msg, 0));
+ LogDebug("body: " << msg_sms_get_message_body(msg));
+
+ req.queue.push(msg);
+ }
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ m_sendRequests.push(req);
+
+ // schedule sending
+ PostEvent(0);
+
+ LogDebug("sending method finished");
+}
+
+void Sms::sendingCallback(MSG_SENT_STATUS_S *sent_status)
+{
+ LogInfo(
+ "sendingCallback callback received. Req id = " <<
+ sent_status->reqId << " Status = " << (int)sent_status->status <<
+ ", Recipient=" << getRecipient());
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ if (sent_status->status != MSG_NETWORK_SEND_SUCCESS)
+ {
+ m_sendRequests.front().failed = true; // TODO mutex
+ //send callback, error for recipient
+ setSendingStatusFailed();
+ }
+ else
+ {
+ setSendingStatusOk();
+ }
+ msg_release_message(¤tQueue().front());
+ currentQueue().pop();
+
+ //schedule another sub message send
+ PostEvent(0);
+}
+
+void Sms::OnEventReceived(const int&)
+{
+ LogDebug("enter");
+ // send another one
+ sendSubMessage();
+}
+
+Api::FolderType Sms::toFolder(const std::string &folder)
+{
+ if (folder == "INBOX") {
+ return INBOX;
+ } else if (folder == "OUTBOX") {
+ return OUTBOX;
+ } else if (folder == "SENTBOX") {
+ return SENTBOX;
+ } else if (folder == "DRAFTBOX") {
+ return DRAFTBOX;
+ }
+ ThrowMsg(Commons::PlatformException, "Invalid folder");
+}
+
+void Sms::sendSubMessage()
+{
+ LogDebug("enter");
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+
+ // if current request queue gets empty, try next one
+ while (!m_sendRequests.empty()) {
+ // send as long as the sending fails until there are no more messages
+ for (MSG_ERROR_T err = MSG_ERR_UNKNOWN;
+ err != MSG_SUCCESS && !currentQueue().empty();)
+ {
+ err = CallbackMgrSingleton::Instance().registerAndSend(
+ msg_sms_send_message,
+ currentQueue().front(),
+ this);
+ LogInfo("Sending Message (submit request) result:" << err);
+ if (err != MSG_SUCCESS) {
+ LogError(
+ "Sending Message (submit request) failed!!! err=" << err);
+ msg_release_message(¤tQueue().front());
+ currentQueue().pop();
+ m_sendRequests.front().failed = true;
+ //send callback, error for recipient
+ setSendingStatusFailed();
+ }
+ }
+
+ // empty queue -> notify about results
+ if (currentQueue().empty()) {
+ auto event = getSendMessageEvent();
+ if (m_sendRequests.front().failed)
+ {
+ event->setExceptionCode(
+ Commons::ExceptionCodes::UnknownException);
+ }
+
+ ReqReceiverMessage *requestReceiver = getRequestReceiver();
+ if (requestReceiver)
+ {
+ requestReceiver->
+ Commons::EventRequestReceiver<EventSendMessage>::
+ ManualAnswer(event);
+ }
+
+ // this request is finished, try next one
+ m_sendRequests.pop();
+ continue;
+ }
+ break;
+ }
+}
+
+void Sms::setSendingStatusOk()
+{
+ LogDebug("enter");
+ //success callback should be executed here
+ ReqReceiverMessage *requestReceiver = getRequestReceiver();
+ if (requestReceiver) {
+ LogInfo("calling JS success callback");
+ EventSendMessagePtr event = getSendMessageEvent();
+ event->addRecipientSendResult(getRecipient(), true);
+ }
+}
+
+void Sms::setSendingStatusFailed()
+{
+ LogDebug("enter");
+ //error callback should be executed here
+ EventOnSendingFailedEmitterPtr emitter = getEmitter();
+ if (emitter) {
+ EventOnSendingFailedPtr event(new EventOnSendingFailed);
+ event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
+ emitter->emit(event);
+ } else {
+ ReqReceiverMessage *requestReceiver = getRequestReceiver();
+ if (requestReceiver) {
+ LogError("calling JS error callback");
+ EventSendMessagePtr event = getSendMessageEvent();
+ event->addRecipientSendResult(getRecipient(), false);
+ }
+ }
+}
+
+void Sms::remove()
+{
+ Try
+ {
+ // delete message from platform
+ if (msg_delete_message(MsgGetCommonHandle(),
+ convertId(getId())) != MSG_SUCCESS)
+ {
+ LogError("delete message failed");
+ Throw(Commons::PlatformException);
+ } else {
+ LogDebug("message deleted succesfully");
+ }
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("remove message error");
+ throw;
+ }
+}
+
+void Sms::createNewMessage()
+{
+ if (m_messageData) {
+ // release platform message if it was created previously
+ msg_release_message(&m_messageData);
+ m_messageData = NULL;
+ }
+ // create new platform message
+ m_messageData = msg_new_message();
+ Try
+ {
+ MSG_SENDINGOPT_S option;
+ memset(&option, 0, sizeof(MSG_SENDINGOPT_S));
+ option.option.smsSendOpt.bReplyPath = true;
+
+ //default message initialization
+ msg_set_message_id(m_messageData, 0); // It should be set 0
+ msg_set_folder_id(m_messageData, MSG_DRAFT_ID);
+ msg_set_message_type(m_messageData, MSG_TYPE_SMS);
+ msg_set_storage_id(m_messageData, MSG_STORAGE_PHONE);
+ msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
+
+ // update sms data
+ updateBody();
+ updateTo();
+
+ tm dateT = getDateTime();
+ msg_set_time(m_messageData, mktime(&dateT));
+
+ LogDebug("Message created successfully, msgId=" << getId());
+ }
+
+ Catch(Commons::PlatformException) {
+ LogError("Problem with message creation, cleaning");
+ }
+}
+
+void Sms::readExistingMessage()
+{
+ if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
+ ThrowMsg(Commons::PlatformException, "Empty id.");
+ }
+
+ Try {
+ MSG_SENDINGOPT_S option;
+ memset(&option, 0, sizeof(MSG_SENDINGOPT_S));
+ option.option.smsSendOpt.bReplyPath = true;
+
+ // release old data
+ msg_release_message(&m_messageData);
+ m_messageData = NULL;
+ // create new platform structure
+ m_messageData = msg_new_message();
+
+ MSG_MESSAGE_ID_T l_id = convertId(getIdRef());
+ LogDebug("reading message id=" << l_id);
+ // trying to get message from platform
+ if (MSG_SUCCESS ==
+ msg_get_message(MsgGetCommonHandle(), l_id, m_messageData,
+ &option))
+ {
+ LogDebug("message found with msgId=" << getIdRef());
+
+ // read all mms dat to abstraction layer
+ readRecipientList(m_messageData);
+ readBody(m_messageData);
+ readFolder(m_messageData);
+ readDateTime(m_messageData);
+ readReadStatus(m_messageData);
+ readSize(m_messageData);
+ } else {
+ LogError("message not found with msgId=" << getIdRef());
+ setId("");
+ }
+ }
+ Catch(Commons::PlatformException) {
+ // nothing to do
+ }
+}
+
+void Sms::updateBody()
+{
+ // check if abstraction body value has been changed
+ if (isBodyValid()) {
+ return;
+ }
+ LogInfo("updating platfoprm body");
+
+ // change body value in platform structure
+ msg_sms_set_message_body(m_messageData, getBodyRef().c_str(),
+ getBodyRef().length());
+
+ // set flag as true - platform synchronized with abstraction
+ setBodyValidity(true);
+}
+
+void Sms::updateTo()
+{
+ // check if abstraction recipient (to) value has been changed
+ if (getToRecipients().isValid()) {
+ return;
+ }
+ LogInfo("updating platform to");
+
+ // change recipient value in platform structure
+ msg_reset_address(m_messageData);
+ vector<string> to = getToRecipients().getRecipients();
+ LogInfo("updating to");
+ for (size_t i = 0; i < to.size(); i++) {
+ if (i >= MAX_TO_ADDRESS_CNT) {
+ LogError("max number of recipient exceeded");
+ break;
+ }
+ LogDebug("adding to[" << i << "]=" << to[i]);
+ string tmpAddr = to[i];
+ // function for validating phone number
+ if (validatePhoneNumber(tmpAddr)) {
+ // add phone number to platform message struncture
+ if (msg_add_address(m_messageData, tmpAddr.c_str(),
+ MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
+ {
+ LogError("problem witgh add address");
+ Throw(Commons::PlatformException);
+ }
+ } else {
+ //nothing to do if wrong format
+ LogError("wrong phone number format");
+ }
+ }
+
+ // set flag as true - platform synchronized with abstraction
+ setToValidity(true);
+}
+
+void Sms::updateFrom()
+{
+ // check if abstraction from field value has been changed
+ if (getFromValidity()) {
+ // do not update if not changed
+ return;
+ }
+ LogInfo("updating platform from");
+
+ //TODO
+
+ // set flag as true - platform synchronized with abstraction
+ setFromValidity(true);
+}
+
+void Sms::updateSourceAddress()
+{
+ // check if abstraction source address value has been changed
+ if (getSourceAddressValidity()) {
+ // do not update if not changed
+ return;
+ }
+ LogInfo("updating platform source address");
+
+ //TODO
+
+ // set flag as true - platform synchronized with abstraction
+ setSourceAddressValidity(true);
+}
+
+void Sms::updateReadStatus()
+{
+ LogInfo("updating platform read status: " << isRead());
+ if (isReadStatusValid()) {
+ // do not update if not changed
+ return;
+ }
+
+ if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
+ LogError("problem with setting subject");
+ ThrowMsg(Commons::PlatformException, "Problem with setting subject");
+ }
+ setReadStatusValidity(true);
+}
+
+void Sms::readRecipientList(msg_message_t& messageData)
+{
+ LogDebug("Adding recipients to message, count=" <<
+ msg_get_address_count(messageData));
+ // iterate for all address and store in abstraction
+ for (int i = 0; i < msg_get_address_count(messageData); i++) {
+ string tmp = msg_get_ith_address(messageData, i);
+ int type = msg_get_direction_info(messageData);
+
+ if (MSG_DIRECTION_TYPE_MT == type) {
+ if (validatePhoneNumber(tmp)) {
+ setSourceAddress(tmp);
+ setFrom(tmp);
+ }
+ } else if (MSG_DIRECTION_TYPE_MO == type) {
+ appendToRecipients(tmp);
+ } else {
+ ThrowMsg(Commons::PlatformException, "Wrong type of recipient.");
+ }
+ }
+}
+
+void Sms::readBody(msg_message_t& messageData)
+{
+ //set abstraction body value
+ const char* body = msg_sms_get_message_body(messageData);
+ if (NULL == body) {
+ ThrowMsg(Commons::PlatformException,
+ "Body is NULL. Probably message is invalid.");
+ }
+ setBody(body);
+}
+
+void Sms::readFolder(msg_message_t& messageData)
+{
+ switch (msg_get_folder_id(messageData)) {
+ case MSG_INBOX_ID:
+ setFolderType(Api::INBOX);
+ break;
+ case MSG_OUTBOX_ID:
+ setFolderType(Api::OUTBOX);
+ break;
+ case MSG_SENTBOX_ID:
+ setFolderType(Api::SENTBOX);
+ break;
+ case MSG_DRAFT_ID:
+ setFolderType(Api::DRAFTBOX);
+ break;
+ case MSG_SPAMBOX_ID:
+ setFolderType(Api::SPAMBOX);
+ break;
+ default:
+ LogError("Wrong folder id");
+ ThrowMsg(Commons::PlatformException, "Unsupported folder id.");
+ }
+}
+
+void Sms::readDateTime(msg_message_t& messageData)
+{
+ tm* time = localtime(msg_get_time(messageData));
+ if (!time) {
+ LogError("localtime failed");
+ Throw(Commons::PlatformException);
+ }
+ setDateTime(*time);
+}
+
+void Sms::readReadStatus(msg_message_t& messageData)
+{
+ // get read status
+ setReadStatus(msg_is_read(messageData));
+}
+
+void Sms::readSize(msg_message_t& messageData)
+{
+ setSize(msg_get_message_body_size(messageData));
+}
+
+msg_message_t Sms::createNewCopyOfPLatformMsg(const msg_message_t src) const
+{
+ msg_message_t msg = msg_new_message();
+
+ msg_set_message_id(msg, 0);
+ msg_set_storage_id(msg, msg_get_storage_id(src));
+ msg_set_message_type(msg, msg_get_message_type(src));
+ msg_set_folder_id(msg, msg_get_folder_id(src));
+ for (int i = 0; i < msg_get_address_count(src); i++) {
+ msg_add_address(msg, msg_get_ith_address(src,
+ i),
+ msg_get_ith_recipient_type(src, i));
+ }
+ msg_sms_set_message_body(msg, msg_sms_get_message_body(
+ src), msg_get_message_body_size(src));
+ msg_set_subject(msg, msg_get_subject(src));
+ msg_set_time(msg, *msg_get_time(src));
+ msg_set_network_status(msg, msg_get_network_status(src));
+ msg_set_encode_type(msg, msg_get_encode_type(src));
+ msg_set_read_status(msg, msg_is_read(src));
+ msg_set_protect_status(msg, msg_is_protected(src));
+ msg_set_priority_info(msg, msg_get_priority_info(src));
+ msg_set_direction_info(msg, msg_get_direction_info(src));
+ msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
+ msg_set_scheduled_time(msg, *msg_get_scheduled_time(src));
+
+ return msg;
+}
+}
+}
--- /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 Sms.h
+ * @author Pawel Misiak (p.misiak@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+#ifndef SMS_H
+#define SMS_H
+
+#include <API/Messaging/ISms.h>
+#include "ISendingObserver.h"
+#include <queue>
+
+extern "C" {
+#include <MapiTransport.h>
+#include <MapiControl.h>
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+class Sms : public Api::ISms,
+ public ISendingObserver,
+ public DPL::Event::Controller<DPL::TypeListDecl<int>::Type >
+{
+ public:
+ explicit Sms(const std::string& id = "");
+
+ virtual ~Sms();
+
+ // implementation of interface of IMessage class
+ virtual void update(bool draftsOnly = false);
+
+ virtual void readAllData();
+
+ virtual void moveToFolder(const Api::FolderType newFolder);
+
+ virtual void moveToFolder(const std::string& newFolder);
+
+ virtual void copyToFolder(const Api::FolderType newFolder);
+
+ virtual void copyToFolder(const std::string& newFolder);
+
+ virtual void remove();
+
+ virtual void send();
+
+ virtual void sendCancel()
+ {
+ }
+
+ virtual void sendingCallback(MSG_SENT_STATUS_S *sent_status);
+
+ virtual void OnEventReceived(const int& /*event*/);
+
+ static Api::FolderType toFolder(const std::string &folder);
+
+ private:
+ void sendSubMessage();
+
+ void setSendingStatusOk();
+
+ void setSendingStatusFailed();
+
+ void createNewMessage();
+
+ void readExistingMessage();
+
+ void updateBody();
+
+ void updateTo();
+
+ void updateFrom();
+
+ void updateSourceAddress();
+
+ void updateReadStatus();
+
+ void readRecipientList(msg_message_t& messageData);
+
+ void readBody(msg_message_t& messageData);
+
+ void readFolder(msg_message_t& messageData);
+
+ void readDateTime(msg_message_t& messageData);
+
+ void readReadStatus(msg_message_t& messageData);
+
+ void readSize(msg_message_t& messageData);
+
+ std::queue<msg_message_t>& currentQueue()
+ {
+ return m_sendRequests.front().queue;
+ }
+
+ msg_message_t createNewCopyOfPLatformMsg(const msg_message_t src) const;
+
+ private:
+ msg_message_t m_messageData;
+ bool m_sendingFailed;
+ DPL::Mutex m_mutex;
+
+ struct SendRequest
+ {
+ // queue of sub messages for each recipient
+ std::queue<msg_message_t> queue;
+ bool failed;
+
+ SendRequest() : failed(false)
+ {
+ }
+ };
+ // queue of send requests
+ std::queue<SendRequest> m_sendRequests;
+};
+}
+}
+
+#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 StorageChangeMessage.cpp
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#include <Commons/Exception.h>
+#include "StorageChangeMessage.h"
+
+namespace {
+const char* DBUS_INTERFACE_STORAGE_CHANGE = "User.Email.StorageChange";
+const int DBUS_MESSAGE_PARAMETERS_NUMBER = 5;
+}
+
+namespace WrtDeviceApis {
+namespace Messaging {
+
+StorageChangeMessage::StorageChangeMessage()
+ : m_accountId(0),
+ m_mailId(0),
+ m_extra(0)
+{ }
+
+StorageChangeMessage StorageChangeMessage::parse(const DBus::MessagePtr& message)
+{
+ Assert(message.Get() != NULL && "Empty message.");
+ Assert(message->getInterface() == DBUS_INTERFACE_STORAGE_CHANGE);
+
+ StorageChangeMessage result;
+
+ DBus::Message::ReadIterator it = message->getReadIterator();
+ for (int i = 0; i < DBUS_MESSAGE_PARAMETERS_NUMBER; it->next(), ++i)
+ {
+ if (!it->isValid())
+ {
+ ThrowMsg(Commons::PlatformException, "Missing some properties.");
+ }
+
+ switch (i)
+ {
+ case 0:
+ result.m_type = it->getInt();
+ break;
+ case 1:
+ result.m_accountId = it->getInt();
+ break;
+ case 2:
+ result.m_mailId = it->getInt();
+ break;
+ case 3:
+ result.m_folderName = it->getString();
+ break;
+ case 4:
+ result.m_extra = it->getInt();
+ break;
+ }
+ }
+
+ return result;
+}
+
+int StorageChangeMessage::getType() const
+{
+ return m_type;
+}
+
+int StorageChangeMessage::getAccountId() const
+{
+ return m_accountId;
+}
+
+int StorageChangeMessage::getMailId() const
+{
+ return m_mailId;
+}
+
+std::string StorageChangeMessage::getFolderName() const
+{
+ return m_folderName;
+}
+
+int StorageChangeMessage::getExtra() const
+{
+ return m_extra;
+}
+
+}
+}
--- /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 StorageChangeMessage.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef SRC_MODULES_TIZEN_MESSAGING_STORAGECHANGEMESSAGE_H_
+#define SRC_MODULES_TIZEN_MESSAGING_STORAGECHANGEMESSAGE_H_
+
+#include <string>
+#include <DBus/Message.h>
+
+namespace WrtDeviceApis {
+namespace Messaging {
+
+class StorageChangeMessage
+{
+public:
+ static StorageChangeMessage parse(const DBus::MessagePtr& message);
+
+ int getType() const;
+ int getAccountId() const;
+ int getMailId() const;
+ std::string getFolderName() const;
+
+ /**
+ * Depends on the type:
+ * - NOTI_MAIL_ADD: id of a thread
+ * - NOTI_MAIL_UPDATE: type of the change @see emf_mail_change_type_t
+ * @return Extra information.
+ */
+ int getExtra() const;
+
+private:
+ StorageChangeMessage();
+
+private:
+ int m_type;
+ int m_accountId;
+ int m_mailId;
+ std::string m_folderName;
+ int m_extra;
+};
+
+}
+}
+
+#endif
--- /dev/null
+get_current_path()
+
+pkg_search_module(msg-service-module REQUIRED msg-service)
+pkg_search_module(email-service-module REQUIRED email-service)
+
+set(INCLUDES_MESSAGING_DIRECTORIES
+ ${msg-service-module_INCLUDE_DIRS}
+ ${email-service-module_INCLUDE_DIRS}
+ ${INCLUDES_IMPLEMENTATION_DBUS}
+ PARENT_SCOPE
+)
+
+set(LIBS_IMPLEMENTATION_MESSAGING
+ ${msg-service-module_LIBRARIES}
+ ${email-service-module_LIBRARIES}
+ ${LIBS_IMPLEMENTATION_DBUS}
+ PARENT_SCOPE
+)
+
+set(SRCS_IMPLEMENTATION_MESSAGING
+ ${CURRENT_PATH}/Attachment.cpp
+ ${CURRENT_PATH}/BinarySms.cpp
+ ${CURRENT_PATH}/Email.cpp
+ ${CURRENT_PATH}/Messaging.cpp
+ ${CURRENT_PATH}/Mms.cpp
+ ${CURRENT_PATH}/Sms.cpp
+ ${CURRENT_PATH}/CallbackMgr.cpp
+ ${CURRENT_PATH}/NetworkStatus.cpp
+ ${CURRENT_PATH}/MailSender.cpp
+ ${CURRENT_PATH}/EmailService.cpp
+ ${CURRENT_PATH}/EmailUtils.cpp
+ ${CURRENT_PATH}/EmailConverter.cpp
+ ${CURRENT_PATH}/MsgServiceHandleMgr.cpp
+ ${CURRENT_PATH}/StorageChangeMessage.cpp
+ ${CURRENT_PATH}/MailNotifier.cpp
+ ${SRCS_IMPLEMENTATION_DBUS}
+ 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 "Connection.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+std::string Connection::getName() const
+{
+ return m_name;
+}
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_CONNECTION_H_
+#define WRTDEVICEAPIS_NETWORKING_CONNECTION_H_
+
+#include <string>
+#include <Networking/IConnection.h>
+
+namespace WrtDeviceApis {
+namespace Networking {
+/* TODO */
+class Connection : public Api::IConnection
+{
+ public:
+ std::string getName() const;
+
+ private:
+ std::string m_name;
+};
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_CONNECTION_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 "EthernetAdapter.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+EthernetAdapter::EthernetAdapter()
+{
+}
+
+void EthernetAdapter::addOnConnected(
+ const Api::EventConnectedEmitterPtr& emitter)
+{
+ m_onConnected.attach(emitter);
+}
+
+void EthernetAdapter::removeOnConnected(
+ Api::EventConnectedEmitter::IdType id)
+{
+ m_onConnected.detach(id);
+}
+
+void EthernetAdapter::addOnDisconnected(
+ const Api::EventDisconnectedEmitterPtr& emitter)
+{
+ m_onDisconnected.attach(emitter);
+}
+
+void EthernetAdapter::removeOnDisconnected(
+ Api::EventDisconnectedEmitter::IdType id)
+{
+ m_onDisconnected.detach(id);
+}
+
+Api::IAdapter::Type EthernetAdapter::getAdapterType() const
+{
+ return Api::IAdapter::T_ETHERNET;
+}
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_ETHERNETADAPTER_H_
+#define WRTDEVICEAPIS_NETWORKING_ETHERNETADAPTER_H_
+
+#include <Networking/IAdapter.h>
+#include <Networking/EventConnected.h>
+#include <Networking/EventDisconnected.h>
+#include <Commons/Emitters.h>
+
+namespace WrtDeviceApis {
+namespace Networking {
+class Manager;
+
+class EthernetAdapter : public Api::IAdapter
+{
+ friend class Manager;
+
+ public:
+ bool isConnected() const /* TODO */
+ { return false;
+ }
+
+ // Api::Networking::IConnectionPtr getConnection() const { /* TODO */ }
+
+ void addOnConnected(
+ const Api::EventConnectedEmitterPtr& emitter);
+
+ void removeOnConnected(Api::EventConnectedEmitter::IdType id);
+
+ void addOnDisconnected(
+ const Api::EventDisconnectedEmitterPtr& emitter);
+
+ void removeOnDisconnected(
+ Api::EventDisconnectedEmitter::IdType id);
+
+ Api::IAdapter::Type getAdapterType() const;
+
+ private:
+ EthernetAdapter();
+
+ private:
+ Commons::Emitters<Api::EventConnectedEmitter> m_onConnected;
+ Commons::Emitters<Api::EventDisconnectedEmitter>
+ m_onDisconnected;
+};
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_ETHERNETADAPTER_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 "Manager.h"
+
+//#include <cstddef>
+//#include <NetCMIntf.h>
+//#include <NetPMIntf.h>
+//#include <wlan-engine-client-intf.h>
+//#include <dpl/log/log.h>
+#include "EthernetAdapter.h"
+#include "WifiAdapter.h"
+
+/* TODO - commented source code will be removed */
+//namespace {
+//const std::size_t SSID_MAX_LENGTH = 32;
+//} // anonymous
+
+namespace WrtDeviceApis {
+namespace Networking {
+//net_event_callbacks Manager::m_netEventCallbacks = Manager::getNetEventCallbacks();
+
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Api::IAdapter* Manager::getAdapter(Api::IAdapter::Type /*type*/) const
+{
+ //TODO: to be implemented
+ return NULL;
+ // Adapters::const_iterator it = m_adapters.find(type);
+ // if (it == m_adapters.end()) {
+ // return NULL;
+ // }
+ // return it->second;
+}
+
+void Manager::getAvailableAdapters(Api::AdaptersSet *retSet) const
+{
+ if (retSet) {
+ retSet->insert(retSet->end(), m_adapters.begin(), m_adapters.end());
+ }
+}
+
+//Api::Connections Manager::getConnections() const {
+// return m_connections;
+//}
+//
+//void Manager::wlanCallback(const wlan_event_type_t* event,
+// void* userData,
+// void* data)
+//{
+// LogDebug("--| ENTER");
+// LogInfo("Event: " << *event);
+//}
+//
+//void Manager::onNetConnectionOpen(const NetErr_t error,
+// const NetDevInfo_t* device,
+// int transportErrorCode,
+// void *userData)
+//{
+// LogDebug("--| ENTER");
+//
+//}
+//
+//void Manager::onNetConnectionClose(const NetErr_t error,
+// int transportErrorCode,
+// void *userData)
+//{ LogDebug("--| ENTER"); }
+//
+//void Manager::onNetConnectionKill(const NetErr_t error,
+// int transportErrorCode,
+// void *userData)
+//{ LogDebug("--| ENTER"); }
+//
+//void Manager::onNetStatusChange(NetStatusInfo_t* status, void *userData) {
+// LogDebug("--| ENTER");
+// LogInfo("Type: " << status->transportType << ", status: " << status->WiFiStatus);
+//}
+
+Manager::Manager()
+{
+ setupAdapters();
+}
+
+Manager::~Manager()
+{
+ removeAdapters();
+}
+
+void Manager::setupAdapters()
+{
+ //TODO: to be implemented
+ // Api::IAdapter* adapter = NULL;
+ //
+ // adapter = new EthernetAdapter();
+ // m_adapters.insert(Adapters::value_type(Api::IAdapter::T_ETHERNET, adapter));
+ //
+ // adapter = new WifiAdapter();
+ // m_adapters.insert(Adapters::value_type(Api::IAdapter::T_WIFI, adapter));
+}
+
+void Manager::removeAdapters()
+{
+ //TODO: to be implemented
+ // Adapters::iterator it = m_adapters.begin();
+ // for (; it != m_adapters.end(); ++it) {
+ // delete it->second;
+ // }
+ // m_adapters.clear();
+}
+
+//void Manager::attachListeners() {
+// int error = 0;
+//
+// if ((error = net_register_client(&m_netEventCallbacks, this)) != NET_ERR_NONE) {
+// LogError("Could not register to datanetworking module (" << error << ").");
+// }
+//
+// if ((error = wlan_client_register(wlanCallback, this)) != WLAN_ERR_NONE) {
+// LogError("Could not register to wifi module (" << error << ").");
+// }
+//}
+//
+//void Manager::detachListeners() {
+// int error = 0;
+//
+// if ((error = net_deregister_client()) != NET_ERR_NONE) {
+// LogError("Could not deregister from datanetworking module (" << error << ").");
+// }
+//
+// if ((error = wlan_client_deregister()) != WLAN_ERR_NONE) {
+// LogError("Could not deregister from wifi module (" << error << ").");
+// }
+//}
+
+//void Manager::initConnections() {
+// int error;
+// int profile = 0;
+// char ssid[SSID_MAX_LENGTH + 1] = {0};
+// if ((error = wlan_client_get_connected_ap_info(&profile, ssid)) == WLAN_ERR_NONE) {
+// Adapter* connection = new Adapter();
+// connection->setType(Api::IAdapter::T_WIFI);
+// connection->setName(ssid);
+// m_connections.push_back(connection);
+// }
+// else {
+// LogError("Could not get wlan connection info (" << error << ").");
+// }
+//}
+//
+//void Manager::clearConnections() {
+// Api::Connections::iterator it = m_connections.begin();
+// for (; it != m_connections.end(); ++it) {
+// delete *it;
+// }
+//}
+//
+//net_event_callbacks Manager::getNetEventCallbacks() {
+// net_event_callbacks result = {0};
+// result.on_open_rsp = Manager::onNetConnectionOpen;
+// result.on_close_rsp = Manager::onNetConnectionClose;
+// result.on_kill_rsp = Manager::onNetConnectionKill;
+// result.on_net_status = Manager::onNetStatusChange;
+// return result;
+//}
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_MANAGER_H_
+#define WRTDEVICEAPIS_NETWORKING_MANAGER_H_
+
+#include <map>
+//extern "C" {
+// #include <wlan-interface.h>
+//}
+//#include <dpl/mutex.h>
+#include <Networking/IManager.h>
+
+namespace WrtDeviceApis {
+namespace Networking {
+/* TODO - commented source code will be removed */
+class Manager : public Api::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ /**
+ * @see Api::IManager::getAdapter()
+ */
+ Api::IAdapter* getAdapter(Api::IAdapter::Type type)
+ const;
+
+ /**
+ * @see Api::IManager::getAvailableAdapters
+ */
+ virtual void getAvailableAdapters(Api::AdaptersSet *retSet)
+ const;
+
+ protected:
+ Manager();
+ virtual ~Manager();
+
+ /**
+ * Initialize adapters available on wac.
+ */
+ void setupAdapters();
+
+ /**
+ * Cleans up adapters.
+ */
+ void removeAdapters();
+
+ private:
+ // typedef std::map<Api::IAdapter::Type,
+ // Api::IAdapter*> Adapters;
+ //private:
+ // static void wlanCallback(const wlan_event_type_t* event,
+ // void* userData,
+ // void* data);
+ //
+ // static void onNetConnectionOpen(const NetErr_t error,
+ // const NetDevInfo_t* device,
+ // int transportErrorCode,
+ // void *userData);
+ //
+ // static void onNetConnectionClose(const NetErr_t error,
+ // int transportErrorCode,
+ // void *userData);
+ //
+ // static void onNetConnectionKill(const NetErr_t error,
+ // int transportErrorCode,
+ // void *userData);
+ //
+ // static void onNetStatusChange(NetStatusInfo_t* status, void *userData);
+ //
+ // static net_event_callbacks getNetEventCallbacks();
+ //
+ //private:
+ // static net_event_callbacks m_netEventCallbacks;
+
+ private:
+ // DPL::Mutex m_mtx; ///< Synchronizes access to this object.
+ // Adapters m_adapters; ///< Adapters container.
+ Api::AdaptersSet m_adapters;
+};
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_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 "WifiAdapter.h"
+
+namespace WrtDeviceApis {
+namespace Networking {
+WifiAdapter::WifiAdapter()
+{
+}
+
+void WifiAdapter::addOnConnected(
+ const Api::EventConnectedEmitterPtr& emitter)
+{
+ m_onConnected.attach(emitter);
+}
+
+void WifiAdapter::removeOnConnected(
+ Api::EventConnectedEmitter::IdType id)
+{
+ m_onConnected.detach(id);
+}
+
+void WifiAdapter::addOnDisconnected(
+ const Api::EventDisconnectedEmitterPtr& emitter)
+{
+ m_onDisconnected.attach(emitter);
+}
+
+void WifiAdapter::removeOnDisconnected(
+ Api::EventDisconnectedEmitter::IdType id)
+{
+ m_onDisconnected.detach(id);
+}
+
+Api::IAdapter::Type WifiAdapter::getAdapterType() const
+{
+ return Api::IAdapter::T_WIFI;
+}
+} // Networking
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_NETWORKING_WIFIADAPTER_H_
+#define WRTDEVICEAPIS_NETWORKING_WIFIADAPTER_H_
+
+#include <Networking/IAdapter.h>
+#include <Networking/EventConnected.h>
+#include <Networking/EventDisconnected.h>
+#include <Commons/Emitters.h>
+
+namespace WrtDeviceApis {
+namespace Networking {
+class Manager;
+
+class WifiAdapter : public Api::IAdapter
+{
+ friend class Manager;
+
+ public:
+ bool isConnected() const /* TODO */
+ { return false;
+ }
+
+ //Api::Networking::IConnectionPtr getConnection() const { /* TODO */ }
+
+ void addOnConnected(
+ const Api::EventConnectedEmitterPtr& emitter);
+
+ void removeOnConnected(Api::EventConnectedEmitter::IdType id);
+
+ void addOnDisconnected(
+ const Api::EventDisconnectedEmitterPtr& emitter);
+
+ void removeOnDisconnected(
+ Api::EventDisconnectedEmitter::IdType id);
+
+ Api::IAdapter::Type getAdapterType() const;
+
+ private:
+ WifiAdapter();
+
+ private:
+ Commons::Emitters<Api::EventConnectedEmitter> m_onConnected;
+ Commons::Emitters<Api::EventDisconnectedEmitter>
+ m_onDisconnected;
+};
+} // Networking
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_NETWORKING_WIFIADAPTER_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(dnet REQUIRED dnet)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_NETWORKING
+ ${dnet_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_NETWORKING
+ ${dnet_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_IMPLEMENTATION_NETWORKING
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/EthernetAdapter.cpp
+ ${CURRENT_PATH}/WifiAdapter.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 Orientation.cpp
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <cassert>
+#include <Orientation/EventGetCurrentOrientation.h>
+#include <Commons/Exception.h>
+#include "Orientation.h"
+
+using namespace DPL;
+
+namespace WrtDeviceApis {
+namespace Orientation {
+
+using namespace Api;
+
+namespace {
+/**
+ * Callback method called by platform as interval time.
+ * @param event_type Platform orientation evet type
+ * @param event Platform sensor event data
+ * @param this_ User data pointer.
+ */
+static void OrientationChangedCallback(unsigned int event_type,
+ sensor_event_data_t *event,
+ void *watcher_ptr)
+{
+ LogDebug("Callback OrientationChangedCallback.");
+ if (watcher_ptr) {
+ if (event_type == GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME &&
+ event != NULL) {
+ ((Orientation::Watcher*)watcher_ptr)->orientationHasChanged(event);
+ }
+ } else {
+ LogError("Callback private data is NULL.");
+ }
+}
+} //private namespace
+
+Orientation::Orientation() :
+ m_handle(-1),
+ m_initialized(false),
+ m_isWatch(false)
+{
+ LogDebug("Platform::Orientation Enter");
+}
+
+Orientation::~Orientation()
+{
+ LogDebug("Enter");
+
+ if (m_initialized == true) {
+ stop(m_handle);
+ }
+
+ LogDebug("All watchers : (" << m_watchers.size() << ")");
+ std::vector<WatcherPtr>::iterator it;
+ for (it = m_watchers.begin(); it != m_watchers.end(); ++it) {
+ stop((*it)->getHandle(), true);
+ }
+ m_watchers.clear();
+ LogDebug("All watchers were cleared. (" << m_watchers.size() << ")");
+}
+
+void Orientation::getCurrentOrientation(
+ const EventGetCurrentOrientationPtr& event)
+{
+ LogDebug("Entered");
+
+ if (m_initialized == false) {
+ m_handle = initialize();
+ start(m_handle);
+ m_initialized = true;
+ }
+ EventRequestReceiver<EventGetCurrentOrientation>::PostRequest(event);
+}
+
+void Orientation::OnRequestReceived(const EventGetCurrentOrientationPtr& event)
+{
+ LogDebug("Entered");
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ /**
+ * Invoke platform API sf_get_data gets raw data from a sensor with connecting the sensor-server.
+ * The type of sensor is supplied and return data is stored in the output parameter values [].
+ */
+ if ((sf_get_data(m_handle, GEOMAGNETIC_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 3)) {
+ LogError("Can't get current Orientation. ");
+ Throw(Commons::PlatformException);
+ }
+
+ event->setAlpha(static_cast<double>(data.values[0]));
+ event->setBeta(static_cast<double>(data.values[1]));
+ event->setGamma(static_cast<double>(data.values[2]));
+}
+
+long Orientation::watchOrientation(
+ const EventOrientationChangedEmitterPtr& emitter,
+ long minNotificationInterval)
+{
+ LogDebug("Entered");
+ int new_handle = initialize();
+ int sensor_state = 0;
+ event_condition_t condition;
+ condition.cond_op = CONDITION_EQUAL;
+ condition.cond_value1 = minNotificationInterval;
+ /**
+ * Invoke platform API sf_register_event registers a user defined callback function with a connected sensor for a particular event.
+ **This callback function will be called when there is a change in the state of respective sensor.
+ **cb_data will be the parameter used during the callback call.
+ **Callback interval can be adjusted using even_contion_t argument.
+ */
+ WatcherPtr watcher(new Watcher(new_handle, emitter));
+
+ sensor_state = sf_register_event(
+ watcher->getHandle(),
+ GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME, &condition,
+ OrientationChangedCallback, watcher.Get());
+ if (sensor_state < 0) {
+ stop(watcher->getHandle());
+ Throw(Commons::PlatformException);
+ }
+ m_isWatch = true;
+ start(watcher->getHandle());
+ m_watchers.push_back(watcher);
+ watcher->getCurrentOrientationForWatch();
+ return static_cast<long>(emitter->getId());
+}
+
+void Orientation::clearWatch(EventOrientationChangedEmitter::IdType id)
+{
+ LogDebug("Entered");
+
+ std::vector<WatcherPtr>::iterator it;
+ for (it = m_watchers.begin(); it != m_watchers.end(); ++it) {
+ if (id == (*it)->getEmitter()->getId()) {
+ stop((*it)->getHandle(), true);
+
+ m_watchers.erase(it);
+ LogDebug("Watcher is removed. (" << m_watchers.size() << ")");
+
+ if (m_watchers.size() == 0) {
+ m_isWatch = false;
+ }
+ break;
+ }
+ }
+}
+
+void Orientation::OrientationHasChanged(sensor_event_data_t *sensorEvent)
+{
+ LogDebug("Entered");
+
+ sensor_data_t *sensor_data = NULL;
+ sensor_data = (sensor_data_t *)sensorEvent->event_data;
+ if (sensor_data == NULL ||
+ (sensor_data->values_num < 3)) {
+ LogError("Can't get current Acceleration. ");
+ Throw(Commons::PlatformException);
+ return;
+ }
+
+ EventOrientationChangedPtr event(new EventOrientationChanged());
+ OrientationProperties props;
+ props.alpha = static_cast<double>(sensor_data->values[0]);
+ props.beta = static_cast<double>(-(sensor_data->values[1]));
+ props.gamma = static_cast<double>(-(sensor_data->values[2]));
+
+ LogDebug(
+ "alpha" << props.alpha << ",beta" << props.beta << ",gamma" <<
+ props.gamma);
+
+ event->setOrientationProperties(props);
+
+ m_OrientationEmitters.emit(event);
+}
+
+void Orientation::getCurrentOrientationForWatch(void)
+{
+ LogDebug("Entered");
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ if ((sf_get_data(m_handle, GEOMAGNETIC_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 3)) {
+ Throw(Commons::PlatformException);
+ }
+
+ EventOrientationChangedPtr event(new EventOrientationChanged());
+ OrientationProperties props;
+ props.alpha = static_cast<double>(data.values[0]);
+ props.beta = static_cast<double>(-(data.values[1]));
+ props.gamma = static_cast<double>(-(data.values[2]));
+
+ event->setOrientationProperties(props);
+
+ m_OrientationEmitters.emit(event);
+}
+
+int Orientation::initialize()
+{
+ LogDebug("Entered");
+ DPL::Mutex::ScopedLock lock(&m_initializationMutex);
+ int handle = sf_connect(GEOMAGNETIC_SENSOR);
+ if (handle < 0) {
+ LogError("Could not connect with orientation sensor.");
+ Throw(Commons::UnsupportedException);
+ }
+ return handle;
+}
+
+void Orientation::restart(int& handle)
+{
+ stop(handle);
+ start(handle);
+}
+
+void Orientation::start(int handle)
+{
+ LogDebug("Entered");
+ if (sf_start(handle, 0) < 0) {
+ LogError("Could not start communication with sensor.");
+ if (handle >= 0) {
+ sf_disconnect(handle);
+ Throw(Commons::UnsupportedException);
+ }
+ } else {
+ // TODO: find the way to fix this
+ usleep(100000);
+ }
+}
+
+void Orientation::stop(int& handle,
+ bool isWatcherHandle)
+{
+ LogDebug("Entered");
+
+ if (handle >= 0) {
+ if (isWatcherHandle == true) {
+ sf_unregister_event(handle,
+ GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME);
+ }
+ sf_stop(handle);
+ sf_disconnect(handle);
+ handle = -1;
+ }
+}
+
+//Watcher's
+void Orientation::Watcher::getCurrentOrientationForWatch()
+{
+ LogDebug("Enter");
+ sensor_data_t data;
+ memset(&data, 0, sizeof(sensor_data_t));
+ if ((sf_get_data(m_handle, GEOMAGNETIC_BASE_DATA_SET, &data) < 0) ||
+ (data.values_num < 3)) {
+ Throw(Commons::PlatformException);
+ }
+
+ EventOrientationChangedPtr event(new EventOrientationChanged());
+ OrientationProperties props;
+ props.alpha = static_cast<double>(data.values[0]);
+ props.beta = static_cast<double>(data.values[1]);
+ props.gamma = static_cast<double>(data.values[2]);
+
+ event->setOrientationProperties(props);
+
+ emit(event);
+}
+
+//Watcher's
+void Orientation::Watcher::orientationHasChanged(
+ sensor_event_data_t *sensorEvent)
+{
+ LogDebug("Enter");
+ sensor_data_t *sensor_data = NULL;
+ sensor_data = (sensor_data_t *)sensorEvent->event_data;
+ if (sensor_data == NULL ||
+ (sensor_data->values_num < 3)) {
+ LogError("Can't get current Orientation. ");
+ Throw(Commons::PlatformException);
+ return;
+ }
+
+ EventOrientationChangedPtr event(new EventOrientationChanged());
+ OrientationProperties props;
+ props.alpha = static_cast<double>(sensor_data->values[0]);
+ props.beta = static_cast<double>(sensor_data->values[1]);
+ props.gamma = static_cast<double>(sensor_data->values[2]);
+ LogDebug(
+ "alpha:" << sensor_data->values[0] << ",beta:" <<
+ sensor_data->values[1] << ",gamma:" << sensor_data->values[2]);
+
+ event->setOrientationProperties(props);
+
+ emit(event);
+}
+
+}
+}
--- /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 Orientation.h
+ * @author Qi Xiangguo (xiangguo.qi@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_ORIENTATION_ORIENTATION_H_
+#define WRTDEVICEAPIS_ORIENTATION_ORIENTATION_H_
+
+#include <map>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <sensor.h>
+#include <sensor_accel.h>
+#include <Orientation/IOrientation.h>
+#include <Orientation/OrientationFactory.h>
+#include <Orientation/EventOrientationChanged.h>
+#include <Commons/Emitters.h>
+
+namespace WrtDeviceApis {
+namespace Orientation {
+
+class Orientation : public Api::IOrientation
+{
+ int m_handle;
+ gulong m_signalId;
+ /**
+ * @See: Api::Orientation.
+ */
+ friend class Api::OrientationFactory;
+
+ public:
+ class Watcher
+ {
+ private:
+ int m_handle;
+ Api::EventOrientationChangedEmitterPtr m_emitter;
+
+ public:
+ Watcher(
+ int handle,
+ const Api::EventOrientationChangedEmitterPtr&
+ emitter) :
+ m_handle(handle),
+ m_emitter(emitter)
+ {
+ }
+
+ int& getHandle()
+ {
+ return m_handle;
+ }
+
+ Api::EventOrientationChangedEmitterPtr getEmitter()
+ {
+ return m_emitter;
+ }
+
+ void emit(const Api::EventOrientationChangedPtr& event)
+ {
+ m_emitter->emit(event);
+ }
+ void getCurrentOrientationForWatch();
+ void orientationHasChanged(sensor_event_data_t *sensorEvent);
+ };
+ typedef DPL::SharedPtr<Watcher> WatcherPtr;
+
+ public:
+ virtual ~Orientation();
+
+ /**
+ * @See: IOrientation::getCurrentOrientation
+ */
+ virtual void getCurrentOrientation(
+ const Api::EventGetCurrentOrientationPtr& event);
+
+ /**
+ * @See: IOrientation::watchOrientation
+ */
+ virtual long watchOrientation(
+ const Api::EventOrientationChangedEmitterPtr&
+ emitter,
+ long minNotificationInterval);
+
+ /**
+ * @See: IOrientation::clearWatch
+ */
+ virtual void clearWatch(
+ Api::EventOrientationChangedEmitter::IdType id);
+
+ /**
+ * Method to run from platform's callback function
+ */
+ void OrientationHasChanged(sensor_event_data_t *sensorEvent);
+
+ /**
+ * Method to get current orientation for watch function
+ */
+ void getCurrentOrientationForWatch();
+
+ protected:
+ Orientation();
+ virtual void OnRequestReceived(
+ const Api::EventGetCurrentOrientationPtr& event);
+
+ private:
+ typedef Commons::Emitters<Api::EventOrientationChangedEmitter>
+ OrientationChangedEmitters;
+
+ /**
+ * Initialize orientation sensor. This method returns when platform error occurs.
+ */
+ int initialize();
+
+ /**
+ * Start orientation sensor. This method sends a start command to sensor server.
+ */
+ void start(int handle);
+
+ /**
+ * Stop orientation sensor. This method sends a stop command to sensor server.
+ */
+ void stop(int& handle,
+ bool isWatcherHandle = false);
+
+ /**
+ * Method to restart orientation sensor server.
+ */
+ void restart(int& handle);
+
+ OrientationChangedEmitters m_OrientationEmitters;
+ DPL::Mutex m_initializationMutex;
+ bool m_initialized;
+ bool m_isWatch;
+ std::vector<WatcherPtr> m_watchers;
+};
+
+}
+}
+
+#endif // WRTDEVICEAPIS_ORIENTATION_ORIENTATION_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(sensor REQUIRED sensor)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_ORIENTATION
+ ${sensor_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_ORIENTATION
+ ${sensor_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_ORIENTATION
+ ${CURRENT_PATH}/Orientation.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 PluginManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "PluginManager.h"
+#include <algorithm>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+#include <plugin_logic.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/Converter.h>
+#include <dpl/exception.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+
+using namespace std;
+
+namespace {
+const string GLOBAL_OBJECT_NAME = "GLOBAL_OBJECT";
+const char* SEPARATOR = ".";
+}
+
+namespace WrtDeviceApis {
+namespace PluginManager {
+
+
+PluginManager::PluginManager(int widgetHandle,
+ const string &objectUri,
+ JSContextRef context) :
+ m_widgetHandle(widgetHandle),
+ m_objectUri(GLOBAL_OBJECT_NAME),
+ m_context(context)
+{
+ m_objectUri.append(SEPARATOR).append(objectUri);
+ WrtDB::WrtDatabase::attachToThread();
+}
+
+PluginManager::~PluginManager()
+{
+ ObjectList::iterator it = m_objectList.begin();
+ for (; it != m_objectList.end(); ++it)
+ {
+ JSValueUnprotect(m_context, it->second);
+ }
+ WrtDB::WrtDatabase::detachFromThread();
+}
+
+bool PluginManager::hasChild(const string &name) const
+{
+ const PropertyList &prop = getProperties();
+ return prop.end() != find(prop.begin(), prop.end(), name);
+}
+
+bool PluginManager::loadChild(const string &name) const
+{
+ LogInfo("loading " << name);
+ string localUri = m_objectUri;
+ localUri.append(SEPARATOR).append(name);
+
+ WrtDB::DbPluginHandle handle =
+ WrtDB::PluginDAOReadOnly::getPluginHandleForImplementedObject(localUri);
+ if (handle == WrtDB::INVALID_PLUGIN_HANDLE) {
+ LogError("Plugin not found");
+ return false;
+ }
+
+ // Create dao
+ WrtDB::DbWidgetFeatureSet features;
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
+ features = dao.getFeaturesList();
+ }
+ Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
+ {
+ // Error while reading database - widget handle may
+ // be invalid or some data may be missing in database
+ LogError("Cannot get feature list");
+ return false;
+ }
+
+ FOREACH (it, features) {
+ if (it->pluginId == handle) {
+ PluginLogicSingleton::Instance().addSpecialFeatureToSession(*it);
+ return true;
+ }
+ }
+ LogError("Plugin not loaded");
+ return false;
+}
+
+JSValueRef PluginManager::getProperty(const string &name) const
+{
+ LogDebug("getProperty " << name);
+ ObjectList::const_iterator it = m_objectList.find(name);
+ if (it != m_objectList.end()) {
+ //return already set value
+ return it->second;
+ }
+
+ if (!loadChild(name)) {
+ ThrowMsg(Commons::PlatformException, "Cannot load plugin");
+ }
+
+ it = m_objectList.find(name);
+ if (it != m_objectList.end()) {
+ //return set value
+ return it->second;
+ }
+
+ ThrowMsg(Commons::PlatformException, "Cannot obtain property");
+}
+
+bool PluginManager::setProperty(const string &name,
+ JSValueRef value)
+{
+ LogDebug("setProperty " << name);
+ if (m_objectList.count(name) > 0) {
+ JSValueUnprotect(m_context, m_objectList[name]);
+ }
+ JSValueProtect(m_context, value);
+ m_objectList[name] = value;
+ return true;
+}
+
+bool PluginManager::deleteProperty(const string &name)
+{
+ if (m_objectList.count(name) > 0) {
+ LogDebug("deleteProperty " << name);
+ JSValueUnprotect(m_context, m_objectList[name]);
+ m_objectList.erase(name);
+ return true;
+ }
+ return false;
+}
+
+
+Api::IPluginManager::PropertyList PluginManager::getProperties() const
+{
+ if (!m_propertyCache.IsNull()) {
+ return *m_propertyCache;
+ }
+
+ m_propertyCache = PropertyList();
+
+ WrtDB::DbWidgetFeatureSet features;
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
+ features = dao.getFeaturesList();
+ }
+ Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
+ {
+ LogError("Cannot get feature list");
+ ReThrow(Commons::PlatformException);
+ }
+
+ string localUri = m_objectUri + SEPARATOR;
+ WrtDB::DbWidgetFeatureSet::const_iterator feature = features.begin();
+ for (; feature != features.end(); ++feature) {
+ WrtDB::ImplementedObjectsList implObjs =
+ WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
+ feature->pluginId);
+ FOREACH(it, implObjs) {
+ //check if implemented object stats with localUri
+ if (it->find(localUri) == 0) {
+ string property = *it;
+ //remove local uri that predicts property name.
+ property.erase(0, localUri.size());
+ //check if property has its own properties.
+ size_t pos = property.find(SEPARATOR);
+ if (pos != string::npos) {
+ //if so then remove them.
+ property.erase(pos);
+ }
+ m_propertyCache->push_back(property);
+ }
+ }
+ }
+ return *m_propertyCache;
+}
+
+void PluginManager::addPropertiesToList(
+ JSPropertyNameAccumulatorRef propertyNames) const
+{
+ PropertyList properties = getProperties();
+ CommonsJavaScript::Converter converter(m_context);
+ FOREACH(it, properties) {
+ JSStringRef name = converter.toJSStringRef(*it);
+ JSPropertyNameAccumulatorAddName(propertyNames, name);
+ JSStringRelease(name);
+ }
+
+}
+
+}
+}
--- /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 PluginManager.h
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_PLUGINMANAGER_PLUGINMANAGER_H_
+#define WRTDEVICEAPIS_PLUGINMANAGER_PLUGINMANAGER_H_
+
+#include <map>
+#include <string>
+#include <API/PluginManager/IPluginManager.h>
+#include <dpl/optional.h>
+
+namespace WrtDeviceApis {
+namespace PluginManager {
+
+class PluginManager : public Api::IPluginManager
+{
+public:
+ PluginManager(int widgetHandle,
+ const std::string &objectUri,
+ JSContextRef context);
+ ~PluginManager();
+ bool hasChild(const std::string &name) const;
+ bool loadChild(const std::string &name) const;
+
+ JSValueRef getProperty(const std::string &name) const;
+ bool setProperty(const std::string &name,
+ JSValueRef value);
+ bool deleteProperty(const std::string &name);
+
+ PropertyList getProperties() const;
+ void addPropertiesToList(JSPropertyNameAccumulatorRef propertyNames) const;
+
+private:
+ typedef std::map<std::string, JSValueRef> ObjectList;
+
+ int m_widgetHandle;
+ std::string m_objectUri;
+ mutable DPL::Optional<PropertyList> m_propertyCache;
+ ObjectList m_objectList;
+ JSContextRef m_context;
+};
+
+}
+}
+
+#endif
--- /dev/null
+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)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER
+ ${dpl-wrt-dao-ro_INCLUDE_DIRS}
+ ${wrt-plugin-loading_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER
+ ${dpl-wrt-dao-ro_LIBRARIES}
+ ${wrt-plugin-loading_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER
+ ${CURRENT_PATH}/PluginManager.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 Backlight.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @version 0.1
+ */
+
+#include <vconf.h>
+#include <pmapi.h>
+#include <dpl/scoped_ptr.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Commons/ThreadPool.h>
+#include "Backlight.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace WrtDeviceApis {
+namespace Power {
+
+Backlight::Backlight() :
+ EventLightOffTimerReqReceiver(ThreadEnum::POWER_THREAD),
+ EventLightReqReceiver(ThreadEnum::POWER_THREAD)
+{
+ // empty
+}
+
+Backlight::~Backlight()
+{
+ // empty
+}
+
+int Backlight::changeState(Power::Api::BacklightStatus state,
+ unsigned int timeout)
+{
+ LogInfo("Entered!!");
+ int result = -1;
+
+ LogDebug("state: " << state << ", timeout: " << timeout);
+ result = pm_change_state(toLCDState(state));
+ if (state == Power::Api::BACKLIGHT_NORMAL) {
+ EventLightOffTimerPtr lightOffTimerEvent =
+ EventLightOffTimerPtr(
+ new EventLightOffTimer());
+ lightOffTimerEvent->setForAsynchronousCall(NULL);
+ EventLightOffTimerReqReceiver::PostRequest(
+ lightOffTimerEvent,
+ timeout / 1000.0);
+ }
+
+ if (result < 0) {
+ LogDebug("[ERROR] return value result =" << result);
+ } else {
+ LogDebug("[SUCCESS]return value result =" << result);
+ }
+
+ return result;
+}
+
+void Backlight::changeState(const Power::Api::EventLightPtr& event)
+{
+ EventLightReqReceiver::PostRequest(event);
+}
+
+int Backlight::toLCDState(Power::Api::BacklightStatus state) const
+{
+ LogDebug("enter");
+ switch (state) {
+ case Power::Api::BACKLIGHT_DIM:
+ return LCD_DIM;
+ break;
+ case Power::Api::BACKLIGHT_NORMAL:
+ return LCD_NORMAL;
+ break;
+ case Power::Api::BACKLIGHT_OFF:
+ return LCD_OFF;
+ break;
+ default:
+ LogDebug("error status");
+ break;
+ }
+
+ return 0;
+}
+
+void Backlight::OnRequestReceived(const EventLightOffTimerPtr& /*event*/)
+{
+ LogInfo("LightOffTimer event is received!!");
+ pm_change_state(LCD_DIM);
+}
+
+void Backlight::OnRequestReceived(const Power::Api::EventLightPtr& event)
+{
+ LogInfo("Backlight event is received!!");
+ try
+ {
+ if (event == NULL) {
+ LogError("event is NULL!");
+ ThrowMsg(Commons::PlatformException, "Event is NULL!!");
+ }
+ LogDebug(
+ "Status: " << event->getStatus() << ", Duratin: " <<
+ event->getDuration());
+ if (changeState(event->getStatus(), event->getDuration()) < 0) {
+ LogError("changeState returned error!!");
+ ThrowMsg(Commons::PlatformException, "Play Beep is Failed!");
+ }
+ }
+ catch (Commons::PlatformException) {
+ LogError("platform exception");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+}
+} // Power
+} // 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 Backlight.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_POWER_BACK_LIGHT_H_
+#define WRTDEVICEAPIS_POWER_BACK_LIGHT_H_
+
+#include <map>
+#include <cstddef>
+#include <dpl/mutex.h>
+#include <Commons/EventReceiver.h>
+#include <Power/IBacklight.h>
+#include <Power/Enums.h>
+#include <VConf/Key.h>
+#include <Elementary.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+
+// Dummy event for asynchronous light on schedule
+class EventLightOffTimer : public Commons::IEvent<EventLightOffTimer>
+{
+};
+
+typedef DPL::SharedPtr<EventLightOffTimer> EventLightOffTimerPtr;
+typedef Commons::EventRequestReceiver<EventLightOffTimer>
+ EventLightOffTimerReqReceiver;
+typedef Commons::EventRequestReceiver<Api::EventLight> EventLightReqReceiver;
+
+class Backlight : public Api::IBacklight,
+ public EventLightOffTimerReqReceiver,
+ public EventLightReqReceiver
+{
+ private:
+ friend class Manager;
+
+ public:
+
+ explicit Backlight();
+ ~Backlight();
+
+ /**
+ * @see Api::IBacklight::changeState()
+ */
+ int changeState(Api::BacklightStatus state,
+ unsigned int timeout);
+
+ /**
+ * @see Api::IBacklight::changeState()
+ */
+ void changeState(const Api::EventLightPtr& event);
+
+ protected:
+ void OnRequestReceived(const EventLightOffTimerPtr& event);
+ void OnRequestReceived(const Api::EventLightPtr& event);
+
+ private:
+ int toLCDState(Api::BacklightStatus state) const;
+};
+typedef DPL::SharedPtr<Backlight> BacklightPtr;
+
+} // Power
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_POWER_BATTERY_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 <vconf.h>
+#include <Commons/Exception.h>
+#include <Power/EventCharging.h>
+#include <Power/EventRemaining.h>
+#include "Battery.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+
+Battery::Battery(std::size_t index) :
+ m_index(index),
+ m_onChargingKey(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW),
+ m_onRemainingKey(VCONFKEY_SYSMAN_BATTERY_LEVEL),
+ m_onLowKey(VCONFKEY_TELEPHONY_LOW_BATTERY)
+{
+}
+
+Battery::~Battery()
+{
+}
+
+bool Battery::isCharging() const
+{
+ Try {
+ return m_onChargingKey.getBool();
+ }
+ Catch(Commons::ConversionException) {
+ ReThrowMsg(Commons::PlatformException,
+ "Could not discover battery state.");
+ }
+}
+
+unsigned int Battery::getRemaining() const
+{
+ Try {
+ int level = m_onRemainingKey.getInt();
+ double ratio =
+ (level / static_cast<double>(VCONFKEY_SYSMAN_BAT_LEVEL_MAX));
+ return static_cast<unsigned int>(ratio * 100);
+ }
+ Catch(Commons::ConversionException) {
+ ReThrowMsg(Commons::PlatformException,
+ "Could not discover battery level.");
+ }
+}
+
+void Battery::addOnCharging(const Power::Api::EventChargingEmitterPtr& emitter)
+{
+ DPL::Mutex::ScopedLock lock(&m_onChargingMtx);
+ ChargingEventEmitters::iterator it = m_onCharging.find(emitter->getId());
+ if (it == m_onCharging.end()) {
+ if (m_onCharging.size() == 0) {
+ if (!m_onChargingKey.attachCallback(Battery::onCharging, this)) {
+ ThrowMsg(Commons::PlatformException,
+ "Could not set platform listener.");
+ }
+ }
+ m_onCharging.insert(ChargingEventEmitters::value_type(emitter->getId(),
+ emitter));
+ }
+}
+
+void Battery::removeOnCharging(Power::Api::EventChargingEmitter::IdType id)
+{
+ DPL::Mutex::ScopedLock lock(&m_onChargingMtx);
+ ChargingEventEmitters::iterator it = m_onCharging.find(id);
+ if (it != m_onCharging.end()) {
+ m_onCharging.erase(it);
+ if (m_onCharging.size() == 0) {
+ m_onChargingKey.detachCallback();
+ }
+ }
+}
+
+void Battery::addOnRemaining(
+ const Api::EventRemainingEmitterPtr& emitter)
+{
+ DPL::Mutex::ScopedLock lock(&m_onRemainingMtx);
+ RemainingEventEmitters::iterator it = m_onRemaining.find(emitter->getId());
+ if (it == m_onRemaining.end()) {
+ if (m_onRemaining.size() == 0) {
+ if (!m_onRemainingKey.attachCallback(Battery::onRemaining, this)) {
+ ThrowMsg(Commons::PlatformException,
+ "Could not set platform listener.");
+ }
+ }
+ m_onRemaining.insert(RemainingEventEmitters::value_type(emitter->getId(),
+ emitter));
+ }
+}
+
+void Battery::removeOnRemaining(Api::EventRemainingEmitter::IdType id)
+{
+ DPL::Mutex::ScopedLock lock(&m_onRemainingMtx);
+ RemainingEventEmitters::iterator it = m_onRemaining.find(id);
+ if (it != m_onRemaining.end()) {
+ m_onRemaining.erase(it);
+ if (m_onRemaining.size() == 0) {
+ m_onRemainingKey.detachCallback();
+ }
+ }
+}
+
+void Battery::addOnLow(const Api::EventLowEmitterPtr& emitter)
+{
+ DPL::Mutex::ScopedLock lock(&m_onLowMtx);
+ LowEventEmitters::iterator it = m_onLow.find(emitter->getId());
+ if (it == m_onLow.end()) {
+ if (m_onLow.size() == 0) {
+ if (!m_onLowKey.attachCallback(Battery::onLow, this)) {
+ ThrowMsg(Commons::PlatformException,
+ "Could not set platform listener.");
+ }
+ }
+ m_onLow.insert(LowEventEmitters::value_type(emitter->getId(), emitter));
+ }
+}
+
+void Battery::removeOnLow(Api::EventLowEmitter::IdType id)
+{
+ DPL::Mutex::ScopedLock lock(&m_onLowMtx);
+ LowEventEmitters::iterator it = m_onLow.find(id);
+ if (it != m_onLow.end()) {
+ m_onLow.erase(it);
+ if (m_onLow.size() == 0) {
+ m_onLowKey.detachCallback();
+ }
+ }
+}
+
+void Battery::onCharging(const VConf::Node* /* node */,
+ void* data)
+{
+ Battery* this_ = static_cast<Battery*>(data);
+ if (this_) {
+ Api::EventChargingPtr event(new Api::EventCharging());
+
+ DPL::Mutex::ScopedLock lock(&this_->m_onChargingMtx);
+ ChargingEventEmitters::iterator it = this_->m_onCharging.begin();
+ for (; it != this_->m_onCharging.end(); ++it) {
+ if (!!it->second) {
+ it->second->emit(event);
+ }
+ }
+ }
+}
+
+void Battery::onRemaining(const VConf::Node* /* node */,
+ void* data)
+{
+ Battery* this_ = static_cast<Battery*>(data);
+ if (this_) {
+ Api::EventRemainingPtr event(new Api::EventRemaining());
+ Try {
+ event->setResult(this_->getRemaining());
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+
+ DPL::Mutex::ScopedLock lock(&this_->m_onRemainingMtx);
+ RemainingEventEmitters::iterator it = this_->m_onRemaining.begin();
+ for (; it != this_->m_onRemaining.end(); ++it) {
+ if (!!it->second) {
+ it->second->emit(event);
+ }
+ }
+ }
+}
+
+void Battery::onLow(const VConf::Node* /* node */,
+ void* data)
+{
+ Battery* this_ = static_cast<Battery*>(data);
+ if (this_) {
+ Api::EventLowPtr event(new Api::EventLow());
+ Try {
+ event->setResult(this_->getRemaining());
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+
+ DPL::Mutex::ScopedLock lock(&this_->m_onLowMtx);
+ LowEventEmitters::iterator it = this_->m_onLow.begin();
+ for (; it != this_->m_onLow.end(); ++it) {
+ if (!!it->second) {
+ it->second->emit(event);
+ }
+ }
+ }
+}
+} // Power
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_BATTERY_H_
+#define WRTDEVICEAPIS_POWER_BATTERY_H_
+
+#include <map>
+#include <cstddef>
+#include <dpl/mutex.h>
+#include <Power/IBattery.h>
+#include <VConf/Key.h>
+
+namespace WrtDeviceApis {
+namespace Power {
+
+class Battery : public Api::IBattery
+{
+ private:
+ friend class Manager;
+
+ public:
+ ~Battery();
+
+ /**
+ * @see Api::Power::IBattery::isCharging()
+ */
+ bool isCharging() const;
+
+ /**
+ * @see Api::Power::IBattery::getRemaining()
+ */
+ unsigned int getRemaining() const;
+
+ /**
+ * @see Api::Power::IBattery::addOnCharging()
+ */
+ void addOnCharging(const Api::EventChargingEmitterPtr& emitter);
+
+ /**
+ * @see Api::Power::IBattery::removeOnCharing()
+ */
+ void removeOnCharging(Api::EventChargingEmitter::IdType id);
+
+ /**
+ * @see Api::Power::IBattery::addOnRemaining()
+ */
+ void addOnRemaining(const Api::EventRemainingEmitterPtr& emitter);
+
+ /**
+ * @see Api::Power::IBattery::removeOnRemaining()
+ */
+ void removeOnRemaining(Api::EventRemainingEmitter::IdType id);
+
+ /**
+ * @see Api::Power::IBattery::addOnLow()
+ */
+ void addOnLow(const Api::EventLowEmitterPtr& emitter);
+
+ /**
+ * @see Api::Power::IBattery::removeOnRemaining()
+ */
+ void removeOnLow(Api::EventLowEmitter::IdType id);
+
+ private:
+ typedef std::map<Api::EventChargingEmitter::IdType,
+ Api::EventChargingEmitterPtr> ChargingEventEmitters;
+
+ typedef std::map<Api::EventRemainingEmitter::IdType,
+ Api::EventRemainingEmitterPtr>
+ RemainingEventEmitters;
+
+ typedef std::map<Api::EventLowEmitter::IdType,
+ Api::EventLowEmitterPtr> LowEventEmitters;
+ private:
+ explicit Battery(std::size_t index);
+
+ /**
+ * Callback method called by platform when battery charging state changes.
+ * @param key Vconf key object.
+ * @param data User data.
+ */
+ static void onCharging(const VConf::Node* node,
+ void* data);
+
+ /**
+ * Callback method called by platform when battery power level changes.
+ * @param key Vconf key object.
+ * @param data User data.
+ */
+ static void onRemaining(const VConf::Node* key,
+ void* data);
+
+ /**
+ * Callback method called by platform when battery power level gets low.
+ * @param key Vconf key object.
+ * @param data User data.
+ */
+ static void onLow(const VConf::Node* key,
+ void* data);
+
+ private:
+ std::size_t m_index; ///< Index of battery this interface represents.
+ VConf::Key m_onChargingKey; ///< Wrapper for vconf on battery charging key.
+ VConf::Key m_onRemainingKey; ///< Wrapper for vconf on battery level key.
+ VConf::Key m_onLowKey; ///< Wrapper for vconf on battery low level state key.
+ ChargingEventEmitters m_onCharging; ///< Charging event emitters.
+ RemainingEventEmitters m_onRemaining; ///< Remaining event emitters.
+ LowEventEmitters m_onLow; ///< Low level event emitters.
+ DPL::Mutex m_onChargingMtx; ///< Mutex synchronizing operations on m_onCharging object.
+ DPL::Mutex m_onRemainingMtx; ///< Mutex synchronizing operations on m_onRemaining object.
+ DPL::Mutex m_onLowMtx; ///< Mutex synchronizing operations on m_onLow object.
+};
+
+} // Power
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_POWER_BATTERY_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 "Manager.h"
+#include <algorithm>
+#include <Commons/Exception.h>
+
+namespace {
+const std::size_t NUMBER_OF_AVAILABLE_BATTERIES = 1;
+const std::size_t NUMBER_OF_AVAILABLE_BACKLIGHT = 1;
+}
+
+namespace WrtDeviceApis {
+namespace Power {
+
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Manager::Manager()
+{
+ //m_backlight = new Backlight();
+}
+
+Manager::~Manager()
+{
+}
+
+void Manager::Release()
+{
+ LogDebug("entered");
+ Batteries::iterator it = m_batteries.begin();
+ for (; it != m_batteries.end(); ++it) {
+ //delete it->second;
+ }
+ if (m_batteries.size() > 0) {
+ m_batteries.clear();
+ }
+
+ if (NULL != m_backlight) {
+ //delete m_backlight;
+ //m_backlight = NULL;
+ }
+}
+
+Battery* Manager::getBattery(std::size_t index) const
+{
+ if (index > NUMBER_OF_AVAILABLE_BATTERIES) {
+ ThrowMsg(Commons::OutOfRangeException, "Battery not available.");
+ }
+
+ Batteries::iterator it = m_batteries.find(index);
+ if (it == m_batteries.end()) {
+ Battery* battery = new Battery(index);
+ m_batteries.insert(Batteries::value_type(index, battery));
+ return battery;
+ }
+ return it->second;
+}
+
+std::size_t Manager::getBatteriesCount() const
+{
+ return NUMBER_OF_AVAILABLE_BATTERIES;
+}
+
+Api::IBacklightPtr Manager::getBacklight(void)
+{
+ if (NULL == m_backlight) {
+ m_backlight = Api::IBacklightPtr(new Backlight());
+ }
+ return m_backlight;
+}
+
+std::size_t Manager::getBacklightCount() const
+{
+ return NUMBER_OF_AVAILABLE_BACKLIGHT;
+}
+} // Power
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_POWER_MANAGER_H_
+#define WRTDEVICEAPIS_POWER_MANAGER_H_
+
+#include <cstddef>
+#include <map>
+#include <Power/IManager.h>
+#include "Battery.h"
+#include "Backlight.h"
+
+namespace WrtDeviceApis {
+namespace Power {
+
+class Manager : public Api::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ ~Manager();
+
+ /**
+ * @see Api::Power::IManager::getBattery()
+ */
+ Battery* getBattery(std::size_t index) const;
+
+ /**
+ * @see Api::Power::IManager::getBatteriesCount()
+ */
+ std::size_t getBatteriesCount() const;
+
+ /**
+ * @see Api::Power::IManager::getBacklight()
+ */
+
+ Api::IBacklightPtr getBacklight(void);
+
+ /**
+ * @see Api::Power::IManager::getBacklightCount()
+ */
+
+ std::size_t getBacklightCount() const;
+
+ /**
+ * @ release singleton resource while singleton deconstructor is not invoked.
+ */
+ void Release();
+ protected:
+ typedef std::map<std::size_t, Battery*> Batteries;
+
+ protected:
+ Manager();
+
+ private:
+ mutable Batteries m_batteries;
+ Api::IBacklightPtr m_backlight;
+};
+
+} // Power
+} // WrtDeviceApis
+
+#endif /* WRTDEVICEAPIS_POWER_MANAGER_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(pmapi REQUIRED pmapi)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_POWER
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_VCONF}
+ ${pmapi_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_POWER
+ ${LIBS_PLATFORM_IMPLEMENTATION_VCONF}
+ ${pmapi_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_POWER
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/Battery.cpp
+ ${CURRENT_PATH}/Backlight.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 "Desktop.h"
+#include <Filesystem/Path.h>
+#include <vconf-keys.h>
+#include <Commons/Exception.h>
+#include <Filesystem/Manager.h>
+#include <Profile/IManager.h>
+
+namespace WrtDeviceApis {
+namespace Profile {
+
+Filesystem::Api::IPathPtr Desktop::getWallpaper() const
+{
+ // TODO: conversion...?
+ return Filesystem::Api::IPath::create(m_wallpaperKey.getString());
+}
+
+void Desktop::setWallpaper(const Filesystem::Api::IPathPtr& path)
+{
+ // TODO: probably we shouldn't expose full path
+ std::string p = path->getFullPath();
+ if (!Filesystem::Manager::fileExists(p)) {
+ LogError("Wallpaper not found. Path: " << p);
+ Throw(Commons::PlatformException);
+ }
+ m_wallpaperKey.setValue(p);
+}
+
+void Desktop::setWallpaper(const Api::EventSetWallpaperPtr& event)
+{
+ EventSetWallpaperReqReceiver::PostRequest(event);
+}
+
+void Desktop::OnRequestReceived(const Api::EventSetWallpaperPtr& event)
+{
+ Try
+ {
+ if (Api::IManager::getInstance().getDesktopCount() == 0) {
+ Throw(Commons::UnsupportedException);
+ }
+ Api::IDesktopPtr desktop = Api::IManager::getInstance().getDesktop(
+ IDesktop::DEFAULT);
+ if (!desktop) {
+ LogError("No default desktop.");
+ Throw(Commons::UnsupportedException);
+ }
+
+ desktop->setWallpaper(Filesystem::Api::IPath::create(event->getPathRef()));
+ }
+ Catch(Commons::PlatformException) {
+ LogError("platform exception");
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ Catch(Commons::UnsupportedException) {
+ LogError("unsupported exception");
+ event->setExceptionCode(Commons::ExceptionCodes::UnsupportedException);
+ }
+ Catch(Commons::InvalidArgumentException) {
+ LogError("invalid argument exception");
+ event->setExceptionCode(
+ Commons::ExceptionCodes::InvalidArgumentException);
+ }
+}
+
+Desktop::Desktop() : EventSetWallpaperReqReceiver(Commons::ThreadEnum::PROFILE_THREAD),
+ m_wallpaperKey(VCONFKEY_BGSET)
+{
+}
+} // Profile
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_DESKTOP_H_
+#define WRTDEVICEAPIS_PROFILE_DESKTOP_H_
+
+#include <API/Profile/IDesktop.h>
+#include <VConf/Key.h>
+
+namespace WrtDeviceApis {
+namespace Profile {
+typedef Commons::EventRequestReceiver< Profile::Api::EventSetWallpaper >
+EventSetWallpaperReqReceiver;
+
+class Manager;
+
+class Desktop : public Profile::Api::IDesktop,
+ public EventSetWallpaperReqReceiver
+{
+ friend class Manager;
+
+ public:
+ /**
+ * @see WrtPlugins::Profile::Api::IDesktop::getWallpaper()
+ */
+ Filesystem::Api::IPathPtr getWallpaper() const;
+
+ /**
+ * @see WrtPlugins::Profile::Api::IDesktop::setWallpaper()
+ */
+ void setWallpaper(const Filesystem::Api::IPathPtr& path);
+
+ /**
+ * @see WrtPlugins::Profile::Api::IDesktop::setWallpaper()
+ */
+ void setWallpaper(const Profile::Api::EventSetWallpaperPtr& event);
+
+ protected:
+ void OnRequestReceived(const Profile::Api::EventSetWallpaperPtr& event);
+
+ private:
+ Desktop();
+
+ private:
+ VConf::Key m_wallpaperKey;
+};
+typedef DPL::SharedPtr<Desktop> DesktopPtr;
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_DESKTOP_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 "Manager.h"
+#include <Commons/Exception.h>
+#include <vconf-keys.h>
+#include "Ringtone.h"
+#include "Desktop.h"
+
+#define __TEMP_OPTION_FOR_GET_CURRENT_VOLUME__ // We can't get current volume by VCONF. This option is temporary till VCONF is woring correctly.
+#if defined (__TEMP_OPTION_FOR_GET_CURRENT_VOLUME__)
+#include <mm_types.h>
+#include <mm_player.h>
+#include <mm_error.h>
+#include <mm_sound.h>
+#endif
+
+namespace {
+const std::size_t NUMBER_OF_AVAILABLE_DESKTOPS = 1;
+const std::size_t DEFAULT_DESKTOP_INDEX = 1;
+
+const WrtDeviceApis::Profile::Api::IManager::ProfileType profileMap[] = {
+ WrtDeviceApis::Profile::Api::IManager::NORMAL,
+ WrtDeviceApis::Profile::Api::IManager::SILENT,
+ WrtDeviceApis::Profile::Api::IManager::DRIVING,
+ WrtDeviceApis::Profile::Api::IManager::MEETING,
+ WrtDeviceApis::Profile::Api::IManager::OUTDOOR,
+ WrtDeviceApis::Profile::Api::IManager::FLIGHT
+};
+const size_t PROFILE_MAP_SIZE = sizeof(profileMap) / sizeof(profileMap[0]);
+} // anonymous
+
+namespace WrtDeviceApis {
+namespace Profile {
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Manager::~Manager()
+{
+}
+
+void Manager::Release() const
+{
+ LogDebug("Entered.");
+ Ringtones::iterator it1 = m_ringtones.begin();
+ for (; it1 != m_ringtones.end(); ++it1) {
+ delete it1->second;
+ }
+ if (m_ringtones.size() > 0) {
+ m_ringtones.clear();
+ }
+
+ Desktops::iterator it2 = m_desktops.begin();
+ for (; it2 != m_desktops.end(); ++it2) {
+ if (it2->second) {
+ //delete it2->second;
+ }
+ }
+ if (m_desktops.size() > 0) {
+ m_desktops.clear();
+ }
+}
+
+Profile::Api::IDesktopPtr Manager::getDesktop(std::size_t index) const
+{
+ if (index == Profile::Api::IDesktop::DEFAULT) {
+ index = DEFAULT_DESKTOP_INDEX;
+ }
+
+ if (index > NUMBER_OF_AVAILABLE_DESKTOPS) {
+ Throw(Commons::OutOfRangeException);
+ }
+
+ Desktops::const_iterator it = m_desktops.find(index);
+ if (it != m_desktops.end()) {
+ return it->second;
+ }
+ return (m_desktops[index] = Profile::Api::IDesktopPtr(new Desktop()));
+}
+
+std::size_t Manager::getDesktopCount() const
+{
+ return NUMBER_OF_AVAILABLE_DESKTOPS;
+}
+
+Profile::Api::IRingtone* Manager::getRingtone(Profile::Api::RingtoneScope scope)
+const
+{
+ switch (scope) {
+ case Profile::Api::RS_CALL:
+ return getRingtone_(Profile::Api::RS_CALL);
+ case Profile::Api::RS_SMS:
+ case Profile::Api::RS_MMS:
+ case Profile::Api::RS_EMAIL:
+ return getRingtone_(Profile::Api::RS_SMS);
+ default:
+ Throw(Commons::UnsupportedException);
+ }
+}
+
+Manager::Manager() :
+ m_profileKey(VCONFKEY_SETAPPL_CUR_PROFILE_INT),
+ m_volumeKey(VCONFKEY_SETAPPL_PROFILE_CURRENT_CALL_VOLUME_INT),
+ m_vibrationKey(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL)
+{
+}
+
+Profile::Api::IRingtone* Manager::getRingtone_(
+ Profile::Api::RingtoneScope scope) const
+{
+ Ringtones::const_iterator it = m_ringtones.find(scope);
+ if (it != m_ringtones.end()) {
+ return it->second;
+ }
+ return (m_ringtones[scope] = new Ringtone(scope));
+}
+
+Profile::Api::IManager::ProfileType Manager::getProfileType() const
+{
+ int profile = m_profileKey.getInt();
+ if (profile < 0 || profile >= static_cast<int>(PROFILE_MAP_SIZE)) {
+ Throw(Commons::OutOfRangeException);
+ }
+
+ return profileMap[profile];
+}
+
+int Manager::getSystemVolume() const
+{
+#if defined (__TEMP_OPTION_FOR_GET_CURRENT_VOLUME__)
+ unsigned int volume = 0;
+ int err = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &volume);
+ if (MM_ERROR_NONE != err) {
+ LogError("Can't get volume level. Error code: " << std::hex << err);
+ volume = 0;
+ }
+ return volume;
+#else
+ return m_volumeKey.getInt();
+#endif
+}
+
+int Manager::getVibrateType() const
+{
+ return m_vibrationKey.getBool();
+}
+} // Profile
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_MANAGER_H_
+#define WRTDEVICEAPIS_PROFILE_MANAGER_H_
+
+#include <map>
+#include <API/Profile/IManager.h>
+#include <VConf/Key.h>
+
+namespace WrtDeviceApis {
+namespace Profile {
+class Manager : public Profile::Api::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ ~Manager();
+
+ /**
+ * @ release singleton resource while singleton deconstructor is not invoked.
+ */
+ void Release() const;
+
+ /**
+ * @see WrtPlugins::Profile::Api::IManager::getDesktop()
+ */
+ Profile::Api::IDesktopPtr getDesktop(std::size_t index) const;
+
+ /**
+ * @see WrtPlugins::Profile::Api::IManager::getDesktopsCount()
+ */
+ std::size_t getDesktopCount() const;
+
+ /**
+ * @see WrtPlugins::Profile::Api::IManager::getRingtone()
+ */
+ Profile::Api::IRingtone* getRingtone(Profile::Api::RingtoneScope scope)
+ const;
+
+ /**
+ * @see WrtPlugins::Profile::Api::IManager::getProfileType()
+ */
+ Profile::Api::IManager::ProfileType getProfileType() const;
+
+ /**
+ * @see WrtPlugins::Profile::Api::IManager::getSystemVolume()
+ */
+ int getSystemVolume() const;
+
+ int getVibrateType() const;
+
+ // int getMsgAlertType() const;
+
+ private:
+ typedef std::map<Profile::Api::RingtoneScope,
+ Profile::Api::IRingtone*> Ringtones;
+ typedef std::map<std::size_t, Profile::Api::IDesktopPtr> Desktops;
+
+ private:
+ Manager();
+ Profile::Api::IRingtone* getRingtone_(Profile::Api::RingtoneScope scope)
+ const;
+
+ private:
+ mutable Ringtones m_ringtones;
+ mutable Desktops m_desktops;
+ VConf::Key m_profileKey;
+ VConf::Key m_volumeKey;
+ VConf::Key m_vibrationKey;
+};
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_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 "Ringtone.h"
+#include <vconf-keys.h>
+#include <Filesystem/Path.h>
+
+namespace {
+enum
+{
+ PLATFORM_VOLUME_LEVEL0 = 0,
+ PLATFORM_VOLUME_LEVEL1,
+ PLATFORM_VOLUME_LEVEL2,
+ PLATFORM_VOLUME_LEVEL3,
+ PLATFORM_VOLUME_LEVEL4,
+ PLATFORM_VOLUME_LEVEL5,
+ PLATFORM_VOLUME_LEVEL6,
+ PLATFORM_VOLUME_LEVEL7
+};
+} // anonymous
+
+namespace WrtDeviceApis {
+namespace Profile {
+Profile::Api::Volume Ringtone::getVolume() const
+{
+ double step = Profile::Api::VOLUME_MAX /
+ static_cast<double>(PLATFORM_VOLUME_LEVEL7);
+ Haptics::Api::Feedback level = Profile::Api::NO_VOLUME +
+ (step * m_volumeKey.getInt());
+ if (level > Profile::Api::VOLUME_MAX) {
+ level = Profile::Api::VOLUME_MAX;
+ }
+ return level;
+}
+
+void Ringtone::setVolume(Profile::Api::Volume level)
+{
+ if (level > Profile::Api::VOLUME_MAX) {
+ level = Profile::Api::VOLUME_MAX;
+ }
+
+ double step = Profile::Api::VOLUME_MAX /
+ static_cast<double>(PLATFORM_VOLUME_LEVEL7);
+ for (int i = PLATFORM_VOLUME_LEVEL0; i <= PLATFORM_VOLUME_LEVEL7; ++i) {
+ if (level <= (i * step)) {
+ m_volumeKey.setValue(i);
+ break;
+ }
+ }
+}
+
+Filesystem::Api::IPathPtr Ringtone::getAudio() const
+{
+ // TODO: probably not a full should be returned (maybe restricted to /mnt/ums)
+ return Filesystem::Api::IPath::create(m_audioKey.getString());
+}
+
+void Ringtone::setAudio(const Filesystem::Api::IPathPtr& path)
+{
+ // TODO: it should probably be converted some way
+ m_audioKey.setValue(path->getFullPath());
+}
+
+Haptics::Api::Feedback Ringtone::getHaptics() const
+{
+ double step = Haptics::Api::FEEDBACK_MAX /
+ static_cast<double>(SETTING_VIB_FEEDBACK_LEVEL5);
+ Haptics::Api::Feedback level = Haptics::Api::NO_FEEDBACK +
+ (step * m_hapticsKey.getInt());
+ if (level > Haptics::Api::FEEDBACK_MAX) {
+ level = Haptics::Api::FEEDBACK_MAX;
+ }
+ return level;
+}
+
+void Ringtone::setHaptics(Haptics::Api::Feedback level)
+{
+ if (level > Haptics::Api::FEEDBACK_MAX) {
+ level = Haptics::Api::FEEDBACK_MAX;
+ }
+
+ double step = Haptics::Api::FEEDBACK_MAX /
+ static_cast<double>(SETTING_VIB_FEEDBACK_LEVEL5);
+ for (int i = SETTING_VIB_FEEDBACK_LEVEL0;
+ i <= SETTING_VIB_FEEDBACK_LEVEL5;
+ ++i) {
+ if (level <= (i * step)) {
+ m_hapticsKey.setValue(i);
+ break;
+ }
+ }
+}
+
+Ringtone::Ringtone(Profile::Api::RingtoneScope scope) :
+ m_scope(scope)
+{
+ if (Profile::Api::RS_CALL == m_scope) {
+ m_volumeKey.reset(VCONFKEY_SETAPPL_PROFILE_CURRENT_CALL_VOLUME_INT);
+ m_hapticsKey.reset(VCONFKEY_SETAPPL_PROFILE_CURRENT_CALL_ALERT_VIB_INT);
+ m_audioKey.reset(VCONFKEY_SETAPPL_PROFILE_CURRENT_CALL_TONE_PATH_STR);
+ } else {
+ m_volumeKey.reset(VCONFKEY_SETAPPL_PROFILE_CURRENT_MSG_VOLUME_INT);
+ m_hapticsKey.reset(VCONFKEY_SETAPPL_PROFILE_CURRENT_MSG_ALERT_VIB_INT);
+ m_audioKey.reset(VCONFKEY_SETAPPL_PROFILE_CURRENT_MSG_TONE_PATH_STR);
+ }
+}
+} // Profile
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_PROFILE_RINGTONE_H_
+#define WRTDEVICEAPIS_PROFILE_RINGTONE_H_
+
+#include <API/Profile/Enums.h>
+#include <API/Profile/IRingtone.h>
+#include <VConf/Key.h>
+#include <API/Haptics/Types.h>
+
+namespace WrtDeviceApis {
+namespace Profile {
+class Manager;
+
+class Ringtone : public Profile::Api::IRingtone
+{
+ friend class Manager;
+
+ public:
+ /**
+ * @see WrtPlugins::IRingtone::Api::getVolume()
+ */
+ Profile::Api::Volume getVolume() const;
+
+ /**
+ * @see WrtPlugins::IRingtone::Api::setVolume()
+ */
+ void setVolume(Profile::Api::Volume level);
+
+ /**
+ * @see WrtPlugins::IRingtone::Api::getAudio()
+ */
+ Filesystem::Api::IPathPtr getAudio() const;
+
+ /**
+ * @see WrtPlugins::IRingtone::Api::setAudio()
+ */
+ void setAudio(const Filesystem::Api::IPathPtr& path);
+
+ /**
+ * @see WrtPlugins::IRingtone::Api::getHaptics()
+ */
+ Haptics::Api::Feedback getHaptics() const;
+
+ /**
+ * @see WrtPlugins::IRingtone::Api::setHaptics()
+ */
+ void setHaptics(Haptics::Api::Feedback level);
+
+ private:
+ explicit Ringtone(Profile::Api::RingtoneScope scope);
+
+ private:
+ Profile::Api::RingtoneScope m_scope;
+ VConf::Key m_volumeKey;
+ VConf::Key m_hapticsKey;
+ VConf::Key m_audioKey;
+};
+} // Profile
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_PROFILE_RINGTONE_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(mmsound REQUIRED mm-sound)
+pkg_search_module(mmplayer REQUIRED mm-player)
+#pkg_search_module(mmtypes REQUIRED mm-types)
+#pkg_search_module(mmerror REQUIRED mm-error)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_PROFILE
+ ${mmplayer_INCLUDE_DIRS}
+ ${mmsound_INCLUDE_DIRS}
+# ${mmerror_INCLUDE_DIRS}
+# ${mmtypes_INCLUDE_DIRS}
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_VCONF}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_PROFILE
+ ${mmplayer_LIBRARIES}
+ ${mmsound_LIBRARIES}
+# ${mmtypes_LIBRARIES}
+# ${mmerror_LIBRARIES}
+ ${LIBS_PLATFORM_IMPLEMENTATION_VCONF}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_PROFILE
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/Desktop.cpp
+ ${CURRENT_PATH}/Ringtone.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 Zbigniew Kostrzewa <z.kostrzewa@samsung.com>
+ */
+
+#include "Manager.h"
+#include <Commons/Exception.h>
+#include "Source.h"
+#include <tizen.h>
+#include <telephony_network_type.h>
+#include <telephony_network.h>
+#include <TapiCommon.h>
+#include <cstdlib>
+#include <dpl/log/log.h>
+
+namespace WrtDeviceApis {
+namespace Radio {
+Manager& Manager::getInstance()
+{
+ static Manager instance;
+ return instance;
+}
+
+Manager::~Manager()
+{
+ delete m_source;
+}
+
+bool Manager::isEnabled() const
+{
+ Try {
+ switch (m_serviceType.getInt()) {
+ case VCONFKEY_TELEPHONY_SVCTYPE_NONE:
+ case VCONFKEY_TELEPHONY_SVCTYPE_NOSVC:
+ case VCONFKEY_TELEPHONY_SVCTYPE_EMERGENCY:
+ case VCONFKEY_TELEPHONY_SVCTYPE_SEARCH:
+ return false;
+ case VCONFKEY_TELEPHONY_SVCTYPE_2G:
+ case VCONFKEY_TELEPHONY_SVCTYPE_2_5G:
+ case VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE:
+ case VCONFKEY_TELEPHONY_SVCTYPE_3G:
+ case VCONFKEY_TELEPHONY_SVCTYPE_HSDPA:
+ return true;
+ default:
+ return false;
+ }
+ }
+ Catch(Commons::ConversionException) {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+bool Manager::isRoaming() const
+{
+ Try {
+ return (m_roam.getInt() == VCONFKEY_TELEPHONY_SVC_ROAM_ON);
+ }
+ Catch(Commons::ConversionException) {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+Api::ISource* Manager::getSource() const
+{
+ return m_source;
+}
+
+Api::Strength Manager::getSignalStrength() const
+{
+ if (VCONFKEY_TELEPHONY_RSSI_6 == 0) {
+ ThrowMsg(Commons::PlatformException, "Division by zero.");
+ }
+ Try {
+ return 100 * m_rssi.getInt() /
+ static_cast<float>(VCONFKEY_TELEPHONY_RSSI_6);
+ }
+ Catch(Commons::ConversionException) {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+std::string Manager::getMcc() const
+{
+ char* mcc = NULL;
+
+ if (network_info_get_mcc(&mcc) == NETWORK_INFO_ERROR_NONE) {
+ LogDebug("Mobile Country Code : " << mcc);
+
+ std::string strMcc(mcc);
+ free(mcc);
+
+ return strMcc;
+ }
+
+ return "";
+}
+
+std::string Manager::getMnc() const
+{
+ char* mnc = NULL;
+
+ if (network_info_get_mnc(&mnc) == NETWORK_INFO_ERROR_NONE) {
+ LogDebug("Mobile Network Code : " << mnc);
+
+ std::string strMnc(mnc);
+ free(mnc);
+
+ return strMnc;
+ }
+
+ return "";
+}
+
+bool Manager::isHardwareOn() const
+{
+ int status = false;
+
+ if (tel_check_service_ready(&status) == TAPI_API_SUCCESS)
+ {
+ if(status) return true;
+ }
+
+ return false;
+}
+
+Manager::Manager() :
+ m_rssi(VCONFKEY_TELEPHONY_RSSI),
+ m_roam(VCONFKEY_TELEPHONY_SVC_ROAM),
+ m_serviceType(VCONFKEY_TELEPHONY_SVCTYPE),
+ m_source(new Source())
+{
+}
+} // Radio
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa <z.kostrzewa@samsung.com>
+ */
+
+#ifndef WRTDEVICEAPIS_RADIO_MANAGER_H_
+#define WRTDEVICEAPIS_RADIO_MANAGER_H_
+
+#include <Radio/IManager.h>
+#include <VConf/Key.h>
+
+namespace WrtDeviceApis {
+namespace Radio {
+class Manager : public Api::IManager
+{
+ public:
+ static Manager& getInstance();
+
+ public:
+ ~Manager();
+
+ /**
+ * @see Api::IManager::isEnabled()
+ */
+ bool isEnabled() const;
+
+ /**
+ * @see Api::IManager::isRoaming()
+ */
+ bool isRoaming() const;
+
+ /**
+ * @see Api::IManager::getSource()
+ */
+ Api::ISource* getSource() const;
+
+ /**
+ * @see Api::IManager::getSignalStrength()
+ */
+ Api::Strength getSignalStrength() const;
+
+ /**
+ * @see Api::IManager::getMcc()
+ */
+ std::string getMcc() const;
+
+ /**
+ * @see Api::IManager::getMnc()
+ */
+ std::string getMnc() const;
+
+ /**
+ * @see Api::IManager::isHardwareOn()
+ */
+ bool isHardwareOn() const;
+
+ protected:
+ Manager();
+
+ private:
+ VConf::Key m_rssi;
+ VConf::Key m_roam;
+ VConf::Key m_serviceType;
+ Api::ISource* m_source;
+};
+} // Radio
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_RADIO_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.
+ */
+/**
+ * @author Zbigniew Kostrzewa <z.kostrzewa@samsung.com>
+ */
+
+#include "Source.h"
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace Radio {
+bool Source::isConnected() const
+{
+ return (m_serviceType.getInt() > VCONFKEY_TELEPHONY_SVCTYPE_SEARCH);
+}
+
+Api::SourceType Source::getType() const
+{
+ Try {
+ switch (m_serviceType.getInt()) {
+ case VCONFKEY_TELEPHONY_SVCTYPE_2G:
+ case VCONFKEY_TELEPHONY_SVCTYPE_2_5G:
+ case VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE:
+ return Api::ST_GSM;
+ case VCONFKEY_TELEPHONY_SVCTYPE_3G:
+ case VCONFKEY_TELEPHONY_SVCTYPE_HSDPA:
+ return Api::ST_WCDMA;
+ default:
+ return Api::ST_UNKNOWN;
+ }
+ }
+ Catch(Commons::ConversionException) {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+void Source::addOnTypeChange(
+ const Api::EventSourceTypeChangeEmitterPtr& emitter)
+{
+ m_onSourceTypeChange.attach(emitter);
+ SourceTypeChangeEmitters::LockType lock = m_onSourceTypeChange.getLock();
+ if (m_onSourceTypeChange.size() == 1) {
+ m_serviceType.attachCallback(onTypeChange, this);
+ }
+}
+
+void Source::removeOnTypeChange(
+ Api::EventSourceTypeChangeEmitter::IdType id)
+{
+ m_onSourceTypeChange.detach(id);
+ SourceTypeChangeEmitters::LockType lock = m_onSourceTypeChange.getLock();
+ if (m_onSourceTypeChange.size() == 0) {
+ m_serviceType.detachCallback();
+ }
+}
+
+Source::Source() :
+ m_serviceType(VCONFKEY_TELEPHONY_SVCTYPE)
+{
+}
+
+void Source::onTypeChange(const VConf::Node* /* node */,
+ void* data)
+{
+ Source* this_ = static_cast<Source*>(data);
+ if (this_) {
+ Api::EventSourceTypeChangePtr event(
+ new Api::EventSourceTypeChange());
+ Try {
+ event->setType(this_->getType());
+ }
+ Catch(Commons::PlatformException) {
+ event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+ }
+ this_->m_onSourceTypeChange.emit(event);
+ }
+}
+} // Radio
+} // 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.
+ */
+/**
+ * @author Zbigniew Kostrzewa <z.kostrzewa@samsung.com>
+ */
+
+#ifndef WRTDEVICEAPIS_RADIO_SOURCE_H_
+#define WRTDEVICEAPIS_RADIO_SOURCE_H_
+
+#include <Radio/ISource.h>
+#include <Commons/Emitters.h>
+#include <VConf/Key.h>
+
+namespace WrtDeviceApis {
+namespace Radio {
+class Manager;
+
+class Source : public Api::ISource
+{
+ friend class Manager;
+
+ public:
+ /**
+ * @see WrtDeviceApis::Radio::Api::ISource::isConnected()
+ */
+ bool isConnected() const;
+
+ /**
+ * @see WrtDeviceApis::Radio::Api::ISource::getType()
+ */
+ Api::SourceType getType() const;
+
+ /**
+ * @see WrtDeviceApis::Radio::Api::ISource::addOnTypeChange()
+ */
+ void addOnTypeChange(
+ const Api::EventSourceTypeChangeEmitterPtr& emitter);
+
+ /**
+ * @see WrtDeviceApis::Radio::Api::ISource::removeOnTypeChange()
+ */
+ void removeOnTypeChange(Api::EventSourceTypeChangeEmitter::IdType id);
+
+ protected:
+ typedef Commons::Emitters<Api::EventSourceTypeChangeEmitter>
+ SourceTypeChangeEmitters;
+
+ protected:
+ Source();
+
+ private:
+ /**
+ * Callback method called by platform when service type changes.
+ * @param key Vconf key object.
+ * @param data User data.
+ */
+ static void onTypeChange(const VConf::Node* node,
+ void* data);
+
+ private:
+ VConf::Key m_serviceType;
+ SourceTypeChangeEmitters m_onSourceTypeChange;
+};
+} // Radio
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_RADIO_SOURCE_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(capi-telephony-network-info REQUIRED capi-telephony-network-info)
+pkg_search_module(tapi REQUIRED tapi)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_RADIO
+ ${INCLUDES_PLATFORM_IMPLEMENTATION_VCONF}
+ ${capi-telephony-network-info_INCLUDE_DIRS}
+ ${tapi_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_RADIO
+ ${LIBS_PLATFORM_IMPLEMENTATION_VCONF}
+ ${capi-telephony-network-info_LIBRARIES}
+ ${tapi_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_RADIO
+ ${CURRENT_PATH}/Manager.cpp
+ ${CURRENT_PATH}/Source.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 Taejeong Lee <taejeong.lee@samsung.com>
+ */
+
+#include "SystemInfo.h"
+#include <Commons/Exception.h>
+#include <cstdlib>
+
+extern "C" {
+#include <iniparser.h>
+#include <libintl.h>
+}
+
+#define DEVICE_INFO_PATH "/etc/info.ini"
+
+namespace WrtDeviceApis {
+namespace SystemInfo {
+SystemInfo& SystemInfo::getInstance()
+{
+ static SystemInfo instance;
+ return instance;
+}
+
+SystemInfo::~SystemInfo()
+{
+}
+
+SystemInfo::SystemInfo()
+{
+}
+
+string SystemInfo::getDeviceModelName()
+{
+ // copied from settings-beat package
+ char szBin[50];
+ char szEmul[50];
+
+ const char* szBinVer = NULL;
+
+ dictionary* dic = iniparser_load(DEVICE_INFO_PATH);
+ if (dic) {
+ szBinVer = (char*)iniparser_getstr(dic, "Version:Build");
+ if (szBinVer) {
+ char* str = strdup(szBinVer);
+ if (str) {
+ char* pPos = str;
+ while (*pPos++) {
+ if ('_' == *pPos)
+ *pPos = ' ';
+ }
+ sscanf(str, "%s %s", szBin, szEmul);
+ }
+ free(str);
+ }
+ }
+
+ if (dic) {
+ iniparser_freedict(dic);
+ dic = NULL;
+ }
+
+ if (!strncmp(szEmul, "emul", 4)) {
+ return string("SDK");
+ } else {
+ return string(string("GT-")+string(szBin));
+ }
+}
+
+string SystemInfo::getDeviceVersion()
+{
+ // copied from settings-beat package
+ string result;
+
+ dictionary* dic = iniparser_load(DEVICE_INFO_PATH);
+ if (dic == NULL) {
+ result = gettext("IDS_ST_HEADER_UNAVAILABLE");
+ } else {
+ char* szBinVer =
+ strdup((char*)iniparser_getstr(dic, "Version:Build"));
+ char* pPos = szBinVer;
+ while(*pPos++) {
+ if ('.' == *pPos) *pPos = '\0';
+ }
+
+ result = string("Tizen") +
+ string((char*)iniparser_getstr(dic, "Version:Major")) +
+ string(".") +
+ string((char*)iniparser_getstr(dic, "Version:Minor")) +
+ string(" (") + string(szBinVer) + string(")");
+
+ free(szBinVer);
+ }
+
+ if (dic) {
+ iniparser_freedict(dic);
+ dic = NULL;
+ }
+
+ return result;
+}
+
+} // SystemInfo
+} // 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.
+ */
+/**
+ * @author Taejeong Lee <taejeong.lee@samsung.com>
+ */
+
+#ifndef WRTDEVICEAPIS_SYSTEMINFO_H_
+#define WRTDEVICEAPIS_SYSTEMINFO_H_
+
+#include <SystemInfo/ISystemInfo.h>
+#include <string>
+
+using namespace std;
+
+namespace WrtDeviceApis {
+namespace SystemInfo {
+class SystemInfo : public Api::ISystemInfo
+{
+ public:
+ static SystemInfo& getInstance();
+
+ public:
+ ~SystemInfo();
+ string getDeviceModelName();
+ string getDeviceVersion();
+
+ protected:
+ SystemInfo();
+
+ private:
+};
+} // SystemInfo
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_SYSTEMINFO_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(iniparser REQUIRED iniparser)
+#pkg_search_module(appcore-efl REQUIRED appcore-efl)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_SYSTEMINFO
+ ${iniparser_INCLUDE_DIRS}
+ ${appcore-efl_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_SYSTEMINFO
+ ${iniparser_LIBRARIES}
+ ${appcore-efl_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_SYSTEMINFO
+ ${CURRENT_PATH}/SystemInfo.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 Task.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#include "Task.h"
+#include <dpl/scoped_ptr.h>
+#include <dpl/log/log.h>
+#include <calendar-svc-provider.h>
+#include <calendar-svc-errors.h>
+#include "TaskManager.h"
+
+namespace WrtDeviceApis {
+namespace Task {
+
+using namespace Api;
+
+Task::Task()
+{
+ LogDebug("entered");
+}
+
+Task::~Task()
+{
+ LogDebug("entered");
+}
+
+void Task::OnRequestReceived(const IEventAddTaskPtr &task)
+{
+ LogDebug("entered");
+ Try
+ {
+ if (!task->getTask()) {
+ ThrowMsg(Commons::NullPointerException, "task parameter is NULL");
+ }
+ if (task->getTask()->getId() != CalendarTask::UNDEFINED_TASK_ID) {
+ LogWarning("adding task that is already added");
+ task->getTask()->setId(CalendarTask::UNDEFINED_TASK_ID);
+ }
+ TaskWrapperPtr taskWrapper(new TaskWrapper(task->getTask()));
+ taskWrapper->convertAbstractTaskToPlatformTask();
+ if (task->checkCancelled()) {
+ task->setCancelAllowed(true);
+ task->setResult(true);
+ return;
+ }
+ taskWrapper->saveTask();
+ task->setResult(true);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during adding task" << ex.DumpToString());
+ task->setResult(false);
+ }
+ task->setCancelAllowed(false);
+}
+
+void Task::OnRequestReceived(const IEventDeleteTaskPtr &task)
+{
+ LogDebug("entered");
+ Try
+ {
+ if (!task->getTask()) {
+ ThrowMsg(Commons::NullPointerException, "task parameter is NULL");
+ }
+ if (task->getTask()->getId() == CalendarTask::UNDEFINED_TASK_ID) {
+ ThrowMsg(Commons::InvalidArgumentException,
+ "Cannot delete non-existing task.");
+ }
+ DPL::ScopedPtr<TaskWrapper> taskWrapper(new TaskWrapper(task->getTask()));
+ taskWrapper->convertAbstractTaskToPlatformTask();
+ if (task->checkCancelled()) {
+ task->setCancelAllowed(true);
+ task->setResult(true);
+ return;
+ }
+ taskWrapper->deleteTask();
+ task->setResult(true);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during deleting task " << ex.DumpToString());
+ task->setResult(false);
+ }
+ task->setCancelAllowed(false);
+}
+
+void Task::OnRequestReceived(const IEventUpdateTaskPtr &task)
+{
+ LogDebug("entered");
+ Try
+ {
+ if (!task->getTask()) {
+ ThrowMsg(Commons::NullPointerException, "task parameter is NULL");
+ }
+ if (task->getTask()->getId() == CalendarTask::UNDEFINED_TASK_ID) {
+ ThrowMsg(
+ Commons::InvalidArgumentException,
+ "Cannot update non-existing task. Task needs adding or ID is wrong");
+ }
+ TaskWrapperPtr taskWrapper(new TaskWrapper(task->getTask()));
+ taskWrapper->convertAbstractTaskToPlatformTask();
+ if (task->checkCancelled()) {
+ task->setCancelAllowed(true);
+ task->setResult(true);
+ return;
+ }
+ taskWrapper->saveTask();
+ task->setResult(true);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during updating task " << ex.DumpToString());
+ task->setResult(false);
+ }
+ task->setCancelAllowed(false);
+}
+
+void Task::OnRequestReceived(const IEventFindTasksPtr &task)
+{
+ LogDebug("entered");
+ const TaskFilterPtr &filter = task->getFilter();
+ cal_struct *platformTask = NULL;
+ cal_iter *iter = NULL;
+ int foundCnt = 0;
+ task->setResult(true);
+
+ try {
+ if (CAL_SUCCESS !=
+ calendar_svc_get_all(0, 0, CAL_STRUCT_TODO, &iter)) {
+ ThrowMsg(Commons::PlatformException, "Can't get all records");
+ }
+ //TODO: currently platform starts iteration with below function
+ // It's possible that current approach will change to be familiar with std iterators
+
+ while (CAL_SUCCESS == calendar_svc_iter_next(iter)) {
+ task->tryCancelled();
+ if (CAL_SUCCESS !=
+ calendar_svc_iter_get_info(iter, &platformTask)) {
+ ThrowMsg(Commons::PlatformException, "Can't get task info.");
+ }
+ //getting ID
+ int eventId = calendar_svc_struct_get_int(platformTask,
+ CAL_VALUE_INT_INDEX);
+ if (CAL_SUCCESS != calendar_svc_struct_free(&platformTask)) {
+ LogError("Can't free calendar task struct.");
+ }
+
+ TaskWrapperPtr taskWrapper(new TaskWrapper());
+ taskWrapper->loadTask(eventId);
+ if (!filter || taskWrapper->matchFilters(filter)) {
+ if (foundCnt >= task->getFirstTask() &&
+ (task->getLastTask() == -1 || foundCnt <=
+ task->getLastTask())) {
+ task->addTask(taskWrapper->getAbstractTask());
+ }
+ foundCnt++;
+ }
+ }
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Exception: " << ex.DumpToString());
+ task->setResult(false);
+ }
+ //According to example in calendar-svc-provider.h it's not needed to pass here
+ //iter set on first element
+ calendar_svc_iter_remove(&iter);
+ task->setCancelAllowed(true);
+}
+
+void Task::OnRequestReceived(const IEventCreateTaskPtr &task)
+{
+ LogDebug("entered");
+ Try
+ {
+ CalendarTaskPtr result(new CalendarTask());
+ task->setResult(result.Get() != NULL);
+ task->setTask(result);
+ }
+ catch (const Commons::Exception &ex)
+ {
+ LogError("Error during creating an task " << ex.DumpToString());
+ task->setResult(false);
+ }
+}
+}
+}
+
--- /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 Task.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_TASK_H_
+#define WRTDEVICEAPIS_TASK_TASK_H_
+
+#include <list>
+#include "Task/ITask.h"
+#include "TaskWrapper.h"
+
+namespace WrtDeviceApis {
+namespace Task {
+
+class Task : public Api::ITask
+{
+ public:
+ Task();
+ virtual ~Task();
+ protected:
+ virtual void OnRequestReceived(const Api::IEventAddTaskPtr &task);
+ virtual void OnRequestReceived(const Api::IEventDeleteTaskPtr &task);
+ virtual void OnRequestReceived(const Api::IEventUpdateTaskPtr &task);
+ virtual void OnRequestReceived(const Api::IEventFindTasksPtr &task);
+ virtual void OnRequestReceived(const Api::IEventCreateTaskPtr &task);
+};
+}
+}
+
+#endif // WRTDEVICEAPIS_TASK_TASK_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 TaskManager.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @author Wojciech Bielawski (w.bielawski@samsung.com)
+ * @version 0.1
+ */
+
+#include "TaskManager.h"
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <calendar-svc-provider.h>
+#include <calendar-svc-errors.h>
+
+namespace {
+const int ID_ALL_ACCOUNTS = 0;
+const int TASK_ID = 1;
+const char* SERVICE_PROVIDER_NAME = "phone";
+const char* TASK_NAME = "test";
+}
+
+namespace WrtDeviceApis {
+namespace Task {
+
+using namespace Api;
+
+int TaskManager::m_instanceCount = 0;
+
+TaskManager::TaskManager()
+{
+ LogDebug("entered");
+ /* wac platform doesn't support calendar manager.
+ * This implementation have to implement it on its own.
+ * One calendar have to be created and stored for further use.
+ */
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ if (m_instanceCount == 0) {
+ LogDebug("opening calendar DB");
+ if (CAL_SUCCESS != calendar_svc_connect()) {
+ ThrowMsg(Commons::PlatformException,
+ "Calendar DB initialization failed");
+ }
+ }
+ m_instanceCount++;
+}
+
+TaskManager::~TaskManager()
+{
+ LogDebug("entered");
+ DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+ m_instanceCount--;
+ if (m_instanceCount == 0) {
+ LogDebug("closing calendar DB");
+ if (CAL_SUCCESS != calendar_svc_close()) {
+ LogError("Calendar database not clearly closed.");
+ }
+ }
+}
+
+int TaskManager::getAccountId()
+{
+ return ID_ALL_ACCOUNTS;
+}
+
+const char *TaskManager::getServiceProviderName()
+{
+ return SERVICE_PROVIDER_NAME;
+}
+
+std::list<ITaskPtr> TaskManager::getTasksInternal()
+{
+ LogDebug("entered");
+ std::list<ITaskPtr> result;
+ ITaskPtr defaultTask(new Task());
+ defaultTask->setName(TASK_NAME);
+ defaultTask->setId(TASK_ID);
+ defaultTask->setAccountId(ID_ALL_ACCOUNTS);
+ defaultTask->setType(Task::DEVICE_TASK);
+ result.push_back(defaultTask);
+ return result;
+}
+
+void TaskManager::OnRequestReceived(const IEventGetTasksPtr &task)
+{
+ Try
+ {
+ const std::list<ITaskPtr> &result = getTasksInternal();
+ task->tryCancelled();
+ task->setResult(true);
+ std::list<ITaskPtr>::const_iterator it = result.begin(), end =
+ result.end();
+ for (; it != end; ++it) {
+ task->addTask(*it);
+ }
+ }
+ Catch(Commons::EventCancelledException)
+ {
+ //revert changes if any
+ }
+ task->setCancelAllowed(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 TaskManager.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_TASKMANAGER_H_
+#define WRTDEVICEAPIS_TASK_TASKMANAGER_H_
+
+#include <vector>
+#include <list>
+#include <dpl/mutex.h>
+#include <Task/ITaskManager.h>
+#include "Task.h"
+
+namespace WrtDeviceApis {
+namespace Task {
+
+class TaskManager : public Api::ITaskManager
+{
+ public:
+ TaskManager();
+ virtual ~TaskManager();
+ static int getAccountId();
+ static const char* getServiceProviderName();
+ protected:
+ std::list<Api::ITaskPtr> getTasksInternal();
+ virtual void OnRequestReceived(const Api::IEventGetTasksPtr &task);
+
+ private:
+ static int m_instanceCount;
+ DPL::Mutex m_constructorMutex;
+};
+
+}
+}
+
+#endif // WRTDEVICEAPIS_TASK_TASKMANAGER_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 TaskWrapper.cpp
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <string.h>
+#include "TaskWrapper.h"
+#include "Task.h"
+
+#define LOCAL_DEBUG_MODE 1
+
+namespace WrtDeviceApis {
+namespace Task {
+
+using namespace Api;
+
+TaskWrapper::TaskWrapper() :
+ m_platformTask(NULL),
+ m_abstractTask(NULL)
+{
+ LogDebug("entered");
+ m_abstractTask = CalendarTaskPtr(new CalendarTask());
+ if (!m_abstractTask) {
+ ThrowMsg(Commons::UnknownException, "abstract object is not created");
+ }
+}
+
+TaskWrapper::TaskWrapper(const CalendarTaskPtr &task) :
+ m_platformTask(NULL),
+ m_abstractTask(task)
+{
+ LogDebug("entered");
+}
+
+TaskWrapper::~TaskWrapper()
+{
+ LogDebug("entered");
+ freePlatformTask();
+}
+
+int TaskWrapper::getIDFromPlatformTask() const
+{
+ LogDebug("Entered");
+ if (m_platformTask == NULL) {
+ ThrowMsg(Commons::NullPointerException, "m_platformTask is not set");
+ }
+
+ return calendar_svc_struct_get_int(m_platformTask, CAL_VALUE_INT_INDEX);
+}
+
+int TaskWrapper::getStatusFromPlatformTask() const
+{
+ LogDebug("Entered");
+ if (m_platformTask == NULL) {
+ ThrowMsg(Commons::NullPointerException, "m_platformTask is not set");
+ }
+
+ return calendar_svc_struct_get_int(m_platformTask,
+ CAL_VALUE_INT_TASK_STATUS);
+}
+
+int TaskWrapper::getPriorityFromPlatformTask() const
+{
+ LogDebug("Entered");
+ if (m_platformTask == NULL) {
+ ThrowMsg(Commons::NullPointerException, "m_platformTask is not set");
+ }
+
+ return calendar_svc_struct_get_int(m_platformTask, CAL_VALUE_INT_PRIORITY);
+}
+void TaskWrapper::saveTask()
+{
+ LogDebug("entered");
+ //Check if platform struct is set.
+ //It could be set here, but forcing user to do it manually can help to avoid problems.
+ if (m_platformTask == NULL) {
+ ThrowMsg(Commons::NullPointerException, "m_platformTask is not set");
+ }
+
+ int taskID = getIDFromPlatformTask();
+ LogDebug("taskID: " << taskID);
+ bool newEvent = (taskID == CalendarTask::UNDEFINED_TASK_ID);
+
+ displayPlatformTask();
+
+ //insert new record or update existing one
+ if (newEvent) { //insert new task
+ int returnValue = calendar_svc_insert(m_platformTask);
+ if (CAL_SUCCESS > returnValue) {
+ LogError("Can't insert new task, error code: " << returnValue);
+ ThrowMsg(Commons::PlatformException, "Can't insert new task.");
+ }
+ m_abstractTask->setId(returnValue);
+ LogInfo("New calendar task inserted");
+ } else { //update
+ if (CAL_SUCCESS != calendar_svc_update(m_platformTask)) {
+ ThrowMsg(Commons::PlatformException, "Can't update new task.");
+ }
+ LogDebug("Calendar task updated");
+ }
+}
+
+void TaskWrapper::loadTask(int id)
+{
+ LogDebug("Entered. ID of task to load: " << id);
+ freePlatformTask();
+ int errorCode = calendar_svc_get(CAL_STRUCT_TODO, id, NULL, &m_platformTask);
+ if (CAL_SUCCESS > errorCode) {
+ LogError(
+ "Can't get task with ID = " << id << ", error code: " <<
+ errorCode);
+ ThrowMsg(
+ Commons::PlatformException,
+ "Can't get task with ID = " << id << ", error code: " <<
+ errorCode);
+ }
+ convertPlatformTaskToAbstractTask();
+ displayAbstractTask();
+}
+
+bool TaskWrapper::matchFilters(TaskFilterPtr filter)
+{
+ LogDebug("Entered");
+ if (!filter) {
+ return true;
+ }
+ if (!m_abstractTask) {
+ ThrowMsg(Commons::NullPointerException,
+ "abstractEvent object is not set");
+ }
+
+ LogDebug("---new task to match---");
+ m_abstractTask->display();
+
+ if (filter->getIdIsSet()) {
+ if (m_abstractTask->getId() != filter->getIdFilter()) {
+#ifdef LOCAL_DEBUG_MODE
+ LogDebug("rejected by id " << filter->getIdFilter());
+#endif
+ return false;
+ }
+ }
+ if (filter->getTaskIdIsSet()) {
+ if (m_abstractTask->getTaskId() != filter->getTaskIdFilter()) {
+#ifdef LOCAL_DEBUG_MODE
+ LogDebug("rejected by calendar id " << filter->getTaskIdFilter());
+#endif
+ return false;
+ }
+ }
+ if (filter->getDescriptionIsSet()) {
+ if (!pcrecpp::RE(filter->getDescriptionFilter()).FullMatch(
+ m_abstractTask->getDescription())) {
+#ifdef LOCAL_DEBUG_MODE
+ LogDebug("rejected by description " << filter->getDescriptionFilter());
+#endif
+ return false;
+ }
+ }
+ if (filter->getSubjectIsSet()) {
+ if (!pcrecpp::RE(filter->getSubjectFilter()).FullMatch(m_abstractTask->
+ getSubject()))
+ {
+#ifdef LOCAL_DEBUG_MODE
+ LogDebug("rejected by subject " << filter->getSubjectFilter());
+#endif
+ return false;
+ }
+ }
+ if (filter->getDueDateIsSet()) {
+ if ((m_abstractTask->getDueDateIsSet() == false) ||
+ (filter->getDueDateMinFilter() != -1 &&
+ m_abstractTask->getDueDate() < filter->getDueDateMinFilter()) ||
+ (filter->getDueDateMaxFilter() != -1 &&
+ m_abstractTask->getDueDate() > filter->getDueDateMaxFilter())) {
+#ifdef LOCAL_DEBUG_MODE
+ LogDebug(
+ "rejected by start time min " << filter->getDueDateMinFilter());
+ LogDebug(
+ "rejected by start time max " << filter->getDueDateMaxFilter());
+ LogDebug("due date " << m_abstractTask->getDueDate());
+#endif
+ return false;
+ }
+ }
+
+ if (filter->getStatusIsSet()) {
+ StatusList statusList = *(filter->getStatusFilter());
+ StatusList::const_iterator it = statusList.begin(), end =
+ statusList.end();
+ for (; it != end; ++it) {
+ if (m_abstractTask->getStatus() == *it) {
+ break;
+ }
+ }
+ if (it == end) {
+#ifdef LOCAL_DEBUG_MODE
+ LogDebug("rejected by status ");
+#endif
+ return false;
+ }
+ }
+
+ if (filter->getPriorityIsSet()) {
+ PriorityList priorityList = *(filter->getPriorityFilter());
+ PriorityList::const_iterator it = priorityList.begin(), end =
+ priorityList.end();
+ for (; it != end; ++it) {
+ if (m_abstractTask->getPriority() == *it) {
+ break;
+ }
+ }
+ if (it == end) {
+#ifdef LOCAL_DEBUG_MODE
+ LogDebug("rejected by priority ");
+#endif
+ return false;
+ }
+ }
+ /*
+ if (filter->getPriorityIsSet()) {
+ if (m_abstractTask->getPriority() != filter->getPriorityFilter()) {
+ #ifdef LOCAL_DEBUG_MODE
+ LogDebug("rejected by priority " << filter->getPriorityFilter() );
+ #endif
+ return false;
+ }
+ }
+ */
+ return true;
+}
+
+void TaskWrapper::deleteTask()
+{
+ LogDebug("entered");
+ if (m_platformTask == NULL) {
+ ThrowMsg(Commons::NullPointerException,
+ "Failed to delete task in calendar (m_platformTask==NULL)");
+ }
+ int taskID = getIDFromPlatformTask();
+ LogDebug("taskID: " << taskID);
+ if (taskID == CalendarTask::UNDEFINED_TASK_ID) {
+ ThrowMsg(
+ Commons::InvalidArgumentException,
+ "Failed to delete task in calendar (task is not saved in calendar)");
+ }
+ if (CAL_SUCCESS != calendar_svc_delete(CAL_STRUCT_TODO, taskID)) {
+ ThrowMsg(Commons::PlatformException, "Can't delete calendar task.");
+ }
+
+ m_abstractTask->setId(CalendarTask::UNDEFINED_TASK_ID);
+ setIDToPlatformTask();
+}
+
+cal_struct *TaskWrapper::getPlatformTask() const
+{
+ return m_platformTask;
+}
+
+CalendarTaskPtr TaskWrapper::getAbstractTask() const
+{
+ return m_abstractTask;
+}
+
+void TaskWrapper::freePlatformTask()
+{
+ LogDebug("entered");
+ if (m_platformTask != NULL) {
+ if (CAL_SUCCESS != calendar_svc_struct_free(&m_platformTask)) {
+ LogError("Can't free calendar task struct.");
+ }
+ m_platformTask = NULL;
+ }
+}
+
+cal_struct *TaskWrapper::convertAbstractTaskToPlatformTask()
+{
+ LogDebug("entered");
+ freePlatformTask();
+ m_platformTask = calendar_svc_struct_new(CAL_STRUCT_TODO);
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "cannot create platform task");
+ }
+ setDescriptionToPlatformTask();
+ setSubjectToPlatformTask();
+ setDueDateToPlatformTask();
+ setStatusToPlatformTask();
+ setPriorityToPlatformTask();
+ setIDToPlatformTask();
+ return getPlatformTask();
+}
+
+void TaskWrapper::setDescriptionToPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformTask,
+ CAL_VALUE_TXT_DESCRIPTION,
+ m_abstractTask->
+ getDescription().c_str()))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set task description.");
+ }
+}
+
+void TaskWrapper::setSubjectToPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_str(m_platformTask,
+ CAL_VALUE_TXT_SUMMARY,
+ m_abstractTask->getSubject()
+ .c_str())) {
+ ThrowMsg(Commons::PlatformException, "Can't set task subject.");
+ }
+}
+
+void TaskWrapper::setDueDateToPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+
+ if (m_abstractTask->getDueDateIsSet() == true) {
+ time_t time = m_abstractTask->getDueDate();
+
+ if (CAL_SUCCESS != calendar_svc_struct_set_time(m_platformTask,
+ CAL_VALUE_GMT_END_DATE_TIME,
+ CAL_TZ_FLAG_GMT,
+ time)) {
+ ThrowMsg(Commons::PlatformException, "Can't set task due time.");
+ }
+ if (CAL_SUCCESS != calendar_svc_struct_set_time(m_platformTask,
+ CAL_VALUE_GMT_START_DATE_TIME,
+ CAL_TZ_FLAG_GMT,
+ time)) {
+ ThrowMsg(Commons::PlatformException, "Can't set task due time.");
+ }
+ }
+}
+
+void TaskWrapper::setStatusToPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformTask,
+ CAL_VALUE_INT_TASK_STATUS,
+ m_abstractTask->getStatus()))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set task Status.");
+ }
+}
+void TaskWrapper::setPriorityToPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformTask,
+ CAL_VALUE_INT_PRIORITY,
+ m_abstractTask->getPriority()))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set task Priority.");
+ }
+}
+
+void TaskWrapper::setIDToPlatformTask()
+{
+ if (m_abstractTask->getIdIsSet()) {
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformTask,
+ CAL_VALUE_INT_INDEX,
+ m_abstractTask->getId()))
+ {
+ ThrowMsg(Commons::PlatformException, "Can't set task ID.");
+ }
+ }
+}
+
+CalendarTaskPtr TaskWrapper::convertPlatformTaskToAbstractTask()
+{
+ LogDebug("entered");
+ setDescriptionFromPlatformTask();
+ setSubjectFromPlatformTask();
+ setDueDateFromPlatformTask();
+ setStatusFromPlatformTask();
+ setPriorityFromPlatformTask();
+ setIDFromPlatformTask();
+ return getAbstractTask();
+}
+
+void TaskWrapper::setDescriptionFromPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ const char *description = calendar_svc_struct_get_str(
+ m_platformTask,
+ CAL_VALUE_TXT_DESCRIPTION);
+ if (description) {
+ m_abstractTask->setDescription(description);
+ }
+}
+
+void TaskWrapper::setSubjectFromPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ const char *summary = calendar_svc_struct_get_str(m_platformTask,
+ CAL_VALUE_TXT_SUMMARY);
+ if (summary) {
+ m_abstractTask->setSubject(summary);
+ }
+}
+
+void TaskWrapper::setDueDateFromPlatformTask()
+{
+ if (!m_platformTask) {
+ ThrowMsg(Commons::UnknownException, "Null platform pointer.");
+ }
+ time_t dueDate = calendar_svc_struct_get_time(m_platformTask,
+ CAL_VALUE_GMT_END_DATE_TIME,
+ CAL_TZ_FLAG_GMT);
+
+ struct tm *tminfo = localtime(&dueDate);
+ if (tminfo->tm_year != PLATFORM_UNSUPPORTED_DATE_YEAR) {
+ m_abstractTask->setDueDate(dueDate);
+ }
+}
+
+void TaskWrapper::setStatusFromPlatformTask()
+{
+ m_abstractTask->setStatus(
+ (CalendarTask::TaskStatus)getStatusFromPlatformTask());
+}
+void TaskWrapper::setPriorityFromPlatformTask()
+{
+ m_abstractTask->setPriority(
+ (CalendarTask::TaskPriority)getPriorityFromPlatformTask());
+}
+
+void TaskWrapper::setIDFromPlatformTask()
+{
+ m_abstractTask->setId(getIDFromPlatformTask());
+}
+
+void TaskWrapper::displayAbstractTask()
+{
+ m_abstractTask->display();
+}
+
+void TaskWrapper::displayPlatformTask()
+{
+ LogDebug("task id: " <<
+ calendar_svc_struct_get_int(m_platformTask, CAL_VALUE_INT_INDEX));
+ LogDebug("task due time: " <<
+ calendar_svc_struct_get_time(m_platformTask,
+ CAL_VALUE_GMT_END_DATE_TIME,
+ CAL_TZ_FLAG_GMT));
+ LogDebug("task summary: " <<
+ calendar_svc_struct_get_str(m_platformTask, CAL_VALUE_TXT_SUMMARY));
+ LogDebug("task description: " <<
+ calendar_svc_struct_get_str(m_platformTask,
+ CAL_VALUE_TXT_DESCRIPTION));
+ LogDebug("task priority: " <<
+ calendar_svc_struct_get_str(m_platformTask, CAL_VALUE_INT_PRIORITY));
+ LogDebug("task status: " <<
+ calendar_svc_struct_get_str(m_platformTask,
+ CAL_VALUE_INT_TASK_STATUS));
+}
+}
+}
--- /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 TaskWrapper.h
+ * @author Shi Hezhang (hezhang.shi@samsung.com)
+ * @author Pan Rui (r.pan@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef WRTDEVICEAPIS_TASK_TASK_WRAPPER_H_
+#define WRTDEVICEAPIS_TASK_TASK_WRAPPER_H_
+
+#include <string>
+#include <calendar-svc-provider.h>
+#include <calendar-svc-errors.h>
+#include <dpl/shared_ptr.h>
+#include <Task/CalendarTask.h>
+#include <Task/TaskFilter.h>
+
+namespace WrtDeviceApis {
+namespace Task {
+
+const int PLATFORM_UNSUPPORTED_DATE_YEAR = 69;
+
+class TaskWrapper
+{
+ public:
+ TaskWrapper();
+ explicit TaskWrapper(const Api::CalendarTaskPtr &task);
+ virtual ~TaskWrapper();
+ cal_struct *convertAbstractTaskToPlatformTask();
+ Api::CalendarTaskPtr convertPlatformTaskToAbstractTask();
+ cal_struct *getPlatformTask() const;
+ Api::CalendarTaskPtr getAbstractTask() const;
+ void freePlatformTask();
+ void saveTask();
+ void loadTask(int id);
+ void deleteTask();
+ bool matchFilters(Api::TaskFilterPtr filter);
+
+ protected:
+ int getIDFromPlatformTask() const;
+ int getStatusFromPlatformTask() const;
+ int getPriorityFromPlatformTask() const;
+
+ void setDescriptionToPlatformTask();
+ void setSubjectToPlatformTask();
+ void setDueDateToPlatformTask();
+ void setStatusToPlatformTask();
+ void setPriorityToPlatformTask();
+ void setIDToPlatformTask();
+
+ void setDescriptionFromPlatformTask();
+ void setSubjectFromPlatformTask();
+ void setDueDateFromPlatformTask();
+ void setStatusFromPlatformTask();
+ void setPriorityFromPlatformTask();
+ void setIDFromPlatformTask();
+ private:
+ //temporaty solution to cover plafrorm bug
+ //int calendar_svc_struct_set_int(cal_struct* record, const char* field, int intval);
+
+ void displayAbstractTask(); //only for debugging
+ void displayPlatformTask(); //only for debugging
+
+ cal_struct *m_platformTask;
+ Api::CalendarTaskPtr m_abstractTask;
+};
+
+typedef DPL::SharedPtr<TaskWrapper> TaskWrapperPtr;
+}
+}
+#endif // WRTDEVICEAPIS_TASK_TASK_WRAPPER_H_
--- /dev/null
+get_current_path()
+
+pkg_search_module(calendar REQUIRED calendar)
+pkg_search_module(glib REQUIRED glib-2.0)
+pkg_search_module(libpcrecpp REQUIRED libpcrecpp)
+
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_TASK
+ ${calendar_INCLUDE_DIRS}
+ ${glib_INCLUDE_DIRS}
+ ${libpcrecpp_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_TASK
+ ${calendar_LIBRARIES}
+ ${glib_LIBRARIES}
+ ${libpcrecpp_LIBRARIES}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_TASK
+ ${CURRENT_PATH}/Task.cpp
+ ${CURRENT_PATH}/TaskManager.cpp
+ ${CURRENT_PATH}/TaskWrapper.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 "Key.h"
+#include <cassert>
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace VConf {
+Key::Key(const char* name) :
+ m_callback(NULL),
+ m_callbackData(NULL)
+{
+ if (name != NULL) {
+ m_name = name;
+ }
+}
+
+Key::~Key()
+{
+ detachCallback();
+}
+
+bool Key::attachCallback(KeyChangeCallback callback,
+ void* data)
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ if (!callback) {
+ return false;
+ }
+
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ bool firstTime = (m_callback == NULL);
+ m_callback = callback;
+ m_callbackData = data;
+
+ if (firstTime) {
+ if (vconf_notify_key_changed(m_name.c_str(), Key::callback,
+ this) != 0) {
+ m_callback = NULL;
+ m_callbackData = NULL;
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void Key::detachCallback()
+{
+ DPL::Mutex::ScopedLock lock(&m_mtx);
+ if (m_callback) {
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ vconf_ignore_key_changed(m_name.c_str(), Key::callback);
+ m_callback = NULL;
+ m_callbackData = NULL;
+ }
+}
+
+void Key::callback(keynode_t* node,
+ void* data)
+{
+ Key* this_ = static_cast<Key*>(data);
+ if (this_) {
+ DPL::Mutex::ScopedLock lock(&this_->m_mtx);
+ if (this_->m_callback) {
+ NodePtr ptr(new Node(node));
+ (*this_->m_callback)(ptr.Get(), this_->m_callbackData);
+ }
+ }
+}
+
+bool Key::getBool() const
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ int result = 0;
+ if (vconf_get_bool(m_name.c_str(), &result) != 0) {
+ Throw(Commons::ConversionException);
+ }
+ return (result != 0);
+}
+
+void Key::setValue(bool value)
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ if (vconf_set_bool(m_name.c_str(), value) != 0) {
+ Throw(Commons::PlatformException);
+ }
+}
+
+int Key::getInt() const
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ int result = 0;
+ if (vconf_get_int(m_name.c_str(), &result) != 0) {
+ Throw(Commons::ConversionException);
+ }
+ return result;
+}
+
+void Key::setValue(int value)
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ if (vconf_set_int(m_name.c_str(), value) != 0) {
+ Throw(Commons::PlatformException);
+ }
+}
+
+double Key::getDouble() const
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ double result = 0;
+ if (vconf_get_dbl(m_name.c_str(), &result) != 0) {
+ Throw(Commons::ConversionException);
+ }
+ return result;
+}
+
+void Key::setValue(double value)
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ if (vconf_set_dbl(m_name.c_str(), value) != 0) {
+ Throw(Commons::PlatformException);
+ }
+}
+
+std::string Key::getString() const
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ char* result = vconf_get_str(m_name.c_str());
+ if (result == NULL) {
+ Throw(Commons::ConversionException);
+ }
+ return result;
+}
+
+void Key::setValue(const std::string& value)
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ setValue(value.c_str());
+}
+
+void Key::setValue(const char* value)
+{
+ assert(!m_name.empty() && "Key name cannot be empty.");
+ if (vconf_set_str(m_name.c_str(), value) != 0) {
+ Throw(Commons::PlatformException);
+ }
+}
+
+void Key::reset(const char* name)
+{
+ detachCallback();
+ m_name = (name == NULL ? std::string() : name);
+}
+} // VConf
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_VCONFKEY_H_
+#define WRTDEVICEAPIS_VCONFKEY_H_
+
+#include <string>
+#include <vconf.h>
+#include <dpl/noncopyable.h>
+#include <dpl/mutex.h>
+#include "Node.h"
+
+namespace WrtDeviceApis {
+namespace VConf {
+typedef void (*KeyChangeCallback)(const Node*, void*);
+
+class Key : private DPL::Noncopyable
+{
+ public:
+ /**
+ * Creates vconf key wrapper.
+ * @param name Key name or NULL (default).
+ */
+ explicit Key(const char* name = NULL);
+
+ ~Key();
+
+ /**
+ * Gets boolean value.
+ * @return Value of the key.
+ * @throw ConversionException If unable to get value.
+ */
+ bool getBool() const;
+
+ /**
+ * Sets boolean value for this key.
+ * @param value Value to set.
+ * @throw PlatformException If unable to perform the request.
+ */
+ void setValue(bool value);
+
+ /**
+ * Gets integer value.
+ * @return Value of the key.
+ * @throw ConversionException If unable to get value.
+ */
+ int getInt() const;
+
+ /**
+ * Sets integer value for this key.
+ * @param value Value to set.
+ * @throw PlatformException If unable to perform the request.
+ */
+ void setValue(int value);
+
+ /**
+ * Gets double value.
+ * @return Value of the key.
+ * @throw ConversionException If unable to get value.
+ */
+ double getDouble() const;
+
+ /**
+ * Sets double value for this key.
+ * @param value Value to set.
+ * @throw PlatformException If unable to perform the request.
+ */
+ void setValue(double value);
+
+ /**
+ * Gets string value.
+ * @return Value of the key.
+ * @throw ConversionException If unable to get value.
+ */
+ std::string getString() const;
+
+ /**
+ * Sets string value for this key.
+ * @param value Value to set.
+ * @throw PlatformException If unable to perform the request.
+ */
+ void setValue(const std::string& value);
+
+ /**
+ * Sets c-string value for this key.
+ * @param value Value to set.
+ * @throw PlatformException If unable to perform the request.
+ */
+ void setValue(const char* value);
+
+ /**
+ * Attaches on key value change callback.
+ * @param callback Callback function.
+ * @param data User data.
+ * @return True if callback has been successfully attached, false otherwsie.
+ * @remarks Does NOT take ownership over user data.
+ * @remarks Creating two independent keys then attaching the same callback to
+ * each and detaching it from one of them causes disconnection of
+ * this callback from vconf engine.
+ */
+ bool attachCallback(KeyChangeCallback callback,
+ void* data);
+
+ /**
+ * Detaches on key value change callback.
+ */
+ void detachCallback();
+
+ /**
+ * Resets this object to wrap other key around.
+ * @param name Key name or NULL (default).
+ */
+ void reset(const char* name = NULL);
+
+ private:
+ /**
+ * Callback set to platform.
+ * @param node Key.
+ * @param data User data.
+ */
+ static void callback(keynode_t* node,
+ void* data);
+
+ private:
+ std::string m_name; ///< Key name.
+ KeyChangeCallback m_callback; ///< Callback.
+ void* m_callbackData; ///< Callback user data.
+ DPL::Mutex m_mtx; ///< Synchronize access to callback.
+};
+} // VConf
+} // WrtDeviceApis
+#endif /* WRTDEVICEAPIS_VCONFKEY_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 "Node.h"
+#include <cassert>
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace VConf {
+Node::Node(keynode_t* node) : m_node(node)
+{
+ assert(m_node && "Node cannot be NULL.");
+
+ m_name = vconf_keynode_get_name(m_node);
+ m_type = static_cast<Type>(vconf_keynode_get_type(m_node));
+ if ((m_type != TYPE_BOOL) && (m_type != TYPE_INT) &&
+ (m_type != TYPE_DOUBLE) && (m_type != TYPE_STRING)) {
+ Throw(Commons::UnsupportedException);
+ }
+}
+
+std::string Node::getName() const
+{
+ return m_name;
+}
+
+Node::Type Node::getType() const
+{
+ return m_type;
+}
+} // VConf
+} // 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.
+ */
+#ifndef WRTDEVICEAPIS_VCONF_NODE_H_
+#define WRTDEVICEAPIS_VCONF_NODE_H_
+
+#include <string>
+#include <vconf.h>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace VConf {
+class Key;
+
+class Node : private DPL::Noncopyable
+{
+ friend class Key;
+
+ public:
+ /**
+ * Type of the node.
+ */
+ enum Type
+ {
+ TYPE_BOOL = VCONF_TYPE_BOOL, //!< TYPE_BOOL
+ TYPE_INT = VCONF_TYPE_INT, //!< TYPE_INT
+ TYPE_DOUBLE = VCONF_TYPE_DOUBLE, //!< TYPE_DOUBLE
+ TYPE_STRING = VCONF_TYPE_STRING //!< TYPE_STRING
+ };
+
+ public:
+ /**
+ * Gets node name.
+ * @return Node's name.
+ */
+ std::string getName() const;
+
+ /**
+ * Gets node type.
+ * @return Node's type.
+ */
+ Type getType() const;
+
+ private:
+ explicit Node(keynode_t* node);
+
+ private:
+ mutable keynode_t* m_node;
+ std::string m_name; ///< Name of the node.
+ Type m_type; ///< Type of the node.
+};
+
+typedef DPL::SharedPtr<Node> NodePtr;
+} // VConf
+} // WrtDeviceApis
+#endif /* WRTDEVICEAPIS_VCONF_NODE_H_ */
--- /dev/null
+get_current_path()
+
+pkg_search_module(vconf REQUIRED vconf)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_VCONF
+ ${vconf_INCLUDE_DIRS}
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_VCONF
+ ${vconf_LIBRARIES}
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_VCONF
+ ${CURRENT_PATH}/Key.cpp
+ ${CURRENT_PATH}/Node.cpp
+)
--- /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 Property.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WIDGET_PROPERTY_H_
+#define WIDGET_PROPERTY_H_
+
+#include <string>
+#include <Commons/Exception.h>
+
+namespace WrtDeviceApis {
+namespace Widget {
+
+template<typename T>
+class Property
+{
+ public:
+ explicit Property() :
+ m_value(),
+ m_valid(false)
+ {
+ }
+
+ void setValue(const T& value)
+ {
+ m_value = value;
+ m_valid = true;
+ }
+
+ T getValue() const
+ {
+ if (!m_valid) {
+ Throw(Commons::PlatformException);
+ }
+ return m_value;
+ }
+
+ bool isValid() const
+ {
+ return m_valid;
+ }
+
+ virtual ~Property()
+ {
+ }
+ private:
+ T m_value;
+ bool m_valid;
+};
+
+typedef Property<std::string> StringProperty;
+typedef Property<unsigned int> UIntProperty;
+}
+}
+#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 Widget.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <Commons/StringUtils.h>
+
+#include "Widget.h"
+#include <WidgetDB/IWidgetDB.h>
+#include <WidgetDB/WidgetDBMgr.h>
+
+
+namespace WrtDeviceApis {
+namespace Widget {
+using namespace std;
+using namespace WidgetDB::Api;
+
+Widget::Widget(Commons::IWrtWrapperPtr wrapper) :
+ m_wrtWrapper(wrapper)
+{
+ if (!wrapper) {
+ LogError("Wrapper is NULL");
+ }
+}
+
+string Widget::getProperty(ConfigAttribute attr) const
+{
+ checkWrapperPointer();
+
+ string value;
+ Try {
+ IWidgetDBPtr widgetDB = getWidgetDB(m_wrtWrapper->getWidgetId());
+ value = widgetDB->getConfigValue(attr);
+ }
+ Catch(Commons::InvalidArgumentException){
+ LogError("Invalid argument exception");
+ Throw(Commons::PlatformException);
+ }
+
+ return value;
+}
+
+string Widget::getAuthor() const
+{
+ checkWrapperPointer();
+
+ if (!m_author.isValid()) {
+ m_author.setValue(getProperty(ConfigAttribute::AUTHOR_NAME));
+ }
+ return m_author.getValue();
+}
+
+string Widget::getAuthorEmail() const
+{
+ checkWrapperPointer();
+
+ if (!m_authorEmail.isValid()) {
+ m_authorEmail.setValue(getProperty(ConfigAttribute::AUTHOR_EMAIL));
+ }
+ return m_authorEmail.getValue();
+}
+
+string Widget::getAuthorHref() const
+{
+ checkWrapperPointer();
+
+ if (!m_authorHref.isValid()) {
+ m_authorHref.setValue(getProperty(ConfigAttribute::AUTHOR_HREF));
+ }
+ return m_authorHref.getValue();
+}
+
+string Widget::getDescription() const
+{
+ checkWrapperPointer();
+
+ if (!m_description.isValid()) {
+ m_description.setValue(getProperty(ConfigAttribute::DESCRIPTION));
+ }
+ return m_description.getValue();
+}
+
+string Widget::getId() const
+{
+ checkWrapperPointer();
+
+ LogDebug("entered");
+ if (!m_id.isValid()) {
+ m_id.setValue(getProperty(ConfigAttribute::ID));
+ }
+ return m_id.getValue();
+}
+
+string Widget::getName() const
+{
+ checkWrapperPointer();
+
+ if (!m_name.isValid()) {
+ m_name.setValue(getProperty(ConfigAttribute::NAME));
+ }
+ return m_name.getValue();
+}
+
+string Widget::getShortName() const
+{
+ checkWrapperPointer();
+
+ if (!m_shortName.isValid()) {
+ m_shortName.setValue(getProperty(ConfigAttribute::SHORT_NAME));
+ }
+ return m_shortName.getValue();
+}
+
+string Widget::getVersion() const
+{
+ checkWrapperPointer();
+
+ if (!m_version.isValid()) {
+ m_version.setValue(getProperty(ConfigAttribute::VERSION));
+ }
+ return m_version.getValue();
+}
+
+unsigned int Widget::getHeight() const
+{
+ checkWrapperPointer();
+
+ if (!m_height.isValid()) {
+ m_height.setValue(Commons::String::toInt(
+ getProperty(ConfigAttribute::HEIGHT)));
+ }
+ return m_height.getValue();
+}
+
+unsigned int Widget::getWidth() const
+{
+ checkWrapperPointer();
+
+ if (!m_width.isValid()) {
+ m_width.setValue(Commons::String::toInt(
+ getProperty(ConfigAttribute::WIDTH)));
+ }
+ return m_width.getValue();
+}
+
+void Widget::checkWrapperPointer() const
+{
+ if (!m_wrtWrapper) {
+ LogError("Null pointer");
+ Throw(Commons::NullPointerException);
+ }
+ return;
+}
+}
+}
--- /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 Widget.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef PLATFORM_WIDGET_CONFIGURATION_H_
+#define PLATFORM_WIDGET_CONFIGURATION_H_
+
+#include <string>
+
+#include <Commons/WrtWrapper/IWrtWrapper.h>
+
+#include <Widget/IWidget.h>
+#include <WidgetDB/IWidgetDB.h>
+#include "Property.h"
+
+namespace WrtDeviceApis {
+namespace Widget {
+
+class Widget : public Api::IWidget
+{
+ public:
+
+ explicit Widget(Commons::IWrtWrapperPtr wrtWrapper);
+
+ virtual std::string getAuthor() const;
+ virtual std::string getAuthorEmail() const;
+ virtual std::string getAuthorHref() const;
+ virtual std::string getDescription() const;
+ virtual std::string getId() const;
+ virtual std::string getName() const;
+ virtual std::string getShortName() const;
+ virtual std::string getVersion() const;
+ virtual unsigned int getHeight() const;
+ virtual unsigned int getWidth() const;
+
+ protected:
+
+ Commons::IWrtWrapperPtr m_wrtWrapper;
+
+ mutable StringProperty m_author;
+ mutable StringProperty m_authorEmail;
+ mutable StringProperty m_authorHref;
+ mutable StringProperty m_description;
+ mutable StringProperty m_id;
+ mutable StringProperty m_name;
+ mutable StringProperty m_shortName;
+ mutable StringProperty m_version;
+ mutable UIntProperty m_height;
+ mutable UIntProperty m_width;
+
+ private:
+
+ std::string getProperty(WidgetDB::Api::ConfigAttribute) const;
+
+ void checkWrapperPointer() const;
+};
+
+}
+}
+
+#endif
--- /dev/null
+get_current_path()
+
+set(SRCS_IMPLEMENTATION_WIDGET
+ ${CURRENT_PATH}/Widget.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 WidgetDB.cpp
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "WidgetDB.h"
+
+#include <string>
+#include <set>
+
+#include <Commons/Exception.h>
+#include <WidgetDB/IWidgetDB.h>
+#include <WidgetDB/IWidgetFeature.h>
+#include <dpl/wrt-dao-ro/property_dao_read_only.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-ro/widget_config.h>
+#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/feature_model.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+
+#include "WidgetFeature.h"
+
+namespace { // anonymous
+ const int INVALID_WIDGET_HANDLE = -1;
+} // namespace
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+
+WidgetDB::WidgetDB(int widgetId) : m_widgetId(widgetId) {}
+
+
+int WidgetDB::getWidgetId() const
+{
+ return m_widgetId;
+}
+
+std::string WidgetDB::getLanguage() const
+{
+ LogDebug("getting language");
+
+ WrtDB::LanguageTagList languageTags;
+ std::string outLanguage;
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly dao(getWidgetId());
+ languageTags = dao.getLanguageTags();
+ }
+ Catch(DPL::Exception)
+ {
+ ReThrow(Commons::SecurityException);
+ }
+
+ // get 'en' language or first from the list if 'en' does not exist
+ if (languageTags.size() > 1)
+ {
+ FOREACH(lang, languageTags)
+ {
+ if ("en" == DPL::ToUTF8String(*lang))
+ return "en";
+ }
+ }
+
+ if (!languageTags.empty())
+ {
+ // get first language tag
+ outLanguage = DPL::ToUTF8String(*(languageTags.begin()));
+ }
+ return outLanguage;
+}
+
+/*License,LicenseHref,Description,Name can be \
+ returned with incorect language*/
+std::string WidgetDB::getConfigValue(Api::ConfigAttribute attribute) const
+{
+ LogDebug("entered");
+ std::string value;
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly dao(getWidgetId());
+ std::string language = getLanguage();
+ WrtDB::WidgetLocalizedInfo widgetInfo = dao.getLocalizedInfo(
+ DPL::FromUTF8String(language));
+
+ std::ostringstream out;
+
+ switch (attribute) {
+ case Api::ConfigAttribute::ID: {
+ DPL::OptionalString val = dao.getGUID();
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::VERSION: {
+ DPL::OptionalString val = dao.getVersion();
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::DESCRIPTION: {
+ DPL::OptionalString val = widgetInfo.description;
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::LICENSE: {
+ DPL::OptionalString val = widgetInfo.license;
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::LICENSE_HREF: {
+ DPL::OptionalString val = widgetInfo.licenseHref;
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::AUTHOR_NAME: {
+ DPL::OptionalString val = dao.getAuthorName();
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::AUTHOR_EMAIL: {
+ DPL::OptionalString val = dao.getAuthorEmail();
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::AUTHOR_HREF: {
+ DPL::OptionalString val = dao.getAuthorHref();
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::NAME: {
+ DPL::OptionalString val = widgetInfo.name;
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::SHORT_NAME: {
+ DPL::OptionalString val = widgetInfo.shortName;
+ value = !val ? "" : DPL::ToUTF8String(*val);
+ break; }
+
+ case Api::ConfigAttribute::ACCESS_NETWORK:
+ value = dao.getAccessNetworkMode() ? "yes" : "no";
+ break;
+
+ case Api::ConfigAttribute::WIDTH: {
+ DPL::OptionalInt width = dao.getPreferredSize().width;
+ !width ? out << "0" : out << *width;
+ value = out.str();
+ break; }
+
+ case Api::ConfigAttribute::HEIGHT: {
+ DPL::OptionalInt height = dao.getPreferredSize().height;
+ !height ? out << "0" : out << *height;
+ value = out.str();
+ break; }
+
+ case Api::ConfigAttribute::INSTALL_PATH:
+ value = DPL::ToUTF8String(dao.getPath());
+ break;
+
+ case Api::ConfigAttribute::PUBLIC_STORAGE_PATH:
+ value = WrtDB::GlobalConfig::GetPublicVirtualRootPath();
+ break;
+
+ default:
+ LogWarning("Unknown attribute requested");
+ Throw(Commons::InvalidArgumentException);
+ }
+ }
+ Catch(Commons::InvalidArgumentException)
+ {
+ ReThrow(Commons::InvalidArgumentException);
+ }
+ Catch(DPL::Exception)
+ {
+ ReThrow(Commons::SecurityException);
+ }
+
+ LogDebug("exit");
+
+ return value;
+}
+
+
+
+std::string WidgetDB::getUserAgent() const
+{
+ LogDebug("Widget User_Agent data get");
+
+ std::string outUA("not implemented");
+ return outUA;
+}
+
+Api::InstallationStatus WidgetDB::checkInstallationStatus(
+ const std::string& gid,
+ const std::string& name,
+ const std::string& version) const
+{
+ LogDebug("Checking widget ( gid(" << gid << "), name(" << name <<
+ "), version(" << version << ")) installation status");
+
+ Api::InstallationStatus outStatus;
+ Try
+ {
+ const WrtDB::WidgetGUID w_guid =
+ WrtDB::WidgetGUID(DPL::FromUTF8String(gid));
+
+ WrtDB::DbWidgetHandle widgetHandle = INVALID_WIDGET_HANDLE;
+
+ WrtDB::DbWidgetHandleList widgetList = WrtDB::WidgetDAOReadOnly
+ ::getHandleList();
+
+ FOREACH(iterator, widgetList) {
+ WrtDB::WidgetDAOReadOnly dao(*iterator);
+ WrtDB::WidgetGUID d_guid = dao.getGUID();
+ if (w_guid == d_guid) {
+ widgetHandle = *iterator;
+ }
+ }
+
+ // TODO check name
+ if (INVALID_WIDGET_HANDLE == widgetHandle) {
+ outStatus = Api::InstallationStatus::STATUS_UNINSTALLED;
+ } else {
+ WrtDB::WidgetDAOReadOnly dao(widgetHandle);
+ DPL::OptionalString ver = dao.getVersion();
+ if (!ver || version > DPL::ToUTF8String(*ver)) {
+ // if there is no version in DB
+ // or DB version is lover or equal than provided
+ outStatus = Api::InstallationStatus::STATUS_INSTALLED;
+ } else {
+ outStatus = Api::InstallationStatus::STATUS_LATEST;
+ }
+ }
+ }
+ Catch(DPL::Exception)
+ {
+ ReThrow(Commons::SecurityException);
+ }
+
+ return outStatus;
+}
+
+
+Api::Features WidgetDB::getWidgetFeatures() const
+{
+ LogDebug("entered");
+ WrtDB::DbWidgetFeatureSet features;
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly doa(getWidgetId());
+ features = doa.getFeaturesList();
+ }
+ Catch(DPL::Exception)
+ {
+ // exception handle
+ ReThrow(Commons::SecurityException);
+ }
+
+ Api::Features outFeatures;
+
+ LogDebug("There is no exception");
+
+ FOREACH(it, features)
+ {
+ Api::IWidgetFeaturePtr feature(
+ new WidgetFeature(DPL::ToUTF8String((*it).name),
+ (*it).required,
+ true)); // requested (WidgetFeature param)
+ // iterating multimap
+ FOREACH(iterator, (*it).params)
+ {
+ // adding features with key(first) and value(second)
+ feature->addParam(DPL::ToUTF8String(iterator->first),
+ DPL::ToUTF8String(iterator->second));
+ }
+
+ outFeatures.push_back(feature);
+ }
+
+ return outFeatures;
+}
+
+Api::Features WidgetDB::getRegisteredFeatures() const
+{
+ Api::Features outRegisteredFeatures;
+ Try
+ {
+ // initialize with our widget features (they are required)
+ outRegisteredFeatures = getWidgetFeatures();
+
+ // searching for another features
+
+ WrtDB::FeatureHandleList features =
+ WrtDB::FeatureDAOReadOnly::GetHandleList();
+
+ bool featureFound = false;
+
+ // throught all features
+ FOREACH(registeredFeature, features)
+ {
+ WrtDB::FeatureHandle handle = *registeredFeature;
+ WrtDB::FeatureDAOReadOnly dao(handle);
+
+ // check if this feature is aleready on outRegisteredFeatures list
+ // and if not, add it
+
+ FOREACH(it, outRegisteredFeatures)
+ {
+ if (dao.GetName() == (*it)->getName()) { // *it = shared ptr
+ // this name is found on list, do not add
+ featureFound = true;
+ break;
+ }
+ }
+
+ if (!featureFound) {
+ // feature is not on outRegisteredFeature so add it with
+ // 'required' property false
+ Api::IWidgetFeaturePtr newFeature(new WidgetFeature(
+ dao.GetName(),
+ false,
+ false));
+
+ // TODO what about feature params? aren't they needed
+ outRegisteredFeatures.push_back(newFeature);
+ }
+ // reset the flag and check another feature
+ featureFound = false;
+ }
+ }
+ Catch(DPL::Exception)
+ {
+ ReThrow(Commons::SecurityException);
+ }
+
+ return outRegisteredFeatures;
+}
+
+
+std::string WidgetDB::getWidgetInstallationPath() const
+{
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly dao(getWidgetId());
+ std::string result(DPL::ToUTF8String(dao.getFullPath()));
+ result.erase(0,strlen("file://"));
+ std::string::size_type pos = result.size();
+ std::string separator("/");
+ pos = result.rfind(separator, pos);
+ if((result.size()-pos) >0 && (result.size()-pos) < 2)
+ {
+ result.erase(pos, result.size());
+ }
+ return result;
+ }
+ Catch(DPL::Exception)
+ {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+std::string WidgetDB::getWidgetPersistentStoragePath() const
+{
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly dao(getWidgetId());
+ return WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(*dao.getPkgname());
+ }
+ Catch(DPL::Exception)
+ {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+std::string WidgetDB::getWidgetTemporaryStoragePath() const
+{
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly dao(getWidgetId());
+ return WrtDB::WidgetConfig::GetWidgetTemporaryStoragePath(*dao.getPkgname());
+ }
+ Catch(DPL::Exception)
+ {
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+} // WidgetDB
+} // 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 WidgetDB.h
+ * @author Andrzej Surdej (a.surdej@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_WIDGETDB_WIDGETDB_H_
+#define WRTDEVICEAPIS_WIDGETDB_WIDGETDB_H_
+
+#include <string>
+#include <WidgetDB/IWidgetDB.h>
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+
+class WidgetDB : public Api::IWidgetDB
+{
+ public:
+
+ explicit WidgetDB(int widgetId);
+
+ virtual int getWidgetId() const;
+
+ virtual std::string getLanguage() const;
+
+ virtual std::string getConfigValue(Api::ConfigAttribute attribute) const;
+
+ virtual std::string getUserAgent() const;
+
+ virtual Api::InstallationStatus checkInstallationStatus(
+ const std::string& gid,
+ const std::string& name,
+ const std::string& version) const;
+
+ virtual Api::Features getWidgetFeatures() const;
+
+ virtual Api::Features getRegisteredFeatures() const;
+
+ virtual std::string getWidgetInstallationPath() const;
+
+ virtual std::string getWidgetPersistentStoragePath() const;
+
+ virtual std::string getWidgetTemporaryStoragePath() const;
+
+ private:
+
+ int m_widgetId;
+
+};
+
+} // WidgetDB
+} // WrtDeviceApis
+
+#endif // WRTDEVICEAPIS_WIDGETDB_WIDGETDB_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/log/log.h>
+#include "WidgetFeature.h"
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+
+WidgetFeature::WidgetFeature(const std::string& name,
+ bool required,
+ bool requested) :
+ m_name(name),
+ m_required(required),
+ m_requested(requested)
+{
+ //LogDebug("entered");
+}
+
+std::string WidgetFeature::getName() const
+{
+ //LogDebug("entered");
+ return m_name;
+}
+
+bool WidgetFeature::isRequired() const
+{
+ //LogDebug("entered");
+ return m_required;
+}
+
+Api::IWidgetFeature::Params WidgetFeature::getParams() const
+{
+ //LogDebug("entered");
+ return m_params;
+}
+
+void WidgetFeature::addParam(const std::string& paramName,
+ const std::string& paramValue)
+{
+ //LogDebug("entered");
+ m_params[paramName] = paramValue;
+}
+
+WidgetFeature::~WidgetFeature()
+{
+ //LogDebug("entered");
+}
+
+bool WidgetFeature::isRequestedByWidget() const
+{
+ return m_requested;
+}
+
+} // WidgetDB
+} // 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.
+ */
+/*
+ * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_H_
+#define WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_H_
+
+#include <string>
+#include <WidgetDB/IWidgetFeature.h>
+
+namespace WrtDeviceApis {
+namespace WidgetDB {
+
+class WidgetFeature : public Api::IWidgetFeature
+{
+ public:
+ WidgetFeature(const std::string& name,
+ bool required,
+ bool requested);
+
+ std::string getName() const;
+
+ bool isRequired() const;
+
+ Api::IWidgetFeature::Params getParams() const;
+
+ virtual ~WidgetFeature();
+
+ virtual void addParam(const std::string& paramName,
+ const std::string& paramValue);
+
+ virtual bool isRequestedByWidget() const;
+
+ private:
+ std::string m_name;
+ bool m_required;
+ bool m_requested;
+ Params m_params;
+};
+
+} // WidgetDB
+} // WrtDeviceApis
+
+#endif
--- /dev/null
+get_current_path()
+
+pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_WIDGETDB
+ ${dpl-wrt-dao-ro_INCLUDE_DIRS}
+ PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_WIDGETDB
+ ${dpl-wrt-dao-ro_LDFLAGS}
+ PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_WIDGETDB
+ ${CURRENT_PATH}/WidgetDB.cpp
+ ${CURRENT_PATH}/WidgetFeature.cpp
+ PARENT_SCOPE
+)
--- /dev/null
+
+get_current_path()
+
+pkg_search_module(dpl-db REQUIRED dpl-db-efl)
+
+include_directories(${CURRENT_PATH})
+
+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 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
+)
+
+ADD_CUSTOM_TARGET(Sqlite3Db ALL DEPENDS ${CURRENT_PATH}/widget_interface_db.sql)
+
+INSTALL(FILES ${CURRENT_PATH}/widget_interface_db.sql
+ DESTINATION share/wrt-plugins-common/
+)
--- /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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#include "WidgetInterfaceDAO.h"
+#include <string>
+#include <sstream>
+#include <fstream>
+#include <sys/stat.h>
+#include <dpl/db/sql_connection.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/string.h>
+#include <Commons/Exception.h>
+#include <dpl/wrt-dao-ro/property_dao_read_only.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+#include <dpl/wrt-dao-ro/widget_config.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include "orm_generator_widget_interface.h"
+namespace {
+DPL::DB::SqlConnection::Flag::Type DATABASE_FLAGS =
+ DPL::DB::SqlConnection::Flag::UseLucene;
+const char *KEY_WIDGET_ARG = "widget_arg";
+}
+
+namespace WrtDeviceApis {
+
+WidgetInterfaceDAO::WidgetInterfaceDAO(int widgetHandle) :
+ m_widgetHandle(widgetHandle),
+ m_databaseInterface(databaseFileName(widgetHandle), DATABASE_FLAGS)
+{
+ if (!checkDatabase()) {
+ LogError("There is a problem with database");
+ }
+ m_databaseInterface.AttachToThread();
+}
+
+WidgetInterfaceDAO::~WidgetInterfaceDAO()
+{
+ m_databaseInterface.DetachFromThread();
+}
+
+bool WidgetInterfaceDAO::checkDatabase()
+{
+ using namespace WrtDB::GlobalConfig;
+ std::string databaseFile = databaseFileName(m_widgetHandle);
+ struct stat buffer;
+ if (stat(databaseFile.c_str(), &buffer) != 0) {
+
+ //Create fresh database
+
+ LogInfo("Creating database " << databaseFile);
+
+ std::fstream file;
+ file.open(GetWrtWidgetInterfaceDatabaseFilePath(), std::ios_base::in);
+ if (!file) {
+ LogError("Cannot create database. SQL file is missing.");
+ return false;
+ }
+
+ std::stringstream buffer;
+ buffer << file.rdbuf();
+
+ file.close();
+
+ Try
+ {
+ DPL::DB::SqlConnection con(databaseFile);
+ con.ExecCommand(buffer.str().c_str());
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot create database");
+ return false;
+ }
+ copyPropertiesFromWrtDatabase();
+ }
+ return true;
+}
+
+bool WidgetInterfaceDAO::copyPropertiesFromWrtDatabase()
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::widget_interface;
+
+ bool result = true;
+ WrtDB::WrtDatabase::attachToThread();
+ m_databaseInterface.AttachToThread();
+
+ Try
+ {
+ WrtDB::PropertyDAOReadOnly::WidgetPreferenceList existing =
+ WrtDB::PropertyDAOReadOnly::GetPropertyList(m_widgetHandle);
+
+ Try
+ {
+ //save all properties read from config.xml
+ FOREACH(prop, existing) {
+ std::string key = DPL::ToUTF8String(prop->key_name);
+ if (key != KEY_WIDGET_ARG) {
+ std::string value;
+ if (!prop->key_value.IsNull()) {
+ value = DPL::ToUTF8String(*(prop->key_value));
+ }
+ bool readonly =
+ !prop->readonly.IsNull() && (*prop->readonly);
+ setItem(key, value, readonly, true);
+ }
+ }
+ }
+ Catch(Commons::Exception)
+ {
+ LogError("Cannot copy properties read from config.xml");
+ result = false;
+ }
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot copy properties read from config.xml");
+ result = false;
+ }
+ WrtDB::WrtDatabase::detachFromThread();
+ m_databaseInterface.DetachFromThread();
+ return result;
+}
+
+void WidgetInterfaceDAO::setItem(const std::string& key,
+ const std::string& value,
+ bool readOnly)
+{
+ setItem(key, value, readOnly, false);
+}
+
+void WidgetInterfaceDAO::setItem(const std::string& key,
+ const std::string& value,
+ bool readOnly,
+ bool fromConfigXml)
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::widget_interface;
+
+ Try
+ {
+ ScopedTransaction tran(&m_databaseInterface);
+ //check if key exists
+ Properties::Select select(&m_databaseInterface);
+ select.Where(
+ Equals<Properties::key>(DPL::FromASCIIString(key)));
+ std::list<Properties::Row> rows = select.GetRowList();
+
+ if (rows.size() == 0) {
+ Properties::Insert insert(&m_databaseInterface);
+ Properties::Row row;
+ row.Set_key(DPL::FromASCIIString(key));
+ row.Set_value(DPL::FromASCIIString(value));
+ row.Set_readonly(readOnly ? 1 : 0);
+ row.Set_configxml(fromConfigXml ? 1 : 0);
+ insert.Values(row);
+ insert.Execute();
+ }
+ else {
+ Assert(rows.size() == 1);
+ Properties::Row row = rows.front();
+ if (row.Get_readonly() != 0) {
+ Throw(Commons::LocalStorageValueNoModifableException);
+ }
+ row.Set_value(DPL::FromASCIIString(value));
+ row.Set_readonly(readOnly ? 1 : 0);
+ Properties::Update update(&m_databaseInterface);
+ update.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+ update.Values(row);
+ update.Execute();
+ }
+ tran.Commit();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot set item " << key << " with value " << value);
+ ReThrow(Commons::PlatformException);
+ }
+
+}
+
+void WidgetInterfaceDAO::removeItem(const std::string& key)
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::widget_interface;
+
+ Try
+ {
+ Properties::Select select(&m_databaseInterface);
+ select.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+ bool readonly = select.GetSingleValue<Properties::readonly>();
+ if (readonly) {
+ ThrowMsg(Commons::LocalStorageValueNoModifableException,
+ "Cannot delete item. Item is readonly");
+ }
+ Properties::Delete deleteItem(&m_databaseInterface);
+ deleteItem.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+ deleteItem.Execute();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot delete item " << key);
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+DPL::Optional<std::string> WidgetInterfaceDAO::getValue(
+ const std::string& key) const
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::widget_interface;
+
+ Try
+ {
+ Properties::Select select(&m_databaseInterface);
+ select.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+ std::list<DPL::String> value = select.GetValueList<Properties::value>();
+ if (value.size() == 0) {
+ return DPL::Optional<std::string>();
+ }
+ return DPL::Optional<std::string>(DPL::ToUTF8String(value.front()));
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Not found item " << key);
+ ReThrow(Commons::PlatformException);
+ }
+ return std::string();
+}
+
+void WidgetInterfaceDAO::clear(bool removeReadOnly)
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::widget_interface;
+ Try
+ {
+ Properties::Delete deleteItem(&m_databaseInterface);
+ if (!removeReadOnly) {
+ deleteItem.Where(Equals<Properties::readonly>(0));
+ }
+ deleteItem.Execute();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot delete all items");
+ ReThrow(Commons::PlatformException);
+ }
+}
+
+size_t WidgetInterfaceDAO::getStorageSize() const
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::widget_interface;
+
+ Try
+ {
+ Properties::Select select(&m_databaseInterface);
+ std::list<DPL::String> list =
+ select.GetValueList<Properties::key>();
+ return list.size();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot get item count");
+ ReThrow(Commons::PlatformException);
+ }
+ return 0;
+}
+
+std::string WidgetInterfaceDAO::getValueByIndex(size_t index) const
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::widget_interface;
+
+ Try
+ {
+ Properties::Select select(&m_databaseInterface);
+ select.OrderBy("key");
+ std::list<DPL::String> list =
+ select.GetValueList<Properties::value>();
+ if (index >= list.size()) {
+ Throw(Commons::InvalidArgumentException);
+ }
+ for (size_t i = 0; i < index; ++i) {
+ list.pop_front();
+ }
+ return DPL::ToUTF8String(list.front());
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot get item count");
+ ReThrow(Commons::PlatformException);
+ }
+ return std::string();
+}
+
+std::string WidgetInterfaceDAO::databaseFileName(int widgetHandle)
+{
+ using namespace DPL::DB::ORM;
+ using namespace WrtDB::WidgetConfig;
+ using namespace WrtDB::GlobalConfig;
+
+ WrtDB::WrtDatabase::attachToThread();
+
+ std::stringstream filename;
+ Try
+ {
+ WrtDB::WidgetDAOReadOnly widgetDAO(widgetHandle);
+ DPL::Optional<DPL::String> pkgname = widgetDAO.getPkgname();
+
+ filename << GetWidgetPersistentStoragePath(*pkgname)
+ << "/"
+ << GetWidgetInterfaceDatabaseFile();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base)
+ {
+ LogError("Cannot get item count");
+ ReThrow(Commons::PlatformException);
+ }
+ WrtDB::WrtDatabase::detachFromThread();
+ return filename.str();
+}
+
+}
--- /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 Lukasz Marek (l.marek@samsung.com)
+ * @version 0.1
+ * @brief
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_DAO_H_
+#define WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_DAO_H_
+
+#include <string>
+#include <dpl/db/thread_database_support.h>
+#include <dpl/db/orm_interface.h>
+#include <LocalStorage/ILocalStorage.h>
+
+namespace WrtDeviceApis {
+
+class WidgetInterfaceDAO :
+ public LocalStorage::Api::ILocalStorage
+{
+ public:
+ WidgetInterfaceDAO(int widgetHandle);
+ virtual ~WidgetInterfaceDAO();
+
+ void setItem(const std::string& key,
+ const std::string& value,
+ bool readOnly,
+ bool fromConfigXml);
+ void setItem(const std::string& key,
+ const std::string& value,
+ bool readOnly);
+ void removeItem(const std::string& key);
+ 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;
+
+ protected:
+ int m_widgetHandle;
+ mutable DPL::DB::ThreadDatabaseSupport m_databaseInterface;
+
+ private:
+ bool checkDatabase();
+ bool copyPropertiesFromWrtDatabase();
+ static std::string databaseFileName(int widgetHandle);
+};
+
+}
+
+#endif //WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_DAO_H_
\ No newline at end of file
--- /dev/null
+
+get_current_path()
+
+set(WIDGET_INTERFACE_INCLUDE_DIRS
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+SET(API_WIDGET_INTERFACE_PATH
+ ${CURRENT_PATH}
+ PARENT_SCOPE
+)
+
+set(SRCS_WIDGET_INTERFACE_DAO
+ ${CURRENT_PATH}/WidgetInterfaceDAO.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.
+ */
+
+#ifndef ORM_GENERATOR_WIDGET_INTERFACE_H_
+#define ORM_GENERATOR_WIDGET_INTERFACE_H_
+
+#define ORM_GENERATOR_DATABASE_NAME widget_interface_db_definitions
+#include <dpl/db/orm_generator.h>
+#undef ORM_GENERATOR_DATABASE_NAME
+
+#endif
--- /dev/null
+SQL(
+ PRAGMA foreign_keys = ON;
+ BEGIN TRANSACTION;
+)
+
+CREATE_TABLE(Properties)
+ COLUMN_NOT_NULL(key, TEXT,)
+ COLUMN_NOT_NULL(value, TEXT,)
+ COLUMN_NOT_NULL(readonly, INTEGER, check(readonly between 0 and 1))
+ COLUMN_NOT_NULL(configxml, INTEGER, check(readonly between 0 and 1) DEFAULT 0)
+
+ TABLE_CONSTRAINTS(unique(key))
+CREATE_TABLE_END()
+
+SQL(
+ COMMIT;
+)
--- /dev/null
+DATABASE_START(widget_interface)
+
+#include "widget_interface_db"
+
+DATABASE_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 wrt_db_sql_generator.h
+ * @author Bartosz Janiak (b.janiak@samsung.com)
+ * @version 1.0
+ * @brief Macro definitions for generating the SQL input file from database definition.
+ */
+
+//Do not include this file directly! It is used only for SQL code generation.
+
+#include <dpl/db/orm_macros.h>
+
+#include "widget_interface_db_definitions"
--- /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
+# @brief
+#
+
+#
+# Test files
+#
+# Define all wrt-plugins-common tests sources.
+# Runner is responsible for runnint it all and
+# generating proper output files
+#
+
+SET(TARGET_NAME wrt-plugins-commons-test)
+
+pkg_search_module(dpl REQUIRED dpl-efl>=1.0.0)
+pkg_search_module(dpl-test REQUIRED dpl-test-efl)
+pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
+
+SET(WRT_PLUGINS_COMMONS_TESTS_SOURCES
+ ${PROJECT_SOURCE_DIR}/tests/main.cpp
+ ${PROJECT_SOURCE_DIR}/tests/test_widget_interface_dao.cpp
+)
+
+SET(WRT_PLUGINS_COMMONS_TESTS_DIR
+ ${PROJECT_SOURCE_DIR}/src/
+ ${PROJECT_SOURCE_DIR}/src/Commons/
+ ${PROJECT_SOURCE_DIR}/src/CommonsJavaScript/
+ ${PROJECT_SOURCE_DIR}/src/modules/tizen/
+ ${PROJECT_SOURCE_DIR}/src/modules/API/
+ ${PROJECT_SOURCE_DIR}/tests
+)
+
+include_directories(
+ ${WRT_PLUGINS_COMMONS_TESTS_DIR}
+ ${dpl_INCLUDE_DIRS}
+ ${dpl-wrt-dao-ro_INCLUDE_DIRS}
+ ${dpl-test_INCLUDE_DIRS}
+)
+
+ADD_EXECUTABLE(${TARGET_NAME}
+ ${WRT_PLUGINS_COMMONS_TESTS_SOURCES}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ ${dpl_LIBRARIES}
+ ${dpl-test_LIBRARIES}
+ ${dpl-wrt-dao-ro_LIBRARIES}
+ "wrt-plugins-widget-interface-dao"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/
+ BUILD_WITH_INSTALL_RPATH ON
+ INSTALL_RPATH_USE_LINK_PATH ON
+)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wrt_plugins_commons_test_prepare_db.sh
+ ${PROJECT_SOURCE_DIR}/bin/wrt_plugins_commons_test_prepare_db.sh COPYONLY)
--- /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 main.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation file of main
+ */
+
+#include <dpl/test/test_runner.h>
+#include <dpl/log/log.h>
+
+int main(int argc, char *argv[])
+{
+ int ret = system("./wrt_plugins_commons_test_prepare_db.sh start");
+
+ if (!WIFEXITED(ret) || WEXITSTATUS(ret))
+ {
+ LogDebug("Fail while preparing database. Restoring");
+ system("./wrt_plugins_commons_test_prepare_db.sh stop");
+ return -1;
+ }
+
+ ret = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
+
+ system("./wrt_plugins_commons_test_prepare_db.sh stop");
+
+ return ret;
+}
+
--- /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_widget_interface_dao.cpp
+ * @author Lukasz Marek (l.marek@samsung.com)
+ * @version 1.0
+ * @brief This is the implementation file of test widget interface dao.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <cstdlib>
+#include <unistd.h>
+#include <string>
+#include <sstream>
+#include <dpl/test/test_runner.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <WidgetInterfaceDAO/WidgetInterfaceDAO.h>
+
+namespace {
+const std::string FAKE_WIDGET_DIR = "/opt/apps/org.tizen.";
+const std::string WIDGET_DATA_SUBDIR = "data/";
+const std::string DATABASE_NAME = "widget_interface.db";
+
+//Following variable is an arbitraty number.
+//It must match value inserted to wrt database by
+//wrt_plugins_commons_test_prepare_db script.
+const int FAKE_WIDGET_ID = 65537;
+}
+
+using namespace WrtDeviceApis;
+
+RUNNER_TEST_GROUP_INIT(WidgetInterfaceDAO)
+
+class FakeWidget
+{
+public:
+ FakeWidget() :
+ m_fakeWidgetId(FAKE_WIDGET_ID)
+ {
+ std::stringstream baseDir;
+ baseDir << FAKE_WIDGET_DIR << m_fakeWidgetId << "/";
+ m_fakeWidgetBaseDir = baseDir.str();
+
+ std::string widgetDataDir =
+ m_fakeWidgetBaseDir + WIDGET_DATA_SUBDIR;
+
+ m_fakeWidgetDatabaseFile = widgetDataDir + DATABASE_NAME;
+
+ if ((mkdir(baseDir.str().c_str(), 0777) < 0) ||
+ (mkdir(widgetDataDir.c_str(), 0777) < 0))
+ {
+ LogError("Cannot create test directory");
+ }
+ }
+
+ ~FakeWidget()
+ {
+ std::string command = "rm -rf ";
+ command.append(m_fakeWidgetBaseDir);
+ int ret = system(command.c_str());
+ if (!WIFEXITED(ret) || WEXITSTATUS(ret))
+ {
+ LogWarning("Fake widget directory is not deleted!");
+ }
+ }
+
+ int widgetId() const
+ {
+ return m_fakeWidgetId;
+ }
+
+ std::string dataBaseFile() const
+ {
+ return m_fakeWidgetDatabaseFile;
+ }
+
+private:
+ int m_fakeWidgetId;
+ std::string m_fakeWidgetBaseDir;
+ std::string m_fakeWidgetDatabaseFile;
+};
+
+RUNNER_TEST(DatabaseCreateOnFirstUse)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ int ret = access(w.dataBaseFile().c_str(), F_OK);
+
+ LogDebug("filename " << w.dataBaseFile() << " result " << ret);
+
+ RUNNER_ASSERT(ret == 0);
+}
+
+RUNNER_TEST(GetStorageSize)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key", "value", false);
+
+ RUNNER_ASSERT(dao.getStorageSize() == 1);
+
+ dao.removeItem("key");
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+}
+
+RUNNER_TEST(RemoveItem)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key", "value", false);
+
+ RUNNER_ASSERT(dao.getStorageSize() == 1);
+
+ dao.setItem("key", "value", true);
+
+ RUNNER_ASSERT(dao.getStorageSize() == 1);
+
+ bool exCaught = false;
+ try
+ {
+ dao.removeItem("key");
+ }
+ catch(const Commons::LocalStorageValueNoModifableException &ex)
+ {
+ exCaught = true;
+ }
+
+ RUNNER_ASSERT(dao.getStorageSize() == 1 && exCaught);
+}
+
+RUNNER_TEST(GetValueExisting)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key1", "value1", false);
+ dao.setItem("key2", "value2", false);
+
+ DPL::Optional<std::string> val1 = dao.getValue("key1");
+ DPL::Optional<std::string> val2 = dao.getValue("key2");
+
+ RUNNER_ASSERT(!val1.IsNull() && *val1 == "value1");
+ RUNNER_ASSERT(!val2.IsNull() && *val2 == "value2");
+
+}
+
+RUNNER_TEST(GetValueNonExisting)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ DPL::Optional<std::string> val1 = dao.getValue("key1");
+
+ RUNNER_ASSERT(val1.IsNull());
+}
+
+RUNNER_TEST(Clear)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key1", "value1", false);
+ dao.setItem("key2", "value1", false);
+ RUNNER_ASSERT(dao.getStorageSize() == 2);
+
+ dao.clear(false);
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key1", "value1", true);
+ dao.setItem("key2", "value1", true);
+ RUNNER_ASSERT(dao.getStorageSize() == 2);
+
+ dao.clear(false);
+ RUNNER_ASSERT(dao.getStorageSize() == 2);
+
+ dao.clear(true);
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+}
+
+RUNNER_TEST(UpdateValue)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key1", "value1", false);
+ DPL::Optional<std::string> val1 = dao.getValue("key1");
+ RUNNER_ASSERT(!val1.IsNull() && *val1 == "value1");
+
+ dao.setItem("key1", "value2", false);
+ val1 = dao.getValue("key1");
+ RUNNER_ASSERT(!val1.IsNull() && *val1 == "value2");
+
+ RUNNER_ASSERT(dao.getStorageSize() == 1);
+}
+
+RUNNER_TEST(UpdateReadOnlyValue)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key1", "value1", true);
+ DPL::Optional<std::string> val1 = dao.getValue("key1");
+ RUNNER_ASSERT(!val1.IsNull() && *val1 == "value1");
+
+ bool exCaught = false;
+ try
+ {
+ dao.setItem("key1", "value2", false);
+ }
+ catch(const Commons::LocalStorageValueNoModifableException &ex)
+ {
+ exCaught = true;
+ }
+
+ RUNNER_ASSERT(dao.getStorageSize() == 1 && exCaught);
+}
+
+RUNNER_TEST(GetValueByIndex)
+{
+ FakeWidget w;
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key1", "value1", false);
+ dao.setItem("key2", "value2", false);
+ RUNNER_ASSERT(dao.getStorageSize() == 2);
+
+ std::string val1 = dao.getValueByIndex(0);
+ std::string val2 = dao.getValueByIndex(1);
+
+ RUNNER_ASSERT((val1 == "value1" && val2 == "value2") ||
+ (val2 == "value1" && val1 == "value2"));
+}
+
+RUNNER_TEST(DataPersistent)
+{
+ FakeWidget w;
+ {
+ WidgetInterfaceDAO dao(w.widgetId());
+
+ RUNNER_ASSERT(dao.getStorageSize() == 0);
+
+ dao.setItem("key1", "value1", false);
+ dao.setItem("key2", "value2", false);
+ }
+
+ {
+ WidgetInterfaceDAO dao(w.widgetId());
+ DPL::Optional<std::string> val1 = dao.getValue("key1");
+ DPL::Optional<std::string> val2 = dao.getValue("key2");
+
+ RUNNER_ASSERT(!val1.IsNull() && *val1 == "value1");
+ RUNNER_ASSERT(!val2.IsNull() && *val2 == "value2");
+ }
+}
--- /dev/null
+#!/bin/sh
+#
+# 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.
+#
+#
+
+WRT_DB=/opt/dbspace/.wrt.db
+WRT_DB_BCK=/tmp/wrt.db_backup
+
+if [ "x$1" == "xstart" ]; then
+ echo start;
+ cp $WRT_DB $WRT_DB_BCK
+ wrt_reset_db.sh;
+
+ #insert some fake widget into to make widget interface dao tests working corectly
+ INS_ALL_WIDGET="insert into WidgetInfo(app_id, widget_id, widget_version, widget_width, widget_height, author_name, author_email, author_href, base_folder, webkit_plugins_required, child_protection, recognized, wac_signed, distributor_signed, min_version, slp_pkgname)";
+ sqlite3 $WRT_DB "${INS_ALL_WIDGET} VALUES(65537, 'w_id_2000', '1.0.0', 100, 200, 'a_name_2000', 'a_email_2000', 'a_href_2000', 'basef_2000', 1, 1, 1, 1, 1, '1.0', 'org.tizen.65537')";
+
+ exit $?
+elif [ "x$1" == "xstop" ]; then
+ echo stop;
+ cp $WRT_DB_BCK $WRT_DB
+ exit $?
+else
+ exit 1
+fi
--- /dev/null
+{
+ global: *;
+ local: *;
+};
+
+