Update change log and spec for wrt-plugins-tizen_0.4.15
authorDongjin Choi <milkelf.choi@samsung.com>
Fri, 12 Apr 2013 13:11:05 +0000 (22:11 +0900)
committerDongjin Choi <milkelf.choi@samsung.com>
Fri, 12 Apr 2013 13:11:05 +0000 (22:11 +0900)
[Issue#] N/A
[Problem] Hidden bug for calendar date based find api if value is greater than 32 bit size.
[Cause] Use of 32 bit time format.
[Solution] Use 64 bit time format for find api date attributes.

[Issue#] N/A
[Problem] Wrong default rrule end date displayed.
[Cause] Wrong use of platform default value.
[Solution] Use platform default end date for rrule.

[Issue#] TREL-251
[Problem] progress value is not unsigned.
[Cause] N/A
[Solution] value type is changed unsigned type & using validator

[Issue#] N/A
[Problem] Oranage(Adelya) request
[Cause] N/A
[Solution] Add setExclusiveMode api

[Issue#] [Application] change error to exception & TCT bug fix
[Problem] N/A
[Cause] N/A
[Solution] change WebAPIError to WebAPIException and bug-fix for TCT

[Issue#] N/A
[Problem] One file is missed for previous upload
[Cause] N/A
[Solution] N/A
[SCMRequest] N/A

[Issue#] N/A
[Problem] It used WebapiError instead of WebapiException
[Cause] N/A
[Solution] Apply AWebapiException.

[Issue#] prevent 50655 50656 50690
[Problem] Had risk not to called destructor
[Cause] Freed void pointer
[Solution] Getting finalizer function from setter

[Issue#] N/A
[Problem] Privilege has been changed
[Cause] Policy has been changed
[Solution] Applied N/P

[Issue#] N/A
[Problem] Init function is called many times while deinit function is not called.
[Cause] DS manager destructor is not called when unit tc is run repetitively.
[Solution] Call init function only once if deinit function is not called.

[Issue#] N/A
[Problem] Apply Argument Validator & WebapiException & Unit TC
[Cause] N/A
[Solution] Apply Argument Validator & WebapiException for TCT Pass

[Issue#] N/A
[Problem] It used WebapiError instead of WebapiException
[Cause] N/A
[Solution] Apply AWebapiException.

[Issue#] Docomo request to access ringtones directory.
[Problem] N/A
[Cause] N/A
[Solution] virtual root addition.

[Issue#] N/A
[Problem] Fail TZDate.difference, equalsTo, ealierThan, laterThan
[Cause] It used WebapiError instead of WebapiException. When APIs to compare with another TZDate called, they compared with same objects.
[Solution] Apply AWebapiException. Fix to compare this obejct with another object.

[#Issue] N/A
[Problem] Argument checking rule was not valid
[Cause] Did not follow ECMAScript rule
[Solution] Used the common ArgumentValidator

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] Apply Argument Validator & WebapiException for TCT Pass

[Issue#] N/A
[Problem] When user input function object as callback interface, then any exception is thrown
[Cause] toCallbackObject() do not check whether input value is not function or not
[Solution] toCallbackObject throws TypeMismatchException in case of function object

[Issue#] N_SE-33433
[Problem] Wrong child record update routine for calendar alarms and attendees.
[Cause] Didn't delete preset records.
[Solution] Delete preset records before updating child records.

[Issue#] TREL-161
[Problem] TCT failed
[Cause] Validation check problem
[Solution] Fixed validation codes

[Issue#] N/A
[Problem] Exception type is wrong
[Cause] Used JSWebAPIError
[Solution] Use JSWebAPIException class

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] [Messaging] JSMessageBody - ArgumentValidator

[Issue#] N/A
[Problem] Crash when addDraftMessage with Email message on sms service
[Cause] call addDraft on sms with email message
[Solution] check the message type and service type

[Issue#] N/A
[Problem] [Contact] fix prevent issues
[Cause] internal error
[Solution] modify code

[Issue#] DCM-1285
[Problem] releaseDate return undefined currently.
[Cause] N/A
[Solution] return value chagned as an result

[Issue#] N/A
[Problem] Invalid array attribute not checked.
[Cause] No array type check.
[Solution] Check array type in converter for TCT pass.

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution]  [Download] Fix WebAPIError to WebAPIException for each operation.
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] [CallHistory] Applied ArgumentValidator and fixed unit TC.

[Issue#] N/A
[Problem] Wrong duratoin value conversion for a large value.
[Cause] Duration value converted using integer type.
[Solution] Use long long type instead of integer.

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] [Common] Use WebAPIException in PlatformException

[Issue#] N/A
[Problem] ArgumentValidator on JSMessagingService, JSMessagingServiceManager, JSMessagingStorage.
[Cause] N/A
[Solution] ArgumentValidator on JSMessagingService, JSMessagingServiceManager, JSMessagingStorage.

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] [Common] Support to JSWebAPIException

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] [SecureElement] Applying the ArgumentValidator

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] return shared directory URI for specific application

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] [TimeUtil] Applying the ArgumentValidator

[Issue#] N/A
[Problem] Conversion exception for a task without start time.
[Cause] Wrong duration calculation for a task without start time.
[Solution] Set null duration for a task without a start time.

[Issue#] CID 50664
[Problem] Dereferencing after null check
[Cause] N/A
[Solution] Fix a bug

[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] [Common] ArgumentValidator fix conversion bug , add JSUtil helper functions (merging missing changes from refactoring branch)

332 files changed:
CMakeLists.txt
packaging/wrt-plugins-tizen.spec
packaging/wrt-plugins-tizen.spec.orig [deleted file]
pkgconfigs/wrt-plugins-tizen-systeminfo.pc.in [changed mode: 0644->0755]
src/Alarm/JSAlarmAbsolute.cpp
src/Alarm/JSAlarmManager.cpp
src/Alarm/JSAlarmManager.h
src/Alarm/JSAlarmRelative.cpp
src/Alarm/plugin_initializer.cpp
src/Application/ApplicationConverter.cpp
src/Application/ApplicationManager.cpp
src/Application/ApplicationManager.h
src/Application/EventApplicationGetAppSharedURI.h [new file with mode: 0644]
src/Application/IApplicationManager.cpp
src/Application/IApplicationManager.h
src/Application/JSApplication.cpp
src/Application/JSApplication.h
src/Application/JSApplicationCert.cpp
src/Application/JSApplicationContext.cpp
src/Application/JSApplicationContext.h
src/Application/JSApplicationControl.cpp
src/Application/JSApplicationControl.h
src/Application/JSApplicationControlData.cpp
src/Application/JSApplicationControlData.h
src/Application/JSApplicationInformation.cpp
src/Application/JSApplicationInformation.h
src/Application/JSApplicationManager.cpp [changed mode: 0755->0644]
src/Application/JSApplicationManager.h
src/Application/plugin_config.h
src/Application/plugin_initializer.cpp
src/Bluetooth/BTDevice.h [deleted file]
src/Bluetooth/BluetoothAdapter.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothAdapter.h [new file with mode: 0644]
src/Bluetooth/BluetoothAdapterListener.cpp [deleted file]
src/Bluetooth/BluetoothAdapterListener.h [deleted file]
src/Bluetooth/BluetoothAdapterManager.cpp [deleted file]
src/Bluetooth/BluetoothAdapterManager.h [deleted file]
src/Bluetooth/BluetoothCBManager.cpp [deleted file]
src/Bluetooth/BluetoothCBManager.h [deleted file]
src/Bluetooth/BluetoothCallbackUtil.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothCallbackUtil.h [new file with mode: 0644]
src/Bluetooth/BluetoothClass.cpp
src/Bluetooth/BluetoothClass.h
src/Bluetooth/BluetoothClassDeviceMajor.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothClassDeviceMajor.h [moved from src/Bluetooth/EventBTGetDevice.h with 52% similarity]
src/Bluetooth/BluetoothClassDeviceMinor.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothClassDeviceMinor.h [moved from src/Bluetooth/EventBTSetName.h with 53% similarity]
src/Bluetooth/BluetoothClassDeviceService.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothClassDeviceService.h [new file with mode: 0644]
src/Bluetooth/BluetoothConverter.cpp [deleted file]
src/Bluetooth/BluetoothConverter.h [deleted file]
src/Bluetooth/BluetoothDevice.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothDevice.h [new file with mode: 0644]
src/Bluetooth/BluetoothDeviceManager.cpp [deleted file]
src/Bluetooth/BluetoothDeviceManager.h [deleted file]
src/Bluetooth/BluetoothDeviceManagerListener.cpp [deleted file]
src/Bluetooth/BluetoothDeviceManagerListener.h [deleted file]
src/Bluetooth/BluetoothFactory.cpp [deleted file]
src/Bluetooth/BluetoothFactory.h [deleted file]
src/Bluetooth/BluetoothMultiCallback.cpp [deleted file]
src/Bluetooth/BluetoothMultiCallback.h [deleted file]
src/Bluetooth/BluetoothProperty.h [deleted file]
src/Bluetooth/BluetoothServiceHandler.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothServiceHandler.h [new file with mode: 0644]
src/Bluetooth/BluetoothServiceHandlerManager.cpp [deleted file]
src/Bluetooth/BluetoothServiceHandlerManager.h [deleted file]
src/Bluetooth/BluetoothSocket.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothSocket.h [new file with mode: 0644]
src/Bluetooth/BluetoothSocketListener.cpp [deleted file]
src/Bluetooth/BluetoothSocketListener.h [deleted file]
src/Bluetooth/BluetoothSocketManager.cpp [deleted file]
src/Bluetooth/BluetoothSocketManager.h [deleted file]
src/Bluetooth/CMakeLists.txt [changed mode: 0755->0644]
src/Bluetooth/EventBTConnectToServiceByUUID.h [deleted file]
src/Bluetooth/EventBTCreateDestroyBonding.cpp [deleted file]
src/Bluetooth/EventBTCreateDestroyBonding.h [deleted file]
src/Bluetooth/EventBTGetAdapter.h [deleted file]
src/Bluetooth/EventBTGetDevice.cpp [deleted file]
src/Bluetooth/EventBTGetKnownDevices.cpp [deleted file]
src/Bluetooth/EventBTGetKnownDevices.h [deleted file]
src/Bluetooth/EventBTOnDiscoveryDevices.cpp [deleted file]
src/Bluetooth/EventBTOnDiscoveryDevices.h [deleted file]
src/Bluetooth/EventBTRegisterRFCOMM.h [deleted file]
src/Bluetooth/EventBTServiceOnConnect.cpp [deleted file]
src/Bluetooth/EventBTServiceOnConnect.h [deleted file]
src/Bluetooth/EventBTSetPowered.h [deleted file]
src/Bluetooth/EventBTSetVisible.h [deleted file]
src/Bluetooth/EventBTSocketNotification.cpp [deleted file]
src/Bluetooth/EventBTSocketNotification.h [deleted file]
src/Bluetooth/EventBTStopDiscovery.h [deleted file]
src/Bluetooth/EventBTUnregisterRFCOMM.h [deleted file]
src/Bluetooth/IBluetoothAdapterManager.cpp [deleted file]
src/Bluetooth/IBluetoothAdapterManager.h [deleted file]
src/Bluetooth/IBluetoothDeviceManager.cpp [deleted file]
src/Bluetooth/IBluetoothDeviceManager.h [deleted file]
src/Bluetooth/IBluetoothServiceHandlerManager.cpp [deleted file]
src/Bluetooth/IBluetoothServiceHandlerManager.h [deleted file]
src/Bluetooth/IBluetoothSocketManager.cpp [deleted file]
src/Bluetooth/IBluetoothSocketManager.h [deleted file]
src/Bluetooth/JSBluetoothAdapter.cpp
src/Bluetooth/JSBluetoothAdapter.h
src/Bluetooth/JSBluetoothClass.cpp
src/Bluetooth/JSBluetoothClass.h
src/Bluetooth/JSBluetoothClassDeviceMajor.cpp
src/Bluetooth/JSBluetoothClassDeviceMajor.h
src/Bluetooth/JSBluetoothClassDeviceMinor.cpp
src/Bluetooth/JSBluetoothClassDeviceMinor.h
src/Bluetooth/JSBluetoothClassDeviceService.cpp
src/Bluetooth/JSBluetoothClassDeviceService.h
src/Bluetooth/JSBluetoothDevice.cpp
src/Bluetooth/JSBluetoothDevice.h
src/Bluetooth/JSBluetoothManager.cpp
src/Bluetooth/JSBluetoothManager.h
src/Bluetooth/JSBluetoothServiceHandler.cpp
src/Bluetooth/JSBluetoothServiceHandler.h
src/Bluetooth/JSBluetoothSocket.cpp
src/Bluetooth/JSBluetoothSocket.h
src/Bluetooth/config.xml
src/Bluetooth/plugin_config.cpp
src/Bluetooth/plugin_config.h
src/Bluetooth/plugin_initializer.cpp
src/Bookmark/JSBookmarkFolder.cpp
src/Bookmark/JSBookmarkItem.cpp
src/Bookmark/JSBookmarkManager.cpp
src/CMakeLists.txt
src/Calendar/CalendarConverter.cpp
src/Calendar/CalendarConverter.h
src/Calendar/CalendarEvent.h
src/Calendar/CalendarFilter.cpp
src/Calendar/CalendarFilter.h
src/Calendar/CalendarFilterConverter.cpp [changed mode: 0644->0755]
src/Calendar/CalendarFilterConverter.h [changed mode: 0644->0755]
src/Calendar/EventWrapper.cpp
src/Calendar/JSCalendarItemProperties.cpp
src/Calendar/JSCalendarRecurrenceRule.cpp
src/Callhistory/JSCallHistory.cpp
src/Callhistory/JSCallHistoryEntry.cpp
src/Callhistory/JSRemoteParty.cpp
src/Callhistory/JSRemoteParty.h
src/Common/ArgumentValidator.cpp [changed mode: 0755->0644]
src/Common/ArgumentValidator.h [changed mode: 0755->0644]
src/Common/CMakeLists.txt
src/Common/JSTizenExceptionFactory.cpp
src/Common/JSUtil.cpp [changed mode: 0755->0644]
src/Common/JSUtil.h [changed mode: 0755->0644]
src/Common/JSWebAPIException.cpp [new file with mode: 0644]
src/Common/JSWebAPIException.h [new file with mode: 0644]
src/Common/PlatformException.cpp
src/Common/PlatformException.h
src/Common/TimeTracer/CMakeLists.txt
src/Common/TimeTracer/TimeTracer.c
src/Common/TimeTracer/TimeTracer.h
src/Contact/Contact.cpp
src/Contact/Contact.h
src/Contact/ContactAddress.cpp
src/Contact/ContactAddress.h
src/Contact/ContactConverter.cpp
src/Contact/ContactConverter.h
src/Contact/ContactEmailAddress.cpp
src/Contact/ContactEmailAddress.h
src/Contact/ContactName.cpp
src/Contact/ContactName.h
src/Contact/ContactPhoneNumber.cpp
src/Contact/ContactPhoneNumber.h
src/Contact/JSAddressBook.cpp
src/Contact/JSContact.cpp
src/Contact/JSContactAddress.cpp
src/Contact/JSContactAnniversary.cpp
src/Contact/JSContactEmailAddress.cpp
src/Contact/JSContactGroup.cpp
src/Contact/JSContactName.cpp
src/Contact/JSContactPhoneNumber.cpp
src/Contact/JSContactWebSite.cpp
src/Content/ContentConverter.cpp
src/Content/ContentListener.cpp
src/Content/IContentManager.cpp
src/Content/JSAudio.cpp
src/Content/JSContent.cpp
src/Content/JSContentManager.cpp
src/Content/JSFolder.cpp
src/Content/JSImage.cpp
src/Content/JSVideo.cpp
src/DataControl/DataControlConverter.cpp
src/DataControl/DataControlConverter.h
src/DataSync/DataSyncManager.cpp
src/DataSync/DataSyncManager.h
src/Download/DownloadCallback.cpp
src/Download/JSDownloadManager.cpp
src/Filesystem/Enums.h
src/Filesystem/Manager.cpp
src/MessagePort/CMakeLists.txt
src/MessagePort/JSLocalMessagePort.cpp
src/MessagePort/JSMessagePortManager.cpp
src/MessagePort/JSRemoteMessagePort.cpp
src/MessagePort/LocalMessagePortController.cpp
src/MessagePort/MessagePortConverter.cpp [deleted file]
src/MessagePort/MessagePortConverter.h [deleted file]
src/MessagePort/MessagePortDataItem.h
src/MessagePort/MessagePortJSUtil.cpp [new file with mode: 0644]
src/MessagePort/MessagePortJSUtil.h [new file with mode: 0644]
src/MessagePort/plugin_config.cpp [deleted file]
src/MessagePort/plugin_config.h [deleted file]
src/Messaging/ConverterMessage.cpp
src/Messaging/ConverterMessage.h
src/Messaging/JSConversation.cpp
src/Messaging/JSConversation.h
src/Messaging/JSMessage.cpp
src/Messaging/JSMessage.h
src/Messaging/JSMessageAttachment.cpp
src/Messaging/JSMessageAttachment.h
src/Messaging/JSMessageBody.cpp
src/Messaging/JSMessageBody.h
src/Messaging/JSMessageFolder.cpp
src/Messaging/JSMessageFolder.h
src/Messaging/JSMessagingService.cpp
src/Messaging/JSMessagingService.h
src/Messaging/JSMessagingServiceManager.cpp
src/Messaging/JSMessagingStorage.cpp
src/Messaging/JSMessagingStorage.h
src/Messaging/MessagingListener.cpp
src/Messaging/ReqReceiverMessage.cpp
src/Messaging/plugin_initializer.cpp
src/NFC/CMakeLists.txt
src/NFC/EventTagAction.h
src/NFC/EventTargetAction.h
src/NFC/INdefMessage.h
src/NFC/INdefRecord.h
src/NFC/JSNFCAdapter.cpp
src/NFC/JSNFCManager.cpp
src/NFC/JSNFCManager.h
src/NFC/JSNFCTag.cpp
src/NFC/JSNFCTarget.cpp
src/NFC/JSNdefMessage.cpp
src/NFC/JSNdefMessage.h
src/NFC/JSNdefRecord.cpp
src/NFC/JSNdefRecord.h
src/NFC/JSNdefRecordArray.cpp [deleted file]
src/NFC/JSNdefRecordArray.h [deleted file]
src/NFC/JSNdefRecordMedia.cpp
src/NFC/JSNdefRecordMedia.h
src/NFC/JSNdefRecordText.cpp
src/NFC/JSNdefRecordText.h
src/NFC/JSNdefRecordURI.cpp
src/NFC/JSNdefRecordURI.h
src/NFC/NFCAdapter.cpp
src/NFC/NFCConverter.cpp
src/NFC/NFCConverter.h
src/NFC/NFCDefaultAdapter.cpp
src/NFC/NFCDefaultAdapter.h
src/NFC/NFCStaticController.cpp
src/NFC/NFCTag.cpp
src/NFC/NFCTarget.cpp
src/NFC/NFCUtil.cpp
src/NFC/NFCUtil.h
src/NFC/NdefMessage.cpp
src/NFC/NdefMessage.h
src/NFC/NdefRecord.cpp
src/NFC/NdefRecord.h
src/NFC/plugin_initializer.cpp
src/NetworkBearerSelection/NetworkBearerSelection.cpp
src/NetworkBearerSelection/NetworkBearerSelection.h
src/NetworkBearerSelection/NetworkBearerSelectionResponseDispatcher.cpp
src/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h
src/Notification/CMakeLists.txt
src/Notification/INotification.cpp [deleted file]
src/Notification/INotification.h [deleted file]
src/Notification/INotificationManager.cpp [deleted file]
src/Notification/INotificationManager.h [deleted file]
src/Notification/JSNotificationDetailInfo.cpp [new file with mode: 0755]
src/Notification/JSNotificationDetailInfo.h [new file with mode: 0755]
src/Notification/JSNotificationLine.cpp [deleted file]
src/Notification/JSNotificationLine.h [deleted file]
src/Notification/JSNotificationLineArray.cpp [deleted file]
src/Notification/JSNotificationLineArray.h [deleted file]
src/Notification/JSNotificationManager.cpp [changed mode: 0644->0755]
src/Notification/JSNotificationManager.h [changed mode: 0755->0644]
src/Notification/JSStatusNotification.cpp
src/Notification/JSStatusNotification.h
src/Notification/JSStringArray.cpp [deleted file]
src/Notification/JSStringArray.h [deleted file]
src/Notification/NotificationConverter.cpp [deleted file]
src/Notification/NotificationConverter.h [deleted file]
src/Notification/NotificationDetailInfo.cpp [new file with mode: 0755]
src/Notification/NotificationDetailInfo.h [new file with mode: 0755]
src/Notification/NotificationFactory.cpp [deleted file]
src/Notification/NotificationFactory.h [deleted file]
src/Notification/NotificationLine.h [deleted file]
src/Notification/NotificationManager.cpp
src/Notification/NotificationManager.h
src/Notification/NotificationTypes.h [new file with mode: 0755]
src/Notification/StatusNotification.cpp
src/Notification/StatusNotification.h
src/Notification/config.xml
src/Notification/plugin_config.cpp [changed mode: 0644->0755]
src/Notification/plugin_config.h [changed mode: 0644->0755]
src/Notification/plugin_initializer.cpp
src/Package/JSPackageInformation.cpp
src/Package/JSPackageInformation.h
src/Package/JSPackageManager.cpp
src/Package/PackageManager.cpp
src/Power/JSPowerManager.cpp
src/Push/JSPushManager.cpp
src/Push/PushManager.cpp
src/SecureElement/ISEService.h
src/SecureElement/JSSEChannel.cpp
src/SecureElement/JSSEReader.cpp
src/SecureElement/JSSEService.cpp
src/SecureElement/JSSESession.cpp
src/SecureElement/SEListenerManager.h
src/SecureElement/SEService.cpp
src/SecureElement/SEService.h
src/Systeminfo/CMakeLists.txt
src/Systeminfo/JSCellularNetworkInfo.cpp
src/Systeminfo/JSDeviceCapabilitiesInfo.cpp
src/Systeminfo/JSSIMInfo.cpp
src/Systeminfo/Systeminfo.cpp
src/Systeminfo/Systeminfo.h
src/Systeminfo/SysteminfoPropertyInfo.h
src/Systeminfo/plugin_config.cpp
src/Systeminfo/plugin_config.h
src/TimeUtil/JSTZDate.cpp
src/TimeUtil/JSTimeDuration.cpp
src/TimeUtil/JSTimeUtil.cpp
src/Tizen/AnyFactory.cpp
src/Tizen/AnyType.cpp
src/Tizen/AnyType.h
src/Tizen/JSAttributeFilter.cpp
src/Tizen/JSAttributeRangeFilter.cpp
src/Tizen/JSCompositeFilter.cpp
src/Tizen/JSCompositeFilter.h
src/Tizen/JSSimpleCoordinates.cpp
src/Tizen/JSSortMode.cpp

index 35a819d..7238d33 100755 (executable)
@@ -36,6 +36,19 @@ ELSE(DPL_LOG)
 ENDIF(DPL_LOG)
 
 # -----------------------------------------------------------------------------
+# Determine the time tracing option
+# -----------------------------------------------------------------------------
+
+OPTION(ENABLE_TIME_TRACER "TIME TRACING" OFF)
+
+IF(ENABLE_TIME_TRACER)
+    MESSAGE(STATUS "Time tracer enabled")
+    ADD_DEFINITIONS("-DENABLE_TIME_TRACER")
+ELSE(ENABLE_TIME_TRACER)
+    MESSAGE(STATUS "Time tracer disabled")
+ENDIF(ENABLE_TIME_TRACER)
+
+# -----------------------------------------------------------------------------
 # Set build type (Release by default)
 # -----------------------------------------------------------------------------
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
@@ -78,6 +91,14 @@ SET(DESTINATION_HEADER_PREFIX include/${PROJECT_NAME})
 
 SET(TOP ${CMAKE_SOURCE_DIR}/src)
 
+SET(INCLUDE_COMMON ${TOP}/Common)
+
+IF(ENABLE_TIME_TRACER)
+SET(INCLUDE_COMMON ${TOP}/Common ${TOP}/Common/TimeTracer)
+ELSE(ENABLE_TIME_TRACER)
+SET(INCLUDE_COMMON ${SRC}/Common)
+ENDIF(ENABLE_TIME_TRACER)
+
 SET(LIBS_COMMON
     ${dpl_LDFLAGS}
     ${dpl-event_LDFLAGS}
index 157e72b..5e114c2 100755 (executable)
@@ -1,7 +1,7 @@
 Name:       wrt-plugins-tizen
 Summary:    JavaScript plugins for WebRuntime
-Version:    0.4.14
-Release:    1
+Version:    0.4.15
+Release:    0
 Group:      Development/Libraries
 License:    Apache License, Version 2.0
 Source0:    %{name}-%{version}.tar.gz
@@ -42,6 +42,7 @@ BuildRequires:  pkgconfig(capi-telephony-call)
 BuildRequires:  pkgconfig(capi-telephony-sim)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(capi-system-runtime-info)
+BuildRequires:  pkgconfig(capi-telephony-network-info)
 BuildRequires:  pkgconfig(sensor)
 BuildRequires:  pkgconfig(capi-system-sensor)
 BuildRequires:  pkgconfig(capi-system-power)
@@ -88,7 +89,7 @@ Wrt-plugin-tizen development headers
 
 export LDFLAGS+="-Wl,--rpath=%{PREFIX} -Wl,--as-needed"
 
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DDPL_LOG="ON"
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DDPL_LOG="ON" -DENABLE_TIME_TRACER="OFF"
 
 make %{?jobs:-j%jobs}
 
diff --git a/packaging/wrt-plugins-tizen.spec.orig b/packaging/wrt-plugins-tizen.spec.orig
deleted file mode 100755 (executable)
index 1781190..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-Name:       wrt-plugins-tizen
-Summary:    JavaScript plugins for WebRuntime
-<<<<<<< HEAD
-Version:    0.4.8
-=======
-Version:    0.4.9
->>>>>>> f5f8121... Update change log and spec for wrt-plugins-tizen_0.4.9
-Release:    0
-Group:      Development/Libraries
-License:    Apache License, Version 2.0
-Source0:    %{name}-%{version}.tar.gz
-BuildRequires:  pkgconfig(capi-web-favorites)
-BuildRequires:  pkgconfig(mm-fileinfo)
-BuildRequires:  pkgconfig(libpcrecpp)
-BuildRequires:  pkgconfig(calendar-service2)
-BuildRequires:  pkgconfig(contacts-service2)
-BuildRequires:  pkgconfig(msg-service)
-BuildRequires:  pkgconfig(email-service)
-BuildRequires:  pkgconfig(accounts-svc)
-BuildRequires:  pkgconfig(tapi)
-BuildRequires:  pkgconfig(icu-i18n)
-BuildRequires:  pkgconfig(icu-io)
-BuildRequires:  pkgconfig(icu-le)
-BuildRequires:  pkgconfig(icu-lx)
-BuildRequires:  pkgconfig(icu-uc)
-BuildRequires:  pkgconfig(network)
-BuildRequires:  pkgconfig(appsvc)
-BuildRequires:  pkgconfig(devman)
-BuildRequires:  pkgconfig(ewebkit2)
-BuildRequires:  pkgconfig(dpl-efl)
-BuildRequires:  pkgconfig(dpl-event-efl)
-BuildRequires:  pkgconfig(wrt-plugins-types)
-BuildRequires:  pkgconfig(wrt-plugins-commons)
-BuildRequires:  pkgconfig(wrt-plugins-commons-javascript)
-BuildRequires:  pkgconfig(wrt-plugins-plugin-manager)
-BuildRequires:  pkgconfig(capi-appfw-application)
-BuildRequires:  pkgconfig(capi-appfw-app-manager)
-BuildRequires:  pkgconfig(capi-network-nfc)
-BuildRequires:  pkgconfig(capi-location-geocoder)
-BuildRequires:  pkgconfig(capi-location-manager)
-BuildRequires:  pkgconfig(capi-location-poi)
-BuildRequires:  pkgconfig(capi-location-route)
-BuildRequires:  pkgconfig(capi-network-bluetooth)
-BuildRequires:  pkgconfig(capi-network-connection)
-BuildRequires:  pkgconfig(capi-telephony-call)
-BuildRequires:  pkgconfig(capi-telephony-sim)
-BuildRequires:  pkgconfig(capi-system-info)
-BuildRequires:  pkgconfig(capi-system-runtime-info)
-BuildRequires:  pkgconfig(sensor)
-BuildRequires:  pkgconfig(capi-system-sensor)
-BuildRequires:  pkgconfig(capi-system-power)
-BuildRequires:  pkgconfig(pmapi)
-BuildRequires:  pkgconfig(capi-system-system-settings)
-BuildRequires:  pkgconfig(capi-system-device)
-BuildRequires:  pkgconfig(capi-content-media-content)
-BuildRequires:  pkgconfig(capi-media-metadata-extractor)
-BuildRequires:  pkgconfig(smartcard-service-common)
-BuildRequires:  pkgconfig(smartcard-service)
-BuildRequires:  pkgconfig(pkgmgr)
-BuildRequires:  pkgconfig(pkgmgr-info)
-BuildRequires:  pkgconfig(capi-appfw-package-manager)
-BuildRequires:  pkgconfig(capi-web-url-download)
-BuildRequires:  pkgconfig(push)
-BuildRequires:  pkgconfig(notification)
-BuildRequires:  pkgconfig(message-port)
-BuildRequires:  pkgconfig(sync-agent)
-BuildRequires:  expat-devel
-BuildRequires:  cmake
-BuildRequires:  gettext-devel
-BuildRequires:  boost-devel
-BuildRequires:  boost-thread
-BuildRequires:  boost-system
-BuildRequires:  boost-filesystem
-
-%description
-JavaScript plugins for WebRuntime
-
-%package devel
-Summary:    Wrt-plugin-tizen development headers
-Group:      Development/Libraries
-Requires:   %{name} = %{version}
-
-%description devel
-Wrt-plugin-tizen development headers
-
-%prep
-%setup -q
-
-%build
-
-%define PREFIX "%{_libdir}/wrt-plugins"
-
-export LDFLAGS+="-Wl,--rpath=%{PREFIX} -Wl,--as-needed"
-
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DDPL_LOG="ON"
-
-make %{?jobs:-j%jobs}
-
-%install
-rm -rf %{buildroot}
-%make_install
-
-%post
-
-%postun
-
-
-%files
-%manifest wrt-plugins-tizen.manifest 
-%{_libdir}/wrt-plugins/*
-/usr/etc/tizen-apis/*
-
-%files devel
-%{_includedir}/*
-%{_libdir}/pkgconfig/*
old mode 100644 (file)
new mode 100755 (executable)
index 4219c95..d322e18
@@ -8,6 +8,6 @@ includedir=${prefix}/include/${project_name}
 Name: wrt-plugins-tizen-${module_name}
 Description: wrt-plugins-tizen-${module_name}
 Version: @CMAKE_PROJECT_VERSION@
-Requires: capi-telephony-sim capi-network-connection capi-system-info capi-system-runtime-info capi-system-sensor sensor
+Requires: capi-telephony-sim capi-network-connection capi-system-info capi-system-runtime-info capi-system-sensor sensor capi-telephony-network-info
 Libs: -L${libdir} -lwrt-plugins-tizen-${module_name}-impl
 Cflags: -I${includedir}/${module_name}
\ No newline at end of file
index 306f4c4..882ea1f 100755 (executable)
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+
 #include <Commons/Exception.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
@@ -59,8 +63,8 @@ JSClassDefinition JSAlarmAbsolute::m_jsClassInfo = {
                NULL, //deleteProperty,Geolocation
                NULL, //getPropertyNames,
                NULL,
-               constructor, // constructor
-               hasInstance,
+               NULL, // constructor
+               NULL,
                NULL
 };
 
@@ -110,80 +114,59 @@ bool JSAlarmAbsolute::hasInstance(JSContextRef context, JSObjectRef constructor,
 
 JSObjectRef JSAlarmAbsolute::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-    struct tm date;
-    AlarmConverter converter(ctx);
-    Validator validator(ctx);
-
-    Try {        
-        AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute());
-
-        if(argumentCount < 1)
-        {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-        }
-
-        if(!validator.isDate(arguments[0]))
-        {
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-        }
-
-        date = converter.toDateTm(arguments[0]);
-        privateData->setDate(date);
-
-        if(argumentCount >= 2)
-        {
-            if(JSIsArrayValue(ctx, arguments[1])) {
-                std::vector<std::string> daysOfTheWeek = converter.toVectorOfStrings(arguments[1]);
-
-                for( int i = 0; i< daysOfTheWeek.size(); i++ )
-                {
-                    if( (daysOfTheWeek[i]!="SU") && (daysOfTheWeek[i]!="MO") &&
-                        (daysOfTheWeek[i]!="TU") && (daysOfTheWeek[i]!="WE") &&
-                        (daysOfTheWeek[i]!="TH") && (daysOfTheWeek[i]!="FR") &&
-                        (daysOfTheWeek[i]!="SA") ) {
-                        ThrowMsg(ConversionException, "Invalid days of the week value.");
+    try {
+        AlarmAbsolutePtr priv = AlarmAbsolutePtr(new AlarmAbsolute());
+               if (!priv) {
+                       throw TypeMismatchException("Private object is null");
+               }
+
+               ArgumentValidator validator(ctx, argumentCount, arguments);     
+               time_t date = validator.toTimeT(0);
+               struct tm *startDate = localtime(&date);
+               mktime(startDate);
+               
+               priv->setDate(*startDate);
+
+               if (argumentCount >= 2) {
+                       if (JSIsArrayValue(ctx, arguments[1])) {
+                               std::vector<std::string> daysOfTheWeek =  validator.toStringVector(1);
+
+                for (int i = 0; i < daysOfTheWeek.size(); i++ ) {
+                    if ( (daysOfTheWeek[i]!="SU") && (daysOfTheWeek[i]!="MO") &&
+                         (daysOfTheWeek[i]!="TU") && (daysOfTheWeek[i]!="WE") &&
+                         (daysOfTheWeek[i]!="TH") && (daysOfTheWeek[i]!="FR") &&
+                         (daysOfTheWeek[i]!="SA") ) {
+                        throw TypeMismatchException("Invalid days of the week value.");
                     }
                 }
 
                 if(daysOfTheWeek.size() > 0) {
-                    privateData->setByDayRecurrence(daysOfTheWeek);    
-                }
-            } else {
-                int interval  = converter.toInt(arguments[1]);
-                if(interval <0) {
-                                       ThrowMsg(InvalidArgumentException, "Invalid period value.");
+                    priv->setByDayRecurrence(daysOfTheWeek);    
                 }
-                privateData->setInterval(interval);
-            }
-        }
-
-        return JSValueToObject(ctx, createJSObject(ctx, privateData), exception);
-       } Catch(ConversionException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch(UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       } Catch(InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch(Exception) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-    return NULL;
+                       } else {
+                               long long interval = validator.toLongLong(1);
+                               priv->setInterval(interval);
+                       }
+               }
+
+               return JSValueToObject(ctx, createJSObject(ctx, priv), exception);
+
+    } catch (const BasePlatformException& err) {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(ctx, err);
+               *exception = exceptionObj;
+               return exceptionObj;
+    }
 }
 
 AlarmAbsolutePtr JSAlarmAbsolute::getPrivData(JSObjectRef object)
 {
     JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(object));
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     AlarmAbsolutePtr result = priv->getObject();
     if (!result) {
-               ThrowMsg(ConversionException, "Private object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return result;
 }
@@ -195,7 +178,7 @@ JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, const int id)
     
     JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return  JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
 }
@@ -204,7 +187,7 @@ JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, AlarmAbsolutePt
 {
     JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
 }
@@ -216,7 +199,7 @@ JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, struct tm date,
 
     JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
 }
@@ -228,43 +211,37 @@ JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, struct tm date)
 
     JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
 }
 
 JSValueRef JSAlarmAbsolute::getNextScheduledDate( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception)
 {   
-    LogError("GContext = " << DeviceAPI::Alarm::JSAlarmManager::gContext);
-
-    struct tm date;
-    Converter converter(ctx);
-    int id;
-    Try
-    {
+       try {
+           struct tm date;
+           Converter converter(ctx);
+               
         AlarmAbsolutePtr privateData = getPrivData(thisObject);
-        id = privateData->getId(); 
+               if (!privateData) {
+                       throw TypeMismatchException("Private object is null");
+           }
+               
+        int id = privateData->getId(); 
         int err = alarm_get_scheduled_date(id, &date);
         JSValueRef result = converter.toJSValueRef(date);
 
-        if(err != ALARM_ERROR_NONE)
-        {
+        if(err != ALARM_ERROR_NONE) {
             return JSValueMakeNull(ctx);
         }
         return result;
-       } Catch(ConversionException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch(UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       } Catch(InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch(Exception) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(ctx, exception, err);
+    }
 }
 
 JSValueRef JSAlarmAbsolute::getDate(JSContextRef ctx,
@@ -274,9 +251,13 @@ JSValueRef JSAlarmAbsolute::getDate(JSContextRef ctx,
 {
     Converter converter(ctx);
     struct tm date;
-    Try
-    {
+
+       try {
         AlarmAbsolutePtr privateData = getPrivData(object);
+               if (!privateData) {
+                       throw TypeMismatchException("Private object is null");
+           }
+               
         date = privateData->getDate();
         LogInfo("JSAlarmAbsolute Date  = " << "  Sec : " << date.tm_sec << "  Min : "<< date.tm_min
         << "  Hour" << date.tm_hour << "Day : " << date.tm_mday << "  MON : " << date.tm_mon 
@@ -292,11 +273,10 @@ JSValueRef JSAlarmAbsolute::getDate(JSContextRef ctx,
 
         JSObjectRef result = JSObjectMakeDate(ctx, 6, args, exception);
         return result;
+    } catch (...) {
+       LogWarning("Exception: occured");
     }
-       Catch(Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
+
        return JSValueMakeUndefined(ctx);
 }
 
@@ -305,24 +285,24 @@ JSValueRef JSAlarmAbsolute::getId(JSContextRef ctx,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-    Converter converter(ctx);
-    int id;
-    Try
-    {
+       try {
         AlarmAbsolutePtr privateData = getPrivData(object);
+               if (!privateData) {
+                       throw TypeMismatchException("Private object is null");
+           }
+               
         Converter converter(ctx);
-        id = privateData->getId();
+        int id = privateData->getId();
         if(id >= 0) {
             std::string strId = converter.toString(id);
             return converter.toJSValueRef(strId);
         } else {
             return JSValueMakeNull(ctx);
         }
-       }
-       Catch(Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
+       } catch (...) {
+       LogWarning("Exception: occured");
+    }
+
        return JSValueMakeUndefined(ctx);
 }
 
@@ -331,24 +311,21 @@ JSValueRef JSAlarmAbsolute::getInterval(JSContextRef ctx,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-    Converter converter(ctx);
-    int interval;
-     Try
-    {
+       try {
         AlarmAbsolutePtr privateData = getPrivData(object);
         AbsoluteRecurrence::Type alarmType = privateData->getRecurrenceType();
        
         if(alarmType == AbsoluteRecurrence::Interval) {
-            interval = privateData->getInterval();
+                   Converter converter(ctx);
+            int interval = privateData->getInterval();
             return converter.toJSValueRef(interval);
         } else {
             return JSValueMakeNull(ctx);    
         }
+    } catch (...) {
+       LogWarning("Exception: occured");
     }
-       Catch(Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
+
        return JSValueMakeUndefined(ctx);
 }
 
@@ -359,34 +336,33 @@ JSValueRef JSAlarmAbsolute::getDaysOfTheWeek(JSContextRef ctx,
 {
     Converter converter(ctx);
     
-    Try {
-        JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
+    try {
         AlarmAbsolutePtr privateData = getPrivData(object);
-        std::vector<std::string> daysOfTheWeek = privateData->getByDayRecurrence();
+               if (!privateData) {
+                       throw TypeMismatchException("Private object is null");
+           }
 
-        if(daysOfTheWeek.size() >0)
-        {
-            if (jsResult == NULL) 
-            {
-                ThrowMsg(NullPointerException, "Could not create js array object");
-            }
+        JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
+               if (jsResult == NULL) {
+                       throw UnknownException("Could not create js array object");
+        }
+               
+        std::vector<std::string> daysOfTheWeek = privateData->getByDayRecurrence();
 
-            for(unsigned int i=0; i<daysOfTheWeek.size(); i++) 
-            {
+        if(daysOfTheWeek.size() > 0) {
+            for(unsigned int i=0; i<daysOfTheWeek.size(); i++) {
                 JSValueRef val = converter.toJSValueRef(daysOfTheWeek.at(i));
-                if(!JSSetArrayElement(ctx, jsResult, i, val)) 
-                {
-                    ThrowMsg(UnknownException, "Could not insert value into js array");
+                if(!JSSetArrayElement(ctx, jsResult, i, val)) {
+                                       throw UnknownException("Could not insert value into js array");
                 }
             }
         }
 
         return jsResult;
-       }
-       Catch(Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
+       } catch (...) {
+       LogWarning("Exception: occured");
+    }
+
        return JSValueMakeUndefined(ctx);
 }
 
index d662dbd..6652e60 100755 (executable)
 //
 
 
-#include <dpl/log/log.h>
 #include <vector>
 #include <app.h>
 #include <time.h>
+#include <string>
+
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
 #include <SecurityExceptions.h>
 #include <Commons/Exception.h>
 #include <Commons/Regex.h>
@@ -43,6 +49,8 @@
 #include "AlarmRelative.h"
 #include "JSAlarmManager.h"
 
+#include <Logger.h>
+
 namespace DeviceAPI {
 namespace Alarm {
 
@@ -76,7 +84,7 @@ JSClassDefinition JSAlarmManager::m_jsClassInfo = {
         NULL, //getPropertyNames,
         NULL,
         NULL, // constructor
-        hasInstance,
+        NULL,
         NULL
 };
 
@@ -90,10 +98,10 @@ JSStaticFunction JSAlarmManager::m_function[] = {
 };
 
 JSStaticValue JSAlarmManager::m_property[] = {
-               { TIZEN_ALARM_CONSTANT_PERIOD_MINUTE, getMin, NULL, kJSPropertyAttributeReadOnly },
-               { TIZEN_ALARM_CONSTANT_PERIOD_HOUR, getHour, NULL, kJSPropertyAttributeReadOnly },
-               { TIZEN_ALARM_CONSTANT_PERIOD_DAY, getDay, NULL, kJSPropertyAttributeReadOnly },
-               { TIZEN_ALARM_CONSTANT_PERIOD_WEEK, getWeek, NULL, kJSPropertyAttributeReadOnly },
+               { TIZEN_ALARM_CONSTANT_PERIOD_MINUTE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+               { TIZEN_ALARM_CONSTANT_PERIOD_HOUR, getProperty, NULL, kJSPropertyAttributeReadOnly },
+               { TIZEN_ALARM_CONSTANT_PERIOD_DAY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+               { TIZEN_ALARM_CONSTANT_PERIOD_WEEK, getProperty, NULL, kJSPropertyAttributeReadOnly },
                { 0, 0, 0, 0 }
 };
 
@@ -138,6 +146,121 @@ JSValueRef JSAlarmManager::add(JSContextRef ctx, JSObjectRef object, JSObjectRef
        AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_ADD);
        TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
 
+       try {
+               ArgumentValidator validator(ctx, argumentCount, arguments);
+               AlarmConverter converter(ctx);
+               
+               // applicationId
+               std::string appId = validator.toString(1);
+               LogDebug("appId:[" << appId << "]");
+
+               // alarm
+        JSObjectRef alarmObj = validator.toObject(0);
+               if (JSValueIsObjectOfClass(ctx, alarmObj, JSAlarmAbsolute::getClassRef())) {
+
+                       JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(alarmObj));
+                       if (!priv) {
+                               throw TypeMismatchException("Object is null.");
+                       }
+                       AlarmAbsolutePtr alarmPtr = priv->getObject();
+                       if (!alarmPtr) {
+                               throw TypeMismatchException("Private object is null.");
+                       }
+       
+                       startDate = alarmPtr->getDate();
+                       service = alarmPtr->getService();
+                       service_set_app_id(service, appId.c_str());
+                       
+                       // appControl
+                       JSObjectRef appControlObj = validator.toObject(2, true);
+                       if (appControlObj) {
+                               if(!JSValueIsObjectOfClass(ctx, appControlObj, DeviceAPI::Application::JSApplicationControl::getClassRef())) {
+                                       throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+                               }
+                               DeviceAPI::Application::ApplicationConverter applicationConverter(ctx);
+                               DeviceAPI::Application::ApplicationControlPtr appService = applicationConverter.toApplicationControl(appControlObj);
+                               if(converter.toAlarmService(service, appService) == false) {
+                                       throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+                               }
+                       } else {
+                               service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+                       }
+
+                       AbsoluteRecurrence::Type alarmType = alarmPtr->getRecurrenceType();
+
+                       int err = ALARM_ERROR_NONE;
+                       if(alarmType == AbsoluteRecurrence::ByDayValue) {
+                               int bydayValue = converter.toNativeAlarmValue(alarmPtr->getByDayRecurrence());
+                               LogInfo("Native bydayValue = " << bydayValue);
+                               err = alarm_schedule_with_recurrence_week_flag(service, &startDate, bydayValue, &alarm_id);
+                       } else if(alarmType == AbsoluteRecurrence::Interval) {
+                               int interval = alarmPtr->getInterval();
+                               err = alarm_schedule_at_date(service, &startDate, interval, &alarm_id);
+                       } else {
+                               err = alarm_schedule_at_date(service, &startDate, 0, &alarm_id);
+                       }
+
+                       if(err == ALARM_ERROR_NONE) {
+                               alarmPtr->setId(alarm_id);
+                       } else {
+                               throw UnknownException("Alarm scheduling failed.");
+                       }
+                       
+               } else if (JSValueIsObjectOfClass(ctx, alarmObj, JSAlarmRelative::getClassRef())) {
+
+                       JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(alarmObj));
+                       if (!priv) {
+                               throw TypeMismatchException("Object is null.");
+                       }
+                       AlarmRelativePtr alarmPtr = priv->getObject();
+                       if (!alarmPtr) {
+                               throw TypeMismatchException("Private object is null.");
+                       }
+
+                       delay = alarmPtr->getDelay();
+                       int interval = alarmPtr->getPeriod();
+                       service = alarmPtr->getService();
+                       service_set_app_id(service, appId.c_str());
+
+                       // appControl
+                       JSObjectRef appControlObj = validator.toObject(2, true);
+                       if (appControlObj) {
+                               if(!JSValueIsObjectOfClass(ctx, appControlObj, DeviceAPI::Application::JSApplicationControl::getClassRef())) {
+                                       throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+                               }
+                               DeviceAPI::Application::ApplicationConverter applicationConverter(ctx);
+                               DeviceAPI::Application::ApplicationControlPtr appService = applicationConverter.toApplicationControl(appControlObj);
+                               if(converter.toAlarmService(service, appService) == false) {
+                                       throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+                               }
+                       } else {
+                               service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+                       }
+
+                       int err = alarm_schedule_after_delay(service, delay, interval, &alarm_id);
+
+                       if(err == ALARM_ERROR_NONE) {
+                               alarmPtr->setId(alarm_id);
+                       } else {
+                               throw UnknownException("Alarm scheduling failed.");
+                       }
+
+               } else {
+                       LogError("First parameter is not a Alarm object");
+                       throw TypeMismatchException("First parameter is not a Alarm object");
+               }               
+
+               return JSValueMakeUndefined(ctx);
+
+       }  catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(ctx, exception, err);
+    }
+
+#if 0
+
        Validator check(ctx, exception);
        AlarmConverter converter(ctx);
        DeviceAPI::Application::ApplicationConverter applicationConverter(ctx);
@@ -267,43 +390,157 @@ JSValueRef JSAlarmManager::add(JSContextRef ctx, JSObjectRef object, JSObjectRef
                LogWarning("Exception: "<<_rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
        }
-
        return JSValueMakeUndefined(ctx);
+#endif
+       
 }
 
 JSValueRef JSAlarmManager::remove(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-    int err;
-
     AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_REMOVE);
     TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
     
-    Converter converter(ctx);
-    JSValueRef value;
-    int id;
+       try {
+               ArgumentValidator validator(ctx, argumentCount, arguments);
+
+               // id
+        std::string id = validator.toString(0);
+               
+               int alarmId = 0;
+               std::stringstream(id) >> alarmId;
+
+               if (alarmId <= 0) {
+                       LogError("id is wrong : " << alarmId);
+                       throw InvalidValuesException("Invalid ID");
+               }
+
+               int ret = alarm_cancel(alarmId);                
+               if (ret == ALARM_ERROR_NONE) {
+                       // no error;
+               } else if (ret == ALARM_ERROR_INVALID_PARAMETER) {
+                       throw NotFoundException("Alarm not found");
+               } else {
+                       throw UnknownException("Platform thrown unknown error");
+               }
+               
+               return JSValueMakeUndefined(ctx);
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(ctx, exception, err);
+    }
+}
 
-    Try {
-        if(argumentCount < 1 ) {
-            value = JSValueMakeUndefined(ctx);
-            id = converter.toInt(value);
+JSValueRef JSAlarmManager::removeAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_REMOVE_ALL);
+    TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
+
+       int returnVal = alarm_cancel_all();
+       if (ALARM_ERROR_NONE != returnVal) {
+               LogInfo("Error while removing all alarms: "<<returnVal);
+       }
+
+    return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmManager::get(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    try {
+               service_h service = NULL;
+               char* alarmType = NULL;
+               JSValueRef result = NULL;
+               
+        ArgumentValidator validator(ctx, argumentCount, arguments);
+           AlarmConverter converter(ctx);
+
+        // id
+        std::string id = validator.toString(0);
+               int alarmId = 0;
+               std::stringstream(id) >> alarmId;       
+               int ret = alarm_get_service(alarmId, &service);
+               if (ret != ALARM_ERROR_NONE) {
+                       throw NotFoundException("Alarm not found");
+               }
+               
+               ret = service_get_extra_data(service, ALARM_TYPE_KEY, &alarmType);
+               if (ret != SERVICE_ERROR_NONE) {
+                       LogError("Getting data failed: " << ret);
+                       service_destroy(service);
+                       throw UnknownException("Unknown error occurred.");
+               }
+               
+               if (strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE) == 0) {
+                       AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(service));
+                       
+                       if(!converter.toAlarmAbsolutePtr(alarmId, service, privateData)) {
+                               service_destroy(service);
+                throw TypeMismatchException("Alarm not found");
+            }
+
+            result = JSAlarmAbsolute::createJSObject(ctx, privateData);                
+
+               } else if(strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE) == 0) {
+            AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(service));
+                       
+            if(!converter.toAlarmRelativePtr(alarmId, service, privateData)) {
+                               service_destroy(service);
+                 throw TypeMismatchException("Alarm not found");
+            }
+                       
+            result = JSAlarmRelative::createJSObject(ctx, privateData);  
+               } else {
+                       service_destroy(service);
+                       throw UnknownException("Unknown error occurred.");
+               }
+
+               service_destroy(service);
+               return result;
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(ctx, exception, err);
+    }
+
+#if 0          
+        if(argumentCount <1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
         } else {
-            id = converter.toInt(arguments[0]);
+            alarmId = converter.toInt(arguments[0]);
         }
 
-        if(id <= 0) {
-            ThrowMsg(InvalidArgumentException, "Invalid id value.");
+        service_h handle = NULL;
+        char* alarmType = NULL;
+        int error = alarm_get_service(alarmId, &handle);
+        if(error != ALARM_ERROR_NONE) {
+            ThrowMsg(NotFoundException, "Alarm not found");
         }
 
-        err = alarm_cancel(id);
+               error =service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
+               if(SERVICE_ERROR_NONE!=error) {
+                       LogInfo("Getting data failed: "<<error);
+                       service_destroy(handle);
+            ThrowMsg(PlatformException, "Unknown error occurred.");
+               }
 
-        if(err != ALARM_ERROR_NONE)
+        if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE)) 
         {
-            if(err == ALARM_ERROR_INVALID_PARAMETER) {
-                               ThrowMsg(NotFoundException, "Alarm not found.");
+            AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
+            if(converter.toAlarmAbsolutePtr(alarmId, handle, privateData) == false) {
+                ThrowMsg(ConversionException, "Absolute alarm conversion failed.");
             }
-            else {
-                ThrowMsg(PlatformException, "Unknown error occurred.");
+            
+            return JSAlarmAbsolute::createJSObject(ctx, privateData);
+
+        } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
+            AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
+            if(converter.toAlarmRelativePtr(alarmId, handle, privateData) == false) {
+                ThrowMsg(ConversionException, "Relative alarm conversion failed.");
             }
+            return JSAlarmRelative::createJSObject(ctx, privateData);    
         }
        } Catch(ConversionException) {
                LogWarning("Exception: "<<_rethrown_exception.GetMessage());
@@ -323,40 +560,94 @@ JSValueRef JSAlarmManager::remove(JSContextRef ctx, JSObjectRef object, JSObject
        }
 
     return JSValueMakeUndefined(ctx);
+#endif
 }
 
-JSValueRef JSAlarmManager::removeAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
-    LogError("GContext = " << gContext);
-    AceSecurityStatus status = ALARM_CHECK_ACCESS(
-            ALARM_FUNCTION_API_REMOVE_ALL);
-    TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
-
-       int returnVal = alarm_cancel_all();
-       if (ALARM_ERROR_NONE!=returnVal) {
-               LogInfo("Error while removing all alarms: "<<returnVal);
-       }
-
-    return JSValueMakeUndefined(ctx);
-}
 
 JSValueRef JSAlarmManager::getAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-    int error;
-    AlarmConverter converter(ctx);
-    std::vector<int> alarmIds; 
-
-    Try {
-        error = alarm_foreach_registered_alarm(alarm_iterate_callback, &alarmIds);
-        if (ALARM_ERROR_CONNECTION_FAIL == error) {
+    try {
+               AlarmConverter converter(ctx);
+               std::vector<int> alarmIds; 
+               
+        int error = alarm_foreach_registered_alarm(alarm_iterate_callback, &alarmIds);
+        if (error == ALARM_ERROR_CONNECTION_FAIL) {
             LogWarning("Alarm system may not be ready yet.");
             alarmIds.clear();
-        } else if(ALARM_ERROR_NONE != error) {
+        } else if(error != ALARM_ERROR_NONE) {
             LogInfo("Error occurred while getting all alarms: "<<error);
-            ThrowMsg(PlatformException, "Unknown error occurred.");
+            throw UnknownException("Unknown error occurred.");
         }
 
         JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
+           if (jsResult == NULL) {
+                       throw TypeMismatchException("Could not create js array object.");
+           }
+
+               for (size_t i = 0 ; i < alarmIds.size(); i++) {
+
+            service_h handle = NULL;
+            char* alarmType = NULL;
+                       
+            error = alarm_get_service(alarmIds.at(i), &handle);
+            if(error != ALARM_ERROR_NONE) {
+                LogInfo("Getting service failed: " << error);
+                throw NotFoundException("Alarm not found");
+            }
+
+            error = service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
+            if(error != SERVICE_ERROR_NONE) {
+                LogInfo("Getting data failed: " << error);
+                service_destroy(handle);
+                throw UnknownException("Unknown error occurred.");
+            }
+
+            LogInfo("Alarm id: " << alarmIds.at(i));
+            LogInfo("Alarm Type: " << alarmType);
+
+                       JSValueRef obj = NULL;
+                       if (strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE) == 0) {
+                               LogInfo("Enter getAll Natvie alarm id = " << alarmIds.at(i));
+                               AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
+
+                               if(!converter.toAlarmAbsolutePtr(alarmIds.at(i), handle, privateData)) {
+                                       service_destroy(handle);
+                                       throw TypeMismatchException("Absolute alarm conversion failed.");
+                               }
+
+                               obj = JSAlarmAbsolute::createJSObject(ctx, privateData);
+                               
+            } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
+                AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
+                               
+                if(!converter.toAlarmRelativePtr(alarmIds.at(i), handle, privateData)) {
+                                       service_destroy(handle);
+                                       throw TypeMismatchException("Relative alarm conversion failed.");
+                }
+                obj = JSAlarmRelative::createJSObject(ctx, privateData);
+
+            }  else {
+                   service_destroy(handle);
+                               throw UnknownException("Unknown error occurred.");
+                       }
+
+            service_destroy(handle);
+                       
+                       if(!JSSetArrayElement(ctx, jsResult, i, obj)) {
+                               service_destroy(handle);
+                               throw UnknownException("JS array creation failed.");
+                       }
+               }
+               
+               return jsResult;
+               
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(ctx, exception, err);
+    }
+#if 0          
         int elementIndex = 0;
 
         LogInfo("Alarms id size: " << alarmIds.size());
@@ -426,70 +717,32 @@ JSValueRef JSAlarmManager::getAll(JSContextRef ctx, JSObjectRef object, JSObject
         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
+#endif
 }
 
-JSValueRef JSAlarmManager::get(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+JSValueRef JSAlarmManager::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-    int alarmId;
-    AlarmConverter converter(ctx);
-
-    Try {    
-        if(argumentCount <1) {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-        } else {
-            alarmId = converter.toInt(arguments[0]);
-        }
-
-        service_h handle = NULL;
-        char* alarmType = NULL;
-        int error = alarm_get_service(alarmId, &handle);
-        if(error != ALARM_ERROR_NONE) {
-            ThrowMsg(NotFoundException, "Alarm not found");
+    try {
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_MINUTE)) {
+                       return JSUtil::toJSValueRef(context, (unsigned long long)60);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_HOUR)) {
+            return JSUtil::toJSValueRef(context, (unsigned long long)3600);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_DAY)) {
+            return JSUtil::toJSValueRef(context, (unsigned long long)86400);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_WEEK)) {
+            return JSUtil::toJSValueRef(context, (unsigned long long)604800);
         }
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed. %s", err.getMessage().c_str());
+    }
 
-               error =service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
-               if(SERVICE_ERROR_NONE!=error) {
-                       LogInfo("Getting data failed: "<<error);
-                       service_destroy(handle);
-            ThrowMsg(PlatformException, "Unknown error occurred.");
-               }
-
-        if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE)) 
-        {
-            AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
-            if(converter.toAlarmAbsolutePtr(alarmId, handle, privateData) == false) {
-                ThrowMsg(ConversionException, "Absolute alarm conversion failed.");
-            }
-            
-            return JSAlarmAbsolute::createJSObject(ctx, privateData);
-
-        } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
-            AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
-            if(converter.toAlarmRelativePtr(alarmId, handle, privateData) == false) {
-                ThrowMsg(ConversionException, "Relative alarm conversion failed.");
-            }
-            return JSAlarmRelative::createJSObject(ctx, privateData);    
-        }
-       } Catch(ConversionException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch(UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       } Catch(InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch (NotFoundException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       } Catch(Exception) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-    return JSValueMakeUndefined(ctx);
+    return NULL;
 }
 
+#if 0
 JSValueRef JSAlarmManager::getMin(JSContextRef ctx,
                JSObjectRef object,
                JSStringRef propertyName,
@@ -579,6 +832,7 @@ char* JSAlarmManager::getPackageById(const char* appId)
        LogDebug(">>> pkg:[" << pkg << "]");
        return pkg;
 }
+#endif
 
 } // Alarm
 } // TizenApis
index 5a2240d..dc35175 100755 (executable)
@@ -49,11 +49,17 @@ protected:
     static JSValueRef getAll(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);  
     
 private:
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);    
+#if 0  
     static JSValueRef getMin(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     static JSValueRef getHour(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     static JSValueRef getDay(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     static JSValueRef getWeek(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     static char* getPackageById(const char* appId);
+#endif
 
     static JSClassDefinition m_jsClassInfo;
     static JSClassRef m_jsClassRef;
index 177e0cc..1f40cfe 100755 (executable)
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+
 #include <Commons/Exception.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
@@ -60,8 +64,8 @@ JSClassDefinition JSAlarmRelative::m_jsClassInfo = {
        NULL, //deleteProperty,Geolocation
        NULL, //getPropertyNames,
        NULL,
-       constructor, // constructor
-       hasInstance,
+       NULL, // constructor
+       NULL,
        NULL
 };
 
@@ -109,66 +113,38 @@ bool JSAlarmRelative::hasInstance(JSContextRef context, JSObjectRef constructor,
 
 JSObjectRef JSAlarmRelative::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-    AlarmConverter converter(ctx);
-    Validator validator(ctx);
-    int delay = 0;
-    int interval = 0;
-
-    Try {
-
-        if(argumentCount < 1)
-        {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-        }
-
-        delay = converter.toInt(arguments[0]);
-
-        if(delay < 0) {
-            ThrowMsg(InvalidArgumentException, "First parameter should be positive.");
-        }
-
-        if(argumentCount >= 2)
-        {
-            // Ignores if it is optional
-            if(JSValueIsUndefined(ctx, arguments[1])) {
-                return JSValueToObject(ctx, createJSObject(ctx, delay, interval), exception);
-            }
-
-            interval = converter.toInt(arguments[1]);
-            if(interval < 0) {
-                ThrowMsg(InvalidArgumentException, "Second parameter should be positive.");
-            }
-
-            LogInfo("Constructor interval  = " << interval);
-        }
-
-        return JSValueToObject(ctx, createJSObject(ctx, delay, interval), exception);
-       } Catch(ConversionException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch(UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       } Catch(InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch(Exception) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+       try {
+               AlarmRelativePtr priv = AlarmRelativePtr(new AlarmRelative());
+               if (!priv) {
+                       throw TypeMismatchException("Private object is null");
+               }
+               
+           ArgumentValidator validator(ctx, argumentCount, arguments);
+
+               unsigned long long delay = validator.toULongLong(0);
+               unsigned long long period = validator.toULongLong(1, true, 0);
+
+               
+        priv->setDelay(validator.toULongLong(0));
+
+               return JSValueToObject(ctx, createJSObject(ctx, delay, period), exception);
+       } catch (const BasePlatformException& err) {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(ctx, err);
+               *exception = exceptionObj;
+               return exceptionObj;
+    }
 
-    return NULL;
 }
 
 AlarmRelativePtr JSAlarmRelative::getPrivData(JSObjectRef object)
 {
     JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(object));
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     AlarmRelativePtr result = priv->getObject();
     if (!result) {
-               ThrowMsg(ConversionException, "Private object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return result;
 }
@@ -177,7 +153,7 @@ JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, AlarmRelativePt
 {
     JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData);
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
 }
@@ -190,7 +166,7 @@ JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, int delay, int
     
     JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData);
     if (!priv) {
-               ThrowMsg(ConversionException, "Object is null.");
+               throw TypeMismatchException("Private object is null");
     }
     return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
 }
@@ -204,7 +180,7 @@ JSValueRef JSAlarmRelative::getRemainingSeconds(JSContextRef ctx, JSObjectRef fu
     Converter converter(ctx);
     int id;
 
-    Try {
+    try {
         AlarmRelativePtr privateData = getPrivData(thisObject);
         id = privateData->getId();
 
@@ -214,7 +190,7 @@ JSValueRef JSAlarmRelative::getRemainingSeconds(JSContextRef ctx, JSObjectRef fu
             if(err == ALARM_ERROR_INVALID_PARAMETER) {
                 return JSValueMakeNull(ctx);
             } else  {
-                ThrowMsg(PlatformException, "Unknown exception occurred.");
+                throw UnknownException("Unknown exception occurred.");
             }
         }
 
@@ -227,26 +203,19 @@ JSValueRef JSAlarmRelative::getRemainingSeconds(JSContextRef ctx, JSObjectRef fu
 
         LogDebug("nextTime: "<<nextTime<<", currentTime: "<<currentTime<<", result: "<<result);
 
-        if(result <0) {
+        if(result < 0) {
             // It is impossible
-            ThrowMsg(Exception, "Invalid result value.");
+            throw UnknownException("Unknown exception occurred.");
         }
 
         JSValueRef jsResult = converter.toJSValueRef(result);
         return jsResult;       
-       } Catch(ConversionException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch(UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       } Catch(InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch(Exception) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(ctx, exception, err);
+    }
 }
 
 JSValueRef JSAlarmRelative::getId(JSContextRef ctx,
@@ -256,9 +225,12 @@ JSValueRef JSAlarmRelative::getId(JSContextRef ctx,
 {
     Converter converter(ctx);
     int id;
-    Try
-    {
+    try {
         AlarmRelativePtr privateData = getPrivData(object);
+               if (!privateData) {
+                       throw TypeMismatchException("Private object is null");
+           }
+               
         id = privateData->getId();
         if(id >= 0) {
             std::string strId = converter.toString(id);
@@ -266,12 +238,12 @@ JSValueRef JSAlarmRelative::getId(JSContextRef ctx,
         } else {
             return JSValueMakeNull(ctx);            
         }
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(ctx, exception, err);
     }
-       Catch(Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
-       return JSValueMakeUndefined(ctx);
 }
 
 JSValueRef JSAlarmRelative::getDelay(JSContextRef ctx,
@@ -281,23 +253,27 @@ JSValueRef JSAlarmRelative::getDelay(JSContextRef ctx,
 {
     Converter converter(ctx);
     int delay;
-    Try
-    {
+
+       try {
         AlarmRelativePtr privateData = getPrivData(object);
+               if (!privateData) {
+                       throw TypeMismatchException("Private object is null");
+           }
+               
         delay = privateData->getDelay();
         LogInfo("JSAlarmRelative delay = " << delay);
         if(delay >= 0) {
             return converter.toJSValueRef(delay);
         } else {
             // Impossible
-            ThrowMsg(Exception, "Invalid delay value.");
+            throw UnknownException("Invalid delay value.");
         }
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(ctx, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(ctx, exception, err);
     }
-       Catch(Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
-       return JSValueMakeUndefined(ctx);
 }
 
 JSValueRef JSAlarmRelative::getPeriod(JSContextRef ctx,
@@ -308,22 +284,26 @@ JSValueRef JSAlarmRelative::getPeriod(JSContextRef ctx,
 
     Converter converter(ctx);
     int period =0;
-    Try
-    {
+
+       try {
         AlarmRelativePtr privateData = getPrivData(object);
+               if (!privateData) {
+                       throw TypeMismatchException("Private object is null");
+           }
+               
         period = privateData->getPeriod();
         LogInfo("JSAlarmRelative interval = " << period);
-         if(period <=0) {
+         if(period <= 0) {
             return JSValueMakeNull(ctx);
         } else {
             return converter.toJSValueRef(period);
         }
-    }
-       Catch(Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+       } catch (const BasePlatformException &err) {
+               return JSWebAPIException::throwException(ctx, exception, err);
+       } catch (...) {
+               DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+               return JSWebAPIException::throwException(ctx, exception, err);
        }
-       return JSValueMakeUndefined(ctx);
 }
 
 } // Alarm
index 12672a5..cd58f40 100755 (executable)
@@ -30,6 +30,17 @@ using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
+class_definition_options_t ConstructorClassOptions =
+{
+    JS_INTERFACE,
+    CREATE_INSTANCE,
+    NONE_NOTICE,
+    USE_OVERLAYED, //ignored
+    NULL,
+    NULL,
+    NULL
+};
+
 void on_widget_start_callback(int widgetId)
 {
     LogDebug("[Tizen\\AlarmManager ] on_widget_start_callback (" << widgetId << ")");
@@ -65,15 +76,17 @@ PLUGIN_CLASS_MAP_ADD_CLASS(
         "alarm",
         (js_class_template_getter)DeviceAPI::Alarm::JSAlarmManager::getClassRef,
         NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(
+PLUGIN_CLASS_MAP_ADD_INTERFACE(
        WRT_JS_EXTENSION_OBJECT_TIZEN,
        TIZEN_ALARM_ABSOLUTE_INTERFACE,
        (js_class_template_getter)DeviceAPI::Alarm::JSAlarmAbsolute::getClassRef,
-       NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(
+       reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmAbsolute::constructor),
+       &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(
        WRT_JS_EXTENSION_OBJECT_TIZEN,
        TIZEN_ALARM_RELATIVE_INTERFACE,
        (js_class_template_getter)DeviceAPI::Alarm::JSAlarmRelative::getClassRef,
-       NULL)
+       reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmRelative::constructor),
+       &ConstructorClassOptions)
 PLUGIN_CLASS_MAP_END
 
index b17a301..be78698 100755 (executable)
@@ -22,6 +22,7 @@
 #include <CommonsJavaScript/ScopedJSStringRef.h>
 #include <Commons/RegexUtils.h>
 #include <Commons/Exception.h>
+#include <JSWebAPIError.h>
 
 #include "ApplicationConverter.h"
 #include "JSApplication.h"
@@ -36,6 +37,7 @@
 namespace DeviceAPI {
 namespace Application {
 
+using namespace DeviceAPI::Common;
 using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
@@ -281,7 +283,7 @@ ApplicationControlPtr ApplicationConverter::toApplicationControl(const JSValueRe
        if(JSApplicationControl::isObjectOfClass(m_context, jsValue)) {
                return JSApplicationControl::getApplicationControl(m_context, jsValue);
        } else {
-           ThrowMsg(Commons::ConversionException, "Wrong parameter type.");
+           throw TypeMismatchException("not a object of class ApplicationControl");
        }
 }
 
index 7c9ba47..2edd27d 100644 (file)
@@ -291,7 +291,7 @@ namespace {
                }
 
                ret = pkgmgrinfo_pkginfo_get_version(pkginfo_h, &version);
-               if (ret != PMINFO_R_OK) {
+               if ((ret != PMINFO_R_OK) || (version == NULL)) {
                        LogDebug("Fail to get version");
                } else {
                        appInfo->setVersion(version);
@@ -338,14 +338,14 @@ namespace {
                }
 
                ret = pkgmgrinfo_appinfo_get_label(handle, &name);
-               if (ret != PMINFO_R_OK) {
+               if ((ret != PMINFO_R_OK) || (name == NULL)) {
                        LogDebug("Fail to get name by " << appId);
                } else {
                        appInfo->setName(name);
                }
 
                ret = pkgmgrinfo_appinfo_get_icon(handle, &iconPath);
-               if (ret != PMINFO_R_OK) {
+               if ((ret != PMINFO_R_OK) || (iconPath == NULL)) {
                        LogDebug("Fail to get icon by " << appId);
                } else {
                        appInfo->setIconPath(iconPath);
@@ -364,7 +364,7 @@ namespace {
                }
 
                ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
-               if (ret != PMINFO_R_OK) {
+               if ((ret != PMINFO_R_OK) || (pkgId == NULL)) {
                        LogDebug("Fail to get pkg Id by " << appId);
                } else {
                        appInfo->setPackageId(pkgId);
@@ -574,6 +574,17 @@ void ApplicationManager::getAppCerts(const EventApplicationGetAppCertsPtr& event
 }
 
 
+void ApplicationManager::getAppSharedURI(const EventApplicationGetAppSharedURIPtr& event)
+{
+       LogError("ApplicationManager::getAppSharedURI");
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationGetAppSharedURI>::PostRequest(event);
+}
+
+
 void ApplicationManager::invokeManualAnswerLaunchAppControl(service_h request, service_h reply,
                service_result_e result,
                EventApplicationLaunchAppControlReplyPtr &event)
@@ -1033,6 +1044,15 @@ void ApplicationManager::OnRequestReceived(const EventApplicationLaunchAppContro
                {
                        LogDebug(" app id    : " << appId);
 
+                       // Application exist checking. if specific application is not exist, return Not Found Exception.
+                       app_info_h info_h;
+                       if (app_manager_get_app_info(appId.c_str(), &info_h) != APP_MANAGER_ERROR_NONE) {
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               return;
+                       } else {
+                               app_info_destroy(info_h);
+                       }
+
                        service_set_app_id(service, appId.c_str());
                }
 
@@ -1142,6 +1162,9 @@ void ApplicationManager::OnRequestReceived(const EventApplicationLaunchAppContro
                                event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
                                break;
                        case SERVICE_ERROR_LAUNCH_REJECTED:
+                               LogDebug("service_send_launch_request returns SERVICE_ERROR_LAUNCH_REJECTED!!!");
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                               break;
                        case SERVICE_ERROR_APP_NOT_FOUND:
                                LogDebug("service_send_launch_request returns SERVICE_ERROR_APP_NOT_FOUND");
                                event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
@@ -1325,10 +1348,12 @@ void ApplicationManager::OnRequestReceived(const EventApplicationGetAppContextPt
                int ret = 0;
 
                std::string contextId = event->getAppContextId();
+               LogDebug("contextId : " << contextId);
                int pid;
 
                if (contextId.empty())
                {
+                       LogDebug("empty");
                        //pid = getpid();
                        pid = getppid();
 
@@ -1338,6 +1363,7 @@ void ApplicationManager::OnRequestReceived(const EventApplicationGetAppContextPt
                }
                else
                {
+                       LogDebug("not empty");
                        std::stringstream(contextId) >> pid;
                        if (pid <= 0)
                        {
@@ -1355,13 +1381,10 @@ void ApplicationManager::OnRequestReceived(const EventApplicationGetAppContextPt
                        switch(ret)
                        {
                        case APP_MANAGER_ERROR_NO_SUCH_APP:
+                       case APP_MANAGER_ERROR_INVALID_PARAMETER:
                                LogError("app_manager_get_app_id error : no such app");
                                event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
                                break;
-                       case APP_MANAGER_ERROR_INVALID_PARAMETER:
-                               LogError("app_manager_get_app_id error : invalid parameter");
-                               event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
-                               break;
                        default:
                                LogError("app_manager_get_app_id error (" << ret << ")");
                                event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
@@ -1491,8 +1514,9 @@ void ApplicationManager::OnRequestReceived(const EventApplicationRemoveAppInfoEv
        {
                long watchId = event->getWatchId();
 
-               if(m_watchIdMap.find(watchId) == m_watchIdMap.end())
+               if(m_watchIdMap.find(watchId) == m_watchIdMap.end()) {
                        ThrowMsg(NotFoundException, "No watchId : " << watchId);
+               }
 
                EventApplicationAppInfoEventListenerEmitter::IdType emitterId = m_watchIdMap[watchId];
 
@@ -1586,6 +1610,86 @@ void ApplicationManager::OnRequestReceived(const EventApplicationGetAppCertsPtr&
        }
 }
 
+#define TIZENAPIS_APP_FILE_SCHEME              "file://"
+#define TIZENAPIS_APP_SLASH                            "/"
+#define TIZENAPIS_APP_SHARED                   "shared"
+
+void ApplicationManager::OnRequestReceived(const EventApplicationGetAppSharedURIPtr& event)
+{
+       LogError("ApplicationManager::getAppCerts");
+       std::string id = event->getAppId();
+       
+       std::string appId;
+       int ret = 0;
+       LogError("appId(" << id << ")");
+       if (id.empty()) {
+               char *app_id = NULL;
+
+               //int ret = app_get_id(&app_id);        // webkit2 patch.
+               ret = get_current_app_id(&app_id);
+               if((ret != APP_ERROR_NONE) || (app_id == NULL)) {
+                       LogError("Can not get app id from current pid (" << ret << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+               appId = app_id;
+               free(app_id);
+       } else {
+               appId = id;
+       }
+
+       app_info_h handle;
+       char* pkg_name = NULL;
+       ret = app_manager_get_app_info(appId.c_str(), &handle);
+       if (ret != APP_ERROR_NONE) {
+               LogDebug("Fail to get appinfo by " << appId);
+               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+               return;
+       }
+
+       ret = app_info_get_package(handle, &pkg_name);
+       if ((ret != APP_ERROR_NONE) || (pkg_name == NULL)) {
+               LogDebug("Fail to get pkg_name by " << appId);
+               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+               return;
+       }
+
+       app_info_destroy(handle);
+
+       LogError("pkg_name(" << pkg_name << ")");
+
+       pkgmgrinfo_pkginfo_h pkginfo_h;
+       char* root_path = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &pkginfo_h);
+       if (ret != PMINFO_R_OK) {
+               free(pkg_name);
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+               return;
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_root_path(pkginfo_h, &root_path);
+       if ((ret != PMINFO_R_OK) && (root_path != NULL)) {
+               LogDebug("Fail to get root path");
+               free(pkg_name);
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+               return;
+       }
+
+       LogError("pkg_name(" << root_path << ")");
+
+       std::string sharedURI = TIZENAPIS_APP_FILE_SCHEME + std::string(root_path) + TIZENAPIS_APP_SLASH + 
+                                       std::string(pkg_name) + TIZENAPIS_APP_SLASH + TIZENAPIS_APP_SHARED;
+       free(pkg_name);
+
+       LogError("sharedURI(" << sharedURI << ")");
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h);
+
+       event->setSharedURI(sharedURI);
+}
+
+
 
 void ApplicationManager::onAppManagerEventInstalled(const char *appId)
 {
index d5bcaf6..b94b3ee 100644 (file)
@@ -52,6 +52,7 @@ public:
        virtual void addAppInfoEventListener(const EventApplicationAddAppInfoEventListenerPtr& event);
        virtual void removeAppInfoEventListener(const EventApplicationRemoveAppInfoEventListenerPtr& event);
        virtual void getAppCerts(const EventApplicationGetAppCertsPtr& event);
+       virtual void getAppSharedURI(const EventApplicationGetAppSharedURIPtr& event);
 
        void invokeManualAnswerLaunchAppControl(service_h request, service_h reply, service_result_e result,
                        EventApplicationLaunchAppControlReplyPtr &event);
@@ -74,6 +75,7 @@ protected:
        virtual void OnRequestReceived(const EventApplicationAddAppInfoEventListenerPtr& event);
        virtual void OnRequestReceived(const EventApplicationRemoveAppInfoEventListenerPtr& event);
        virtual void OnRequestReceived(const EventApplicationGetAppCertsPtr& event);
+       virtual void OnRequestReceived(const EventApplicationGetAppSharedURIPtr& event);
 
        // inherited from IAppManagerAppListChangedCallbacks
        virtual void onAppManagerEventInstalled(const char *appId);
diff --git a/src/Application/EventApplicationGetAppSharedURI.h b/src/Application/EventApplicationGetAppSharedURI.h
new file mode 100644 (file)
index 0000000..840ed59
--- /dev/null
@@ -0,0 +1,65 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT 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 TIZENAPIS_API_APPLICATION_EVENT_GET_APP_SHARED_URI_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_GET_APP_SHARED_URI_H_
+
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace DeviceAPI {
+namespace Application {
+
+class EventApplicationGetAppSharedURI : public WrtDeviceApis::Commons::IEvent<EventApplicationGetAppSharedURI>
+{
+private:
+       std::string m_appId;
+       std::string m_sharedURI;
+
+public:
+       void setAppId(std::string appId)
+       {
+               m_appId = appId;
+       }
+
+       std::string getAppId()
+       {
+               return m_appId;
+       }
+       
+       void setSharedURI(std::string &sharedURI)
+       {
+               m_sharedURI = sharedURI;
+       }
+
+       std::string getSharedURI() const
+       {
+               return m_sharedURI;
+       }
+
+       EventApplicationGetAppSharedURI()
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationGetAppSharedURI> EventApplicationGetAppSharedURIPtr;
+
+} // Application
+} // DeviceAPI
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_GET_APP_SHARED_URI_H_
\ No newline at end of file
index 1bb66fb..2f15c1c 100644 (file)
@@ -35,7 +35,8 @@ IApplicationManager::IApplicationManager() :
                EventRequestReceiver<EventApplicationGetAppInfo>(ThreadEnum::APPLICATION_THREAD),
                EventRequestReceiver<EventApplicationAddAppInfoEventListener>(ThreadEnum::APPLICATION_THREAD),
                EventRequestReceiver<EventApplicationRemoveAppInfoEventListener>(ThreadEnum::APPLICATION_THREAD),
-               EventRequestReceiver<EventApplicationGetAppCerts>(ThreadEnum::APPLICATION_THREAD)
+               EventRequestReceiver<EventApplicationGetAppCerts>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationGetAppSharedURI>(ThreadEnum::APPLICATION_THREAD)
 {
 }
 
index c1ba391..8939313 100644 (file)
@@ -32,6 +32,7 @@
 #include "EventApplicationAddAppInfoEventListener.h"
 #include "EventApplicationRemoveAppInfoEventListener.h"
 #include "EventApplicationGetAppCerts.h"
+#include "EventApplicationGetAppSharedURI.h"
 
 namespace DeviceAPI {
 namespace Application {
@@ -49,7 +50,8 @@ class IApplicationManager :
        public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppInfo>,
        public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationAddAppInfoEventListener>,
        public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationRemoveAppInfoEventListener>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppCerts>
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppCerts>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppSharedURI>
 {
 public:
        virtual ~IApplicationManager();
@@ -65,6 +67,7 @@ public:
        virtual void addAppInfoEventListener(const EventApplicationAddAppInfoEventListenerPtr& event) = 0;
        virtual void removeAppInfoEventListener(const EventApplicationRemoveAppInfoEventListenerPtr& event) = 0;
        virtual void getAppCerts(const EventApplicationGetAppCertsPtr& event) = 0;
+       virtual void getAppSharedURI(const EventApplicationGetAppSharedURIPtr& event) = 0;
 
 protected:
        IApplicationManager();
@@ -82,6 +85,7 @@ protected:
        virtual void OnRequestReceived(const EventApplicationAddAppInfoEventListenerPtr& event) = 0;
        virtual void OnRequestReceived(const EventApplicationRemoveAppInfoEventListenerPtr& event) = 0;
        virtual void OnRequestReceived(const EventApplicationGetAppCertsPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationGetAppSharedURIPtr& event) = 0;
  };
 
 typedef DPL::SharedPtr<IApplicationManager> IApplicationManagerPtr;
index 9b8bb2e..df7cd83 100644 (file)
 
 #include <cassert>
 #include <memory>
-#include <dpl/log/log.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/Converter.h>
 #include <Commons/Exception.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include <SecurityExceptions.h>
+
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
+//#include <JSTizenExceptionFactory.h>
+//#include <JSTizenException.h>
+//#include <SecurityExceptions.h>
 
 #include "ApplicationController.h"
 #include "ApplicationConverter.h"
@@ -33,6 +37,8 @@
 #include "JSApplicationManager.h"
 #include "JSApplication.h"
 
+#include <Logger.h>
+
 namespace DeviceAPI {
 namespace Application {        
 
@@ -48,12 +54,12 @@ JSClassDefinition JSApplication::m_classInfo = {
     kJSClassAttributeNone,
     TIZEN_INTERFACE_APPLICATION,
     0,
-    m_property,
+    NULL,
     m_function,
     initialize,
     finalize,
     NULL,     //HasProperty,
-    getProperty,       //GetProperty,
+    NULL,      //GetProperty,
     NULL,     //SetProperty,
     NULL,     //DeleteProperty,
     NULL,     //GetPropertyNames,
@@ -63,12 +69,13 @@ JSClassDefinition JSApplication::m_classInfo = {
     NULL,     //ConvertToType
 };
 
-
+#if 0
 JSStaticValue JSApplication::m_property[] = {
     { TIZEN_APPLICATION_APP_INFO, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { TIZEN_APPLICATION_APP_CONTEXT_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { 0, 0, 0, 0 }
 };
+#endif
 
 JSStaticFunction JSApplication::m_function[] = {
                { APPLICATION_FUNCTION_API_EXIT, JSApplication::exit, kJSPropertyAttributeNone },
@@ -99,6 +106,26 @@ void JSApplication::finalize(JSObjectRef object)
     delete priv;               
 }
 
+JSValueRef JSApplication::makeObject(JSContextRef ctx, const ApplicationPtr value)
+{
+       LogInfo("entered to ApplicationPtr ");
+       if(value == NULL)       {
+               throw TypeMismatchException("Private object is NULL.");
+       }
+
+       JSApplicationPriv* priv = new JSApplicationPriv(ctx, value);
+       JSObjectRef target = JSObjectMake(ctx, getClassRef(), priv);
+
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(ctx);
+       JSUtil::setProperty(ctx, target, TIZEN_APPLICATION_APP_INFO, converter->toJSValueRefFromApplicationInformation(value->getAppInfo()),
+                                                               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete );
+       JSUtil::setProperty(ctx, target, TIZEN_APPLICATION_APP_CONTEXT_ID, converter->toJSValueRef(value->getContextId()), 
+                                                               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete );
+       return target;
+}
+
+#if 0
+
 bool JSApplication::isObjectOfClass(JSContextRef context, JSValueRef value)
 {
        return JSValueIsObjectOfClass(context, value, getClassRef());
@@ -117,6 +144,7 @@ ApplicationPtr JSApplication::getPrivData(JSObjectRef object)
        return result;
 }
 
+
 JSValueRef JSApplication::getProperty(JSContextRef context,
        JSObjectRef object,
        JSStringRef propertyName,
@@ -138,7 +166,7 @@ JSValueRef JSApplication::getProperty(JSContextRef context,
        
        return NULL;
 }
-
+#endif
 
 JSValueRef JSApplication::exit(JSContextRef context, 
        JSObjectRef object, 
@@ -149,17 +177,16 @@ JSValueRef JSApplication::exit(JSContextRef context,
 {
        LogDebug("entered");
 
-       Try {
+       try {
                JSApplicationManager::setTitleProperty(context, "tizen://exit");
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+               return JSValueMakeUndefined(context);
 
-       return JSValueMakeUndefined(context);
+       } catch (const BasePlatformException &err) {
+           return JSWebAPIException::throwException(context, exception, err);
+       } catch (...) {
+               DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+               return JSWebAPIException::throwException(context, exception, err);
+       }
 }
 
 JSValueRef JSApplication::hide(JSContextRef context, 
@@ -171,17 +198,16 @@ JSValueRef JSApplication::hide(JSContextRef context,
 {
        LogDebug("entered");
 
-       Try {
+       try {
                JSApplicationManager::setTitleProperty(context, "tizen://hide");
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+               return JSValueMakeUndefined(context);
 
-       return JSValueMakeUndefined(context);
+       } catch (const BasePlatformException &err) {
+               return JSWebAPIException::throwException(context, exception, err);
+       } catch (...) {
+               DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+               return JSWebAPIException::throwException(context, exception, err);
+       }
 }
 
 
@@ -197,9 +223,9 @@ JSValueRef JSApplication::getRequestedAppControl(JSContextRef context,
        JSApplicationPriv *priv = static_cast<JSApplicationPriv*>(JSObjectGetPrivate(thisObject));
 
 
-       Try {
+       try {
                if (!priv) {
-                       ThrowMsg(ConversionException, "Object is null.");
+                       throw TypeMismatchException("No private object.");
                }
                
        ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
@@ -220,29 +246,19 @@ JSValueRef JSApplication::getRequestedAppControl(JSContextRef context,
                app->getRequestedAppControl(event);
                
                if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) {
-                       ThrowMsg(NotFoundException, "No application control request found.");
+                       throw NotFoundException("No application control request found.");
                } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) {
                        return JSValueMakeNull(context);
                }
 
                return converter->toJSValueRef(event->getRequestedAppControl());
 
-    } Catch (NotFoundException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+        } catch (const BasePlatformException &err) {
+                return JSWebAPIException::throwException(context, exception, err);
+        } catch (...) {
+                DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+                return JSWebAPIException::throwException(context, exception, err);
+        }
 }
 
 }
index 2884abf..6ad4619 100644 (file)
@@ -51,8 +51,12 @@ public:
                        const std::vector<std::string> &categories,
                        const time_t &installDate,
                        const long &installSize);
-*/
+
        static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+*/
+
+
+       static JSValueRef makeObject(JSContextRef ctx, const ApplicationPtr value);
 
 /*
        static ApplicationInformationPtr 
@@ -109,6 +113,7 @@ private:
        static JSStaticFunction m_function[];   
 
        static JSClassRef m_classRef;
+#if 0
 
        static ApplicationPtr getPrivData(JSObjectRef object);
 
@@ -116,7 +121,7 @@ private:
                JSObjectRef object,
                JSStringRef propertyName,
                JSValueRef* exception);
-
+#endif
 };
 
 }
index bde258d..2f07ec8 100644 (file)
 #include <dpl/log/log.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/Converter.h>
-#include <Commons/Exception.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+#include <JSWebAPIException.h>
+
+//#include <Commons/Exception.h>
+//#include <JSWebAPIexception.h>
+//#include <JSTizenExceptionFactory.h>
+//#include <JSTizenException.h>
+
 #include "ApplicationCert.h"
 #include "JSApplicationCert.h"
 
@@ -46,7 +50,7 @@ JSClassDefinition JSApplicationCert::m_classInfo = {
     initialize,
     finalize,
     NULL,     //HasProperty,
-    getProperty,       //GetProperty,
+    NULL,      //GetProperty,
     NULL,     //SetProperty,
     NULL,     //DeleteProperty,
     NULL,     //GetPropertyNames,
@@ -93,11 +97,11 @@ ApplicationCertPtr JSApplicationCert::getPrivData(JSObjectRef object)
 {
        JSApplicationCertPriv *priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        ApplicationCertPtr result = priv->getObject();
        if (!result) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        return result;
 }
@@ -108,7 +112,7 @@ JSValueRef JSApplicationCert::getProperty(JSContextRef context,
        JSStringRef propertyName,
        JSValueRef* exception)
 {
-       Try     {
+       try     {
                CommonsJavaScript::Converter converter(context);
                ApplicationCertPtr privateData = getPrivData(object);
 
@@ -119,9 +123,11 @@ JSValueRef JSApplicationCert::getProperty(JSContextRef context,
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_VALUE)) {
                        return converter.toJSValueRef(privateData->getValue());
                }
-       } Catch(WrtDeviceApis::Commons::Exception) {
-        LogError("Exception: " << _rethrown_exception.GetMessage());
-               JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
        
        return JSValueMakeUndefined(context);
index de6e681..12e4739 100644 (file)
 #include <dpl/log/log.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/Converter.h>
-#include <Commons/Exception.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+#include <JSWebAPIException.h>
+//#include <Commons/Exception.h>
+//#include <JSTizenExceptionFactory.h>
+//#include <JSTizenException.h>
 #include "ApplicationContext.h"
 #include "JSApplicationContext.h"
 
@@ -45,7 +46,7 @@ JSClassDefinition JSApplicationContext::m_classInfo = {
     initialize,
     finalize,
     NULL,     //HasProperty,
-    getProperty,       //GetProperty,
+    NULL,      //GetProperty,
     NULL,    //SetProperty,
     NULL,     //DeleteProperty,
     NULL,     //GetPropertyNames,
@@ -106,16 +107,16 @@ bool JSApplicationContext::isObjectOfClass(JSContextRef context, JSValueRef valu
        return JSValueIsObjectOfClass(context, value, getClassRef());
 }
 
-ApplicationContextPtr JSApplicationContext::getPrivData(JSObjectRef object)
+ApplicationContextPtr JSApplicationContext::getPrivData(JSContextRef context, JSObjectRef object)
 {
        JSApplicationContextPriv *priv = static_cast<JSApplicationContextPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        
        ApplicationContextPtr result = priv->getObject();
        if (!result) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        
        return result;
@@ -124,17 +125,17 @@ ApplicationContextPtr JSApplicationContext::getPrivData(JSObjectRef object)
 ApplicationContextPtr JSApplicationContext::getApplicationContext(JSContextRef context, JSValueRef value)
 {
        if (!isObjectOfClass(context, value)) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("is not a object class");
        }
        
        JSObjectRef object = JSValueToObject(context, value, NULL);
        if (!object) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("Private object is null");
        }
        
        JSApplicationContextPriv *priv = static_cast<JSApplicationContextPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
+               throw TypeMismatchException("Private object is null");
        }
        
        return priv->getObject();
@@ -146,9 +147,9 @@ JSValueRef JSApplicationContext::getProperty(JSContextRef context,
        JSStringRef propertyName,
        JSValueRef* exception)
 {
-       Try     {
+       try {
                CommonsJavaScript::Converter converter(context);
-               ApplicationContextPtr privateData = getPrivData(object);
+               ApplicationContextPtr privateData = getPrivData(context, object);
        
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTEXT_APP_ID)) {
                        return converter.toJSValueRef(privateData->getAppId());
@@ -156,9 +157,11 @@ JSValueRef JSApplicationContext::getProperty(JSContextRef context,
                        return converter.toJSValueRef(privateData->getContextId());
                } 
 
-       } Catch(WrtDeviceApis::Commons::Exception) {
-        LogError("Exception: " << _rethrown_exception.GetMessage());
-               JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
        
        return JSValueMakeUndefined(context);
index 037a616..24f7034 100755 (executable)
@@ -77,7 +77,7 @@ private:
 
        static JSClassRef m_classRef;
 
-       static ApplicationContextPtr getPrivData(JSObjectRef object);
+       static ApplicationContextPtr getPrivData(JSContextRef context, JSObjectRef object);
 
        static JSValueRef getProperty(JSContextRef context,
                JSObjectRef object,
index df68460..65108c9 100644 (file)
 #include <CommonsJavaScript/PrivateObject.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <SecurityExceptions.h>
-#include <Commons/Exception.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+
+//#include <Commons/Exception.h>
+//#include <JSTizenExceptionFactory.h>
+//#include <JSTizenException.h>
 
 #include "plugin_config.h"
+#include <Logger.h>
 
 #include "ApplicationConverter.h"
 #include "ApplicationUtil.h"
@@ -53,13 +57,13 @@ JSClassDefinition JSApplicationControl::m_classInfo = {
     initialize,
     finalize,
     NULL,     //HasProperty,
-    getProperty,
-    setProperty,     //SetProperty,
+    NULL,
+    NULL,     //SetProperty,
     NULL,     //DeleteProperty,
     NULL,     //GetPropertyNames,
     NULL,     //CallAsFunction,
-    constructor,     //CallAsConstructor,
-    hasInstance,
+    NULL,     //CallAsConstructor,
+    NULL,
     NULL,     //ConvertToType
 };
 
@@ -92,7 +96,7 @@ JSObjectRef JSApplicationControl::createJSObject(JSContextRef context, const App
     JSApplicationControlPriv *priv = new JSApplicationControlPriv(context, appsvc);
 
     if (!priv) {
-        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
+        throw TypeMismatchException("Private object is null");
     }
        
     return JSObjectMake(context, getClassRef(), priv);
@@ -102,31 +106,32 @@ JSObjectRef JSApplicationControl::createJSObject(JSContextRef context, const App
 ApplicationControlPtr JSApplicationControl::getApplicationControl(JSContextRef context, JSValueRef value)
 {
        if (!isObjectOfClass(context, value)) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("is not a object class");
        }
        
        JSObjectRef object = JSValueToObject(context, value, NULL);
        if (!object) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("Private object is null");
        }
        
        JSApplicationControlPriv *priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("Private object is null");
        }
        return priv->getObject();
 }
 
-ApplicationControlPtr JSApplicationControl::getPrivateData(JSObjectRef object)
+#if 0
+ApplicationControlPtr JSApplicationControl::getPrivateData(JSContextRef context, JSObjectRef object)
 {
        JSApplicationControlPriv* priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
+               throw TypeMismatchException("Private object is null");
        }
        
        return priv->getObject();
 }
-
+#endif
 
 void JSApplicationControl::initialize(JSContextRef context,JSObjectRef object)
 {
@@ -148,49 +153,38 @@ JSObjectRef JSApplicationControl::constructor(JSContextRef context,
        const JSValueRef arguments[], 
        JSValueRef* exception)
 {
-       if (argumentCount == 0) {
-               LogError("Wrong parameters");
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
-       }
+    ArgumentValidator validator(context, argumentCount, arguments);
 
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+    ApplicationControlPtr appsvc = ApplicationControlPtr(new ApplicationControl());
+       
+    try {
+        appsvc->setOperation(validator.toString(0));
+        appsvc->setUri(validator.toString(1, true, ""));
+        appsvc->setMime(validator.toString(2, true, ""));
+        appsvc->setCategory(validator.toString(3, true, ""));
+
+               JSObjectRef dataArray = validator.toArrayObject(4, true);
+               if (dataArray) {
+                       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+                       std::vector<ApplicationControlDataPtr> appControlDataArray = converter->toApplicationControlDataArray(dataArray);
+                       appsvc->setAppControlDataArray(appControlDataArray);
+               }
+    } catch (const BasePlatformException& err) {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, err);
+               *exception = exceptionObj;
+               return exceptionObj;
+    }
 
-       Try {
-               std::string operation = "";
-               std::string uri = "";
-               std::string mime = "";
-               std::string category = "";
-               std::vector<ApplicationControlDataPtr> appControlDataArray;
+       JSApplicationControlPriv *priv = new JSApplicationControlPriv(context, appsvc);
 
-               operation = converter->toString(arguments[0]);
-               ApplicationUtil util(context, exception);
-               if ((argumentCount > 1) && !util.isNullOrUndefined(arguments[1])) {
-                       uri = converter->toString(arguments[1]);
-               }
-               if ((argumentCount > 2) && !util.isNullOrUndefined(arguments[2])) {
-                       mime = converter->toString(arguments[2]);
-               }
-               if ((argumentCount > 3) && !util.isNullOrUndefined(arguments[3])) {
-                       category = converter->toString(arguments[3]);
-               }
-               if (argumentCount > 4) {
-                       appControlDataArray = converter->toApplicationControlDataArray(arguments[4]);
-               }               
-
-               ApplicationControlPtr appsvc = ApplicationControlPtr(new ApplicationControl(operation, uri, mime, category, appControlDataArray));
-               if (!appsvc) {
-                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "unknow error on constructor");
-                       return NULL;
-               }
-       
-               return createJSObject(context, appsvc);
-               
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
-               
-       }
+    JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
+
+    JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+    JSObjectSetProperty(context, obj, ctorName, constructor,
+        kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+    JSStringRelease(ctorName);
+
+    return obj;
 }
        
 
@@ -199,16 +193,16 @@ bool JSApplicationControl::isObjectOfClass(JSContextRef context, JSValueRef valu
        return JSValueIsObjectOfClass(context, value, getClassRef());
 }
 
-ApplicationControlPtr JSApplicationControl::getPrivData(JSObjectRef object)
+ApplicationControlPtr JSApplicationControl::getPrivData(JSContextRef context, JSObjectRef object)
 {
        LogDebug("entered");
        JSApplicationControlPriv *priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        ApplicationControlPtr result = priv->getObject();
        if (!result) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        return result;
 }
@@ -218,10 +212,11 @@ JSValueRef JSApplicationControl::getProperty(JSContextRef context, JSObjectRef o
 {
     JSApplicationControlPriv *priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
     if (!priv) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error.");
+               DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
        }
 
-    Try {
+    try {
         ApplicationControlPtr appsvc = priv->getObject();
                ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
 
@@ -229,32 +224,48 @@ JSValueRef JSApplicationControl::getProperty(JSContextRef context, JSObjectRef o
             LogDebug("JSApplicationControl::getProperty::operation " << appsvc->getOperation());
             return converter->toJSValueRef(appsvc->getOperation());
         } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_URI)) {
-            LogDebug("JSApplicationControl::getProperty::uri " << appsvc->getUri());
-            return converter->toJSValueRef(appsvc->getUri());
+                       std::string uri = appsvc->getUri();
+            LogDebug("JSApplicationControl::getProperty::uri " << uri);                        
+                       if (uri.empty()) {
+                               return JSValueMakeNull(context);
+                       } else {
+                               return converter->toJSValueRef(uri);
+                       }
         } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_MIME)) {
-            LogDebug("JSApplicationControl::getProperty::mime " << appsvc->getMime());
-            return converter->toJSValueRef(appsvc->getMime());
+                       std::string mime = appsvc->getMime();
+            LogDebug("JSApplicationControl::getProperty::mime " << mime);                      
+                       if (mime.empty()) {
+                               return JSValueMakeNull(context);
+                       } else {
+                               return converter->toJSValueRef(mime);
+                       }
         } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_CATEGORY)) {
-            LogDebug("JSApplicationControl::getProperty::category " << appsvc->getCategory());
-            return converter->toJSValueRef(appsvc->getCategory());
+                       std::string category = appsvc->getCategory();
+            LogDebug("JSApplicationControl::getProperty::category " << category);                      
+                       if (category.empty()) {
+                               return JSValueMakeNull(context);
+                       } else {
+                               return converter->toJSValueRef(category);
+                       }        
                }else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_DATA)) {
                        LogDebug("JSApplicationControl::getProperty::extraData ");
                        return converter->toJSValueRef(appsvc->getAppControlDataArray());
                }
 
-    } Catch(WrtDeviceApis::Commons::Exception) {
-        LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSDOMExceptionFactory::UnknownException.make(context, exception);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
-
        /* do not return undefined object to find method */
     return NULL;
 }
 
 bool JSApplicationControl::setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
 {
-       Try     {
-               ApplicationControlPtr privateData = getPrivData(object);
+       try {
+               ApplicationControlPtr privateData = getPrivData(context, object);
                ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
        
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_OPERATION)) {
@@ -274,9 +285,11 @@ bool JSApplicationControl::setProperty(JSContextRef context, JSObjectRef object,
                        return true;
                } 
 
-       } Catch(WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-        JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
        
        return false;
index d85b0a2..c047517 100755 (executable)
@@ -61,7 +61,7 @@ public:
        /**
          * return private data
          */
-       static ApplicationControlPtr getPrivateData(JSObjectRef object);
+       //static ApplicationControlPtr getPrivateData(JSObjectRef object);
 
 
 private:
@@ -75,7 +75,7 @@ private:
         */
        static void finalize(JSObjectRef object);
 
-    static ApplicationControlPtr getPrivData(JSObjectRef object);
+    static ApplicationControlPtr getPrivData(JSContextRef context, JSObjectRef object);
 
   /**
      * The callback invoked when getting a property's value.
index a626aab..5c35008 100644 (file)
 #include <dpl/shared_ptr.h>
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
+//#include <JSTizenExceptionFactory.h>
+//#include <JSTizenException.h>
+#include <JSUtil.h>
+#include <Logger.h>
 
 #include "JSApplicationControlData.h"
 #include "ApplicationConverter.h"
@@ -47,12 +52,12 @@ JSClassDefinition JSApplicationControlData::m_classInfo =
        initialize,
        finalize,
        NULL, //hasProperty,
-       getProperty, //GetProperty,
-       setProperty, //SetProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
        NULL, //DeleteProperty,
        NULL, //getPropertyNames,
        NULL,
-       constructor,
+       NULL,
        NULL,
        NULL, //ConvertToType,
 };
@@ -75,54 +80,41 @@ JSClassRef JSApplicationControlData::getClassRef() {
        return m_classRef;
 }
 
-JSValueRef JSApplicationControlData::createJSObject(JSContextRef context,
-               const std::string &key,
-               const std::vector<std::string> &value)
+JSObjectRef JSApplicationControlData::createJSObject(JSContextRef context, const ApplicationControlDataPtr &appdata)
 {
-       ApplicationControlDataPtr privateData = ApplicationControlDataPtr(new ApplicationControlData());
+       LogInfo(">> createJSObject");
+       JSApplicationControlDataPriv *priv = new JSApplicationControlDataPriv(context, appdata);
 
-       privateData->setKey(key);
-       privateData->setValue(value);
-       JSApplicationControlDataPriv *priv = new JSApplicationControlDataPriv(context, privateData);
-       
-       JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsValueRef) {
-               LogError("object creation error");
-               return JSValueMakeUndefined(context);
+       if (!priv) {
+               throw TypeMismatchException("Private object is null");
        }
-       
-       return jsValueRef;
+
+       return JSObjectMake(context, getClassRef(), priv);
 }
 
 JSObjectRef JSApplicationControlData::constructor(JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-       if (argumentCount == 0) {
-               LogError("Wrong parameters");
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
-       }       
-
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
-       Try {
-               std::string key;
-               std::vector<std::string> value;
-               
-               if (argumentCount > 0) {
-                       key = converter->toString(arguments[0]);
-               }
-               if (argumentCount > 1) {
-                       if (JSIsArrayValue(context, arguments[1])) {
-                               value = converter->toVectorOfStrings(arguments[1]);
-                       } else {
-                               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-                               return NULL;
-                       }
-               }
-               return JSValueToObject(context, createJSObject(context, key, value), exception);
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
-       }
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+               ApplicationControlDataPtr appdata(new ApplicationControlData());
+
+           appdata->setKey(validator.toString(0));
+               appdata->setValue(JSUtil::JSArrayToStringVector(context, validator.toArrayObject(1)));
+
+               JSApplicationControlDataPriv *priv = new JSApplicationControlDataPriv(context, appdata);
+               JSObjectRef obj = JSObjectMake(context, getClassRef(),priv);
+
+           JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+           JSObjectSetProperty(context, obj, ctorName, constructor,
+               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+           JSStringRelease(ctorName);
+
+           return obj;
+       } catch (BasePlatformException &err) {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, err);
+               *exception = exceptionObj;
+               return exceptionObj;
+    }
 }
 
 void JSApplicationControlData::initialize(JSContextRef context, JSObjectRef object)
@@ -149,11 +141,11 @@ ApplicationControlDataPtr JSApplicationControlData::getPrivData(JSObjectRef obje
        LogDebug("entered");
        JSApplicationControlDataPriv *priv = static_cast<JSApplicationControlDataPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        ApplicationControlDataPtr result = priv->getObject();
        if (!result) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        return result;
 }
@@ -161,15 +153,15 @@ ApplicationControlDataPtr JSApplicationControlData::getPrivData(JSObjectRef obje
 ApplicationControlDataPtr JSApplicationControlData::getApplicationControlData(JSContextRef context, JSValueRef value)
 {
        if (!isObjectOfClass(context, value)) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("is not a object class");
        }
        JSObjectRef object = JSValueToObject(context, value, NULL);
        if (!object) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("Fail to get object");
        }
        JSApplicationControlDataPriv *priv = static_cast<JSApplicationControlDataPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
+               throw TypeMismatchException("Private object is null");
        }
        return priv->getObject();
 }
@@ -180,7 +172,7 @@ JSValueRef JSApplicationControlData::getProperty(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       Try     {
+       try {
                WrtDeviceApis::CommonsJavaScript::Converter converter(context);
                ApplicationControlDataPtr privateData = getPrivData(object);
                
@@ -189,9 +181,11 @@ JSValueRef JSApplicationControlData::getProperty(JSContextRef context,
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_DATA_VALUE)) {
                        return converter.toJSValueRef(privateData->getValue());
                } 
-       } Catch(WrtDeviceApis::Commons::Exception) {
-        LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSDOMExceptionFactory::UnknownException.make(context, exception);
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
        
        return JSValueMakeUndefined(context);
@@ -203,7 +197,7 @@ bool JSApplicationControlData::setProperty(JSContextRef context,
                        JSValueRef value,
                        JSValueRef* exception)
 {
-       Try     {
+       try {
                WrtDeviceApis::CommonsJavaScript::Converter converter(context);
                ApplicationControlDataPtr privateData = getPrivData(object);
                
@@ -214,9 +208,11 @@ bool JSApplicationControlData::setProperty(JSContextRef context,
                        privateData->setValue(converter.toVectorOfStrings(value));
                        return true;                    
                } 
-       } Catch(WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-        JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
        
        return false;
index 672b911..a4539d5 100755 (executable)
@@ -41,9 +41,8 @@ public:
        */
        static JSClassRef getClassRef();
 
-       static JSValueRef createJSObject(JSContextRef context,
-                       const std::string &key,
-                       const std::vector<std::string> &value);
+       static JSObjectRef createJSObject(JSContextRef context, 
+                       const ApplicationControlDataPtr &appdata);
 
        static JSObjectRef constructor(JSContextRef ctx, 
                        JSObjectRef constructor, 
index 00705bc..07940c4 100644 (file)
@@ -22,8 +22,9 @@
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/Converter.h>
 #include <Commons/Exception.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+#include <JSWebAPIException.h>
+//#include <JSTizenExceptionFactory.h>
+//#include <JSTizenException.h>
 #include "ApplicationInformation.h"
 #include "JSApplicationInformation.h"
 #include "AppManagerWrapper.h"
@@ -47,7 +48,7 @@ JSClassDefinition JSApplicationInformation::m_classInfo = {
     initialize,
     finalize,
     NULL,     //HasProperty,
-    getProperty,       //GetProperty,
+    NULL,      //GetProperty,
     NULL,     //SetProperty,
     NULL,     //DeleteProperty,
     NULL,     //GetPropertyNames,
@@ -129,15 +130,15 @@ bool JSApplicationInformation::isObjectOfClass(JSContextRef context, JSValueRef
        return JSValueIsObjectOfClass(context, value, getClassRef());
 }
 
-ApplicationInformationPtr JSApplicationInformation::getPrivData(JSObjectRef object)
+ApplicationInformationPtr JSApplicationInformation::getPrivData(JSContextRef context, JSObjectRef object)
 {
        JSApplicationInformationPriv *priv = static_cast<JSApplicationInformationPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        ApplicationInformationPtr result = priv->getObject();
        if (!result) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
        return result;
 }
@@ -145,17 +146,17 @@ ApplicationInformationPtr JSApplicationInformation::getPrivData(JSObjectRef obje
 ApplicationInformationPtr JSApplicationInformation::getApplicationInformation(JSContextRef context, JSValueRef value)
 {
        if (!isObjectOfClass(context, value)) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("is not a object class");
        }
        
        JSObjectRef object = JSValueToObject(context, value, NULL);
        if (!object) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw TypeMismatchException("Fail to get object");
        }
        
        JSApplicationInformationPriv *priv = static_cast<JSApplicationInformationPriv*>(JSObjectGetPrivate(object));
        if (!priv) {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
+               throw TypeMismatchException("Private object is null");
        }
        
        return priv->getObject();
@@ -166,9 +167,9 @@ JSValueRef JSApplicationInformation::getProperty(JSContextRef context,
        JSStringRef propertyName,
        JSValueRef* exception)
 {
-       Try     {
+       try {
                CommonsJavaScript::Converter converter(context);
-               ApplicationInformationPtr privateData = getPrivData(object);
+               ApplicationInformationPtr privateData = getPrivData(context, object);
 
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_ID)) {
                        return converter.toJSValueRef(privateData->getAppId());
@@ -198,9 +199,11 @@ JSValueRef JSApplicationInformation::getProperty(JSContextRef context,
                                return converter.toJSValueRefLong(privateData->getInstallSize());
                        } 
                }
-       } Catch(WrtDeviceApis::Commons::Exception) {
-        LogError("Exception: " << _rethrown_exception.GetMessage());
-               JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
        
        return JSValueMakeUndefined(context);
index 8a4be87..8170d7f 100755 (executable)
@@ -93,7 +93,7 @@ private:
 
        static JSClassRef m_classRef;
 
-       static ApplicationInformationPtr getPrivData(JSObjectRef object);
+       static ApplicationInformationPtr getPrivData(JSContextRef context, JSObjectRef object);
 
        static JSValueRef getProperty(JSContextRef context,
                JSObjectRef object,
old mode 100755 (executable)
new mode 100644 (file)
index 892fe71..9a9a1fd
 //
 
 
-#include <memory>
+//#include <memory>
+
 #include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
+
+//#include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/JSUtils.h>
+
 #include <CommonsJavaScript/JSCallbackManager.h>
 #include <CommonsJavaScript/Utils.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
+
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
 #include <SecurityExceptions.h>
-#include <Commons/Exception.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+//#include <Commons/Exception.h>
+//#include <JSTizenExceptionFactory.h>
+//#include <JSTizenException.h>
+
 #include "ApplicationFactory.h"
 #include "plugin_config.h"
 #include "ApplicationController.h"
@@ -38,7 +47,9 @@
 #include "ApplicationListenerManager.h"
 #include "ApplicationInformationEventPrivateData.h"
 #include "JSApplicationEventCallbackManager.h"
-#include <bundle.h>
+#include "JSApplication.h"
+
+#include <Logger.h>
 
 namespace DeviceAPI {
 namespace Application {
@@ -66,7 +77,7 @@ JSClassDefinition JSApplicationManager::m_classInfo = {
                NULL, //getPropertyNames,
                NULL,
                NULL,
-               hasInstance,
+               NULL,
                NULL
 };
 
@@ -84,6 +95,7 @@ JSStaticFunction JSApplicationManager::m_function[] = {
                { APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL, JSApplicationManager::launchAppControl, kJSPropertyAttributeNone },
                { APPLICATION_FUNCTION_API_FIND_APP_CONTROL, JSApplicationManager::findAppControl, kJSPropertyAttributeNone },
                { APPLICATION_FUNCTION_API_GET_APP_CERTS, JSApplicationManager::getAppCerts, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_GET_APP_SHARED_URI, JSApplicationManager::getAppSharedURI, kJSPropertyAttributeNone },
                { 0, 0, 0 }
 };
 
@@ -146,48 +158,30 @@ JSValueRef JSApplicationManager::getCurrentApplication(JSContextRef context,
        IApplicationManagerPtr appmgr;
        ApplicationController *controller;
 
-       Try     {
+       try {
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-       Try {
        EventApplicationGetCurrAppPtr event(new EventApplicationGetCurrApp());
        ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
 
                event->setForSynchronousCall();
                appmgr->getCurrentApplication(event);
                
-               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) {
-                       ThrowMsg(NotFoundException, "Given package not found.");
-               } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) {
-                       ThrowMsg(Exception, "Unknown error occurred.");
+               if (event->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None) {
+                       throw UnknownException("Unknown exception occured");
                }
 
                LogError("get Current Application Successfully. convert application to JSValue");
 
-               return converter->toJSValueRefFromApplication(event->getApp());
-    } Catch (NotFoundException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+               //return converter->toJSValueRefFromApplication(event->getApp());
+               return JSApplication::makeObject(context, event->getApp()); 
+       } catch (...) {
+               DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getCurrentApplication().");
+               return JSWebAPIException::throwException(context, exception, err);
        }
 }
 
@@ -201,78 +195,57 @@ JSValueRef JSApplicationManager::launch(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
+       
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_LAUNCH);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       try {
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
 
-       Try     {
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_LAUNCH);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               EventApplicationLaunchPtr event(new EventApplicationLaunch());
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);               
 
-    JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
-       Try {
-       ApplicationUtil util(context, exception);
-       if (argumentCount > 1) {
-               if (util.isFunction(arguments[1])) {
-                       callbackManager->setOnSuccess(arguments[1]);
-               } else if (!util.isNullOrUndefined(arguments[1])) {
-                       ThrowMsg(ConversionException, "Wrong second parameter type.");
-               }
-       }
-
-       if (argumentCount > 2) {
-               if (util.isFunction(arguments[2])) {
-                       callbackManager->setOnError(arguments[2]);
-               } else if (!util.isNullOrUndefined(arguments[2])) {
-                       ThrowMsg(ConversionException, "Wrong third parameter type.");
-               }
-       }
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       callbackManager->setObject(thisObject);
-               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+               // id
+               std::string id = validator.toString(0);
+               event->setAppId(id);
 
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+               // successCallback
+               JSObjectRef successCallback = validator.toFunction(1, true);
+               if (successCallback)
+                       callbackManager->setOnSuccess(successCallback);
 
-       EventApplicationLaunchPtr event(new EventApplicationLaunch());
-       
-               if (argumentCount > 0) {
-                       event->setAppId(converter->toString(arguments[0]));
-               } else {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-               }
+               // errorCallback
+               JSObjectRef errorCallback = validator.toFunction(2, true);
+               if (errorCallback)
+                       callbackManager->setOnError(errorCallback);
+
+       callbackManager->setObject(thisObject);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
 
                event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
                event->setForAsynchronousCall(controller);
 
                appmgr->launch(event);
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       }
-
-       return JSValueMakeUndefined(context);
+               
+               return JSValueMakeUndefined(context);
+
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.launch().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 JSValueRef JSApplicationManager::kill(JSContextRef context, 
@@ -283,80 +256,57 @@ JSValueRef JSApplicationManager::kill(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
 
-       Try     {
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_KILL);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       try {
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
+               
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_KILL);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               EventApplicationKillPtr event(new EventApplicationKill());
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
 
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
-       Try{
-       ApplicationUtil util(context, exception);
-       if (argumentCount > 1) {
-               if (util.isFunction(arguments[1])) {
-                       callbackManager->setOnSuccess(arguments[1]);
-               } else if (!util.isNullOrUndefined(arguments[1])) {
-                ThrowMsg(ConversionException, "Wrong second parameter type.");
-               }
-       }
-
-       if (argumentCount > 2) {
-               if (util.isFunction(arguments[2])) {
-                       callbackManager->setOnError(arguments[2]);
-               } else if (!util.isNullOrUndefined(arguments[2])) {
-                ThrowMsg(ConversionException, "Wrong third parameter type.");
-               }
-       }
+        ArgumentValidator validator(context, argumentCount, arguments);
 
-       callbackManager->setObject(thisObject);
+        // contextId
+       std::string contextId = validator.toString(0);
+               event->setContextId(contextId);
 
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
-       EventApplicationKillPtr event(new EventApplicationKill());
+               // successCallback
+               JSObjectRef successCallback = validator.toFunction(1, true);
+               if (successCallback)
+                       callbackManager->setOnSuccess(successCallback);
 
-               std::string appContextId;
-               if (argumentCount > 0) {
-                       appContextId = converter->toString(arguments[0]);
-               } else {
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-               }
+               // errorCallback
+               JSObjectRef errorCallback = validator.toFunction(2, true);
+               if (errorCallback)
+                       callbackManager->setOnError(errorCallback);
+
+       callbackManager->setObject(thisObject);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
 
-               event->setContextId(appContextId);
                event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
                event->setForAsynchronousCall(controller);
 
                appmgr->kill(event);
-
-               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       }
-
-       return JSValueMakeUndefined(context);
+               
+               return JSValueMakeUndefined(context);
+       
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.kill().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
@@ -368,49 +318,28 @@ JSValueRef JSApplicationManager::setUserAgent(JSContextRef context,
        JSValueRef* exception)
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       ApplicationController *controller;
-
-       Try     {
-               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
-               if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
-               }
-               appmgr = controller->getObject();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-       if (argumentCount < 1) {
-               LogError("Wrong parameters");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
-       }
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       Try {
-               std::string propertyValue;
-               ApplicationUtil util(context, exception);
-               if (util.isString(arguments[0])) {
-                       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
-                       propertyValue = "tizen://changeUA?ua=" + converter->toString(arguments[0]);
-               }else{
-                       LogError("TYPE_MISMATCH_ERROR");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "First parameter should be a DOMString");
-               }
+        // UserAgent
+        std::string userAgent = validator.toString(0);         
 
+               // perform
+               std::string propertyValue = "tizen://changeUA?ua=" + userAgent;
                setTitleProperty(context, propertyValue);
-
-       } Catch (WrtDeviceApis::Commons::UnsupportedException) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not supported");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage() << " Code: " << _rethrown_exception.getCode());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
-       }
-
-       LogDebug(">>>");
-       return JSValueMakeUndefined(context);
+               
+               return JSValueMakeUndefined(context);
+
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.removeAppInfoEventListener().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
+
 JSValueRef JSApplicationManager::launchAppControl(JSContextRef context,
        JSObjectRef object, 
        JSObjectRef thisObject, 
@@ -419,100 +348,77 @@ JSValueRef JSApplicationManager::launchAppControl(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
 
-       Try     {
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);  
+
+       try {
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);  
 
-    JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
-       Try {
+               EventApplicationLaunchAppControlPtr event(new EventApplicationLaunchAppControl());
+           JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
 
-       ApplicationUtil util(context, exception);
+               ArgumentValidator validator(context, argumentCount, arguments);
 
+        // appControl
+        JSObjectRef appControlObj = validator.toObject(0);
+               ApplicationControlPtr appControl = converter->toApplicationControl(appControlObj);
+        if (!appControl) {
+            throw TypeMismatchException("ApplicationControl's private object is NULL.");
+        }
+               event->setAppControl(appControl);
 
-       if (argumentCount > 2) {
-               if (util.isFunction(arguments[2])) {
-                       callbackManager->setOnSuccess(arguments[2]);
-               } else if (!util.isNullOrUndefined(arguments[2])) {
-                       ThrowMsg(ConversionException, "Wrong third parameter type.");
-               }
-       }
+        // id
+        std::string id = validator.toString(1, true, "");
+               LogWarning("id : " << id);
+               event->setAppId(id);
 
-       if (argumentCount > 3) {
-               if (util.isFunction(arguments[3])) {
-                       callbackManager->setOnError(arguments[3]);
-               } else if (!util.isNullOrUndefined(arguments[3])) {
-                       ThrowMsg(ConversionException, "Wrong fourth parameter type.");
-               }
-       }
+               // successCallback
+               JSObjectRef successCallback = validator.toFunction(2, true);
+               if (successCallback)
+                       callbackManager->setOnSuccess(successCallback);
+               
+               // errorCallback
+               JSObjectRef errorCallback = validator.toFunction(3, true);
+               if (errorCallback)
+                       callbackManager->setOnError(errorCallback);
 
-       callbackManager->setObject(thisObject);
+               callbackManager->setObject(thisObject);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
 
-       JSCallbackManagerPtr callbackManagerReply;
-               if (argumentCount > 4) {
-                       if (util.isObject(arguments[4])) {
-                               JSObjectRef cbObj = JSValueToObject(context, arguments[4], exception);
-                               JSValueRef onsuccess = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onsuccess");
-                               JSValueRef onfail = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onfailure");
-
-                               if (!util.isNullOrUndefinedOrFunction(onsuccess) || !util.isNullOrUndefinedOrFunction(onfail)) {
-                    ThrowMsg(ConversionException, "Wrong fifth parameter type.");
-                               }
-
-                               callbackManagerReply = JSCallbackManager::createObject(gContext);
-                               
-                               if (util.isFunction(onsuccess)) {
-                                       callbackManagerReply->setOnSuccess(onsuccess);
-                               }
-
-                               if (util.isFunction(onfail)) {
-                                       callbackManagerReply->setOnError(onfail);
-                               }
-                               
-                               callbackManagerReply->setObject(thisObject);
-
-                       } else if (!util.isNullOrUndefined(arguments[4])) {
-                ThrowMsg(ConversionException, "Wrong fifth parameter type.");
+               // replyCallback
+               JSCallbackManagerPtr callbackManagerReply;
+               JSObjectRef replyCallbackObj = validator.toCallbackObject(4, true, "onsuccess", "onfailure", NULL);
+
+               if (replyCallbackObj) {
+                       callbackManagerReply = JSCallbackManager::createObject(gContext);
+                       
+                       // onsuccess
+                       JSValueRef onsuccess = JSUtil::getProperty(context, replyCallbackObj, "onsuccess", exception);
+                       if (!JSValueIsUndefined(context, onsuccess)) {
+                               callbackManagerReply->setOnSuccess(onsuccess);          
                        }
-               }
-
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
-       EventApplicationLaunchAppControlPtr event(new EventApplicationLaunchAppControl());
-
-               ApplicationControlPtr appControl;
-               if (argumentCount > 0) {
-                       appControl = converter->toApplicationControl(arguments[0]);
-               } else {
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-               }
-
-               std::string appId = "";
-               if ((argumentCount > 1) && !util.isNullOrUndefined(arguments[1])) {
-                       appId = converter->toString(arguments[1]);
-               }
 
-               event->setAppId(appId);
-               event->setAppControl(appControl); 
+                       // onfailure
+                       JSValueRef onfailure = JSUtil::getProperty(context, replyCallbackObj, "onfailure", exception);
+                       if (!JSValueIsUndefined(context, onfailure)) {
+                               callbackManagerReply->setOnError(onfailure);            
+                       }
 
-               event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
-               event->setForAsynchronousCall(controller);
+                       callbackManagerReply->setObject(thisObject);
+                       ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManagerReply, gContext);
 
-               if(callbackManagerReply != NULL)
-               {
                        EventApplicationLaunchAppControlReplyPtr eventReply(new EventApplicationLaunchAppControlReply());
                        eventReply->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManagerReply));
                        eventReply->setForAsynchronousCall(controller);
@@ -520,32 +426,22 @@ JSValueRef JSApplicationManager::launchAppControl(JSContextRef context,
                        event->setEventReply(eventReply);
                }
 
-               appmgr->launchAppControl(event);
-
-               if(callbackManagerReply != NULL)
-                       ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManagerReply, gContext);
+               event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+               event->setForAsynchronousCall(controller);
 
-               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+               appmgr->launchAppControl(event);
                
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       }
+               return JSValueMakeUndefined(context);
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.launchAppControl().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
-    return JSValueMakeUndefined(context);
 }
 
+
 JSValueRef JSApplicationManager::findAppControl(JSContextRef context,
        JSObjectRef object,
        JSObjectRef thisObject,
@@ -554,82 +450,66 @@ JSValueRef JSApplicationManager::findAppControl(JSContextRef context,
        JSValueRef* exception)
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
 
-       Try     {
+       try {
+
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-    JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
-       Try {
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+       EventApplicationFindAppControlPtr event(new EventApplicationFindAppControl());
+           JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
 
-       if (argumentCount <= 1) {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-       }
+               ArgumentValidator validator(context, argumentCount, arguments);
+               
+        // appControl
+        JSObjectRef appControlObj = validator.toObject(0);
+               
+        ApplicationControlPtr appControl = converter->toApplicationControl(appControlObj);
+        if (!appControl) {
+            throw TypeMismatchException("ApplicationControl's private object is NULL.");
+        }
+               event->setAppControl(appControl);
 
-       ApplicationUtil util(context, exception);
-       if ((argumentCount > 1) && util.isFunction(arguments[1])) {
-               callbackManager->setOnSuccess(arguments[1]);
-       } else {
-            ThrowMsg(ConversionException, "Wrong second parameter type.");
-       }
+        // successCallback
+        JSObjectRef successCallbackObj = validator.toFunction(1);
+        if (successCallbackObj) {
+            callbackManager->setOnSuccess(successCallbackObj);
+        }
 
-       if (argumentCount > 2) {
-               if (util.isFunction(arguments[2])) {
-                       callbackManager->setOnError(arguments[2]);
-               } else if (!util.isNullOrUndefined(arguments[2])) {
-                       ThrowMsg(ConversionException, "Wrong third parameter type.");
-               }
-       }
+        // errorCallback
+        JSObjectRef errorCallback = validator.toFunction(2, true);
+               if (errorCallback) {
+                       callbackManager->setOnError(errorCallback);
+               }
 
        callbackManager->setObject(thisObject);
-
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
-       EventApplicationFindAppControlPtr event(new EventApplicationFindAppControl());
-
-               ApplicationControlPtr appControl;
-               if (argumentCount > 0) {
-                       appControl = converter->toApplicationControl(arguments[0]);
-               } else {
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-               }
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
 
                event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
-               event->setAppControl(appControl);
                event->setForAsynchronousCall(controller);
 
                appmgr->findAppControl(event);
-               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
-
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       }
-
-    return JSValueMakeUndefined(context);
+               
+               return JSValueMakeUndefined(context);
+
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.findAppControl().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
+
 JSValueRef JSApplicationManager::getAppsContext(JSContextRef context, 
        JSObjectRef object, 
        JSObjectRef thisObject, 
@@ -638,71 +518,54 @@ JSValueRef JSApplicationManager::getAppsContext(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
 
-       Try     {
+       try {
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-    JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
-       Try {
-       if (argumentCount == 0) {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-       }
-
-       ApplicationUtil util(context, exception);
-       if ((argumentCount > 0) && util.isFunction(arguments[0])) {
-               callbackManager->setOnSuccess(arguments[0]);
-       } else {
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-       }
-
-       if (argumentCount > 1) {
-               if (util.isFunction(arguments[1])) {
-                       callbackManager->setOnError(arguments[1]);
-               } else if (!util.isNullOrUndefined(arguments[1])) {
-                ThrowMsg(ConversionException, "Wrong second parameter type.");
-               }
-       }
+               EventApplicationGetAppsContextPtr event(new EventApplicationGetAppsContext());
+           JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
 
-       callbackManager->setObject(thisObject);
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // successCallback
+        JSObjectRef successCallbackObj = validator.toFunction(0);
+               callbackManager->setOnSuccess(successCallbackObj);
 
-       EventApplicationGetAppsContextPtr event(new EventApplicationGetAppsContext());
+        // errorCallback
+        JSObjectRef errorCallbackObj = validator.toFunction(1, true);
+               if (errorCallbackObj)
+                       callbackManager->setOnError(errorCallbackObj);
 
+       callbackManager->setObject(thisObject);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+               
                event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
                event->setForAsynchronousCall(controller);
 
                appmgr->getAppsContext(event);
-               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       }
-
-       return JSValueMakeUndefined(context);
+               
+               return JSValueMakeUndefined(context);
+               
+       } catch (const BasePlatformException &err) {
+               LogDebug("BasePlatformException");
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+           LogDebug("etc...");
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppsContext().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
+
 JSValueRef JSApplicationManager::getAppContext(JSContextRef context, 
        JSObjectRef object, 
        JSObjectRef thisObject, 
@@ -711,68 +574,47 @@ JSValueRef JSApplicationManager::getAppContext(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       ApplicationController *controller;
 
-       Try     {
+       try {
+               IApplicationManagerPtr appmgr;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-       Try {
        EventApplicationGetAppContextPtr event(new EventApplicationGetAppContext());
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
 
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+        // contextId
+        std::string contextId = validator.toString(0, true, "");
+               LogDebug("contextId : " << contextId);
+               event->setAppContextId(contextId);
                event->setForSynchronousCall();
-               ApplicationUtil util(context, exception);
-               if (argumentCount > 0 && !util.isNullOrUndefined(arguments[0])) {
-                       event->setAppContextId(converter->toString(arguments[0]));
-               }
+
                appmgr->getAppContext(event);
 
-               if (event->getExceptionCode() != ExceptionCodes::None)
-               {
-                       switch (event->getExceptionCode())
-                       {
-                       case ExceptionCodes::NotFoundException:
-                       case ExceptionCodes::InvalidArgumentException:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Watch id not found");
-                               break;
-                       case ExceptionCodes::PlatformException:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
-                               break;
-                       default:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
-                               break;
-                       }
+               if (event->getExceptionCode() == ExceptionCodes::NotFoundException) {
+                       throw NotFoundException("Cannot found context with given context ID");
+               } else if (event->getExceptionCode() != ExceptionCodes::None) {
+                       throw UnknownException("Unknown exception occured");
                }
 
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
                return converter->toJSValueRefFromApplicationContext(event->getAppContext());
 
-       } Catch (NotFoundException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppContext().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
+
 JSValueRef JSApplicationManager::getAppsInfo(JSContextRef context, 
        JSObjectRef object, 
        JSObjectRef thisObject, 
@@ -781,70 +623,53 @@ JSValueRef JSApplicationManager::getAppsInfo(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
 
-       Try     {
+       try {
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-    JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
-       Try{
-       if (argumentCount == 0) {
-               ThrowMsg(ConversionException, "Wrong parameter type.");
-       }
-
-       ApplicationUtil util(context, exception);
-       if ((argumentCount > 0) && util.isFunction(arguments[0])) {
-               callbackManager->setOnSuccess(arguments[0]);
-       } else {
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-       }
-
-       if (argumentCount > 1) {
-               if (util.isFunction(arguments[1])) {
-                       callbackManager->setOnError(arguments[1]);
-               } else if (!util.isNullOrUndefined(arguments[1])) {
-                ThrowMsg(ConversionException, "Wrong second parameter type.");
-               }
-       }
+               EventApplicationGetAppsInfoPtr event(new EventApplicationGetAppsInfo());
+           JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
 
-       callbackManager->setObject(thisObject);
-               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+        ArgumentValidator validator(context, argumentCount, arguments);
 
-       EventApplicationGetAppsInfoPtr event(new EventApplicationGetAppsInfo());
+        // successCallback
+        JSObjectRef successCallbackObj = validator.toFunction(0);
+               callbackManager->setOnSuccess(successCallbackObj);
+
+        // errorCallback
+        JSObjectRef errorCallbackObj = validator.toFunction(1, true);
+               if (errorCallbackObj) {
+                       callbackManager->setOnError(errorCallbackObj);
+               }
+
+               callbackManager->setObject(thisObject);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
 
                event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
                event->setForAsynchronousCall(controller);
+
                appmgr->getAppsInfo(event);
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-           LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-           LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       } Catch (Exception) {
-           LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage()));
-               return JSValueMakeNull(context);
-       }
-       
-       return JSValueMakeUndefined(context);
+                       
+               return JSValueMakeUndefined(context);
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppsInfo().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
+
 JSValueRef JSApplicationManager::getAppInfo(JSContextRef context, 
        JSObjectRef object, 
        JSObjectRef thisObject, 
@@ -853,54 +678,44 @@ JSValueRef JSApplicationManager::getAppInfo(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       ApplicationController *controller;
 
-       Try     {
+       try {
+               IApplicationManagerPtr appmgr;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-       Try {
        EventApplicationGetAppInfoPtr event(new EventApplicationGetAppInfo());
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // id
+        std::string id = validator.toString(0, true, "");
+               event->setAppId(id);
 
                event->setForSynchronousCall();
-               ApplicationUtil util(context, exception);
-               if (argumentCount > 0 && !util.isNullOrUndefined(arguments[0])) {
-                       event->setAppId(converter->toString(arguments[0]));
-               }
+
                appmgr->getAppInfo(event);
                
                if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) {
-                       ThrowMsg(NotFoundException, "Given package not found.");
+                       throw NotFoundException("Given package not found.");
                } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) {
-                       ThrowMsg(Exception, "Unknown error occurred.");
+                       throw UnknownException("Unknown error occurred.");
                }
 
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
                return converter->toJSValueRefFromApplicationInformation(event->getAppInfo());
-    } Catch (NotFoundException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+               
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppInfo().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 JSValueRef JSApplicationManager::addAppInfoEventListener(JSContextRef context, 
@@ -911,97 +726,71 @@ JSValueRef JSApplicationManager::addAppInfoEventListener(JSContextRef context,
        JSValueRef* exception) 
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
 
-       Try     {
+       try {
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-       Try {
-       ApplicationUtil util(context, exception);
-       if ((argumentCount < 1) || (!util.isObject(arguments[0]))) {
-               ThrowMsg(ConversionException, "Wrong parameter type.");
-       }
 
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+               EventApplicationAddAppInfoEventListenerPtr event(new EventApplicationAddAppInfoEventListener());
 
-               JSObjectRef cbObj = converter->toJSObjectRef(arguments[0]);
-           JSValueRef onInstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "oninstalled");
-           JSValueRef onUpdated = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onupdated");
-           JSValueRef onUninstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onuninstalled");
+        ArgumentValidator validator(context, argumentCount, arguments);
+               
+               // eventCallback
+               JSObjectRef eventCBObj = validator.toCallbackObject(0, false, "oninstalled", "onupdated", "onuninstalled", NULL);
+               JSApplicationEventCallbackManagerPtr callbackManager = JSApplicationEventCallbackManager::createObject(gContext);
 
-               if (!util.isNullOrUndefinedOrFunction(onInstalled) || !util.isNullOrUndefinedOrFunction(onUpdated) || !util.isNullOrUndefinedOrFunction(onUninstalled)) {
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
+               JSValueRef oninstalled = JSUtil::getProperty(context, eventCBObj, "oninstalled", exception);
+               if (!JSValueIsUndefined(context, oninstalled)) {
+                       callbackManager->setOnInstalled(oninstalled);
                }
 
-               JSApplicationEventCallbackManagerPtr callbackManager =
-                               JSApplicationEventCallbackManager::createObject(gContext);
-               if (util.isFunction(onInstalled)) {
-                       callbackManager->setOnInstalled(onInstalled);
+               JSValueRef onupdated = JSUtil::getProperty(context, eventCBObj, "onupdated", exception);
+               if (!JSValueIsUndefined(context, onupdated)) {
+                       callbackManager->setOnUpdated(onupdated);
                }
-               if (util.isFunction(onUpdated)) {
-                       callbackManager->setOnUpdated(onUpdated);
-               }
-               if (util.isFunction(onUninstalled)) {
-                       callbackManager->setOnUninstalled(onUninstalled);
+
+               JSValueRef onuninstalled = JSUtil::getProperty(context, eventCBObj, "onuninstalled", exception);
+               if (!JSValueIsUndefined(context, onuninstalled)) {
+                       callbackManager->setOnUninstalled(onuninstalled);
                }
+
                EventApplicationAppInfoEventListenerEmitterPtr emitter(new EventApplicationAppInfoEventListenerEmitter());
 
                emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
                emitter->setListener(controller);
 
-       EventApplicationAddAppInfoEventListenerPtr event(new EventApplicationAddAppInfoEventListener());
-
        event->setEmitter(emitter);
                event->setForSynchronousCall();
 
                appmgr->addAppInfoEventListener(event);
 
-               if (event->getExceptionCode() != ExceptionCodes::None)
-               {
-                       switch (event->getExceptionCode())
-                       {
-                       case ExceptionCodes::InvalidArgumentException:
-                       case ExceptionCodes::PlatformException:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
-                               break;
-                       default:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
-                               break;
-                       }
+               if (event->getExceptionCode() != ExceptionCodes::None) {
+                       throw UnknownException("Unknown Exception Occured");
                }
 
                unsigned long id = event->getWatchId();
 
-               if (id == 0) {
-                       ThrowMsg(UnsupportedException, "Only one event listener can be registered.");
-               }
-
                ApplicationListenerCancellerPtr canceller = ApplicationListenerCancellerPtr(new ApplicationListenerCanceller(gContext, thisObject, id));
                DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
                ApplicationListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
 
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
                return converter->toJSValueRef(id);
-       } Catch (WrtDeviceApis::Commons::ConversionException) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error");
-       } Catch (WrtDeviceApis::Commons::UnsupportedException) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not supported"); 
-       } Catch (WrtDeviceApis::Commons::InvalidArgumentException) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage() << " Code: " << _rethrown_exception.getCode());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
-       }
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.addAppInfoEventListener().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 JSValueRef JSApplicationManager::removeAppInfoEventListener(JSContextRef context,
@@ -1012,77 +801,50 @@ JSValueRef JSApplicationManager::removeAppInfoEventListener(JSContextRef context
         JSValueRef* exception)
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       JSContextRef gContext;
-       ApplicationController *controller;
 
-       Try     {
+       try {
+               IApplicationManagerPtr appmgr;
+               JSContextRef gContext;
+               ApplicationController *controller;
+
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
                gContext = controller->getContext();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
 
-    Try {
-       if (argumentCount == 0) {
-               ThrowMsg(ConversionException, "Wrong parameter type.");
-       }
+       EventApplicationRemoveAppInfoEventListenerPtr event(new EventApplicationRemoveAppInfoEventListener());
 
-               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+        ArgumentValidator validator(context, argumentCount, arguments);
 
-       EventApplicationRemoveAppInfoEventListenerPtr event(new EventApplicationRemoveAppInfoEventListener());
+        // watchId
+        long watchId = validator.toLong(0);
+               LogDebug("watchId : " << watchId);
+               event->setWatchId(watchId);
 
                event->setForSynchronousCall();
 
-               long id = converter->toLong(arguments[0]);
-               event->setWatchId(id);
-
                appmgr->removeAppInfoEventListener(event);
 
-               if (event->getExceptionCode() != ExceptionCodes::None)
-               {
-                       switch (event->getExceptionCode())
-                       {
-                       case ExceptionCodes::NotFoundException:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Watch id not found");
-                               break;
-                       case ExceptionCodes::InvalidArgumentException:
-                       case ExceptionCodes::PlatformException:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
-                               break;
-                       default:
-                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
-                               break;
-                       }
-               }
-
-        ApplicationListenerCancellerPtr canceller = ApplicationListenerCancellerPtr(new ApplicationListenerCanceller(gContext, thisObject, id));
+        ApplicationListenerCancellerPtr canceller = ApplicationListenerCancellerPtr(new ApplicationListenerCanceller(gContext, thisObject, watchId));
        DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
        ApplicationListenerManagerSingleton::Instance().unregisterListener(listenerItem);
 
-       } Catch (NotFoundException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
+               if (event->getExceptionCode() == ExceptionCodes::NotFoundException) {
+                       throw NotFoundException("Watch id not found");
+               }\relse if (event->getExceptionCode() != ExceptionCodes::None) {
+                       throw UnknownException("UnknownException Occured");
+               }
+
+           return JSValueMakeUndefined(context);
 
-    return JSValueMakeUndefined(context);
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.removeAppInfoEventListener().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
@@ -1094,64 +856,98 @@ JSValueRef JSApplicationManager::getAppCerts(JSContextRef context,
        JSValueRef* exception)
 {
        LogDebug("entered");
-       IApplicationManagerPtr appmgr;
-       ApplicationController *controller;
 
-       LogError("JSApplicationManager::getAppCerts");
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_GET_APP_CERTS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+       try {
+               IApplicationManagerPtr appmgr;
+               ApplicationController *controller;
 
-       Try     {
                controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
                if (!controller) {
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("No private object.");
                }
                appmgr = controller->getObject();
-       } Catch(Exception) {
-               LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_GET_APP_CERTS);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       Try {
        EventApplicationGetAppCertsPtr event(new EventApplicationGetAppCerts());
-       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // id
+        std::string id = validator.toString(0, true, "");
+               event->setAppId(id);
 
                event->setForSynchronousCall();
-               ApplicationUtil util(context, exception);
-               if (argumentCount > 0 && !util.isNullOrUndefined(arguments[0])) {
-                       event->setAppId(converter->toString(arguments[0]));
-               }
+
                appmgr->getAppCerts(event);
-               
+
                if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) {
-                       ThrowMsg(NotFoundException, "Given package not found.");
+                       throw NotFoundException("Given package not found.");
                } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) {
-                       ThrowMsg(Exception, "Unknown error occurred.");
+                       throw UnknownException("Unknown error occurred.");
                }
-
+               
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
                return converter->toJSValueRefFromeApplicationCerts(event->getAppCerts());
-    } Catch (NotFoundException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       } Catch (ConversionException) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       } Catch (UnsupportedException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); 
-       } Catch (InvalidArgumentException) {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       } Catch (Exception) {
-        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
+               
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppCerts().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
+JSValueRef JSApplicationManager::getAppSharedURI(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+
+       try {
+               IApplicationManagerPtr appmgr;
+               ApplicationController *controller;
+
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       throw TypeMismatchException("No private object.");
+               }
+               appmgr = controller->getObject();
+
+       EventApplicationGetAppSharedURIPtr event(new EventApplicationGetAppSharedURI());
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // id
+        std::string id = validator.toString(0, true, "");
+               event->setAppId(id);
+
+               event->setForSynchronousCall();
+
+               appmgr->getAppSharedURI(event);
+               
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) {
+                       throw NotFoundException("Given package not found.");
+               } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) {
+                       throw UnknownException("Unknown error occurred.");
+               }
+
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+               return converter->toJSValueRef(event->getSharedURI());
+
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+}
+
 void JSApplicationManager::setTitleProperty(JSContextRef context, std::string propertyValue){
        LogDebug("<<<propertyValue:[" << propertyValue << "]");
 
index 4c6b0fe..3f28d1d 100644 (file)
@@ -133,6 +133,11 @@ private:
        static JSValueRef getAppCerts(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
                        const JSValueRef arguments[], JSValueRef* exception);
 
+       /**
+        * Get shared directory URI of specific application
+        */
+       static JSValueRef getAppSharedURI(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
 
        /**
         * This structure contains properties and callbacks that define a type of object.
index 014fdc6..0e44e7e 100755 (executable)
 #include <Commons/FunctionDeclaration.h>\r
 \r
 // feature : launch\r
-#define APPLICATION_FUNCTION_API_LAUNCH                        "launch"\r
-#define APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL    "launchAppControl"\r
+#define APPLICATION_FUNCTION_API_LAUNCH                                                "launch"\r
+#define APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL                            "launchAppControl"\r
 \r
 // feature : kill - public candidate\r
-#define APPLICATION_FUNCTION_API_KILL                          "kill"\r
+#define APPLICATION_FUNCTION_API_KILL                                                  "kill"\r
 \r
-// feature : read\r
+// feature : certificate - public candidate\r
+#define APPLICATION_FUNCTION_API_GET_APP_CERTS                                 "getAppCerts"\r
+\r
+// no feature required\r
 #define APPLICATION_FUNCTION_API_GET_APPS_INFO                                 "getAppsInfo"\r
 #define APPLICATION_FUNCTION_API_GET_APP_INFO                                  "getAppInfo"\r
 #define APPLICATION_FUNCTION_API_GET_APPS_CONTEXT                              "getAppsContext"\r
 #define APPLICATION_FUNCTION_API_FIND_APP_CONTROL                              "findAppControl"\r
 #define APPLICATION_FUNCTION_API_ADD_APP_INFO_EVENT_LISTENER   "addAppInfoEventListener"\r
 #define APPLICATION_FUNCTION_API_REMOVE_APP_INFO_EVENT_LISTENER        "removeAppInfoEventListener"\r
-\r
-// feature : certificate - public candidate\r
-#define APPLICATION_FUNCTION_API_GET_APP_CERTS                                 "getAppCerts"\r
-\r
-// no feature required\r
 #define APPLICATION_FUNCTION_API_GET_CURRENT_APP                               "getCurrentApplication"\r
 #define APPLICATION_FUNCTION_API_GET_REQUESTED_APP_CONTROL             "getRequestedAppControl"\r
 #define APPLICATION_FUNCTION_API_EXIT                                                  "exit"\r
 #define APPLICATION_FUNCTION_API_HIDE                                                  "hide"\r
 #define APPLICATION_FUNCTION_API_REPLY_RESULT                                  "replyResult"\r
 #define APPLICATION_FUNCTION_API_REPLY_FAILURE                                 "replyFailure"\r
+#define APPLICATION_FUNCTION_API_GET_APP_SHARED_URI                            "getAppSharedURI"\r
 #define APPLICATION_FUNCTION_API_SET_USER_AGENT                                        "setUserAgent"\r
 \r
 namespace DeviceAPI {\r
index ec067b4..d4614ee 100755 (executable)
@@ -30,6 +30,17 @@ using namespace WrtDeviceApis::Commons;
 namespace DeviceAPI {
 namespace Application {
 
+class_definition_options_t ApplicationOptions =
+{
+    JS_INTERFACE,
+    CREATE_INSTANCE,
+    NONE_NOTICE,
+    USE_OVERLAYED, //ignored
+    NULL,
+    NULL,
+    NULL
+};
+
 void on_widget_start_callback(int widgetId) {
        LogDebug("[Tizen1_0\\Application] on_widget_start_callback ("<<widgetId<<")");
     Try {
@@ -73,17 +84,19 @@ PLUGIN_CLASS_MAP_BEGIN
                (js_class_template_getter)DeviceAPI::Application::JSApplicationManager::getClassRef,
                NULL)
 
-       PLUGIN_CLASS_MAP_ADD_CLASS(
+       PLUGIN_CLASS_MAP_ADD_INTERFACE(
                WRT_JS_EXTENSION_OBJECT_TIZEN,
                TIZEN_INTERFACE_APPLICATION_CONTROL,
                (js_class_template_getter)DeviceAPI::Application::JSApplicationControl::getClassRef,
-               NULL)
+               reinterpret_cast<js_class_constructor_cb_t>(JSApplicationControl::constructor),
+               &ApplicationOptions)
 
-       PLUGIN_CLASS_MAP_ADD_CLASS(
+       PLUGIN_CLASS_MAP_ADD_INTERFACE(
                WRT_JS_EXTENSION_OBJECT_TIZEN,
                TIZEN_INTERFACE_APPLICATION_CONTROL_DATA,
                (js_class_template_getter)DeviceAPI::Application::JSApplicationControlData::getClassRef,
-               NULL)
+               reinterpret_cast<js_class_constructor_cb_t>(JSApplicationControlData::constructor),
+               &ApplicationOptions)
 
 PLUGIN_CLASS_MAP_END
 
diff --git a/src/Bluetooth/BTDevice.h b/src/Bluetooth/BTDevice.h
deleted file mode 100644 (file)
index ed4504b..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BT_DEVICE_H_
-#define TIZENAPIS_API_BT_DEVICE_H_
-
-#include <ctime>
-#include <dpl/shared_ptr.h>
-
-namespace DeviceAPI {
-namespace Bluetooth {
-    
-struct BluetoothDeviceDataClass 
-{
-       unsigned short major;
-       unsigned short minor;
-       int majorServiceMask;
-};
-
-class BluetoothDeviceData
-{
-public:
-       std::string name;
-       std::string address;
-       BluetoothDeviceDataClass btClass;
-       bool isBonded;
-       bool isTrusted;
-       bool isConnected;
-       std::vector<std::string> uuids;
-
-       BluetoothDeviceData() { btClass.major = 0; btClass.minor = 0; btClass.majorServiceMask = 0; isBonded = false; isTrusted = false; isConnected = false; };
-       ~BluetoothDeviceData() {};                      
-};
-
-typedef DPL::SharedPtr<BluetoothDeviceData> BluetoothDeviceDataPtr;
-
-struct BluetoothSocketData
-{
-       std::string uuid;
-       bool isServer;
-       unsigned short int protocol;
-       unsigned short int state;
-       int connectedSocket;
-       int registeredSocket;
-       BluetoothDeviceData peerDevice;
-};
-
-} 
-} 
-
-#endif 
diff --git a/src/Bluetooth/BluetoothAdapter.cpp b/src/Bluetooth/BluetoothAdapter.cpp
new file mode 100644 (file)
index 0000000..ecabee9
--- /dev/null
@@ -0,0 +1,1493 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <Logger.h>
+#include <JSWebAPIError.h>
+#include <system_info.h>
+#include <JSUtil.h>
+
+#include "BluetoothAdapter.h"
+#include "BluetoothCallbackUtil.h"
+#include "JSBluetoothDevice.h"
+#include "JSBluetoothServiceHandler.h"
+#include "JSBluetoothSocket.h"
+
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+pthread_mutex_t count_mutex     = PTHREAD_MUTEX_INITIALIZER;
+
+
+void BluetoothAdapter::onStateChangedCB(int result, bt_adapter_state_e adapterState, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+    object->mEnabled = (adapterState == BT_ADAPTER_ENABLED) ? true : false;
+
+    if(object->mUserDataList[SET_POWERED] != NULL) {  // requested event
+        bool state = (adapterState == BT_ADAPTER_ENABLED) ? true : false;    
+        if(object->mRequestedState != state) {
+            LogWarning("Requested state is same to current state");
+            return;        
+        }
+        
+        MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[SET_POWERED]);
+        
+        if(result == BT_ERROR_NONE) {
+            if(callback)
+                callback->invokeCallback("success");
+        }
+        else if(result == BT_ERROR_RESOURCE_BUSY) {
+            if(callback) {
+                JSContextRef context = callback->getContext();
+                ServiceNotAvailableException error("Bluetooth device is busy");
+                callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
+            }    
+        }
+        else {
+            if(callback) {
+                JSContextRef context = callback->getContext();
+                UnknownException error("Unknown error");
+                callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));        
+            }
+        }
+        
+        object->mUserDataList[SET_POWERED].reset();
+    }
+    else {  // unexpected event
+        LogWarning("Bluetooth state is changed unexpectedly");
+    }
+}
+
+void BluetoothAdapter::onNameChangedCB(char *name, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+
+    if(object->mUserDataList[SET_NAME] != NULL && !strcmp(object->mRequestedName.c_str(), name)) {  // requested event      
+        MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[SET_NAME]);
+        if(callback)
+            callback->invokeCallback("success");
+        
+        object->mUserDataList[SET_NAME].reset();
+        bt_adapter_unset_name_changed_cb();
+    }
+    else {  // unexpected event
+        LogWarning("Bluetooth name is changed unexpectedly");
+    }
+}
+
+void BluetoothAdapter::onVisibilityChangedCB(int result, bt_adapter_visibility_mode_e visibilityMode, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+
+    if(object->mUserDataList[SET_VISIBLE] != NULL) {  // requested event
+        //bool visibility = (visibilityMode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) ? false : true;    
+        if(object->mRequestedVisibility != visibilityMode) {
+            LogWarning("Requested visibility is not same to current visibility");
+            return;
+        }    
+    
+        MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[SET_VISIBLE]);
+        
+        if(result == BT_ERROR_NONE) {
+            if(callback)
+                callback->invokeCallback("success");
+        }
+        else {
+            if(callback) {
+                JSContextRef context = callback->getContext();
+                UnknownException error("Unknown error");
+                callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));        
+            }
+        }
+        
+        object->mUserDataList[SET_VISIBLE].reset();
+        bt_adapter_unset_visibility_mode_changed_cb();
+    }
+    else {  // unexpected event
+        LogWarning("Bluetooth visibility is changed unexpectedly");
+    }
+}
+
+void BluetoothAdapter::onDiscoveryStateChangedCB(int result, bt_adapter_device_discovery_state_e discoveryState, 
+        bt_adapter_device_discovery_info_s *discoveryInfo, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+
+    switch(discoveryState) {
+        case BT_ADAPTER_DEVICE_DISCOVERY_STARTED:
+        {
+            LogDebug("BT_ADAPTER_DEVICE_DISCOVERY_STARTED");
+            if(object->mUserDataList[DISCOVER_DEVICES] != NULL) {  // requested event
+                MultiCallbackUserDataPtr callback = 
+                        static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[DISCOVER_DEVICES]);
+                        
+                if(result == BT_ERROR_NONE) {
+
+                    // store MAC address of previously found device into mDisappearedDevices
+                    object->mDisappearedDevices.clear();
+                    for(std::vector<BluetoothDeviceSharedPtr>::iterator iter = object->mFoundDevices.begin(); 
+                            iter != object->mFoundDevices.end(); iter++) {
+                        BluetoothDeviceSharedPtr foundDevice = *iter;
+                        object->mDisappearedDevices.push_back(foundDevice->getAddress());
+                    }
+                    
+                    object->mFoundDevices.clear();
+                    if(callback)
+                        callback->invokeCallback("onstarted");
+                }
+                else {
+                    if(callback) {
+                        JSContextRef context = callback->getContext();
+                        UnknownException error("Unknown error");
+                        callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
+                        LogDebug("Reset DISCOVER_DEVICES");
+                        object->mUserDataList[DISCOVER_DEVICES].reset();
+                    }
+                    
+                    if(object->mUserDataList[STOP_DISCOVERY] == NULL)    // because same core API callback is used 
+                        bt_adapter_unset_device_discovery_state_changed_cb();
+                }            
+            }
+            else {  // unexpected event
+                LogWarning("Unexpected discovery");
+            }
+            break;
+        }
+        case BT_ADAPTER_DEVICE_DISCOVERY_FINISHED:
+        {
+            LogDebug("BT_ADAPTER_DEVICE_DISCOVERY_FINISHED");
+            if(result == BT_ERROR_NONE || result == BT_ERROR_CANCELLED) {
+                // in case of discoverDevices()
+                if(object->mUserDataList[DISCOVER_DEVICES] != NULL) {
+                    MultiCallbackUserDataPtr callback = 
+                            static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[DISCOVER_DEVICES]);
+
+                    if(callback) {
+                        LogDebug("Call onfinished()");
+                        if(object->mDisappearedDevices.size() > 0) {
+                            LogDebug("There are disappeared devices");
+                            for(std::vector<std::string>::iterator iter = object->mDisappearedDevices.begin();
+                                    iter != object->mDisappearedDevices.end(); iter++) {
+                        
+                                callback->invokeCallback("ondevicedisappeared",
+                                        JSUtil::toJSValueRef(callback->getContext(), *iter));                                
+                            }
+                        }
+                        
+                        if(object->mFoundDevices.size() > 0) { // There are found devices
+                            LogDebug("There are found devices");                        
+                            int num = object->mFoundDevices.size();
+                            JSObjectRef devices[num];
+                            for(int i = 0; i < num; i++) {
+                                JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(callback->getContext(), object->mFoundDevices[i]);                        
+                                devices[i] = deviceObj;
+                            }
+                        
+                            callback->invokeCallback(
+                                    "onfinished",
+                                    JSObjectMakeArray(callback->getContext(), num, devices, NULL) );                            
+                        }
+                        else {  // There is no found device
+                            LogDebug("There is no found device");
+                            callback->invokeCallback(
+                                    "onfinished",
+                                    JSObjectMakeArray(callback->getContext(), 0, NULL, NULL) );
+                        }
+
+                        LogDebug("Reset DISCOVER_DEVICES");
+                        object->mUserDataList[DISCOVER_DEVICES].reset();                
+                    }
+                }
+
+                // in case of stopDiscovery()
+                if(object->mUserDataList[STOP_DISCOVERY] != NULL) {
+                    MultiCallbackUserDataPtr callback = 
+                            static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[STOP_DISCOVERY]);
+
+                    if(callback) {
+                        LogDebug("Call successCallback of stopDiscovery()");
+                        callback->invokeCallback("success");
+                        object->mUserDataList[STOP_DISCOVERY].reset();
+                    }
+                }
+
+                bt_adapter_unset_device_discovery_state_changed_cb();
+            }
+            else {
+                LogWarning("result MUST be BT_ERROR_NONE or BT_ERROR_CANCELLED when BT_ADAPTER_DEVICE_DISCOVERY_FINISHED");
+            }
+            break;
+        }
+        case BT_ADAPTER_DEVICE_DISCOVERY_FOUND:
+        {
+            LogDebug("BT_ADAPTER_DEVICE_DISCOVERY_FOUND");
+            if(!discoveryInfo) {
+                LogWarning("discoveryInfo is NULL");
+                return;    
+            }
+        
+            if(object->mUserDataList[DISCOVER_DEVICES] != NULL) {  // requested event
+                MultiCallbackUserDataPtr callback = 
+                        static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[DISCOVER_DEVICES]);
+                        
+                if(result == BT_ERROR_NONE) {
+                    // create BluetoothDevice
+                    BluetoothDeviceSharedPtr device(new BluetoothDevice(discoveryInfo));
+                    JSContextRef context = callback->getContext();
+                    JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(context, device);
+                    object->mFoundDevices.push_back(device);
+
+                    // remove MAC address of found device from mDisappearedDevices
+                    for(std::vector<std::string>::iterator iter = object->mDisappearedDevices.begin();
+                            iter != object->mDisappearedDevices.end(); iter++) {
+                        if(!strcmp(discoveryInfo->remote_address, (*iter).c_str())) {
+                            LogDebug("This device is still found");
+                            object->mDisappearedDevices.erase(iter);
+                            break;
+                        }
+                    }
+
+                    if(callback)
+                        callback->invokeCallback("ondevicefound", deviceObj);
+                }
+                else {
+                    LogWarning("result MUST be BT_ERROR_NONE when BT_ADAPTER_DEVICE_DISCOVERY_FOUND");
+                }            
+            }
+            else {  // unexpected event
+                LogWarning("Unexpected discovery");
+            }
+            break;
+        }
+        default:
+        {
+            LogWarning("Unknown state");
+        }
+    }
+}
+
+bool BluetoothAdapter::foreachBondedDevicesCB(bt_device_info_s *deviceInfo, void *userData)
+{
+    LogDebug("Entered");
+    
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return true;
+    }
+
+    if(deviceInfo == NULL) {
+        LogWarning("deviceInfo is NULL");
+        return true;
+    }
+
+    std::vector<BluetoothDeviceSharedPtr>::iterator iter;
+    for(iter = object->mFoundDevices.begin(); iter != object->mFoundDevices.end(); ++iter) {
+        BluetoothDeviceSharedPtr foundDevice = *iter;
+
+        if(!strcmp(foundDevice->getAddress().c_str(), deviceInfo->remote_address)) {
+            LogDebug("Already known device");
+            foundDevice->updateInfo(deviceInfo);
+            break;
+        }
+    }
+
+    if(iter == object->mFoundDevices.end()) {
+        LogDebug("Add a device into foundDevices");
+        BluetoothDeviceSharedPtr device(new BluetoothDevice(deviceInfo));
+        object->mFoundDevices.push_back(device);        
+    }
+
+    return true;
+}
+
+void BluetoothAdapter::onBondCreatedCB(int result, bt_device_info_s *deviceInfo, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+   
+    if(!deviceInfo) {
+        LogWarning("deviceInfo is NULL");
+        return;    
+    }
+
+    if(object->mUserDataList[CREATE_BONDING] != NULL &&
+            !strcmp(object->mCreateBondingAddress.c_str(), deviceInfo->remote_address)) {  // requested event
+    
+        MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[CREATE_BONDING]);
+        
+        if(result == BT_ERROR_NONE && deviceInfo != NULL) {
+            if(callback) {
+                BluetoothDeviceSharedPtr device(new BluetoothDevice(deviceInfo));
+                JSContextRef context = callback->getContext();
+                JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(context, device);
+                callback->invokeCallback("success", deviceObj);
+            }
+        }
+        else {
+            if(callback) {
+                JSContextRef context = callback->getContext();
+                UnknownException error("Unknown error");
+                callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));        
+            }
+        }
+        
+        object->mUserDataList[CREATE_BONDING].reset();
+        bt_device_unset_bond_created_cb();
+        object->mCreateBondingAddress.clear();
+    }
+    else {  // unexpected event
+        LogWarning("A bonding is created unexpectedly");
+    }
+}
+
+void BluetoothAdapter::onBondDestroyedCB(int result, char *remoteAddress, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+
+    if(object->mUserDataList[DESTROY_BONDING] != NULL &&
+            !strcmp(object->mDestroyBondingAddress.c_str(), remoteAddress)) {  // requested event
+    
+        MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(object->mUserDataList[DESTROY_BONDING]);
+        
+        if(result == BT_ERROR_NONE) {
+            if(callback)
+                callback->invokeCallback("success");
+        }
+        else {
+            if(callback) {
+                JSContextRef context = callback->getContext();
+                UnknownException error("Unknown error");
+                callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));        
+            }
+        }
+        
+        object->mUserDataList[DESTROY_BONDING].reset();
+        bt_device_unset_bond_destroyed_cb();
+        object->mDestroyBondingAddress.clear();
+    }
+    else {  // unexpected event
+        LogWarning("A bonding is created unexpectedly");
+    }
+}
+
+void BluetoothAdapter::onSocketConnected(int result, bt_socket_connection_state_e state, bt_socket_connection_s *connection, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+
+    if(!connection) {
+        LogWarning("connection is NULL");
+        return;    
+    }
+    
+    if(connection->local_role == BT_SOCKET_SERVER) {
+        RegisteredUUIDMapT::iterator iter = object->mRegisteredUUID.find(connection->service_uuid);
+        if(iter == object->mRegisteredUUID.end()) {
+            LogWarning("Connection state is changed unexpectedly");
+            return;        
+        }
+
+        if(state == BT_SOCKET_CONNECTED) {  // connected when Server
+            if(result == BT_ERROR_NONE) {
+                // Update BluetoothServiceHandler
+                BluetoothServiceHandlerPtr service = iter->second;
+                service->setConnectionState(true);
+
+                // Call BluetoothServiceHandler.onconnect
+                BluetoothSocketPtr socket = new BluetoothSocket(connection);
+                MultiCallbackUserDataPtr callback = service->getOnConnect();
+                JSContextRef context = callback->getContext();
+                JSObjectRef socketObj = JSBluetoothSocket::createJSObject(context, socket);
+                if(callback)
+                    callback->invokeCallback("onconnect", socketObj);
+
+                // Update mConnectedSocket
+                object->mConnectedSocket.insert(std::pair<int, BluetoothSocketPtr>(connection->socket_fd, socket));
+                bt_socket_set_data_received_cb(onSocketReceivedCB, userData);
+            }
+            else {
+                LogWarning("Establishing a connection failed");
+            }
+            return;
+        }
+        else {  // disconnected when Server
+            if(result == BT_ERROR_NONE) {
+                // Update BluetoothServiceHandler
+                BluetoothServiceHandlerPtr service = iter->second;
+                service->setConnectionState(false);
+
+                // call BluetoothSocket.onclose;
+                ConnectedSocketMapT::iterator i = object->mConnectedSocket.find(connection->socket_fd);
+                if(i == object->mConnectedSocket.end()) {
+                    LogWarning("Unknown connected socket");
+                    return;
+                }
+                //BluetoothSocketSharedPtr socket = i->second;
+                BluetoothSocketPtr socket = i->second;
+                socket->setConnectionState(false);
+                MultiCallbackUserDataPtr callback = socket->getOnClose();
+                if(callback)
+                    callback->invokeCallback("onclose");
+                
+                // Update mConnectedSocket
+                object->mConnectedSocket.erase(i);
+            }
+            else {
+                LogWarning("Disconnecting a connection failed");
+            }        
+        }        
+    }
+    else if(connection->local_role == BT_SOCKET_CLIENT) {
+        std::string remoteAddress(connection->remote_address);
+        ConnReqMultiMapT::iterator iter;
+        do {
+            iter = object->mConnReqMap.find(remoteAddress);
+            if(iter != object->mConnReqMap.end() && !strcmp(iter->second->mUUID.c_str(), connection->service_uuid)) {
+                LogDebug("Find");
+                break;
+            }
+        } while(iter != object->mConnReqMap.end());
+        
+        if(iter == object->mConnReqMap.end()) {
+            LogWarning("Connection state is changed unexpectedly");
+            return;    
+        }
+
+        MultiCallbackUserDataPtr callback = static_cast<MultiCallbackUserDataPtr>(iter->second->mUserData);
+
+        if(state == BT_SOCKET_CONNECTED) {  // connected when Client
+            if(result == BT_ERROR_NONE) {
+                // Update mConnectedSocket
+                BluetoothSocketPtr socket = new BluetoothSocket(connection);
+                object->mConnectedSocket.insert(std::pair<int, BluetoothSocketPtr>(connection->socket_fd, socket));
+                bt_socket_set_data_received_cb(onSocketReceivedCB, userData);
+                
+                // Call successcallback of connectToServiceByUUID 
+                JSContextRef context = callback->getContext();
+                JSObjectRef socketObj = JSBluetoothSocket::createJSObject(context, socket);
+                if(callback)
+                    callback->invokeCallback("success", socketObj);
+
+                // Update mConnReqMap
+                object->mConnReqMap.erase(iter);         
+            }
+            else {
+                // Call errorcallback of connectToServiceByUUID 
+                JSContextRef context = callback->getContext();                
+                InvalidValuesException error("Invalid value");
+                if(callback)
+                    callback->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(context, error));
+
+                // Update mConnReqMap
+                object->mConnReqMap.erase(iter);                
+            }
+            return;
+        }
+        else {  // disconnected when Client
+            if(result == BT_ERROR_NONE) {
+                // call BluetoothSocket.onclose;
+                ConnectedSocketMapT::iterator i = object->mConnectedSocket.find(connection->socket_fd);
+                if(i == object->mConnectedSocket.end()) {
+                    LogWarning("Unknown connected socket");
+                    return;
+                }
+                
+                BluetoothSocketPtr socket = i->second;
+                socket->setConnectionState(false);
+                MultiCallbackUserDataPtr callback = socket->getOnClose();
+                if(callback)
+                    callback->invokeCallback("onclose");
+            
+                // Update mConnectedSocket
+                object->mConnectedSocket.erase(i);                
+            }
+            else {
+                LogWarning("Disconnecting a connection failed");
+            }
+        }        
+    }
+    else {
+        LogWarning("Unknown role");
+        return;    
+    }
+
+    if(object->mConnectedSocket.size() == 0) {
+        bt_socket_unset_data_received_cb();
+    }
+    
+    if(object->mRegisteredUUID.size() == 0 && object->mConnReqMap.size() == 0 && object->mConnectedSocket.size() == 0) {
+        LogDebug("mRegisteredUUID.size()=%d, mConnReqMap.size()=%d, mConnectedSocket.size()=%d", 
+                object->mRegisteredUUID.size(), object->mConnReqMap.size(), object->mConnectedSocket.size());
+        bt_socket_unset_connection_state_changed_cb();
+    }
+}
+
+void BluetoothAdapter::onSocketReceivedCB(bt_socket_received_data_s *data, void *userData)
+{
+    LogDebug("Entered");
+
+    BluetoothAdapterPtr object = static_cast<BluetoothAdapterPtr>(userData);
+    if(!object) {
+        LogWarning("userData is NULL");
+        return;
+    }
+
+    if(!data) {
+        LogWarning("data is NULL");
+        return;    
+    }
+
+    ConnectedSocketMapT::iterator i = object->mConnectedSocket.find(data->socket_fd);
+    if(i == object->mConnectedSocket.end()) {
+        LogWarning("Unknown connected socket");
+        return;
+    }
+
+    // Store received data
+    BluetoothSocketPtr socket = i->second;
+    socket->storeRecivedData(data->data, static_cast<unsigned long>(data->data_size));
+
+    // Call BluetoothSocket.onmessage
+    MultiCallbackUserDataPtr callback = socket->getOnMessage();
+    if(callback)
+        callback->invokeCallback("onmessage");
+}
+
+BluetoothAdapter::BluetoothAdapter(): 
+        mEnabled(false)
+{
+    LogDebug("Entered");
+    
+    bt_initialize();
+
+    bt_adapter_state_e state;
+    if (bt_adapter_get_state(&state) == BT_ERROR_NONE) {
+        if (state == BT_ADAPTER_ENABLED) {
+            mEnabled = true;
+        }
+    }    
+
+    bt_adapter_set_state_changed_cb(onStateChangedCB, this);
+}
+
+BluetoothAdapter::~BluetoothAdapter()
+{
+    LogDebug("Entered");
+
+    // unset platform callback
+    bt_adapter_unset_state_changed_cb();
+    bt_adapter_unset_name_changed_cb();
+    bt_adapter_unset_visibility_mode_changed_cb();
+    bt_adapter_unset_device_discovery_state_changed_cb();
+    bt_device_unset_bond_created_cb();
+    bt_device_unset_bond_destroyed_cb();
+    bt_socket_unset_connection_state_changed_cb();
+    bt_socket_unset_data_received_cb();
+    bt_deinitialize();
+
+    for(int i = 0; i <= DESTROY_BONDING; i++) {
+        mUserDataList[i].reset();
+    }
+    mRegisteredUUID.clear();
+    mConnReqMap.clear();
+    mFoundDevices.clear();
+    mConnectedSocket.clear();
+}
+
+void BluetoothAdapter::unregisterUUID(std::string &uuid)
+{
+    LogDebug("Entered");
+
+    mRegisteredUUID.erase(mRegisteredUUID.find(uuid));
+    if(mRegisteredUUID.size() == 0 && mConnReqMap.size() == 0 && mConnectedSocket.size() == 0) {
+        LogDebug("mRegisteredUUID.size()=%d, mConnReqMap.size()=%d, mConnectedSocket.size()=%d", 
+                mRegisteredUUID.size(), mConnReqMap.size(), mConnectedSocket.size());
+        bt_socket_unset_connection_state_changed_cb();
+    }
+}
+
+bool BluetoothAdapter::closeConnectedSocket(int socket)
+{
+    LogDebug("Entered");
+
+    if(mEnabled == true) {
+        ConnectedSocketMapT::iterator iter = mConnectedSocket.find(socket);
+        if(iter == mConnectedSocket.end()) {
+            LogWarning("Already disconnected");
+            return true;
+        }
+
+        mConnectedSocket.erase(iter);
+        if(mConnectedSocket.size() == 0) {
+            bt_socket_unset_data_received_cb();
+        }
+
+        if(mRegisteredUUID.size() == 0 && mConnReqMap.size() == 0 && mConnectedSocket.size() == 0) {
+            LogDebug("mRegisteredUUID.size()=%d, mConnReqMap.size()=%d, mConnectedSocket.size()=%d", 
+                    mRegisteredUUID.size(), mConnReqMap.size(), mConnectedSocket.size());
+            bt_socket_unset_connection_state_changed_cb();
+        }
+        
+        return true;    
+    }
+    else {
+        LogError("Bluetooth is not powered");
+        return false;
+    }
+}
+
+void BluetoothAdapter::removeConnReq(std::string &remoteAddress)
+{
+    LogDebug("Entered");
+
+    ConnReqMultiMapT::iterator iter;
+    do {
+        iter = mConnReqMap.find(remoteAddress);
+        if(iter != mConnReqMap.end()) {
+            LogDebug("Remove connection request");
+            mConnReqMap.erase(iter);
+        }        
+    } while(iter != mConnReqMap.end());
+
+    if(mRegisteredUUID.size() == 0 && mConnReqMap.size() == 0 && mConnectedSocket.size() == 0) {
+        LogDebug("mRegisteredUUID.size()=%d, mConnReqMap.size()=%d, mConnectedSocket.size()=%d", 
+                mRegisteredUUID.size(), mConnReqMap.size(), mConnectedSocket.size());
+        bt_socket_unset_connection_state_changed_cb();
+    }
+}
+
+BluetoothAdapter* BluetoothAdapter::getInstance()
+{
+    LogDebug("Entered");
+    
+    static BluetoothAdapter instance;
+    return &instance;
+}
+
+bool BluetoothAdapter::isBluetoothSupported()
+{
+    bool isSupported = false;
+    
+    if(system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, &isSupported) != SYSTEM_INFO_ERROR_NONE) {
+        LogError("Can't know whether Bluetooth is supported or not");
+    }
+    
+    return isSupported;
+}
+
+bool BluetoothAdapter::isValidAddress(std::string &address)
+{
+    LogDebug("Entered");
+
+    pcrecpp::RE re("(([0-9a-zA-Z]+):)+([0-9a-zA-Z]+)");
+    std::string compareAddress = "00:12:47:08:9A:A6";
+
+    if (!re.FullMatch(address)) {
+        LogError("Invalid address");
+        return false;
+    }
+
+    if (address.size() != compareAddress.size())
+    {
+        LogError("Invalid size");
+        return false;
+    }
+
+    return true;
+}
+
+bool BluetoothAdapter::isValidUUID(std::string &uuid)
+{
+    pcrecpp::RE re("(([0-9a-zA-Z]+)-)+([0-9a-zA-Z]+)");
+    std::string compareUUID = "00001101-0000-1000-8000-00805F9B34FB";
+
+    if (!re.FullMatch(uuid))
+    {
+        LogError("Invalid UUID");
+        return false;
+    }
+
+    if (uuid.size() != compareUUID.size())
+    {
+        LogError("Invalid size");
+        return false;
+    }
+
+    return true;
+}
+
+std::string BluetoothAdapter::getName() const
+{
+    LogDebug("Entered");
+    
+    char* name = NULL; 
+    std::string str = "";
+
+    if(bt_adapter_get_name(&name) == BT_ERROR_NONE) {
+        if (name != NULL)
+        {
+            str = name;
+            free(name);
+            LogDebug("name" << str);
+        }
+    }
+    else {
+        LogError("bt_adapter_get_name() failed");
+    }
+    
+    return str;
+}
+
+void BluetoothAdapter::setName(std::string &name, MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+    
+    if(mEnabled == true) {
+        std::string adapterName = getName();
+        if(adapterName == name) {   // in case of same name
+            LogDebug("same name");
+            BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+            return;
+        }
+
+        if(mUserDataList[SET_NAME] == NULL) {
+            bt_adapter_set_name_changed_cb(onNameChangedCB, this);
+            mUserDataList[SET_NAME] = static_cast<MultiCallbackUserDataPtr>(userData);
+        } else {
+            LogError("Already requested");
+            UnknownException *error = new UnknownException("Already requested");
+            BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            return;
+        }
+        
+        int ret = bt_adapter_set_name(name.c_str());
+        
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_adapter_set_name() succeeded");
+                mRequestedName = name;
+                return;            
+            }
+            case BT_ERROR_INVALID_PARAMETER:
+            {
+                LogError("Invalid value");
+                InvalidValuesException *error = new InvalidValuesException("Invalid value");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                break;
+            }
+            default:
+            {
+                LogError("Invalid value");
+                UnknownException *error = new UnknownException("Unknown exception");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }            
+        }
+        
+        bt_adapter_unset_name_changed_cb();
+        mUserDataList[SET_NAME].reset();         
+    } else {   // Not enabled
+        LogError("Bluetooth device is turned off");
+        ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }
+}
+
+std::string BluetoothAdapter::getAddress() const
+{
+    LogDebug("Entered");
+    
+    char* address = NULL; 
+    std::string str = "";
+
+    if (bt_adapter_get_address(&address) == BT_ERROR_NONE) {
+        if (address != NULL) {
+            str = address;
+            free(address);
+            LogDebug("address: " << str);
+        }
+        else {
+            LogWarning("address is NULL");
+        }
+    }
+    else {
+        LogError("bt_adapter_get_address() failed");
+    }
+    
+    return str;
+}
+
+bool BluetoothAdapter::getPowered() const
+{
+    LogDebug("Entered");
+
+    return mEnabled;    
+}
+
+void BluetoothAdapter::setPowered(bool powered, MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(powered == mEnabled) {    
+        LogDebug("same state");
+        BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+        return;
+    }
+
+    if(mUserDataList[SET_POWERED] == NULL) {
+        mUserDataList[SET_POWERED] = static_cast<MultiCallbackUserDataPtr>(userData);
+    } else {
+        // Already requested
+        LogError("Already requested");
+        ServiceNotAvailableException *error = new ServiceNotAvailableException("Already requested");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        return;
+    }
+
+    mRequestedState = powered;
+    if(powered == true) {
+        int ret = bt_adapter_enable();
+
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_adapter_enable() succeeded");
+                return;
+            }
+            case BT_ERROR_ALREADY_DONE:
+            {
+                // call successCallback
+                LogDebug("BT_ERROR_ALREADY_DONE");
+                BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+                break;
+            }
+            case BT_ERROR_NOW_IN_PROGRESS:
+            {
+                LogDebug("BT_ERROR_NOW_IN_PROGRESS");
+                ServiceNotAvailableException *error = new ServiceNotAvailableException("Bluetooth device is busy");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                break;
+            }
+            default:
+            {
+                LogDebug("Unknown error");
+                UnknownException *error = new UnknownException("Unknown error");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }
+        }
+    } else {
+        int ret = bt_adapter_disable();
+        
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_adapter_disable() succeeded");
+                return;
+            }
+            case BT_ERROR_NOT_ENABLED:
+            {
+                // call successCallback
+                LogDebug("Already disabled");
+                BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+                break;
+            }
+            case BT_ERROR_NOW_IN_PROGRESS:
+            {
+                LogDebug("BT_ERROR_NOW_IN_PROGRESS");
+                ServiceNotAvailableException *error = new ServiceNotAvailableException("Bluetooth device is busy");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                break;
+            }
+            default:
+            {
+                LogDebug("Unknown error");
+                UnknownException *error = new UnknownException("Unknown error");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }
+        }
+    }
+
+    mUserDataList[SET_POWERED].reset();  
+}
+
+bool BluetoothAdapter::getVisible() const
+{
+    LogDebug("Entered");
+
+    bt_adapter_visibility_mode_e mode;
+
+    if (bt_adapter_get_visibility(&mode, NULL) == BT_ERROR_NONE) {
+        if (mode != BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) {
+            return true;
+        }
+    }
+    
+    return false;
+}
+
+void BluetoothAdapter::setVisible(bool visible, unsigned int timeout, MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+   
+    if(mEnabled == true) {        
+        bt_adapter_visibility_mode_e discoverable_mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
+        if(visible == true) {
+            if(timeout == 0)
+                discoverable_mode = BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE;        
+            else
+                discoverable_mode = BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE;
+        }
+        
+        bt_adapter_visibility_mode_e current = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
+        int time = 0;
+        bt_adapter_get_visibility(&current , &time);
+        if(discoverable_mode == current) {
+            if(discoverable_mode != BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE) {
+                LogDebug("same visibility");
+                BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+                return;
+            }
+            else if((unsigned int)time == timeout) {
+                LogDebug("same visibility");
+                BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+                return;
+            }
+        }
+
+        if(mUserDataList[SET_VISIBLE] == NULL) {
+            bt_adapter_set_visibility_mode_changed_cb(onVisibilityChangedCB, this);
+            mUserDataList[SET_VISIBLE] = static_cast<MultiCallbackUserDataPtr>(userData);
+        } else {
+            UnknownException *error = new UnknownException("Already requested");
+            BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            return;
+        }        
+        
+        mRequestedVisibility = discoverable_mode;    
+        int ret = bt_adapter_set_visibility(discoverable_mode, timeout);        
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_adapter_set_visibility() succeeded");
+                return;            
+            }
+            case BT_ERROR_INVALID_PARAMETER:
+            {
+                InvalidValuesException *error = new InvalidValuesException("Invalid value");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                break;
+            }
+            default:
+            {
+                UnknownException *error = new UnknownException("Unknown error");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }
+        }
+        
+        bt_adapter_unset_visibility_mode_changed_cb();
+        mUserDataList[SET_VISIBLE].reset();         
+    } else {   // Not enabled
+        ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }
+
+}
+
+void BluetoothAdapter::discoverDevices(MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(mUserDataList[DISCOVER_DEVICES] == NULL) {
+        mUserDataList[DISCOVER_DEVICES] = static_cast<MultiCallbackUserDataPtr>(userData);
+        
+        if(mUserDataList[STOP_DISCOVERY] == NULL)
+            bt_adapter_set_device_discovery_state_changed_cb(onDiscoveryStateChangedCB, this);     
+    } else {
+        UnknownException *error = new UnknownException("Already requested");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        return;
+    }
+    
+    if(mEnabled == true) {          
+        int ret = bt_adapter_start_device_discovery();
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_adapter_start_device_discovery() succeeded");
+                return;            
+            }
+            default:
+            {
+                LogError("Unknown exception");
+                UnknownException *error = new UnknownException("Unknown error");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }            
+        }
+    } else {   // Not enabled
+        LogError("Bluetooth device is turned off");
+        ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }
+
+    mUserDataList[DISCOVER_DEVICES].reset(); 
+    if(mUserDataList[STOP_DISCOVERY] == NULL) {
+        bt_adapter_unset_device_discovery_state_changed_cb();
+    }    
+}
+
+void BluetoothAdapter::stopDiscovery(MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+    
+    if(mEnabled == true) {
+    
+        bool isDiscovering = false;
+        bt_adapter_is_discovering(&isDiscovering);
+        if(!isDiscovering) {
+            BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+            return;
+        }
+
+        if(mUserDataList[STOP_DISCOVERY] == NULL) {
+            mUserDataList[STOP_DISCOVERY] = static_cast<MultiCallbackUserDataPtr>(userData);
+            
+            if(mUserDataList[DISCOVER_DEVICES] == NULL)
+                bt_adapter_set_device_discovery_state_changed_cb(onDiscoveryStateChangedCB, this);     
+        } else {
+            LogDebug("Already requested");
+            UnknownException *error = new UnknownException("Already requested");
+            BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            return;
+        }
+    
+        int ret = bt_adapter_stop_device_discovery();
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_adapter_stop_device_discovery() succeeded");
+                return;            
+            }
+            default:
+            {
+                UnknownException *error = new UnknownException("Unknown error");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }            
+        }
+
+        mUserDataList[STOP_DISCOVERY].reset(); 
+        if(mUserDataList[DISCOVER_DEVICES] == NULL) {
+            bt_adapter_unset_device_discovery_state_changed_cb();
+        }        
+    } else {   // Not enabled
+        ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }
+}
+
+void BluetoothAdapter::getKnownDevices(MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+    BluetoothCallbackUtil::syncToAsyncDeviceArrayCallback(userData);
+}
+
+void BluetoothAdapter::getDevice(std::string &address, MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+    BluetoothCallbackUtil::syncToAsyncDeviceCallback(userData, address);
+}
+
+void BluetoothAdapter::createBonding(std::string &address, MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(!isValidAddress(address)) {
+        LogError("Wrong address");
+        NotFoundException *error = new NotFoundException("Wrong address");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        return;
+    }
+
+    if(mUserDataList[CREATE_BONDING] == NULL) {
+        bt_device_set_bond_created_cb(onBondCreatedCB, this);
+        mCreateBondingAddress = address;
+        mUserDataList[CREATE_BONDING] = static_cast<MultiCallbackUserDataPtr>(userData);
+    } else {
+        LogError("Already requested");
+        UnknownException *error = new UnknownException("Already requested");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        return;
+    }
+    
+    if(mEnabled == true) {
+        int ret = bt_device_create_bond(address.c_str());
+        
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_device_create_bond() succeeded");
+                return;            
+            }
+            case BT_ERROR_INVALID_PARAMETER:
+            {
+                LogError("Not found");
+                NotFoundException *error = new NotFoundException("Not found");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                break;
+            }
+            default:
+            {
+                LogError("Unknown exception");
+                UnknownException *error = new UnknownException("Unknown error");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }            
+        }        
+    } else {   // Not enabled
+        LogError("Bluetooth device is turned off");
+        ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }
+
+    bt_device_unset_bond_created_cb();
+    mCreateBondingAddress.clear();
+    mUserDataList[CREATE_BONDING].reset(); 
+}
+
+void BluetoothAdapter::destroyBonding(std::string &address, MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(!isValidAddress(address)) {
+        LogError("Wrong address");
+        NotFoundException *error = new NotFoundException("Wrong address");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        return;
+    }
+
+    if(mUserDataList[DESTROY_BONDING] == NULL) {
+        bt_device_set_bond_destroyed_cb(onBondDestroyedCB, this);
+        mDestroyBondingAddress = address;
+        mUserDataList[DESTROY_BONDING] = static_cast<MultiCallbackUserDataPtr>(userData);
+    } else {
+        LogDebug("Already requested");
+        UnknownException *error = new UnknownException("Already requested");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        return;
+    }
+    
+    if(mEnabled == true) {
+        bt_device_info_s *deviceInfo = NULL;
+        if(bt_adapter_get_bonded_device_info(address.c_str(), &deviceInfo) != BT_ERROR_NONE || deviceInfo == NULL) {
+            LogDebug("There is no bonding");
+            NotFoundException *error = new NotFoundException("Not found");
+            BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        }
+        else {
+            bt_adapter_free_device_info(deviceInfo);
+            int ret = bt_device_destroy_bond(address.c_str());
+            
+            switch(ret) {
+                case BT_ERROR_NONE:
+                {
+                    LogDebug("bt_device_destroy_bond() succeeded");
+                    return;            
+                }
+                case BT_ERROR_INVALID_PARAMETER:
+                {
+                    NotFoundException *error = new NotFoundException("Not found");
+                    BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                    break;
+                }
+                default:
+                {
+                    UnknownException *error = new UnknownException("Unknown error");
+                    BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                }            
+            }        
+        }
+    } else {   // Not enabled
+        ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }
+
+    bt_device_unset_bond_destroyed_cb();
+    mDestroyBondingAddress.clear();
+    mUserDataList[DESTROY_BONDING].reset(); 
+}
+
+void BluetoothAdapter::registerRFCOMMServiceByUUID(std::string &uuid, std::string &name, MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+    BluetoothCallbackUtil::syncToAsyncServiceCallback(userData, uuid, name);
+}
+
+void BluetoothAdapter::connectToServiceByUUID(std::string &remoteAddress, std::string &uuid, Common::MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(!isValidUUID(uuid)) {
+        LogError("Wrong UUID");
+        InvalidValuesException *error = new InvalidValuesException("Wrong UUID");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        return;
+    }
+    
+
+    if(mEnabled == true) {
+        int ret = bt_socket_connect_rfcomm(remoteAddress.c_str(), uuid.c_str());
+        
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_socket_connect_rfcomm() succeeded");
+                bt_socket_set_connection_state_changed_cb(onSocketConnected, this);
+                
+                BluetoothConnReqPtr connReq = new BluetoothConnReq(uuid, userData);
+                mConnReqMap.insert(std::pair<std::string, BluetoothConnReqPtr>(remoteAddress, connReq));
+                break;            
+            }
+            case BT_ERROR_INVALID_PARAMETER:
+            case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
+            {
+                InvalidValuesException *error = new InvalidValuesException("Invalid value");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+                break;
+            }
+            default:
+            {
+                UnknownException *error = new UnknownException("Unknown error");
+                BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+            }            
+        }        
+    } else {   // Not enabled
+        ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }
+}
+
+void BluetoothAdapter::returnKnownDevices(Common::MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(mEnabled == true) {            
+        if(bt_adapter_foreach_bonded_device(foreachBondedDevicesCB, this) == BT_ERROR_NONE) {
+            if(mFoundDevices.size() > 0) { // There are found devices
+                LogDebug("There are found devices");                        
+                int num = mFoundDevices.size();
+                JSObjectRef devices[num];
+                for(int i = 0; i < num; i++) {
+                    JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(userData->getContext(), mFoundDevices[i]);                        
+                    devices[i] = deviceObj;
+                }
+
+                LogDebug("invoke successCallback");
+                userData->invokeCallback("success", JSObjectMakeArray(userData->getContext(), num, devices, NULL));
+            }
+            else {  // There is no found device
+                LogDebug("There is no found device");
+                userData->invokeCallback("success", JSObjectMakeArray(userData->getContext(), 0, NULL, NULL) );
+            }
+        }
+        else {
+            LogError("Unknown exception");
+            userData->invokeCallback(
+                    "error", 
+                    JSWebAPIError::makeJSWebAPIError(userData->getContext(), UnknownException("Unknown exception"))
+            );
+        }
+    } else {   // Not enabled
+        LogError("Bluetooth device is turned off");
+        userData->invokeCallback(
+                "error",
+                JSWebAPIError::makeJSWebAPIError(userData->getContext(), ServiceNotAvailableException("Bluetooth device is turned off"))
+        );
+    }
+}
+
+void BluetoothAdapter::returnDevice(std::string &address, Common::MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(!isValidAddress(address)) {
+        LogError("Wrong address");
+        userData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(userData->getContext(), NotFoundException("Wrong address")));
+        return;
+    }
+
+    if(mEnabled == true) {      
+        bt_device_info_s *deviceInfo = NULL;
+        if(bt_adapter_get_bonded_device_info(address.c_str(), &deviceInfo) == BT_ERROR_NONE &&
+                deviceInfo != NULL) {
+            BluetoothDeviceSharedPtr device(new BluetoothDevice(deviceInfo));
+            bt_adapter_free_device_info(deviceInfo);
+
+            LogDebug("invoke successCallback");
+            userData->invokeCallback("success", JSBluetoothDevice::createJSObject(userData->getContext(), device));
+            return;
+        }
+
+        std::vector<BluetoothDeviceSharedPtr>::iterator iter;
+        for(iter = mFoundDevices.begin(); iter != mFoundDevices.end(); ++iter) {
+                BluetoothDeviceSharedPtr foundDevice = *iter;
+            if(!strcmp(foundDevice->getAddress().c_str(), address.c_str())) {
+                LogDebug("Found in mFoundDevices");                
+                userData->invokeCallback("success", JSBluetoothDevice::createJSObject(userData->getContext(), foundDevice));
+                break;
+            }
+        }
+        
+        if(iter == mFoundDevices.end()) {
+            LogError("Can't find this device");
+
+            userData->invokeCallback(
+                    "error",
+                    JSWebAPIError::makeJSWebAPIError(userData->getContext(), NotFoundException("There is no device with the given address"))
+            );            
+        }        
+
+    } else {   // Not enabled
+        LogError("Bluetooth device is turned off");
+        userData->invokeCallback(
+                "error",
+                JSWebAPIError::makeJSWebAPIError(userData->getContext(), ServiceNotAvailableException("Bluetooth device is turned off"))
+        );
+    }
+}
+
+void BluetoothAdapter::returnRegisteredService(std::string &uuid, std::string &name, Common::MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Entered");
+
+    if(!isValidUUID(uuid)) {
+        LogError("Wrong UUID");
+        userData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(userData->getContext(), InvalidValuesException("Wrong UUID")));        
+        return;
+    }
+
+    if(mEnabled == true) {
+    
+        bool isRegistered;
+        if(bt_adapter_is_service_used(uuid.c_str(), &isRegistered) == BT_ERROR_NONE && isRegistered == true) {
+            LogDebug("Already registered");
+            userData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(userData->getContext(), InvalidValuesException("Already registered")));
+            return;
+        }        
+
+        int socket = -1;
+        int ret = bt_socket_create_rfcomm(uuid.c_str(), &socket);
+        
+        switch(ret) {
+            case BT_ERROR_NONE:
+            {
+                LogDebug("bt_socket_create_rfcomm() succeeded");
+                int ret = bt_socket_listen_and_accept_rfcomm(socket, 0);
+                switch(ret) {
+                    case BT_ERROR_NONE:
+                    {
+                        LogDebug("bt_socket_listen() succeeded");                        
+                        bt_socket_set_connection_state_changed_cb(onSocketConnected, this);
+
+                        BluetoothServiceHandlerPtr serviceHandler = new BluetoothServiceHandler(uuid, name, socket);
+                        mRegisteredUUID.insert(std::pair<std::string, BluetoothServiceHandlerPtr>(uuid, serviceHandler));
+                        
+                        JSObjectRef serviceObj = JSBluetoothServiceHandler::createJSObject(userData->getContext(), serviceHandler);
+                        userData->invokeCallback("success", serviceObj);
+                        break;
+                    }
+                    case BT_ERROR_INVALID_PARAMETER:
+                    {
+                        LogDebug("Invalid value");
+                        userData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(userData->getContext(), InvalidValuesException("Invalid value")));
+                        break;
+                    }
+                    default:
+                    {
+                        LogDebug("Unknown exception");
+                        userData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(userData->getContext(), UnknownException("Unknown exception")));
+                    }                    
+                }
+                
+                break;            
+            }
+            case BT_ERROR_INVALID_PARAMETER:
+            {
+                LogDebug("Invalid value");
+                userData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(userData->getContext(), InvalidValuesException("Invalid value")));
+                break;
+            }
+            default:
+            {
+                LogDebug("Unknown exception");
+                userData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(userData->getContext(), UnknownException("Unknown exception")));
+            }            
+        }        
+    } else {   // Not enabled
+        LogError("Bluetooth device is turned off");
+        userData->invokeCallback(
+                "error",
+                JSWebAPIError::makeJSWebAPIError(userData->getContext(), ServiceNotAvailableException("Bluetooth device is turned off"))
+        );
+    }
+}
+
+
+} // Bluetooth
+} // DeviceAPI
diff --git a/src/Bluetooth/BluetoothAdapter.h b/src/Bluetooth/BluetoothAdapter.h
new file mode 100644 (file)
index 0000000..7ba7bc7
--- /dev/null
@@ -0,0 +1,133 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_BLUETOOTH_ADAPTER_H__
+#define __TIZEN_BLUETOOTH_ADAPTER_H__
+
+#include <string>
+#include <vector>
+#include <map>
+
+#include <bluetooth.h>
+
+#include <MultiCallbackUserData.h>
+#include <PlatformException.h>
+
+#include "BluetoothDevice.h"
+#include "BluetoothServiceHandler.h"
+#include "BluetoothSocket.h"
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+class BluetoothConnReq
+{
+public:
+    BluetoothConnReq(std::string uuid, Common::MultiCallbackUserDataPtr userData) 
+    {
+        mUUID = uuid;
+        mUserData = userData;
+    };
+    
+    std::string mUUID;
+    Common::MultiCallbackUserDataPtr mUserData;
+};
+typedef BluetoothConnReq* BluetoothConnReqPtr;
+
+class BluetoothAdapter
+{
+public:
+    enum adapterAsyncE
+    {
+        SET_POWERED = 0,
+        SET_NAME,
+        SET_VISIBLE,
+        DISCOVER_DEVICES,
+        STOP_DISCOVERY,
+        CREATE_BONDING,
+        DESTROY_BONDING,
+    };
+    
+    bool getPowered() const;    
+    void setPowered(bool powered, Common::MultiCallbackUserDataPtr userData);    
+    std::string getName() const;    
+    void setName(std::string &name, Common::MultiCallbackUserDataPtr userData);
+    std::string getAddress() const;
+    bool getVisible() const;    
+    void setVisible(bool visible, unsigned int timeout, Common::MultiCallbackUserDataPtr userData);
+    void discoverDevices(Common::MultiCallbackUserDataPtr userData);
+    void stopDiscovery(Common::MultiCallbackUserDataPtr userData);
+    void getKnownDevices(Common::MultiCallbackUserDataPtr userData);
+    void getDevice(std::string &address, Common::MultiCallbackUserDataPtr userData);
+    void createBonding(std::string &address, Common::MultiCallbackUserDataPtr userData);
+    void destroyBonding(std::string &address, Common::MultiCallbackUserDataPtr userData);
+    void registerRFCOMMServiceByUUID(std::string &uuid, std::string &name, Common::MultiCallbackUserDataPtr userData);
+    void connectToServiceByUUID(std::string &remoteAddress, std::string &uuid, Common::MultiCallbackUserDataPtr userData);
+
+    void returnKnownDevices(Common::MultiCallbackUserDataPtr userData);
+    void returnDevice(std::string &address, Common::MultiCallbackUserDataPtr userData);
+    void returnRegisteredService(std::string &uuid, std::string &name, Common::MultiCallbackUserDataPtr userData);
+    
+    void unregisterUUID(std::string &uuid);
+    bool closeConnectedSocket(int socket);
+    void removeConnReq(std::string &remoteAddress);
+    
+    static BluetoothAdapter* getInstance();
+    static bool isBluetoothSupported();
+    static bool isValidAddress(std::string &address);
+    static bool isValidUUID(std::string &uuid);
+    //void unloadFrame();
+    
+private:  
+    BluetoothAdapter();
+    virtual ~BluetoothAdapter();
+
+    static void onStateChangedCB(int result, bt_adapter_state_e adapterState, void *userData);
+    static void onNameChangedCB(char *name, void *userData);
+    static void onVisibilityChangedCB(int result, bt_adapter_visibility_mode_e visibilityMode, void *userData);
+    static void  onDiscoveryStateChangedCB(int result, bt_adapter_device_discovery_state_e discoveryState, 
+            bt_adapter_device_discovery_info_s *discoveryInfo, void *userData);
+    static bool foreachBondedDevicesCB(bt_device_info_s *deviceInfo, void *userData);
+    static void onBondCreatedCB(int result, bt_device_info_s *deviceInfo, void *userData);
+    static void onBondDestroyedCB(int result, char *remoteAddress, void *userData);
+    static void onSocketConnected(int result, bt_socket_connection_state_e state, bt_socket_connection_s *connection, void *userData);
+    static void onSocketReceivedCB(bt_socket_received_data_s *data, void *userData);
+
+    typedef std::multimap<std::string, BluetoothConnReqPtr> ConnReqMultiMapT;   // <remoteAddress, BluetoothConnReqPtr>
+    typedef std::map<std::string, BluetoothServiceHandlerPtr> RegisteredUUIDMapT;   // <UUID, BluetoothServiceHandlerPtr>
+    typedef std::map<int, BluetoothSocketPtr> ConnectedSocketMapT;   // <socketFD, BluetoothSocketPtr>
+
+    bool mEnabled;
+    ConnReqMultiMapT mConnReqMap;
+    RegisteredUUIDMapT mRegisteredUUID;
+    ConnectedSocketMapT mConnectedSocket;
+    bool mRequestedState;
+    std::string mRequestedName;
+    bt_adapter_visibility_mode_e mRequestedVisibility;    
+    std::string mCreateBondingAddress;
+    std::string mDestroyBondingAddress;
+    Common::MultiCallbackUserDataPtr mUserDataList[DESTROY_BONDING + 1];    
+    std::vector<std::string> mDisappearedDevices;
+    std::vector<BluetoothDeviceSharedPtr> mFoundDevices;
+};
+
+typedef BluetoothAdapter* BluetoothAdapterPtr;
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_BLUETOOTH_ADAPTER_H__
diff --git a/src/Bluetooth/BluetoothAdapterListener.cpp b/src/Bluetooth/BluetoothAdapterListener.cpp
deleted file mode 100644 (file)
index d263af6..0000000
+++ /dev/null
@@ -1,370 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <JavaScriptCore/JavaScript.h>
-#include <dpl/log/log.h>
-#include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Converter.h>
-#include <Commons/IEvent.h>
-#include <CommonsJavaScript/Utils.h>
-#include "BluetoothAdapterListener.h"
-#include "JSBluetoothDevice.h"
-#include "BluetoothFactory.h"
-#include <CommonsJavaScript/JSUtils.h>
-#include "BluetoothMultiCallback.h"
-#include "JSBluetoothSocket.h"
-#include "JSBluetoothServiceHandler.h"
-#include "JSBluetoothAdapter.h"
-#include "BluetoothConverter.h"
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-
-using namespace DeviceAPI::Common;
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-
-BluetoothAdapterListener::~BluetoothAdapterListener() 
-{
-       LogDebug("entered");
-}
-
-BluetoothAdapterListener::BluetoothAdapterListener() :
-       EventBTCreateDestroyBondingAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTGetKnownDevicesAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTGetDeviceAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTSetPoweredAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTSetVisibleAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTOnDiscoveryDevicesListener(ThreadEnum::NULL_THREAD),
-       EventBTRegisterRFCOMMAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTUnregisterRFCOMMServiceAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTStopDiscoveryAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTSetNameAnswerReceiver(ThreadEnum::NULL_THREAD),
-       EventBTServiceOnConnectListener(ThreadEnum::NULL_THREAD)        
-{
-       LogDebug("entered");
-}
-
-
-BluetoothAdapterListener& BluetoothAdapterListener::getInstance()
-{
-       static BluetoothAdapterListener instance;
-       return instance;
-
-}
-
-void BluetoothAdapterListener::MakeErrorJSCallBack(JSCallbackManagerPtr cbm, JSContextRef globalContext, unsigned short error)
-{
-       LogDebug("Enter");
-       JSValueRef err = 0;
-
-       switch (error)
-       {
-               case ExceptionCodes::SecurityException:
-                       err = JSTizenExceptionFactory::makeErrorObject(globalContext, 
-                               JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");                          
-                       break;
-               case ExceptionCodes::UnsupportedException:
-                       err = JSTizenExceptionFactory::makeErrorObject(globalContext,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "unsupport error");
-                       break;
-               case ExceptionCodes::NotFoundException:
-                       err = JSTizenExceptionFactory::makeErrorObject(globalContext,
-                               JSTizenException::NOT_FOUND_ERROR, "not found error");
-                       break;
-               case ExceptionCodes::AlreadyInUseException:
-                       err = JSTizenExceptionFactory::makeErrorObject(globalContext,
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "service not available");
-                       break;
-               case ExceptionCodes::EventCancelledException:
-                       LogDebug("Enter - Event was cancled, callback will be silently discarded");
-                       return;
-               case ExceptionCodes::UnknownException:
-               default:                                
-                       err = JSTizenExceptionFactory::makeErrorObject(globalContext,
-                               JSTizenException::UNKNOWN_ERROR, "unknown error");
-                       break;
-       }
-       cbm->callOnError(err);
-}
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTCreateDestroyBondingPtr& event)
-{
-       LogDebug("Enter - EventBTCreateDestroyBondingPtr");
-//     JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-
-       BluetoothCreateBondingPrivateDataPtr privData;
-       JSCallbackManagerPtr callbackManager;
-
-       if (event->isCreateBonding() == true)
-       {
-               privData = DPL::StaticPointerCast<BluetoothCreateBondingPrivateData> (event->getPrivateData());
-               callbackManager = privData->getCallbackManager();
-       }
-       else 
-       {
-               callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       }
-       
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               BluetoothDeviceData device = event->getDevice();
-               JSObjectRef deviceObject = JSBluetoothDevice::createJSObject(l_globalContext, device);
-               callbackManager->callOnSuccess(deviceObject);
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-}
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTGetKnownDevicesPtr& event)
-{
-       LogDebug("Enter - EventBTGetKnownDevicesPtr");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               std::vector<BluetoothDeviceData> devices = event->getDevices();
-               BluetoothConverter converter(l_globalContext);
-               JSObjectRef result = converter.toBluetoothDevices(devices);
-               callbackManager->callOnSuccess(result);
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-
-
-       }
-
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTSetPoweredPtr& event)
-{
-       LogDebug("Enter - EventBTSetPoweredPtr");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               callbackManager->callOnSuccess();
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-}
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTGetDevicePtr& event)
-{
-       LogDebug("Enter - EventBTGetDevicePtr");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               BluetoothDeviceData device = event->getDevice();
-               LogDebug("Enter" << device.name << " " << device.address << "major: " << device.btClass.major << "minor: " << device.btClass.minor);
-               JSObjectRef adapterObject = JSBluetoothDevice::createJSObject(callbackManager->getContext(), device);
-               callbackManager->callOnSuccess(adapterObject);
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-
-}
-
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTSetVisiblePtr& event)
-{
-       LogDebug("Enter - EventBTSetVisiblePtr");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               callbackManager->callOnSuccess();
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-}
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTUnregisterRFCOMMServicePtr& event)
-{
-       LogDebug("Enter - EventBTUnregisterRFCOMMServicePtr");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               callbackManager->callOnSuccess();
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-}
-
-
-void BluetoothAdapterListener::onAnswerReceived(const EventBTOnDiscoveryDevicesPtr& event)
-{
-       LogDebug("Enter");
-       
-       EventBTOnDiscoveryDevicesPrivateDataPtr multiCallbacks = 
-               DPL::DynamicPointerCast<EventBTOnDiscoveryDevicesPrivateData>(event->getPrivateData());
-       JSCallbackManagerPtr defaultCbm = multiCallbacks->getOnSuccess();
-       std::vector<BluetoothDeviceData> devices;
-
-/*     assert(multiCallbacks != NULL);
-       assert(defaultCbm != NULL);
-       assert(multiCallbacks->getOnFound() != NULL);
-       assert(multiCallbacks->getOnFinished() != NULL);*/
-       
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               switch(event->getDiscoveryState())
-               {
-               case EventBTOnDiscoveryDevices::STARTED:
-                       multiCallbacks->getOnSuccess()->callOnSuccess();
-                       break;
-               case EventBTOnDiscoveryDevices::DISCOVERYING:
-               {
-                       JSObjectRef adapterObject; 
-                       devices = event->getDevices();
-                       defaultCbm = multiCallbacks->getOnFound();
-                       adapterObject = JSBluetoothDevice::createJSObject(defaultCbm->getContext(), devices[0]);
-                       defaultCbm->callOnSuccess(adapterObject);
-               }
-                       break;
-                       
-               case EventBTOnDiscoveryDevices::FINISHED:
-               {
-                       devices = event->getDevices();
-                       defaultCbm = multiCallbacks->getOnFinished();                   
-                       
-                       BluetoothConverter converter(defaultCbm->getContext());
-                       JSObjectRef result = converter.toBluetoothDevices(devices);
-                       defaultCbm->callOnSuccess(result);
-               }
-                       break;
-               default:
-                       MakeErrorJSCallBack(defaultCbm, defaultCbm->getContext(), event->getExceptionCode());
-                       break;
-                       
-               }
-       }
-       else
-       {
-               MakeErrorJSCallBack(defaultCbm, defaultCbm->getContext(), event->getExceptionCode());
-       }
-}
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTRegisterRFCOMMPtr& event)
-{
-       
-       LogDebug("Enter - EventBTRegisterRFCOMMPtr");
-
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               JSObjectRef adapterObject; 
-               int socketFd = event->getSocketFd();
-               std::string uuid = event->getUuid();
-               std::string name = event->getName();
-               adapterObject = JSBluetoothServiceHandler::createJSObject(l_globalContext, name, uuid, socketFd);
-               callbackManager->callOnSuccess(adapterObject);
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-
-
-}      
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTStopDiscoveryPtr& event)
-{
-       LogDebug("Enter - EventBTStopDiscoveryPtr");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-       
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               callbackManager->callOnSuccess();
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-}
-
-void BluetoothAdapterListener::OnAnswerReceived(const EventBTSetNamePtr& event)
-{
-       LogDebug("Enter - EventBTSetNamePtr");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-       
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               callbackManager->callOnSuccess();
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-}
-
-void BluetoothAdapterListener::onAnswerReceived(const EventBTServiceOnConnectPtr& event)
-{
-       LogDebug("Enter - EventBTServiceOnConnectPtr");
-
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-       JSContextRef l_globalContext = callbackManager->getContext();
-
-       BluetoothSocketData socketData;
-       JSObjectRef adapterObject;
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               socketData = event->getSocketData();
-               adapterObject = JSBluetoothSocket::createJSObject(l_globalContext, socketData);
-               callbackManager->callOnSuccess(adapterObject);
-       }
-       else
-       {
-               MakeErrorJSCallBack(callbackManager, l_globalContext, event->getExceptionCode());
-       }
-
-}
-
-
-
-}
-}
diff --git a/src/Bluetooth/BluetoothAdapterListener.h b/src/Bluetooth/BluetoothAdapterListener.h
deleted file mode 100644 (file)
index bf7532c..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_TIZEN_BLUETOOTH_ADAPTER_LISTENER_H_
-#define TIZENAPIS_TIZEN_BLUETOOTH_ADAPTER_LISTENER_H_
-
-#include <map>
-#include <dpl/shared_ptr.h>
-#include <dpl/noncopyable.h>
-#include "IBluetoothAdapterManager.h"
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include "EventBTServiceOnConnect.h"
-#include "EventBTUnregisterRFCOMM.h"
-
-
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-       
-typedef EventAnswerReceiver<EventBTCreateDestroyBonding> EventBTCreateDestroyBondingAnswerReceiver;
-typedef EventAnswerReceiver<EventBTGetKnownDevices> EventBTGetKnownDevicesAnswerReceiver;
-typedef EventAnswerReceiver<EventBTGetDevice> EventBTGetDeviceAnswerReceiver;
-typedef EventAnswerReceiver<EventBTSetPowered> EventBTSetPoweredAnswerReceiver;
-typedef EventAnswerReceiver<EventBTSetVisible> EventBTSetVisibleAnswerReceiver;
-typedef EventListener<EventBTOnDiscoveryDevices> EventBTOnDiscoveryDevicesListener;
-typedef EventAnswerReceiver<EventBTRegisterRFCOMM> EventBTRegisterRFCOMMAnswerReceiver;
-typedef EventAnswerReceiver<EventBTUnregisterRFCOMMService> EventBTUnregisterRFCOMMServiceAnswerReceiver;
-typedef EventAnswerReceiver<EventBTStopDiscovery> EventBTStopDiscoveryAnswerReceiver;
-typedef EventAnswerReceiver<EventBTSetName> EventBTSetNameAnswerReceiver;
-typedef EventListener<EventBTServiceOnConnect> EventBTServiceOnConnectListener;
-
-
-       
-class BluetoothAdapterListener : 
-       public EventBTCreateDestroyBondingAnswerReceiver,
-       public EventBTGetKnownDevicesAnswerReceiver,    
-       public EventBTGetDeviceAnswerReceiver,
-       public EventBTSetPoweredAnswerReceiver,
-       public EventBTSetVisibleAnswerReceiver,
-       public EventBTOnDiscoveryDevicesListener,
-       public EventBTRegisterRFCOMMAnswerReceiver,
-       public EventBTUnregisterRFCOMMServiceAnswerReceiver,
-       public EventBTStopDiscoveryAnswerReceiver,
-       public EventBTSetNameAnswerReceiver,
-       public EventBTServiceOnConnectListener
-{
-
-private:
-       BluetoothAdapterListener();
-       void MakeErrorJSCallBack(JSCallbackManagerPtr cbm, JSContextRef globalContext, unsigned short error);
-public:
-       static BluetoothAdapterListener& getInstance();
-       virtual void onAnswerReceived(const EventBTOnDiscoveryDevicesPtr& event);
-       virtual void onAnswerReceived(const EventBTServiceOnConnectPtr& event);
-
-       virtual ~BluetoothAdapterListener();
-protected:
-
-       virtual void OnAnswerReceived(const EventBTCreateDestroyBondingPtr& event);
-       virtual void OnAnswerReceived(const EventBTGetKnownDevicesPtr& event);
-       virtual void OnAnswerReceived(const EventBTGetDevicePtr& event);
-       virtual void OnAnswerReceived(const EventBTSetPoweredPtr& event);
-       virtual void OnAnswerReceived(const EventBTSetVisiblePtr& event);
-       virtual void OnAnswerReceived(const EventBTUnregisterRFCOMMServicePtr& event);
-       virtual void OnAnswerReceived(const EventBTStopDiscoveryPtr& event);
-       virtual void OnAnswerReceived(const EventBTSetNamePtr& event);
-       virtual void OnAnswerReceived(const EventBTRegisterRFCOMMPtr& event);
-
-
-};
-
-typedef DPL::SharedPtr<BluetoothAdapterListener> BluetoothAdapterListenerPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/BluetoothAdapterManager.cpp b/src/Bluetooth/BluetoothAdapterManager.cpp
deleted file mode 100755 (executable)
index f5fa479..0000000
+++ /dev/null
@@ -1,1086 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <cassert>
-#include <Commons/Exception.h>
-#include "BluetoothAdapterManager.h"
-#include "BluetoothCBManager.h"
-#include "BluetoothProperty.h"
-
-
-
-
-using namespace WrtDeviceApis;
-using namespace DPL;
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-bool BluetoothAdapterManager::m_btPowered = false;
-bool BluetoothAdapterManager::m_btGetDeviceEvent = false;
-int BluetoothAdapterManager::m_currentServiceSocket = -1;
-std::vector<BluetoothDeviceData> BluetoothAdapterManager::m_Devices;
-
-
-namespace {
-
-// put only sync capi callback to this.
-// others shuld be moved to BluetoothCBManager.cpp
-
-static bool capi_callback_bt_adapter_bonded_device(bt_device_info_s *device_info, void *user_data)
-{
-       if( device_info != NULL )
-       {
-               LogDebug("address " << device_info->remote_address << " " << device_info->remote_name);
-               ((BluetoothAdapterManager*)user_data)->getKnownDevicesManualAnswer      (device_info);
-       }
-
-       return true;
-}
-
-static bool capi_callback_bt_adapter_bonded_device_find(bt_device_info_s *device_info, void *user_data)
-{
-       bool ret = true;
-       if( device_info != NULL )
-       {
-               LogDebug("address " << device_info->remote_address << " " << device_info->remote_name);
-               ret = ((BluetoothAdapterManager*)user_data)->getDeviceManualAnswer      (device_info);
-       }
-
-       return ret;;
-}
-
-static bool capi_callback_bt_adapter_check_connected_profile(bt_profile_e profile, void *user_data)
-{
-
-       if (profile == BT_PROFILE_RFCOMM)
-       {
-               LogDebug("Rfcomm connected");
-               
-               
-               if( user_data != NULL )
-               {
-                       *(bool*)user_data = true;
-               }
-               return false;
-       }
-
-       return true;
-}
-
-}
-
-BluetoothAdapterManager::BluetoothAdapterManager() 
-{
-       LogDebug("Enter");
-       Init();
-       m_btPowered = canUseBluetooth();
-}
-
-BluetoothAdapterManager::~BluetoothAdapterManager() 
-{
-       LogDebug("Enter");
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SETPOWERED);
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SETNAME);
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DISCOVERY);
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_CREATEBOND);
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DESTROYBOND);
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SERVICESEARCH);       
-}
-
-
-void BluetoothAdapterManager::Init()
-{
-       LogDebug("Enter");
-
-       if (bt_initialize() != BT_ERROR_NONE)
-       {
-               LogDebug("init error");
-       }
-}
-
-bool BluetoothAdapterManager::canUseBluetooth()
-{
-       bt_adapter_state_e state;
-       int ret;                
-
-       ret = bt_adapter_get_state(&state);
-
-       if (ret == BT_ERROR_NONE && state == BT_ADAPTER_ENABLED)
-       {
-               return true;
-       }
-       else
-       {
-               return false;
-       }
-}
-
-
-std::string BluetoothAdapterManager::getName()
-{
-       char* name = NULL; 
-       std::string str = "";
-
-       if (bt_adapter_get_name(&name) == BT_ERROR_NONE)
-       {
-               LogDebug("OK");
-
-               if (name != NULL)
-               {
-                       LogDebug("Set");
-                       str = name;
-                       free(name);
-               }
-       }
-       return str;
-}
-
-std::string BluetoothAdapterManager::getAddress()
-{
-       char* address = NULL; 
-       std::string str = "";
-
-       if (bt_adapter_get_address(&address) == BT_ERROR_NONE)
-       {
-               LogDebug("OK");
-               if (address != NULL)
-               {
-                       LogDebug("Set");
-                       str = address;
-                       free(address);
-               }
-       }
-       return str;
-
-}
-
-bool BluetoothAdapterManager::getPowered()
-{
-       bt_adapter_state_e state;
-
-       if (bt_adapter_get_state(&state) == BT_ERROR_NONE)
-       {
-               if (state == BT_ADAPTER_ENABLED)
-               {
-               return true;
-               }
-       }
-
-       return false;
-}
-
-bool BluetoothAdapterManager::getVisibility()
-{
-       bt_adapter_visibility_mode_e mode;
-
-       if (bt_adapter_get_visibility(&mode, NULL) == BT_ERROR_NONE)
-       {
-               if (mode != BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE)
-               {
-                       return true;
-               }
-       }       
-       return false;
-}
-       
-void BluetoothAdapterManager::setPowered(const  EventBTSetPoweredPtr& event) 
-{
-       LogDebug("Enter");
-       BluetoothCBManagerSingleton::Instance().addAdapterCallback(BluetoothCBManager::ADAPTER_SETPOWERED, (void*)this);
-       EventRequestReceiver<EventBTSetPowered>::PostRequest(event);
-}
-
-void BluetoothAdapterManager::setPoweredManualAnswer() 
-{
-       LogDebug("Enter");
-
-       m_btPowered = canUseBluetooth();
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SETPOWERED);
-
-       if(m_EventBTSetPoweredPtr != NULL)
-       {
-               if (m_EventBTSetPoweredPtr->isEnableRequested())
-               {
-                       if (m_btPowered == true)
-                       {
-                               m_EventBTSetPoweredPtr->setExceptionCode(Commons::ExceptionCodes::None);
-                       }
-                       else
-                       {
-                               m_EventBTSetPoweredPtr->setExceptionCode(Commons::ExceptionCodes::PlatformException);
-                       }
-               }
-               else
-               {
-                       if (m_btPowered == false)
-                       {
-                               m_EventBTSetPoweredPtr->setExceptionCode(Commons::ExceptionCodes::None);
-                               BluetoothCBManagerSingleton::Instance().clearAll();
-                       }
-                       else
-                       {
-                               m_EventBTSetPoweredPtr->setExceptionCode(Commons::ExceptionCodes::PlatformException);
-
-                       }
-               }
-               EventRequestReceiver<EventBTSetPowered>::ManualAnswer(m_EventBTSetPoweredPtr);
-       }
-       else
-               LogDebug("Ignore unexpected event");
-}
-
-void BluetoothAdapterManager::setVisible(const  EventBTSetVisiblePtr& event) 
-{
-       LogDebug("Enter");
-       EventRequestReceiver<EventBTSetVisible>::PostRequest(event);
-}
-
-
-void BluetoothAdapterManager::discoveryDevicesEmitter(const EventBTOnDiscoveryDevicesEmitterPtr& emitter)
-
-{
-       LogDebug("Enter");
-
-       int ret = 0;
-       bool status = false;
-       
-       try 
-       {
-               if (m_btPowered == false)       
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-
-               
-               if ((ret = bt_adapter_is_discovering(&status)) != BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::UnknownException, "platform exception error" << ret);
-               }
-
-               if (status) 
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "now discover devices progressing");
-               }
-
-               BluetoothCBManagerSingleton::Instance().addAdapterCallback(BluetoothCBManager::ADAPTER_DISCOVERY, (void*)this);
-
-               if ((ret = bt_adapter_start_device_discovery() != BT_ERROR_NONE))
-               {
-                       ThrowMsg(Commons::UnknownException, "device discovery fail" << ret);                    
-               }
-               m_discoverDevicesEmitter = emitter;
-               LogDebug("OK Discovery Start");         
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DISCOVERY);
-               EventBTOnDiscoveryDevicesPtr event(new EventBTOnDiscoveryDevices());
-               event->setExceptionCode(ex.getCode());
-               emitter->emit(event);
-       }
-}
-
-
-void BluetoothAdapterManager::discoveryDevicesCallbackEmit(int error, unsigned short state, 
-       bt_adapter_device_discovery_info_s *discovery_info)
-
-{
-       BluetoothDeviceData device;
-       EventBTOnDiscoveryDevicesPtr event(new EventBTOnDiscoveryDevices());
-       unsigned int index = 0;
-       
-       try 
-       {
-               if (discovery_info != NULL)
-               {
-                       device.address = discovery_info->remote_address;
-
-                       if (discovery_info->remote_name == NULL)
-                       {
-                               device.name = "";
-                       }
-                       else 
-                       {
-                               device.name = discovery_info->remote_name;
-                       }
-                       
-                       device.btClass.major = discovery_info->bt_class.major_device_class;
-                       device.btClass.minor = discovery_info->bt_class.minor_device_class;
-                       device.btClass.majorServiceMask = discovery_info->bt_class.major_service_class_mask;
-               }
-
-               switch(state)
-               {
-               case BT_ADAPTER_DEVICE_DISCOVERY_STARTED:
-                       event->setDiscoveryState(EventBTOnDiscoveryDevices::STARTED);
-                       break;
-               case BT_ADAPTER_DEVICE_DISCOVERY_FOUND:
-                       event->setDiscoveryState(EventBTOnDiscoveryDevices::DISCOVERYING);
-                       event->addDevice(device);
-                       m_Devices.push_back(device);
-                       break;
-               case BT_ADAPTER_DEVICE_DISCOVERY_FINISHED:
-                       event->setDiscoveryState(EventBTOnDiscoveryDevices::FINISHED);                  
-
-                       for (index = 0; index < m_Devices.size(); index++)
-                       {
-                               event->addDevice(m_Devices[index]);
-                       }
-                       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DISCOVERY);
-
-                       break;
-               default:
-                       ThrowMsg(Commons::UnknownException, "device discovery fail");                                           
-               }
-               event->setExceptionCode(Commons::ExceptionCodes::None);
-               m_discoverDevicesEmitter->emit(event);
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DISCOVERY);
-
-               m_discoverDevicesEmitter->emit(event);
-       }
-}
-
-void BluetoothAdapterManager::getKownDevices(const  EventBTGetKnownDevicesPtr& event) 
-{
-       LogDebug("Enter");
-       EventRequestReceiver<EventBTGetKnownDevices>::PostRequest(event);
-}
-
-void BluetoothAdapterManager::updateDevice(BluetoothDeviceData &device)
-{
-       unsigned int i = 0;
-       LogDebug("Enter");
-
-       for (i = 0; i < m_Devices.size(); i++)
-       {
-               if (device.address == m_Devices[i].address)
-               {
-                       m_Devices[i].name = device.name;
-                       m_Devices[i].isBonded = device.isBonded;
-                       m_Devices[i].isConnected = device.isConnected;
-                       m_Devices[i].isTrusted = device.isTrusted;
-                       m_Devices[i].btClass = device.btClass;
-                       m_Devices[i].uuids = device.uuids;
-               }
-       }
-
-       if (i == m_Devices.size())
-       {
-               m_Devices.push_back(device);
-       }
-}
-
-int BluetoothAdapterManager::findDevice(std::string address, BluetoothDeviceData& device)
-{
-       unsigned int i = 0;
-       
-       for (i = 0; i < m_Devices.size(); i++)
-       {
-               if (address == m_Devices[i].address)
-               {
-                       device = m_Devices[i];
-                       return BT_ERROR_NONE;
-               }
-       }
-       return BT_ERROR_OPERATION_FAILED;
-}
-
-void BluetoothAdapterManager::getKnownDevicesManualAnswer(bt_device_info_s *device_info)
-{
-       LogDebug("Enter");
-
-       BluetoothDeviceData device;
-       int index = 0;
-
-       if (device_info != NULL)
-       {
-
-               device.address = device_info->remote_address;
-
-               if (device_info->remote_name == NULL)
-               {
-                       device.name = "";
-               }
-               else 
-               {
-                       device.name = device_info->remote_name;
-               }
-
-               device.btClass.major = device_info->bt_class.major_device_class;
-               device.btClass.minor = device_info->bt_class.minor_device_class;
-               device.btClass.majorServiceMask = device_info->bt_class.major_service_class_mask;
-
-               bool connected = false;
-               bt_device_foreach_connected_profiles(device.address.c_str(), 
-                       capi_callback_bt_adapter_check_connected_profile, (void*)&connected);
-               
-
-               device.isBonded = device_info->is_bonded;
-               device.isConnected = connected;
-               device.isTrusted = device_info->is_authorized;
-
-               if (device_info->service_uuid != NULL)
-               {
-                       for (index = 0; index < device_info->service_count; index++)
-                       {
-                               if (device_info->service_uuid[index] != NULL)
-                               {
-                                       device.uuids.push_back(device_info->service_uuid[index]);
-                               }
-                       }
-               }
-               else
-               {
-                       LogDebug("uuid is null");
-               }
-               updateDevice(device);
-               m_EventBTGetKnownDevicesPtr->addDevice(device);
-       }
-
-}
-
-void BluetoothAdapterManager::getDevice(const  EventBTGetDevicePtr& event) 
-{
-       LogDebug("Enter");
-       BluetoothCBManagerSingleton::Instance().addAdapterCallback(BluetoothCBManager::ADAPTER_SERVICESEARCH, 
-               (void*)this, event->getAddress().data());
-       EventRequestReceiver<EventBTGetDevice>::PostRequest(event);
-}
-
-void BluetoothAdapterManager::serviceSearchManualAnswer(int error)
-{
-       try 
-       {
-               int ret = 0;
-               m_btGetDeviceEvent = true;
-
-               if (error != BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::NotFoundException, "service search failed");
-               }
-               
-               if ((bt_adapter_foreach_bonded_device(capi_callback_bt_adapter_bonded_device_find, (void*)this))!= BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::NotFoundException, "bt_adapter_foreach_bonded_device" << ret);
-               }
-               m_btGetDeviceEvent = false;
-
-               LogDebug("EventBTGetDevicePtr - serviceSearchManualAnswer");            
-               m_EventBTGetDevicePtr->setExceptionCode(Commons::ExceptionCodes::None);
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               m_EventBTGetDevicePtr->setExceptionCode(ex.getCode());
-       }
-       
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SERVICESEARCH,
-               m_EventBTGetDevicePtr->getAddress());
-       EventRequestReceiver<EventBTGetDevice>::ManualAnswer(m_EventBTGetDevicePtr);
-}
-
-bool BluetoothAdapterManager::getDeviceManualAnswer(bt_device_info_s *device_info)
-{
-       std::string address = "";
-
-       if (device_info == NULL)
-       {
-               return false;
-       }
-       
-       address = device_info->remote_address;
-
-       
-       BluetoothDeviceData device;
-       int index = 0;
-
-       device.address = device_info->remote_address;
-
-       if (device_info->remote_name == NULL)
-       {
-               device.name = "";
-       }
-       else 
-       {
-               device.name = device_info->remote_name;
-       }
-
-       device.btClass.major = device_info->bt_class.major_device_class;
-       device.btClass.minor = device_info->bt_class.minor_device_class;
-       device.btClass.majorServiceMask = device_info->bt_class.major_service_class_mask;
-
-
-       bool connected = false;
-       bt_device_foreach_connected_profiles(device.address.c_str(), 
-               capi_callback_bt_adapter_check_connected_profile, (void*)&connected);
-       
-
-       device.isBonded = device_info->is_bonded;
-       device.isConnected = connected;
-               //device_info->is_connected;
-       device.isTrusted = device_info->is_authorized;
-
-       LogDebug("Enter Found " << device.address << " " << device.name << " " << device.btClass.major << " " << device.btClass.minor);
-
-       if (device_info->service_uuid != NULL)
-       {
-
-               for (index = 0; index < device_info->service_count; index++)
-               {
-                       if (device_info->service_uuid[index] != NULL)
-                       {
-                               device.uuids.push_back(device_info->service_uuid[index]);
-                       }
-               }
-       }
-       else
-       {
-               LogDebug("service uuid null");
-       }
-
-       if (m_btGetDeviceEvent)
-       {
-               LogDebug("Enter - getDeviceManualAnswer" << address << ":" << m_EventBTGetDevicePtr->getAddress());
-               
-               if (address == m_EventBTGetDevicePtr->getAddress())
-               {
-                       updateDevice(device);
-                       m_EventBTGetDevicePtr->setDevice(device);
-                       return false;
-               }
-       }
-       else
-       {
-               updateDevice(device);
-       }
-       
-       return true;
-}
-
-
-
-void BluetoothAdapterManager::createBonding(const  EventBTCreateDestroyBondingPtr& event) 
-{
-       LogDebug("Post Event EventBTCreate");
-       BluetoothCBManagerSingleton::Instance().addAdapterCallback(BluetoothCBManager::ADAPTER_CREATEBOND, (void*)this);
-       EventRequestReceiver<EventBTCreateDestroyBonding>::PostRequest(event);
-}
-
-void BluetoothAdapterManager::createBondingManualAnswer(int error, bt_device_info_s *device_info)
-{
-       int index = 0;
-
-       if(m_EventBTCreateDestroyBondingPtr != NULL)
-       {
-               if (error == BT_ERROR_CANCELLED)
-               {
-                       LogDebug("createBondingManualAnswer cancel");
-                       m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::EventCancelledException);
-               }
-               else if (error == BT_ERROR_NONE)
-               {
-                       LogDebug("createBondingManualAnswer");
-
-                       BluetoothDeviceData device;
-                       device.address = device_info->remote_address;
-
-                       if (device_info->remote_name == NULL)
-                       {
-                               device.name = "";
-                       }
-                       else
-                       {
-                               device.name = device_info->remote_name;
-                       }
-
-                       bool connected = false;
-                       bt_device_foreach_connected_profiles(device.address.c_str(),
-                                       capi_callback_bt_adapter_check_connected_profile, (void*)&connected);
-
-                       device.isBonded = device_info->is_bonded;
-                       device.isConnected = connected;
-                       device.isTrusted = device_info->is_authorized;
-
-                       if (device_info->service_uuid != NULL)
-                       {
-                               for (index = 0; index < device_info->service_count; index++)
-                               {
-                                       if (device_info->service_uuid[index] != NULL)
-                                       {
-                                               device.uuids.push_back(device_info->service_uuid[index]);
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               LogDebug("service uuid null");
-                       }
-                       m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::None);
-                       m_EventBTCreateDestroyBondingPtr->setDevice(device);
-               }
-               else if (error == BT_ERROR_REMOTE_DEVICE_NOT_FOUND)
-               {
-                       m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
-               }
-               else
-               {
-                       m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::UnknownException);
-               }
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_CREATEBOND);
-               EventRequestReceiver<EventBTCreateDestroyBonding>::ManualAnswer(m_EventBTCreateDestroyBondingPtr);
-       }
-       else
-               LogDebug("Ignore unexpected event");
-}
-
-bool BluetoothAdapterManager::createBondingCancel()
-{
-       int ret = bt_device_cancel_bonding();
-
-       LogDebug("Cancel returned" << ret);
-
-       return (ret == BT_ERROR_NONE);
-}
-
-
-void BluetoothAdapterManager::destroyBonding(const  EventBTCreateDestroyBondingPtr& event) 
-{
-       LogDebug("Post Event DestroyBonding");
-       BluetoothCBManagerSingleton::Instance().addAdapterCallback(BluetoothCBManager::ADAPTER_DESTROYBOND, (void*)this);
-       EventRequestReceiver<EventBTCreateDestroyBonding>::PostRequest(event);
-}
-
-void BluetoothAdapterManager::destroyBondingManualAnswer(int error)
-{
-       if(m_EventBTCreateDestroyBondingPtr != NULL)
-       {
-               if (error == BT_ERROR_NONE)
-               {
-                       m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::None);
-               }
-               else if (error == BT_ERROR_REMOTE_DEVICE_NOT_FOUND)
-               {
-                       m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
-               }
-               else
-               {
-                       m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::UnknownException);
-               }
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DESTROYBOND);
-               EventRequestReceiver<EventBTCreateDestroyBonding>::ManualAnswer(m_EventBTCreateDestroyBondingPtr);
-       }
-       else
-               LogDebug("Ignore unexpected event");
-}
-
-
-void BluetoothAdapterManager::registerRFCOMMServiceByUUID(const EventBTRegisterRFCOMMPtr& event)
-{
-       LogDebug("EventBTRegisterRFCOMMPtr");
-       BluetoothCBManagerSingleton::Instance().checkUUIDAvailable(event->getUuid());
-
-       EventRequestReceiver<EventBTRegisterRFCOMM>::PostRequest(event);
-}
-
-
-void BluetoothAdapterManager::setAdapterName(const EventBTSetNamePtr& event)
-{
-       LogDebug("EventBTSetNamePtr");
-       BluetoothCBManagerSingleton::Instance().addAdapterCallback(BluetoothCBManager::ADAPTER_SETNAME, (void*)this);
-       EventRequestReceiver<EventBTSetName>::PostRequest(event);
-       
-}
-
-void BluetoothAdapterManager::setAdapterNameManualAnswer(char* deviceName) 
-{
-       LogDebug("Enter");
-
-       if(m_EventBTSetNamePtr != NULL)
-       {
-               if (deviceName != NULL)
-               {
-                       if (strcmp(deviceName,  m_EventBTSetNamePtr->getName().c_str()) != 0)
-                       {
-                               m_EventBTSetNamePtr->setExceptionCode(Commons::ExceptionCodes::UnknownException);
-                       }
-                       else
-                       {
-                               m_EventBTSetNamePtr->setExceptionCode(Commons::ExceptionCodes::None);
-                       }
-               }
-               else
-               {
-                       m_EventBTSetNamePtr->setExceptionCode(Commons::ExceptionCodes::UnknownException);
-               }
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SETNAME);
-               EventRequestReceiver<EventBTSetName>::ManualAnswer(m_EventBTSetNamePtr);
-       }
-       else
-               LogDebug("Ignore unexpected event");
-}
-
-
-
-void BluetoothAdapterManager::stopDiscovery(const EventBTStopDiscoveryPtr& event)
-{
-       LogDebug("EventBTStopDiscoveryPtr");
-       EventRequestReceiver<EventBTStopDiscovery>::PostRequest(event);
-
-}
-
-void BluetoothAdapterManager::OnRequestReceived(const  EventBTSetPoweredPtr& event) 
-{
-       int ret = 0;            
-
-       try 
-       {
-               event->switchToManualAnswer();
-               m_EventBTSetPoweredPtr = event; 
-               
-               if (event->isEnableRequested())
-               {
-                       ret = bt_adapter_enable();
-
-                       switch(ret) 
-                       {
-                       case BT_ERROR_NONE:
-                               return;
-                       case BT_ERROR_ALREADY_DONE:
-                               event->setExceptionCode(Commons::ExceptionCodes::None);
-                               m_btPowered = canUseBluetooth();
-                               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SETPOWERED);
-                               EventRequestReceiver<EventBTSetPowered>::ManualAnswer(event);
-                               break;
-                       case BT_ERROR_NOT_INITIALIZED:
-                               ThrowMsg(Commons::UnknownException, "bt is not initialized");
-                               break;
-                       case BT_ERROR_RESOURCE_BUSY:
-                               default:
-                               ThrowMsg(Commons::AlreadyInUseException, "bt is busy");
-                               break;
-                       }
-               }
-               else
-               {
-                       LogDebug("Disable");
-                       ret = bt_adapter_disable();
-
-                       if (ret == BT_ERROR_NONE)
-                       {
-                               return;
-                       }
-                       ThrowMsg(Commons::UnknownException, "can not disable bt");
-               }
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SETPOWERED);
-               EventRequestReceiver<EventBTSetPowered>::ManualAnswer(event);
-       }
-}
-
-void BluetoothAdapterManager::OnRequestReceived(const  EventBTSetVisiblePtr& event) 
-{
-       LogDebug("Enter");
-       int ret = 0;
-       bt_adapter_visibility_mode_e visibility_mode = BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE;
-
-       try 
-       {
-               if (m_btPowered == false)
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-               
-               if (event->isVisibleRequested())
-               {
-                       if (event->getTimeout() == 0) 
-                       {
-                               visibility_mode = BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE;
-                       }
-                       else
-                       {
-                               visibility_mode = BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE;
-                       }
-               }
-               else
-               {
-                       visibility_mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
-
-               }
-
-               LogDebug("bt_adapter_set_visibility " << visibility_mode << "  " << event->getTimeout());
-
-               if ((ret = bt_adapter_set_visibility(visibility_mode, event->getTimeout()) != BT_ERROR_NONE))
-               {
-                       ThrowMsg(Commons::UnknownException, "set visibility error" << ret);
-               }
-               event->setExceptionCode(Commons::ExceptionCodes::None);
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-
-       }
-}
-
-       
-void BluetoothAdapterManager::OnRequestReceived(const  EventBTGetKnownDevicesPtr& event) 
-{
-       LogDebug("EventBTGetKnownDevicesPtr Enter");
-
-       try 
-       {
-               m_EventBTGetKnownDevicesPtr = event;
-
-               if (m_btPowered == false)       
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-
-               if (bt_adapter_foreach_bonded_device(capi_callback_bt_adapter_bonded_device, (void*)this)!= BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::UnknownException, "bt_adapter_foreach_bonded_device");
-               }
-
-               LogDebug("Get Konwn device OK");                
-
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-
-       }
-}
-
-void BluetoothAdapterManager::OnRequestReceived(const  EventBTGetDevicePtr& event) 
-{
-       LogDebug("EventBTGetDevicePtr Enter");
-
-       try 
-       {
-               m_EventBTGetDevicePtr = event;
-               event->switchToManualAnswer();          
-               
-               if (m_btPowered == false)       
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-               if (bt_device_start_service_search(event->getAddress().data()) != BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::UnknownException, "service search failed" );
-               }
-
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               EventRequestReceiver<EventBTGetDevice>::ManualAnswer(event);
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SERVICESEARCH);
-
-       }
-}
-
-void BluetoothAdapterManager::OnRequestReceived(const  EventBTCreateDestroyBondingPtr& event) 
-{
-       LogDebug("Enter");
-
-       int ret = 0;
-       std::string addressFromEvent = event->getAddress();
-       const char *device_addr = addressFromEvent.c_str();
-
-       try 
-       {
-               m_EventBTCreateDestroyBondingPtr = event;
-               event->switchToManualAnswer();
-
-
-               if (m_btPowered == false)       
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-
-               if ((event->getAddress()).length() == 0)
-               {
-                       ThrowMsg(Commons::PlatformException, "address error" << ret);
-               }
-
-               if (event->isCreateBonding())
-               {
-                       if ((ret = bt_device_create_bond(device_addr) != BT_ERROR_NONE ))
-                       {
-                               ThrowMsg(Commons::PlatformException, "bt_device_create_bond error" << ret);
-                       }
-               }
-               else
-               {
-                       if ((ret = bt_device_destroy_bond (device_addr) != BT_ERROR_NONE ))
-                       {
-                               ThrowMsg(Commons::PlatformException, "bt_device_create_bond error" << ret);
-                       }
-
-               }
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-
-
-               if (event->isCreateBonding())
-               {
-                       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_CREATEBOND);
-               }
-               else
-               {
-                       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DESTROYBOND); 
-               }
-
-               EventRequestReceiver<EventBTCreateDestroyBonding>::ManualAnswer(event);
-       }
-}
-
-void BluetoothAdapterManager::OnRequestReceived(const EventBTSetNamePtr& event) 
-{
-       LogDebug("Enter");
-       try 
-       {
-               m_EventBTSetNamePtr = event;            
-               event->switchToManualAnswer();
-               std::string adapterName = event->getName();
-
-
-               if (m_btPowered == false)       
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-               
-               if (adapterName.length() == 0)
-               {
-                       ThrowMsg(Commons::PlatformException, "set name parameter error");
-               }
-
-               if (bt_adapter_set_name(adapterName.c_str()) != BT_ERROR_NONE )
-               {
-                       ThrowMsg(Commons::PlatformException, "set name error");                 
-               }
-               
-
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               EventRequestReceiver<EventBTSetName>::ManualAnswer(event);
-               bt_adapter_unset_name_changed_cb();
-               BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_SETNAME);
-       }
-}
-
-
-void BluetoothAdapterManager::OnRequestReceived(const EventBTStopDiscoveryPtr& event)
-{
-       LogDebug("Enter");
-       bool state = false;
-       try 
-       {
-               if (m_btPowered == false)       
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-
-               if (bt_adapter_is_discovering(&state) !=  BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::PlatformException, "device discovery stop fail");
-               }
-
-               if (state == false)
-               {
-                       ThrowMsg(Commons::PlatformException, "device discovery stop fail");
-               }
-
-               if (bt_adapter_stop_device_discovery() != BT_ERROR_NONE)                
-               {
-                       ThrowMsg(Commons::PlatformException, "device discovery stop fail");
-               }
-               event->setExceptionCode(Commons::ExceptionCodes::None);
-       }
-       catch (const Commons::Exception &ex)
-       {
-               LogError("Exception: " << ex.GetMessage());
-        event->setExceptionCode(ex.getCode());
-       }
-       BluetoothCBManagerSingleton::Instance().removeAdapterCallback(BluetoothCBManager::ADAPTER_DISCOVERY);
-}
-
-
-void BluetoothAdapterManager::OnRequestReceived(const EventBTRegisterRFCOMMPtr& event)
-{
-
-       try 
-       {
-               int ret = 0;
-               std::string uuid = event->getUuid();
-               int serviceSocket = -1;
-               
-               if (m_btPowered == false)       
-               {
-                       ThrowMsg(Commons::AlreadyInUseException, "bluetooth adpater off");
-               }
-
-               BluetoothCBManagerSingleton::Instance().checkUUIDAvailable(uuid);
-
-               if((ret = bt_socket_create_rfcomm(uuid.data(), &serviceSocket)) != BT_ERROR_NONE )
-               {
-                       ThrowMsg(Commons::UnknownException, "service socket creation error" << ret);
-               }
-
-               if( bt_socket_listen_and_accept_rfcomm(serviceSocket, 1) != BT_ERROR_NONE )
-               {
-                       ThrowMsg(Commons::UnknownException, "service socket register error");
-               }
-               event->setSocketFd(serviceSocket);
-               event->setExceptionCode(Commons::ExceptionCodes::None);
-               BluetoothCBManagerSingleton::Instance().registerSocket(uuid, serviceSocket);
-
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-
-               event->setExceptionCode(ex.getCode());
-       }
-}
-
-}
-}
-
-
diff --git a/src/Bluetooth/BluetoothAdapterManager.h b/src/Bluetooth/BluetoothAdapterManager.h
deleted file mode 100644 (file)
index f20adf6..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_PLATFORM_BLUETOOTH_ADAPTER_MANAGER_H_
-#define TIZENAPIS_PLATFORM_BLUETOOTH_ADAPTER_MANAGER_H_
-
-#include <map>
-#include <dpl/shared_ptr.h>
-#include <dpl/noncopyable.h>
-#include "IBluetoothAdapterManager.h"
-#include "BluetoothFactory.h"
-#include <glib.h>
-#include <bluetooth.h>
-#include "BluetoothProperty.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class BluetoothAdapterManager : public IBluetoothAdapterManager
-{
-       friend class BluetoothFactory;
-
-public:
-       virtual ~BluetoothAdapterManager();
-       virtual void setPowered(const EventBTSetPoweredPtr& event) ;
-       virtual void setVisible(const EventBTSetVisiblePtr& event) ;
-       virtual void getKownDevices(const EventBTGetKnownDevicesPtr& event) ;
-       virtual void getDevice(const EventBTGetDevicePtr& event) ;
-       virtual void createBonding(const EventBTCreateDestroyBondingPtr& event) ;
-       virtual bool createBondingCancel();
-       virtual void destroyBonding(const EventBTCreateDestroyBondingPtr& event) ;
-       virtual void registerRFCOMMServiceByUUID(const EventBTRegisterRFCOMMPtr& event);
-       virtual void discoveryDevicesEmitter(const EventBTOnDiscoveryDevicesEmitterPtr& emitter);
-       virtual void stopDiscovery(const EventBTStopDiscoveryPtr& event);
-               
-       virtual void setAdapterName(const EventBTSetNamePtr& event);
-
-       virtual std::string getName();
-       virtual std::string getAddress();
-       virtual bool getPowered();
-       virtual bool getVisibility();
-
-       void Init();
-       void Test();
-       bool canUseBluetooth();
-       void setPoweredManualAnswer();
-       void createBondingManualAnswer(int error, bt_device_info_s *device_info);
-       void destroyBondingManualAnswer(int error);
-       void getKnownDevicesManualAnswer(bt_device_info_s *discovery_info);
-       void serviceSearchManualAnswer(int error);
-       bool getDeviceManualAnswer(bt_device_info_s *device_info);
-       void discoveryDevicesCallbackEmit(int error, unsigned short state, bt_adapter_device_discovery_info_s *discovery_info);
-       void updateDevice(BluetoothDeviceData &device);
-       int findDevice(std::string address, BluetoothDeviceData &device);
-       void setAdapterNameManualAnswer(char* deviceName);
-protected:
-       BluetoothAdapterManager();
-
-       virtual void OnRequestReceived(const EventBTCreateDestroyBondingPtr& event);
-       virtual void OnRequestReceived(const EventBTGetKnownDevicesPtr& event);
-       virtual void OnRequestReceived(const EventBTGetDevicePtr& event);
-       virtual void OnRequestReceived(const EventBTSetPoweredPtr& event);
-       virtual void OnRequestReceived(const EventBTSetVisiblePtr& event);
-       virtual void OnRequestReceived(const EventBTSetNamePtr& event);
-       virtual void OnRequestReceived(const EventBTStopDiscoveryPtr& event);   
-       virtual void OnRequestReceived(const EventBTRegisterRFCOMMPtr& event);  
-
-private:
-       static bool m_btPowered;
-       static bool m_btGetDeviceEvent;
-       static int m_currentServiceSocket;
-       static std::vector<BluetoothDeviceData> m_Devices;
-
-       std::string m_uuid;
-       std::string m_name;
-       std::map<std::string, BluetoothSocketData> m_socketMap;
-       EventBTSetPoweredPtr m_EventBTSetPoweredPtr;
-       EventBTGetKnownDevicesPtr m_EventBTGetKnownDevicesPtr;
-       EventBTGetDevicePtr m_EventBTGetDevicePtr;
-       EventBTCreateDestroyBondingPtr m_EventBTCreateDestroyBondingPtr;
-       EventBTRegisterRFCOMMPtr m_EventBTRegisterRFCOMMPtr;
-       EventBTOnDiscoveryDevicesEmitterPtr m_discoverDevicesEmitter;
-       EventBTSetNamePtr m_EventBTSetNamePtr;
-
-};
-
-}
-}
-
-
-#endif 
diff --git a/src/Bluetooth/BluetoothCBManager.cpp b/src/Bluetooth/BluetoothCBManager.cpp
deleted file mode 100644 (file)
index 42ba5cb..0000000
+++ /dev/null
@@ -1,587 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <bluetooth.h>
-#include "BluetoothCBManager.h"
-#include "BluetoothAdapterManager.h"
-#include "BluetoothDeviceManager.h"
-#include "BluetoothSocketManager.h"
-#include "BluetoothServiceHandlerManager.h"
-#include <dpl/singleton_impl.h>
-#include <dpl/scoped_array.h>
-
-#include <cassert>
-#include <Commons/Exception.h>
-
-using namespace DPL;
-IMPLEMENT_SINGLETON(DeviceAPI::Bluetooth::BluetoothCBManager);
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-namespace {
-
-static void capi_callback_bt_state_changed(int result, bt_adapter_state_e adapter_state, void* user_data)
-{
-       if( result == BT_ERROR_NONE && user_data != NULL)
-       {
-               LogDebug("State Changed" << adapter_state);
-               ((BluetoothAdapterManager*)user_data)->setPoweredManualAnswer();
-
-       }
-       else
-       {
-               LogDebug("Error from platform");
-       }
-}
-
-static void capi_callback_bt_name_changed(char *device_name, void *user_data)
-{
-       ((BluetoothAdapterManager*)user_data)->setAdapterNameManualAnswer(device_name);
-}
-
-static void capi_callback_bt_discovery_state_changed(int result, 
-       bt_adapter_device_discovery_state_e discovery_state, bt_adapter_device_discovery_info_s *discovery_info, void *user_data)
-{
-       LogDebug("Discovery state" << discovery_state);
-       
-       if (discovery_state ==  BT_ADAPTER_DEVICE_DISCOVERY_FOUND && discovery_info != NULL)
-       {
-               LogDebug("found device" << discovery_info->remote_name << " " << discovery_info->remote_address);
-       }
-       
-       LogDebug("Discovery state" << discovery_state);
-
-       if (user_data != NULL)
-       {
-               ((BluetoothAdapterManager*)user_data)->discoveryDevicesCallbackEmit(result, discovery_state, discovery_info);
-       }
-       else
-       {
-               LogDebug("Error from platform");
-       }
-
-}
-
-static void capi_callback_bt_device_bond_created(int result, bt_device_info_s *device_info, void *user_data)
-{
-       if (user_data != NULL)
-       {
-               ((BluetoothAdapterManager*)user_data)->createBondingManualAnswer(result, device_info);
-       }
-       else
-       {
-               LogDebug("Error from platform");
-       }
-
-}
-
-static void capi_callback_bt_device_bond_destroyed(int result, char* remote_address, void *user_data)
-{
-       if (user_data != NULL)
-       {
-               ((BluetoothAdapterManager*)user_data)->destroyBondingManualAnswer(result);
-       }
-       else
-       {
-               LogDebug("Error from platform");
-       }
-}
-
-static void capi_bt_device_service_searched(int result, bt_device_sdp_info_s* sdp_info, void* user_data)
-{
-       if (user_data != NULL && sdp_info != NULL && sdp_info->remote_address != NULL)
-       {
-               ((BluetoothCBManager*)user_data)->serviceSearchRouter(result, sdp_info, user_data);
-       }
-       else
-       {
-               LogDebug("Error from platform");
-       }
-
-}
-
-static void capi_callback_bt_socket_connection_state_changed(int result, bt_socket_connection_state_e connection_state, 
-       bt_socket_connection_s *connection, void *user_data)
-{
-       if (user_data != NULL && connection != NULL && connection->remote_address != NULL)
-       {
-               ((BluetoothCBManager*)user_data)->connectionStateRouter(result, connection_state, connection);
-       }
-       else
-       {
-               LogDebug("Error from platform");
-       }
-
-}
-
-static void capi_callback_bt_data_received(bt_socket_received_data_s *data, void *user_data)
-{
-       if (user_data != NULL && data != NULL) 
-       {
-               ((BluetoothCBManager*)(user_data))->socketDataReceivedRouter(data);
-       }
-       else 
-       {
-               LogDebug("Error from platform");
-       }
-}
-
-
-
-}
-
-
-
-
-BluetoothCBManager::BluetoothCBManager()
-{
-       LogDebug("BluetoothCBManager singleton");
-
-}
-
-BluetoothCBManager::~BluetoothCBManager()
-{
-       LogDebug("BluetoothCBManager singleton removed");
-       disconnectAllSockets();
-
-
-}
-
-
-void BluetoothCBManager::addAdapterCallback(adapterCallback cb, void *passData, std::string address)
-{
-       std::vector<adapterCallback>::iterator it;
-
-       for (it = m_adapterCallback.begin(); it < m_adapterCallback.end(); ++it) 
-       {
-               if (*it == cb)
-                       break;
-       }
-       
-       if (cb == ADAPTER_DESTROYBOND)
-       {
-               LogDebug("ADAPTER_DESTROYBOND");
-       }
-
-       if (it == m_adapterCallback.end()) 
-       {
-
-               switch (cb) 
-               {
-               case ADAPTER_SETPOWERED:
-                       if( bt_adapter_set_state_changed_cb(capi_callback_bt_state_changed, passData) != BT_ERROR_NONE )
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "call back set error");
-                       }
-                       break;
-               case ADAPTER_SETNAME:
-                       if (bt_adapter_set_name_changed_cb(capi_callback_bt_name_changed, passData) != BT_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "callback set error");
-                       }
-                       break;
-               case ADAPTER_DISCOVERY:
-                       if (bt_adapter_set_device_discovery_state_changed_cb(capi_callback_bt_discovery_state_changed, 
-                               passData)!= BT_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,  "callback set error");             
-                       }
-                       break;
-               case ADAPTER_SERVICESEARCH:
-                       addServiceSearchCallback(address, passData, FROM_ADAPTER);
-                       break;
-               case ADAPTER_CREATEBOND:
-                       if (bt_device_set_bond_created_cb(capi_callback_bt_device_bond_created, passData) != BT_ERROR_NONE )
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "callback set error");
-                       }
-                       break;
-               case ADAPTER_DESTROYBOND:
-                       if (bt_device_set_bond_destroyed_cb (capi_callback_bt_device_bond_destroyed, passData) != BT_ERROR_NONE )
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "callback set error");
-                       }
-                       break;
-               case ADAPTER_REGISTER:
-                       LogDebug("do nothing to set callback");
-                       break;                  
-               }
-               
-               m_adapterCallback.push_back(cb);
-               LogDebug("operation call back is set successfully");
-       }
-       else 
-       {
-               LogDebug("same operation now, throws error");
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "same operation now");
-       }
-
-       
-}
-
-void BluetoothCBManager::removeAdapterCallback(adapterCallback cb, std::string address)
-{
-       std::vector<adapterCallback>::iterator it;
-
-       for (it = m_adapterCallback.begin(); it != m_adapterCallback.end(); ++it) 
-       {
-               if (*it == cb) 
-               {
-                       break;
-               }
-       }       
-
-       if (it == m_adapterCallback.end())
-       {
-               LogDebug("there is no such callback");
-       }
-       else 
-       {
-               m_adapterCallback.erase(it);
-               LogDebug("operation call back is unset successfully");
-
-               switch (cb) 
-               {
-               case ADAPTER_SETPOWERED:
-                       bt_adapter_unset_state_changed_cb();
-                       break;
-               case ADAPTER_SETNAME:
-                       bt_adapter_unset_name_changed_cb();
-                       break;
-               case ADAPTER_DISCOVERY:
-                       bt_adapter_unset_device_discovery_state_changed_cb();
-                       break;
-               case ADAPTER_SERVICESEARCH:
-                       removeServiceSearchCallback(address);
-                       break;
-               case ADAPTER_CREATEBOND:
-                       bt_device_unset_bond_created_cb();
-                       break;
-               case ADAPTER_DESTROYBOND:                       
-                       bt_device_unset_bond_destroyed_cb();
-                       break;
-               case ADAPTER_REGISTER:
-                       LogDebug("do nothing to set callback");
-                       break;                  
-                       
-               }
-               
-       }
-}
-
-void BluetoothCBManager::registerSocket(std::string uuid, int socket)
-{
-       std::map<std::string, int>::iterator it = m_serverSocketUuidMap.find(uuid);
-
-       if (it != m_serverSocketUuidMap.end()) 
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "same uuid exist");
-       }
-  
-       m_serverSocketUuidMap[uuid] = socket;
-}
-
-void BluetoothCBManager::checkUUIDAvailable(std::string uuid)
-{
-       std::map<std::string, int>::iterator it = m_serverSocketUuidMap.find(uuid);
-
-       if (it != m_serverSocketUuidMap.end()) 
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "same uuid exist");
-       }
-}
-
-void BluetoothCBManager::unregisterSocket(std::string uuid)
-{
-       std::map<std::string, int>::iterator it = m_serverSocketUuidMap.find(uuid);
-
-       if (it != m_serverSocketUuidMap.end()) 
-       {
-               LogDebug("no such uuid");
-       }
-
-       m_serverSocketUuidMap.erase (uuid);
-       
-}
-
-void BluetoothCBManager::serviceSearchRouter(int result, bt_device_sdp_info_s* sdp_info, void* user_data)
-{
-       std::map<std::string, void*>::iterator it = 
-               m_serviceSearchMap.find(sdp_info->remote_address);
-       std::map<std::string, managerType>::iterator managerIt = 
-               m_serviceSearchManagerMap.find(sdp_info->remote_address);
-
-       LogDebug(sdp_info->remote_address);
-       
-       if (it != m_serviceSearchMap.end() && managerIt !=  m_serviceSearchManagerMap.end())
-       {
-               if (managerIt->second == FROM_DEVICE)
-               {
-                       ((BluetoothDeviceManager*)(it->second))->serviceSearchManualAnswer(result);
-               }
-               else if(managerIt->second == FROM_ADAPTER)
-               {
-                       ((BluetoothAdapterManager*)(it->second))->serviceSearchManualAnswer(result);
-               }
-       }
-       else 
-       {
-               LogDebug("manager is not registered");
-       }
-}
-
-void BluetoothCBManager::connectionStateRouter(int result, bt_socket_connection_state_e connection_state, 
-       bt_socket_connection_s *connection)
-{
-       std::map<std::string, void*>::iterator it;
-       std::map<std::string, managerType>::iterator managerIt;
-
-       if (connection->service_uuid == NULL) 
-       {
-               LogDebug("Error service uuid NULL");
-               return;
-       }
-
-       LogDebug(connection->service_uuid);
-       
-       std::string uuid = connection->service_uuid;
-
-       if (connection->local_role == BT_SOCKET_SERVER)
-       {
-               LogDebug("Route servicehandler");
-               
-               it = m_devicePrivateObjectMap.find(uuid);       
-               managerIt = m_devicePrivateObjectManagerMap.find(uuid);
-
-               if (it != m_devicePrivateObjectMap.end() && managerIt !=  m_devicePrivateObjectManagerMap.end())
-               {
-                       if(managerIt->second == FROM_SERVICE)
-                       {
-                               ((BluetoothServiceHandlerManager*)(it->second))->connectionStateChangedEmit(result, connection_state, connection);
-                       }               
-               }
-                       
-       }
-
-       it = m_devicePrivateObjectMap.find(connection->remote_address);
-       managerIt = m_devicePrivateObjectManagerMap.find(connection->remote_address);
-                       
-       if (it != m_devicePrivateObjectMap.end() && managerIt !=  m_devicePrivateObjectManagerMap.end())
-       {
-               if (managerIt->second == FROM_DEVICE)
-               {
-                       LogDebug("Route device");
-                       ((BluetoothDeviceManager*)(it->second))->connectToServiceByUUIDManualAnswer(result, connection_state, connection);
-               }
-               else if(managerIt->second == FROM_SOCKET)
-               {
-                       LogDebug("Route socket");
-                       ((BluetoothSocketManager*)(it->second))->connectionStateChangedEmit(result, connection_state, connection);
-               }
-       }
-
-}
-
-void BluetoothCBManager::socketDataReceivedRouter(bt_socket_received_data_s *data)
-{
-       std::map<int, void*>::iterator it = m_socketPrivateObjectMap.find(data->socket_fd);
-
-       if (it != m_socketPrivateObjectMap.end()) 
-       {
-               ((BluetoothSocketManager*)(it->second))->setDataReceivedEmit(data);
-       }
-       else 
-       {
-               LogDebug("manager is not registered");
-       }
-
-}
-
-void BluetoothCBManager::addServiceSearchCallback(std::string deviceAddress, void *data, managerType type)
-{
-       if (m_serviceSearchMap.size() != 0)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "same operation now");
-       }
-
-       std::map<std::string, void*>::iterator it = 
-               m_serviceSearchMap.find(deviceAddress);
-
-       if (it != m_serviceSearchMap.end())
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "searvice search same device address");
-       }
-
-       if (bt_device_set_service_searched_cb(capi_bt_device_service_searched, this) != BT_ERROR_NONE)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException,      "callback set error");          
-       }
-
-       LogDebug(deviceAddress);
-       
-       m_serviceSearchMap[deviceAddress] = data;
-       m_serviceSearchManagerMap[deviceAddress] = type;
-
-}
-
-void BluetoothCBManager::removeServiceSearchCallback(std::string deviceAddress)
-{
-       std::map<std::string, void*>::iterator it = 
-               m_serviceSearchMap.find(deviceAddress);
-
-       if (it == m_serviceSearchMap.end())
-       {
-               LogDebug("there is no such address");
-               return;
-       }
-
-
-       m_serviceSearchMap.erase(deviceAddress);
-       m_serviceSearchManagerMap.erase(deviceAddress);
-       
-       if (m_serviceSearchMap.size() == 0) 
-       {
-               bt_device_unset_service_searched_cb();
-       }
-}
-
-void BluetoothCBManager::addConnectionStateCallback(std::string deviceAddress, void *data, managerType type)
-{
-       std::map<std::string, void*>::iterator it = 
-               m_devicePrivateObjectMap.find(deviceAddress);
-
-       if (type != FROM_SERVICE && it != m_devicePrivateObjectMap.end())
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "connecting to same device address");
-       }
-
-       if (m_devicePrivateObjectMap.size() == 0)
-       {
-               if (bt_socket_set_connection_state_changed_cb(capi_callback_bt_socket_connection_state_changed, this) != BT_ERROR_NONE)
-               {
-                       LogDebug("callback set error");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "callback set error");
-               }
-       }
-       LogDebug("connection callback for " << deviceAddress);
-       m_devicePrivateObjectMap[deviceAddress] = data;
-       m_devicePrivateObjectManagerMap[deviceAddress] = type;
-}
-
-void BluetoothCBManager::removeConnectionStateCallback(std::string deviceAddress, managerType type)
-{
-       std::map<std::string, void*>::iterator it = 
-               m_devicePrivateObjectMap.find(deviceAddress);
-
-       if (it == m_devicePrivateObjectMap.end())
-       {
-               LogDebug("there is no such address");
-               return;
-       }
-
-       if (type == m_devicePrivateObjectManagerMap[deviceAddress])
-       {
-               m_devicePrivateObjectMap.erase(deviceAddress);
-               m_devicePrivateObjectManagerMap.erase(deviceAddress);
-               LogDebug("remove connection" << deviceAddress);
-       }
-       else 
-       {
-               LogDebug("type different");
-       }
-
-       if (m_devicePrivateObjectMap.size() == 0) 
-       {
-               LogDebug("remove connection state call back");
-               bt_socket_unset_connection_state_changed_cb();          
-       }
-}
-
-void BluetoothCBManager::addSocketDataReceivedCallback(int socket, void *data)
-{
-       std::map<int, void*>::iterator it = m_socketPrivateObjectMap.find(socket);
-
-       if (it != m_socketPrivateObjectMap.end())
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "there is same socket");
-       }
-
-       if (m_socketPrivateObjectMap.size() == 0)
-       {
-               LogDebug("set data receive call back");
-               if (bt_socket_set_data_received_cb(capi_callback_bt_data_received, this) != BT_ERROR_NONE)
-               {
-                       LogDebug("callback set error");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "callback set error");
-               }
-       }
-       
-       m_socketPrivateObjectMap[socket] = data;
-       LogDebug(socket << "add socket (" << data << ")");
-
-}
-
-void BluetoothCBManager::removeSocketDataReceivedCallback(int socket)
-{
-       std::map<int, void*>::iterator it = m_socketPrivateObjectMap.find(socket);
-       
-       if (it == m_socketPrivateObjectMap.end())
-       {
-               LogDebug("there is no such socket");
-               return;
-       }
-
-       LogDebug(socket << "remove socket " <<  m_socketPrivateObjectMap[socket] );
-       m_socketPrivateObjectMap.erase(socket);
-
-       if (m_socketPrivateObjectMap.size() == 0)
-       {
-               LogDebug("remove data receive call back");
-               bt_socket_unset_data_received_cb(); 
-       }
-}
-
-void BluetoothCBManager::clearAll()
-{
-       m_adapterCallback.clear();
-       m_serverSocketUuidMap.clear();
-       m_devicePrivateObjectMap.clear();
-       m_devicePrivateObjectManagerMap.clear();
-       m_serviceSearchMap.clear();
-       m_serviceSearchManagerMap.clear();
-       m_socketPrivateObjectMap.clear();
-}
-void BluetoothCBManager::disconnectAllSockets()
-{
-       // close connection socket
-       for (std::map<int, void*>::iterator it = m_socketPrivateObjectMap.begin(); it != m_socketPrivateObjectMap.end(); ++it)
-       {
-               bt_socket_disconnect_rfcomm((*it).first);
-       }       
-
-       // close server socket
-       for (std::map<std::string, int>::iterator it = m_serverSocketUuidMap.begin(); it != m_serverSocketUuidMap.end(); ++it)
-       {
-               bt_socket_destroy_rfcomm((*it).second);
-       }
-
-}
-
-}
-}
diff --git a/src/Bluetooth/BluetoothCBManager.h b/src/Bluetooth/BluetoothCBManager.h
deleted file mode 100644 (file)
index bd0c483..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_PLATFROM_BLUETOOTH_CALLBACK_MANAGER_H_
-#define TIZENAPIS_PLATFROM_BLUETOOTH_CALLBACK_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <dpl/singleton.h>
-#include <vector>
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class BluetoothCBManager
-{
-public:
-       typedef enum 
-       {
-               ADAPTER_SETPOWERED,
-               ADAPTER_SETNAME,
-               ADAPTER_DISCOVERY,
-               ADAPTER_CREATEBOND,
-               ADAPTER_DESTROYBOND,
-               ADAPTER_SERVICESEARCH,
-               ADAPTER_REGISTER                
-       } adapterCallback;
-       
-       typedef enum 
-       {
-               FROM_ADAPTER,
-               FROM_DEVICE,
-               FROM_SERVICE,
-               FROM_SOCKET
-       } managerType;
-       
-       BluetoothCBManager();
-       virtual ~BluetoothCBManager();
-       
-       void addAdapterCallback(adapterCallback cb, void *passData, std::string address="");
-       void removeAdapterCallback(adapterCallback cb, std::string address="");
-       void registerSocket(std::string uuid, int socket); // for server socket
-       void unregisterSocket(std::string uuid); // for server socket
-       void serviceSearchRouter(int result, bt_device_sdp_info_s* sdp_info, void* user_data);
-       void connectionStateRouter(int result, bt_socket_connection_state_e connection_state, 
-               bt_socket_connection_s *connection);
-               
-       void addServiceSearchCallback(std::string deviceAddress, void *data, managerType type);
-       void removeServiceSearchCallback(std::string deviceAddress);
-       void addConnectionStateCallback(std::string deviceAddress, void *data, managerType type);
-       void removeConnectionStateCallback(std::string deviceAddress, managerType type);
-       void socketDataReceivedRouter(bt_socket_received_data_s *data);
-       void addSocketDataReceivedCallback(int socket, void *data);
-       void removeSocketDataReceivedCallback(int socket);
-       void checkUUIDAvailable(std::string uuid);
-       void clearAll();
-
-private:
-       void disconnectAllSockets();
-       
-       std::vector<adapterCallback> m_adapterCallback;
-       std::map<std::string, int> m_serverSocketUuidMap; 
-
-       std::map<std::string, void*> m_devicePrivateObjectMap; 
-       std::map<std::string, managerType> m_devicePrivateObjectManagerMap; 
-
-       std::map<std::string, void*> m_serviceSearchMap; 
-       std::map<std::string, managerType> m_serviceSearchManagerMap; 
-       
-       std::map<int, void*> m_socketPrivateObjectMap; 
-
-};
-
-typedef DPL::Singleton<BluetoothCBManager> BluetoothCBManagerSingleton;
-
-
-}
-}
-
-#endif
-
diff --git a/src/Bluetooth/BluetoothCallbackUtil.cpp b/src/Bluetooth/BluetoothCallbackUtil.cpp
new file mode 100644 (file)
index 0000000..7741ad2
--- /dev/null
@@ -0,0 +1,120 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <Ecore.h>
+
+#include <JSUtil.h>
+#include <JSWebAPIError.h>
+
+#include "BluetoothCallbackUtil.h"
+#include "BluetoothAdapter.h"
+
+#include <Logger.h>
+
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+static Eina_Bool jobCompleteCB(void *userData){
+    LogDebug("Entered");
+
+    BluetoothCallbackUserDataPtr data = static_cast<BluetoothCallbackUserDataPtr>(userData);
+
+    if(!data) {
+        LogWarning("BluetoothCallbackUserDataPtr is NULL");
+    }
+
+    if(data->mUserData == NULL) {
+        LogWarning("MulticallbackUserData is NULL");
+        return false;            
+    }
+
+    switch(data->mCBType) {
+        case BluetoothCallbackUserData::BT_CB_SUCCESS:
+        {
+            LogDebug("BT_CB_SUCCESS");
+            data->mUserData->invokeCallback("success");
+            break;
+        }
+        case BluetoothCallbackUserData::BT_CB_ERROR:
+        {
+            LogDebug("BT_CB_ERROR");
+            data->mUserData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(data->mUserData->getContext(), *(data->mError)));
+            break;
+        }
+        case BluetoothCallbackUserData::BT_CB_DEVICE:
+        {
+            LogDebug("BT_CB_DEVICE");
+            BluetoothAdapter::getInstance()->returnDevice(data->mAddress, data->mUserData);
+            break;      
+        }
+        case BluetoothCallbackUserData::BT_CB_DEVICES:
+        {
+            LogDebug("BT_CB_DEVICES");
+            BluetoothAdapter::getInstance()->returnKnownDevices(data->mUserData);
+            break;
+        }
+        case BluetoothCallbackUserData::BT_CB_SERVICE:
+        {
+            LogDebug("BT_CB_SERVICE");
+            BluetoothAdapter::getInstance()->returnRegisteredService(data->mUUID, data->mName, data->mUserData);
+            break;
+        }
+        default:
+        {
+            LogWarning("Unknown callback type");
+        }
+    }
+
+    delete data;
+    return false;
+}
+
+void BluetoothCallbackUtil::syncToAsyncSuccessCallback(Common::MultiCallbackUserDataPtr userData)
+{
+    BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, BluetoothCallbackUserData::BT_CB_SUCCESS);
+    ecore_idler_add(jobCompleteCB, data);
+}
+
+void BluetoothCallbackUtil::syncToAsyncErrorCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error)
+{
+    BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, error);
+    ecore_idler_add(jobCompleteCB, data);
+}
+
+void BluetoothCallbackUtil::syncToAsyncDeviceCallback(Common::MultiCallbackUserDataPtr userData, std::string &address)
+{
+    BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, address);
+    ecore_idler_add(jobCompleteCB, data);
+}
+
+void BluetoothCallbackUtil::syncToAsyncDeviceArrayCallback(Common::MultiCallbackUserDataPtr userData)
+{
+    BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, BluetoothCallbackUserData::BT_CB_DEVICES);
+    ecore_idler_add(jobCompleteCB, data);
+}
+
+void BluetoothCallbackUtil::syncToAsyncServiceCallback(Common::MultiCallbackUserDataPtr userData, std::string &uuid, std::string &name)
+{
+    BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, uuid, name);
+    ecore_idler_add(jobCompleteCB, data);
+}
+
+
+} // Bluetooth
+} // DeviceAPI
diff --git a/src/Bluetooth/BluetoothCallbackUtil.h b/src/Bluetooth/BluetoothCallbackUtil.h
new file mode 100644 (file)
index 0000000..610fd42
--- /dev/null
@@ -0,0 +1,105 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_BLUETOOTH_CALLBACK_UTIL_H__
+#define __TIZEN_BLUETOOTH_CALLBACK_UTIL_H__
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+#include <MultiCallbackUserData.h>
+#include <PlatformException.h>
+
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+
+class BluetoothCallbackUserData
+{
+public:
+    typedef enum {
+        BT_CB_SUCCESS,
+        BT_CB_ERROR,
+        BT_CB_DEVICE,
+        BT_CB_DEVICES,
+        BT_CB_SERVICE
+    } callbackTypeE;
+
+
+    BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, callbackTypeE type)
+    {
+        mUserData = userData;
+        mCBType = type;
+    };
+
+    BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error)
+    {
+        mUserData = userData;
+        mError = error;
+        mCBType = BT_CB_ERROR;
+    };    
+
+    BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &uuid, std::string &name)
+    {
+        mUserData = userData;
+        mCBType = BT_CB_SERVICE;
+        mUUID = uuid;
+        mName = name;
+    };
+
+    BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &address)
+    {
+        mUserData = userData;
+        mCBType = BT_CB_DEVICE;
+        mAddress = address;
+    };
+
+    virtual ~BluetoothCallbackUserData()
+    {
+        if(mCBType == BT_CB_ERROR)
+            delete mError;
+    };
+    
+
+    callbackTypeE mCBType;
+    DeviceAPI::Common::MultiCallbackUserDataPtr mUserData;
+    Common::BasePlatformException *mError;
+    std::string mUUID;
+    std::string mName;
+    std::string mAddress;
+};
+
+typedef BluetoothCallbackUserData* BluetoothCallbackUserDataPtr;
+
+
+class BluetoothCallbackUtil
+{
+public:    
+    static void syncToAsyncSuccessCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData);
+    static void syncToAsyncErrorCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error);
+    static void syncToAsyncDeviceCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &address);
+    static void syncToAsyncDeviceArrayCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData);
+    static void syncToAsyncServiceCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &uuid, std::string &name);
+};
+
+
+} // Bluetooth
+} // DeviceAPI
+
+
+
+#endif // __TIZEN_BLUETOOTH_CALLBACK_UTIL_H__
index 29c9576..d8d09c2 100644 (file)
 // limitations under the License.
 //
 
+#include <PlatformException.h>
+#include <JSUtil.h>
 
+#include "plugin_config.h"
 #include "BluetoothClass.h"
-#include <CommonsJavaScript/JSUtils.h>
+#include "BluetoothClassDeviceMajor.h"
+#include "BluetoothClassDeviceMinor.h"
+#include "BluetoothClassDeviceService.h"
+#include "JSBluetoothClassDeviceService.h"
 
-using namespace DPL;
+#include <Logger.h>
+
+using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Bluetooth {
-       
-std::map<std::string,int> BluetoothClass::m_serviceConstants;
 
-BluetoothClass::BluetoothClass()
+BluetoothClass::BluetoothClass(bt_class_s bluetoothClass)    
 {
-       initConstants();
-       m_readOnly = false;
+    LogDebug("Enter");
+    mMajor = BluetoothClassDeviceMajor::getInstance()->getMajorValue(bluetoothClass.major_device_class);
+    mMinor = BluetoothClassDeviceMinor::getInstance()->getMinorValue(bluetoothClass.minor_device_class);
+    mServices= BluetoothClassDeviceService::getInstance()->getServiceValues(bluetoothClass.major_service_class_mask);
 }
 
 BluetoothClass::~BluetoothClass()
 {
-
-}
-
-void BluetoothClass::setReadOnly()
-{
-       m_readOnly = true;
-}
-
-bool BluetoothClass::getReadOnly()
-{
-       return m_readOnly;
-}
-
-bool BluetoothClass::find(const std::string key, int &value)
-{
-       if (m_serviceConstants.find(key) == m_serviceConstants.end())
-       {
-               LogDebug("fetch error");
-               return false;
-       }
-
-       value = m_serviceConstants[key];
-       LogDebug(key << ":" <<  value);
-       return true;
-}
-
-int BluetoothClass::getMajor()
-{
-       return m_major;
-}
-
-void BluetoothClass::setMajor(int major)
-{
-       m_major = major;
+    LogDebug("Enter");
 }
 
-int BluetoothClass::getMinor()
+unsigned long BluetoothClass::getMajor() const
 {
-       return m_minor;
+    LogDebug("Enter");
+    return mMajor;
 }
 
-void BluetoothClass::setMinor(int minor)
+unsigned long BluetoothClass::getMinor() const
 {
-       m_minor = minor;
+    LogDebug("Enter");
+    return mMinor;
 }
 
-std::vector<int> BluetoothClass::getServices()
+JSValueRef BluetoothClass::getServices(JSContextRef context)
 {
-       return m_services;
+    LogDebug("Enter");
+    JSValueRef service = mLocalProperty.getProperty(context, BLUETOOTH_CLASS_SERVICES);
+    if(service == NULL) {
+        service = JSUtil::toJSValueRef_(context, mServices);
+        mLocalProperty.setProperty(context, BLUETOOTH_CLASS_SERVICES, service);
+    }
+
+    return service;
 }
 
-void BluetoothClass::setServices(int device)
+bool BluetoothClass::hasService(unsigned long service)
 {
-       if (m_services.size() != 0)
-       {
-               m_services.clear();
-       }
-
-       std::map<std::string, int>::iterator it;
-       int service = SERVICE_MASK_SHIFT(device);
-
-       it = m_serviceConstants.find("LIMITED_DISCOVERABILITY");
-
-       if (it == m_serviceConstants.end())
-       {
-               LogDebug("Invalid Service Mask Passed");
-               return;
-       }
-
-       for (; it != m_serviceConstants.end(); ++it)
-       {
-               if (service & (*it).second)
-               {
-                       LogDebug("SERVICE " << (*it).first << " " << std::hex << (*it).second);
-                       m_services.push_back((*it).second);
-               }
-       }
-
-       if (m_services.size() == 0)
-       {
-               LogDebug("Invalid Service Mask Passed");
-       }
-       
-}
-
-unsigned long BluetoothClass::toInt()
-{
-       unsigned long uuid = 0;
-
-       uuid = (m_major << MAJOR_SHIFT | m_minor << MINOR_SHIFT);
-
-       LogDebug("major&minor" << std::hex << uuid);
-       
-       for (size_t index = 0; index < m_services.size(); index++)
-       {
-               uuid |= (m_services[index] << SERVICE_SHIFT);
-       }
-
-       LogDebug("service" << std::hex << uuid);
-       
-       return uuid;
+    LogDebug("Enter");
+
+    for(std::vector<unsigned long>::iterator iter = mServices.begin(); iter != mServices.end(); ++iter) {
+        if((*iter) == service) {
+            return true;
+        }
+    }
+    return false;
 }
-void BluetoothClass::fromInt(unsigned long device)
-{
-       if (m_readOnly)
-       {
-               LogDebug("static function, set error");
-               return;
-       }
-       
-       LogDebug("device:" << std::hex << device);
-       
-       m_major = MAJOR_MASK_SHIFT(device);
-       m_minor = MINOR_MASK_SHIFT(device);
-
-       LogDebug("major:" << std::hex << m_major << "minor:" << std::hex << m_minor);
-       
-       setServices(device);
-
-}                              
 
-void BluetoothClass::initConstants()
-{
-       if (m_serviceConstants.find("MISC") != m_serviceConstants.end())
-               return;
-       
-       m_serviceConstants.insert(std::pair<std::string, int>("MISC", 0x00));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("PHONE", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("NETWORK", 0x03));
-       m_serviceConstants.insert(std::pair<std::string, int>("AUDIO_VIDEO", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL", 0x05));
-       m_serviceConstants.insert(std::pair<std::string, int>("IMAGING", 0x06));
-       m_serviceConstants.insert(std::pair<std::string, int>("WEARABLE", 0x07));
-       m_serviceConstants.insert(std::pair<std::string, int>("TOY", 0x08));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH", 0x09));
-       m_serviceConstants.insert(std::pair<std::string, int>("UNCATEGORIZED", 0x1F));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER_UNCATEGORIZED", 0x00));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER_DESKTOP", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER_SERVER", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER_LAPTOP", 0x03));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER_HANDHELD_PC_OR_PDA", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER_PALM_PC_OR_PDA", 0x5));
-       m_serviceConstants.insert(std::pair<std::string, int>("COMPUTER_WEARABLE", 0x06));
-       m_serviceConstants.insert(std::pair<std::string, int>("PHONE_UNCATEGORIZED", 0x00));
-       m_serviceConstants.insert(std::pair<std::string, int>("PHONE_CELLULAR", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("PHONE_CORDLESS", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("PHONE_SMARTPHONE", 0x03));
-       m_serviceConstants.insert(std::pair<std::string, int>("PHONE_MODEM_OR_GATEWAY", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("PHONE_ISDN", 0x05));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_UNRECOGNIZED", 0x00));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_WEARABLE_HEADSET", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_HANDSFREE", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_MICROPHONE", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_LOUDSPEAKER", 0x05));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_HEADPHONES", 0x06));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_PORTABLE_AUDIO", 0x07));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_CAR_AUDIO", 0x08));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_SETTOP_BOX", 0x09));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_HIFI", 0x0a));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_VCR", 0x0b));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_VIDEO_CAMERA", 0x0c));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_CAMCORDER", 0x0d));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_MONITOR", 0x0e));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_DISPLAY_AND_LOUDSPEAKER", 0x0f));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_VIDEO_CONFERENCING", 0x10));
-       m_serviceConstants.insert(std::pair<std::string, int>("AV_GAMING_TOY", 0x12));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_UNCATEGORIZED", 0));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_KEYBOARD", 0x10));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_POINTING_DEVICE", 0x20));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_KEYBOARD_AND_POINTING_DEVICE", 0x30));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_JOYSTICK", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_GAMEPAD", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_REMOTE_CONTROL", 0x03));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_SENSING_DEVICE", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_DEGITIZER_TABLET", 0x05));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_CARD_READER", 0x06));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_DIGITAL_PEN", 0x07));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_HANDHELD_SCANNER", 0x08));
-       m_serviceConstants.insert(std::pair<std::string, int>("PERIPHERAL_HANDHELD_INPUT_DEVICE", 0x09));
-       m_serviceConstants.insert(std::pair<std::string, int>("IMAGING_UNCATEGORIZED", 0x00));
-       m_serviceConstants.insert(std::pair<std::string, int>("IMAGING_DISPLAY", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("IMAGING_CAMERA", 0x08));
-       m_serviceConstants.insert(std::pair<std::string, int>("IMAGING_SCANNER", 0x10));
-       m_serviceConstants.insert(std::pair<std::string, int>("IMAGING_PRINTER", 0x20));
-       m_serviceConstants.insert(std::pair<std::string, int>("WEARABLE_WRITST_WATCH", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("WEARABLE_PAGER", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("WEARABLE_JACKET", 0x03));
-       m_serviceConstants.insert(std::pair<std::string, int>("WEARABLE_HELMET", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("WEARABLE_GLASSES", 0x05));
-       m_serviceConstants.insert(std::pair<std::string, int>("TOY_ROBOT", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("TOY_VEHICLE", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("TOY_DOLL", 0x03));
-       m_serviceConstants.insert(std::pair<std::string, int>("TOY_CONTROLLER", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("TOY_GAME", 0x05));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_UNDEFINED", 0x00));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_BLOOD_PRESSURE_MONITOR", 0x01));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_THERMOMETER", 0x02));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_WEIGHING_SCALE", 0x03));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_GLUCOSE_METER", 0x04));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_PULSE_OXIMETER", 0x05));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_PULSE_RATE_MONITOR", 0x06));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_DATA_DISPLAY", 0x07));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_STEP_COUNTER", 0x08));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_BODY_COMPOSITION_ANALYZER", 0x09));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_PEAK_FLOW_MONITOR", 0x0a));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_MEDICATION_MONITOR", 0x0b));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_KNEE_PROSTHESIS", 0x0c));
-       m_serviceConstants.insert(std::pair<std::string, int>("HEALTH_ANKLE_PROSTHESIS", 0x0d));
-       m_serviceConstants.insert(std::pair<std::string, int>("LIMITED_DISCOVERABILITY", 0x0001));
-       m_serviceConstants.insert(std::pair<std::string, int>("POSITIONING", 0x0008)); 
-       m_serviceConstants.insert(std::pair<std::string, int>("NETWORKING", 0x0010)); 
-       m_serviceConstants.insert(std::pair<std::string, int>("RENDERING", 0x0020)); 
-       m_serviceConstants.insert(std::pair<std::string, int>("CAPTURING", 0x0040));
-       m_serviceConstants.insert(std::pair<std::string, int>("OBJECT_TRANSFER", 0x0080)); 
-       m_serviceConstants.insert(std::pair<std::string, int>("AUDIO", 0x0100));
-       m_serviceConstants.insert(std::pair<std::string, int>("TELEPHONY", 0x0200));
-       m_serviceConstants.insert(std::pair<std::string, int>("INFORMATION", 0x0400));
-}
-}
-}
 
+} // Bluetooth
+} // DeviceAPI
index 124b200..4452fd6 100644 (file)
 // limitations under the License.
 //
 
-#ifndef TIZENAPIS_TIZEN_BLUETOOTH_CLASS_H_
-#define TIZENAPIS_TIZEN_BLUETOOTH_CLASS_H_
+#ifndef __TIZEN_BLUETOOTH_CLASS_H__
+#define __TIZEN_BLUETOOTH_CLASS_H__
 
-#include <dpl/shared_ptr.h>
-#include <map>
 #include <string>
 #include <vector>
 
+#include <JavaScriptCore/JavaScript.h>
+#include <bluetooth.h>
+
+#include <boost/shared_ptr.hpp>
+#include <PropertyBag.h>
+
 namespace DeviceAPI {
 namespace Bluetooth {
 
-class BluetoothClass;
-typedef DPL::SharedPtr<BluetoothClass> BluetoothClassPtr;
-
-#define MAJOR_SHIFT 7
-#define MINOR_SHIFT 1
-#define SERVICE_SHIFT 12
+class BluetoothClass
+{
+public:
+    BluetoothClass(bt_class_s bluetoothClass);
+    virtual ~BluetoothClass();
 
-#define MAJOR_MASK_SHIFT(A) ((A & 0x00000F80) >> MAJOR_SHIFT)
-#define MINOR_MASK_SHIFT(A) ((A & 0x0000007E) >> MINOR_SHIFT)
-#define SERVICE_MASK_SHIFT(A) ((A & 0x007FF000) >> SERVICE_SHIFT)
+    unsigned long getMajor() const;
+    unsigned long getMinor() const;
+    JSValueRef getServices(JSContextRef context);
 
+    bool hasService(unsigned long service);
 
-class BluetoothClass
-{
-public:        
-       bool find(const std::string key, int &value);
-       int getMajor();
-       int getMinor();
-       std::vector<int> getServices();
-       void setServices(int device);
-       void setMajor(int major);
-       void setMinor(int minor);
-       void fromInt(unsigned long value);
-       void setReadOnly();
-       bool getReadOnly();
-       unsigned long toInt();
-       BluetoothClass();
-       ~BluetoothClass();
-private:       
-       void initConstants();
-       static std::map<std::string,int> m_serviceConstants;
-       std::vector<int> m_services;
-       bool m_readOnly;
-       int m_major;
-       int m_minor;
+private:
+    unsigned long mMajor;
+    unsigned long mMinor;
+    std::vector<unsigned long> mServices;
+    Common::PropertyBag mLocalProperty;    
 };
-}
-}
-#endif
+
+typedef boost::shared_ptr<BluetoothClass> BluetoothClassSharedPtr;
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_BLUETOOTH_CLASS_H__
diff --git a/src/Bluetooth/BluetoothClassDeviceMajor.cpp b/src/Bluetooth/BluetoothClassDeviceMajor.cpp
new file mode 100644 (file)
index 0000000..4696461
--- /dev/null
@@ -0,0 +1,82 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <PlatformException.h>
+
+#include "BluetoothClassDeviceMajor.h"
+
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+BluetoothClassDeviceMajor::BluetoothClassDeviceMajor()
+{
+    LogDebug("Enter");
+    
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("MISC", 0x00));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER", 0x01));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("PHONE", 0x02));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("NETWORK", 0x03));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("AUDIO_VIDEO", 0x04));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL", 0x05));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("IMAGING", 0x06));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("WEARABLE", 0x07));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("TOY", 0x08));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH", 0x09));
+    mMajorStringMap.insert(std::pair<std::string, unsigned long>("UNCATEGORIZED", 0x1F));
+
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_MISC, 0x00));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_COMPUTER, 0x01));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_PHONE, 0x02));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT, 0x03));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO, 0x04));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_PERIPHERAL, 0x05));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_IMAGING, 0x06));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_WEARABLE, 0x07));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_TOY, 0x08));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_HEALTH, 0x09));
+    mMajorEnumMap.insert(std::pair<bt_major_device_class_e, unsigned long>(BT_MAJOR_DEVICE_CLASS_UNCATEGORIZED, 0x1F));
+}
+
+BluetoothClassDeviceMajor::~BluetoothClassDeviceMajor()
+{
+    LogDebug("Enter");
+}
+
+BluetoothClassDeviceMajor* BluetoothClassDeviceMajor::getInstance()
+{
+    LogDebug("Enter");
+    static BluetoothClassDeviceMajor instance;
+    return &instance;
+}
+
+unsigned long BluetoothClassDeviceMajor::getMajorValue(std::string major)
+{
+    LogDebug("Enter");
+    return mMajorStringMap.find(major)->second;
+}
+
+unsigned long BluetoothClassDeviceMajor::getMajorValue(bt_major_device_class_e major)
+{
+    LogDebug("Enter");
+    return mMajorEnumMap.find(major)->second;
+}
+
+
+} // Bluetooth
+} // DeviceAPI
similarity index 52%
rename from src/Bluetooth/EventBTGetDevice.h
rename to src/Bluetooth/BluetoothClassDeviceMajor.h
index 9d01a3c..dbc3b9c 100644 (file)
 // limitations under the License.
 //
 
- #ifndef TIZENAPIS_API_BLUETOOTH_GET_DEVICE_H_
-#define TIZENAPIS_API_BLUETOOTH_GET_DEVICE_H_
+#ifndef __TIZEN_BLUETOOTH_CLASS_DEVICE_MAJOR_H__
+#define __TIZEN_BLUETOOTH_CLASS_DEVICE_MAJOR_H__
 
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include "BTDevice.h"
+#include <string>
+#include <map>
+#include <bluetooth.h>
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-class EventBTGetDevice : public WrtDeviceApis::Commons::IEvent<EventBTGetDevice>
+class BluetoothClassDeviceMajor
 {
-private:
-       BluetoothDeviceData m_Device;
-       std::string m_address;
 public:
-       EventBTGetDevice() { LogDebug("entered"); }
-       ~EventBTGetDevice() { }
-
-       void setDevice(BluetoothDeviceData device);
-       void setAddress(std::string address) ;
-       std::string getAddress() ;
-       BluetoothDeviceData getDevice();
-
+    
+    BluetoothClassDeviceMajor();
+    virtual ~BluetoothClassDeviceMajor();
+    
+    static BluetoothClassDeviceMajor* getInstance();
+    unsigned long getMajorValue(std::string major);
+    unsigned long getMajorValue(bt_major_device_class_e major);
 
+private:
+    std::map<std::string, unsigned long> mMajorStringMap;
+    std::map<bt_major_device_class_e, unsigned long> mMajorEnumMap;    
 };
 
-typedef DPL::SharedPtr<EventBTGetDevice> EventBTGetDevicePtr;
+} // Bluetooth
+} // DeviceAPI
 
-}
-}
-#endif 
+#endif // __TIZEN_BLUETOOTH_CLASS_DEVICE_MAJOR_H__
diff --git a/src/Bluetooth/BluetoothClassDeviceMinor.cpp b/src/Bluetooth/BluetoothClassDeviceMinor.cpp
new file mode 100644 (file)
index 0000000..8b4d590
--- /dev/null
@@ -0,0 +1,210 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <PlatformException.h>
+
+#include "BluetoothClassDeviceMinor.h"
+
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+BluetoothClassDeviceMinor::BluetoothClassDeviceMinor()
+{
+    LogDebug("Enter");
+
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER_UNCATEGORIZED", 0x00));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER_DESKTOP", 0x01));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER_SERVER", 0x02));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER_LAPTOP", 0x03));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER_HANDHELD_PC_OR_PDA", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER_PALM_PC_OR_PDA", 0x5));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("COMPUTER_WEARABLE", 0x06));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PHONE_UNCATEGORIZED", 0x00));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PHONE_CELLULAR", 0x01));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PHONE_CORDLESS", 0x02));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PHONE_SMARTPHONE", 0x03));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PHONE_MODEM_OR_GATEWAY", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PHONE_ISDN", 0x05));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_UNRECOGNIZED", 0x00));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_WEARABLE_HEADSET", 0x01));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_HANDSFREE", 0x02));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_MICROPHONE", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_LOUDSPEAKER", 0x05));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_HEADPHONES", 0x06));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_PORTABLE_AUDIO", 0x07));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_CAR_AUDIO", 0x08));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_SETTOP_BOX", 0x09));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_HIFI", 0x0a));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_VCR", 0x0b));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_VIDEO_CAMERA", 0x0c));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_CAMCORDER", 0x0d));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_MONITOR", 0x0e));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_DISPLAY_AND_LOUDSPEAKER", 0x0f));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_VIDEO_CONFERENCING", 0x10));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("AV_GAMING_TOY", 0x12));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_UNCATEGORIZED", 0));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_KEYBOARD", 0x10));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_POINTING_DEVICE", 0x20));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_KEYBOARD_AND_POINTING_DEVICE", 0x30));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_JOYSTICK", 0x01));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_GAMEPAD", 0x02));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_REMOTE_CONTROL", 0x03));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_SENSING_DEVICE", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_DEGITIZER_TABLET", 0x05));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_CARD_READER", 0x06));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_DIGITAL_PEN", 0x07));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_HANDHELD_SCANNER", 0x08));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("PERIPHERAL_HANDHELD_INPUT_DEVICE", 0x09));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("IMAGING_UNCATEGORIZED", 0x00));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("IMAGING_DISPLAY", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("IMAGING_CAMERA", 0x08));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("IMAGING_SCANNER", 0x10));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("IMAGING_PRINTER", 0x20));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("WEARABLE_WRITST_WATCH", 0x01));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("WEARABLE_PAGER", 0x02));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("WEARABLE_JACKET", 0x03));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("WEARABLE_HELMET", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("WEARABLE_GLASSES", 0x05));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("TOY_ROBOT", 0x01));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("TOY_VEHICLE", 0x02));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("TOY_DOLL", 0x03));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("TOY_CONTROLLER", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("TOY_GAME", 0x05));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_UNDEFINED", 0x00));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_BLOOD_PRESSURE_MONITOR", 0x01));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_THERMOMETER", 0x02));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_WEIGHING_SCALE", 0x03));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_GLUCOSE_METER", 0x04));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_PULSE_OXIMETER", 0x05));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_PULSE_RATE_MONITOR", 0x06));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_DATA_DISPLAY", 0x07));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_STEP_COUNTER", 0x08));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_BODY_COMPOSITION_ANALYZER", 0x09));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_PEAK_FLOW_MONITOR", 0x0a));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_MEDICATION_MONITOR", 0x0b));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_KNEE_PROSTHESIS", 0x0c));
+    mMinorStringMap.insert(std::pair<std::string, unsigned long>("HEALTH_ANKLE_PROSTHESIS", 0x0d));
+
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_COMPUTER_UNCATEGORIZED, 0x00));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_COMPUTER_DESKTOP_WORKSTATION , 0x01));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_COMPUTER_SERVER_CLASS , 0x02));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_COMPUTER_LAPTOP , 0x03));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_COMPUTER_HANDHELD_PC_OR_PDA , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_COMPUTER_PALM_SIZED_PC_OR_PDA, 0x5));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_COMPUTER_WEARABLE_COMPUTER , 0x06));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PHONE_UNCATEGORIZED , 0x00));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PHONE_CELLULAR , 0x01));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PHONE_CORDLESS , 0x02));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PHONE_SMART_PHONE , 0x03));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PHONE_WIRED_MODEM_OR_VOICE_GATEWAY , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PHONE_COMMON_ISDN_ACCESS , 0x05));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_UNCATEGORIZED , 0x00));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_WEARABLE_HEADSET , 0x01));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HANDS_FREE , 0x02));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_MICROPHONE , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_LOUDSPEAKER , 0x05));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HEADPHONES , 0x06));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_PORTABLE_AUDIO , 0x07));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAR_AUDIO , 0x08));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_SET_TOP_BOX , 0x09));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HIFI_AUDIO_DEVICE , 0x0a));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VCR , 0x0b));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CAMERA , 0x0c));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAMCORDER , 0x0d));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_MONITOR , 0x0e));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_DISPLAY_LOUDSPEAKER , 0x0f));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CONFERENCING , 0x10));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_GAMING_TOY , 0x12));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERA_UNCATEGORIZED , 0));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_KEY_BOARD , 0x10));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_POINTING_DEVICE , 0x20));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_COMBO_KEYBOARD_POINTING_DEVICE , 0x30));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_JOYSTICK , 0x01));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_GAME_PAD , 0x02));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_REMOTE_CONTROL , 0x03));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_SENSING_DEVICE , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITIZER_TABLET , 0x05));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_CARD_READER , 0x06));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITAL_PEN , 0x07));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_SCANNER , 0x08));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_GESTURAL_INPUT_DEVICE , 0x09));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_IMAGING_DISPLAY , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_IMAGING_CAMERA , 0x08));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_IMAGING_SCANNER , 0x10));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_IMAGING_PRINTER, 0x20));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_WEARABLE_WRIST_WATCH , 0x01));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_WEARABLE_PAGER , 0x02));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_WEARABLE_JACKET , 0x03));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_WEARABLE_HELMET , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_WEARABLE_GLASSES , 0x05));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_TOY_ROBOT , 0x01));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_TOY_VEHICLE , 0x02));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_TOY_DOLL_ACTION , 0x03));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_TOY_CONTROLLER , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_TOY_GAME , 0x05));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_UNCATEGORIZED , 0x00));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_BLOOD_PRESSURE_MONITOR , 0x01));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_THERMOMETER , 0x02));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_WEIGHING_SCALE , 0x03));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_GLUCOSE_METER , 0x04));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_PULSE_OXIMETER , 0x05));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_HEART_PULSE_RATE_MONITOR , 0x06));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_DATA_DISPLAY , 0x07));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_STEP_COUNTER , 0x08));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_BODY_COMPOSITION_ANALYZER , 0x09));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_PEAK_FLOW_MONITOR , 0x0a));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_MEDICATION_MONITOR , 0x0b));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_KNEE_PROSTHESIS , 0x0c));
+    mMinorEnumMap.insert(std::pair<bt_minor_device_class_e, unsigned long>(BT_MINOR_DEVICE_CLASS_HEATH_ANKLE_PROSTHESIS , 0x0d));  
+}
+
+BluetoothClassDeviceMinor::~BluetoothClassDeviceMinor()
+{
+    LogDebug("Enter");
+}
+
+BluetoothClassDeviceMinor* BluetoothClassDeviceMinor::getInstance()
+{
+    LogDebug("Enter");
+    static BluetoothClassDeviceMinor instance;
+    return &instance;
+}
+
+unsigned long BluetoothClassDeviceMinor::getMinorValue(std::string minor)
+{
+    LogDebug("Enter");
+    return mMinorStringMap.find(minor)->second;
+}
+
+unsigned long BluetoothClassDeviceMinor::getMinorValue(bt_minor_device_class_e minor)
+{
+    LogDebug("Enter");
+
+    // F/W provides more minor deivce class
+    std::map<bt_minor_device_class_e, unsigned long>::iterator iter = mMinorEnumMap.find(minor);
+    if(iter != mMinorEnumMap.end()) {
+        return iter->second;
+    }
+    
+    return 0;
+}
+
+
+} // Bluetooth
+} // DeviceAPI
similarity index 53%
rename from src/Bluetooth/EventBTSetName.h
rename to src/Bluetooth/BluetoothClassDeviceMinor.h
index 5f6b920..7107568 100644 (file)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_API_BLUETOOTH_SET_NAME_H
-#define TIZENAPIS_API_BLUETOOTH_SET_NAME_H
+#ifndef __TIZEN_BLUETOOTH_CLASS_DEVICE_MINOR_H__
+#define __TIZEN_BLUETOOTH_CLASS_DEVICE_MINOR_H__
 
 #include <string>
-#include <dpl/shared_ptr.h>
-#include <Commons/IEvent.h>
+#include <map>
+#include <bluetooth.h>
 
 namespace DeviceAPI {
 namespace Bluetooth {
-       
-class EventBTSetName;
-
-typedef DPL::SharedPtr<EventBTSetName> EventBTSetNamePtr;
 
-class EventBTSetName :
-    public WrtDeviceApis::Commons::IEvent<EventBTSetName>
+class BluetoothClassDeviceMinor
 {
 public:
-       EventBTSetName(){}
-       ~EventBTSetName(){}
-       void setName(std::string name) { m_name = name;}
-       std::string getName() { return m_name;}
+    BluetoothClassDeviceMinor();
+    virtual ~BluetoothClassDeviceMinor();
+    
+    static BluetoothClassDeviceMinor* getInstance();
+    unsigned long getMinorValue(std::string minor);
+    unsigned long getMinorValue(bt_minor_device_class_e minor);   
+
 private:
-       std::string m_name;
+    std::map<std::string, unsigned long> mMinorStringMap;
+    std::map<bt_minor_device_class_e, unsigned long> mMinorEnumMap;    
 };
 
+} // Bluetooth
+} // DeviceAPI
 
-}
-}
-#endif
-
+#endif // __TIZEN_BLUETOOTH_CLASS_DEVICE_MINOR_H__
diff --git a/src/Bluetooth/BluetoothClassDeviceService.cpp b/src/Bluetooth/BluetoothClassDeviceService.cpp
new file mode 100644 (file)
index 0000000..369e4af
--- /dev/null
@@ -0,0 +1,92 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <PlatformException.h>
+
+#include "BluetoothClassDeviceService.h"
+
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+BluetoothClassDeviceService::BluetoothClassDeviceService()
+{
+    LogDebug("Enter");
+    
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("LIMITED_DISCOVERABILITY", 0x0001));
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("POSITIONING", 0x0008)); 
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("NETWORKING", 0x0010)); 
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("RENDERING", 0x0020)); 
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("CAPTURING", 0x0040));
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("OBJECT_TRANSFER", 0x0080)); 
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("AUDIO", 0x0100));
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("TELEPHONY", 0x0200));
+    mServiceStringMap.insert(std::pair<std::string, unsigned long>("INFORMATION", 0x0400));
+
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE, 0x0001));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_POSITIONING, 0x0008));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_NETWORKING, 0x0010));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_RENDERING, 0x0020));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_CAPTURING, 0x0040));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER, 0x0080));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_AUDIO, 0x0100));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_TELEPHONY, 0x0200));
+    mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_INFORMATION, 0x0400));  
+}
+
+BluetoothClassDeviceService::~BluetoothClassDeviceService()
+{
+    LogDebug("Enter");
+}
+
+BluetoothClassDeviceService* BluetoothClassDeviceService::getInstance()
+{
+    LogDebug("Enter");
+    static BluetoothClassDeviceService instance;
+    return &instance;
+}
+
+unsigned long BluetoothClassDeviceService::getServiceValue(std::string service)
+{
+    LogDebug("Enter");
+    return mServiceStringMap.find(service)->second;
+}
+
+unsigned long BluetoothClassDeviceService::getServiceValue(bt_major_service_class_e service)
+{
+    LogDebug("Enter");
+    return mServiceEnumMap.find(service)->second;
+}
+
+std::vector<unsigned long> BluetoothClassDeviceService::getServiceValues(int serviceMask)
+{
+    LogDebug("Enter");
+
+    std::vector<unsigned long> ret;
+    for(std::map<bt_major_service_class_e, unsigned long>::iterator iter = mServiceEnumMap.begin(); iter != mServiceEnumMap.end(); iter++) {
+        if(iter->first & serviceMask) {
+            ret.push_back(iter->second);
+        }
+    }
+
+    return ret;
+}
+
+
+} // Bluetooth
+} // DeviceAPI
diff --git a/src/Bluetooth/BluetoothClassDeviceService.h b/src/Bluetooth/BluetoothClassDeviceService.h
new file mode 100644 (file)
index 0000000..713eecb
--- /dev/null
@@ -0,0 +1,48 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_BLUETOOTH_CLASS_DEVICE_SERVICE_H__
+#define __TIZEN_BLUETOOTH_CLASS_DEVICE_SERVICE_H__
+
+#include <string>
+#include <map>
+#include <vector>
+#include <bluetooth.h>
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+class BluetoothClassDeviceService
+{
+public:
+    BluetoothClassDeviceService();
+    virtual ~BluetoothClassDeviceService();
+
+    static BluetoothClassDeviceService* getInstance();
+    unsigned long getServiceValue(std::string service);
+    unsigned long getServiceValue(bt_major_service_class_e service);
+    std::vector<unsigned long> getServiceValues(int serviceMask);
+
+private:
+    std::map<std::string, unsigned long> mServiceStringMap;
+    std::map<bt_major_service_class_e, unsigned long> mServiceEnumMap;    
+};
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_BLUETOOTH_CLASS_DEVICE_SERVICE_H__
diff --git a/src/Bluetooth/BluetoothConverter.cpp b/src/Bluetooth/BluetoothConverter.cpp
deleted file mode 100644 (file)
index e1ec3d1..0000000
+++ /dev/null
@@ -1,362 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <dpl/assert.h>
-#include <Commons/Exception.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include "BluetoothProperty.h"
-#include "BluetoothConverter.h"
-#include "JSBluetoothDevice.h"
-
-#include <pcrecpp.h>
-
-using namespace std;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-BluetoothConverter::BluetoothConverter(JSContextRef context) :
-    Converter(context)
-{
-}
-
-BluetoothConverter::~BluetoothConverter()
-{
-}
-
-
-
-JSValueRef BluetoothConverter::toFunctionOrNull(const JSValueRef& arg)
-{
-       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg))
-       {
-               LogDebug("null.");
-
-               return NULL;
-       } 
-       else if (JSValueIsObject(m_context, arg) == false)
-       {
-               LogDebug("undefined, not object");
-               ThrowMsg(ConversionException, "Not a function nor JS null.");
-       }
-       else if (Validator(m_context).isCallback(arg)) 
-       {
-               LogDebug("Function OK");
-               return arg;
-       } 
-
-       ThrowMsg(ConversionException, "Not a function nor JS null.");
-       return NULL;
-}
-
-JSValueRef BluetoothConverter::toFunction(const JSValueRef& arg)
-{
-       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg) 
-               || !JSValueIsObject(m_context, arg))
-       {
-               ThrowMsg(ConversionException, "JS null passed as function.");
-       }       
-       else if (Validator(m_context).isCallback(arg)) 
-       {
-               LogDebug("Function OK");
-               return arg;
-       } 
-
-       ThrowMsg(ConversionException, "Not a function nor JS null.");
-       return NULL;
-}
-
-
-EventBTOnDiscoveryDevicesPrivateDataPtr 
-       BluetoothConverter::toEventBTOnDiscoveryDevicesPrivateData(JSObjectRef thisObject, JSValueRef successParam, JSValueRef errorParam)
-{
-       JSValueRef errorCalback;
-       if (JSValueIsNull(m_context, successParam) || JSValueIsUndefined(m_context, successParam) 
-                       || !JSValueIsObject(m_context, successParam))
-       {
-               LogError("not a object");
-               Throw(ConversionException);
-       }
-
-       JSObjectRef objectCallbacks = toJSObjectRef(successParam);
-       Validator validator(m_context);
-       BluetoothDiscoveryDevicesSuccessCallback result;
-
-       errorCalback = toFunctionOrNull(errorParam);
-
-       result.onSuccess = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "onstarted");
-       result.onFound = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "ondevicefound");
-       /* bluez doesn't support device disappeared, we don't care onDeviceDisappeared */
-       result.onFinished = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "onfinished");
-                       
-       if (!validator.isCallback(result.onSuccess) || !validator.isCallback(result.onFound) ||
-               !validator.isCallback(result.onFinished))
-       {
-               LogError("java script call back set error");
-               Throw(ConversionException);
-       }
-
-       JSCallbackManagerPtr onSuccessCbm = JSCallbackManager::createObject(m_context, result.onSuccess, NULL);
-       JSCallbackManagerPtr onFoundCbm = JSCallbackManager::createObject(m_context, result.onFound, NULL);
-       JSCallbackManagerPtr onFinishedCbm = JSCallbackManager::createObject(m_context, result.onFinished, NULL);
-
-       onSuccessCbm->setOnError(errorCalback);
-       onFoundCbm->setOnError(errorCalback);
-       onFinishedCbm->setOnError(errorCalback);
-
-       return EventBTOnDiscoveryDevicesPrivateDataPtr(
-               new EventBTOnDiscoveryDevicesPrivateData(onSuccessCbm, onFoundCbm, onFinishedCbm));
-}
-
-BluetoothSocketNotifierPrivateDataPtr 
-       BluetoothConverter::getInitalBluetoothSocketNotifierPrivateData()
-{
-       JSCallbackManagerPtr onMessageCbm = JSCallbackManager::createObject(m_context, NULL, NULL);
-       JSCallbackManagerPtr onErrorCbm = JSCallbackManager::createObject(m_context, NULL, NULL);
-       JSCallbackManagerPtr onCloseCbm = JSCallbackManager::createObject(m_context, NULL, NULL);
-
-       return BluetoothSocketNotifierPrivateDataPtr(
-               new BluetoothSocketNotifierPrivateData(onMessageCbm, onErrorCbm, onCloseCbm));
-       
-}
-
-void BluetoothConverter::setBluetoothSocketNotifierCallback(JSStringRef propertyName, JSValueRef value, 
-       JSObjectRef object, BluetoothSocketNotifierPrivateDataPtr& privData)
-{
-       JSValueRef successCallback = toFunctionOrNull(value);
-
-       if(JSStringIsEqualToUTF8CString(propertyName, "onclose")) 
-       {
-               privData->getOnClose()->setOnSuccess(successCallback);
-       }
-       else if(JSStringIsEqualToUTF8CString(propertyName, "onerror")) 
-       {
-               privData->getOnError()->setOnSuccess(successCallback);
-       }
-       else if(JSStringIsEqualToUTF8CString(propertyName, "onmessage")) 
-       {
-               privData->getOnMessage()->setOnSuccess(successCallback);
-               privData->setObject(object);
-       }
-       else
-       {
-               ThrowMsg(ConversionException, "unknown property");
-       }
-                       
-}
-
-JSObjectRef BluetoothConverter::toBluetoothDevices(const std::vector<BluetoothDeviceData>& devices)
-{
-       int count = devices.size();
-       int index = 0;
-       JSObjectRef adapterObject[count];
-       
-       for (index = 0; index < count; index++)
-       {
-               adapterObject[index] = JSBluetoothDevice::createJSObject(m_context, devices[index]);
-       }
-       JSObjectRef result = JSObjectMakeArray(m_context, count, adapterObject, NULL);
-       return result;  
-}
-
-JSObjectRef BluetoothConverter::toBluetoothByteArray(std::vector<char>& data)
-{
-       JSObjectRef result = JSCreateArrayObject(m_context, 0, NULL);
-       int length = data.size();
-
-       if (!result) 
-       {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Could not create array object.");
-       }
-
-       LogDebug("size" << length);
-       for (int i = 0; i < length; ++i) 
-       {
-               JSValueRef value = JSValueMakeNumber(m_context, data[i]);
-
-               if (!JSSetArrayElement(m_context, result, i, value)) 
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Could not fill array.");
-               }
-       }
-       return result;
-}
-std::string BluetoothConverter::toBluetoothDeviceAddress(JSValueRef deviceAddress)
-{
-       std::string address = toString(deviceAddress);
-       pcrecpp::RE re("(([0-9a-zA-Z]+):)+([0-9a-zA-Z]+)");
-       std::string compareAddress = "00:12:47:08:9A:A6";
-
-       if (!re.FullMatch(address))
-       {
-               ThrowMsg(InvalidArgumentException, "not a bluetooth device address");
-       }
-
-       if (address.size() != compareAddress.size())
-       {
-               ThrowMsg(InvalidArgumentException, "too long or too short parameter");
-       }
-       
-       return address;
-}
-
-std::string BluetoothConverter::toBluetoothUUIDString(JSValueRef uuidString)
-{
-       std::string uuid = toString(uuidString);
-       pcrecpp::RE re("(([0-9a-zA-Z]+)-)+([0-9a-zA-Z]+)");
-       std::string compareUUID = "00001101-0000-1000-8000-00805F9B34FB";
-
-       if (!re.FullMatch(uuid))
-       {
-               LogDebug("not a bluetooth service uuid");
-               ThrowMsg(InvalidArgumentException, "not a bluetooth service uuid");
-       }
-
-       if (uuid.size() != compareUUID.size())
-       {
-               LogDebug("too long or too short parameter");
-               ThrowMsg(InvalidArgumentException, "too long or too short parameter");
-       }
-
-       return uuid;
-}
-
-
-
-unsigned short BluetoothConverter::toBluetoothSecurityLevelInt(JSValueRef level)
-{
-       unsigned short securityLevel= SECURITY_LEVEL_HIGH_VALUE_INT;
-
-       if (!JSValueIsNull(m_context, level) && !JSValueIsUndefined(m_context, level))
-       {
-               std::string securityLevelStr = toString(level);
-               
-               if(strcmp(securityLevelStr.c_str(), SECURITY_LEVEL_HIGH_VALUE) == 0) 
-               {
-                       securityLevel = SECURITY_LEVEL_HIGH_VALUE_INT;
-               }
-               else
-               {
-                       if (strcmp(securityLevelStr.c_str(), SECURITY_LEVEL_MEDIUM_VALUE) == 0 ||
-                               strcmp(securityLevelStr.c_str(), SECURITY_LEVEL_LOW_VALUE) == 0)
-                       {
-                               Throw(UnsupportedException);
-                       }
-                       else
-                       {
-                               Throw(ConversionException);
-                       }
-               }
-       }
-       return securityLevel;
-}
-
-
-unsigned short BluetoothConverter::toBluetoothProtocolInt(JSValueRef protocol)
-{
-       unsigned short bluetoothProtocol = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-       std::string protocolString;
-       
-       if (JSValueIsNull(m_context, protocol) == true || JSValueIsUndefined(m_context, protocol) == true)
-       {
-               bluetoothProtocol  = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-       }
-       else 
-       {
-               protocolString = toString(protocol);
-               LogDebug(protocolString.c_str());
-       
-               if (strcmp(protocolString.c_str(), PROTOCOL_TYPE_RFCOMM_VALUE) == 0)
-               {
-                       bluetoothProtocol = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-               }
-               else if (strcmp(protocolString.c_str(), PROTOCOL_TYPE_L2CAP_VALUE) == 0)
-               {
-                       LogError("Not support protocol");
-                       Throw(UnsupportedException);    
-               }
-               else 
-               {
-                       Throw(InvalidArgumentException);        
-               }
-       }
-       return bluetoothProtocol;
-}
-JSValueRef BluetoothConverter::toBluetoothSecurityLevelJSValueRef(unsigned short level)
-{
-       JSValueRef result;
-
-       switch (level)
-       {
-       case SECURITY_LEVEL_HIGH_VALUE_INT:
-               result = toJSValueRef(SECURITY_LEVEL_HIGH_VALUE);
-               break;
-       case SECURITY_LEVEL_MEDIUM_VALUE_INT:
-               result = toJSValueRef(SECURITY_LEVEL_MEDIUM_VALUE);
-               break;
-       case SECURITY_LEVEL_LOW_VALUE_INT:
-               result = toJSValueRef(SECURITY_LEVEL_LOW_VALUE);
-               break;
-       default:
-               ThrowMsg(InvalidArgumentException, "Not a security level value");
-       }
-       return result;
-}
-
-JSValueRef BluetoothConverter::toBluetoothProtocolJSValue(unsigned short int protocol)
-{
-       if (protocol == PROTOCOL_TYPE_RFCOMM_VALUE_INT)
-       {
-               return toJSValueRef(PROTOCOL_TYPE_RFCOMM_VALUE);
-
-       }
-       else if (protocol == PROTOCOL_TYPE_L2CAP_VALUE_INT)
-       {
-               return toJSValueRef(PROTOCOL_TYPE_L2CAP_VALUE);
-       }
-       else
-       {
-               ThrowMsg(InvalidArgumentException, "Not a protocol value");
-       }
-}
-
-JSValueRef BluetoothConverter::toBluetoothStateJSValue(unsigned short int state)
-{
-       if (state == SOCKET_STATE_CLOSED_VALUE_INT)
-       {
-               return toJSValueRef(SOCKET_STATE_CLOSED_VALUE);
-       
-       }
-       else if (state == SOCKET_STATE_OPEN_VALUE_INT)
-       {
-               return toJSValueRef(SOCKET_STATE_OPEN_VALUE);
-       }
-       else
-       {
-               ThrowMsg(InvalidArgumentException, "Not a state value");
-       }
-}
-
-}
-}
-
diff --git a/src/Bluetooth/BluetoothConverter.h b/src/Bluetooth/BluetoothConverter.h
deleted file mode 100644 (file)
index 9b8fd44..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <dpl/log/log.h>
-#include <CommonsJavaScript/Converter.h>
-#include "BTDevice.h"
-#include "BluetoothMultiCallback.h"
-
-#ifndef TIZENAPIS_TIZEN_BLUETOOTH_CONVERTER_H_
-#define TIZENAPIS_TIZEN_BLUETOOTH_CONVERTER_H_
-
-namespace DeviceAPI {
-namespace Bluetooth {
-       
-class BluetoothConverter : public WrtDeviceApis::CommonsJavaScript::Converter
-{
-  public:
-    using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
-
-    explicit BluetoothConverter(JSContextRef context);
-    virtual ~BluetoothConverter();
-
-    JSValueRef toFunctionOrNull(const JSValueRef& arg);
-    JSValueRef toFunction(const JSValueRef& arg);
-       EventBTOnDiscoveryDevicesPrivateDataPtr 
-               toEventBTOnDiscoveryDevicesPrivateData(JSObjectRef thisObject, 
-               JSValueRef successParam, JSValueRef errorParam);
-       BluetoothSocketNotifierPrivateDataPtr getInitalBluetoothSocketNotifierPrivateData();
-       void setBluetoothSocketNotifierCallback(JSStringRef propertyName, JSValueRef value, 
-               JSObjectRef object, BluetoothSocketNotifierPrivateDataPtr& privData);
-       JSObjectRef toBluetoothDevices(const std::vector<BluetoothDeviceData>& devices);
-       JSObjectRef toBluetoothByteArray(std::vector<char>& data);
-       unsigned short toBluetoothSecurityLevelInt(JSValueRef level);
-       unsigned short toBluetoothProtocolInt(JSValueRef protocol);
-       JSValueRef toBluetoothSecurityLevelJSValueRef(unsigned short level);
-       std::string toBluetoothDeviceAddress(JSValueRef deviceAddress);
-       std::string toBluetoothUUIDString(JSValueRef uuidString);
-       JSValueRef toBluetoothProtocolJSValue(unsigned short int protocol);
-       JSValueRef toBluetoothStateJSValue(unsigned short int state);
-};
-}
-}
-
-#endif
-
diff --git a/src/Bluetooth/BluetoothDevice.cpp b/src/Bluetooth/BluetoothDevice.cpp
new file mode 100644 (file)
index 0000000..d99d4e0
--- /dev/null
@@ -0,0 +1,157 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <PlatformException.h>
+#include <JSUtil.h>
+
+#include "plugin_config.h"
+#include "BluetoothDevice.h"
+#include "BluetoothAdapter.h"
+#include "JSBluetoothClass.h"
+
+#include <Logger.h>
+
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+BluetoothDevice::BluetoothDevice(bt_adapter_device_discovery_info_s *discoveryInfo)
+{
+    LogDebug("Enter");
+
+    mName = std::string(discoveryInfo->remote_name);
+    mAddress = std::string(discoveryInfo->remote_address);
+    mDeviceClass = BluetoothClassSharedPtr(new BluetoothClass(discoveryInfo->bt_class));
+    for(int i = 0; i < discoveryInfo->service_count; i++) {
+        mUUIDs.push_back(std::string(discoveryInfo->service_uuid[i]));
+    }
+    isUpdated = true;
+}
+
+BluetoothDevice::BluetoothDevice(bt_device_info_s *deviceInfo)
+{
+    LogDebug("Enter");
+
+    mName = std::string(deviceInfo->remote_name);
+    mAddress = std::string(deviceInfo->remote_address);
+    mDeviceClass = BluetoothClassSharedPtr(new BluetoothClass(deviceInfo->bt_class));
+    for(int i = 0; i < deviceInfo->service_count; i++) {
+        mUUIDs.push_back(std::string(deviceInfo->service_uuid[i]));
+    }
+    isUpdated = true;    
+}
+
+BluetoothDevice::~BluetoothDevice()
+{
+    LogDebug("Enter");
+    BluetoothAdapter::getInstance()->removeConnReq(mAddress);
+}
+
+void BluetoothDevice::updateInfo(bt_device_info_s *deviceInfo)
+{
+    LogDebug("Enter");
+
+    mName = std::string(deviceInfo->remote_name);
+    mUUIDs.clear();
+    for(int i = 0; i < deviceInfo->service_count; i++) {
+        mUUIDs.push_back(std::string(deviceInfo->service_uuid[i]));
+    }
+    isUpdated = true;
+}
+
+std::string BluetoothDevice::getName() const
+{
+    LogDebug("Enter");
+    return mName;
+}
+
+std::string BluetoothDevice::getAddress() const
+{
+    LogDebug("Enter");
+    return mAddress;
+}
+
+JSValueRef BluetoothDevice::getDeviceClass(JSContextRef context)
+{
+    LogDebug("Enter");
+    JSValueRef deviceClass = mLocalProperty.getProperty(context, BLUETOOTH_DEVICE_DEVICE_CLASS);
+    if(deviceClass == NULL) {
+        deviceClass = JSBluetoothClass::createJSObject(context, mDeviceClass);
+        mLocalProperty.setProperty(context, BLUETOOTH_DEVICE_DEVICE_CLASS, deviceClass);
+    }
+    
+    return deviceClass;
+}
+
+bool BluetoothDevice::isBonded() const
+{
+    LogDebug("Enter");
+
+    bool ret = false;
+    bt_device_info_s *deviceInfo = NULL;
+    if(bt_adapter_get_bonded_device_info(mAddress.c_str(), &deviceInfo) == BT_ERROR_NONE && deviceInfo != NULL) {
+        ret = deviceInfo->is_bonded;
+        bt_adapter_free_device_info(deviceInfo);
+    }
+    
+    return ret;
+}
+
+bool BluetoothDevice::isTrusted() const
+{
+    LogDebug("Enter");
+
+    bool ret = false;
+    bt_device_info_s *deviceInfo = NULL;
+    if(bt_adapter_get_bonded_device_info(mAddress.c_str(), &deviceInfo) == BT_ERROR_NONE && deviceInfo != NULL) {
+        ret = deviceInfo->is_authorized;
+        bt_adapter_free_device_info(deviceInfo);
+    }
+    
+    return ret;
+}
+
+bool BluetoothDevice::isConnected() const
+{
+    LogDebug("Enter");
+
+    bool ret = false;
+    bt_device_info_s *deviceInfo = NULL;
+    if(bt_adapter_get_bonded_device_info(mAddress.c_str(), &deviceInfo) == BT_ERROR_NONE && deviceInfo != NULL) {
+        ret = deviceInfo->is_connected;
+        bt_adapter_free_device_info(deviceInfo);
+    }
+    
+    return ret;
+}
+
+JSValueRef BluetoothDevice::getUUIDs(JSContextRef context)
+{
+    LogDebug("Enter");
+
+    if(isUpdated == true) {
+        mLocalProperty.setProperty(context, BLUETOOTH_DEVICE_UUIDS, JSUtil::toJSValueRef(context, mUUIDs));
+        isUpdated = false;
+    }
+    
+    return mLocalProperty.getProperty(context, BLUETOOTH_DEVICE_UUIDS);
+}
+
+
+} // Bluetooth
+} // DeviceAPI
diff --git a/src/Bluetooth/BluetoothDevice.h b/src/Bluetooth/BluetoothDevice.h
new file mode 100644 (file)
index 0000000..14b8399
--- /dev/null
@@ -0,0 +1,64 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_BLUETOOTH_DEVICE_H__
+#define __TIZEN_BLUETOOTH_DEVICE_H__
+
+#include <string>
+#include <vector>
+
+#include <JavaScriptCore/JavaScript.h>
+#include <bluetooth.h>
+#include <boost/shared_ptr.hpp>
+#include <PropertyBag.h>
+
+#include "BluetoothClass.h"
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+class BluetoothDevice
+{
+public:
+    BluetoothDevice(bt_adapter_device_discovery_info_s *discoveryInfo);
+    BluetoothDevice(bt_device_info_s *deviceInfo);
+    virtual ~BluetoothDevice();
+    
+    void updateInfo(bt_device_info_s *deviceInfo);
+    std::string getName() const;
+    std::string getAddress() const;
+    JSValueRef getDeviceClass(JSContextRef context);
+    bool isBonded() const;
+    bool isTrusted() const;
+    bool isConnected() const;
+    JSValueRef getUUIDs(JSContextRef context);    
+
+private:
+    std::string mName;
+    std::string mAddress;
+    BluetoothClassSharedPtr mDeviceClass;
+    std::vector<std::string> mUUIDs;
+    Common::PropertyBag mLocalProperty;
+    bool isUpdated;
+};
+
+typedef boost::shared_ptr<BluetoothDevice> BluetoothDeviceSharedPtr;
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_BLUETOOTH_DEVICE_H__
diff --git a/src/Bluetooth/BluetoothDeviceManager.cpp b/src/Bluetooth/BluetoothDeviceManager.cpp
deleted file mode 100644 (file)
index 25c98c1..0000000
+++ /dev/null
@@ -1,338 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "BluetoothDeviceManager.h"
-#include "BluetoothCBManager.h"
-
-using namespace WrtDeviceApis;
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-BluetoothDeviceManager::BluetoothDeviceManager()  
-{
-       m_serviceSocket= -1;
-       m_cancelRequest = false;
-}
-
-BluetoothDeviceManager::~BluetoothDeviceManager() 
-{
-       BluetoothCBManagerSingleton::Instance().removeServiceSearchCallback(m_device.address);
-       BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_device.address, BluetoothCBManager::FROM_DEVICE);
-}
-
-namespace {
-
-
-static bool capi_callback_bt_device_bonded_device_find(bt_device_info_s *device_info, void *user_data)
-{
-       bool ret = true;
-       if( device_info != NULL )
-       {
-               LogDebug("address " << device_info->remote_address << " " << device_info->remote_name);
-               ret = ((BluetoothDeviceManager*)user_data)->deviceFoundAnswer(device_info);
-       }
-
-       return ret;
-}
-
-static bool capi_callback_bt_device_check_connected_profile(bt_profile_e profile, void *user_data)
-{
-
-       if (profile == BT_PROFILE_RFCOMM)
-       {
-               LogDebug("Rfcomm connected");
-               
-               
-               if( user_data != NULL )
-               {
-                       *(bool*)user_data = true;
-               }
-               return false;
-       }
-
-       return true;
-}
-
-
-}
-
-
-
-
-bool BluetoothDeviceManager::deviceFoundAnswer(bt_device_info_s *device_info)
-{
-       std::string remoteAddress = device_info->remote_address;
-       int index = 0;
-       
-       if (m_remoteAddress == remoteAddress)
-       {
-               LogDebug("Got Device : Major Class:" << device_info->bt_class.major_device_class);              
-               LogDebug("Minor Class:" << device_info->bt_class.minor_device_class);           
-               
-               m_remoteDevice.address = device_info->remote_address;
-
-               if (device_info->remote_name == NULL)
-               {
-                       m_remoteDevice.name = "";
-               }
-               else 
-               {
-                       m_remoteDevice.name = device_info->remote_name;
-               }
-
-               m_remoteDevice.btClass.major = device_info->bt_class.major_device_class;
-               m_remoteDevice.btClass.minor = device_info->bt_class.minor_device_class;
-               m_remoteDevice.btClass.majorServiceMask = device_info->bt_class.major_service_class_mask;
-                               
-               bool connected = false;
-               bt_device_foreach_connected_profiles(remoteAddress.c_str(), 
-                               capi_callback_bt_device_check_connected_profile, (void*)&connected);
-
-               m_remoteDevice.isBonded = device_info->is_bonded;
-               m_remoteDevice.isConnected = connected;
-               m_remoteDevice.isTrusted = device_info->is_authorized;
-
-               if (device_info->service_uuid != NULL)
-               {
-                       for (index = 0; index < device_info->service_count; index++)
-                       {
-                               if (device_info->service_uuid[index] != NULL)
-                               {
-                                       m_remoteDevice.uuids.push_back(device_info->service_uuid[index]);
-                               }
-                       }
-               }
-               else
-               {
-                       LogDebug("service uuid is null");
-               }
-               return false;
-       }
-       return true;
-}
-void BluetoothDeviceManager::connectToServiceByUUID(const EventBTConnectToServiceByUUIDPtr& event) 
-{
-       LogDebug("Enter");
-       EventRequestReceiver<EventBTConnectToServiceByUUID>::PostRequest(event);
-}
-
-void BluetoothDeviceManager::setDevice(const BluetoothDeviceData device) 
-{
-       m_device = device;
-}
-
-BluetoothDeviceDataClass BluetoothDeviceManager::getClass()
-{
-       return m_device.btClass;
-}
-
-void BluetoothDeviceManager::setNameProperty(const std::string name) 
-{
-       LogDebug("Enter");
-       m_device.name = name;
-}
-
-void BluetoothDeviceManager::setAddressProperty(const std::string address) 
-{
-       LogDebug("Enter");
-       m_device.address = address;
-}
-
-void BluetoothDeviceManager::setBondProperty(const bool bonded) 
-{
-       LogDebug("Enter");
-       m_device.isBonded = bonded;
-}
-
-void BluetoothDeviceManager::setTrustProperty(const bool trusted) 
-{
-       LogDebug("Enter");
-       m_device.isTrusted = trusted;
-}
-
-void BluetoothDeviceManager::setConnectProperty(const bool connected) 
-{
-       LogDebug("Enter");
-       m_device.isConnected= connected;
-}
-
-void BluetoothDeviceManager::setUuidsProperty(const std::vector<std::string> uuids) 
-{
-       LogDebug("Enter");
-       m_device.uuids = uuids;
-}
-
-std::string BluetoothDeviceManager::getNameProperty(void) 
-{
-       LogDebug("Enter" << m_device.name);
-       return  m_device.name;
-}
-std::string BluetoothDeviceManager::getAddressProperty(void) 
-{
-       LogDebug("Enter" << m_device.address);
-       return  m_device.address;
-}
-bool BluetoothDeviceManager::getBondProperty(void) 
-{
-       LogDebug("Enter" << m_device.isBonded);
-       return  m_device.isBonded;
-}
-bool BluetoothDeviceManager::getTrustProperty(void) 
-{
-       LogDebug("Enter" << m_device.isTrusted);
-       return  m_device.isTrusted;
-}
-bool BluetoothDeviceManager::getConnectProperty(void) 
-{
-       LogDebug("Enter" <<     m_device.isConnected);
-       return  m_device.isConnected;
-}
-std::vector<std::string> BluetoothDeviceManager::getUuidsProperty(void) 
-{
-       LogDebug("Enter");
-       return  m_device.uuids;
-}
-
-void BluetoothDeviceManager::cancelConnectToServiceByUUID()
-{
-       m_cancelRequest = true;
-}
-
-void BluetoothDeviceManager::serviceSearchManualAnswer(unsigned short error)
-{
-       BluetoothSocketData socketData = m_EventBTConnectToServiceByUUIDPtr->getSocketData();
-
-       try 
-       {
-               if (error != BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::NotFoundException, "service search error");
-               }
-               
-               BluetoothCBManagerSingleton::Instance().removeServiceSearchCallback(socketData.peerDevice.address.data());
-               BluetoothCBManagerSingleton::Instance().addConnectionStateCallback(socketData.peerDevice.address.data(),
-                       this, BluetoothCBManager::FROM_DEVICE);
-
-               if (bt_socket_connect_rfcomm(socketData.peerDevice.address.data(), 
-                       socketData.uuid.data()) != BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::UnknownException, "connect error");
-               }
-               LogDebug("Service search OK, try to connect");
-
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               m_EventBTConnectToServiceByUUIDPtr->setExceptionCode(ex.getCode());     
-               BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(socketData.peerDevice.address.data(), BluetoothCBManager::FROM_DEVICE);
-               EventRequestReceiver<EventBTConnectToServiceByUUID>::ManualAnswer(m_EventBTConnectToServiceByUUIDPtr);
-       }
-}
-
-
-void BluetoothDeviceManager::connectToServiceByUUIDManualAnswer(unsigned short error, 
-       bt_socket_connection_state_e connectionState, bt_socket_connection_s *connection)
-
-{
-       LogDebug("Enter" << connectionState);
-
-       if (error == BT_ERROR_NONE)
-       {
-               if (m_cancelRequest)
-               {
-                       if (connection->socket_fd > 0)
-                       {
-                               LogDebug("Cancel connect, try to disconnect");
-                               bt_socket_disconnect_rfcomm(connection->socket_fd);
-                               BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_remoteAddress, BluetoothCBManager::FROM_DEVICE);
-                       }
-                       return;
-               }
-
-               BluetoothSocketData socketData = m_EventBTConnectToServiceByUUIDPtr->getSocketData();
-               m_remoteAddress = connection->remote_address;
-               LogDebug("address" << m_remoteAddress << "-" << socketData.peerDevice.address);
-
-               if ((bt_adapter_foreach_bonded_device(capi_callback_bt_device_bonded_device_find, (void*)this)) != BT_ERROR_NONE)
-               {
-                       m_remoteDevice.address = m_remoteAddress;
-               }                       
-
-               m_remoteDevice.isConnected = true;
-               socketData.peerDevice = m_remoteDevice;
-               socketData.connectedSocket = connection->socket_fd;
-               socketData.protocol = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-               socketData.state = SOCKET_STATE_OPEN_VALUE_INT;                 
-
-               if (connection->local_role == BT_SOCKET_SERVER)
-               {
-                       socketData.isServer = true;
-               }
-               else
-               {
-                       socketData.isServer = false;
-               }
-               
-               m_EventBTConnectToServiceByUUIDPtr->setExceptionCode(Commons::ExceptionCodes::None);
-               m_EventBTConnectToServiceByUUIDPtr->setSocketData(socketData);
-       }
-       else
-       {
-               m_EventBTConnectToServiceByUUIDPtr->setExceptionCode(Commons::ExceptionCodes::PlatformException);               
-               
-       }
-       BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_remoteAddress, BluetoothCBManager::FROM_DEVICE);
-       EventRequestReceiver<EventBTConnectToServiceByUUID>::ManualAnswer(m_EventBTConnectToServiceByUUIDPtr);
-}
-
-void BluetoothDeviceManager::OnRequestReceived(const  EventBTConnectToServiceByUUIDPtr& event) 
-{
-       LogDebug("Enter");
-
-       m_EventBTConnectToServiceByUUIDPtr = event;
-       event->switchToManualAnswer();
-       BluetoothSocketData socketData = event->getSocketData();
-       socketData.peerDevice = m_device;
-       event->setSocketData(socketData);
-       m_cancelRequest = false;
-       
-       try 
-       {
-               BluetoothCBManagerSingleton::Instance().addServiceSearchCallback(socketData.peerDevice.address.data(),
-                       this, BluetoothCBManager::FROM_DEVICE);
-               
-               if (bt_device_start_service_search(socketData.peerDevice.address.data()) != BT_ERROR_NONE)
-               {
-                       ThrowMsg(Commons::UnknownException, "service search failed" );
-               }
-       }
-       catch (const Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());  
-               BluetoothCBManagerSingleton::Instance().removeServiceSearchCallback(socketData.peerDevice.address.data());
-               EventRequestReceiver<EventBTConnectToServiceByUUID>::ManualAnswer(event);
-       }
-       
-}
-
-}
-}
diff --git a/src/Bluetooth/BluetoothDeviceManager.h b/src/Bluetooth/BluetoothDeviceManager.h
deleted file mode 100644 (file)
index c135331..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_TIZEN_BLUETOOTH_DEVICE_MANAGER_H_
-#define TIZENAPIS_TIZEN_BLUETOOTH_DEVICE_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include "IBluetoothDeviceManager.h"
-#include "BluetoothFactory.h"
-#include <bluetooth.h>
-#include "BluetoothProperty.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class BluetoothDeviceManager : public IBluetoothDeviceManager
-{
-       friend class BluetoothFactory;
-
-private:
-       BluetoothDeviceData m_device;
-       BluetoothDeviceData m_remoteDevice;
-       int m_serviceSocket;
-       std::string m_remoteAddress;
-       EventBTConnectToServiceByUUIDPtr m_EventBTConnectToServiceByUUIDPtr;
-       bool m_cancelRequest;
-public:
-       bool deviceFoundAnswer(bt_device_info_s *device_info);
-       void connectToServiceByUUIDManualAnswer(unsigned short error, 
-               bt_socket_connection_state_e connectionState, bt_socket_connection_s *connection);
-       void serviceSearchManualAnswer(unsigned short error);
-
-       virtual ~BluetoothDeviceManager();
-       virtual void connectToServiceByUUID(const EventBTConnectToServiceByUUIDPtr& event) ;
-
-       virtual void setNameProperty(const std::string name) ;
-       virtual void setAddressProperty(const std::string address) ;
-       virtual void setBondProperty(const bool bonded) ;
-       virtual void setTrustProperty(const bool trused) ;
-       virtual void setConnectProperty(const bool connected) ;
-       virtual void setUuidsProperty(const std::vector<std::string> uuids) ;
-       virtual void cancelConnectToServiceByUUID();
-       
-       virtual std::string getNameProperty(void) ;
-       virtual std::string getAddressProperty(void) ;
-       virtual bool getBondProperty(void) ;
-       virtual bool getTrustProperty(void) ;
-       virtual bool getConnectProperty(void) ;
-       virtual std::vector<std::string> getUuidsProperty(void) ;
-       virtual void setDevice(const BluetoothDeviceData device) ;
-       virtual BluetoothDeviceDataClass getClass();
-protected:
-       BluetoothDeviceManager();
-       virtual void OnRequestReceived(const EventBTConnectToServiceByUUIDPtr& event) ;
-       
-};
-
-}
-}
-
-#endif 
-
diff --git a/src/Bluetooth/BluetoothDeviceManagerListener.cpp b/src/Bluetooth/BluetoothDeviceManagerListener.cpp
deleted file mode 100644 (file)
index 043b490..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <JavaScriptCore/JavaScript.h>
-#include <dpl/log/log.h>
-#include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Converter.h>
-#include <Commons/IEvent.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "BluetoothDeviceManagerListener.h"
-#include "JSBluetoothSocket.h"
-
-using namespace DeviceAPI::Common;
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-BluetoothDeviceManagerListener::~BluetoothDeviceManagerListener() 
-{
-       LogDebug("entered");
-}
-BluetoothDeviceManagerListener::BluetoothDeviceManagerListener() :
-       EventBTConnectedAnswerReceiver(ThreadEnum::NULL_THREAD)
-{
-       LogDebug("entered");
-}
-
-
-BluetoothDeviceManagerListener& BluetoothDeviceManagerListener::getInstance()
-{
-       static BluetoothDeviceManagerListener instance;
-       return instance;
-}
-
-void BluetoothDeviceManagerListener::OnAnswerReceived(const EventBTConnectToServiceByUUIDPtr& event)
-{
-       LogDebug("Enter");
-       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
-
-       if (event->getExceptionCode() == ExceptionCodes::None)
-       {
-               BluetoothSocketData socketData = event->getSocketData();
-               socketData = event->getSocketData();
-               JSObjectRef adapterObject = JSBluetoothSocket::createJSObject(callbackManager->getContext(), socketData);
-               callbackManager->callOnSuccess(adapterObject);
-       }
-       else if (event->getExceptionCode() == ExceptionCodes::NotFoundException)
-       {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(), 
-                       JSTizenException::UNKNOWN_ERROR, "service search failed"));
-
-       }
-       else if (event->getExceptionCode() == ExceptionCodes::AlreadyInUseException)
-       {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(), 
-                       JSTizenException::SERVICE_NOT_AVAILABLE, "already connected"));
-       }
-       else 
-       {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(), 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error"));
-       }
-}
-
-}
-}
-
diff --git a/src/Bluetooth/BluetoothDeviceManagerListener.h b/src/Bluetooth/BluetoothDeviceManagerListener.h
deleted file mode 100644 (file)
index 3e2a570..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_TIZEN_BLUETOOTH_DEVICE_MANAGER_LISTENER_H_
-#define TIZENAPIS_TIZEN_BLUETOOTH_DEVICE_MANAGER_LISTENER_H_
-
-#include <map>
-#include <dpl/shared_ptr.h>
-#include <dpl/noncopyable.h>
-#include "IBluetoothDeviceManager.h"
-
-using namespace WrtDeviceApis::Commons;
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-       
-typedef EventAnswerReceiver<EventBTConnectToServiceByUUID> EventBTConnectedAnswerReceiver;
-
-
-class BluetoothDeviceManagerListener : 
-       public EventBTConnectedAnswerReceiver
-{
-private:
-       BluetoothDeviceManagerListener();
-public:
-       static BluetoothDeviceManagerListener& getInstance();
-       virtual ~BluetoothDeviceManagerListener();
-protected:
-
-       virtual void OnAnswerReceived(const EventBTConnectToServiceByUUIDPtr& event);
-};
-
-typedef DPL::SharedPtr<BluetoothDeviceManagerListener> BluetoothDeviceManagerListenerPtr;
-
-}
-}
-
-#endif
-
diff --git a/src/Bluetooth/BluetoothFactory.cpp b/src/Bluetooth/BluetoothFactory.cpp
deleted file mode 100644 (file)
index dd66c5c..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "BluetoothAdapterManager.h"
-#include "BluetoothDeviceManager.h"
-#include "BluetoothSocketManager.h"
-#include "BluetoothServiceHandlerManager.h"
-#include "BluetoothFactory.h"
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-
-IBluetoothAdapterManagerPtr BluetoothFactory::getBluetoothAdapterManager() 
-{
-       return IBluetoothAdapterManagerPtr(new BluetoothAdapterManager());
-}              
-
-IBluetoothDeviceManagerPtr BluetoothFactory::getBluetoothDeviceManager() 
-{
-       return IBluetoothDeviceManagerPtr( new BluetoothDeviceManager() );
-}              
-
-IBluetoothSocketManagerPtr BluetoothFactory::getBluetoothSocketManager() 
-{
-       return IBluetoothSocketManagerPtr( new BluetoothSocketManager() );
-}              
-
-IBluetoothServiceHandlerManagerPtr BluetoothFactory::getBluetoothServiceHandlerManager()
-{
-       return IBluetoothServiceHandlerManagerPtr( new BluetoothServiceHandlerManager() );
-}
-
-
-BluetoothFactory& BluetoothFactory::getInstance() 
-{
-       static BluetoothFactory theInstance;
-       return theInstance;
-}
-
-BluetoothFactory::BluetoothFactory() 
-{
-}
-
-BluetoothFactory::~BluetoothFactory()
-{
-}
-
-}
-}
diff --git a/src/Bluetooth/BluetoothFactory.h b/src/Bluetooth/BluetoothFactory.h
deleted file mode 100644 (file)
index 9af2ff5..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_FACTORY_H_
-#define TIZENAPIS_API_BLUETOOTH_FACTORY_H_
-
-#include <dpl/noncopyable.h>
-#include "IBluetoothAdapterManager.h"
-#include "IBluetoothDeviceManager.h"
-#include "IBluetoothSocketManager.h"
-#include "IBluetoothServiceHandlerManager.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-       
-class BluetoothFactory : DPL::Noncopyable
-{
-public:
-       IBluetoothAdapterManagerPtr getBluetoothAdapterManager();
-       IBluetoothDeviceManagerPtr getBluetoothDeviceManager();
-       IBluetoothSocketManagerPtr getBluetoothSocketManager();
-       IBluetoothServiceHandlerManagerPtr getBluetoothServiceHandlerManager();
-
-       static BluetoothFactory& getInstance();
-
-protected:
-       BluetoothFactory();
-       ~BluetoothFactory();
-};
-
-}
-}
-
-#endif 
-
diff --git a/src/Bluetooth/BluetoothMultiCallback.cpp b/src/Bluetooth/BluetoothMultiCallback.cpp
deleted file mode 100644 (file)
index 5fcc299..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "BluetoothMultiCallback.h"
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-EventBTOnDiscoveryDevicesPrivateData::EventBTOnDiscoveryDevicesPrivateData
-                       (const JSCallbackManagerPtr& onSuccess, const JSCallbackManagerPtr& onFound,
-                       const JSCallbackManagerPtr& onFinished) :
-                       m_onSuccess(onSuccess), m_onFound(onFound), m_onFinished(onFinished) {}
-
-JSCallbackManagerPtr EventBTOnDiscoveryDevicesPrivateData::getOnSuccess() const
-{
-       return m_onSuccess;
-}
-
-JSCallbackManagerPtr EventBTOnDiscoveryDevicesPrivateData::getOnFound() const
-{
-       return m_onFound;
-}
-
-JSCallbackManagerPtr EventBTOnDiscoveryDevicesPrivateData::getOnFinished() const
-{
-       return m_onFinished;
-}
-
-
-BluetoothSocketNotifierPrivateData::BluetoothSocketNotifierPrivateData
-                       (const JSCallbackManagerPtr& onMessage, const JSCallbackManagerPtr& onError,
-                       const JSCallbackManagerPtr& onClose) :
-                       m_onMessage(onMessage), m_onError(onError), m_onClose(onClose){ m_object = NULL;}
-
-JSCallbackManagerPtr BluetoothSocketNotifierPrivateData::getOnMessage() const
-{
-       return m_onMessage;
-}
-
-JSCallbackManagerPtr BluetoothSocketNotifierPrivateData::getOnError() const
-{
-       return m_onError;
-}
-
-JSCallbackManagerPtr BluetoothSocketNotifierPrivateData::getOnClose() const
-{
-       return m_onClose;
-}
-
-JSObjectRef BluetoothSocketNotifierPrivateData::getObject() const
-{
-       return m_object;
-}
-
-void BluetoothSocketNotifierPrivateData::setObject(JSObjectRef object)
-{
-       m_object = object;
-}
-
-
-
-BluetoothRegisterServiceSuccessCallbackPrivateData ::BluetoothRegisterServiceSuccessCallbackPrivateData
-                       (const JSCallbackManagerPtr& onSuccess, const JSCallbackManagerPtr& onConnected) :
-                       m_onSuccess(onSuccess), m_onConnected(onConnected) {}
-
-
-JSCallbackManagerPtr BluetoothRegisterServiceSuccessCallbackPrivateData::getOnSuccess() const
-{
-       return m_onSuccess;
-}
-
-JSCallbackManagerPtr BluetoothRegisterServiceSuccessCallbackPrivateData::getOnConnected() const
-{
-       return m_onConnected;
-}
-
-}
-}
-
-
-
-
diff --git a/src/Bluetooth/BluetoothMultiCallback.h b/src/Bluetooth/BluetoothMultiCallback.h
deleted file mode 100644 (file)
index 440e8c4..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_TIZEN_BLUETOOTH_MULTI_CALLBACK_H_
-#define TIZENAPIS_TIZEN_BLUETOOTH_MULTI_CALLBACK_H_
-
-#include <dpl/shared_ptr.h>
-#include <Commons/IEvent.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <JavaScriptCore/JavaScript.h>
-
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-struct BluetoothDiscoveryDevicesSuccessCallback 
-{
-       JSValueRef onSuccess;
-       JSValueRef onFound;
-       JSValueRef onFinished;
-
-       BluetoothDiscoveryDevicesSuccessCallback()
-               : onSuccess(NULL),
-               onFound(NULL),
-               onFinished(NULL)
-       { }
-};
-
-struct BluetoothSocketNotifier 
-{
-       JSValueRef onMessage;
-       JSValueRef onError;
-       JSValueRef onClose;
-
-       BluetoothSocketNotifier()
-               : onMessage(NULL),
-               onError(NULL),
-               onClose(NULL)
-       { }
-
-};
-
-struct BluetoothRegisterServiceSuccessCallback 
-{
-       JSValueRef onSuccess;
-       JSValueRef onConnected;
-
-       BluetoothRegisterServiceSuccessCallback()
-               : onSuccess(NULL),
-               onConnected(NULL)
-       { }
-};
-
-
-class EventBTOnDiscoveryDevicesPrivateData : public WrtDeviceApis::Commons::IEventPrivateData 
-{
-public:
-       EventBTOnDiscoveryDevicesPrivateData(const JSCallbackManagerPtr& onSuccess,
-                       const JSCallbackManagerPtr& onFound,
-                       const JSCallbackManagerPtr& onFinished);
-
-       JSCallbackManagerPtr getOnSuccess() const;
-       JSCallbackManagerPtr getOnFound() const;
-       JSCallbackManagerPtr getOnFinished() const;
-
-private:
-       JSCallbackManagerPtr m_onSuccess;
-       JSCallbackManagerPtr m_onFound;
-       JSCallbackManagerPtr m_onFinished;      
-};
-
-typedef DPL::SharedPtr<EventBTOnDiscoveryDevicesPrivateData> EventBTOnDiscoveryDevicesPrivateDataPtr;
-
-
-class BluetoothSocketNotifierPrivateData : public WrtDeviceApis::Commons::IEventPrivateData 
-{
-public:
-       BluetoothSocketNotifierPrivateData
-                       (const JSCallbackManagerPtr& onMessage,
-                       const JSCallbackManagerPtr& onError,
-                       const JSCallbackManagerPtr& onClose);
-
-       JSCallbackManagerPtr getOnMessage() const;
-       JSCallbackManagerPtr getOnError() const;
-       JSCallbackManagerPtr getOnClose() const;
-       JSObjectRef getObject() const;
-       void setObject(const JSObjectRef object);
-
-private:
-       JSCallbackManagerPtr m_onMessage;
-       JSCallbackManagerPtr m_onError;
-       JSCallbackManagerPtr m_onClose; 
-       JSObjectRef m_object;
-};
-
-typedef DPL::SharedPtr<BluetoothSocketNotifierPrivateData> BluetoothSocketNotifierPrivateDataPtr;
-
-
-class BluetoothRegisterServiceSuccessCallbackPrivateData : public WrtDeviceApis::Commons::IEventPrivateData 
-{
-public:
-       BluetoothRegisterServiceSuccessCallbackPrivateData
-                       (const JSCallbackManagerPtr& onSuccess, const JSCallbackManagerPtr& onConnected);
-
-       JSCallbackManagerPtr getOnSuccess() const;
-       JSCallbackManagerPtr getOnConnected() const;
-
-private:
-       JSCallbackManagerPtr m_onSuccess;
-       JSCallbackManagerPtr m_onConnected;
-};
-
-typedef DPL::SharedPtr<BluetoothRegisterServiceSuccessCallbackPrivateData> BluetoothRegisterServiceSuccessCallbackPrivateDataPtr;
-}
-}
-
-#endif
diff --git a/src/Bluetooth/BluetoothProperty.h b/src/Bluetooth/BluetoothProperty.h
deleted file mode 100644 (file)
index ed5de3b..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_PROPERTY_H_
-#define TIZENAPIS_API_BLUETOOTH_PROPERTY_H_
-
-#define SOCKET_STATE_CLOSED "SOCKET_STATE_CLOSED"
-#define SOCKET_STATE_OPEN  "SOCKET_STATE_OPEN"
-#define PROTOCOL_TYPE_RFCOMM "PROTOCOL_TYPE_RFCOMM"
-#define PROTOCOL_TYPE_L2CAP "PROTOCOL_TYPE_L2CAP"
-#define SECURITY_LEVEL_LOW "SECURITY_LEVEL_LOW"
-#define SECURITY_LEVEL_MEDIUM "SECURITY_LEVEL_MEDIUM"
-#define SECURITY_LEVEL_HIGH "SECURITY_LEVEL_HIGH"
-
-
-#define SOCKET_STATE_CLOSED_VALUE "CLOSED"
-#define SOCKET_STATE_OPEN_VALUE "OPEN"
-#define SOCKET_STATE_CLOSED_VALUE_INT 0
-#define SOCKET_STATE_OPEN_VALUE_INT 1
-
-#define PROTOCOL_TYPE_RFCOMM_VALUE "RFCOMM"
-#define PROTOCOL_TYPE_L2CAP_VALUE "L2CAP"
-#define SECURITY_LEVEL_LOW_VALUE "LOW"
-#define SECURITY_LEVEL_MEDIUM_VALUE "MEDIUM"
-#define SECURITY_LEVEL_HIGH_VALUE "HIGH"
-#define PROTOCOL_TYPE_RFCOMM_VALUE_INT 0
-#define PROTOCOL_TYPE_L2CAP_VALUE_INT 1
-#define SECURITY_LEVEL_LOW_VALUE_INT  0
-#define SECURITY_LEVEL_MEDIUM_VALUE_INT 1
-#define SECURITY_LEVEL_HIGH_VALUE_INT 2
-#define UUID_STR_LENGTH 36
-
-#endif
-
diff --git a/src/Bluetooth/BluetoothServiceHandler.cpp b/src/Bluetooth/BluetoothServiceHandler.cpp
new file mode 100644 (file)
index 0000000..5abb586
--- /dev/null
@@ -0,0 +1,132 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <GlobalContextManager.h>
+#include <PlatformException.h>
+
+#include "BluetoothServiceHandler.h"
+#include "BluetoothAdapter.h"
+#include "BluetoothCallbackUtil.h"
+#include "plugin_config.h"
+
+#include <Logger.h>
+
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+BluetoothServiceHandler::BluetoothServiceHandler(std::string uuid, std::string name, int registeredSocket)
+{
+    mUUID = uuid;
+    mName = name;
+    mRegisteredSocket = registeredSocket;
+    mIsRegistered = true;
+    mIsConnected = false;
+}
+
+BluetoothServiceHandler::~BluetoothServiceHandler()
+{
+    LogDebug("Enter");
+
+    if(mIsRegistered) {        
+        BluetoothAdapter::getInstance()->unregisterUUID(mUUID);
+        bt_socket_destroy_rfcomm(mRegisteredSocket);
+    }
+}
+
+bool BluetoothServiceHandler::setOnConnect(JSContextRef context, JSObjectRef onConnect)
+{
+    LogDebug("Enter");
+
+    MultiCallbackUserDataPtr callback(
+            new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+    if(!callback){
+        LogWarning("Can't create MultiCallbackUserData");
+        return false;
+    }    
+    callback->setCallback("onconnect", onConnect);
+    mOnConnect = callback;
+
+    return mLocalProperty.setProperty(context, BLUETOOTH_SERVICE_HANDLER_ONCONNECT, onConnect);
+}
+
+std::string BluetoothServiceHandler::getUUID() const
+{
+    return mUUID;
+}
+
+std::string BluetoothServiceHandler::getName() const
+{
+    return mName;
+}
+
+int BluetoothServiceHandler::getRegisteredSocket() const
+{
+    return mRegisteredSocket;
+}
+
+MultiCallbackUserDataPtr BluetoothServiceHandler::getOnConnect() const
+{
+    return mOnConnect;
+}
+
+JSValueRef BluetoothServiceHandler::getOnConnect(JSContextRef context)
+{
+    LogDebug("Enter");
+    
+    JSValueRef onConnect = mLocalProperty.getProperty(context, BLUETOOTH_SERVICE_HANDLER_ONCONNECT);
+    if(onConnect == NULL) {
+        LogDebug("onconnect is null");
+        return JSValueMakeNull(context);
+    }
+    
+    return onConnect;
+}
+
+void BluetoothServiceHandler::setConnectionState(bool isConnected)
+{
+    mIsConnected = isConnected;
+}
+
+bool BluetoothServiceHandler::getConnectionState()
+{
+    return mIsConnected;
+}
+
+void BluetoothServiceHandler::unregister(MultiCallbackUserDataPtr userData)
+{
+    LogDebug("Enter");
+
+    if(BluetoothAdapter::getInstance()->getPowered() == true) {
+        if(bt_socket_destroy_rfcomm(mRegisteredSocket) == BT_ERROR_NONE) {
+            mIsRegistered = false;
+            BluetoothAdapter::getInstance()->unregisterUUID(mUUID);
+            BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData);
+        }
+        else {
+            UnknownException *error = new UnknownException("Unknown exception");
+            BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+        }
+    } else {   // Not enabled
+        ServiceNotAvailableException *error = new ServiceNotAvailableException("Bluetooth device is turned off");
+        BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error);
+    }    
+}
+
+} // Bluetooth
+} // DeviceAPI
diff --git a/src/Bluetooth/BluetoothServiceHandler.h b/src/Bluetooth/BluetoothServiceHandler.h
new file mode 100644 (file)
index 0000000..3f50010
--- /dev/null
@@ -0,0 +1,64 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_BLUETOOTH_SERVICE_HANDLER_H__
+#define __TIZEN_BLUETOOTH_SERVICE_HANDLER_H__
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+
+//#include <boost/shared_ptr.hpp>
+#include <MultiCallbackUserData.h>
+#include <PropertyBag.h>
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+class BluetoothServiceHandler
+{
+public:
+    BluetoothServiceHandler(std::string uuid, std::string name, int registeredSocket);
+    virtual ~BluetoothServiceHandler();
+
+    std::string getUUID() const;
+    std::string getName() const;
+    int getRegisteredSocket() const;
+    bool getConnectionState();
+    Common::MultiCallbackUserDataPtr getOnConnect() const;
+    JSValueRef getOnConnect(JSContextRef context);
+
+    void setConnectionState(bool isConnected);
+    bool setOnConnect(JSContextRef context, JSObjectRef onConnect);
+    
+    void unregister(Common::MultiCallbackUserDataPtr userData);
+
+private:
+    std::string mUUID;
+    std::string mName;
+    int mRegisteredSocket;
+    bool mIsConnected;
+    bool mIsRegistered;
+    Common::MultiCallbackUserDataPtr mOnConnect;
+    Common::PropertyBag mLocalProperty;
+};
+
+typedef BluetoothServiceHandler* BluetoothServiceHandlerPtr;
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_BLUETOOTH_SERVICE_HANDLER_H__
diff --git a/src/Bluetooth/BluetoothServiceHandlerManager.cpp b/src/Bluetooth/BluetoothServiceHandlerManager.cpp
deleted file mode 100644 (file)
index aef14f7..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "BluetoothServiceHandlerManager.h"
-#include "BluetoothCBManager.h"
-#include <dpl/assert.h>
-#include "BluetoothProperty.h"
-#include "BTDevice.h"
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-BluetoothServiceHandlerManager::BluetoothServiceHandlerManager()
-{
-       LogDebug("Enter");
-}
-
-BluetoothServiceHandlerManager::~BluetoothServiceHandlerManager() 
-{
-       LogDebug("Enter");
-
-       BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_Uuid, BluetoothCBManager::FROM_SERVICE);
-}
-
-
-
-void BluetoothServiceHandlerManager::connectionStateChangedEmit(int result, 
-       bt_socket_connection_state_e connection_state,  bt_socket_connection_s *connection)
-{
-       LogDebug("OK" << connection_state);
-
-       EventBTServiceOnConnectPtr event(new EventBTServiceOnConnect());
-
-       if (result == BT_ERROR_NONE)
-       {
-               if (connection_state == BT_SOCKET_CONNECTED)
-               {
-       
-                       BluetoothSocketData socketdata;
-                       socketdata.uuid = m_Uuid;
-                       socketdata.isServer = true;
-                       socketdata.protocol = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-                       socketdata.state = SOCKET_STATE_OPEN_VALUE_INT;
-                       socketdata.connectedSocket = connection->socket_fd;
-                       socketdata.registeredSocket = m_registerSocket;
-                       socketdata.peerDevice.address = connection->remote_address;
-                       socketdata.peerDevice.isConnected = true;
-                       m_Connected = true;
-                       event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
-                       event->setSocketData(socketdata);
-               }
-               else 
-               {
-                       m_Connected = false;
-                       return;
-               }
-       }
-       else
-       {
-               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
-       }
-       m_emitter->emit(event);
-}
-
-void BluetoothServiceHandlerManager::setRegisterSocket(int socket)
-{
-       m_registerSocket = socket;
-}
-
-void BluetoothServiceHandlerManager::setName(std::string name)
-{
-       m_Name = name;
-}
-
-void BluetoothServiceHandlerManager::setIsConnected(bool connected)
-{
-       m_Connected =  connected;
-
-}
-
-std::string BluetoothServiceHandlerManager::getName()
-{
-       return m_Name;
-}
-
-bool BluetoothServiceHandlerManager::getIsConnected()
-{
-       return m_Connected;
-}
-
-void BluetoothServiceHandlerManager::setServiceHandlerListener(
-       const EventBTServiceOnConnectEmitterPtr& emitter)
-{
-       // pass uuid for server socket
-       BluetoothCBManagerSingleton::Instance().addConnectionStateCallback(m_Uuid, 
-                               (void*)this, BluetoothCBManager::FROM_SERVICE);
-
-       LogDebug("setServiceHandlerListener - OK");
-       m_emitter = emitter;
-}
-
-EventBTServiceOnConnectEmitterPtr BluetoothServiceHandlerManager::getServiceHandlerListener()
-{
-       return m_emitter;
-}
-
-std::string BluetoothServiceHandlerManager::getUUID()
-{
-       return m_Uuid;
-}
-
-void BluetoothServiceHandlerManager::setUUID(std::string uuid)
-{
-       m_Uuid = uuid;
-}
-
-void BluetoothServiceHandlerManager::unRegister(const EventBTUnregisterRFCOMMServicePtr &event)
-{
-       LogDebug("Enter");
-       WrtDeviceApis::Commons::EventRequestReceiver<EventBTUnregisterRFCOMMService>::PostRequest(event);
-}
-
-void BluetoothServiceHandlerManager::OnRequestReceived(const EventBTUnregisterRFCOMMServicePtr& event) 
-{
-       LogDebug("Enter");
-       
-       try 
-       {
-               std::map<std::string, BluetoothSocketData>::iterator it;
-               
-               if (m_registerSocket < 0)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "no service socket");
-               }
-
-               if (bt_socket_destroy_rfcomm(m_registerSocket) != BT_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "socket destroy error");
-               }
-               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
-               
-               BluetoothCBManagerSingleton::Instance().unregisterSocket(m_Uuid);
-               BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_Uuid, BluetoothCBManager::FROM_SERVICE);
-               
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-        event->setExceptionCode(ex.getCode());
-       }       
-       bt_adapter_unset_state_changed_cb();
-
-}
-
-}
-}
diff --git a/src/Bluetooth/BluetoothServiceHandlerManager.h b/src/Bluetooth/BluetoothServiceHandlerManager.h
deleted file mode 100644 (file)
index 9361cbb..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_PLATFROM_BLUETOOTH_SERVICE_HANDLER_MANAGER_H_
-#define TIZENAPIS_PLATFROM_BLUETOOTH_SERVICE_HANDLER_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <Commons/ThreadPool.h>
-#include "IBluetoothServiceHandlerManager.h"
-#include "BluetoothFactory.h"
-#include <bluetooth.h>
-#include <dpl/mutex.h>
-#include <vector>
-#include <bluetooth.h>
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class BluetoothServiceHandlerManager : public IBluetoothServiceHandlerManager
-{
-       friend class BluetoothFactory;
-public:
-       virtual ~BluetoothServiceHandlerManager();
-       virtual void unRegister(const EventBTUnregisterRFCOMMServicePtr &event);
-       virtual void setServiceHandlerListener(const EventBTServiceOnConnectEmitterPtr& emitter);
-       virtual EventBTServiceOnConnectEmitterPtr getServiceHandlerListener();
-       virtual void setUUID(std::string uuid);
-       virtual std::string getUUID();
-       virtual void setRegisterSocket(int socket);
-       virtual void setName(std::string name);
-       virtual void setIsConnected(bool connected);
-       virtual std::string getName();
-       virtual bool getIsConnected();
-       void connectionStateChangedEmit(int result, 
-               bt_socket_connection_state_e connection_state,  bt_socket_connection_s *connection);
-private:
-       std::string m_Uuid;
-       std::string m_Name;
-       bool m_Connected;
-       int m_registerSocket;
-       EventBTServiceOnConnectEmitterPtr m_emitter;
-protected:
-       BluetoothServiceHandlerManager();
-       virtual void OnRequestReceived(const EventBTUnregisterRFCOMMServicePtr& event) ;
-};
-
-}
-}
-
-#endif
-
diff --git a/src/Bluetooth/BluetoothSocket.cpp b/src/Bluetooth/BluetoothSocket.cpp
new file mode 100644 (file)
index 0000000..138e0ad
--- /dev/null
@@ -0,0 +1,244 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <GlobalContextManager.h>
+#include <PlatformException.h>
+
+#include "BluetoothSocket.h"
+#include "BluetoothAdapter.h"
+#include "plugin_config.h"
+#include "JSBluetoothDevice.h"
+
+#include <Logger.h>
+
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+BluetoothSocket::BluetoothSocket(bt_socket_connection_s *connection)
+{
+    LogDebug("Enter");
+    mConnectedSocket = connection->socket_fd;
+    mUUID = std::string(connection->service_uuid);
+    mIsConnected = true;
+
+    bt_device_info_s *deviceInfo = NULL;
+    bt_adapter_get_bonded_device_info(connection->remote_address, &deviceInfo);
+    if(deviceInfo) {
+        BluetoothDeviceSharedPtr device(new BluetoothDevice(deviceInfo));
+        mPeer = device;
+        bt_adapter_free_device_info(deviceInfo);
+    }
+    
+}
+
+BluetoothSocket::~BluetoothSocket()
+{
+    LogDebug("Enter");
+    if(mIsConnected) {
+        bt_socket_disconnect_rfcomm(mConnectedSocket);
+        BluetoothAdapter::getInstance()->closeConnectedSocket(mConnectedSocket);
+    }
+}
+
+bool BluetoothSocket::setOnMessage(JSContextRef context, JSObjectRef onMessage)
+{
+    LogDebug("Enter");
+    MultiCallbackUserDataPtr callback(
+            new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+    if(!callback){
+        LogWarning("Can't create MultiCallbackUserData");
+        return false;
+    }    
+    callback->setCallback("onmessage", onMessage);
+    mOnMessage = callback;
+
+    return mLocalProperty.setProperty(context, BLUETOOTH_SOCKET_ONMESSAGE, onMessage);    
+}
+
+bool BluetoothSocket::setOnClose(JSContextRef context, JSObjectRef onClose)
+{
+    LogDebug("Enter");
+    MultiCallbackUserDataPtr callback(
+            new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+    if(!callback){
+        LogWarning("Can't create MultiCallbackUserData");
+        return false;
+    }    
+    callback->setCallback("onclose", onClose);
+    mOnClose = callback;
+
+    return mLocalProperty.setProperty(context, BLUETOOTH_SOCKET_ONCLOSE, onClose);    
+}
+
+bool BluetoothSocket::setOnError(JSContextRef context, JSObjectRef onError)
+{
+    LogDebug("Enter");
+    MultiCallbackUserDataPtr callback(
+            new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+    if(!callback){
+        LogWarning("Can't create MultiCallbackUserData");
+        return false;
+    }    
+    callback->setCallback("onerror", onError);
+    mOnError = callback;
+
+    return mLocalProperty.setProperty(context, BLUETOOTH_SOCKET_ONERROR, onError);    
+}
+
+std::string BluetoothSocket::getUUID() const
+{
+    LogDebug("Enter");
+    return mUUID;
+}
+
+void BluetoothSocket::setConnectionState(bool isConnected)
+{
+    LogDebug("Enter");
+    mIsConnected = isConnected;
+}
+
+bool BluetoothSocket::getConnectionState()
+{
+    LogDebug("Enter");
+    return mIsConnected;
+}
+
+JSValueRef BluetoothSocket::getPeer(JSContextRef context)
+{
+    LogDebug("Enter");
+    JSValueRef peer = mLocalProperty.getProperty(context, BLUETOOTH_SOCKET_PEER);
+    if(peer == NULL && mPeer != NULL) {
+        peer = JSBluetoothDevice::createJSObject(context, mPeer);
+        mLocalProperty.setProperty(context, BLUETOOTH_DEVICE_DEVICE_CLASS, peer);
+    }
+    
+    return peer;
+}
+
+MultiCallbackUserDataPtr BluetoothSocket::getOnMessage() const
+{
+    return mOnMessage;
+}
+
+JSValueRef BluetoothSocket::getOnMessage(JSContextRef context)
+{
+    LogDebug("Enter");
+    JSValueRef onMessage = mLocalProperty.getProperty(context, BLUETOOTH_SOCKET_ONMESSAGE);
+    if(onMessage == NULL) {
+        LogDebug("onmessage is null");
+        return JSValueMakeNull(context);
+    }
+    
+    return onMessage;
+}
+
+MultiCallbackUserDataPtr BluetoothSocket::getOnClose() const
+{
+    return mOnClose;
+}
+
+JSValueRef BluetoothSocket::getOnClose(JSContextRef context)
+{
+    LogDebug("Enter");
+    
+    JSValueRef onClose = mLocalProperty.getProperty(context, BLUETOOTH_SOCKET_ONCLOSE);
+    if(onClose == NULL) {
+        LogDebug("onclose is null");
+        return JSValueMakeNull(context);
+    }
+    
+    return onClose;
+}
+
+MultiCallbackUserDataPtr BluetoothSocket::getOnError() const
+{
+    return mOnError;
+}
+
+JSValueRef BluetoothSocket::getOnError(JSContextRef context)
+{
+    LogDebug("Enter");
+
+    JSValueRef onError = mLocalProperty.getProperty(context, BLUETOOTH_SOCKET_ONERROR);
+    if(onError == NULL) {
+        LogDebug("onerror is null");
+        return JSValueMakeNull(context);
+    }
+    
+    return onError;
+}
+
+unsigned long BluetoothSocket::writeData(char* data, unsigned long size)
+{
+    LogDebug("Enter");
+    
+    unsigned long ret = 0;
+    if(bt_socket_send_data(mConnectedSocket, data, static_cast<int>(size)) == BT_ERROR_NONE) {
+        LogDebug("bt_socket_send_data() succeeded");
+        ret = size;
+    }
+    else {
+        throw UnknownException("Unknown error");
+    }
+
+    delete data;
+    return ret;
+}
+
+void BluetoothSocket::storeRecivedData(char *data, unsigned long size)
+{
+    LogDebug("Enter");
+
+    for(unsigned long i = 0; i < size; i++) {
+        mReceivedData.push_back(static_cast<signed char>(data[i]));
+    }
+}
+
+std::vector<signed char> BluetoothSocket::readData()
+{
+    LogDebug("Enter");
+
+    std::vector<signed char> result (mReceivedData);
+    mReceivedData.clear();
+
+    return result;
+}
+
+void BluetoothSocket::close()
+{
+    LogDebug("Enter");
+
+    if(!mIsConnected) {
+        LogDebug("Already disconnected");
+        return;
+    }
+    
+    if(bt_socket_disconnect_rfcomm(mConnectedSocket) != BT_ERROR_NONE) {
+        LogError("bt_socket_disconnect_rfcomm() failed");
+        return;
+    }    
+
+    mIsConnected = false;
+    if(!BluetoothAdapter::getInstance()->closeConnectedSocket(mConnectedSocket)) {
+        throw UnknownException("Unknown error");
+    }
+}
+
+} // Bluetooth
+} // DeviceAPI
diff --git a/src/Bluetooth/BluetoothSocket.h b/src/Bluetooth/BluetoothSocket.h
new file mode 100644 (file)
index 0000000..d7d9d25
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_BLUETOOTH_SOCKET_H__
+#define __TIZEN_BLUETOOTH_SOCKET_H__
+
+#include <string>
+#include <bluetooth.h>
+#include <JavaScriptCore/JavaScript.h>
+
+//#include <boost/shared_ptr.hpp>
+#include <MultiCallbackUserData.h>
+#include <PropertyBag.h>
+
+#include "BluetoothDevice.h"
+
+namespace DeviceAPI {
+namespace Bluetooth {
+
+class BluetoothSocket
+{
+public:
+    BluetoothSocket(bt_socket_connection_s *connection);
+    virtual ~BluetoothSocket();
+
+    std::string getUUID() const;
+    bool getConnectionState();
+    JSValueRef getPeer(JSContextRef context);
+    Common::MultiCallbackUserDataPtr getOnMessage() const;
+    JSValueRef getOnMessage(JSContextRef context);    
+    Common::MultiCallbackUserDataPtr getOnClose() const;
+    JSValueRef getOnClose(JSContextRef context);
+    Common::MultiCallbackUserDataPtr getOnError() const;    
+    JSValueRef getOnError(JSContextRef context);    
+    bool setOnMessage(JSContextRef context, JSObjectRef onMessage);
+    bool setOnClose(JSContextRef context, JSObjectRef onClose);
+    bool setOnError(JSContextRef context, JSObjectRef onError);
+    void storeRecivedData(char *data, unsigned long size);
+    void setConnectionState(bool isConnected);   
+    
+    unsigned long writeData(char* data, unsigned long size);
+    std::vector<signed char> readData();
+    void close();
+
+private:
+    std::string mUUID;
+    int mConnectedSocket;
+    bool mIsConnected;
+    BluetoothDeviceSharedPtr mPeer;
+    std::vector<signed char> mReceivedData;
+    Common::MultiCallbackUserDataPtr mOnMessage;
+    Common::MultiCallbackUserDataPtr mOnClose;
+    Common::MultiCallbackUserDataPtr mOnError;
+    Common::PropertyBag mLocalProperty;  
+};
+
+typedef BluetoothSocket* BluetoothSocketPtr;
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_BLUETOOTH_SOCKET_H__
diff --git a/src/Bluetooth/BluetoothSocketListener.cpp b/src/Bluetooth/BluetoothSocketListener.cpp
deleted file mode 100644 (file)
index a2f44c4..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <JavaScriptCore/JavaScript.h>
-#include <dpl/log/log.h>
-#include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Converter.h>
-#include <Commons/IEvent.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "BluetoothSocketListener.h"
-#include "BluetoothMultiCallback.h"
-#include "JSBluetoothSocket.h"
-
-using namespace DeviceAPI::Common;
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-BluetoothSocketListener::~BluetoothSocketListener() 
-{
-       LogDebug("entered");
-}
-BluetoothSocketListener::BluetoothSocketListener() :
-       EventBTSocketNotificationListener(ThreadEnum::NULL_THREAD)
-{
-       LogDebug("entered");
-       
-}
-
-BluetoothSocketListener& BluetoothSocketListener::getInstance()
-{
-       static BluetoothSocketListener instance;
-       return instance;
-
-}
-
-void BluetoothSocketListener::onAnswerReceived(const EventBTSocketNotificationPtr& event)
-{
-       LogDebug("Enter-Socket notification");
-       
-       BluetoothSocketNotifierPrivateDataPtr multiCallbacks = 
-               DPL::DynamicPointerCast<BluetoothSocketNotifierPrivateData>(event->getPrivateData());
-
-       switch(event->getConnectionState())
-       {
-       case EventBTSocketNotification::DISCONNECTED:
-               multiCallbacks->getOnClose()->callOnSuccess();
-               break;                  
-       case EventBTSocketNotification::DATARECEIVED:
-       {
-               EventBTReadDataType readData;
-
-               if (multiCallbacks->getObject() == NULL)
-               {
-                       multiCallbacks->getOnError()->callOnSuccess(JSTizenExceptionFactory::makeErrorObject(multiCallbacks->getOnError()->getContext(), 
-                               JSTizenException::UNKNOWN_ERROR, "socket object is not set"));
-                       return;
-               }
-               
-               JSBluetoothSocketPriv *priv = 
-                       static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(multiCallbacks->getObject()));
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-
-               readData = event->getReadData();
-               LogDebug("Size" << readData.size());
-               BluetoothSocketManager->setReadData(readData);
-               multiCallbacks->getOnMessage()->callOnSuccess();
-       }
-               break;
-       case EventBTSocketNotification::SOCKETERROR:
-       default:
-               multiCallbacks->getOnError()->callOnSuccess(JSTizenExceptionFactory::makeErrorObject(multiCallbacks->getOnError()->getContext(), 
-                               JSTizenException::UNKNOWN_ERROR, "unknown error"));
-               break;
-       }
-}
-
-}
-}
diff --git a/src/Bluetooth/BluetoothSocketListener.h b/src/Bluetooth/BluetoothSocketListener.h
deleted file mode 100644 (file)
index fb96c71..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_TIZEN_BLUETOOTH_SOCKET_LISTENER_H_
-#define TIZENAPIS_TIZEN_BLUETOOTH_SOCKET_LISTENER_H_
-
-#include <map>
-#include <dpl/shared_ptr.h>
-#include "IBluetoothSocketManager.h"
-#include <dpl/noncopyable.h>
-#include "EventBTSocketNotification.h"
-#include <CommonsJavaScript/JSCallbackManager.h>
-
-
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-typedef EventListener<EventBTSocketNotification> EventBTSocketNotificationListener;
-class BluetoothSocketListener : 
-       public EventBTSocketNotificationListener
-{
-public:
-       BluetoothSocketListener();
-       static BluetoothSocketListener& getInstance();
-       virtual void onAnswerReceived(const EventBTSocketNotificationPtr& event);
-       virtual ~BluetoothSocketListener();
-};
-
-typedef DPL::SharedPtr<BluetoothSocketListener> BluetoothSocketListenerPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/BluetoothSocketManager.cpp b/src/Bluetooth/BluetoothSocketManager.cpp
deleted file mode 100644 (file)
index d7ae8fd..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "BluetoothSocketManager.h"
-#include "BluetoothCBManager.h"
-#include <dpl/assert.h>
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-BluetoothSocketManager::BluetoothSocketManager()
-{
-       LogDebug("Enter");
-       m_socketData.connectedSocket = -1;
-       m_socketData.registeredSocket = -1;
-}
-
-BluetoothSocketManager::~BluetoothSocketManager() 
-{
-       LogDebug("Enter");
-
-       close();
-
-       BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_socketData.peerDevice.address, BluetoothCBManager::FROM_SOCKET);
-       BluetoothCBManagerSingleton::Instance().removeSocketDataReceivedCallback(m_socketData.connectedSocket);
-}
-
-
-
-void BluetoothSocketManager::setReadData(EventBTReadDataType readData)
-{
-       DPL::Mutex::ScopedLock lock(&m_mtx);
-       m_readData = readData;
-}
-
-void BluetoothSocketManager::setDataReceivedEmit(bt_socket_received_data_s *data)
-{
-       LogDebug("OK" << data->data[0] << data->data[1] << " :" << data->data_size);
-
-       DPL::Mutex::ScopedLock lock(&m_mtx);
-               
-       EventBTSocketNotificationPtr event(new EventBTSocketNotification());
-       event->setSocketData(m_socketData);
-       event->setReadData(data->data, data->data_size);
-       event->setConnectionState(EventBTSocketNotification::DATARECEIVED);
-       m_EventBTSocketNotificationEmitterPtr->emit(event);
-}
-
-void BluetoothSocketManager::connectionStateChangedEmit(int result, 
-       bt_socket_connection_state_e connection_state,  bt_socket_connection_s *connection)
-{
-
-       LogDebug("OK");
-       
-       EventBTSocketNotificationPtr event(new EventBTSocketNotification());
-       event->setConnectionState(EventBTSocketNotification::SOCKETERROR);              
-
-       if (result == BT_ERROR_NONE)
-       {
-               if (connection_state == BT_SOCKET_DISCONNECTED)
-               {
-                       event->setConnectionState(EventBTSocketNotification::DISCONNECTED);
-                       BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_socketData.peerDevice.address, BluetoothCBManager::FROM_SOCKET);
-                       BluetoothCBManagerSingleton::Instance().removeSocketDataReceivedCallback(m_socketData.connectedSocket);
-               }
-       }
-
-       event->setSocketData(m_socketData);
-       m_EventBTSocketNotificationEmitterPtr->emit(event);
-
-}
-void BluetoothSocketManager::setSocketData(BluetoothSocketData socketData)
-{
-       m_socketData = socketData;
-}
-
-
-int BluetoothSocketManager::setSocketNotifier(EventBTSocketNotificationEmitterPtr emitter)
-{
-       try 
-       {
-               
-               BluetoothCBManagerSingleton::Instance().addConnectionStateCallback(m_socketData.peerDevice.address, 
-                       (void*)this, BluetoothCBManager::FROM_SOCKET);
-               BluetoothCBManagerSingleton::Instance().addSocketDataReceivedCallback(m_socketData.connectedSocket, (void*)this);
-
-               m_EventBTSocketNotificationEmitterPtr = emitter;
-               return BT_ERROR_NONE;
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LogDebug("callback set error");
-               return BT_ERROR_NOT_INITIALIZED;
-       }
-}
-
-EventBTSocketNotificationEmitterPtr BluetoothSocketManager::getSocketNotifier()
-{
-       return m_EventBTSocketNotificationEmitterPtr;
-}
-
-int BluetoothSocketManager::writeData(const char *data, const unsigned int length)
-{
-       LogDebug(length);
-
-       if (m_socketData.connectedSocket < 0)
-       {
-               return BT_ERROR_NOT_INITIALIZED;
-       }
-
-                       
-       if (data == NULL || length == 0)
-       {
-               return BT_ERROR_INVALID_PARAMETER;
-       }
-
-
-       return  bt_socket_send_data(m_socketData.connectedSocket, data, length);
-}
-
-EventBTReadDataType BluetoothSocketManager::readData()
-{
-       DPL::Mutex::ScopedLock lock(&m_mtx);
-       
-       return m_readData;
-}
-
-
-int BluetoothSocketManager::close()
-{
-       DPL::Mutex::ScopedLock lock(&m_mtx);
-       int ret = 0;
-       
-
-       if (m_socketData.isServer == true)
-       {
-               ret = bt_socket_destroy_rfcomm(m_socketData.registeredSocket);
-       }
-       else
-       {
-               ret = bt_socket_disconnect_rfcomm(m_socketData.connectedSocket);
-       }
-       BluetoothCBManagerSingleton::Instance().removeConnectionStateCallback(m_socketData.peerDevice.address, BluetoothCBManager::FROM_SOCKET);
-       BluetoothCBManagerSingleton::Instance().removeSocketDataReceivedCallback(m_socketData.connectedSocket);
-       return ret;
-}
-
-std::string BluetoothSocketManager::getUUID()
-{
-       return m_socketData.uuid;
-}
-unsigned int BluetoothSocketManager::getProtocol()
-{
-       return m_socketData.protocol;
-}
-unsigned int BluetoothSocketManager::getState()
-{
-       return m_socketData.state;
-}
-BluetoothDeviceData BluetoothSocketManager::getPeer()
-{
-       return m_socketData.peerDevice;
-}
-
-}
-}
diff --git a/src/Bluetooth/BluetoothSocketManager.h b/src/Bluetooth/BluetoothSocketManager.h
deleted file mode 100644 (file)
index b888746..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_PLATFROM_BLUETOOTH_SOCKET_MANAGER_H_
-#define TIZENAPIS_PLATFROM_BLUETOOTH_SOCKET_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <Commons/ThreadPool.h>
-#include "IBluetoothSocketManager.h"
-#include "BluetoothFactory.h"
-#include <bluetooth.h>
-#include <dpl/mutex.h>
-#include <vector>
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-
-class BluetoothSocketManager : public IBluetoothSocketManager
-{
-       friend class BluetoothFactory;
-public:
-       virtual ~BluetoothSocketManager();
-       virtual std::string getUUID();
-       virtual unsigned int getProtocol();
-       virtual unsigned int getState();
-       virtual BluetoothDeviceData getPeer();
-       virtual int setSocketNotifier(EventBTSocketNotificationEmitterPtr emitter);
-       virtual EventBTSocketNotificationEmitterPtr getSocketNotifier();
-       virtual int writeData(const char *data, const unsigned int length);
-       virtual EventBTReadDataType readData();
-       virtual int close();
-       virtual void setSocketData(BluetoothSocketData socketData);
-       virtual void setReadData(EventBTReadDataType readData);
-       void setDataReceivedEmit(bt_socket_received_data_s *data);
-       void connectionStateChangedEmit(int result, bt_socket_connection_state_e connection_state, 
-               bt_socket_connection_s *connection);
-private:
-       EventBTReadDataType m_readData;
-       DPL::Mutex m_mtx;
-       BluetoothSocketData m_socketData;
-       EventBTSocketNotificationEmitterPtr m_EventBTSocketNotificationEmitterPtr;
-protected:
-       BluetoothSocketManager();
-
-};
-
-}
-}
-
-#endif /* WRTPLUGINS_API_BluetoothSocketManager_H_ */
-
old mode 100755 (executable)
new mode 100644 (file)
index f6bbacb..2b92f6d
@@ -2,66 +2,48 @@ SET(TARGET_NAME ${bluetooth_target})
 SET(DESTINATION_NAME ${bluetooth_dest})
 SET(TARGET_IMPL_NAME ${bluetooth_impl})
 
-PKG_CHECK_MODULES(platform_pkgs_bluetooth REQUIRED capi-network-bluetooth)
-
-INCLUDE_DIRECTORIES(
-       ${TOP}/Common
-       ${platform_pkgs_bluetooth_INCLUDE_DIRS}
-)
+PKG_SEARCH_MODULE(bluetooth REQUIRED capi-network-bluetooth)
+PKG_SEARCH_MODULE(system-info REQUIRED capi-system-info)
 
 SET(CMAKE_INSTALL_RPATH
        ${CMAKE_INSTALL_RPATH}
        ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}
 )
 
-SET(SRCS_PLATFORM_API_BLUETOOTH
-       BluetoothFactory.cpp
-       EventBTGetKnownDevices.cpp
-       EventBTGetDevice.cpp
-       EventBTOnDiscoveryDevices.cpp
-       EventBTSocketNotification.cpp
-       EventBTCreateDestroyBonding.cpp
-       IBluetoothAdapterManager.cpp
-       IBluetoothDeviceManager.cpp
-       IBluetoothSocketManager.cpp
-       IBluetoothServiceHandlerManager.cpp
-       IBluetoothSocketManager.cpp
-)
-
-SET(SRCS_PLATFORM_IMPLEMENTATION_BLUETOOTH
-       BluetoothAdapterManager.cpp
-       BluetoothDeviceManager.cpp
-       BluetoothSocketManager.cpp
-       BluetoothServiceHandlerManager.cpp
-       BluetoothCBManager.cpp
+SET(SRCS_IMPL
+    JSBluetoothManager.cpp
+    JSBluetoothAdapter.cpp
+    JSBluetoothDevice.cpp
+    JSBluetoothSocket.cpp
+    JSBluetoothClass.cpp
+    JSBluetoothClassDeviceMajor.cpp
+    JSBluetoothClassDeviceMinor.cpp
+    JSBluetoothClassDeviceService.cpp
+    JSBluetoothServiceHandler.cpp
+    BluetoothAdapter.cpp
+    BluetoothDevice.cpp
+    BluetoothSocket.cpp
+    BluetoothClass.cpp
+    BluetoothClassDeviceMajor.cpp
+    BluetoothClassDeviceMinor.cpp
+    BluetoothClassDeviceService.cpp
+    BluetoothServiceHandler.cpp
+    BluetoothCallbackUtil.cpp
 )
+#   BluetoothManager.cpp
 
-SET(SRCS_IMPL
-       ${SRCS_PLATFORM_IMPLEMENTATION_BLUETOOTH}
-       ${SRCS_PLATFORM_API_BLUETOOTH}
-       BluetoothAdapterListener.cpp
-       BluetoothSocketListener.cpp
-       BluetoothDeviceManagerListener.cpp
-       BluetoothClass.cpp
-       BluetoothMultiCallback.cpp
-       BluetoothConverter.cpp
-       JSBluetoothAdapter.cpp
-       JSBluetoothDevice.cpp
-       JSBluetoothClass.cpp
-       JSBluetoothClassDeviceMajor.cpp
-       JSBluetoothClassDeviceMinor.cpp
-       JSBluetoothClassDeviceService.cpp
-       JSBluetoothServiceHandler.cpp
-       JSBluetoothManager.cpp
-       JSBluetoothSocket.cpp
-       JSBluetoothDevice.cpp
+INCLUDE_DIRECTORIES(
+       ${TOP}/Common
+       ${bluetooth_INCLUDE_DIRS}
+       ${system-info_INCLUDE_DIRS}
 )
 
 ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
 
 TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME}
        ${LIBS_COMMON}
-       ${platform_pkgs_bluetooth_LIBRARIES}
+       ${bluetooth_LIBRARIES}
+       ${system-info_LIBRARIES}
 )
 
 SET(SRCS
@@ -78,6 +60,6 @@ TARGET_LINK_LIBRARIES(${TARGET_NAME}
 INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
 INSTALL(
-       DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/bluetooth
-       FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE
+        DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/bluetooth
+        FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE
 )
diff --git a/src/Bluetooth/EventBTConnectToServiceByUUID.h b/src/Bluetooth/EventBTConnectToServiceByUUID.h
deleted file mode 100644 (file)
index ec76384..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_CONNECTED_TO_SERVICE_BY_UUID_H_
-#define TIZENAPIS_API_BLUETOOTH_CONNECTED_TO_SERVICE_BY_UUID_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTConnectToServiceByUUID : public WrtDeviceApis::Commons::IEvent<EventBTConnectToServiceByUUID>
-{
-private :
-       BluetoothSocketData m_socketData;
-       bool m_result;
-public:
-       EventBTConnectToServiceByUUID() { LogDebug("entered"); }
-       ~EventBTConnectToServiceByUUID() { }
-       void setSocketData(BluetoothSocketData socketData) { m_socketData = socketData;}
-       BluetoothSocketData getSocketData() { return m_socketData;}
-};
-
-typedef DPL::SharedPtr<EventBTConnectToServiceByUUID> EventBTConnectToServiceByUUIDPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/EventBTCreateDestroyBonding.cpp b/src/Bluetooth/EventBTCreateDestroyBonding.cpp
deleted file mode 100644 (file)
index 66b3300..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "EventBTCreateDestroyBonding.h"
-#include "IBluetoothAdapterManager.h"
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include "JSBluetoothAdapter.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-EventBTCreateDestroyBonding::EventBTCreateDestroyBonding() 
-{ 
-       LogDebug("entered"); 
-}
-EventBTCreateDestroyBonding::~EventBTCreateDestroyBonding() 
-{ 
-
-}
-
-
-bool EventBTCreateDestroyBonding::cancelRequest()
-{
-       LogDebug("OK");
-       bool result = false;
-
-       BluetoothCreateBondingPrivateDataPtr privData = 
-               DPL::StaticPointerCast<BluetoothCreateBondingPrivateData>(IEvent<EventBTCreateDestroyBonding>::getPrivateData());
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(privData->getObject()));
-       IBluetoothAdapterManagerPtr BluetoothAdapter(priv->getObject());
-
-       if (m_cancelled) {
-               LogDebug("Already canceleed");          
-               return false;
-       }
-       
-       if (m_state) {
-               LogDebug("cancelling");
-               result = BluetoothAdapter->createBondingCancel();
-               return result;
-       }
-
-       return result;
-}
-
-}
-}
diff --git a/src/Bluetooth/EventBTCreateDestroyBonding.h b/src/Bluetooth/EventBTCreateDestroyBonding.h
deleted file mode 100644 (file)
index 44df41b..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_CREATE_DESTROY_BONDING_H_
-#define TIZENAPIS_API_BLUETOOTH_CREATE_DESTROY_BONDING_H_
-
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTCreateDestroyBonding : public WrtDeviceApis::Commons::IEvent<EventBTCreateDestroyBonding>
-{
-private:
-       std::string m_address;
-       bool m_operation;
-       BluetoothDeviceData m_device;
-public:
-       EventBTCreateDestroyBonding() ;
-       ~EventBTCreateDestroyBonding() ;
-       void setAddress(std::string address) { m_address = address;}
-       std::string getAddress() { return m_address;}
-       void setCreateBonding(void) { m_operation = true; }
-       void setDestroyBonding(void) { m_operation = false; }
-       bool isCreateBonding(void) { return m_operation == true;}
-       bool isDestroyBonding(void) { return m_operation == true;}
-       BluetoothDeviceData getDevice() { return m_device;}
-       void setDevice(BluetoothDeviceData device) { m_device = device;}
-       virtual bool cancelRequest();
-};
-
-typedef DPL::SharedPtr<EventBTCreateDestroyBonding> EventBTCreateDestroyBondingPtr;
-
-}
-} 
-
-#endif 
diff --git a/src/Bluetooth/EventBTGetAdapter.h b/src/Bluetooth/EventBTGetAdapter.h
deleted file mode 100644 (file)
index 42a3bf9..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_BT_GET_ADAPTER_H_
-#define TIZENAPIS_API_BLUETOOTH_BT_GET_ADAPTER_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTGetAdapter : public WrtDeviceApis::Commons::IEvent<EventBTGetAdapter>
-{
-private:
-       bool m_result;
-public:
-       EventBTGetAdapter() { m_result = false;}
-       ~EventBTGetAdapter() { }
-
-};
-typedef DPL::SharedPtr<EventBTGetAdapter> EventBTGetAdapterPtr;
-
-} 
-} 
-
-#endif 
diff --git a/src/Bluetooth/EventBTGetDevice.cpp b/src/Bluetooth/EventBTGetDevice.cpp
deleted file mode 100644 (file)
index 737f37e..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "EventBTGetDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-
-void EventBTGetDevice::setDevice(BluetoothDeviceData device)
-{
-       m_Device = device;
-}
-
-void EventBTGetDevice::setAddress(std::string address)
-{
-       m_address = address;
-}
-
-std::string EventBTGetDevice::getAddress()
-{
-       return m_address;
-}
-
-
-BluetoothDeviceData EventBTGetDevice::getDevice()
-{
-       return m_Device;
-}
-
-}
-}
diff --git a/src/Bluetooth/EventBTGetKnownDevices.cpp b/src/Bluetooth/EventBTGetKnownDevices.cpp
deleted file mode 100644 (file)
index 9755b9f..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "EventBTGetKnownDevices.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-void EventBTGetKnownDevices::addDevice(BluetoothDeviceData device)
-{
-       m_Devices.push_back(device);
-}
-
-std::vector<BluetoothDeviceData> EventBTGetKnownDevices::getDevices()
-{
-       return m_Devices;
-}
-
-}
-}
diff --git a/src/Bluetooth/EventBTGetKnownDevices.h b/src/Bluetooth/EventBTGetKnownDevices.h
deleted file mode 100644 (file)
index 6fe472b..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_GET_KNOWN_DEVICES_H_
-#define TIZENAPIS_API_BLUETOOTH_GET_KNOWN_DEVICES_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTGetKnownDevices : public WrtDeviceApis::Commons::IEvent<EventBTGetKnownDevices>
-{
-private:
-public:
-
-private:
-       std::vector<BluetoothDeviceData> m_Devices;
-
-public:
-       EventBTGetKnownDevices() { LogDebug("entered"); }
-       ~EventBTGetKnownDevices() { }
-
-       void addDevice(BluetoothDeviceData device);
-       std::vector<BluetoothDeviceData> getDevices();
-};
-
-typedef DPL::SharedPtr<EventBTGetKnownDevices> EventBTGetKnownDevicesPtr;
-
-}
-}
-#endif 
diff --git a/src/Bluetooth/EventBTOnDiscoveryDevices.cpp b/src/Bluetooth/EventBTOnDiscoveryDevices.cpp
deleted file mode 100644 (file)
index e532cc6..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "EventBTOnDiscoveryDevices.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-EventBTOnDiscoveryDevices::EventBTOnDiscoveryDevices()
-{ 
-       LogDebug("entered"); 
-}
-
-EventBTOnDiscoveryDevices::~EventBTOnDiscoveryDevices()
-{
-       LogDebug("entered"); 
-}
-
-void EventBTOnDiscoveryDevices::addDevice(BluetoothDeviceData device)
-{
-       m_Devices.push_back(device);
-}
-
-std::vector<BluetoothDeviceData> EventBTOnDiscoveryDevices::getDevices()
-{
-       return m_Devices;
-}
-
-void EventBTOnDiscoveryDevices::setDiscoveryState(DiscoveryStates state)
-{
-       m_discoveryState = state;
-}
-
-}
-}
diff --git a/src/Bluetooth/EventBTOnDiscoveryDevices.h b/src/Bluetooth/EventBTOnDiscoveryDevices.h
deleted file mode 100644 (file)
index 73ad7c1..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_ON_DISCOVERY_DEVICES_H_
-#define TIZENAPIS_API_BLUETOOTH_ON_DISCOVERY_DEVICES_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include <Commons/ListenerEvent.h>
-#include <Commons/ListenerEventEmitter.h>
-#include <dpl/shared_ptr.h>
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTOnDiscoveryDevices : public WrtDeviceApis::Commons::ListenerEvent<EventBTOnDiscoveryDevices>
-{
-public:
-    typedef enum
-    {
-               STARTED,
-               DISCOVERYING,
-               FINISHED
-    } DiscoveryStates;
-private:
-       DiscoveryStates m_discoveryState;
-       std::vector<BluetoothDeviceData> m_Devices;
-public:
-    EventBTOnDiscoveryDevices();
-    ~EventBTOnDiscoveryDevices();
-       void setDiscoveryState(DiscoveryStates state);
-       DiscoveryStates getDiscoveryState() {   return m_discoveryState;}
-       void addDevice(BluetoothDeviceData device);
-       std::vector<BluetoothDeviceData> getDevices();
-};
-
-typedef DPL::SharedPtr<EventBTOnDiscoveryDevices> EventBTOnDiscoveryDevicesPtr;
-typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventBTOnDiscoveryDevices> EventBTOnDiscoveryDevicesEmitter;
-typedef DPL::SharedPtr<EventBTOnDiscoveryDevicesEmitter> EventBTOnDiscoveryDevicesEmitterPtr;
-
-}
-}
-#endif 
diff --git a/src/Bluetooth/EventBTRegisterRFCOMM.h b/src/Bluetooth/EventBTRegisterRFCOMM.h
deleted file mode 100644 (file)
index 0f478f2..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_REGISTER_RFCOMM_H_
-#define TIZENAPIS_API_BLUETOOTH_REGISTER_RFCOMM_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTRegisterRFCOMM :
-    public WrtDeviceApis::Commons::IEvent<EventBTRegisterRFCOMM>
-{
-private:
-       std::string m_uuid;
-       std::string m_name;
-       int m_registerSocket;
-       int m_securityLevel;
-public:
-       EventBTRegisterRFCOMM() { m_uuid = ""; m_registerSocket = -1;}
-       ~EventBTRegisterRFCOMM() {}
-       void setUuid(std::string uuid) { m_uuid = uuid;}
-       void setSocketFd(int registerSocketFd) { m_registerSocket = registerSocketFd;}
-       void setSecurityLevel(int securityLevel) { m_securityLevel = securityLevel;}
-       void setName(std::string name) { m_name = name;}
-       std::string getName() { return m_name;}
-       int getSecurityLevel() { return m_securityLevel; }
-       std::string getUuid() { return m_uuid;}
-       int getSocketFd() { return m_registerSocket;}
-};
-
-typedef DPL::SharedPtr<EventBTRegisterRFCOMM> EventBTRegisterRFCOMMPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/EventBTServiceOnConnect.cpp b/src/Bluetooth/EventBTServiceOnConnect.cpp
deleted file mode 100644 (file)
index d3144cc..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include "EventBTServiceOnConnect.h"
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-EventBTServiceOnConnect::EventBTServiceOnConnect()
-{
-       
-}
-
-EventBTServiceOnConnect::~EventBTServiceOnConnect()
-{
-}
-
-void EventBTServiceOnConnect::setSocketData(BluetoothSocketData socketData) 
-{ 
-       m_socketData = socketData;
-}
-
-BluetoothSocketData EventBTServiceOnConnect::getSocketData() 
-{ 
-       return m_socketData;
-}
-
-
-
-}
-}
-
diff --git a/src/Bluetooth/EventBTServiceOnConnect.h b/src/Bluetooth/EventBTServiceOnConnect.h
deleted file mode 100644 (file)
index 1b0cf31..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_SERVICE_ON_CONNECT_H_
-#define TIZENAPIS_API_BLUETOOTH_SERVICE_ON_CONNECT_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include <Commons/ListenerEvent.h>
-#include <Commons/ListenerEventEmitter.h>
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTServiceOnConnect : public WrtDeviceApis::Commons::ListenerEvent<EventBTServiceOnConnect>
-{
-private:
-       BluetoothSocketData m_socketData;
-public:
-       EventBTServiceOnConnect() {}
-       ~EventBTServiceOnConnect() {} 
-
-       void setSocketData(BluetoothSocketData socketData)
-       { 
-               m_socketData = socketData;
-       }
-       
-       BluetoothSocketData getSocketData()
-       {
-               return m_socketData;
-       }
-
-};
-
-typedef DPL::SharedPtr<EventBTServiceOnConnect> EventBTServiceOnConnectPtr;
-typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventBTServiceOnConnect> EventBTServiceOnConnectEmitter;
-typedef DPL::SharedPtr<EventBTServiceOnConnectEmitter> EventBTServiceOnConnectEmitterPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/EventBTSetPowered.h b/src/Bluetooth/EventBTSetPowered.h
deleted file mode 100644 (file)
index f530e7c..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_SET_POWERED_H_
-#define TIZENAPIS_API_BLUETOOTH_SET_POWERED_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTSetPowered : public WrtDeviceApis::Commons::IEvent<EventBTSetPowered>
-{
-private:
-       bool m_operation;
-       bool m_result;
-       unsigned short m_error;
-public:
-       EventBTSetPowered()
-       {
-               LogDebug("entered");
-               m_operation = false; 
-       }
-
-       ~EventBTSetPowered() { }
-
-       void setEnable() { m_operation = true;}
-       void setDisable() { m_operation = false;}
-       bool isEnableRequested() { return m_operation;}
-};
-
-typedef DPL::SharedPtr<EventBTSetPowered> EventBTSetPoweredPtr;
-
-}
-}
-#endif 
diff --git a/src/Bluetooth/EventBTSetVisible.h b/src/Bluetooth/EventBTSetVisible.h
deleted file mode 100644 (file)
index 5c26dfe..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_SET_VISIBLE_H_
-#define TIZENAPIS_API_BLUETOOTH_SET_VISIBLE_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTSetVisible : public WrtDeviceApis::Commons::IEvent<EventBTSetVisible>
-{
-private:
-       bool m_visible;
-       unsigned short m_timeout;       
-public:
-       EventBTSetVisible() { LogDebug("entered"); m_timeout = 120;}
-       ~EventBTSetVisible() { }
-
-       void setVisible() { m_visible = true;}
-       void setInvisible() { m_visible = false;}
-       void setTimeout(unsigned short timeout) { m_timeout = timeout;}
-       unsigned short getTimeout() { return m_timeout;}
-       bool isVisibleRequested() { return m_visible;}
-
-};
-
-typedef DPL::SharedPtr<EventBTSetVisible> EventBTSetVisiblePtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/EventBTSocketNotification.cpp b/src/Bluetooth/EventBTSocketNotification.cpp
deleted file mode 100644 (file)
index d6c3ed0..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "EventBTSocketNotification.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-EventBTSocketNotification::EventBTSocketNotification() 
-{
-}
-
-EventBTSocketNotification::~EventBTSocketNotification() 
-{
-}
-
-void EventBTSocketNotification::setSocketData(BluetoothSocketData socket) 
-{ 
-       m_socketData = socket;
-}
-
-BluetoothSocketData& EventBTSocketNotification::getSocketData() 
-{ 
-       return m_socketData;
-}
-
-void EventBTSocketNotification::setReadData(char *data, int length) 
-{ 
-/*     Assert(data != NULL);
-       Assert(length != 0);*/
-       
-       for (int i = 0; i < length; i++)
-       {
-               m_readData.push_back(data[i]);
-       }
-}
-
-EventBTReadDataType EventBTSocketNotification::getReadData() 
-{ 
-       return m_readData;
-}
-
-}
-}
-
-
diff --git a/src/Bluetooth/EventBTSocketNotification.h b/src/Bluetooth/EventBTSocketNotification.h
deleted file mode 100644 (file)
index 3c110c0..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_SOCKET_NOTIFICATION_H_
-#define TIZENAPIS_API_BLUETOOTH_SOCKET_NOTIFICATION_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-#include <Commons/ListenerEvent.h>
-#include <Commons/ListenerEventEmitter.h>
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-typedef std::vector<char> EventBTReadDataType;
-
-class EventBTSocketNotification : public WrtDeviceApis::Commons::ListenerEvent<EventBTSocketNotification>
-{
-public :
-       typedef enum 
-       {
-               CONNECTED,
-               DISCONNECTED,
-               DATARECEIVED,
-               SOCKETERROR
-       } EventBTSoncketState;
-
-private:
-       EventBTSoncketState m_State;
-       BluetoothSocketData m_socketData;
-       std::vector<char> m_readData;
-public:
-       EventBTSocketNotification();
-       ~EventBTSocketNotification();
-       void setSocketData(BluetoothSocketData socket);
-       BluetoothSocketData& getSocketData();
-       void setReadData(char* data, int length);
-       EventBTReadDataType getReadData(); 
-       void setConnectionState(EventBTSoncketState state) {m_State = state;}
-       EventBTSoncketState getConnectionState() { return m_State;}
-
-};
-
-typedef DPL::SharedPtr<EventBTSocketNotification> EventBTSocketNotificationPtr;
-typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventBTSocketNotification> EventBTSocketNotificationEmitter;
-typedef DPL::SharedPtr<EventBTSocketNotificationEmitter> EventBTSocketNotificationEmitterPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/EventBTStopDiscovery.h b/src/Bluetooth/EventBTStopDiscovery.h
deleted file mode 100644 (file)
index 97ece66..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_STOP_DISCOVERY_H_
-#define TIZENAPIS_API_BLUETOOTH_STOP_DISCOVERY_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTStopDiscovery : public WrtDeviceApis::Commons::IEvent<EventBTStopDiscovery>
-{
-private:
-public:
-       EventBTStopDiscovery()
-       {
-       }
-
-       ~EventBTStopDiscovery() { }
-};
-
-typedef DPL::SharedPtr<EventBTStopDiscovery> EventBTStopDiscoveryPtr;
-
-}
-}
-#endif 
-
diff --git a/src/Bluetooth/EventBTUnregisterRFCOMM.h b/src/Bluetooth/EventBTUnregisterRFCOMM.h
deleted file mode 100644 (file)
index 7529a51..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_BLUETOOTH_UNREGISTER_RFCOMM_SERVICE_H_
-#define TIZENAPIS_API_BLUETOOTH_UNREGISTER_RFCOMM_SERVICE_H_
-
-#include <Commons/IEvent.h>
-#include <dpl/shared_ptr.h>
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class EventBTUnregisterRFCOMMService : public WrtDeviceApis::Commons::IEvent<EventBTUnregisterRFCOMMService>
-{
-public:
-       EventBTUnregisterRFCOMMService() { }
-       ~EventBTUnregisterRFCOMMService() { }
-};
-
-typedef DPL::SharedPtr<EventBTUnregisterRFCOMMService> EventBTUnregisterRFCOMMServicePtr;
-
-}
-}
-#endif 
-
diff --git a/src/Bluetooth/IBluetoothAdapterManager.cpp b/src/Bluetooth/IBluetoothAdapterManager.cpp
deleted file mode 100644 (file)
index c8d73e6..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "IBluetoothAdapterManager.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-using namespace WrtDeviceApis::Commons;
-IBluetoothAdapterManager::IBluetoothAdapterManager() :
-/*     EventRequestReceiver<EventBTCreateDestroyBonding>(ThreadEnum::BLUETOOTH_THREAD),
-       EventRequestReceiver<EventBTGetKnownDevices>(ThreadEnum::BLUETOOTH_THREAD),
-       EventRequestReceiver<EventBTGetDevice>(ThreadEnum::BLUETOOTH_THREAD),   
-       EventRequestReceiver<EventBTSetPowered>(ThreadEnum::BLUETOOTH_THREAD),
-       EventRequestReceiver<EventBTSetVisible>(ThreadEnum::BLUETOOTH_THREAD),
-       EventRequestReceiver<EventBTSetName>(ThreadEnum::BLUETOOTH_THREAD),
-       EventRequestReceiver<EventBTStopDiscovery>(ThreadEnum::BLUETOOTH_THREAD),
-       EventRequestReceiver<EventBTRegisterRFCOMM>(ThreadEnum::BLUETOOTH_THREAD)*/
-       EventRequestReceiver<EventBTCreateDestroyBonding>(ThreadEnum::NULL_THREAD),
-       EventRequestReceiver<EventBTGetKnownDevices>(ThreadEnum::NULL_THREAD),
-       EventRequestReceiver<EventBTGetDevice>(ThreadEnum::NULL_THREAD),        
-       EventRequestReceiver<EventBTSetPowered>(ThreadEnum::NULL_THREAD),
-       EventRequestReceiver<EventBTSetVisible>(ThreadEnum::NULL_THREAD),
-       EventRequestReceiver<EventBTSetName>(ThreadEnum::NULL_THREAD),
-       EventRequestReceiver<EventBTStopDiscovery>(ThreadEnum::NULL_THREAD),
-       EventRequestReceiver<EventBTRegisterRFCOMM>(ThreadEnum::NULL_THREAD)
-       
-{
-}
-
-IBluetoothAdapterManager::~IBluetoothAdapterManager() {
-}
-
-}
-}
diff --git a/src/Bluetooth/IBluetoothAdapterManager.h b/src/Bluetooth/IBluetoothAdapterManager.h
deleted file mode 100644 (file)
index 87bc017..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_IBLUETOOTH_ADAPTER_MANAGER_H_
-#define TIZENAPIS_API_IBLUETOOTH_ADAPTER_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <Commons/ThreadPool.h>
-#include "EventBTCreateDestroyBonding.h"
-#include "EventBTGetKnownDevices.h"
-#include "EventBTGetDevice.h"
-#include "EventBTSetPowered.h"
-#include "EventBTRegisterRFCOMM.h"
-#include "EventBTSetVisible.h"
-#include "EventBTOnDiscoveryDevices.h"
-#include "EventBTSetName.h"
-#include "EventBTStopDiscovery.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class IBluetoothAdapterManager :
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTCreateDestroyBonding>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTGetKnownDevices>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTGetDevice>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTSetPowered>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTSetVisible>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTSetName>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTStopDiscovery>,
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTRegisterRFCOMM>
-       
-{
-public:
-       virtual ~IBluetoothAdapterManager();
-       virtual void setPowered(const EventBTSetPoweredPtr& event) = 0;
-       virtual void setVisible(const EventBTSetVisiblePtr& event) = 0;
-       virtual void discoveryDevicesEmitter(const EventBTOnDiscoveryDevicesEmitterPtr& emitter) = 0;
-       virtual void getKownDevices(const EventBTGetKnownDevicesPtr& event) = 0;
-       virtual void getDevice(const EventBTGetDevicePtr& event) = 0;
-       virtual void createBonding(const EventBTCreateDestroyBondingPtr& event) = 0;
-       virtual bool createBondingCancel() = 0;
-       virtual void destroyBonding(const EventBTCreateDestroyBondingPtr& event) = 0;
-       virtual void registerRFCOMMServiceByUUID(const EventBTRegisterRFCOMMPtr& event) = 0;
-       virtual void stopDiscovery(const EventBTStopDiscoveryPtr& event) = 0;
-       virtual void setAdapterName(const EventBTSetNamePtr& event) = 0;
-       virtual std::string getName() = 0;
-       virtual std::string getAddress() = 0;
-       virtual bool getPowered() = 0;
-       virtual bool getVisibility() = 0;
-
-protected:
-       IBluetoothAdapterManager();
-
-       virtual void OnRequestReceived(const EventBTCreateDestroyBondingPtr& event) = 0;
-       virtual void OnRequestReceived(const EventBTGetKnownDevicesPtr& event) = 0;
-       virtual void OnRequestReceived(const EventBTGetDevicePtr& event) = 0;
-       virtual void OnRequestReceived(const EventBTSetPoweredPtr& event) = 0;
-       virtual void OnRequestReceived(const EventBTSetVisiblePtr& event) = 0;
-       virtual void OnRequestReceived(const EventBTSetNamePtr& event) = 0;
-       virtual void OnRequestReceived(const EventBTStopDiscoveryPtr& event) = 0;       
-       virtual void OnRequestReceived(const EventBTRegisterRFCOMMPtr& event) = 0;      
-};
-
-typedef DPL::SharedPtr<IBluetoothAdapterManager> IBluetoothAdapterManagerPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/IBluetoothDeviceManager.cpp b/src/Bluetooth/IBluetoothDeviceManager.cpp
deleted file mode 100644 (file)
index faca0a6..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "IBluetoothDeviceManager.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-using namespace WrtDeviceApis::Commons;
-
-IBluetoothDeviceManager::IBluetoothDeviceManager() :
-//     EventRequestReceiver<EventBTConnectToServiceByUUID>(ThreadEnum::BLUETOOTH_THREAD)
-       EventRequestReceiver<EventBTConnectToServiceByUUID>(ThreadEnum::NULL_THREAD)
-
-{
-}
-
-IBluetoothDeviceManager::~IBluetoothDeviceManager() {
-}
-
-}
-}
-
diff --git a/src/Bluetooth/IBluetoothDeviceManager.h b/src/Bluetooth/IBluetoothDeviceManager.h
deleted file mode 100644 (file)
index b21d98c..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_IBLUETOOTH_DEVICE_MANAGER_H_
-#define TIZENAPIS_API_IBLUETOOTH_DEVICE_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <Commons/ThreadPool.h>
-#include"EventBTConnectToServiceByUUID.h"
-#include "BTDevice.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-
-class IBluetoothDeviceManager :
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTConnectToServiceByUUID>
-{
-public:
-       virtual ~IBluetoothDeviceManager();
-       virtual void connectToServiceByUUID(const EventBTConnectToServiceByUUIDPtr& event) = 0;
-
-       virtual void setNameProperty(const std::string name) = 0;
-       virtual void setAddressProperty(const std::string address) = 0;
-       virtual void setBondProperty(const bool bonded) = 0;
-       virtual void setTrustProperty(const bool trused) = 0;
-       virtual void setConnectProperty(const bool connected) = 0;
-       virtual void setUuidsProperty(const std::vector<std::string> uuids) = 0;
-       virtual void cancelConnectToServiceByUUID() = 0;
-       
-       virtual std::string getNameProperty(void) = 0;
-       virtual std::string getAddressProperty(void) = 0;
-       virtual bool getBondProperty(void) = 0;
-       virtual bool getTrustProperty(void) = 0;
-       virtual bool getConnectProperty(void) = 0;
-       virtual std::vector<std::string> getUuidsProperty(void) = 0;
-       virtual void setDevice(const BluetoothDeviceData device) = 0;
-       virtual BluetoothDeviceDataClass getClass() = 0;
-protected:
-       IBluetoothDeviceManager();
-       virtual void OnRequestReceived(const EventBTConnectToServiceByUUIDPtr& event) = 0;
-};
-
-typedef DPL::SharedPtr<IBluetoothDeviceManager> IBluetoothDeviceManagerPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Bluetooth/IBluetoothServiceHandlerManager.cpp b/src/Bluetooth/IBluetoothServiceHandlerManager.cpp
deleted file mode 100644 (file)
index 334892b..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "IBluetoothServiceHandlerManager.h"
-
-using namespace WrtDeviceApis::Commons;
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-
-IBluetoothServiceHandlerManager::IBluetoothServiceHandlerManager() :
-//     EventRequestReceiver<EventBTUnregisterRFCOMMService>(ThreadEnum::BLUETOOTH_THREAD)
-       EventRequestReceiver<EventBTUnregisterRFCOMMService>(ThreadEnum::NULL_THREAD)
-{
-}
-
-IBluetoothServiceHandlerManager::~IBluetoothServiceHandlerManager() {
-}
-
-}
-}
-
diff --git a/src/Bluetooth/IBluetoothServiceHandlerManager.h b/src/Bluetooth/IBluetoothServiceHandlerManager.h
deleted file mode 100644 (file)
index a6cfa91..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_IBLUETOOTH_SERVICE_HANDLER_MANAGER_H_
-#define TIZENAPIS_API_IBLUETOOTH_SERVICE_HANDLER_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <Commons/ThreadPool.h>
-#include "EventBTUnregisterRFCOMM.h"
-#include "EventBTServiceOnConnect.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class IBluetoothServiceHandlerManager :
-       public WrtDeviceApis::Commons::EventRequestReceiver<EventBTUnregisterRFCOMMService>
-{
-public:
-       virtual ~IBluetoothServiceHandlerManager();
-       virtual void unRegister(const EventBTUnregisterRFCOMMServicePtr &event) = 0;
-       virtual void setServiceHandlerListener(const EventBTServiceOnConnectEmitterPtr& emitter) = 0;
-       virtual EventBTServiceOnConnectEmitterPtr getServiceHandlerListener() = 0;
-       virtual void setUUID(std::string uuid) = 0;
-       virtual std::string getUUID() = 0;
-       virtual void setRegisterSocket(int socket) = 0;
-       virtual void setName(std::string name) = 0;
-       virtual void setIsConnected(bool connected) = 0;
-       virtual std::string getName() = 0;
-       virtual bool getIsConnected() = 0;
-protected:
-       IBluetoothServiceHandlerManager();
-       virtual void OnRequestReceived(const EventBTUnregisterRFCOMMServicePtr& event) = 0;     
-};
-
-typedef DPL::SharedPtr<IBluetoothServiceHandlerManager> IBluetoothServiceHandlerManagerPtr;
-
-}
-}
-#endif
diff --git a/src/Bluetooth/IBluetoothSocketManager.cpp b/src/Bluetooth/IBluetoothSocketManager.cpp
deleted file mode 100644 (file)
index 203d179..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "IBluetoothSocketManager.h"
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-
-IBluetoothSocketManager::IBluetoothSocketManager()
-{
-}
-
-IBluetoothSocketManager::~IBluetoothSocketManager() {
-}
-
-}
-}
-
diff --git a/src/Bluetooth/IBluetoothSocketManager.h b/src/Bluetooth/IBluetoothSocketManager.h
deleted file mode 100644 (file)
index 35a17fd..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_IBLUETOOTH_SOCKET_MANAGER_H_
-#define TIZENAPIS_API_IBLUETOOTH_SOCKET_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <Commons/ThreadPool.h>
-#include "BTDevice.h"
-#include "EventBTSocketNotification.h"
-
-
-namespace DeviceAPI {
-namespace Bluetooth {
-
-class IBluetoothSocketManager 
-{
-public:
-       virtual ~IBluetoothSocketManager();
-       virtual std::string getUUID() = 0;
-       virtual unsigned int getProtocol() = 0;
-       virtual unsigned int getState() = 0;
-       virtual BluetoothDeviceData getPeer() = 0;
-       virtual int setSocketNotifier(EventBTSocketNotificationEmitterPtr emitter) = 0;
-       virtual EventBTSocketNotificationEmitterPtr getSocketNotifier() = 0;
-       virtual int writeData(const char *data, const unsigned int length) = 0;
-       virtual EventBTReadDataType readData() = 0;
-       virtual int close() = 0;
-       virtual void setSocketData(BluetoothSocketData socketData) = 0;
-       virtual void setReadData(EventBTReadDataType readData) = 0;
-protected:
-       IBluetoothSocketManager();
-};
-
-typedef DPL::SharedPtr<IBluetoothSocketManager> IBluetoothSocketManagerPtr;
-
-}
-}
-#endif
index 01fffb2..87a2eb7 100644 (file)
 // limitations under the License.
 //
 
-
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
 #include <SecurityExceptions.h>
-#include <Commons/Exception.h>
-#include "JSBluetoothAdapter.h"
-#include "IBluetoothAdapterManager.h"
-#include "BluetoothFactory.h"
-#include "BluetoothProperty.h"
-#include "BluetoothAdapterListener.h"
-#include "BluetoothMultiCallback.h"
-#include "BluetoothConverter.h"
+
+#include <JSUtil.h>
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+
 #include "plugin_config.h"
+#include "JSBluetoothAdapter.h"
+#include "BluetoothAdapter.h"
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::CommonsJavaScript;
-using namespace DeviceAPI::Common;
+#include <Logger.h>
 
+using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassRef JSBluetoothAdapter::m_jsClassRef = NULL;
-
-JSClassDefinition JSBluetoothAdapter::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothAdapter",
-       NULL,
-       m_properties,
-       m_function,
-       initialize,
-       finalize,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSBluetoothAdapter::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothAdapter",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    m_function, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-JSStaticFunction JSBluetoothAdapter::m_function[] =
-{
-       { "setPowered", JSBluetoothAdapter::setPowered, kJSPropertyAttributeNone },
-       { "setVisible", JSBluetoothAdapter::setVisible, kJSPropertyAttributeNone },
-       { "setName", JSBluetoothAdapter::setName, kJSPropertyAttributeNone },   
-       { "discoverDevices", JSBluetoothAdapter::discoveryDevices, kJSPropertyAttributeNone },
-       { "stopDiscovery", JSBluetoothAdapter::stopDiscovery, kJSPropertyAttributeNone },
-       { "getKnownDevices", JSBluetoothAdapter::getKnownDevices, kJSPropertyAttributeNone },
-       { "getDevice", JSBluetoothAdapter::getDevice, kJSPropertyAttributeNone },
-       { "createBonding", JSBluetoothAdapter::createBonding, kJSPropertyAttributeNone },
-       { "destroyBonding", JSBluetoothAdapter::destroyBonding, kJSPropertyAttributeNone },
-       { "registerRFCOMMServiceByUUID", JSBluetoothAdapter::registerRFCOMMServiceByUUID, kJSPropertyAttributeNone },   
-       { 0, 0, 0 }
+JSStaticValue JSBluetoothAdapter::m_property[] = {
+    { BLUETOOTH_ADAPTER_NAME, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_ADAPTER_POWERED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_ADAPTER_VISIBLE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_ADAPTER_ADDRESS, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { 0, 0, 0, 0 }
 };
 
-JSStaticValue JSBluetoothAdapter::m_properties[] = {
-       {"address", getAddress, NULL, kJSPropertyAttributeReadOnly},
-       {"name", getName, NULL, kJSPropertyAttributeReadOnly},
-       {"powered", getPowered, NULL, kJSPropertyAttributeReadOnly},            
-       {"visible", getVisible, NULL, kJSPropertyAttributeReadOnly},            
-
-       {0, 0, 0, 0}
+JSStaticFunction JSBluetoothAdapter::m_function[] = {
+    { BLUETOOTH_ADAPTER_API_SET_NAME, setName, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_SET_POWERED, setPowered, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_SET_VISIBLE, setVisible, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES, discoverDevices, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_STOP_DISCOVERY, stopDiscovery, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES, getKnownDevices, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_GET_DEVICE, getDevice, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_CREATE_BONDING, createBonding, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_DESTROY_BONDING, destroyBonding, kJSPropertyAttributeNone },
+    { BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID, registerRFCOMMServiceByUUID, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
 };
 
-JSValueRef JSBluetoothAdapter::getName(JSContextRef context,
-                                                                       JSObjectRef object,
-                                                                       JSStringRef propertyName,
-                                                                       JSValueRef* exception)
-{
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-                       
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               std::string name = BluetoothAdapterManager->getName();
-               return converter.toJSValueRef(name);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-
-       return NULL;
-}
-
-JSValueRef JSBluetoothAdapter::setName(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("Enter");      
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-       JSValueRef reserveArguments[3];
-       size_t index = 0;
-               
-       Try 
-       {
-               for (index = 0; index < 3; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);
-                               
-               }
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_SET_NAME]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               BluetoothConverter converter(priv->getContext());
-
-               successCallback = converter.toFunctionOrNull(reserveArguments[1]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
-
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);
-               }
-
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-               
-               
-
-               
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               std::string name = converter.toString(reserveArguments[0]);
-
-
-               if (name != BluetoothAdapterManager->getName())
-               {
-                       EventBTSetNamePtr event(new EventBTSetName);
-                       
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-                       BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-                       event->setForAsynchronousCall(&listener);
-                       event->setName(name);
-                       BluetoothAdapterManager->setAdapterName(event);
-               }
-               else
-               {
-                       LogDebug("same name is already set");
-                       cbm->callOnSuccess();
-               }
-       }       
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-               
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }       
-       
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("UnkownException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "Unkown error");
-       }
-       return JSValueMakeUndefined(context);
-}
-
+JSClassRef JSBluetoothAdapter::m_jsClassRef = JSClassCreate(JSBluetoothAdapter::getClassInfo());
 
-JSValueRef JSBluetoothAdapter::getAddress(JSContextRef context,
-                                                               JSObjectRef object,
-                                                               JSStringRef propertyName,
-                                                               JSValueRef* exception)
+const JSClassRef JSBluetoothAdapter::getClassRef()
 {
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               std::string address = BluetoothAdapterManager->getAddress();
-               return converter.toJSValueRef(address);
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return NULL;
-
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-
-JSValueRef JSBluetoothAdapter::getVisible(JSContextRef context,
-                                                                       JSObjectRef object,
-                                                                       JSStringRef propertyName,
-                                                                       JSValueRef* exception)
+const JSClassDefinition* JSBluetoothAdapter::getClassInfo()
 {
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(object));
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               bool visibility = BluetoothAdapterManager->getVisibility();
-               return converter.toJSValueRef(visibility);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-
-       return NULL;
-
+    return &m_classInfo;
 }
 
-
-
-const JSClassRef JSBluetoothAdapter::getClassRef() 
+JSObjectRef JSBluetoothAdapter::createJSObject(JSContextRef context)
 {
-       if (!m_jsClassRef) 
-       {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
+    return JSObjectMake(context, getClassRef(), NULL);
 }
 
-const JSClassDefinition* JSBluetoothAdapter::getClassInfo() 
+void JSBluetoothAdapter::initialize(JSContextRef context, JSObjectRef object)
 {
-       return &m_classInfo;
+    // do nothing
+    LogDebug("Enter");
 }
 
 
-void JSBluetoothAdapter::initialize(JSContextRef context, JSObjectRef object) 
+void JSBluetoothAdapter::finalize(JSObjectRef object)
 {
-       JSBluetoothAdapterPriv* priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(object));
-
-       if (priv != NULL)
-       {
-               LogDebug("Already Exist");
-       }
-       else
-       {
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(BluetoothFactory::getInstance().getBluetoothAdapterManager());
-               priv = new JSBluetoothAdapterPriv( context, BluetoothAdapterManager);
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-               LogDebug("JSBluetoothAdapter::initialize ");
-       }
+    // do nothing
+    LogDebug("Enter");
 }
 
-void JSBluetoothAdapter::finalize(JSObjectRef object) 
+JSValueRef JSBluetoothAdapter::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-       LogDebug("JSBluetoothAdapter::Finalrize");
-
-       JSBluetoothAdapterPriv* priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(object));
-
-       if (priv != NULL)
-       {
-               JSObjectSetPrivate(object, NULL);
-               LogDebug("Deleting BluetoothAdapterManager");
-               delete priv;
-       }
-
-
+    LogDebug("Enter");
+    try {
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_ADAPTER_NAME)) {
+            std::string name = BluetoothAdapter::getInstance()->getName();
+            LogDebug("name: " << name);
+            return JSUtil::toJSValueRef(context, name);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_ADAPTER_POWERED)) {
+            return JSUtil::toJSValueRef(context, BluetoothAdapter::getInstance()->getPowered());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_ADAPTER_VISIBLE)) {
+            return JSUtil::toJSValueRef(context, BluetoothAdapter::getInstance()->getVisible());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_ADDRESS)) {
+            std::string address = BluetoothAdapter::getInstance()->getAddress();
+            LogDebug("address: " << address);
+            return JSUtil::toJSValueRef(context, address);
+        }
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed" << err.getMessage().c_str());
+    }
+
+    return NULL;
 }
 
-bool JSBluetoothAdapter::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::setName(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    LogDebug("Entered");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_SET_NAME);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        ArgumentValidator validator(context, argumentCount, arguments);        
+        std::string name = validator.toString(0);  // name
+        JSObjectRef successCallback = validator.toFunction(1, true);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(2, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->setName(name, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setName().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-
-JSObjectRef JSBluetoothAdapter::createJSObject(JSContextRef context)
+JSValueRef JSBluetoothAdapter::setPowered(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       IBluetoothAdapterManagerPtr BluetoothAdapterManager(BluetoothFactory::getInstance().getBluetoothAdapterManager());
-       JSBluetoothAdapterPriv* priv = new JSBluetoothAdapterPriv( context, BluetoothAdapterManager);
-
-       return JSObjectMake(context, getClassRef(), priv);
-
+    LogDebug("Entered");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_SET_POWERED);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        bool state = validator.toBool(0);  // state
+        JSObjectRef successCallback = validator.toFunction(1, true);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(2, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->setPowered(state, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setPowered().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSBluetoothAdapter::getPowered(JSContextRef context,
-                                                                       JSObjectRef object,
-                                                                       JSStringRef propertyName,
-                                                                       JSValueRef* exception)
-
+JSValueRef JSBluetoothAdapter::setVisible(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               bool powered = BluetoothAdapterManager->getPowered();
-               return converter.toJSValueRef(powered);
-       }       
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-
-       return NULL;
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_SET_VISIBLE);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {    
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+        
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        bool mode = validator.toBool(0);  // mode
+        JSObjectRef successCallback = validator.toFunction(1, true);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(2, true);  // errorCallback
+        unsigned long timeout = validator.toULong(3, true);  // timeout 
+        if(timeout > 65535)
+            timeout = 180;
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->setVisible(mode, timeout, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setVisible().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-
-JSValueRef JSBluetoothAdapter::setPowered(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::discoverDevices(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-
-       LogDebug("setPowered");
-
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       size_t index = 0;
-       JSValueRef reserveArguments[3];
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-       
-       Try     
-       {
-               for (index = 0; index < 3; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);
-               }
-
-               LogDebug(bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_SET_POWERED]);
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_SET_POWERED]);
-               
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               BluetoothConverter converter(priv->getContext());
-
-               successCallback = converter.toFunctionOrNull(reserveArguments[1]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
-
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-
-       
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTSetPoweredPtr event(new EventBTSetPowered);
-
-               if (BluetoothAdapterManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-
-               bool powered = BluetoothAdapterManager->getPowered();
-               LogDebug(converter.toBool(reserveArguments[0]) << converter.toString(reserveArguments[0]));
-               
-               if (converter.toBool(reserveArguments[0]) == true)
-               {
-                       if (powered)
-                       {
-                               LogDebug("Already powered");
-                               cbm->callOnSuccess();
-                               return JSValueMakeUndefined(context);
-                       }
-                       else
-                       {
-                               event->setEnable();
-                       }
-               }
-               else
-               {
-                       if (powered == false)
-                       {
-                               LogDebug("Already power off");
-                               cbm->callOnSuccess();
-                               return JSValueMakeUndefined(context);
-                       }
-                       else
-                       {
-                               event->setDisable();
-                       }
-               }
-               
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-               event->setForAsynchronousCall(&listener);
-               BluetoothAdapterManager->setPowered(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-       }
-       return JSValueMakeUndefined(context);
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {    
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiMultiCallbackUserData");
+        }
+
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // successCallback
+        JSObjectRef successCallback = validator.toCallbackObject(0, false, "onstarted", "ondevicefound", "ondevicedisappeared", "onfinished", NULL);
+
+        // onstarted
+        JSValueRef onstartedValue = JSUtil::getProperty(context , successCallback, "onstarted");
+        if(!JSValueIsUndefined(context, onstartedValue)) {
+            LogDebug("There is a onstarted()");
+            callback->setCallback("onstarted", JSUtil::JSValueToObject(context, onstartedValue));
+        }
+
+        // ondevicefound
+        JSValueRef ondevicefoundValue = JSUtil::getProperty(context , successCallback, "ondevicefound");
+        if(!JSValueIsUndefined(context, ondevicefoundValue)) {
+            LogDebug("There is a ondevicefound()");
+            callback->setCallback("ondevicefound", JSUtil::JSValueToObject(context, ondevicefoundValue));
+        }
+        
+        // ondevicedisappeared
+        JSValueRef ondevicedisappearedValue = JSUtil::getProperty(context , successCallback, "ondevicedisappeared");
+        if(!JSValueIsUndefined(context, ondevicedisappearedValue)) {
+            LogDebug("There is a ondevicedisappeared()");
+            callback->setCallback("ondevicedisappeared", JSUtil::JSValueToObject(context, ondevicedisappearedValue));
+        }
+
+        // onfinished
+        JSValueRef onfinishedValue = JSUtil::getProperty(context , successCallback, "onfinished");
+        if(!JSValueIsUndefined(context, onfinishedValue)) {
+            LogDebug("There is a onfinished()");
+            callback->setCallback("onfinished", JSUtil::JSValueToObject(context, onfinishedValue));
+        }      
+
+        // errorCallback
+        JSObjectRef errorCallback = validator.toFunction(1, true);
+        callback->setCallback("error", errorCallback);
+
+        // perform       
+        BluetoothAdapter::getInstance()->discoverDevices(callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.discoverDevices().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSBluetoothAdapter::setVisible(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::stopDiscovery(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("setVisible");
-
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       size_t index = 0;
-       JSValueRef reserveArguments[4];
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-
-       Try     
-       {
-               for (index = 0; index < 4; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
-
-               }
-
-               LogDebug("check ace");
-                
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_SET_VISIBLE]);
-               
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               
-               BluetoothConverter converter(priv->getContext());
-
-               successCallback = converter.toFunctionOrNull(reserveArguments[1]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
-               
-
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTSetVisiblePtr event(new EventBTSetVisible);
-
-               if (BluetoothAdapterManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-
-               if (converter.toBool(reserveArguments[0]) == true)
-               {
-                       event->setVisible();
-               }
-               else
-               {
-                       event->setInvisible();
-               }
-
-               if (argumentCount == 4)
-               {
-                       if (JSValueIsUndefined(context, reserveArguments[3]) == true || JSValueIsNull(context, reserveArguments[3]) == true)
-                       {
-                               event->setTimeout(0);
-                       }
-                       else
-                       {
-                               if (JSValueIsNumber(context, reserveArguments[3]) == false) 
-                               {
-                                       LogError("Wrong parameter passed");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       LogDebug("timeout " << (short)converter.toInt(reserveArguments[3]));
-                       short timeout = (short)converter.toInt(reserveArguments[3]);
-
-                       if (timeout < 0) 
-                       {
-                               LogError("Wrong parameter passed, timemut should be > 0");
-                               Throw(ConversionException);
-                       }
-                       event->setTimeout((unsigned short)converter.toInt(reserveArguments[3]));
-               }
-               else
-               {
-                       event->setTimeout(0);
-               }
-       
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-               event->setForAsynchronousCall(&listener);
-               BluetoothAdapterManager->setVisible(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-
-       }
-       return JSValueMakeUndefined(context);
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_STOP_DISCOVERY);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+        
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        JSObjectRef successCallback = validator.toFunction(0, true);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(1, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->stopDiscovery(callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.stopDiscovery().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSBluetoothAdapter::discoveryDevices(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::getKnownDevices(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("discoveryDevices");
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       size_t index = 0;
-       JSValueRef reserveArguments[2];
-       JSValueRef errorArgument = JSValueMakeNull(context);
-       
-       Try     
-       {
-               for (index = 0; index < 2; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
-
-               }
-
-               if (priv == NULL)
-               {
-                       LogError("priv null");
-                       Throw(ConversionException);     
-               }
-               
-               LogDebug(bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_DISCOVER_DEVICES]);
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_DISCOVER_DEVICES]);
-               
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-
-               if (argumentCount >= 2 && JSValueIsUndefined(context, reserveArguments[1]) == false)
-               {
-                       errorArgument = reserveArguments[1];
-               }
-
-               BluetoothConverter converter(priv->getContext());
-               EventBTOnDiscoveryDevicesPrivateDataPtr privData(
-                       converter.toEventBTOnDiscoveryDevicesPrivateData(thisObject, reserveArguments[0], errorArgument));
-               
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTOnDiscoveryDevicesEmitterPtr emitter(new EventBTOnDiscoveryDevicesEmitter);
-
-               if (BluetoothAdapterManager == NULL || emitter == NULL || privData == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-               emitter->setListener(&BluetoothAdapterListener::getInstance());
-               emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
-               BluetoothAdapterManager->discoveryDevicesEmitter(emitter);
-       }       
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-       }
-       return JSValueMakeUndefined(context);
-
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+        
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        JSObjectRef successCallback = validator.toFunction(0);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(1, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->getKnownDevices(callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.getKnownDevices().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSBluetoothAdapter::stopDiscovery(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::getDevice(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("discoveryDevices");
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       size_t index = 0;
-       JSValueRef reserveArguments[2];
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-
-       Try     
-       {
-               for (index = 0; index < 2; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
-
-               }
-                       
-               LogDebug(bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_STOP_DISCOVERY]);
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_STOP_DISCOVERY]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               BluetoothConverter converter(priv->getContext());
-
-               if (argumentCount >= 1 && JSValueIsUndefined(context, reserveArguments[0]) == false)
-               {
-                       successCallback = converter.toFunctionOrNull(reserveArguments[0]);
-               }
-               
-               if (argumentCount >= 2 && JSValueIsUndefined(context, reserveArguments[1]) == false)
-               {
-                       errorCallBack = converter.toFunctionOrNull(reserveArguments[1]);
-               }
-
-               
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-                       
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTStopDiscoveryPtr  event(new EventBTStopDiscovery);
-               
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-               event->setForAsynchronousCall(&listener);
-               BluetoothAdapterManager->stopDiscovery(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-
-       }
-       
-       return JSValueMakeUndefined(context);
-
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_GET_DEVICE);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+        
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        std::string address = validator.toString(0);  // address
+        JSObjectRef successCallback = validator.toFunction(1);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(2, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->getDevice(address, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.getDevice().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-
-JSValueRef JSBluetoothAdapter::getKnownDevices(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::createBonding(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("getKnownDevices");
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-       size_t index = 0;
-       JSValueRef reserveArguments[2];
-       
-       Try     
-       {
-               for (index = 0; index < 2; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
-
-               }
-               
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_GET_KNOWN_DEVICES]);
-               
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               BluetoothConverter converter(priv->getContext());
-               successCallback = converter.toFunction(reserveArguments[0]);
-               
-               if (argumentCount >= 2 && JSValueIsUndefined(context, reserveArguments[1]) == false)
-               {
-                       errorCallBack = converter.toFunctionOrNull(reserveArguments[1]);
-               }
-
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-                       
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTGetKnownDevicesPtr event(new EventBTGetKnownDevices);
-
-
-               if (BluetoothAdapterManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-               event->setForAsynchronousCall(&listener);
-               BluetoothAdapterManager->getKownDevices(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-
-       }
-       return JSValueMakeUndefined(context);
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_CREATE_BONDING);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+        
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        std::string address = validator.toString(0);  // address
+        JSObjectRef successCallback = validator.toFunction(1);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(2, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->createBonding(address, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.createBonding().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSBluetoothAdapter::getDevice(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
-{
-       LogDebug("Enter");
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       size_t index = 0;
-       JSValueRef reserveArguments[3];
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-
-       Try     
-       {
-               for (index = 0; index < 3; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
-
-               }
-               
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_GET_DEVICE]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               
-               BluetoothConverter converter(priv->getContext());
-               successCallback = converter.toFunction(reserveArguments[1]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
-
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-               std::string address = converter.toBluetoothDeviceAddress(reserveArguments[0]);
-       
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTGetDevicePtr event(new EventBTGetDevice);
-
-               if (BluetoothAdapterManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-               
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-               event->setForAsynchronousCall(&listener);
-               event->setAddress(address);
-               BluetoothAdapterManager->getDevice(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-
-       }
-
-       return JSValueMakeUndefined(context);}
-
-
-JSValueRef JSBluetoothAdapter::createBonding(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::destroyBonding(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("createBonding");
-
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       size_t index = 0; 
-       JSValueRef reserveArguments[3];
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-
-       Try     
-       {
-
-               for (index = 0; index < 3; index++)
-               {
-
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
-               }
-  
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADPATER_CREATE_BONDING]);
-
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               BluetoothConverter converter(priv->getContext());
-               successCallback = converter.toFunction(reserveArguments[1]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
-
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-                       
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-               std::string address = converter.toBluetoothDeviceAddress(reserveArguments[0]);
-
-
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTCreateDestroyBondingPtr event(new EventBTCreateDestroyBonding);
-
-               if (BluetoothAdapterManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-               BluetoothCreateBondingPrivateDataPtr privData(new BluetoothCreateBondingPrivateData(cbm, thisObject));
-
-//             event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (privData));
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-               event->setForAsynchronousCall(&listener);
-               event->setAddress(address);
-               event->setCreateBonding();
-               BluetoothAdapterManager->createBonding(event);
-               // temporarily remove pending operation
-//             JSValueRef pendingOperation = makePendingOperation(context, event);
-                       //JSBluetoothDummyPendingOperation::createJSObject(context);
-       //      return pendingOperation;
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-
-       }       
-       return JSValueMakeUndefined(context);
-
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_DESTROY_BONDING);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+        
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        std::string address = validator.toString(0);  // address
+        JSObjectRef successCallback = validator.toFunction(1, true);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(2, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->destroyBonding(address, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.destroyBonding().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSBluetoothAdapter::destroyBonding(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothAdapter::registerRFCOMMServiceByUUID(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-
-       LogDebug("destroyBonding");
-
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       size_t index = 0;
-       JSValueRef reserveArguments[3];
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-       
-       Try     
-       {
-               for (index = 0; index < 3; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                
-               }
-               
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADPATER_DESTROY_BONDING]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               BluetoothConverter converter(priv->getContext());
-               successCallback = converter.toFunctionOrNull(reserveArguments[1]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
-               
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-                       
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-               std::string address = converter.toBluetoothDeviceAddress(reserveArguments[0]);
-               
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTCreateDestroyBondingPtr event(new EventBTCreateDestroyBonding);
-               
-               if (BluetoothAdapterManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();           
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               event->setForAsynchronousCall(&listener);
-               event->setDestroyBonding();
-               event->setAddress(address);
-               BluetoothAdapterManager->destroyBonding(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-
-       }       
-       
-       return JSValueMakeUndefined(context);
+    LogDebug("Entered");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+        
+        // Validate arguments
+        ArgumentValidator validator(context, argumentCount, arguments);
+        std::string uuid = validator.toString(0);  // uuid
+        std::string name = validator.toString(1);  // name
+        JSObjectRef successCallback = validator.toFunction(2);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(3, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->registerRFCOMMServiceByUUID(uuid, name, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.registerRFCOMMServiceByUUID().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
-JSValueRef JSBluetoothAdapter::registerRFCOMMServiceByUUID(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
-{
-       LogDebug("registerRFCOMMServiceByUUID");
-
-       JSBluetoothAdapterPriv *priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(thisObject));    
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-       size_t index = 0;
-       JSValueRef reserveArguments[4];
-
-       Try     
-       {
-               for (index = 0; index < 4; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                
-               }
-                       
-               std::string serviceName, uuid;
-               unsigned short securityLevel= SECURITY_LEVEL_HIGH_VALUE_INT;
-               Validator validator(context);           
-               
-               LogDebug("context address" << context << "priv-context" << priv->getContext());
-                               
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADPATER_REGISTER_RFCOMM]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               BluetoothConverter converter(priv->getContext());
-               successCallback = converter.toFunction(reserveArguments[2]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[3]);
-
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-
-               uuid = converter.toBluetoothUUIDString(reserveArguments[0]);
-               serviceName = converter.toString(reserveArguments[1]);
-
-               
-               /*if (argumentCount >= 5)
-               {
-                       securityLevel = converter.toBluetoothSecurityLevelInt(reserveArguments[4]);
-               }*/
-       
-               
-               
-               IBluetoothAdapterManagerPtr BluetoothAdapterManager(priv->getObject());
-               EventBTRegisterRFCOMMPtr event(new EventBTRegisterRFCOMM);
-
-               if (BluetoothAdapterManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-               LogDebug("UUid:" << uuid << " serviceName:" << serviceName);
-
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();           
-               event->setForAsynchronousCall(&listener);
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               event->setUuid(uuid);
-               event->setSecurityLevel(securityLevel); 
-               event->setName(serviceName);
-               BluetoothAdapterManager->registerRFCOMMServiceByUUID(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "blueetooth device busy"));            
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("AlreadyInUseException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-
-       }       
-       return JSValueMakeUndefined(context);
-
-}
-
-
-}
-}
+} // Bluetooth
+} // DeviceAPI
index 1123524..161892b 100644 (file)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_ADAPTER_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_ADAPTER_H_
+#ifndef __TIZEN_JS_BLUETOOTH_ADAPTER_H__
+#define __TIZEN_JS_BLUETOOTH_ADAPTER_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "IBluetoothAdapterManager.h"
-#include <Commons/IEvent.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-
-using namespace WrtDeviceApis::CommonsJavaScript;
-using namespace WrtDeviceApis::Commons;
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef PrivateObjectT<IBluetoothAdapterManagerPtr>::Type JSBluetoothAdapterPriv;
-
-class BluetoothCreateBondingPrivateData : public IEventPrivateData
+class JSBluetoothAdapter
 {
-public :
-       BluetoothCreateBondingPrivateData(const JSCallbackManagerPtr &callbackManager,
-               JSObjectRef object) : 
-               m_callbackManager(callbackManager),
-               m_object(object) {}
-
-       virtual ~BluetoothCreateBondingPrivateData() {}
-
-       JSCallbackManagerPtr getCallbackManager() const {return m_callbackManager;}
-       JSObjectRef getObject() const {return m_object;};
-private:
-       JSCallbackManagerPtr m_callbackManager;
-       JSObjectRef m_object;
-};
-
-typedef DPL::SharedPtr<BluetoothCreateBondingPrivateData> BluetoothCreateBondingPrivateDataPtr;
-
-
-class JSBluetoothAdapter {
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static JSObjectRef createJSObject(JSContextRef context);
-private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-       JSValueRef possibleInstance, JSValueRef* exception);
-
-       static JSValueRef setPowered(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSValueRef getPowered(
-               JSContextRef context, JSObjectRef object,
-               JSStringRef propertyName, JSValueRef* exception);
-
-       static JSValueRef setVisible(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSValueRef getVisible(
-               JSContextRef context, JSObjectRef object,
-               JSStringRef propertyName, JSValueRef* exception);
-
-       static JSValueRef setName(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-       
-       static JSValueRef getName(
-               JSContextRef context, JSObjectRef object,
-               JSStringRef propertyName, JSValueRef* exception);
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context);
 
-       
-
-       static JSValueRef discoveryDevices(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSValueRef stopDiscovery(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-
-       static JSValueRef getKnownDevices(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-
-       static JSValueRef getDevice(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-
-       static JSValueRef createBonding(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSValueRef destroyBonding(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSValueRef registerRFCOMMServiceByUUID(
-               JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSValueRef getAddress(
-               JSContextRef context, JSObjectRef object, 
-               JSStringRef propertyName, JSValueRef* exception);
-
-       static JSClassDefinition m_classInfo;
-
-       static JSStaticFunction m_function[];
-       static JSStaticValue m_properties[];
+private:
 
-       static JSClassRef m_jsClassRef;
-       static bool m_AdapterEnabled;
+    /**
+     * 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);
+    
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef setName(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef setPowered(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef setVisible(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef discoverDevices(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef stopDiscovery(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef getKnownDevices(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef getDevice(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef createBonding(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef destroyBonding(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef registerRFCOMMServiceByUUID(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_function[];
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-}
-}
 
-#endif
 
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index 5219df3..cea1f40 100644 (file)
 // limitations under the License.
 //
 
-
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
 #include <SecurityExceptions.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "JSBluetoothClass.h"
+
+#include <JSUtil.h>
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <PlatformException.h>
+
 #include "plugin_config.h"
 
+#include "JSBluetoothClass.h"
+#include "BluetoothAdapter.h"
+
+#include <Logger.h>
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassDefinition JSBluetoothClass::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothClass",
-       NULL,
-       m_properties,
-       m_function,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSBluetoothClass::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothClass",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    m_function, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-       
-JSStaticFunction JSBluetoothClass::m_function[] =
-{
-       { "hasService", JSBluetoothClass::hasService, kJSPropertyAttributeNone },
-
-       { 0, 0, 0 }
+JSStaticValue JSBluetoothClass::m_property[] = {
+    { BLUETOOTH_CLASS_MAJOR, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_CLASS_MINOR, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_CLASS_SERVICES, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { 0, 0, 0, 0 }
 };
 
-
-JSStaticValue JSBluetoothClass::m_properties[] = 
-{
-       {"major", JSBluetoothClass::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"minor", JSBluetoothClass::getProperty, NULL, kJSPropertyAttributeReadOnly },  
-       {"services", JSBluetoothClass::getProperty, NULL, kJSPropertyAttributeReadOnly },       
-       {0, 0, 0, 0}
+JSStaticFunction JSBluetoothClass::m_function[] = {
+    { BLUETOOTH_CLASS_API_HAS_SERVICE, hasService, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
 };
 
-
-const JSClassRef JSBluetoothClass::getClassRef() 
-{
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-const JSClassDefinition* JSBluetoothClass::getClassInfo() 
-{
-       return &m_classInfo;
-}
-
 JSClassRef JSBluetoothClass::m_jsClassRef = JSClassCreate(JSBluetoothClass::getClassInfo());
 
-void JSBluetoothClass::initialize(JSContextRef context, JSObjectRef object) 
-{
-       LogDebug("JSBluetoothClass::initialize ");
-       JSBluetoothClassPriv* priv = static_cast<JSBluetoothClassPriv*>(JSObjectGetPrivate(object));
-
-       if (priv == NULL)
-       {
-               BluetoothClassPtr btClass(new BluetoothClass());
-               priv = new JSBluetoothClassPriv( context, btClass);
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-       }
-       else
-       {
-               LogDebug("JSBluetoothClass::already exist ");           
-       }
-}
-
-
-JSObjectRef JSBluetoothClass::createJSObject(JSContextRef context)
+const JSClassRef JSBluetoothClass::getClassRef()
 {
-       BluetoothClassPtr btClass(new BluetoothClass());
-       JSBluetoothClassPriv* priv = new JSBluetoothClassPriv( context, btClass);
-       btClass->setReadOnly();
-
-       return JSObjectMake(context, getClassRef(), priv);
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-JSObjectRef JSBluetoothClass::createJSObject(JSContextRef context, int device)
+const JSClassDefinition* JSBluetoothClass::getClassInfo()
 {
-       BluetoothClassPtr btClass(new BluetoothClass());
-       JSBluetoothClassPriv* priv = new JSBluetoothClassPriv( context, btClass);
-
-       btClass->fromInt(device);
-       btClass->setReadOnly();
-       
-       return JSObjectMake(context, getClassRef(), priv);
-
+    return &m_classInfo;
 }
 
-JSObjectRef JSBluetoothClass::createJSObject(JSContextRef context, BluetoothDeviceDataClass devClass)
+JSObjectRef JSBluetoothClass::createJSObject(JSContextRef context, BluetoothClassSharedPtr bluetoothClass)
 {
-       BluetoothClassPtr btClass(new BluetoothClass());
-       JSBluetoothClassPriv* priv = new JSBluetoothClassPriv( context, btClass);
-
-       btClass->setMajor(devClass.major);
-       btClass->setMinor(devClass.minor);
-       btClass->setServices(devClass.majorServiceMask);
-       btClass->setReadOnly();
-       
-       LogDebug("Major:" << std::hex << devClass.major << "Minor:" << std::hex << devClass.minor << "ServiceClass:" << devClass.majorServiceMask);
-       
-       return JSObjectMake(context, getClassRef(), priv);
+    BluetoothClassHolderPtr holder = new BluetoothClassHolder(bluetoothClass);
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(holder));
 }
 
-
-void JSBluetoothClass::finalize(JSObjectRef object) 
+void JSBluetoothClass::initialize(JSContextRef context, JSObjectRef object)
 {
-       JSBluetoothClassPriv* priv = static_cast<JSBluetoothClassPriv*>(JSObjectGetPrivate(object));
-
-       LogDebug("JSBluetoothClass::Finalrize");
-
-       if (priv != NULL) 
-       {
-               JSObjectSetPrivate(object, NULL);
-               delete priv;
-       }
+    LogDebug("Enter");
+    // do nothing
 }
 
-bool JSBluetoothClass::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
+void JSBluetoothClass::finalize(JSObjectRef object)
 {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    BluetoothClassHolderPtr priv = static_cast<BluetoothClassHolderPtr>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
 }
 
 JSValueRef JSBluetoothClass::getProperty(JSContextRef context,
-                                                                               JSObjectRef object,
-                                                                               JSStringRef propertyName,
-                                                                               JSValueRef* exception)
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-       LogDebug("OK"); 
-
-       Converter converter(context);
-       JSBluetoothClassPriv* priv = static_cast<JSBluetoothClassPriv*>(JSObjectGetPrivate(object));    
-       
-       try 
-       {
-               if (priv == NULL)
-               {
-                       Throw(WrtDeviceApis::Commons::ConversionException);
-               }
-
-               BluetoothClassPtr btClass(priv->getObject());
-               std::string key = converter.toString(propertyName);
-               int value = 0;
-               
-               if (key == "major") 
-               {
-                       value = btClass->getMajor();
-                       return converter.toJSValueRef(value);
-               }
-               else if (key == "minor")
-               {
-                       value = btClass->getMinor();
-                       return converter.toJSValueRef(value);
-               }
-               else if (key == "services")
-               {
-                       std::vector<int> service = btClass->getServices();
-                       JSObjectRef result = JSCreateArrayObject(context, 0, NULL);
-
-                       if (!result) 
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Could not create array object.");
-                       }
-
-                       for (std::size_t i = 0; i < service.size(); ++i) 
-                       {
-                               JSValueRef value = JSValueMakeNumber(context, service[i]);
-
-                               if (!JSSetArrayElement(context, result, i, value)) 
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Could not fill array.");
-                               }
-                       }
-
-                       return result;
-               }
-               else
-               {
-                       btClass->find(key, value);
-                       return converter.toJSValueRef(value);
-               }
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Unkwon Exception");
-       }       
-       return JSValueMakeUndefined(context);
+    try {
+        BluetoothClassHolderPtr priv = static_cast<BluetoothClassHolderPtr>(JSObjectGetPrivate(object));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL");
+        }
+
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_CLASS_MAJOR)) {
+            return JSUtil::toJSValueRef(context, priv->mClass->getMajor());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_CLASS_MINOR)) {
+            return JSUtil::toJSValueRef(context, priv->mClass->getMinor());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_CLASS_SERVICES)) {
+            return priv->mClass->getServices(context);
+        }
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed: " << err.getMessage().c_str());
+    }
+    
+    return NULL;
 }
 
-JSValueRef JSBluetoothClass::hasService(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
-
+JSValueRef JSBluetoothClass::hasService(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       JSBluetoothClassPriv* priv = static_cast<JSBluetoothClassPriv*>(JSObjectGetPrivate(thisObject));        
-       JSValueRef reserveArgument = JSValueMakeUndefined(context);
-
-       try 
-       {
-               if (priv == NULL)
-               {
-                       LogError("Private object is NULL");
-                       Throw(WrtDeviceApis::Commons::ConversionException);
-               }
-
-               if (argumentCount >= 1)
-               {
-                       reserveArgument = arguments[0];
-               }
-
-               
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_BLUETOOTHCLASS_HAS_SERVICE]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               BluetoothClassPtr btClass(priv->getObject());
-               std::vector<int> service = btClass->getServices();
-               Converter converter(context);
-               int queryService = converter.toInt(reserveArgument);
-               int index = 0;
+    LogDebug("Enter");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_CLASS_API_HAS_SERVICE);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        // Private Object
+        BluetoothClassHolderPtr priv = static_cast<BluetoothClassHolderPtr>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+    
+        ArgumentValidator validator(context, argumentCount, arguments);
+        unsigned long service = validator.toULong(0);  // uuid
+        if(service > 65535) {
+            throw InvalidValuesException("Invalid value");
+        }
+
+        return JSUtil::toJSValueRef(context, priv->mClass->hasService(service));
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothClass.hasService().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+}
 
-               for (index = 0; index < (int)service.size(); index++)
-               {
-                       if (service[index] == queryService)
-                       {
-                               return converter.toJSValueRef(true);
-                       }
-               }
-               return converter.toJSValueRef(false);
-               
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");     
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnkownException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException) 
-       {
-               LogError("permission denied error");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
 
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("UnkownException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "Unkown error");
-       }
-}
-}
-}
 
+} // Bluetooth
+} // DeviceAPI
index 745d224..c188e54 100644 (file)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_H_
+#ifndef __TIZEN_JS_BLUETOOTH_CLASS_H__
+#define __TIZEN_JS_BLUETOOTH_CLASS_H__
 
 #include <JavaScriptCore/JavaScript.h>
- #include "BluetoothClass.h"
-#include "BTDevice.h"
- #include <CommonsJavaScript/PrivateObject.h>
-
-using namespace WrtDeviceApis::CommonsJavaScript;
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::Commons;
+#include "BluetoothClass.h"
 
-       
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassPriv;
-
-class JSBluetoothClass {
+class BluetoothClassHolder
+{
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static JSObjectRef createJSObject(JSContextRef context, BluetoothDeviceDataClass devClass);
-       static JSObjectRef createJSObject(JSContextRef context);
-       static JSObjectRef createJSObject(JSContextRef context, int device);
+    BluetoothClassHolder(BluetoothClassSharedPtr bluetoothClass) {mClass = bluetoothClass;}
+    BluetoothClassSharedPtr mClass; 
+};
+typedef BluetoothClassHolder* BluetoothClassHolderPtr;
 
+class JSBluetoothClass
+{
+public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, BluetoothClassSharedPtr bluetoothClass);
+    
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void initConstants();
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-       JSValueRef possibleInstance, JSValueRef* exception);
-
-       static JSValueRef hasService(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception); 
-
-       static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
-                               JSStringRef propertyName, JSValueRef* exception);
-
-       static JSClassDefinition m_classInfo;
-       static JSStaticFunction m_function[];
-       static JSStaticValue m_properties[];
-       
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef hasService(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_function[];
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-}
-}
 
-#endif
 
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index f4aba33..7272303 100644 (file)
 // limitations under the License.
 //
 
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "JSBluetoothClassDeviceMajor.h"
+#include <JSUtil.h>
 #include "plugin_config.h"
+#include "JSBluetoothClassDeviceMajor.h"
+#include "BluetoothClassDeviceMajor.h"
 
+#include <Logger.h>
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
-
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassDefinition JSBluetoothClassDeviceMajor::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothClassDeviceMajor",
-       NULL,
-       m_properties,
-       NULL,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSBluetoothClassDeviceMajor::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothClassDeviceMajor",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    NULL, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-       
+JSClassRef JSBluetoothClassDeviceMajor::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceMajor::getClassInfo());
 
-JSStaticValue JSBluetoothClassDeviceMajor::m_properties[] = 
-{
-       {"MISC", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"COMPUTER", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PHONE", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"NETWORK", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AUDIO_VIDEO", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"IMAGING", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"WEARABLE", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"TOY", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"UNCATEGORIZED", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {0, 0, 0, 0}
+JSStaticValue JSBluetoothClassDeviceMajor::m_property[] = {
+    { "MISC", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "COMPUTER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "PHONE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "NETWORK", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "AUDIO_VIDEO", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "PERIPHERAL", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "IMAGING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "WEARABLE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "TOY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "HEALTH", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "UNCATEGORIZED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { 0, 0, 0, 0 }
 };
 
 
-const JSClassRef JSBluetoothClassDeviceMajor::getClassRef() 
+const JSClassRef JSBluetoothClassDeviceMajor::getClassRef()
 {
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-const JSClassDefinition* JSBluetoothClassDeviceMajor::getClassInfo() 
-{
-       return &m_classInfo;
-}
-
-JSClassRef JSBluetoothClassDeviceMajor::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceMajor::getClassInfo());
-
-void JSBluetoothClassDeviceMajor::initialize(JSContextRef context, JSObjectRef object) 
+const JSClassDefinition* JSBluetoothClassDeviceMajor::getClassInfo()
 {
-       LogDebug("JSBluetoothClassDeviceMajor::initialize ");
-       JSBluetoothClassDeviceMajorPriv* priv = static_cast<JSBluetoothClassDeviceMajorPriv*>(JSObjectGetPrivate(object));
-
-       if (priv == NULL)
-       {
-               BluetoothClassPtr btClass(new BluetoothClass());
-               priv = new JSBluetoothClassDeviceMajorPriv( context, btClass);
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-       }
-       else
-       {
-               LogDebug("JSBluetoothClassDeviceMajor::already exist ");                
-       }
+    return &m_classInfo;
 }
 
-
 JSObjectRef JSBluetoothClassDeviceMajor::createJSObject(JSContextRef context)
 {
-       BluetoothClassPtr btClass(new BluetoothClass());
-       JSBluetoothClassDeviceMajorPriv* priv = new JSBluetoothClassDeviceMajorPriv( context, btClass);
-       btClass->setReadOnly();
-
-       return JSObjectMake(context, getClassRef(), priv);
+    return JSObjectMake(context, getClassRef(), NULL);
 }
 
-
-void JSBluetoothClassDeviceMajor::finalize(JSObjectRef object) 
+void JSBluetoothClassDeviceMajor::initialize(JSContextRef context, JSObjectRef object)
 {
-       JSBluetoothClassDeviceMajorPriv* priv = static_cast<JSBluetoothClassDeviceMajorPriv*>(JSObjectGetPrivate(object));
-
-       LogDebug("JSBluetoothClassDeviceMajor::Finalrize");
-
-       if (priv != NULL) 
-       {
-               JSObjectSetPrivate(object, NULL);
-               delete priv;
-       }
+    LogDebug("Enter");
+    // Do nothing
 }
 
-bool JSBluetoothClassDeviceMajor::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+void JSBluetoothClassDeviceMajor::finalize(JSObjectRef object)
+{
+    LogDebug("Enter");
+    // Do nothing
 }
 
 JSValueRef JSBluetoothClassDeviceMajor::getProperty(JSContextRef context,
-                                                                               JSObjectRef object,
-                                                                               JSStringRef propertyName,
-                                                                               JSValueRef* exception)
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-       LogDebug("OK"); 
-
-       JSBluetoothClassDeviceMajorPriv* priv = static_cast<JSBluetoothClassDeviceMajorPriv*>(JSObjectGetPrivate(object));      
-       
-       try 
-       {
-               
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-               
-               Converter converter(context);
-               BluetoothClassPtr btClass(priv->getObject());
-               std::string key = converter.toString(propertyName);
-               int value = 0;
-               
-               if (btClass->find(key, value) == false)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "can not find property" << key);
-               }
-               return converter.toJSValueRef(value);
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return NULL;
-}
-}
+    try {
+        std::string name = JSUtil::JSStringToString(context, propertyName);
+        return JSUtil::toJSValueRef(context, BluetoothClassDeviceMajor::getInstance()->getMajorValue(name));
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed: " << err.getMessage().c_str());
+    }
+
+    return NULL;
 }
 
+
+} // Bluetooth
+} // DeviceAPI
index 40fc9ee..b61d84f 100644 (file)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_DEVICE_MAJOR_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_DEVICE_MAJOR_H_
+#ifndef __TIZEN_JS_BLUETOOTH_CLASS_DEVICE_MAJOR_H__
+#define __TIZEN_JS_BLUETOOTH_CLASS_DEVICE_MAJOR_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include "BluetoothClass.h"
-#include "BTDevice.h"
-#include <CommonsJavaScript/PrivateObject.h>
-
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassDeviceMajorPriv;
-
-class JSBluetoothClassDeviceMajor {
+class JSBluetoothClassDeviceMajor
+{
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static JSObjectRef createJSObject(JSContextRef context);
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context);
 
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void initConstants();
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-       JSValueRef possibleInstance, JSValueRef* exception);
-       static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
-                               JSStringRef propertyName, JSValueRef* exception);
-
-       static JSClassDefinition m_classInfo;
-       static JSStaticValue m_properties[];
-       
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-}
-}
 
-#endif
 
+} // Bluetooth
+} // DeviceAPI
 
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index e702073..81541d8 100644 (file)
 // limitations under the License.
 //
 
-
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "JSBluetoothClassDeviceMinor.h"
+#include <JSUtil.h>
 #include "plugin_config.h"
+#include "JSBluetoothClassDeviceMinor.h"
+#include "BluetoothClassDeviceMinor.h"
 
+#include <Logger.h>
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
-
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassDefinition JSBluetoothClassDeviceMinor::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothClassDeviceMinor",
-       NULL,
-       m_properties,
-       NULL,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSBluetoothClassDeviceMinor::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothClassDeviceMinor",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    NULL, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
 
-JSStaticValue JSBluetoothClassDeviceMinor::m_properties[] = 
-{
-       {"COMPUTER_UNCATEGORIZED", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"COMPUTER_DESKTOP", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"COMPUTER_SERVER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"COMPUTER_LAPTOP", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"COMPUTER_HANDHELD_PC_OR_PDA", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"COMPUTER_PALM_PC_OR_PDA", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"COMPUTER_WEARABLE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PHONE_UNCATEGORIZED", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PHONE_CELLULAR", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PHONE_CORDLESS", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PHONE_SMARTPHONE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PHONE_MODEM_OR_GATEWAY", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PHONE_ISDN", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_UNRECOGNIZED", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_WEARABLE_HEADSET", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_HANDSFREE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_MICROPHONE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_LOUDSPEAKER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_HEADPHONES", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_PORTABLE_AUDIO", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_CAR_AUDIO", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_SETTOP_BOX", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_HIFI", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_VCR", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_VIDEO_CAMERA", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_CAMCORDER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_MONITOR", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_DISPLAY_AND_LOUDSPEAKER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_VIDEO_CONFERENCING", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AV_GAMING_TOY", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_UNCATEGORIZED", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_KEYBOARD", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_POINTING_DEVICE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_KEYBOARD_AND_POINTING_DEVICE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_JOYSTICK", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_GAMEPAD", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_REMOTE_CONTROL", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_SENSING_DEVICE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_DEGITIZER_TABLET", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_CARD_READER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_DIGITAL_PEN", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_HANDHELD_SCANNER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"PERIPHERAL_HANDHELD_INPUT_DEVICE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"IMAGING_UNCATEGORIZED", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"IMAGING_DISPLAY", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"IMAGING_CAMERA", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"IMAGING_SCANNER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"IMAGING_PRINTER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"WEARABLE_WRITST_WATCH", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"WEARABLE_PAGER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"WEARABLE_JACKET", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"WEARABLE_HELMET", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"WEARABLE_GLASSES", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"TOY_ROBOT", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"TOY_VEHICLE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"TOY_DOLL", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"TOY_CONTROLLER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"TOY_GAME", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_UNDEFINED", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_BLOOD_PRESSURE_MONITOR", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_THERMOMETER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_WEIGHING_SCALE", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_GLUCOSE_METER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_PULSE_OXIMETER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_PULSE_RATE_MONITOR", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_DATA_DISPLAY", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_STEP_COUNTER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_BODY_COMPOSITION_ANALYZER", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_PEAK_FLOW_MONITOR", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_MEDICATION_MONITOR", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_KNEE_PROSTHESIS", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"HEALTH_ANKLE_PROSTHESIS", JSBluetoothClassDeviceMinor::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {0, 0, 0, 0}
-};
-
+JSClassRef JSBluetoothClassDeviceMinor::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceMinor::getClassInfo());
 
-const JSClassRef JSBluetoothClassDeviceMinor::getClassRef() 
-{
-       if (!m_jsClassRef) 
-       {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
+JSStaticValue JSBluetoothClassDeviceMinor::m_property[] = {
+    {"COMPUTER_UNCATEGORIZED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"COMPUTER_DESKTOP", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"COMPUTER_SERVER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"COMPUTER_LAPTOP", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"COMPUTER_HANDHELD_PC_OR_PDA", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"COMPUTER_PALM_PC_OR_PDA", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"COMPUTER_WEARABLE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PHONE_UNCATEGORIZED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PHONE_CELLULAR", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PHONE_CORDLESS", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PHONE_SMARTPHONE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PHONE_MODEM_OR_GATEWAY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PHONE_ISDN", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_UNRECOGNIZED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_WEARABLE_HEADSET", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_HANDSFREE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_MICROPHONE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_LOUDSPEAKER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_HEADPHONES", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_PORTABLE_AUDIO", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_CAR_AUDIO", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_SETTOP_BOX", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_HIFI", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_VCR", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_VIDEO_CAMERA", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_CAMCORDER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_MONITOR", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_DISPLAY_AND_LOUDSPEAKER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_VIDEO_CONFERENCING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"AV_GAMING_TOY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_UNCATEGORIZED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_KEYBOARD", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_POINTING_DEVICE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_KEYBOARD_AND_POINTING_DEVICE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_JOYSTICK", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_GAMEPAD", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_REMOTE_CONTROL", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_SENSING_DEVICE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_DEGITIZER_TABLET", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_CARD_READER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_DIGITAL_PEN", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_HANDHELD_SCANNER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"PERIPHERAL_HANDHELD_INPUT_DEVICE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"IMAGING_UNCATEGORIZED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"IMAGING_DISPLAY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"IMAGING_CAMERA", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"IMAGING_SCANNER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"IMAGING_PRINTER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"WEARABLE_WRITST_WATCH", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"WEARABLE_PAGER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"WEARABLE_JACKET", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"WEARABLE_HELMET", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"WEARABLE_GLASSES", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"TOY_ROBOT", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"TOY_VEHICLE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"TOY_DOLL", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"TOY_CONTROLLER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"TOY_GAME", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_UNDEFINED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_BLOOD_PRESSURE_MONITOR", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_THERMOMETER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_WEIGHING_SCALE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_GLUCOSE_METER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_PULSE_OXIMETER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_PULSE_RATE_MONITOR", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_DATA_DISPLAY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_STEP_COUNTER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_BODY_COMPOSITION_ANALYZER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_PEAK_FLOW_MONITOR", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_MEDICATION_MONITOR", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_KNEE_PROSTHESIS", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    {"HEALTH_ANKLE_PROSTHESIS", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { 0, 0, 0, 0 }
+};
 
-const JSClassDefinition* JSBluetoothClassDeviceMinor::getClassInfo() 
+const JSClassRef JSBluetoothClassDeviceMinor::getClassRef()
 {
-       return &m_classInfo;
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-JSClassRef JSBluetoothClassDeviceMinor::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceMinor::getClassInfo());
-
-void JSBluetoothClassDeviceMinor::initialize(JSContextRef context, JSObjectRef object) 
+const JSClassDefinition* JSBluetoothClassDeviceMinor::getClassInfo()
 {
-       LogDebug("JSBluetoothClassDeviceMinor::initialize ");
-       JSBluetoothClassDeviceMinorPriv* priv = static_cast<JSBluetoothClassDeviceMinorPriv*>(JSObjectGetPrivate(object));
-
-       if (priv == NULL)
-       {
-               BluetoothClassPtr btClass(new BluetoothClass());
-               priv = new JSBluetoothClassDeviceMinorPriv( context, btClass);
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-       }
-       else
-       {
-               LogDebug("JSBluetoothClassDeviceMinor::already exist ");                
-       }
+    return &m_classInfo;
 }
 
-
 JSObjectRef JSBluetoothClassDeviceMinor::createJSObject(JSContextRef context)
 {
-       BluetoothClassPtr btClass(new BluetoothClass());
-       JSBluetoothClassDeviceMinorPriv* priv = new JSBluetoothClassDeviceMinorPriv( context, btClass);
-       btClass->setReadOnly();
-
-       return JSObjectMake(context, getClassRef(), priv);
+    return JSObjectMake(context, getClassRef(), NULL);
 }
 
-
-void JSBluetoothClassDeviceMinor::finalize(JSObjectRef object) 
+void JSBluetoothClassDeviceMinor::initialize(JSContextRef context, JSObjectRef object)
 {
-       JSBluetoothClassDeviceMinorPriv* priv = static_cast<JSBluetoothClassDeviceMinorPriv*>(JSObjectGetPrivate(object));
-
-       LogDebug("JSBluetoothClassDeviceMinor::Finalrize");
-
-       if (priv != NULL) 
-       {
-               JSObjectSetPrivate(object, NULL);
-               delete priv;
-       }
+    LogDebug("Enter");    // do nothing
 }
 
-bool JSBluetoothClassDeviceMinor::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
+void JSBluetoothClassDeviceMinor::finalize(JSObjectRef object)
 {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    LogDebug("Enter");    // do nothing
 }
 
 JSValueRef JSBluetoothClassDeviceMinor::getProperty(JSContextRef context,
-                                                                               JSObjectRef object,
-                                                                               JSStringRef propertyName,
-                                                                               JSValueRef* exception)
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-       LogDebug("OK"); 
-
-       Converter converter(context);
-       JSBluetoothClassDeviceMinorPriv* priv = static_cast<JSBluetoothClassDeviceMinorPriv*>(JSObjectGetPrivate(object));      
-
-       try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-               
-               Converter converter(context);
-               BluetoothClassPtr btClass(priv->getObject());
-               std::string key = converter.toString(propertyName);
-               int value = 0;
-               
-               if (btClass->find(key, value) == false)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "can not find property" << key);
-               }
-               return converter.toJSValueRef(value);
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-
-       return NULL;
-}
-}
+    try {
+        std::string name = JSUtil::JSStringToString(context, propertyName);
+        return JSUtil::toJSValueRef(context, BluetoothClassDeviceMinor::getInstance()->getMinorValue(name));
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed: " << err.getMessage().c_str());
+    }
+
+    return NULL;
 }
 
+
+} // Bluetooth
+} // DeviceAPI
index cfee85e..1877cc5 100644 (file)
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
 
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_H_
+#ifndef __TIZEN_JS_BLUETOOTH_CLASS_DEVICE_MINOR_H__
+#define __TIZEN_JS_BLUETOOTH_CLASS_DEVICE_MINOR_H__
 
 #include <JavaScriptCore/JavaScript.h>
- #include "BluetoothClass.h"
-#include "BTDevice.h"
- #include <CommonsJavaScript/PrivateObject.h>
 
- namespace DeviceAPI {
- namespace Bluetooth {
+namespace DeviceAPI {
+namespace Bluetooth {
 
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassDeviceMinorPriv;
-
-class JSBluetoothClassDeviceMinor 
+class JSBluetoothClassDeviceMinor
 {
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static JSObjectRef createJSObject(JSContextRef context);
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context);
 
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void initConstants();
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-       JSValueRef possibleInstance, JSValueRef* exception);
-       static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
-                               JSStringRef propertyName, JSValueRef* exception);
-
-       static JSClassDefinition m_classInfo;
-       static JSStaticValue m_properties[];
-       
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-}
-}
 
-#endif
 
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index 817e811..18d894e 100644 (file)
 // limitations under the License.
 //
 
-
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "JSBluetoothClassDeviceService.h"
+#include <JSUtil.h>
 #include "plugin_config.h"
+#include "JSBluetoothClassDeviceService.h"
+#include "BluetoothClassDeviceService.h"
 
+#include <Logger.h>
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
-
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassDefinition JSBluetoothClassDeviceService::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothClassDeviceService",
-       NULL,
-       m_properties,
-       NULL,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSBluetoothClassDeviceService::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothClassDeviceService",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    NULL, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-       
 
-JSStaticValue JSBluetoothClassDeviceService::m_properties[] = 
-{
-       {"LIMITED_DISCOVERABILITY", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"POSITIONING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"NETWORKING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"RENDERING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"CAPTURING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"OBJECT_TRANSFER", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"AUDIO", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"TELEPHONY", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"INFORMATION", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {0, 0, 0, 0}
-};
 
+JSClassRef JSBluetoothClassDeviceService::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceService::getClassInfo());
 
-const JSClassRef JSBluetoothClassDeviceService::getClassRef() 
-{
-       if (!m_jsClassRef) 
-       {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
+JSStaticValue JSBluetoothClassDeviceService::m_property[] = {
+    { "LIMITED_DISCOVERABILITY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "POSITIONING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "NETWORKING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "RENDERING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "CAPTURING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "OBJECT_TRANSFER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "AUDIO", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "TELEPHONY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { "INFORMATION", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { 0, 0, 0, 0 }
+};
 
-const JSClassDefinition* JSBluetoothClassDeviceService::getClassInfo() 
+const JSClassRef JSBluetoothClassDeviceService::getClassRef()
 {
-       return &m_classInfo;
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-JSClassRef JSBluetoothClassDeviceService::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceService::getClassInfo());
-
-void JSBluetoothClassDeviceService::initialize(JSContextRef context, JSObjectRef object) 
+const JSClassDefinition* JSBluetoothClassDeviceService::getClassInfo()
 {
-       LogDebug("JSBluetoothClassDeviceService::initialize ");
-       JSBluetoothClassDeviceServicePriv* priv = static_cast<JSBluetoothClassDeviceServicePriv*>(JSObjectGetPrivate(object));
-
-       if (priv == NULL)
-       {
-               BluetoothClassPtr btClass(new BluetoothClass());
-               priv = new JSBluetoothClassDeviceServicePriv( context, btClass);
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-       }
-       else
-       {
-               LogDebug("JSBluetoothClassDeviceService::already exist ");              
-       }
+    return &m_classInfo;
 }
 
-
 JSObjectRef JSBluetoothClassDeviceService::createJSObject(JSContextRef context)
 {
-       BluetoothClassPtr btClass(new BluetoothClass());
-       JSBluetoothClassDeviceServicePriv* priv = new JSBluetoothClassDeviceServicePriv( context, btClass);
-       btClass->setReadOnly();
-
-       return JSObjectMake(context, getClassRef(), priv);
+    return JSObjectMake(context, getClassRef(), NULL);
 }
 
-void JSBluetoothClassDeviceService::finalize(JSObjectRef object) 
+void JSBluetoothClassDeviceService::initialize(JSContextRef context, JSObjectRef object)
 {
-       JSBluetoothClassDeviceServicePriv* priv = static_cast<JSBluetoothClassDeviceServicePriv*>(JSObjectGetPrivate(object));
-
-       LogDebug("JSBluetoothClassDeviceService::Finalrize");
-
-       if (priv != NULL) 
-       {
-               JSObjectSetPrivate(object, NULL);
-               delete priv;
-       }
+    LogDebug("Enter");    // do nothing
 }
 
-bool JSBluetoothClassDeviceService::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
+void JSBluetoothClassDeviceService::finalize(JSObjectRef object)
 {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    LogDebug("Enter");    // do nothing
 }
 
 JSValueRef JSBluetoothClassDeviceService::getProperty(JSContextRef context,
-                                                                               JSObjectRef object,
-                                                                               JSStringRef propertyName,
-                                                                               JSValueRef* exception)
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-       LogDebug("OK"); 
-
-       Converter converter(context);
-       JSBluetoothClassDeviceServicePriv* priv = static_cast<JSBluetoothClassDeviceServicePriv*>(JSObjectGetPrivate(object));  
-       
-       try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               BluetoothClassPtr btClass(priv->getObject());
-               std::string key = converter.toString(propertyName);
-               int value = 0;
-               
-               if (btClass->find(key, value) == false)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "can not find property" << key);
-               }
-               return converter.toJSValueRef(value);
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-
-       return NULL;
-}
-}
+    try {
+        std::string name = JSUtil::JSStringToString(context, propertyName);
+        return JSUtil::toJSValueRef(context, BluetoothClassDeviceService::getInstance()->getServiceValue(name));
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed: " << err.getMessage().c_str());
+    }
+
+    return NULL;
 }
 
 
+} // Bluetooth
+} // DeviceAPI
index 035bf8c..5ae6fce 100644 (file)
 // limitations under the License.
 //
 
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_DEVICE_SERVICE_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_DEVICE_SERVICE_H_
+#ifndef __TIZEN_JS_BLUETOOTH_CLASS_DEVICE_SERVICE_H__
+#define __TIZEN_JS_BLUETOOTH_CLASS_DEVICE_SERVICE_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include "BluetoothClass.h"
-#include "BTDevice.h"
-#include <CommonsJavaScript/PrivateObject.h>
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassDeviceServicePriv;
-
-class JSBluetoothClassDeviceService 
+class JSBluetoothClassDeviceService
 {
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static JSObjectRef createJSObject(JSContextRef context);
-
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context);
 
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void initConstants();
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-       JSValueRef possibleInstance, JSValueRef* exception);
-
-       static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
-                               JSStringRef propertyName, JSValueRef* exception);
-       static JSClassDefinition m_classInfo;
-       static JSStaticValue m_properties[];
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
-}
-}
 
-#endif
 
 
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index f5e7c84..b829f0d 100644 (file)
 // limitations under the License.
 //
 
-
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
 #include <SecurityExceptions.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "JSBluetoothDevice.h"
-#include "IBluetoothDeviceManager.h"
-#include "BluetoothFactory.h"
-#include "BluetoothDeviceManagerListener.h"
-#include "BluetoothProperty.h"
-#include "JSBluetoothClass.h"
-#include "BluetoothConverter.h"
+
+#include <JSUtil.h>
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <PlatformException.h>
+#include <MultiCallbackUserData.h>
+
 #include "plugin_config.h"
-#include "JSUtil.h"
+#include "JSBluetoothDevice.h"
+#include "BluetoothDevice.h"
+#include "BluetoothAdapter.h"
+
+#include <Logger.h>
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassDefinition JSBluetoothDevice::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothDevice",
-       NULL,
-       m_properties,
-       m_function,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSBluetoothDevice::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothDevice",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    m_function, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-JSStaticFunction JSBluetoothDevice::m_function[] =
-{
-       { "connectToServiceByUUID", JSBluetoothDevice::connectToServiceByUUID, kJSPropertyAttributeNone },
-       { 0, 0, 0 }
+JSStaticValue JSBluetoothDevice::m_property[] = {
+    { BLUETOOTH_DEVICE_NAME, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_DEVICE_ADDRESS, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_DEVICE_DEVICE_CLASS, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_DEVICE_IS_BONDED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_DEVICE_IS_TRUSTED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_DEVICE_IS_CONNECTED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_DEVICE_UUIDS, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { 0, 0, 0, 0 }
 };
 
-JSStaticValue JSBluetoothDevice::m_properties[] = {
-       {"name", getName, NULL, kJSPropertyAttributeReadOnly},
-       {"address", getAddress, NULL, kJSPropertyAttributeReadOnly},
-       {"isBonded", getBondProperty, NULL, kJSPropertyAttributeReadOnly},
-       {"isTrusted", getTrustProperty, NULL, kJSPropertyAttributeReadOnly},
-       {"isConnected", getConnectProperty, NULL, kJSPropertyAttributeReadOnly},
-       {"uuids", getUuids, NULL, kJSPropertyAttributeReadOnly},        
-       {0, 0, 0, 0}
+JSStaticFunction JSBluetoothDevice::m_function[] = {
+    { BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID, connectToServiceByUUID, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
 };
 
-const JSClassRef JSBluetoothDevice::getClassRef() 
-{
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-const JSClassDefinition* JSBluetoothDevice::getClassInfo() 
-{
-       return &m_classInfo;
-}
-
 JSClassRef JSBluetoothDevice::m_jsClassRef = JSClassCreate(JSBluetoothDevice::getClassInfo());
 
-void JSBluetoothDevice::initialize(JSContextRef context, JSObjectRef object) 
+const JSClassRef JSBluetoothDevice::getClassRef()
 {
-       LogDebug("initialize ");
-
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       if (priv == NULL)
-       {
-               IBluetoothDeviceManagerPtr BluetoothManager(BluetoothFactory::getInstance().getBluetoothDeviceManager());
-               priv = new JSBluetoothDevicePriv( context, BluetoothManager);
-               
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-       }
-       else
-       {
-               LogDebug("already exist");              
-       }
-
-       setAttributesIntoJSObject(context, object);     
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-void JSBluetoothDevice::finalize(JSObjectRef object) 
+const JSClassDefinition* JSBluetoothDevice::getClassInfo()
 {
-       LogDebug("Finalrize");
-
-       JSBluetoothDevicePriv* priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       if (priv != NULL)
-       {
-               JSObjectSetPrivate(object, NULL);
-               LogDebug("Deleting BluetoothManager");
-               delete priv;
-       }
+    return &m_classInfo;
 }
 
-
-bool JSBluetoothDevice::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
+JSObjectRef JSBluetoothDevice::createJSObject(JSContextRef context, BluetoothDeviceSharedPtr device)
 {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    BluetoothDeviceHolderPtr holder = new BluetoothDeviceHolder(device);
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(holder));
 }
 
-
-JSObjectRef JSBluetoothDevice::createJSObject(JSContextRef context, BluetoothDeviceData device)
+void JSBluetoothDevice::initialize(JSContextRef context, JSObjectRef object)
 {
-       IBluetoothDeviceManagerPtr BluetoothManager(BluetoothFactory::getInstance().getBluetoothDeviceManager());
-       BluetoothManager->setDevice(device);
-       
-       JSBluetoothDevicePriv* priv = new JSBluetoothDevicePriv( context, BluetoothManager);
-       return JSObjectMake(context, getClassRef(), priv);
+    LogDebug("Enter");
+    // Do nothing
 }
 
-
-
-JSValueRef JSBluetoothDevice::getName(JSContextRef context,
-                                                                               JSObjectRef object,
-                                                                               JSStringRef propertyName,
-                                                                               JSValueRef* exception)
+void JSBluetoothDevice::finalize(JSObjectRef object)
 {
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               std::string name = BluetoothDeviceManager->getNameProperty();
-               LogDebug("name" << name);       
-               return converter.toJSValueRef(name);
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return NULL;
+    BluetoothDeviceHolderPtr priv = static_cast<BluetoothDeviceHolderPtr>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
 }
 
-JSValueRef JSBluetoothDevice::getAddress(JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSStringRef propertyName,
-                                                       JSValueRef* exception)
+JSValueRef JSBluetoothDevice::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               std::string address = BluetoothDeviceManager->getAddressProperty();
-
-               LogDebug("address" << address); 
-               return converter.toJSValueRef(address);
-       }
-       Catch(WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return NULL;
-}
-JSValueRef JSBluetoothDevice::getBondProperty(JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSStringRef propertyName,
-                                                       JSValueRef* exception)
+    try {
+        BluetoothDeviceHolderPtr priv = static_cast<BluetoothDeviceHolderPtr>(JSObjectGetPrivate(object));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL");
+        }
+
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_NAME)) {
+            return JSUtil::toJSValueRef(context, priv->mDevice->getName());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_ADDRESS)) {
+            return JSUtil::toJSValueRef(context, priv->mDevice->getAddress());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_DEVICE_CLASS)) {
+            return priv->mDevice->getDeviceClass(context);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_IS_BONDED)) {
+            return JSUtil::toJSValueRef(context, priv->mDevice->isBonded());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_IS_TRUSTED)) {
+            return JSUtil::toJSValueRef(context, priv->mDevice->isTrusted());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_IS_CONNECTED)) {
+            return JSUtil::toJSValueRef(context, priv->mDevice->isConnected());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_DEVICE_UUIDS)) {
+            return priv->mDevice->getUUIDs(context);
+        }
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed: " << err.getMessage().c_str());
+    }
+
+    return NULL;
+}
+
+JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               bool isBonded = BluetoothDeviceManager->getBondProperty();
-
-               LogDebug("isBonded " << isBonded);      
-               
-               return converter.toJSValueRef(isBonded);
-       }
-       Catch(WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return JSValueMakeUndefined(context);
-}
-JSValueRef JSBluetoothDevice::getTrustProperty(JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSStringRef propertyName,
-                                                       JSValueRef* exception)
-{
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               bool isTrusted = BluetoothDeviceManager->getTrustProperty();
-
-               LogDebug("isTrusted " << isTrusted);    
-               return converter.toJSValueRef(isTrusted);
-       }
-       Catch(WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return JSValueMakeUndefined(context);
-}
-JSValueRef JSBluetoothDevice::getConnectProperty(JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSStringRef propertyName,
-                                                       JSValueRef* exception)
-{
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               bool isConnected = BluetoothDeviceManager->getConnectProperty();
-
-               LogDebug("isConnected " << isConnected);        
-               return converter.toJSValueRef(isConnected);
-       }
-       Catch(WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSBluetoothDevice::getUuids(JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSStringRef propertyName,
-                                                       JSValueRef* exception)
-{
-       LogDebug("Enter");      
-
-       Converter converter(context);
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-
-       Try 
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-               
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               std::vector<std::string> uuids = BluetoothDeviceManager->getUuidsProperty();
-               JSObjectRef result = JSCreateArrayObject(context, 0, NULL);
-               int length = uuids.size();
-               
-               if (!result) 
-               {
-                       return converter.toJSValueRef("");
-               }
-
-               for (int i = 0; i < length; ++i) 
-               {
-                       JSValueRef value = converter.toJSValueRef(uuids[i]);
-
-                       if (!JSSetArrayElement(context, result, i, value)) 
-                       {
-                               return converter.toJSValueRef("");
-                       }
-               }
-
-               return result;
-       }
-       Catch(WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());
-       }
-       
-       return JSValueMakeUndefined(context);
-}
-
-
-       
-
-JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) {
-
-       LogDebug("connectToServiceByUUID");
-
-       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(thisObject));
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       size_t index = 0;
-       JSValueRef reserveArguments[3];
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-               
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-
-       Try     {
-
-               for (index = 0; index < 3; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeNull(context);
-                       
-               }
-
-               LogDebug(bluetoothExportedNames[BLUETOOTH_FUNCTION_API_DEVICE_CONNECT_TO_SERVICE]);
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                       bluetoothExportedNames[BLUETOOTH_FUNCTION_API_DEVICE_CONNECT_TO_SERVICE]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               
-               BluetoothConverter converter(context);
-               successCallback = converter.toFunction(reserveArguments[1]);
-               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
-               
-
-               if (cbm == NULL)
-               {
-                       return JSValueMakeUndefined(context);
-               }
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               EventBTConnectToServiceByUUIDPtr event(new EventBTConnectToServiceByUUID);
-               BluetoothSocketData socketData;
-               socketData.uuid = converter.toBluetoothUUIDString(reserveArguments[0]);
-               socketData.protocol  = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-
-/*             if (argumentCount >= 4)
-               {
-                       socketData.protocol = converter.toBluetoothProtocolInt(reserveArguments[3]);
-               }*/
-               
-               
-               if (BluetoothDeviceManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothDeviceManager or event or listener NULL");
-                       Throw(WrtDeviceApis::Commons::UnknownException);        
-               }
-
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-
-               event->setForAsynchronousCall(&BluetoothDeviceManagerListener::getInstance());
-               event->setSocketData(socketData);
-               BluetoothDeviceManager->connectToServiceByUUID(event);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }
-       
-       Catch (WrtDeviceApis::Commons::AlreadyInUseException)
-       {
-               LogError("AlreadyInUseException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::SERVICE_NOT_AVAILABLE, "already connected"));         
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-       }
-
-       return JSValueMakeUndefined(context);
-}
-
-void JSBluetoothDevice::setAttributesIntoJSObject(JSContextRef context, JSObjectRef object)
-{
-       // deviceClass
-       Try
-       {       
-               JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-               IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
-               BluetoothDeviceDataClass devClass = BluetoothDeviceManager->getClass();
-
-               LogDebug("Major:" << std::hex << devClass.major << "Minor:" << std::hex << devClass.minor << "Service Mask:" << std::hex <<  devClass.majorServiceMask);
-               
-               JSUtil::setProperty(context, object, "deviceClass",
-                               JSBluetoothClass::createJSObject(priv->getContext(), devClass), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());              
-       }
-}
-
-}
-}
-
+    LogDebug("Enter");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        // Private Object
+        BluetoothDeviceHolderPtr priv = static_cast<BluetoothDeviceHolderPtr>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+    
+        ArgumentValidator validator(context, argumentCount, arguments);        
+        std::string uuid = validator.toString(0);  // uuid
+        JSObjectRef successCallback = validator.toFunction(1);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(2, true);  // errorCallback
+        std::string remoteAddress = priv->mDevice->getAddress();    // remote address
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        BluetoothAdapter::getInstance()->connectToServiceByUUID(remoteAddress, uuid, callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothDevice.connectToServiceByUUID().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+}
+
+
+
+} // Bluetooth
+} // DeviceAPI
index 1d87e6a..50e3d3e 100644 (file)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_DEVICE_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_DEVICE_H_
+#ifndef __TIZEN_JS_BLUETOOTH_DEVICE_H__
+#define __TIZEN_JS_BLUETOOTH_DEVICE_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include "IBluetoothDeviceManager.h"
-#include <CommonsJavaScript/PrivateObject.h>
-using namespace WrtDeviceApis::CommonsJavaScript;
+
+#include "BluetoothDevice.h"
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef PrivateObjectT<IBluetoothDeviceManagerPtr>::Type JSBluetoothDevicePriv;
-
-class JSBluetoothDevice 
+class BluetoothDeviceHolder
 {
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static JSObjectRef createJSObject(JSContextRef context, BluetoothDeviceData device);
+    BluetoothDeviceHolder(BluetoothDeviceSharedPtr device) {mDevice = device;}
+    BluetoothDeviceSharedPtr mDevice; 
+};
+typedef BluetoothDeviceHolder* BluetoothDeviceHolderPtr;
 
+class JSBluetoothDevice
+{
+public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, BluetoothDeviceSharedPtr device);
 
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception);
-       static JSValueRef getName(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static JSValueRef getAddress(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static JSValueRef getBondProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static JSValueRef getTrustProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static JSValueRef getConnectProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static JSValueRef getUuids(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static JSValueRef connectToServiceByUUID(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-       /**
-        * Sets attributes into JS object.
-        */
-       static void setAttributesIntoJSObject(JSContextRef context,
-                       JSObjectRef object);    
-       
-       static JSClassDefinition m_classInfo;
-       static JSStaticFunction m_function[];
-       static JSStaticValue m_properties[];
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static bool setProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+
+    static JSValueRef connectToServiceByUUID(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_function[];
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-} 
-}
 
-#endif
 
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index 82390d2..cbc7ae6 100644 (file)
 // limitations under the License.
 //
 
-
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
 #include <SecurityExceptions.h>
-#include "BluetoothFactory.h"
-#include "IBluetoothAdapterManager.h"
-#include "BluetoothProperty.h"
+
+#include <JSUtil.h>
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <PlatformException.h>
+#include <PropertyBag.h>
+
+#include "plugin_config.h"
 #include "JSBluetoothManager.h"
-#include "JSBluetoothAdapter.h"
 #include "JSBluetoothClassDeviceMajor.h"
 #include "JSBluetoothClassDeviceMinor.h"
 #include "JSBluetoothClassDeviceService.h"
-#include "plugin_config.h"
-#include "JSUtil.h"
+//#include "BluetoothManager.h"
+#include "JSBluetoothAdapter.h"
+#include "BluetoothAdapter.h"
+
+#include <Logger.h>
 
 using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
-namespace {
-       #define DEVICE_MAJOR "deviceMajor"
-       #define DEVICE_MINOR "deviceMinor"
-       #define DEVICE_SERVICE "deviceService"
-}
-
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassRef JSBluetoothManager::m_jsClassRef = NULL;
-
-JSClassDefinition JSBluetoothManager::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothManager",
-       NULL,
-       NULL,
-       m_function,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       NULL,
-       NULL
+JSClassDefinition JSBluetoothManager::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothManager",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    m_function, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
+JSStaticValue JSBluetoothManager::m_property[] = {
+    { BLUETOOTH_MANAGER_DEVICE_MAJOR, getReadOnlyProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { BLUETOOTH_MANAGER_DEVICE_MINOR, getReadOnlyProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
+    { BLUETOOTH_MANAGER_DEVICE_SERVICE, getReadOnlyProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},      
+    { 0, 0, 0, 0 }
+};
 
-JSStaticFunction JSBluetoothManager::m_function[] =
-{
-       { "getDefaultAdapter", getDefaultAdapter, kJSPropertyAttributeNone },
-       { 0, 0, 0 }
+JSStaticFunction JSBluetoothManager::m_function[] = {
+    { BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER, getDefaultAdapter, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
 };
 
-const JSClassRef JSBluetoothManager::getClassRef() 
-{
-       if (!m_jsClassRef) 
-       {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
+JSClassRef JSBluetoothManager::m_jsClassRef = JSClassCreate(JSBluetoothManager::getClassInfo());
 
-JSValueRef JSBluetoothManager::getDefaultAdapter(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+const JSClassRef JSBluetoothManager::getClassRef()
 {
-       JSBluetoothManagerPriv* priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(thisObject));
-
-       LogDebug("OK"); 
-
-       Try
-       {
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-               
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_MANAGER_GET_DEFAULT_ADAPTER]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               JSContextRef globalContext = priv->getContext();
-
-               return JSBluetoothAdapter::createJSObject(globalContext);
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException) 
-       {
-               LogError("permission denied error");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
-
-       }       
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnkownException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }
-       Catch(WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("UnkownException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Unkown error");
-       }
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-const JSClassDefinition* JSBluetoothManager::getClassInfo() 
+const JSClassDefinition* JSBluetoothManager::getClassInfo()
 {
-       return &m_classInfo;
+    return &m_classInfo;
 }
 
-
-void JSBluetoothManager::initialize(JSContextRef context, JSObjectRef object) 
+void JSBluetoothManager::initialize(JSContextRef context, JSObjectRef object)
 {
-       JSBluetoothManagerPriv *priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(object));
-       LogDebug("JSBluetoothManager::initialize");
-
-       if (priv != NULL)
-       {
-               LogError("already exist");
-       }
-       else
-       {
-               priv = new JSBluetoothManagerPriv(context);
-
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-       }
-
-       setAttributesIntoJSObject(context, object);
+    if (!JSObjectGetPrivate(object)) {
+        PropertyBag *priv = new PropertyBag();    
+        if(priv) {
+            // deviceMajor
+            priv->setProperty(context, BLUETOOTH_MANAGER_DEVICE_MAJOR,
+                    JSBluetoothClassDeviceMajor::createJSObject(context));
+
+            // deviceMinor
+            priv->setProperty(context, BLUETOOTH_MANAGER_DEVICE_MINOR,
+                    JSBluetoothClassDeviceMinor::createJSObject(context));
+
+            // deviceService
+            priv->setProperty(context, BLUETOOTH_MANAGER_DEVICE_SERVICE,
+                    JSBluetoothClassDeviceService::createJSObject(context));
+
+            if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+                LogWarning("Failed to set private data");
+                delete priv;
+            }            
+        }
+        else {
+            LogWarning("Failed to create private data");
+        }
+    }
+    else {
+        LogWarning("Private data already exists");
+    }
 }
 
-void JSBluetoothManager::finalize(JSObjectRef object) 
+void JSBluetoothManager::finalize(JSObjectRef object)
 {
-       JSBluetoothManagerPriv* priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(object));
-       LogDebug("JSBluetoothManager::Finalrize");
-
-       if (priv != NULL)
-       {
-               JSObjectSetPrivate(object, NULL);
-               LogDebug("Deleting BluetoothManager");
-               delete priv;
-       }
+    PropertyBag *priv = static_cast<PropertyBag*>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
 }
 
-bool JSBluetoothManager::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
-{
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+JSValueRef JSBluetoothManager::getReadOnlyProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {
+    PropertyBag *priv = static_cast<PropertyBag*>(JSObjectGetPrivate(object));
+    if(!priv) {
+        LogWarning("There is no private data");
+        return NULL;
+    }
+
+    std::string name = JSUtil::JSStringToString(context, propertyName);
+    return priv->getProperty(context, propertyName);
 }
 
-void JSBluetoothManager::setAttributesIntoJSObject(JSContextRef context, JSObjectRef object)
+JSValueRef JSBluetoothManager::getDefaultAdapter(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       // deviceMajor
-       JSUtil::setProperty(context, object, DEVICE_MAJOR,
-                       JSBluetoothClassDeviceMajor::createJSObject(context), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);
-
-       // deviceMinor
-       JSUtil::setProperty(context, object, DEVICE_MINOR,
-                       JSBluetoothClassDeviceMinor::createJSObject(context), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);
-
-       // deviceService
-       JSUtil::setProperty(context, object, DEVICE_SERVICE,
-                       JSBluetoothClassDeviceService::createJSObject(context), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);
+    LogDebug("Enter");
+
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }    
+    
+        return JSBluetoothAdapter::createJSObject(context);
+
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothManager.getDefaultAdapter().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-}
-}
 
+} // Bluetooth
+} // DeviceAPI
index 9cc2690..99e579e 100644 (file)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_H_
+#ifndef __TIZEN_JS_BLUETOOTH_MANAGER_H__
+#define __TIZEN_JS_BLUETOOTH_MANAGER_H__
 
 #include <JavaScriptCore/JavaScript.h>
- #include <CommonsJavaScript/PrivateObject.h>
-
-using namespace WrtDeviceApis;
- namespace DeviceAPI {
- namespace Bluetooth {
 
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<void>::Type JSBluetoothManagerPriv;
+namespace DeviceAPI {
+namespace Bluetooth {
 
-class JSBluetoothManager 
+class JSBluetoothManager
 {
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
 
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
-       
-       /**
-        * Sets attributes into JS object.
-        */
-       static void setAttributesIntoJSObject(JSContextRef context,
-                       JSObjectRef object);
-       static JSValueRef getDefaultAdapter(JSContextRef context, JSObjectRef object, 
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) ;
-       static JSClassDefinition m_classInfo;
-       static JSStaticFunction m_function[];
-       static JSStaticValue m_properties[];
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef getReadOnlyProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSValueRef getDefaultAdapter(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_function[];
+
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
+
 };
-}
-} 
 
-#endif
 
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index 4e4814c..c8558a3 100644 (file)
 // limitations under the License.
 //
 
-#include "JSBluetoothServiceHandler.h"
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
 #include <SecurityExceptions.h>
-#include "BluetoothProperty.h"
-#include "BluetoothConverter.h"
-#include "BluetoothAdapterListener.h"
-#include "BluetoothFactory.h"
-#include <bluetooth.h>
+
+#include <JSUtil.h>
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <PlatformException.h>
+#include <MultiCallbackUserData.h>
+
 #include "plugin_config.h"
+#include "JSBluetoothServiceHandler.h"
+#include "BluetoothAdapter.h"
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
+#include <Logger.h>
 
+using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-JSClassRef JSBluetoothServiceHandler::m_jsClassRef = NULL;
-
-JSClassDefinition JSBluetoothServiceHandler::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothServiceHandler",
-       NULL,
-       m_properties,
-       m_function,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       NULL,
-       NULL
+JSClassDefinition JSBluetoothServiceHandler::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothServiceHandler",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    m_function, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-
-
-
-JSStaticValue JSBluetoothServiceHandler::m_properties[] = 
-{
-       {"uuid", getUuid, NULL, kJSPropertyAttributeReadOnly},
-       {"onconnect", getOnConnect, setOnConnect, kJSPropertyAttributeNone},
-       {"name", getName, NULL, kJSPropertyAttributeReadOnly},                  
-       {"isConnected", getIsConnected, NULL, kJSPropertyAttributeReadOnly},                    
-       {0, 0, 0, 0}
+JSStaticValue JSBluetoothServiceHandler::m_property[] = {
+    { BLUETOOTH_SERVICE_HANDLER_UUID, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SERVICE_HANDLER_NAME, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SERVICE_HANDLER_IS_CONNECTED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SERVICE_HANDLER_ONCONNECT, getProperty, setProperty, kJSPropertyAttributeNone|kJSPropertyAttributeDontDelete },
+    { 0, 0, 0, 0 }
 };
 
-JSStaticFunction JSBluetoothServiceHandler::m_function[] =
-{
-       {"unregister", JSBluetoothServiceHandler::unregisterRFCOMMService, kJSPropertyAttributeNone},
-       { 0, 0, 0 }
+JSStaticFunction JSBluetoothServiceHandler::m_function[] = {
+    { BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER, unregister, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
 };
 
-void JSBluetoothServiceHandler::initialize(JSContextRef context, JSObjectRef object) 
-{
-       LogDebug("JSBluetoothServiceHandler::initialize");
-}
-
-JSObjectRef JSBluetoothServiceHandler::createJSObject(JSContextRef context, std::string name, std::string uuid, int registerSock)
-{
-       IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(BluetoothFactory::getInstance().getBluetoothServiceHandlerManager());
-       BluetoothServiceHandlerManager->setRegisterSocket(registerSock);
-       BluetoothServiceHandlerManager->setUUID(uuid);
-       BluetoothServiceHandlerManager->setIsConnected(false);
-       BluetoothServiceHandlerManager->setName(name);
-
-       JSBluetoothServiceHandlerPriv* priv = new JSBluetoothServiceHandlerPriv( context, BluetoothServiceHandlerManager);
-
-       return JSObjectMake(context, getClassRef(), priv);
-
-}
-
-
+JSClassRef JSBluetoothServiceHandler::m_jsClassRef = JSClassCreate(JSBluetoothServiceHandler::getClassInfo());
 
-const JSClassRef JSBluetoothServiceHandler::getClassRef() 
+const JSClassRef JSBluetoothServiceHandler::getClassRef()
 {
-       if (!m_jsClassRef) 
-       {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-
-void JSBluetoothServiceHandler::getPropertyNames(JSContextRef context,
-                                       JSObjectRef object,
-                                       JSPropertyNameAccumulatorRef propertyNames)
+const JSClassDefinition* JSBluetoothServiceHandler::getClassInfo()
 {
+    return &m_classInfo;
 }
 
-
-bool JSBluetoothServiceHandler::setOnConnect(JSContextRef context,
-                                       JSObjectRef object,
-                                       JSStringRef propertyName,
-                                       JSValueRef value,
-                                       JSValueRef* exception)
-
+JSObjectRef JSBluetoothServiceHandler::createJSObject(JSContextRef context, BluetoothServiceHandlerPtr service)
 {
-       LogDebug("OK");
-       
-       try 
-       {
-               JSBluetoothServiceHandlerPriv *priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "private object null");
-               }
-
-               BluetoothConverter converter(priv->getContext());
-               JSValueRef successCallback = NULL;
-               JSValueRef errorCallback = NULL;
-
-               if( JSValueIsNull(context, value) ||
-                       JSObjectIsFunction(context, converter.toJSObjectRef(value)) )
-               {
-                       LogDebug("Callable or null");
-                       successCallback = converter.toFunctionOrNull(value);
-               }
-               else
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Non callable object");
-               }
-
-               JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-               if (cbm == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "callback manager creation fail");
-               }
-               
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallback);
-
-               IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(priv->getObject());
-               EventBTServiceOnConnectEmitterPtr emitter(new EventBTServiceOnConnectEmitter);
-               if (BluetoothServiceHandlerManager == NULL || emitter == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException,
-                               "IBluetoothServiceHandlerManagerPtr or EventBTServiceOnConnectEmitterPtr is NULL");
-               }
-
-               emitter->setListener(&BluetoothAdapterListener::getInstance());
-               emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(cbm));
-               BluetoothServiceHandlerManager->setServiceHandlerListener(emitter);
-
-               return true;
-       }
-       catch (const WrtDeviceApis::Commons::ConversionException& ex)
-       {
-               LogError("Exception: " << ex.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context,
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }       
-       catch (const WrtDeviceApis::Commons::Exception& ex)
-       {
-               LogWarning("Exception: " << ex.GetMessage());
-       }
-
-       return false;
+    LogDebug("Enter");
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(service));
 }
 
-
-JSValueRef JSBluetoothServiceHandler::getOnConnect(JSContextRef context,
-                                       JSObjectRef object,
-                                       JSStringRef propertyName,
-                                       JSValueRef* exception)
+void JSBluetoothServiceHandler::initialize(JSContextRef context, JSObjectRef object)
 {
-       LogDebug("OK");
-
-       try
-       {
-               JSBluetoothServiceHandlerPriv *priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "private object null");
-               }
-
-               IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(priv->getObject());
-               if(BluetoothServiceHandlerManager == NULL)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "IBluetoothServiceHandlerManagerPtr is null");
-
-               EventBTServiceOnConnectEmitterPtr emitter = BluetoothServiceHandlerManager->getServiceHandlerListener();
-               if(emitter == NULL)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "EventBTServiceOnConnectEmitterPtr is null");
-
-               JSCallbackManagerPtr privData =
-                       DPL::DynamicPointerCast<JSCallbackManager>(emitter->getEventPrivateData());
-
-               if(privData == NULL)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "JSCallbackManagerPtr is null");
-
-               JSValueRef callback = privData->getOnSuccess();
-               if(callback == NULL)
-               {
-                       LogDebug("callback is NULL");
-               }
-               else
-               {
-                       LogDebug("callback is not NULL");
-                       return callback;
-               }
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex)
-       {
-               LogWarning("Exception: " << ex.GetMessage());
-       }
-
-       return JSValueMakeNull(context);
+    LogDebug("Enter");  // do nothing
 }
-       
 
-JSValueRef JSBluetoothServiceHandler::getUuid(JSContextRef context,
-                                       JSObjectRef object,
-                                       JSStringRef propertyName,
-                                       JSValueRef* exception)
+void JSBluetoothServiceHandler::finalize(JSObjectRef object)
 {
-       LogDebug("OK"); 
-       
-       try 
-       {
-               JSBluetoothServiceHandlerPriv *priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(object));
-               BluetoothConverter converter(priv->getContext());
-
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(priv->getObject());
-               std::string uuid = BluetoothServiceHandlerManager->getUUID();
-               return converter.toJSValueRef(uuid);
-
-       }       
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LogWarning("Exception: " << ex.GetMessage());
-       }       
-       
-       return JSValueMakeUndefined(context);
-}
-
+    LogDebug("Enter");
 
-JSValueRef JSBluetoothServiceHandler::getName(JSContextRef context,
-                                       JSObjectRef object,
-                                       JSStringRef propertyName,
-                                       JSValueRef* exception)
-{
-       LogDebug("OK"); 
-       
-       try 
-       {
-               JSBluetoothServiceHandlerPriv *priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(object));
-               BluetoothConverter converter(priv->getContext());
-
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(priv->getObject());
-               std::string name = BluetoothServiceHandlerManager->getName();
-               return converter.toJSValueRef(name);
-
-       }       
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LogWarning("Exception"<<ex.GetMessage());
-       }       
-       
-       return JSValueMakeUndefined(context);
+    BluetoothServiceHandlerPtr priv = static_cast<BluetoothServiceHandlerPtr>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
 }
 
-JSValueRef JSBluetoothServiceHandler::getIsConnected(JSContextRef context,
-                                       JSObjectRef object,
-                                       JSStringRef propertyName,
-                                       JSValueRef* exception)
-{
-       LogDebug("OK"); 
-       
-       try 
-       {
-               JSBluetoothServiceHandlerPriv *priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(object));
-               BluetoothConverter converter(priv->getContext());
-
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(priv->getObject());
-               bool connected = BluetoothServiceHandlerManager->getIsConnected();
-               return converter.toJSValueRef(connected);
-
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LogWarning("Exception"<<ex.GetMessage());
-       }       
-
-       return JSValueMakeUndefined(context);
+JSValueRef JSBluetoothServiceHandler::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("Enter");
+
+    try {
+        BluetoothServiceHandlerPtr priv = static_cast<BluetoothServiceHandlerPtr>(JSObjectGetPrivate(object));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL");
+        }
+
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SERVICE_HANDLER_UUID)) {
+            return JSUtil::toJSValueRef(context, priv->getUUID());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SERVICE_HANDLER_NAME)) {
+            return JSUtil::toJSValueRef(context, priv->getName());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SERVICE_HANDLER_IS_CONNECTED)) {
+            return JSUtil::toJSValueRef(context, priv->getConnectionState());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SERVICE_HANDLER_ONCONNECT)) {
+            return priv->getOnConnect(context);
+        }
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed: " << err.getMessage().c_str());
+    }
+
+    return NULL;
 }
 
-const JSClassDefinition* JSBluetoothServiceHandler::getClassInfo() 
-{
-       return &m_classInfo;
+bool JSBluetoothServiceHandler::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogDebug("Enter");
+
+    try {
+        BluetoothServiceHandlerPtr priv = static_cast<BluetoothServiceHandlerPtr>(JSObjectGetPrivate(object));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL");
+        }
+        
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SERVICE_HANDLER_ONCONNECT)) {
+            JSObjectRef object = NULL;
+            if(!JSValueIsNull(context, value)) {
+                if(!JSValueIsObject(context, value)) {
+                    throw TypeMismatchException("Value is not Object");
+                }
+
+                JSValueRef ex = NULL;
+                object = JSValueToObject(context, value, &ex);
+                if(ex){
+                    throw TypeMismatchException("Can't convert to Object");
+                }                
+
+                if(!JSObjectIsFunction(context, object)) {
+                    throw TypeMismatchException("Not function");
+                }
+            }
+            else {
+                LogDebug("onconnect() is NULL");
+            }
+            
+            return priv->setOnConnect(context, object);
+        }
+    } catch (const BasePlatformException &err) {
+        JSWebAPIException::throwException(context, exception, err);
+    }
+
+    return false;
 }
 
-
-
-
-
-void JSBluetoothServiceHandler::finalize(JSObjectRef object) 
-{
-       JSBluetoothServiceHandlerPriv* priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(object));
-       LogDebug("JSBluetoothServiceHandler::Finalrize");
-
-       if (priv != NULL)
-       {
-               JSObjectSetPrivate(object, NULL);
-               LogDebug("Deleting BluetoothManager");
-               delete priv;
-       }
-}
-
-bool JSBluetoothServiceHandler::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
-{
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+JSValueRef JSBluetoothServiceHandler::unregister(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("Enter");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        // Private Object
+        BluetoothServiceHandlerPtr priv = static_cast<BluetoothServiceHandlerPtr>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+
+        ArgumentValidator validator(context, argumentCount, arguments);        
+        JSObjectRef successCallback = validator.toFunction(0, true);  // successCallback  
+        JSObjectRef errorCallback = validator.toFunction(1, true);  // errorCallback
+
+        // perform
+        MultiCallbackUserDataPtr callback(
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
+        if(!callback){
+            throw DeviceAPI::Common::UnknownException("Can't create MultiCallbackUserData");
+        }
+        
+        callback->setCallback("success", successCallback);
+        callback->setCallback("error", errorCallback);
+        priv->unregister(callback);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothServiceHandler.unregister().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSBluetoothServiceHandler::unregisterRFCOMMService(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
-{
 
-       LogDebug("unregisterRFCOMMService");
-       
-       JSValueRef successCallback = NULL;
-       JSValueRef errorCallBack = NULL;
-       JSBluetoothServiceHandlerPriv *priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(thisObject));
-
-       if (priv == NULL)
-       {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }
-       
-       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
-       size_t index = 0;
-       JSValueRef reserveArguments[2];
-       Try     
-       {
-               for (index = 0; index < 2; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);
-               }
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADPATER_UNREGISTER]);
-               
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);  
-       
-
-               BluetoothConverter converter(priv->getContext());
-
-               if (argumentCount >= 1 && JSValueIsUndefined(context, reserveArguments[0]) == false)
-               {
-                       successCallback = converter.toFunctionOrNull(reserveArguments[0]);
-               }
-               
-               if (argumentCount >= 2 && JSValueIsUndefined(context, reserveArguments[1]) == false)
-               {
-                       errorCallBack = converter.toFunctionOrNull(reserveArguments[1]);
-               }
-
-               
-               if (cbm == NULL)
-               {
-                       Throw(UnknownException);        
-               }
-                       
-               cbm->setOnSuccess(successCallback);
-               cbm->setOnError(errorCallBack);
-               
-               IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(priv->getObject());
-               EventBTUnregisterRFCOMMServicePtr event(new EventBTUnregisterRFCOMMService);
-
-               if (BluetoothServiceHandlerManager == NULL || event == NULL)
-               {
-                       LogError("BluetoothAdapterManager or event or listener NULL");
-                       Throw(UnknownException);        
-               }
-
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-               BluetoothAdapterListener& listener = BluetoothAdapterListener::getInstance();
-               event->setForAsynchronousCall(&listener);
-               BluetoothServiceHandlerManager->unRegister(event);
-               
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }               
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogError("InvalidArgumentException");
-               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(priv->getContext(), 
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid values error"));       
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-       }       
-       return JSValueMakeUndefined(context);
-}
-
-
-}
-}
 
+} // Bluetooth
+} // DeviceAPI
index 89b710f..c59540d 100644 (file)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_SERVICE_HANDLER_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_SERVICE_HANDLER_H_
+#ifndef __TIZEN_JS_BLUETOOTH_SERVICE_HANDLER_H__
+#define __TIZEN_JS_BLUETOOTH_SERVICE_HANDLER_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "IBluetoothServiceHandlerManager.h"
-
-using namespace WrtDeviceApis::CommonsJavaScript;
+#include "BluetoothServiceHandler.h"
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef PrivateObjectT<IBluetoothServiceHandlerManagerPtr>::Type JSBluetoothServiceHandlerPriv;
-
-class JSBluetoothServiceHandler 
+class JSBluetoothServiceHandler
 {
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-
-       static JSObjectRef createJSObject(JSContextRef context, std::string name, std::string uuid, int registerSock);
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, BluetoothServiceHandlerPtr service);
 
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
-       static JSValueRef getUuid(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static bool setOnConnect(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
-       static JSValueRef getOnConnect(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-       static void getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
-       static JSValueRef unregisterRFCOMMService(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, 
-               const JSValueRef arguments[], JSValueRef* exception);
-       static JSValueRef getName(JSContextRef context, JSObjectRef object, JSStringRef propertyName,JSValueRef* exception);
-       static JSValueRef getIsConnected(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
-               
-       static JSClassDefinition m_classInfo;
-       static JSStaticValue m_properties[];
-       static JSStaticFunction m_function[];
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static bool setProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+
+    static JSValueRef unregister(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_function[];
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
-}
-} 
 
-#endif
 
+
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index ed4f80a..4ebccad 100644 (file)
 // limitations under the License.
 //
 
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+#include <vector>
+
 #include <SecurityExceptions.h>
-#include "BluetoothFactory.h"
-#include "BluetoothProperty.h"
-#include <dpl/scoped_array.h>
-#include <dpl/scoped_free.h>
-#include "BluetoothSocketListener.h"
-#include "JSBluetoothSocket.h"
-#include "JSBluetoothDevice.h"
-#include "BluetoothMultiCallback.h"
-#include "BluetoothConverter.h"
-#include <bluetooth.h>
+#include <JSUtil.h>
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <PlatformException.h>
+#include <MultiCallbackUserData.h>
+
 #include "plugin_config.h"
-#include "JSUtil.h"
+#include "JSBluetoothSocket.h"
+#include "BluetoothSocket.h"
+#include "BluetoothAdapter.h"
 
-using namespace std;
-using namespace DPL;
-using namespace DeviceAPI::Common;
+#include <Logger.h>
 
+using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
-
-JSClassDefinition JSBluetoothSocket::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "BluetoothSocket",
-       NULL,
-       m_properties,
-       m_function,
-       initialize,
-       finalize,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSBluetoothSocket::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "BluetoothSocket",
+    NULL, //ParentClass
+    m_property, //StaticValues
+    m_function, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-JSStaticValue JSBluetoothSocket::m_properties[] = 
-{
-       {"uuid", getProperty, NULL, kJSPropertyAttributeReadOnly},
-//     {"protocol", getProperty, NULL, kJSPropertyAttributeReadOnly},
-       {"state", getProperty, NULL, kJSPropertyAttributeReadOnly},
-       {"onerror", getCallback, setProperty, kJSPropertyAttributeNone},
-       {"onmessage", getCallback, setProperty, kJSPropertyAttributeNone},
-       {"onclose", getCallback, setProperty, kJSPropertyAttributeNone},
-       {0, 0, 0, 0}
+JSStaticValue JSBluetoothSocket::m_property[] = {
+    { BLUETOOTH_SOCKET_UUID, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SOCKET_STATE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SOCKET_PEER, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SOCKET_ONMESSAGE, getProperty, setProperty, kJSPropertyAttributeNone|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SOCKET_ONCLOSE, getProperty, setProperty, kJSPropertyAttributeNone|kJSPropertyAttributeDontDelete },
+    { BLUETOOTH_SOCKET_ONERROR, getProperty, setProperty, kJSPropertyAttributeNone|kJSPropertyAttributeDontDelete },
+    { 0, 0, 0, 0 }
 };
 
-
-JSStaticFunction JSBluetoothSocket::m_function[] =
-{
-       { "writeData", JSBluetoothSocket::writeData, kJSPropertyAttributeNone },
-       { "readData", JSBluetoothSocket::readData, kJSPropertyAttributeNone },
-       { "close", JSBluetoothSocket::close, kJSPropertyAttributeNone },        
-       { 0, 0, 0 }
+JSStaticFunction JSBluetoothSocket::m_function[] = {
+    { BLUETOOTH_SOCKET_API_WRITE_DATA, writeData, kJSPropertyAttributeNone },
+    { BLUETOOTH_SOCKET_API_READ_DATA, readData, kJSPropertyAttributeNone },
+    { BLUETOOTH_SOCKET_API_CLOSE, close, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
 };
 
-const JSClassRef JSBluetoothSocket::getClassRef() 
-{
-       if (!m_jsClassRef) 
-       {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-const JSClassDefinition* JSBluetoothSocket::getClassInfo() 
-{
-       return &m_classInfo;
-}
-
 JSClassRef JSBluetoothSocket::m_jsClassRef = JSClassCreate(JSBluetoothSocket::getClassInfo());
 
-bool JSBluetoothSocket::setProperty(JSContextRef context, 
-                                       JSObjectRef object,
-                                       JSStringRef propertyName,
-                                       JSValueRef value,
-                                       JSValueRef* exception)
-{
-       LogDebug("OK");
-
-       try
-       {
-               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "private object is null");
-               }
-
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-               BluetoothConverter converter(priv->getContext());
-               if (BluetoothSocketManager == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "BluetoothManager is NULL");
-               }
-
-               EventBTSocketNotificationEmitterPtr emitter = BluetoothSocketManager->getSocketNotifier();
-               if (emitter == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "emitter is NULL");
-               }
-
-               BluetoothSocketNotifierPrivateDataPtr privData =
-                               DPL::DynamicPointerCast<BluetoothSocketNotifierPrivateData>(emitter->getEventPrivateData());
-
-               if (privData == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "BluetoothSocketNotifierPrivateData is NULL");
-               }
-
-               if(JSValueIsNull(context, value) ||
-                       JSObjectIsFunction(context, converter.toJSObjectRef(value)) )
-               {
-                       LogDebug("Callable or null");
-                       converter.setBluetoothSocketNotifierCallback(propertyName, value, object, privData);
-               }
-               else
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Non callable object");
-               }
-               
-               emitter->setListener(&BluetoothSocketListener::getInstance());
-               emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
-
-               return true;
-       }
-       catch (const WrtDeviceApis::Commons::ConversionException& ex)
-       {
-               LogError("Exception: " << ex.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context,
-                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-       }       
-       catch (WrtDeviceApis::Commons::Exception& ex)
-       {
-               LogWarning("Exception: " << ex.GetMessage());
-       }
-
-       return false;
-}
-
-void JSBluetoothSocket::initialize(JSContextRef context, JSObjectRef object) 
+const JSClassRef JSBluetoothSocket::getClassRef()
 {
-       LogDebug("JSBluetoothSocket::initialize ");
-       setAttributesIntoJSObject(context, object);     
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-void JSBluetoothSocket::finalize(JSObjectRef object) 
+const JSClassDefinition* JSBluetoothSocket::getClassInfo()
 {
-       LogDebug("JSBluetoothSocket::Finalrize");
-
-       JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(object));
-
-       if (priv != NULL)
-       {
-               delete priv;
-               JSObjectSetPrivate(object, NULL);
-       }
+    return &m_classInfo;
 }
 
-bool JSBluetoothSocket::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
+JSObjectRef JSBluetoothSocket::createJSObject(JSContextRef context, BluetoothSocketPtr socket)
 {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(socket));
 }
 
-JSObjectRef JSBluetoothSocket::createJSObject(JSContextRef context, BluetoothSocketData socketData)
+void JSBluetoothSocket::initialize(JSContextRef context, JSObjectRef object)
 {
-       IBluetoothSocketManagerPtr BluetoothSocketManager(BluetoothFactory::getInstance().getBluetoothSocketManager());
-       JSBluetoothSocketPriv* priv = new JSBluetoothSocketPriv( context, BluetoothSocketManager);
-       BluetoothSocketManager->setSocketData(socketData);
-
-       try 
-       {
-               if (BluetoothSocketManager == NULL || priv == NULL)
-               {
-                       LogError("BluetoothManager or event or listener NULL");
-                       Throw(WrtDeviceApis::Commons::UnknownException);        
-               }
-
-               BluetoothConverter converter(priv->getContext());
-               EventBTSocketNotificationEmitterPtr emitter(new EventBTSocketNotificationEmitter);
-
-               BluetoothSocketNotifierPrivateDataPtr privData(converter.getInitalBluetoothSocketNotifierPrivateData());
-               emitter->setListener(&BluetoothSocketListener::getInstance());
-               emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
-               
-               if (BluetoothSocketManager->setSocketNotifier(emitter) != BT_ERROR_NONE)
-               {
-                       LogError("callback set error");
-                       Throw(WrtDeviceApis::Commons::UnknownException);        
-               }
-               
-               return JSObjectMake(context, getClassRef(), priv);
-       }
-       catch (WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LogError("Exception: " << ex.GetMessage());
-
-               switch (ex.getCode())
-               {
-               case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
-                       return JSTizenExceptionFactory::makeErrorObject(context,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-               case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
-                       return JSTizenExceptionFactory::makeErrorObject(context,
-                               JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
-               case WrtDeviceApis::Commons::ExceptionCodes::Exception:
-               default:
-                       return JSTizenExceptionFactory::makeErrorObject(context,
-                               JSTizenException::UNKNOWN_ERROR, "Unkown error");
-               }
-       }
-
-       
+    LogDebug("Enter");  // do nothing
 }
 
-JSObjectRef JSBluetoothSocket::createJSObject(JSContextRef context, BluetoothSocketData socketData, EventBTReadDataType readData)
+void JSBluetoothSocket::finalize(JSObjectRef object)
 {
-       IBluetoothSocketManagerPtr BluetoothSocketManager(BluetoothFactory::getInstance().getBluetoothSocketManager());
-       JSBluetoothSocketPriv* priv = new JSBluetoothSocketPriv( context, BluetoothSocketManager);
-       BluetoothSocketManager->setSocketData(socketData);
-       BluetoothSocketManager->setReadData(readData);
-       return JSObjectMake(context, getClassRef(), priv);
+    BluetoothSocketPtr priv = static_cast<BluetoothSocketPtr>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
 }
 
 JSValueRef JSBluetoothSocket::getProperty(JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSStringRef propertyName,
-                                                       JSValueRef* exception)
-{
-       LogDebug("OK");
-
-       
-       Try
-       {
-               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "private object null");
-               }
-
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-               BluetoothConverter converter(priv->getContext());
-               if (BluetoothSocketManager == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "BluetoothManager is NULL");
-               }
-
-               if(JSStringIsEqualToUTF8CString(propertyName, "uuid")) 
-               {
-                       std::string uuid = BluetoothSocketManager->getUUID();
-                       return converter.toJSValueRef(uuid);
-               }
-               else if(JSStringIsEqualToUTF8CString(propertyName, "state")) 
-               {
-                       unsigned short int state = BluetoothSocketManager->getState();
-                       return converter.toBluetoothStateJSValue(state);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSBluetoothSocket::getCallback(JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSStringRef propertyName,
-                                                       JSValueRef* exception)
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
 {
-       LogDebug("OK");
-
-       Try
-       {
-               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "private object null");
-               }
-
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-               BluetoothConverter converter(priv->getContext());
-               if (BluetoothSocketManager == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "BluetoothManager is NULL");
-               }
-
-               EventBTSocketNotificationEmitterPtr emitter = BluetoothSocketManager->getSocketNotifier();
-               if (emitter == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "emitter is NULL");
-               }
-
-               BluetoothSocketNotifierPrivateDataPtr privData =
-                               DPL::DynamicPointerCast<BluetoothSocketNotifierPrivateData>(emitter->getEventPrivateData());
-
-               if (privData == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "privData NULL");
-               }
-
-               if(JSStringIsEqualToUTF8CString(propertyName, "onmessage"))
-               {
-                       JSValueRef callback = privData->getOnMessage()->getOnSuccess();
-                       if(callback == NULL)
-                       {
-                               LogDebug("callback is NULL");
-                       }
-                       else
-                       {
-                               LogDebug("callback is not NULL");
-                               return callback;
-                       }
-               }
-               else if(JSStringIsEqualToUTF8CString(propertyName, "onclose"))
-               {
-                       JSValueRef callback = privData->getOnClose()->getOnSuccess();
-                       if(callback == NULL)
-                       {
-                               LogDebug("callback is NULL");
-                       }
-                       else
-                       {
-                               LogDebug("callback is not NULL");
-                               return callback;
-                       }
-               }
-               else if(JSStringIsEqualToUTF8CString(propertyName, "onerror"))
-               {
-                       JSValueRef callback = privData->getOnError()->getOnSuccess();
-                       if(callback == NULL)
-                       {
-                               LogDebug("callback is NULL");
-                       }
-                       else
-                       {
-                               LogDebug("callback is not NULL");
-                               return callback;
-                       }
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeNull(context);
+    LogDebug("Enter");
+
+    try {
+        BluetoothSocketPtr priv = static_cast<BluetoothSocketPtr>(JSObjectGetPrivate(object));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL");
+        }
+
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_UUID)) {
+            return JSUtil::toJSValueRef(context, priv->getUUID());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_STATE)) {
+            LogDebug("get state");
+            std::string state;
+            if(priv->getConnectionState()) {
+                state = "OPEN";                
+            }
+            else {
+                state = "CLOSED";
+            }
+            LogDebug("state: " << state);
+            return JSUtil::toJSValueRef(context, state);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_PEER)) {
+            return priv->getPeer(context);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_ONMESSAGE)) {
+            return priv->getOnMessage(context);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_ONCLOSE)) {
+            return priv->getOnClose(context);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_ONERROR)) {
+            return priv->getOnError(context);
+        }
+    } catch (const BasePlatformException &err) {
+        LogWarning("Getting property is failed: " << err.getMessage().c_str());
+    }
+
+    return NULL;
 }
 
-
-JSValueRef JSBluetoothSocket::writeData(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+bool JSBluetoothSocket::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
 {
-       LogDebug("JSBluetoothSocket");
-       Converter converter(context);   
-       Try     
-       {
-               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(thisObject));
-
-               if (priv == NULL) 
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-               }
-
-               if (argumentCount < 1)
-               {
-                       LogError("argument wrong");
-                       Throw(WrtDeviceApis::Commons::ConversionException);                             
-               }
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                       bluetoothExportedNames[BLUETOOTH_FUNCTION_API_SOCKET_WRITE_DATA]);
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-               std::vector<char> data = converter.toVectorOfChars(arguments[0]);
-               unsigned int index = 0;
-               
-               if (data.size() == 0)
-               {
-                       LogError("size 0 array passed");
-                       Throw(WrtDeviceApis::Commons::ConversionException);                             
-               }
-
-               DPL::ScopedArray<char> buffer(new char[data.size()]);
-
-               for (index = 0; index < data.size(); index++)
-               {
-                       buffer[index] = data[index];
-               }
-               
-               if (BluetoothSocketManager->writeData(buffer.Get(), data.size()) != BT_ERROR_NONE)
-               {
-                       LogError("BluetoothSocket Write Error");
-                       Throw(WrtDeviceApis::Commons::UnknownException);        
-               }
-               
-               return converter.toJSValueRef(data.size());
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException) 
-       {
-               LogError("permission denied error");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-       }
+    try {
+        BluetoothSocketPtr priv = static_cast<BluetoothSocketPtr>(JSObjectGetPrivate(object));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL");
+        }
+
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_ONMESSAGE)) {
+            JSObjectRef object = NULL;
+            if(!JSValueIsNull(context, value)) {
+                if(!JSValueIsObject(context, value)) {
+                    throw TypeMismatchException("Value is not Object");
+                }
+
+                JSValueRef ex;
+                object = JSValueToObject(context, value, &ex);
+                if(ex){
+                    throw TypeMismatchException("Can't convert to Object");
+                }                
+
+                if(!JSObjectIsFunction(context, object)) {
+                    throw TypeMismatchException("Not function");
+                }
+            }
+            else {
+                LogDebug("onmessage() is NULL");
+            }
+            
+            return priv->setOnMessage(context, object);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_ONCLOSE)) {
+            JSObjectRef object = NULL;
+            if(!JSValueIsNull(context, value)) {
+                if(!JSValueIsObject(context, value)) {
+                    throw TypeMismatchException("Value is not Object");
+                }
+
+                JSValueRef ex;
+                object = JSValueToObject(context, value, &ex);
+                if(ex){
+                    throw TypeMismatchException("Can't convert to Object");
+                }                
+
+                if(!JSObjectIsFunction(context, object)) {
+                    throw TypeMismatchException("Not function");
+                }
+            }
+            else {
+                LogDebug("onclose() is NULL");
+            }
+            
+            return priv->setOnClose(context, object);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_SOCKET_ONERROR)) {
+            JSObjectRef object = NULL;
+            if(!JSValueIsNull(context, value)) {
+                if(!JSValueIsObject(context, value)) {
+                    throw TypeMismatchException("Value is not Object");
+                }
+
+                JSValueRef ex;
+                object = JSValueToObject(context, value, &ex);
+                if(ex){
+                    throw TypeMismatchException("Can't convert to Object");
+                }                
+
+                if(!JSObjectIsFunction(context, object)) {
+                    throw TypeMismatchException("Not function");
+                }
+            }
+            else {
+                LogDebug("onerror() is NULL");
+            }
+            
+            return priv->setOnError(context, object);
+        }
+    } catch (const BasePlatformException &err) {
+        JSWebAPIException::throwException(context, exception, err);
+    }
+
+    return false;
 }
 
-
-JSValueRef JSBluetoothSocket::readData(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothSocket::writeData(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-
-
-       LogDebug("JSBluetoothSocket");
-
-       Try     
-       {
-               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(thisObject));
-               if(!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-                       
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                       bluetoothExportedNames[BLUETOOTH_FUNCTION_API_SOCKET_READ_DATA]);
-               
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-
-               EventBTReadDataType     data = BluetoothSocketManager->readData();
-               int length = data.size();
-               LogDebug("size" << length);
-               BluetoothConverter converter(priv->getContext());
-
-               if (length == 0)
-               {
-                       LogError("BluetoothSocket Read Error");
-                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);        
-               }
-
-
-               JSObjectRef result = converter.toBluetoothByteArray(data);
-               return result;
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException) 
-       {
-               LogError("permission denied error");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-       }       
+    LogDebug("Enter");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SOCKET_API_WRITE_DATA);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        // Private Object
+        BluetoothSocketPtr priv = static_cast<BluetoothSocketPtr>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+    
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        JSObjectRef dataArrayObj  = validator.toArrayObject(0);  // data
+        size_t size = JSGetArrayLength(context, dataArrayObj);
+        char *buffer = new char[size];
+        for(size_t i = 0; i < size; ++i) {
+            JSValueRef element = JSGetArrayElement(context, dataArrayObj, i);
+            buffer[i] = static_cast<char>(JSUtil::JSValueToByte(context, element));
+        }
+        
+        return JSUtil::toJSValueRef(context, priv->writeData(buffer, size));
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothSocket.writeData().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-
-JSValueRef JSBluetoothSocket::close(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) 
+JSValueRef JSBluetoothSocket::readData(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("JSBluetoothSocket");
-
-       Try     
-       {
-               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(thisObject));
-               if(!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
-
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-
-               LogDebug(bluetoothExportedNames[BLUETOOTH_FUNCTION_API_SOCKET_CLOSE]);
-
-               AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                       bluetoothExportedNames[BLUETOOTH_FUNCTION_API_SOCKET_CLOSE]);
-
-
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               if (BluetoothSocketManager->close() != BT_ERROR_NONE)
-               {
-                       Throw(WrtDeviceApis::Commons::UnknownException);        
-               }
-
-               return JSValueMakeNull(context);
-
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException) 
-       {
-               LogError("permission denied error");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogError("UnsupportException");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
-       }                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogError("Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, "unknown error");
-       }               
+    LogDebug("Enter");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SOCKET_API_READ_DATA);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        // Private Object
+        BluetoothSocketPtr priv = static_cast<BluetoothSocketPtr>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+
+        std::vector<signed char> data = priv->readData();
+        return JSUtil::toJSValueRef_(context, data);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothSocket.readData().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
-void JSBluetoothSocket::setAttributesIntoJSObject(JSContextRef context, JSObjectRef object)
+JSValueRef JSBluetoothSocket::close(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       // peer
-       Try
-       {
-               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "private object null");
-               }
-
-               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
-               BluetoothConverter converter(priv->getContext());
-               if (BluetoothSocketManager == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "BluetoothManager is NULL");
-               }
-               
-               BluetoothDeviceData device = BluetoothSocketManager->getPeer();
-               JSUtil::setProperty(context, object, "peer",
-                               JSBluetoothDevice::createJSObject(priv->getContext(), device), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception"<<_rethrown_exception.GetMessage());              
-       }
+    LogDebug("Enter");
+    
+    // Access Check
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SOCKET_API_CLOSE);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Check whether Bluetooth is supported or not
+        if(!BluetoothAdapter::isBluetoothSupported()) {
+            throw DeviceAPI::Common::NotSupportedException("Bluetooth is not supported");
+        }
+    
+        // Private Object
+        BluetoothSocketPtr priv = static_cast<BluetoothSocketPtr>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+
+        priv->close();
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothSocket.close().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
-}
-}
 
+} // Bluetooth
+} // DeviceAPI
index 799323d..7b98871 100644 (file)
 // limitations under the License.
 //
 
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_SOCKET_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_SOCKET_H_
+#ifndef __TIZEN_JS_BLUETOOTH_SOCKET_H__
+#define __TIZEN_JS_BLUETOOTH_SOCKET_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "BTDevice.h"
-#include "IBluetoothSocketManager.h"
+#include "BluetoothSocket.h"
 
-using namespace WrtDeviceApis::CommonsJavaScript;
-  
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef  PrivateObjectT<IBluetoothSocketManagerPtr>::Type JSBluetoothSocketPriv;
-class JSBluetoothSocket 
+class JSBluetoothSocket
 {
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static JSObjectRef createJSObject(JSContextRef context, BluetoothSocketData socketData);
-       static JSObjectRef createJSObject(JSContextRef context, BluetoothSocketData socketData, 
-               EventBTReadDataType readData);
-
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, BluetoothSocketPtr socket);
+    
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception);
-
-       static bool setProperty(JSContextRef context, 
-                                               JSObjectRef object,
-                                               JSStringRef propertyName,
-                                               JSValueRef value,
-                                               JSValueRef* exception);
-
-       static bool setOnConnect(JSContextRef context, JSObjectRef object,
-                                               JSStringRef propertyName, JSValueRef value,
-                                               JSValueRef* exception);
-
-
-       static JSValueRef setSocketNotifier(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSValueRef writeData(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-               
-       static JSValueRef readData(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-               
-       static JSValueRef close(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-
-
-       static JSValueRef getProperty(JSContextRef context,
-                               JSObjectRef object,
-                               JSStringRef propertyName,
-                               JSValueRef* exception);
-
-       static JSValueRef getCallback(JSContextRef context,
-                               JSObjectRef object,
-                               JSStringRef propertyName,
-                               JSValueRef* exception);
-
-       /**
-        * Sets attributes into JS object.
-        */
-       static void setAttributesIntoJSObject(JSContextRef context,
-                       JSObjectRef object);    
-
-       static JSClassDefinition m_classInfo;
-       static JSStaticFunction m_function[];
-       static JSStaticValue m_properties[];
-
-       static JSClassRef m_jsClassRef;
-       
+
+    /**
+     * 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);
+
+    static JSValueRef getProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static bool setProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+
+    static JSValueRef writeData(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef readData(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef close(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_function[];
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-} 
-}
 
-#endif
 
+} // Bluetooth
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index ef2c4b0..0bf9d4c 100644 (file)
@@ -1,26 +1,30 @@
 <?xml version="1.0" ?>
 <!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
 <plugin-properties>
-       <library-name>libwrt-plugins-tizen-bluetooth.so</library-name>
-       <feature-install-uri>bluetooth.install.uri</feature-install-uri>
-       <feature-key-cn>SAMSUNG plugin group</feature-key-cn>
-       <feature-root-cn>SAMSUNG certificate authority</feature-root-cn>
-       <feature-root-fingerprint>AAAABBBBCCCCDDDEEEE0000</feature-root-fingerprint>
-       <api-feature>
-               <name>http://tizen.org/privilege/bluetooth.admin</name>
-               <device-capability>bluetooth.admin</device-capability>
-       </api-feature>
-       <api-feature>
-               <name>http://tizen.org/privilege/bluetooth.gap</name>
-               <device-capability>bluetooth.gap</device-capability>
-       </api-feature>
-       <api-feature>
-               <name>http://tizen.org/privilege/bluetooth.spp</name>
-               <device-capability>bluetooth.spp</device-capability>
-       </api-feature>
-        <api-feature>
-                <name>http://tizen.org/privilege/bluetoothmanager</name>
-                <device-capability>bluetoothmanager</device-capability>
-        </api-feature>
-</plugin-properties>
+    <library-name>libwrt-plugins-tizen-bluetooth.so</library-name>
+    <feature-install-uri>bluetooth.install.uri</feature-install-uri>
+    <feature-key-cn>SAMSUNG plugin group</feature-key-cn>
+    <feature-root-cn>SAMSUNG certificate authority</feature-root-cn>
+    <feature-root-fingerprint>AAAABBBBCCCCDDDEEEE0000</feature-root-fingerprint>
 
+    <api-feature>
+        <name>http://tizen.org/privilege/bluetooth.gap</name>
+        <device-capability>bluetooth.gap</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/bluetooth.admin</name>
+        <device-capability>bluetooth.admin</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/bluetoothmanager</name>
+        <device-capability>bluetoothmanager</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/bluetooth.spp</name>
+        <device-capability>bluetooth.spp</device-capability>
+    </api-feature>
+
+</plugin-properties>
\ No newline at end of file
index 2bc273c..e8e9ec1 100644 (file)
 //
 
 
-#include <map>
-#include <utility>
 #include <Commons/FunctionDefinition.h>
 #include <Commons/FunctionDeclaration.h>
-#include <Commons/Exception.h>
+#include <map>
+
 #include "plugin_config.h"
 
 #define BLUETOOTH_FEATURE_API_ADMIN "http://tizen.org/privilege/bluetooth.admin"
 #define BLUETOOTH_DEVICE_CAP_SPP "bluetooth.spp"
 #define BLUETOOTH_DEVICE_CAP_MANAGER "bluetoothmanager"
 
+using namespace WrtDeviceApis::Commons;
+
 namespace DeviceAPI {
 namespace Bluetooth {
 
-const char* bluetoothExportedNames[] = 
-{
-       "getDefaultAdapter",
-       "setName",
-       "setPowered",
-       "setVisible",
-       "discoverDevices",
-       "stopDiscovery",
-       "getKnownDevices",
-       "getDevice",
-       "createBonding",
-       "destroyBonding",
-       "hasService",
-       "registerRFCOMMServiceByUUID",
-       "unregister",
-       "connectToServiceByUUID",
-       "writeData",
-       "readData",
-       "close"
-};
-
-static WrtDeviceApis::Commons::FunctionMapping createBluetoothFunctions();
-
-static WrtDeviceApis::Commons::FunctionMapping BluetoothFunctions =
-    createBluetoothFunctions();
+static FunctionMapping createBluetoothFunctions();
+static FunctionMapping BluetoothFunctions = createBluetoothFunctions();
 
 DEFINE_FUNCTION_GETTER(Bluetooth, BluetoothFunctions);
 
-static WrtDeviceApis::Commons::FunctionMapping createBluetoothFunctions()
+static FunctionMapping createBluetoothFunctions()
 {
-       using namespace WrtDeviceApis::Commons;
-
-       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_ADMIN, BLUETOOTH_DEVICE_CAP_ADMIN);
-       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_GAP, BLUETOOTH_DEVICE_CAP_GAP);
-       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_SPP, BLUETOOTH_DEVICE_CAP_SPP);
-       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_MANAGER, BLUETOOTH_DEVICE_CAP_MANAGER);
-
-       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_ADMIN);
-       ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_ADMIN, DEVICE_CAP_BLUETOOTH_ADMIN);
-
-       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_GAP);
-       ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_GAP, DEVICE_CAP_BLUETOOTH_GAP);
-
-       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_SPP);
-       ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_SPP, DEVICE_CAP_BLUETOOTH_SPP);
-
-       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_MANAGER);
-       ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_MANAGER, DEVICE_CAP_BLUETOOTH_MANAGER);
-
-       ACE_CREATE_FEATURE(FEATURE_ADMIN, BLUETOOTH_FEATURE_API_ADMIN);
-       ACE_CREATE_FEATURE(FEATURE_GAP, BLUETOOTH_FEATURE_API_GAP);
-       ACE_CREATE_FEATURE(FEATURE_SPP, BLUETOOTH_FEATURE_API_SPP);
-       ACE_CREATE_FEATURE(FEATURE_MANAGER, BLUETOOTH_FEATURE_API_MANAGER);
-
-       ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_ADMIN);
-       ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_ADMIN, FEATURE_ADMIN);
-
-       ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_GAP);
-       ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_GAP, FEATURE_GAP);
-
-       ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_SPP);
-       ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_SPP, FEATURE_SPP);
-
-       ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER);
-       ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_MANAGER);
-       // FEATURE_ADMIN will be remove from BLUETOOTH_FEATURES_BLUETOOTH_MANAGER
-       ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_ADMIN);
-
-       FunctionMapping BluetoothFunctions;
-
-       for (int index = BLUETOOTH_FUNCTION_API_ADAPTER_SET_NAME; 
-               index <= BLUETOOTH_FUNCTION_API_ADAPTER_SET_POWERED; index++)
-       {
-               AceFunction adminLoopFunc = 
-                       ACE_CREATE_FUNCTION(FUNCTION_ADMIN_DUMMY_FUNC_ID, bluetoothExportedNames[index], 
-                       BLUETOOTH_FEATURES_BLUETOOTH_ADMIN, DEVICE_LIST_BLUETOOTH_ADMIN);
-               BluetoothFunctions.insert(std::make_pair(
-                       bluetoothExportedNames[index], adminLoopFunc));
-       }
-
-       AceFunction managerSetVisible =
-               ACE_CREATE_FUNCTION(FUNCTION_ADMIN_DUMMY_FUNC_ID,
-                       bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_SET_VISIBLE],
-                       BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, DEVICE_LIST_BLUETOOTH_MANAGER);
-       BluetoothFunctions.insert(std::make_pair(
-               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_ADAPTER_SET_VISIBLE],
-               managerSetVisible));
-
-       for (int index = BLUETOOTH_FUNCTION_API_ADAPTER_DISCOVER_DEVICES; 
-               index <= BLUETOOTH_FUNCTION_API_BLUETOOTHCLASS_HAS_SERVICE; index++)
-       {
-               AceFunction gapLoopFunc = 
-                       ACE_CREATE_FUNCTION(FUNCTION_GAP_DUMMY_FUNC_ID, bluetoothExportedNames[index],
-                       BLUETOOTH_FEATURES_BLUETOOTH_GAP, DEVICE_LIST_BLUETOOTH_GAP);
-               BluetoothFunctions.insert(std::make_pair(
-                       bluetoothExportedNames[index], gapLoopFunc));
-       }
-
-       // allow getDefaultAdapter for bluetooth.gap feature
-       AceFunction gapDefaultAdapter = 
-               ACE_CREATE_FUNCTION(FUNCTION_GAP_DUMMY_FUNC_ID,
-                       bluetoothExportedNames[BLUETOOTH_FUNCTION_API_MANAGER_GET_DEFAULT_ADAPTER],
-                       BLUETOOTH_FEATURES_BLUETOOTH_GAP, DEVICE_LIST_BLUETOOTH_GAP);
-       BluetoothFunctions.insert(std::make_pair(
-               bluetoothExportedNames[BLUETOOTH_FUNCTION_API_MANAGER_GET_DEFAULT_ADAPTER], 
-               gapDefaultAdapter));
-
-
-       for (int index = BLUETOOTH_FUNCTION_API_ADPATER_REGISTER_RFCOMM; 
-               index <= BLUETOOTH_FUNCTION_API_SOCKET_CLOSE; index++)
-       {
-               AceFunction sppLoopFunc = 
-                       ACE_CREATE_FUNCTION(FUNCTION_SPP_DUMMY_FUNC_ID, bluetoothExportedNames[index],
-                       BLUETOOTH_FEATURES_BLUETOOTH_SPP, DEVICE_LIST_BLUETOOTH_SPP);
-               BluetoothFunctions.insert(std::make_pair(
-                       bluetoothExportedNames[index], sppLoopFunc));
-       }
-
-       return BluetoothFunctions;
-}
-} 
+    /**
+     * Device capabilities
+     */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_ADMIN, BLUETOOTH_DEVICE_CAP_ADMIN);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_ADMIN);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_ADMIN, DEVICE_CAP_BLUETOOTH_ADMIN);
+
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_GAP, BLUETOOTH_DEVICE_CAP_GAP);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_GAP);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_GAP, DEVICE_CAP_BLUETOOTH_GAP);
+
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_SPP, BLUETOOTH_DEVICE_CAP_SPP);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_SPP);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_SPP, DEVICE_CAP_BLUETOOTH_SPP);
+
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_MANAGER, BLUETOOTH_DEVICE_CAP_MANAGER);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_MANAGER);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_MANAGER, DEVICE_CAP_BLUETOOTH_MANAGER);
+    
+    
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_ADMIN, BLUETOOTH_FEATURE_API_ADMIN);
+    ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_ADMIN);
+    ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_ADMIN, FEATURE_ADMIN);
+
+    ACE_CREATE_FEATURE(FEATURE_GAP, BLUETOOTH_FEATURE_API_GAP);
+    ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_GAP);
+    ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_GAP, FEATURE_GAP);
+
+    ACE_CREATE_FEATURE(FEATURE_SPP, BLUETOOTH_FEATURE_API_SPP);
+    ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_SPP);
+    ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_SPP, FEATURE_SPP);
+
+    ACE_CREATE_FEATURE(FEATURE_MANAGER, BLUETOOTH_FEATURE_API_MANAGER);
+    ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER);
+    ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_MANAGER);
+    ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_ADMIN);   // for backward compatibility
+
+
+    /**
+     * Functions
+     */
+    FunctionMapping BluetoothMapping;
+
+    // getDefaultAdapter()
+    AceFunction getDefaultAdapterFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER,
+            BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER,
+            getDefaultAdapterFunc));
+
+    // setName()
+    AceFunction setNameFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_SET_NAME,
+            BLUETOOTH_ADAPTER_API_SET_NAME,
+            BLUETOOTH_FEATURES_BLUETOOTH_ADMIN,
+            DEVICE_LIST_BLUETOOTH_ADMIN);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_SET_NAME,
+            setNameFunc));
+
+    // setPowered()
+    AceFunction setPoweredFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_SET_POWERED,
+            BLUETOOTH_ADAPTER_API_SET_POWERED,
+            BLUETOOTH_FEATURES_BLUETOOTH_ADMIN,
+            DEVICE_LIST_BLUETOOTH_ADMIN);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_SET_POWERED,
+            setPoweredFunc));
+
+    // setVisible()
+    AceFunction setVisibleFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_SET_VISIBLE,
+            BLUETOOTH_ADAPTER_API_SET_VISIBLE,
+            BLUETOOTH_FEATURES_BLUETOOTH_MANAGER,
+            DEVICE_LIST_BLUETOOTH_MANAGER);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_SET_VISIBLE,
+            setVisibleFunc));
+
+    // discoverDevices()
+    AceFunction discoverDevicesFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES,
+            BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES,
+            discoverDevicesFunc));
+
+    //  stopDiscovery()
+    AceFunction  stopDiscoveryFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_STOP_DISCOVERY,
+            BLUETOOTH_ADAPTER_API_STOP_DISCOVERY,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_STOP_DISCOVERY,
+            stopDiscoveryFunc));
+
+    //  getKnownDevices()
+    AceFunction  getKnownDevicesFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES,
+            BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES,
+            getKnownDevicesFunc));
+
+    //  getDevice()
+    AceFunction  getDeviceFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_GET_DEVICE,
+            BLUETOOTH_ADAPTER_API_GET_DEVICE,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_GET_DEVICE,
+            getDeviceFunc));
+
+    //  createBonding()
+    AceFunction  createBondingFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_CREATE_BONDING,
+            BLUETOOTH_ADAPTER_API_CREATE_BONDING,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_CREATE_BONDING,
+            createBondingFunc));
+
+    //  destroyBonding()
+    AceFunction  destroyBondingFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_DESTROY_BONDING,
+            BLUETOOTH_ADAPTER_API_DESTROY_BONDING,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_DESTROY_BONDING,
+            destroyBondingFunc));
+
+    //  registerRFCOMMServiceByUUID()
+    AceFunction  registerRFCOMMServiceByUUIDFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID,
+            BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID,
+            BLUETOOTH_FEATURES_BLUETOOTH_SPP,
+            DEVICE_LIST_BLUETOOTH_SPP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID,
+            registerRFCOMMServiceByUUIDFunc));
+
+    //  connectToServiceByUUID()
+    AceFunction  connectToServiceByUUIDFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID,
+            BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID,
+            BLUETOOTH_FEATURES_BLUETOOTH_SPP,
+            DEVICE_LIST_BLUETOOTH_SPP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID,
+            connectToServiceByUUIDFunc));
+
+    //  writeData()
+    AceFunction  writeDataFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_SOCKET_API_WRITE_DATA,
+            BLUETOOTH_SOCKET_API_WRITE_DATA,
+            BLUETOOTH_FEATURES_BLUETOOTH_SPP,
+            DEVICE_LIST_BLUETOOTH_SPP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_SOCKET_API_WRITE_DATA,
+            writeDataFunc));
+
+    //  readData()
+    AceFunction  readDataFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_SOCKET_API_READ_DATA,
+            BLUETOOTH_SOCKET_API_READ_DATA,
+            BLUETOOTH_FEATURES_BLUETOOTH_SPP,
+            DEVICE_LIST_BLUETOOTH_SPP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_SOCKET_API_READ_DATA,
+            readDataFunc));
+
+    //  close()
+    AceFunction  closeFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_SOCKET_API_CLOSE,
+            BLUETOOTH_SOCKET_API_CLOSE,
+            BLUETOOTH_FEATURES_BLUETOOTH_SPP,
+            DEVICE_LIST_BLUETOOTH_SPP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_SOCKET_API_CLOSE,
+            closeFunc));
+
+    //  hasService()
+    AceFunction  hasServiceFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_CLASS_API_HAS_SERVICE,
+            BLUETOOTH_CLASS_API_HAS_SERVICE,
+            BLUETOOTH_FEATURES_BLUETOOTH_GAP,
+            DEVICE_LIST_BLUETOOTH_GAP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_CLASS_API_HAS_SERVICE,
+            hasServiceFunc));
+
+    //  unregister()
+    AceFunction  unregisterFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER,
+            BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER,
+            BLUETOOTH_FEATURES_BLUETOOTH_SPP,
+            DEVICE_LIST_BLUETOOTH_SPP);
+
+    BluetoothMapping.insert(std::make_pair(
+            BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER,
+            unregisterFunc));
+
+    return BluetoothMapping;
 }
 
-#undef BLUETOOTH_FEATURE_API 
-#undef BLUETOOTH_FEATURE_API_GAP 
-#undef BLUETOOTH_FEATURE_API_SPP 
-#undef BLUETOOTH_DEVICE_CAP_GAP 
-#undef BLUETOOTH_DEVICE_CAP_SPP 
+} // Bluetooth
+} // DeviceAPI
index ba2cd79..3930c9f 100644 (file)
 // limitations under the License.
 //
 
-#ifndef TIZENAPIS_TIZEN_JS_BLUETOOTH_PLUGIN_CONFIG_H_
-#define TIZENAPIS_TIZEN_JS_BLUETOOTH_PLUGIN_CONFIG_H_
 
+#ifndef _BLUETOOTH_PLUGIN_CONFIG_H_
+#define _BLUETOOTH_PLUGIN_CONFIG_H_
+
+#include <string>
 #include <Commons/FunctionDeclaration.h>
 
+#include <Logger.h>
+
 namespace DeviceAPI {
 namespace Bluetooth {
 
-typedef enum 
-{
-BLUETOOTH_FUNCTION_API_MANAGER_GET_DEFAULT_ADAPTER = 0,
-BLUETOOTH_FUNCTION_API_ADAPTER_SET_NAME,
-BLUETOOTH_FUNCTION_API_ADAPTER_SET_POWERED,
-BLUETOOTH_FUNCTION_API_ADAPTER_SET_VISIBLE,
-BLUETOOTH_FUNCTION_API_ADAPTER_DISCOVER_DEVICES,
-BLUETOOTH_FUNCTION_API_ADAPTER_STOP_DISCOVERY,
-BLUETOOTH_FUNCTION_API_ADAPTER_GET_KNOWN_DEVICES,
-BLUETOOTH_FUNCTION_API_ADAPTER_GET_DEVICE,
-BLUETOOTH_FUNCTION_API_ADPATER_CREATE_BONDING,
-BLUETOOTH_FUNCTION_API_ADPATER_DESTROY_BONDING,
-BLUETOOTH_FUNCTION_API_BLUETOOTHCLASS_HAS_SERVICE,
-BLUETOOTH_FUNCTION_API_ADPATER_REGISTER_RFCOMM,
-BLUETOOTH_FUNCTION_API_ADPATER_UNREGISTER,
-BLUETOOTH_FUNCTION_API_DEVICE_CONNECT_TO_SERVICE,
-BLUETOOTH_FUNCTION_API_SOCKET_WRITE_DATA,
-BLUETOOTH_FUNCTION_API_SOCKET_READ_DATA,
-BLUETOOTH_FUNCTION_API_SOCKET_CLOSE,
-} bluetoothFuncNames;
-
-
-extern const char* bluetoothExportedNames[];
+// attributes
+#define BLUETOOTH_MANAGER_DEVICE_MAJOR "deviceMajor"
+#define BLUETOOTH_MANAGER_DEVICE_MINOR "deviceMinor"
+#define BLUETOOTH_MANAGER_DEVICE_SERVICE "deviceService"
+#define BLUETOOTH_ADAPTER_NAME "name"
+#define BLUETOOTH_ADAPTER_ADDRESS "address"
+#define BLUETOOTH_ADAPTER_POWERED "powered"
+#define BLUETOOTH_ADAPTER_VISIBLE "visible"
+#define BLUETOOTH_DEVICE_NAME "name"
+#define BLUETOOTH_DEVICE_ADDRESS "address"
+#define BLUETOOTH_DEVICE_DEVICE_CLASS "deviceClass"
+#define BLUETOOTH_DEVICE_IS_BONDED "isBonded"
+#define BLUETOOTH_DEVICE_IS_TRUSTED "isTrusted"
+#define BLUETOOTH_DEVICE_IS_CONNECTED "isConnected"
+#define BLUETOOTH_DEVICE_UUIDS "uuids"
+#define BLUETOOTH_SOCKET_UUID "uuid"
+#define BLUETOOTH_SOCKET_STATE "state"
+#define BLUETOOTH_SOCKET_PEER "peer"
+#define BLUETOOTH_SOCKET_ONMESSAGE "onmessage"
+#define BLUETOOTH_SOCKET_ONCLOSE "onclose"
+#define BLUETOOTH_SOCKET_ONERROR "onerror"
+#define BLUETOOTH_CLASS_MAJOR "major"
+#define BLUETOOTH_CLASS_MINOR "minor"
+#define BLUETOOTH_CLASS_SERVICES "services"
+#define BLUETOOTH_SERVICE_HANDLER_UUID "uuid"
+#define BLUETOOTH_SERVICE_HANDLER_NAME "name"
+#define BLUETOOTH_SERVICE_HANDLER_IS_CONNECTED "isConnected"
+#define BLUETOOTH_SERVICE_HANDLER_ONCONNECT "onconnect"
+
+// functions
+#define BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER "getDefaultAdapter"
+#define BLUETOOTH_ADAPTER_API_SET_NAME "setName"
+#define BLUETOOTH_ADAPTER_API_SET_POWERED "setPowered"
+#define BLUETOOTH_ADAPTER_API_SET_VISIBLE "setVisible"
+#define BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES "discoverDevices"
+#define BLUETOOTH_ADAPTER_API_STOP_DISCOVERY "stopDiscovery"
+#define BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES "getKnownDevices"
+#define BLUETOOTH_ADAPTER_API_GET_DEVICE "getDevice"
+#define BLUETOOTH_ADAPTER_API_CREATE_BONDING "createBonding"
+#define BLUETOOTH_ADAPTER_API_DESTROY_BONDING "destroyBonding"
+#define BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID "registerRFCOMMServiceByUUID"
+#define BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID "connectToServiceByUUID"
+#define BLUETOOTH_SOCKET_API_WRITE_DATA "writeData"
+#define BLUETOOTH_SOCKET_API_READ_DATA "readData"
+#define BLUETOOTH_SOCKET_API_CLOSE "close"
+#define BLUETOOTH_CLASS_API_HAS_SERVICE "hasService"
+#define BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER "unregister"
 
 DECLARE_FUNCTION_GETTER(Bluetooth);
 
-#define BLUETOOTH_CHECK_ACCESS(functionName)                       \
-    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
-        getBluetoothFunctionData,             \
-        functionName)
+#define BLUETOOTH_CHECK_ACCESS(functionName) \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \
+    getBluetoothFunctionData, \
+    functionName)
+
 }
 }
 
-#endif 
+#endif // _BLUETOOTH_PLUGIN_CONFIG_H_
\ No newline at end of file
index ffe1325..d12f32d 100644 (file)
 // limitations under the License.
 //
 
-#include <dpl/log/log.h>
+
 #include <Commons/plugin_initializer_def.h>
 #include <Commons/WrtAccess/WrtAccess.h>
 
+#include <GlobalContextManager.h>
 
 #include "JSBluetoothManager.h"
-#include "JSBluetoothAdapter.h"
+//#include "BluetoothAdapter.h"
+
+#include <Logger.h>
 
 using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Bluetooth {
 
+
 void on_widget_start_callback(int widgetId)
 {
-       LogDebug("[Tizen\\Bluetooth ] on_widget_start_callback ("<<widgetId<<")");
-       Try
-       {
+    LogDebug("[Tizen\\Bluetooth] on_widget_start_callback (%d)", widgetId);
+    try {
         WrtAccessSingleton::Instance().initialize(widgetId);
-       }
-       Catch(Commons::Exception)
-       {
-               LogError("WrtAccess initialization failed");
-       }
+    } catch (...) {
+        LogError("WrtAccess initialization failed");
+    }
 }
 
 void on_widget_stop_callback(int widgetId)
 {
-       LogDebug("[Tizen\\Bluetooth] on_widget_stop_callback ("<<widgetId<<")");
-       Try
-       {
+    LogDebug("[Tizen\\Bluetooth] on_widget_stop_callback (%d)", widgetId);
+    try {
         WrtAccessSingleton::Instance().deinitialize(widgetId);
-       }
-       Catch(Commons::Exception)
-       {
-               LogError("WrtAccess deinitialization failed");
-       }
+    } catch (...) {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+void on_frame_load_callback(const void *context)
+{
+    LogDebug("[Tizen\\Bluetooth] on_frame_load_callback (%p)", context);
+    GlobalContextManager::getInstance()->addGlobalContext(static_cast<JSContextRef>(context));
+}
+
+void on_frame_unload_callback(const void *context)
+{
+    LogDebug("[Tizen\\Bluetooth] on_frame_unload_callback (%p)", context);
+    GlobalContextManager::getInstance()->removeGlobalContext(static_cast<JSContextRef>(context));
 }
 
 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
-
-#define BLUETOOTH "bluetooth"
-//#define BLUETOOTH_ADAPTER "adapter"
+PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
+PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
 
 PLUGIN_CLASS_MAP_BEGIN
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, BLUETOOTH,
-      (js_class_template_getter)JSBluetoothManager::getClassRef,NULL)
-//PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN "." BLUETOOTH,BLUETOOTH_ADAPTER,
-//      (js_class_template_getter)JSBluetoothAdapter::getClassRef,NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "bluetooth",
+        (js_class_template_getter)JSBluetoothManager::getClassRef,
+        NULL)
 PLUGIN_CLASS_MAP_END
 
-}
-}
-
+} // Bluetooth
+} // DeviceAPI
index 94312b5..4ed6095 100755 (executable)
@@ -21,7 +21,7 @@
 #include <ArgumentValidator.h>
 #include <CommonsJavaScript/Converter.h>
 #include <PlatformException.h>
-#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 #include "JSBookmarkFolder.h"
 #include "BookmarkManager.h"
 #include "BookmarkData.h"
@@ -105,7 +105,7 @@ JSObjectRef JSBookmarkFolder::constructor(JSContextRef ctx, JSObjectRef construc
                std::string title = validator.toString(0);
            return createJSObject(ctx, title);
     } catch(const BasePlatformException& err){
-        JSObjectRef error = JSWebAPIError::makeJSWebAPIError(ctx, err);
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, err);
         *exception = error;
         return error;
     }
@@ -168,7 +168,7 @@ JSValueRef JSBookmarkFolder::getProperty(JSContextRef context, JSObjectRef objec
                        return convert.toJSValueRef(priv->m_title);
                }
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }catch(const WrtDeviceApis::Commons::ConversionException& err){
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "converting fail");    
     }
index 2625fc7..0f287cc 100755 (executable)
@@ -24,7 +24,7 @@
 #include <CommonsJavaScript/Converter.h>
 #include <ArgumentValidator.h>
 #include <PlatformException.h>
-#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 
 using namespace DeviceAPI::Common;
 using namespace WrtDeviceApis::CommonsJavaScript;
@@ -108,7 +108,7 @@ JSObjectRef JSBookmarkItem::constructor(JSContextRef ctx, JSObjectRef constructo
                std::string url = validator.toString(1);
                return createJSObject(ctx, title, url);
     }catch(const BasePlatformException& err){
-        JSObjectRef error = JSWebAPIError::makeJSWebAPIError(ctx, err);
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, err);
         *exception = error;
         return error;
     }
@@ -153,7 +153,7 @@ JSValueRef JSBookmarkItem::getProperty(JSContextRef context, JSObjectRef object,
                        return convert.toJSValueRef(priv->m_url);
                }
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }catch(const WrtDeviceApis::Commons::ConversionException& err){
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "converting fail");    
     }
index 3edc2ce..8467ea8 100755 (executable)
@@ -27,7 +27,7 @@
 #include "plugin_config.h"
 #include <ArgumentValidator.h>
 #include <PlatformException.h>
-#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 #include <CommonsJavaScript/Converter.h>
 
 #include <string>
@@ -142,7 +142,7 @@ JSValueRef JSBookmarkManager::get(JSContextRef ctx, JSObjectRef object, JSObject
                return converter.toJSValueRef(bookmarksArray);
 
     }catch( const BasePlatformException& err){
-        return JSWebAPIError::throwException(ctx, exception, err);
+        return JSWebAPIException::throwException(ctx, exception, err);
     }
 }
 
@@ -193,7 +193,7 @@ JSValueRef JSBookmarkManager::add(JSContextRef ctx, JSObjectRef object, JSObject
                LogDebug("bookmark parent id:" << bookmark->m_parentId);
                
     }catch( const BasePlatformException& err){
-        return JSWebAPIError::throwException(ctx, exception, err);
+        return JSWebAPIException::throwException(ctx, exception, err);
     }
 
     return JSValueMakeUndefined(ctx);
@@ -228,7 +228,7 @@ JSValueRef JSBookmarkManager::remove(JSContextRef ctx, JSObjectRef object, JSObj
         BookmarkManager::getInstance()->remove(searchData);
 
     }catch( const BasePlatformException& err){
-        return JSWebAPIError::throwException(ctx, exception, err);
+        return JSWebAPIException::throwException(ctx, exception, err);
     }
 
     return JSValueMakeUndefined(ctx);
index a74a457..9ff73f7 100755 (executable)
@@ -12,7 +12,7 @@ SET(CMAKE_INSTALL_RPATH
 configure_and_install_pkg(wrt-plugins-tizen-common.pc)
 add_subdir(Common)
 
-set(LIBS_COMMON
+SET(LIBS_COMMON
   ${LIBS_COMMON}
   ${COMMON_TARGET_NAME}
 )
@@ -20,12 +20,33 @@ set(LIBS_COMMON
 add_subdir(Common/StandaloneConsole)
 add_subdir(Common/TimeTracer)
 
-set(LIBS_TEST
+IF(ENABLE_TIME_TRACER)
+SET(LIBS_COMMON
   ${LIBS_COMMON}
-  "standaloneconsole"
   "timetracer"
 )
 
+ENDIF(ENABLE_TIME_TRACER)
+
+SET(LIBS_TEST
+  ${LIBS_COMMON}
+  "standaloneconsole"
+)
+
+#set(LIBS_COMMON
+#  ${LIBS_COMMON}
+#  ${COMMON_TARGET_NAME}
+#)
+#
+#add_subdir(Common/StandaloneConsole)
+#add_subdir(Common/TimeTracer)
+#
+#set(LIBS_TEST
+#  ${LIBS_COMMON}
+#  "standaloneconsole"
+#  "timetracer"
+#)
+
 # -----------------------------------------------------------------------------
 # Plugin Modules
 # -----------------------------------------------------------------------------
index eab3260..35606f0 100755 (executable)
@@ -149,8 +149,8 @@ StringArrayPtr CalendarConverter::toStringArray(const JSValueRef &jsValue)
 {
        StringArrayPtr result = StringArrayPtr(new StringArray());
        if(!JSIsArrayValue(m_context, jsValue)) {
-               LogWarning("StringArray is not an array. Skip this.");
-               return result;
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid string array type.");
        }
 
        JSObjectRef jsObject = toJSObjectRef(jsValue);
@@ -165,8 +165,8 @@ NumberArrayPtr CalendarConverter::toNumberArray(const JSValueRef &jsValue)
 {
        NumberArrayPtr result = NumberArrayPtr(new NumberArray());
        if(!JSIsArrayValue(m_context, jsValue)) {
-               LogWarning("NumberArray is not an array. Skip this.");
-               return result;
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid number array type.");
        }
 
        JSObjectRef jsObject = toJSObjectRef(jsValue);
@@ -181,8 +181,8 @@ NumberArrayPtr CalendarConverter::toTZDateArray(const JSValueRef &jsValue)
 {
        NumberArrayPtr result = NumberArrayPtr(new NumberArray());
        if(!JSIsArrayValue(m_context, jsValue)) {
-               LogWarning("TZDateArray is not an array. Skip this.");
-               return result;
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid TZDate array type.");
        }
 
     TimeUtilConverter timeConverter(m_context);
@@ -192,7 +192,6 @@ NumberArrayPtr CalendarConverter::toTZDateArray(const JSValueRef &jsValue)
         JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
         result->push_back((long long int) (timeConverter.getTimeInMilliseconds(element)/1000));
     }
-    LogDebug("First value: "<<result->at(0));
     return result;
 }
 
@@ -655,6 +654,11 @@ EventAttendeePtr CalendarConverter::toAttendee(JSValueRef attendee)
 
 EventAttendeeListPtr CalendarConverter::toVectorOfAttendeesFromDictionary(JSValueRef attendees)
 {
+       if(!JSIsArrayValue(m_context, attendees)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     EventAttendeeListPtr result(new EventAttendeeList());
 
     JSObjectRef objArg = toJSObjectRef(attendees);
@@ -669,6 +673,11 @@ EventAttendeeListPtr CalendarConverter::toVectorOfAttendeesFromDictionary(JSValu
 
 EventAttendeeListPtr CalendarConverter::toVectorOfAttendeesFromReference(JSValueRef attendees)
 {
+       if(!JSIsArrayValue(m_context, attendees)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     EventAttendeeListPtr result(new EventAttendeeList());
 
     JSObjectRef objArg = toJSObjectRef(attendees);
@@ -721,6 +730,11 @@ EventAlarmPtr CalendarConverter::toEventAlarm(JSValueRef alarm)
 
 EventAlarmListPtr CalendarConverter::toVectorOfEventAlarmsFromDictionary(JSValueRef alarms)
 {
+       if(!JSIsArrayValue(m_context, alarms)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     EventAlarmListPtr result(new EventAlarmList());
 
     JSObjectRef objArg = toJSObjectRef(alarms);
@@ -735,6 +749,11 @@ EventAlarmListPtr CalendarConverter::toVectorOfEventAlarmsFromDictionary(JSValue
 
 EventAlarmListPtr CalendarConverter::toVectorOfEventAlarmsFromReference(JSValueRef alarms)
 {
+       if(!JSIsArrayValue(m_context, alarms)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     EventAlarmListPtr result(new EventAlarmList());
 
     JSObjectRef objArg = toJSObjectRef(alarms);
@@ -817,27 +836,20 @@ CalendarEventPtr CalendarConverter::toItem(const JSValueRef value, bool updateMo
     if (!JSValueIsUndefined(m_context, summaryData)) {
         result->setSubject(toString(summaryData));
     }
-    
+
     //It's important to set startTime before duration to set end date
     if (!JSValueIsUndefined(m_context, startTimeData)) {
         result->setStartTime((long long int) (timeUtilConverter.getTimeInMilliseconds(startTimeData)/1000));
         result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(startTimeData).timezone);
         LogInfo("start time converted from TZDate: "<<result->getStartTime()<<", time zone: "<<result->getTimeZone());
     } else {
-    
-        //set default value, current local time.
-        if(m_calendarType == CalendarEvent::EVENT_TYPE) {
-            //result->setStartTime(std::time(NULL));
-        }
+       LogDebug("Start time undefined.");
     }
 
     if (!JSValueIsUndefined(m_context, durationData)) {
-        long length = timeUtilConverter.getDurationLength(durationData);
+        long long length = timeUtilConverter.getDurationLength(durationData);
         int unit = timeUtilConverter.getDurationUnit(durationData);
         LogDebug("duration length: "<<length<<", unit "<<unit);
-        if (length < 0) {
-            ThrowMsg(ConversionException, "Wrong duration length.");
-        }
         if( MSECS_UNIT==unit ) {
                    result->setEndTime(result->getStartTime() + length/1000);
                } else if( SECONDS_UNIT==unit ) {
@@ -852,6 +864,7 @@ CalendarEventPtr CalendarConverter::toItem(const JSValueRef value, bool updateMo
             ThrowMsg(ConversionException, "Wrong duration unit.");
         }
     }
+
     if (!JSValueIsUndefined(m_context, locationData)) {
         result->setLocation(toString(locationData));
     }
@@ -926,11 +939,16 @@ CalendarEventPtr CalendarConverter::toItem(const JSValueRef value, bool updateMo
     return result;
 }
 
-CalendarEventListPtr CalendarConverter::toVectorOfItems(JSValueRef events)
+CalendarEventListPtr CalendarConverter::toVectorOfItems(JSValueRef items)
 {
+       if(!JSIsArrayValue(m_context, items)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     CalendarEventListPtr result(new CalendarEventList());
 
-    JSObjectRef objArg = toJSObjectRef(events);
+    JSObjectRef objArg = toJSObjectRef(items);
     LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
     for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
         JSValueRef element = JSGetArrayElement(m_context, objArg, i);
@@ -949,11 +967,16 @@ CalendarEventListPtr CalendarConverter::toVectorOfItems(JSValueRef events)
     return result;
 }
 
-CalendarEventListPtr CalendarConverter::toVectorOfItemsFromDictionary(JSValueRef events)
+CalendarEventListPtr CalendarConverter::toVectorOfItemsFromDictionary(JSValueRef items)
 {
+       if(!JSIsArrayValue(m_context, items)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     CalendarEventListPtr result(new CalendarEventList());
 
-    JSObjectRef objArg = toJSObjectRef(events);
+    JSObjectRef objArg = toJSObjectRef(items);
     LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
     for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
         result->push_back(toItem(JSGetArrayElement(m_context, objArg, i), true));
@@ -985,6 +1008,11 @@ EventIdPtr CalendarConverter::toEventId(JSValueRef eventId)
 
 EventIdListPtr CalendarConverter::toVectorOfEventIds(JSValueRef eventIds)
 {
+       if(!JSIsArrayValue(m_context, eventIds)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     EventIdListPtr result(new EventIdList());
 
     JSObjectRef objArg = toJSObjectRef(eventIds);
@@ -1007,6 +1035,11 @@ EventIdListPtr CalendarConverter::toVectorOfEventIds(JSValueRef eventIds)
 
 std::vector<long long int> CalendarConverter::toVectorOfTimeFromTZDate(JSValueRef dates)
 {
+       if(!JSIsArrayValue(m_context, dates)) {
+               LogWarning("JSValue is not an array.");
+        ThrowMsg(ConversionException, "Invalid array type.");
+       }
+
     std::vector<long long int> result;
     TimeUtilConverter converter(m_context);
 
index ebdc6b8..b8f0660 100755 (executable)
@@ -39,8 +39,8 @@ class CalendarConverter : public WrtDeviceApis::CommonsJavaScript::Converter
     virtual ~CalendarConverter();
 
     CalendarEventPtr toItem(const JSValueRef value, bool updateMode=false);
-    CalendarEventListPtr toVectorOfItems(JSValueRef events);
-    CalendarEventListPtr toVectorOfItemsFromDictionary(JSValueRef events);
+    CalendarEventListPtr toVectorOfItems(JSValueRef items);
+    CalendarEventListPtr toVectorOfItemsFromDictionary(JSValueRef items);
     StringArrayPtr toCategories(JSValueRef categories);
     EventAttendeePtr toAttendee(JSValueRef attendee);
     EventAttendeeListPtr toVectorOfAttendeesFromDictionary(JSValueRef attendees);
index c6ad12f..78f6706 100755 (executable)
 
 #include <JavaScriptCore/JavaScript.h>
 #include "SimpleCoordinates.h"
+#include <calendar2.h>
 
 namespace DeviceAPI {
 namespace Calendar {
 
 #define UNDEFINED_CALENDAR_ID -1
 #define UNDEFINED_ITEM_ID -1
-#define UNDEFINED_GEO -1
+#define UNDEFINED_GEO CALENDAR_RECORD_NO_COORDINATE
 #define UNDEFINED_ID "-1"
 
 typedef std::vector<std::string> AttributeList;
index b3348bf..f9f3a1a 100755 (executable)
@@ -22,7 +22,6 @@
 #include <calendar2.h>
 #include <map>
 #include <sstream>
-#include <ctime>
 
 #include "CalendarUtility.h"
 
@@ -199,11 +198,11 @@ void CalendarFilter::visitAttribute(std::string& attrName, DeviceAPI::Tizen::Mat
         LogDebug("Added int filter with id: "<<id);
     } else if(CALENDAR_FILTER_ATTRIBUTE_LAST_MODIFIED_DATE==attrName ||
         CALENDAR_FILTER_ATTRIBUTE_COMPLETED_DATE==attrName) {
-               std::time_t time = getTimeTFromTZDateAny(matchValue);
+               long long int time = getTimeTFromTZDateAny(matchValue);
         if(CalendarEvent::TASK_TYPE==m_type) {
-            calendar_filter_add_lli(m_filter, m_taskAttributeMap[attrName], intMatchFlag, (long long int) time);
+            calendar_filter_add_lli(m_filter, m_taskAttributeMap[attrName], intMatchFlag, time);
         } else {
-            calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], intMatchFlag, (long long int) time);
+            calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], intMatchFlag, time);
         }
         LogDebug("Added lli filter with value: "<<time);
     } else if(CALENDAR_FILTER_ATTRIBUTE_DESCRIPTION==attrName ||
@@ -227,8 +226,8 @@ void CalendarFilter::visitAttribute(std::string& attrName, DeviceAPI::Tizen::Mat
         CALENDAR_FILTER_ATTRIBUTE_DUE_DATE==attrName ||
         CALENDAR_FILTER_ATTRIBUTE_END_DATE==attrName) {
         calendar_time_s calTime = {CALENDAR_TIME_UTIME, {0}};
-        std::time_t time = getTimeTFromTZDateAny(matchValue);
-        calTime.time.utime = (long long int) time;
+        long long int time = getTimeTFromTZDateAny(matchValue);
+        calTime.time.utime = time;
         if(CalendarEvent::TASK_TYPE==m_type) {
             calendar_filter_add_caltime(m_filter, m_taskAttributeMap[attrName], intMatchFlag, calTime);
         } else {
@@ -321,12 +320,12 @@ void CalendarFilter::visitAttributeRange(std::string& attrName, DeviceAPI::Tizen
         calendar_time_s startTimeAllday = {CALENDAR_TIME_LOCALTIME, {0}};
         calendar_time_s endTimeAllday = {CALENDAR_TIME_LOCALTIME, {0}};
         if (!initialValue->isNullOrUndefined()) {
-            startTime.time.utime = (long long int) (getTimeTFromTZDateAny(initialValue));
-                       startTimeAllday.time.date = CalendarUtility::LLIToCalTime(NULL, (long long int) (getTimeTFromTZDateAny(initialValue))).time.date;
+            startTime.time.utime = getTimeTFromTZDateAny(initialValue);
+                       startTimeAllday.time.date = CalendarUtility::LLIToCalTime(NULL, getTimeTFromTZDateAny(initialValue)).time.date;
         }
         if (!endValue->isNullOrUndefined()) {
-            endTime.time.utime = (long long int) (getTimeTFromTZDateAny(endValue));
-                       endTimeAllday.time.date = CalendarUtility::LLIToCalTime(NULL, (long long int) (getTimeTFromTZDateAny(endValue))).time.date;
+            endTime.time.utime = getTimeTFromTZDateAny(endValue);
+                       endTimeAllday.time.date = CalendarUtility::LLIToCalTime(NULL, getTimeTFromTZDateAny(endValue)).time.date;
         }
         if(CalendarEvent::TASK_TYPE==m_type) {
                        calendar_filter_h subFilter = NULL;
@@ -500,23 +499,23 @@ void CalendarFilter::visitAttributeRange(std::string& attrName, DeviceAPI::Tizen
         CALENDAR_FILTER_ATTRIBUTE_LAST_MODIFIED_DATE==attrName) {
         if(CalendarEvent::TASK_TYPE==m_type) {
             if (!initialValue->isNullOrUndefined()) {
-                calendar_filter_add_lli(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, (long long int)(getTimeTFromTZDateAny(initialValue)));
+                calendar_filter_add_lli(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, getTimeTFromTZDateAny(initialValue));
             }
             if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
                 calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
             }
             if (!endValue->isNullOrUndefined()) {
-                calendar_filter_add_lli(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, (long long int)(getTimeTFromTZDateAny(endValue)));
+                calendar_filter_add_lli(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, getTimeTFromTZDateAny(endValue));
             }
         } else {
             if (!initialValue->isNullOrUndefined()) {
-                calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, (long long int)(getTimeTFromTZDateAny(initialValue)));
+                calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, getTimeTFromTZDateAny(initialValue));
             }
             if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
                 calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
             }
             if (!endValue->isNullOrUndefined()) {
-                calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, (long long int)(getTimeTFromTZDateAny(endValue)));
+                calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, getTimeTFromTZDateAny(endValue));
             }
         }
         LogDebug("Added lli range filter with initial value: "<<getTimeTFromTZDateAny(initialValue)<<", end value: "<<getTimeTFromTZDateAny(endValue));
@@ -734,9 +733,9 @@ int CalendarFilter::convertStringToIntValue(const std::string attrName, const st
     return -1;
 }
 
-std::time_t CalendarFilter::getTimeTFromTZDateAny(DeviceAPI::Tizen::AnyPtr &any) const
+long long int CalendarFilter::getTimeTFromTZDateAny(DeviceAPI::Tizen::AnyPtr &any) const
 {
-       std::time_t *pt = static_cast<time_t*>(any->getPriv());
+       long long int *pt = static_cast<long long int *>(any->getPriv());
 
        return *pt;
 }
index 5af1540..21106f9 100755 (executable)
@@ -117,7 +117,7 @@ public:
 private:
        int convertStringToIntValue(const std::string attrName, const std::string valueString);
 
-       std::time_t getTimeTFromTZDateAny(DeviceAPI::Tizen::AnyPtr &any) const;
+       long long int getTimeTFromTZDateAny(DeviceAPI::Tizen::AnyPtr &any) const;
 };
 
 typedef DPL::SharedPtr<CalendarFilter> CalendarFilterPtr;
old mode 100644 (file)
new mode 100755 (executable)
index ec40f3a..915c76a
 // limitations under the License.
 //
 
-/**
- * @file        CalendarFilterConverter.cpp
- * @author      Kisub Song (kisubs.song@samsung.com)
- * @version     0.1
- * @description        Reference from CalendarConverter.cpp
- */
 
 #include "CalendarFilterConverter.h"
 
@@ -33,12 +27,13 @@ namespace DeviceAPI {
 namespace Calendar {
 
 using namespace DeviceAPI::Tizen;
-using namespace DeviceAPI::Time;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
 using namespace std;
 
+void anyPrivFinalizerFunc(void *priv);
+
 static PropertyStructArray properties =
 {
                { CALENDAR_FILTER_ATTRIBUTE_ID_UID,             PrimitiveType_String},
@@ -75,12 +70,10 @@ set<string> CalendarFilterConverter::sCustomAttributeNames = {
 CalendarFilterConverter::CalendarFilterConverter(JSContextRef context) :
                FilterConverter(context, properties, false)
 {
-       LogDebug("entered");
 }
 
 CalendarFilterConverter::~CalendarFilterConverter()
 {
-       LogDebug("entered");
 }
 
 void CalendarFilterConverter::toAnyCustom(const JSValueRef& arg, const std::string &attrName, AnyPtr& any) const
@@ -92,13 +85,18 @@ void CalendarFilterConverter::toAnyCustom(const JSValueRef& arg, const std::stri
        {
                DeviceAPI::Time::TimeUtilConverter timeConverter(m_context);
 
-               time_t *ptTime = new time_t;
-               tm tmTime = timeConverter.toTZDateTime(arg);
-               *ptTime = mktime(&tmTime);
-               any->setPriv(static_cast<void *>(ptTime), true);
+               long long int *lli = new long long int;
+               *lli = (long long int) (timeConverter.getTimeInMilliseconds(arg)/1000);
+               any->setPriv(static_cast<void *>(lli), anyPrivFinalizerFunc);
        }
 }
 
+void anyPrivFinalizerFunc(void *priv)
+{
+       if(priv)
+               delete(static_cast<long long int *>(priv));
+}
+
 } // Tizen
 } // DeviceAPI
 
old mode 100644 (file)
new mode 100755 (executable)
index 1bd3d7a..d3c626c
 // limitations under the License.
 //
 
-/**
- * @file        CalendarFilterConverter.h
- * @version     0.1
- * @description        Reference from CalendarConverter.h
- */
 
 #ifndef _TIZEN_CALENDAR_FILTER_CONVERTER_H_
 #define _TIZEN_CALENDAR_FILTER_CONVERTER_H_
index 7ae384b..2f03209 100755 (executable)
@@ -675,11 +675,53 @@ void EventWrapper::setRecurrenceRuleToPlatformEvent()
 
 void EventWrapper::setAlarmsToPlatformEvent()
 {
-    if( 0 != m_abstractEvent->getAlarms()->size() ) {
-        int ret;
-        calendar_record_h alarm = NULL;
+       // Remove the preset child alarms before adding new ones.
+    int ret;
+    unsigned int count = 0, i;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_todo.calendar_alarm, &count);
+    } else {
+        ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_event.calendar_alarm, &count);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get alarms count: "<<ret);
+    }
 
-        for( unsigned int i=0; i<m_abstractEvent->getAlarms()->size(); i++ )
+    if(0==count) {
+        LogDebug("No alarms to remove.");
+    } else {
+        LogDebug("Number of alarms to remove: "<<count);
+    }
+
+    calendar_record_h alarm = NULL;
+    for(i=0; i<count; i++) {
+               alarm = NULL;
+               // Be careful about the index. We always insert 0 cause the child list is updated every time we remove one.
+        if(CalendarEvent::TASK_TYPE==getType()) {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_alarm, 0, &alarm);
+        } else {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_alarm, 0, &alarm);
+        }
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't get the alarm: "<<ret);
+            continue;
+        }
+
+        if(CalendarEvent::TASK_TYPE==getType()) {
+            ret = calendar_record_remove_child_record(m_platformEvent, _calendar_todo.calendar_alarm, alarm);
+        } else {
+            ret = calendar_record_remove_child_record(m_platformEvent, _calendar_event.calendar_alarm, alarm);
+        }
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't remove the alarm: "<<ret);
+            continue;
+        }
+    }
+
+       // Now add the new alarms.
+    if( 0 != m_abstractEvent->getAlarms()->size() ) {
+        for( i=0; i<m_abstractEvent->getAlarms()->size(); i++ )
         {
             LogDebug("Set the alarms #"<<i);
 
@@ -977,13 +1019,55 @@ void EventWrapper::setUIdToPlatformEvent()
 
 void EventWrapper::setAttendeesToPlatformEvent()
 {
+       // Remove the preset child attendees before adding new ones.
+    int ret;
+    unsigned int count = 0, i;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_todo.calendar_attendee, &count);
+    } else {
+        ret = calendar_record_get_child_record_count(m_platformEvent, _calendar_event.calendar_attendee, &count);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get attendees count: "<<ret);
+    }
+
+    if(0==count) {
+        LogDebug("No attendees to remove.");
+    } else {
+        LogDebug("Number of attendees to remove: "<<count);
+    }
+
+    calendar_record_h attendee = NULL;
+    for(i=0; i<count; i++) {
+               attendee = NULL;
+               // Be careful about the index. We always insert 0 cause the child list is updated every time we remove one.
+        if(CalendarEvent::TASK_TYPE==getType()) {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_attendee, 0, &attendee);
+        } else {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_attendee, 0, &attendee);
+        }
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't get the attendee: "<<ret);
+            continue;
+        }
+
+        if(CalendarEvent::TASK_TYPE==getType()) {
+            ret = calendar_record_remove_child_record(m_platformEvent, _calendar_todo.calendar_attendee, attendee);
+        } else {
+            ret = calendar_record_remove_child_record(m_platformEvent, _calendar_event.calendar_attendee, attendee);
+        }
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't remove the attendee: "<<ret);
+            continue;
+        }
+    }
+
+       // Now add the new attendees.
     EventAttendeeListPtr attendeeList  = m_abstractEvent->getAttendees();
 
     if( 0!=attendeeList->size() ) {
-        int ret;
-        calendar_record_h attendee = NULL;
-
-        for (size_t i = 0; i < attendeeList->size(); ++i) {
+        for (i = 0; i < attendeeList->size(); ++i) {
             LogDebug("Adding attendee "<<i+1<<" over "<<attendeeList->size());
 
             attendee = NULL;
@@ -1498,7 +1582,11 @@ void EventWrapper::setRecurrenceRuleFromPlatformEvent()
         LogWarning("Can't get recurrence end date: "<<ret);
     }
        if(cal.time.utime>0) {
-           rrule->setEndDate(cal.time.utime);
+               if(CALENDAR_RECORD_NO_UNTIL==cal.time.utime) {
+                       rrule->setEndDate(UNDEFINED_TIME);
+               } else {
+                   rrule->setEndDate(cal.time.utime);
+               }
        } else {
                rrule->setEndDate(UNDEFINED_TIME);
        }
index 646bc5b..42e18c0 100755 (executable)
@@ -800,11 +800,16 @@ JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
 {
     Try
     {
-        CalendarEventPtr event = getPrivateObject(object);
+        CalendarEventPtr item = getPrivateObject(object);
+
+               if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
+                       LogDebug("Start or end time is not defined.");
+                   return JSValueMakeUndefined(context);
+               }
 
         TimeUtilConverter converter(context);
-        long length = event->getEndTime() - event->getStartTime(); // in seconds only
-        LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
+        long long length = item->getEndTime() - item->getStartTime(); // in seconds only
+        LogDebug("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
         return converter.makeMillisecondDurationObject( length*1000 );
     }
     Catch(Exception)
index 2473f70..aaa4e73 100755 (executable)
@@ -235,7 +235,11 @@ JSValueRef JSCalendarRecurrenceRule::getProperty(JSContextRef context,
                 return timeConverter.toJSValueRefTZDate((double)(rrule->getEndDate()*1000.0), rrule->getTimeZone());
             }
         } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_OCCURRENCE_COUNT)) {
-            return converter.toJSValueRefLong(rrule->getOccurrenceCount());
+               if(0<rrule->getOccurrenceCount()) {
+                   return converter.toJSValueRefLong(rrule->getOccurrenceCount());
+                       } else {
+                               return converter.toJSValueRefLong(-1);
+                       }
         //} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_MONTH)) {
             //return converter.toJSValueRef(rrule->getDaysOfTheMonth());
         } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_WEEK)) {
index a67b29b..12ed034 100755 (executable)
@@ -31,6 +31,9 @@
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
 #include <JSUtil.h>
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+
 
 #include "JSCallHistoryEntry.h"
 #include "JSCallHistory.h"
@@ -145,6 +148,29 @@ JSValueRef JSCallHistory::find(JSContextRef context, JSObjectRef object, JSObjec
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+       bool bSuccess = false;
+       bool bError = false;
+
+
+    try{
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+               JSObjectRef successCB = validator.toFunction(0);
+               if(successCB)
+                       bSuccess = true;
+
+               JSObjectRef errCB = validator.toFunction(1, true);
+               if(errCB)
+                       bError = true;
+
+               unsigned long limit = validator.toULong(4, true);
+               unsigned long offset = validator.toULong(5, true);
+
+    }catch(const BasePlatformException& err){
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+
        if (argumentCount < 1) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
        }
@@ -202,7 +228,12 @@ JSValueRef JSCallHistory::find(JSContextRef context, JSObjectRef object, JSObjec
                if (argumentCount >= 3) {
                        if (!check.isNullOrUndefined(arguments[2])) {
                                FilterPtr filter = filterConverter->toFilter(arguments[2]);
-                               event ->setFilter(filter);
+
+                               if(filter == NULL){
+                                       throw DeviceAPI::Common::TypeMismatchException("Invalid Filter");
+                               }else{
+                                       event ->setFilter(filter);
+                               }
                        }
                }
 
@@ -225,6 +256,8 @@ JSValueRef JSCallHistory::find(JSContextRef context, JSObjectRef object, JSObjec
                }
                callHistory->find(event);
                CallHistoryAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, gContext);
+       } catch(const BasePlatformException& err) {
+               return JSWebAPIError::throwException(context, exception, err);
        } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
        } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
@@ -246,6 +279,18 @@ JSValueRef JSCallHistory::remove(JSContextRef context, JSObjectRef object, JSObj
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+
+    try{
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        JSObjectRef entryObj = validator.toObject(0);
+
+    }catch(const BasePlatformException& err){
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+
+
        if (argumentCount < 1) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
        }
@@ -287,6 +332,17 @@ JSValueRef JSCallHistory::removeBatch(JSContextRef context, JSObjectRef object,
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+    try{
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        JSObjectRef entryObj = validator.toObject(0);
+        JSObjectRef successCB = validator.toFunction(1, true);
+        JSObjectRef errCB = validator.toFunction(2, true);
+
+    }catch(const BasePlatformException& err){
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
        if (argumentCount < 1) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
        }
@@ -369,6 +425,17 @@ JSValueRef JSCallHistory::removeAll(JSContextRef context, JSObjectRef object, JS
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+    try{
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        JSObjectRef successCB = validator.toFunction(0, true);
+               JSObjectRef errCB = validator.toFunction(1, true);
+
+    }catch(const BasePlatformException& err){
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+
        JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(thisObject));
 
        if (!priv) {
@@ -434,6 +501,15 @@ JSValueRef JSCallHistory::addChangeListener(JSContextRef context, JSObjectRef ob
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+    try{
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        JSObjectRef observerObj = validator.toObject(0);
+
+    }catch(const BasePlatformException& err){
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
        if (argumentCount < 1) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
        }
@@ -486,6 +562,15 @@ JSValueRef JSCallHistory::removeChangeListener(JSContextRef context, JSObjectRef
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+    try{
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        long handle = validator.toLong(0);
+
+    }catch(const BasePlatformException& err){
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
        if (argumentCount < 1) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
        }
index 9219327..119746d 100755 (executable)
@@ -52,7 +52,7 @@ JSClassDefinition JSCallHistoryEntry::m_classInfo = {
        finalize,
        NULL,     //HasProperty,
        getProperty,
-       NULL,     //SetProperty,
+       setProperty, // NULL,     //SetProperty,
        NULL,     //DeleteProperty,
        NULL,     //GetPropertyNames,
        NULL,     //CallAsFunction,
@@ -166,7 +166,7 @@ JSValueRef JSCallHistoryEntry::getProperty(JSContextRef context,
        } catch(const WrtDeviceApis::Commons::Exception& ex) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
        }
-       return JSValueMakeUndefined(context);
+       return NULL;
 }
 
 bool JSCallHistoryEntry::setProperty(JSContextRef context,
@@ -192,22 +192,11 @@ bool JSCallHistoryEntry::setProperty(JSContextRef context,
                                        if((entryInfo->getDirection().compare(STR_MISSED_NEW) == 0) && (direction.compare(STR_MISSED) == 0)) {
                                                callHistoryEntry->setMarkSeen(entryInfo->getEntryId());
                                                entryInfo->setDirection(STR_MISSED);
-                                       } else {
-                                               Throw(WrtDeviceApis::Commons::ConversionException);
                                        }
-
                                        return true;
-                               } else {
-                                       Throw(WrtDeviceApis::Commons::Exception);
                                }
-                       } else {
-                               Throw(WrtDeviceApis::Commons::Exception);
                        }
-               } else {
-                       Throw(WrtDeviceApis::Commons::ConversionException);
-               }
-       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
-               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+               } 
        } catch (const WrtDeviceApis::Commons::Exception& ex) {
                JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
        }
index 3b35b12..8a87b2d 100755 (executable)
@@ -48,7 +48,7 @@ JSClassDefinition JSRemoteParty::m_classInfo = {
        finalize,
        NULL,     //HasProperty,
        getProperty,
-       NULL,     //SetProperty,
+       setProperty, // NULL,     //SetProperty,
        NULL,     //DeleteProperty,
        NULL,     //GetPropertyNames,
        NULL,     //CallAsFunction,
@@ -142,9 +142,19 @@ JSValueRef JSRemoteParty::getProperty(JSContextRef context,
        } catch(const WrtDeviceApis::Commons::Exception& ex) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
        }
-       return JSValueMakeUndefined(context);
+       return NULL;
 }
 
+bool JSRemoteParty::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       return false;
+}
+
+
 bool JSRemoteParty::hasInstance(JSContextRef context,
        JSObjectRef constructor,
        JSValueRef possibleInstance,
index 9019f4c..9069ad4 100755 (executable)
@@ -51,6 +51,12 @@ private:
                JSStringRef propertyName,
                JSValueRef* exception);
 
+       static bool setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception);
+
        static bool hasInstance(JSContextRef context,
                JSObjectRef constructor,
                JSValueRef possibleInstance,
old mode 100755 (executable)
new mode 100644 (file)
index 5d4308d..9a3957b
 #include "JSUtil.h"
 #include <CommonsJavaScript/Converter.h>
 
+#include <limits>
 #include <dlog.h>
 #include <math.h>
+#include <stdarg.h>
+
 
 #undef LOG_TAG
 #define LOG_TAG "TIZEN_DEVICEAPI"
@@ -56,40 +59,49 @@ JSValueRef ArgumentValidator::getArgument(int index, bool nullable) const{
 
 double ArgumentValidator::toNumber(int index, bool nullable, double defaultvalue) const{
     JSValueRef value = getArgument(index, nullable);
-    JSValueRef exception = NULL;
     if( JSValueIsNull(mContext, value) && nullable){
         return defaultvalue;
     }
-    double numberValue = JSValueToNumber(mContext, value, &exception);
-    if(exception != NULL){
-        throw TypeMismatchException(mContext, exception);
-    }
-    return numberValue;
+    return JSUtil::JSValueToNumber(mContext, value);
 }
 
 long ArgumentValidator::toLong(int index, bool nullable, long defaultvalue) const{
     return static_cast<long>(toLongLong(index,nullable,defaultvalue));
 }
 
-unsigned long ArgumentValidator::toULong(int index, bool nullable, long defaultvalue) const{
-    return static_cast<unsigned long>(toULongLong(index,nullable,defaultvalue));
+signed char ArgumentValidator::toByte(int index, bool nullable, signed char defaultvalue) const{
+    return static_cast<signed char>(toLong(index,nullable,defaultvalue));
+}
+
+unsigned char ArgumentValidator::toOctet(int index, bool nullable, unsigned char defaultvalue) const{
+    return static_cast<unsigned char>(toULong(index,nullable,defaultvalue));
+}
+
+unsigned long ArgumentValidator::toULong(int index, bool nullable, unsigned long defaultvalue) const{
+    double number = toNumber(index,nullable,defaultvalue);
+    if( number < 0 )
+        return static_cast<unsigned long>(static_cast<long>(number));
+    return static_cast<unsigned long>(number);
 }
 
 long long ArgumentValidator::toLongLong(int index, bool nullable, long long defaultvalue) const{
     return static_cast<long long>(toNumber(index,nullable,defaultvalue));
 }
 
-unsigned long long ArgumentValidator::toULongLong(int index, bool nullable, long long defaultvalue) const{
-    return static_cast<unsigned long long>(toNumber(index,nullable,defaultvalue));
+unsigned long long ArgumentValidator::toULongLong(int index, bool nullable, unsigned long long defaultvalue) const{
+    double number = toNumber(index,nullable,defaultvalue);
+    if( number < 0 )
+        return static_cast<unsigned long long>(static_cast<long long>(number));
+    return static_cast<unsigned long long>(number);
 }
 
 
 double ArgumentValidator::toDouble(int index, bool nullable, double defaultvalue) const{
-    double doublevalue = toNumber(index,nullable,defaultvalue);
-    if( isnan(doublevalue)){
-        throw TypeMismatchException("Value is not number");
+    JSValueRef value = getArgument(index, nullable);
+    if( JSValueIsNull(mContext, value) && nullable){
+        return defaultvalue;
     }
-    return doublevalue;
+    return JSUtil::JSValueToDouble(mContext, value);
 }
 
 std::string ArgumentValidator::toString(int index, bool nullable, const  string & defaultvalue) const{
@@ -256,6 +268,30 @@ std::map<std::string, std::string> ArgumentValidator::toStringMap(int index, boo
     return JSUtil::JSValueToStringMap(mContext, value);
 }
 
+JSObjectRef ArgumentValidator::toCallbackObject(int index, bool nullable, const char *callback, ...) const{
+    JSObjectRef obj = toObject(index, nullable);
+    if( obj == NULL && nullable){
+        return NULL;
+    }
+    va_list var_args;
+    va_start (var_args, callback);
+    const char * check = callback;
+    while( check != NULL ){
+        JSStringRef propertyName = JSStringCreateWithUTF8CString(check);
+        bool has = JSObjectHasProperty(mContext, obj, propertyName);
+        JSStringRelease(propertyName);
+        if( has ){
+            JSObjectRef o = JSUtil::JSValueToObject(mContext, JSUtil::getProperty(mContext, obj, check));
+            if( !JSObjectIsFunction(mContext, o) ){
+                throw TypeMismatchException("Property is not function object");
+            }
+        }
+        check = static_cast<const char *>(va_arg(var_args, const char *));
+    }
+    return obj;
+}
+
+
 
 }
 }
old mode 100755 (executable)
new mode 100644 (file)
index 32fa109..a38f05a
@@ -32,12 +32,14 @@ public:
     ArgumentValidator(JSContextRef ctx, int argc, const JSValueRef* argv);
     ~ArgumentValidator();
 
-    double toNumber(int index, bool nullable = false, double defaultvalue = 0) const;
+    double toNumber(int index, bool nullable = false, double defaultvalue = 0.0) const;
     long toLong(int index, bool nullable = false, long defaultvalue = 0) const;
-    unsigned long toULong(int index, bool nullable = false, long defaultvalue = 0) const;
+    unsigned long toULong(int index, bool nullable = false, unsigned long defaultvalue = 0) const;
     long long toLongLong(int index, bool nullable = false, long long defaultvalue = 0) const;
-    unsigned long long toULongLong(int index, bool nullable = false, long long defaultvalue = 0) const;
-    double toDouble(int index, bool nullable = false, double defaultvalue = 0) const;
+    unsigned long long toULongLong(int index, bool nullable = false, unsigned long long defaultvalue = 0) const;
+    double toDouble(int index, bool nullable = false, double defaultvalue = 0.0) const;
+    signed char toByte(int index, bool nullable = false, signed char defaultvalue = 0) const;
+    unsigned char toOctet(int index, bool nullable = false, unsigned char defaultvalue = 0) const;
     std::string toString(int index, bool nullable = false, const std::string& defaultvalue = "") const;
     bool toBool(int index, bool nullable = false, bool defaultvalue = false) const;
     time_t toTimeT(int index, bool nullable = false, time_t defaultvalue = 0) const;
@@ -47,6 +49,8 @@ public:
     JSObjectRef toArrayObject(int index, bool nullable = false) const;
     JSValueRef toJSValueRef(int index, bool nullable = false) const;
 
+    JSObjectRef toCallbackObject(int index, bool nullable, const char *callback, ...) const;
+
     std::vector<std::string> toStringVector(int index, bool nullable = false) const;
     std::vector<long> toLongVector(int index, bool nullable = false) const;
     std::vector<double> toDoubleVector(int index, bool nullable = false) const;
index 4d59e03..9f7c67c 100755 (executable)
@@ -3,6 +3,7 @@ SET(SRCS
   TizenExceptionData.cpp
   JSTizenExceptionFactory.cpp
   JSWebAPIError.cpp
+  JSWebAPIException.cpp
   CallbackUserData.cpp
   GlobalContextManager.cpp
   ArgumentValidator.cpp
index 08e9413..19f8ffd 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "TizenExceptionData.h"
 #include "JSWebAPIError.h"
+#include "JSWebAPIException.h"
 
 namespace DeviceAPI {
 namespace Common {
@@ -45,10 +46,10 @@ namespace Common {
                JSValueRef JSTizenExceptionFactory::postException(JSContextRef context, JSValueRef* exception, const std::string& name, const std::string& message) {
                        Assert(exception && "Exception object can't be NULL.");
 
-                       int code = JSWebAPIError::convertToWebAPIErrorCode(name);
+                       int code = JSWebAPIException::convertToWebAPIExceptionCode(name);
 
                        JSWebAPIError::PrivateObject::ObjectType data(new TizenExceptionData(code, name, message));
-                       *exception = WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(context, JSWebAPIError::getClassRef(), data);
+                       *exception = WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(context, JSWebAPIException::getClassRef(), data);
                        return JSValueMakeUndefined(context);
                }
 }// Common
old mode 100755 (executable)
new mode 100644 (file)
index 80a98ad..1297795
@@ -18,6 +18,8 @@
 #include "JSUtil.h"
 #include "PlatformException.h"
 #include <cmath>
+#include <limits>
+
 
 using namespace std;
 
@@ -86,26 +88,22 @@ long JSUtil::JSValueToLong(JSContextRef ctx, JSValueRef value){
 }
 
 unsigned long JSUtil::JSValueToULong(JSContextRef ctx, JSValueRef value){
-    return static_cast<unsigned long>(JSValueToULongLong(ctx,value));
+    double number = JSValueToNumber(ctx, value);
+    if( number < 0 )
+        return static_cast<unsigned long>(static_cast<long>(number));
+    return static_cast<unsigned long>(number);
 }
 
 
 long long JSUtil::JSValueToLongLong(JSContextRef ctx, JSValueRef value){
-    JSValueRef exception = NULL;
-    long long longvalue = static_cast<long long>(JSValueToNumber(ctx, value, &exception));
-    if(exception != NULL){
-        throw TypeMismatchException(ctx, exception);
-    }
-    return longvalue;
+    return static_cast<long long>(JSValueToNumber(ctx, value));
 }
 
 unsigned long long JSUtil::JSValueToULongLong(JSContextRef ctx, JSValueRef value){
-    JSValueRef exception = NULL;
-    long long longvalue = static_cast<unsigned long long>(JSValueToNumber(ctx, value, &exception));
-    if(exception != NULL){
-        throw TypeMismatchException(ctx, exception);
-    }
-    return longvalue;
+    double number = JSValueToNumber(ctx, value);
+    if( number < 0 )
+        return static_cast<unsigned long long>(static_cast<long long>(number));
+    return static_cast<unsigned long long>(number);
 }
 
 
@@ -113,16 +111,44 @@ unsigned long long JSUtil::JSValueToULongLong(JSContextRef ctx, JSValueRef value
 double JSUtil::JSValueToDouble(JSContextRef ctx, JSValueRef value){
     JSValueRef exception = NULL;
 
-    double doublevalue = JSValueToNumber(ctx, value, &exception);
+    double doublevalue = ::JSValueToNumber(ctx, value, &exception);
     if(exception != NULL){
         throw TypeMismatchException(ctx, exception);
     }
+    if( doublevalue == std::numeric_limits<double>::infinity() )
+        throw TypeMismatchException("Value is POSITIVE_INFINITY");
+    if( doublevalue == -std::numeric_limits<double>::infinity() )
+        throw TypeMismatchException("Value is NEGATIVE_INFINITY");
     if( isnan(doublevalue)){
         throw TypeMismatchException("Value is not number");
     }
     return doublevalue;
 }
 
+double JSUtil::JSValueToNumber(JSContextRef ctx, JSValueRef value){
+    JSValueRef exception = NULL;
+
+    double doublevalue = ::JSValueToNumber(ctx, value, &exception);
+    if(exception != NULL){
+        throw TypeMismatchException(ctx, exception);
+    }
+    if( doublevalue == std::numeric_limits<double>::infinity() )
+        doublevalue = 0.0;
+
+    if( doublevalue == -std::numeric_limits<double>::infinity() )
+        doublevalue = 0.0;
+
+    return doublevalue;
+}
+
+signed char JSUtil::JSValueToByte(JSContextRef ctx, JSValueRef value){
+    return static_cast<signed char>(JSValueToNumber(ctx,value));
+}
+
+unsigned char JSUtil::JSValueToOctet(JSContextRef ctx, JSValueRef value){
+    return static_cast<unsigned char>(JSValueToNumber(ctx,value));
+}
+
 bool JSUtil::JSValueToBoolean(JSContextRef ctx, JSValueRef value){
     return ::JSValueToBoolean(ctx, value);
 }
@@ -210,6 +236,15 @@ JSValueRef JSUtil::toJSValueRef(JSContextRef ctx, const double value){
     return JSValueMakeNumber(ctx, value);
 }
 
+JSValueRef JSUtil::toJSValueRef(JSContextRef ctx, const signed char value){
+    return JSValueMakeNumber(ctx, value);
+}
+
+JSValueRef JSUtil::toJSValueRef(JSContextRef ctx, const unsigned char value){
+    return JSValueMakeNumber(ctx, value);
+}
+
+
 JSValueRef JSUtil::toJSValueRef(JSContextRef ctx, const bool value){
     return JSValueMakeBoolean(ctx, value);
 }
old mode 100755 (executable)
new mode 100644 (file)
index 5a8e32c..534d090
@@ -148,6 +148,44 @@ public:
     static double JSValueToDouble(JSContextRef ctx, JSValueRef value);
 
     /**
+     * @brief Converts a JavaScript value to number and returns the resulting number.
+     *
+     * @param[in] ctx The execution context to use.
+     * @param[in] value The JSValue to convert.
+     *
+     * @return The result of conversion
+     *
+     * @exception TypeMismatchException
+     */
+    static double JSValueToNumber(JSContextRef ctx, JSValueRef value);
+
+
+    /**
+     * @brief Converts a JavaScript value to byte(signed) number and returns the resulting byte(signed) number.
+     *
+     * @param[in] ctx The execution context to use.
+     * @param[in] value The JSValue to convert.
+     *
+     * @return The result of conversion
+     *
+     * @exception TypeMismatchException
+     */
+    static signed char JSValueToByte(JSContextRef ctx, JSValueRef value);
+
+    /**
+     * @brief Converts a JavaScript value to Octet(unsigned) number and returns the resulting Octet(unsigned) number.
+     *
+     * @param[in] ctx The execution context to use.
+     * @param[in] value The JSValue to convert.
+     *
+     * @return The result of conversion
+     *
+     * @exception TypeMismatchException
+     */
+    static unsigned char JSValueToOctet(JSContextRef ctx, JSValueRef value);
+
+
+    /**
      * @brief Converts a JavaScript value to boolean and returns the resulting bollean
      *
      *
@@ -346,6 +384,26 @@ public:
      */
     static JSValueRef toJSValueRef(JSContextRef ctx, const bool value);
 
+    /**
+     * @brief Creates a JavaScript value of the number type.
+     *
+     * @param[in] ctx The execution context to use.
+     * @param[in] value The signed char to assign to the newly created JSValue.
+     *
+     * @return A JSValue of the number type, representing the value of number.
+     */
+    static JSValueRef toJSValueRef(JSContextRef ctx, const signed char value);
+
+    /**
+     * @brief Creates a JavaScript value of the number type.
+     *
+     * @param[in] ctx The execution context to use.
+     * @param[in] value The signed char to assign to the newly created JSValue.
+     *
+     * @return A JSValue of the number type, representing the value of number.
+     */
+    static JSValueRef toJSValueRef(JSContextRef ctx, const unsigned char value);
+
 
 
     /**
diff --git a/src/Common/JSWebAPIException.cpp b/src/Common/JSWebAPIException.cpp
new file mode 100644 (file)
index 0000000..0db9318
--- /dev/null
@@ -0,0 +1,331 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 "JSWebAPIException.h"
+
+#include <dpl/log/log.h>
+
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <string>
+
+namespace DeviceAPI {
+namespace Common {
+
+namespace{
+
+                       #define PLUGIN_NAME       "WebAPIException"
+                       #define PROPERTY_CODE     "code"
+                       #define PROPERTY_NAME     "name"
+                       #define PROPERTY_TYPE     "type"
+                       #define PROPERTY_MESSAGE  "message"
+
+                       #define PROPERTY_UNKNOWN_ERR                              "UNKNOWN_ERR"
+                       #define PROPERTY_INDEX_SIZE_ERR                           "INDEX_SIZE_ERR"
+                       #define PROPERTY_DOMSTRING_SIZE_ERR                       "DOMSTRING_SIZE_ERR"
+                       #define PROPERTY_HIERARCHY_REQUEST_ERR                    "HIERARCHY_REQUEST_ERR"
+                       #define PROPERTY_WRONG_DOCUMENT_ERR                       "WRONG_DOCUMENT_ERR"
+                       #define PROPERTY_INVALID_CHARACTER_ERR                    "INVALID_CHARACTER_ERR"
+                       #define PROPERTY_NO_DATA_ALLOWED_ERR                      "NO_DATA_ALLOWED_ERR"
+                       #define PROPERTY_NO_MODIFICATION_ALLOWED_ERR              "NO_MODIFICATION_ALLOWED_ERR"
+                       #define PROPERTY_NOT_FOUND_ERR                            "NOT_FOUND_ERR"
+                       #define PROPERTY_NOT_SUPPORTED_ERR                        "NOT_SUPPORTED_ERR"
+                       #define PROPERTY_INUSE_ATTRIBUTE_ERR                      "INUSE_ATTRIBUTE_ERR"
+                       #define PROPERTY_INVALID_STATE_ERR                        "INVALID_STATE_ERR"
+                       #define PROPERTY_SYNTAX_ERR                               "SYNTAX_ERR"
+                       #define PROPERTY_INVALID_MODIFICATION_ERR                 "INVALID_MODIFICATION_ERR"
+                       #define PROPERTY_NAMESPACE_ERR                            "NAMESPACE_ERR"
+                       #define PROPERTY_INVALID_ACCESS_ERR                       "INVALID_ACCESS_ERR"
+                       #define PROPERTY_VALIDATION_ERR                           "VALIDATION_ERR"
+                       #define PROPERTY_TYPE_MISMATCH_ERR                        "TYPE_MISMATCH_ERR"
+                       #define PROPERTY_SECURITY_ERR                             "SECURITY_ERR"
+                       #define PROPERTY_NETWORK_ERR                              "NETWORK_ERR"
+                       #define PROPERTY_ABORT_ERR                                "ABORT_ERR"
+                       #define PROPERTY_URL_MISMATCH_ERR                         "URL_MISMATCH_ERR"
+                       #define PROPERTY_QUOTA_EXCEEDED_ERR                       "QUOTA_EXCEEDED_ERR"
+                       #define PROPERTY_TIMEOUT_ERR                              "TIMEOUT_ERR"
+                       #define PROPERTY_INVALID_NODE_TYPE_ERR                    "INVALID_NODE_TYPE_ERR"
+                       #define PROPERTY_DATA_CLONE_ERR                           "DATA_CLONE_ERR"
+                       #define PROPERTY_INVALID_VALUES_ERR                       "INVALID_VALUES_ERR"
+                       #define PROPERTY_IO_ERR                                   "IO_ERR"
+                       #define PROPERTY_OUT_OF_MEMORY_ERR                        "OUT_OF_MEMORY_ERR"
+                       #define PROPERTY_NOT_CONNECTED_SERVICE_ERR                "NOT_CONNECTED_SERVICE_ERR"
+                       #define PROPERTY_FAIL_TO_REQUEST_ERR                      "FAIL_TO_REQUEST_ERR"
+                       #define PROPERTY_INVALID_RESPONSE_ERR                     "INVALID_RESPONSE_ERR"
+                       #define PROPERTY_NO_AVAILABLE_NETWORK_ERR                 "NO_AVAILABLE_NETWORK_ERR"
+                       #define PROPERTY_INVALID_DEVICE_ERR                       "INVALID_DEVICE_ERR"
+                       #define PROPERTY_NOT_SUPPORTED_FUNCTION_ERR               "NOT_SUPPORTED_FUNCTION_ERR"
+                       #define PROPERTY_NO_PERMISSION_ERR                        "NO_PERMISSION_ERR"
+                       #define PROPERTY_INVALID_ITEM_ERR                         "INVALID_ITEM_ERR"
+                       #define PROPERTY_FAIL_TO_PLAY_ERR                         "FAIL_TO_PLAY_ERR"
+                       #define PROPERTY_SERVICE_NOT_AVAILABLE                    "SERVICE_NOT_AVAILABLE"
+                       #define PROPERTY_AVPLAY_NETWORK_DISCONNECTED_ERR          "AVPLAY_NETWORK_DISCONNECTED_ERR"
+                       #define PROPERTY_AVPLAY_UNSUPPORTED_VIDEO_FORMAT_ERR      "AVPLAY_UNSUPPORTED_VIDEO_FORMAT_ERR"
+                       #define PROPERTY_AVPLAY_UNSUPPORTED_AUDIO_FORMAT_ERR      "AVPLAY_UNSUPPORTED_AUDIO_FORMAT_ERR"
+                       #define PROPERTY_AVPLAY_UNSUPPORTED_VIDEO_RESOLUTION_ERR  "AVPLAY_UNSUPPORTED_VIDEO_RESOLUTION_ERR"
+                       #define PROPERTY_AVPLAY_UNSUPPORTED_VIDEO_FRAMERATE_ERR   "AVPLAY_UNSUPPORTED_VIDEO_FRAMERATE_ERR"
+                       #define PROPERTY_AVPLAY_CURRUPTED_STREAM_ERR              "AVPLAY_CURRUPTED_STREAM_ERR"
+               }
+
+               JSClassRef JSWebAPIException::m_classRef = NULL;
+
+               JSClassDefinition JSWebAPIException::m_classInfo = {
+                       0,
+                       kJSClassAttributeNone,
+                       PLUGIN_NAME,
+                       0,
+                       m_properties,
+                       m_function, //__function,
+                       initialize,
+                       finalize,
+                       NULL,
+                       NULL,
+                       NULL, //SetProperty,
+                       NULL, //DeleteProperty,
+                       NULL,
+                       NULL, //CallAsFunction,
+                       NULL, //CallAsConstructor,
+                       hasInstance,
+                       NULL, //ConvertToType,
+               };
+
+        JSStaticFunction JSWebAPIException::m_function[] = {
+            { "toString", toString, kJSPropertyAttributeNone },
+            { 0, 0, 0 }
+        };
+
+
+               JSStaticValue JSWebAPIException::m_properties[] = {
+                       { PROPERTY_CODE,    getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NAME,    getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_TYPE,    getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_MESSAGE, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+
+                       { PROPERTY_UNKNOWN_ERR,                             getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INDEX_SIZE_ERR,                          getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_DOMSTRING_SIZE_ERR,                      getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_HIERARCHY_REQUEST_ERR,                   getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_WRONG_DOCUMENT_ERR,                      getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_CHARACTER_ERR,                   getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NO_DATA_ALLOWED_ERR,                     getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NO_MODIFICATION_ALLOWED_ERR,             getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NOT_FOUND_ERR,                           getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NOT_SUPPORTED_ERR,                       getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INUSE_ATTRIBUTE_ERR,                     getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_STATE_ERR,                       getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_SYNTAX_ERR,                              getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_MODIFICATION_ERR,                getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NAMESPACE_ERR,                           getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_ACCESS_ERR,                      getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_VALIDATION_ERR,                          getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_TYPE_MISMATCH_ERR,                       getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_SECURITY_ERR,                            getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NETWORK_ERR,                             getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_ABORT_ERR,                               getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_URL_MISMATCH_ERR,                        getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_QUOTA_EXCEEDED_ERR,                      getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_TIMEOUT_ERR,                             getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_NODE_TYPE_ERR,                   getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_DATA_CLONE_ERR,                          getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_VALUES_ERR,                      getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_IO_ERR,                                  getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_OUT_OF_MEMORY_ERR,                       getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NOT_CONNECTED_SERVICE_ERR,               getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_FAIL_TO_REQUEST_ERR,                     getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_RESPONSE_ERR,                    getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NO_AVAILABLE_NETWORK_ERR,                getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_DEVICE_ERR,                      getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NOT_SUPPORTED_FUNCTION_ERR,              getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_NO_PERMISSION_ERR,                       getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_INVALID_ITEM_ERR,                        getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_FAIL_TO_PLAY_ERR,                        getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_SERVICE_NOT_AVAILABLE,                   getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_AVPLAY_NETWORK_DISCONNECTED_ERR,         getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_AVPLAY_UNSUPPORTED_VIDEO_FORMAT_ERR,     getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_AVPLAY_UNSUPPORTED_AUDIO_FORMAT_ERR,     getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_AVPLAY_UNSUPPORTED_VIDEO_RESOLUTION_ERR, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_AVPLAY_UNSUPPORTED_VIDEO_FRAMERATE_ERR,  getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_AVPLAY_CURRUPTED_STREAM_ERR,             getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { 0, 0, 0, 0 }
+               };
+
+               const JSClassDefinition* JSWebAPIException::getClassInfo() {
+                       return &m_classInfo;
+               }
+
+               JSClassRef JSWebAPIException::getClassRef() {
+                       if (!m_classRef) {
+                               m_classRef = JSClassCreate(&m_classInfo);
+                       }
+                       return m_classRef;
+               }
+
+               void JSWebAPIException::initialize(JSContextRef /*context*/, JSObjectRef /*object*/) {
+               }
+
+               void JSWebAPIException::finalize(JSObjectRef object) {
+                       PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(object));
+                       if (privateObject) {
+                               JSObjectSetPrivate(object, NULL);
+                               delete privateObject;
+                       }
+               }
+
+               JSValueRef JSWebAPIException::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);
+                       }
+
+                       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+                       try {
+                               if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CODE)) {
+                                       LogDebug("propertyName PROPERTY_CODE");
+                                       return converter.toJSValueRef(privateObject->getObject()->getCode());
+                               } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME)) {
+                                       return converter.toJSValueRef(privateObject->getObject()->getName());
+                               } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_TYPE)) {
+                                       return converter.toJSValueRef(privateObject->getObject()->getName());
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MESSAGE)) {
+                                       return converter.toJSValueRef(privateObject->getObject()->getMessage());
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_UNKNOWN_ERR)) {
+                                       return converter.toJSValueRef(UNKNOWN_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_INDEX_SIZE_ERR)) {
+                                       return converter.toJSValueRef(INDEX_SIZE_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_DOMSTRING_SIZE_ERR)) {
+                                       return converter.toJSValueRef(DOMSTRING_SIZE_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_HIERARCHY_REQUEST_ERR)) {
+                                       return converter.toJSValueRef(HIERARCHY_REQUEST_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_WRONG_DOCUMENT_ERR)) {
+                                       return converter.toJSValueRef(WRONG_DOCUMENT_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_INVALID_CHARACTER_ERR)) {
+                                       return converter.toJSValueRef(INVALID_CHARACTER_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NO_DATA_ALLOWED_ERR)) {
+                                       return converter.toJSValueRef(NO_DATA_ALLOWED_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NO_MODIFICATION_ALLOWED_ERR)) {
+                                       return converter.toJSValueRef(NO_MODIFICATION_ALLOWED_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NOT_FOUND_ERR)) {
+                                       return converter.toJSValueRef(NOT_FOUND_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NOT_SUPPORTED_ERR)) {
+                                       return converter.toJSValueRef(NOT_SUPPORTED_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_INUSE_ATTRIBUTE_ERR)) {
+                                       return converter.toJSValueRef(INUSE_ATTRIBUTE_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_INVALID_STATE_ERR)) {
+                                       return converter.toJSValueRef(INVALID_STATE_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_SYNTAX_ERR)) {
+                                       return converter.toJSValueRef(SYNTAX_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_INVALID_MODIFICATION_ERR)) {
+                                       return converter.toJSValueRef(INVALID_MODIFICATION_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAMESPACE_ERR)) {
+                                       return converter.toJSValueRef(NAMESPACE_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_INVALID_ACCESS_ERR)) {
+                                       return converter.toJSValueRef(INVALID_ACCESS_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_VALIDATION_ERR)) {
+                                       return converter.toJSValueRef(VALIDATION_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_TYPE_MISMATCH_ERR)) {
+                                       return converter.toJSValueRef(TYPE_MISMATCH_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_SECURITY_ERR)) {
+                                       return converter.toJSValueRef(SECURITY_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NETWORK_ERR)) {
+                                       return converter.toJSValueRef(NETWORK_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_ABORT_ERR)) {
+                                       return converter.toJSValueRef(ABORT_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_URL_MISMATCH_ERR)) {
+                                       return converter.toJSValueRef(URL_MISMATCH_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_QUOTA_EXCEEDED_ERR)) {
+                                       return converter.toJSValueRef(QUOTA_EXCEEDED_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_TIMEOUT_ERR)) {
+                                       return converter.toJSValueRef(TIMEOUT_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_INVALID_NODE_TYPE_ERR)) {
+                                       return converter.toJSValueRef(INVALID_NODE_TYPE_ERR);
+                               }else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_DATA_CLONE_ERR)) {
+                                       return converter.toJSValueRef(DATA_CLONE_ERR);
+                               }else{
+                                       LogDebug("propertyName not supported");
+                                       return converter.toJSValueRef(UNKNOWN_ERR);
+                               }
+                       } catch (const WrtDeviceApis::Commons::ConversionException& ex) {
+                               LogError("Exception: " << ex.GetMessage());
+                       }
+
+                       return JSValueMakeUndefined(context);
+               }
+
+        JSValueRef JSWebAPIException::toString(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
+                       PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(thisObject));
+                       if (!privateObject) {
+                return NULL;
+                       }
+
+                       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+            std::string name = privateObject->getObject()->getName();
+            std::string message = privateObject->getObject()->getMessage();
+            std::string result = name + ": "+message;
+            return converter.toJSValueRef(result);
+        }
+
+               bool JSWebAPIException::hasInstance(JSContextRef context, JSObjectRef /*constructor*/, JSValueRef possibleInstance, JSValueRef* /*exception*/) {
+                       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+               }
+
+               int JSWebAPIException::convertToWebAPIExceptionCode(const std::string& errorName){
+                       LogDebug("<<< errorName:[" << errorName << "]");
+
+                       int retErrorCode = -1;
+
+                       if(errorName.compare(JSTizenException::UNKNOWN_ERROR) == 0){
+                               retErrorCode = UNKNOWN_ERR;
+                       }else if(errorName.compare(JSTizenException::NOT_FOUND_ERROR) == 0){
+                               retErrorCode = NOT_FOUND_ERR;
+                       }else if(errorName.compare(JSTizenException::NOT_SUPPORTED_ERROR) == 0){
+                               retErrorCode = NOT_SUPPORTED_ERR;
+                       }else if(errorName.compare(JSTizenException::TYPE_MISMATCH_ERROR) == 0){
+                               retErrorCode = TYPE_MISMATCH_ERR;
+                       }else if(errorName.compare(JSTizenException::PERMISSION_DENIED_ERROR) == 0){
+                               retErrorCode = SECURITY_ERR;
+                       }else if(errorName.compare(JSTizenException::TIMEOUT_ERROR) == 0){
+                               retErrorCode = TIMEOUT_ERR;
+                       }else if(errorName.compare(JSTizenException::INVALID_VALUES_ERROR) == 0){
+                               retErrorCode = 0;
+                       }else if(errorName.compare(JSTizenException::IO_ERROR) == 0){
+                               retErrorCode = 0;
+                       }else if(errorName.compare(JSTizenException::SERVICE_NOT_AVAILABLE) == 0){
+                               retErrorCode = 0;
+                       }else if(errorName.compare(JSTizenException::NETWORK_ERROR) == 0){
+                               retErrorCode = NETWORK_ERR;
+                       }else{
+                               retErrorCode = UNKNOWN_ERR;
+                       }
+
+                       LogDebug(">>> retERrorCode:" << retErrorCode );
+                       return retErrorCode;
+               }
+
+        JSObjectRef JSWebAPIException::makeJSWebAPIException(JSContextRef context, const BasePlatformException& error){
+                       JSWebAPIException::PrivateObject::ObjectType data(new TizenExceptionData(error.getCode(), error.getName(), error.getMessage()));
+                       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(context, JSWebAPIException::getClassRef(), data);
+        }
+        JSValueRef JSWebAPIException::throwException(JSContextRef context, JSValueRef* exception, const BasePlatformException& error){
+                       Assert(exception && "Exception object can't be NULL.");
+
+                       *exception = makeJSWebAPIException(context, error);
+                       return JSValueMakeUndefined(context);
+        }
+
+}// Common
+}// DeviceAPI
diff --git a/src/Common/JSWebAPIException.h b/src/Common/JSWebAPIException.h
new file mode 100644 (file)
index 0000000..e0f7629
--- /dev/null
@@ -0,0 +1,115 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 JSWEBAPIEXCEPTION_H_
+#define JSWEBAPIEXCEPTION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+#include "JSTizenException.h"
+#include "PlatformException.h"
+
+namespace DeviceAPI {
+namespace Common {
+
+               class JSWebAPIException {
+                       public:
+                               typedef  WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenExceptionDataPtr>::Type PrivateObject;
+
+                               static JSClassRef getClassRef();
+                               static const JSClassDefinition* getClassInfo();
+
+                               static int convertToWebAPIExceptionCode(const std::string& errorName);
+
+                static JSObjectRef makeJSWebAPIException(JSContextRef context, const BasePlatformException& error);
+                static JSValueRef throwException(JSContextRef context, JSValueRef* exception, const BasePlatformException& error);
+
+                       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 JSValueRef getStaticProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+                               /**
+                                * 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);
+
+
+                static JSValueRef toString(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], 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;
+
+                static JSStaticFunction m_function[];
+
+                       public:
+                               enum{
+                                       UNKNOWN_ERR                              = 0,
+                                       INDEX_SIZE_ERR                           = 1,
+                                       DOMSTRING_SIZE_ERR                       = 2,
+                                       HIERARCHY_REQUEST_ERR                    = 3,
+                                       WRONG_DOCUMENT_ERR                       = 4,
+                                       INVALID_CHARACTER_ERR                    = 5,
+                                       NO_DATA_ALLOWED_ERR                      = 6,
+                                       NO_MODIFICATION_ALLOWED_ERR              = 7,
+                                       NOT_FOUND_ERR                            = 8,
+                                       NOT_SUPPORTED_ERR                        = 9,
+                                       INUSE_ATTRIBUTE_ERR                      = 10,
+                                       INVALID_STATE_ERR                        = 11,
+                                       SYNTAX_ERR                               = 12,
+                                       INVALID_MODIFICATION_ERR                 = 13,
+                                       NAMESPACE_ERR                            = 14,
+                                       INVALID_ACCESS_ERR                       = 15,
+                                       VALIDATION_ERR                           = 16,
+                                       TYPE_MISMATCH_ERR                        = 17,
+                                       SECURITY_ERR                             = 18,
+                                       NETWORK_ERR                              = 19,
+                                       ABORT_ERR                                = 20,
+                                       URL_MISMATCH_ERR                         = 21,
+                                       QUOTA_EXCEEDED_ERR                       = 22,
+                                       TIMEOUT_ERR                              = 23,
+                                       INVALID_NODE_TYPE_ERR                    = 24,
+                                       DATA_CLONE_ERR                           = 25,
+
+                               };      //WebAPIException
+               };
+
+}// Common
+}// DeviceAPI
+#endif /* JSWEBAPIEXCEPTION_H_ */
index 252d6f1..9541913 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "PlatformException.h"
 #include "JSUtil.h"
-#include "JSWebAPIError.h"
+#include "JSWebAPIException.h"
 #include <CommonsJavaScript/Converter.h>
 
 using namespace WrtDeviceApis::CommonsJavaScript;
@@ -66,10 +66,10 @@ std::string BasePlatformException::getMessage() const{
 }
 
 
-TypeMismatchException::TypeMismatchException(const char* message):BasePlatformException(JSWebAPIError::TYPE_MISMATCH_ERR,"TypeMismatchError", message){
+TypeMismatchException::TypeMismatchException(const char* message):BasePlatformException(JSWebAPIException::TYPE_MISMATCH_ERR,"TypeMismatchError", message){
 }
 TypeMismatchException::TypeMismatchException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
-    mCode = JSWebAPIError::TYPE_MISMATCH_ERR;
+    mCode = JSWebAPIException::TYPE_MISMATCH_ERR;
     mName = "TypeMismatchError";
 }
 
@@ -102,27 +102,34 @@ ServiceNotAvailableException::ServiceNotAvailableException(JSContextRef ctx, JSV
     mName = "ServiceNotAvailableError";
 }
 
-SecurityException::SecurityException(const char* message):BasePlatformException(JSWebAPIError::SECURITY_ERR,"SecurityError", message){
+SecurityException::SecurityException(const char* message):BasePlatformException(JSWebAPIException::SECURITY_ERR,"SecurityError", message){
 }
 SecurityException::SecurityException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
-    mCode = JSWebAPIError::SECURITY_ERR;
+    mCode = JSWebAPIException::SECURITY_ERR;
     mName = "SecurityError";
 }
 
-NotSupportedException::NotSupportedException(const char* message):BasePlatformException(JSWebAPIError::NOT_SUPPORTED_ERR,"NotSupportedError", message){
+NotSupportedException::NotSupportedException(const char* message):BasePlatformException(JSWebAPIException::NOT_SUPPORTED_ERR,"NotSupportedError", message){
 }
 NotSupportedException::NotSupportedException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
-    mCode = JSWebAPIError::NOT_SUPPORTED_ERR;
+    mCode = JSWebAPIException::NOT_SUPPORTED_ERR;
     mName = "NotSupportedError";
 }
 
-NotFoundException::NotFoundException(const char* message):BasePlatformException(JSWebAPIError::NOT_FOUND_ERR,"NotFoundError", message){
+NotFoundException::NotFoundException(const char* message):BasePlatformException(JSWebAPIException::NOT_FOUND_ERR,"NotFoundError", message){
 }
 NotFoundException::NotFoundException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
-    mCode = JSWebAPIError::NOT_FOUND_ERR;
+    mCode = JSWebAPIException::NOT_FOUND_ERR;
     mName = "NotFoundError";
 }
 
+InvalidAccessException::InvalidAccessException(const char* message):BasePlatformException(JSWebAPIException::INVALID_ACCESS_ERR,"InvalidAccessError", message){
+}
+InvalidAccessException::InvalidAccessException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
+    mCode = JSWebAPIException::INVALID_ACCESS_ERR;
+    mName = "InvalidAccessError";
+}
+
 
 
 
index c1fae39..613ac13 100644 (file)
@@ -92,6 +92,12 @@ public:
     NotFoundException(JSContextRef ctx, JSValueRef exception);
 };
 
+class InvalidAccessException : public BasePlatformException{
+public:
+       InvalidAccessException(const char* message);
+       InvalidAccessException(JSContextRef ctx, JSValueRef exception);
+};
+
 
 
 
index 73e451c..3dddade 100644 (file)
@@ -8,6 +8,8 @@ INCLUDE_DIRECTORIES(
        ${TOP}/Common
 )
 
+ADD_DEFINITIONS("-DTIME_TRACER_UNIT_MSEC")
+
 ADD_LIBRARY(${TARGET} SHARED ${SRCS})
 
 TARGET_LINK_LIBRARIES(${TARGET}
index ba64207..beef969 100644 (file)
@@ -27,6 +27,8 @@
 #include <sys/time.h>
 #include <sys/utsname.h>
 #include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -36,9 +38,8 @@
 /*
 * Global Variables
 */
-#undef TIME_TRACER_UNIT_MSEC
-#define TIME_TRACER_ITEM_MAX   100
-#define OUTPUT_FILE "/tmp/wrt-plugins-tizen-time-trace-result.log"
+#define TIME_TRACER_ITEM_MAX   500
+#define OUTPUT_DIR "/tmp/wrt-plugins-tizen-time-trace-result"
 
 time_tracer_item ** g_items = NULL; //Time tracer item list
 static int g_index = 0;
@@ -102,6 +103,7 @@ int time_tracer_init(void)
                return -1;
        }
        g_first_time = 0xFFFFFFFF;
+       LOGE("TIME TRACER INITIALIZED");
        return 0;
 }
 
@@ -109,6 +111,7 @@ int time_tracer_release(void)
 {
        if (!g_items)
                return 0;
+       LOGE("TIME TRACER DESTROYED");
        __time_tracer_item_free();
        return 0;
 }
@@ -287,7 +290,7 @@ int time_tracer_item_end(const char* name, int show, const char* filename, int l
        return 0;
 }
 
-void time_tracer_export_report(int direction)
+void time_tracer_export_report(int direction, char* name)
 {
        int i = 0;
        char format[256];
@@ -305,7 +308,13 @@ void time_tracer_export_report(int direction)
                        fp = stderr;
                        break;
                case TIME_TRACER_EXPORT_FILE:
-                       fp = fopen(OUTPUT_FILE, "wt");
+                       mkdir(OUTPUT_DIR,0755);
+                       char f_name[256];
+                       if(name==NULL || strlen(name)==0)
+                               sprintf(f_name,"%s/%s",OUTPUT_DIR,"default.log");
+                       else
+                               sprintf(f_name,"%s/%s.%s",OUTPUT_DIR,name,"log");
+                       fp = fopen(f_name, "wt");
                        if (!fp)
                        {
                                LOGE("[%s] Failed to fopen().",__FUNCTION__);
@@ -320,13 +329,11 @@ void time_tracer_export_report(int direction)
 #ifdef TIME_TRACER_UNIT_MSEC
        sprintf(format, "[%%3d] %%-%ds|\tTotal:%%4ld,\tCnt:%%3ld,\tAvg:%%4ld,\tMin:%%4ld,\tMax:%%4ld,\tStart:%%4lu,\tEnd:%%4lu,\tMismatch:%%3ld\n", g_max_item_name_length);
        fprintf(fp, "TIME TRACER REPORT [BEGIN]=========================== [# of Item:%d, unit(msec)]\n", g_index);
-       //sprintf(format, "[%%3d] %%-%ds | \tTotal : %%4ld\t# of calls : %%3ld\tAvg : %%4ld\tMin : %%4ld\tMax : %%4ld\tStart : %%4lu\tEnd : %%4lu\t# of Mismatch : %%3ld\n", g_max_item_name_length);
-       //fprintf(fp, "TIME TRACER REPORT [BEGIN]=========================== : # of Item : %d, unit(msec)\n", g_index);
+       LOGE("TIME TRACER REPORT [BEGIN]=========================== [# of Item:%d, unit(msec)]", g_index);
 #else
        snprintf(format, sizeof(format)-1, "[%%3d] %%-%ds |\tTotal:%%ld,\tCnt:%%ld,\tAvg:%%ld,\tMin:%%ld,\tMax:%%ld,\tStart:%%lu,\tEnd:%%lu,\tMismatch:%%ld\n", g_max_item_name_length);
        fprintf(fp, "TIME TRACER REPORT [BEGIN]=========================== [# of Item:%d, unit(usec)]\n", g_index);
-       //snprintf(format, sizeof(format)-1, "[%%3d] %%-%ds | \tTotal : %%ld\t# of calls : %%ld\tAvg : %%ld\tMin : %%ld\tMax : %%ld\tStart : %%lu\tEnd : %%lu\t# of Mismatch : %%ld\n", g_max_item_name_length);
-       //fprintf(fp, "TIME TRACER REPORT [BEGIN]============================ : # of Item : %d, unit(usec)\n", g_index);
+       LOGE("TIME TRACER REPORT [BEGIN]=========================== [# of Item:%d, unit(usec)]", g_index);
 #endif
 
        for ( i = 0; i < g_index; i++ )
@@ -344,8 +351,11 @@ void time_tracer_export_report(int direction)
                        g_items[i]->first_timestamp - g_first_time, //begin timestamp
                        g_items[i]->last_timestamp - g_first_time, //end timestamp
                        g_items[i]->mismatch_count ); // # of mismatch (begin - end mismatch)
+
+               LOG(LOG_ERROR, LOG_TAG, format,i,g_items[i]->name,  g_items[i]->total_elapsed_time, g_items[i]->invoke_count, (g_items[i]->total_elapsed_time == 0)?0:(int)(g_items[i]->total_elapsed_time / g_items[i]->invoke_count), g_items[i]->min_elapsed_time, g_items[i]->max_elapsed_time, g_items[i]->first_timestamp - g_first_time,         g_items[i]->last_timestamp - g_first_time, g_items[i]->mismatch_count );
        }
        fprintf(fp, "TIME TRACER REPORT [END]  ============================\n");
+       LOGE("TIME TRACER REPORT [END]  ============================");
 
        if ( direction == TIME_TRACER_EXPORT_FILE )
                fclose(fp);
index e5b49e0..f203c91 100644 (file)
@@ -39,7 +39,7 @@ typedef struct _time_tracer_item
 /* COMMON */
 int time_tracer_init(void);
 int time_tracer_release(void);
-void time_tracer_export_report(int direction);
+void time_tracer_export_report(int direction, char* name);
 int time_tracer_item_begin(const char* name, int show,const  char* filename, int line);
 int time_tracer_item_end(const char* name, int show, const char* filename, int line);
 
@@ -53,9 +53,9 @@ int time_tracer_item_end(const char* name, int show, const char* filename, int l
 //Release the time tracer
 #define TIME_TRACER_RELEASE()  (time_tracer_release())
 //Export tracing report to stdout
-#define TIME_TRACER_EXPORT_REPORT()            (time_tracer_export_report(TIME_TRACER_EXPORT_STDOUT))
+#define TIME_TRACER_EXPORT_REPORT()            (time_tracer_export_report(TIME_TRACER_EXPORT_STDOUT,NULL))
 //Export tracing report to user specific direction (stdout, stderr, file)
-#define TIME_TRACER_EXPORT_REPORT_TO(x)        (time_tracer_export_report(x))
+#define TIME_TRACER_EXPORT_REPORT_TO(x,y)      (time_tracer_export_report(x,y))
 //Set tracing point to begin
 #define TIME_TRACER_ITEM_BEGIN(name,show)      (time_tracer_item_begin(name,show,__FILE__,__LINE__))
 //Set tracing point to end
@@ -64,7 +64,7 @@ int time_tracer_item_end(const char* name, int show, const char* filename, int l
 #define TIME_TRACER_INIT()
 #define TIME_TRACER_RELEASE()
 #define TIME_TRACER_EXPORT_REPORT()
-#define TIME_TRACER_EXPORT_REPORT_TO(x)
+#define TIME_TRACER_EXPORT_REPORT_TO(x,y)
 #define TIME_TRACER_ITEM_BEGIN(name,show)
 #define TIME_TRACER_ITEM_END(name,show)
 #endif
index 7769b32..b4ade83 100755 (executable)
@@ -228,6 +228,18 @@ JSValueRef Contact::getNumbersJSValue()
        return m_numbersJSValue;
 }
 
+void Contact::resetNumbersJSObj()
+{
+       if(numbersJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getNumbersJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_numbersJSObjIsSet = false;
+       m_numbersObj = NULL;
+       m_numbersJSValue = NULL;
+}
+
 void Contact::setEmailsJSObj(bool value, JSObjectRef initObj)
 {
        m_emailsJSObjIsSet = value;
@@ -249,6 +261,18 @@ JSValueRef Contact::getEmailsJSValue()
        return m_emailsJSValue;
 }
 
+void Contact::resetEmailsJSObj()
+{
+       if(EmailsJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getEmailsJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_emailsJSObjIsSet = false;
+       m_emailsObj = NULL;
+       m_emailsJSValue = NULL;
+}
+
 void Contact::setAnniversariesJSObj(bool value, JSObjectRef initObj)
 {
        m_anniversariesJSObjIsSet = value;
@@ -270,6 +294,18 @@ JSValueRef Contact::getAnniversariesJSValue()
        return m_anniversariesJSValue;
 }
 
+void Contact::resetAnniversariesJSObj()
+{
+       if(anniversariesJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getAnniversariesJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_anniversariesJSObjIsSet = false;
+       m_anniversariesObj = NULL;
+       m_anniversariesJSValue = NULL;
+}
+
 void Contact::setUrlsJSObj(bool value, JSObjectRef initObj)
 {
        m_urlsJSObjIsSet = value;
@@ -291,6 +327,18 @@ JSValueRef Contact::getUrlsJSValue()
        return m_urlsJSValue;
 }
 
+void Contact::resetUrlsJSObj()
+{
+       if(urlsJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getUrlsJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_urlsJSObjIsSet = false;
+       m_urlsObj = NULL;
+       m_urlsJSValue = NULL;
+}
+
 void Contact::setAddressesJSObj(bool value, JSObjectRef initObj)
 {
        m_addressesJSObjIsSet = value;
@@ -312,6 +360,18 @@ JSValueRef Contact::getAddressesJSValue()
        return m_addressesJSValue;
 }
 
+void Contact::resetAddressesJSObj()
+{
+       if(addressesJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getAddressesJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_addressesJSObjIsSet = false;
+       m_addressesObj = NULL;
+       m_addressesJSValue = NULL;
+}
+
 void Contact::setOrganizationsJSObj(bool value, JSObjectRef initObj)
 {
        m_organizationsJSObjIsSet = value;
@@ -333,6 +393,18 @@ JSValueRef Contact::getOrganizationsJSValue()
        return m_organizationsJSValue;
 }
 
+void Contact::resetOrganizationsJSObj()
+{
+       if(organizationsJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getOrganizationsJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_organizationsJSObjIsSet = false;
+       m_organizationsObj = NULL;
+       m_organizationsJSValue = NULL;
+}
+
 void Contact::setNotesJSObj(bool value, JSObjectRef initObj)
 {
        m_notesJSObjIsSet = value;
@@ -354,6 +426,18 @@ JSValueRef Contact::getNotesJSValue()
        return m_notesJSValue;
 }
 
+void Contact::resetNotesJSObj()
+{
+       if(notesJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getNotesJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_notesJSObjIsSet = false;
+       m_notesObj = NULL;
+       m_notesJSValue = NULL;
+}
+
 void Contact::setGroupIdsJSObj(bool value, JSObjectRef initObj)
 {
        m_groupIdsJSObjIsSet = value;
@@ -375,6 +459,18 @@ JSValueRef Contact::getGroupIdsJSValue()
        return m_groupIdsJSValue;
 }
 
+void Contact::resetGroupIdsJSObj()
+{
+       if(groupIdsJSObjIsSet()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getGroupIdsJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       m_groupIdsJSObjIsSet = false;
+       m_groupIdsObj = NULL;
+       m_groupIdsJSValue = NULL;
+}
+
 void Contact::setContext(JSContextRef contextRef)
 {
        if(m_context == NULL)
index 60fb416..6fef7b2 100755 (executable)
@@ -49,41 +49,49 @@ public:
        bool numbersJSObjIsSet() const;
        JSObjectRef getNumbersJSObj();
        JSValueRef getNumbersJSValue();
+       void resetNumbersJSObj();
 
        void setEmailsJSObj(bool value, JSObjectRef initObj);
        bool EmailsJSObjIsSet() const;
        JSObjectRef getEmailsJSObj();
        JSValueRef getEmailsJSValue();
+       void resetEmailsJSObj();
 
        void setAnniversariesJSObj(bool value, JSObjectRef initObj);
        bool anniversariesJSObjIsSet() const;
        JSObjectRef getAnniversariesJSObj();
        JSValueRef getAnniversariesJSValue();
+       void resetAnniversariesJSObj();
 
        void setUrlsJSObj(bool value, JSObjectRef initObj);
        bool urlsJSObjIsSet() const;
        JSObjectRef getUrlsJSObj();
        JSValueRef getUrlsJSValue();
+       void resetUrlsJSObj();
 
        void setAddressesJSObj(bool value, JSObjectRef initObj);
        bool addressesJSObjIsSet() const;
        JSObjectRef getAddressesJSObj();
        JSValueRef getAddressesJSValue();
+       void resetAddressesJSObj();
 
        void setOrganizationsJSObj(bool value, JSObjectRef initObj);
        bool organizationsJSObjIsSet() const;
        JSObjectRef getOrganizationsJSObj();
        JSValueRef getOrganizationsJSValue();
+       void resetOrganizationsJSObj();
 
        void setNotesJSObj(bool value, JSObjectRef initObj);
        bool notesJSObjIsSet() const;
        JSObjectRef getNotesJSObj();
        JSValueRef getNotesJSValue();
+       void resetNotesJSObj();
 
        void setGroupIdsJSObj(bool value, JSObjectRef initObj);
        bool groupIdsJSObjIsSet() const;
        JSObjectRef getGroupIdsJSObj();
        JSValueRef getGroupIdsJSValue();
+       void resetGroupIdsJSObj();
 
        void setContext(JSContextRef contextRef);
        JSContextRef getContext();
index 74e97de..1e1228d 100755 (executable)
@@ -365,6 +365,17 @@ bool ContactAddress::IsTypesSetJSArray() const
        return is_typesSetJSArray;
 }
 
+void ContactAddress::resetTypesJSObj()
+{
+       if(IsTypesSetJSArray()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getTypesJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       is_typesSetJSArray = false;
+       m_typesObj = NULL;
+       m_typesJsValue = NULL;
+}
 
 void ContactAddress::setContext(JSContextRef contextRef)
 {
index a43dd57..d0c52ae 100755 (executable)
@@ -103,6 +103,7 @@ public:
        JSValueRef getTypesJSArray();
        JSObjectRef getTypesJSObj();
        bool IsTypesSetJSArray() const;
+       void resetTypesJSObj();
 
        void setContext(JSContextRef contextRef);
        JSContextRef getContext();
index 8b2f24a..e3e0f01 100755 (executable)
@@ -1209,7 +1209,6 @@ JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressArrayPtr &arg
 
 ContactEmailAddressArrayPtr ContactConverter::toContactEmailAddressArray(const JSValueRef &jsValue)
 {
-       LogDebug("1");
        if(!JSIsArrayValue(m_context, jsValue))
                ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressArray is not array.");
 
@@ -1217,8 +1216,6 @@ ContactEmailAddressArrayPtr ContactConverter::toContactEmailAddressArray(const J
 
        JSObjectRef jsObject = toJSObjectRef(jsValue);
     for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
-
-               LogDebug("count : " << i);
         JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
         result->push_back(toContactEmailAddress(element));
     }
@@ -1237,7 +1234,7 @@ ContactWebSiteType ContactConverter::toContactWebSiteType(const std::string &arg
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactWebSiteType : " << arg);
-       return WEBSITE_TYPE_NULL;
+       return WEBSITE_TYPE_HOMEPAGE;
 }
 
 std::string ContactConverter::toContactWebSiteTypeStr(ContactWebSiteType arg)
@@ -1249,7 +1246,7 @@ std::string ContactConverter::toContactWebSiteTypeStr(ContactWebSiteType arg)
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactWebSiteType : " << arg);
-       return STR_CONTACT_EMPTY_STRING;
+       return STR_WEBSITE_TYPE_HOMEPAGE;
 }
 
 ContactWebSiteType ContactConverter::toContactWebSiteType(const JSValueRef &value)
@@ -1279,8 +1276,9 @@ ContactAddressType ContactConverter::toContactAddressType(const std::string &arg
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactAddressType : " << arg);
-       return CONTACT_ADDRESS_TYPE_NULL;
+       return CONTACT_ADDRESS_TYPE_HOME;
 }
+
 std::string ContactConverter::toContactAddressTypeStr(ContactAddressType arg)
 {
        if (arg == CONTACT_ADDRESS_TYPE_WORK) {
@@ -1292,7 +1290,7 @@ std::string ContactConverter::toContactAddressTypeStr(ContactAddressType arg)
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactAddressType : " << arg);
-       return STR_CONTACT_EMPTY_STRING;
+       return STR_CONTACT_ADDRESS_TYPE_HOME;
 }
 
 ContactAddressType ContactConverter::toContactAddressType(const JSValueRef &value)
@@ -1383,7 +1381,7 @@ ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const std::str
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactPhoneNumverType : " << arg);
-       return CONTACT_PHONE_NUMBER_TYPE_NULL;
+       return CONTACT_PHONE_NUMBER_TYPE_VOICE;
 }
 
 std::string ContactConverter::toContactPhoneNumberTypeStr(ContactPhoneNumberType arg)
@@ -1419,7 +1417,7 @@ std::string ContactConverter::toContactPhoneNumberTypeStr(ContactPhoneNumberType
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactPhoneNumberType : " << arg);
-       return STR_CONTACT_EMPTY_STRING;
+       return STR_CONTACT_PHONE_NUMBER_TYPE_VOICE;
 }
 
 ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const JSValueRef &value)
@@ -1455,11 +1453,11 @@ JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberTypeArrayPtr &
 
 ContactPhoneNumberTypeArrayPtr ContactConverter::toContactPhoneNumberTypeArray(const JSValueRef &jsValue)
 {
-       if(!JSIsArrayValue(m_context, jsValue))
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressTypeArray is not array.");
-
        ContactPhoneNumberTypeArrayPtr result(new ContactPhoneNumberTypeArray());
 
+       if(!JSIsArrayValue(m_context, jsValue) || JSValueIsNull(m_context, jsValue))
+                return result;
+
        JSObjectRef jsObject = toJSObjectRef(jsValue);
     for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
         JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
@@ -1486,7 +1484,7 @@ ContactEmailAddressType ContactConverter::toContactEmailAddressType(const std::s
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactEmailAddressType : " << arg);
-       return CONTACT_EMAIL_TYPE_NULL;
+       return CONTACT_EMAIL_TYPE_WORK;
 }
 
 std::string ContactConverter::toContactEmailAddressTypeStr(ContactEmailAddressType arg)
@@ -1500,7 +1498,7 @@ std::string ContactConverter::toContactEmailAddressTypeStr(ContactEmailAddressTy
        }
 
        //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactEmailAddressType : " << arg);
-       return STR_CONTACT_EMPTY_STRING;
+       return STR_CONTACT_EMAIL_TYPE_WORK;
 }
 
 ContactEmailAddressType ContactConverter::toContactEmailAddressType(const JSValueRef &value)
@@ -1536,11 +1534,11 @@ JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressTypeArrayPtr
 
 ContactEmailAddressTypeArrayPtr ContactConverter::toContactEmailAddressTypeArray(const JSValueRef &jsValue)
 {
-       if(!JSIsArrayValue(m_context, jsValue))
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressTypeArray is not array.");
-
        ContactEmailAddressTypeArrayPtr result(new ContactEmailAddressTypeArray());
 
+       if(!JSIsArrayValue(m_context, jsValue) || JSValueIsNull(m_context, jsValue))
+                return result;
+
        JSObjectRef jsObject = toJSObjectRef(jsValue);
     for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
         JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
index c73d7ea..c2d441e 100755 (executable)
@@ -40,6 +40,9 @@
 #include "ContactAddress.h"
 #include "ContactPhoneNumber.h"
 #include "ContactEmailAddress.h"
+#include <ArgumentValidator.h>
+#include <JSWebAPIError.h>
+#include <JSUtil.h>
 
 namespace DeviceAPI {
 namespace Contact {
index 433e41b..e968e7d 100755 (executable)
@@ -152,6 +152,18 @@ bool ContactEmailAddress::IsTypesSetJSArray() const
        return is_typesSetJSArray;
 }
 
+void ContactEmailAddress::resetTypesJSObj()
+{
+       if(IsTypesSetJSArray()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getTypesJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       is_typesSetJSArray = false;
+       m_typesObj = NULL;
+       m_typesJsValue = NULL;
+}
+
 void ContactEmailAddress::setContext(JSContextRef contextRef)
 {
        if(m_context == NULL)
index b470b7c..ff3855d 100755 (executable)
@@ -71,6 +71,7 @@ public:
        JSValueRef getTypesJSArray();
        JSObjectRef getTypesJSObj();
        bool IsTypesSetJSArray() const;
+       void resetTypesJSObj();
 
        void setContext(JSContextRef contextRef);
        JSContextRef getContext();
index 1c694e1..ce6a4b0 100755 (executable)
@@ -346,6 +346,18 @@ bool ContactName::IsTypesSetJSArray() const
        return is_typesSetJSArray;
 }
 
+void ContactName::resetTypesJSObj()
+{
+       if(IsTypesSetJSArray()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getTypesJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       is_typesSetJSArray = false;
+       m_typesObj = NULL;
+       m_typesJsValue = NULL;
+}
+
 void ContactName::setContext(JSContextRef contextRef)
 {
        if(m_context == NULL)
index 6230f87..650f8fd 100755 (executable)
@@ -99,6 +99,7 @@ public:
        JSValueRef getTypesJSArray();
        JSObjectRef getTypesJSObj();
        bool IsTypesSetJSArray() const;
+       void resetTypesJSObj();
 
        void setContext(JSContextRef contextRef);
        JSContextRef getContext();
index 91ad6de..6ba79c2 100755 (executable)
@@ -157,6 +157,18 @@ bool ContactPhoneNumber::IsTypesSetJSArray() const
        return is_typesSetJSArray;
 }
 
+void ContactPhoneNumber::resetTypesJSObj()
+{
+       if(IsTypesSetJSArray()){
+               JSContextRef contextRef = getContext();
+               JSObjectRef tempJSObject = getTypesJSObj();
+               JSValueUnprotect(contextRef, tempJSObject);
+       }
+       is_typesSetJSArray = false;
+       m_typesObj = NULL;
+       m_typesJsValue = NULL;
+}
+
 void ContactPhoneNumber::setContext(JSContextRef contextRef)
 {
        if(m_context == NULL)
index ac1445f..34e44da 100755 (executable)
@@ -72,6 +72,7 @@ public:
        JSValueRef getTypesJSArray();
        JSObjectRef getTypesJSObj();
        bool IsTypesSetJSArray() const;
+       void resetTypesJSObj();
 
        void setContext(JSContextRef contextRef);
        JSContextRef getContext();
index f74e15b..f42cf0e 100755 (executable)
@@ -51,6 +51,7 @@
 #include "ContactFilterConverter.h"
 #include <ArgumentValidator.h>
 #include <JSWebAPIError.h>
+#include <JSUtil.h>
 
 using namespace std;
 
@@ -65,8 +66,7 @@ namespace DeviceAPI {
 namespace Contact {
 
 using namespace DeviceAPI::Common;
-using namespace DeviceAPI::Tizen;
-using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Tizen;\rusing namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
 JSClassRef JSAddressBook::m_jsClassRef = NULL;
@@ -716,7 +716,6 @@ JSValueRef JSAddressBook::remove(JSContextRef context,
        LogDebug("entered");
        AddressBookPtr addressBook;
        AddressBookController *controller;
-       JSContextRef gContext;
 
        Try     {
                controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
@@ -724,7 +723,6 @@ JSValueRef JSAddressBook::remove(JSContextRef context,
                        ThrowMsg(InvalidArgumentException, "No private object.");
                }
                addressBook = controller->getObject();
-               gContext = controller->getContext();
        } Catch(Exception) {
                LogError("No private object");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
@@ -1108,7 +1106,8 @@ JSValueRef JSAddressBook::addChangeListener(JSContextRef context,
 
        JSValueRef result;
        Try {
-               result = converter->toJSValueRefLong(watchId);
+               result = JSUtil::toJSValueRef(context, watchId);
+//             result = converter->toJSValueRefLong(watchId);
        } Catch(Exception) {
                LogError("Error on conversion : " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
@@ -1148,7 +1147,7 @@ JSValueRef JSAddressBook::removeChangeListener(JSContextRef context,
 
        try {
                ArgumentValidator validator(context, argumentCount, arguments);
-               watchId = validator.toLong(0, false, 0);
+               watchId = validator.toLong(0, false);
        } catch (const TypeMismatchException& err ) {
                return JSWebAPIError::throwException(context, exception, err);
        } catch(const BasePlatformException& err) {
@@ -1473,7 +1472,6 @@ JSValueRef JSAddressBook::removeGroup(JSContextRef context,
        LogDebug("entered");
        AddressBookPtr addressBook;
        AddressBookController *controller;
-       JSContextRef gContext;
 
        Try     {
                controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
@@ -1481,7 +1479,6 @@ JSValueRef JSAddressBook::removeGroup(JSContextRef context,
                        ThrowMsg(InvalidArgumentException, "No private object.");
                }
                addressBook = controller->getObject();
-               gContext = controller->getContext();
        } Catch(Exception) {
                LogError("No private object");
                return JSTizenExceptionFactory::postException(context, exception,
index 41aff4e..5afa7b2 100755 (executable)
@@ -517,9 +517,10 @@ bool JSContact::setAddresses(JSContextRef context,
        Try
        {
                ContactPtr contact = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
                contact->setAddresses(converter->toContactAddressArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetAddressesJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -628,10 +629,10 @@ bool JSContact::setPhoneNumbers(JSContextRef context,
        Try
        {
                ContactPtr contact = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
-               contact->setPhoneNumbers(
-                               converter->toContactPhoneNumberArray(value));
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+               contact->setPhoneNumbers(converter->toContactPhoneNumberArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetNumbersJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -696,6 +697,8 @@ bool JSContact::setEmails(JSContextRef context,
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
                contact->setEmails(converter->toContactEmailAddressArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetEmailsJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -805,9 +808,10 @@ bool JSContact::setAnniversaries(JSContextRef context,
        Try
        {
                ContactPtr contact = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
                contact->setAnniversaries(converter->toContactAnniversaryArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetAnniversariesJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -867,9 +871,10 @@ bool JSContact::setOrganizations(JSContextRef context,
        Try
        {
                ContactPtr contact = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
                contact->setOrganizations(converter->toContactOrganizationArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetOrganizationsJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -928,10 +933,17 @@ bool JSContact::setNotes(JSContextRef context,
 {
        Try
        {
+               JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               }
+               JSContextRef gContext = priv->getContext();
                ContactPtr contact = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
+
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
                contact->setNotes(converter->toStringArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetNotesJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -991,9 +1003,10 @@ bool JSContact::setUrls(JSContextRef context,
        Try
        {
                ContactPtr contact = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
                contact->setUrls(converter->toContactWebSiteArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetUrlsJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -1104,9 +1117,10 @@ bool JSContact::setGroupIds(JSContextRef context,
        Try
        {
                ContactPtr contact = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
                contact->setGroupIds(converter->toStringArray(value));
+               DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
+               newContactT->resetGroupIdsJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
index 55ba72d..4eec716 100755 (executable)
@@ -618,6 +618,7 @@ bool JSContactAddress::setTypes(JSContextRef context,
                                ContactConverterFactory::getConverter(context);
 
                contactAddress->setTypes(converter->toContactAddressTypeArray(value));
+               contactAddress->resetTypesJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
index 5f73b0e..f5b234e 100755 (executable)
@@ -154,63 +154,50 @@ JSObjectRef JSContactAnniversary::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsString = false;
-
        JSContactAnniversaryPriv *priv = static_cast<JSContactAnniversaryPriv*>(JSObjectGetPrivate(constructor));
        if (!priv) {
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
        }
        JSContextRef gContext = priv->getContext();
 
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'Date object'");
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
 
-               if (!JSValueIsObject(gContext, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'Date object'");
+       std::tm date;
+       std::string label;
+       ContactAnniversaryPtr contactAnniversary(new ContactAnniversary());
 
-               if (argumentCount >= 2)
-               {
-                       if (!JSValueIsUndefined(context, arguments[1]) && !JSValueIsNull(context, arguments[1]))
-                               js2ndParamIsString = true;
-               }
+       try {
+               ArgumentValidator Argvalidator(context, argumentCount, arguments);
+               Argvalidator.toObject(0, false);
 
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Date object'");
+               if (argumentCount >= 2){
+                       label = Argvalidator.toString(1, true);
+                       contactAnniversary->setLabel(label);
+               }
+       } catch (const TypeMismatchException& err ) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const BasePlatformException& err) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const ConversionException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
+               return NULL;
+       } catch(const NullPointerException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
                return NULL;
        }
 
-       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
-
-       std::tm date;
-       std::string label;
 
        Try {
                date = converter->toDateTm(arguments[0]);
+               contactAnniversary->setDate(date);
        } Catch(Exception) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
                *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Date object'");
                return NULL;
        }
 
-       Try {
-               if (js2ndParamIsString)
-                       label = converter->toString(arguments[1]);
-
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       ContactAnniversaryPtr contactAnniversary(new ContactAnniversary());
-       contactAnniversary->setDate(date);
-
-       if(js2ndParamIsString)
-               contactAnniversary->setLabel(label);
-
        JSObjectRef jsobject;
 
        Try {
index 8c8daf0..341efb3 100755 (executable)
@@ -159,75 +159,45 @@ JSObjectRef JSContactEmailAddress::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsArray = false;
-
        JSContactEmailAddressPriv *priv = static_cast<JSContactEmailAddressPriv*>(JSObjectGetPrivate(constructor));
        if (!priv) {
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
        }
        JSContextRef gContext = priv->getContext();
 
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount >= 2)
-               {
-                       if (JSIsArrayValue(gContext, arguments[1]))
-                               js2ndParamIsArray = true;
-
-                       if (!js2ndParamIsArray &&
-                                       !JSValueIsNull(gContext, arguments[1]) &&
-                                       !JSValueIsUndefined(gContext, arguments[1]))
-                               ThrowMsg(InvalidArgumentException, "2nd argument must be array of ContactEmailAddress types");
-               }
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be array of ContactEmailAddress types");
-               return NULL;
-       }
-
        ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
 
        std::string email;
        ContactEmailAddressTypeArrayPtr types(NULL);
-       bool isDefault;
+       bool isDefault = false;
 
-       Try {
-               if(argumentCount >= 1)
-                       email = converter->toString(arguments[0]);
-               else
-                       email = converter->toString(JSValueMakeUndefined(context));
-
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
+       try {
+               ArgumentValidator Argvalidator(context, argumentCount, arguments);
+               email = Argvalidator.toString(0, false);
 
-       Try {
-               if(js2ndParamIsArray)
+               if (argumentCount >= 2){
+                       Argvalidator.toArrayObject(1, true);
                        types = converter->toContactEmailAddressTypeArray(arguments[1]);
-               else
+               }else
                        types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
 
                if(types->size() == 0)
                        types->push_back(CONTACT_EMAIL_TYPE_WORK);
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       Try {
-               if(argumentCount >= 3)
-                       isDefault = converter->toBool(arguments[2]);
-               else
-                       isDefault = converter->toBool(JSValueMakeUndefined(context));
+               if (argumentCount >= 3)
+                       isDefault = Argvalidator.toBool(2, false);
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+       } catch (const TypeMismatchException& err ) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const BasePlatformException& err) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const ConversionException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
+               return NULL;
+       } catch(const NullPointerException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
                return NULL;
        }
 
@@ -395,6 +365,7 @@ bool JSContactEmailAddress::setTypes(JSContextRef context,
                        emailAddress->setTypes(JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(context, value));
                else
                        emailAddress->setTypes(converter->toContactEmailAddressTypeArray(value));
+               emailAddress->resetTypesJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
index cb8c7ee..a510287 100755 (executable)
@@ -177,25 +177,28 @@ JSObjectRef JSContactGroup::constructor(JSContextRef context,
        }
        JSContextRef gContext = priv->getContext();
 
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
-
        ContactGroupPtr contactGroup = ContactGroupPtr(new ContactGroup());
-       Try {
-               if(argumentCount >= 1)
-                       contactGroup->setName(converter->toString(arguments[0]));
-               else
-                       contactGroup->setName(converter->toString(JSValueMakeUndefined(context)));
+       try {
+               ArgumentValidator Argvalidator(context, argumentCount, arguments);
+               contactGroup->setName(Argvalidator.toString(0, false));
 
-               if(argumentCount >= 2 && !validator->isNullOrUndefined(arguments[1]))
-                       contactGroup->setRingtoneURI(converter->toString(arguments[1]));
+               if (argumentCount >= 2)
+                       contactGroup->setRingtoneURI(Argvalidator.toString(1, true));
 
-               if(argumentCount >= 3 && !validator->isNullOrUndefined(arguments[2]))
-                       contactGroup->setPhotoURI(converter->toString(arguments[2]));
+               if (argumentCount >= 3)
+                       contactGroup->setPhotoURI(Argvalidator.toString(2, true));
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       } catch (const TypeMismatchException& err ) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const BasePlatformException& err) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const ConversionException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
+               return NULL;
+       } catch(const NullPointerException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
                return NULL;
        }
 
index b56c561..d6ba76a 100755 (executable)
@@ -537,6 +537,7 @@ bool JSContactName::setNicknames(JSContextRef context,
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
                contactName->setNicknames(converter->toStringArray(value));
+               contactName->resetTypesJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
index c0501f9..fdd84c2 100755 (executable)
@@ -159,75 +159,44 @@ JSObjectRef JSContactPhoneNumber::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsArray = false;
-
        JSContactPhoneNumberPriv *priv = static_cast<JSContactPhoneNumberPriv*>(JSObjectGetPrivate(constructor));
        if (!priv) {
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
        }
        JSContextRef gContext = priv->getContext();
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount >= 2)
-               {
-                       if (JSIsArrayValue(gContext, arguments[1]))
-                               js2ndParamIsArray = true;
-
-                       if (!js2ndParamIsArray &&
-                                       !JSValueIsNull(gContext, arguments[1]) &&
-                                       !JSValueIsUndefined(gContext, arguments[1]))
-                               ThrowMsg(InvalidArgumentException, "2nd argument must be array of ContactPhoneNumber types");
-               }
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be array of ContactPhoneNumber types");
-               return NULL;
-       }
-
        ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
 
        std::string number;
        ContactPhoneNumberTypeArrayPtr types(NULL);
-       bool isDefault;
-
-       Try {
-               if(argumentCount >= 1)
-                       number = converter->toString(arguments[0]);
-               else
-                       number = converter->toString(JSValueMakeUndefined(context));
+       bool isDefault = false;
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
-               return NULL;
-       }
+       try {
+               ArgumentValidator Argvalidator(context, argumentCount, arguments);
+               number = Argvalidator.toString(0, false);
 
-       Try {
-               if(js2ndParamIsArray)
+               if (argumentCount >= 2){
+                       Argvalidator.toArrayObject(1, true);
                        types = converter->toContactPhoneNumberTypeArray(arguments[1]);
-               else
+               }else
                        types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
 
                if(types->size() == 0)
                        types->push_back(CONTACT_PHONE_NUMBER_TYPE_VOICE);
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       Try {
-               if(argumentCount >= 3)
-                       isDefault = converter->toBool(arguments[2]);
-               else
-                       isDefault = converter->toBool(JSValueMakeUndefined(context));
+               if (argumentCount >= 3)
+                       isDefault = Argvalidator.toBool(2, false);
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+       } catch (const TypeMismatchException& err ) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const BasePlatformException& err) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const ConversionException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
+               return NULL;
+       } catch(const NullPointerException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
                return NULL;
        }
 
@@ -390,6 +359,7 @@ bool JSContactPhoneNumber::setTypes(JSContextRef context,
                ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
 
                contactPhoneNumber->setTypes(converter->toContactPhoneNumberTypeArray(value));
+               contactPhoneNumber->resetTypesJSObj();
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
index 10a81d9..1455c6c 100755 (executable)
@@ -155,53 +155,38 @@ JSObjectRef JSContactWebSite::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsString = false;
-
        JSContactWebSitePriv *priv = static_cast<JSContactWebSitePriv*>(JSObjectGetPrivate(constructor));
        if (!priv) {
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
        }
        JSContextRef gContext = priv->getContext();
 
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount >= 2)
-               {
-                       if (!JSValueIsUndefined(context, arguments[1]) && !JSValueIsNull(context, arguments[1]))
-                               js2ndParamIsString = true;
-               }
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Date object'");
-               return NULL;
-       }
-
-       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
-
        std::string url;
+       std::string stringType;
        ContactWebSiteType type = WEBSITE_TYPE_HOMEPAGE;
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
 
-       Try {
-               if (argumentCount >= 1)
-                       url = converter->toString(arguments[0]);
-               else
-                       url = converter->toString(JSValueMakeUndefined(context));
-
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
+       try {
+               ArgumentValidator Argvalidator(context, argumentCount, arguments);
+               url = Argvalidator.toString(0, false);
 
-       Try {
-               if (js2ndParamIsString)
-                       type = converter->toContactWebSiteType(arguments[1]);
-               else
-                       type = WEBSITE_TYPE_HOMEPAGE;
+               if (argumentCount >= 2){
+                       stringType = Argvalidator.toString(1, true);
+                       type = converter->toContactWebSiteType(stringType);
+               }
 
-       } Catch(Exception) {
-               LogError("2nd argument only support 'HOMEPAGE' or 'BLOG'");
+       } catch (const TypeMismatchException& err ) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const BasePlatformException& err) {
+               JSWebAPIError::throwException(context, exception, err);
+               return NULL;
+       } catch(const ConversionException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
+               return NULL;
+       } catch(const NullPointerException& err) {
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
+               return NULL;
        }
 
        ContactWebSitePtr contactWebSite(new ContactWebSite());
index 2c4fe39..4ddbcf3 100755 (executable)
@@ -122,6 +122,13 @@ MediacontentMediaListPtr MediaConverter::toVectorOfMediaItem(JSValueRef events)
         JSValueRef element = JSGetArrayElement(m_context, objArg, i);
         JSObjectRef arg = JSValueToObject(m_context, element, NULL);
 
+        if (!JSValueIsObjectOfClass(m_context, element, JSMedia::getClassRef()) &&
+            !JSValueIsObjectOfClass(m_context, element, JSImage::getClassRef()) &&
+            !JSValueIsObjectOfClass(m_context, element, JSAudio::getClassRef()) &&
+            !JSValueIsObjectOfClass(m_context, element, JSVideo::getClassRef())) {
+                throw TypeMismatchException("content type mismatched.");
+        }
+
         if(JSValueIsObjectOfClass(m_context, element, JSImage::getClassRef())){
             JSValueRef geoValRef = JSUtil::getProperty(m_context , JSUtil::JSValueToObject(m_context, element), "geolocation");
             JSObjectRef geoObjRef = JSUtil::JSValueToObject(m_context, geoValRef);
index 75791db..7a082eb 100755 (executable)
-//\r
-// Tizen Web Device API\r
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the License);\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-// http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-\r
-#include <pthread.h>\r
-\r
-#include <dlog.h>\r
-\r
-#include <CommonsJavaScript/JSUtils.h>\r
-#include <CommonsJavaScript/Validator.h>\r
-#include <JSWebAPIError.h>\r
-#include "ContentListener.h"\r
-#include "ContentConverter.h"\r
-\r
-#undef LOG_TAG\r
-#define LOG_TAG "TIZEN_DEVICEAPI"\r
-\r
-using namespace DeviceAPI::Common;\r
-using namespace WrtDeviceApis::Commons;\r
-using namespace WrtDeviceApis::CommonsJavaScript;\r
-\r
-\r
-namespace DeviceAPI {\r
-namespace Content {\r
-\r
-ContentListener::ContentListener(JSContextRef globalCtx, JSObjectRef object)\r
-{\r
-       m_callback = new MultiCallbackUserData(globalCtx);\r
-\r
-       LOGD("%s:%d, thread_id=%ld", __FUNCTION__, __LINE__, pthread_self());\r
-       LOGD("%s:%d, context=%p", __FUNCTION__, __LINE__, globalCtx);\r
-\r
-       Validator validator(globalCtx);\r
-\r
-       // oncontentadded\r
-       JSValueRef oncontentadded = JSUtils::getJSPropertyOrUndefined(globalCtx, object, "oncontentadded");\r
-       if (validator.isNullOrUndefined(oncontentadded)) {\r
-               oncontentadded = NULL;\r
-       }\r
-       else if (validator.isCallback(oncontentadded)) {\r
-               JSObjectRef cbObj = JSValueToObject(globalCtx, oncontentadded, NULL);\r
-               if(JSObjectIsFunction(globalCtx, cbObj)) {\r
-                       m_callback->setCallback("oncontentadded", cbObj);\r
-               }\r
-               else {\r
-                       ThrowMsg(ConversionException,"oncontentadded is not a callback function.");\r
-               }\r
-       }\r
-       else{\r
-               ThrowMsg(ConversionException, "oncontentadded is not available");\r
-       }\r
-\r
-       // oncontentupdated\r
-       JSValueRef oncontentupdated = JSUtils::getJSPropertyOrUndefined(globalCtx, object, "oncontentupdated");\r
-       if (validator.isNullOrUndefined(oncontentupdated)) {\r
-               oncontentupdated = NULL;\r
-       }\r
-       else if (validator.isCallback(oncontentupdated)) {\r
-               JSObjectRef cbObj = JSValueToObject(globalCtx, oncontentupdated, NULL);\r
-               if(JSObjectIsFunction(globalCtx, cbObj)) {\r
-                       m_callback->setCallback("oncontentupdated", cbObj);\r
-               }\r
-               else {\r
-                       ThrowMsg(ConversionException,"oncontentupdated is not a callback function.");\r
-               }\r
-       }\r
-       else{\r
-               ThrowMsg(ConversionException, "oncontentupdated is not available");\r
-       }\r
-\r
-       // oncontentremoved\r
-       JSValueRef oncontentremoved = JSUtils::getJSPropertyOrUndefined(globalCtx, object, "oncontentremoved");\r
-       if (validator.isNullOrUndefined(oncontentremoved)) {\r
-               oncontentremoved = NULL;\r
-       }\r
-       else if (validator.isCallback(oncontentremoved)) {\r
-               JSObjectRef cbObj = JSValueToObject(globalCtx, oncontentremoved, NULL);\r
-               if(JSObjectIsFunction(globalCtx, cbObj)) {\r
-                       m_callback->setCallback("oncontentremoved", cbObj);\r
-               }\r
-               else {\r
-                       ThrowMsg(ConversionException,"oncontentremoved is not a callback function.");\r
-               }\r
-       }\r
-       else{\r
-               ThrowMsg(ConversionException, "oncontentremoved is not available");\r
-       }\r
-\r
-       if(!oncontentadded && !oncontentupdated && !oncontentremoved){\r
-               ThrowMsg(ConversionException, "contentChangeListener is not available");\r
-       }\r
-}\r
-\r
-ContentListener::~ContentListener() {\r
-       if(m_callback != NULL){\r
-               delete m_callback;\r
-               m_callback = NULL;\r
-       }\r
-}\r
-\r
-void ContentListener::oncontentadded(MediacontentMediaPtr content)\r
-{\r
-       JSContextRef context = m_callback->getContext();\r
-\r
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);\r
-       JSValueRef result = converter->toJSValueRefMedia(content);\r
-       m_callback->invokeCallback("oncontentadded", result);\r
-}\r
-\r
-void ContentListener::oncontentupdated(MediacontentMediaPtr content)\r
-{\r
-\r
-       JSContextRef context = m_callback->getContext();\r
-\r
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);\r
-       JSValueRef result = converter->toJSValueRefMedia(content);\r
-       m_callback->invokeCallback("oncontentupdated", result);\r
-\r
-}\r
-\r
-void ContentListener::oncontentremoved(std::string id)\r
-{\r
-       JSContextRef context = m_callback->getContext();\r
-\r
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);\r
-       m_callback->invokeCallback("oncontentremoved", converter->toJSValueRef(id));\r
-}\r
-\r
-\r
-} // Download\r
-} // DeviceAPI\r
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <pthread.h>
+
+#include <dlog.h>
+
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <JSWebAPIError.h>
+#include <JSUtil.h>
+#include "ContentListener.h"
+#include "ContentConverter.h"
+
+#undef LOG_TAG
+#define LOG_TAG "TIZEN_DEVICEAPI"
+
+using namespace DeviceAPI::Common;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace DeviceAPI {
+namespace Content {
+
+ContentListener::ContentListener(JSContextRef globalCtx, JSObjectRef object)
+{
+       m_callback = new MultiCallbackUserData(globalCtx);
+
+       LOGD("%s:%d, thread_id=%ld", __FUNCTION__, __LINE__, pthread_self());
+       LOGD("%s:%d, context=%p", __FUNCTION__, __LINE__, globalCtx);
+    // onstarted
+    JSValueRef oncontentadded = JSUtil::getProperty(globalCtx , object, "oncontentadded");
+    if(!JSValueIsUndefined(globalCtx,oncontentadded)) {
+        m_callback->setCallback("oncontentadded", JSUtil::JSValueToObject(globalCtx, oncontentadded));
+    }
+    JSValueRef oncontentupdated = JSUtil::getProperty(globalCtx , object, "oncontentupdated");
+    if(!JSValueIsUndefined(globalCtx,oncontentupdated)) {
+        m_callback->setCallback("oncontentupdated", JSUtil::JSValueToObject(globalCtx, oncontentupdated));
+    }
+    JSValueRef oncontentremoved = JSUtil::getProperty(globalCtx , object, "oncontentremoved");
+    if(!JSValueIsUndefined(globalCtx,oncontentremoved)) {
+        m_callback->setCallback("oncontentremoved", JSUtil::JSValueToObject(globalCtx, oncontentremoved));
+    }
+/*
+       // oncontentadded
+       JSValueRef oncontentadded = JSUtils::getJSPropertyOrUndefined(globalCtx, object, "oncontentadded");
+       if (validator.isNullOrUndefined(oncontentadded)) {
+               oncontentadded = NULL;
+       }
+       else if (validator.isCallback(oncontentadded)) {
+               JSObjectRef cbObj = JSValueToObject(globalCtx, oncontentadded, NULL);
+               if(JSObjectIsFunction(globalCtx, cbObj)) {
+                       m_callback->setCallback("oncontentadded", cbObj);
+               }
+               else {
+                       ThrowMsg(ConversionException,"oncontentadded is not a callback function.");
+               }
+       }
+       else{
+               ThrowMsg(ConversionException, "oncontentadded is not available");
+       }
+
+       // oncontentupdated
+       JSValueRef oncontentupdated = JSUtils::getJSPropertyOrUndefined(globalCtx, object, "oncontentupdated");
+       if (validator.isNullOrUndefined(oncontentupdated)) {
+               oncontentupdated = NULL;
+       }
+       else if (validator.isCallback(oncontentupdated)) {
+               JSObjectRef cbObj = JSValueToObject(globalCtx, oncontentupdated, NULL);
+               if(JSObjectIsFunction(globalCtx, cbObj)) {
+                       m_callback->setCallback("oncontentupdated", cbObj);
+               }
+               else {
+                       ThrowMsg(ConversionException,"oncontentupdated is not a callback function.");
+               }
+       }
+       else{
+               ThrowMsg(ConversionException, "oncontentupdated is not available");
+       }
+
+       // oncontentremoved
+       JSValueRef oncontentremoved = JSUtils::getJSPropertyOrUndefined(globalCtx, object, "oncontentremoved");
+       if (validator.isNullOrUndefined(oncontentremoved)) {
+               oncontentremoved = NULL;
+       }
+       else if (validator.isCallback(oncontentremoved)) {
+               JSObjectRef cbObj = JSValueToObject(globalCtx, oncontentremoved, NULL);
+               if(JSObjectIsFunction(globalCtx, cbObj)) {
+                       m_callback->setCallback("oncontentremoved", cbObj);
+               }
+               else {
+                       ThrowMsg(ConversionException,"oncontentremoved is not a callback function.");
+               }
+       }
+       else{
+               ThrowMsg(ConversionException, "oncontentremoved is not available");
+       }
+*/
+}
+
+ContentListener::~ContentListener() {
+       if(m_callback != NULL){
+               delete m_callback;
+               m_callback = NULL;
+       }
+}
+
+void ContentListener::oncontentadded(MediacontentMediaPtr content)
+{
+        LogInfo("ContentListener::oncontentadded is entered");
+        JSContextRef context = m_callback->getContext();
+
+        MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+        JSValueRef result = converter->toJSValueRefMedia(content);
+        m_callback->invokeCallback("oncontentadded", result);
+}
+
+void ContentListener::oncontentupdated(MediacontentMediaPtr content)
+{
+        LogInfo("ContentListener::oncontentupdated is entered");
+        JSContextRef context = m_callback->getContext();
+
+        MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+        JSValueRef result = converter->toJSValueRefMedia(content);
+        m_callback->invokeCallback("oncontentupdated", result);
+
+}
+
+void ContentListener::oncontentremoved(std::string id)
+{
+        LogInfo("ContentListener::oncontentremoved is entered");
+        JSContextRef context = m_callback->getContext();
+
+        MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+        m_callback->invokeCallback("oncontentremoved", converter->toJSValueRef(id));
+}
+
+
+} // Download
+} // DeviceAPI
index 673a660..caf44a3 100755 (executable)
@@ -315,7 +315,6 @@ bool IMediacontentManager::setListener( void* user_data)
        {
                ret = true;
        }
-
        return ret;
 }
 
index 3ed1958..762b5fc 100755 (executable)
@@ -90,7 +90,7 @@ void JSAudio::initialize(JSContextRef context, JSObjectRef object)
 {
     LogDebug( "entered" );
     AudioPrivObject *priv = static_cast<AudioPrivObject*>( JSObjectGetPrivate( object ) );
-    if (!priv) 
+    if (!priv)
     {
         MediacontentAudioPtr privateData(new MediacontentAudio());
         priv = new AudioPrivObject(context, privateData);
@@ -146,7 +146,7 @@ MediacontentAudioPtr JSAudio::getAudioObject(JSObjectRef object)
     }
     return result;
 }
-                                       
+
 JSValueRef JSAudio::getPropertyAlbum(
                                JSContextRef context,
                        JSObjectRef object,
@@ -158,13 +158,15 @@ JSValueRef JSAudio::getPropertyAlbum(
     {
         Converter converter(context);
         MediacontentAudioPtr audio = getAudioObject(object);
-        return converter.toJSValueRef(audio->getAudioAlbum());
+        if(!audio->getAudioAlbum().empty()){
+            return converter.toJSValueRef(audio->getAudioAlbum());
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSAudio::getPropertyArtist(
@@ -176,33 +178,29 @@ JSValueRef JSAudio::getPropertyArtist(
     LogDebug("getPropertyArtist::entered");
     Try
     {  
-
-               Converter converter(context);
-                       MediacontentAudioPtr audio = getAudioObject(object);
-               JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
-               if (NULL == jsResult) 
-               {
-                       ThrowMsg(NullPointerException, "Could not create js array object");
-               }
-
-               for( unsigned int i=0; i < audio->getAudioArtist().size(); i++) 
-               {
-                       string artist = audio->getAudioArtist().at(i);
-                       LogDebug("artist : "  << artist);
-                       JSValueRef val = converter.toJSValueRef(artist);
-                       if(!JSSetArrayElement(context, jsResult, i, val)) 
-                       {
-                          ThrowMsg(UnknownException, "Could not insert value into js array");
-                       }
-               }
-
-               return jsResult;  
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        if(audio->getAudioArtist().size() != 0){
+            JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+            if (NULL == jsResult){
+                ThrowMsg(NullPointerException, "Could not create js array object");
+            }
+            for( unsigned int i=0; i < audio->getAudioArtist().size(); i++){
+                string artist = audio->getAudioArtist().at(i);
+                LogDebug("artist : "  << artist);
+                JSValueRef val = converter.toJSValueRef(artist);
+                if(!JSSetArrayElement(context, jsResult, i, val)){
+                    ThrowMsg(UnknownException, "Could not insert value into js array");
+                }
+            }
+            return jsResult;
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
@@ -216,33 +214,30 @@ JSValueRef JSAudio::getPropertyGenre(
     LogDebug("getPropertyGenre::entered");
     Try
     {
-
-                       Converter converter(context);
-               MediacontentAudioPtr audio = getAudioObject(object);
-               JSObjectRef jsResult = JSCreateArrayObject(context, 0 , NULL);
-
-               if (NULL == jsResult) 
-               {
-                       ThrowMsg(NullPointerException, "Could not create js array object");
-               }
-               
-               for( unsigned int i=0; i < audio->getAudioGenre().size(); i++) 
-               {
-                       string genre = audio->getAudioGenre().at(i);
-                       JSValueRef val = converter.toJSValueRef(genre);
-                       if(!JSSetArrayElement(context, jsResult, i, val)) 
-                       {
-                          ThrowMsg(UnknownException, "Could not insert value into js array");
-                       }
-               }
-
-               return jsResult;
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        if(audio->getAudioGenre().size() != 0){
+            JSObjectRef jsResult = JSCreateArrayObject(context, 0 , NULL);
+            if (NULL == jsResult)
+            {
+                ThrowMsg(NullPointerException, "Could not create js array object");
+            }
+
+            for( unsigned int i=0; i < audio->getAudioGenre().size(); i++){
+                string genre = audio->getAudioGenre().at(i);
+                JSValueRef val = converter.toJSValueRef(genre);
+                if(!JSSetArrayElement(context, jsResult, i, val)){
+                   ThrowMsg(UnknownException, "Could not insert value into js array");
+                }
+            }
+            return jsResult;
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
@@ -255,34 +250,28 @@ JSValueRef JSAudio::getPropertyComposer(
     LogDebug("getPropertyComposer::entered");
     Try
     {  
-
-               Converter converter(context);
-               MediacontentAudioPtr audio = getAudioObject(object);
-
-               JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
-
-               if (NULL == jsResult) 
-               {
-                       ThrowMsg(NullPointerException, "Could not create js array object");
-               }
-
-               for( unsigned int i=0; i < audio->getAudioComposer().size(); i++) 
-               {
-                       string composer = audio->getAudioComposer().at(i);
-                       JSValueRef val = converter.toJSValueRef(composer);
-                       if(!JSSetArrayElement(context, jsResult, i, val)) 
-                       {
-                          ThrowMsg(UnknownException, "Could not insert value into js array");
-                       }
-               }
-
-               return jsResult;
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        if(audio->getAudioComposer().size() != 0){
+            JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+            if (NULL == jsResult){
+                ThrowMsg(NullPointerException, "Could not create js array object");
+            }
+            for( unsigned int i=0; i < audio->getAudioComposer().size(); i++){
+                string composer = audio->getAudioComposer().at(i);
+                JSValueRef val = converter.toJSValueRef(composer);
+                if(!JSSetArrayElement(context, jsResult, i, val)){
+                    ThrowMsg(UnknownException, "Could not insert value into js array");
+                }
+            }
+            return jsResult;
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSAudio::getPropertyCopyright(
@@ -296,13 +285,15 @@ JSValueRef JSAudio::getPropertyCopyright(
     {
         Converter converter(context);
         MediacontentAudioPtr audio = getAudioObject(object);
-        return converter.toJSValueRef(audio->getAudioCopyright());
+        if(!audio->getAudioCopyright().empty()){
+            return converter.toJSValueRef(audio->getAudioCopyright());
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSAudio::getPropertyLyrics(
@@ -351,7 +342,7 @@ JSValueRef JSAudio::getPropertyLyrics(
                        mediaContent = audio->getAudioLyrics();
                }
                
-               if (mediaContent)
+               if (mediaContent && (audio->getLyricsState() != CONTENT_LYRIC_NON_EXISTENT))
                {
                        LogDebug(" lyrics success ");
                        JSObjectRef jsobject;
@@ -371,7 +362,7 @@ JSValueRef JSAudio::getPropertyLyrics(
         LogWarning("trying to get incorrect value");
     }
 
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSAudio::getPropertyBitrate(
@@ -391,7 +382,7 @@ JSValueRef JSAudio::getPropertyBitrate(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSAudio::getPropertyTrackNum(
@@ -411,7 +402,7 @@ JSValueRef JSAudio::getPropertyTrackNum(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSAudio::getPropertyDuration(
@@ -431,7 +422,7 @@ JSValueRef JSAudio::getPropertyDuration(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSAudio::getPropertySize(
@@ -466,7 +457,7 @@ bool JSAudio::setPropertyAlbum(
     Try
     {
         Converter converter(context);
-                       
+
         MediacontentAudioPtr audio = getAudioObject(object);
         string album = converter.toString(value);
         audio->setAudioAlbum(album, true);
@@ -500,7 +491,7 @@ bool  JSAudio::setPropertyArtist(
                if (JSIsArrayValue(context, value))
                {
                JSObjectRef jsObject = converter.toJSObjectRef(value);
-               
+
                for (std::size_t i = 0; i < JSGetArrayLength(context, jsObject); ++i) {
                        JSValueRef element = JSGetArrayElement(context, jsObject, i);
                        artists.push_back(converter.toString(element));
index fcff7bd..88514e3 100755 (executable)
@@ -270,25 +270,23 @@ JSValueRef JSMedia::getPropertyThumbnailPath(
         Converter converter(context);
         MediacontentMediaPtr media = getMediaObject(object);
         JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
-               if (NULL == jsResult) 
-               {
-                       ThrowMsg(NullPointerException, "Could not create js array object");
-               }
-
-               JSValueRef val = converter.toJSValueRef(media->getThumbnailPath());
-               if(!JSSetArrayElement(context, jsResult, 0, val)) 
-               {
-                  ThrowMsg(UnknownException, "Could not insert value into js array");
-               }
+        if (NULL == jsResult){
+            ThrowMsg(NullPointerException, "Could not create js array object");
+        }
 
-               return jsResult;      
-        
+        if(!(media->getThumbnailPath().empty())){
+            JSValueRef val = converter.toJSValueRef(media->getThumbnailPath());
+            if(!JSSetArrayElement(context, jsResult, 0, val)){
+                ThrowMsg(UnknownException, "Could not insert value into js array");
+            }
+            return jsResult;
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSMedia::getPropertyDescription(
@@ -302,13 +300,16 @@ JSValueRef JSMedia::getPropertyDescription(
     {
         Converter converter(context);
         MediacontentMediaPtr media = getMediaObject(object);
-        return converter.toJSValueRef(media->getDescription());
+        if(!(media->getDescription().empty()))
+        {
+            return converter.toJSValueRef(media->getDescription());
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
@@ -332,7 +333,7 @@ JSValueRef JSMedia::getPropertyModifiedDate(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSMedia::getPropertyReleasedDate(
@@ -355,7 +356,7 @@ JSValueRef JSMedia::getPropertyReleasedDate(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 
 }
 
@@ -377,7 +378,7 @@ JSValueRef JSMedia::getPropertyRating(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 JSValueRef JSMedia::getPropertyType(
@@ -421,7 +422,7 @@ JSValueRef JSMedia::getPropertySize(
         LogWarning("trying to get incorrect value");
     }
 
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
index 26ec105..eb47c22 100755 (executable)
 #include <MultiCallbackUserData.h>
 #include <GlobalContextManager.h>
 #include <FilterConverter.h>
-#include "JSUtil.h"
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+
 
+#include "JSUtil.h"
 #include "ContentFactory.h"
 #include "ContentController.h"
 #include "JSContentManager.h"
@@ -50,6 +53,8 @@
 #include "ContentVideo.h"
 #include "ContentImage.h"
 #include "ContentFilterConverter.h"
+#include "ContentUtility.h"
+#include "JSWebAPIException.h"
 
 
 using namespace DeviceAPI::Common;
@@ -57,7 +62,7 @@ using namespace DeviceAPI::Tizen;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
-#define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME                            "content"
+#define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME                 "content"
 
 namespace DeviceAPI {
 namespace Content {
@@ -69,13 +74,13 @@ JSStaticValue JSMediacontentManager::m_property[] =
 
 JSStaticFunction JSMediacontentManager::m_function[] = 
 {
-       { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
+    { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
     { 0, 0, 0 }
 };
 
@@ -84,120 +89,104 @@ JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
 
 JSClassDefinition JSMediacontentManager::m_classInfo =
 {
-               0,
-               kJSClassAttributeNone,
-               TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
-               0,
-               m_property,
-               m_function,
-               initialize,
-               finalize,
-               NULL, //hasProperty,
-               NULL, //getProperty,
-               NULL, //setProperty,
-               NULL, //deleteProperty,
-               NULL, //getPropertyNames,
-               NULL, //callAsFunction,
-               NULL, //callAsConstructor,
-               NULL,
-               NULL, //convertToType
+        0,
+        kJSClassAttributeNone,
+        TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
+        0,
+        m_property,
+        m_function,
+        initialize,
+        finalize,
+        NULL, //hasProperty,
+        NULL, //getProperty,
+        NULL, //setProperty,
+        NULL, //deleteProperty,
+        NULL, //getPropertyNames,
+        NULL, //callAsFunction,
+        NULL, //callAsConstructor,
+        NULL,
+        NULL, //convertToType
 };
 
 JSValueRef JSMediacontentManager::getFolders(
-                                                       JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSObjectRef thisObject,
-                                                       size_t argumentCount,
-                                                       const JSValueRef arguments[],
-                                                       JSValueRef* exception )
+                            JSContextRef context,
+                            JSObjectRef object,
+                            JSObjectRef thisObject,
+                            size_t argumentCount,
+                            const JSValueRef arguments[],
+                            JSValueRef* exception )
 {
-       LogDebug("JSContentManagerManager::getFolders entered");
+    LogDebug("JSContentManagerManager::getFolders entered");
 
+    MediacontentManagerPrivObject *privateObject;
+    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    if (!privateObject) {
+        DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
+    JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
 
-       JSContextRef globalContext = privateObject->getContext();
-       Validator validator(context);
     JSCallbackManagerPtr cbm(NULL);
-    FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+    cbm = JSCallbackManager::createObject(globalContext);
+    
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+        JSObjectRef successCallbackObj = argValidator.toFunction(0);
+        if(successCallbackObj){
+            cbm->setOnSuccess(successCallbackObj);
+        }
+        else{
+            throw TypeMismatchException("SuccessCallback type mismatched.");
+        }
 
-       cbm = JSCallbackManager::createObject(globalContext);
-       cbm->setObject(thisObject);
+        JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
+        if(errorCallbackObj){
+            cbm->setOnError(errorCallbackObj);
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIException::throwException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
     Try
     {
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-
-               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-               if(argumentCount >= 1)  //MediaFolderArraySuccessCB successCallback
-               {
-                       if(validator.isCallback(arguments[0]))
-                       {
-                               onSuccessForCbm = arguments[0];
-                       }
-                       else
-                       {
-                               ThrowMsg(ConversionException, "SuccessCallback type mismatched.");
-                       }
-               }
-               else
-               {
-                       ThrowMsg(ConversionException,"There is no successCallback.");
-               }
-               if(argumentCount >= 2)  //optional ErrorCallback? errorCallback
-               {
-                       if(validator.isCallback(arguments[1]))
-                       {
-                               onErrorForCbm = arguments[1];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
-                       }
-               }
-               if(cbm)
-               {
-                       cbm->setOnSuccess(onSuccessForCbm);
-                       cbm->setOnError(onErrorForCbm);
-               }
-
-               IEventFindFolderPtr dplEvent(new IEventFindFolder());
-               dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
-               dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
-
-               contentMgr->findFolder(dplEvent);
-
-               MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+        IEventFindFolderPtr dplEvent(new IEventFindFolder());
+        dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
+        dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
+
+        contentMgr->findFolder(dplEvent);
+
+        MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
     }
     Catch(WrtDeviceApis::Commons::UnsupportedException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::ConversionException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::NotFoundException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::Exception)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
@@ -208,178 +197,133 @@ JSValueRef JSMediacontentManager::getFolders(
 
 
 JSValueRef JSMediacontentManager::findItems(
-                                                       JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSObjectRef thisObject,
-                                                       size_t argumentCount,
-                                                       const JSValueRef arguments[],
-                                                       JSValueRef* exception )
+                            JSContextRef context,
+                            JSObjectRef object,
+                            JSObjectRef thisObject,
+                            size_t argumentCount,
+                            const JSValueRef arguments[],
+                            JSValueRef* exception )
 {
+    LogDebug("JSContentManagerManager::find entered");
 
-       LogDebug("JSContentManagerManager::findItems entered");
-
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
+    MediacontentManagerPrivObject *privateObject;
+    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    if(!privateObject) {
+        DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 
+    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_FIND_ITEMS);
 
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(
-            CONTENT_FUNCTION_API_FIND_ITEMS);
+    JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
 
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    JSCallbackManagerPtr cbm(NULL);
+    MediaContentFilterConverterFactory::ConverterType fConverter = MediaContentFilterConverterFactory::getConverter(context);
+    MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+
+    cbm = JSCallbackManager::createObject(globalContext);
+
+    string folderId;
+    Tizen::FilterPtr filter;
+    Tizen::SortModePtr sortPtr;
+    JSObjectRef filterObj;
+    JSObjectRef sortModeObj;
+    IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+        JSObjectRef successCallbackObj = argValidator.toFunction(0);
+        if(successCallbackObj){
+            cbm->setOnSuccess(successCallbackObj);
+        }
+        else{
+            throw TypeMismatchException("SuccessCallback type mismatched.");
+        }
 
+        JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
+        if(errorCallbackObj){
+            cbm->setOnError(errorCallbackObj);
+        }
 
-       JSContextRef globalContext = privateObject->getContext();
-       Validator validator(context);
-    JSCallbackManagerPtr cbm(NULL);
-    MediaContentFilterConverterFactory::ConverterType filterConverter = MediaContentFilterConverterFactory::getConverter(context);
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
-       MediaConverter mediaConverter(globalContext);
+        folderId = argValidator.toString(2, true);
+        if(!folderId.empty()){
+            if(folderId == "null" || folderId == "undefined"){
+                throw InvalidValuesException("folderId is not valid.");
+            }
+            dplEvent->setFolderID(folderId);
+        }
+        //filter
+        filterObj = argValidator.toObject(3,true);
 
-       cbm = JSCallbackManager::createObject(globalContext);
-       cbm->setObject(thisObject);
+        //sortMode
+        sortModeObj= argValidator.toObject(4,true);
 
+        // count
+        if(argumentCount >= 6){        
+            unsigned long count = argValidator.toLong(5, true, -1);
+            if( count >= 0 ){
+                dplEvent->setLimit(count);
+            }
+            else{
+                throw InvalidValuesException( "count should be positive.");
+            }
+        }
+        if(argumentCount >= 7){
+            // offset
+            unsigned long offset = argValidator.toLong(6, true);
+            if( offset >= 0 ){
+                dplEvent->setOffset(offset);
+            }
+            else{
+                throw InvalidValuesException("offset should be positive.");
+            }
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIException::throwException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
     Try
     {
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-               IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
-               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-               if(argumentCount >= 1)  //MediaItemArraySuccessCB successCallback
-               {
-                       if(validator.isCallback(arguments[0]))
-                       {
-                               onSuccessForCbm = arguments[0];
-                       }
-                       else
-                       {
-                               ThrowMsg(ConversionException,"SuccessCallback type mismatched.");
-                       }
-               }
-               else
-               {
-                       ThrowMsg(ConversionException,"There is no SuccessCallback.");
-               }
-               if(argumentCount >= 2)  //ErrorCallback? errorCallback
-               {
-                       if(validator.isCallback(arguments[1]))
-                       {
-                               onErrorForCbm = arguments[1];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
-                       }
-               }
-               if(cbm)
-               {
-                       cbm->setOnSuccess(onSuccessForCbm);
-                       cbm->setOnError(onErrorForCbm);
-               }
-
-               if(argumentCount >= 3)  //MediaFolderId id,
-               {
-                       string folderId = mediaConverter.toString(arguments[2]);
-                       if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0)  )
-                       {
-                               LogDebug("folderId:"+ folderId);
-
-                               int nFolderId = 0;
-                               istringstream(folderId) >> nFolderId; //string -> int
-
-                               if (nFolderId<0)
-                               {
-                                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
-                                               JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
-                                       return JSValueMakeUndefined(context);
-                               }
-
-                               dplEvent->setFolderID(folderId);
-                       }
-               }
-
-               if(argumentCount >= 4)  //optional AbstractFilter? filter
-               {
-                       if(JSValueIsObject(context, arguments[3]))
-                       {
-                               dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[3]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"Filter type mismatched.");
-                       }
-               }
-               if(argumentCount >= 5)  //optional SortMode? sortMode
-               {
-
-                       if ( JSValueIsObject(context, arguments[4]) &&
-                               !JSValueIsNull(context, arguments[4]) &&
-                               !JSValueIsUndefined(context, arguments[4]) &&
-                               !JSIsArrayValue(context, arguments[4]))
-                       {
-                               LogDebug("sortmode is object");
-                               dplEvent->setSortMode(filterConverter->toSortMode(arguments[4]));
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[4]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"SortMode type mismatched.");
-                       }
-               }
-               if(argumentCount >= 6)  //optional unsigned long? count
-               {
-                       if(!JSValueIsNull(context, arguments[5]) && !JSValueIsUndefined(context, arguments[5])){
-                               long count = filterConverter->toLong(arguments[5]);
-                               if( count >= 0 ){
-                                       dplEvent->setLimit(count);
-                               }
-                               else{
-                                       ThrowMsg(InvalidArgumentException, "count should be positive.");
-                               }
-                       }
-               }
-               if(argumentCount >= 7)  //optional unsigned long? offset
-               {
-                       long offset = filterConverter->toLong(arguments[6]);
-                       if( offset >= 0 ){
-                               dplEvent->setOffset(offset);
-                       }
-                       else{
-                               ThrowMsg(InvalidArgumentException, "offset should be positive.");
-                       }
-               }
+        if(filterObj){
+            dplEvent->setFilter(fConverter->toFilter(filterObj));
+        }
+        if(sortModeObj){
+            dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
+        }
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
         contentMgr->browseFolder(dplEvent);
-
-               MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+        MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
     }
     Catch(WrtDeviceApis::Commons::UnsupportedException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::ConversionException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::NotFoundException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::Exception)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
@@ -396,108 +340,93 @@ JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
         JSValueRef* exception)
 {
     LogDebug("JSContentManagerManager::updateItemsBatch entered");
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
+    MediacontentManagerPrivObject *privateObject;
+    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    if(!privateObject) {
+        DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 
-       JSContextRef globalContext = privateObject->getContext();
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(
-            CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       Validator validator(context);
     JSCallbackManagerPtr cbm(NULL);
-    FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
-
-       cbm = JSCallbackManager::createObject(globalContext);
-       cbm->setObject(thisObject);
-
-       Try
-    {
-
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-
-               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-               MediacontentMediaListPtr events;
-               if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0])))     //MediaItem[] items
-               {
-                       events = converter->toVectorOfMediaItem(arguments[0]);
-                       if(!events)
-                       {
-                               ThrowMsg(ConversionException, "Items type mismatched.");
-                       }
-               }
-               else
-               {
-                       ThrowMsg(ConversionException, "Items type mismatched.");
-               }
-
-               if(argumentCount >= 2)  //Function? successCallback,
-               {
-                       if(validator.isCallback(arguments[1]))
-                       {
-                               onSuccessForCbm = arguments[1];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"successCallback type mismatched.");
-                       }
-               }
-
-               if(argumentCount >= 3)  //ErrorCallback? errorCallback,
-               {
-                       if(validator.isCallback(arguments[2]))
-                       {
-                               onErrorForCbm = arguments[2];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[2]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"ErrorCallback type is mismatched.");
-                       }
-               }
-
-               if(cbm)
-               {
-                       cbm->setOnSuccess(onSuccessForCbm);
-                       cbm->setOnError(onErrorForCbm);
-               }
+    MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+
+    cbm = JSCallbackManager::createObject(globalContext);
+
+    MediacontentMediaListPtr contents;
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+
+        if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
+            contents = converter->toVectorOfMediaItem(arguments[0]);
+            if(!contents)
+            {
+                throw TypeMismatchException( "content type mismatched.");
+            }
+        }
+        else{
+            throw TypeMismatchException("content type mismatched.");
+        }
+        
+        JSObjectRef successCallbackObj = argValidator.toFunction(1,true);        
+        if(successCallbackObj){
+            cbm->setOnSuccess(successCallbackObj);
+        }
+        else{
+            throw TypeMismatchException("SuccessCallback type mismatched.");
+        }
+
+        JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
+        if(errorCallbackObj){
+            cbm->setOnError(errorCallbackObj);
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIException::throwException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+
+    Try
+    {
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
 
         IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
-        dplEvent->setMediaItems(events);
+        dplEvent->setMediaItems(contents);
         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
 
         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
         contentMgr->updateMediaItems(dplEvent);
 
-               MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+        MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
     }
     Catch(WrtDeviceApis::Commons::UnsupportedException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::ConversionException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::NotFoundException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::Exception)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
@@ -507,386 +436,308 @@ JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
 
 
 JSValueRef JSMediacontentManager::updateItem(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
 {
-LogDebug("JSContentManagerManager::updateItem entered");
-
-
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-
-
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
-
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    LogDebug("JSContentManagerManager::updateItem entered");
 
-       Validator validator(context);
-
-       Try
-       {
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-
-               //parameter : MediaItem item
-
-               JSObjectRef arg;
-               if(argumentCount >= 1)
-               {
-                       if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
-                               !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
-                               !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&                       
-                               !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
-                                   ThrowMsg(ConversionException, "Item type mismatched.");
-                       }
-                       arg = JSValueToObject(context, arguments[0], exception);
-               }
-               else
-               {
-                        ThrowMsg(ConversionException, "Item type mismatched.");
-               }
-
-               MediacontentMediaPtr event;
-               IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
+    MediacontentManagerPrivObject *privateObject;
+    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    if (!privateObject) {
+        DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 
-               if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
+    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-                       JSValueRef geoValRef = JSUtil::getProperty(context ,
-                               JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
-                       JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
-                       double latitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "latitude"));
+    Try
+    {
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+        //parameter : MediaItem item
+
+        JSObjectRef arg;
+        if(argumentCount >= 1)
+        {
+            if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
+                !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
+                !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&           
+                !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
+                    ThrowMsg(ConversionException, "Content type mismatched.");
+            }
+            arg = JSValueToObject(context, arguments[0], exception);
+        }
+        else
+        {
+             ThrowMsg(ConversionException, "Content type mismatched.");
+        }
 
-                       double longitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "longitude"));
+        MediacontentMediaPtr event;
+        IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
 
-                       MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
-                       imgPtr->setImageLatitude(latitude);
-                       imgPtr->setImageLongitude(longitude);
+        if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
+            JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
+            JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
+            double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
+            double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
 
-               }
-               else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
-                       JSValueRef geoValRef = JSUtil::getProperty(context ,
-                               JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
-                       JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
+            MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
+            imgPtr->setImageLatitude(latitude);
+            imgPtr->setImageLongitude(longitude);
+        }
+        else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
+            JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
+            JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
 
-                       double latitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "latitude"));
+            double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
 
-                       double longitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "longitude"));
+            double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
 
-                       MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
-                       vedioPtr->setVideoLatitude(latitude);
-                       vedioPtr->setVideoLongitude(longitude);
-               }
+            MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
+            vedioPtr->setVideoLatitude(latitude);
+            vedioPtr->setVideoLongitude(longitude);
+        }
 
-               event = JSMedia::getMediaObject(arg);
-               dplEvent->setMediaItem(event);
+        event = JSMedia::getMediaObject(arg);
+        dplEvent->setMediaItem(event);
 
-               dplEvent->setForSynchronousCall();
-               contentMgr->updateMedia(dplEvent);
+        dplEvent->setForSynchronousCall();
+        contentMgr->updateMedia(dplEvent);
 
         if (!(dplEvent->getResult())) {
             ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
         }
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+    }
+    Catch(WrtDeviceApis::Commons::UnsupportedException)
+    {
+    LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+    {
+    LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException)
+    {
+    LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::NotFoundException)
+    {
+    LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+    LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return JSValueMakeUndefined(context);
 
 }
 
 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
     CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
-       if(cb != NULL){
-                       if(err_msg.empty() ){
-                               Converter converter(cb->getContext());
-                               JSValueRef jsPath = converter.toJSValueRef(path);
-                               cb->callSuccessCallback(jsPath);
-                       }
-                       else{
-                               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cb->getContext(), JSTizenException::UNKNOWN_ERROR, err_msg);
-                               cb->callErrorCallback(errorObject);
-                       }
-                       delete cb;
-       }
+    if(cb != NULL){
+            if(err_msg.empty() ){
+                        Converter converter(cb->getContext());
+                        JSValueRef jsPath = converter.toJSValueRef(path);
+                        cb->callSuccessCallback(jsPath);
+            }
+            else{
+                        DeviceAPI::Common::UnknownException err(err_msg.c_str());
+                        JSObjectRef errorObject = JSWebAPIError::makeJSWebAPIError(cb->getContext(),err);
+                        cb->callErrorCallback(errorObject);
+            }
+            delete cb;
+    }
 }
 
 JSValueRef JSMediacontentManager::scanFile(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
 {
-       LogDebug("JSContentManagerManager::scanFile entered");
-
-
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       Try
-       {
-
-               if(!privateObject){
-                       ThrowMsg(ConversionException, "private object is null");
-               }
-
-               CallbackUserData *callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-
-               Converter convert(context);
-               Validator validator(context);
-               IMediacontentManagerPtr contentMgr = privateObject->getObject();
-               string path;
-
-               if(argumentCount >= 1){                                 //directoryURI
-                       path = convert.toString(arguments[0]);
-                       if(validator.isNullOrUndefined(arguments[0])){
-                               ThrowMsg(InvalidArgumentException, path+" is not available");
-                       }
-               }
-               else{
-                       ThrowMsg(InvalidArgumentException, "file path is not available");
-               }
-
-               if(argumentCount >= 2){                                 //successCallback[optional|nullable]
-                       if(validator.isCallback(arguments[1])){
-                               callback->setSuccessCallback(arguments[1]);
-                       }
-                       else if(!(JSValueIsNull(context,arguments[1]))){
-                               ThrowMsg(ConversionException, path + ":successCallback is not available");
-                       }
-               }
-
-               if(argumentCount >= 3){                                 //errorCallback
-                       if(validator.isCallback(arguments[2])){
-                               callback->setErrorCallback(arguments[2]);
-                       }
-                       else if(!(JSValueIsNull(context,arguments[2]))){
-                               ThrowMsg(ConversionException, path + ":errorCallback is not available");
-                       }
-               }
-
-               contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
-
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+    LogDebug("JSContentManagerManager::scanFile entered");
 
-}
+    MediacontentManagerPrivObject *privateObject;
+    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    if(!privateObject) {
+        DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
+    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    string path;
+    CallbackUserData *callback = NULL;
+    try{
+        callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));    
+        ArgumentValidator argValidator(context, argumentCount, arguments);    
+        path = argValidator.toString(0);
+        if(path.empty()){
+            throw TypeMismatchException("File path type mismatched.");
+        }
+        else if(path == "null" || path == "undefined"){
+            throw InvalidValuesException("File path is not valid.");
+        }
+        path = ContentUtility::convertUriToPath(path);
 
-JSValueRef JSMediacontentManager::setChangeListener(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
-{
-       LogDebug("JSContentManagerManager::setChangeListener entered");
+        JSObjectRef successCallbackObj = argValidator.toFunction(1,true);        
+        if(successCallbackObj){
+            callback->setSuccessCallback(successCallbackObj);
+        }
 
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+        JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
+        if(errorCallbackObj){
+            callback->setErrorCallback(errorCallbackObj);
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIException::throwException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    Try
+    {
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+        contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
+    }
+    Catch(WrtDeviceApis::Commons::UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
 
-       Try
-       {
+    return JSValueMakeUndefined(context);
 
-               if(!privateObject){
-                       ThrowMsg(ConversionException, "private object is null");
-               }
+}
 
-        if(argumentCount>=1) {
-            if (!JSValueIsObject(context, arguments[0])) {
-                ThrowMsg(ConversionException, "Wrong first parameter type.");
-            }
-        }
-               else{
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-        }
 
-               Converter convert(context);
-               Validator validator(context);
-
-               JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
-
-               // changeCallback Object
-               JSObjectRef callbackObj = convert.toJSObjectRef(arguments[0]);
-
-               ContentListener *listener = new ContentListener(globalCtx, callbackObj);
-
-               // perform
-               IMediacontentManagerPtr contentMgr = privateObject->getObject();
-               if(!(contentMgr->setListener(listener)))
-               {
-                       ThrowMsg(Exception, "Unknown exception is occured by platfrom");
-               }
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+JSValueRef JSMediacontentManager::setChangeListener(
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
+{
+    LogDebug("JSContentManagerManager::setChangeListener entered");
+
+    MediacontentManagerPrivObject *privateObject;
+    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    if(!privateObject) {
+        DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+
+    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+        JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);        
+        JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
+        ContentListener *listener = new ContentListener(globalCtx, callbackObj);
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+        if(!(contentMgr->setListener(listener)))
+        {
+            throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIException::throwException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+    return JSValueMakeUndefined(context);
 
 
 }
 
 JSValueRef JSMediacontentManager::unsetChangeListener(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
 {
-       LogDebug("JSContentManagerManager::unsetChangeListener entered");
-
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       Try
-       {
-               if(!privateObject){
-                       ThrowMsg(ConversionException, "private object is null");
-               }
-
-               // perform
-               IMediacontentManagerPtr contentMgr = privateObject->getObject();
-               if(!(contentMgr->unsetListener()))
-               {
-                       ThrowMsg(Exception, "Unknown exception is occured by platfrom");
-               }
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+    LogDebug("JSContentManagerManager::unsetChangeListener entered");
+    MediacontentManagerPrivObject *privateObject;
+    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    if(!privateObject) {
+        DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+
+    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try{
+        // perform
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+        if(!(contentMgr->unsetListener()))
+        {
+            throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIException::throwException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
 
 }
 
 const JSClassRef JSMediacontentManager::getClassRef() {
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
 
 const JSClassDefinition* JSMediacontentManager::getClassInfo()
 {
-       return &m_classInfo;
+    return &m_classInfo;
 }
 
 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
@@ -894,12 +745,12 @@ void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
     LogDebug("JSContentManager  initialize entered");
     MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
     if (NULL == privateObject)
-       {
+    {
         LogDebug("Create ContenttManagerPrivObject");
         IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
         privateObject = new MediacontentManagerPrivObject(context, contentManager);
         if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
-               {
+        {
             delete privateObject;
         }
     }
@@ -908,26 +759,26 @@ void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
 
 void JSMediacontentManager::finalize(JSObjectRef object)
 {
-       LogDebug("Entered");
-       MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
-       if(priv != NULL)
-       {
-               LogDebug("Deleting coordinates object");
-               delete priv;
-               JSObjectSetPrivate(object, NULL);
-               priv = NULL;
-       }
+    LogDebug("Entered");
+    MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
+    if(priv != NULL)
+    {
+        LogDebug("Deleting coordinates object");
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+        priv = NULL;
+    }
 
 }
 
 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
-                                               JSContextRef ctx,
-                                       const JSObjectRef object,
-                                       JSValueRef* exception)
+                        JSContextRef ctx,
+                        const JSObjectRef object,
+                        JSValueRef* exception)
 {
     MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
     if (priv)
-       {
+    {
         return priv->getObject();
     }
     ThrowMsg(ConversionException, "Private object is NULL.");
index a07de6e..d105fff 100755 (executable)
@@ -201,7 +201,7 @@ JSValueRef JSFolder::getPropertyPath(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
@@ -246,7 +246,7 @@ JSValueRef JSFolder::getPropertyModifiedDate(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
index db6c171..12d2511 100755 (executable)
@@ -165,7 +165,7 @@ JSValueRef JSImage::getPropertyGeoLocation(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
@@ -221,13 +221,15 @@ JSValueRef JSImage::getPropertyOrientation(
     {
         Converter converter(context);
         MediacontentImagePtr image = getImageObject(object);
-        return converter.toJSValueRef(image->getImageOrientation());
+        if(!(image->getImageOrientation().empty())){
+            return converter.toJSValueRef(image->getImageOrientation());
+        }
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 bool   JSImage::setPropertyOrientation(
index c2c104c..2a7e7cd 100755 (executable)
@@ -157,14 +157,14 @@ JSValueRef JSVideo::getPropertyGeoLocation(
     {
         Converter converter(context);
         MediacontentVideoPtr video = getVideoObject(object);
-               SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(video->getVideoLatitude(),video->getVideoLongitude()));
+        SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(video->getVideoLatitude(),video->getVideoLongitude()));
         return JSSimpleCoordinates::createJSObject(context,geoPtr);
     }
     Catch(Exception)
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 bool JSVideo::setPropertyGeoLocation(
@@ -209,7 +209,7 @@ JSValueRef JSVideo::getPropertyAlbum(
     {
                Converter converter(context);
                MediacontentVideoPtr video = getVideoObject(object);
-               if(video){
+               if(!video->getVideoAlbum().empty()){
                        return converter.toJSValueRef(video->getVideoAlbum());
                }
     }
@@ -217,7 +217,7 @@ JSValueRef JSVideo::getPropertyAlbum(
     {
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
@@ -243,16 +243,15 @@ JSValueRef JSVideo::getPropertyArtist(
                        JSValueRef val = converter.toJSValueRef(artist);
 
                        if(!JSSetArrayElement(context, jsResult, i, val)){
-                          ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Could not insert value into js array");
+                          ThrowMsg(NullPointerException, "Could not insert value into js array");
                        }
                }
-
                return jsResult;
     }
        Catch(Exception){
         LogWarning("trying to get incorrect value");
     }
-    return JSValueMakeUndefined(context);
+    return JSValueMakeNull(context);
 }
 
 
index 6154fc3..d06d456 100755 (executable)
 #include <CommonsJavaScript/ScopedJSStringRef.h>
 #include "DataType.h"
 #include <pcrecpp.h>
+#include <JSUtil.h>
 
 using namespace std;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
-
+using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace DataControl {
@@ -42,8 +43,46 @@ DataControlConverter::~DataControlConverter()
 {
 }
 
+unsigned long DataControlConverter::toULong(const JSValueRef& arg)
+{
+    return JSUtil::JSValueToULong(m_context, arg);
+}
+
+std::string DataControlConverter::toString(int arg)
+{
+       std::stringstream ss;
+       if (!(ss << arg)) {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException,
+                                "Could not convert to string.");
+       }
+       return ss.str();
+}
 
 
+std::string DataControlConverter::toString(const JSValueRef& arg)
+{
+    std::string result;
+
+    JSValueRef exception = NULL;
+    JSStringRef str = JSValueToStringCopy(m_context, arg, &exception);
+    if (exception != NULL) {
+               ThrowMsg(ConversionException, "Conversion Exception");
+    }
+    size_t jsSize = JSStringGetMaximumUTF8CStringSize(str);
+    {
+        char buffer[jsSize];
+        JSStringGetUTF8CString(str, buffer, jsSize);
+        result = buffer;
+    }
+    JSStringRelease(str);
+    return result;
+}
+
+std::string DataControlConverter::toString(const JSStringRef& arg)
+{
+       return Converter::toString(arg);
+}
+
 JSValueRef DataControlConverter::toFunctionOrNull(const JSValueRef& arg)
 {
        if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg))
index 9bfcbec..768532a 100755 (executable)
@@ -38,6 +38,10 @@ class DataControlConverter : public WrtDeviceApis::CommonsJavaScript::Converter
     JSValueRef toFunction(const JSValueRef& arg);
        RowDataPtr toRowDataPtr(const JSValueRef& arg);
        JSValueRef toJSRowData(const RowDataPtr & arg);
+       std::string toString(const JSValueRef& arg);
+       std::string toString(int arg);
+       std::string toString(const JSStringRef& arg);
+       unsigned long toULong(const JSValueRef& arg);
 };
 
 }
index 804020f..f5aa191 100755 (executable)
@@ -32,24 +32,32 @@ using namespace WrtDeviceApis::Commons;
 namespace DeviceAPI {
 namespace DataSync {
 
+int DataSyncManager::m_instanceCount = 0;
+
 DataSyncManager::DataSyncManager()
 {
-       LogInfo("Initialize the datasync manager.");
+       LogInfo("Initialize the datasync manager with count: "<<m_instanceCount);
 
-       sync_agent_ds_error_e ds_err = sync_agent_ds_init();
-       if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
-          LogError("Failed to init oma ds.");
+    if (0==m_instanceCount) {
+               sync_agent_ds_error_e ds_err = sync_agent_ds_init();
+               if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
+                  LogError("Failed to init oma ds.");
+               }
        }
+    m_instanceCount++;
 }
 
 DataSyncManager::~DataSyncManager()
 {
-       LogInfo("Deinitialize the datasync manager.");
+       LogInfo("Deinitialize the datasync manager with count: "<<m_instanceCount);
 
-       sync_agent_ds_error_e ds_err = sync_agent_ds_deinit();
-       if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
-          LogError("Failed to deinit oma ds.");
-       }
+    m_instanceCount--;
+    if (0==m_instanceCount) {
+               sync_agent_ds_error_e ds_err = sync_agent_ds_deinit();
+               if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
+                  LogError("Failed to deinit oma ds.");
+               }
+       }
 }
 
 static int datasync_state_changed_cb(sync_agent_event_data_s* request, void *user_data)
index 9fff45c..c8528e0 100755 (executable)
@@ -49,6 +49,9 @@ class DataSyncManager : public IDataSyncManager
     virtual void OnRequestReceived(const IEventStartSyncPtr &event);
     virtual void OnRequestReceived(const IEventStopSyncPtr &event);
     virtual void OnRequestReceived(const IEventGetLastSyncStatisticsPtr &event);
+
+  private:
+    static int m_instanceCount;
 };
 
 }
index 1935315..eb46d58 100755 (executable)
@@ -98,10 +98,6 @@ DownloadCallback::DownloadCallback(JSContextRef globalCtx, JSObjectRef object)
                }
        }
 
-       // check listener
-       if (!onprogress && !onpaused && !oncanceled && !oncompleted && !onfailed) {
-               throw TypeMismatchException("invalid listener.");
-       }
 }
 
 DownloadCallback::~DownloadCallback() {
index 0a1d2ad..33629bc 100644 (file)
@@ -18,7 +18,7 @@
 #include <SecurityExceptions.h>
 
 #include <JSUtil.h>
-#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 #include <ArgumentValidator.h>
 #include <GlobalContextManager.h>
 
@@ -101,7 +101,7 @@ void JSDownloadManager::finalize(JSObjectRef object)
        DownloadManager *downloadManager = static_cast<DownloadManager*>(JSObjectGetPrivate(object));
        if (downloadManager) {
                JSObjectSetPrivate(object, NULL);
-               delete downloadManager;         
+               delete downloadManager;
        }
 }
 
@@ -144,10 +144,12 @@ JSValueRef JSDownloadManager::startDownload(JSContextRef context,
 
         return JSUtil::toJSValueRef(context, downloadId);
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.start().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -180,10 +182,12 @@ JSValueRef JSDownloadManager::setListener(JSContextRef context,
 
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.setListener().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -211,10 +215,12 @@ JSValueRef JSDownloadManager::cancelDownload(JSContextRef context,
 
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.cancel().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -242,10 +248,12 @@ JSValueRef JSDownloadManager::pauseDownload(JSContextRef context,
 
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.pause().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -273,10 +281,12 @@ JSValueRef JSDownloadManager::resumeDownload(JSContextRef context,
 
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.resume().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -305,10 +315,12 @@ JSValueRef JSDownloadManager::getState(JSContextRef context,
 
         return JSUtil::toJSValueRef(context, ret);
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.resume().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -338,10 +350,12 @@ JSValueRef JSDownloadManager::getDownloadRequest(JSContextRef context,
 
         return obj;
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.resume().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -369,10 +383,12 @@ JSValueRef JSDownloadManager::getMIMEType(JSContextRef context,
 
         return JSUtil::toJSValueRef(context, ret);
     } catch (const BasePlatformException &err) {
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in tizen.download.resume().");
-        return JSWebAPIError::throwException(context, exception, err);
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
index 86658e3..23351f6 100755 (executable)
@@ -38,6 +38,7 @@ enum LocationType
     LT_SOUNDS,
     LT_TEMP,
     LT_VIDEOS,
+    LT_RINGTONES,
     LT_WGTPKG,
     LT_WGTPRV,
     LT_WGTPRVTMP
index 4313e96..4ab7b88 100755 (executable)
@@ -42,6 +42,7 @@ const char* PATH_DOCUMENTS = "/opt/usr/media/Documents";
 const char* PATH_SOUNDS = "/opt/usr/media/Sounds";
 const char* PATH_IMAGES = "/opt/usr/media/Images";
 const char* PATH_VIDEOS = "/opt/usr/media/Videos";
+const char* PATH_RINGTONE = "/opt/share/settings/Ringtones/";
 }
 
 using namespace WrtDeviceApis;
@@ -86,6 +87,7 @@ bool Manager::getSupportedDeviceCB(int storage, storage_type_e type, storage_sta
                snprintf(buf, size, "removable%d", storage);
                lable.append(buf);
        }
+       LogDebug(lable);
 
        storageItem->setId(storage);
        storageItem->setLabel(lable);
@@ -815,6 +817,7 @@ bool Manager::init()
        setupLocation("music", PATH_SOUNDS);
        setupLocation("images", PATH_IMAGES);
        setupLocation("videos", PATH_VIDEOS);
+       setupLocation("ringtones", PATH_RINGTONE);
 
        m_subrootlist[LT_ROOT] = "internal0";
        m_subrootlist[LT_SDCARD] = "removable1";
@@ -824,6 +827,7 @@ bool Manager::init()
        m_subrootlist[LT_SOUNDS] = "music";
        m_subrootlist[LT_IMAGES] = "images";
        m_subrootlist[LT_VIDEOS] = "videos";
+       m_subrootlist[LT_RINGTONES] = "ringtones";
        return true;
 
 }
index 3e04191..be505fa 100644 (file)
@@ -28,7 +28,7 @@ SET(SRCS_IMPL
        JSMessagePortManager.cpp
        JSRemoteMessagePort.cpp
        LocalMessagePortController.cpp
-       MessagePortConverter.cpp
+       MessagePortJSUtil.cpp
        MessagePortListenerManager.cpp
 )
 
@@ -40,7 +40,6 @@ TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME}
 )
 
 SET(SRCS
-       plugin_config.cpp
        plugin_initializer.cpp
 )
 
index c2b7e81..af4c3c7 100644 (file)
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
 #include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSPendingOperation.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include <SecurityExceptions.h>
-#include "plugin_config.h"
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
 #include "EventLocalMessagePortAddMessagePortListener.h"
 #include "EventLocalMessagePortRemoveMessagePortListener.h"
-#include "MessagePortConverter.h"
 #include "MessagePortListenerManager.h"
+#include "MessagePortJSUtil.h"
 
 #define TIZEN_LOCAL_MESSAGE_PORT                                "LocalMessagePort"
 
@@ -124,15 +121,15 @@ bool JSLocalMessagePort::isObjectOfClass(JSContextRef context, JSValueRef value)
 LocalMessagePortPtr JSLocalMessagePort::getLocalMessagePort(JSContextRef context, JSValueRef value)
 {
        if (!isObjectOfClass(context, value))
-               Throw(InvalidArgumentException);
+               throw TypeMismatchException("value is not a LocalMessagePort object");
 
        JSObjectRef object = JSValueToObject(context, value, NULL);
        if (!object)
-               Throw(InvalidArgumentException);
+               throw TypeMismatchException("value is not a object");
 
        LocalMessagePortController *priv = static_cast<LocalMessagePortController*>(JSObjectGetPrivate(object));
        if (!priv)
-               Throw(NullPointerException);
+               throw TypeMismatchException("cannot get priv object from LocalMessagePort object");
 
        return priv->getObject();
 }
@@ -153,14 +150,12 @@ JSValueRef JSLocalMessagePort::getMessagePortName(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       Try
+       try
        {
-               MessagePortConverterFactory::ConverterType converter =
-                               MessagePortConverterFactory::getConverter(context);
                LocalMessagePortPtr localMessagePort = getPrivData(object);
-               return converter->toJSValueRef(localMessagePort->getMessagePortName());
+               return JSUtil::toJSValueRef(context, localMessagePort->getMessagePortName());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
                LogWarning("trying to get incorrect value");
        }
@@ -173,14 +168,12 @@ JSValueRef JSLocalMessagePort::getIsTrusted(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       Try
+       try
        {
-               MessagePortConverterFactory::ConverterType converter =
-                               MessagePortConverterFactory::getConverter(context);
                LocalMessagePortPtr localMessagePort = getPrivData(object);
-               return converter->toJSValueRef(localMessagePort->getIsTrusted());
+               return JSUtil::toJSValueRef(context, localMessagePort->getIsTrusted());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
                LogWarning("trying to get incorrect value");
        }
@@ -200,47 +193,37 @@ JSValueRef JSLocalMessagePort::addMessagePortListener(JSContextRef context,
        JSContextRef gContext;
        LocalMessagePortController *controller;
 
-       Try
+       try
        {
                controller = static_cast<LocalMessagePortController*>(JSObjectGetPrivate(thisObject));
                if (!controller)
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("Wrong object");
 
                localMessagePort = controller->getObject();
                gContext = controller->getContext();
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("No private object.");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+               LogError("No private object");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
-       //AceSecurityStatus status = MESSAGE_PORT_CHECK_ACCESS(MESSAGE_PORT_FUNCTION_API_ADD_MESSAGE_PORT_LISTENER);
-       //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+       JSValueRef listener = NULL;
 
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try
-       {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'MessagePortCallback' function'");
+       ArgumentValidator validator(context, argumentCount, arguments);
 
-               if (!validator->isCallback(arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'MessagePortCallback' function'");
+       try
+       {
+               listener = validator.toFunction(0, false);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(context);
-
        JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
 
-       callbackManager->setOnSuccess(arguments[0]);
+       callbackManager->setOnSuccess(listener);
 
        EventLocalMessagePortListenerEmitterPtr emitter(new EventLocalMessagePortListenerEmitter());
 
@@ -259,8 +242,8 @@ JSValueRef JSLocalMessagePort::addMessagePortListener(JSContextRef context,
        Catch(Exception)
        {
                LogError("Error on platform : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Plugin's internal error.");
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Plugin's internal error"));
        }
 
        if (!dplEvent->getResult() || !dplEvent->getIdIsSet())
@@ -268,16 +251,16 @@ JSValueRef JSLocalMessagePort::addMessagePortListener(JSContextRef context,
                switch (dplEvent->getExceptionCode())
                {
                case ExceptionCodes::InvalidArgumentException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Plugin's internal error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Plugin's internal error."));
                        break;
                case ExceptionCodes::PlatformException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The method cannot proceed due to a severe system error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The method cannot proceed due to a severe system error."));
                        break;
                default:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Internal error"));
                        break;
                }
        }
@@ -289,15 +272,15 @@ JSValueRef JSLocalMessagePort::addMessagePortListener(JSContextRef context,
        MessagePortListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
 
        JSValueRef result;
-       Try
+       try
        {
-               result = converter->toJSValueRefLong(watchId);
+               result = JSUtil::toJSValueRef(context, watchId);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               LogError("Error on conversion : " << e.getMessage());
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Internal error"));
        }
 
        return result;
@@ -315,49 +298,32 @@ JSValueRef JSLocalMessagePort::removeMessagePortListener(JSContextRef context,
        JSContextRef gContext;
        LocalMessagePortController *controller;
 
-       Try
+       try
        {
                controller = static_cast<LocalMessagePortController*>(JSObjectGetPrivate(thisObject));
                if (!controller)
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("Wrong object");
 
                localMessagePort = controller->getObject();
                gContext = controller->getContext();
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
                LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
-       //AceSecurityStatus status = MESSAGE_PORT_CHECK_ACCESS(MESSAGE_PORT_FUNCTION_API_REMOVE_MESSAGE_PORT_LISTENER);
-       //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       if (argumentCount < 1)
-       {
-               LogError("1st argument must not be undefined.");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_FOUND_ERROR, "No watch id 'undefined'");
-       }
+       long watchId = 0;
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(context);
+       ArgumentValidator validator(context, argumentCount, arguments);
 
-       long watchId = 0;
-       Try
+       try
        {
-               watchId = static_cast<long>(converter->toLong(arguments[0]));
-
-               if (watchId < 0)
-                       ThrowMsg(PlatformException, "watchId is wrong (" << watchId << ")");
+               watchId = validator.toLong(0, false);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        EventLocalMessagePortRemoveMessagePortListenerPtr dplEvent(new EventLocalMessagePortRemoveMessagePortListener());
@@ -372,8 +338,8 @@ JSValueRef JSLocalMessagePort::removeMessagePortListener(JSContextRef context,
        Catch(Exception)
        {
                LogError("Error on platform : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Internal error"));
        }
 
        MessagePortsChangeListenerCancellerPtr canceller =
@@ -387,21 +353,21 @@ JSValueRef JSLocalMessagePort::removeMessagePortListener(JSContextRef context,
                switch (dplEvent->getExceptionCode())
                {
                case ExceptionCodes::InvalidArgumentException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Plugin's internal error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       InvalidValuesException(oss.str().c_str()));
                        break;
                case ExceptionCodes::NotFoundException:
                        oss << "No watchId (" << watchId << ") has been registered.";
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       return JSWebAPIException::throwException(context, exception,
+                                       NotFoundException(oss.str().c_str()));
                        break;
                case ExceptionCodes::PlatformException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The method cannot proceed due to a severe system error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The method cannot proceed due to a severe system error."));
                        break;
                default:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Internal error."));
                        break;
                }
        }
index af784ba..6de4b56 100644 (file)
 #include <dpl/log/log.h>
 #include <dpl/shared_ptr.h>
 #include <CommonsJavaScript/Validator.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include <SecurityExceptions.h>
-#include "plugin_config.h"
+#include <JSWebAPIException.h>
+#include <ArgumentValidator.h>
 #include "IMessagePortManager.h"
 #include "MessagePortFactory.h"
-#include "MessagePortConverter.h"
 #include "JSLocalMessagePort.h"
 #include "JSRemoteMessagePort.h"
+#include "MessagePortJSUtil.h"
 
 #define CLASS_NAME "MessagePortManager"
 
@@ -132,60 +130,38 @@ JSValueRef JSMessagePortManager::requestLocalMessagePort(JSContextRef context,
        JSContextRef gContext;
        JSMessagePortManagerPriv *priv;
 
-       Try
+       try
        {
                priv = static_cast<JSMessagePortManagerPriv*>(JSObjectGetPrivate(thisObject));
                if (!priv)
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("Wrong object");
 
                messagePortManager = priv->getObject();
                gContext = priv->getContext();
        }
-       Catch(Exception)
-       {
-               LogError("No private object.");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-       AceSecurityStatus status = MESSAGE_PORT_CHECK_ACCESS(MESSAGE_PORT_FUNCTION_API_REQUEST_LOCAL_MESSAGE_PORT);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try
-       {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'string' value.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'string' value.");
-       }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+               LogError("No private object");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        string localMessagePortName;
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(context);
-       Try
+       ArgumentValidator validator(context, argumentCount, arguments);
+
+       try
        {
-               localMessagePortName = converter->toString(arguments[0]);
+               localMessagePortName = validator.toString(0, false);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'string' value.");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        if(localMessagePortName.empty())
        {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::INVALID_VALUES_ERROR, "Local message port name is empty.");
+               return JSWebAPIException::throwException(context, exception,
+                               InvalidValuesException("Local message port name is empty"));
        }
 
        EventMessagePortManagerRequestLocalMessagePortPtr dplEvent(
@@ -201,8 +177,8 @@ JSValueRef JSMessagePortManager::requestLocalMessagePort(JSContextRef context,
        Catch(Exception)
        {
                LogError("Error on platform : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Plugin's internal error");
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Plugin's internal error"));
        }
 
        if (!dplEvent->getResult() || !dplEvent->getLocalMessagePortIsSet())
@@ -212,16 +188,16 @@ JSValueRef JSMessagePortManager::requestLocalMessagePort(JSContextRef context,
                {
                case ExceptionCodes::InvalidArgumentException:
                        oss << "Invalid local message port name ('" << localMessagePortName << "')";
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       return JSWebAPIException::throwException(context, exception,
+                                       InvalidValuesException(oss.str().c_str()));
                        break;
                case ExceptionCodes::PlatformException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The method cannot proceed due to a severe system error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The method cannot proceed due to a severe system error."));
                        break;
                default:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Internal error"));
                        break;
                }
        }
@@ -229,16 +205,15 @@ JSValueRef JSMessagePortManager::requestLocalMessagePort(JSContextRef context,
        LocalMessagePortPtr localMessagePort = dplEvent->getLocalMessagePort();
 
        JSValueRef result;
-       Try
+       try
        {
-               converter = MessagePortConverterFactory::getConverter(gContext);
-               result = converter->toJSValueRef(localMessagePort);
+               result = MessagePortJSUtil::toJSValueRef(gContext, localMessagePort);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               LogError("Error on conversion : " << e.getMessage());
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Internal error"));
        }
 
        return result;
@@ -256,60 +231,38 @@ JSValueRef JSMessagePortManager::requestTrustedLocalMessagePort(JSContextRef con
        JSContextRef gContext;
        JSMessagePortManagerPriv *priv;
 
-       Try
+       try
        {
                priv = static_cast<JSMessagePortManagerPriv*>(JSObjectGetPrivate(thisObject));
                if (!priv)
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("Wrong object");
 
                messagePortManager = priv->getObject();
                gContext = priv->getContext();
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
                LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-       AceSecurityStatus status = MESSAGE_PORT_CHECK_ACCESS(MESSAGE_PORT_FUNCTION_API_REQUEST_TRUSTED_LOCAL_MESSAGE_PORT);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try
-       {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'string' value.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'string' value.");
-       }
-       Catch(Exception )
-       {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        string localMessagePortName;
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(context);
-       Try
+       ArgumentValidator validator(context, argumentCount, arguments);
+
+       try
        {
-               localMessagePortName = converter->toString(arguments[0]);
+               localMessagePortName = validator.toString(0, false);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'string' value.");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        if(localMessagePortName.empty())
        {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::INVALID_VALUES_ERROR, "Local message port name is empty.");
+               return JSWebAPIException::throwException(context, exception,
+                               InvalidValuesException("Local message port name is empty"));
        }
 
        EventMessagePortManagerRequestTrustedLocalMessagePortPtr dplEvent(
@@ -325,8 +278,8 @@ JSValueRef JSMessagePortManager::requestTrustedLocalMessagePort(JSContextRef con
        Catch(Exception)
        {
                LogError("Error on platform : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Plugin's internal error"));
        }
 
        if (!dplEvent->getResult() || !dplEvent->getLocalMessagePortIsSet())
@@ -336,16 +289,16 @@ JSValueRef JSMessagePortManager::requestTrustedLocalMessagePort(JSContextRef con
                {
                case ExceptionCodes::InvalidArgumentException:
                        oss << "Invalid local message port name ('" << localMessagePortName << "')";
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       return JSWebAPIException::throwException(context, exception,
+                                       InvalidValuesException(oss.str().c_str()));
                        break;
                case ExceptionCodes::PlatformException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The method cannot proceed due to a severe system error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The method cannot proceed due to a severe system error."));
                        break;
                default:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Internal error"));
                        break;
                }
        }
@@ -353,16 +306,15 @@ JSValueRef JSMessagePortManager::requestTrustedLocalMessagePort(JSContextRef con
        LocalMessagePortPtr localMessagePort = dplEvent->getLocalMessagePort();
 
        JSValueRef result;
-       Try
+       try
        {
-               converter = MessagePortConverterFactory::getConverter(gContext);
-               result = converter->toJSValueRef(localMessagePort);
+               result = MessagePortJSUtil::toJSValueRef(gContext, localMessagePort);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               LogError("Error on conversion : " << e.getMessage());
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Internal error"));
        }
 
        return result;
@@ -380,74 +332,47 @@ JSValueRef JSMessagePortManager::requestRemoteMessagePort(JSContextRef context,
        JSContextRef gContext;
        JSMessagePortManagerPriv *priv;
 
-       Try
+       try
        {
                priv = static_cast<JSMessagePortManagerPriv*>(JSObjectGetPrivate(thisObject));
                if (!priv)
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("Wrong object");
 
                messagePortManager = priv->getObject();
                gContext = priv->getContext();
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
                LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-       AceSecurityStatus status = MESSAGE_PORT_CHECK_ACCESS(MESSAGE_PORT_FUNCTION_API_REQUEST_LOCAL_MESSAGE_PORT);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try
-       {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'ApplicationId' value.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'ApplicationId' value.");
-
-               if (argumentCount < 2)
-                       ThrowMsg(InvalidArgumentException, "2nd argument must be a 'string' value.");
-
-               if (!JSValueIsString(context, arguments[1]))
-                       ThrowMsg(InvalidArgumentException, "2nd argument must be a 'string' value.");
-       }
-       Catch(Exception )
-       {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        string appId;
        string remoteMessagePortName;
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(context);
-       Try
+       ArgumentValidator argValidator(context, argumentCount, arguments);
+
+       try
        {
-               appId = converter->toString(arguments[0]);
-               remoteMessagePortName = converter->toString(arguments[1]);
+               appId = argValidator.toString(0, false);
+               remoteMessagePortName = argValidator.toString(1, false);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
+
        if(appId.empty())
        {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::INVALID_VALUES_ERROR, "Application id is empty.");
+               return JSWebAPIException::throwException(context, exception,
+                               InvalidValuesException("Application id is empty"));
        }
 
        if(remoteMessagePortName.empty())
        {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::INVALID_VALUES_ERROR, "Remote message port name is empty.");
+               return JSWebAPIException::throwException(context, exception,
+                               InvalidValuesException("Remote message port name is empty"));
        }
 
        EventMessagePortManagerRequestRemoteMessagePortPtr dplEvent(
@@ -464,8 +389,8 @@ JSValueRef JSMessagePortManager::requestRemoteMessagePort(JSContextRef context,
        Catch(Exception)
        {
                LogError("Error on platform : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Plugin's internal error");
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Plugin's internal error"));
        }
 
        if (!dplEvent->getResult() || !dplEvent->getRemoteMessagePortIsSet())
@@ -475,21 +400,21 @@ JSValueRef JSMessagePortManager::requestRemoteMessagePort(JSContextRef context,
                {
                case ExceptionCodes::InvalidArgumentException:
                        oss << "Invalid values for appId '" << appId << "' or port name '" << remoteMessagePortName << "'";
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       return JSWebAPIException::throwException(context, exception,
+                                       InvalidValuesException(oss.str().c_str()));
                        break;
                case ExceptionCodes::NotFoundException:
                        oss << "No port name '" << remoteMessagePortName << "' on app '" << appId << "'";
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       return JSWebAPIException::throwException(context, exception,
+                                       NotFoundException(oss.str().c_str()));
                        break;
                case ExceptionCodes::PlatformException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The method cannot proceed due to a severe system error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The method cannot proceed due to a severe system error."));
                        break;
                default:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Internal error"));
                        break;
                }
        }
@@ -497,16 +422,15 @@ JSValueRef JSMessagePortManager::requestRemoteMessagePort(JSContextRef context,
        RemoteMessagePortPtr remoteMessagePort = dplEvent->getRemoteMessagePort();
 
        JSValueRef result;
-       Try
+       try
        {
-               converter = MessagePortConverterFactory::getConverter(gContext);
-               result = converter->toJSValueRef(remoteMessagePort);
+               result = MessagePortJSUtil::toJSValueRef(gContext, remoteMessagePort);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               LogError("Error on conversion : " << e.getMessage());
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Internal error"));
        }
 
        return result;
@@ -524,74 +448,47 @@ JSValueRef JSMessagePortManager::requestTrustedRemoteMessagePort(JSContextRef co
        JSContextRef gContext;
        JSMessagePortManagerPriv *priv;
 
-       Try
+       try
        {
                priv = static_cast<JSMessagePortManagerPriv*>(JSObjectGetPrivate(thisObject));
                if (!priv)
-                       ThrowMsg(InvalidArgumentException, "No private object.");
+                       throw TypeMismatchException("Wrong object");
 
                messagePortManager = priv->getObject();
                gContext = priv->getContext();
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
                LogError("No private object");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-       AceSecurityStatus status = MESSAGE_PORT_CHECK_ACCESS(MESSAGE_PORT_FUNCTION_API_REQUEST_LOCAL_MESSAGE_PORT);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try
-       {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'ApplicationId' value.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'ApplicationId' value.");
-
-               if (argumentCount < 2)
-                       ThrowMsg(InvalidArgumentException, "2nd argument must be a 'string' value.");
-
-               if (!JSValueIsString(context, arguments[1]))
-                       ThrowMsg(InvalidArgumentException, "2nd argument must be a 'string' value.");
-       }
-       Catch(Exception )
-       {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        string appId;
        string remoteMessagePortName;
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(context);
-       Try
+       ArgumentValidator argValidator(context, argumentCount, arguments);
+
+       try
        {
-               appId = converter->toString(arguments[0]);
-               remoteMessagePortName = converter->toString(arguments[1]);
+               appId = argValidator.toString(0, false);
+               remoteMessagePortName = argValidator.toString(1, false);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
+
        if(appId.empty())
        {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::INVALID_VALUES_ERROR, "Application id is empty.");
+               return JSWebAPIException::throwException(context, exception,
+                               InvalidValuesException("Application id is empty"));
        }
 
        if(remoteMessagePortName.empty())
        {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::INVALID_VALUES_ERROR, "Remote message port name is empty.");
+               return JSWebAPIException::throwException(context, exception,
+                               InvalidValuesException("Remote message port name is empty"));
        }
 
        EventMessagePortManagerRequestTrustedRemoteMessagePortPtr dplEvent(
@@ -608,8 +505,8 @@ JSValueRef JSMessagePortManager::requestTrustedRemoteMessagePort(JSContextRef co
        Catch(Exception)
        {
                LogError("Error on platform : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Plugin's internal error"));
        }
 
        if (!dplEvent->getResult() || !dplEvent->getRemoteMessagePortIsSet())
@@ -619,25 +516,21 @@ JSValueRef JSMessagePortManager::requestTrustedRemoteMessagePort(JSContextRef co
                {
                case ExceptionCodes::InvalidArgumentException:
                        oss << "Invalid values for appId '" << appId << "' or port name '" << remoteMessagePortName << "'";
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       return JSWebAPIException::throwException(context, exception,
+                                       InvalidValuesException(oss.str().c_str()));
                        break;
                case ExceptionCodes::NotFoundException:
                        oss << "No port name '" << remoteMessagePortName << "' on app '" << appId << "'";
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
-                       break;
-               case ExceptionCodes::PlatformWrongStateException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::INVALID_ACCESS_ERROR, "The target application is not signed with the same certificate.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       NotFoundException(oss.str().c_str()));
                        break;
                case ExceptionCodes::PlatformException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The method cannot proceed due to a severe system error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The method cannot proceed due to a severe system error."));
                        break;
                default:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Internal error"));
                        break;
                }
        }
@@ -645,16 +538,15 @@ JSValueRef JSMessagePortManager::requestTrustedRemoteMessagePort(JSContextRef co
        RemoteMessagePortPtr remoteMessagePort = dplEvent->getRemoteMessagePort();
 
        JSValueRef result;
-       Try
+       try
        {
-               converter = MessagePortConverterFactory::getConverter(gContext);
-               result = converter->toJSValueRef(remoteMessagePort);
+               result = MessagePortJSUtil::toJSValueRef(gContext, remoteMessagePort);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+               LogError("Error on conversion : " << e.getMessage());
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Internal error"));
        }
 
        return result;
index 0d8734e..eddb45a 100644 (file)
 #include <CommonsJavaScript/JSCallbackManager.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSPendingOperation.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include <SecurityExceptions.h>
-#include "plugin_config.h"
+#include <JSWebAPIException.h>
 #include "EventRemoteMessagePortSendMessage.h"
-#include "MessagePortConverter.h"
 #include "JSLocalMessagePort.h"
+#include "MessagePortJSUtil.h"
 
 #define TIZEN_REMOTE_MESSAGE_PORT                   "RemoteMessagePort"
 
@@ -123,15 +120,15 @@ bool JSRemoteMessagePort::isObjectOfClass(JSContextRef context, JSValueRef value
 RemoteMessagePortPtr JSRemoteMessagePort::getRemoteMessagePort(JSContextRef context, JSValueRef value)
 {
        if (!isObjectOfClass(context, value))
-               Throw(InvalidArgumentException);
+               throw TypeMismatchException("value is not a RemoteMessagePort object");
 
        JSObjectRef object = JSValueToObject(context, value, NULL);
        if (!object)
-               Throw(InvalidArgumentException);
+               throw TypeMismatchException("value is not a object");
 
        JSRemoteMessagePortPriv *priv = static_cast<JSRemoteMessagePortPriv*>(JSObjectGetPrivate(object));
        if (!priv)
-               Throw(NullPointerException);
+               throw TypeMismatchException("cannot get priv object from RemoteMessagePort object");
 
        return priv->getObject();
 }
@@ -144,7 +141,7 @@ RemoteMessagePortPtr JSRemoteMessagePort::getPrivData(JSObjectRef object)
        if (priv)
                return priv->getObject();
 
-       Throw(NullPointerException);
+       throw TypeMismatchException("cannot get priv object from RemoteMessagePort object");
 }
 
 JSValueRef JSRemoteMessagePort::getMessagePortName(JSContextRef context,
@@ -152,14 +149,12 @@ JSValueRef JSRemoteMessagePort::getMessagePortName(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       Try
+       try
        {
-               MessagePortConverterFactory::ConverterType converter =
-                               MessagePortConverterFactory::getConverter(context);
                RemoteMessagePortPtr localMessagePort = getPrivData(object);
-               return converter->toJSValueRef(localMessagePort->getMessagePortName());
+               return JSUtil::toJSValueRef(context, localMessagePort->getMessagePortName());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
                LogWarning("trying to get incorrect value");
        }
@@ -172,14 +167,12 @@ JSValueRef JSRemoteMessagePort::getAppId(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       Try
+       try
        {
-               MessagePortConverterFactory::ConverterType converter =
-                               MessagePortConverterFactory::getConverter(context);
                RemoteMessagePortPtr localMessagePort = getPrivData(object);
-               return converter->toJSValueRef(localMessagePort->getAppId());
+               return JSUtil::toJSValueRef(context, localMessagePort->getAppId());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
                LogWarning("trying to get incorrect value");
        }
@@ -192,14 +185,12 @@ JSValueRef JSRemoteMessagePort::getIsTrusted(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       Try
+       try
        {
-               MessagePortConverterFactory::ConverterType converter =
-                               MessagePortConverterFactory::getConverter(context);
                RemoteMessagePortPtr localMessagePort = getPrivData(object);
-               return converter->toJSValueRef(localMessagePort->getIsTrusted());
+               return JSUtil::toJSValueRef(context, localMessagePort->getIsTrusted());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
                LogWarning("trying to get incorrect value");
        }
@@ -217,81 +208,53 @@ JSValueRef JSRemoteMessagePort::sendMessage(JSContextRef context,
        LogDebug("entered");
        RemoteMessagePortPtr remoteMessagePort(NULL);
 
-       bool js2ndParamIsObject = false;
-       Try
-       {
-               remoteMessagePort = getPrivData(thisObject);
-               if (remoteMessagePort == NULL)
-                       ThrowMsg(InvalidArgumentException, "No private object.");
-       }
-       Catch(Exception)
+       try
        {
-               LogError("No private object.");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
+               JSRemoteMessagePortPriv *priv =
+                       static_cast<JSRemoteMessagePortPriv*>(JSObjectGetPrivate(thisObject));
 
-       //AceSecurityStatus status = MESSAGE_PORT_CHECK_ACCESS(MESSAGE_PORT_FUNCTION_API_SEND_MESSAGE);
-       //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               if (!priv)
+                       throw TypeMismatchException("Wrong object");
 
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try
-       {
-               if (argumentCount < 1)
-                       ThrowMsg(ConversionException, "1st argument must be array of 'MessagePortDataItem'");
-
-               if (!JSValueIsObject(context, arguments[0]) || !JSIsArrayValue(context, arguments[0]))
-                       ThrowMsg(ConversionException, "1st argument must be array of 'MessagePortDataItem'");
-
-               if (argumentCount >= 2)
-               {
-                       if (validator->isNullOrUndefined(arguments[1]))
-                               js2ndParamIsObject = false;
-                       else if(!JSLocalMessagePort::isObjectOfClass(context, arguments[1]))
-                               ThrowMsg(ConversionException, "2nd argument must be 'LocalMessagePort' or null");
-                       else
-                               js2ndParamIsObject = true;
-               }
+               remoteMessagePort = priv->getObject();
        }
-       Catch (Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+               LogError("No private object");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        MessagePortDataItemMapPtr data(NULL);
        LocalMessagePortPtr localMessagePort(NULL);
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(context);
-       Try
+       try
        {
-               data = converter->toMessagePortDataItemMap(arguments[0]);
+               if(argumentCount < 1)
+                       throw TypeMismatchException("1st argument must be array of MessagePortDataItem");
+
+               data = MessagePortJSUtil::JSValueToMessagePortDataItemMap(context, arguments[0]);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be array of 'MessagePortDataItem'");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
-       Try
+       try
        {
-               if(js2ndParamIsObject)
-                       localMessagePort = converter->toLocalMessagePort(arguments[1]);
+               if(argumentCount >= 2 &&
+                               !JSValueIsUndefined(context, arguments[1]) &&
+                               !JSValueIsNull(context, arguments[1]))
+                       localMessagePort = MessagePortJSUtil::JSValueToLocalMessagePort(context, arguments[1]);
        }
-       Catch(Exception)
+       catch(BasePlatformException &e)
        {
-               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'LocalMessagePort' or null");
+               return JSWebAPIException::throwException(context, exception, e);
        }
 
        EventRemoteMessagePortSendMessagePtr dplEvent(new EventRemoteMessagePortSendMessage());
 
        dplEvent->setData(data);
-       if(js2ndParamIsObject)
+       if(localMessagePort != NULL)
                dplEvent->setLocalMessagePort(localMessagePort);
        dplEvent->setForSynchronousCall();
 
@@ -302,8 +265,8 @@ JSValueRef JSRemoteMessagePort::sendMessage(JSContextRef context,
        Catch(Exception)
        {
                LogError("Error on platform : " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, "Plugin's internal error.");
+               return JSWebAPIException::throwException(context, exception,
+                               UnknownException("Plugin's internal error."));
        }
 
        if (!dplEvent->getResult())
@@ -311,24 +274,24 @@ JSValueRef JSRemoteMessagePort::sendMessage(JSContextRef context,
                switch (dplEvent->getExceptionCode())
                {
                case ExceptionCodes::ConversionException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::TYPE_MISMATCH_ERROR, "Wrong LocalMessagePort object.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       TypeMismatchException("Wrong LocalMessagePort object."));
                        break;
                case ExceptionCodes::InvalidArgumentException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::INVALID_VALUES_ERROR, "The data argument is wrong.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       InvalidValuesException("The data argument is wrong."));
                        break;
                case ExceptionCodes::NotFoundException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The target application's port is not found.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The target application's port is not found."));
                        break;
                case ExceptionCodes::PlatformException:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "The method cannot proceed due to a severe system error.");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("The method cannot proceed due to a severe system error."));
                        break;
                default:
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return JSWebAPIException::throwException(context, exception,
+                                       UnknownException("Internal error"));
                        break;
                }
        }
index 6050be7..40741b8 100644 (file)
 
 #include <dpl/log/log.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
 #include "MessagePortDataItem.h"
-#include "MessagePortConverter.h"
+#include "MessagePortJSUtil.h"
 
 namespace DeviceAPI {
 namespace MessagePort {
@@ -67,20 +65,34 @@ void LocalMessagePortAsyncAnswerHandler::localMessagePortListener(const EventLoc
 
        JSContextRef gContext = cbm->getContext();
 
-       MessagePortConverterFactory::ConverterType converter =
-                       MessagePortConverterFactory::getConverter(gContext);
-
        if(!event->getDataIsSet())
        {
                LogError("No data items");
                return;
        }
-       result[0] = converter->toJSValueRef(event->getData());
 
-       if(event->getRemoteMessagePortIsSet())
-               result[1] = converter->toJSValueRef(event->getRemoteMessagePort());
-       else
-               result[1] = JSValueMakeNull(gContext);
+       try
+       {
+               result[0] = MessagePortJSUtil::toJSValueRef(gContext, event->getData());
+       }
+       catch(BasePlatformException &e)
+       {
+               LogError("Fail to convert MessagePortDataItemMap");
+               return;
+       }
+
+       try
+       {
+               if(event->getRemoteMessagePortIsSet())
+                       result[1] = MessagePortJSUtil::toJSValueRef(gContext, event->getRemoteMessagePort());
+               else
+                       result[1] = JSValueMakeNull(gContext);
+       }
+       catch(BasePlatformException &e)
+       {
+               LogError("Fail to convert RemoteMessagePort");
+               return;
+       }
 
        cbm->callOnSuccess(result, 2);
 }
diff --git a/src/MessagePort/MessagePortConverter.cpp b/src/MessagePort/MessagePortConverter.cpp
deleted file mode 100644 (file)
index f3a7ec6..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file        MessagePortConverter.cpp
- * @author      Kisub Song (kisubs.song@samsung.com)
- * @version     0.1
- * @brief
- */
-
-#include "MessagePortConverter.h"
-
-#include <string>
-#include <algorithm>
-#include <dpl/log/log.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <Commons/RegexUtils.h>
-#include "JSLocalMessagePort.h"
-#include "JSRemoteMessagePort.h"
-
-#define MESSAGE_PORT_ATTRIBUTE_KEY "key"
-#define MESSAGE_PORT_ATTRIBUTE_VALUE "value"
-
-namespace DeviceAPI {
-namespace MessagePort {
-
-using namespace std;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-MessagePortConverter::MessagePortConverter(JSContextRef context) : Converter(context)
-{
-}
-
-MessagePortConverter::~MessagePortConverter()
-{
-}
-
-JSValueRef MessagePortConverter::toJSValueRef(const MessagePortDataItemMapPtr &arg)
-{
-       JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL);
-       if (!resultObject)
-               ThrowMsg(ConversionException, "Can not create array object.");
-
-       int i = 0;
-       MessagePortDataItemMap::iterator iter;
-       for(iter = arg->begin(); iter != arg->end(); iter++, i++)
-       {
-               const ScopedJSStringRef keyStr(JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_KEY));
-               const ScopedJSStringRef valueStr(JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_VALUE));
-
-               JSValueRef key = toJSValueRef(iter->first);
-               JSValueRef value = toJSValueRef(iter->second);
-
-               JSObjectRef jsobject = JSObjectMake(m_context, NULL, NULL);
-               JSObjectSetProperty(m_context, jsobject, keyStr.get(), key, kJSPropertyAttributeNone, NULL);
-               JSObjectSetProperty(m_context, jsobject, valueStr.get(), value, kJSPropertyAttributeNone, NULL);
-
-               JSValueRef jsvalue = jsobject;
-
-               if (!JSSetArrayElement(m_context, resultObject, i, jsvalue))
-                       ThrowMsg(ConversionException, "Can not fill contact array.");
-       }
-
-       return static_cast<JSValueRef>(resultObject);
-}
-
-MessagePortDataItemMapPtr MessagePortConverter::toMessagePortDataItemMap(const JSValueRef &jsValue)
-{
-       if(!JSIsArrayValue(m_context, jsValue))
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "MessagePortArray is not array.");
-
-       Validator validator(m_context);
-
-       MessagePortDataItemMapPtr result = MessagePortDataItemMapPtr(new MessagePortDataItemMap());
-
-       JSObjectRef jsObject = toJSObjectRef(jsValue);
-       unsigned int length = JSGetArrayLength(m_context, jsObject);
-       for (std::size_t i = 0; i < length; i++)
-       {
-               JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
-
-               if(!JSValueIsObject(m_context, element))
-               {
-                       LogWarning("element is not object (" << i << ")");
-                       continue;
-               }
-
-               const ScopedJSStringRef keyStr(JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_KEY));
-               const ScopedJSStringRef valueStr(JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_VALUE));
-
-               JSObjectRef jsObject = toJSObjectRef(element);
-
-               std::string key;
-               std::string value;
-
-               JSValueRef keyData = JSObjectGetProperty(m_context, jsObject, keyStr.get(), NULL);
-               if (!validator.isNullOrUndefined(keyData))
-               {
-                       if(!JSValueIsString(m_context, keyData))
-                       {
-                               LogWarning("key is not string");
-                               continue;
-                       }
-
-                       key = toString(keyData);
-               }
-
-               JSValueRef valueData = JSObjectGetProperty(m_context, jsObject, valueStr.get(), NULL);
-               if (!validator.isNullOrUndefined(valueData))
-               {
-                       if(!JSValueIsString(m_context, valueData))
-                               value = "";
-                       else
-                               value = toString(valueData);
-               }
-
-               MessagePortDataItemPair pair(key, value);
-               result->insert(pair);
-       }
-
-       return result;
-}
-
-JSValueRef MessagePortConverter::toJSValueRef(const LocalMessagePortPtr &arg)
-{
-       LocalMessagePortController *priv = new LocalMessagePortController(m_context, arg);
-       return JSObjectMake(m_context, JSLocalMessagePort::getClassRef(), priv);
-}
-
-LocalMessagePortPtr MessagePortConverter::toLocalMessagePort(const JSValueRef &jsValue)
-{
-       if(!JSLocalMessagePort::isObjectOfClass(m_context, jsValue))
-       {
-               LogError("Not a LocalMessagePort object");
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
-       }
-
-       return JSLocalMessagePort::getLocalMessagePort(m_context, jsValue);
-}
-
-JSValueRef MessagePortConverter::toJSValueRef(const RemoteMessagePortPtr &arg)
-{
-       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSRemoteMessagePort::getClassRef(), arg);
-}
-
-RemoteMessagePortPtr MessagePortConverter::toRemoteMessagePort(const JSValueRef &jsValue)
-{
-       if(!JSRemoteMessagePort::isObjectOfClass(m_context, jsValue))
-       {
-               LogError("Not a RemoteMessagePort object");
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
-       }
-
-       return JSRemoteMessagePort::getRemoteMessagePort(m_context, jsValue);
-}
-
-} // MessagePort
-} // DeviceAPI
diff --git a/src/MessagePort/MessagePortConverter.h b/src/MessagePort/MessagePortConverter.h
deleted file mode 100644 (file)
index 0b63a06..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file        MessagePortConverter.cpp
- * @author      Kisub Song (kisubs.song@samsung.com)
- * @version     0.1
- * @brief
- */
-
-#ifndef _TIZEN_MESSAGE_PORT_CONVERTER_H_
-#define _TIZEN_MESSAGE_PORT_CONVERTER_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/Converter.h>
-#include "MessagePortDataItem.h"
-#include "ILocalMessagePort.h"
-#include "IRemoteMessagePort.h"
-
-namespace DeviceAPI {
-namespace MessagePort {
-
-class MessagePortConverter : public WrtDeviceApis::CommonsJavaScript::Converter
-{
-public:
-       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
-
-       explicit MessagePortConverter(JSContextRef context);
-       virtual ~MessagePortConverter();
-
-       JSValueRef toJSValueRef(const MessagePortDataItemMapPtr &arg);
-       MessagePortDataItemMapPtr toMessagePortDataItemMap(const JSValueRef &jsValue);
-
-       JSValueRef toJSValueRef(const LocalMessagePortPtr &arg);
-       LocalMessagePortPtr toLocalMessagePort(const JSValueRef &jsValue);
-
-       JSValueRef toJSValueRef(const RemoteMessagePortPtr &arg);
-       RemoteMessagePortPtr toRemoteMessagePort(const JSValueRef &jsValue);
-};
-
-typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<MessagePortConverter> MessagePortConverterFactory;
-
-} // MessagePort
-} // DeviceAPI
-
-#endif // _TIZEN_MESSAGE_PORT_CONVERTER_H_
index 8d92e6e..260174f 100644 (file)
@@ -36,7 +36,7 @@ namespace MessagePort {
 typedef std::string MessagePortDataItemKey;
 typedef std::string MessagePortDataItemValue;
 
-typedef std::map<MessagePortDataItemKey, MessagePortDataItemKey> MessagePortDataItemMap;
+typedef std::map<MessagePortDataItemKey, MessagePortDataItemValue> MessagePortDataItemMap;
 typedef DPL::SharedPtr<MessagePortDataItemMap> MessagePortDataItemMapPtr;
 
 typedef std::pair<MessagePortDataItemKey, MessagePortDataItemKey> MessagePortDataItemPair;
diff --git a/src/MessagePort/MessagePortJSUtil.cpp b/src/MessagePort/MessagePortJSUtil.cpp
new file mode 100644 (file)
index 0000000..7f1aee8
--- /dev/null
@@ -0,0 +1,166 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 "MessagePortJSUtil.h"
+
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+
+#include "JSLocalMessagePort.h"
+#include "JSRemoteMessagePort.h"
+
+#define MESSAGE_PORT_ATTRIBUTE_KEY "key"
+#define MESSAGE_PORT_ATTRIBUTE_VALUE "value"
+
+namespace DeviceAPI {
+namespace MessagePort {
+
+using namespace std;
+using namespace DeviceAPI::Common;
+
+JSValueRef MessagePortJSUtil::toJSValueRef(JSContextRef context, const MessagePortDataItemMapPtr &arg)
+{
+       JSObjectRef resultObject = JSCreateArrayObject(context, 0, NULL);
+       if (!resultObject)
+               throw TypeMismatchException("Can not create array object");
+
+       int i = 0;
+       MessagePortDataItemMap::iterator iter;
+       for(iter = arg->begin(); iter != arg->end(); iter++, i++)
+       {
+               const WrtDeviceApis::CommonsJavaScript::ScopedJSStringRef keyStr(
+                               JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_KEY));
+               const WrtDeviceApis::CommonsJavaScript::ScopedJSStringRef valueStr(
+                               JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_VALUE));
+
+               JSValueRef key = JSUtil::toJSValueRef(context, iter->first);
+               JSValueRef value = JSUtil::toJSValueRef(context, iter->second);
+
+               JSObjectRef jsobject = JSObjectMake(context, NULL, NULL);
+               JSObjectSetProperty(context, jsobject, keyStr.get(), key, kJSPropertyAttributeNone, NULL);
+               JSObjectSetProperty(context, jsobject, valueStr.get(), value, kJSPropertyAttributeNone, NULL);
+
+               JSValueRef jsvalue = jsobject;
+
+               if (!JSSetArrayElement(context, resultObject, i, jsvalue))
+                       throw TypeMismatchException("Can not fill contact array");
+       }
+
+       return static_cast<JSValueRef>(resultObject);
+}
+
+JSValueRef MessagePortJSUtil::toJSValueRef(JSContextRef context, const LocalMessagePortPtr &arg)
+{
+       LocalMessagePortController *priv = new LocalMessagePortController(context, arg);
+       JSObjectRef object = JSObjectMake(context, JSLocalMessagePort::getClassRef(), priv);
+       if (!object)
+               throw TypeMismatchException("Could not create JS object.");
+
+       return object;
+}
+
+JSValueRef MessagePortJSUtil::toJSValueRef(JSContextRef context, const RemoteMessagePortPtr &arg)
+{
+       JSRemoteMessagePortPriv* priv = new JSRemoteMessagePortPriv(context, arg);
+       JSObjectRef object = JSObjectMake(context, JSRemoteMessagePort::getClassRef(), priv);
+       if (!object)
+               throw TypeMismatchException("Could not create JS object.");
+
+       return object;
+}
+
+MessagePortDataItemMapPtr MessagePortJSUtil::JSValueToMessagePortDataItemMap(JSContextRef context, JSValueRef jsValue)
+{
+       if(!JSIsArrayValue(context, jsValue))
+               throw TypeMismatchException("MessagePortArray is not array.");
+
+       MessagePortDataItemMapPtr result = MessagePortDataItemMapPtr(new MessagePortDataItemMap());
+
+       const WrtDeviceApis::CommonsJavaScript::ScopedJSStringRef keyStr(
+                       JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_KEY));
+       const WrtDeviceApis::CommonsJavaScript::ScopedJSStringRef valueStr(
+                       JSStringCreateWithUTF8CString(MESSAGE_PORT_ATTRIBUTE_VALUE));
+
+       JSObjectRef jsObject = JSValueToObject(context, jsValue);
+       unsigned int length = JSGetArrayLength(context, jsObject);
+       for (std::size_t i = 0; i < length; i++)
+       {
+               JSValueRef element = JSGetArrayElement(context, jsObject, i);
+
+               if(!JSValueIsObject(context, element))
+               {
+                       LogWarning("element is not object (" << i << ")");
+                       continue;
+               }
+
+               JSObjectRef jsObject = JSValueToObject(context, element);
+
+               std::string key;
+               std::string value;
+
+               JSValueRef keyData = JSObjectGetProperty(context, jsObject, keyStr.get(), NULL);
+               try
+               {
+                       key = JSUtil::JSValueToString(context, keyData);
+               }
+               catch(BasePlatformException &e)
+               {
+                       LogWarning("key is not string");
+                       continue;
+               }
+
+               JSValueRef valueData = JSObjectGetProperty(context, jsObject, valueStr.get(), NULL);
+               try
+               {
+                       value = JSUtil::JSValueToString(context, valueData);
+               }
+               catch(BasePlatformException &e)
+               {
+                       LogWarning("value is not string");
+                       continue;
+               }
+
+               MessagePortDataItemPair pair(key, value);
+               result->insert(pair);
+       }
+
+       return result;
+}
+
+LocalMessagePortPtr MessagePortJSUtil::JSValueToLocalMessagePort(JSContextRef context, JSValueRef jsValue)
+{
+       if(!JSLocalMessagePort::isObjectOfClass(context, jsValue))
+       {
+               LogError("Not a LocalMessagePort object");
+               throw TypeMismatchException("value is not a LocalMessagePort object");
+       }
+
+       return JSLocalMessagePort::getLocalMessagePort(context, jsValue);
+}
+
+RemoteMessagePortPtr MessagePortJSUtil::JSValueToRemoteMessagePort(JSContextRef context, JSValueRef jsValue)
+{
+       if(!JSRemoteMessagePort::isObjectOfClass(context, jsValue))
+       {
+               LogError("Not a RemoteMessagePort object");
+               throw TypeMismatchException("value is not a RemoteMessagePort object");
+       }
+
+       return JSRemoteMessagePort::getRemoteMessagePort(context, jsValue);
+}
+
+} // MessagePort
+} // DeviceAPI
diff --git a/src/MessagePort/MessagePortJSUtil.h b/src/MessagePort/MessagePortJSUtil.h
new file mode 100644 (file)
index 0000000..4094e70
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 _MESSAGE_PORT_JSUTIL_H_
+#define _MESSAGE_PORT_JSUTIL_H_
+
+#include <JSUtil.h>
+#include "MessagePortDataItem.h"
+#include "ILocalMessagePort.h"
+#include "IRemoteMessagePort.h"
+
+namespace DeviceAPI {
+namespace MessagePort {
+
+class MessagePortJSUtil : public DeviceAPI::Common::JSUtil
+{
+public:
+       static JSValueRef toJSValueRef(JSContextRef context, const MessagePortDataItemMapPtr &arg);
+       static JSValueRef toJSValueRef(JSContextRef context, const LocalMessagePortPtr &arg);
+       static JSValueRef toJSValueRef(JSContextRef context, const RemoteMessagePortPtr &arg);
+
+       static MessagePortDataItemMapPtr JSValueToMessagePortDataItemMap(JSContextRef context, JSValueRef value);
+       static LocalMessagePortPtr JSValueToLocalMessagePort(JSContextRef context, JSValueRef value);
+       static RemoteMessagePortPtr JSValueToRemoteMessagePort(JSContextRef context, JSValueRef value);
+};
+
+} // MessagePort
+} // DeviceAPI
+
+#endif //_MESSAGE_PORT_JSUTIL_H_
diff --git a/src/MessagePort/plugin_config.cpp b/src/MessagePort/plugin_config.cpp
deleted file mode 100644 (file)
index 40acb17..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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/FunctionDefinition.h>
-#include <Commons/FunctionDeclaration.h>
-#include <iostream>
-#include <Commons/Exception.h>
-#include <dpl/exception.h>
-#include <map>
-
-#include "plugin_config.h"
-
-#define MESSAGE_PORT_FEATURE_API_OPENED  "http://tizen.org/privilege/messageport"
-
-#define MESSAGE_PORT_DEVICE_CAP_OPENED "messageport"
-
-using namespace WrtDeviceApis::Commons;
-
-namespace DeviceAPI {
-namespace MessagePort {
-
-static FunctionMapping createMessagePortFunctions();
-
-static FunctionMapping MessagePortFunctions =
-    createMessagePortFunctions();
-
-DEFINE_FUNCTION_GETTER(MessagePort, MessagePortFunctions);
-
-static FunctionMapping createMessagePortFunctions()
-{
-    /**
-     * Device capabilities
-     */
-    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_MESSAGE_PORT_OPENED, MESSAGE_PORT_DEVICE_CAP_OPENED);
-
-    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
-
-    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_MESSAGE_PORT_OPENED);
-    ACE_ADD_DEVICE_CAP(DEVICE_LIST_MESSAGE_PORT_OPENED, DEVICE_CAP_MESSAGE_PORT_OPENED);
-
-    /**
-     * Api Features
-     */
-    ACE_CREATE_FEATURE(FEATURE_MESSAGE_PORT_OPENED, MESSAGE_PORT_FEATURE_API_OPENED);
-
-    ACE_CREATE_FEATURE_LIST(MESSAGE_PORT_FEATURES_MESSAGE_PORT);
-    ACE_ADD_API_FEATURE(MESSAGE_PORT_FEATURES_MESSAGE_PORT, FEATURE_MESSAGE_PORT_OPENED);
-
-    /**
-     * Functions
-     */
-
-    FunctionMapping messagePortMapping;
-
-    //MessagePortManager.requestLocalMessagePort
-    AceFunction messagePortManagerRequestLocalMessagePortFunc = ACE_CREATE_FUNCTION(
-            FUNCTION_MESSAGE_PORT_MANAGER_REQUEST_LOCAL_MESSAGE_PORT,
-            MESSAGE_PORT_FUNCTION_API_REQUEST_LOCAL_MESSAGE_PORT,
-            MESSAGE_PORT_FEATURES_MESSAGE_PORT,
-            DEVICE_LIST_MESSAGE_PORT_OPENED);
-
-    messagePortMapping.insert(std::make_pair(
-                                  MESSAGE_PORT_FUNCTION_API_REQUEST_LOCAL_MESSAGE_PORT,
-                                  messagePortManagerRequestLocalMessagePortFunc));
-
-    //MessagePortManager.requestTrustedLocalMessagePort
-    AceFunction messagePortManagerRequestTrustedLocalMessagePortFunc = ACE_CREATE_FUNCTION(
-            FUNCTION_MESSAGE_PORT_MANAGER_REQUEST_TRUSTED_LOCAL_MESSAGE_PORT,
-            MESSAGE_PORT_FUNCTION_API_REQUEST_TRUSTED_LOCAL_MESSAGE_PORT,
-            MESSAGE_PORT_FEATURES_MESSAGE_PORT,
-            DEVICE_LIST_MESSAGE_PORT_OPENED);
-
-    messagePortMapping.insert(std::make_pair(
-                                  MESSAGE_PORT_FUNCTION_API_REQUEST_TRUSTED_LOCAL_MESSAGE_PORT,
-                                  messagePortManagerRequestTrustedLocalMessagePortFunc));
-
-    //MessagePortManager.requestRemoteMessagePort
-    AceFunction messagePortManagerRequestRemoteMessagePortFunc = ACE_CREATE_FUNCTION(
-            FUNCTION_MESSAGE_PORT_MANAGER_REQUEST_REMOTE_MESSAGE_PORT,
-            MESSAGE_PORT_FUNCTION_API_REQUEST_REMOTE_MESSAGE_PORT,
-            MESSAGE_PORT_FEATURES_MESSAGE_PORT,
-            DEVICE_LIST_MESSAGE_PORT_OPENED);
-
-    messagePortMapping.insert(std::make_pair(
-                                  MESSAGE_PORT_FUNCTION_API_REQUEST_REMOTE_MESSAGE_PORT,
-                                  messagePortManagerRequestRemoteMessagePortFunc));
-
-    //MessagePortManager.requestTrustedRemoteMessagePort
-    AceFunction messagePortManagerRequestTrustedRemoteMessagePortFunc = ACE_CREATE_FUNCTION(
-            FUNCTION_MESSAGE_PORT_MANAGER_REQUEST_TRUSTED_REMOTE_MESSAGE_PORT,
-            MESSAGE_PORT_FUNCTION_API_REQUEST_TRUSTED_REMOTE_MESSAGE_PORT,
-            MESSAGE_PORT_FEATURES_MESSAGE_PORT,
-            DEVICE_LIST_MESSAGE_PORT_OPENED);
-
-    messagePortMapping.insert(std::make_pair(
-                                  MESSAGE_PORT_FUNCTION_API_REQUEST_TRUSTED_REMOTE_MESSAGE_PORT,
-                                  messagePortManagerRequestTrustedRemoteMessagePortFunc));
-
-    return messagePortMapping;
-}
-
-} // MessagePort
-} // DeviceAPI
diff --git a/src/MessagePort/plugin_config.h b/src/MessagePort/plugin_config.h
deleted file mode 100644 (file)
index febaa53..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 _MESSAGE_PORT_PLUGIN_CONFIG_H_
-#define _MESSAGE_PORT_PLUGIN_CONFIG_H_
-
-#include <string>
-#include <Commons/FunctionDeclaration.h>
-
-namespace DeviceAPI {
-namespace MessagePort {
-
-#define MESSAGE_PORT_FUNCTION_API_REQUEST_LOCAL_MESSAGE_PORT            "requestLocalMessagePort"
-#define MESSAGE_PORT_FUNCTION_API_REQUEST_TRUSTED_LOCAL_MESSAGE_PORT    "requestTrustedLocalMessagePort"
-#define MESSAGE_PORT_FUNCTION_API_REQUEST_REMOTE_MESSAGE_PORT           "requestRemoteMessagePort"
-#define MESSAGE_PORT_FUNCTION_API_REQUEST_TRUSTED_REMOTE_MESSAGE_PORT   "requestTrustedRemoteMessagePort"
-
-DECLARE_FUNCTION_GETTER(MessagePort);
-
-#define MESSAGE_PORT_CHECK_ACCESS(functionName)                     \
-    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
-        getMessagePortFunctionData,           \
-        functionName)
-
-} // MessagePort
-} // DeviceAPI
-
-#endif // _MESSAGE_PORT_PLUGIN_CONFIG_H_
index 02e0e0f..5bf5509 100644 (file)
@@ -31,6 +31,8 @@
 #include "JSConversation.h"
 #include "JSMessageFolder.h"
 
+#include <JSWebAPIError.h>
+
 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
 #include <JSFile.h>
 #endif
@@ -50,9 +52,9 @@ namespace Messaging {
 
 MessageFunctions ConverterMessage::m_callbackNames[MESSAGING_MULTI_FUNTION_MAX]
 {
-       {"messagesadded", "messagesupdated", "messagesremoved"},
-       {"conversationsadded", "conversationsupdated", "conversationsremoved"},
-       {"foldersadded", "foldersupdated", "foldersremoved"}
+    {"messagesadded", "messagesupdated", "messagesremoved"},
+    {"conversationsadded", "conversationsupdated", "conversationsremoved"},
+    {"foldersadded", "foldersupdated", "foldersremoved"}
 };
 
 ConverterMessage::ConverterMessage(JSContextRef context) :
@@ -154,9 +156,9 @@ JSValueRef ConverterMessage::toJSValueRef(const std::vector<IConversationPtr>& c
 {
     vector<JSValueRef> conversationJS;
 
-       for (size_t i = 0; i < conversations.size(); i++)
-       {
-               JSValueRef value = JSConversation::createJSObject(m_context, conversations[i]);
+    for (size_t i = 0; i < conversations.size(); i++)
+    {
+        JSValueRef value = JSConversation::createJSObject(m_context, conversations[i]);
         conversationJS.push_back(value);
     }
 
@@ -167,9 +169,9 @@ JSValueRef ConverterMessage::toJSValueRef(const std::vector<IMessageFolderPtr>&
 {
     vector<JSValueRef> messagefolderJS;
 
-       for (size_t i = 0; i < messagefolders.size(); i++)
-       {
-               JSValueRef value = JSMessageFolder::createJSObject(m_context, messagefolders[i]);
+    for (size_t i = 0; i < messagefolders.size(); i++)
+    {
+        JSValueRef value = JSMessageFolder::createJSObject(m_context, messagefolders[i]);
         messagefolderJS.push_back(value);
     }
 
@@ -256,66 +258,66 @@ IMessagePtr ConverterMessage::toIMessage(JSObjectRef arg)
 
 IAttachmentPtr ConverterMessage::toIAttachment(JSValueRef arg)
 {
-       return toIAttachment(toJSObjectRef(arg));
+    return toIAttachment(toJSObjectRef(arg));
 }
 
 IAttachmentPtr ConverterMessage::toIAttachment(JSObjectRef arg)
 {
-       if (!arg)
-       {
-               LogError("Object is Null");
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object not initialized");
-       }
+    if (!arg)
+    {
+        LogError("Object is Null");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object not initialized");
+    }
 
-       IAttachmentPtr retVal;
-       JSMessageAttachmentPrivate* priv =
+    IAttachmentPtr retVal;
+    JSMessageAttachmentPrivate* priv =
         static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(arg));
 
-       if (!priv) {
+    if (!priv) {
         LogError("Private object not initialized");
         ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
                  "Private object not initialized");
-       }
+        }
 
-       retVal = priv->getObject();
-       if (!retVal) {
+    retVal = priv->getObject();
+        if (!retVal) {
         LogError("Message private object not initialized");
         ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
                  "Private object not initialized");
-       }
-       return retVal;
+        }
+        return retVal;
 }
 
 IMessageFolderPtr ConverterMessage::toIMessageFolder(JSValueRef arg)
 {
-       return toIMessageFolder(toJSObjectRef(arg));
+    return toIMessageFolder(toJSObjectRef(arg));
 }
 
 IMessageFolderPtr ConverterMessage::toIMessageFolder(JSObjectRef arg)
 {
-       if (!arg)
-       {
-               LogError("Object is Null");
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object not initialized");
-       }
+    if (!arg)
+    {
+        LogError("Object is Null");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object not initialized");
+    }
 
-       IMessageFolderPtr retVal;
-       JSMessageFolderPriv* priv =
+    IMessageFolderPtr retVal;
+    JSMessageFolderPriv* priv =
         static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(arg));
 
-       if (!priv) {
+    if (!priv) {
         LogError("Private object not initialized");
         ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
                  "Private object not initialized");
-       }
+        }
 
-       retVal = priv->getObject();
-       if (!retVal) {
+    retVal = priv->getObject();
+        if (!retVal) {
         LogError("Message private object not initialized");
         ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
                  "Private object not initialized");
-       }
-       return retVal;
+        }
+        return retVal;
 }
 
 Recipients ConverterMessage::toRecipients(JSValueRef arg)
@@ -338,48 +340,48 @@ Recipients ConverterMessage::toRecipients(JSValueRef arg)
 
 OnMessagesChanged ConverterMessage::toMessageMultifunctions(JSValueRef argument)
 {
-       OnMessagesChanged result;
-       Validator validator(m_context);
-       JSObjectRef objectCallbacks = toJSObjectRef(argument);
-       std::string callbackName = toString(argument);
-       int index = 0;
+    OnMessagesChanged result;
+    Validator validator(m_context);
+    JSObjectRef objectCallbacks = toJSObjectRef(argument);
+    std::string callbackName = toString(argument);
+    int index = 0;
 
-       LogDebug("Enter\n");
+    LogDebug("Enter\n");
 
-       for (index = 0; index < MESSAGING_MULTI_FUNTION_MAX; index++)
-       {
-               ScopedJSStringRef propName(toJSStringRef(m_callbackNames[index].addedFunction));
+    for (index = 0; index < MESSAGING_MULTI_FUNTION_MAX; index++)
+    {
+        ScopedJSStringRef propName(toJSStringRef(m_callbackNames[index].addedFunction));
 
-               if (JSObjectHasProperty(m_context, objectCallbacks, propName.get()))
-               {
-                       LogDebug("Callback name :" << m_callbackNames[index].addedFunction << " "
-                       << m_callbackNames[index].updatedFunction << " " << m_callbackNames[index].removedFunction);
+        if (JSObjectHasProperty(m_context, objectCallbacks, propName.get()))
+        {
+            LogDebug("Callback name :" << m_callbackNames[index].addedFunction << " "
+            << m_callbackNames[index].updatedFunction << " " << m_callbackNames[index].removedFunction);
 
-                       result.messagesAdded = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].addedFunction);
-                       result.messagesUpdated = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].updatedFunction);
-                       result.messagesRemoved = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].removedFunction);
-                       break;
-               }
+            result.messagesAdded = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].addedFunction);
+            result.messagesUpdated = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].updatedFunction);
+            result.messagesRemoved = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].removedFunction);
+            break;
+        }
 
-       }
+    }
 
-       if(result.messagesAdded == NULL || result.messagesUpdated == NULL || result.messagesRemoved == NULL)
-       {
-               LogError("OnMessagesChanged is not set");
-               Throw(WrtDeviceApis::Commons::ConversionException);
-       }
+    if(result.messagesAdded == NULL || result.messagesUpdated == NULL || result.messagesRemoved == NULL)
+    {
+        LogError("OnMessagesChanged is not set");
+        Throw(WrtDeviceApis::Commons::ConversionException);
+    }
 
-       result.functionIndex = index;
+    result.functionIndex = index;
 
-       if ((!validator.isNullOrUndefined(result.messagesAdded) && !validator.isCallback(result.messagesAdded)) ||
-       (!validator.isNullOrUndefined(result.messagesUpdated) && !validator.isCallback(result.messagesUpdated)) ||
-       (!validator.isNullOrUndefined(result.messagesRemoved) && !validator.isCallback(result.messagesRemoved)))
-       {
-               LogError("java script call back set error");
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+    if ((!validator.isNullOrUndefined(result.messagesAdded) && !validator.isCallback(result.messagesAdded)) ||
+    (!validator.isNullOrUndefined(result.messagesUpdated) && !validator.isCallback(result.messagesUpdated)) ||
+    (!validator.isNullOrUndefined(result.messagesRemoved) && !validator.isCallback(result.messagesRemoved)))
+    {
+        LogError("java script call back set error");
+        Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
 
-       return result;
+    return result;
 }
 
 
@@ -409,100 +411,124 @@ FolderType ConverterMessage::toFolderType(const JSValueRef& arg)
 
 MessageType ConverterMessage::toMessageType(JSValueRef arg)
 {
-        return toMessageType(toJSObjectRef(arg));
+     return toMessageType(toJSObjectRef(arg));
 }
 
 MessageType ConverterMessage::toMessageType(JSObjectRef arg)
 {
     // convert JSvalue to message type enum
-       std::string strMsgType = toString(arg);
-       LogDebug("Messasge Type : " << strMsgType);
-
-       if ( strMsgType.compare("messaging.sms") == 0 ) 
-       {
-               return SMS;
-       }
-       else if ( strMsgType.compare("messaging.mms") == 0 ) 
-       {
-               return MMS;
-       }
-       else if ( strMsgType.compare("messaging.email") == 0 )
-       {
-               return EMAIL;
-       }
-       else
-       {
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message type not supported");
-       }
+    std::string strMsgType = toString(arg);
+    LogDebug("Messasge Type : " << strMsgType);
+
+    if ( strMsgType.compare("messaging.sms") == 0 )
+    {
+        return SMS;
+    }
+    else if ( strMsgType.compare("messaging.mms") == 0 )
+    {
+        return MMS;
+    }
+    else if ( strMsgType.compare("messaging.email") == 0 )
+    {
+        return EMAIL;
+    }
+    else
+    {
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message type not supported");
+    }
 
 }
 
 std::string ConverterMessage::toMessageType( long msgtype )
 {
-       LogDebug("Messasge Type : " << msgtype);
+    LogDebug("Messasge Type : " << msgtype);
+
+    switch (msgtype)
+    {
+        case SMS:
+            return "messaging.sms";
+        case MMS:
+            return "messaging.mms";
+        case EMAIL:
+            return "messaging.email";
+        default :
+            ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message type not supported");
+    }
+}
+
+MessageType ConverterMessage::toMessageType(std::string arg)
+{
+    LogDebug("Messasge Type : " << arg);
+
+    if ( arg.compare("messaging.sms") == 0 )
+    {
+        return SMS;
+    }
+    else if ( arg.compare("messaging.mms") == 0 )
+    {
+        return MMS;
+    }
+    else if ( arg.compare("messaging.email") == 0 )
+    {
+        return EMAIL;
+    }
+    else
+    {
+        std::string message = "Message type " + arg + " not supported.";
+        throw DeviceAPI::Common::InvalidValuesException(message.c_str());
+    }
 
-       switch (msgtype)
-       {
-               case SMS:
-                       return "messaging.sms";
-               case MMS:
-                       return "messaging.mms";
-               case EMAIL:
-                       return "messaging.email";
-               default :
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message type not supported");
-       }
 }
 
 std::string ConverterMessage::toMessageStatusType( long msgstatus )
 {
-       LogDebug("Messasge Status : " << msgstatus);
-
-       switch (msgstatus)
-       {
-               case MESSAGE_STATUS_SENT:
-                       return "SENT";
-               case MESSAGE_STATUS_SENDING:
-                       return "SENDING";
-               case MESSAGE_STATUS_FAILED:
-                       return "FAILED";
-               case MESSAGE_STATUS_DRAFT:
-                       return "DRAFT";
-               case MESSAGE_STATUS_CREATED:
-               case MESSAGE_STATUS_LOADED:
-                       return "";
-               default :
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message status not supported");
-       }
+    LogDebug("Messasge Status : " << msgstatus);
+
+    switch (msgstatus)
+    {
+        case MESSAGE_STATUS_SENT:
+            return "SENT";
+        case MESSAGE_STATUS_SENDING:
+            return "SENDING";
+        case MESSAGE_STATUS_FAILED:
+            return "FAILED";
+        case MESSAGE_STATUS_DRAFT:
+            return "DRAFT";
+        case MESSAGE_STATUS_CREATED:
+        case MESSAGE_STATUS_LOADED:
+            return "";
+        default :
+            ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message status not supported");
+    }
 }
 
 std::string ConverterMessage::convertIntToString( int msgInt )
 {
-       LogDebug("input int : " << msgInt);
-       std::stringstream stream;
-       stream << msgInt;
-       return stream.str();
+    LogDebug("input int : " << msgInt);
+    std::stringstream stream;
+    stream << msgInt;
+    return stream.str();
 }
 
 IConversationPtr ConverterMessage::toConversation(const JSValueRef& arg)
 {
-       return JSConversation::getConversation(m_context, arg);
+    return JSConversation::getConversation(m_context, arg);
 }
 
 std::vector<IConversationPtr> ConverterMessage::toVectorOfConversation(const JSValueRef& arg)
 {
-       std::vector<IConversationPtr> result;
+    std::vector<IConversationPtr> result;
 
-       JSObjectRef jsObject = toJSObjectRef(arg);
+    JSObjectRef jsObject = toJSObjectRef(arg);
 
-       if(     JSGetArrayLength(m_context, jsObject) == 0)
-       {
+    if(    JSGetArrayLength(m_context, jsObject) == 0)
+    {
         LogError("this is empty conversation");
-        Throw(WrtDeviceApis::Commons::ConversionException);    
-       }
+        Throw(WrtDeviceApis::Commons::ConversionException);
+    }
 
-       for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i)
-       {
+    for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i)
+    {
         JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
         result.push_back(toConversation(element));
     }
@@ -579,7 +605,7 @@ JSValueRef ConverterMessage::toFunction(const JSValueRef& arg)
     if (Validator(m_context).isCallback(arg)) {
         return arg;
     } else if (JSValueIsNull(m_context, 
-               arg) || JSValueIsUndefined(m_context, arg)) {
+        arg) || JSValueIsUndefined(m_context, arg)) {
         ThrowMsg(InvalidArgumentException, "JS null passed as function.");
     }
     ThrowMsg(ConversionException, "Not a function nor JS null.");
index f4527d0..824c944 100644 (file)
@@ -118,6 +118,8 @@ class ConverterMessage : public WrtDeviceApis::CommonsJavaScript::Converter
 
     std::string toMessageType( long msgtype );
 
+    MessageType toMessageType(std::string arg);
+
     std::string toMessageStatusType( long msgstatus );
 
     std::string convertIntToString( int msgInt );
index 5fa27dd..04aa758 100755 (executable)
@@ -27,6 +27,8 @@
 #include "JSConversation.h"
 #include "ConverterMessage.h"
 
+#include <JSWebAPIError.h>
+
 
 using namespace std;
 using namespace DPL;
@@ -44,15 +46,15 @@ JSClassDefinition JSConversation::m_classInfo =
        kJSClassAttributeNone,
        "MessageConversation",
        NULL,
-       m_properties,
+       NULL, //m_properties,
        NULL,
        initialize,
        finalize,
        NULL, //hasProperty,
-       NULL, //getProperty,
-       NULL, //setProperty,
+       getProperty,
+       setProperty,
        NULL, //deleteProperty,
-       NULL, //getPropertyNames,
+       getPropertyNames,
        NULL,
        NULL,
        hasInstance,
@@ -69,18 +71,19 @@ const char* JSConversation::SUBJECT = "subject";
 const char* JSConversation::ISREAD = "isRead";
 const char* JSConversation::FROM = "from";
 const char* JSConversation::TO = "to";
-const char* JSConversation::CC = "cc"; 
-const char* JSConversation::BCC = "bcc"; 
-const char* JSConversation::LASTMESSAGEID = "lastMessageId";   
+const char* JSConversation::CC = "cc";
+const char* JSConversation::BCC = "bcc";
+const char* JSConversation::LASTMESSAGEID = "lastMessageId";
 
 const std::string JSConversation::TYPE_SMS              = "messaging.sms";
 const std::string JSConversation::TYPE_MMS              = "messaging.mms";
 const std::string JSConversation::TYPE_EMAIL    = "messaging.email";
 
+#if 0
 JSStaticValue JSConversation::m_properties[] = {
        {"id", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"type", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },     
-       {"timestamp", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },        
+       {"type", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"timestamp", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
        {"messageCount", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
        {"unreadMessages", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
        {"preview", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
@@ -93,6 +96,7 @@ JSStaticValue JSConversation::m_properties[] = {
        {"lastMessageId", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
        {0, 0, 0, 0}
 };
+#endif
 
 const JSClassRef JSConversation::getClassRef() {
        if (!m_jsClassRef) {
@@ -107,23 +111,22 @@ const JSClassDefinition* JSConversation::getClassInfo() {
 
 JSClassRef JSConversation::m_jsClassRef = JSClassCreate(JSConversation::getClassInfo());
 
-void JSConversation::initialize(JSContextRef context, JSObjectRef object) 
+void JSConversation::initialize(JSContextRef context, JSObjectRef object)
 {
        LogDebug("JSConversation::initialize ");
        JSConversationPriv* priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));
 ;
        if (priv == NULL)
        {
-               LogDebug("Private data is null ");              
+               LogDebug("Private data is null ");
        }
        else
        {
-               LogDebug("JSConversation::already exist ");             
+               LogDebug("JSConversation::already exist ");
        }
 }
 
 
-
 JSObjectRef JSConversation::createJSObject(JSContextRef context, IConversationPtr object)
 {
        JSConversationPriv* priv = new JSConversationPriv( context, object);
@@ -134,9 +137,9 @@ JSObjectRef JSConversation::createJSObject(JSContextRef context, IConversationPt
 void JSConversation::finalize(JSObjectRef object) {
        JSConversationPriv* priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));
 
-       LogDebug("JSConversation::Finalrize");
+       LogDebug("JSConversation::Finalize");
 
-       if (priv != NULL) 
+       if (priv != NULL)
        {
                JSObjectSetPrivate(object, NULL);
                delete priv;
@@ -153,74 +156,74 @@ JSValueRef JSConversation::getProperty(JSContextRef context,
                                                                                JSStringRef propertyName,
                                                                                JSValueRef* exception)
 {
-       LogDebug("OK"); 
+       LogDebug("OK");
 
        ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(context);
 //     WrtDeviceApis::CommonsJavaScript::Converter converter(context);
 
-       JSConversationPriv* priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));        
-       try 
+       JSConversationPriv* priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));
+       try
        {
                if (priv == NULL)
                {
-                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                       throw DeviceAPI::Common::UnknownException("Object is null");
                }
-               
+
                IConversationPtr conversation(priv->getObject());
 
                if (conversation->getResult() == false)
                {
-                       Throw(WrtDeviceApis::Commons::PlatformException);
+                       throw DeviceAPI::Common::UnknownException("Failed to get object");
                }
                if(JSStringIsEqualToUTF8CString(propertyName, CONVID))
                {
                        return converter->toJSValueRef(converter->convertIntToString(conversation->getConvId()));
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, TYPE)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, TYPE))
                {
                        return converter->toJSValueRef(convertMessageType(conversation->getType()));
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, TIMESTAMP)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, TIMESTAMP))
                {
                        return converter->toJSValueRef(conversation->getTime());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, MESSAGECOUNT)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, MESSAGECOUNT))
                {
                        return converter->toJSValueRef(conversation->getMessageCount());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, UNREADMESSAGES)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, UNREADMESSAGES))
                {
                        return converter->toJSValueRef(conversation->getUnreadMessages());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, PREVIEW)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, PREVIEW))
                {
                        return converter->toJSValueRef(conversation->getPreview());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, SUBJECT)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, SUBJECT))
                {
                        return converter->toJSValueRef(conversation->getSubject());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, ISREAD)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, ISREAD))
                {
                        return converter->toJSValueRef(conversation->getRead());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, FROM)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, FROM))
                {
                        return converter->toJSValueRef(conversation->getFrom());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, TO)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, TO))
                {
                        return converter->toJSValueRef(conversation->getTo());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, CC)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, CC))
                {
                        return converter->toJSValueRef(conversation->getCC());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, BCC)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, BCC))
                {
                        return converter->toJSValueRef(conversation->getBCC());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, LASTMESSAGEID)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, LASTMESSAGEID))
                {
                        return converter->toJSValueRef(converter->convertIntToString(conversation->getLastMessageId()));
                }
@@ -228,8 +231,107 @@ JSValueRef JSConversation::getProperty(JSContextRef context,
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) {
                LogError("Exception: " << ex.GetMessage());
-       }       
-       return JSValueMakeNull(context);
+               return JSValueMakeUndefined(context);
+       }
+       return NULL;
+}
+
+bool JSConversation::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    if (JSStringIsEqualToUTF8CString(propertyName, CONVID)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, TYPE)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, TIMESTAMP)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, MESSAGECOUNT)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, UNREADMESSAGES)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, PREVIEW)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, SUBJECT)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, ISREAD)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, FROM)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, TO)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, CC)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, BCC)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, LASTMESSAGEID)) {
+        return true;
+       }
+    return false;
+}
+
+void JSConversation::getPropertyNames(JSContextRef context,
+        JSObjectRef object,
+        JSPropertyNameAccumulatorRef propertyNames)
+{
+    LogDebug("Entered");
+    JSStringRef propertyName = NULL;
+
+    propertyName = JSStringCreateWithUTF8CString(CONVID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(TYPE);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(TIMESTAMP);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(MESSAGECOUNT);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(UNREADMESSAGES);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(PREVIEW);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(SUBJECT);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(ISREAD);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(FROM);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(TO);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(CC);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(BCC);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(LASTMESSAGEID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
 }
 
 bool JSConversation::isObjectOfClass(JSContextRef context, JSValueRef value)
@@ -240,23 +342,23 @@ bool JSConversation::isObjectOfClass(JSContextRef context, JSValueRef value)
 IConversationPtr JSConversation::getConversation(JSContextRef context, JSValueRef value)
 {
        JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) 
+       if (!object)
        {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw DeviceAPI::Common::TypeMismatchException("Failed to get object");
        }
        JSConversationPriv *priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));
-       
-       if (!priv) 
+
+       if (!priv)
        {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
+               throw DeviceAPI::Common::TypeMismatchException("Object is null");
        }
        return priv->getObject();
 }
 
 std::string JSConversation::convertMessageType(int msgType){
 
-       if(msgType == SMS){
-               return JSConversation::TYPE_SMS;                
+       if(msgType == SMS){
+               return JSConversation::TYPE_SMS;
        }else if(msgType == MMS){
                return JSConversation::TYPE_MMS;
        }else if(msgType == EMAIL){
@@ -266,7 +368,7 @@ std::string JSConversation::convertMessageType(int msgType){
        }
  }
 
-} 
+}
 }// WrtPlugins
 
 
index d877820..b21d926 100755 (executable)
@@ -63,16 +63,25 @@ private:
         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);
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
 
+       static bool setProperty(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static void getPropertyNames(JSContextRef context,
+                       JSObjectRef object,
+                       JSPropertyNameAccumulatorRef propertyNames);
 
        /**
         * This structure contains properties and callbacks that define a type of object.
@@ -82,11 +91,11 @@ private:
        /**
         * This structure describes a statically declared function property.
         */
-       static JSStaticValue m_properties[];
+       //static JSStaticValue m_properties[];
        static JSClassRef m_jsClassRef;
 
 
-       
+
        static const char* CONVID;
        static const char* TYPE;
        static const char* TIMESTAMP;
@@ -97,9 +106,9 @@ private:
        static const char* ISREAD;
        static const char* FROM;
        static const char* TO;
-       static const char* CC;  
-       static const char* BCC; 
-       static const char* LASTMESSAGEID;       
+       static const char* CC;
+       static const char* BCC;
+       static const char* LASTMESSAGEID;
 
        static const std::string TYPE_SMS;
        static const std::string TYPE_MMS;
index a9939eb..2247440 100644 (file)
 #include <SecurityExceptions.h>
 
 #include <CommonsJavaScript/ScopedJSStringRef.h>
+// ==== new common headers
+#include <GlobalContextManager.h>
+#include <PlatformException.h>
+#include <JSWebAPIError.h>
+#include <JSUtil.h>
+#include <ArgumentValidator.h>
+// ====
 
 #include "MessagingErrorMsg.h"
 #include "JSMessageAttachment.h"
 
 #include "Sms.h"
 
-
 using namespace std;
-using namespace DeviceAPI::Messaging;
 using namespace DeviceAPI::Common;
 using namespace WrtDeviceApis::Commons;
-using namespace DeviceAPI::Messaging;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
 namespace DeviceAPI {
 namespace Messaging {
 JSClassRef JSMessage::m_jsClassRef = NULL;
 
+#define MESSAGE_ATTRIBUTE_ID "id"
+#define MESSAGE_ATTRIBUTE_SERVICE_ID "serviceId"
+#define MESSAGE_ATTRIBUTE_CONVERSATION_ID "conversationId"
+#define MESSAGE_ATTRIBUTE_FOLDER_ID  "folderId"
+#define MESSAGE_ATTRIBUTE_TYPE "type"
+#define MESSAGE_ATTRIBUTE_TIMESTAMP "timestamp"
+#define MESSAGE_ATTRIBUTE_FROM "from"
+#define MESSAGE_ATTRIBUTE_TO "to" // used also in dictionary
+#define MESSAGE_ATTRIBUTE_CC "cc" // used also in dictionary
+#define MESSAGE_ATTRIBUTE_BCC  "bcc" // used also in dictionary
+#define MESSAGE_ATTRIBUTE_BODY "body"
+#define MESSAGE_ATTRIBUTE_IS_READ "isRead"
+#define MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY "isHighPriority" // used also in dictionary
+#define MESSAGE_ATTRIBUTE_SUBJECT "subject" // used also in dictionary
+#define MESSAGE_ATTRIBUTE_IN_RESPONSE_TO "inResponseTo"
+#define MESSAGE_ATTRIBUTE_MESSAGE_STATUS "messageStatus"
+#define MESSAGE_ATTRIBUTE_ATTACHMENTS "attachments"
+#define MESSAGE_ATTRIBUTE_HAS_ATTACHMENT "hasAttachment"
+
+#define MESSAGE_DICTIONARY_ATTRIBUTE_PLAIN_BODY "plainBody"
+#define MESSAGE_DICTIONARY_ATTRIBUTE_HTML_BODY "htmlBody"
+
 JSClassDefinition JSMessage::m_classInfo = {
-       0,
-       kJSClassAttributeNone,
-       "Message",
-       0,
-       m_property,
-       NULL,           //m_function
-       initialize,
-       finalize,
-       NULL, //hasProperty,
-       NULL, //getProperty,
-       NULL, //setProperty,
-       NULL, //deleteProperty,
-       NULL, //getPropertyNames,
-       NULL, //callAsFunction,
-       constructor, //callAsConstructor,
-       NULL, //hasInstance,
-       NULL, //convertToType,
+    0,
+    kJSClassAttributeNone,
+    "Message",
+    0,
+    NULL, // m_property not used here - access properties by setProperty()/getProperty()
+    NULL, // m_function
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    JSMessage::getProperty, //getProperty,
+    JSMessage::setProperty, //setProperty,
+    NULL, //deleteProperty,
+    JSMessage::getPropertyNames, //getPropertyNames,
+    NULL, //callAsFunction,
+    constructor, //callAsConstructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
 };
 
-// JSMessage properties
+// JSMessage properties - used in: getProperty(), setProperty(), getPropertyNames()
 JSStaticValue JSMessage::m_property[] = {
-       { "id", getMessageId, NULL, kJSPropertyAttributeReadOnly },
-       { "serviceId", getAccountID, NULL, kJSPropertyAttributeReadOnly},
-       { "conversationId", getConversationId, NULL, kJSPropertyAttributeReadOnly },
-       { "folderId", getFolder, NULL, kJSPropertyAttributeReadOnly },
-       { "type", getMessageType, NULL, kJSPropertyAttributeReadOnly },
-       { "timestamp", getTime, NULL, kJSPropertyAttributeReadOnly },
-       { "from", getSourceAddress, NULL, kJSPropertyAttributeReadOnly },
-       { "to", getDestinationAddress, setDestinationAddress, kJSPropertyAttributeNone },
-       { "cc", getCcAddress, setCcAddress, kJSPropertyAttributeNone },
-       { "bcc", getBccAddress, setBccAddress, kJSPropertyAttributeNone },
-       { "body", getMessageBody, setMessageBody, kJSPropertyAttributeNone },
-       { "isRead", getIsRead, setIsRead, kJSPropertyAttributeNone },
-       //{ "hasAttachment", getAttachmentExistence, NULL, kJSPropertyAttributeReadOnly },
-       { "isHighPriority", getMessagePriority, setMessagePriority, kJSPropertyAttributeNone },
-       { "subject", getSubject, setSubject, kJSPropertyAttributeNone },
-       { "inResponseTo", getInResponseTo, NULL, kJSPropertyAttributeNone },
-       { "messageStatus", getMessageStatus, NULL, kJSPropertyAttributeReadOnly},
-       { "attachments", getAttachments, setAttachments, kJSPropertyAttributeNone },
-       { "hasAttachment", hasAttachment, NULL, kJSPropertyAttributeReadOnly},
-       //{ "uid", getUID, NULL, kJSPropertyAttributeReadOnly},
-       { 0, 0, 0, 0 }
+    { MESSAGE_ATTRIBUTE_ID, getMessageId, NULL, kJSPropertyAttributeReadOnly },
+    { MESSAGE_ATTRIBUTE_SERVICE_ID, getAccountID, NULL, kJSPropertyAttributeReadOnly},
+    { MESSAGE_ATTRIBUTE_CONVERSATION_ID, getConversationId, NULL, kJSPropertyAttributeReadOnly },
+    { MESSAGE_ATTRIBUTE_FOLDER_ID, getFolder, NULL, kJSPropertyAttributeReadOnly },
+    { MESSAGE_ATTRIBUTE_TYPE, getMessageType, NULL, kJSPropertyAttributeReadOnly },
+    { MESSAGE_ATTRIBUTE_TIMESTAMP, getTime, NULL, kJSPropertyAttributeReadOnly },
+    { MESSAGE_ATTRIBUTE_FROM, getSourceAddress, NULL, kJSPropertyAttributeReadOnly },
+    { MESSAGE_ATTRIBUTE_TO, getDestinationAddress, setDestinationAddress, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_CC, getCcAddress, setCcAddress, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_BCC, getBccAddress, setBccAddress, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_BODY, getMessageBody, setMessageBody, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_IS_READ, getIsRead, setIsRead, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY, getMessagePriority, setMessagePriority, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_SUBJECT, getSubject, setSubject, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_IN_RESPONSE_TO, getInResponseTo, NULL, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_MESSAGE_STATUS, getMessageStatus, NULL, kJSPropertyAttributeReadOnly},
+    { MESSAGE_ATTRIBUTE_ATTACHMENTS, getAttachments, setAttachments, kJSPropertyAttributeNone },
+    { MESSAGE_ATTRIBUTE_HAS_ATTACHMENT, hasAttachment, NULL, kJSPropertyAttributeReadOnly},
+    { 0, 0, 0, 0 }
 };
 
+
 JSValueRef JSMessage::createJSObject(JSContextRef context,
                EmailAccountInfo& account,
                MessageType msgType,
@@ -226,7 +251,7 @@ JSValueRef JSMessage::createDummyMessageJSObject(JSContextRef context,
        else
        {
                LogError("message type is invalid");
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException); 
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
        }
        return createJSObject(context, msg);
 }
@@ -270,8 +295,23 @@ JSValueRef JSMessage::getProperty(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       LogError("should not enter");
-       return JSValueMakeUndefined(context);
+    LogInfo("Main getProperty()");
+    int index = 0;
+    // for non-NULL property names
+    while(m_property[index].name != NULL) {
+        // if property name matches
+        if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
+            if(m_property[index].getProperty != NULL) {
+                // if getProperty() function exists - call it
+                return m_property[index].getProperty(context, object, propertyName, exception);
+            } else {
+                //otherwise return undefined
+                return JSValueMakeUndefined(context);
+            }
+        }
+        index++;
+    }
+    return NULL;
 }
 
 bool JSMessage::setProperty(JSContextRef context,
@@ -280,8 +320,23 @@ bool JSMessage::setProperty(JSContextRef context,
         JSValueRef value,
         JSValueRef* exception)
 {
-       LogError("should not enter");
-       return false;
+    LogInfo("Main setProperty()");
+    int index = 0;
+    // for non-NULL property names
+    while(m_property[index].name != NULL) {
+        // if property name matches
+        if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
+            if(m_property[index].setProperty != NULL) {
+                // if setProperty() function exists - call it
+                return m_property[index].setProperty(context, object, propertyName, value, exception);
+            } else {
+                // otherwise return true (lack of function - readonly attribute)
+                return true;
+            }
+        }
+        index++;
+    }
+    return false;
 }
 
 bool JSMessage::deleteProperty(JSContextRef context,
@@ -298,6 +353,17 @@ void JSMessage::getPropertyNames(JSContextRef context,
         JSPropertyNameAccumulatorRef propertyNames)
 {
        LogInfo("enter");
+
+    JSStringRef propertyName = NULL;
+    int index = 0;
+    // repeat for each declared property - until null on property name
+    while(m_property[index].name != NULL) {
+        LogDebug("Property: " << m_property[index].name);
+        propertyName = JSStringCreateWithUTF8CString(m_property[index].name);
+        JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+        JSStringRelease(propertyName);
+        index++;
+    }
 }
 
 JSValueRef JSMessage::callAsFunction(JSContextRef context,
@@ -320,179 +386,153 @@ bool JSMessage::hasInstance(JSContextRef context,
        return true;
 }
 
-JSObjectRef JSMessage::constructor(JSContextRef context, 
-               JSObjectRef constructor, 
-               size_t argumentCount, 
-               const JSValueRef arguments[], 
-               JSValueRef* exception)
+JSObjectRef JSMessage::constructor(JSContextRef context,
+        JSObjectRef constructor,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       LogDebug("entered");
-
-       JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(constructor));
-       JSContextRef globalContext = priv ? priv->getContext() : context;
-
-       if (!globalContext)
-       {
-               LogDebug(" globalContext is NULL ");
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);     
-               return NULL;
-       }
-
-       try
-       {
-               if ( argumentCount < 1 ) {
-                       LogError("Wrong argument count");
-                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong Message argumentCount");
-               }
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-               MessageType msgType = converter->toMessageType(arguments[0]);
-               //objMsg = JSMessage::createDummyMessageJSObject(globalContext, msgType);               //make message JSValueRef.
-
-               IMessagePtr msg;
-               if ( msgType == EMAIL )
-               {
-                       msg = MessageFactory::createEmailMessage();
-               }
-               else if (msgType == MMS || msgType == SMS)
-               {
-                       msg = MessageFactory::createMessage(msgType);   //create message
-               }
-               else
-               {
-                       LogError("message type is invalid");
-                       Throw(WrtDeviceApis::Commons::InvalidArgumentException); 
-               }
-
-               if (msg)
-               {
-                       if ( argumentCount == 2 )
-                       {
-                               LogDebug ("##### msg type is " << msgType);
-
-                               const ScopedJSStringRef subjectStr(JSStringCreateWithUTF8CString("subject"));
-                               const ScopedJSStringRef toStr(JSStringCreateWithUTF8CString("to"));
-                               const ScopedJSStringRef ccStr(JSStringCreateWithUTF8CString("cc"));
-                               const ScopedJSStringRef bccStr(JSStringCreateWithUTF8CString("bcc"));
-                               const ScopedJSStringRef plainBodyStr(JSStringCreateWithUTF8CString("plainBody"));
-                               const ScopedJSStringRef htmlBodyStr(JSStringCreateWithUTF8CString("htmlBody"));
-                               const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("isHighPriority"));
-
-                               JSObjectRef arg = converter->toJSObjectRef(arguments[1]);       //get dictionary
-                               JSValueRef subjectData = JSObjectGetProperty(globalContext, arg, subjectStr.get(), NULL);
-                               JSValueRef toData = JSObjectGetProperty(globalContext, arg, toStr.get(), NULL);
-                               JSValueRef ccData = JSObjectGetProperty(globalContext, arg, ccStr.get(), NULL);
-                               JSValueRef bccData = JSObjectGetProperty(globalContext, arg, bccStr.get(), NULL);
-                               JSValueRef plainBodyData = JSObjectGetProperty(globalContext, arg, plainBodyStr.get(), NULL);
-                               JSValueRef htmlBodyData = JSObjectGetProperty(globalContext, arg, htmlBodyStr.get(), NULL);
-                               JSValueRef priorityData = JSObjectGetProperty(globalContext, arg, priorityStr.get(), NULL);
-
-                               //subject
-                               if (!JSValueIsUndefined(globalContext, subjectData) )
-                               {
-                                       LogDebug ( " Subject : " << converter->toString(subjectData) );
-                                       std::string subject = converter->toString(subjectData);
-                                       switch (msgType)
-                                       {
-                                               case MMS:
-                                               {
-                                                       IMmsPtr mms = MessageFactory::convertToMms(msg);
-                                                       mms->setSubject(subject);
-                                                       break;
-                                               }
-                                               case EMAIL:
-                                               {
-                                                       IEmailPtr email = MessageFactory::convertToEmail(msg);
-                                                       email->setSubject(subject);
-                                                       break;
-                                               }
-                                               default:
-                                               {
-                                                       LogError("message not supported");
-                                                       //Throw(WrtDeviceApis::Commons::UnsupportedException);
-                                                       //break;
-                                               }
-                                       }
-                               }
-                               //to
-                               if (!JSValueIsUndefined(globalContext, toData) )
-                               {
-                                       Recipients to = converter->toRecipients(toData);
-                                       LogDebug("setting to field, size=" << to.getRecipientSize());
-                                       msg->setToRecipients(to);
-                               }
-                               //cc
-                               if (msgType == EMAIL )
-                               {
-                                       IEmailPtr email = MessageFactory::convertToEmail(msg);
-                                       if (!JSValueIsUndefined(globalContext, ccData))
-                                       {
-                                               Recipients cc = converter->toRecipients(ccData);
-                                               email->setCcRecipients(cc);
-                                       }
+    LogDebug("entered");
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+        std::string msgTypeString = validator.toString(0);
+        MessageType msgType = stringToMessageType(msgTypeString);
+        JSObjectRef dictionary = validator.toObject(1, true);
+        // converter is still used for some parameter
+        ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+        IMessagePtr msg;
+        if ( msgType == EMAIL )
+        {
+            msg = MessageFactory::createEmailMessage();
+        }
+        else if (msgType == MMS || msgType == SMS)
+        {
+            msg = MessageFactory::createMessage(msgType);      //create message
+        }
+        else
+        {
+            // this should never happen - message type checking done in stringToMessageType()
+            LogError("message type is invalid");
+            throw TypeMismatchException("Invalid message type");
+        }
 
-                                       if (!JSValueIsUndefined(globalContext, bccData))
-                                       {
-                                               Recipients bcc = converter->toRecipients(bccData);
-                                               email->setBccRecipients(bcc);
-                                       }
+        if (msg == NULL) {
+            LogDebug("Message Creation failed");
+            throw DeviceAPI::Common::UnknownException("Message has been not created");
+        }
 
-                                       if (!JSValueIsUndefined(globalContext, htmlBodyData))
-                                       {
-                                               std::string body = converter->toString(htmlBodyData);
-                                               LogDebug("html body : " << body);
-                                               email->setHtmlBody(body);
-                                       }
+        if (dictionary != NULL)
+        {
+            LogDebug ("##### msg type is " << msgType);
+
+            JSValueRef subjectData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_SUBJECT);
+            JSValueRef toData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_TO);
+            JSValueRef ccData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_CC);
+            JSValueRef bccData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_BCC);
+            JSValueRef plainBodyData = JSUtil::getProperty(context, dictionary, MESSAGE_DICTIONARY_ATTRIBUTE_PLAIN_BODY);
+            JSValueRef htmlBodyData = JSUtil::getProperty(context, dictionary, MESSAGE_DICTIONARY_ATTRIBUTE_HTML_BODY);
+            JSValueRef priorityData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY);
+
+            //subject
+            if (!JSValueIsUndefined(context, subjectData) )
+            {
+                std::string subject = JSUtil::JSValueToString(context, subjectData);
+                LogDebug (" Subject : " << subject);
+                switch (msgType)
+                {
+                    case MMS:
+                    {
+                        IMmsPtr mms = MessageFactory::convertToMms(msg);
+                        mms->setSubject(subject);
+                        break;
+                    }
+                    case EMAIL:
+                    {
+                        IEmailPtr email = MessageFactory::convertToEmail(msg);
+                        email->setSubject(subject);
+                        break;
+                    }
+                    default:
+                    {
+                        LogError("message not supported");
+                        //Throw(WrtDeviceApis::Commons::UnsupportedException);
+                        //break;
+                    }
+                }
+            }
+            //to
+            if (!JSValueIsUndefined(context, toData) )
+            {
+                Recipients to = converter->toRecipients(toData);
+                LogDebug("setting to field, size=" << to.getRecipientSize());
+                msg->setToRecipients(to);
+            }
+            //cc
+            if (msgType == EMAIL )
+            {
+                IEmailPtr email = MessageFactory::convertToEmail(msg);
+                if (!JSValueIsUndefined(context, ccData))
+                {
+                    Recipients cc = converter->toRecipients(ccData);
+                    email->setCcRecipients(cc);
+                }
 
-                                       if (!JSValueIsUndefined(globalContext, priorityData))
-                                       {
-                                               email->setPriority(converter->toMessagePriority(priorityData));
-                                       }
-                               }
-                               if (!JSValueIsUndefined(globalContext, plainBodyData) )
-                               {
-                                       std::string body = converter->toString(plainBodyData);
-                                       LogDebug("plain body  : " << body);
-                                       msg->setBody(body);
-                               }
+                if (!JSValueIsUndefined(context, bccData))
+                {
+                    Recipients bcc = converter->toRecipients(bccData);
+                    email->setBccRecipients(bcc);
+                }
 
-                       }
+                if (!JSValueIsUndefined(context, htmlBodyData))
+                {
+                    std::string body = JSUtil::JSValueToString(context, htmlBodyData);
+                    LogDebug("html body : " << body);
+                    email->setHtmlBody(body);
+                }
 
-                       //return
-                       JSClassRef jsClassRef = JSClassCreate(getClassInfo());
-                       LogDebug("jsClassRef success");
-                       JSMessagePrivateObject* priv = new JSMessagePrivateObject(globalContext, msg);
-                       LogDebug("priv success");
-
-                       JSObjectRef jsObjRef = JSObjectMake(globalContext, jsClassRef, static_cast<void*>(priv));
-                       LogDebug("JSObjectMake success");
-                       JSClassRelease(jsClassRef);
-                       if (NULL == jsObjRef) {
-                               LogError("object creation error");
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "JSObject make error"); 
-                       }
-                       return jsObjRef;
+                if (!JSValueIsUndefined(context, priorityData))
+                {
+                    email->setPriority(converter->toMessagePriority(priorityData));
+                }
+            }
+            if (!JSValueIsUndefined(context, plainBodyData) )
+            {
+                std::string body = JSUtil::JSValueToString(context, plainBodyData);
+                LogDebug("plain body  : " << body);
+                msg->setBody(body);
+            }
+        }
 
-               }
-               else
-               {
-                       LogDebug("Message Creation failed");
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "message has been not created"); 
-               }
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               return NULL;
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               return NULL;
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               return NULL;
-       }
-       return NULL;
+        //return
+        JSClassRef jsClassRef = JSClassCreate(JSMessage::getClassInfo());
+        LogDebug("jsClassRef success");
+        JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
+        LogDebug("priv success");
+
+        JSObjectRef jsObjRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
+        LogDebug("JSObjectMake success");
+        JSClassRelease(jsClassRef);
+        if (NULL == jsObjRef) {
+            LogError("JSObject creation error");
+            throw DeviceAPI::Common::UnknownException("JSObject make error");
+        }
+        return jsObjRef;
+    }
+    catch(BasePlatformException &bex) {
+        LogError("Message creation failed: " << bex.getMessage());
+        JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, bex);
+        *exception = error;
+        return NULL;
+    }
+    catch(...) {
+        DeviceAPI::Common::UnknownException err("UnknownError in Message constructor.");
+        JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
+        *exception = error;
+        return NULL;
+    }
+    return NULL;
 }
 
 JSValueRef JSMessage::convertToType(JSContextRef context,
@@ -510,20 +550,20 @@ JSValueRef JSMessage::getAttachments(JSContextRef context,
         JSValueRef* exception)
 {
        LogInfo("enter");
-       Try
-       {
-               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-               if (!priv)
-                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-
-               JSContextRef globalContext = priv->getContext();
+       try {
+        GlobalContextManager *gcm = GlobalContextManager::getInstance();
+        if(gcm == NULL) {
+            LogError("Failed to get GlobalContextManager");
+            throw DeviceAPI::Common::UnknownException("Unable to receive global context");
+        }
+               JSContextRef globalContext = gcm->getGlobalContext(context);
 
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                MessageType msgType = msg->getMessageType();
                LogInfo("msgType=" << msgType);
                // prepare common values
-               JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(converter->toJSGlobalContext(object), NULL, NULL);
+               JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(globalContext, NULL, NULL);
 
                switch (msgType) {
                        case MMS:
@@ -561,7 +601,7 @@ JSValueRef JSMessage::getAttachments(JSContextRef context,
                        }
                        case SMS:
                        {
-                               JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
+                               JSObjectRef arrayValue = JSObjectMakeArray(globalContext, 0, NULL, NULL);
                                if (NULL == arrayValue)
                                {
                                        LogError("Could not create js array object");
@@ -570,20 +610,21 @@ JSValueRef JSMessage::getAttachments(JSContextRef context,
                                return arrayValue;
                        }
                        default:
-                               LogError("not supported message type");
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                               LogError("Not supported message type");
+                /* unsupported type -> type is integral message attribute
+                 * so error at this place means internal api error*/
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("Attachments getting failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting attachments.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 
@@ -593,8 +634,7 @@ JSValueRef JSMessage::getBccAddress(JSContextRef context,
         JSValueRef* exception)
 {
        LogDebug("enter");
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                MessageType msgType = msg->getMessageType();
@@ -605,25 +645,31 @@ JSValueRef JSMessage::getBccAddress(JSContextRef context,
                        {
                                IEmailPtr email = MessageFactory::convertToEmail(msg);
                                RecipientsPtr recipient = email->getBccRecipientsPtr();
-                               JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
+                               JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
                                if (NULL == arrayValue)
                                {
                                        LogError("Could not create js array object");
                                        return JSValueMakeUndefined(context);
                                }
+                JSValueRef referr;
                                for(size_t i = 0; i < recipient->getRecipientSize(); i++)
                                {
-                                       if(!JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i))))
-                       {
-                                               ThrowMsg(ConversionException, "Could not insert value into js array");
-                       }
+                    referr = NULL;
+                    JSObjectSetPropertyAtIndex(context, arrayValue, i,
+                            converter->toJSValueRef(recipient->getRecipient(i)), &referr);
+                    if(referr != NULL)
+                    {
+                        /* previously it was DPL ConversionException converted in
+                         * catch into TypeMismatch but it's more an internal error */
+                        throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
+                    }
                                }
                                return arrayValue;
                        }
                        case SMS:
                        case MMS:
                        {
-                               JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
+                               JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
                                if (NULL == arrayValue)
                                {
                                        LogError("Could not create js array object");
@@ -632,22 +678,21 @@ JSValueRef JSMessage::getBccAddress(JSContextRef context,
                                return arrayValue;
                        }
                        default:
-                               LogError("not supported message type");
-                               return JSTizenExceptionFactory::postException(context, exception,
-                                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported type
-                       break;
+                LogError("not supported message type");
+                /* unsupported type -> type is integral message attribute
+                 * so error at this place means internal api error*/
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("BCC addressess getting failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting BCC addressess.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getBody(JSContextRef context,
@@ -655,23 +700,23 @@ JSValueRef JSMessage::getBody(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-               IMessagePtr msg = converter->toIMessage(object);
-               string body = msg->getBody();
-               return converter->toJSValueRef(body);
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    try {
+        ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+        IMessagePtr msg = converter->toIMessage(object);
+        string body = msg->getBody();
+        return converter->toJSValueRef(body);
+    }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Message body getting failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting Message body.");
+        return JSValueMakeUndefined(context);;
+    }
 }
 
 JSValueRef JSMessage::getCcAddress(JSContextRef context,
@@ -680,8 +725,7 @@ JSValueRef JSMessage::getCcAddress(JSContextRef context,
         JSValueRef* exception)
 {
        LogDebug("enter");
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                MessageType msgType = msg->getMessageType();
@@ -692,17 +736,23 @@ JSValueRef JSMessage::getCcAddress(JSContextRef context,
                        {
                                IEmailPtr email = MessageFactory::convertToEmail(msg);
                                RecipientsPtr recipient = email->getCcRecipientsPtr();
-                               JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
+                               JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
                                if (NULL == arrayValue)
                                {
                                        LogError("Could not create js array object");
                                        return JSValueMakeUndefined(context);
                                }
+                JSValueRef referr;
                                for(size_t i = 0; i < recipient->getRecipientSize(); i++)
                                {
-                                       if(!JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i))))
+                    referr = NULL;
+                    JSObjectSetPropertyAtIndex(context, arrayValue, i,
+                            converter->toJSValueRef(recipient->getRecipient(i)), &referr);
+                    if(referr != NULL)
                        {
-                                               ThrowMsg(ConversionException, "Could not insert value into js array");
+                        /* previously it was DPL ConversionException converted in
+                         * catch into TypeMismatch but it's more an internal error */
+                        throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
                        }
                                }
                                return arrayValue;
@@ -710,7 +760,7 @@ JSValueRef JSMessage::getCcAddress(JSContextRef context,
                        case MMS:
                        case SMS:
                        {
-                               JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
+                               JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
                                if (NULL == arrayValue)
                                {
                                        LogError("Could not create js array object");
@@ -720,22 +770,20 @@ JSValueRef JSMessage::getCcAddress(JSContextRef context,
                        }
                        default:
                                LogError("not supported message type");
-                               return JSTizenExceptionFactory::postException(context, exception, 
-                                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);    // unsupported type
-
-                       break;
+                /* unsupported type -> type is integral message attribute
+                 * so error at this place means internal api error*/
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    }
+    catch(BasePlatformException &bex) {
+        LogError("CC addressess getting failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting CC addressess.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
@@ -744,37 +792,39 @@ JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
         JSValueRef* exception)
 {
        LogInfo("enter");
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                RecipientsPtr recipient = msg->getToRecipientsPtr();
-               JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
+               JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
                if (NULL == arrayValue)
                {
                        LogError("Could not create js array object");
                        return JSValueMakeUndefined(context);
                }
-               LogError("recipient->getRecipientSize() : " << recipient->getRecipientSize());
+               LogError("getRecipientSize() : " << recipient->getRecipientSize());
+        JSValueRef referr;
                for(size_t i = 0; i < recipient->getRecipientSize(); i++)
                {
-                       if(!JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i))))
-                       {
-                               ThrowMsg(ConversionException, "Could not insert value into js array");
+            referr = NULL;
+            JSObjectSetPropertyAtIndex(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)), &referr);
+            if(referr != NULL)
+            {
+                /* previously it was DPL ConversionException converted in
+                 * catch into TypeMismatch but it's more an internal error */
+                throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
                        }
                }
                return arrayValue;
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("Destination addressess getting failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting destination addressess.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getIsRead(JSContextRef context,
@@ -782,23 +832,23 @@ JSValueRef JSMessage::getIsRead(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-               {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                bool isRead = msg->isRead();
                return converter->toJSValueRef(isRead);
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Checking if message is read failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when checking if message is read.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getMessageId(JSContextRef context,
@@ -806,8 +856,7 @@ JSValueRef JSMessage::getMessageId(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                const string& id = msg->getIdRef();
@@ -819,16 +868,17 @@ JSValueRef JSMessage::getMessageId(JSContextRef context,
                }
                return converter->toJSValueRef(id);
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting message id failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message id.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getMessagePriority(JSContextRef context,
@@ -836,8 +886,7 @@ JSValueRef JSMessage::getMessagePriority(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                MessageType msgType = msg->getMessageType();
@@ -860,21 +909,20 @@ JSValueRef JSMessage::getMessagePriority(JSContextRef context,
                        }
                        default:
                                LogError("unsupported message type");
-                               return JSTizenExceptionFactory::postException(context, exception,
-                                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
-                       break;
+                /* unsupported type -> type is integral message attribute
+                 * so error at this place means internal api error*/
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("Getting message priority failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message priority.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getMessageType(JSContextRef context,
@@ -882,24 +930,24 @@ JSValueRef JSMessage::getMessageType(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                MessageType msgType = msg->getMessageType();
 
                return converter->toJSValueRef(converter->toMessageType(msgType));
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting message type failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message type.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getSourceAddress(JSContextRef context,
@@ -907,8 +955,7 @@ JSValueRef JSMessage::getSourceAddress(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                string from = msg->getSourceAddress();
@@ -920,16 +967,17 @@ JSValueRef JSMessage::getSourceAddress(JSContextRef context,
                }
                return converter->toJSValueRef(from);
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting message source address failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message source address.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getSubject(JSContextRef context,
@@ -937,8 +985,7 @@ JSValueRef JSMessage::getSubject(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                MessageType msgType = msg->getMessageType();
@@ -959,25 +1006,20 @@ JSValueRef JSMessage::getSubject(JSContextRef context,
                                return converter->toJSValueRef("");
                        default:
                                LogError("message not support subject");
-                               return JSTizenExceptionFactory::postException(context, exception,
-                                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
-                       break;
+                /* unsupported type -> type is integral message attribute
+                 * so error at this place means internal api error*/
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException) {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("Getting message subject failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message subject.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getTime(JSContextRef context,
@@ -985,8 +1027,7 @@ JSValueRef JSMessage::getTime(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                struct tm dateTime = msg->getDateTime();
@@ -997,19 +1038,20 @@ JSValueRef JSMessage::getTime(JSContextRef context,
                {
                        LogInfo("JSValueMakeNull");
                        return JSValueMakeNull(context);
-               }               
+               }
                return converter->toJSValueRef(dateTime);
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting message time failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message time.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getFolder(JSContextRef context,
@@ -1017,8 +1059,7 @@ JSValueRef JSMessage::getFolder(JSContextRef context,
         JSStringRef propertyName,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                FolderType folder = msg->getCurrentFolder();
@@ -1035,17 +1076,18 @@ JSValueRef JSMessage::getFolder(JSContextRef context,
 
                tmpInt = (int)folder;
                return converter->toJSValueRef(converter->convertIntToString(tmpInt));
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting message folder failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message folder.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getMessageBody(JSContextRef context,
@@ -1055,29 +1097,27 @@ JSValueRef JSMessage::getMessageBody(JSContextRef context,
 {
        LogInfo("getMessageBody");
 
-       Try
-       {
-               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-               if (!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Couldn't get Messaage Private Object");
-
-               JSContextRef globalContext = priv->getContext();
+       try {
+        GlobalContextManager *gcm = GlobalContextManager::getInstance();
+        if(gcm == NULL) {
+            LogError("Failed to get GlobalContextManager");
+            throw DeviceAPI::Common::UnknownException("Unable to receive global context");
+        }
+               JSContextRef globalContext = gcm->getGlobalContext(context);
 
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
                IMessagePtr msg = converter->toIMessage(object);        //get message point
 
                return JSMessageBody::createJS(globalContext, msg);
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("Getting message body failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message body.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getAccountID(JSContextRef context,
@@ -1087,13 +1127,13 @@ JSValueRef JSMessage::getAccountID(JSContextRef context,
 {
        LogInfo("getAccountID");
 
-       Try
-       {
-               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-               if (!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
-
-               JSContextRef globalContext = priv->getContext();
+    try {
+        GlobalContextManager *gcm = GlobalContextManager::getInstance();
+        if(gcm == NULL) {
+            LogError("Failed to get GlobalContextManager");
+            throw DeviceAPI::Common::UnknownException("Unable to receive global context");
+        }
+        JSContextRef globalContext = gcm->getGlobalContext(context);
 
                ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
 
@@ -1111,7 +1151,7 @@ JSValueRef JSMessage::getAccountID(JSContextRef context,
                        std::stringstream stream;
                        stream << email->getAccountID();
                        if (stream.fail()) {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert e-mail account id");
+                               throw DeviceAPI::Common::UnknownException("Couldn't convert e-mail account id");
                        }
 
                        return converter->toJSValueRef(stream.str());
@@ -1121,7 +1161,7 @@ JSValueRef JSMessage::getAccountID(JSContextRef context,
                        std::stringstream stream;
                        stream << SMS_ACCOUNT_ID;
                        if (stream.fail()) {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert sms account id");
+                throw DeviceAPI::Common::UnknownException("Couldn't convert sms account id");
                        }
 
                        return converter->toJSValueRef(stream.str());
@@ -1131,7 +1171,7 @@ JSValueRef JSMessage::getAccountID(JSContextRef context,
                        std::stringstream stream;
                        stream << MMS_ACCOUNT_ID;
                        if (stream.fail()) {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert mms account id");
+                throw DeviceAPI::Common::UnknownException("Couldn't convert mms account id");
                        }
 
                        return converter->toJSValueRef(stream.str());
@@ -1141,16 +1181,14 @@ JSValueRef JSMessage::getAccountID(JSContextRef context,
                        return JSValueMakeUndefined(context);
                }
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("Getting account id failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting account id.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getUID(JSContextRef context,
@@ -1160,13 +1198,13 @@ JSValueRef JSMessage::getUID(JSContextRef context,
 {
        LogInfo("getUID");
 
-       Try
-       {
-               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-               if (!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
-
-               JSContextRef globalContext = priv->getContext();
+    try {
+        GlobalContextManager *gcm = GlobalContextManager::getInstance();
+        if(gcm == NULL) {
+            LogError("Failed to get GlobalContextManager");
+            throw DeviceAPI::Common::UnknownException("Unable to receive global context");
+        }
+        JSContextRef globalContext = gcm->getGlobalContext(context);
 
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
 
@@ -1184,16 +1222,14 @@ JSValueRef JSMessage::getUID(JSContextRef context,
                        return JSValueMakeUndefined(context);
                }
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        LogError("Getting account id failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting account id.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 bool JSMessage::setAttachments(JSContextRef context,
@@ -1204,20 +1240,8 @@ bool JSMessage::setAttachments(JSContextRef context,
 {
        LogInfo("enter");
 
-       Try
-       {
-               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-               
-               if (!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
-
-               JSContextRef globalContext = priv->getContext();
-               if (!globalContext)
-               {
-                       LogDebug("globalContext is NULL");
-                       globalContext = context;
-               }
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+    try {
+        ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
 
                vector<IAttachmentPtr> attachments;
                if (JSIsArrayValue(context, value)) {
@@ -1226,7 +1250,7 @@ bool JSMessage::setAttachments(JSContextRef context,
                        LogDebug("Array Length = " << len);
                        for (unsigned int i = 0; i < len; ++i)
                        {
-                               JSValueRef att = JSGetArrayElement(context, valueObj, i);
+                               JSValueRef att = JSObjectGetPropertyAtIndex(context, valueObj, i, NULL);
                                if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
                                        LogWarning("Invalid array element. Skipping.");
                                        continue;
@@ -1235,8 +1259,8 @@ bool JSMessage::setAttachments(JSContextRef context,
 
                                if(attachment->getIsValidAttachment() == false)
                                {
-                                       LogDebug("invalid attachment : " << i);
-                                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                    LogDebug("invalid attachment : " << i);
+                    throw DeviceAPI::Common::InvalidValuesException("Invalid attachment in array");
                                }
 
                                LogDebug("Adding attachment , shotname: " << attachment->getShortName());
@@ -1250,7 +1274,7 @@ bool JSMessage::setAttachments(JSContextRef context,
                        if(attachment->getIsValidAttachment() == false)
                        {
                                LogDebug("invalid attachment");
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                               throw DeviceAPI::Common::InvalidValuesException("Invalid attachments array");
                        }
                        attachments.push_back(attachment);
                }
@@ -1276,36 +1300,28 @@ bool JSMessage::setAttachments(JSContextRef context,
                                                break;
                                        }
                                        default:
-                                               LogError("not supported message type");
-                                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                        LogError("not supported message type");
+                        throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                        break;
                                }
                                return true;
                        }
                        else
                        {
                                LogError("Message converter failed...");
-                               Throw(WrtDeviceApis::Commons::NullPointerException);
+                               throw DeviceAPI::Common::UnknownException("Message conversion failure");
                        }
                }
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-               LogError("Invalid argument exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException) {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
-       }
-       return false;   
+    catch(BasePlatformException &bex) {
+        LogError("Setting attachments failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting attachments.");
+        return true;
+    }
+    return true;
 }
 
 
@@ -1324,13 +1340,13 @@ bool JSMessage::setAttachments(JSContextRef context,
             static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
 
         if (!priv) {
-            return JSTizenExceptionFactory::postException(context, exception, 
+            return JSTizenExceptionFactory::postException(context, exception,
                           JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
         }
     }
     Catch(WrtDeviceApis::Commons::NullPointerException) {
         LogError("Error on pointer, null value");
-          return JSTizenExceptionFactory::postException(context, exception, 
+          return JSTizenExceptionFactory::postException(context, exception,
                           JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
     }
 
@@ -1390,17 +1406,17 @@ bool JSMessage::setAttachments(JSContextRef context,
     }
     Catch(WrtDeviceApis::Commons::ConversionException) {
         LogError("Error on conversion");
-         return JSTizenExceptionFactory::postException(context, exception, 
+         return JSTizenExceptionFactory::postException(context, exception,
                   JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
     }
     Catch(WrtDeviceApis::Commons::NullPointerException) {
         LogError("Error on pointer, null value");
-         return JSTizenExceptionFactory::postException(context, exception, 
+         return JSTizenExceptionFactory::postException(context, exception,
                         JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
         LogError("Invalid argument");
-          return JSTizenExceptionFactory::postException(context, exception, 
+          return JSTizenExceptionFactory::postException(context, exception,
                           JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
     }
     return false;
@@ -1413,8 +1429,7 @@ bool JSMessage::setBccAddress(JSContextRef context,
         JSValueRef value,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                Recipients bcc = converter->toRecipients(value);
@@ -1433,26 +1448,21 @@ bool JSMessage::setBccAddress(JSContextRef context,
                                break;
                        }
                        default:
-                               LogError("unsupported message type");
-                               return JSTizenExceptionFactory::postException(context, exception,
-                                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
+                LogError("not supported message type");
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
                return true;
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-    return false;
+    catch(BasePlatformException &bex) {
+        LogError("Setting BCC addresses failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting BCC addresses.");
+        return true;
+    }
+    return true;
 }
 
 bool JSMessage::setBody(JSContextRef context,
@@ -1461,30 +1471,25 @@ bool JSMessage::setBody(JSContextRef context,
         JSValueRef value,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                string body = converter->toString(value);
                msg->setBody(body);
                return true;
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       return false;
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Setting BCC addresses failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting BCC addresses.");
+        return true;
+    }
+       return true;
 }
 
 bool JSMessage::setCcAddress(JSContextRef context,
@@ -1493,8 +1498,7 @@ bool JSMessage::setCcAddress(JSContextRef context,
         JSValueRef value,
         JSValueRef* exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                Recipients cc = converter->toRecipients(value);
@@ -1504,8 +1508,7 @@ bool JSMessage::setCcAddress(JSContextRef context,
                switch (msgType) {
                        case SMS:
                        case MMS:
-                               return false;   // ignore
-
+                               return true;   // ignore
                        case EMAIL:
                        {
                                IEmailPtr email = MessageFactory::convertToEmail(msg);
@@ -1513,29 +1516,21 @@ bool JSMessage::setCcAddress(JSContextRef context,
                                break;
                        }
                        default:
-                               LogError("unsuported message type");
-                               return JSTizenExceptionFactory::postException(context, exception,
-                                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
-                       break;
-               }
-                       return true;
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+                LogError("unsuported message type");
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
+        }
+        return true;
        }
-    return false;
+    catch(BasePlatformException &bex) {
+        LogError("Setting CC addresses failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting CC addresses.");
+        return true;
+    }
+       return true;
 }
 
 bool JSMessage::setDestinationAddress(JSContextRef context,
@@ -1545,7 +1540,7 @@ bool JSMessage::setDestinationAddress(JSContextRef context,
         JSValueRef * exception)
 {
        LogInfo("enter");
-       Try
+       try
        {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
@@ -1554,22 +1549,18 @@ bool JSMessage::setDestinationAddress(JSContextRef context,
                msg->setToRecipients(to);
                return true;
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       return false;
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Setting destination addresses failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting destination addresses.");
+        return true;
+    }
+    return true;
 }
 
 bool JSMessage::setIsRead(JSContextRef context,
@@ -1578,25 +1569,25 @@ bool JSMessage::setIsRead(JSContextRef context,
         JSValueRef value,
         JSValueRef * exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                msg->setReadStatus(converter->toBool(value));
                msg->setisReadChangeStatus(converter->toBool(value));
                return true;
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       return false;
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Setting destination addresses failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting destination addresses.");
+        return true;
+    }
+    return true;
 }
 
 bool JSMessage::setMessagePriority(JSContextRef context,
@@ -1613,35 +1604,28 @@ bool JSMessage::setMessagePriority(JSContextRef context,
                switch (msgType) {
                        case MMS:
                        case SMS:
-                               return false;   // ignore
-
+                // do not set value but show that this attribute is supported in object
+                return true;
                        case EMAIL:
-                               msg->setPriority(converter->toMessagePriority(value));
-                       break;
+                msg->setPriority(converter->toMessagePriority(value));
+                break;
 
                        default:
-                               LogError("unsuported message type");
-                               Throw(WrtDeviceApis::Commons::ConversionException);
-                       break;
+                LogError("unsuported message type");
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
                return true;
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       return false;
+    catch(BasePlatformException &bex) {
+        LogError("Setting message priority failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting message priority.");
+        return true;
+    }
+    return true;
 }
 
 bool JSMessage::setSubject(JSContextRef context,
@@ -1650,8 +1634,7 @@ bool JSMessage::setSubject(JSContextRef context,
         JSValueRef value,
         JSValueRef * exception)
 {
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                IMessagePtr msg = converter->toIMessage(object);
                MessageType msgType = msg->getMessageType();
@@ -1670,35 +1653,24 @@ bool JSMessage::setSubject(JSContextRef context,
                                break;
                        }
                        case SMS:
-                               return false;   // ignore
+                               return true;   // ignore
 
                        default:
                                LogError("message not supported");
-                               Throw(WrtDeviceApis::Commons::UnsupportedException);
-                       break;
+                throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
+                break;
                }
                return true;
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException) {
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
-       }
-       return false;
+    catch(BasePlatformException &bex) {
+        LogError("Setting message priority failed: " << bex.getMessage());
+        return true;
+    }
+    catch(...) {
+        LogError("UnknownError when setting message priority.");
+        return true;
+    }
+    return true;
 }
 
 bool JSMessage::setMessageBody(JSContextRef context,
@@ -1707,27 +1679,7 @@ bool JSMessage::setMessageBody(JSContextRef context,
         JSValueRef value,
         JSValueRef* exception)
 {
-       Try
-       {
-               LogDebug("Set Message Body.");
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       return false;
+    return true;
 }
 
 JSValueRef JSMessage::getConversationId(JSContextRef context,
@@ -1737,8 +1689,7 @@ JSValueRef JSMessage::getConversationId(JSContextRef context,
 {
        LogDebug("getConversationId");
 
-       Try
-       {
+       try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                int convId = 0;
                IMessagePtr msg = converter->toIMessage(object);
@@ -1752,21 +1703,17 @@ JSValueRef JSMessage::getConversationId(JSContextRef context,
                }
                return converter->toJSValueRef(converter->convertIntToString(convId));
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting conversation id failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting conversation id.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getInResponseTo(JSContextRef context,
@@ -1776,8 +1723,7 @@ JSValueRef JSMessage::getInResponseTo(JSContextRef context,
 {
        LogDebug("getInResponseTo");
 
-       Try
-       {
+    try {
                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
                int convId = -1;
                int msgId = 0;
@@ -1803,21 +1749,17 @@ JSValueRef JSMessage::getInResponseTo(JSContextRef context,
 
                return converter->toJSValueRef(converter->convertIntToString(convId));
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting in response to failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting in response to.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 JSValueRef JSMessage::getMessageStatus(JSContextRef context,
@@ -1827,31 +1769,26 @@ JSValueRef JSMessage::getMessageStatus(JSContextRef context,
 {
        LogInfo("getMessageStatus");
 
-       Try
+       try
        {
-               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-               if (!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
-
-               JSContextRef globalContext = priv->getContext();
-
-               ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
+               ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(context);
 
                IMessagePtr msg = converter->toIMessage(object); //get message point
 
                LogInfo("create JS");
                return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
        }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting message status failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting message status.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
 
@@ -1862,15 +1799,8 @@ JSValueRef JSMessage::hasAttachment(JSContextRef context,
 {
        LogInfo("hasAttachment");
 
-       Try
-               {
-               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-               if (!priv)
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
-
-               JSContextRef globalContext = priv->getContext();
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
+       Try {
+        ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
 
                IMessagePtr msg = converter->toIMessage(object); //get message point
 
@@ -1895,57 +1825,38 @@ JSValueRef JSMessage::hasAttachment(JSContextRef context,
                        hasAttachmentFlag = false;
                }
                return converter->toJSValueRef(hasAttachmentFlag);
-
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
        }
+    catch(BasePlatformException &bex) {
+        /* Currently this exception will not be caught here as converter
+         * is using od-style, DPL exceptions. This catch sections
+         * is prepared for future converter refactoring */
+        LogError("Getting hasAttachment flag failure: " << bex.getMessage());
+        return JSValueMakeUndefined(context);
+    }
+    catch(...) {
+        LogError("UnknownError when getting hasAttachment flag.");
+        return JSValueMakeUndefined(context);
+    }
 }
 
-#if 0
-JSValueRef JSMessage::getAttachmentExistence(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception)
+// Utility functions.
+MessageType JSMessage::stringToMessageType(std::string type)
 {
-       LogInfo("getAttachmentExistence");
-
-       Try
-       {
-         JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
-         Assert(priv && "Private object is NULL.");
-
-         JSContextRef globalContext = priv->getContext();
-
-         ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
-
-         IMessagePtr msg = converter->toIMessage(object); //get message point
-
-         LogInfo("create JS");
-         return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
-
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-         return JSTizenExceptionFactory::postException(context, exception, 
-                  JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-         return JSTizenExceptionFactory::postException(context, exception, 
-                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       
-       return JSValueMakeUndefined(context);
+    MessageType retval = UNKNOWN;
+    if (type.compare("messaging.sms") == 0) {
+        retval = SMS;
+    }
+    else if (type.compare("messaging.mms") == 0) {
+        retval = MMS;
+    }
+    else if (type.compare("messaging.mms") == 0) {
+        retval = EMAIL;
+    }
+    else{
+        throw DeviceAPI::Common::TypeMismatchException("Invalid MessageServiceTag");
+    }
+    return retval;
 }
-#endif
 
 }
 }
index f06a283..202c320 100755 (executable)
@@ -59,10 +59,10 @@ class JSMessage
     }
 
     static JSValueRef createJSObject(JSContextRef context,
-            EmailAccountInfo& account, 
+            EmailAccountInfo& account,
             MessageType msgType,
             const std::string& msgId = "");
-       
+
     static JSValueRef createJSObject(JSContextRef context,
             EventUpdateMessageAnswerReceiver* listener,
             MessageType msgType = MESSAGETYPE_COUNT,
@@ -151,10 +151,10 @@ class JSMessage
             JSValueRef possibleInstance,
             JSValueRef* exception);
 
-    static JSObjectRef constructor(JSContextRef ctx, 
-                       JSObjectRef constructor, 
-                       size_t argumentCount, 
-                       const JSValueRef arguments[], 
+    static JSObjectRef constructor(JSContextRef ctx,
+                       JSObjectRef constructor,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
                        JSValueRef* exception);
 
     /**
@@ -326,6 +326,13 @@ class JSMessage
      * The values are given according to the data structure JSPropertySpec
      */
     static JSStaticValue m_property[];
+
+    // Utility functions. After full refactoring should be moved into lower layer
+    /**
+     * Functions that provides enum MessageServiceTag support. Converts message
+     * type given as string into MessageType value
+     */
+    static MessageType stringToMessageType(std::string type);
 };
 }
 }
index ab4b725..1196d60 100644 (file)
@@ -30,6 +30,9 @@
 #include "MessagingErrorMsg.h"
 #include "Attachment.h"
 
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+
 #if 0
 namespace {
 const char* MSG_ATTACHMENT_MIMETYPE            = "MIMEType";
@@ -55,24 +58,28 @@ JSClassDefinition JSMessageAttachment::m_classInfo = {
     0,
     kJSClassAttributeNone,
     "MessageAttachment",
-    /*NULL,*/
-    /*JSFile::getClassRef(), parent*/
     NULL,
-    m_property,
+    NULL, //m_property,
     NULL,
     initialize,
     finalize,
     NULL, //hasProperty,
-    NULL,   //getproperty
-    NULL,  //setProperty
+    getProperty,
+    setProperty,
     NULL, //deleteProperty,
-    NULL, //getPropertyNames,
+    getPropertyNames,
     NULL, //callAsFunction,
     constructor, //callAsConstructor,
     NULL, //hasInstance,
     NULL, //convertToType,
 };
 
+const char* JSMessageAttachment::ATTACHMENTID = "id";
+const char* JSMessageAttachment::MSGID = "messageId";
+const char* JSMessageAttachment::MIMETYPE = "mimeType";
+const char* JSMessageAttachment::FILEPATH = "filePath";
+
+#if 0
 JSStaticValue JSMessageAttachment::m_property[] = {
     //{ "MIMEType", JSMessageAttachment::getMIMEType, NULL, kJSPropertyAttributeReadOnly },
     { "id", JSMessageAttachment::getContentID, NULL, kJSPropertyAttributeNone },
@@ -83,6 +90,8 @@ JSStaticValue JSMessageAttachment::m_property[] = {
     { "filePath", JSMessageAttachment::getFilePath, NULL, kJSPropertyAttributeReadOnly },
     { 0, 0, 0, 0 }
 };
+#endif
+
 const JSClassDefinition* JSMessageAttachment::getClassInfo()
 {
     return &(m_classInfo);
@@ -103,7 +112,7 @@ void JSMessageAttachment::initialize(JSContextRef context,
        if (!JSObjectGetPrivate(object)) {
                LogDebug("Private object not set... setting it.");
                IAttachmentPtr attachment(new Attachment());
-                                               
+
                JSMessageAttachmentPrivate *priv = new JSMessageAttachmentPrivate(context, attachment);
                if (!JSObjectSetPrivate(object, priv)) {
                        delete priv;
@@ -116,9 +125,9 @@ void JSMessageAttachment::finalize(JSObjectRef object)
     LogDebug("enter");
     JSMessageAttachmentPrivate* priv = static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(object));
     JSContextRef gContext = priv->getContext();
-       
+
     IAttachmentPtr attachment = getAttachment(gContext, object);
-       
+
     if ( attachment )
    {
        if (attachment->hasDummyFile())
@@ -138,6 +147,7 @@ JSObjectRef JSMessageAttachment::createJS( JSContextRef context, const IAttachme
     return JSObjectMake(context, getClassRef(), priv); //make JSObjectRef.
 }
 
+#if 0
 JSValueRef JSMessageAttachment::getMIMEType(JSContextRef context,
           JSObjectRef object,
           JSStringRef propertyName,
@@ -186,13 +196,13 @@ JSValueRef JSMessageAttachment::getMessageID(JSContextRef context,
        Catch(WrtDeviceApis::Commons::InvalidArgumentException)
        {
                LogError("invalid value conversion");
-               return JSTizenExceptionFactory::postException(context, exception, 
+               return JSTizenExceptionFactory::postException(context, exception,
                JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
                LogError("Unkown Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
+               return JSTizenExceptionFactory::postException(context, exception,
                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
        }
 }
@@ -233,13 +243,13 @@ JSValueRef JSMessageAttachment::getContentID(JSContextRef context,
        Catch(WrtDeviceApis::Commons::InvalidArgumentException)
        {
                LogError("invalid value conversion");
-               return JSTizenExceptionFactory::postException(context, exception, 
+               return JSTizenExceptionFactory::postException(context, exception,
                JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
                LogError("Unkown Exception");
-               return JSTizenExceptionFactory::postException(context, exception, 
+               return JSTizenExceptionFactory::postException(context, exception,
                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
        }
 }
@@ -250,12 +260,12 @@ JSValueRef JSMessageAttachment::getLoaded(JSContextRef context,
           JSStringRef propertyName,
           JSValueRef* exception)
 {
-       
+
          LogDebug("enter");
            Try
            {
                  IAttachmentPtr attachment = getAttachment(context, object);
-                 
+
        WrtDeviceApis::CommonsJavaScript::Converter converter(context);
                  LogDebug("Attachment Loaded :" << (attachment->getDownloaded() ));
                  return converter.toJSValueRef(attachment->getDownloaded());
@@ -263,13 +273,13 @@ JSValueRef JSMessageAttachment::getLoaded(JSContextRef context,
            Catch(WrtDeviceApis::Commons::InvalidArgumentException)
            {
                   LogError("invalid value conversion");
-                  return JSTizenExceptionFactory::postException(context, exception, 
+                  return JSTizenExceptionFactory::postException(context, exception,
                           JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
            }
            Catch(WrtDeviceApis::Commons::Exception)
            {
                LogError("Unkown Exception");
-                  return JSTizenExceptionFactory::postException(context, exception, 
+                  return JSTizenExceptionFactory::postException(context, exception,
                                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
            }
 //         return JSValueMakeUndefined(context);
@@ -287,17 +297,17 @@ JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
                LogDebug("priv is vaild");
 
        JSContextRef globalContext = priv ? priv->getContext() : context;
-       
+
        IAttachmentPtr attachment = getAttachment(context, object);
-       
+
        if ( attachment )
        {
                Try
-               {       
+               {
                        WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-                       
+
                        std::string fullPath = attachment->getFullPath();
-                       LogDebug("fullPath=" << fullPath);              
+                       LogDebug("fullPath=" << fullPath);
 
                        if (fullPath.empty()) {
                                return JSValueMakeNull(context);
@@ -341,10 +351,10 @@ JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
                                                }
                                                else
                                                {
-                                                       return JSValueMakeNull(context); 
+                                                       return JSValueMakeNull(context);
                                                }
                                        }
-                                       
+
 */
                                }
 
@@ -355,25 +365,25 @@ JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
                Catch(WrtDeviceApis::Commons::InvalidArgumentException)
                {
                   LogError("invalid value conversion");
-                  return JSTizenExceptionFactory::postException(context, exception, 
+                  return JSTizenExceptionFactory::postException(context, exception,
                           JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
                }
                Catch(WrtDeviceApis::Commons::Exception)
                {
                    LogError("Unkown Exception");
-                   return JSTizenExceptionFactory::postException(context, exception, 
+                   return JSTizenExceptionFactory::postException(context, exception,
                                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
                }
 //             return JSValueMakeUndefined(context);
-               
+
        }
        else
        {
-               return JSTizenExceptionFactory::postException(context, exception, 
+               return JSTizenExceptionFactory::postException(context, exception,
                        JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
        }
-       
-#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+
+/* // MESSAGING ATTACHMENT IS BLOCKED
                LogDebug("enter");
                Try
                {
@@ -383,7 +393,7 @@ JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
                    }
 
                    std::string fullPath = attachment->getFullPath();
-                   LogDebug("full Path = " << fullPath );      
+                   LogDebug("full Path = " << fullPath );
                    if (fullPath.empty()) {
                        return JSValueMakeUndefined(context);
                    }
@@ -404,7 +414,7 @@ JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
                    WrtDeviceApis::Commons::ExceptionCodes::Enumeration code = event->getExceptionCode();
                    if (code != WrtDeviceApis::Commons::ExceptionCodes::None) {
                        LogError("Attachment location not resolved. Exception code: " << code);
-                          return JSTizenExceptionFactory::postException(context, exception, 
+                          return JSTizenExceptionFactory::postException(context, exception,
                                         JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
 
                    }
@@ -412,7 +422,7 @@ JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
                    DeviceAPI::Filesystem::INodePtr node = event->getResult();
                    if (!node) {
                        LogError("Resolved attachment location is empty.");
-                          return JSTizenExceptionFactory::postException(context, exception, 
+                          return JSTizenExceptionFactory::postException(context, exception,
                                         JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
 
                    }
@@ -420,31 +430,32 @@ JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
                        DeviceAPI::Filesystem::IPathPtr path = node->getPath();
 
                        LogError(" Path = " << path->getPath()  << " Full Path = " <<  path->getFullPath());
-                       
+
                    JSObjectRef result = WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(context,
                                                                      JSFile::getClassRef(),
                                                                      node);
                    return result;
-               
+
                }
                Catch(WrtDeviceApis::Commons::InvalidArgumentException)
                {
                   LogError("invalid value conversion");
-                  return JSTizenExceptionFactory::postException(context, exception, 
+                  return JSTizenExceptionFactory::postException(context, exception,
                           JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
 
                }
                Catch(WrtDeviceApis::Commons::Exception)
                {
                    LogError("Unkown Exception");
-                   return JSTizenExceptionFactory::postException(context, exception, 
+                   return JSTizenExceptionFactory::postException(context, exception,
                                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
                }
                return JSValueMakeUndefined(context);
-#endif
+*/
 //return JSValueMakeUndefined(context);
 
 }
+#endif
 
 IAttachmentPtr JSMessageAttachment::getAttachment(JSContextRef context,
         JSValueRef value)
@@ -471,114 +482,183 @@ JSMessageAttachmentPrivate* JSMessageAttachment::getPrivate(JSObjectRef thisObje
     return thisPrivate;
 }
 
-JSObjectRef JSMessageAttachment::constructor(JSContextRef context, 
-               JSObjectRef constructor, 
-               size_t argumentCount, 
-               const JSValueRef arguments[], 
+JSObjectRef JSMessageAttachment::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
                JSValueRef* exception)
 {
        LogDebug("entered");
 
        JSMessageAttachmentPrivate* priv = static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(constructor));
        JSContextRef globalContext = priv ? priv->getContext() : context;
-       
-       if (globalContext)
+
+       try
        {
-               try
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               std::string path = validator.toString(0);
+               std::string mimetype = validator.toString(1, true);
+
+               LogDebug("path size() : " << path.size());
+
+               if(path.size() != 0)
                {
-                       LogDebug("argumentCount=" << argumentCount);
-                       if ( argumentCount < 1 ) {
-                               LogError("Wrong argument count");
-                               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-                               return NULL;
+                       DeviceAPI::Filesystem::IPathPtr src = DeviceAPI::Filesystem::Utils::fromVirtualPath(globalContext, path);
+                       if (src)
+                       {
+                               LogDebug("path size() : " << path.size());
+                               path = src->getFullPath();
                        }
                        else
-                       {       
-                               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                               
-                               std::string path = converter->toString(arguments[0]);   //filepath
-                               std::string mimetype;
-                               
-                               if ( argumentCount == 2)
-                                       mimetype = converter->toString(arguments[1]);   //filepath
-
+                       {
                                LogDebug("path size() : " << path.size());
-
-                               if(path.size() != 0)
-                               {
-                                       DeviceAPI::Filesystem::IPathPtr src = DeviceAPI::Filesystem::Utils::fromVirtualPath(globalContext, path);
-                                       if (src)
-                                       {
-                                               LogDebug("path size() : " << path.size());
-                                               path = src->getFullPath();
-                                       }
-                                       else
-                                       {
-                                               LogDebug("path size() : " << path.size());                              
-                                               path = "";      //set empty string.
-                                       }
-                               }
-                               else
-                               {
-                                       LogDebug("path size() : " << path.size());
-                                       path = "";      //set empty string.
-                               }
-                               
-                               LogDebug("real path = " << path);
-                               IAttachmentPtr attachment = AttachmentFactory::createAttachment(
-                                                                                   path,
-                                                                                   mimetype);
-                               if (attachment)
-                               {
-                                       JSClassRef jsClassRef = JSClassCreate(getClassInfo());
-                                       LogDebug("jsClassRef success");
-                                       JSMessageAttachmentPrivate* priv = new JSMessageAttachmentPrivate(globalContext, attachment);
-                                       LogDebug("priv success");
-                                       
-                                       JSObjectRef jsObjRef = JSObjectMake(globalContext, jsClassRef, static_cast<void*>(priv));
-                                       LogDebug("JSObjectMake success");
-                                       JSClassRelease(jsClassRef);
-                                       if (NULL == jsObjRef) {
-                                               LogError("object creation error");
-                                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "JSObject make error"); 
-                                       }
-                                       return jsObjRef;
-                               }
-                               else
-                               {
-                                       LogDebug("attachment can't create");
-                                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "attachment create failed..."); 
-                               }
+                               path = "";      //set empty string.
                        }
+               }
+               else
+               {
+                       LogDebug("path size() : " << path.size());
+                       path = "";      //set empty string.
+               }
 
-               }       
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-                       return NULL;
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) {
-                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-                       return NULL;
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) {
-                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);     
-                       return NULL;
-               }
-               Catch(WrtDeviceApis::Commons::NotFoundException) {
-                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND); 
-                       return NULL;
-               }
+               LogDebug("real path = " << path);
+               IAttachmentPtr attachment = AttachmentFactory::createAttachment(
+                                                                               path,
+                                                                               mimetype);
+               if (attachment)
+               {
+                       JSClassRef jsClassRef = JSClassCreate(getClassInfo());
+                       LogDebug("jsClassRef success");
+                       JSMessageAttachmentPrivate* priv = new JSMessageAttachmentPrivate(globalContext, attachment);
+                       LogDebug("priv success");
+
+                       JSObjectRef jsObjRef = JSObjectMake(globalContext, jsClassRef, static_cast<void*>(priv));
+                       LogDebug("JSObjectMake success");
+                       JSClassRelease(jsClassRef);
+                       if (NULL == jsObjRef) {
+                               LogError("object creation error");
+                               throw DeviceAPI::Common::UnknownException("JSObject make error");
+                       }
+                       return jsObjRef;
+               }
+               else
+               {
+                       LogDebug("attachment can't create");
+                       throw DeviceAPI::Common::UnknownException("attachment create failed");
+               }
+       }catch(BasePlatformException & e) {
+               LogError("Message creation failed: " << e.getMessage());
+               JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, e);
+               *exception = error;
        }
-       else
-       {
-               LogDebug(" globalContext is NULL ");
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);     
-               return NULL;
+       catch(...) {
+               DeviceAPI::Common::UnknownException err("UnknownError in Message constructor.");
+               JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
+               *exception = error;
        }
+       return NULL;
+}
+
+JSValueRef JSMessageAttachment::getProperty(JSContextRef context,
+                                                                                       JSObjectRef object,
+                                                                                       JSStringRef propertyName,
+                                                                                       JSValueRef* exception)
+{
+       LogDebug("OK");
+
+       ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(context);
+//     WrtDeviceApis::CommonsJavaScript::Converter converter(context);
 
+       JSMessageAttachmentPrivate* priv = static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(object));
+       JSContextRef globalContext = priv ? priv->getContext() : context;
+
+       IAttachmentPtr attachment = getAttachment(context, object);
+       try
+       {
+               if (attachment == NULL)
+               {
+                       throw DeviceAPI::Common::UnknownException("Object is null");
+               }
+
+               if(JSStringIsEqualToUTF8CString(propertyName, ATTACHMENTID))
+               {
+                       if(attachment->getAttachmentID() != -1)
+                               return converter->toJSValueRef(converter->convertIntToString(attachment->getAttachmentID()));
+                       return JSValueMakeNull(context);
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, MSGID))
+               {
+                       if((attachment->getAttachmentID() < 0) && (attachment->getMessage() == 0))
+                               return JSValueMakeNull(context);
+                       else
+                               return converter->toJSValueRef(attachment->getMessage()->getId());
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, MIMETYPE))
+               {
+                       if(attachment->getMimeType().size() == 0)
+                               return JSValueMakeNull(context);
+                       else
+                               return converter->toJSValueRef(attachment->getMimeType());
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, FILEPATH))
+               {
+                       std::string fullPath = attachment->getFullPath();
+                       std::string filePath = DeviceAPI::Filesystem::Utils::toVirtualPath(globalContext, fullPath);
+                       return converter->toJSValueRef(filePath);
+               }
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               return JSValueMakeUndefined(context);
+       }
        return NULL;
 }
 
+bool JSMessageAttachment::setProperty(JSContextRef context,
+                                                                         JSObjectRef object,
+                                                                         JSStringRef propertyName,
+                                                                         JSValueRef value,
+                                                                         JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    if (JSStringIsEqualToUTF8CString(propertyName, ATTACHMENTID)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, MSGID)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, MIMETYPE)) {
+        return true;
+    } else if (JSStringIsEqualToUTF8CString(propertyName, FILEPATH)) {
+        return true;
+    }
+    return false;
+}
+
+void JSMessageAttachment::getPropertyNames(JSContextRef context,
+                                                                                  JSObjectRef object,
+                                                                                  JSPropertyNameAccumulatorRef propertyNames)
+{
+    LogDebug("Entered");
+    JSStringRef propertyName = NULL;
+
+    propertyName = JSStringCreateWithUTF8CString(ATTACHMENTID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(MSGID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(MIMETYPE);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(FILEPATH);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+}
+
 
 }
 }
index 20c4d8d..4626fad 100755 (executable)
@@ -27,18 +27,18 @@ namespace DeviceAPI {
 namespace Messaging {
 
 typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<IAttachmentPtr>::Type JSMessageAttachmentPrivate;     //IAttachmentPtr
-       
+
 class JSMessageAttachment
 {
        static JSClassRef m_jsClassRef;
-       
+
 public:
        static const JSClassDefinition* getClassInfo();
        static JSClassRef getClassRef();
        static JSObjectRef createJS( JSContextRef context, const IAttachmentPtr &msg);
 
 private:
-       
+
     /**
      * The callback invoked when an object is first created.
      */
@@ -54,13 +54,29 @@ private:
             JSObjectRef object,
             JSStringRef propertyName);
 
-    static JSObjectRef constructor(JSContextRef ctx, 
-                       JSObjectRef constructor, 
-                       size_t argumentCount, 
-                       const JSValueRef arguments[], 
+    static JSObjectRef constructor(JSContextRef ctx,
+                       JSObjectRef constructor,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
                        JSValueRef* exception);
 
-    /**
+       static JSValueRef getProperty(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setProperty(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static void getPropertyNames(JSContextRef context,
+                       JSObjectRef object,
+                       JSPropertyNameAccumulatorRef propertyNames);
+
+#if 0
+       /**
      * Get MIME Type of Attachment File.  readonly
      */
     static JSValueRef getMIMEType(JSContextRef context,
@@ -68,7 +84,7 @@ private:
                JSStringRef propertyName,
                JSValueRef* exception);
 
-    
+
     static JSValueRef getMessageID(JSContextRef context,
                JSObjectRef object,
                JSStringRef propertyName,
@@ -84,17 +100,18 @@ private:
                JSStringRef propertyName,
                JSValueRef* exception);
 
-       
+
     static JSValueRef getLoaded(JSContextRef context,
                JSObjectRef object,
                JSStringRef propertyName,
                JSValueRef* exception);
-       
+
    static JSValueRef getFilePath(JSContextRef context,
                JSObjectRef object,
                JSStringRef propertyName,
                JSValueRef* exception);
-       
+#endif
+
     /*
      * returns private object or throws WrtDeviceApis::Commons::NullPointerException
      */
@@ -129,10 +146,14 @@ private:
        * This member variable contains the initialization values for the static properties of this class.
        * The values are given according to the data structure JSPropertySpec
        */
-       static JSStaticValue m_property[];
-  
+       //static JSStaticValue m_property[];
+
+       static const char* ATTACHMENTID;
+       static const char* MSGID;
+       static const char* MIMETYPE;
+       static const char* FILEPATH;
 };
-       
+
 }
 }
 
index bd2f2eb..2443047 100644 (file)
 
 #include "JSMessageAttachment.h"
 
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
 namespace DeviceAPI {
 namespace Messaging {
 
-       using namespace DeviceAPI::Common;
-       using namespace DeviceAPI::Messaging;
-       using namespace WrtDeviceApis::Commons; 
-       using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DeviceAPI::Common;
+using namespace DeviceAPI::Messaging;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
 
+const char* JSMessageBody::MSGID = "messageId";
+const char* JSMessageBody::LOADED = "loaded";
+const char* JSMessageBody::PLAINBODY = "plainBody";
+const char* JSMessageBody::HTMLBODY = "htmlBody";
+const char* JSMessageBody::INLINEATT = "inlineAttachments";
 
 JSClassRef JSMessageBody::m_jsClassRef = NULL;
 
@@ -47,11 +56,11 @@ JSClassDefinition JSMessageBody::m_classInfo = {
     NULL,
     initialize,
     finalize,
-    hasProperty,
-    NULL,   //getproperty
-    NULL,  //setProperty
+    NULL, //hasProperty,
+    getProperty,
+    setProperty,
     NULL, //deleteProperty,
-    NULL, //getPropertyNames,
+    getPropertyNames,
     NULL, //callAsFunction,
     NULL, //callAsConstructor,
     NULL, //hasInstance,
@@ -59,11 +68,6 @@ JSClassDefinition JSMessageBody::m_classInfo = {
 };
 
 JSStaticValue JSMessageBody::m_property[] = {
-    { "messageId", JSMessageBody::getMessageID, NULL, kJSPropertyAttributeReadOnly },
-    { "loaded", JSMessageBody::getLoadedStatus, NULL, kJSPropertyAttributeReadOnly },
-    { "plainBody", JSMessageBody::getPlainBody, JSMessageBody::setPlainBody, kJSPropertyAttributeNone },
-    { "htmlBody", JSMessageBody::getHtmlBody, JSMessageBody::setHtmlBody, kJSPropertyAttributeNone },
-    { "inlineAttachments", JSMessageBody::getAttachments, JSMessageBody::setAttachments, kJSPropertyAttributeNone },
     { 0, 0, 0, 0 }
 };
 
@@ -80,27 +84,6 @@ JSClassRef JSMessageBody::getClassRef()
     return m_jsClassRef;
 }
 
-bool JSMessageBody::hasProperty(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName)
-{
-    LogDebug("enter");
-    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-    Try
-    {
-        IMessagePtr msg = getMessage(context, object);
-
-       if (!msg) {
-            return true;
-        }
-    }
-    Catch(WrtDeviceApis::Commons::Exception)
-    {
-        //not reporting error is intended
-    }
-    return false;
-}
-
 void JSMessageBody::initialize(JSContextRef context,
         JSObjectRef object)
 {
@@ -118,420 +101,276 @@ void JSMessageBody::finalize(JSObjectRef object)
 JSObjectRef JSMessageBody::createJS( JSContextRef context, const IMessagePtr &msg)
 {
     JSMessageBodyPrivate *priv = new JSMessageBodyPrivate(context, msg);
-    return JSObjectMake(context, getClassRef(), priv); //make JSObjectRef.
+    return JSObjectMake(context, getClassRef(), priv); //make JSObjectRef.
 }
 
-JSValueRef JSMessageBody::getMessageID(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+IMessagePtr JSMessageBody::getMessage(JSContextRef context,
+        JSValueRef value)
 {
-    LogDebug("enter");
-    Try
-    {
-               IMessagePtr msg = getMessage(context, object);
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-         
-               std::string id = msg->getId();
-               LogDebug("msgId=" << id);
-               LogDebug("msg->getMessageStatus()=" << msg->getMessageStatus());
-               if((id.size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
-               {
-                       return converter->toJSValueRef("");
-               }
-               return converter->toJSValueRef(id);
-    }
-    Catch(WrtDeviceApis::Commons::Exception)
-    {
-        LogError("invalid conversion");
-    }
-    return JSValueMakeUndefined(context);
+    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+    return getMessage(context, converter.toJSObjectRef(value));
 }
 
-JSValueRef JSMessageBody::getLoadedStatus(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+IMessagePtr JSMessageBody::getMessage(JSContextRef context,
+        JSObjectRef object)
 {
-    LogDebug("enter");
-    Try
-    {
-         WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-         IMessagePtr msg = getMessage(context, object);
-         
-         if (msg->getMessageType() == EMAIL)
-         {
-               IEmailPtr email = MessageFactory::convertToEmail(msg);
-               return converter.toJSValueRef(email->isBodyDownloaded() > 0 ? true : false);
-         }
-         else
-         {
-               std::string id = msg->getId();
-               LogDebug("msgId=" << id);
-               LogDebug("msg->getMessageStatus()=" << msg->getMessageStatus());
-               if((id.size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
-               {
-                       return converter.toJSValueRef(false);
-               }
-               return converter.toJSValueRef(true);
-         }
-         
-    }
-    Catch(WrtDeviceApis::Commons::Exception)
-    {
-        LogError("invalid conversion");
-    }
-    return JSValueMakeUndefined(context);
+    return getPrivate(object)->getObject();
 }
 
-
-JSValueRef JSMessageBody::getPlainBody(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+JSMessageBodyPrivate* JSMessageBody::getPrivate(JSObjectRef thisObject)
 {
-       LogDebug("getPlainBody");
-
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-               IMessagePtr msg = getMessage(context, object);
-               std::string body = msg->getBody();
-               LogDebug("getPlainBody plainBody" << body );
-               return converter.toJSValueRef(body);
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    JSMessageBodyPrivate* thisPrivate = static_cast<JSMessageBodyPrivate*>(JSObjectGetPrivate(thisObject));
+    if (!thisPrivate) {
+        LogError("no private");
+        Throw(WrtDeviceApis::Commons::NullPointerException);
+    }
+    return thisPrivate;
 }
 
-bool JSMessageBody::setPlainBody(JSContextRef context,
+JSValueRef JSMessageBody::getProperty(JSContextRef context,
         JSObjectRef object,
         JSStringRef propertyName,
-        JSValueRef value,
         JSValueRef* exception)
 {
-    LogDebug("setPlainBody");
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-               IMessagePtr msg = getMessage(context, object);
-               std::string body = converter.toString(value);
-               msg->setBody(body);
-               LogDebug("setPlainBody plainBody" << body );
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       return false;
-}
-
-JSValueRef JSMessageBody::getHtmlBody(JSContextRef context,
-       JSObjectRef object,
-       JSStringRef propertyName,
-       JSValueRef* exception)
-{
-       LogDebug("getHtmlBody");
-       Try
-       {               
-               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-               IMessagePtr msg = getMessage(context, object);
-
-               LogDebug("message Type : " << msg->getMessageType() );
-               if (msg->getMessageType() == EMAIL)
-               {
-                       IEmailPtr email = MessageFactory::convertToEmail(msg);
-                       LogDebug("Html Body : " << email->getHtmlBody() );
-                       return converter.toJSValueRef(email->getHtmlBody());
-               }
-               else
-               {
-                       return converter.toJSValueRef("");
-               }
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-}
+    LogDebug("Entered");
 
-bool JSMessageBody::setHtmlBody(JSContextRef context,
-       JSObjectRef object,
-       JSStringRef propertyName,
-       JSValueRef value,
-       JSValueRef* exception)
-{
-       LogDebug("setHtmlBody");
-
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-               IMessagePtr msg = getMessage(context, object);
-
-               if (msg->getMessageType() == EMAIL)
-               {
-                       IEmailPtr email = MessageFactory::convertToEmail(msg);
-                       std::string body = converter.toString(value);
-                       LogDebug("input String : " << body);
-                       email->setHtmlBody(body);
-                       return true;
-               }
-               else
-               {
-                       LogError("html body is for Email only.");
-                       return true;
-//                     return JSTizenExceptionFactory::postException(context, exception, 
-//                                     JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("Platform execution");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-
-       return false;
-}
+    try {
+       IMessagePtr msg = getMessage(context, object);
+        if (msg == NULL) {
+            throw DeviceAPI::Common::UnknownException("Object is null");
+        }
 
+        if (JSStringIsEqualToUTF8CString(propertyName, MSGID)) {
+            std::string id = msg->getId();
+            LogDebug("msgId=" << id);
+            LogDebug("msg->getMessageStatus()=" << msg->getMessageStatus());
+            if((id.size() == 0) && (msg->getMessageStatus() == MESSAGE_STATUS_CREATED)) {
+                id = "";
+            }
+            return JSUtil::toJSValueRef(context, id);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, LOADED)) {
+            if (msg->getMessageType() == EMAIL) {
+                IEmailPtr email = MessageFactory::convertToEmail(msg);
+                return JSUtil::toJSValueRef(context, email->isBodyDownloaded() > 0 ? true : false);
+            }
+            else {
+               LogDebug("msgId=" << msg->getId());
+               LogDebug("msg->getMessageStatus()=" << msg->getMessageStatus());
+                if ((msg->getId().size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED) {
+                    return JSUtil::toJSValueRef(context, false);
+                }
+                return JSUtil::toJSValueRef(context, true);
+            }
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, PLAINBODY)) {
+           std::string body = msg->getBody();
+           LogDebug("getPlainBody plainBody" << body );
+           return JSUtil::toJSValueRef(context, body);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, HTMLBODY)) {
+           LogDebug("message Type : " << msg->getMessageType() );
+           std::string emailHtmlBody = "";
+           if (msg->getMessageType() == EMAIL) {
+               IEmailPtr email = MessageFactory::convertToEmail(msg);
+               emailHtmlBody = email->getHtmlBody();
+               LogDebug("Html Body : " << emailHtmlBody );
+           }
+           return JSUtil::toJSValueRef(context, emailHtmlBody);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, INLINEATT)) {
+            switch(msg->getMessageType()) {
+                case EMAIL:
+                {
+                    std::vector<IAttachmentPtr> inlineAttachments;
+                    std::vector<IAttachmentPtr>::iterator it;
+                    int count = 0;
+
+                    AttachmentsPtr emailAttachments =
+                    DPL::StaticPointerCast<Attachments>(MessageFactory::convertToEmail(msg));
+                    inlineAttachments = emailAttachments->getInlineAttachments();
+                    count = inlineAttachments.size();
+
+                    LogDebug( "attachments.size(): " << count);
+
+                    JSObjectRef jsMessageAttachmentObject[count]; //make
+                    for(int i = 0; i < count; i++) {
+                        LogDebug("Attachment ID: " << inlineAttachments[i]->getAttachmentID());
+                        jsMessageAttachmentObject[i] = JSMessageAttachment::createJS(context, inlineAttachments[i]);
+                    }
+                    JSObjectRef result = JSObjectMakeArray(context, count, jsMessageAttachmentObject, NULL);
+                    return result;
+                }
+                case SMS:
+                case MMS:
+                {
+                    JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
+                    if(NULL == arrayValue){
+                        LogError("Could not create JS array object");
+                        return JSValueMakeUndefined(context);
+                    }
+                    return arrayValue;
+                }
+
+                default:
+                   throw DeviceAPI::Common::UnknownException("Not supported message type.");
+            }
+        }
+        else {
+            LogDebug("Not supported property.");
+        }
+    }
+    catch (const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSValueMakeUndefined(context);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& err) {
+        LogError(err.GetMessage().c_str());
+        return JSValueMakeUndefined(context);
+    }
 
-JSValueRef JSMessageBody::getAttachments(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
-{
-    LogInfo("enter");
-    Try
-    {
-
-               ConverterMessageFactory::ConverterType converter =
-               ConverterMessageFactory::getConverter(context);
-               IMessagePtr msg = getMessage(context, object);
-               MessageType msgType = msg->getMessageType();
-               int count = 0;
-
-               LogInfo("msgType=" << msgType);
-
-               switch (msgType) {
-                       case EMAIL:
-                       {
-
-                               std::vector<IAttachmentPtr> inlineAttachments;
-                               std::vector<IAttachmentPtr>::iterator it;
-
-                               AttachmentsPtr emailAttachments =
-                               DPL::StaticPointerCast<Attachments>(MessageFactory::convertToEmail(msg));
-                               inlineAttachments = emailAttachments->getInlineAttachments();
-
-                               count = inlineAttachments.size();
-
-                               LogDebug( "attachments.size() : " << count);
-
-                               JSObjectRef jsMessageAttachmentObject[count];   //make
-
-                               for (unsigned int index = 0 ; index < count; index++ )
-                               {
-                                       LogDebug( "Attachment ID : " << inlineAttachments[index]->getAttachmentID());
-                                       jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(context, inlineAttachments[index] );
-                               }
-                               JSObjectRef result = JSObjectMakeArray(context, count, jsMessageAttachmentObject, NULL);
-
-                               return result;
-
-                       }
-                       case SMS:
-                       case MMS:
-                       {
-                               JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
-                               if (NULL == arrayValue)
-                               {
-                                       LogError("Could not create js array object");
-                                       return JSValueMakeUndefined(context);
-                               }
-                               return arrayValue;
-                       }
-
-                       default:
-                               LogError("not supported message type");
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
+    return NULL;
 }
 
-bool JSMessageBody::setAttachments(JSContextRef context,
+bool JSMessageBody::setProperty(JSContextRef context,
         JSObjectRef object,
         JSStringRef propertyName,
         JSValueRef value,
         JSValueRef* exception)
 {
-    LogInfo("enter");
-
-       Try
-    {
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-               
-               std::vector<IAttachmentPtr> inlineAttachments;
-               if (JSIsArrayValue(context, value)) {
-                       JSObjectRef valueObj = converter->toJSObjectRef(value);
-                       unsigned int len = JSGetArrayLength(context, valueObj);
-                       LogDebug("Array Length = " << len);
-                       for (unsigned int i = 0; i < len; ++i) {
-
-                               JSValueRef att = JSGetArrayElement(context, valueObj, i);
-                               if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
-                                   LogWarning("Invalid array element. Skipping.");
-                                   continue;
-                               }
-                               IAttachmentPtr attachment = converter->toIAttachment(att);
-
-                               if(attachment->getIsValidAttachment() == false)
-                               {
-                                       LogDebug("invalid attachment : " << i);
-                                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-                               }
-
-                               LogDebug("Adding attachment , shotname: " << attachment->getShortName());
-                               inlineAttachments.push_back(attachment);
-                       }
-               }
-               else
-               {
-                       IAttachmentPtr attachment = converter->toIAttachment(value);
-                       LogDebug("Adding attachment , shotname: " << attachment->getShortName());
-                       if(attachment->getIsValidAttachment() == false)
-                       {
-                               LogDebug("invalid attachment");
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-                       }
-                       inlineAttachments.push_back(attachment);
-               }
-
-               LogDebug("inlineAttachments Size =" << inlineAttachments.size());
-               if ( inlineAttachments.size() > 0)
-               {
-                       IMessagePtr msg = converter->toIMessage(object);
-                       if (msg)
-                       {
-                               MessageType msgType = msg->getMessageType();
-                               switch (msgType) {
-                                       case EMAIL:
-                                       {
-                                               IEmailPtr email = MessageFactory::convertToEmail(msg);
-                                               email->setInlineAttachments(inlineAttachments);
-                                               break;
-                                       }
-                                       default:
-                                               LogError("not supported message type");
-//                                             Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-                                       return true;
-                               }
-                               return true;
-                       }
-                       else
-                       {
-                               LogError("Message converter failed...");
-                               Throw(WrtDeviceApis::Commons::NullPointerException);
-                       }
-               }
+    LogDebug("Entered");
+
+    try {
+        if (JSStringIsEqualToUTF8CString(propertyName, MSGID)) {
+            return true;
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, LOADED)) {
+            return true;
+        }
+        else if(JSStringIsEqualToUTF8CString(propertyName, PLAINBODY)) {
+            IMessagePtr msg = getMessage(context, object);
+            std::string body = JSUtil::JSValueToString(context, value);
+            msg->setBody(body);
+            LogDebug("setPlainBody plainBody" << body );
+            return true;
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, HTMLBODY)) {
+            IMessagePtr msg = getMessage(context, object);
+
+            if (msg->getMessageType() == EMAIL)
+            {
+                IEmailPtr email = MessageFactory::convertToEmail(msg);
+                std::string body = JSUtil::JSValueToString(context, value);
+                LogDebug("input String : " << body);
+                email->setHtmlBody(body);
+                return true;
+            }
+            else {
+                throw DeviceAPI::Common::NotSupportedException("HTML body is for Email only.");
+            }
+            return true;
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, INLINEATT)) {
+            ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+            std::vector<IAttachmentPtr> inlineAttachments;
+            if (JSIsArrayValue(context, value)) {
+                JSObjectRef valueObj = converter->toJSObjectRef(value);
+                unsigned int len = JSGetArrayLength(context, valueObj);
+                LogDebug("Array Length = " << len);
+                for (unsigned int i = 0; i < len; ++i) {
+
+                    JSValueRef att = JSGetArrayElement(context, valueObj, i);
+                    if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
+                        LogWarning("Invalid array element. Skipping.");
+                        continue;
+                    }
+                    IAttachmentPtr attachment = converter->toIAttachment(att);
+
+                    if (attachment->getIsValidAttachment() == false) {
+                        std::string logMsg = "Invalid attachment : " + i;
+                        throw DeviceAPI::Common::InvalidValuesException(logMsg.c_str());
+                    }
+
+                    LogDebug("Adding attachment , shortname: " << attachment->getShortName());
+                    inlineAttachments.push_back(attachment);
+                }
+            }
+            else {
+                IAttachmentPtr attachment = converter->toIAttachment(value);
+                LogDebug("Adding attachment , shortname: " << attachment->getShortName());
+                if (attachment->getIsValidAttachment() == false) {
+                    throw DeviceAPI::Common::InvalidValuesException("Invalid attachment.");
+                }
+                inlineAttachments.push_back(attachment);
+            }
+
+            LogDebug("inlineAttachments Size =" << inlineAttachments.size());
+            if ( inlineAttachments.size() > 0) {
+                IMessagePtr msg = converter->toIMessage(object);
+                if (msg) {
+                    MessageType msgType = msg->getMessageType();
+                    switch (msgType) {
+                        case EMAIL:
+                        {
+                            IEmailPtr email = MessageFactory::convertToEmail(msg);
+                            email->setInlineAttachments(inlineAttachments);
+                            break;
+                        }
+                        default:
+                            throw DeviceAPI::Common::NotSupportedException("Not supported message type.");
+                    }
+                }
+                else {
+                    throw DeviceAPI::Common::UnknownException("Message converter failed.");
+                }
+            }
+            return true;
+        }
+        else {
+            LogDebug("Not supported property.");
+        }
+    }
+    catch (const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return true;
+    }
+    catch (const WrtDeviceApis::Commons::Exception& err) {
+        LogError(err.GetMessage().c_str());
+        return true;
     }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               LogError("Error on conversion");
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-               LogError("Invalid argument exception");
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               LogError("Error on pointer, null value");
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException) {
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
-       }
-
-       return false;
-}
 
-IMessagePtr JSMessageBody::getMessage(JSContextRef context,
-        JSValueRef value)
-{
-    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-    return getMessage(context, converter.toJSObjectRef(value));
+    return false;
 }
 
-IMessagePtr JSMessageBody::getMessage(JSContextRef context,
-        JSObjectRef object)
+void JSMessageBody::getPropertyNames(JSContextRef context,
+        JSObjectRef object,
+        JSPropertyNameAccumulatorRef propertyNames)
 {
-    return getPrivate(object)->getObject();
-}
+    LogDebug("Entered");
+    JSStringRef propertyName = NULL;
 
-JSMessageBodyPrivate* JSMessageBody::getPrivate(JSObjectRef thisObject)
-{
-       JSMessageBodyPrivate* thisPrivate = static_cast<JSMessageBodyPrivate*>(JSObjectGetPrivate(thisObject));
-    if (!thisPrivate) {
-        LogError("no private");
-        Throw(WrtDeviceApis::Commons::NullPointerException);
-    }
-    return thisPrivate;
+    propertyName = JSStringCreateWithUTF8CString(MSGID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(LOADED);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(PLAINBODY);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(HTMLBODY);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(INLINEATT);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
 }
 
 }
 }
 
-
index 1684d05..b206a00 100755 (executable)
 namespace DeviceAPI {
 namespace Messaging {
 
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<IMessagePtr>::Type JSMessageBodyPrivate;      //IMessagePtr
-       
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<IMessagePtr>::Type JSMessageBodyPrivate;    //IMessagePtr
+
 
 class JSMessageBody
 {
-       static JSClassRef m_jsClassRef;
-       
-public:        
-       static const JSClassDefinition* getClassInfo();
-       static JSClassRef getClassRef();
+    static JSClassRef m_jsClassRef;
+
+public:
+    static const JSClassDefinition* getClassInfo();
+    static JSClassRef getClassRef();
 
-       static JSObjectRef createJS( JSContextRef context, const IMessagePtr &msg);
+    static JSObjectRef createJS( JSContextRef context, const IMessagePtr &msg);
 
 private:
-       
+
     /**
      * The callback invoked when an object is first created.
      */
@@ -52,98 +52,73 @@ private:
      */
     static void finalize(JSObjectRef object);
 
-    static bool hasProperty(JSContextRef context,
-            JSObjectRef object,
-            JSStringRef propertyName);
-
-    static bool setProperty(JSContextRef context,
-            JSObjectRef object,
-            JSStringRef propertyName,
-            JSValueRef value,
-            JSValueRef* exception);
-
-    static JSValueRef getMessageID(JSContextRef context,
+    /**
+    * The callback invoked when getting a property's value.
+    */
+    static JSValueRef getProperty(JSContextRef context,
             JSObjectRef object,
             JSStringRef propertyName,
             JSValueRef* exception);
 
-    static JSValueRef getLoadedStatus(JSContextRef context,
+    /**
+    * The callback invoked when setting a property's value.
+    */
+    static bool setProperty(JSContextRef context,
             JSObjectRef object,
             JSStringRef propertyName,
+            JSValueRef value,
             JSValueRef* exception);
 
-    static JSValueRef getPlainBody(JSContextRef context,
+    /**
+     * The callback invoked when collecting the names of an object's properties.
+     */
+    static void getPropertyNames(JSContextRef context,
             JSObjectRef object,
-            JSStringRef propertyName,
-            JSValueRef* exception);
-
-    static bool setPlainBody(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef value,
-        JSValueRef* exception);
-
-    static JSValueRef getHtmlBody(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception);
-
-    static bool setHtmlBody(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef value,
-        JSValueRef* exception);
-
-       static JSValueRef getAttachments(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception);
-
-       static bool setAttachments(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef value,
-               JSValueRef* exception);
-
+            JSPropertyNameAccumulatorRef propertyNames);
 
     /*
      * returns private object or throws WrtDeviceApis::Commons::NullPointerException
      */
     static JSMessageBodyPrivate* getPrivate(JSObjectRef value);
 
-       /*
-        * extracts Api Message representation
-        * throws WrtDeviceApis::Commons::NullPointerException if there's no private object
-        * throws WrtDeviceApis::Commons::ConversionException if it's not possible to convert to JSObjectRef
-        */
-       static IMessagePtr getMessage(JSContextRef context,
-                       JSValueRef value);
-
-       /*
-        * extracts Api Message representation
-        * throws WrtDeviceApis::Commons::NullPointerException if there's no private object
-        */
-       static IMessagePtr getMessage(JSContextRef context,
-                       JSObjectRef object);
-
-       /**
-       * This structure describes a statically declared function property.
-       */
-       static JSStaticFunction m_function[];
-
-       /**
-       * This structure contains properties and callbacks that define a type of object.
-       */
-       static JSClassDefinition m_classInfo;
-
-       /**
-       * This member variable contains the initialization values for the static properties of this class.
-       * The values are given according to the data structure JSPropertySpec
-       */
-       static JSStaticValue m_property[];
-  
+    /*
+     * extracts Api Message representation
+     * throws WrtDeviceApis::Commons::NullPointerException if there's no private object
+     * throws WrtDeviceApis::Commons::ConversionException if it's not possible to convert to JSObjectRef
+     */
+    static IMessagePtr getMessage(JSContextRef context,
+            JSValueRef value);
+
+    /*
+     * extracts Api Message representation
+     * throws WrtDeviceApis::Commons::NullPointerException if there's no private object
+     */
+    static IMessagePtr getMessage(JSContextRef context,
+            JSObjectRef object);
+
+    /**
+    * This structure describes a statically declared function property.
+    */
+    static JSStaticFunction m_function[];
+
+    /**
+    * This structure contains properties and callbacks that define a type of object.
+    */
+    static JSClassDefinition m_classInfo;
+
+    /**
+    * This member variable contains the initialization values for the static properties of this class.
+    * The values are given according to the data structure JSPropertySpec
+    */
+    static JSStaticValue m_property[];
+
+    static const char* MSGID;
+    static const char* LOADED;
+    static const char* PLAINBODY;
+    static const char* HTMLBODY;
+    static const char* INLINEATT;
 };
-       
+
 }
 }
 
index 8c8c69a..980c6da 100644 (file)
@@ -15,7 +15,7 @@
 // limitations under the License.
 //
 
+
 
 
 #include <CommonsJavaScript/Converter.h>
@@ -27,6 +27,8 @@
 #include "IMessageFolder.h"
 #include "IMessagingTypes.h"
 
+#include <JSWebAPIError.h>
+
 
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
@@ -52,15 +54,15 @@ JSClassDefinition JSMessageFolder::m_classInfo =
        kJSClassAttributeNone,
        "MessageFolder",
        NULL,
-       m_properties,
+       NULL, //m_properties,
        NULL,
        initialize,
        finalize,
        NULL, //hasProperty,
-       NULL, //getProperty,
-       NULL, //setProperty,
+       getProperty,
+       setProperty,
        NULL, //deleteProperty,
-       NULL, //getPropertyNames,
+       getPropertyNames,
        NULL,
        NULL,
        hasInstance,
@@ -88,10 +90,11 @@ const std::string JSMessageFolder::FOLDER_NOTSTANDARD        = "";
 
 
 
+#if 0
 JSStaticValue JSMessageFolder::m_properties[] = {
        {"id", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },
-       {"parentId", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },        
-       {"serviceId", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },       
+       {"parentId", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"serviceId", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },
        {"contentType", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },
        {"name", JSMessageFolder::getProperty, JSMessageFolder::setProperty, kJSPropertyAttributeNone },
        {"path", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },
@@ -99,6 +102,7 @@ JSStaticValue JSMessageFolder::m_properties[] = {
        {"synchronizable", JSMessageFolder::getProperty, JSMessageFolder::setProperty, kJSPropertyAttributeNone },
        {0, 0, 0, 0}
 };
+#endif
 
 const JSClassRef JSMessageFolder::getClassRef() {
        if (!m_jsClassRef) {
@@ -113,7 +117,7 @@ const JSClassDefinition* JSMessageFolder::getClassInfo() {
 
 JSClassRef JSMessageFolder::m_jsClassRef = JSClassCreate(JSMessageFolder::getClassInfo());
 
-void JSMessageFolder::initialize(JSContextRef context, JSObjectRef object) 
+void JSMessageFolder::initialize(JSContextRef context, JSObjectRef object)
 {
        LogDebug("JSMessageFolder::initialize ");
        JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));
@@ -124,12 +128,10 @@ void JSMessageFolder::initialize(JSContextRef context, JSObjectRef object)
        }
        else
        {
-               LogDebug("JSMessageFolder::already exist ");            
+               LogDebug("JSMessageFolder::already exist ");
        }
 }
 
-
-
 JSObjectRef JSMessageFolder::createJSObject(JSContextRef context, IMessageFolderPtr object)
 {
        JSMessageFolderPriv* priv = new JSMessageFolderPriv(context, object);
@@ -142,7 +144,7 @@ void JSMessageFolder::finalize(JSObjectRef object) {
 
        LogDebug("JSMessageFolder::Finalrize");
 
-       if (priv != NULL) 
+       if (priv != NULL)
        {
                JSObjectSetPrivate(object, NULL);
                delete priv;
@@ -159,24 +161,23 @@ JSValueRef JSMessageFolder::getProperty(JSContextRef context,
                                                                                JSStringRef propertyName,
                                                                                JSValueRef* exception)
 {
-       LogDebug("<<<");        
+       LogDebug("<<<");
 
        ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-       JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));      
-       try 
+       JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));
+       try
        {
                if (priv == NULL)
                {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+                       throw DeviceAPI::Common::UnknownException("Object is null");
                }
-               
+
                IMessageFolderPtr MessageFolder(priv->getObject());
-               if(JSStringIsEqualToUTF8CString(propertyName, FOLDERID)) 
+               if(JSStringIsEqualToUTF8CString(propertyName, FOLDERID))
                {
                        return converter->toJSValueRef(converter->convertIntToString(MessageFolder->getId()));
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, PARENTID)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, PARENTID))
                {
                        int tmpInt;
                        tmpInt = MessageFolder->getParentId();
@@ -186,27 +187,27 @@ JSValueRef JSMessageFolder::getProperty(JSContextRef context,
                        }
                        return converter->toJSValueRef(converter->convertIntToString(tmpInt));
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, ACCOUNTID)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, ACCOUNTID))
                {
                        return converter->toJSValueRef(converter->convertIntToString(MessageFolder->getAccountId()));
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, CONTENTTYPE)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, CONTENTTYPE))
                {
                        return converter->toJSValueRef(convertMessageType(MessageFolder->getContentType()));
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, NAME)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, NAME))
                {
                        return converter->toJSValueRef(MessageFolder->getName());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, PATH)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, PATH))
                {
                        return converter->toJSValueRef(MessageFolder->getPath());
                }
-               else if(JSStringIsEqualToUTF8CString(propertyName, TYPE)) 
+               else if(JSStringIsEqualToUTF8CString(propertyName, TYPE))
                {
                        return converter->toJSValueRef(convertFolderType(MessageFolder->getType()));
-               }       
-               else if(JSStringIsEqualToUTF8CString(propertyName, SYNCHRONIZABLE)) 
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, SYNCHRONIZABLE))
                {
                        return converter->toJSValueRef(MessageFolder->getSynchronizable());
                }
@@ -214,11 +215,11 @@ JSValueRef JSMessageFolder::getProperty(JSContextRef context,
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) {
                LogError("Exception: " << ex.GetMessage());
-       }       
-       return JSValueMakeNull(context);
+               return JSValueMakeUndefined(context);
+       }
+       return NULL;
 }
 
-
 bool JSMessageFolder::setProperty(JSContextRef context,
         JSObjectRef object,
         JSStringRef propertyName,
@@ -227,35 +228,85 @@ bool JSMessageFolder::setProperty(JSContextRef context,
 {
     LogDebug("entered");
        WrtDeviceApis::CommonsJavaScript::Converter converter(context);
-       
-    Try
+
+    try
     {
-               JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));      
+               JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));
         if (!priv) {
-            Throw(WrtDeviceApis::Commons::NullPointerException);
+               throw DeviceAPI::Common::UnknownException("Object is null");
         }
                IMessageFolderPtr MessageFolder(priv->getObject());
 
-        if (JSStringIsEqualToUTF8CString(propertyName, NAME)) {
+           if (JSStringIsEqualToUTF8CString(propertyName, FOLDERID)) {
+               return true;
+           } else if (JSStringIsEqualToUTF8CString(propertyName, PARENTID)) {
+               return true;
+           } else if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNTID)) {
+               return true;
+           } else if (JSStringIsEqualToUTF8CString(propertyName, CONTENTTYPE)) {
+               return true;
+           } else if (JSStringIsEqualToUTF8CString(propertyName, NAME)) {
             std::string name = converter.toString(value);
             MessageFolder->setName(name);
             return true;
+           } else if (JSStringIsEqualToUTF8CString(propertyName, PATH)) {
+               return true;
+           } else if (JSStringIsEqualToUTF8CString(propertyName, TYPE)) {
+               return true;
         } else if (JSStringIsEqualToUTF8CString(propertyName, SYNCHRONIZABLE)) {
             bool synchronizable = converter.toBool(value);
             MessageFolder->setSynchronizable(synchronizable);
             return true;
+       }
     }
-    }
-    Catch(WrtDeviceApis::Commons::Exception)
+    catch(const WrtDeviceApis::Commons::Exception& ex)
     {
-        LogWarning("trying to set incorrect value");
-          return JSTizenExceptionFactory::postException(context, exception, 
-                        JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+               LogError("Exception: " << ex.GetMessage());
+               return true;
     }
-
     return false;
 }
 
+void JSMessageFolder::getPropertyNames(JSContextRef context,
+        JSObjectRef object,
+        JSPropertyNameAccumulatorRef propertyNames)
+{
+    LogDebug("Entered");
+    JSStringRef propertyName = NULL;
+
+    propertyName = JSStringCreateWithUTF8CString(FOLDERID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(PARENTID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(ACCOUNTID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(CONTENTTYPE);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(NAME);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(PATH);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(TYPE);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(SYNCHRONIZABLE);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+}
+
 bool JSMessageFolder::isObjectOfClass(JSContextRef context, JSValueRef value)
 {
        return JSValueIsObjectOfClass(context, value, getClassRef());
@@ -264,15 +315,15 @@ bool JSMessageFolder::isObjectOfClass(JSContextRef context, JSValueRef value)
 IMessageFolderPtr JSMessageFolder::getMessageFolder(JSContextRef context, JSValueRef value)
 {
        JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) 
+       if (!object)
        {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               throw DeviceAPI::Common::TypeMismatchException("Failed to get object");
        }
        JSMessageFolderPriv *priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));
-       
-       if (!priv) 
+
+       if (!priv)
        {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
+               throw DeviceAPI::Common::TypeMismatchException("Object is null");
        }
        return priv->getObject();
 }
@@ -280,7 +331,7 @@ IMessageFolderPtr JSMessageFolder::getMessageFolder(JSContextRef context, JSValu
 std::string JSMessageFolder::convertMessageType(int msgType){
 
        if(msgType == SMS){
-               return JSMessageFolder::TYPE_SMS;               
+               return JSMessageFolder::TYPE_SMS;
        }else if(msgType == MMS){
                return JSMessageFolder::TYPE_MMS;
        }else if(msgType == EMAIL){
@@ -293,7 +344,7 @@ std::string JSMessageFolder::convertMessageType(int msgType){
 std::string JSMessageFolder::convertFolderType(int msgType){
 
        if(msgType == INBOX){
-               return JSMessageFolder::FOLDER_INBOX;           
+               return JSMessageFolder::FOLDER_INBOX;
        }else if(msgType == OUTBOX){
                return JSMessageFolder::FOLDER_OUTBOX;
        }else if(msgType == DRAFTBOX){
@@ -308,7 +359,7 @@ std::string JSMessageFolder::convertFolderType(int msgType){
  }
 
 
-} 
+}
 }// WrtPlugins
 
 
index 3f00d8d..d10ec7d 100755 (executable)
@@ -16,7 +16,7 @@
 //
 
 
+
 
 #ifndef WRTPLUGINS_TIZEN_JS_MESSAGEFOLDER_H_
 #define WRTPLUGINS_TIZEN_JS_MESSAGEFOLDER_H_
@@ -66,15 +66,15 @@ private:
         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);
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
 
        static bool setProperty(JSContextRef context,
                        JSObjectRef object,
@@ -82,6 +82,9 @@ private:
                        JSValueRef value,
                        JSValueRef* exception);
 
+       static void getPropertyNames(JSContextRef context,
+                   JSObjectRef object,
+                   JSPropertyNameAccumulatorRef propertyNames);
        /**
         * This structure contains properties and callbacks that define a type of object.
         */
@@ -90,11 +93,11 @@ private:
        /**
         * This structure describes a statically declared function property.
         */
-       static JSStaticValue m_properties[];
+       //static JSStaticValue m_properties[];
        static JSClassRef m_jsClassRef;
 
 
-       
+
        static const char* FOLDERID;
        static const char* PARENTID;
        static const char* ACCOUNTID;
@@ -112,12 +115,12 @@ private:
        static const std::string FOLDER_OUTBOX;
        static const std::string FOLDER_DRAFTBOX;
        static const std::string FOLDER_SENTBOX;
-       static const std::string FOLDER_NOTSTANDARD;    
+       static const std::string FOLDER_NOTSTANDARD;
 
 
 };
 
-} 
+}
 } //WrtPlugins
 
 #endif //WRTPLUGINS_TIZEN_JS_MESSAGING_SERVICE_MANAGER_H_
index ab27a08..bdb128b 100644 (file)
@@ -21,7 +21,7 @@
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>                                   
+#include <CommonsJavaScript/Utils.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
 #include <CommonsJavaScript/JSPendingOperation.h>
 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
 
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
 #include "MessagingErrorMsg.h"
 #include "ConverterMessage.h"
 #include "MessagingListener.h"
 #include "JSMessagingStorage.h"
 #include "JSMessage.h"
-#include "EventSendMessagePrivateData.h"       //for send message
+#include "EventSendMessagePrivateData.h" //for send message
 #include "EventMessagingServicePrivateData.h"
 #include "MessageAsyncCallbackManager.h"
 #include "plugin_config.h"
@@ -53,300 +57,351 @@ using namespace DeviceAPI::Common;
 namespace DeviceAPI {
 namespace Messaging {
 
-       JSClassRef JSMessagingService::m_jsClassRef = NULL;
-       JSClassDefinition JSMessagingService::m_classInfo = {
-               0,
-               kJSClassAttributeNone,
-               "MessageService",
-               NULL,
-               m_property,
-               m_function,
-               initialize,
-               finalize,
-               NULL, //hasProperty,
-               NULL, //getProperty,
-               NULL, //setProperty,
-               NULL, //deleteProperty,Geolocation
-               NULL, //getPropertyNames,
-               NULL,
-               NULL,
-               hasInstance,
-               NULL
-       };
-
-       JSStaticValue JSMessagingService::m_property[] =
-       {
-           {"id",                      getProperty, NULL, kJSPropertyAttributeReadOnly},
-           {"type",                            getProperty, NULL, kJSPropertyAttributeReadOnly},
-           {"name",                            getProperty, NULL, kJSPropertyAttributeReadOnly},
-           {"messageStorage",                          getProperty, NULL, kJSPropertyAttributeReadOnly},
-           { 0, 0, 0, 0 }
-       };
-
-       JSStaticFunction JSMessagingService::m_function[] = {
-                       //{ "createMessage",      JSMessagingService::createMessage,       kJSPropertyAttributeNone },
-                       { "sendMessage",          JSMessagingService::sendMessage,         kJSPropertyAttributeNone },
-                       { "loadMessageBody",      JSMessagingService::loadMessageBody,     kJSPropertyAttributeNone },
-                       { "loadMessageAttachment",        JSMessagingService::loadMessageAttachment,       kJSPropertyAttributeNone },
-                       { "sync",         JSMessagingService::sync,        kJSPropertyAttributeNone },
-                       { "syncFolder",   JSMessagingService::syncFolder,          kJSPropertyAttributeNone },
-                       //{ "cancelOperation",   JSMessagingService::cancelOperation,      kJSPropertyAttributeNone },
-                       { "stopSync",   JSMessagingService::stopSync,      kJSPropertyAttributeNone },
-                       { 0, 0, 0 }
-       };
-
-       const JSClassRef JSMessagingService::getClassRef() {
-               if (!m_jsClassRef) {
-                       m_jsClassRef = JSClassCreate(&m_classInfo);
-               }
-               return m_jsClassRef;
-       }
-
-       void JSMessagingService::initialize(JSContextRef context, JSObjectRef object) {
-               LogDebug("creation messaging Service instance");
-       }
-
-       void JSMessagingService::finalize(JSObjectRef object) {
-               LogDebug("finalize messaging instance");
-               //JSMessagingServicePriv *priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object));
-               JSMessagingServicePriv *priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object));
-               delete priv;
-       }
-
-       bool JSMessagingService::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
-               return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-       }
-
-       JSObjectRef JSMessagingService::createJSObject(JSContextRef context, const IMessagingServicePtr &messagingService)
-       {
-               JSMessagingServicePriv* priv = new JSMessagingServicePriv( context, messagingService);  //make private class.
-               return JSObjectMake(context, getClassRef(), priv);
-       }
-
-       JSValueRef JSMessagingService::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-       {
-               LogDebug("<<< ");
-               JSValueRef retVal = NULL;
-
-               JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object));        //get private object
-            if (priv)
-               {
-                       IMessagingServicePtr imessagingService = priv->getObject();
-                       Try{
-                               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-
-                               if (JSStringIsEqualToUTF8CString(propertyName, "type")) {
-                                       LogDebug("type" << ":" << imessagingService->getType());
-                                       retVal = converter->toJSValueRef(converter->toMessageType(imessagingService->getType()));                                       
-                               } else if (JSStringIsEqualToUTF8CString(propertyName, "name")) {
-                                       LogDebug("name" << ":" <<  imessagingService->getName());
-                                       retVal = converter->toJSValueRef(imessagingService->getName());
-                               } else if (JSStringIsEqualToUTF8CString(propertyName, "id")) {
-                                       LogDebug("accountId" << ":" <<  imessagingService->getAccountID());
-                                       
-                                       std::stringstream stream;
-                                       stream << imessagingService->getAccountID();
-                                       if (stream.fail()) {        
-                                               ThrowMsg(WrtDeviceApis::Commons::UnknownException,"Couldn't convert e-mail account id");
-                                       }
-                                       
-                                       retVal = converter->toJSValueRef(stream.str());
-                               } else if (JSStringIsEqualToUTF8CString(propertyName, "messageStorage")) {
-                                       JSContextRef l_globalContext = converter->toJSGlobalContext(object);                                    
-                                       MessagingStoragePrivObjPtr storagePriv(new MessagingStoragePrivObj());
-//                                     MessagingListenerPtr listener_priv = MessagingListener::getInstance(l_globalContext) ;
-                                       storagePriv->m_index = imessagingService->getAccountID();
-                                       storagePriv->m_type = imessagingService->getType();
-                                       LogDebug("type" << ":" << imessagingService->getType());
-                                       LogDebug("accountId" << ":" <<  imessagingService->getAccountID());
-                                       
-                                       MessagingStoragePriv *priv = new MessagingStoragePriv(l_globalContext, storagePriv);
-                                       //MessagingStoragePrivObjPtr storagePriv = priv->getObject();
-
-//                                     retVal = JSUtils::makeObject(l_globalContext, JSMessagingStorage::getClassRef(), priv);
-                                       retVal = JSObjectMake(l_globalContext, JSMessagingStorage::getClassRef(), priv);
-
-                               } else{
-                                       retVal = JSValueMakeUndefined(context);
-                               }
-
-                       } Catch (WrtDeviceApis::Commons::Exception){
-                               LogError("Exception: " << _rethrown_exception.GetMessage());
-                               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);                    
-                       }
-
-                       LogDebug(">>>");
-                       return retVal;
-                       
-               }
-               else
-               {       
-                       LogDebug(" Private Object is NULL ");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
-               }
-               
-       }
-
-       JSValueRef JSMessagingService::createMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-               const JSValueRef arguments[], JSValueRef* exception) 
-       {
-
-               LogInfo("<<<");
-               LogDebug("arumentConunt:" << argumentCount);
-
-               JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
-               if (priv)
-               {
-                       AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                               MessagingExportedNames[MESSAGING_FUNCTION_API_CREATE_MESSAGE]);
-                       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-                               
-                       try {
-                               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                               JSContextRef l_globalContext = converter->toJSGlobalContext(thisObject);
-                               Validator check(context, exception);
-
-                               IMessagingServicePtr imessagingService = priv->getObject();                             //get MessagingService.
-                               JSValueRef objMsg = NULL;
-                               
-                               MessageType msgType = (MessageType)imessagingService->getType();
-                               LogInfo("msgType :" << msgType);
-       
-                               if (msgType == EMAIL)
-                               {
-                                       EmailAccountInfo account = imessagingService->getCurrentEmailAccount();
-                                       LogDebug("Account Address:" << &account);
-                                       objMsg = JSMessage::createJSObject(l_globalContext, account, msgType);          //make message JSValueRef.
-                               }
-                               else
-                               {
-                                       objMsg = JSMessage::createJSObject(l_globalContext, msgType);           //make message JSValueRef.
-                               }
-
-                               //set Properties
-                               if ( argumentCount == 1)
-                               {
-                                       IMessagePtr msg = converter->toIMessage(objMsg) ;
-
-                                       if (!msg)
-                                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,"platform exception");
-
-                                       LogDebug ("##### msg type is " << msg->getId());
-                                                                               
-                                       const ScopedJSStringRef subjectStr(JSStringCreateWithUTF8CString("subject"));
-                                       const ScopedJSStringRef toStr(JSStringCreateWithUTF8CString("to"));
-                                       const ScopedJSStringRef ccStr(JSStringCreateWithUTF8CString("cc"));
-                                       const ScopedJSStringRef bccStr(JSStringCreateWithUTF8CString("bcc"));
-                                       const ScopedJSStringRef plainBodyStr(JSStringCreateWithUTF8CString("plainBody"));
-                                       const ScopedJSStringRef htmlBodyStr(JSStringCreateWithUTF8CString("htmlBody"));
-                                       const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("isHighPriority"));
-
-                                       JSObjectRef arg = converter->toJSObjectRef(arguments[0]);
-                                       JSValueRef subjectData = JSObjectGetProperty(l_globalContext, arg, subjectStr.get(), NULL);
-                                       JSValueRef toData = JSObjectGetProperty(l_globalContext, arg, toStr.get(), NULL);
-                                       JSValueRef ccData = JSObjectGetProperty(l_globalContext, arg, ccStr.get(), NULL);
-                                       JSValueRef bccData = JSObjectGetProperty(l_globalContext, arg, bccStr.get(), NULL);
-                                       JSValueRef plainBodyData = JSObjectGetProperty(l_globalContext, arg, plainBodyStr.get(), NULL);
-                                       JSValueRef htmlBodyData = JSObjectGetProperty(l_globalContext, arg, htmlBodyStr.get(), NULL);
-                                       JSValueRef priorityData = JSObjectGetProperty(l_globalContext, arg, priorityStr.get(), NULL);   
-
-                                       //subject
-                                        if (!JSValueIsUndefined(l_globalContext, subjectData) ) 
-                                        {
-                                               LogDebug ( " Subject : " << converter->toString(subjectData) );                                         
-                                               std::string subject = converter->toString(subjectData);
-                                                switch (msgType) 
-                                                {
-                                               case MMS:
-                                               {
-                                                   IMmsPtr mms = MessageFactory::convertToMms(msg);
-                                                   mms->setSubject(subject);
-                                                   break;
-                                               }
-                                               case EMAIL:
-                                               {
-                                                   IEmailPtr email = MessageFactory::convertToEmail(msg);
-                                                   email->setSubject(subject);
-                                                   break;
-                                               }
-                                                 default:
-                                                 {
-                                                   LogError("message not supported");
-                                                   //Throw(WrtDeviceApis::Commons::UnsupportedException);
-                                                   //break;
-                                                 }
-                                               }
-                                        }
-                                       //to
-                                       if (!JSValueIsUndefined(l_globalContext, toData) )
-                                       {
-                                               Recipients to = converter->toRecipients(toData);
-                                               LogDebug("setting to field, size=" << to.getRecipientSize());
-                                               msg->setToRecipients(to);
-                                       }
-                                       //cc
-                                       if (msgType == EMAIL )
-                                       {
-                                               IEmailPtr email = MessageFactory::convertToEmail(msg);
-                                               if (!JSValueIsUndefined(l_globalContext, ccData))
-                                               {
-                                                       Recipients cc = converter->toRecipients(ccData);
-                                               email->setCcRecipients(cc);
-                                               }
-
-                                               if (!JSValueIsUndefined(l_globalContext, bccData))
-                                               {
-                                                       Recipients bcc = converter->toRecipients(bccData);
-                                               email->setBccRecipients(bcc);
-                                               }
-
-                                               if (!JSValueIsUndefined(l_globalContext, htmlBodyData))
-                                               {
-                                                       std::string body = converter->toString(htmlBodyData);
-                                                       LogDebug("html body : " << body);
-                                                       email->setHtmlBody(body);
-                                               }
-
-                                               if (!JSValueIsUndefined(l_globalContext, priorityData))
-                                               {
-                                                       email->setPriority(converter->toMessagePriority(priorityData));
-                                               }
-                                               
-                                       }
-
-                                       if (!JSValueIsUndefined(l_globalContext, plainBodyData) )
-                                       {
-                                               std::string body = converter->toString(plainBodyData);
-                                               LogDebug("plain body  : " << body);
-                                               msg->setBody(body);
-                                       }
-                       
-                               }
-                               return objMsg;
-                                                               
-                       }
-                       Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);    
-                       }
-                       Catch(WrtDeviceApis::Commons::ConversionException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);        
-                       }
-
-//                     LogInfo(">>>");
-//                     return JSValueMakeUndefined(context);
-               }
-               else
-               {
-                       LogDebug(" Private Object is NULL ");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
-               }
-
-       }
+namespace {
+    const char* MESSAGING_SERVICE_ID = "id";
+    const char* MESSAGING_SERVICE_TYPE = "type";
+    const char* MESSAGING_SERVICE_NAME = "name";
+    const char* MESSAGING_SERVICE_MESSAGESTORAGE = "messageStorage";
+}
+
+JSClassRef JSMessagingService::m_jsClassRef = NULL;
+
+JSClassDefinition JSMessagingService::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "MessageService",
+    NULL,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    JSMessagingService::getProperty, //getProperty,
+    JSMessagingService::setProperty, //setProperty,
+    NULL, //deleteProperty,
+    JSMessagingService::getPropertyNames, //getPropertyNames,
+    NULL,
+    NULL,
+    hasInstance,
+    NULL
+};
+
+JSStaticValue JSMessagingService::m_property[] =
+{
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSMessagingService::m_function[] = {
+    //{ "createMessage",      JSMessagingService::createMessage,       kJSPropertyAttributeNone },
+    { "sendMessage",      JSMessagingService::sendMessage,       kJSPropertyAttributeNone },
+    { "loadMessageBody",      JSMessagingService::loadMessageBody,       kJSPropertyAttributeNone },
+    { "loadMessageAttachment",      JSMessagingService::loadMessageAttachment,       kJSPropertyAttributeNone },
+    { "sync",      JSMessagingService::sync,       kJSPropertyAttributeNone },
+    { "syncFolder",      JSMessagingService::syncFolder,       kJSPropertyAttributeNone },
+    //{ "cancelOperation",   JSMessagingService::cancelOperation,       kJSPropertyAttributeNone },
+    { "stopSync",   JSMessagingService::stopSync,       kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+const JSClassRef JSMessagingService::getClassRef() {
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+void JSMessagingService::initialize(JSContextRef context, JSObjectRef object) {
+    LogDebug("creation messaging Service instance");
+}
+
+void JSMessagingService::finalize(JSObjectRef object) {
+    LogDebug("finalize messaging instance");
+    //JSMessagingServicePriv *priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object));
+    JSMessagingServicePriv *priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object));
+    delete priv;
+}
+
+bool JSMessagingService::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSObjectRef JSMessagingService::createJSObject(JSContextRef context, const IMessagingServicePtr &messagingService)
+{
+    JSMessagingServicePriv* priv = new JSMessagingServicePriv( context, messagingService);    //make private class.
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSMessagingService::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object)); //get private object
+    if (!priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    IMessagingServicePtr imessagingService = priv->getObject();
+    try {
+        ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_TYPE)) {
+            LogDebug("type" << ": " << imessagingService->getType());
+            return JSUtil::toJSValueRef(context, converter->toMessageType(imessagingService->getType()));
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_NAME)) {
+            LogDebug("name : " <<  imessagingService->getName());
+            return JSUtil::toJSValueRef(context, imessagingService->getName());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_ID)) {
+            LogDebug("accountId : " <<  imessagingService->getAccountID());
+
+            std::stringstream stream;
+            stream << imessagingService->getAccountID();
+            if (stream.fail()) {
+                throw DeviceAPI::Common::UnknownException("Couldn't convert e-mail account id");
+            }
+
+            return JSUtil::toJSValueRef(context, stream.str());
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_MESSAGESTORAGE)) {
+            JSContextRef l_globalContext = converter->toJSGlobalContext(object);
+            MessagingStoragePrivObjPtr storagePrivObj(new MessagingStoragePrivObj());
+
+            storagePrivObj->m_index = imessagingService->getAccountID();
+            LogDebug("accountId" << ": " <<  storagePrivObj->m_index);
+
+            storagePrivObj->m_type = imessagingService->getType();
+            LogDebug("type" << ": " << storagePrivObj->m_type);
+
+            MessagingStoragePriv *privStorage = new MessagingStoragePriv(l_globalContext, storagePrivObj);
+
+            return JSObjectMake(l_globalContext, JSMessagingStorage::getClassRef(), privStorage);
+        }
+    }
+    catch (const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSValueMakeUndefined(context);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& err) {
+        LogError(err.GetMessage().c_str());
+        return JSValueMakeUndefined(context);
+    }
+
+    return NULL;
+}
+
+bool JSMessagingService::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_ID)) {
+        return true;
+    }
+    else if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_TYPE)) {
+        return true;
+    }
+    else if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_NAME)) {
+        return true;
+    }
+    else if (JSStringIsEqualToUTF8CString(propertyName, MESSAGING_SERVICE_MESSAGESTORAGE)) {
+        return true;
+    }
+
+    return false;
+}
+
+void JSMessagingService::getPropertyNames(JSContextRef context,
+        JSObjectRef object,
+        JSPropertyNameAccumulatorRef propertyNames)
+{
+    LogDebug("Entered");
+    JSStringRef propertyName = NULL;
+
+    propertyName = JSStringCreateWithUTF8CString(MESSAGING_SERVICE_ID);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(MESSAGING_SERVICE_TYPE);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(MESSAGING_SERVICE_NAME);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+
+    propertyName = JSStringCreateWithUTF8CString(MESSAGING_SERVICE_MESSAGESTORAGE);
+    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+    JSStringRelease(propertyName);
+}
+
+#if 0
+JSValueRef JSMessagingService::createMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+    const JSValueRef arguments[], JSValueRef* exception)
+{
+
+    LogInfo("<<<");
+    LogDebug("arumentConunt:" << argumentCount);
+
+    JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
+    if (priv)
+    {
+        AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+            MessagingExportedNames[MESSAGING_FUNCTION_API_CREATE_MESSAGE]);
+        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+        try {
+            ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+            JSContextRef l_globalContext = converter->toJSGlobalContext(thisObject);
+            Validator check(context, exception);
+
+            IMessagingServicePtr imessagingService = priv->getObject();                //get MessagingService.
+            JSValueRef objMsg = NULL;
+
+            MessageType msgType = (MessageType)imessagingService->getType();
+            LogInfo("msgType :" << msgType);
+
+            if (msgType == EMAIL)
+            {
+                EmailAccountInfo account = imessagingService->getCurrentEmailAccount();
+                LogDebug("Account Address:" << &account);
+                objMsg = JSMessage::createJSObject(l_globalContext, account, msgType);        //make message JSValueRef.
+            }
+            else
+            {
+                objMsg = JSMessage::createJSObject(l_globalContext, msgType);        //make message JSValueRef.
+            }
+
+            //set Properties
+            if ( argumentCount == 1)
+            {
+                IMessagePtr msg = converter->toIMessage(objMsg) ;
+
+                if (!msg)
+                    ThrowMsg(WrtDeviceApis::Commons::PlatformException,"platform exception");
+
+                LogDebug ("##### msg type is " << msg->getId());
+
+                const ScopedJSStringRef subjectStr(JSStringCreateWithUTF8CString("subject"));
+                const ScopedJSStringRef toStr(JSStringCreateWithUTF8CString("to"));
+                const ScopedJSStringRef ccStr(JSStringCreateWithUTF8CString("cc"));
+                const ScopedJSStringRef bccStr(JSStringCreateWithUTF8CString("bcc"));
+                const ScopedJSStringRef plainBodyStr(JSStringCreateWithUTF8CString("plainBody"));
+                const ScopedJSStringRef htmlBodyStr(JSStringCreateWithUTF8CString("htmlBody"));
+                const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("isHighPriority"));
+
+                JSObjectRef arg = converter->toJSObjectRef(arguments[0]);
+                JSValueRef subjectData = JSObjectGetProperty(l_globalContext, arg, subjectStr.get(), NULL);
+                JSValueRef toData = JSObjectGetProperty(l_globalContext, arg, toStr.get(), NULL);
+                JSValueRef ccData = JSObjectGetProperty(l_globalContext, arg, ccStr.get(), NULL);
+                JSValueRef bccData = JSObjectGetProperty(l_globalContext, arg, bccStr.get(), NULL);
+                JSValueRef plainBodyData = JSObjectGetProperty(l_globalContext, arg, plainBodyStr.get(), NULL);
+                JSValueRef htmlBodyData = JSObjectGetProperty(l_globalContext, arg, htmlBodyStr.get(), NULL);
+                JSValueRef priorityData = JSObjectGetProperty(l_globalContext, arg, priorityStr.get(), NULL);
+
+                //subject
+                 if (!JSValueIsUndefined(l_globalContext, subjectData) )
+                 {
+                     LogDebug ( " Subject : " << converter->toString(subjectData) );
+                    std::string subject = converter->toString(subjectData);
+                     switch (msgType)
+                     {
+                        case MMS:
+                        {
+                            IMmsPtr mms = MessageFactory::convertToMms(msg);
+                            mms->setSubject(subject);
+                            break;
+                        }
+                        case EMAIL:
+                        {
+                            IEmailPtr email = MessageFactory::convertToEmail(msg);
+                            email->setSubject(subject);
+                            break;
+                        }
+                      default:
+                      {
+                            LogError("message not supported");
+                            //Throw(WrtDeviceApis::Commons::UnsupportedException);
+                            //break;
+                      }
+                      }
+                 }
+                //to
+                if (!JSValueIsUndefined(l_globalContext, toData) )
+                {
+                    Recipients to = converter->toRecipients(toData);
+                    LogDebug("setting to field, size=" << to.getRecipientSize());
+                    msg->setToRecipients(to);
+                }
+                //cc
+                if (msgType == EMAIL )
+                {
+                    IEmailPtr email = MessageFactory::convertToEmail(msg);
+                    if (!JSValueIsUndefined(l_globalContext, ccData))
+                    {
+                        Recipients cc = converter->toRecipients(ccData);
+                            email->setCcRecipients(cc);
+                    }
+
+                    if (!JSValueIsUndefined(l_globalContext, bccData))
+                    {
+                        Recipients bcc = converter->toRecipients(bccData);
+                            email->setBccRecipients(bcc);
+                    }
+
+                    if (!JSValueIsUndefined(l_globalContext, htmlBodyData))
+                    {
+                        std::string body = converter->toString(htmlBodyData);
+                        LogDebug("html body : " << body);
+                        email->setHtmlBody(body);
+                    }
+
+                    if (!JSValueIsUndefined(l_globalContext, priorityData))
+                    {
+                        email->setPriority(converter->toMessagePriority(priorityData));
+                    }
+
+                }
+
+                if (!JSValueIsUndefined(l_globalContext, plainBodyData) )
+                {
+                    std::string body = converter->toString(plainBodyData);
+                    LogDebug("plain body  : " << body);
+                    msg->setBody(body);
+                }
+
+            }
+            return objMsg;
+
+        }
+            Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+              return JSTizenExceptionFactory::postException(context, exception,
+                JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+           }
+            Catch(WrtDeviceApis::Commons::ConversionException) {
+              return JSTizenExceptionFactory::postException(context, exception,
+                JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+            }
+
+//            LogInfo(">>>");
+//            return JSValueMakeUndefined(context);
+    }
+    else
+    {
+        LogDebug(" Private Object is NULL ");
+        return JSTizenExceptionFactory::postException(context, exception,
+                JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
+    }
+
+}
+#endif
 
 JSValueRef JSMessagingService::sendMessage(JSContextRef context,
         JSObjectRef function,
@@ -355,123 +410,82 @@ JSValueRef JSMessagingService::sendMessage(JSContextRef context,
         const JSValueRef arguments[],
         JSValueRef* exception)
 {
-    LogDebug("entered");
+    LogDebug("Entered");
 
     //check permission.
     AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-               MessagingExportedNames[MESSAGING_FUNCTION_API_SEND_MESSAGE]);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+        MessagingExportedNames[MESSAGING_FUNCTION_API_SEND_MESSAGE]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
     JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
-
     if (!priv) {
-        LogError("Null pointer");
-        return JSTizenExceptionFactory::postException(context, exception, 
-                          JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);         
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
     }
 
     JSContextRef globalContext = priv->getContext();
-    LogInfo(">>> argument count : " << argumentCount);
-
-    if (argumentCount < 1) {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-    }
 
     WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
     WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr recipientCallbackManager;
 
     callbackManager->setObject(thisObject);
 
-    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);  
-
-Try {
-               //argu 1. Message ( mandatory )
-               if (!JSValueIsObject(context, arguments[0])  || JSIsArrayValue(context, arguments[0]))
-               {
-                       LogDebug("arguments is invaild");
-                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
-               }
-               
-               IMessagePtr msg = converter->toIMessage(arguments[0]);
-               
-               //argu 2. Success callback (optional)
-               if ( argumentCount > 1)
-               {
-                       if ( JSValueIsObject(context, arguments[1]) || Validator(context).isCallback(arguments[1]))
-                       {
-                               MessageSendCallback callbacks = converter->toMessageSendCallback(arguments[1]);                 
-                                                       
-                               if (!(JSValueIsUndefined(context, callbacks.onSuccess) || JSValueIsNull(context, callbacks.onSuccess)) )
-                               {
-                                       callbackManager->setOnSuccess( converter->toFunctionOrNull(callbacks.onSuccess) );
-                               }
-                               else
-                               {
-                                       callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
-                               }
-                       }
-                       else
-                       {       
-                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
-                       }
-               }
-               //argu 3. error callback (optional & nullable)
-               if ( argumentCount > 2)
-               {
-                       if ( Validator(context).isCallback(arguments[2]))
-                               callbackManager->setOnError(arguments[2]);
-                       else if(Validator(context).isNullOrUndefined(arguments[2]))
-                               callbackManager->setOnError(NULL);
-                       else
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-               }
-          //create PrivateData
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Message ( mandatory )
+        IMessagePtr msg = converter->toIMessage(validator.toObject(0));
+
+        // argu 2. Success callback (optional)
+        JSObjectRef successcb = validator.toFunction(1, true);
+        // cannot be nullable
+        if (( argumentCount > 1 ) && (NULL == successcb))
+        {
+            throw DeviceAPI::Common::TypeMismatchException("Invalid success callback.");
+        }
+        callbackManager->setOnSuccess(successcb);
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        //create PrivateData
         EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager, recipientCallbackManager) );
 
-        //EventSendMessagePtr event(new EventSendMessage());
-         EventMessagingServicePtr event(new EventMessagingService());
+        EventMessagingServicePtr event(new EventMessagingService());
 
         IMessagingServicePtr imessagingService = priv->getObject();
-       
+
         event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SEND_MESSAGE);
         event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE);
         event->m_message = msg;
         imessagingService->setMessageToOpId( event->opId, event->m_message);
-        event->store = true;           //always store message in sendbox after send , email Type.
+        event->store = true; //always store message in sendbox after send , email Type.
         event->m_messagingService = imessagingService;
         event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
         event->setForAsynchronousCall(&MessagingController::getInstance());
-     
-        ReqReceiverMessageSingleton::Instance().sendMessage(event);    //send message
-        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
-#if 0 //Pending Operation.
-       DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
-               DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
-
-       IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
-               new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
 
-       return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
-#endif                 
-        //return converter->toJSValueRef(event->opId);
-
-       return JSValueMakeUndefined(context);
+        ReqReceiverMessageSingleton::Instance().sendMessage(event); //send message
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
     }
-    Catch(WrtDeviceApis::Commons::ConversionException) {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);        
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
     }
-    Catch(WrtDeviceApis::Commons::NullPointerException) {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);        
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
     }
-    Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);        
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
     }
 
-//    return JSValueMakeNull(context);
+    return JSValueMakeUndefined(context);
 }
 
 JSValueRef JSMessagingService::loadMessageBody(JSContextRef context,
@@ -481,156 +495,99 @@ JSValueRef JSMessagingService::loadMessageBody(JSContextRef context,
         const JSValueRef arguments[],
         JSValueRef* exception)
 {
-    LogDebug("entered");
+    LogDebug("Entered");
 
-       //check permission.
-       AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-               MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_BODY]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_BODY]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
     JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
-
     if (!priv) {
-        LogError("Null pointer");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                  JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
     }
 
-    JSContextRef globalContext = priv->getContext();           //create global Context
-    LogInfo(">>> argument count : " << argumentCount);
-
-       if (argumentCount < 2) {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-       }
-
-       Validator check(context, exception);    //create check
-
-       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
-       callbackManager->setObject(thisObject);
-       
-       ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
-
-       Try {
-                       //argu 1. message (mandatory)
-                       if (!JSValueIsObject(context, arguments[0]) || JSIsArrayValue(context, arguments[0]))
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
-                       }
-                       //argu 2. success callback
-                       if ( Validator(context).isCallback(arguments[1]))
-                       {
-                               callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
-                       }
-                       else
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
-                       }
-                       
-                       //argu 3. error callback (optional & nullable)
-                       if ( argumentCount > 2)
-                       {
-                               if ( check.isCallback(arguments[2]))
-                                       callbackManager->setOnError(arguments[2]);
-                               else if(check.isNullOrUndefined(arguments[2]))
-                                       callbackManager->setOnError(NULL);
-                               else
-                                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-                       }
-                       else
-                       {
-                               callbackManager->setOnError(NULL);
-                       }
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-
-       Try {
-                       IMessagePtr msg = converter->toIMessage(arguments[0]);
-                        LogInfo(" checked toIMessages " );             
-                       //create event
-                       EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
-                       EventMessagingServicePtr event(new EventMessagingService());     
-                       event->m_message = msg;
-
-                       if ( event->m_message )
-                       {       
-                               int msgType = event->m_message->getMessageType();
-                               
-                               if (msgType == EMAIL)
-                               {
-                                       IEmailPtr email = MessageFactory::convertToEmail(event->m_message);
-                                       if (email && email->isBodyDownloaded() > 0)
-                                       {
-                                               callbackManager->callOnSuccess(converter->toJSValueRef(msg));
-                                               return JSValueMakeNull(context);
-                                       }
-                               }
-                               else
-                               {
-                                       callbackManager->callOnSuccess(converter->toJSValueRef(msg));
-                                               return JSValueMakeNull(context);
-                               }
-
-                               privateData->setMessageJSValueRef(arguments[0]);        //set Message JSValueRef.
-                       }
-                       LogInfo(" Checked Message Type " );
-                       
-                       IMessagingServicePtr imessagingService = priv->getObject();
-                       int opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_DOWNLOAD_BODY);
-                       LogDebug("Operation ID is = " << opId);
-
-                       event->opId = opId;
-                       imessagingService->setMessageToOpId(opId, event->m_message);
-                       imessagingService->setEventToOpId(event->opId, event);
-                       event->m_messagingService = imessagingService;
-                       
-                       event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY);
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
-                       event->setForAsynchronousCall(&MessagingController::getInstance());
-
-                       ReqReceiverMessageSingleton::Instance().loadMessageBody(event); //load message Body
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
-#if 0
-                       DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
-                               DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
+    JSContextRef globalContext = priv->getContext(); //create global Context
 
-                       IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
-                               new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
+    callbackManager->setObject(thisObject);
 
-                       return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
-#endif
-                       //return converter->toJSValueRef(event->opId);
-                       return JSValueMakeUndefined(context);
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
-               return JSValueMakeNull(context);
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
-               return JSValueMakeNull(context);
-       }
-       Catch(WrtDeviceApis::Commons::Exception) {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
-               return JSValueMakeNull(context);
-       }
-
-//     return JSValueMakeNull(context);
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Message ( mandatory )
+        IMessagePtr msg = converter->toIMessage(validator.toObject(0));
+
+        // argu 2. Success callback
+        callbackManager->setOnSuccess(validator.toFunction(1));
 
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        //create event
+        EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+        EventMessagingServicePtr event(new EventMessagingService());
+        event->m_message = msg;
+
+        if ( event->m_message )
+        {
+            int msgType = event->m_message->getMessageType();
+
+            if (msgType == EMAIL)
+            {
+                IEmailPtr email = MessageFactory::convertToEmail(event->m_message);
+                if (email && email->isBodyDownloaded() > 0)
+                {
+                    callbackManager->callOnSuccess(converter->toJSValueRef(msg));
+                    return JSValueMakeUndefined(context);
+                }
+            }
+            else
+            {
+                callbackManager->callOnSuccess(converter->toJSValueRef(msg));
+                    return JSValueMakeUndefined(context);
+            }
+
+            privateData->setMessageJSValueRef(arguments[0]); //set Message JSValueRef.
+        }
+        LogInfo(" Checked Message Type " );
+
+        IMessagingServicePtr imessagingService = priv->getObject();
+        int opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_DOWNLOAD_BODY);
+        LogDebug("Operation ID is = " << opId);
+
+        event->opId = opId;
+        imessagingService->setMessageToOpId(opId, event->m_message);
+        imessagingService->setEventToOpId(event->opId, event);
+        event->m_messagingService = imessagingService;
+
+        event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY);
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+        event->setForAsynchronousCall(&MessagingController::getInstance());
+
+        ReqReceiverMessageSingleton::Instance().loadMessageBody(event); //load message Body
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
 }
 
 JSValueRef JSMessagingService::loadMessageAttachment(JSContextRef context,
@@ -640,662 +597,461 @@ JSValueRef JSMessagingService::loadMessageAttachment(JSContextRef context,
         const JSValueRef arguments[],
         JSValueRef* exception)
 {
-       LogDebug("entered");
-
-       //check permission.
-       AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-               MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_ATTACHMENT]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
-
-       if (!priv) {
-               LogError("Private Object is Null pointer");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-       
-       JSContextRef globalContext = priv->getContext();                //create global Context
-       LogInfo(">>> argument count : " << argumentCount);
-
-       if (argumentCount < 2) {
-               return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-       }
-
-       Validator check(context, exception);    //create check
-
-       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
-       callbackManager->setObject(thisObject);
-       ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
-
-       Try {
-
-               //argu 1. Attachment (mandatory)
-               if (!JSValueIsObject(context, arguments[0]) || JSIsArrayValue(context, arguments[0]))
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
-               }
-                               
-               //argu 2. success callback
-               if ( check.isCallback(arguments[1]))
-                       callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
-               else
-                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
-
-               //argu 3. error callback (optional & nullable)
-               if ( argumentCount > 2)
-               {
-                       if ( check.isCallback(arguments[2]))
-                               callbackManager->setOnError(arguments[2]);
-                       else if(check.isNullOrUndefined(arguments[2]))
-                               callbackManager->setOnError(NULL);
-                       else
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-               }
-               else{
-                       callbackManager->setOnError(NULL);
-               }
-
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-       }
-       Catch(WrtDeviceApis::Commons::Exception) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-       }
-
-
-       EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
-
-       if (!privateData)
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-
-       Try {
-               IAttachmentPtr iAttchmentPtr = converter->toIAttachment(arguments[0]);
-               LogInfo("iAttchmentPtr->getDownloaded() : " << iAttchmentPtr->getDownloaded());
-               if(iAttchmentPtr->getDownloaded() > 0)
-               {
-                       callbackManager->callOnSuccess(converter->toJSValueRef(iAttchmentPtr));
-                       return JSValueMakeNull(context);
-               }
-
-               EventMessagingServicePtr event(new EventMessagingService());     //create event
-               event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT);
-               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
-               event->setForAsynchronousCall(&MessagingController::getInstance());
-
-               event->m_attachment = iAttchmentPtr;
-               event->m_message = event->m_attachment->getMessage();
-
-               privateData->setMessageJSValueRef(arguments[0]); //set attachment JSValueRef.
-
-               IMessagingServicePtr imessagingService = priv->getObject();
-               if (imessagingService)
-               {
-                       int opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT);
-                       LogDebug("Operation ID is = " << opId);
-
-                       event->opId = opId;
-                       imessagingService->setMessageToOpId(opId, event->m_message);
-                       imessagingService->setEventToOpId(event->opId, event);
-                       event->m_messagingService = imessagingService;
-
-                       //JSValueRef pendingOperation = WrtDeviceApis::CommonsJavaScript::makePendingOperation(globalContext, event);   //create pendingOperation.
-                       ReqReceiverMessageSingleton::Instance().loadMessageAttachment(event);   //load message Body
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
-#if 0
-                       DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
-                       DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
+    LogDebug("Entered");
 
-                       IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
-                                       new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_ATTACHMENT]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-                       return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
-#endif
-                       //return converter->toJSValueRef(event->opId);
-                       return JSValueMakeUndefined(context);
-
-               }
-               else
-               {
-                       return JSTizenExceptionFactory::postException(context, exception,
-                                       JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
-               }
-
-       }
-       Catch(WrtDeviceApis::Commons::NullPointerException) {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
-               return JSValueMakeNull(context);
-       }
-       Catch(WrtDeviceApis::Commons::Exception) {
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
-               return JSValueMakeNull(context);
-       }
-//     return JSValueMakeUndefined(context);
+    JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    JSContextRef globalContext = priv->getContext(); //create global Context
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
+    callbackManager->setObject(thisObject);
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        //argu 1. Attachment (mandatory)
+        IAttachmentPtr iAttchmentPtr = converter->toIAttachment(validator.toObject(0));
+
+        // argu 2. Success callback
+        callbackManager->setOnSuccess(validator.toFunction(1));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+        if (!privateData) {
+            throw DeviceAPI::Common::UnknownException("Private data is NULL.");
+        }
+
+        LogInfo("iAttchmentPtr->getDownloaded() : " << iAttchmentPtr->getDownloaded());
+        if(iAttchmentPtr->getDownloaded() > 0)
+        {
+            callbackManager->callOnSuccess(converter->toJSValueRef(iAttchmentPtr));
+            return JSValueMakeUndefined(context);
+        }
+
+        EventMessagingServicePtr event(new EventMessagingService());     //create event
+        event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT);
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+        event->setForAsynchronousCall(&MessagingController::getInstance());
+
+        event->m_attachment = iAttchmentPtr;
+        event->m_message = event->m_attachment->getMessage();
+
+        privateData->setMessageJSValueRef(arguments[0]); //set attachment JSValueRef.
+
+        IMessagingServicePtr imessagingService = priv->getObject();
+        if (imessagingService)
+        {
+            int opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT);
+            LogDebug("Operation ID is = " << opId);
+
+            event->opId = opId;
+            imessagingService->setMessageToOpId(opId, event->m_message);
+            imessagingService->setEventToOpId(event->opId, event);
+            event->m_messagingService = imessagingService;
+
+            ReqReceiverMessageSingleton::Instance().loadMessageAttachment(event); //load message Attachment
+            MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
+        }
+        else
+        {
+            throw DeviceAPI::Common::UnknownException("MessagingService not found.");
+        }
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
 }
 
 JSValueRef JSMessagingService::sync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                       size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+            size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
+    LogDebug("Entered");
 
-       LogDebug("entered");
-
-       //check permission.
-       AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-               MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC]);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
-
-       if (priv) {
-
-               JSContextRef globalContext = priv->getContext();                //get global Context
-
-               LogInfo(">>> argument count : " << argumentCount);
-
-//             if (argumentCount < 2 ) {
-//                     return JSTizenExceptionFactory::postException(context, exception, 
-//                             JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-//             }
-
-               Validator check(context, exception);    //check context
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
-               callbackManager->setObject(thisObject);
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
-
-               IMessagingServicePtr imessagingService = priv->getObject();                             //get MessagingService.
-
-               MessageType msgType = (MessageType)imessagingService->getType();
-               LogInfo("msgType :" << msgType);
-
-
-                       
-               Try {
-
-                       int limit = -1; //sync limit
-                       //argu 1. success  callback ( nullable )
-                       if (argumentCount > 0)
-                       {
-                               if ( check.isCallback(arguments[0]))
-                               {
-                                       callbackManager->setOnSuccess(arguments[0]);
-                               }
-                               else if(check.isNullOrUndefined(arguments[0]))
-                               {
-                                       callbackManager->setOnSuccess(NULL);
-                               }
-                               else
-                               {
-                                       Throw(WrtDeviceApis::Commons::ConversionException);
-                               }
-                       }
-                       else{
-                                       callbackManager->setOnSuccess(NULL);
-                       }
-                       //argu 2. error callback ( nullable )
-                       if (argumentCount > 1)
-                       {
-
-                               if ( check.isCallback(arguments[1]))
-                                       callbackManager->setOnError(arguments[1]);
-                               else if(check.isNullOrUndefined(arguments[1]))
-                                       callbackManager->setOnError(NULL);
-                               else
-                                       Throw(WrtDeviceApis::Commons::ConversionException);
-                       }
-                       else{
-                                       callbackManager->setOnError(NULL);
-                       }
-                       //argu 3. limit ( optional )
-                       if(argumentCount > 2)
-                       {
-                               if (!Validator(context).isNullOrUndefined(arguments[2]))
-                               {
-                                       limit = converter->toInt(arguments[2]);
-                               }
-                       }
-
-                       EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
-                       EventMessagingServicePtr event(new EventMessagingService());     //create event         
-
-                       LogDebug("limit : " << limit);
-
-                       event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SYNC);
-                       event->m_sync_account_id = imessagingService->getAccountID() ;
-                       event->m_sync_limit = limit;
-                       event->m_messagingService = imessagingService;
-                       imessagingService->setEventToOpId(event->opId, event);
-
-                       event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC);
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
-                       event->setForAsynchronousCall(&MessagingController::getInstance());
-
-                       ReqReceiverMessageSingleton::Instance().sync(event);    //load message Body
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
-#if 0
-                               DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
-                                       DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
-                        
-                               IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
-                                        new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
-
-                               return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
-#endif         
-                       return converter->toJSValueRef(event->opId);
-                       
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-                       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) {
-                       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
-               }
-       
-       }
-       else
-       {               
-               LogError("Null pointer");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                  JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-
-       return JSValueMakeNull(context);
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-}
+    JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 
+    JSContextRef globalContext = priv->getContext(); //get global Context
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
+    callbackManager->setObject(thisObject);
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Success callback (optional & nullable)
+        callbackManager->setOnSuccess(validator.toFunction(0, true));
+
+        // argu 2. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(1, true));
+
+        // argu 3. limit ( optional )
+        int limit = validator.toLong(2, true, -1); //sync limit
+        LogDebug("limit : " << limit);
+
+        IMessagingServicePtr imessagingService = priv->getObject(); //get MessagingService.
+
+        MessageType msgType = (MessageType)imessagingService->getType();
+        LogInfo("msgType :" << msgType);
+        if (msgType != EMAIL) {
+            std::string errMessage = converter->toMessageType(imessagingService->getType()) + " not supported";
+            throw DeviceAPI::Common::NotSupportedException(errMessage.c_str());
+        }
+
+        EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+        EventMessagingServicePtr event(new EventMessagingService()); //create event
+
+        event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SYNC);
+        event->m_sync_account_id = imessagingService->getAccountID() ;
+        event->m_sync_limit = limit;
+        event->m_messagingService = imessagingService;
+        imessagingService->setEventToOpId(event->opId, event);
+
+        event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC);
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+        event->setForAsynchronousCall(&MessagingController::getInstance());
+
+        ReqReceiverMessageSingleton::Instance().sync(event); // sync with an external mail server
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
+
+        return JSUtil::toJSValueRef(context, (long int)event->opId);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
 
 JSValueRef JSMessagingService::syncFolder(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                       size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+            size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-       LogDebug("entered");
-
-       //check permission
-       AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-               MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC_FOLDER]);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
-
-       if (priv) {
-               JSContextRef globalContext = priv->getContext();                //get global Context
-
-               LogInfo(">>> argument count : " << argumentCount);
-
-               if (argumentCount < 1) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               Validator check(context, exception);    //check context
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
-               callbackManager->setObject(thisObject);
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
-
-               IMessagingServicePtr imessagingService = priv->getObject();                     //get MessagingService.
-
-               MessageType msgType = (MessageType)imessagingService->getType();
-               LogInfo("msgType :" << msgType);
-
-               Try {
-
-                       int limit = -1;
-                       //argu 1. Folder (mandatory)
-                       if (!JSValueIsObject(context, arguments[0]) || JSIsArrayValue(context, arguments[0]))
-                       {
-                               Throw(WrtDeviceApis::Commons::ConversionException);
-                       }
-                       IMessageFolderPtr folder = converter->toIMessageFolder(arguments[0]);           
-                       LogInfo("check :");
-                       //argu 2. success callback.
-                       if ( argumentCount > 1)
-                       {
-                               if (Validator(context).isCallback(arguments[1]))
-                                       callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
-                               else if(check.isNullOrUndefined(arguments[1]))
-                                       callbackManager->setOnSuccess(NULL);
-                               else
-                                       Throw(WrtDeviceApis::Commons::ConversionException);
-                       }
-                       else{
-                                       callbackManager->setOnSuccess(NULL);
-                       }
-                       //argu 3. error callback (optional & nullable)
-                       if ( argumentCount > 2)
-                       {
-                               if ( check.isCallback(arguments[2]))
-                                       callbackManager->setOnError(arguments[2]);
-                               else if(check.isNullOrUndefined(arguments[2]))
-                                       callbackManager->setOnError(NULL);
-                               else
-                                       Throw(WrtDeviceApis::Commons::ConversionException);
-                       }
-                       else{
-                                       callbackManager->setOnError(NULL);
-                       }
-                       //argu 4. limit ( optional )
-                       if(argumentCount > 3)
-                       {
-                               if (!Validator(context).isNullOrUndefined(arguments[3]))
-                               {
-                                       limit = converter->toInt(arguments[3]);
-                               }
-                       }
-                       
-                       EventMessagingServicePtr event(new EventMessagingService());     //create event                         
-                       EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
-                               
-                               if ( folder )
-                               {
-                                   event->m_folder_name = folder->getPath();           //it will be changed to the folder ptr
-                                   event->m_sync_folder_id = folder->getId();          //it will be changed to the folder ptr
-                               }
-
-                               LogDebug("limit : " << limit);
-                               LogDebug("folderName : " << event->m_folder_name);
-                               event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SYNC_FOLDER);
-                               event ->m_sync_account_id = imessagingService->getAccountID() ;
-                               event ->m_sync_limit = limit;
-                               event->m_messagingService = imessagingService;
-                               imessagingService->setEventToOpId(event->opId, event);
-
-                               event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER);
-                               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
-                               event->setForAsynchronousCall(&MessagingController::getInstance());
-
-                               ReqReceiverMessageSingleton::Instance().syncFolder(event);      //load message Body
-                               MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
+    LogDebug("Entered");
 
-#if 0
-                               DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
-                                       DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
-                               
-                               IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
-                                       new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
-                               
-                               return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
-#endif         
-                               return converter->toJSValueRef(event->opId);
-               }
-               Catch(WrtDeviceApis::Commons::UnsupportedException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) {
-                       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
-                       return JSValueMakeNull(context);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-                       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
-                       return JSValueMakeNull(context);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) {
-                       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
-               }
-               
-       }
-       else
-       {
-               LogError("Null pointer");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                  JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-       }
-
-       return JSValueMakeNull(context);
+    //check permission
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC_FOLDER]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+    JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 
-}
+    JSContextRef globalContext = priv->getContext(); //get global Context
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
+    callbackManager->setObject(thisObject);
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Folder (mandatory)
+        IMessageFolderPtr folder = converter->toIMessageFolder(validator.toObject(0));
+
+        // argu 2. Success callback (optional & nullable)
+        callbackManager->setOnSuccess(validator.toFunction(1, true));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        // argu 4. limit ( optional )
+        int limit = validator.toLong(3, true, -1); //sync limit
+        LogDebug("limit : " << limit);
+
+        IMessagingServicePtr imessagingService = priv->getObject(); //get MessagingService.
 
+        MessageType msgType = (MessageType)imessagingService->getType();
+        LogInfo("msgType :" << msgType);
+        if (msgType != EMAIL) {
+            std::string errMessage = converter->toMessageType(imessagingService->getType()) + " not supported";
+            throw DeviceAPI::Common::NotSupportedException(errMessage.c_str());
+        }
+
+        EventMessagingServicePtr event(new EventMessagingService()); //create event
+        EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+
+        if ( folder )
+        {
+            event->m_folder_name = folder->getPath(); //it will be changed to the folder ptr
+            event->m_sync_folder_id = folder->getId(); //it will be changed to the folder ptr
+        }
+
+        LogDebug("folderName : " << event->m_folder_name);
+        event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SYNC_FOLDER);
+        event->m_sync_account_id = imessagingService->getAccountID() ;
+        event->m_sync_limit = limit;
+        event->m_messagingService = imessagingService;
+        imessagingService->setEventToOpId(event->opId, event);
+
+        event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER);
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+        event->setForAsynchronousCall(&MessagingController::getInstance());
+
+        ReqReceiverMessageSingleton::Instance().syncFolder(event); //load message Body
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
+
+        return JSUtil::toJSValueRef(context, (long int)event->opId);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+#if 0
 JSValueRef JSMessagingService::cancelOperation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                       size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+            size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-       LogDebug("entered");
-
-       JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));    //get private object
-
-       if (priv)
-       {
-               IMessagingServicePtr imessagingService = priv->getObject();
-               Try
-               {
-                       LogInfo(">>> argument count : " << argumentCount);
-
-                       if ( argumentCount == 1 && !Validator(context).isCallback(arguments[0]))
-                       {
-                               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                               MessageType msgType = (MessageType)imessagingService->getType();
-                               LogInfo("msgType :" << msgType);
-
-                               int opId = converter->toLong( arguments[0] );   //Fetch operation ID
-                               int handle = imessagingService->getHandleFromOpId(opId);
-                               if ( handle < 0 )
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::NotFoundException,"Operation ID Not found");
-                               }
-                               
-                               int opType = imessagingService->getOpTypeFromOpId(opId);
-                               LogInfo("operation ID :" << opId << " operation Type : "  << opType);                   
-
-                               if ( opType == MESSAGING_SERVICE_OP_SEND_MESSAGE)
-                               {       
-                                       IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
-                                       if (msg)
-                                       {
-                                               LogDebug("Call Cancel Function");
-                                               msg->sendCancel(handle);
-                                               imessagingService->deleteOpId(opId);
-                                       }
-                               }
-                               else
-                               {       //for email.
-                                       if (msgType == EMAIL)
-                                       {       
-                                               IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
-                                               IEmailPtr email = MessageFactory::convertToEmail(msg);
-                                                       
-                                               if ( opType == MESSAGING_SERVICE_OP_DOWNLOAD_BODY )
-                                               {       
-                                                       LogDebug("Cancel Download Body , handle = " << handle);
-                                                       email->downloadBodyCancel(handle);
-                                               }
-                                               else if ( opType == MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT)
-                                               {
-                                                       LogDebug("Cancel Download Attachment , handle = " << handle);
-                                                       email->downloadAttachmentCancel(handle);
-                                               }
-                                               else if (  opType == MESSAGING_SERVICE_OP_SYNC )
-                                               {       
-                                                       LogDebug("Cancel Sync , handle = " << handle);
-                                                       imessagingService->syncCancel(handle);
-                                               }
-                                               else if ( opType == MESSAGING_SERVICE_OP_SYNC_FOLDER )
-                                               {
-                                                       LogDebug("Cancel Sync Folder, handle = " << handle);
-                                                       imessagingService->syncFolderCancel(handle);
-                                               }
-                                               imessagingService->deleteOpId(opId);
-                                       }
-                                       else
-                                       {
-                                               ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Operation Type is mismatched");
-                                       }
-                               }
-                               
-                       }
-                       else
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
-                       }
-
-               }
-               Catch (WrtDeviceApis::Commons::InvalidArgumentException){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);                                            
-               }
-               Catch (WrtDeviceApis::Commons::NotFoundException){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);                                                
-               }
-               Catch (WrtDeviceApis::Commons::UnsupportedException){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);                                                
-               } 
-               Catch (WrtDeviceApis::Commons::Exception){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);                    
-               }
-               
-       }
-       else
-       {       
-               LogDebug(" Private Object is NULL ");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
-       }
-
-       LogDebug(">>>");
-       return JSValueMakeUndefined(context);
+    LogDebug("entered");
+
+    JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));    //get private object
+
+    if (priv)
+    {
+        IMessagingServicePtr imessagingService = priv->getObject();
+        Try
+        {
+            LogInfo(">>> argument count : " << argumentCount);
+
+            if ( argumentCount == 1 && !Validator(context).isCallback(arguments[0]))
+            {
+                ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+                MessageType msgType = (MessageType)imessagingService->getType();
+                LogInfo("msgType :" << msgType);
+
+                int opId = converter->toLong( arguments[0] );    //Fetch operation ID
+                int handle = imessagingService->getHandleFromOpId(opId);
+                if ( handle < 0 )
+                {
+                    ThrowMsg(WrtDeviceApis::Commons::NotFoundException,"Operation ID Not found");
+                }
+
+                int opType = imessagingService->getOpTypeFromOpId(opId);
+                LogInfo("operation ID :" << opId << " operation Type : "  << opType);
+
+                if ( opType == MESSAGING_SERVICE_OP_SEND_MESSAGE)
+                {
+                    IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
+                    if (msg)
+                    {
+                        LogDebug("Call Cancel Function");
+                        msg->sendCancel(handle);
+                        imessagingService->deleteOpId(opId);
+                    }
+                }
+                else
+                {    //for email.
+                    if (msgType == EMAIL)
+                    {
+                        IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
+                        IEmailPtr email = MessageFactory::convertToEmail(msg);
+
+                        if ( opType == MESSAGING_SERVICE_OP_DOWNLOAD_BODY )
+                        {
+                            LogDebug("Cancel Download Body , handle = " << handle);
+                            email->downloadBodyCancel(handle);
+                        }
+                        else if ( opType == MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT)
+                        {
+                            LogDebug("Cancel Download Attachment , handle = " << handle);
+                            email->downloadAttachmentCancel(handle);
+                        }
+                        else if (  opType == MESSAGING_SERVICE_OP_SYNC )
+                        {
+                            LogDebug("Cancel Sync , handle = " << handle);
+                            imessagingService->syncCancel(handle);
+                        }
+                        else if ( opType == MESSAGING_SERVICE_OP_SYNC_FOLDER )
+                        {
+                            LogDebug("Cancel Sync Folder, handle = " << handle);
+                            imessagingService->syncFolderCancel(handle);
+                        }
+                        imessagingService->deleteOpId(opId);
+                    }
+                    else
+                    {
+                        ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Operation Type is mismatched");
+                    }
+                }
+
+            }
+            else
+            {
+                ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+            }
+
+        }
+        Catch (WrtDeviceApis::Commons::InvalidArgumentException){
+            LogError("Exception: " << _rethrown_exception.GetMessage());
+            return JSTizenExceptionFactory::postException(context, exception,
+                JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+        }
+        Catch (WrtDeviceApis::Commons::NotFoundException){
+            LogError("Exception: " << _rethrown_exception.GetMessage());
+            return JSTizenExceptionFactory::postException(context, exception,
+                JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
+        }
+        Catch (WrtDeviceApis::Commons::UnsupportedException){
+            LogError("Exception: " << _rethrown_exception.GetMessage());
+            return JSTizenExceptionFactory::postException(context, exception,
+                JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
+        }
+        Catch (WrtDeviceApis::Commons::Exception){
+            LogError("Exception: " << _rethrown_exception.GetMessage());
+            return JSTizenExceptionFactory::postException(context, exception,
+                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+        }
+
+    }
+    else
+    {
+        LogDebug(" Private Object is NULL ");
+        return JSTizenExceptionFactory::postException(context, exception,
+                    JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
+    }
+
+    LogDebug(">>>");
+    return JSValueMakeUndefined(context);
 }
+#endif
 
 JSValueRef JSMessagingService::stopSync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                       size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+            size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-       LogDebug("entered");
-
-       JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));    //get private object
-
-       if (priv)
-       {
-               IMessagingServicePtr imessagingService = priv->getObject();
-               Try
-               {
-                       LogInfo(">>> argument count : " << argumentCount);
-
-                       if ( argumentCount < 1 )
-                       {
-                               return JSTizenExceptionFactory::postException(context, exception, 
-                                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-                       }
-
-                               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                               MessageType msgType = (MessageType)imessagingService->getType();
-                               LogInfo("msgType :" << msgType);
-
-                               int opId = converter->toLong( arguments[0]);    //Fetch operation ID
-                               int handle = imessagingService->getHandleFromOpId(opId);
-                               if ( handle < 0 )
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::NotFoundException,"Operation ID Not found");
-                               }
-                               
-                               int opType = imessagingService->getOpTypeFromOpId(opId);
-                               LogInfo("operation ID :" << opId << " operation Type : "  << opType);
-
-                               if (msgType == EMAIL)
-                               {                       
-                                       if (  opType == MESSAGING_SERVICE_OP_SYNC )
-                                       {       
-                                               LogDebug("Cancel Sync , handle = " << handle);
-                                               imessagingService->syncCancel(handle);
-                                       }
-                                       else if ( opType == MESSAGING_SERVICE_OP_SYNC_FOLDER )
-                                       {
-                                               LogDebug("Cancel Sync Folder, handle = " << handle);
-                                               imessagingService->syncFolderCancel(handle);
-                                       }
-
-                                       //call error callback.
-                                       EventMessagingServicePtr event = imessagingService->getEventFromOpId(opId);
-                                       if (event)
-                                       {
-                                               LogDebug("get callback Manager");
-                                               EventMessagingServicePrivateDataPtr privateData = 
-                                                       DPL::StaticPointerCast<EventMessagingServicePrivateData>(event->getPrivateData());
-       
-                                               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager();             //get callback manager
-                                               JSContextRef globalContext = callbackManager->getContext();
-                                               if (callbackManager)
-                                               {
-                                                       LogDebug("call error callback.");
-                                                       callbackManager->callOnError(JSDOMExceptionFactory::AbortException.make(globalContext, JSMESSAGING_EXCEPTION_MSG_ABORT_ERROR));
-                                               }
-                                       }
-
-                                       imessagingService->deleteOpId(opId);
-
-                               }
-                               else
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Operation Type is mismatched");
-                               }
-                               
-
-               }
-               Catch (WrtDeviceApis::Commons::InvalidArgumentException){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);                                            
-               }
-               Catch (WrtDeviceApis::Commons::NotFoundException){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch (WrtDeviceApis::Commons::UnsupportedException){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);                                                
-               } 
-               Catch (WrtDeviceApis::Commons::Exception){
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);                    
-               }
-               
-       }
-       else
-       {       
-               LogDebug(" Private Object is NULL ");
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
-       }
-
-       LogDebug(">>>");
-       return JSValueMakeUndefined(context);
+    LogDebug("Entered");
+
+    JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. opId
+        int opId = validator.toLong(0);
+        LogDebug("opId : " << opId);
+
+        ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+        IMessagingServicePtr imessagingService = priv->getObject();
+        MessageType msgType = (MessageType)imessagingService->getType();
+        LogInfo("msgType :" << msgType);
+        if (msgType != EMAIL) {
+            std::string errMessage = converter->toMessageType(imessagingService->getType()) + " not supported";
+            throw DeviceAPI::Common::NotSupportedException(errMessage.c_str());
+        }
+
+        int handle = imessagingService->getHandleFromOpId(opId);
+        if ( handle < 0 )
+        {
+            throw DeviceAPI::Common::InvalidValuesException("Operation ID Not found");
+        }
+
+        int opType = imessagingService->getOpTypeFromOpId(opId);
+        LogInfo("operation ID :" << opId << " operation Type : "  << opType);
+
+        if (  opType == MESSAGING_SERVICE_OP_SYNC )
+        {
+            LogDebug("Cancel Sync , handle = " << handle);
+            imessagingService->syncCancel(handle);
+        }
+        else if ( opType == MESSAGING_SERVICE_OP_SYNC_FOLDER )
+        {
+            LogDebug("Cancel Sync Folder, handle = " << handle);
+            imessagingService->syncFolderCancel(handle);
+        }
+        else
+        {
+            throw DeviceAPI::Common::UnknownException("Operation Type is mismatched");
+        }
+
+        //call error callback.
+        EventMessagingServicePtr event = imessagingService->getEventFromOpId(opId);
+        if (event)
+        {
+            LogDebug("get callback Manager");
+            EventMessagingServicePrivateDataPtr privateData =
+                DPL::StaticPointerCast<EventMessagingServicePrivateData>(event->getPrivateData());
+
+            WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager(); //get callback manager
+            JSContextRef globalContext = callbackManager->getContext();
+            if (callbackManager)
+            {
+                LogDebug("call error callback.");
+                callbackManager->callOnError(JSDOMExceptionFactory::AbortException.make(globalContext, JSMESSAGING_EXCEPTION_MSG_ABORT_ERROR));
+            }
+        }
+
+        imessagingService->deleteOpId(opId);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
 }
 
 
index 14c5b37..831cd18 100755 (executable)
@@ -29,81 +29,100 @@ typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<IMessagingServicePtr>::
 
 class JSMessagingService {
 
-public :       
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       
-       static JSObjectRef createJSObject(JSContextRef context, const IMessagingServicePtr &messagingService);
-       
+public :
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+
+    static JSObjectRef createJSObject(JSContextRef context, const IMessagingServicePtr &messagingService);
+
 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 an object is used as the target of an 'instanceof' expression.
-        */
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
-
-       /**
-       * The callback invoked when determining whether an object has a property.
-       */
-       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 create message
-       */      
-       static JSValueRef createMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, 
-               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
-       static JSValueRef sendMessage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+    /**
+     * 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 an object is used as the target of an 'instanceof' expression.
+     */
+    static bool hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
+
+    /**
+    * The callback invoked when determining whether an object has a property.
+    */
+    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 setting a property's value.
+    */
+    static bool setProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+
+    /**
+     * The callback invoked when collecting the names of an object's properties.
+     */
+    static void getPropertyNames(JSContextRef context,
+            JSObjectRef object,
+            JSPropertyNameAccumulatorRef propertyNames);
+
+#if 0
+    /**
+    * The callback invoked when create message
+    */
+    static JSValueRef createMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+#endif
+
+    static JSValueRef sendMessage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
             size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-       
-       static JSValueRef loadMessageBody(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
-       static JSValueRef loadMessageAttachment(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
-       static JSValueRef sync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
-       static JSValueRef syncFolder(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
-       static JSValueRef cancelOperation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
-       static JSValueRef stopSync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
-                               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-       
-       /**
-        * This structure contains properties and callbacks that define a type of object.
-        */
-       static JSClassDefinition m_classInfo;
-
-       static JSStaticFunction m_function[];
-       static JSStaticValue m_property[];
-       static JSClassRef m_jsClassRef;
-               
+
+    static JSValueRef loadMessageBody(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef loadMessageAttachment(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef sync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef syncFolder(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+#if 0
+    static JSValueRef cancelOperation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+#endif
+
+    static JSValueRef stopSync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSStaticFunction m_function[];
+    static JSStaticValue m_property[];
+    static JSClassRef m_jsClassRef;
+
 }; //JSMessagingService
 
 }
index f26fab0..28c9bca 100644 (file)
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>                                   
+#include <CommonsJavaScript/Utils.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
 
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+
 #include "JSMessagingServiceManager.h"
 #include "MessagingController.h"
 #include "MessagingListener.h"
@@ -46,212 +49,148 @@ using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Messaging {
-       
-       JSClassRef JSMessagingServiceManager::m_jsClassRef = NULL;
-
-       JSClassDefinition JSMessagingServiceManager::m_classInfo = {
-               0,
-               kJSClassAttributeNone,
-               "messaging",
-               NULL,
-               m_property,
-               m_function,
-               initialize,
-               finalize,
-               NULL, //hasProperty,
-               NULL, //getProperty,
-               NULL, //setProperty,
-               NULL, //deleteProperty,Geolocation
-               NULL, //getPropertyNames,
-               NULL,
-               NULL,
-               hasInstance,
-               NULL
-       };
-
-       JSStaticValue JSMessagingServiceManager::m_property[] =
-       {
-           { 0, 0, 0, 0 }
-       };
-
-       JSStaticFunction JSMessagingServiceManager::m_function[] = {
-                       { "getMessageServices",   JSMessagingServiceManager::getMessagingServices,         kJSPropertyAttributeNone },
-                       { 0, 0, 0 }
-       };
-
-       const JSClassRef JSMessagingServiceManager::getClassRef() {
-               if (!m_jsClassRef) {
-                       m_jsClassRef = JSClassCreate(&m_classInfo);
-               }
-               return m_jsClassRef;
-       }
-
-       void JSMessagingServiceManager::initialize(JSContextRef context, JSObjectRef object) {
-               LogDebug("creation messaging instance");
-
-               JSMessagingServiceManagerPriv *priv = static_cast<JSMessagingServiceManagerPriv*>(JSObjectGetPrivate(object));
-               if (priv == NULL)
-               {
-                       IMessagingServiceManagerPtr MessagingServiceManager(MessagingFactory::getInstance().getMessagingServiceManager());
-                       priv = new JSMessagingServiceManagerPriv( context, MessagingServiceManager);
-
-                       if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
-                               LogError("Object can't store private data.");
-                               delete priv;
-                       }
-               }
-               else
-               {
-                       LogDebug("already exist");
-                       LogDebug("global context=" << priv->getContext());
-               }
-
-       }
-
-       void JSMessagingServiceManager::finalize(JSObjectRef object) {
-               LogDebug("enter");
-               JSMessagingServiceManagerPriv* priv = static_cast<JSMessagingServiceManagerPriv*>(JSObjectGetPrivate(object));
-               MessagingListener::getInstance().deregisterMessageReceivedEmitter();
-
-               if (priv) {
-                       JSObjectSetPrivate(object, NULL);
-                       delete priv;  // object will be deleted, but used to show that private object is deleted
-               }
-               LogDebug("Leave");
-
-       }
-
-       bool JSMessagingServiceManager::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
-               return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-       }
-
-       JSValueRef JSMessagingServiceManager::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-       {
-               return JSValueMakeUndefined(context);
-       }
-
-JSValueRef JSMessagingServiceManager::getMessagingServices(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-               const JSValueRef arguments[], JSValueRef* exception) 
+
+    JSClassRef JSMessagingServiceManager::m_jsClassRef = NULL;
+
+    JSClassDefinition JSMessagingServiceManager::m_classInfo = {
+        0,
+        kJSClassAttributeNone,
+        "Messaging",
+        NULL,
+        m_property,
+        m_function,
+        initialize,
+        finalize,
+        NULL, //hasProperty,
+        NULL, //getProperty,
+        NULL, //setProperty,
+        NULL, //deleteProperty,
+        NULL, //getPropertyNames,
+        NULL,
+        NULL,
+        hasInstance,
+        NULL
+    };
+
+    JSStaticValue JSMessagingServiceManager::m_property[] =
+    {
+           { 0, 0, 0, 0 }
+    };
+
+    JSStaticFunction JSMessagingServiceManager::m_function[] = {
+            { "getMessageServices", JSMessagingServiceManager::getMessagingServices, kJSPropertyAttributeNone },
+            { 0, 0, 0 }
+    };
+
+    const JSClassRef JSMessagingServiceManager::getClassRef() {
+        if (!m_jsClassRef) {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+        }
+        return m_jsClassRef;
+    }
+
+    void JSMessagingServiceManager::initialize(JSContextRef context, JSObjectRef object) {
+        LogDebug("creation messaging instance");
+
+        JSMessagingServiceManagerPriv *priv = static_cast<JSMessagingServiceManagerPriv*>(JSObjectGetPrivate(object));
+        if (priv == NULL)
+        {
+            IMessagingServiceManagerPtr MessagingServiceManager(MessagingFactory::getInstance().getMessagingServiceManager());
+            priv = new JSMessagingServiceManagerPriv( context, MessagingServiceManager);
+
+            if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+                LogError("Object can't store private data.");
+                delete priv;
+            }
+        }
+        else
+        {
+            LogDebug("already exist");
+            LogDebug("global context=" << priv->getContext());
+        }
+
+    }
+
+    void JSMessagingServiceManager::finalize(JSObjectRef object) {
+        LogDebug("enter");
+        JSMessagingServiceManagerPriv* priv = static_cast<JSMessagingServiceManagerPriv*>(JSObjectGetPrivate(object));
+        MessagingListener::getInstance().deregisterMessageReceivedEmitter();
+
+        if (priv) {
+            JSObjectSetPrivate(object, NULL);
+            delete priv;  // object will be deleted, but used to show that private object is deleted
+        }
+        LogDebug("Leave");
+
+    }
+
+    bool JSMessagingServiceManager::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
+        return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    }
+
+    JSValueRef JSMessagingServiceManager::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+    {
+        return JSValueMakeUndefined(context);
+    }
+
+JSValueRef JSMessagingServiceManager::getMessagingServices(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-               LogInfo("<<<");
-               JSMessagingServiceManagerPriv* priv = static_cast<JSMessagingServiceManagerPriv*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Null pointer");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                          JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);         
-               }
-
-               JSContextRef gContext = priv->getContext();             
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-               Validator check(context, exception);
-
-               if (argumentCount < 2) {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               
-               LogInfo(">>> argument count : " << argumentCount);
-               int messagingType = -1;
-               int accountId = -1;
-               bool accountIdFlag = false;
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);     //create callback manager
-               callbackManager->setObject(thisObject);
-               
-               Try{
-
-                       // argu 1. message type (mandatory)
-                       if (JSValueIsString(context, arguments[0]))
-                               messagingType = converter->toMessageType(arguments[0]);
-                       else
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-                       
-                       //argu 2. success callback.
-                       if ( check.isCallback(arguments[1]))
-                       {
-                               callbackManager->setOnSuccess(converter->toFunction(arguments[1]));
-                       }
-                       else
-                       {
-                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-                       }
-                       //argu 3. error callback (optional & nullable)
-                       if ( argumentCount > 2)
-                       {
-                               if ( check.isCallback(arguments[2]))
-                                       callbackManager->setOnError(arguments[2]);
-                               else if(check.isNullOrUndefined(arguments[2]))
-                                       callbackManager->setOnError(NULL);
-                               else
-                                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-                       }       
-                       //arg 4. optional account ID
-                       if ( argumentCount > 3)
-                       {
-                               if(Validator(context).isNullOrUndefined(arguments[3]))  //nullable
-                               {
-                                       LogDebug("account ID is Null or Undefined");
-                               }
-                               else
-                               {
-                                       accountId = converter->toInt(arguments[3]);
-                                       LogDebug("acount Id : " << accountId );
-                                       accountIdFlag = true;
-                               }
-                       }
-               }
-               Catch (WrtDeviceApis::Commons::InvalidArgumentException)
-               {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch (WrtDeviceApis::Commons::Exception)
-               {
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-               
-               try {
-                       LogDebug("Messaging Service Type =" << messagingType);
-
-                       // JSCallbackManager contains function pointers of successCallback and errorCallback.
-                       // The function pointers is be using to return results to Javascriptcore.  So JSCallbackManager should be executed by main thread.
-       
-                       EventGetMessagingServicePtr event(new EventGetMessagingService());      //create event          
-                       
-                       IMessagingServiceManagerPtr messagingServiceManager(priv->getObject());
-                       
-                       event->setPrivateData(StaticPointerCast<IEventPrivateData> (callbackManager));  //callback manager
-                       event->setForAsynchronousCall(&MessagingController::getInstance());
-
-                       event->setEventType(EventGetMessagingService::MESSAGING_SERVICE_MANAGER_EVENT_TYPE_ALL);
-                       if (accountIdFlag)
-                       {
-                               if ( accountId > 0 )            //vaild account id must be positive number.
-                               {
-                                       event->setAccountID(accountId);
-                               }
-                               else
-                               {       // invaild value.
-                                       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
-                                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
-                                       return JSValueMakeUndefined(context);
-                               }
-                       }
-                       event->setMessagingServiceType(messagingType);
-
-                       messagingServiceManager->getMessagingServiceManager(event);     //call postEvent
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext); 
-                       return makePendingOperation(gContext, event);
-               }
-               Catch(WrtDeviceApis::Commons::Exception)
-               {
-                       return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-
-//             LogInfo(">>>");
-//             return JSValueMakeUndefined(context);
+    LogDebug("Entered");
+
+    JSMessagingServiceManagerPriv* priv = static_cast<JSMessagingServiceManagerPriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    JSContextRef gContext = priv->getContext();
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); //create callback manager
+    callbackManager->setObject(thisObject);
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+        int messagingType = converter->toMessageType(validator.toString(0));
+        callbackManager->setOnSuccess(validator.toFunction(1));
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        LogDebug("Messaging Service Type: " << messagingType);
+
+        // JSCallbackManager contains function pointers of successCallback and errorCallback.
+        // The function pointers is be using to return results to Javascriptcore.  So JSCallbackManager should be executed by main thread.
+
+        EventGetMessagingServicePtr event(new EventGetMessagingService()); //create event
+
+        IMessagingServiceManagerPtr messagingServiceManager(priv->getObject());
+
+        event->setPrivateData(StaticPointerCast<IEventPrivateData> (callbackManager)); //callback manager
+        event->setForAsynchronousCall(&MessagingController::getInstance());
+
+        event->setEventType(EventGetMessagingService::MESSAGING_SERVICE_MANAGER_EVENT_TYPE_ALL);
+
+        event->setMessagingServiceType(messagingType);
+
+        messagingServiceManager->getMessagingServiceManager(event); //call postEvent
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
 }
 
 
index f715777..32e34ac 100644 (file)
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>                                   
-#include <CommonsJavaScript/JSDOMExceptionFactory.h>           
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
 #include <CommonsJavaScript/SecurityExceptions.h>
 
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
 
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
 #include "MessagingErrorMsg.h"
 #include "MessageAsyncCallbackManager.h"
 #include "MessageFilterConverter.h"
@@ -55,1786 +59,1314 @@ using namespace DeviceAPI::Common;
 namespace DeviceAPI {
 namespace Messaging {
 
-       JSClassRef JSMessagingStorage::m_jsClassRef = NULL;
-
-       JSClassDefinition JSMessagingStorage::m_classInfo = 
-       {
-               0,
-               kJSClassAttributeNone,
-               "messageStorage",
-               NULL,
-               NULL,
-               m_function,
-               initialize,
-               finalize,
-               NULL, //hasProperty,
-               NULL, //getProperty,
-               NULL, //setProperty,
-               NULL, //deleteProperty,Geolocation
-               NULL, //getPropertyNames,
-               NULL,
-               NULL,
-               hasInstance,
-               NULL
-       };
-
-       JSStaticFunction JSMessagingStorage::m_function[] = 
-       {
-                       { "addDraftMessage",                    JSMessagingStorage::addDraftMessage,                                     kJSPropertyAttributeNone },            
-                       { "findMessages",                       JSMessagingStorage::findMessages,                                        kJSPropertyAttributeNone },
-                       { "removeMessages",                     JSMessagingStorage::removeMessages,                      kJSPropertyAttributeNone },
-                       { "updateMessages",                     JSMessagingStorage::updateMessages,                      kJSPropertyAttributeNone },
-                       { "findConversations",                  JSMessagingStorage::findConversations,                   kJSPropertyAttributeNone },
-                       { "removeConversations",                JSMessagingStorage::removeConversations,                         kJSPropertyAttributeNone },
-                       { "findFolders",                                JSMessagingStorage::findFolders,                                 kJSPropertyAttributeNone },
-                       { "addMessagesChangeListener",  JSMessagingStorage::addMessagesChangeListener,   kJSPropertyAttributeNone },
-                       { "addConversationsChangeListener",     JSMessagingStorage::addConversationsChangeListener,      kJSPropertyAttributeNone },
-                       { "addFoldersChangeListener",   JSMessagingStorage::addFoldersChangeListener,    kJSPropertyAttributeNone },                    
-                       { "removeChangeListener",                               JSMessagingStorage::removeChangeListener,                                kJSPropertyAttributeNone },
-                       { 0, 0, 0 }
-       };
-
-       const JSClassRef JSMessagingStorage::getClassRef() 
-       {
-               if (!m_jsClassRef) 
-               {
-                       m_jsClassRef = JSClassCreate(&m_classInfo);
-               }
-               return m_jsClassRef;
-       }
-
-       void JSMessagingStorage::initialize(JSContextRef context, JSObjectRef object) 
-       {
-               LogDebug("creation messaging instance");
-       }
-
-       void JSMessagingStorage::finalize(JSObjectRef object) 
-       {
-               LogDebug("enter");
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(object));
-               if (priv)
-               {
-                       LogDebug("deleting private object (messaging)");
-                       // for messaging object, private object is shared pointer, so will be deleted automatically
-                       delete priv;
-                       // object will be deleted, but used to show that private object is deleted
-                       JSObjectSetPrivate(object, NULL);
-               }
-       }
-
-       bool JSMessagingStorage::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) 
-       {
-               return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-       }
-
-       JSValueRef JSMessagingStorage::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
-       {
-               LogDebug("<<< ");
-               JSValueRef retVal = NULL;
-
-               Try
-               {
-                       Converter convert(context);
-                       if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_INBOX")) 
-                       {
-                               LogDebug("FOLDER_INBOX" << ":" << "1");
-                               retVal = convert.toJSValueRef(INBOX);
-                       }
-                       else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_OUTBOX")) 
-                       {
-                               LogDebug("FOLDER_OUTBOX" << ":" << "2");
-                               retVal = convert.toJSValueRef(OUTBOX);
-                       }
-                       else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_DRAFTS")) 
-                       {
-                               LogDebug("FOLDER_DRAFTS" << ":" << "3");
-                               retVal = convert.toJSValueRef(DRAFTBOX);
-                       }
-                       else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_SENTBOX")) 
-                       {
-                               LogDebug("FOLDER_SENTBOX" << ":" << "4");
-                               retVal = convert.toJSValueRef(SENTBOX);
-                       }
-                       else
-                       {
-                               retVal = JSValueMakeUndefined(context);
-                       }
-               }
-               Catch (WrtDeviceApis::Commons::Exception)
-               {
-                       LogError("Exception: " << _rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                          JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-
-               LogDebug(">>>");
-               return retVal;
-       }
-
-       JSValueRef JSMessagingStorage::addDraftMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception) 
-       {
-
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_DRAFT_MESSAGE]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-               
-               Try
-               {
-                       EventAddDraftMessagePtr event(new EventAddDraftMessage());
-
-                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  // Message object
-                       {
-                               if(JSValueIsObject(context, arguments[0]) && !JSIsArrayValue(context, arguments[0]) && (!Validator(context).isNullOrUndefined(arguments[0])))
-                               {
-                                       event->msg = converter->toIMessage(arguments[0]);
-                               }
-                               else    // NOT nullable 
-                               {
-                                       LogDebug("Invalid argument exception");
-                                       Throw(ConversionException);                     
-                               }
-                       }               
-                       if(argumentCount >= 2)  // successCallback
-                       {
-                               if(Validator(context).isCallback(arguments[1]))
-                               {
-                                       onSuccessForCbm = arguments[1];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[1]))    //nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 3)  //optional ErrorCallback? errorCallback
-                       {       
-                               if(Validator(context).isCallback(arguments[2]))
-                               {
-                                       onErrorForCbm = arguments[2];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[2]))    //nullable
-                               {
-                                       LogDebug("ErrorCallback type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                               callbackManager->setOnError(onErrorForCbm);
-                               callbackManager->setObject(thisObject);
-                       }
-               
-                       event->setIndex(objectPriv->getIndex());
-                       event->setType(objectPriv->getType());
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
-                       event->setForAsynchronousCall(&MessagingListener::getInstance());
-
-                       ReqReceiverMessageSingleton::Instance().addDraftMessage(event);
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
-
-                       return makePendingOperation(context, event);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError(">>> UnknownException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-
-//             LogError(">>> JSValueMakeNull");
-//             return JSValueMakeNull(context);
-                               
-       
-       }
-
-
-       JSValueRef JSMessagingStorage::findMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception)
-       {
-
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_MESSAGES]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-               
-               Try
-               {
-                       EventQueryMessagesPtr event(new EventQueryMessages());
-                       
-                       MessageMessagesFilterConverterFactory::ConverterType filterConverter =
-                                       MessageMessagesFilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 2)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  //optional AbstractFilter? filter
-                       {
-                               if(JSValueIsObject(context, arguments[0]))
-                               {
-                                       DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
-                                       event->setFilter(filter);
-                               }
-                               else    // NOT nullable 
-                               {
-                                       LogDebug("Filter type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 2)  // successCallback
-                       {
-                               if(Validator(context).isCallback(arguments[1]))
-                               {
-                                       onSuccessForCbm = arguments[1];
-                               }
-                               else // NOT nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 3)  //optional ErrorCallback? errorCallback
-                       {       
-                               if(Validator(context).isCallback(arguments[2]))
-                               {
-                                       onErrorForCbm = arguments[2];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[2]))    //nullable
-                               {
-                                       LogDebug("ErrorCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 4)  //optional SortMode? sortMode
-                       {
-                               if(JSValueIsObject(context, arguments[3]))
-                               {
-                                       DeviceAPI::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
-                                       event->setSortMode(sortMode);
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[3]))    //nullable
-                               {
-                                       LogDebug("SortMode type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 5)  //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
-                       {
-                               if (!Validator(context).isNullOrUndefined(arguments[4]))
-                               {
-                                       long limit = filterConverter->toULong(arguments[4]);
-                                       event->setLimit(limit);
-                               }
-                       }
-                       if(argumentCount >= 6)  //optional unsigned long? offset JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
-                       {
-                               if (!Validator(context).isNullOrUndefined(arguments[5]))
-                               {
-                                       long offset = filterConverter->toULong(arguments[5]);
-                                       event->setOffset(offset);                                       
-                               }
-                       }
-
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                               callbackManager->setOnError(onErrorForCbm);
-                               callbackManager->setObject(thisObject);
-                       }
-
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
-                       event->setForAsynchronousCall(&MessagingListener::getInstance());
-                       event->setIndex(objectPriv->getIndex());
-                       event->setType(objectPriv->getType());
-
-                       ReqReceiverMessageSingleton::Instance().queryMessages(event);
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
-
-                       LogError(">>>");
-                       return makePendingOperation(context, event);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError(">>> UnknownException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-
-//             LogError(">>> JSValueMakeNull");
-//             return JSValueMakeNull(context);
-       }
-
-       JSValueRef JSMessagingStorage::removeMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception) 
-       {
-
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_MESSAGES]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                       
-               Try 
-               {
-
-                       EventDeleteMessagesPtr event(new EventDeleteMessages());
-                       
-                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-                       JSObjectRef objArg = NULL;
-
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  // Message object
-                       {
-                               if(JSValueIsObject(context, arguments[0]) && JSIsArrayValue(context, arguments[0]) && (!Validator(context).isNullOrUndefined(arguments[0])) )
-                               {
-                                       objArg = converter->toJSObjectRef(arguments[0]);
-                                       if(JSGetArrayLength(context, objArg) == 0)
-                                       {
-                                               LogDebug("this is empty message");
-                                               Throw(ConversionException);                                     
-                                       }                                       
-                               }
-                               else
-                               {
-                                       LogDebug("Invalid argument exception");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 2)  // successCallback
-                       {
-                               if(Validator(context).isCallback(arguments[1]))
-                               {
-                                       onSuccessForCbm = arguments[1];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[1]))    //nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 3)  //optional ErrorCallback? errorCallback
-                       {       
-                               if(Validator(context).isCallback(arguments[2]))
-                               {
-                                       onErrorForCbm = arguments[2];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[2]))    //nullable
-                               {
-                                       LogDebug("ErrorCallback type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                               callbackManager->setOnError(onErrorForCbm);
-                               callbackManager->setObject(thisObject);
-                       }
-
-                       std::vector<IMessagePtr> msgs;
-                                               
-                       LogDebug("array length "<<JSGetArrayLength(context, objArg));
-                       for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++)
-                       {
-                               JSValueRef element = JSGetArrayElement(context, objArg, i);
-                               JSObjectRef arg = JSValueToObject(context, element, NULL);
-                               IMessagePtr msg = converter->toIMessage(arg);
-                               msgs.push_back(msg);
-                       }
-
-                       event->msgArray = msgs;
-
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
-                       event->setForAsynchronousCall(&MessagingListener::getInstance());
-                       event->setIndex(objectPriv->getIndex());
-                       event->setType(objectPriv->getType());
-
-                       ReqReceiverMessageSingleton::Instance().deleteMessages(event);
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
-
-                       return makePendingOperation(context, event);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException)
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);                    
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError(">>> UnknownException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-               
-//             return JSValueMakeNull(context);
-       }
-
-       JSValueRef JSMessagingStorage::updateMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception) 
-       {
-
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_UPDATE_MESSAGES]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                       
-               Try 
-               {
-
-                       EventUpdateMessagesPtr event(new EventUpdateMessages());
-
-                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-                       JSObjectRef objArg = NULL;
-
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  // Message object
-                       {
-                               if(JSValueIsObject(context, arguments[0]) && JSIsArrayValue(context, arguments[0]) && (!Validator(context).isNullOrUndefined(arguments[0])))
-                               {
-                                       objArg = converter->toJSObjectRef(arguments[0]);
-                                       if(JSGetArrayLength(context, objArg) == 0)
-                                       {
-                                               LogDebug("this is empty message");
-                                               Throw(ConversionException);                                     
-                                       }
-                               }
-                               else
-                               {
-                                       LogDebug("Invalid argument exception");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 2)  // successCallback
-                       {
-                               if(Validator(context).isCallback(arguments[1]))
-                               {
-                                       onSuccessForCbm = arguments[1];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[1]))    //nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 3)  //optional ErrorCallback? errorCallback
-                       {       
-                               if(Validator(context).isCallback(arguments[2]))
-                               {
-                                       onErrorForCbm = arguments[2];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[2]))    //nullable
-                               {
-                                       LogDebug("ErrorCallback type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                               callbackManager->setOnError(onErrorForCbm);
-                               callbackManager->setObject(thisObject);
-                       }
-
-                       std::vector<IMessagePtr> msgs;
-                       LogDebug("array length "<<JSGetArrayLength(context, objArg));
-                       for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++)
-                       {
-                               JSValueRef element = JSGetArrayElement(context, objArg, i);
-                               JSObjectRef arg = JSValueToObject(context, element, NULL);
-                               IMessagePtr msg = converter->toIMessage(arg);
-                               msgs.push_back(msg);
-                       }
-
-                       event->msgArray = msgs;
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
-                       event->setForAsynchronousCall(&MessagingListener::getInstance());
-                       
-                       event->setIndex(objectPriv->getIndex());
-                       event->setType(objectPriv->getType());
-
-                       ReqReceiverMessageSingleton::Instance().updateMessages(event);
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
-
-                       return makePendingOperation(context, event);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError(">>> UnknownException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-//             return JSValueMakeNull(context);
-       }
-
-       JSValueRef JSMessagingStorage::findConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception)
-       {
-
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_CONVERSATIONS]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                       
-               Try 
-               {
-                       EventQueryConversationsPtr event(new EventQueryConversations());
-                       
-                       MessageConversationsFilterConverterFactory::ConverterType filterConverter =
-                                       MessageConversationsFilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 2)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  //optional AbstractFilter? filter
-                       {
-                               if(JSValueIsObject(context, arguments[0]))
-                               {
-                                       DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
-                                       event->setFilter(filter);
-                               }
-                               else    // NOT nullable 
-                               {
-                                       LogDebug("Filter type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 2)  // successCallback
-                       {
-                               if(Validator(context).isCallback(arguments[1]))
-                               {
-                                       onSuccessForCbm = arguments[1];
-                               }
-                               else // NOT nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 3)  //optional ErrorCallback? errorCallback
-                       {
-                               if(Validator(context).isCallback(arguments[2]))
-                               {
-                                       onErrorForCbm = arguments[2];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[2]))    //nullable
-                               {
-                                       LogDebug("ErrorCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 4)  //optional SortMode? sortMode
-                       {
-                               if(JSValueIsObject(context, arguments[3]))
-                               {
-                                       DeviceAPI::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
-                                       event->setSortMode(sortMode);
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[3]))    //nullable
-                               {
-                                       LogDebug("SortMode type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 5)  //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
-                       {
-                               if (!Validator(context).isNullOrUndefined(arguments[4]))
-                               {
-                                       long limit = filterConverter->toULong(arguments[4]);
-                                       event->setLimit(limit);
-                               }
-                       }
-                       if(argumentCount >= 6)  //optional unsigned long? offset JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
-                       {
-                               if (!Validator(context).isNullOrUndefined(arguments[5]))
-                               {
-                                       long offset = filterConverter->toULong(arguments[5]);
-                                       event->setOffset(offset);
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                               callbackManager->setOnError(onErrorForCbm);
-                               callbackManager->setObject(thisObject);
-                       }
-
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
-                       event->setForAsynchronousCall(&MessagingListener::getInstance());
-                       event->setIndex(objectPriv->getIndex());
-                       event->setType(objectPriv->getType());
-
-                       ReqReceiverMessageSingleton::Instance().queryConversations(event);
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
-
-                       return makePendingOperation(context, event);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError(">>> UnknownException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-
-//             LogError(">>> JSValueMakeNull");
-//             return JSValueMakeNull(context);
-       }
-
-       JSValueRef JSMessagingStorage::removeConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception)
-       {
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                               MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-                       
-               Try 
-               {
-
-                       EventDeleteConversationsPtr event(new EventDeleteConversations());
-                       
-                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-                       std::vector<IConversationPtr> deleteConversationArray;
-
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  // Message object
-                       {
-                               if(JSValueIsObject(context, arguments[0]) && JSIsArrayValue(context, arguments[0]) && (!Validator(context).isNullOrUndefined(arguments[0])))
-                               {
-                                       deleteConversationArray = converter->toVectorOfConversation(arguments[0]);                              
-                               }
-                               else
-                               {
-                                       LogDebug("Invalid argument exception");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 2)  // successCallback
-                       {
-                               if(Validator(context).isCallback(arguments[1]))
-                               {
-                                       onSuccessForCbm = arguments[1];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[1]))    //nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 3)  //optional ErrorCallback? errorCallback
-                       {       
-                               if(Validator(context).isCallback(arguments[2]))
-                               {
-                                       onErrorForCbm = arguments[2];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[2]))    //nullable
-                               {
-                                       LogDebug("ErrorCallback type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                               callbackManager->setOnError(onErrorForCbm);
-                               callbackManager->setObject(thisObject);
-                       }
-
-                       event->setConversations(deleteConversationArray);
-                       event->setFilterUsing(false);
-
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
-                       event->setForAsynchronousCall(&MessagingListener::getInstance());
-                       event->setIndex(objectPriv->getIndex());
-                       event->setType(objectPriv->getType());
-
-                       ReqReceiverMessageSingleton::Instance().deleteConversations(event);
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
-
-                       return makePendingOperation(context, event);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError(">>> UnknownException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-//             return JSValueMakeNull(context);
-       }
-
-       JSValueRef JSMessagingStorage::findFolders(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception)
-       {
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_FOLDERS]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-               
-               Try
-               {
-                       EventQueryFoldersPtr event(new EventQueryFolders());
-                       
-                       MessageFoldersFilterConverterFactory::ConverterType filterConverter =
-                                       MessageFoldersFilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-       
-                       if(argumentCount < 2)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  //optional AbstractFilter? filter
-                       {
-                               if(JSValueIsObject(context, arguments[0]))
-                               {
-                                       DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
-                                       event->setFilter(filter);
-                               }
-                               else    // NOT nullable 
-                               {
-                                       LogDebug("Filter type is mismatched.");
-                                       Throw(ConversionException);             
-                               }
-                       }
-                       if(argumentCount >= 2)  // successCallback
-                       {
-                               if(Validator(context).isCallback(arguments[1]))
-                               {
-                                       onSuccessForCbm = arguments[1];
-                               }
-                               else // NOT nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-                       if(argumentCount >= 3)  //optional ErrorCallback? errorCallback
-                       {       
-                               if(Validator(context).isCallback(arguments[2]))
-                               {
-                                       onErrorForCbm = arguments[2];
-                               }
-                               else if(!Validator(context).isNullOrUndefined(arguments[2]))    //nullable
-                               {
-                                       LogDebug("ErrorCallback type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                               callbackManager->setOnError(onErrorForCbm);
-                               callbackManager->setObject(thisObject);
-                       }
-
-                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
-                       event->setForAsynchronousCall(&MessagingListener::getInstance());
-                       event->setIndex(objectPriv->getIndex());
-                       event->setType(objectPriv->getType());
-
-                       ReqReceiverMessageSingleton::Instance().queryFolders(event);
-                       MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
-
-                       return makePendingOperation(context, event);
-
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::NullPointerException) 
-               {
-                       LogError(">>> TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError(">>> UnknownException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-               }
-
-//             return JSValueMakeNull(context);
-       }
-
-       JSValueRef JSMessagingStorage::addMessagesChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception) 
-       {
-
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
-               
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-
-               Try
-               {
-                       MessageMessagesChangeFilterConverterFactory::ConverterType filterConverter =
-                                       MessageMessagesChangeFilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL;
-
-                       OnMessagesChanged functionResult;
-                       int funtionIndex = -1;
-                       
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  // successCallback
-                       {
-                               if(!Validator(context).isNullOrUndefined(arguments[0]))
-                               {
-                                       functionResult = converter->toMessageMultifunctions(arguments[0]);
-                                       funtionIndex = functionResult.functionIndex;
-                                       
-                                       onSuccessForCbm = functionResult.messagesAdded;
-                                       messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
-                                       messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
-                               }
-                               else // NOT nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-
-                       if(funtionIndex < 0)
-                       {
-                               LogError("funtionIndex is not valid");
-                               Throw(ConversionException);                     
-                       }
-
-                       EventOnMessagingStorageChangesPrivateDataPtr privData(
-                               new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
-                       
-                       if(argumentCount >= 2)  //optional AbstractFilter? filter
-                       {
-                               if(JSValueIsObject(context, arguments[1]))
-                               {
-                                       DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
-                                       privData->setFilter(filter);
-                               }
-                               else    // NOT nullable 
-                               {
-                                       LogDebug("Filter type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                       }
-
-                       privData->setIndex(objectPriv->getIndex());
-                       privData->setType(objectPriv->getType());                       
-
-                       MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
-
-                       // add to map and return index
-                       long id = MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex);
-                       MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, id));
-                       IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
-                       MessageListenerManagerSingleton::Instance().registerListener(listenerItem, priv->getContext());
-                       
-                       return JSValueMakeNumber(context, id);
-
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError("Error on conversion");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
-                       LogError("Invalid argument exception");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::UnsupportedException) 
-               {
-                       LogError("Unsupported exception");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported type
-               }
-               Catch(WrtDeviceApis::Commons::AlreadyInUseException) 
-               {
-                       LogError("Already in use exception");
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError("not registered for incoming message notifications");
-               }
-
-               return JSValueMakeUndefined(context);
-       }
-
-       JSValueRef JSMessagingStorage::addConversationsChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception) 
-       {
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
-               
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-
-               Try
-               {
-                       MessageConversationsFilterConverterFactory::ConverterType filterConverter =
-                                       MessageConversationsFilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL;
-
-                       OnMessagesChanged functionResult;
-                       int funtionIndex = -1;
-                       
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  // successCallback
-                       {
-                               if(!Validator(context).isNullOrUndefined(arguments[0]))
-                               {
-                                       functionResult = converter->toMessageMultifunctions(arguments[0]);
-                                       funtionIndex = functionResult.functionIndex;
-                                       
-                                       onSuccessForCbm = functionResult.messagesAdded;
-                                       messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
-                                       messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
-                               }
-                               else // NOT nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-
-                       if(funtionIndex < 0)
-                       {
-                               LogError("funtionIndex is not valid");
-                               Throw(ConversionException);                     
-                       }
-
-                       EventOnMessagingStorageChangesPrivateDataPtr privData(
-                               new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
-                       
-                       if(argumentCount >= 2)  //optional AbstractFilter? filter
-                       {
-                               if(JSValueIsObject(context, arguments[1]))
-                               {
-                                       DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
-                                       privData->setFilter(filter);
-                               }
-                               else    // NOT nullable 
-                               {
-                                       LogDebug("Filter type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                       }
-
-                       privData->setIndex(objectPriv->getIndex());
-                       privData->setType(objectPriv->getType());                       
-               
-                       MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
-
-                       long id = MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex);
-                       MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, id));
-                       IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
-                       MessageListenerManagerSingleton::Instance().registerListener(listenerItem, priv->getContext());
-
-                       // add to map and return index
-                       return JSValueMakeNumber(context, id);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError("Error on conversion");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError("Invalid argument exception");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::UnsupportedException) 
-               {
-                       LogError("Unsupported exception");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported type
-               }
-               Catch(WrtDeviceApis::Commons::AlreadyInUseException) 
-               {
-                       LogError("Already in use exception");
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError("not registered for incoming message notifications");
-               }
-
-               return JSValueMakeUndefined(context);
-       }
-
-
-       JSValueRef JSMessagingStorage::addFoldersChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
-                       const JSValueRef arguments[], JSValueRef* exception) 
-       {
-
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
-               
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-
-               Try
-               {
-
-                       MessageFoldersFilterConverterFactory::ConverterType filterConverter =
-                                       MessageFoldersFilterConverterFactory::getConverter(context);
-
-                       JSValueRef onSuccessForCbm = NULL;
-
-                       OnMessagesChanged functionResult;
-                       int funtionIndex = -1;
-                       
-                       if((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL))
-                       {
-                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
-                       }
-                       else
-                       {
-                               if(objectPriv->getType() == EMAIL)
-                               {
-                                       if(objectPriv->getIndex()  < 1)
-                                       {
-                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
-                                       }
-                               }
-                       }
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  // successCallback
-                       {
-                               if(!Validator(context).isNullOrUndefined(arguments[0]))
-                               {
-                                       functionResult = converter->toMessageMultifunctions(arguments[0]);
-                                       funtionIndex = functionResult.functionIndex;
-                                       
-                                       onSuccessForCbm = functionResult.messagesAdded;
-                                       messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
-                                       messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
-                               }
-                               else // NOT nullable
-                               {
-                                       LogDebug("SuccessCallback type is mismatched.");
-                                       Throw(ConversionException);
-                               }
-                       }
-
-                       if(funtionIndex < 0)
-                       {
-                               LogError("funtionIndex is not valid");
-                               Throw(ConversionException);                     
-                       }
-
-                       EventOnMessagingStorageChangesPrivateDataPtr privData(
-                               new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
-                       
-                       if(argumentCount >= 2)  //optional AbstractFilter? filter
-                       {
-                               if(JSValueIsObject(context, arguments[1]))
-                               {
-                                       DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
-                                       privData->setFilter(filter);
-                               }
-                               else    // NOT nullable 
-                               {
-                                       LogDebug("Filter type is mismatched.");
-                                       Throw(ConversionException);                     
-                               }
-                       }
-                       if(callbackManager)
-                       {
-                               callbackManager->setOnSuccess(onSuccessForCbm);
-                       }
-
-                       privData->setIndex(objectPriv->getIndex());
-                       privData->setType(objectPriv->getType());
-
-                       MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
-
-                       long id = MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex);
-                       MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, id));
-                       IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
-                       MessageListenerManagerSingleton::Instance().registerListener(listenerItem, priv->getContext());
-
-                       // add to map and return index
-                       return JSValueMakeNumber(context, id);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError("Error on conversion");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError("Invalid argument exception");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               Catch(WrtDeviceApis::Commons::UnsupportedException) 
-               {
-                       LogError("Unsupported exception");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported type
-               }
-               Catch(WrtDeviceApis::Commons::AlreadyInUseException) 
-               {
-                       LogError("Already in use exception");
-               }
-               Catch(WrtDeviceApis::Commons::PlatformException) 
-               {
-                       LogError("not registered for incoming message notifications");
-               }
-
-               return JSValueMakeUndefined(context);
-       }
-
-       JSValueRef JSMessagingStorage::removeChangeListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, 
-                       const JSValueRef arguments[], JSValueRef* exception)
-       {
-               LogDebug("<<<");
-
-               //check permission.
-               AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
-                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER]);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
-
-               long handler = -1;
-               
-               if (!priv) 
-               {
-                       LogDebug("priv is NULL.");
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
-
-               if (!objectPriv)
-               {
-                       LogDebug("objectPriv is NULL.");                
-                       return JSTizenExceptionFactory::postException(
-                               context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-
-               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
-               callbackManager = JSCallbackManager::createObject(priv->getContext());
-
-               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-
-               Try 
-               {
-                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-
-                       if(argumentCount < 1)
-                       {
-                               LogDebug("argumentCount is too few");
-                               Throw(ConversionException);
-                       }
-                       if(argumentCount >= 1)  //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
-                       {
-                               if (!Validator(context).isNullOrUndefined(arguments[0]))
-                               {
-                                       if (!JSValueIsNumber(context, arguments[0]))
-                                       {
-                                               Throw(ConversionException);                                     
-                                       }
-                                       handler = filterConverter->toLong(arguments[0]);
-                               }
-                               else
-                               {
-                                       Throw(ConversionException);
-                               }
-                       }               
-
-                       MessagingListener::getInstance().removeIncomingMsgCallback(handler, objectPriv->getType(), objectPriv->getIndex());
-
-                       MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, objectPriv->getIndex()));
-                       IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
-                       MessageListenerManagerSingleton::Instance().unregisterListener(listenerItem);
-               }
-               Catch(WrtDeviceApis::Commons::ConversionException) 
-               {
-                       LogError("conversion error");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
-               }
-               Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
-               {
-                       LogError(">>> InvalidValuesException");
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
-               }
-               return JSValueMakeUndefined(context);
-       }
+JSClassRef JSMessagingStorage::m_jsClassRef = NULL;
+
+JSClassDefinition JSMessagingStorage::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    "MessageStorage",
+    NULL,
+    NULL,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL,
+    NULL,
+    hasInstance,
+    NULL
+};
+
+JSStaticFunction JSMessagingStorage::m_function[] =
+{
+        { "addDraftMessage", JSMessagingStorage::addDraftMessage, kJSPropertyAttributeNone },
+        { "findMessages", JSMessagingStorage::findMessages, kJSPropertyAttributeNone },
+        { "removeMessages", JSMessagingStorage::removeMessages, kJSPropertyAttributeNone },
+        { "updateMessages", JSMessagingStorage::updateMessages, kJSPropertyAttributeNone },
+        { "findConversations", JSMessagingStorage::findConversations, kJSPropertyAttributeNone },
+        { "removeConversations", JSMessagingStorage::removeConversations, kJSPropertyAttributeNone },
+        { "findFolders", JSMessagingStorage::findFolders, kJSPropertyAttributeNone },
+        { "addMessagesChangeListener", JSMessagingStorage::addMessagesChangeListener, kJSPropertyAttributeNone },
+        { "addConversationsChangeListener", JSMessagingStorage::addConversationsChangeListener, kJSPropertyAttributeNone },
+        { "addFoldersChangeListener", JSMessagingStorage::addFoldersChangeListener, kJSPropertyAttributeNone },
+        { "removeChangeListener", JSMessagingStorage::removeChangeListener, kJSPropertyAttributeNone },
+        { 0, 0, 0 }
+};
+
+const JSClassRef JSMessagingStorage::getClassRef()
+{
+    if (!m_jsClassRef)
+    {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+void JSMessagingStorage::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug("creation messaging instance");
+}
+
+void JSMessagingStorage::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(object));
+    if (priv)
+    {
+        LogDebug("deleting private object (messaging)");
+        // for messaging object, private object is shared pointer, so will be deleted automatically
+        delete priv;
+        // object will be deleted, but used to show that private object is deleted
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+bool JSMessagingStorage::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+#if 0
+    JSValueRef JSMessagingStorage::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+    {
+        LogDebug("<<< ");
+        JSValueRef retVal = NULL;
+
+        Try
+        {
+            Converter convert(context);
+            if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_INBOX"))
+            {
+                LogDebug("FOLDER_INBOX" << ":" << "1");
+                retVal = convert.toJSValueRef(INBOX);
+            }
+            else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_OUTBOX"))
+            {
+                LogDebug("FOLDER_OUTBOX" << ":" << "2");
+                retVal = convert.toJSValueRef(OUTBOX);
+            }
+            else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_DRAFTS"))
+            {
+                LogDebug("FOLDER_DRAFTS" << ":" << "3");
+                retVal = convert.toJSValueRef(DRAFTBOX);
+            }
+            else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_SENTBOX"))
+            {
+                LogDebug("FOLDER_SENTBOX" << ":" << "4");
+                retVal = convert.toJSValueRef(SENTBOX);
+            }
+            else
+            {
+                retVal = JSValueMakeUndefined(context);
+            }
+        }
+        Catch (WrtDeviceApis::Commons::Exception)
+        {
+            LogError("Exception: " << _rethrown_exception.GetMessage());
+            return JSTizenExceptionFactory::postException(context, exception,
+               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+        }
+
+        LogDebug(">>>");
+        return retVal;
+    }
+#endif
+
+JSValueRef JSMessagingStorage::addDraftMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_DRAFT_MESSAGE]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+    if (!callbackManager) {
+        LogError("callbackManager is NULL.");
+        DeviceAPI::Common::UnknownException err("callbackManager is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Message ( mandatory )
+        IMessagePtr msg = converter->toIMessage(validator.toObject(0));
+
+        // argu 2. Success callback (optional & nullable)
+        callbackManager->setOnSuccess(validator.toFunction(1, true));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        callbackManager->setObject(thisObject);
+
+        EventAddDraftMessagePtr event(new EventAddDraftMessage());
+
+        FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        event->msg = msg;
+        event->setIndex(objectPriv->getIndex());
+        event->setType(objectPriv->getType());
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+        event->setForAsynchronousCall(&MessagingListener::getInstance());
+
+        ReqReceiverMessageSingleton::Instance().addDraftMessage(event);
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::findMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_MESSAGES]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+    if (!callbackManager) {
+        LogError("callbackManager is NULL.");
+        DeviceAPI::Common::UnknownException err("callbackManager is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        EventQueryMessagesPtr event(new EventQueryMessages());
+
+        MessageMessagesFilterConverterFactory::ConverterType filterConverter =
+                MessageMessagesFilterConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. filter ( mandatory )
+        DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(0));
+        if (!filter) {
+            throw DeviceAPI::Common::TypeMismatchException("Invalid filter.");
+        }
+
+        // argu 2. Success callback ( mandatory )
+        callbackManager->setOnSuccess(validator.toFunction(1));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        callbackManager->setObject(thisObject);
+
+        // argu 4. Sorting mode (optional & nullable)
+        JSValueRef param4 = validator.toJSValueRef(3, true);
+        if ((argumentCount >= 4)
+            && (!JSValueIsNull(context, param4))
+            && (!JSValueIsUndefined(context, param4)))
+        {
+            DeviceAPI::Tizen::SortModePtr sortMode = filterConverter->toSortMode(param4);
+            event->setSortMode(sortMode);
+        }
+
+        // argu 5. limit (optional & nullable)
+        long limit = validator.toULong(4, true, 0);
+
+        // argu 6. offset (optional & nullable)
+        long offset = validator.toULong(5, true, 0);
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        event->setFilter(filter);
+        event->setLimit(limit);
+        event->setOffset(offset);
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+        event->setForAsynchronousCall(&MessagingListener::getInstance());
+        event->setIndex(objectPriv->getIndex());
+        event->setType(objectPriv->getType());
+
+        ReqReceiverMessageSingleton::Instance().queryMessages(event);
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::removeMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_MESSAGES]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+    if (!callbackManager) {
+        LogError("callbackManager is NULL.");
+        DeviceAPI::Common::UnknownException err("callbackManager is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        EventDeleteMessagesPtr event(new EventDeleteMessages());
+
+        FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Messages ( mandatory )
+        std::vector<JSValueRef> jsMsgsArray = validator.toJSValueRefVector(0);
+        std::vector<IMessagePtr> msgs;
+        for (std::vector<JSValueRef>::iterator it = jsMsgsArray.begin() ; it != jsMsgsArray.end(); ++it)
+        {
+            IMessagePtr msg = converter->toIMessage(*it);
+            msgs.push_back(msg);
+        }
+
+        // argu 2. Success callback (optional & nullable)
+        callbackManager->setOnSuccess(validator.toFunction(1,true));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        callbackManager->setObject(thisObject);
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        event->msgArray = msgs;
+
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+        event->setForAsynchronousCall(&MessagingListener::getInstance());
+        event->setIndex(objectPriv->getIndex());
+        event->setType(objectPriv->getType());
+
+        ReqReceiverMessageSingleton::Instance().deleteMessages(event);
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::updateMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_UPDATE_MESSAGES]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+    if (!callbackManager) {
+        LogError("callbackManager is NULL.");
+        DeviceAPI::Common::UnknownException err("callbackManager is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        EventUpdateMessagesPtr event(new EventUpdateMessages());
+
+        FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Messages ( mandatory )
+        std::vector<JSValueRef> jsMsgsArray = validator.toJSValueRefVector(0);
+        std::vector<IMessagePtr> msgs;
+        for (std::vector<JSValueRef>::iterator it = jsMsgsArray.begin() ; it != jsMsgsArray.end(); ++it)
+        {
+            IMessagePtr msg = converter->toIMessage(*it);
+            msgs.push_back(msg);
+        }
+
+        // argu 2. Success callback (optional & nullable)
+        callbackManager->setOnSuccess(validator.toFunction(1,true));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        callbackManager->setObject(thisObject);
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        event->msgArray = msgs;
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+        event->setForAsynchronousCall(&MessagingListener::getInstance());
+
+        event->setIndex(objectPriv->getIndex());
+        event->setType(objectPriv->getType());
+
+        ReqReceiverMessageSingleton::Instance().updateMessages(event);
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::findConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_CONVERSATIONS]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+    if (!callbackManager) {
+        LogError("callbackManager is NULL.");
+        DeviceAPI::Common::UnknownException err("callbackManager is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        EventQueryConversationsPtr event(new EventQueryConversations());
+
+        MessageConversationsFilterConverterFactory::ConverterType filterConverter =
+                MessageConversationsFilterConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. filter ( mandatory )
+        DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(0));
+        if (!filter) {
+            throw DeviceAPI::Common::TypeMismatchException("Invalid filter.");
+        }
+
+        // argu 2. Success callback ( mandatory )
+        callbackManager->setOnSuccess(validator.toFunction(1));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        callbackManager->setObject(thisObject);
+
+        // argu 4. Sorting mode (optional & nullable)
+        JSValueRef param4 = validator.toJSValueRef(3, true);
+        if ((argumentCount >= 4)
+            && (!JSValueIsNull(context, param4))
+            && (!JSValueIsUndefined(context, param4)))
+        {
+            DeviceAPI::Tizen::SortModePtr sortMode = filterConverter->toSortMode(param4);
+            event->setSortMode(sortMode);
+        }
+
+        // argu 5. limit (optional & nullable)
+        long limit = validator.toULong(4, true, 0);
+
+        // argu 6. offset (optional & nullable)
+        long offset = validator.toULong(5, true, 0);
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        event->setFilter(filter);
+        event->setLimit(limit);
+        event->setOffset(offset);
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+        event->setForAsynchronousCall(&MessagingListener::getInstance());
+        event->setIndex(objectPriv->getIndex());
+        event->setType(objectPriv->getType());
+
+        ReqReceiverMessageSingleton::Instance().queryConversations(event);
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::removeConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+            MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+    if (!callbackManager) {
+        LogError("callbackManager is NULL.");
+        DeviceAPI::Common::UnknownException err("callbackManager is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        EventDeleteConversationsPtr event(new EventDeleteConversations());
+
+        FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Messages ( mandatory )
+        std::vector<JSValueRef> jsConvsArray = validator.toJSValueRefVector(0);
+        std::vector<IConversationPtr> deleteConversationArray;
+        for (std::vector<JSValueRef>::iterator it = jsConvsArray.begin() ; it != jsConvsArray.end(); ++it)
+        {
+            IConversationPtr conv = converter->toConversation(*it);
+            deleteConversationArray.push_back(conv);
+        }
+
+        // argu 2. Success callback (optional & nullable)
+        callbackManager->setOnSuccess(validator.toFunction(1,true));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        callbackManager->setObject(thisObject);
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        event->setConversations(deleteConversationArray);
+        event->setFilterUsing(false);
+
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+        event->setForAsynchronousCall(&MessagingListener::getInstance());
+        event->setIndex(objectPriv->getIndex());
+        event->setType(objectPriv->getType());
+
+        ReqReceiverMessageSingleton::Instance().deleteConversations(event);
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::findFolders(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_FOLDERS]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+    if (!callbackManager) {
+        LogError("callbackManager is NULL.");
+        DeviceAPI::Common::UnknownException err("callbackManager is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        EventQueryFoldersPtr event(new EventQueryFolders());
+
+        MessageFoldersFilterConverterFactory::ConverterType filterConverter =
+                MessageFoldersFilterConverterFactory::getConverter(context);
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. filter ( mandatory )
+        DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(0));
+        if (!filter) {
+            throw DeviceAPI::Common::TypeMismatchException("Invalid filter.");
+        }
+
+        // argu 2. Success callback ( mandatory )
+        callbackManager->setOnSuccess(validator.toFunction(1));
+
+        // argu 3. error callback (optional & nullable)
+        callbackManager->setOnError(validator.toFunction(2, true));
+
+        callbackManager->setObject(thisObject);
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        event->setFilter(filter);
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+        event->setForAsynchronousCall(&MessagingListener::getInstance());
+        event->setIndex(objectPriv->getIndex());
+        event->setType(objectPriv->getType());
+
+        ReqReceiverMessageSingleton::Instance().queryFolders(event);
+        MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::NullPointerException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::addMessagesChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
+
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        MessageMessagesChangeFilterConverterFactory::ConverterType filterConverter =
+                MessageMessagesChangeFilterConverterFactory::getConverter(context);
+
+        JSValueRef onSuccessForCbm = NULL;
+
+        OnMessagesChanged functionResult;
+        int funtionIndex = -1;
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Messages Change Callback ( mandatory )
+        functionResult = converter->toMessageMultifunctions(validator.toJSValueRef(0));
+        funtionIndex = functionResult.functionIndex;
+        if(funtionIndex < 0)
+        {
+            throw DeviceAPI::Common::TypeMismatchException("funtionIndex is not valid.");
+        }
+
+        onSuccessForCbm = functionResult.messagesAdded;
+        messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
+        messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
+
+        EventOnMessagingStorageChangesPrivateDataPtr privData(
+            new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        // argu 2. filter ( optional )
+        DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(1));
+        if (filter) {
+            DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(1));
+            privData->setFilter(filter);
+        }
+
+        if(callbackManager)
+        {
+            callbackManager->setOnSuccess(onSuccessForCbm);
+        }
+
+        privData->setIndex(objectPriv->getIndex());
+        privData->setType(objectPriv->getType());
+
+        MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
+
+        // add to map and return index
+        long id = MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex);
+        MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, id));
+        IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
+        MessageListenerManagerSingleton::Instance().registerListener(listenerItem, priv->getContext());
+
+        return JSValueMakeNumber(context, id);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::UnsupportedException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::AlreadyInUseException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::addConversationsChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
+
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        MessageConversationsFilterConverterFactory::ConverterType filterConverter =
+                MessageConversationsFilterConverterFactory::getConverter(context);
+
+        JSValueRef onSuccessForCbm = NULL;
+
+        OnMessagesChanged functionResult;
+        int funtionIndex = -1;
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Messages Change Callback ( mandatory )
+        functionResult = converter->toMessageMultifunctions(validator.toJSValueRef(0));
+        funtionIndex = functionResult.functionIndex;
+        if(funtionIndex < 0)
+        {
+            throw DeviceAPI::Common::TypeMismatchException("funtionIndex is not valid.");
+        }
+
+        onSuccessForCbm = functionResult.messagesAdded;
+        messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
+        messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
+
+        EventOnMessagingStorageChangesPrivateDataPtr privData(
+            new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        // argu 2. filter ( optional )
+        DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(1));
+        if (filter) {
+            DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(1));
+            privData->setFilter(filter);
+        }
+
+        if(callbackManager)
+        {
+            callbackManager->setOnSuccess(onSuccessForCbm);
+        }
+
+        privData->setIndex(objectPriv->getIndex());
+        privData->setType(objectPriv->getType());
+
+        MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
+
+        long id = MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex);
+        MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, id));
+        IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
+        MessageListenerManagerSingleton::Instance().registerListener(listenerItem, priv->getContext());
+
+        // add to map and return index
+        return JSValueMakeNumber(context, id);
+
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::UnsupportedException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::AlreadyInUseException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMessagingStorage::addFoldersChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
+
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        MessageFoldersChangeFilterConverterFactory::ConverterType filterConverter =
+                MessageFoldersChangeFilterConverterFactory::getConverter(context);
+        JSValueRef onSuccessForCbm = NULL;
+
+        OnMessagesChanged functionResult;
+        int funtionIndex = -1;
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. Messages Change Callback ( mandatory )
+        functionResult = converter->toMessageMultifunctions(validator.toJSValueRef(0));
+        funtionIndex = functionResult.functionIndex;
+        if(funtionIndex < 0)
+        {
+            throw DeviceAPI::Common::TypeMismatchException("funtionIndex is not valid.");
+        }
+
+        onSuccessForCbm = functionResult.messagesAdded;
+        messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
+        messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
+
+        EventOnMessagingStorageChangesPrivateDataPtr privData(
+            new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+
+        if ((objectPriv->getType() < SMS) || (objectPriv->getType() > EMAIL)) {
+            throw DeviceAPI::Common::TypeMismatchException("Message type is not SMS or MMS or EMAIL.");
+        }
+
+        if ((objectPriv->getType() == EMAIL) && (objectPriv->getIndex() < 1)) {
+            throw DeviceAPI::Common::TypeMismatchException("serviceId is not defined.");
+        }
+
+        // argu 2. filter ( optional )
+        DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(1));
+        if (filter) {
+            DeviceAPI::Tizen::FilterPtr filter = filterConverter->toFilter(validator.toJSValueRef(1));
+            privData->setFilter(filter);
+        }
+
+        if(callbackManager)
+        {
+            callbackManager->setOnSuccess(onSuccessForCbm);
+        }
+
+        privData->setIndex(objectPriv->getIndex());
+        privData->setType(objectPriv->getType());
+
+        MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
+
+        long id = MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex);
+        MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, id));
+        IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
+        MessageListenerManagerSingleton::Instance().registerListener(listenerItem, priv->getContext());
+
+        // add to map and return index
+        return JSValueMakeNumber(context, id);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::UnsupportedException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::AlreadyInUseException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingStorage::removeChangeListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("Entered");
+
+    //check permission.
+    AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+        MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER]);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+    if (!priv) {
+        LogError("Private object is NULL.");
+        DeviceAPI::Common::UnknownException err("Private object is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+    if (!objectPriv) {
+        LogError("objectPriv is NULL.");
+        DeviceAPI::Common::UnknownException err("objectPriv is NULL.");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+    callbackManager = JSCallbackManager::createObject(priv->getContext());
+
+    ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+    try {
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // argu 1. watchId ( mandatory )
+        long handler = validator.toLong(0);
+
+        MessagingListener::getInstance().removeIncomingMsgCallback(handler, objectPriv->getType(), objectPriv->getIndex());
+
+        MessageListenerCancellerPtr canceller = MessageListenerCancellerPtr(new MessageListenerCanceller(priv->getContext(), thisObject, objectPriv->getIndex()));
+        IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
+        MessageListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+    }
+    catch(const BasePlatformException& err) {
+        LogError(err.getMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::ConversionException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::TypeMismatchException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::InvalidArgumentException& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::InvalidValuesException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+    catch (const WrtDeviceApis::Commons::Exception& exc) {
+        LogError(exc.GetMessage().c_str());
+        DeviceAPI::Common::UnknownException err(exc.GetMessage().c_str());
+        return JSWebAPIError::throwException(context, exception, err);
+    }
+
+    return JSValueMakeUndefined(context);
+}
 
 }
 }
index 0206ee4..6ebaac6 100755 (executable)
@@ -79,15 +79,16 @@ private:
         static bool hasProperty(JSContextRef context,
                         JSObjectRef object,
                         JSStringRef propertyName);
-  
+
+#if 0
         /**
          * The callback invoked when getting a property's value.
          */
-
        static JSValueRef getProperty(JSContextRef context,
                         JSObjectRef object,
                         JSStringRef propertyName,
                         JSValueRef* exception);
+#endif
 
        static JSValueRef addDraftMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
         const JSValueRef arguments[], JSValueRef* exception);
index 15dfe83..e037aa0 100644 (file)
@@ -94,6 +94,8 @@ void MessagingListener::OnAnswerReceived(
                 Throw(WrtDeviceApis::Commons::PlatformException);
             case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
                 Throw(WrtDeviceApis::Commons::ConversionException);
+            case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
             default:
                 Throw(WrtDeviceApis::Commons::UnknownException);
             }
@@ -109,6 +111,11 @@ void MessagingListener::OnAnswerReceived(
         callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
                                                JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
     }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+        LogError("InvalidArgument error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+    }
     Catch(WrtDeviceApis::Commons::UnknownException) {
         LogError("unknown error");
         callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
index b8b368a..ce72c7e 100755 (executable)
@@ -220,6 +220,13 @@ void ReqReceiverMessage::OnRequestReceived(const EventAddDraftMessagePtr& event)
 
        Try {
                IMessagePtr msg = event->msg;
+               if(event->getType() != msg->getMessageType())
+               {
+                       LogDebug("msg type and serviceType is not match");
+                       LogDebug("service type : "<< event->getType());
+                       LogDebug("msg type : "<< msg->getMessageType());
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }
                if (!event->checkCancelled())
                {
                        event->setCancelAllowed(false);
index efea324..8b4714a 100755 (executable)
 #include "MessageAsyncCallbackManager.h"
 #include "MessageListenerManager.h"
 
-
+#include <GlobalContextManager.h>
 
 #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
-#define OBJECT_MESSAGING ".messaging"
 
 using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::Commons;
@@ -54,12 +53,14 @@ void on_widget_stop_callback(int widgetId) {
 void on_frame_load_callback(const void * context)
 {
     LogDebug("[Tizen\\contact] on_frame_load_callback (" << context << ")");
+    DeviceAPI::Common::GlobalContextManager::getInstance()->addGlobalContext(static_cast<JSContextRef>(context));
 }
 
 void on_frame_unload_callback(const void * context)
 {
     LogDebug("[Tizen\\contact] on_frame_unload_callback (" << context << ")");
 
+    DeviceAPI::Common::GlobalContextManager::getInstance()->removeGlobalContext(static_cast<JSContextRef>(context));
     DeviceAPI::Messaging::MessageAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
     DeviceAPI::Messaging::MessageListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
 }
index d7663cc..8a6afa4 100755 (executable)
@@ -23,7 +23,6 @@ SET(SRCS_IMPL
        JSNdefRecordText.cpp
        JSNdefRecordURI.cpp
        JSNdefRecordMedia.cpp
-       JSNdefRecordArray.cpp
        JSNFCTarget.cpp
        NFCConverter.cpp
        EventNFCChangedPrivateData.cpp
index 35573f8..97295e5 100755 (executable)
@@ -53,7 +53,6 @@ class EventTagActionWrite : public EventTagAction<EventTagActionWrite>
 public:
        void writeNdef(void *handle) {setNdefMessageHandle(handle);}
        void *getNdefForWriting()  {return getNdefMessageHandle();}
-       void setNdefForWriting(void *handle) {setNdefMessageHandle(handle);}
        EventTagActionWrite(){ }
 };
 
index a971fb2..b5d0b34 100755 (executable)
@@ -44,7 +44,6 @@ class EventTargetActionSend : public EventNFCTemplate<EventTargetActionSend>
 {
 public:
        void *getMessageForSending()  {return message;}
-       void setMessageForSending(void* handle)  {message = handle;}
        EventTargetActionSend(void *handle) :message(handle){ }
 private:
        void *message;
index 6e8465f..1563c25 100755 (executable)
@@ -33,15 +33,13 @@ class INdefMessage
 
                                       INdefMessage() {}
         virtual                     ~INdefMessage() {}
-       virtual void *getHandle() = 0;
-       virtual void *getRecordHandle(const long index) = 0;
        virtual std::vector<unsigned char> toByte()= 0;
        virtual long getRecordCount() = 0;
        virtual NdefRecordData getNDEFRecord(const long index) = 0;
-       virtual bool insertNDEFRecord(const long index, void *recordHandle) = 0;
-       virtual bool appendNDEFRecord(void *recordHandle) = 0;
-       virtual bool removeNDEFRecord(const long index) = 0;
-       virtual void changeAllRecords(std::vector<void *> &ndefRecords) = 0;
+       virtual void *makeMessage(std::vector<void *> &ndefRcords) = 0;
+       virtual void *makeMessage(const std::vector<unsigned char> &rawdata) = 0;
+       virtual void setRecordesPtr(void *records) = 0;
+       virtual void* getRecordesPtr() = 0;
 };
 
 typedef DPL::SharedPtr<INdefMessage> INdefMessagePtr;
index 12cc1b4..5d93e39 100755 (executable)
@@ -39,7 +39,6 @@ class INdefRecord
        virtual std::vector<unsigned char> getTypeName() = 0;
        virtual std::vector<unsigned char> getID() = 0;
        virtual std::vector<unsigned char> getPayload() = 0;
-       virtual std::vector<unsigned char> toByte() = 0;
        virtual bool getText(char **text) = 0;
        virtual bool getLangCode(char **langCode) = 0;
        virtual bool getEncodeType(nfcTextEncodeUTF *encodeType) = 0;
index 8df196c..27265b9 100755 (executable)
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <GlobalContextManager.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 
 #include "JSNFCManager.h"
 #include "JSNFCAdapter.h"
@@ -146,7 +151,7 @@ JSValueRef JSNFCAdapter::getProperty(JSContextRef context, JSObjectRef object,
                                LogError("private object is null");
                                ThrowMsg(NullPointerException, "Private object not initialized");
                        }
-                       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
+                       INFCAdapterPtr nfcAdapter(privateObject->getObject());
                        return convert.toJSValueRef(nfcAdapter->getPowerState());
                }
        } Catch (NullPointerException) {
@@ -155,7 +160,7 @@ JSValueRef JSNFCAdapter::getProperty(JSContextRef context, JSObjectRef object,
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (UnsupportedException) {
                LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -173,59 +178,34 @@ JSValueRef JSNFCAdapter::setTagListener (JSContextRef context, JSObjectRef objec
 
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_TAG_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       NFCConverter nfcConverter(context);
-       Validator validator(context, exception);
-
-       if (argumentCount == 0) {
-               LogError("JSNFCAdapter::setTagListener TypeMismatchException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) ) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("JSNFCAdapter::setTagListener TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       NFCChangedCallback callbacks;
-
-       if (JSValueIsObject(context, arguments[0]) &&
-            !validator.isCallback(arguments[0])) {
-            callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
-       } else {
-               LogError("DetectedCB must has onattach and ondetach");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSContextRef global_context = privateObject->getContext();
-
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
-       JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
-    
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
        Try {
-               INFCAdapterPtr nfcAdapter(privateObject->getObject());
-
-               //process the filter object
-               TagFilterPtr tagFilter;
-               if ((argumentCount > 1) &&  !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
-                       if (JSIsArrayValue(context, arguments[1])) {
-                                       tagFilter = nfcConverter.toNFCTagFilter(arguments[1]);
-
-                       } else
-                               Throw(ConversionException);
+               ArgumentValidator validator(context, argumentCount, arguments);
+               NFCChangedCallback callbacks;
+               NFCConverter nfcConverter(context);
+               if (validator.toObject(0))
+                       callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
+
+               std::vector<std::string> filterValue = validator.toStringVector(1, true);
+       
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
+               JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
+               TagFilterPtr tagFilter(new TagFilter());
+               for (unsigned int i=0; i<filterValue.size(); i++) {
+                       nfcTagType filter = nfcConverter.toNfcTagType(filterValue.at(i));
+
+                       tagFilter->addTagTypeValue(filter);
+                       LogDebug("tag_types.at(i): " << filterValue.at(i));
                }
-               else
-               {
-                       TagFilterPtr _filter (new TagFilter());
-                       tagFilter = _filter;
+
+               NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("private object is null");
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
                }
 
+               INFCAdapterPtr nfcAdapter(privateObject->getObject());
+
                EventNFCChangedPrivateDataPtr privateData(
                    new EventNFCChangedPrivateData(callbackManager,
                                                    detachedCallbackManager)
@@ -235,20 +215,23 @@ JSValueRef JSNFCAdapter::setTagListener (JSContextRef context, JSObjectRef objec
                emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
 
                if (nfcAdapter->setTagListener(emitter, tagFilter) != 0)
-                       Throw(UnknownException);
+                       Throw(WrtDeviceApis::Commons::UnknownException);
 
                NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_TAG_LISTENER)));
                IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
                NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
 
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("JSNFCAdapter::setTagListener : ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
     } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -264,42 +247,26 @@ JSValueRef JSNFCAdapter::setPeerListener (JSContextRef context, JSObjectRef obje
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       NFCConverter nfcConverter(context);
-       Validator validator(context, exception);
-
-
-       if (argumentCount == 0) {
-               LogError("JSNFCAdapter::setPeerListener TypeMismatchException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) ) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("JSNFCAdapter::setPeerListener TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       NFCChangedCallback callbacks;
-
-       if (JSValueIsObject(context, arguments[0]) &&
-            !validator.isCallback(arguments[0])) {
-            callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
-       } else {
-               LogError("DetectedCB must has onattach and ondetach");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
-       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSContextRef global_context = privateObject->getContext();
+       Try {
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
-       JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
+               NFCConverter nfcConverter(context);
+               NFCChangedCallback callbacks;
+
+               if (validator.toObject(0))
+                       callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
+       
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
+               JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
+
+               NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("private object is null");
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               }
 
-       Try {
                INFCAdapterPtr nfcAdapter(privateObject->getObject());
 
                EventNFCChangedPrivateDataPtr privateData(
@@ -312,20 +279,23 @@ JSValueRef JSNFCAdapter::setPeerListener (JSContextRef context, JSObjectRef obje
                emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
 
                if (nfcAdapter->setPeerListener(emitter) != 0)
-                       Throw(UnknownException);
+                       Throw(WrtDeviceApis::Commons::UnknownException);
 
                NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_PEER_LISTENER)));
                IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
                NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
 
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("JSNFCAdapter::setPeerListener : ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -346,7 +316,7 @@ JSValueRef JSNFCAdapter::unsetTagListener(JSContextRef context, JSObjectRef obje
        }
 
        Try     {
-               INFCAdapterPtr nfcAdapter( privateObject->getObject() );
+               INFCAdapterPtr nfcAdapter(privateObject->getObject());
 
                nfcAdapter->unsetTagListener();
 
@@ -414,13 +384,14 @@ JSValueRef JSNFCAdapter::getCachedMessage (JSContextRef context, JSObjectRef obj
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
        Try {
                INFCAdapterPtr nfcAdapter(privateObject->getObject());
                void *cachedMessage = nfcAdapter->getCachedMessage();
                if (cachedMessage != NULL)
-                       return JSNdefMessage::createJSObject(context, nfcAdapter->getCachedMessage());
+                       return JSNdefMessage::createJSObject(global_context, cachedMessage);
                return JSValueMakeNull(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -442,30 +413,7 @@ JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_ADMIN_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       Validator validator(context, exception);
-    if(argumentCount == 0) {
-        /* 1st argument is mandatory. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-    }
-       if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]) && !validator.isCallback(arguments[1])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2]) && !validator.isCallback(arguments[2])) {
-               /* 2nd argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if ((argumentCount > 1) && validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
@@ -473,15 +421,22 @@ JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
-       JSContextRef global_context = privateObject->getContext();
-
-       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
+       INFCAdapterPtr nfcAdapter(privateObject->getObject());
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, NULL, NULL, true, true);
 
        Try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               // state
+        bool state = validator.toBool(0);
+               // successCallback
+               if (validator.toFunction(1, true))
+                       callbackManager->setOnSuccess(arguments[1]);
+               // errorCallback
+               if (validator.toFunction(2, true))
+                       callbackManager->setOnError(arguments[2]);
+
                NFCConverter nfcConverter(context);
-               bool state = false;
-               state = nfcConverter.toBool(arguments[0]);
 
                EventNFCChangedSetPoweredPtr event(new EventNFCChangedSetPowered(state));
                event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
@@ -489,6 +444,9 @@ JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
                nfcAdapter->setPowered(event);
                NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
@@ -496,7 +454,7 @@ JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index 4203dae..7867efb 100644 (file)
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <GlobalContextManager.h>
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 
 #include "JSNFCManager.h"
 #include "JSNFCAdapter.h"
 #include "NFCConverter.h"
 #include "NFCFactory.h"
 #include "plugin_config.h"
+#include "NFCDefaultAdapter.h"
 
 using namespace std;
 using namespace DPL;
@@ -85,6 +90,7 @@ JSStaticValue JSNFCManager::m_property[] =
 
 JSStaticFunction JSNFCManager::m_function[] = {
        {"getDefaultAdapter",      JSNFCManager::getDefaultAdapter, kJSPropertyAttributeNone },
+       {"setExclusiveMode",      JSNFCManager::setExclusiveMode, kJSPropertyAttributeNone },
        { 0, 0, 0}
 };
 
@@ -103,7 +109,7 @@ void JSNFCManager::initialize(JSContextRef context, JSObjectRef object)
                        }
                } Catch (UnsupportedException) {
                        LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
-               } Catch (UnknownException) {
+               } Catch (WrtDeviceApis::Commons::UnknownException) {
                        LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
                } Catch (PlatformException) {
                        LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -165,7 +171,7 @@ JSValueRef JSNFCManager::getProperty(JSContextRef context, JSObjectRef object,
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (UnsupportedException) {
                LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -190,7 +196,7 @@ JSValueRef JSNFCManager::getDefaultAdapter (JSContextRef context, JSObjectRef ob
                        LogError("private object is null");
                        ThrowMsg(UnsupportedException, "private object is null");
                }
-               return JSNFCAdapter::createJSObject(privateObject->getContext());
+               return JSNFCAdapter::createJSObject(GlobalContextManager::getInstance()->getGlobalContext(context));
        } Catch (UnsupportedException) {
                LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not Supported");
@@ -206,7 +212,44 @@ JSValueRef JSNFCManager::getDefaultAdapter (JSContextRef context, JSObjectRef ob
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
+               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNFCManager::setExclusiveMode (JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) {
+       LogDebug("Enter");
+
+       Try {
+               AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_COMMON_FUNCS);
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               ArgumentValidator validator(context, argumentCount, arguments);
+               // mode
+        bool mode = validator.toBool(0);
+               LogDebug("mode : " << mode);
+               NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("private object is null");
+                       ThrowMsg(UnsupportedException, "private object is null");
+               }
+               NFCDefaultAdapterSingleton::Instance().setExclusiveMode(mode);
+               return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index 8fc02ff..f8eae26 100755 (executable)
@@ -78,6 +78,10 @@ private:
                JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
                JSValueRef* exception);
 
+       static JSValueRef setExclusiveMode(JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception);
+
 };
 
 }
index 8201f0c..e0ef66f 100644 (file)
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 
 #include "JSNFCTag.h"
 #include "JSNdefMessage.h"
@@ -173,7 +177,7 @@ JSValueRef JSNFCTag::getProperty(JSContextRef context, JSObjectRef object,
                LogError("NullPointerException: " << _rethrown_exception.GetMessage());
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -203,33 +207,7 @@ JSValueRef JSNFCTag::readNDEF(JSContextRef context,
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_TAG_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       Validator validator(context, exception);
-
-       if (argumentCount == 0) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid Values");
-       }
-       if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !validator.isCallback(arguments[0])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("JSNFCTag::readNDEF TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
-               if (!validator.isCallback(arguments[1])) {
-                       /* 2nd argument must be Callback. */
-                       LogError("JSNFCTag::readNDEF TypeMismatchException!");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-       }
-
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if (validator.isCallback(arguments[0])) {
-               onSuccessForCbm = arguments[0];
-       }
-       if (argumentCount > 1) {
-               if (validator.isCallback(arguments[1])) {
-                       onErrorForCbm = arguments[1];
-               }
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
        NFCTagPrivObject* privateObject = static_cast<NFCTagPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -238,16 +216,28 @@ JSValueRef JSNFCTag::readNDEF(JSContextRef context,
        }
 
        INFCTagPtr nfcTag(privateObject->getObject());
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
-    
+    JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, NULL, NULL, true, true);
+
        Try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               // successCallback
+               if (validator.toFunction(0))
+                       callbackManager->setOnSuccess(arguments[0]);
+               // errorCallback
+               if (validator.toFunction(1, true))
+                       callbackManager->setOnError(arguments[1]);
+
                EventTagActionReadPtr event(new EventTagActionRead());
                event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
                event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
 
                nfcTag->readNdef(event);
-               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, privateObject->getContext());
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("readNDEF : ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
@@ -262,7 +252,7 @@ JSValueRef JSNFCTag::readNDEF(JSContextRef context,
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -284,32 +274,7 @@ JSValueRef JSNFCTag::writeNDEF(JSContextRef context,
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_TAG_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       NFCConverter convert(context);
-       Validator validator(context, exception);
-
-       if (argumentCount == 0) {
-        /* 1st argument is mandatory. */
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 1) && (!JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]) && !validator.isCallback(arguments[1]))) {
-               /* And 2nd argument must be Callback. */
-               LogError("JSNFCTag::writeNdef TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 2) && (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2]) && !validator.isCallback(arguments[2]))) {
-               /* 3rd argument must be Callback. */
-               LogError("JSNFCTag::writeNdef TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if ((argumentCount > 1) && validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
        NFCTagPrivObject* privateObject = static_cast<NFCTagPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -318,16 +283,31 @@ JSValueRef JSNFCTag::writeNDEF(JSContextRef context,
        }
 
        INFCTagPtr nfcTag(privateObject->getObject());
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, NULL, NULL, true, true);
        Try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               // ndefMessage
+               JSObjectRef ndefMessageObj = validator.toObject(0, JSNdefMessage::getClassRef(), false);
+               // successCallback
+               if (validator.toFunction(1, true))
+                       callbackManager->setOnSuccess(arguments[1]);
+               // errorCallback
+               if (validator.toFunction(2, true))
+                       callbackManager->setOnError(arguments[2]);
+
                EventTagActionWritePtr event(new EventTagActionWrite());
-               void *messageHandle = convert.getMessageHandle(arguments[0]);
+               NFCConverter convert(context);
+               void *messageHandle = convert.copiedMessage(ndefMessageObj);
                event->writeNdef(messageHandle);
-               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager));
                event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
                nfcTag->writeNdef(event);
-               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, privateObject->getContext());
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("writeNDEF : ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
@@ -342,7 +322,7 @@ JSValueRef JSNFCTag::writeNDEF(JSContextRef context,
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -364,33 +344,7 @@ JSValueRef JSNFCTag::transceive(JSContextRef context,
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_TAG_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       NFCConverter convert(context);
-       Validator validator(context, exception);
-
-       if (argumentCount < 2) {
-        /* 1st argument is mandatory. */
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid Values");
-       }
-
-       if (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !validator.isCallback(arguments[1])) {
-               /* 2nd argument must be Callback. */
-               LogError("JSNFCTag::transceive TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 2) && (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2]) && !validator.isCallback(arguments[2]))) {
-               /* 3rd argument must be Callback. */
-               LogError("JSNFCTag::transceive TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if (validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
        NFCTagPrivObject* privateObject = static_cast<NFCTagPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -399,16 +353,34 @@ JSValueRef JSNFCTag::transceive(JSContextRef context,
        }
 
        INFCTagPtr nfcTag(privateObject->getObject());
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, NULL, NULL, true, true);
        Try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               // ndefMessage
+               JSObjectRef dataObj = validator.toArrayObject(0);
+               
+               // successCallback
+               if (validator.toFunction(1))
+                       callbackManager->setOnSuccess(arguments[1]);
+               // errorCallback
+               if (validator.toFunction(2, true))
+                       callbackManager->setOnError(arguments[2]);
+
                EventTagActionTransceivePtr event(new EventTagActionTransceive());
-               std::vector<unsigned char> data = convert.toVectorOfUChars(arguments[0]);
+               Converter convert(context);
+               std::vector<unsigned char> data;
+               if (dataObj)
+                       data= convert.toVectorOfUChars(arguments[0]);
                event->transceive(data);
                event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
                event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
                nfcTag->transceive(event);
-               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, privateObject->getContext());
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("transceive : ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
@@ -420,7 +392,7 @@ JSValueRef JSNFCTag::transceive(JSContextRef context,
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index 72cada1..8e3e86d 100644 (file)
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 
 #include "JSNFCTarget.h"
 #include "JSNFCManager.h"
@@ -152,7 +156,7 @@ JSValueRef JSNFCTarget::getProperty(JSContextRef context, JSObjectRef object,
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (NullPointerException) {
                LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -182,19 +186,7 @@ JSValueRef JSNFCTarget::setReceiveNDEFListener(JSContextRef context,
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       NFCConverter convert(context);
-       Validator validator(context, exception);
-
-       if ((argumentCount == 0) || JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !validator.isCallback(arguments[0])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("JSNFCTarget::setReceiveNDEFListener NDEFMessageReadCB TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL;
-       if (validator.isCallback(arguments[0])) {
-               onSuccessForCbm = arguments[0];
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
        NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -203,26 +195,36 @@ JSValueRef JSNFCTarget::setReceiveNDEFListener(JSContextRef context,
        }
        
        INFCTargetPtr nfcTarget(privateObject->getObject());
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, NULL, true, true);
+
        Try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+               JSValueRef onSuccessForCbm = NULL;
+               // NDEFMessageReadCallback
+               if (validator.toFunction(0))
+                       onSuccessForCbm = arguments[0];
+
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, NULL, true, true);
 
                EventTargetActionReceiveEmitterPtr emitter(new EventTargetActionReceiveEmitter);
                emitter->setListener(&NFCResponseDispatcher::getInstance());
                emitter->setEventPrivateData(StaticPointerCast<EventTargetActionReceive::PrivateDataType>(callbackManager));
                nfcTarget->setReceiveNDEFListener(emitter);
 
-               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject, static_cast<long>(ID_NFCPEER_RECEIVENDEF_LISTENER)));
+               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCPEER_RECEIVENDEF_LISTENER)));
                IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
-               NFCListenerManagerSingleton::Instance().registerListener(listenerItem, privateObject->getContext());
+               NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
 
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("setReceiveNDEFListener : ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -243,6 +245,8 @@ JSValueRef JSNFCTarget::unsetReceiveNDEFListener(JSContextRef context,
                AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
                TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
+
                NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(thisObject));
                if (NULL == privateObject) {
                        LogError("private object is null");
@@ -252,12 +256,12 @@ JSValueRef JSNFCTarget::unsetReceiveNDEFListener(JSContextRef context,
                INFCTargetPtr nfcTarget(privateObject->getObject());
                nfcTarget->unsetReceiveNDEFListener();
 
-               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCPEER_RECEIVENDEF_LISTENER)));
+               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject,  static_cast<long>(ID_NFCPEER_RECEIVENDEF_LISTENER)));
                IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
                NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
 
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -284,33 +288,9 @@ JSValueRef JSNFCTarget::sendNDEF(JSContextRef context,
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
+       
        NFCConverter convert(context);
-       Validator validator(context, exception);
-
-       if (argumentCount == 0) {
-        /* 1st argument is mandatory. */
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 1) && (!JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]) && !validator.isCallback(arguments[1]))) {
-               /* And 2nd argument must be Callback. */
-               LogError("JSNFCTag::writeNdef TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 2) && (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2]) && !validator.isCallback(arguments[2]))) {
-               /* 3rd argument must be Callback. */
-               LogError("JSNFCTag::writeNdef TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if ((argumentCount > 1) && validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
 
        NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -319,15 +299,29 @@ JSValueRef JSNFCTarget::sendNDEF(JSContextRef context,
        }
 
        INFCTargetPtr nfcTarget(privateObject->getObject());
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, NULL, NULL, true, true);
        Try {
-               void *messageHandle = convert.getMessageHandle(arguments[0]);
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               // ndefMessage
+               JSObjectRef ndefMessageObj = validator.toObject(0, JSNdefMessage::getClassRef());
+               // successCallback
+               if (validator.toFunction(1, true))
+                       callbackManager->setOnSuccess(arguments[1]);
+               // errorCallback
+               if (validator.toFunction(2, true))
+                       callbackManager->setOnError(arguments[2]);
+
+               void *messageHandle = convert.copiedMessage(ndefMessageObj);
                EventTargetActionSendPtr event(new EventTargetActionSend(messageHandle));
-               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager));
                event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
                nfcTarget->sendNDEF(event);
-               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, privateObject->getContext());
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
                return JSValueMakeUndefined(context);
+    } Catch (BasePlatformException) {
+        LogError(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
+        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LogError("sendNDEF : ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
@@ -339,7 +333,7 @@ JSValueRef JSNFCTarget::sendNDEF(JSContextRef context,
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
                callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index a64c0f7..0f13e45 100644 (file)
 #include "JSNdefRecordText.h"
 #include "JSNdefRecordURI.h"
 #include "JSNdefRecordMedia.h"
-#include "JSNdefRecordArray.h"
 #include "NFCConverter.h"
-
+#include <GlobalContextManager.h>
 #include <dpl/log/log.h>
-
+#include <ArgumentValidator.h>
 #include <Commons/Exception.h>
 #include <CommonsJavaScript/PrivateObject.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
+
 #include "NFCFactory.h"
 #include "plugin_config.h"
 
@@ -62,8 +64,8 @@ namespace NFC {
     NULL, //DeleteProperty,
     NULL, //GetPropertyNames,
     NULL, //CallAsFunction,
-    constructor, //CallAsConstructor,
-    hasInstance, //HasInstance,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
     NULL  //ConvertToType
 };
 
@@ -88,90 +90,63 @@ JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, void *messageHan
        LogDebug("entered");
 
        INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(messageHandle);
-
-       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, ndefMessage);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefMessage object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, ndefMessage);
 }
 
 JSObjectRef JSNdefMessage::createJSObject(JSContextRef context) {
        LogDebug("entered");
 
        INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject();
-
-       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, ndefMessage);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefMessage object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, ndefMessage);
 }
 
 JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, INdefMessagePtr message) {
        LogDebug("entered");
 
+       NFCConverter convert(context);
+       JSValueRef records = convert.toJSNdefRecordArray(message);
+       JSValueProtect(context, records);
+       message->setRecordesPtr((void*)records);
        NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, message);
 
        if (!priv) {
                ThrowMsg(NullPointerException, "Can not new a NdefMessage object");
        }
 
-       return JSObjectMake(context, getClassRef(), priv);
+       JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
+       return obj;
 }
 
 JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, std::vector<void *> ndefRcords) {
        LogDebug("entered");
 
        INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(ndefRcords);
-
-       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, ndefMessage);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefMessage object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, ndefMessage);
 }
 
 JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, std::vector<unsigned char> rawdata) {
        LogDebug("entered");
 
        INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(rawdata);
-
-       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, ndefMessage);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefMessage object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, ndefMessage);
 }
 void JSNdefMessage::initialize(JSContextRef context, JSObjectRef object)
 {
        LogDebug("entered");
-
-       if (!JSObjectGetPrivate(object)) {
-               LogDebug("Private object not set... setting it.");
-               INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject();
-               NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, ndefMessage);
-               if (!JSObjectSetPrivate(object, priv)) {
-                       delete priv;
-               }
-       }
 }
 
 void JSNdefMessage::finalize(JSObjectRef object)
 {
        LogDebug( "entered" );
-       NdefMessagePrivObject *priv = static_cast<NdefMessagePrivObject*>( JSObjectGetPrivate( object ) ) ;
-       JSObjectSetPrivate(object, NULL);
-       LogDebug("Deleting NdefMessage object");
-       delete priv;
+       NdefMessagePrivObject *priv = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+       if (priv) {
+               INdefMessagePtr ndefMessage(priv->getObject());
+               LogDebug("getRecordesPtr:"<<ndefMessage->getRecordesPtr());
+               JSValueUnprotect(priv->getContext(), (JSValueRef)(ndefMessage->getRecordesPtr()));
+               JSObjectSetPrivate(object, NULL);
+               LogDebug("Deleting NdefMessage object");
+               delete priv;
+       }
 }
 
 
@@ -193,25 +168,24 @@ JSObjectRef JSNdefMessage::constructor(JSContextRef ctx, JSObjectRef constructor
        LogDebug("entered");
 
        Try {
-               if ((argumentCount == 0) || JSValueIsNull(ctx, arguments[0]) || JSValueIsUndefined(ctx, arguments[0]))
-                       return createJSObject(ctx);
-               else {
-                       if (!(JSIsArrayValue(ctx, arguments[0]) || JSNdefRecordArray::isObjectOfClass(ctx, arguments[0])))
-                               ThrowMsg(ConversionException, "Parameter's type is not matched");
+               ArgumentValidator validator(ctx, argumentCount, arguments);
+        JSObjectRef objArg = validator.toArrayObject(0, true);
+               JSObjectRef result = NULL;
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
 
+               if (objArg == NULL)
+                       result = createJSObject(global_context);
+               else {
                        NFCConverter convert(ctx);
 
-                       if (JSNdefRecordArray::isObjectOfClass(ctx, arguments[0])) {
-                               return createJSObject(ctx, JSNdefRecordArray::getNdefRecordArray(ctx, arguments[0]));
-                       }
-
-                       JSObjectRef objArg = convert.toJSObjectRef(arguments[0]);
                        if (JSGetArrayLength(ctx, objArg) > 0) {
                                bool isRecordArray = false;
                                bool isByteArray = false;
                                for (std::size_t i = 0; i < JSGetArrayLength(ctx, objArg); ++i) {
                                        JSValueRef element = JSGetArrayElement(ctx, objArg, i);
-                                       if (convert.isNdefRecord(element))
+                                       bool bNdefRecord = convert.isNdefRecord(element);
+                                       LogDebug("isNdefRecord : " << bNdefRecord);
+                                       if (bNdefRecord)
                                                isRecordArray = true;
                                        else
                                                isByteArray = true;
@@ -221,31 +195,45 @@ JSObjectRef JSNdefMessage::constructor(JSContextRef ctx, JSObjectRef constructor
                                if (isRecordArray && isByteArray)
                                        ThrowMsg(ConversionException, "Parameter's type is not matched");
                                else if (isRecordArray)
-                                       return createJSObject(ctx, convert.toVectorOfRecordHandles(arguments[0]));
+                                       result = createJSObject(global_context, convert.toVectorOfRecordHandles(objArg));
                                else
-                                       return createJSObject(ctx, convert.toVectorOfUChars(arguments[0]));
+                                       result = createJSObject(global_context, convert.toVectorOfUChars(arguments[0]));
+                               
                        } else
-                               return createJSObject(ctx);
+                               result = createJSObject(global_context);
                }
+               if (result) {
+                       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+                   JSObjectSetProperty(global_context, result, ctorName, constructor,
+                       kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+               JSStringRelease(ctorName);
+                       return result;
+               } else
+                       throw TypeMismatchException("Parameter Type Mismatch");
+       } Catch(BasePlatformException){
+               JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, _rethrown_exception);
+        *exception = error;
+        return error;
        } Catch(ConversionException) {
-               LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               *exception = error;
+               return error;
        } Catch (InvalidArgumentException) {
-               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               *exception = error;
+               return error;
        } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-               return NULL;
-       } Catch (UnknownException) {
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               *exception = error;
+               return error;
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        }
-       *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-       return NULL;
+       JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       *exception = error;
+       return error;
 }
 
 JSValueRef JSNdefMessage::getProperty(JSContextRef context, JSObjectRef object,
@@ -265,15 +253,16 @@ JSValueRef JSNdefMessage::getProperty(JSContextRef context, JSObjectRef object,
 
                LogDebug("propertyName : " << convert.toString(propertyName));
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFMESSAGE_RECORDCOUNT)) {
-                       return convert.toJSValueRefLong(ndefMessage->getRecordCount());
+                       std::vector<void *> records = convert.toVectorOfRecordHandles(static_cast<JSValueRef>(ndefMessage->getRecordesPtr()));
+                       return convert.toJSValueRefLong(records.size());
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFMESSAGE_RECORDS)) {
-                       return JSNdefRecordArray::createArray(context, ndefMessage);
+                       return static_cast<JSValueRef>(ndefMessage->getRecordesPtr());
                }
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (NullPointerException) {
                LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -298,56 +287,35 @@ bool JSNdefMessage::setProperty(JSContextRef context, JSObjectRef object,
 
                        NFCConverter convert(context);
 
-                       if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value) || !(JSIsArrayValue(context, value) || JSNdefRecordArray::isObjectOfClass(context, value))) {
+
+                       if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value) || !JSIsArrayValue(context, value)) {
                                LogError("value is invald.");
                                ThrowMsg(ConversionException, "value is invald.");
                        }
+                       INdefMessagePtr ndefMessage(privateObject->getObject());
+                       JSValueUnprotect(privateObject->getContext(), (JSValueRef)ndefMessage->getRecordesPtr());
+                       JSValueProtect(privateObject->getContext(), value);
+                       ndefMessage->setRecordesPtr((void *)value);
 
-                       NdefMessagePrivObject *priv;
-                       if (JSNdefRecordArray::isObjectOfClass(context, value))
-                               priv = new NdefMessagePrivObject(context, JSNdefRecordArray::getNdefRecordArray(context, value));
-                       else {
-                               std::vector<void *> records = convert.toVectorOfRecordHandles(value);
-                               priv = new NdefMessagePrivObject(context, NFCFactory::getInstance().createNDEFMessageObject(records));
-                       }
-                       if (!JSObjectSetPrivate(object, priv)) {
-                               delete priv;
-                                       ThrowMsg(NullPointerException, "Private object not set");
-                       }
-                       delete privateObject;
                        return true;
                 }
        } Catch (NullPointerException) {
                LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (InvalidArgumentException) {
                LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        }
        return false;
 
 }
 
-bool JSNdefMessage::hasInstance(JSContextRef context,
-        JSObjectRef constructor,
-        JSValueRef possibleInstance,
-        JSValueRef* exception)
-{
-    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
 JSValueRef JSNdefMessage::toByte(JSContextRef context,
         JSObjectRef object,
         JSObjectRef thisObject,
@@ -366,8 +334,13 @@ JSValueRef JSNdefMessage::toByte(JSContextRef context,
                INdefMessagePtr ndefMessage(privateObject->getObject());
                NFCConverter convert(context);
 
-               return convert.toJSValueRef(ndefMessage->toByte());
-       } Catch (UnknownException) {
+               std::vector<void *> records = convert.toVectorOfRecordHandles(static_cast<JSValueRef>(ndefMessage->getRecordesPtr()));
+               INdefMessagePtr newMessage = NFCFactory::getInstance().createNDEFMessageObject(records);
+               return convert.toJSValueRef(newMessage->toByte());
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index d5c0a69..6080af1 100755 (executable)
@@ -43,6 +43,8 @@ public:
     static JSObjectRef createJSObject(JSContextRef context, std::vector<void *> ndefRcords);
     static JSObjectRef createJSObject(JSContextRef context, std::vector<unsigned char> rawdata);
 
+    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
 private:
     /**
      * This member variable contains the values which has to be passed when
@@ -74,7 +76,6 @@ private:
      */
     static void finalize(JSObjectRef object);
 
-    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
 
     /**
      * Getters and setters for properties
@@ -83,14 +84,6 @@ private:
             JSStringRef propertyName, JSValueRef* exception);
     static bool setProperty(JSContextRef context, JSObjectRef object,
             JSStringRef propertyName,  JSValueRef value,  JSValueRef* exception);
-    /**
-     * 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);
-
     static JSValueRef toByte(JSContextRef context,
                JSObjectRef object,
                JSObjectRef thisObject,
index 80719df..827a915 100644 (file)
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
-
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 #include "NFCFactory.h"
 
 #include "JSNdefRecord.h"
@@ -59,8 +62,8 @@ JSClassDefinition JSNdefRecord::m_classInfo =
        NULL, //DeleteProperty,
        NULL, //GetPropertyNames,
        NULL, //CallAsFunction,
-       constructor, //CallAsConstructor,
-       hasInstance,
+       NULL, //CallAsConstructor,
+       NULL,
        NULL, //ConvertToType
 };
 
@@ -92,103 +95,100 @@ JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, const NdefRecordD
 }
 
 JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload);
-
-       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
 }
 
 JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, std::vector<unsigned char> rawdata) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(rawdata);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(rawdata));
+}
 
+JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, INdefRecordPtr ndefRecord) {
        NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
 
        if (!priv) {
                ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
        }
 
-       return JSObjectMake(context, getClassRef(), priv);
+       JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
+       return obj;
 }
 
 void JSNdefRecord::initialize(JSContextRef context, JSObjectRef object) {
        LogDebug("entered");
-
-       if (!JSObjectGetPrivate(object)) {
-               LogDebug("Private object not set... setting it.");
-               INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject();
-               NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-               if (!JSObjectSetPrivate(object, priv)) {
-                       delete priv;
-               }
-       }
 }
 
 void JSNdefRecord::finalize(JSObjectRef object) {
        LogDebug("Entered");
        NdefRecordPrivObject* priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
-       JSObjectSetPrivate(object, NULL);
-       LogDebug("Deleting ndefrecord object");
-       delete priv;
+       if (priv) {
+               INdefRecordPtr ndefRecord = priv->getObject();
+               JSObjectSetPrivate(object, NULL);
+               LogDebug("Deleting ndefrecord object");
+               delete priv;
+       } else
+               LogDebug("priv null");
 }
 
 JSObjectRef JSNdefRecord::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
        LogDebug("entered");
 
-       Try {
-               if (argumentCount < 1) {
-                       ThrowMsg(ConversionException, "parameter count is wrong.");
-               } else if (argumentCount < 3) {
-                       if (JSValueIsNull(ctx, arguments[0]) || JSValueIsUndefined(ctx, arguments[0]) || !JSIsArrayValue(ctx, arguments[0]))
-                               ThrowMsg(ConversionException, "parameter is JSNull/JSUndefined/Not array");
-               } else {
-                       if (JSValueIsNull(ctx, arguments[1]) || JSValueIsUndefined(ctx, arguments[1]) || !JSIsArrayValue(ctx, arguments[1]))
-                               ThrowMsg(ConversionException, "2nd parameter is Not array");
-                       else if (JSValueIsNull(ctx, arguments[2]) || JSValueIsUndefined(ctx, arguments[2]) || !JSIsArrayValue(ctx, arguments[2]))
-                               ThrowMsg(ConversionException, "3rd parameter is Not array");
-               }
-
+    Try {
+               ArgumentValidator validator(ctx, argumentCount, arguments);
                NFCConverter convert(ctx);
+               JSObjectRef result = NULL;
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
 
-               if (argumentCount < 3)
-                       return createJSObject(ctx, convert.toVectorOfUChars(arguments[0]));
-
-               NdefRecordProperties prop;
-               prop.tnf = convert.toNfcTNF(arguments[0]);
-
-               prop.typeName = convert.toVectorOfUChars(arguments[1]);
-               if ((argumentCount > 3) && !JSValueIsNull(ctx, arguments[3]) && !JSValueIsUndefined(ctx, arguments[3])) {
-                       if (!JSIsArrayValue(ctx, arguments[3]))
-                               ThrowMsg(ConversionException, "4th parameter is Not array");
-                       prop.id = convert.toVectorOfUChars(arguments[3]);
+               if (argumentCount < 3) {
+                       if (validator.toArrayObject(0))
+                               result = createJSObject(global_context, convert.toVectorOfUChars(arguments[0]));
+               } else {
+                       NdefRecordProperties prop;
+                       prop.tnf = static_cast<nfcTNF>(validator.toNumber(0));
+                       if (validator.toArrayObject(1)) 
+                               prop.typeName = convert.toVectorOfUChars(arguments[1]);
+                       std::vector<unsigned char> payload;
+                       if (validator.toArrayObject(2))
+                               payload = convert.toVectorOfUChars(arguments[2]);
+                       if (validator.toArrayObject(3, true))
+                               prop.id = convert.toVectorOfUChars(arguments[3]);
+                       result = createJSObject(global_context, prop, payload);
                }
-
-               return createJSObject(ctx, prop, convert.toVectorOfUChars(arguments[2]));
-
+               if (result) {
+                       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+                   JSObjectSetProperty(global_context, result, ctorName, constructor,
+                       kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+                   JSStringRelease(ctorName);
+                       return result;
+               } else
+                       throw TypeMismatchException("Parameter Type Mismatch");
+    } Catch (BasePlatformException) {
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, _rethrown_exception);
+        *exception = error;
+        return error;
        } Catch(ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               *exception = error;
+        return error;
        } Catch (InvalidArgumentException) {
                LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               *exception = error;
+        return error;
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-               return NULL;
-       } Catch (UnknownException) {
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               *exception = error;
+        return error;
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        }
-       *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-       return NULL;
+       JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       *exception = error;
+       return error;
 }
 
 JSValueRef JSNdefRecord::getProperty(JSContextRef context, JSObjectRef object,
@@ -214,7 +214,7 @@ JSValueRef JSNdefRecord::getProperty(JSContextRef context, JSObjectRef object,
                        return convert.toJSValueRef(ndefRecord->getPayload());
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -226,48 +226,6 @@ JSValueRef JSNdefRecord::getProperty(JSContextRef context, JSObjectRef object,
        return JSValueMakeUndefined(context);
 }
 
-bool JSNdefRecord::hasInstance(JSContextRef context,
-        JSObjectRef constructor,
-        JSValueRef possibleInstance,
-        JSValueRef* exception)
-{
-    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
-JSValueRef JSNdefRecord::toByte(JSContextRef context,
-        JSObjectRef object,
-        JSObjectRef thisObject,
-        size_t argumentCount,
-        const JSValueRef arguments[],
-        JSValueRef* exception)
-{
-       LogDebug("Entered ");
-       Try {
-               NdefRecordPrivObject* privateObject = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(thisObject));
-               if (NULL == privateObject) {
-                       LogError("private object is null");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-
-               INdefRecordPtr ndefRecord(privateObject->getObject());
-               NFCConverter convert(context);
-
-               return convert.toJSValueRef(ndefRecord->toByte());
-       } Catch (UnknownException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       } Catch (PlatformException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch(NullPointerException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       }
-
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
 } //NFC
 } //DeviceAPI
 
index 29c163b..1397366 100755 (executable)
@@ -42,6 +42,10 @@ public:
                const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
        static JSObjectRef createJSObject(JSContextRef context, 
                std::vector<unsigned char> rawdata);
+       static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
+
+    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
 private:
        /**
      * The callback invoked when an object is first created.
@@ -53,8 +57,6 @@ private:
      */
        static void finalize(JSObjectRef object);
 
-       static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
        /**
      * The callback invoked when getting a property's value.
      */
@@ -62,14 +64,6 @@ private:
 
 
        /**
-     * 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;
@@ -81,12 +75,6 @@ private:
 
        static JSClassRef m_jsClassRef;
 
-    static JSValueRef toByte(JSContextRef context,
-               JSObjectRef object,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception);
 };
 
 } //NFC
diff --git a/src/NFC/JSNdefRecordArray.cpp b/src/NFC/JSNdefRecordArray.cpp
deleted file mode 100644 (file)
index a7c34c9..0000000
+++ /dev/null
@@ -1,767 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <dpl/log/log.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "JSNdefRecordArray.h"
-#include "JSNdefMessage.h"
-#include "NFCConverter.h"
-#include "NFCFactory.h"
-
-namespace {
-const char* FUNCTION_CONCAT = "concat";
-const char* FUNCTION_JOIN = "join";
-const char* FUNCTION_POP = "pop";
-const char* FUNCTION_PUSH = "push";
-const char* FUNCTION_REVERSE = "reverse";
-const char* FUNCTION_SHIFT = "shift";
-const char* FUNCTION_SLICE = "slice";
-const char* FUNCTION_SORT = "sort";
-const char* FUNCTION_SPLICE = "splice";
-const char* FUNCTION_TOSTRING = "toString";
-const char* FUNCTION_UNSHIFT = "unshift";
-const char* FUNCTION_VALUEOF = "valueOf";
-const char *ARRAY = "Array";
-const char *ATTRIBUTE_LENGTH = "length";
-}
-
-namespace DeviceAPI {
-namespace NFC {
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-       
-JSClassDefinition JSNdefRecordArray::m_classInfo = {
-       0,
-       kJSClassAttributeNone,
-       ARRAY,
-       0,
-       m_property,
-       m_function,
-       initialize,
-       finalize,
-       hasProperty,
-       getProperty,
-       setProperty,
-       NULL, //deleteProperty,
-       getPropertyNames, //getPropertyNames,
-       NULL, //callAsFunction,
-       NULL, //callAsConstructor,
-       NULL, //hasInstance,
-       NULL, //convertToType,
-};
-
-JSStaticValue JSNdefRecordArray::m_property[] = {
-       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
-       { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSNdefRecordArray::m_function[] = {
-       { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { 0, 0, 0 }
-};
-
-JSClassRef JSNdefRecordArray::m_jsClassRef = JSClassCreate(
-               JSNdefRecordArray::getClassInfo());
-
-JSValueRef JSNdefRecordArray::getLength(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       LogDebug("Enter");
-       Try
-       {
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(NullPointerException);
-               }
-               INdefMessagePtr privateDatas = priv->getObject();
-               if (privateDatas) {
-                       Converter converter(context);
-                       return converter.toJSValueRefLong(privateDatas->getRecordCount());
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid conversion");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSNdefRecordArray::createArray(JSContextRef context,
-               const INdefMessagePtr &privateDatas)
-{
-       LogDebug("Enter");
-       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, privateDatas);
-       return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSNdefRecordArray::getClassInfo()
-{
-       return &(m_classInfo);
-}
-
-JSClassRef JSNdefRecordArray::getClassRef()
-{
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-bool JSNdefRecordArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
-       return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-INdefMessagePtr 
-       JSNdefRecordArray::getNdefRecordArray(JSContextRef context, JSValueRef value)
-{
-       LogDebug("Enter");
-       if (!isObjectOfClass(context, value)) {
-               Throw(InvalidArgumentException);
-       }
-       JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
-               Throw(InvalidArgumentException);
-       }
-       NdefMessagePrivObject *priv = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
-       if (!priv) {
-               Throw(NullPointerException);
-       }
-       return priv->getObject();
-}
-
-void JSNdefRecordArray::initialize(JSContextRef context,
-               JSObjectRef object)
-{
-       LogDebug("Enter");      
-}
-
-void JSNdefRecordArray::finalize(JSObjectRef object)
-{
-       NdefMessagePrivObject* priv =
-               static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
-       delete priv;
-       JSObjectSetPrivate(object, NULL);
-}
-
-bool JSNdefRecordArray::hasProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName)
-{      
-       LogDebug("Enter");
-       Converter converter(context);
-       Try
-       {
-               size_t index = converter.toSizeT(propertyName);
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(NullPointerException);
-               }
-               INdefMessagePtr privateDatas = priv->getObject();
-               if (static_cast<long>(index) < privateDatas->getRecordCount()) {
-                       return true;
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               //not reporting error is intended
-       }
-       return false;
-}
-
-JSValueRef JSNdefRecordArray::getProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       LogDebug("Enter");      
-
-       Try
-       {
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(NullPointerException);
-               }
-
-               NFCConverter converter(context);
-               size_t index = converter.toSizeT(propertyName);
-
-               INdefMessagePtr privateDatas = priv->getObject();
-               if (static_cast<long>(index) < privateDatas->getRecordCount()) {
-                       NdefRecordData result = privateDatas->getNDEFRecord(index);
-                       return converter.toJSValueRef(result);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid property");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-bool JSNdefRecordArray::setProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef value,
-               JSValueRef* exception)
-{      
-       LogDebug("Enter");
-       NFCConverter converter(context);
-       Try
-       {
-               size_t index = converter.toSizeT(propertyName);
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(NullPointerException);
-               }
-               INdefMessagePtr privateDatas = priv->getObject();
-               if (!privateDatas) {
-                       Throw(NullPointerException);
-               }
-               void *record = converter.getRecordHandle(value);
-               if (privateDatas->getRecordCount() == static_cast<long>(index)) {
-                       privateDatas->appendNDEFRecord(record);
-               } else if (privateDatas->getRecordCount() > static_cast<long>(index)) {
-                       privateDatas->removeNDEFRecord(static_cast<long>(index));
-                       privateDatas->insertNDEFRecord(static_cast<long>(index), record);
-               } else
-                       Throw(InvalidArgumentException);
-
-               return true;
-       } Catch (NullPointerException) {
-               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (ConversionException) {
-               LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-       } Catch(WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-       }
-       return false;
-}
-
-void JSNdefRecordArray::getPropertyNames(JSContextRef context, JSObjectRef object,
-        JSPropertyNameAccumulatorRef propertyNames)
-{
-       Try {
-               NdefMessagePrivObject* priv =
-               static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
-               if (!priv || !priv->getObject()) {
-                       LogError("No private obejct");
-                       return;
-               }
-               Converter converter(context);
-               INdefMessagePtr privObj = priv->getObject();
-               for (int i = 0; i < privObj->getRecordCount(); i++) {
-                       JSStringRef name = converter.toJSStringRef(converter.toString(i));
-                       JSPropertyNameAccumulatorAddName(propertyNames, name);
-                       JSStringRelease(name);
-               }
-
-       } Catch(WrtDeviceApis::Commons::Exception) {
-               LogError("Error occured");
-       }
-}
-
-JSValueRef JSNdefRecordArray::concat(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("Enter");
-       Try
-       {
-               //copy current privateDatas
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Private object is not set.");
-                       ThrowMsg(NullPointerException, "Private object not initialized");
-               }
-
-               INdefMessagePtr myMessage = priv->getObject();
-               
-               INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(myMessage->toByte());
-
-               if (argumentCount == 0)
-                       return createArray(context, ndefMessage);
-
-               NFCConverter converter(context);
-               for (size_t i = 0; i < argumentCount; i++) {
-                       if (JSIsArrayValue(context, arguments[i])) {
-                               std::vector<void *> records = converter.toVectorOfRecordHandles(arguments[i]);
-                               for (size_t j = 0; j < records.size(); j++)
-                                       ndefMessage->appendNDEFRecord(records[j]);
-                       } else if (isObjectOfClass(context, arguments[i])) {
-                               NdefMessagePrivObject* argPriv =
-                                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(converter.toJSObjectRef(arguments[i])));
-                               if (!argPriv) {
-                                       LogError(i << "record's private object is not set.");
-                                       ThrowMsg(ConversionException, "Record's private object not initialized");
-                               }
-                               INdefMessagePtr argMessage = argPriv->getObject();
-                               for (long j = 0 ; j < argMessage->getRecordCount(); j++)
-                                       ndefMessage->appendNDEFRecord(argMessage->getRecordHandle(j));
-                       } else
-                               ThrowMsg(ConversionException, "No Array");
-               }
-               
-               return createArray(context, ndefMessage);
-       } Catch (UnknownException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       } Catch (PlatformException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch(NullPointerException) {
-               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(ConversionException) {
-               LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       }
-
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
-JSValueRef JSNdefRecordArray::join(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("Enter");
-       Try
-       {
-               std::string result;
-               std::string separator(",");
-               NFCConverter converter(context);
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Private object is not set.");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-               INdefMessagePtr myMessage = priv->getObject();
-               if (argumentCount > 0) {
-                       separator = converter.toString(arguments[0]);
-               }
-               for (long i = 0; i < myMessage->getRecordCount(); i++) {
-                       if (i != 0) {
-                               result += separator;
-                       }
-                       result += "[object " + converter.toRecordClassName(myMessage->getNDEFRecord(i)) + "]";
-               }
-               return converter.toJSValueRef(result);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-}
-
-JSValueRef JSNdefRecordArray::pop(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{      
-       LogDebug("Enter");
-       Try
-       {
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Private object is not set.");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-               INdefMessagePtr myMessage = priv->getObject();
-
-               NFCConverter converter(context);
-               long recordCount = myMessage->getRecordCount();
-               if (recordCount > 0) {
-                       NdefRecordData result = myMessage->getNDEFRecord(recordCount - 1);
-                       myMessage->removeNDEFRecord(recordCount - 1);
-                       return converter.toJSValueRef(result);
-               }
-               return JSCreateArrayObject(context, 0, NULL);
-       } Catch (UnknownException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       } Catch (PlatformException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch(NullPointerException) {
-               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(ConversionException) {
-               LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
-JSValueRef JSNdefRecordArray::push(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{      
-       LogDebug("Enter");
-       Try
-       {
-               NFCConverter converter(context);
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Private object is not set.");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-               INdefMessagePtr myMessage = priv->getObject();
-
-               for (size_t i = 0; i < argumentCount; ++i) {
-                       void *record = converter.getRecordHandle(arguments[i]);
-                       myMessage->appendNDEFRecord(record);
-               }
-               return converter.toJSValueRefLong(myMessage->getRecordCount());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-}
-
-JSValueRef JSNdefRecordArray::reverse(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("Enter");      
-       Try
-       {
-               NFCConverter converter(context);
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Private object is not set.");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-               INdefMessagePtr myMessage = priv->getObject();
-
-               long recordCounts = myMessage->getRecordCount();
-               if (recordCounts > 0) {
-                       std::vector<void *> records;
-                       for (long i = recordCounts; i > 0; i--) {
-                               records.push_back(myMessage->getRecordHandle(i-1));
-                       }
-                       myMessage->changeAllRecords(records);
-               }
-               return thisObject;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
-JSValueRef JSNdefRecordArray::shift(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("Enter");      
-       Try
-       {
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Private object is not set.");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-               INdefMessagePtr myMessage = priv->getObject();
-
-               NFCConverter converter(context);
-               long recordCount = myMessage->getRecordCount();
-               if (recordCount > 0) {
-                       NdefRecordData result = myMessage->getNDEFRecord(0);
-                       myMessage->removeNDEFRecord(0);
-                       return converter.toJSValueRef(result);
-               }
-               return JSCreateArrayObject(context, 0, NULL);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
-JSValueRef JSNdefRecordArray::slice(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("Enter");      
-       Try
-       {
-               if (argumentCount < 1) {
-                       return JSValueMakeUndefined(context);
-               }
-
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               if (!priv) {
-                       LogError("Private object is not set.");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               }
-               INdefMessagePtr myMessage = priv->getObject();
-
-               NFCConverter converter(context);
-               
-               long recordCount = myMessage->getRecordCount();
-               long start = 0, end = recordCount;
-               if (argumentCount > 0)
-                       start = converter.toLong(arguments[0]);
-
-               if (argumentCount > 1)
-                       end = converter.toLong(arguments[1]) < recordCount ? converter.toLong(arguments[1]) : recordCount;
-
-               if (start < 0)
-                       start = recordCount + start;
-
-               if (start > end) {
-                       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject();
-                       return createArray(context, ndefMessage);
-               }
-
-               std::vector<void *> sliceRecords;
-               for (long i = start; i < end; i++) {
-                       void * record = myMessage->getRecordHandle(i);
-                       sliceRecords.push_back(record);
-               }
-               INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(sliceRecords);
-               return createArray(context, ndefMessage);
-}
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-}
-
-JSValueRef JSNdefRecordArray::sort(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("Enter");      
-       return thisObject;
-}
-
-JSValueRef JSNdefRecordArray::splice(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               if (argumentCount < 1) {
-                       return JSCreateArrayObject(context, 0, NULL);
-               }
-       
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               INdefMessagePtr myMessage = priv->getObject();
-
-               NFCConverter converter(context);
-               
-               long recordCount = myMessage->getRecordCount();
-               long start = 0;
-
-               if (argumentCount > 0)
-                       start = converter.toLong(arguments[0]);
-               long howmany = 0;
-               if (argumentCount > 1)
-                       howmany= converter.toLong(arguments[1]);
-
-               if (start < 0)
-                       start = recordCount + start;
-
-               JSObjectRef result;
-               if (howmany > 0 ) {
-                       if ((start + howmany) > recordCount)
-                               howmany = recordCount - start;
-
-                       std::vector<void *> spliceRecords;
-                       for (long i = 0; i < howmany; i++) {
-                               void * record = myMessage->getRecordHandle(i + start);
-                               spliceRecords.push_back(record);
-                       }
-                       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(spliceRecords);
-
-                       result = createArray(context, ndefMessage);
-
-                       for (long i = 0; i < howmany; i++) {
-                               myMessage->removeNDEFRecord(i);
-                       }                       
-               } else
-                       result = JSCreateArrayObject(context, 0, NULL);
-
-               if (argumentCount > 2) {
-                       for (size_t j = 2; j < argumentCount; j++) {
-                               void *record = converter.getRecordHandle(arguments[j]);
-                               if (start < recordCount)
-                                       myMessage->appendNDEFRecord(record);
-                               else
-                                       myMessage->insertNDEFRecord(start++, record);
-                       }
-               }
-               return result;
-       } Catch (UnknownException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       } Catch (PlatformException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch(NullPointerException) {
-               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(ConversionException) {
-               LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
-JSValueRef JSNdefRecordArray::toString(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       
-       return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSNdefRecordArray::unshift(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               NdefMessagePrivObject* priv =
-                       static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
-               INdefMessagePtr myMessage = priv->getObject();
-       
-               NFCConverter converter(context);
-
-               if (argumentCount > 0) {
-                       for (size_t i = 0; i < argumentCount; i++) {
-                               if (converter.isNdefRecord(arguments[i]) == false)
-                                       ThrowMsg(ConversionException, "parameter is Not record");
-                       }
-
-                       for (size_t i = 0 ; i < argumentCount; i++) {
-                               void *record = converter.getRecordHandle(arguments[i]);
-                               myMessage->insertNDEFRecord(i, record);                 
-                       }
-               }
-               return converter.toJSValueRefLong(myMessage->getRecordCount());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-}
-
-JSValueRef JSNdefRecordArray::valueOf(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       
-       return join(context, function, thisObject, 0, arguments, exception);
-}
-}
-}
diff --git a/src/NFC/JSNdefRecordArray.h b/src/NFC/JSNdefRecordArray.h
deleted file mode 100755 (executable)
index 2f0c566..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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_TIZEN_JS_NDEFRECORD_ARRAY_H_
-#define WRTPLUGINS_TIZEN_JS_NDEFRECORD_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "INdefMessage.h"
-
-namespace DeviceAPI {
-namespace NFC {
-
-class JSNdefRecordArray
-{
-  public:
-
-    static const JSClassDefinition* getClassInfo();
-
-    static JSClassRef getClassRef();
-
-    static JSObjectRef createArray(JSContextRef context,
-            const INdefMessagePtr &recordArray);
-
-       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
-       static INdefMessagePtr 
-               getNdefRecordArray(JSContextRef context, JSValueRef value);
-
-  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);
-
-    static JSValueRef getLength(JSContextRef context,
-            JSObjectRef object,
-            JSStringRef propertyName,
-            JSValueRef* exception);
-
-    static bool hasProperty(JSContextRef context,
-            JSObjectRef object,
-            JSStringRef propertyName);
-
-    static JSValueRef getProperty(JSContextRef context,
-            JSObjectRef object,
-            JSStringRef propertyName,
-            JSValueRef* exception);
-
-    static bool setProperty(JSContextRef context,
-            JSObjectRef object,
-            JSStringRef propertyName,
-            JSValueRef value,
-            JSValueRef* exception);
-
-    static void getPropertyNames(JSContextRef ctx, 
-            JSObjectRef object,
-            JSPropertyNameAccumulatorRef propertyNames);
-
-    static JSValueRef concat(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef join(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef pop(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef push(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef reverse(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef shift(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef slice(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef sort(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef splice(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef toString(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef unshift(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-    static JSValueRef valueOf(JSContextRef context,
-            JSObjectRef function,
-            JSObjectRef thisObject,
-            size_t argumentCount,
-            const JSValueRef arguments[],
-            JSValueRef* exception);
-
-    static bool checkValue(const std::string &value);
-    static JSClassRef m_jsClassRef;
-    /**
-     * This structure describes a statically declared function property.
-     */
-    static JSStaticFunction m_function[];
-
-    /**
-     * This structure contains properties and callbacks that define a type of object.
-     */
-    static JSClassDefinition m_classInfo;
-
-    /**
-     * This member variable contains the initialization values for the static properties of this class.
-     * The values are given according to the data structure JSPropertySpec
-     */
-    static JSStaticValue m_property[];
-};
-}
-}
-#endif
index 8239da3..c5bf8f9 100644 (file)
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 
 #include "NFCFactory.h"
 
@@ -55,8 +59,8 @@ JSClassDefinition JSNdefRecordMedia::m_classInfo =
        NULL, //DeleteProperty,
        NULL, //GetPropertyNames,
        NULL, //CallAsFunction,
-       constructor, //CallAsConstructor,
-       hasInstance,
+       NULL, //CallAsConstructor,
+       NULL,
        NULL, //ConvertToType
 };
 
@@ -80,46 +84,30 @@ const JSClassDefinition* JSNdefRecordMedia::getClassInfo() {
 JSClassRef JSNdefRecordMedia::m_jsClassRef = JSClassCreate(JSNdefRecordMedia::getClassInfo());
 
 JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload);
-
-       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
 }
 
 JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, const std::string &mimeType, std::vector<unsigned char> data) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(mimeType, data);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(mimeType, data));
+}
 
+JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, INdefRecordPtr ndefRecord) {
        NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
 
        if (!priv) {
                ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
        }
 
-       return JSObjectMake(context, getClassRef(), priv);
+       JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
+       return obj;
 }
 
 void JSNdefRecordMedia::initialize(JSContextRef context, JSObjectRef object) {
-       if (!JSObjectGetPrivate(object)) {
-               LogDebug("Private object not set... setting it.");
-               INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject();
-               NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-               if (!JSObjectSetPrivate(object, priv)) {
-                       delete priv;
-               }
-       }
+       LogDebug("Entered");
 }
 
 void JSNdefRecordMedia::finalize(JSObjectRef object) {
        LogDebug("Entered");
-       NdefRecordPrivObject* priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
-       JSObjectSetPrivate(object, NULL);
-       LogDebug("Deleting ndefrecord object");
-       delete priv;
 }
 
 JSObjectRef JSNdefRecordMedia::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
@@ -127,34 +115,49 @@ JSObjectRef JSNdefRecordMedia::constructor(JSContextRef ctx, JSObjectRef constru
        LogDebug("entered");
 
        Try {
-               if (argumentCount < 2) {
-                       ThrowMsg(ConversionException, "parameter count is wrong.");
-               } else if (JSValueIsNull(ctx, arguments[1]) || JSValueIsUndefined(ctx, arguments[1]) || !JSIsArrayValue(ctx, arguments[1])) {
-                       ThrowMsg(ConversionException, "parameter is JSNull/JSUndefined/Not array");
-               }
+               ArgumentValidator validator(ctx, argumentCount, arguments);
+               std::string mimeType = validator.toString(0);
+               std::vector<unsigned char> data;
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
 
                Converter convert(ctx);
-               return createJSObject(ctx, convert.toString(arguments[0]), convert.toVectorOfUChars(arguments[1]));
+               if (validator.toArrayObject(1))
+                       data = convert.toVectorOfUChars(arguments[1]);
+
+               JSObjectRef result = createJSObject(global_context, mimeType, data);
+
+               JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+           JSObjectSetProperty(global_context, result, ctorName, constructor,
+               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+           JSStringRelease(ctorName);
+               return result;
+    } Catch (BasePlatformException) {
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, _rethrown_exception);
+        *exception = error;
+        return error;
        } Catch(ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               *exception = error;
+        return error;
        } Catch (InvalidArgumentException) {
                LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               *exception = error;
+        return error;
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-               return NULL;
-       } Catch (UnknownException) {
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               *exception = error;
+        return error;
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        }
-       *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-       return NULL;
-
+       JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       *exception = error;
+       return error;
 }
 
 JSValueRef JSNdefRecordMedia::getProperty(JSContextRef context, JSObjectRef object,
@@ -181,7 +184,7 @@ JSValueRef JSNdefRecordMedia::getProperty(JSContextRef context, JSObjectRef obje
 
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -193,13 +196,6 @@ JSValueRef JSNdefRecordMedia::getProperty(JSContextRef context, JSObjectRef obje
        return JSValueMakeUndefined(context);
 }
 
-bool JSNdefRecordMedia::hasInstance(JSContextRef context,
-        JSObjectRef constructor,
-        JSValueRef possibleInstance,
-        JSValueRef* exception)
-{
-    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
 
 } //NFC
 } //DeviceAPI
index 870e708..c1f4b95 100755 (executable)
@@ -37,6 +37,10 @@ public:
 
        static JSObjectRef createJSObject(JSContextRef context, 
                const std::string &mimeType, std::vector<unsigned char> data);
+       static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
+
+    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
 private:
        /**
      * The callback invoked when an object is first created.
@@ -48,21 +52,11 @@ private:
      */
        static void finalize(JSObjectRef object);
 
-       static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
        /**
      * The callback invoked when getting a property's value.
      */
        static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
 
-    /**
-     * 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.
      */
index efc632c..9212ade 100644 (file)
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 
 #include "NFCFactory.h"
 
@@ -57,8 +61,8 @@ JSClassDefinition JSNdefRecordText::m_classInfo =
        NULL, //DeleteProperty,
        NULL, //GetPropertyNames,
        NULL, //CallAsFunction,
-       constructor, //CallAsConstructor,
-       hasInstance,
+       NULL, //CallAsConstructor,
+       NULL,
        NULL, //ConvertToType
 };
 
@@ -84,48 +88,30 @@ const JSClassDefinition* JSNdefRecordText::getClassInfo() {
 JSClassRef JSNdefRecordText::m_jsClassRef = JSClassCreate(JSNdefRecordText::getClassInfo());
 
 JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload);
-
-       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
 }
 
 JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, const std::string &text, const std::string &langCode, const short encodeType) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(text, langCode, encodeType);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(text, langCode, encodeType));
+}
 
+JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, INdefRecordPtr ndefRecord) {
        NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
 
        if (!priv) {
                ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
        }
 
-       return JSObjectMake(context, getClassRef(), priv);
+       JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
+       return obj;
 }
 
 void JSNdefRecordText::initialize(JSContextRef context, JSObjectRef object) {
        LogDebug("entered");
-
-       if (!JSObjectGetPrivate(object)) {
-               LogDebug("Private object not set... setting it.");
-               INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject();
-               NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-               if (!JSObjectSetPrivate(object, priv)) {
-                       delete priv;
-               }
-       }
 }
 
 void JSNdefRecordText::finalize(JSObjectRef object) {
        LogDebug("Entered");
-       NdefRecordPrivObject* priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
-       JSObjectSetPrivate(object, NULL);
-       LogDebug("Deleting ndefrecord object");
-       delete priv;
 }
 
 JSObjectRef JSNdefRecordText::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
@@ -133,43 +119,52 @@ JSObjectRef JSNdefRecordText::constructor(JSContextRef ctx, JSObjectRef construc
        LogDebug("entered");
 
        Try {
+               ArgumentValidator validator(ctx, argumentCount, arguments);
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
+
                NFCConverter convert(ctx);
                short encodeType = NFC_TEXT_ENCODE_UTF_8;
-               std::string text, languageCode;
-               if (argumentCount > 0)
-                       text = convert.toString(arguments[0]);
-               else
-                       text = convert.toString(JSValueMakeUndefined(ctx));
-               if (argumentCount > 1)
-                       languageCode = convert.toString(arguments[1]);
-               else
-                       languageCode = convert.toString(JSValueMakeUndefined(ctx));
-
-               if ((argumentCount > 2) && (!JSValueIsNull(ctx, arguments[2])) && (!JSValueIsUndefined(ctx, arguments[2]))) {
-                       encodeType = convert.toNfcTextEncodeUTF(convert.toString(arguments[2]));
-               }
 
-               return createJSObject(ctx, text, languageCode, encodeType);
+               std::string text = validator.toString(0);
+               std::string languageCode = validator.toString(1);
+               std::string encoding = validator.toString(2, true);
+               if (encoding != "")
+                       encodeType = convert.toNfcTextEncodeUTF(encoding);
+
+               JSObjectRef result = createJSObject(global_context, text, languageCode, encodeType);
+               JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+           JSObjectSetProperty(global_context, result, ctorName, constructor,
+               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+           JSStringRelease(ctorName);
+
+               return result;
+    } Catch (BasePlatformException) {
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, _rethrown_exception);
+        *exception = error;
+        return error;
        } Catch(ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               *exception = error;
+        return error;
        } Catch (InvalidArgumentException) {
                LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               *exception = error;
+        return error;
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-               return NULL;
-       } Catch (UnknownException) {
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               *exception = error;
+        return error;
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        }
-       *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-       return NULL;
-
+       JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       *exception = error;
+       return error;
 }
 JSValueRef JSNdefRecordText::getProperty(JSContextRef context, JSObjectRef object,
        JSStringRef propertyName, JSValueRef* exception) {
@@ -212,7 +207,7 @@ JSValueRef JSNdefRecordText::getProperty(JSContextRef context, JSObjectRef objec
 
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -224,14 +219,6 @@ JSValueRef JSNdefRecordText::getProperty(JSContextRef context, JSObjectRef objec
        return JSValueMakeUndefined(context);
 }
 
-bool JSNdefRecordText::hasInstance(JSContextRef context,
-        JSObjectRef constructor,
-        JSValueRef possibleInstance,
-        JSValueRef* exception)
-{
-    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
 } //NFC
 } //DeviceAPI
 
index a63a59f..87e9181 100755 (executable)
@@ -37,6 +37,10 @@ public:
 
        static JSObjectRef createJSObject(JSContextRef context, const std::string &text, 
                const std::string &langCode, const short encodeType);
+       static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
+
+    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
 private:
        /**
      * The callback invoked when an object is first created.
@@ -48,21 +52,11 @@ private:
      */
        static void finalize(JSObjectRef object);
 
-       static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
        /**
      * The callback invoked when getting a property's value.
      */
        static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
 
-    /**
-     * 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.
      */
index bf50ada..b67ba88 100644 (file)
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
 #include <CommonsJavaScript/Converter.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <JSWebAPIException.h>
+#include <PlatformException.h>
 
 #include "NFCFactory.h"
 #include "JSNdefRecordURI.h"
@@ -54,8 +58,8 @@ JSClassDefinition JSNdefRecordURI::m_classInfo =
        NULL, //DeleteProperty,
        NULL, //GetPropertyNames,
        NULL, //CallAsFunction,
-       constructor, //CallAsConstructor,
-       hasInstance,
+       NULL, //CallAsConstructor,
+       NULL,
        NULL, //ConvertToType
 };
 
@@ -80,47 +84,29 @@ JSClassRef JSNdefRecordURI::m_jsClassRef = JSClassCreate(JSNdefRecordURI::getCla
 
 void JSNdefRecordURI::initialize(JSContextRef context, JSObjectRef object) {
        LogDebug("entered");
-
-       if (!JSObjectGetPrivate(object)) {
-               LogDebug("Private object not set... setting it.");
-               INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject();
-               NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-               if (!JSObjectSetPrivate(object, priv)) {
-                       delete priv;
-               }
-       }
 }
 
 void JSNdefRecordURI::finalize(JSObjectRef object) {
        LogDebug("Entered");
-       NdefRecordPrivObject* priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
-       JSObjectSetPrivate(object, NULL);
-       LogDebug("Deleting ndefrecord object");
-       delete priv;
 }
 
 JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload);
-
-       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
-       }
-
-       return JSObjectMake(context, getClassRef(), priv);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
 }
 
 JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, const std::string &uri) {
-       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(uri);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(uri));
+}
 
+JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, INdefRecordPtr ndefRecord) {
        NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
 
        if (!priv) {
                ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
        }
 
-       return JSObjectMake(context, getClassRef(), priv);
+       JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
+       return obj;
 }
 
 JSObjectRef JSNdefRecordURI::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
@@ -128,32 +114,43 @@ JSObjectRef JSNdefRecordURI::constructor(JSContextRef ctx, JSObjectRef construct
        LogDebug("entered");
 
        Try {
-               Converter convert(ctx);
-
-               if (argumentCount > 0)
-                       return createJSObject(ctx, convert.toString(arguments[0]));
-               else
-                       return createJSObject(ctx, convert.toString(JSValueMakeUndefined(ctx)));
+               ArgumentValidator validator(ctx, argumentCount, arguments);
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
+
+               JSObjectRef result = createJSObject(global_context, validator.toString(0));
+
+               JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+           JSObjectSetProperty(global_context, result, ctorName, constructor,
+               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+           JSStringRelease(ctorName);
+               return result;
+    } Catch (BasePlatformException) {
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(ctx, _rethrown_exception);
+        *exception = error;
+        return error;
        } Catch(ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               *exception = error;
+        return error;
        } Catch (InvalidArgumentException) {
                LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
-               return NULL;
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               *exception = error;
+        return error;
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-               return NULL;
-       } Catch (UnknownException) {
+               JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               *exception = error;
+        return error;
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        }
-       *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-       return NULL;
-
+       JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       *exception = error;
+       return error;
 }
 JSValueRef JSNdefRecordURI::getProperty(JSContextRef context, JSObjectRef object,
        JSStringRef propertyName, JSValueRef* exception) {
@@ -178,7 +175,7 @@ JSValueRef JSNdefRecordURI::getProperty(JSContextRef context, JSObjectRef object
                }
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformException: " << _rethrown_exception.GetMessage());
@@ -190,13 +187,6 @@ JSValueRef JSNdefRecordURI::getProperty(JSContextRef context, JSObjectRef object
        return JSValueMakeUndefined(context);
 }
 
-bool JSNdefRecordURI::hasInstance(JSContextRef context,
-        JSObjectRef constructor,
-        JSValueRef possibleInstance,
-        JSValueRef* exception)
-{
-    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
 
 } //NFC
 } //DeviceAPI
index cff3f59..c446607 100755 (executable)
@@ -36,6 +36,11 @@ public:
                const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
 
        static JSObjectRef createJSObject(JSContextRef context, const std::string &uri);
+
+       static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
+
+    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
 private:
        /**
      * The callback invoked when an object is first created.
@@ -47,21 +52,11 @@ private:
      */
        static void finalize(JSObjectRef object);
 
-       static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-
        /**
      * The callback invoked when getting a property's value.
      */
        static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
 
-    /**
-     * 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.
      */
index 1a165b4..a7aadcd 100755 (executable)
@@ -184,16 +184,18 @@ void NFCAdapter::OnRequestReceived(const EventNFCChangedSetPoweredPtr& event) {
 
 void NFCAdapter::setPoweredManualAnswer(int error) {
        if (m_EventNFCChangedSetPoweredPtr.Get() != NULL) {
+               EventNFCChangedSetPoweredPtr event = m_EventNFCChangedSetPoweredPtr;
+               m_EventNFCChangedSetPoweredPtr.Reset();
+
                if (error == NFC_ERROR_NONE) {
-                       m_EventNFCChangedSetPoweredPtr->setResult(true);
+                       event->setResult(true);
                } else {
                        NFCUtil util;
-                       m_EventNFCChangedSetPoweredPtr->setResult(false);
-                       m_EventNFCChangedSetPoweredPtr->setError(util.getNFCErrorString(error));
-                       m_EventNFCChangedSetPoweredPtr->setErrorMessage(util.getNFCErrorMessage(error));
+                       event->setResult(false);
+                       event->setError(util.getNFCErrorString(error));
+                       event->setErrorMessage(util.getNFCErrorMessage(error));
                }
-               EventRequestReceiver<EventNFCChangedSetPowered>::ManualAnswer(m_EventNFCChangedSetPoweredPtr);
-               m_EventNFCChangedSetPoweredPtr.Reset();
+               EventRequestReceiver<EventNFCChangedSetPowered>::ManualAnswer(event);
        }
 }
 
index d5deb1a..e30edf5 100755 (executable)
@@ -264,6 +264,17 @@ JSValueRef NFCConverter::toJSValueRef(std::vector<NFCTagProperties> props) {
        return jsResult;
 }
 
+JSValueRef NFCConverter::toJSNdefRecordArray(INdefMessagePtr ndefMessage) {
+       long recordCount = ndefMessage->getRecordCount();
+       std::vector<JSValueRef> jsResult;
+
+       for (long i = 0; i < recordCount; i++) {
+               JSValueRef ndefRecord = toJSValueRef(ndefMessage->getNDEFRecord(i));
+               jsResult.push_back(ndefRecord);
+       }
+       return toJSValueRef(jsResult);
+}
+
 bool NFCConverter::isNdefRecord(const JSValueRef& arg) {
        LogDebug("Entered");
        if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg)) {
@@ -289,14 +300,25 @@ std::vector<void *> NFCConverter::toVectorOfRecordHandles(const JSValueRef& arg)
         ThrowMsg(Commons::ConversionException, "Argument is not an JS array.");
     }
 
+       JSObjectRef obj = toJSObjectRef(arg);
+       
+       if (!obj) {
+               LogError("Object is null");
+               ThrowMsg(Commons::ConversionException, "Object is null");
+       }
+
+    return toVectorOfRecordHandles(obj);
+}
+
+std::vector<void *> NFCConverter::toVectorOfRecordHandles(const JSObjectRef& obj) {
     std::vector<void *> result;
-    JSObjectRef objArg = toJSObjectRef(arg);
-    for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); ++i) {
-        JSValueRef element = JSGetArrayElement(m_context, objArg, i);
+
+    for (std::size_t i = 0; i < JSGetArrayLength(m_context, obj); ++i) {
+        JSValueRef element = JSGetArrayElement(m_context, obj, i);
        if (isNdefRecord(element))
                result.push_back(getRecordHandle(element));
        else
-               ThrowMsg(Commons::ConversionException, "JS array has no record.");
+               ThrowMsg(Commons::ConversionException, "JS array has items those are not NDEFRecord.");
     }
     return result;
 }
@@ -338,7 +360,7 @@ void *NFCConverter::getRecordHandle(const JSValueRef& arg) {
        return record->getHandle();
 }
 
-void *NFCConverter::getMessageHandle(const JSValueRef& arg) {
+void *NFCConverter::copiedMessage(const JSValueRef& arg) {
        if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg) ||
                (!JSValueIsObjectOfClass(m_context, arg, JSNdefMessage::getClassRef()))) {
                ThrowMsg(Commons::ConversionException,
@@ -350,6 +372,10 @@ void *NFCConverter::getMessageHandle(const JSValueRef& arg) {
                LogError("Object is null");
                ThrowMsg(Commons::ConversionException, "Object is null");
        }
+       return copiedMessage(obj);
+}
+
+void *NFCConverter::copiedMessage(const JSObjectRef& obj) {
        NdefMessagePrivObject* privateObject = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(obj));
        if (!privateObject) {
                LogError("Private object is not set.");
@@ -358,7 +384,7 @@ void *NFCConverter::getMessageHandle(const JSValueRef& arg) {
 
        INdefMessagePtr message = privateObject->getObject();
 
-       return message->getHandle();
+       return message->makeMessage(message->toByte());
 }
 
 NFCChangedCallback NFCConverter::toNFCChangedCallback(const JSValueRef& arg) {
index ecdb70e..15c9e27 100755 (executable)
@@ -28,6 +28,7 @@
 #include "NdefRecordProperties.h"
 #include "NFCTagProperties.h"
 #include "INdefRecord.h"
+#include "INdefMessage.h"
 #include "EventNFCChanged.h"
 #include "NFCChangedCallback.h"
 
@@ -53,9 +54,12 @@ class NFCConverter : public WrtDeviceApis::CommonsJavaScript::Converter
        JSValueRef toJSValueRef(NdefRecordData arg);
        bool isNdefRecord(const JSValueRef& arg);
        std::vector<void *> toVectorOfRecordHandles(const JSValueRef& arg);
+       std::vector<void *> toVectorOfRecordHandles(const JSObjectRef& obj);
        std::string toRecordClassName(NdefRecordData arg);
        void *getRecordHandle(const JSValueRef& arg);
-       void *getMessageHandle(const JSValueRef& arg);
+       void *copiedMessage(const JSValueRef& arg);
+       void *copiedMessage(const JSObjectRef& obj);
+       JSValueRef toJSNdefRecordArray(INdefMessagePtr ndefMessage);
        NFCChangedCallback toNFCChangedCallback(const JSValueRef& arg);
   private:
     bool initializeAllowedProperties();
index 8d2a688..dfe7e6a 100755 (executable)
@@ -88,6 +88,31 @@ NFCDefaultAdapter::~NFCDefaultAdapter() {
        deinitialze();
 }
 
+void NFCDefaultAdapter::setExclusiveMode(bool mode) {
+       LogDebug("Enter");
+       LogDebug("initilized:" << m_initialized);
+       if (!m_initialized) {
+
+               if (nfc_manager_initialize_sync() != NFC_ERROR_NONE) {
+                       ThrowMsg(UnknownException, "Could not initialize NFC.");
+               }
+               m_initialized = true;
+/*
+               if (initialize() != NFC_ERROR_NONE) {
+                       m_NFCTagListeners.clear();
+                       ThrowMsg(PlatformException, "Could not initialize NFC.");
+               }
+               m_initialized = true;
+*/
+       }
+       bool bEnabled = !mode;
+       LogDebug("system handeler enable?" << bEnabled);
+       // If exclusive mode is true, system handler has to be disabled.
+       if (nfc_manager_set_system_handler_enable(!bEnabled) != NFC_ERROR_NONE)
+               ThrowMsg(UnknownException, "Failed to set exclusive mode.");
+       LogDebug("End");
+}
+
 bool NFCDefaultAdapter::isSupported() {
        return nfc_manager_is_supported();
 }
@@ -103,6 +128,8 @@ void NFCDefaultAdapter::deinitialze() {
        nfc_manager_unset_tag_discovered_cb();
        nfc_manager_unset_p2p_target_discovered_cb();
 
+       unsetExclusiveMode();
+
        if(m_initialized == true)
        {
                result = nfc_manager_deinitialize ();
@@ -115,6 +142,13 @@ void NFCDefaultAdapter::deinitialze() {
        LogDebug("destroy nfc");
 }
 
+void NFCDefaultAdapter::unsetExclusiveMode() {
+       LogDebug("entered");
+       if (m_initialized)
+               if (nfc_manager_set_system_handler_enable(true) != NFC_ERROR_NONE)
+                       LogDebug("failed to unset exclusive mode");
+}
+
 int NFCDefaultAdapter::setTagListener(NFCAdapter * adapter) {
        LogDebug(" NFCDefaultAdapter::setTagListener Entered");
        int result = -1;
@@ -126,6 +160,7 @@ int NFCDefaultAdapter::setTagListener(NFCAdapter * adapter) {
                        m_NFCTagListeners.clear();
                        ThrowMsg(PlatformException, "Could not initialize NFC.");
                }
+               nfc_manager_set_tag_filter(NFC_TAG_FILTER_ALL_ENABLE);
        } else {
                nfc_tag_h currentTag;
                if (nfc_manager_get_connected_tag(&currentTag) == NFC_ERROR_NONE)
@@ -183,9 +218,8 @@ void NFCDefaultAdapter::unsetTagListener(NFCAdapter * adapter) {
        LogDebug(" NFCDefaultAdapter::unsetTagListener Entered");
 
        if (!m_initialized) {
-               if (initialize() != NFC_ERROR_NONE) {
-                       ThrowMsg(PlatformException, "Could not initialize NFC.");
-               }
+               m_NFCTagListeners.clear();
+               return;
        }
 
        std::vector<NFCAdapter *>::iterator it;
@@ -205,9 +239,8 @@ void NFCDefaultAdapter::unsetPeerListener(NFCAdapter * adapter) {
        LogDebug(" NFCDefaultAdapter::unsetPeerListener Entered");
 
        if (!m_initialized) {
-               if (initialize() != NFC_ERROR_NONE) {
-                       ThrowMsg(PlatformException, "Could not initialize NFC.");
-               }
+               m_NFCTagListeners.clear();
+               return;
        }
 
        std::vector<NFCAdapter *>::iterator it;
@@ -276,7 +309,6 @@ int NFCDefaultAdapter::initialize() {
                m_initialized = false;
        } else {
                m_initialized = true;
-               nfc_manager_set_tag_filter(NFC_TAG_FILTER_ALL_ENABLE);
        }
        return result;
 }
@@ -286,17 +318,11 @@ void *NFCDefaultAdapter::getCachedMessage() {
        nfc_ndef_message_h messageHandle = NULL;
        int result = nfc_manager_get_cached_message(&messageHandle);
        if ((result == NFC_ERROR_INVALID_NDEF_MESSAGE) || (result == NFC_ERROR_NO_NDEF_MESSAGE)) {
-               if (messageHandle)
-                       nfc_ndef_message_destroy(messageHandle);
-
                return NULL;
        }
 
        NFCUtil util;
        if (result != NFC_ERROR_NONE) {
-               if (messageHandle)
-                       nfc_ndef_message_destroy(messageHandle);
-
                util.throwNFCException(result, "Can't get cached message");
        }
        return (void *)(messageHandle);
index 500993f..36154d9 100755 (executable)
@@ -59,6 +59,9 @@ public:
        void setPowered(const bool state, NFCAdapter * adapter);
        void setPoweredManualAnswer(int error);
 
+
+       void setExclusiveMode(bool mode);
+       void unsetExclusiveMode();
        bool isSupported();
        void deinitialze();
 private:
index 5418c35..40b2e8c 100755 (executable)
@@ -31,7 +31,6 @@
 #include "EventNFCChangedPrivateData.h"
 #include "JSNFCTag.h"
 #include "JSNFCTarget.h"
-#include "JSNdefMessage.h"
 #include "NFCConverter.h"
 #include "NFCAsyncCallbackManager.h"
 
index ca5bc0e..7e993ac 100644 (file)
@@ -195,23 +195,12 @@ void NFCTag::writeNdef(const EventTagActionWritePtr& event) {
        if (!isNDEFSupport())
                ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Not Support NDEF");
 
-       nfc_ndef_message_h srcHandle = static_cast<nfc_ndef_message_h>(event->getNdefForWriting());
-       nfc_ndef_message_h destHandle = NULL;
-
-       NFCUtil util;
-       if (util.copyNDEFMessage((void **)&srcHandle, (void **)&destHandle)) {
-               if (destHandle != NULL) {
-                       event->setNdefForWriting((void *)destHandle);
-
-                       if (m_EventTagActionWritePtr.Get() != NULL)
-                               EventTagActionWrites.push_back(event);
-                       else
-                               EventRequestReceiver<EventTagActionWrite>::PostRequest(event);
+       if (m_EventTagActionWritePtr.Get() != NULL)
+               EventTagActionWrites.push_back(event);
+       else
+               EventRequestReceiver<EventTagActionWrite>::PostRequest(event);
 
-                       return;
-               }
-       }
-       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can't copy NdefMessage");
+       return;
 }
 
 void NFCTag::transceive(const EventTagActionTransceivePtr& event) {
index 17863e1..a6376ca 100755 (executable)
@@ -137,22 +137,13 @@ void NFCTarget::unsetReceiveNDEFListener() {
 void NFCTarget::sendNDEF(const EventTargetActionSendPtr& event) {
        LogDebug("Enter");
 
-       nfc_ndef_message_h  srcHandle = static_cast<nfc_ndef_message_h>(event->getMessageForSending());
-       nfc_ndef_message_h destHandle = NULL;
+       if (m_EventTargetActionSendPtr.Get() != NULL)
+               m_EventTargetActionSends.push_back(event);
+       else
+               EventRequestReceiver<EventTargetActionSend>::PostRequest(event);
 
-       NFCUtil util;
-       if (util.copyNDEFMessage((void **)&srcHandle, (void **)&destHandle)) {
-               if (destHandle != NULL) {
-                       event->setMessageForSending((void *)destHandle);
-
-                       if (m_EventTargetActionSendPtr.Get() != NULL)
-                               m_EventTargetActionSends.push_back(event);
-                       else
-                               EventRequestReceiver<EventTargetActionSend>::PostRequest(event);
+       return;
 
-                       return;
-               }
-       }
        ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can't copy NdefMessage");
 }
 
index b069dff..b147d20 100755 (executable)
@@ -231,29 +231,6 @@ bool NFCUtil::copyNDEFRecord(void **src, void **dest) {
        return true;
 }
 
-bool NFCUtil::copyNDEFMessage(void **src, void **dest) {
-       nfc_ndef_message_h *srcHandle, *destHandle;
-       srcHandle = (nfc_ndef_message_h *)src;
-       destHandle = (nfc_ndef_message_h *)dest;
-
-       unsigned char *rawdata;
-       int size;
-       int result = nfc_ndef_message_get_rawdata(*srcHandle, &rawdata, &size);
-
-       if (result != NFC_ERROR_NONE)
-               return false;
-
-       if (nfc_ndef_message_create_from_rawdata(destHandle, rawdata, size) != NFC_ERROR_NONE) {
-               if (rawdata)
-                       free(rawdata);
-               return false;
-       }
-
-       if (rawdata)
-               free(rawdata);
-       return true;
-}
-
 std::string NFCUtil::getNFCErrorString(const int errorCode) {
        LogDebug ("Errorcode : " << errorCode);
        switch(errorCode) {
@@ -317,7 +294,8 @@ std::string NFCUtil::getNFCErrorMessage(const int errorCode) {
 
 void NFCUtil::throwNFCException(const int errorCode, const std::string &message) {
        LogDebug ("Errorcode : " << static_cast<unsigned int>(errorCode));
-       LogDebug ("Message : " << message);
+       if (errorCode != errorCode)
+               LogDebug ("Message : " << message);
 
        switch(errorCode) {
                case NFC_ERROR_NONE:
index 5dc335f..1ec835b 100755 (executable)
@@ -44,7 +44,6 @@ class NFCUtil
        nfcTNF convertTonfcTNF(unsigned short tnf);
        NdefRecordData getNDEFRecordData(void *handle);
        bool copyNDEFRecord(void **src, void **dest);
-       bool copyNDEFMessage(void **src, void **dest);
        std::string getNFCErrorString(const int errorCode);
        std::string getNFCErrorMessage(const int errorCode);
        void throwNFCException(const int errorCode, const std::string &message);
index b023692..707a89b 100755 (executable)
@@ -31,6 +31,7 @@ using namespace WrtDeviceApis::Commons;
 NdefMessage::NdefMessage()
 {
        LogDebug("entered");
+       recordPtr = NULL;
        NFCUtil util;
        int result = nfc_ndef_message_create(&handle);
 
@@ -43,7 +44,7 @@ NdefMessage::NdefMessage()
 NdefMessage::NdefMessage(void *messageHandle)
 {
        LogDebug("entered");
-
+       recordPtr = NULL;
        if (messageHandle == NULL) {
                handle = NULL;
                ThrowMsg(UnknownException, "Message Handler is Null Pointer.");
@@ -55,41 +56,31 @@ NdefMessage::NdefMessage(void *messageHandle)
 NdefMessage::NdefMessage(std::vector<void *> &ndefRcords)
 {
        LogDebug("entered");
-
-       _makeMessage(ndefRcords);
+       recordPtr = NULL;
+       handle = NULL;
+       handle = static_cast<nfc_ndef_message_h>(makeMessage(ndefRcords));
 }
 
 NdefMessage::NdefMessage(const std::vector<unsigned char> &rawdata)
 {
        LogDebug("entered");
-
-       NFCUtil util;
-       unsigned char *messageRawdata = util.toCharPtr(rawdata);
-       int result = nfc_ndef_message_create_from_rawdata(&handle, messageRawdata, rawdata.size());
-
-       if (result != NFC_ERROR_NONE) {
-               handle = NULL;
-               if (messageRawdata)
-                       free(messageRawdata);
-               util.throwNFCException(result, "Can't create Ndef Message");
-       }
-
-       free(messageRawdata);
+       recordPtr = NULL;
+       handle = static_cast<nfc_ndef_message_h>(makeMessage(rawdata));
 }
 
 NdefMessage::~NdefMessage()
 {
-       LogDebug("entered");
+       LogDebug("entered"<<recordPtr);
        if (handle != NULL)
                nfc_ndef_message_destroy(handle);
 }
 
-void NdefMessage::_makeMessage(std::vector<void *> &ndefRcords) {
+void *NdefMessage::makeMessage(std::vector<void *> &ndefRcords) {
        NFCUtil util;
-       int result = nfc_ndef_message_create(&handle);
+       nfc_ndef_message_h message;
+       int result = nfc_ndef_message_create(&message);
 
        if (result != NFC_ERROR_NONE) {
-               handle = NULL;
                util.throwNFCException(result, "Can't create Ndef Message");
        }
 
@@ -101,28 +92,44 @@ void NdefMessage::_makeMessage(std::vector<void *> &ndefRcords) {
                        ThrowMsg(UnknownException, "Can't copy Record");
                }
 
-               result = nfc_ndef_message_append_record(handle, insertRecord);
+               result = nfc_ndef_message_append_record(message, insertRecord);
 
                if (result != NFC_ERROR_NONE) {
-                       LogError(i << " record can't be inserted. " << insertRecord << " : " << handle);
+                       LogError(i << " record can't be inserted. " << insertRecord << " : " << message);
+                       nfc_ndef_message_destroy(message);
                        util.throwNFCException(result, "Can't insert record in Ndef Message");
                }
        }
+       return (void*)message;
 }
 
-void *NdefMessage::getHandle() {
-       return (void *)handle;
-}
+void *NdefMessage::makeMessage(const std::vector<unsigned char> &rawdata) {
+       NFCUtil util;
+       unsigned char *messageRawdata = util.toCharPtr(rawdata);
+       nfc_ndef_message_h message;
+       int result = nfc_ndef_message_create_from_rawdata(&message, messageRawdata, rawdata.size());
 
-void *NdefMessage::getRecordHandle(const long index) {
-       nfc_ndef_record_h recordHandle;
-       int result = nfc_ndef_message_get_record(handle, static_cast<int>(index), &recordHandle);
+       if (result != NFC_ERROR_NONE) {
+               handle = NULL;
+               if (messageRawdata)
+                       free(messageRawdata);
+               util.throwNFCException(result, "Can't create Ndef Message");
+       }
+       if (messageRawdata)
+               free(messageRawdata);
 
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get Ndef Record");
+       return (void*)message;
+}
+
+void NdefMessage::setRecordesPtr(void *records) {
+       LogDebug("entered"<<records);
+       recordPtr = records;
+}
 
-       return (void *)recordHandle;
+void* NdefMessage::getRecordesPtr() {
+       LogDebug("entered"<<recordPtr);
+       
+       return recordPtr;
 }
 
 long NdefMessage::getRecordCount() {
@@ -171,58 +178,6 @@ NdefRecordData NdefMessage::getNDEFRecord(const long index) {
        return util.getNDEFRecordData(recordHandle);
 }
 
-bool NdefMessage::insertNDEFRecord(const long index, void *recordHandle) {
-       nfc_ndef_record_h insertRecord;
-
-       NFCUtil util;
-       if (!util.copyNDEFRecord(&recordHandle, (void **)(&insertRecord))) {
-               LogDebug("copyNDEFRecord fail!");
-               ThrowMsg(UnknownException, "Can't copy Record");
-       }
-
-       int result = nfc_ndef_message_insert_record(handle, static_cast<int>(index), insertRecord);
-
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't insert ndef Record");
-
-       return TRUE;
-}
-
-bool NdefMessage::appendNDEFRecord(void *recordHandle) {
-       nfc_ndef_record_h appendRecord;
-
-       NFCUtil util;
-       if (!util.copyNDEFRecord(&recordHandle, (void **)(&appendRecord))) {
-               LogDebug("copyNDEFRecord fail!");
-               ThrowMsg(UnknownException, "Can't copy Record");
-       }
-
-       int result = nfc_ndef_message_append_record(handle, appendRecord);
-
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't insert Ndef Record");
-
-       return TRUE;
-}
-
-bool NdefMessage::removeNDEFRecord(const long index) {
-       int result = nfc_ndef_message_remove_record(handle, static_cast<int>(index));
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't remove ndef Record");
-
-       return TRUE;
-}
-
-void NdefMessage::changeAllRecords(std::vector<void *> &ndefRecords) {
-       nfc_ndef_message_h newHandle = handle;
-       handle = NULL;
-
-       _makeMessage(ndefRecords);
-       if (newHandle != NULL)
-               nfc_ndef_message_destroy(newHandle);
-}
 
 }
 }
index 426c2b8..92ebbf7 100755 (executable)
@@ -38,18 +38,17 @@ class NdefMessage : public INdefMessage
                NdefMessage(const std::vector<unsigned char> &rawdata);
        virtual  ~NdefMessage();
 
-       virtual void *getHandle();
-       virtual void *getRecordHandle(const long index);
        virtual std::vector<unsigned char> toByte();
        virtual long getRecordCount();
        virtual NdefRecordData getNDEFRecord(const long index);
-       virtual bool insertNDEFRecord(const long index, void *recordHandle);
-       virtual bool appendNDEFRecord(void *recordHandle);
-       virtual bool removeNDEFRecord(const long index);
-       virtual void changeAllRecords(std::vector<void *> &ndefRecords);
+
+       virtual void *makeMessage(std::vector<void *> &ndefRcords);
+       virtual void *makeMessage(const std::vector<unsigned char> &rawdata);
+       virtual void setRecordesPtr(void *records);
+       virtual void* getRecordesPtr();
     private:
        nfc_ndef_message_h handle;
-       void _makeMessage(std::vector<void *> &ndefRcords);
+       void *recordPtr;
 };
 
 }
index 0e0ed93..34d8607 100755 (executable)
@@ -44,8 +44,6 @@ NdefRecord::NdefRecord(std::vector<unsigned char> data)
        int result = nfc_ndef_message_create_from_rawdata(&messageHandle, rawdata, data.size());
 
        if (result != NFC_ERROR_NONE) {
-               if (messageHandle)
-                       nfc_ndef_message_destroy(messageHandle);
                messageHandle = NULL;
                if (rawdata)
                        free(rawdata);
@@ -322,57 +320,5 @@ std::vector<unsigned char> NdefRecord::getPayload() {
        return util.toVector(recordbuffer, size);
 }
 
-std::vector<unsigned char> NdefRecord::toByte() {
-       LogDebug("entered");
-
-       nfc_ndef_record_h copy_record;
-       nfc_ndef_message_h temp_message;
-       NFCUtil util;
-
-       if (!util.copyNDEFRecord((void **)&handle, (void **)(&copy_record))) {
-               ThrowMsg(UnknownException, "Can't copy Ndef Record");
-       }
-
-       int result = nfc_ndef_message_create(&temp_message);
-
-       if (result != NFC_ERROR_NONE) {
-               if (copy_record != NULL)
-                       nfc_ndef_record_destroy(copy_record);
-               util.throwNFCException(result, "Can't create Ndef Message");
-       }
-
-       result = nfc_ndef_message_append_record(temp_message, copy_record);
-       if (result != NFC_ERROR_NONE) {
-               if (temp_message != NULL)
-                       nfc_ndef_message_destroy(temp_message);
-               else if (copy_record != NULL)
-                       nfc_ndef_record_destroy(copy_record);
-               util.throwNFCException(result, "Can't append ndef Record");
-       }
-
-       unsigned char *rawdata;
-       int size;
-
-       result = nfc_ndef_message_get_rawdata(temp_message, &rawdata, &size);
-       if (result != NFC_ERROR_NONE) {
-               if (temp_message != NULL)
-                       nfc_ndef_message_destroy(temp_message);
-               else if (copy_record != NULL)
-                       nfc_ndef_record_destroy(copy_record);
-               util.throwNFCException(result, "Can't get serial bytes of NDEF message");
-       }
-
-       if (temp_message != NULL)
-               nfc_ndef_message_destroy(temp_message);
-       else if (copy_record != NULL)
-               nfc_ndef_record_destroy(copy_record);
-
-       std::vector<unsigned char> byteData = util.toVector(rawdata, size);
-       if (rawdata)
-               free(rawdata);
-
-       return byteData;
-}
-
 }
 }
index f943cf9..e7020e5 100755 (executable)
@@ -46,7 +46,6 @@ class NdefRecord : public INdefRecord
        virtual std::vector<unsigned char> getTypeName();
        virtual std::vector<unsigned char> getID();
        virtual std::vector<unsigned char> getPayload();
-       virtual std::vector<unsigned char> toByte();
        virtual bool getText(char **text);
        virtual bool getLangCode(char **langCode);
        virtual bool getEncodeType(nfcTextEncodeUTF *encodeType);
index 7a5c781..6865243 100755 (executable)
@@ -18,6 +18,7 @@
 #include <dpl/log/log.h>
 #include <Commons/plugin_initializer_def.h>
 #include <Commons/WrtAccess/WrtAccess.h>
+#include <GlobalContextManager.h>
 #include "JSNFCManager.h"
 #include "JSNdefMessage.h"
 #include "JSNdefRecord.h"
 #include "JSNdefRecordMedia.h"
 #include "NFCAsyncCallbackManager.h"
 #include "NFCListenerManager.h"
+#include "NFCDefaultAdapter.h"
 
 using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace NFC {
+
+class_definition_options_t ConstructorClassOptions =
+{
+    JS_INTERFACE,
+    CREATE_INSTANCE,
+    NONE_NOTICE,
+    USE_OVERLAYED, //ignored
+    NULL,
+    NULL,
+    NULL
+};
 
 void on_widget_start_callback(int widgetId)
 {
@@ -59,14 +76,16 @@ void on_widget_stop_callback(int widgetId)
 void on_frame_load_callback(const void * context)
 {
        LogDebug("[Tizen\\NFC] on_frame_load_callback (" << context << ")");
+    GlobalContextManager::getInstance()->addGlobalContext(static_cast<JSContextRef>(context));
 }
 
 void on_frame_unload_callback(const void * context)
 {
        LogDebug("[Tizen\\NFC] on_frame_unload_callback (" << context << ")");
-
+       GlobalContextManager::getInstance()->removeGlobalContext(static_cast<JSContextRef>(context));
        DeviceAPI::NFC::NFCAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
        DeviceAPI::NFC::NFCListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+       DeviceAPI::NFC::NFCDefaultAdapterSingleton::Instance().unsetExclusiveMode();
 }
 
 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
@@ -75,11 +94,36 @@ PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
 PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
 
 PLUGIN_CLASS_MAP_BEGIN
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "nfc", (js_class_template_getter)DeviceAPI::NFC::JSNFCManager::getClassRef, NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFMessage", (js_class_template_getter)DeviceAPI::NFC::JSNdefMessage::getClassRef, NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecord", (js_class_template_getter)DeviceAPI::NFC::JSNdefRecord::getClassRef, NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecordText", (js_class_template_getter)DeviceAPI::NFC::JSNdefRecordText::getClassRef, NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecordURI", (js_class_template_getter)DeviceAPI::NFC::JSNdefRecordURI::getClassRef, NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecordMedia", (js_class_template_getter)DeviceAPI::NFC::JSNdefRecordMedia::getClassRef, NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "nfc",
+        (js_class_template_getter)JSNFCManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "NDEFMessage",
+        (js_class_template_getter)JSNdefMessage::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(JSNdefMessage::constructor),
+        &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "NDEFRecord",
+        (js_class_template_getter)JSNdefRecord::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(JSNdefRecord::constructor),
+        &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "NDEFRecordText",
+        (js_class_template_getter)JSNdefRecordText::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(JSNdefRecordText::constructor),
+        &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "NDEFRecordURI",
+        (js_class_template_getter)JSNdefRecordURI::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(JSNdefRecordURI::constructor),
+        &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "NDEFRecordMedia",
+        (js_class_template_getter)JSNdefRecordMedia::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(JSNdefRecordMedia::constructor),
+        &ConstructorClassOptions)
 PLUGIN_CLASS_MAP_END
 
+} // NFC
+} // DeviceAPI
index 138db9b..d985b05 100755 (executable)
@@ -33,6 +33,7 @@ namespace NetworkBearerSelection {
     
 static void connection_state_changed_callback(connection_profile_state_e state, void* user_data)
 {
+    LogDebug("enter");
     if(user_data != NULL) {
         LogDebug("Callback registration Succeeded");
         NewtorkBearerSelectionPendingEvent *pendingEvent = (NewtorkBearerSelectionPendingEvent *)user_data;
@@ -53,6 +54,7 @@ static void connection_state_changed_callback(connection_profile_state_e state,
 
 static void connection_opened_callback(connection_error_e result, void* user_data)
 {
+    LogDebug("enter");
        if (result ==  CONNECTION_ERROR_NONE) {
         LogDebug("Connection open Succeeded");
         if(user_data != NULL) {
@@ -71,6 +73,7 @@ static void connection_opened_callback(connection_error_e result, void* user_dat
 
 static void connection_closed_callback(connection_error_e result, void* user_data)
 {
+    LogDebug("enter");
        if (result ==  CONNECTION_ERROR_NONE) {
                LogDebug("Connection close Succeeded");
         if (user_data != NULL) {
@@ -87,8 +90,18 @@ static void connection_closed_callback(connection_error_e result, void* user_dat
     }
 }
 
+static void connection_closed_callback2(connection_error_e result, void* user_data)
+{
+    LogDebug("enter");
+       if (result ==  CONNECTION_ERROR_NONE) {
+               LogDebug("Connection close Succeeded");
+    }
+}
+
+
 static void connection_removed_callback(connection_error_e result, void* user_data)
 {
+    LogDebug("enter");
     if (user_data != NULL) {
         if (result ==  CONNECTION_ERROR_NONE) {
             LogDebug("Connection close Succeeded");
@@ -107,7 +120,8 @@ static void connection_removed_callback(connection_error_e result, void* user_da
 }
 
 NetworkBearerSelection::NetworkBearerSelection() : m_connectionHandle(NULL),
-                                                   m_profileHandle(NULL)
+                                                   m_profileHandle(NULL),
+                                                   m_connectionState(NETWORK_UNKNOWN)
 {
     int ret = connection_create(&m_connectionHandle);
 
@@ -131,21 +145,19 @@ NetworkBearerSelection::~NetworkBearerSelection()
 
 void NetworkBearerSelection::requestRouteToHost(const EventNetworkBearerSelectionPtr &event)
 {
-    LogDebug("enter");
     EventRequestReceiver<EventNetworkBearerSelection>::PostRequest(event);
 }
 
 void NetworkBearerSelection::releaseRouteToHost(const EventNetworkBearerReleasePtr &event)
 {
-    LogDebug("enter");
     EventRequestReceiver<EventNetworkBearerRelease>::PostRequest(event);
 }
 
 void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerSelectionPtr &event)
 {
-    LogDebug("enter");
+    LogDebug("m_connectionState : " << m_connectionState);
 
-    if (checkProfileHandle() == false) {
+    if (m_connectionState == NETWORK_CONNECTED) {
         reLaunchConnection(event);
         return;
     }
@@ -155,11 +167,13 @@ void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerSelection
     int ret = connection_get_profile_iterator(m_connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &profileIter);
        if (ret != CONNECTION_ERROR_NONE) {
         LogDebug("Fail to get profile iterator");
+        makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
         return;
     }
     while (connection_profile_iterator_has_next(profileIter)) {
         if (connection_profile_iterator_next(profileIter, &m_profileHandle) != CONNECTION_ERROR_NONE) {
             LogDebug("Fail to get profile handle");
+            makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
             return;
        }
     }
@@ -168,6 +182,7 @@ void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerSelection
 
     if (connection_open_profile(m_connectionHandle, m_profileHandle, connection_opened_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
         LogDebug("Connection open Failed");
+        makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
         delete pendingEvent;
         pendingEvent = NULL;
     }
@@ -185,7 +200,7 @@ void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerReleasePt
         }        
         
         NewtorkBearerReleasePendingEvent *pendingEvent = new NewtorkBearerReleasePendingEvent((void *)this, event);
-        
+
         if (connection_close_profile(m_connectionHandle, m_profileHandle, connection_closed_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
             LogDebug("connection close failed");
             delete pendingEvent;
@@ -203,7 +218,8 @@ void NetworkBearerSelection::reLaunchConnection(const EventNetworkBearerSelectio
     LogDebug("enter");
 
     if (connection_profile_unset_state_changed_cb(m_profileHandle) != CONNECTION_ERROR_NONE) {
-        LogDebug("unset callback is failed");        
+        LogDebug("unset callback is failed");
+        makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
         return;
     }
 
@@ -211,6 +227,7 @@ void NetworkBearerSelection::reLaunchConnection(const EventNetworkBearerSelectio
 
     if (connection_close_profile(m_connectionHandle, m_profileHandle, connection_removed_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
         LogDebug("connection close failed");
+        makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
         delete pendingEvent;
         pendingEvent = NULL;
     }
@@ -226,11 +243,13 @@ void NetworkBearerSelection::removeStateChangeListener(const EventNetworkBearerS
     int ret = connection_get_profile_iterator(m_connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &profileIter);
     if (ret != CONNECTION_ERROR_NONE) {
         LogDebug("Fail to get profile iterator");
+        makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
         return;
     }
     while (connection_profile_iterator_has_next(profileIter)) {
         if (connection_profile_iterator_next(profileIter, &m_profileHandle) != CONNECTION_ERROR_NONE) {
             LogDebug("Fail to get profile handle");
+            makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
             return;
         }
     }
@@ -239,6 +258,7 @@ void NetworkBearerSelection::removeStateChangeListener(const EventNetworkBearerS
 
     if (connection_open_profile(m_connectionHandle, m_profileHandle, connection_opened_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
         LogDebug("Connection open Failed");
+        makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
         delete pendingEvent;
         pendingEvent = NULL;
     }
@@ -250,11 +270,10 @@ void NetworkBearerSelection::registStateChangeListener(const EventNetworkBearerS
     char *interfaceName = NULL;
     char *hostAddr = NULL;
     struct hostent *host_entry;
-    int ndx = 0;
-    int ret = 0;
 
        if (connection_profile_get_network_interface_name(m_profileHandle, &interfaceName) != CONNECTION_ERROR_NONE) {
         LogDebug("Fail to get interface name!");
+        makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
     }
        else {
         LogDebug("Interface name : " << interfaceName);
@@ -264,7 +283,13 @@ void NetworkBearerSelection::registStateChangeListener(const EventNetworkBearerS
 
     if(!host_entry) {
         LogDebug("gethostbyname is failed");
-        makeCallback(event, CONNECTION_STATE_ERROR);
+        makeCallback(event, CONNECTION_STATE_INVALID_VALUES_ERROR);
+
+        if (connection_close_profile(m_connectionHandle, m_profileHandle, connection_closed_callback2, NULL) != CONNECTION_ERROR_NONE) {
+            LogDebug("connection close failed");
+            makeCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
+        }
+        m_profileHandle = NULL;
         return;
     }
 
@@ -280,24 +305,30 @@ void NetworkBearerSelection::deregistStateChangeListener(const EventNetworkBeare
 {
     LogDebug("enter");
     m_profileHandle = NULL;
-
+    m_connectionState = NETWORK_DISCONNECTED;
        EventRequestReceiver<EventNetworkBearerRelease>::ManualAnswer(event);         
 }
 
 void NetworkBearerSelection::makeCallback(const EventNetworkBearerSelectionPtr &event, connectionStateType state)
 {
-    LogDebug("enter");
+    LogDebug("state : " << state);
     OnNetworkBearerSelectionStateChangedEmitterPtr emitter = event->getEmitter();
        OnNetworkBearerSelectionStateChangedPtr listener(new OnNetworkBearerSelectionStateChanged());    
 
     m_domainName = event->getDomainName();    
-
     listener->setConnectionStateType(state);
 
-    if (state == CONNECTION_STATE_ERROR) {
+    if (state == CONNECTION_STATE_INVALID_VALUES_ERROR) {
+        m_connectionState = NETWORK_CONNECTION_FAILED;
         listener->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    } else if (state == CONNECTION_STATE_PLATFORM_ERROR) {
+        m_connectionState = NETWORK_CONNECTION_FAILED;
+        listener->setExceptionCode(ExceptionCodes::PlatformException);
+    } else if (state == CONNECTION_STATE_DISCONNECTED) {
+        m_connectionState = NETWORK_DISCONNECTED;
+    } else if (state == CONNECTION_STATE_CONNECTED) {
+        m_connectionState = NETWORK_CONNECTED;
     }
-
     emitter->emit(listener);
 }
 
index 27545c9..40ae3fa 100755 (executable)
 namespace DeviceAPI {
 namespace NetworkBearerSelection {
 
+enum {
+    NETWORK_UNKNOWN = 0,
+    NETWORK_CONNECTED = 1,
+    NETWORK_DISCONNECTED = 2,
+    NETWORK_CONNECTION_FAILED = 3
+};
+
 class NetworkBearerSelection : public INetworkBearerSelection
 {
     friend class NetworkBearerSelectionFactory;
@@ -59,6 +66,7 @@ class NetworkBearerSelection : public INetworkBearerSelection
     connection_h m_connectionHandle;
     connection_profile_h m_profileHandle;
     std::string m_domainName;
+    long m_connectionState;
 };
 
 class NewtorkBearerSelectionPendingEvent
index 1bce2a5..6e0b297 100755 (executable)
@@ -110,7 +110,7 @@ void NetworkBearerSelectionResponseDispatcher::onAnswerReceived(const OnNetworkB
         } else if (event->getConnectionStateType() == CONNECTION_STATE_DISCONNECTED) {
             LogDebug("disconnect callback");  
             callbackManager->callOnDisconnected();
-        } else if (event->getConnectionStateType() == CONNECTION_STATE_ERROR) {
+        } else if (event->getConnectionStateType() == CONNECTION_STATE_INVALID_VALUES_ERROR || event->getConnectionStateType() == CONNECTION_STATE_PLATFORM_ERROR) {
                JSContextRef gContext = callbackManager->getContext();        
             JSValueRef error = NULL;
             
index c29c6fb..02d393d 100755 (executable)
@@ -29,7 +29,8 @@ namespace NetworkBearerSelection {
 enum connectionStateType {
     CONNECTION_STATE_DISCONNECTED = 0,
     CONNECTION_STATE_CONNECTED = 1,
-    CONNECTION_STATE_ERROR = 2
+    CONNECTION_STATE_INVALID_VALUES_ERROR = 2,
+    CONNECTION_STATE_PLATFORM_ERROR = 3
 };
 
 class OnNetworkBearerSelectionStateChanged : public WrtDeviceApis::Commons::ListenerEvent<OnNetworkBearerSelectionStateChanged>
index 487fd72..f242441 100755 (executable)
@@ -1,3 +1,4 @@
+
 SET(TARGET_NAME ${notification_target})
 SET(DESTINATION_NAME ${notification_dest})
 SET(TARGET_IMPL_NAME ${notification_impl})
@@ -9,6 +10,7 @@ INCLUDE_DIRECTORIES(
        ${TOP}/Application
        ${TOP}/Filesystem
        ${platform_pkgs_notification_INCLUDE_DIRS}
+       ${notification_INCLUDE_DIRS}
 )
 
 SET(CMAKE_INSTALL_RPATH
@@ -20,25 +22,19 @@ SET(CMAKE_INSTALL_RPATH
 )
 
 SET(SRCS_IMPL
-       JSStatusNotification.cpp
-       JSNotificationManager.cpp
-       NotificationConverter.cpp
-       NotificationFactory.cpp
-       INotificationManager.cpp
-       INotification.cpp
-       NotificationManager.cpp
-       StatusNotification.cpp
-       JSNotificationLine.cpp
-       JSNotificationLineArray.cpp
-       NotificationLine.cpp
-       JSStringArray.cpp
+    JSNotificationManager.cpp
+    JSStatusNotification.cpp
+    JSNotificationDetailInfo.cpp
+    NotificationManager.cpp
+    StatusNotification.cpp
+    NotificationDetailInfo.cpp
 )
 
 ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
 
 TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME}
        ${LIBS_COMMON}
-       ${tizen_impl}
+       ${notification_LIBRARIES}
        ${application_impl}
        ${filesystem_impl}
        ${platform_pkgs_notification_LIBRARIES}
@@ -53,6 +49,8 @@ ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS})
 
 TARGET_LINK_LIBRARIES(${TARGET_NAME}
        ${TARGET_IMPL_NAME}
+               ${tizen_impl}
+       ${timeutil_impl}
        "-Wl,--no-as-needed" ${application_config}
        "-Wl,--no-as-needed" ${filesystem_config}
 )
@@ -60,6 +58,6 @@ TARGET_LINK_LIBRARIES(${TARGET_NAME}
 INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
 INSTALL(
-       DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/notification
-       FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE
+        DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/notification
+        FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE
 )
diff --git a/src/Notification/INotification.cpp b/src/Notification/INotification.cpp
deleted file mode 100755 (executable)
index 58c89d3..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "INotification.h"
-
-namespace DeviceAPI {
-namespace Notification {
-
-INotification::INotification() :
-m_notiUpdated(false)
-{
-       LogDebug(" created Notification ");
-}
-
-INotification::~INotification() {
-       LogDebug(" type  = "  << m_notiType);
-}
-
-}
-}
diff --git a/src/Notification/INotification.h b/src/Notification/INotification.h
deleted file mode 100755 (executable)
index e761720..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_INOTIFICATION_H_
-#define TIZENAPIS_API_INOTIFICATION_H_
-
-#include <dpl/shared_ptr.h>
-#include <string>
-#include <time.h>
-#include <ApplicationControl.h>
-#include "NotificationLine.h"
-
-namespace DeviceAPI {
-namespace Notification {
-
-typedef std::vector<std::string> StringArray;
-typedef DPL::SharedPtr<StringArray> StringArrayPtr;    
-
-typedef enum 
-{
-       NOTI_TYPE_NONE = 0,
-       NOTI_TYPE_SIMPLE,
-       NOTI_TYPE_ONGOING,
-       NOTI_TYPE_PROGRESS,
-       NOTI_TYPE_MUTIPLE,
-       NOTI_TYPE_THUMBNAIL,
-       NOTI_TYPE_MAX
-}NotificationType;
-
-typedef enum 
-{
-       NOTI_PROGRESS_TYPE_NONE = 0,
-       NOTI_PROGRESS_TYPE_SIZE,
-       NOTI_PROGRESS_TYPE_PERCENTAGE,
-       NOTI_PROGRESS_TYPE_MAX  
-} NotificationProgressType;
-
-
-typedef enum
-{
-       NOTI_STATE_NONE = 0,
-       NOTI_STATE_CREATED,
-       NOTI_STATE_POSTED,
-       NOTI_STATE_DELETED 
-}NotificationStateType;        
-
-class INotification 
-{
-public:
-       virtual ~INotification();
-
-       NotificationType getNotiType()
-       {
-               return m_notiType;
-       }
-       
-       void setNotiType(NotificationType type)
-       {
-               m_notiType = type;
-       }
-       
-       NotificationStateType getNotificationState()
-       {
-               return m_notiState;
-       }
-
-       void setNotificationState(NotificationStateType notiState)
-       {
-               m_notiState = notiState;
-       }
-               
-       NotificationProgressType getProgressType()
-       {
-               return m_progressType;
-       }
-
-       void setProgressType( NotificationProgressType type)
-       {
-               m_progressType = type;
-       }
-       
-       void setUpdatedFlag(bool value)
-       {
-               if (value)
-                       LogDebug("set True");
-               m_notiUpdated = value;
-       }
-       
-       bool getUpdatedFlag()
-       {
-               return m_notiUpdated;
-       }
-       
-       //virtual function
-       virtual int getID() = 0;
-       virtual time_t getPostedTime() = 0;
-
-       virtual std::string getTitle() = 0;
-       virtual void setTitle(std::string title) = 0;
-       virtual std::string getContent() = 0;
-       virtual void setContent(std::string content) = 0;
-               
-       virtual std::string getIconPath() = 0;  
-       virtual void setIconPath(const std::string& iconPath) = 0;
-
-       virtual std::string getSoundPath() = 0;
-       virtual void setSoundPath(const std::string& sound) = 0;
-       
-       virtual bool getDefaultVibration() = 0; 
-       virtual void setDefaultVibration(const bool& vibration) = 0;
-
-       virtual double getProgressValue() = 0;
-       virtual void setProgressValue(const double & progressValue) = 0;
-
-       virtual std::string getSubIconPath() = 0;
-       virtual void setSubIconPath(const std::string& subIconPath) = 0;
-       
-       virtual std::vector<std::string> getInformations() = 0;
-       virtual std::string getInformation(int index)  = 0;
-       virtual void setInformations(std::vector<std::string>& infos) = 0;
-       virtual void setInformation( const std::string& info, int index) = 0;
-       
-       virtual std::vector<std::string> getSubInformations() = 0;
-       virtual std::string getSubInformation(int index)  = 0;
-       virtual void setSubInformations(std::vector<std::string>& infos) = 0;
-       virtual void setSubInformation( const std::string& info, int index) = 0;
-
-       //virtual std::vector<std::string> getThumbnails() = 0;
-       virtual std::string getThumbnail(int index) = 0;
-       virtual void setThumbnails(std::vector<std::string>& thumbs) = 0;
-       virtual void setThumbnail( const std::string& info, int index) = 0;
-
-       virtual void setThumbnails(const StringArrayPtr &value) = 0;
-       virtual StringArrayPtr getThumbnails() = 0;
-       
-       virtual std::string getBackground() = 0;
-       virtual void setBackground(const std::string imagePath) = 0;
-       
-       virtual unsigned int getNumber() = 0;
-       virtual void setNumber(const unsigned int number) = 0;
-
-       virtual DeviceAPI::Application::ApplicationControlPtr getApplicationControl() = 0;
-       virtual void setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control) = 0;
-       virtual void setApplicationId(const std::string& appId) = 0;
-       virtual std::string getApplicationId() = 0;
-
-       virtual void* getNotificationHandle() = 0;
-       virtual void setNotificationHandle(void *handle) = 0;
-
-       virtual service_h getService() = 0;
-
-       virtual NotificationLineArrayPtr getLines() const = 0;
-       virtual int getLinesNum() const = 0;
-       virtual void setLines(const NotificationLineArrayPtr &value) = 0;
-       virtual void addLine(const NotificationLinePtr &value) = 0;
-       virtual void clearLines() = 0;
-
-private:
-       bool m_notiUpdated;
-       NotificationType m_notiType;
-       NotificationStateType m_notiState;
-       NotificationProgressType m_progressType;
-       
-protected:
-       INotification();
-};
-
-typedef DPL::SharedPtr<INotification> INotificationPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Notification/INotificationManager.cpp b/src/Notification/INotificationManager.cpp
deleted file mode 100755 (executable)
index 5590497..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "INotificationManager.h"
-
-namespace DeviceAPI {
-namespace Notification {
-
-INotificationManager::INotificationManager()   
-{
-}
-
-INotificationManager::~INotificationManager()  
-{
-}
-
-}
-}
diff --git a/src/Notification/INotificationManager.h b/src/Notification/INotificationManager.h
deleted file mode 100755 (executable)
index d3480bf..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_INOTIFICATION_MANAGER_H_
-#define TIZENAPIS_API_INOTIFICATION_MANAGER_H_
-
-#include <dpl/shared_ptr.h>
-#include <string>
-#include <vector>
-
-#include "INotification.h"
-
-namespace DeviceAPI {
-namespace Notification {
-
-
-class INotificationManager 
-{
-public:
-       virtual ~INotificationManager();
-       virtual void post(INotificationPtr notification) = 0;
-       virtual void update(INotificationPtr notification) = 0;
-       virtual void cancel(std::string id) = 0;
-       virtual void cancelAll() = 0;
-       virtual std::vector<INotificationPtr> getAll() = 0;
-       virtual INotificationPtr get(std::string id) = 0;
-protected:
-       INotificationManager();
-};
-
-typedef DPL::SharedPtr<INotificationManager> INotificationManagerPtr;
-
-}
-}
-
-#endif 
diff --git a/src/Notification/JSNotificationDetailInfo.cpp b/src/Notification/JSNotificationDetailInfo.cpp
new file mode 100755 (executable)
index 0000000..bfc1b73
--- /dev/null
@@ -0,0 +1,160 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <SecurityExceptions.h>
+
+#include <JSUtil.h>
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <MultiCallbackUserData.h>
+#include <PlatformException.h>
+
+#include "plugin_config.h"
+
+#include "JSNotificationDetailInfo.h"
+
+using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Notification {
+
+JSClassDefinition JSNotificationDetailInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "NotificationDetailInfo",
+    NULL, //ParentClass
+    NULL, //StaticValues
+    NULL, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
+};
+
+
+JSClassRef JSNotificationDetailInfo::m_jsClassRef = JSClassCreate(JSNotificationDetailInfo::getClassInfo());
+
+const JSClassRef JSNotificationDetailInfo::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNotificationDetailInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSNotificationDetailInfo::initialize(JSContextRef context, JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        NotificationDetailInfo *priv = new NotificationDetailInfo();
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+}
+
+void JSNotificationDetailInfo::finalize(JSObjectRef object)
+{
+    NotificationDetailInfo *priv = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
+}
+
+JSObjectRef JSNotificationDetailInfo::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    ArgumentValidator validator(context, argumentCount, arguments);
+
+    NotificationDetailInfo *priv = new NotificationDetailInfo();
+
+    try {
+        priv->setMainText(validator.toString(0, false, ""));
+    } catch (const BasePlatformException& err) {
+        LogWarning("mainText convertion is failed. %s", err.getMessage().c_str());
+    }
+
+    try {
+        priv->setSubText(validator.toString(1, true, ""));
+    } catch (const BasePlatformException& err) {
+        LogWarning("subText convertion is failed. %s", err.getMessage().c_str());
+    }
+
+    JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
+    setPrivateObject(context, obj, priv);
+
+    JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+    JSObjectSetProperty(context, obj, ctorName, constructor,
+        kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+    JSStringRelease(ctorName);
+
+    return obj;
+}
+
+NotificationDetailInfo* JSNotificationDetailInfo::getPrivateObject(JSContextRef context, JSObjectRef object)
+{
+    NotificationDetailInfo *priv = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        throw TypeMismatchException("NotificationDetailInfo's private object is NULL.");
+    }
+
+    // mainText
+    JSValueRef mainText = JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_MAIN_TEXT);
+    priv->setMainText(JSUtil::JSValueToString(context, mainText));
+
+    // subText
+    JSValueRef subText = JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT);
+    priv->setSubText(JSUtil::JSValueToString(context, subText));
+
+    return priv;
+}
+
+void JSNotificationDetailInfo::setPrivateObject(JSContextRef context, JSObjectRef object, NotificationDetailInfo *priv)
+{
+    if (priv) {
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+    }
+
+    // mainText
+    JSUtil::setProperty(context, object, NOTIFICATION_DETAIL_INFO_MAIN_TEXT,
+            JSUtil::toJSValueRef(context, priv->getMainText()), kJSPropertyAttributeNone);
+
+    // subText
+    JSUtil::setProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT,
+            JSUtil::toJSValueRef(context, priv->getSubText()), kJSPropertyAttributeNone);
+}
+
+
+} // Notification
+} // DeviceAPI
diff --git a/src/Notification/JSNotificationDetailInfo.h b/src/Notification/JSNotificationDetailInfo.h
new file mode 100755 (executable)
index 0000000..1843ea5
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_JS_NOTIFICATION_DETAIL_INFO_H__
+#define __TIZEN_JS_NOTIFICATION_DETAIL_INFO_H__
+
+#include <JavaScriptCore/JavaScript.h>
+
+#include "NotificationDetailInfo.h"
+
+namespace DeviceAPI {
+namespace Notification {
+
+class JSNotificationDetailInfo
+{
+public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+
+    static JSObjectRef constructor(JSContextRef context,
+            JSObjectRef constructor,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static NotificationDetailInfo* getPrivateObject(JSContextRef context, JSObjectRef object);
+    static void setPrivateObject(JSContextRef context, JSObjectRef object, NotificationDetailInfo *priv);
+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 member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
+};
+
+
+
+} // Notification
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
diff --git a/src/Notification/JSNotificationLine.cpp b/src/Notification/JSNotificationLine.cpp
deleted file mode 100755 (executable)
index b074990..0000000
+++ /dev/null
@@ -1,323 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <dpl/shared_ptr.h>
-#include <CommonsJavaScript/Validator.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "NotificationConverter.h"
-#include "JSNotificationLine.h"
-
-#define NOTIFICATION_CLASS_NAME "NotificationDetailInfo"
-
-#define NOTIFICATION_ATTR_INFORMATION  "mainText"
-#define NOTIFICATION_ATTR_SUBINFORMATION "subText"
-
-namespace DeviceAPI {
-namespace Notification {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSNotificationLine::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       NOTIFICATION_CLASS_NAME,
-       NULL,
-       m_property,
-       m_functions,
-       Initialize,
-       Finalize,
-       NULL, //hasProperty,
-       NULL, //GetProperty,
-       NULL, //SetProperty,
-       NULL, //DeleteProperty,
-       NULL, //getPropertyNames,
-       NULL, //CallAsFunction,
-       constructor, //CallAsConstructor,
-       hasInstance, //HasInstance,
-       NULL, //ConvertToType,
-};
-
-JSStaticValue JSNotificationLine::m_property[] = {
-       { NOTIFICATION_ATTR_INFORMATION, getInformation, setInformation, kJSPropertyAttributeNone },
-       { NOTIFICATION_ATTR_SUBINFORMATION, getSubInformation, setSubInformation, kJSPropertyAttributeNone },
-       { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSNotificationLine::m_functions[] =
-{
-       { 0, 0, 0 }
-};
-
-JSClassRef JSNotificationLine::m_classRef = JSClassCreate(&m_classInfo);
-
-JSClassRef JSNotificationLine::getClassRef() {
-       if (!m_classRef) {
-               m_classRef = JSClassCreate(&m_classInfo);
-       }
-       return m_classRef;
-}
-
-bool JSNotificationLine::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
-       return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-NotificationLinePtr JSNotificationLine::getNotificationLine(JSContextRef context, JSValueRef value)
-{
-       if (!isObjectOfClass(context, value)) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
-       JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
-       JSNotificationLinePriv *priv = static_cast<JSNotificationLinePriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
-       return priv->getObject();
-}
-
-void JSNotificationLine::Initialize(JSContextRef context, JSObjectRef object)
-{
-       if (!JSObjectGetPrivate(object))
-       {
-               NotificationLinePtr line(new NotificationLine());
-               JSNotificationLinePriv *priv = new JSNotificationLinePriv(context, NotificationLinePtr(line));
-               if (!JSObjectSetPrivate(object, priv)) {
-                       delete priv;
-               }
-       }
-}
-
-void JSNotificationLine::Finalize(JSObjectRef object)
-{
-       JSNotificationLinePriv *priv = static_cast<JSNotificationLinePriv*>(JSObjectGetPrivate(object));
-
-       if (priv != NULL)
-               delete (priv);
-}
-
-JSObjectRef JSNotificationLine::createJSObject(JSContextRef context, NotificationLinePtr line)
-{
-       JSNotificationLinePriv *priv = new JSNotificationLinePriv(context, line);
-       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsObjectRef) {
-               LogError("object creation error");
-               return NULL;
-       }
-       return jsObjectRef;
-}
-
-NotificationLinePtr JSNotificationLine::getPrivData(JSObjectRef object)
-{
-       JSNotificationLinePriv *priv = static_cast<JSNotificationLinePriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
-       NotificationLinePtr result = priv->getObject();
-       if (!result) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
-       return result;
-}
-
-JSObjectRef JSNotificationLine::constructor(JSContextRef context,
-               JSObjectRef constructor,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       LogDebug("entered");
-
-       bool js2ndParamIsString = false;
-
-       JSNotificationLinePriv *priv = static_cast<JSNotificationLinePriv*>(JSObjectGetPrivate(constructor));
-       if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
-       JSContextRef gContext = priv->getContext();
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount >= 2)
-               {
-                       if (!JSValueIsUndefined(context, arguments[1]) && !JSValueIsNull(context, arguments[1]))
-                               js2ndParamIsString = true;
-               }
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Date object'");
-               return NULL;
-       }
-
-       NotificationConverterFactory::ConverterType converter = NotificationConverterFactory::getConverter(gContext);
-
-       std::string info;
-       std::string subInfo;
-
-       Try {
-               if (argumentCount >= 1)
-                       info = converter->toString(arguments[0]);
-               else
-                       info = converter->toString(JSValueMakeUndefined(context));
-
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       Try {
-               if (js2ndParamIsString)
-                       subInfo = converter->toString(arguments[1]);
-
-       } Catch(Exception) {
-               LogError("2nd argument only support 'HOMEPAGE' or 'BLOG'");
-       }
-
-       NotificationLinePtr line(new NotificationLine());
-       line->setInformation(info);
-       if(js2ndParamIsString)
-               line->setSubInformation(subInfo);
-
-       JSObjectRef jsobject;
-
-       Try {
-               jsobject = createJSObject(gContext, line);
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       return jsobject;
-}
-
-bool JSNotificationLine::hasInstance(JSContextRef context,
-               JSObjectRef constructor,
-               JSValueRef possibleInstance,
-               JSValueRef* exception)
-{
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
-JSValueRef JSNotificationLine::getInformation(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
-               NotificationLinePtr line = getPrivData(object);
-               return converter->toJSValueRef(line->getInformation());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to get incorrect value");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-bool JSNotificationLine::setInformation(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef value,
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationLinePtr line = getPrivData(object);
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               line->setInformation(converter->toString(value));
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to set incorrect value");
-       }
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
-}
-
-
-JSValueRef JSNotificationLine::getSubInformation(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               NotificationLinePtr line = getPrivData(object);
-               
-               return converter->toJSValueRef(line->getSubInformation());
-               //std::string ret = converter->toString(line->getSubInformation());
-               //if(!line->getSubInformationIsSet())
-               //              return JSValueMakeNull(context);
-               //else
-               //              return converter->toJSValueRef(ret);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to get incorrect value");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-bool JSNotificationLine::setSubInformation(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef value,
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationLinePtr line = getPrivData(object);
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               BasicValidator validator =
-                               BasicValidatorFactory::getValidator(context, exception);
-               if(validator->isNullOrUndefined(value))
-                       line->setSubInformation("");
-               else
-               {
-                       //std::string subInfo = converter->toString(converter->toString(value));
-                       //line->setSubInformation(subInfo);
-                       line->setSubInformation("");
-               }
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to set incorrect value");
-       }
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
-}
-
-} // Notification 
-} // DeviceAPI
diff --git a/src/Notification/JSNotificationLine.h b/src/Notification/JSNotificationLine.h
deleted file mode 100755 (executable)
index 8defa09..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 _TIZEN_NOTIFICATION_JS_NOTIFICATION_LINE_H_
-#define _TIZEN_NOTIFICATION_JS_NOTIFICATION_LINE_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include <Commons/IEvent.h>
-#include "NotificationLine.h"
-
-namespace DeviceAPI {
-namespace Notification {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObject< NotificationLinePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSNotificationLinePriv;
-
-class JSNotificationLine {
-public:
-       /*
-       * This initializes this JS class in the JS Engine.
-       */
-       static JSClassRef getClassRef();
-
-       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
-       static NotificationLinePtr getNotificationLine(JSContextRef context, JSValueRef value);
-       
-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[];
-
-       /**
-        * This member variable contains the initialization values for the static properties of this class.
-        * The values are given according to the data structure JSPropertySpec
-        */
-       static JSStaticValue m_property[];
-
-       static JSClassRef m_classRef;
-
-       static JSObjectRef createJSObject(JSContextRef context, NotificationLinePtr line);
-
-       static NotificationLinePtr getPrivData(JSObjectRef object);
-
-       static JSObjectRef constructor(JSContextRef context,
-                       JSObjectRef constructor,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static bool hasInstance(JSContextRef context,
-                       JSObjectRef constructor,
-                       JSValueRef possibleInstance,
-                       JSValueRef* exception);
-
-       static JSValueRef getInformation(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static bool setInformation(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef value,
-                       JSValueRef* exception);
-
-       static JSValueRef getSubInformation(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static bool setSubInformation(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef value,
-                       JSValueRef* exception);
-
-};
-
-} // Notification
-} // DeviceAPI
-
-#endif // _TIZEN_NOTIFICATION_JS_NOTIFICATION_LINE_H_
diff --git a/src/Notification/JSNotificationLineArray.cpp b/src/Notification/JSNotificationLineArray.cpp
deleted file mode 100755 (executable)
index 49dd327..0000000
+++ /dev/null
@@ -1,622 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <algorithm>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "NotificationConverter.h"
-#include "JSNotificationLineArray.h"
-#include "Logger.h"
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Notification{
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSNotificationLineArray::m_classInfo = {
-       0,
-       kJSClassAttributeNone,
-       ARRAY,
-       0,
-       m_property,
-       m_function,
-       initialize,
-       finalize,
-       hasProperty,
-       getProperty,
-       setProperty,
-       deleteProperty,
-       getPropertyNames,
-       NULL, //callAsFunction,
-       NULL, //callAsConstructor,
-       NULL, //hasInstance,
-       NULL, //convertToType,
-};
-
-JSStaticValue JSNotificationLineArray::m_property[] = {
-       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSNotificationLineArray::m_function[] = {
-       { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { 0, 0, 0 }
-};
-
-JSClassRef JSNotificationLineArray::m_jsClassRef = JSClassCreate(
-               JSNotificationLineArray::getClassInfo());
-
-JSValueRef JSNotificationLineArray::getLength(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       Try
-       {
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               NotificationLineArrayPtr lines = priv->getObject();
-               if (lines) {
-                       NotificationConverterFactory::ConverterType converter =
-                                       NotificationConverterFactory::getConverter(context);
-                       return converter->toJSValueRef(lines->size());
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid conversion");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-bool JSNotificationLineArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
-       return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-NotificationLineArrayPtr JSNotificationLineArray::getNotificationLineArray(JSContextRef context, JSValueRef value)
-{
-       if (!isObjectOfClass(context, value)) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
-       JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
-       JSNotificationLineArrayPriv *priv = static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
-       return priv->getObject();
-}
-
-JSObjectRef JSNotificationLineArray::createArray(JSContextRef context,
-               const NotificationLineArrayPtr &lines)
-{
-       JSNotificationLineArrayPriv *priv = new JSNotificationLineArrayPriv(context, lines);
-       return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSNotificationLineArray::getClassInfo()
-{
-       return &(m_classInfo);
-}
-
-JSClassRef JSNotificationLineArray::getClassRef()
-{
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-void JSNotificationLineArray::initialize(JSContextRef context,
-               JSObjectRef object)
-{
-}
-
-void JSNotificationLineArray::finalize(JSObjectRef object)
-{
-       JSNotificationLineArrayPriv* priv =
-               static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-       delete priv;
-       JSObjectSetPrivate(object, NULL);
-}
-
-bool JSNotificationLineArray::hasProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName)
-{
-       NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
-       Try
-       {
-               size_t index = converter->toSizeT(propertyName);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               NotificationLineArrayPtr lines = priv->getObject();
-               if (index < lines->size()) {
-                       return true;
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               //not reporting error is intended
-       }
-       return false;
-}
-
-JSValueRef JSNotificationLineArray::getProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
-       Try
-       {
-               size_t index = converter->toSizeT(propertyName);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               NotificationLineArrayPtr lines = priv->getObject();
-               if (index < lines->size()) {
-                       NotificationLinePtr result = lines->at(index);
-                       if (result) {
-                               return converter->toJSValueRef(result);
-                       }
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid property");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-bool JSNotificationLineArray::setProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef value,
-               JSValueRef* exception)
-{
-       NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
-       Try
-       {
-               size_t index = converter->toSizeT(propertyName);
-               NotificationLinePtr line(NULL);
-               if (!JSValueIsUndefined(context, value)) {
-                       line = converter->toNotificationLine(value);
-               }
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               NotificationLineArrayPtr lines = priv->getObject();
-               if (!lines) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               if (lines->size() <= index) {
-                       lines->resize(index + 1);
-               }
-               (*lines)[index] = line;
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       }
-       return false;
-}
-
-bool JSNotificationLineArray::deleteProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
-       Try
-       {
-               size_t index = converter->toSizeT(propertyName);
-               NotificationLinePtr line(NULL);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               NotificationLineArrayPtr lines = priv->getObject();
-               if (!lines) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               if (lines->size() > index) {
-                       (*lines)[index] = line;
-               }
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       }
-       return false;
-}
-
-void JSNotificationLineArray::getPropertyNames(JSContextRef context,
-               JSObjectRef object,
-               JSPropertyNameAccumulatorRef propertyNames)
-{
-       NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
-       Try
-       {
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               NotificationLineArrayPtr lines = priv->getObject();
-
-               int count = lines->size();
-
-               for(int i=0; i < count; i++)
-               {
-                       ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
-                       JSPropertyNameAccumulatorAddName(propertyNames, name.get());
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid property");
-       }
-}
-
-JSValueRef JSNotificationLineArray::concat(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationLineArrayPtr lines = NotificationLineArrayPtr(new NotificationLineArray());
-               JSNotificationLineArrayPriv *newPrivateObject = new JSNotificationLineArrayPriv(context, lines);
-               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
-
-               //copy current lines
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               for (size_t i = 0; i < currentLines->size(); ++i) {
-                       lines->push_back(currentLines->at(i));
-               }
-
-               //copy submitted arrays
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               for (size_t i = 0; i < argumentCount; ++i) {
-                       if (!JSIsArrayValue(context, arguments[i])) {
-                               Throw(WrtDeviceApis::Commons::ConversionException);
-                       }
-                       // process array of strings
-                       JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
-                       unsigned int len = JSGetArrayLength(context, arrayObj);
-                       for (unsigned int e = 0; e < len; ++e) {
-                               JSValueRef att = JSGetArrayElement(context, arrayObj, e);
-                               lines->push_back(converter->toNotificationLine(att));
-                       }
-               }
-               return result;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSNotificationLineArray::join(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               std::string result;
-               std::string separator(",");
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
-                       separator = converter->toString(arguments[0]);
-               }
-               for (size_t i = 0; i < currentLines->size(); ++i) {
-                       if (i != 0) {
-                               result += separator;
-                       }
-                       //FIXME : to be changed to support join
-                       //result += currentLines->at(i);
-               }
-               return converter->toJSValueRef(result);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSNotificationLineArray::pop(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               if (currentLines->size() > 0) {
-                       NotificationLinePtr result = currentLines->at(currentLines->size() - 1);
-                       currentLines->pop_back();
-                       return converter->toJSValueRef(result);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSNotificationLineArray::push(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               for (size_t i = 0; i < argumentCount; ++i) {
-                       currentLines->push_back(converter->toNotificationLine(arguments[i]));
-               }
-               return converter->toJSValueRef(currentLines->size());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSNotificationLineArray::reverse(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               std::reverse(currentLines->begin(), currentLines->end());
-               return thisObject;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSNotificationLineArray::shift(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               if (currentLines->size() > 0) {
-                       NotificationLinePtr result = currentLines->at(0);
-                       currentLines->erase(currentLines->begin());
-                       return converter->toJSValueRef(result);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSNotificationLineArray::slice(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               if (argumentCount < 1) {
-                       return JSValueMakeUndefined(context);
-               }
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               NotificationLineArrayPtr lines = NotificationLineArrayPtr(new NotificationLineArray());
-               JSNotificationLineArrayPriv *newPrivateObject = new JSNotificationLineArrayPriv(
-                               context,
-                               lines);
-               JSValueRef result = JSObjectMake(context,
-                                                                                getClassRef(), newPrivateObject);
-
-               //copy current lines
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               std::size_t first = converter->toSizeT(arguments[0]);
-               std::size_t last = currentLines->size() - 1;
-               if (argumentCount > 1) {
-                       last = converter->toSizeT(arguments[1]);
-                       if (last >= currentLines->size()) {
-                               last = currentLines->size() - 1;
-                       }
-               }
-               for (size_t i = first; i <= last; ++i) {
-                       lines->push_back(currentLines->at(i));
-               }
-
-               return result;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSNotificationLineArray::sort(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               NotificationConverterFactory::ConverterType converter =
-                               NotificationConverterFactory::getConverter(context);
-               JSNotificationLineArrayPriv* priv =
-                       static_cast<JSNotificationLineArrayPriv*>(JSObjectGetPrivate(thisObject));
-               NotificationLineArrayPtr currentLines = priv->getObject();
-               std::sort(currentLines->begin(), currentLines->end());
-               return thisObject;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSNotificationLineArray::splice(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSNotificationLineArray::toString(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSNotificationLineArray::unshift(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSNotificationLineArray::valueOf(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return JSValueMakeUndefined(context);
-}
-
-} //Notification
-} 
diff --git a/src/Notification/JSNotificationLineArray.h b/src/Notification/JSNotificationLineArray.h
deleted file mode 100755 (executable)
index 98e5aa9..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 _TIZEN_NOTIFICATION_JS_NOTIFICATION_LINE_ARRAY_H_
-#define _TIZEN_NOTIFICATION_JS_NOTIFICATION_LINE_ARRAY_H_
-
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "NotificationLine.h"
-
-namespace DeviceAPI {
-namespace Notification {
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT< NotificationLineArrayPtr >::Type JSNotificationLineArrayPriv;
-
-class JSNotificationLineArray
-{
-public:
-
-       static const JSClassDefinition* getClassInfo();
-
-       static JSClassRef getClassRef();
-
-       static JSObjectRef createArray(JSContextRef context,
-                       const NotificationLineArrayPtr &webSites);
-
-       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
-       static NotificationLineArrayPtr getNotificationLineArray(JSContextRef context, JSValueRef value);
-
-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);
-
-       static JSValueRef getLength(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static bool hasProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName);
-
-       static JSValueRef getProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static bool setProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef value,
-                       JSValueRef* exception);
-
-       static bool deleteProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static void getPropertyNames(JSContextRef context,
-                       JSObjectRef object,
-                       JSPropertyNameAccumulatorRef propertyNames);
-
-       static JSValueRef concat(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef join(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef pop(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef push(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef reverse(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef shift(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef slice(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef sort(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef splice(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef toString(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef unshift(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static JSValueRef valueOf(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static bool checkValue(const std::string &value);
-
-       static JSClassRef m_jsClassRef;
-       /**
-        * This structure describes a statically declared function property.
-        */
-       static JSStaticFunction m_function[];
-
-       /**
-        * This structure contains properties and callbacks that define a type of object.
-        */
-       static JSClassDefinition m_classInfo;
-
-       /**
-        * This member variable contains the initialization values for the static properties of this class.
-        * The values are given according to the data structure JSPropertySpec
-        */
-       static JSStaticValue m_property[];
-};
-
-} // Notification
-} // DeviceAPI 
-
-#endif // _TIZEN_NOTIFICATION_JS_NOTIFICATION_LINE_ARRAY_H_
old mode 100644 (file)
new mode 100755 (executable)
index f002cd2..b590833
 // limitations under the License.
 //
 
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
 #include <SecurityExceptions.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include <Commons/Exception.h>
-#include "NotificationFactory.h"
-#include "JSNotificationManager.h"
-#include "NotificationConverter.h"
+
+#include <JSUtil.h>
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <MultiCallbackUserData.h>
+#include <PlatformException.h>
+
 #include "plugin_config.h"
+#include "JSStatusNotification.h"
+#include "JSNotificationManager.h"
 
-using namespace std;
-using namespace DPL;
-using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
 using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Notification {
 
-JSClassDefinition JSNotificationManager::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "NotificationManager",
-       NULL,
-       NULL,
-       m_function,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       NULL,
-       hasInstance,
-       NULL
+JSClassDefinition JSNotificationManager::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "NotificationManager",
+    NULL, //ParentClass
+    NULL, //StaticValues
+    m_function, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-       
-JSStaticFunction JSNotificationManager::m_function[] =
-{
-       { "post", JSNotificationManager::post, kJSPropertyAttributeNone },
-       { "update", JSNotificationManager::update, kJSPropertyAttributeNone },
-       { "get", JSNotificationManager::get, kJSPropertyAttributeNone },        
-       { "getAll", JSNotificationManager::getAll, kJSPropertyAttributeNone },          
-       { "remove", JSNotificationManager::cancel, kJSPropertyAttributeNone },          
-       { "removeAll", JSNotificationManager::cancelAll, kJSPropertyAttributeNone },            
-       { 0, 0, 0 }
+JSStaticFunction JSNotificationManager::m_function[] = {
+    { NOTIFICATION_MANAGER_API_POST, post, kJSPropertyAttributeNone },
+    { NOTIFICATION_MANAGER_API_UPDATE, update, kJSPropertyAttributeNone },
+    { NOTIFICATION_MANAGER_API_REMOVE, remove, kJSPropertyAttributeNone },
+    { NOTIFICATION_MANAGER_API_REMOVE_ALL, removeAll, kJSPropertyAttributeNone },
+    { NOTIFICATION_MANAGER_API_GET, get, kJSPropertyAttributeNone },
+    { NOTIFICATION_MANAGER_API_GET_ALL, getAll, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
 };
 
+JSClassRef JSNotificationManager::m_jsClassRef = JSClassCreate(JSNotificationManager::getClassInfo());
 
-const JSClassRef JSNotificationManager::getClassRef() 
-{
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-const JSClassDefinition* JSNotificationManager::getClassInfo() 
+const JSClassRef JSNotificationManager::getClassRef()
 {
-       return &m_classInfo;
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-JSClassRef JSNotificationManager::m_jsClassRef = JSClassCreate(JSNotificationManager::getClassInfo());
-
-void JSNotificationManager::initialize(JSContextRef context, JSObjectRef object) 
+const JSClassDefinition* JSNotificationManager::getClassInfo()
 {
-       LogDebug("JSNotificationManager::initialize ");
-
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(object));
-
-       if (priv == NULL)
-       {
-               LogDebug("JSNotificationManager::initialize create");           
-
-               INotificationManagerPtr  notificationManager(NotificationFactory::getInstance().getNotificationManager());
-               
-               priv = new JSNotificationManagerPriv( context, notificationManager);
-
-               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
-               {
-                       LogError("Object can't store private data.");
-                       delete priv;
-               }
-       }
-       else
-       {
-               LogDebug("JSNotificationManager::already exist ");              
-       }
+    return &m_classInfo;
 }
 
-void JSNotificationManager::finalize(JSObjectRef object) 
+void JSNotificationManager::initialize(JSContextRef context, JSObjectRef object)
 {
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(object));
-
-       LogDebug("JSNotificationManager::Finalrize");
-
-       if (priv != NULL) 
-       {
-               JSObjectSetPrivate(object, NULL);
-               delete priv;
-       }
+    if (!JSObjectGetPrivate(object)) {
+        NotificationManager *priv = new NotificationManager();
+       LogDebug("initialize priv=" << priv);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
 }
 
-bool JSNotificationManager::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
+void JSNotificationManager::finalize(JSObjectRef object)
 {
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+    NotificationManager *priv = static_cast<NotificationManager*>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
 }
 
-
-JSValueRef JSNotificationManager::cancel(JSContextRef context, JSObjectRef object,
-       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-       JSValueRef* exception)
+JSValueRef JSNotificationManager::post(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(thisObject));      
-       JSValueRef reserveArguments;
-
+    AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       try 
-       {
-               AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               if (argumentCount == 1)
-                       reserveArguments = arguments[0];
-               else 
-                       reserveArguments = JSValueMakeUndefined(context);       
+    try {
+        // Private Object
+        NotificationManager *priv = static_cast<NotificationManager*>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
 
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");        
-               }
+        LogDebug("priv=" << priv);
+        ArgumentValidator validator(context, argumentCount, arguments);
 
-               //NotificationConverter converter(priv->getContext());
-               NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
+        // notification
+        JSObjectRef notificationObj = validator.toObject(0, JSStatusNotification::getClassRef());
+       LogDebug("Notification Obj: " << notificationObj);      
+        StatusNotification *notification = JSStatusNotification::getPrivateObject(context, notificationObj);
 
-               std::string id = converter->toString(reserveArguments);
-               
-               INotificationManagerPtr notificationManager(priv->getObject());
-               notificationManager->cancel(id);
-               LogDebug("Cancel OK");
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, _rethrown_exception.GetMessage());   
-       }                                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }       
+       LogDebug("Notification : " << notification);
        
-       return JSValueMakeUndefined(context);
-
+        if (!notification) {
+            throw TypeMismatchException("Notification's private object is NULL.");
+        }
+
+        // perform
+        //notification ID
+        int id = priv->post(notification);
+        if( id>=0)
+        {
+            std::stringstream stream;
+           stream << id;
+           
+           if(stream.fail())
+              throw TypeMismatchException("Notification's ID conversion is failed.");
+
+           JSUtil::setProperty(context, notificationObj, NOTIFICATION_ID,
+               JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeNone);
+        }
+        else
+               {
+                   throw DeviceAPI::Common::UnknownException("Notification ID value is invalied.");
+               }
+
+        //posted time
+        JSUtil::setProperty(context, notificationObj, NOTIFICATION_POSTED_TIME,
+                JSUtil::makeDateObject(context,notification->getPostedTime()), kJSPropertyAttributeNone);
+                
+//set notification ID.
+//set notification postedTime.
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIError::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in NotificationManager.post().");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSNotificationManager::cancelAll(JSContextRef context, JSObjectRef object,
-       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-       JSValueRef* exception)
+JSValueRef JSNotificationManager::update(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(thisObject));      
-
-       try 
-       {
-
-               AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");        
-               }
-
-               INotificationManagerPtr notificationManager(priv->getObject());
-               notificationManager->cancelAll();
-
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, _rethrown_exception.GetMessage());   
-       }                                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }       
-       return JSValueMakeUndefined(context);
-
+    AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Private Objexct
+        NotificationManager *priv = static_cast<NotificationManager*>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // notification
+        JSObjectRef notificationObj = validator.toObject(0, JSStatusNotification::getClassRef());
+        StatusNotification *notification = JSStatusNotification::getPrivateObject(context, notificationObj);
+        if (!notification) {
+            throw TypeMismatchException("Notification's private object is NULL.");
+        }
+
+        // perform
+        priv->update(notification);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIError::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in NotificationManager.update().");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 }
 
-
-JSValueRef JSNotificationManager::update(JSContextRef context, JSObjectRef object,
-       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-       JSValueRef* exception)
+JSValueRef JSNotificationManager::remove(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(thisObject));      
-       JSValueRef reserveArguments;
-
-       try 
-       {
-
-               AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");
-               }
-
-               if (argumentCount == 1) 
-                       reserveArguments = arguments[0];
-               else 
-                       reserveArguments = JSValueMakeUndefined(context);
-
-               //NotificationConverter converter(priv->getContext());
-                NotificationConverterFactory::ConverterType converter =
-                        NotificationConverterFactory::getConverter(context);
-
-               INotificationManagerPtr notificationManager(priv->getObject());
-               INotificationPtr notification =  converter->toINotificationPtr(reserveArguments);
-               notificationManager->update(notification);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, _rethrown_exception.GetMessage());   
-       }                                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }       
-       return JSValueMakeUndefined(context);
+    AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Private Object
+        NotificationManager *priv = static_cast<NotificationManager*>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+
+        ArgumentValidator validator(context, argumentCount, arguments);
+
+        // id
+        std::string id = validator.toString(0);
+
+        // perform
+        priv->remove(id);
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIError::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in NotificationManager.remove().");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSNotificationManager::get(JSContextRef context, JSObjectRef object,
-       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-       JSValueRef* exception)
+JSValueRef JSNotificationManager::removeAll(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(thisObject));      
-       JSValueRef reserveArguments;
-
-       try 
-       {
-
-               //AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
-               //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               if (argumentCount == 1)
-                       reserveArguments = arguments[0];
-               else 
-                       reserveArguments = JSValueMakeUndefined(context);       
-
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");
-               }
-
-               //NotificationConverter converter(priv->getContext());
-                NotificationConverterFactory::ConverterType converter =
-                        NotificationConverterFactory::getConverter(context);
-               std::string id = converter->toString(reserveArguments);
-               
-               INotificationManagerPtr notificationManager(priv->getObject());
-               INotificationPtr notification =  notificationManager->get(id);
-               return converter->toJSValueRef(notification);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-               
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, _rethrown_exception.GetMessage());   
-       }                                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }       
-
+    AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    try {
+        // Private Object
+        NotificationManager *priv = static_cast<NotificationManager*>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+
+        // perform
+        priv->removeAll();
+
+        return JSValueMakeUndefined(context);
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIError::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in NotificationManager.removeAll().");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSNotificationManager::post(JSContextRef context, JSObjectRef object,
-       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-       JSValueRef* exception)
+JSValueRef JSNotificationManager::get(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(thisObject));      
-       JSValueRef reserveArguments;
+    try {
+        // Private Object
+        NotificationManager *priv = static_cast<NotificationManager*>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
 
-       try 
-       {
+        ArgumentValidator validator(context, argumentCount, arguments);
 
-               AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-               
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");
-               }
-
-               if (argumentCount == 1) 
-                       reserveArguments = arguments[0];
-               else 
-                       reserveArguments = JSValueMakeUndefined(context);
-
-               LogDebug("reArg = " << reserveArguments);
-
-               //NotificationConverter converter(priv->getContext());
-                NotificationConverterFactory::ConverterType converter =
-                        NotificationConverterFactory::getConverter(context);
-               INotificationManagerPtr notificationManager(priv->getObject());
-               INotificationPtr notification =  converter->toINotificationPtr(reserveArguments);
-               LogDebug("title = " << notification->getTitle());
-               notificationManager->post(notification);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, _rethrown_exception.GetMessage());   
-       }                                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }               
-       return JSValueMakeUndefined(context);
+        // id
+        std::string id = validator.toString(0);
 
+        JSObjectRef obj = JSObjectMake(context, JSStatusNotification::getClassRef(), NULL);    //make object
+       StatusNotification* noti = priv->get(id);                                                                       // perform
+       JSStatusNotification::setPrivateObject(context, obj, noti);
+
+       return obj;
+       
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIError::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in NotificationManager.get().");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 }
 
-JSValueRef JSNotificationManager::getAll(JSContextRef context, JSObjectRef object,
-       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-       JSValueRef* exception)
+JSValueRef JSNotificationManager::getAll(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
 {
-       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(thisObject));      
-
-       try 
-       {
+    try {
+        // Private Object
+        NotificationManager *priv = static_cast<NotificationManager*>(JSObjectGetPrivate(thisObject));
+        if (!priv) {
+            throw TypeMismatchException("Private object is NULL.");
+        }
+       
+       std::vector<StatusNotification*> notifications = priv->getAll();
+       
+        JSObjectRef notiArray[notifications.size()];
+         for( unsigned int i = 0 ; i < notifications.size(); i++){
+             notiArray[i] =  JSObjectMake(GlobalContextManager::getInstance()->getGlobalContext(context), JSStatusNotification::getClassRef(), NULL);  //make object
+             JSStatusNotification::setPrivateObject(context, notiArray[i], notifications[i]);
+        }
+       
+        JSValueRef exception = NULL;
+        JSObjectRef jsResult = JSObjectMakeArray(GlobalContextManager::getInstance()->getGlobalContext(context), notifications.size(), notiArray, &exception);
+        if (exception != NULL) {
+            throw DeviceAPI::Common::UnknownException(context, exception);
+        }
 
-               //AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC);
-               //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+        return jsResult;
                
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");
-               }
-
-               //NotificationConverter converter(priv->getContext());
-                NotificationConverterFactory::ConverterType converter =
-                        NotificationConverterFactory::getConverter(context);
-               INotificationManagerPtr notificationManager(priv->getObject());
-               std::vector<INotificationPtr> notificationArray =  notificationManager->getAll();
-               return converter->toJSValueRef(notificationArray);
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::SecurityException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::PERMISSION_DENIED_ERROR, _rethrown_exception.GetMessage());   
-       }                                       
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }       
-
+    } catch (const BasePlatformException &err) {
+        return JSWebAPIError::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in NotificationManager.getAll().");
+        return JSWebAPIError::throwException(context, exception, err);
+    }
 }
 
-}
-}
 
+} // Notification
+} // DeviceAPI
old mode 100755 (executable)
new mode 100644 (file)
index 82d21d6..cf68a81
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_NOTIFICATION_MANAGER_H_
-#define TIZENAPIS_TIZEN_JS_NOTIFICATION_MANAGER_H_
+#ifndef __TIZEN_JS_NOTIFICATION_MANAGER_H__
+#define __TIZEN_JS_NOTIFICATION_MANAGER_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "INotificationManager.h"
-       
+
+#include "NotificationManager.h"
+
 namespace DeviceAPI {
 namespace Notification {
 
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<INotificationManagerPtr>::Type JSNotificationManagerPriv;
-
-class JSNotificationManager {
+class JSNotificationManager
+{
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-       JSValueRef possibleInstance, JSValueRef* exception);
-
-       static JSValueRef post(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);
-       static JSValueRef update(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception); 
-       static JSValueRef cancel(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception);         
-       static JSValueRef cancelAll(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception); 
-       static JSValueRef get(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception); 
-       static JSValueRef getAll(JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception); 
-
-       static JSClassDefinition m_classInfo;
-       static JSStaticFunction m_function[];
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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);
+
+    static JSValueRef post(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef update(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef remove(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef removeAll(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef get(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static JSValueRef getAll(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * This member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_function[];
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-}
-}
 
-#endif
 
+} // Notification
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
index eeccd99..780def8 100755 (executable)
 // limitations under the License.
 //
 
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
 #include <SecurityExceptions.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "NotificationFactory.h"
-#include "JSStatusNotification.h"
-#include "NotificationConverter.h"
 
-//#include "plugin_config.h"
+#include <JSUtil.h>
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <MultiCallbackUserData.h>
+#include <PlatformException.h>
+#include <JSWebAPIError.h>
+#include <FilesystemUtils.h>
+#include "plugin_config.h"
+
+#include "JSStatusNotification.h"
+#include "JSNotificationDetailInfo.h"
 
+using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
 namespace DeviceAPI {
 namespace Notification {
 
-
-JSClassDefinition JSStatusNotification::m_classInfo =
-{
-       0,
-       kJSClassAttributeNone,
-       "StatusNotification",
-       NULL,
-       m_properties,
-       NULL,
-       initialize,
-       finalize,
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL, 
-       NULL,
-       constructor,
-       hasInstance,
-       NULL
-};
-
-JSStaticValue JSStatusNotification::m_properties[] = 
-{
-       {NOTIFICATION_ID,                               JSStatusNotification::getProperty, NULL,        kJSPropertyAttributeReadOnly },
-       {NOTIFICATION_TYPE,                     JSStatusNotification::getProperty, NULL,        kJSPropertyAttributeReadOnly },
-       {NOTIFICATION_POSTED_TIME,              JSStatusNotification::getProperty, NULL,        kJSPropertyAttributeReadOnly },
-       {NOTIFICATION_TITLE,                    JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },
-       {NOTIFICATION_CONTENT,                  JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },
-       
-       {NOTIFICATION_STATUS_TYPE,              JSStatusNotification::getProperty, NULL,        kJSPropertyAttributeReadOnly },
-       {NOTIFICATION_ICON_PATH,                JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },
-       {NOTIFICATION_SOUND_PATH,               JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },
-       {NOTIFICATION_VIBRATION,                JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-       {NOTIFICATION_SEVICE,                   JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-#endif
-       {NOTIFICATION_APP_CONTROL,              JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },
-       {NOTIFICATION_APP_ID,                   JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {NOTIFICATION_PROGRESS_VALUE,   JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {NOTIFICATION_LINES,    JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {NOTIFICATION_BACKGROUND_IMAGE_PATH,    JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {NOTIFICATION_NUMBER,   JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {NOTIFICATION_THUMBNAILS,       JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {NOTIFICATION_SUB_ICON_PATH,    JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {NOTIFICATION_PROGRESS_TYPE,    JSStatusNotification::getProperty, JSStatusNotification::setProperty,   kJSPropertyAttributeNone },     
-       {0, 0, 0, 0}
+#define NOTIFICATION_TYPE_VALUE "STATUS"
+
+JSClassDefinition JSStatusNotification::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "StatusNotification",
+    NULL, //ParentClass
+    NULL, //StaticValues
+    NULL, //StaticFunctions
+    initialize, //Initialize
+    finalize, //Finalize
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
 };
 
-const JSClassRef JSStatusNotification::getClassRef() 
-{
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-const JSClassDefinition* JSStatusNotification::getClassInfo() 
-{
-       return &m_classInfo;
-}
 
 JSClassRef JSStatusNotification::m_jsClassRef = JSClassCreate(JSStatusNotification::getClassInfo());
 
-void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object) 
+const JSClassRef JSStatusNotification::getClassRef()
 {
-       LogDebug("JSStatusNotification::initialize, nothing ");
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
-void JSStatusNotification::finalize(JSObjectRef object) 
+const JSClassDefinition* JSStatusNotification::getClassInfo()
 {
-       JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
-
-       LogDebug("JSStatusNotification::Finalize");
-
-       if (priv != NULL) 
-       {
-               JSObjectSetPrivate(object, NULL);
-               delete priv;
-       }
-}
-
-bool JSStatusNotification::hasInstance(JSContextRef context, JSObjectRef constructor,
-               JSValueRef possibleInstance, JSValueRef* exception) 
-{
-       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
-bool JSStatusNotification::setProperty(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef value,
-        JSValueRef* exception)
-{
-       LogDebug("OK"); 
-
-       JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
-       //NotificationConverter converter(context);
-        NotificationConverterFactory::ConverterType converter =
-                 NotificationConverterFactory::getConverter(context);
-       std::string property = converter->toString(propertyName);
-       LogDebug("Property = " << property);
-       try {
-               
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
-               }
-
-
-               INotificationPtr notification(priv->getObject());
-
-               if (notification == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
-               }
-
-               if (property == NOTIFICATION_TITLE)
-               {
-                       std::string title = converter->toString(value);
-                       notification->setTitle(title);
-                       return true;
-               }
-               else if (property == NOTIFICATION_CONTENT)
-               {
-                       std::string content = converter->toString(value);
-                       notification->setContent(content);
-                       return true;
-               }
-
-               else if (property == NOTIFICATION_ICON_PATH)
-               {
-                       if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value)) 
-                       {
-                               return true;
-                       }
-                       
-                       std::string iconPath = converter->toString(value);
-                       DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, iconPath);
-                       iconPath = path->getFullPath();
-               
-                       notification->setIconPath(iconPath);
-                       return true;
-
-               }
-               else if (property == NOTIFICATION_SOUND_PATH)
-               {
-                       if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value)) 
-                       {
-                               return true;
-                       }
-                       
-                       std::string soundPath = converter->toString(value);
-                       DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, soundPath);
-                       soundPath = path->getFullPath();
-                       
-                       notification->setSoundPath(soundPath);
-                       return true;
-               }
-               else if (property == NOTIFICATION_VIBRATION)
-               {
-                       bool virbration = converter->toBool(value);
-                       notification->setDefaultVibration(virbration);
-                       return true;
-               }
-               else if (property == NOTIFICATION_APP_CONTROL
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-                               || property == NOTIFICATION_SEVICE
-#endif
-                               )
-               {
-                       DeviceAPI::Application::ApplicationControlPtr appControl = converter->toIApplicationPtr(value);
-                       notification->setApplicationControl(appControl);
-                       return true;
-               }
-               else if (property == NOTIFICATION_APP_ID)
-               {
-                       std::string appId = converter->toString(value);
-                       notification->setApplicationId(appId);
-               }
-               else if (property == NOTIFICATION_PROGRESS_VALUE)
-               {
-                       unsigned short progressValue = (unsigned short)converter->toULong(value);
-                       NotificationProgressType progressType = notification->getProgressType();
-                       
-                       LogDebug(" progress type = " << progressType << "progressValue = " << progressValue);
-                                                       
-                       if ( NOTI_PROGRESS_TYPE_SIZE == progressType)
-                       {
-                               notification->setProgressValue(progressValue);
-                       }
-                       else if ( NOTI_PROGRESS_TYPE_PERCENTAGE == progressType)
-                       {
-                               //check arrang.
-                               if (  progressValue > 100 )
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "progress value error");
-                               }                                                       
-                               
-                               double percentage = (double)progressValue/(double)100;
-                               LogDebug(" Percentage Value = " << percentage);
-                               notification->setProgressValue(percentage);
-                       }
-                                               
-                       return true;
-               }
-
-               else if (property == NOTIFICATION_PROGRESS_TYPE)
-               {
-                       notification->setProgressType(converter->toNotificationProgressType(value));
-               }
-               
-               else if (property == NOTIFICATION_LINES)
-               {
-                       NotificationLineArrayPtr lines = converter->toNotificationLineArray(value);
-                       notification->setLines(lines);
-               }
-               else if (property == NOTIFICATION_BACKGROUND_IMAGE_PATH )
-               {
-                       if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value)) 
-                       {
-                               return true;
-                       }
-                       
-                       std::string backgroundImagePath = converter->toString(value);
-                       DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, backgroundImagePath); 
-                       backgroundImagePath = path->getFullPath();
-                       notification->setBackground(backgroundImagePath);
-                       return true;
-               }
-               else if (property == NOTIFICATION_NUMBER)
-               {
-                       unsigned int number = converter->toULong(value);
-                       LogDebug("Number is = " << number);
-                       notification->setNumber(number);
-               }
-               else if (property == NOTIFICATION_THUMBNAILS)
-               {
-
-                       StringArrayPtr thumbnailsPtr = converter->toStringArray(value);
-                       notification->setThumbnails(thumbnailsPtr);
-
-                       std::vector<std::string>::iterator it;
-
-                       int idx = 0;
-                       for (it = thumbnailsPtr->begin(); it < thumbnailsPtr->end(); ++it)
-                       {
-                               std::string str = *it;
-                               LogDebug(" thumbs : " << str);
-                               DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, str);
-                               str = path->getFullPath();
-
-                               LogDebug(" thumbs : " << str);
-                               notification->setThumbnail(str, idx);
-                               idx ++;
-                       }
-                       
-               }
-               else if (property == NOTIFICATION_SUB_ICON_PATH )
-               {
-                       if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value)) 
-                       {
-                               return true;
-                       }
-                       
-                       std::string subIconPath = converter->toString(value);
-                       DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, subIconPath); 
-                       subIconPath = path->getFullPath();
-                       notification->setSubIconPath(subIconPath);
-                       return true;
-               }
-               else 
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"No attribute");
-               }
-               
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return false;
+    return &m_classInfo;
 }
 
-JSValueRef JSStatusNotification::getProperty(JSContextRef context,
-                                                                               JSObjectRef object,
-                                                                               JSStringRef propertyName,
-                                                                               JSValueRef* exception)
+void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object)
 {
-       LogDebug("OK"); 
-
-       JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
-       //NotificationConverter converter(context);
-        NotificationConverterFactory::ConverterType converter =
-               NotificationConverterFactory::getConverter(context);
-       std::string property = converter->toString(propertyName);
-
-       LogDebug("property = " << property);
-
-       try {
-               
-               if (priv == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
-               }
-               
-               INotificationPtr notification(priv->getObject());
-
-               if (notification == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
-               }
-
-               if (property == NOTIFICATION_ID)
-               {
-                       LogDebug(" ID : " << notification->getID());
-                       int id = notification->getID();
-                       if (id >= 0)
-                       {
-                               std::stringstream stream;
-                               stream << id;
-                               
-                               return converter->toJSValueRef(stream.str());
-                       }
-                       else
-                       {
-                               return JSValueMakeNull(context);
-                       }
-                       
-               }
-               else if (property == NOTIFICATION_TYPE)
-               {
-                       LogDebug(" TYPE : " << notification->getNotiType());
-                       return converter->toJSValueRef("STATUS");
-               }
-               else if (property == NOTIFICATION_POSTED_TIME)
-               {       
-                       LogDebug("notification =" << notification) ;
-                       time_t postedTime = notification->getPostedTime();
-                       
-                       LogDebug("postedtime = " << postedTime);
-                       
-                       if (postedTime)
-                               return converter->toJSValueRef(postedTime);
-                       else
-                               return JSValueMakeNull(context);
-               }
-               else if (property == NOTIFICATION_TITLE)
-               {
-                       std::string title = notification->getTitle();
-                       LogDebug(" Title : " << title);
-                       return converter->toJSValueRef(title);
-               }
-               else if (property == NOTIFICATION_CONTENT)
-               {
-                       std::string content = notification->getContent();
-
-                       if (content.size() == 0)
-                               return JSValueMakeNull(context);
-                               
-                       LogDebug(" Content : " << content);
-                       
-                       return converter->toJSValueRef(content);
-               }
-               else if (property == NOTIFICATION_STATUS_TYPE)
-               {
-                       //std::string statusType = notification->getStatusType();
-                       LogDebug(" NOTIFICATION_STATUS_TYPE : " << notification->getNotiType());
-                       return converter->toJSValueRef(notification->getNotiType());
-               }
-               else if (property == NOTIFICATION_ICON_PATH)
-               {
-                       std::string iconPath = notification->getIconPath();
-                       LogDebug(" IconPath : " << iconPath);
-                       if (iconPath.empty())
-                               return JSValueMakeNull(context);
-                       
-                       iconPath = DeviceAPI::Filesystem::Utils::toVirtualPath(context, iconPath);
-                       
-                       return converter->toJSValueRef(iconPath);
-               }
-               else if (property == NOTIFICATION_SOUND_PATH)
-               {
-                       std::string soundPath = notification->getSoundPath();
-                       LogDebug(" NOTIFICATION_SOUND_PATH : " << soundPath);
-                       if (soundPath.empty())
-                               return JSValueMakeNull(context);
-                                               
-                       soundPath = DeviceAPI::Filesystem::Utils::toVirtualPath(context, soundPath);
-                                               
-                       return converter->toJSValueRef(soundPath);
-               }
-               else if (property == NOTIFICATION_VIBRATION)
-               {
-                       bool virbration = notification->getDefaultVibration();
-                       LogDebug(" NOTIFICATION_VIBRATION : " << virbration);
-                       return converter->toJSValueRef(virbration);
-               }
-               else if (property == NOTIFICATION_APP_ID)
-               {
-                       std::string appid = notification->getApplicationId();
-                       LogDebug(" NOTIFICATION_APP_ID : " << appid);
-                       return converter->toJSValueRef(appid);
-               }
-               else if (property == NOTIFICATION_APP_CONTROL
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-                               || property == NOTIFICATION_SEVICE
-#endif
-                               )
-               {
-                       DeviceAPI::Application::ApplicationControlPtr appControl = notification->getApplicationControl();
-                       return converter->toJSValueRef(appControl);
-               }
-               else if (property == NOTIFICATION_PROGRESS_VALUE)
-               {
-                       double progress = notification->getProgressValue();
-                       NotificationProgressType progressType = notification->getProgressType();
-                       LogDebug(" progress type = " << progressType << " progress = " << progress);
-
-                       int progressValue = 0;
-                               
-                       if ( NOTI_PROGRESS_TYPE_SIZE == progressType)
-                       {
-                               progressValue = int(progress);
-                       }
-                       else if ( NOTI_PROGRESS_TYPE_PERCENTAGE == progressType)
-                       {
-                               progressValue = int(progress*100 + 0.01);
-                       }
-                       LogDebug("ProgressValue = " << progressValue);
-                       
-                       //int progressValue = int (progress);
-                       //LogDebug("progress = " << progress << " value = " << progressValue);
-                       
-                       return converter->toJSValueRef(progressValue);
-               }
-               else if (property == NOTIFICATION_LINES)
-               {
-                       if (notification->getLines())
-                               return converter->toJSValueRef(notification->getLines());
-                       else
-                               return JSValueMakeNull(context);
-               }
-               else if (property == NOTIFICATION_BACKGROUND_IMAGE_PATH )
-               {
-                       std::string strBackground = notification->getBackground();
-                       LogDebug(" NOTIFICATION_BACKGROUND_PATH : " << strBackground);
-                       if (strBackground.empty())
-                               return JSValueMakeNull(context);
-                                               
-                       strBackground = DeviceAPI::Filesystem::Utils::toVirtualPath(context, strBackground);
-                       return converter->toJSValueRef(strBackground);
-               }
-               else if (property == NOTIFICATION_NUMBER)
-               {
-                       unsigned int number = notification->getNumber();
-                       LogDebug(" NUMBER : " << notification->getNumber());
-                       return converter->toJSValueRef(number);
-               }
-               else if (property == NOTIFICATION_THUMBNAILS)
-               {
-                       StringArrayPtr thumbnailsPtr = notification->getThumbnails();
-                       
-                       std::vector<std::string>::iterator it;
-
-                       int idx = 0;
-                       for (it = thumbnailsPtr->begin(); it < thumbnailsPtr->end(); ++it)
-                       {
-                               std::string str = *it;
-                               LogDebug(" thumbs : " << str);
-                               str = DeviceAPI::Filesystem::Utils::toVirtualPath(context, str);
-                               //str = path->getFullPath();
-
-                               LogDebug(" thumbs : " << str);
-                               *it = str;
-                               idx ++;
-                       }
-                       return converter->toJSValueRef(thumbnailsPtr);
-                       
-                       //return converter->toJSValueRef(notification->getThumbnails());
-               }
-               else if (property == NOTIFICATION_SUB_ICON_PATH )
-               {
-                       std::string strSubIcon = notification->getSubIconPath();
-                       LogDebug(" NOTIFICATION_SUB_ICON_PATH : " << strSubIcon);
-                       if (strSubIcon.empty())
-                               return JSValueMakeNull(context);
-                                               
-                       strSubIcon = DeviceAPI::Filesystem::Utils::toVirtualPath(context, strSubIcon);
-                       return converter->toJSValueRef(strSubIcon);
-               }
-               else if (property == NOTIFICATION_PROGRESS_TYPE)
-               {
-                       return converter->toJSValueRef(notification->getProgressType());
-               }               
-               else 
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"No attribute");
-               }
-               
-       }
-       Catch (WrtDeviceApis::Commons::NullPointerException)
-       {
-               if (property == NOTIFICATION_POSTED_TIME || property == NOTIFICATION_APP_CONTROL
-       #ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-                                       || property == NOTIFICATION_SEVICE
-       #endif
-                       )
-               {
-                       return JSValueMakeNull(context);
-               }
-               else 
-               {
-                       LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-                       return JSTizenExceptionFactory::postException(context, exception, 
-                                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-               }
-       }
-       Catch (WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                                       JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
-       }
-       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                       JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());      
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, 
-                       JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }       
-
+       LogDebug("JSStatusNotification::initialize, nothing ");
 }
 
-
-JSObjectRef JSStatusNotification::createJSObject(JSContextRef context, INotificationPtr notification)
+void JSStatusNotification::finalize(JSObjectRef object)
 {
-       JSStatusNotificationPriv* priv = new JSStatusNotificationPriv( context, notification);
-       return JSObjectMake(context, getClassRef(), priv);
+    StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
+    if (priv) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
 }
 
-
 JSObjectRef JSStatusNotification::constructor(JSContextRef context,
     JSObjectRef constructor,
     size_t argumentCount,
     const JSValueRef arguments[],
     JSValueRef* exception)
 {
-       LogDebug("OK"); 
-       //NotificationConverter converter(context);
-        NotificationConverterFactory::ConverterType converter =
-                NotificationConverterFactory::getConverter(context);
-       JSValueRef reserveArguments[3];
-       size_t index = 0;
-       JSStatusNotificationPriv* priv = NULL;
-
-       Try     
-       {
-               for (index = 0; index < 3; index++)
-               {
-                       if (index < argumentCount)
-                               reserveArguments[index] = arguments[index];
-                       else 
-                               reserveArguments[index] = JSValueMakeUndefined(context);                                
-               }
-
-               std::string statusType = converter->toString(reserveArguments[0]);
+    ArgumentValidator validator(context, argumentCount, arguments);
+
+    //get StatusType
+    JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
+           
+    JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+    JSObjectSetProperty(context, obj, ctorName, constructor,
+               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+    JSStringRelease(ctorName);
+
+    try {
+        NotificationType notiType = NOTI_TYPE_NONE;
+        std::string strStatusType = validator.toString(0, false, "");
+        LogInfo("Notification Type : " << strStatusType);
+        
+        if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
+            notiType = NOTI_TYPE_SIMPLE;
+        else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
+            notiType = NOTI_TYPE_THUMBNAIL;
+        else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
+            notiType = NOTI_TYPE_ONGOING;
+        else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
+            notiType = NOTI_TYPE_PROGRESS;
+        else
+            throw TypeMismatchException("status type mismatch.");
+        
+        StatusNotification *priv = new StatusNotification(notiType);
+        
+        priv->setTitle(validator.toString(1, false, ""));    //title
+        
+            JSObjectRef notiInitDict = validator.toObject(2, true);
        
-               //create notification private object.
-               INotificationPtr notification = NotificationFactory::getInstance().getNotification(converter->toNotificationType(reserveArguments[0]));                 
-               priv = new JSStatusNotificationPriv(context, notification);
-
-               LogDebug("notification=" << notification);
-               
-#if 0
-               if (statusType == "ONGOING" || statusType == "PROGRESS") 
-               {
-                       notification.Reset();
-                       INotificationPtr newNotification(
-                       NotificationFactory::getInstance().getNotification(TRUE));
-                       notification = newNotification;
-
-                       if (priv)
-                       {
-                               delete priv;
-                               priv = new JSStatusNotificationPriv(context, notification);
-                       }
-               }
-#endif         
-               //notification->setStatusType(converter.toString(reserveArguments[0]));
-               //notification->setNotiType(converter.toNotificationType(reserveArguments[0]));         
-               
-               notification->setTitle(converter->toString(reserveArguments[1]));
-
-               if (!JSValueIsUndefined(context, reserveArguments[2]))
-               {       
-                       converter->toNotificationFromDict(notification, reserveArguments[2]);
-               }
+            if (notiInitDict)
+            {
+                //content
+                try {             
+                    JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
+                    if (!JSValueIsUndefined(context, contentValue))
+                        priv->setContent(JSUtil::JSValueToString(context, contentValue));
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's content convertion is failed."  << err.getMessage().c_str());
+                }
+            
+                //icon
+                try {             
+                    JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
+                    if (!JSValueIsUndefined(context, iconValue))
+                    {
+                        DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
+                        priv->setIconPath(path->getFullPath());
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }
+                
+                //sound
+                try {             
+                    JSValueRef soundValue   = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);         
+                    if (!JSValueIsUndefined(context, soundValue))
+                    {
+                        DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
+                        priv->setSoundPath(path->getFullPath());
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's sound path convertion is failed."  << err.getMessage().c_str());
+                }
+                
+                //vibration
+                try {             
+                    JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
+                    if (!JSValueIsUndefined(context, vibrationValue))
+                    {
+                        priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's vibration value convertion is failed."  << err.getMessage().c_str());
+                }              
+                
+                //appControl
+                try {             
+                    JSValueRef appControlValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);  
+                    if (!JSValueIsUndefined(context, appControlValue))
+                    {
+                       priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's App Control convertion is failed."  << err.getMessage().c_str());
+                }
+        
+                //appID
+                try {             
+                    JSValueRef appIdValue         = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
+                    if (!JSValueIsUndefined(context, appIdValue))
+                    {
+                        priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }
+
+                          
+                //progressType
+                NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+                try {
+                    JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
+                    if (!JSValueIsUndefined(context, progressTypeValue))
+                    {
+                        std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
+                        LogInfo("Progress Type : " << strProgressType);
+                        
+                        
+                        if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
+                            progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+                        else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+                            progressType = NOTI_PROGRESS_TYPE_SIZE;
+                        else
+                            throw InvalidValuesException("Invalid Progress Type.");
+                            
+                        priv->setProgressType(progressType);
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }
+    
+                //ProgressValue
+                try {             
+                    JSValueRef progressValue    = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);         
+                    if (!JSValueIsUndefined(context, progressValue))
+                    {
+                        if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
+                           {
+                               if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
+                                               throw InvalidValuesException("The percentage progress value must be between 0 and 100");
+                               priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
+                           }
+                           else 
+                           {
+                               priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
+                           }
+                               
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }   
+    
+                //DetailInfo
+                try {  
+                    JSValueRef detailInfoValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
+    
+                    std::vector<NotificationDetailInfo*> detailInfos;
+                    if (JSIsArrayValue(context, detailInfoValue))
+                    {
+                        JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
+                        for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
+                        {
+                            JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+                           JSObjectRef object = JSUtil::JSValueToObject(context, element);
+                           if (object)
+                           {
+                               NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
+                               std::string main = item->getMainText();
+                               std::string sub = item->getSubText();
+                               LogInfo("Main : " << main << " Sub : " << sub);
                
-               return JSObjectMake(context, getClassRef(), priv);
-       }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               if (priv != NULL) 
-               {                       
-                       delete priv;
-               }
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       
+                               NotificationDetailInfo *detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
+                               detailInfos.push_back(detailinfo);      
+                           }
+                        }
+                    }
+                    priv->setDetailInfos(detailInfos);
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }
+        
+                //backgroundimage
+                try {             
+                    JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
+                    if (!JSValueIsUndefined(context, backgroundImageValue))
+                    {
+                        DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
+                        priv->setBackground(path->getFullPath());
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }
+    
+                //number
+                try {             
+                    JSValueRef numberValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
+                    if (!JSValueIsUndefined(context, numberValue))
+                    {
+                        priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                } 
+
+                //thumbnail
+                try {             
+                    JSValueRef thumbnailsValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
+                    if (!JSValueIsUndefined(context, thumbnailsValue))
+                    {
+                        priv->setThumbnails(JSUtil::JSArrayToStringVector(context, thumbnailsValue));
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }
+    
+                //subIconPath
+                try {             
+                    JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
+                    if (!JSValueIsUndefined(context, subIconPathValue))
+                    {
+                        DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
+                        priv->setSubIconPath( path->getFullPath());
+                    }
+                }
+                catch ( const BasePlatformException& err) 
+                {
+                    LogWarning("notification's icon path convertion is failed."  << err.getMessage().c_str());
+                }
+                        
+            }
+               
+        setPrivateObject(context, obj, priv);
+               
+    } 
+     catch ( const BasePlatformException& err) 
+    {
+        LogWarning(" notification convertion is failed. "   << err.getName().c_str() << ":"  << err.getMessage().c_str());
+       JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
+       *exception = error;
        return NULL;
+    }
+
+    return obj;      
+
 }
 
-INotificationPtr JSStatusNotification::getNotification(JSContextRef context, JSValueRef value)
+StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSObjectRef object)
 {
-       JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) 
-       {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
-       JSStatusNotificationPriv *priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
-       
-       if (!priv) 
-       {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
-       return priv->getObject();
+    LogDebug("get object :" << object);
+
+    StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
+    LogDebug("statusNotification :" << priv);
+    if (!priv) {
+        throw TypeMismatchException("StatusNotification's private object is NULL.");
+    }
+
+    //type
+    JSValueRef type = JSUtil::getProperty(context, object, NOTIFICATION_TYPE);
+    if ((JSUtil::JSValueToString(context, type)).compare(NOTIFICATION_TYPE_VALUE) )
+    {
+       throw TypeMismatchException("StatusNotification's type is mismatched");
+    }
+     
+    //Title
+    JSValueRef title = JSUtil::getProperty(context, object, NOTIFICATION_TITLE);
+    priv->setTitle( JSUtil::JSValueToString(context, title));
+
+    //Content
+    JSValueRef contents = JSUtil::getProperty(context, object, NOTIFICATION_CONTENT);
+    priv->setContent( JSUtil::JSValueToString(context, contents));
+
+    // iconPath
+    JSValueRef iconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_ICON_PATH);
+    if (!JSUtil::JSValueToString(context, iconPath).empty())
+    {
+        DeviceAPI::Filesystem::IPathPtr icon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconPath));
+        priv->setIconPath(icon->getFullPath());
+    }
+    else
+    {
+        priv->setIconPath("");
+    }
+
+    // subIconPath
+    JSValueRef subIconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH);
+    if (!JSUtil::JSValueToString(context, subIconPath).empty())
+    {
+        DeviceAPI::Filesystem::IPathPtr subIcon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPath));
+        priv->setSubIconPath(subIcon->getFullPath());
+    }
+    else
+    {
+        priv->setIconPath("");
+    }
+
+    // number
+    JSValueRef number = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_NUMBER);
+    priv->setNumber(JSUtil::JSValueToLong(context, number));
+
+    // detailInfo
+    JSValueRef detailInfo = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO);
+    std::vector<NotificationDetailInfo*> detailInfos;
+    if (JSIsArrayValue(context, detailInfo))
+    {
+        JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfo);
+        for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
+        {
+            JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+            JSObjectRef object = JSUtil::JSValueToObject(context, element);
+            if (object)
+            {
+                NotificationDetailInfo* detailinfo = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
+                detailInfos.push_back(detailinfo);     
+            }
+        }
+    }
+    priv->setDetailInfos(detailInfos);
+    
+    // backgroundImagePath
+    JSValueRef backgroundImagePath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
+    if (!JSUtil::JSValueToString(context, backgroundImagePath).empty())
+    {
+        DeviceAPI::Filesystem::IPathPtr backgroundImage = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImagePath));
+        priv->setBackground(backgroundImage->getFullPath());
+    }
+    else
+    {
+        priv->setBackground("");
+    }
+    
+    // thumbnails
+    JSValueRef thumbnails = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS);
+
+    std::vector<std::string> thumbnailPaths;
+    if( JSIsArrayValue(context, thumbnails)){
+        JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnails);    
+        for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
+                JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+                DeviceAPI::Filesystem::IPathPtr thumbnailPath = 
+                    DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
+                LogInfo("thumbnail Path = " << thumbnailPath->getFullPath());
+                thumbnailPaths.push_back(thumbnailPath->getFullPath());
+        }
+    }          
+    priv->setThumbnails(thumbnailPaths);
+    
+    // soundPath
+    JSValueRef soundPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH);
+    if (!JSUtil::JSValueToString(context, soundPath).empty())
+    {
+        DeviceAPI::Filesystem::IPathPtr sound = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundPath));
+        priv->setSoundPath(sound->getFullPath());
+    }
+    else
+    {
+        priv->setSoundPath("");
+    }
+    
+    // vibration
+    JSValueRef vibration = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_VIBRATION);
+    priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibration));
+
+    // appControl
+    JSValueRef appControl = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL);
+    priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context,appControl)));
+
+    // appId
+    JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
+    priv->setApplicationId(JSUtil::JSValueToString(context, appId));
+
+    // progressType
+    JSValueRef progressType = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE);
+    std::string strProgressType = JSUtil::JSValueToString(context, progressType);
+    LogInfo("Progress Type : " << strProgressType);
+    
+    NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
+    if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
+        progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+    else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+        progType = NOTI_PROGRESS_TYPE_SIZE;
+    else
+        throw InvalidValuesException("Invalid Progress Type.");
+    priv->setProgressType(progType);
+    
+    // progressValue
+    JSValueRef progressValue = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE);
+    LogInfo(" Progress Value in Private Object = " << JSUtil::JSValueToULong(context, progressValue));
+    if ( progType == NOTI_PROGRESS_TYPE_PERCENTAGE)
+    {
+       if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
+                       throw InvalidValuesException("The percentage progress value must be between 0 and 100");
+       priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
+    }
+    else 
+    {
+       priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
+    }
+    
+    return priv;
 }
 
-
-}
+void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv)
+{
+    if (priv) {
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+    }
+
+    //type
+    std::string typeVal(NOTIFICATION_TYPE_VALUE);
+    JSUtil::setProperty(context, object, NOTIFICATION_TYPE,
+            JSUtil::toJSValueRef(context, typeVal), kJSPropertyAttributeNone);
+       
+    std::string type;
+    
+    //statusType
+    if ( NOTI_TYPE_SIMPLE ==  priv->getNotiType())
+       type = TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE;
+    else if ( NOTI_TYPE_ONGOING ==  priv->getNotiType())
+       type = TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING;
+    else if ( NOTI_TYPE_PROGRESS ==  priv->getNotiType())
+       type = TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS; 
+    else if ( NOTI_TYPE_THUMBNAIL ==  priv->getNotiType())
+       type = TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL;
+    else
+       throw TypeMismatchException("status type mismatch.");
+       
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
+            JSUtil::toJSValueRef(context, type), kJSPropertyAttributeNone);
+
+    //id
+    if (priv->getID() >= 0)
+    {
+           std::stringstream stream;
+           stream << priv->getID();
+           
+           if(stream.fail())
+              throw TypeMismatchException("Notification's ID conversion is failed.");
+
+           JSUtil::setProperty(context, object, NOTIFICATION_ID,
+               JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeNone);    
+    }
+    else
+    {
+           JSUtil::setProperty(context, object, NOTIFICATION_ID,
+                   JSValueMakeNull(context), kJSPropertyAttributeNone);
+    }
+
+    //postedTime
+    if (priv->getPostedTime() > 0)
+    {
+           JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
+                JSUtil::makeDateObject(context,priv->getPostedTime()), kJSPropertyAttributeNone);  
+    }
+    else
+    {
+           JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
+                   JSValueMakeNull(context), kJSPropertyAttributeNone);
+    }    
+
+    //title
+    JSUtil::setProperty(context, object, NOTIFICATION_TITLE,
+            JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
+
+    //content
+    JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
+            JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
+
+    //iconPath
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
+            JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
+
+    //subIconPath
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
+            JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
+
+    //number
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
+            JSUtil::toJSValueRef(context, (unsigned long)priv->getNumber()), kJSPropertyAttributeNone);
+
+     // backgroundImagePath
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
+            JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getBackground())), kJSPropertyAttributeNone);
+
+    // thumbnails
+
+    std::vector<std::string> thumbnails = priv->getThumbnails();
+    LogInfo("Thumbnail Size : " << thumbnails.size());
+     JSValueRef tumbnailvalueArray[thumbnails.size()];
+    for( unsigned int i = 0 ; i < thumbnails.size(); i++) {
+           if (!thumbnails[i].empty())
+           {
+               LogInfo("Thumbnail :" << thumbnails[i]);
+                tumbnailvalueArray[i] =  JSUtil::toJSValueRef(context, thumbnails[i]);
+           }
+    }
+
+    JSValueRef exception = NULL;
+    JSObjectRef jsThumbnails = JSObjectMakeArray(context, thumbnails.size(), tumbnailvalueArray, &exception);
+    if (exception != NULL) {
+        throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
+    }
+
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS,
+           jsThumbnails, kJSPropertyAttributeNone);
+
+    // soundPath
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
+            JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSoundPath())), kJSPropertyAttributeNone);
+
+    // vibration
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
+            JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
+
+    // appId
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
+            JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);            
+
+    // progressType   & Value
+    LogInfo("Progress Type=" << priv->getProgressType());
+
+       // progressValue
+    unsigned long progressVal = 0;     
+    if ( NOTI_PROGRESS_TYPE_PERCENTAGE ==  priv->getProgressType())
+    {
+       type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
+       progressVal = (unsigned long)( (priv->getProgressValue()*100) );
+    }
+    else if ( NOTI_PROGRESS_TYPE_SIZE==   priv->getProgressType())
+    {
+       type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
+       progressVal = (unsigned long)priv->getProgressValue();
+    }
+
+    LogInfo("Progress Type=" << type);
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE,
+            JSUtil::toJSValueRef(context, type), kJSPropertyAttributeNone);
+               
+    LogInfo("Progress Value =" << progressVal);        
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE,               
+            JSUtil::toJSValueRef(context, progressVal), kJSPropertyAttributeNone);
+
+    // detailInfo
+    std::vector<NotificationDetailInfo*> detailInfo = priv->getDetailInfos();
+    LogInfo("detail Info Size : " << detailInfo.size());
+    JSObjectRef valueArray[detailInfo.size()];
+    for( unsigned int i = 0 ; i < detailInfo.size(); i++) {
+           if (detailInfo[i])
+           {
+               LogInfo("Main = " << detailInfo[i]->getMainText() << " Sub = " << detailInfo[i]->getSubText());
+                valueArray[i] = JSObjectMake(GlobalContextManager::getInstance()->getGlobalContext(context), JSNotificationDetailInfo::getClassRef(), static_cast<void*>(detailInfo[i]));
+                JSNotificationDetailInfo::setPrivateObject(context, valueArray[i], detailInfo[i]);
+               LogInfo("make Object : " << valueArray[i]);
+           }
+    }
+
+    exception = NULL;
+    JSObjectRef jsResult = JSObjectMakeArray(GlobalContextManager::getInstance()->getGlobalContext(context), detailInfo.size(), valueArray, &exception);
+    if (exception != NULL) {
+        throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
+    }
+
+       // detailInfo
+    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO,
+           jsResult, kJSPropertyAttributeNone);
+
+    // appControl
+    DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
+    if (appCtrlPriv)
+    {
+           JSObjectRef jsAppCtrl = JSObjectMake(context, DeviceAPI::Application::JSApplicationControl::getClassRef(), appCtrlPriv);
+           JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL,  jsAppCtrl, kJSPropertyAttributeNone);
+    }
+  
 }
 
+
+} // Notification
+} // DeviceAPI
index 78cd909..a5b1b84 100755 (executable)
 // limitations under the License.
 //
 
-
-#ifndef TIZENAPIS_TIZEN_JS_STATUS_NOTIFICATION_H_
-#define TIZENAPIS_TIZEN_JS_STATUS_NOTIFICATION_H_
+#ifndef __TIZEN_JS_STATUS_NOTIFICATION_H__
+#define __TIZEN_JS_STATUS_NOTIFICATION_H__
 
 #include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include "INotification.h"
+#include "StatusNotification.h"
 
 namespace DeviceAPI {
 namespace Notification {
 
-
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<INotificationPtr>::Type JSStatusNotificationPriv;
-
-#define NOTIFICATION_ID "id"
-#define NOTIFICATION_TYPE "type"
-#define NOTIFICATION_POSTED_TIME "postedTime"
-#define NOTIFICATION_TITLE "title"
-#define NOTIFICATION_CONTENT "content"
-
-#define NOTIFICATION_STATUS_TYPE "statusType"
-#define NOTIFICATION_ICON_PATH "iconPath"
-#define NOTIFICATION_SOUND_PATH "soundPath"
-#define NOTIFICATION_VIBRATION "vibration"
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-#define NOTIFICATION_SEVICE "service"
-#endif
-#define NOTIFICATION_APP_CONTROL "appControl"
-#define NOTIFICATION_APP_ID "appId"
-#define NOTIFICATION_PROGRESS_TYPE "progressType"
-#define NOTIFICATION_PROGRESS_VALUE "progressValue"
-#define NOTIFICATION_LINES "detailInfo"
-#define NOTIFICATION_BACKGROUND_IMAGE_PATH "backgroundImagePath"
-#define NOTIFICATION_NUMBER "number"
-#define NOTIFICATION_THUMBNAILS "thumbnails"
-#define NOTIFICATION_SUB_ICON_PATH "subIconPath"
-
-
-class JSStatusNotification {
+class JSStatusNotification
+{
 public:
-       static const JSClassDefinition* getClassInfo();
-       static const JSClassRef getClassRef();
-       static INotificationPtr getNotification(JSContextRef context, JSValueRef value);
-       static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
-               JSStringRef propertyName, JSValueRef* exception);       
-       static bool setProperty(JSContextRef context, JSObjectRef object,
-        JSStringRef propertyName, JSValueRef value, JSValueRef* exception);    
-       static JSObjectRef createJSObject(JSContextRef context, INotificationPtr notification);
-       
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+
+    static JSObjectRef constructor(JSContextRef context,
+            JSObjectRef constructor,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    static StatusNotification* getPrivateObject(JSContextRef context, JSObjectRef object);
+    static void setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv);
 private:
-       static void initialize(JSContextRef context, JSObjectRef object);
-       static void finalize(JSObjectRef object);
-       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
-       JSValueRef possibleInstance, JSValueRef* exception);
-
-       static JSObjectRef constructor(JSContextRef context,
-               JSObjectRef constructor,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception);
-
-       static JSClassDefinition m_classInfo;
-       static JSStaticValue m_properties[];
-       
-       static JSClassRef m_jsClassRef;
+
+    /**
+     * 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 member variable contains the values which has to be passed
+     * when the this class is embedded into JS Engine.
+     */
+    static JSClassDefinition m_classInfo;
+
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
 };
 
-}
-}
 
-#endif
 
+} // Notification
+} // DeviceAPI
+
+#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__
diff --git a/src/Notification/JSStringArray.cpp b/src/Notification/JSStringArray.cpp
deleted file mode 100755 (executable)
index 1dd08c6..0000000
+++ /dev/null
@@ -1,602 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file        JSStringArray.cpp
- * @author      Kisub Song (kisubs.song@samsung.com)
- * @version     0.1
- * @brief
- */
-
-#include <algorithm>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "NotificationConverter.h"
-#include "JSStringArray.h"
-#include "Logger.h"
-
-#define FUNCTION_CONCAT "concat"
-#define FUNCTION_JOIN "join"
-#define FUNCTION_POP "pop"
-#define FUNCTION_PUSH "push"
-#define FUNCTION_REVERSE "reverse"
-#define FUNCTION_SHIFT "shift"
-#define FUNCTION_SLICE "slice"
-#define FUNCTION_SORT "sort"
-#define FUNCTION_SPLICE "splice"
-#define FUNCTION_TOSTRING "toString"
-#define FUNCTION_UNSHIFT "unshift"
-#define FUNCTION_VALUEOF "valueOf"
-#define ARRAY "Array"
-#define ATTRIBUTE_LENGTH "length"
-
-namespace DeviceAPI {
-namespace Notification {
-
-using namespace DeviceAPI::Common;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-JSClassDefinition JSStringArray::m_classInfo = {
-       0,
-       kJSClassAttributeNone,
-       ARRAY,
-       0,
-       m_property,
-       m_function,
-       initialize,
-       finalize,
-       hasProperty,
-       getProperty,
-       setProperty,
-       NULL, //deleteProperty,
-       getPropertyNames,
-       NULL, //callAsFunction,
-       NULL, //callAsConstructor,
-       NULL, //hasInstance,
-       NULL, //convertToType,
-};
-
-JSStaticValue JSStringArray::m_property[] = {
-       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { 0, 0, 0, 0 }
-};
-
-JSStaticFunction JSStringArray::m_function[] = {
-       { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
-       { 0, 0, 0 }
-};
-
-JSClassRef JSStringArray::m_jsClassRef = JSClassCreate(
-               JSStringArray::getClassInfo());
-
-JSValueRef JSStringArray::getLength(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       Try
-       {
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               StringArrayPtr strs = priv->getObject();
-               if (strs) {
-                       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-                       return converter->toJSValueRef(strs->size());
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid conversion");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSObjectRef JSStringArray::createArray(JSContextRef context,
-               const StringArrayPtr &strs)
-{
-       JSStringArrayPriv *priv = new JSStringArrayPriv(context, strs);
-       return JSObjectMake(context, getClassRef(), priv);
-}
-
-const JSClassDefinition* JSStringArray::getClassInfo()
-{
-       return &(m_classInfo);
-}
-
-JSClassRef JSStringArray::getClassRef()
-{
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
-}
-
-bool JSStringArray::isObjectOfClass(JSContextRef context, JSValueRef value)
-{
-       return JSValueIsObjectOfClass(context, value, getClassRef());
-}
-
-StringArrayPtr JSStringArray::getStringArray(JSContextRef context, JSValueRef value)
-{
-       if (!isObjectOfClass(context, value)) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
-       JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
-               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
-       JSStringArrayPriv* priv = static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
-               Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
-       return priv->getObject();
-}
-
-void JSStringArray::initialize(JSContextRef context,
-               JSObjectRef object)
-{
-}
-
-void JSStringArray::finalize(JSObjectRef object)
-{
-       JSStringArrayPriv* priv =
-               static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
-       delete priv;
-       JSObjectSetPrivate(object, NULL);
-}
-
-bool JSStringArray::hasProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName)
-{
-       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-       Try
-       {
-               size_t index = converter->toSizeT(propertyName);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               StringArrayPtr strs = priv->getObject();
-               if (index < strs->size()) {
-                       return true;
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               //not reporting error is intended
-       }
-       return false;
-}
-
-JSValueRef JSStringArray::getProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-       Try
-       {
-               size_t index = converter->toSizeT(propertyName);
-               LogDebug("index = " << index);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               StringArrayPtr strs = priv->getObject();
-               if (index < strs->size()) {
-                       std::string result = strs->at(index);
-                       if (!result.empty()) {
-                               return converter->toJSValueRef(result);
-                       }
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid property");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-bool JSStringArray::setProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef value,
-               JSValueRef* exception)
-{
-       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-       Try
-       {
-               size_t index = converter->toSizeT(propertyName);
-               LogDebug("idx = " <<index);
-               std::string str;
-               if (!JSValueIsUndefined(context, value)) {
-                       str = converter->toString(value);
-               }
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               StringArrayPtr strs = priv->getObject();
-               if (!strs) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               if (strs->size() <= index) {
-                       strs->resize(index + 1);
-               }
-               (*strs)[index] = str;
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       }
-       return false;
-}
-
-void JSStringArray::getPropertyNames(JSContextRef context,
-               JSObjectRef object,
-               JSPropertyNameAccumulatorRef propertyNames)
-{
-       NotificationConverterFactory::ConverterType converter =
-                       NotificationConverterFactory::getConverter(context);
-       Try
-       {
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(object));
-               if (!priv) {
-                       Throw(WrtDeviceApis::Commons::NullPointerException);
-               }
-               StringArrayPtr strings = priv->getObject();
-
-               int count = strings->size();
-
-               for(int i=0; i < count; i++)
-               {
-                       ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
-                       JSPropertyNameAccumulatorAddName(propertyNames, name.get());
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("invalid property");
-       }
-}
-
-JSValueRef JSStringArray::concat(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               StringArrayPtr strs = StringArrayPtr(new StringArray());
-               JSStringArrayPriv *newPrivateObject = new JSStringArrayPriv(
-                               context,
-                               strs);
-               JSValueRef result = JSObjectMake(context,
-                                                                                getClassRef(), newPrivateObject);
-
-               //copy current strs
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               for (size_t i = 0; i < currentStrings->size(); ++i) {
-                       strs->push_back(currentStrings->at(i));
-               }
-
-               //copy submitted arrays
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               for (size_t i = 0; i < argumentCount; ++i) {
-                       if (!JSIsArrayValue(context, arguments[i])) {
-                               Throw(WrtDeviceApis::Commons::ConversionException);
-                       }
-                       // process array of strings
-                       JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
-                       unsigned int len = JSGetArrayLength(context, arrayObj);
-                       for (unsigned int e = 0; e < len; ++e) {
-                               JSValueRef att = JSGetArrayElement(context, arrayObj, e);
-                               strs->push_back(converter->toString(att));
-                       }
-               }
-               return result;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::join(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               std::string result;
-               std::string separator(",");
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
-                       separator = converter->toString(arguments[0]);
-               }
-               for (size_t i = 0; i < currentStrings->size(); ++i) {
-                       if (i != 0) {
-                               result += separator;
-                       }
-                       result += currentStrings->at(i);
-               }
-               return converter->toJSValueRef(result);
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::pop(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               if (currentStrings->size() > 0) {
-                       std::string result = currentStrings->at(
-                                       currentStrings->size() - 1);
-                       currentStrings->pop_back();
-                       return converter->toJSValueRef(result);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::push(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               for (size_t i = 0; i < argumentCount; ++i) {
-                       currentStrings->push_back(converter->toString(arguments[i]));
-               }
-               return converter->toJSValueRef(currentStrings->size());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::reverse(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               std::reverse(currentStrings->begin(), currentStrings->end());
-               return thisObject;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::shift(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               if (currentStrings->size() > 0) {
-                       std::string result = currentStrings->at(0);
-                       currentStrings->erase(currentStrings->begin());
-                       return converter->toJSValueRef(result);
-               }
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::slice(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               if (argumentCount < 1) {
-                       return JSValueMakeUndefined(context);
-               }
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               StringArrayPtr strs = StringArrayPtr(new StringArray());
-               JSStringArrayPriv *newPrivateObject = new JSStringArrayPriv(
-                               context,
-                               strs);
-               JSValueRef result = JSObjectMake(context,
-                                                                                getClassRef(), newPrivateObject);
-
-               //copy current strs
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               std::size_t first = converter->toSizeT(arguments[0]);
-               std::size_t last = currentStrings->size() - 1;
-               if (argumentCount > 1) {
-                       last = converter->toSizeT(arguments[1]);
-                       if (last >= currentStrings->size()) {
-                               last = currentStrings->size() - 1;
-                       }
-               }
-               for (size_t i = first; i <= last; ++i) {
-                       strs->push_back(currentStrings->at(i));
-               }
-
-               return result;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-}
-
-JSValueRef JSStringArray::sort(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       Try
-       {
-               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
-                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
-               JSStringArrayPriv* priv =
-                       static_cast<JSStringArrayPriv*>(JSObjectGetPrivate(thisObject));
-               StringArrayPtr currentStrings = priv->getObject();
-               std::sort(currentStrings->begin(), currentStrings->end());
-               return thisObject;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogError("error occured");
-       }
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::splice(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::toString(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return join(context, function, thisObject, 0, arguments, exception);
-}
-
-JSValueRef JSStringArray::unshift(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSStringArray::valueOf(JSContextRef context,
-               JSObjectRef function,
-               JSObjectRef thisObject,
-               size_t argumentCount,
-               const JSValueRef arguments[],
-               JSValueRef* exception)
-{
-       return JSValueMakeUndefined(context);
-}
-
-} // Contact
-} // DeviceAPI
diff --git a/src/Notification/JSStringArray.h b/src/Notification/JSStringArray.h
deleted file mode 100755 (executable)
index 843c7e9..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file        JSStringArray.h
- * @author      Kisub Song (kisubs.song@samsung.com)
- * @version     0.1
- * @brief
- */
-
-#ifndef _TIZEN_NOTIFICATION_JS_STRING_ARRAY_H_
-#define _TIZEN_NOTIFICATION_JS_STRING_ARRAY_H_
-
-#include <vector>
-#include <JavaScriptCore/JavaScript.h>
-#include <CommonsJavaScript/PrivateObject.h>
-
-namespace DeviceAPI {
-namespace Notification {
-
-typedef std::vector<std::string> StringArray;
-typedef DPL::SharedPtr<StringArray> StringArrayPtr;
-typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<StringArrayPtr>::Type JSStringArrayPriv;
-
-class JSStringArray
-{
-public:
-
-       static const JSClassDefinition* getClassInfo();
-
-       static JSClassRef getClassRef();
-
-       static JSObjectRef createArray(JSContextRef context,
-                       const StringArrayPtr &Strings);
-
-       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
-
-       static StringArrayPtr getStringArray(JSContextRef context, JSValueRef value);
-
-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);
-
-       static JSValueRef getLength(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static bool hasProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName);
-
-       static JSValueRef getProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static bool setProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef value,
-                       JSValueRef* exception);
-
-       static void getPropertyNames(JSContextRef context,
-                       JSObjectRef object,
-                       JSPropertyNameAccumulatorRef propertyNames);
-
-       static JSValueRef concat(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef join(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef pop(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef push(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef reverse(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef shift(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef slice(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef sort(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef splice(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef toString(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef unshift(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-       static JSValueRef valueOf(JSContextRef context,
-                       JSObjectRef function,
-                       JSObjectRef thisObject,
-                       size_t argumentCount,
-                       const JSValueRef arguments[],
-                       JSValueRef* exception);
-
-       static bool checkValue(const std::string &value);
-
-       static JSClassRef m_jsClassRef;
-       /**
-        * This structure describes a statically declared function property.
-        */
-       static JSStaticFunction m_function[];
-
-       /**
-        * This structure contains properties and callbacks that define a type of object.
-        */
-       static JSClassDefinition m_classInfo;
-
-       /**
-        * This member variable contains the initialization values for the static properties of this class.
-        * The values are given according to the data structure JSPropertySpec
-        */
-       static JSStaticValue m_property[];
-};
-
-} // Notification
-} // DeviceAPI
-
-#endif // _TIZEN_NOTIFICATION_JS_STRING_ARRAY_H_
diff --git a/src/Notification/NotificationConverter.cpp b/src/Notification/NotificationConverter.cpp
deleted file mode 100755 (executable)
index de98447..0000000
+++ /dev/null
@@ -1,433 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 <dpl/assert.h>
-#include <Commons/Exception.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <ApplicationConverter.h>
-#include "JSStatusNotification.h"
-#include "JSNotificationLine.h"
-#include "JSNotificationLineArray.h"
-#include "NotificationConverter.h"
-#include "JSStringArray.h"
-
-#include <pcrecpp.h>
-
-using namespace std;
-using namespace WrtDeviceApis::Commons;
-using namespace WrtDeviceApis::CommonsJavaScript;
-
-namespace DeviceAPI {
-namespace Notification {
-
-NotificationConverter::NotificationConverter(JSContextRef context) :
-    Converter(context)
-{
-}
-
-NotificationConverter::~NotificationConverter()
-{
-}
-
-INotificationPtr NotificationConverter::toINotificationPtr(const JSValueRef arg)
-{
-       if (JSValueIsObjectOfClass(m_context, arg, JSStatusNotification::getClassRef())) 
-       {
-               return JSStatusNotification::getNotification(m_context, arg);   
-       } 
-
-       ThrowMsg(ConversionException, "type missmatch");
-       // dummy return, will raise exception
-       //return JSStatusNotification::getNotification(m_context, arg); 
-}
-
-DeviceAPI::Application::ApplicationControlPtr NotificationConverter::toIApplicationPtr(const JSValueRef arg)
-{
-       DeviceAPI::Application::ApplicationConverter applicationConverter(m_context);
-       return applicationConverter.toApplicationControl(arg);
-}
-
-NotificationType NotificationConverter::toNotificationType(const JSValueRef arg)
-{
-       std::string strType = toString(arg);
-       LogDebug("Notification Type : " << strType);
-
-       if ( strType.compare("SIMPLE") == 0 ) 
-       {
-               return NOTI_TYPE_SIMPLE;
-       }
-       else if ( strType.compare("ONGOING") == 0 ) 
-       {
-               return NOTI_TYPE_ONGOING;
-       }
-       else if ( strType.compare("PROGRESS") == 0 ) 
-       {
-               return NOTI_TYPE_PROGRESS;
-       }
-       else if ( strType.compare("MULTIPLE") == 0 )
-       {
-               return NOTI_TYPE_MUTIPLE;
-       }
-       else if ( strType.compare("THUMBNAIL") == 0 )
-       {
-               return NOTI_TYPE_THUMBNAIL;
-       }       
-       else
-       {
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "notification type not supported");
-       }       
-}
-
-NotificationProgressType NotificationConverter::toNotificationProgressType(const JSValueRef arg)
-{
-       std::string strType = toString(arg);
-       LogDebug("progress Type : " << strType);
-       if ( strType.compare("BYTE") == 0 ) 
-       {
-               return NOTI_PROGRESS_TYPE_SIZE;
-       }
-       else if ( strType.compare("PERCENTAGE") == 0 ) 
-       {
-               return NOTI_PROGRESS_TYPE_PERCENTAGE;
-       }       
-       else
-       {
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "notification type not supported");
-       }
-}
-
-
-void NotificationConverter::NotificationConverter::toNotificationFromDict( INotificationPtr& notification, const JSValueRef arg)
-{
-       if (JSValueIsUndefined(m_context, arg) || JSValueIsNull(m_context, arg)) 
-       {
-               return;
-       }
-
-       if (!JSValueIsObject(m_context, arg))
-       {
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "arg is not object");
-       }
-
-       const ScopedJSStringRef contentStr(JSStringCreateWithUTF8CString(NOTIFICATION_CONTENT));
-       const ScopedJSStringRef iconStr(JSStringCreateWithUTF8CString(NOTIFICATION_ICON_PATH));
-       const ScopedJSStringRef soundStr(JSStringCreateWithUTF8CString(NOTIFICATION_SOUND_PATH));
-       const ScopedJSStringRef vibrationStr(JSStringCreateWithUTF8CString(NOTIFICATION_VIBRATION));
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-       const ScopedJSStringRef serviceStr(JSStringCreateWithUTF8CString(NOTIFICATION_SEVICE));
-#endif
-       const ScopedJSStringRef appControlStr(JSStringCreateWithUTF8CString(NOTIFICATION_APP_CONTROL));
-       const ScopedJSStringRef appIdStr(JSStringCreateWithUTF8CString(NOTIFICATION_APP_ID));
-       const ScopedJSStringRef progressValueStr(JSStringCreateWithUTF8CString(NOTIFICATION_PROGRESS_VALUE)); 
-               
-       const ScopedJSStringRef linesStr(JSStringCreateWithUTF8CString(NOTIFICATION_LINES));
-       const ScopedJSStringRef backgroundImageStr(JSStringCreateWithUTF8CString(NOTIFICATION_BACKGROUND_IMAGE_PATH)); 
-       const ScopedJSStringRef numberStr(JSStringCreateWithUTF8CString(NOTIFICATION_NUMBER)); 
-       const ScopedJSStringRef thumbnailsStr(JSStringCreateWithUTF8CString(NOTIFICATION_THUMBNAILS)); 
-       const ScopedJSStringRef subIconPathStr(JSStringCreateWithUTF8CString(NOTIFICATION_SUB_ICON_PATH)); 
-       const ScopedJSStringRef progressTypeStr(JSStringCreateWithUTF8CString(NOTIFICATION_PROGRESS_TYPE)); 
-
-       DeviceAPI::Filesystem::IPathPtr path;
-       
-       JSObjectRef dictObject = toJSObjectRef(arg);
-
-       JSValueRef contentValue = JSObjectGetProperty(m_context, dictObject, contentStr.get(), NULL);
-       JSValueRef iconValue = JSObjectGetProperty(m_context, dictObject, iconStr.get(), NULL);
-       JSValueRef soundValue = JSObjectGetProperty(m_context, dictObject, soundStr.get(), NULL);
-       JSValueRef vibrationValue = JSObjectGetProperty(m_context, dictObject, vibrationStr.get(), NULL);
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-       JSValueRef serviceValue = JSObjectGetProperty(m_context, dictObject, serviceStr.get(), NULL);
-#endif
-       JSValueRef appControlValue = JSObjectGetProperty(m_context, dictObject, appControlStr.get(), NULL);
-       JSValueRef appIdValue = JSObjectGetProperty(m_context, dictObject, appIdStr.get(), NULL);
-       JSValueRef progressValue = JSObjectGetProperty(m_context, dictObject, progressValueStr.get(), NULL);
-
-       JSValueRef detailInfoValue = JSObjectGetProperty(m_context, dictObject, linesStr.get(), NULL);
-       JSValueRef backgroundImageValue = JSObjectGetProperty(m_context, dictObject, backgroundImageStr.get(), NULL);
-       JSValueRef numberValue = JSObjectGetProperty(m_context, dictObject, numberStr.get(), NULL);
-       JSValueRef thumbnailsValue = JSObjectGetProperty(m_context, dictObject, thumbnailsStr.get(), NULL);
-       JSValueRef subIconPathValue = JSObjectGetProperty(m_context, dictObject, subIconPathStr.get(), NULL);
-       JSValueRef progressTypeValue = JSObjectGetProperty(m_context, dictObject, progressTypeStr.get(), NULL);
-
-    if (!JSValueIsUndefined(m_context, contentValue)) 
-       {
-               std::string content = toString(contentValue);
-               notification->setContent(content);
-       }
-    if (!JSValueIsUndefined(m_context, iconValue)) 
-       {
-               std::string icon = toString(iconValue);
-               path = DeviceAPI::Filesystem::Utils::fromVirtualPath(m_context, icon);
-               icon = path->getFullPath();
-               LogDebug(icon);
-               
-               notification->setIconPath(icon);
-       }
-    if (!JSValueIsUndefined(m_context, soundValue)) 
-       {
-               std::string sound = toString(soundValue);
-               path = DeviceAPI::Filesystem::Utils::fromVirtualPath(m_context, sound);
-               sound = path->getFullPath();
-               LogDebug(sound);
-
-               notification->setSoundPath(sound);
-       }
-    if (!JSValueIsUndefined(m_context, vibrationValue)) 
-       {
-               bool vibration = toBool(vibrationValue);
-               notification->setDefaultVibration(vibration);
-       }
-
-    if (!JSValueIsUndefined(m_context, appControlValue))
-       {
-               DeviceAPI::Application::ApplicationControlPtr appControl = toIApplicationPtr(appControlValue);
-               notification->setApplicationControl(appControl);
-       }
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
-    else if (!JSValueIsUndefined(m_context, serviceValue))
-       {
-               DeviceAPI::Application::ApplicationControlPtr appControl = toIApplicationPtr(serviceValue);
-               notification->setApplicationControl(appControl);
-       }       
-#endif
-
-       if (!JSValueIsUndefined(m_context, appIdValue)) 
-       {
-               std::string appId = toString(appIdValue);
-               notification->setApplicationId(appId);
-       }
-
-       if (!JSValueIsUndefined(m_context, progressTypeValue)) 
-       {
-               notification->setProgressType(toNotificationProgressType(progressTypeValue));
-       }
-       
-       if (!JSValueIsUndefined(m_context, progressValue)) 
-       {
-               unsigned int progressVal = toULong(progressValue);
-               NotificationProgressType progressType = notification->getProgressType();
-               
-               LogDebug(" progress type = " << progressType << "progressValue = " << progressVal);
-                                               
-               if ( NOTI_PROGRESS_TYPE_SIZE == progressType)
-               {
-                       notification->setProgressValue(progressVal);
-               }
-               else if ( NOTI_PROGRESS_TYPE_PERCENTAGE == progressType)
-               {
-                       //check arrang.
-                       if (  progressVal > 100 )
-                       {
-                               progressVal = 100;
-                       }
-                       double percentage = (double)progressVal/(double)100;
-                       LogDebug(" Percentage Value = " << percentage);
-                       notification->setProgressValue(percentage);
-               }
-                               
-               //double value = toDouble(progressValue);
-               //LogDebug(" Progress Value : " << value);
-               //notification->setProgressValue(value);
-       }
-
-       if (!JSValueIsUndefined(m_context, detailInfoValue)) 
-       {
-               NotificationLineArrayPtr lines = toNotificationLineArray(detailInfoValue);
-               notification->setLines(lines);
-       }
-       
-       if (!JSValueIsUndefined(m_context, backgroundImageValue)) 
-       {
-               std::string backgroundImagePath = toString(backgroundImageValue);
-               DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(m_context, backgroundImagePath); 
-               backgroundImagePath = path->getFullPath();
-               notification->setBackground(backgroundImagePath);
-       }
-
-       if (!JSValueIsUndefined(m_context, numberValue)) 
-       {
-               unsigned int number = toULong(numberValue);
-               LogDebug("Number is = " << number);
-               notification->setNumber(number);
-
-       }
-       
-       if (!JSValueIsUndefined(m_context, thumbnailsValue)) 
-       {
-               StringArrayPtr thumbnailsPtr = toStringArray(thumbnailsValue);
-               notification->setThumbnails(thumbnailsPtr);
-
-               std::vector<std::string>::iterator it;
-
-               int idx = 0;
-               for (it = thumbnailsPtr->begin(); it < thumbnailsPtr->end(); ++it)
-               {
-                       std::string str = *it;
-                       LogDebug(" thumbs : " << str);
-                       DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(m_context, str);
-                       str = path->getFullPath();
-
-                       LogDebug(" thumbs : " << str);
-                       notification->setThumbnail(str, idx);
-                       idx ++;
-               }
-       }
-
-       if (!JSValueIsUndefined(m_context, subIconPathValue)) 
-       {
-               std::string subIconPath = toString(subIconPathValue);
-               DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(m_context, subIconPath); 
-               subIconPath = path->getFullPath();
-               notification->setSubIconPath(subIconPath);
-       }
-       
-
-}
-
-NotificationLineArrayPtr NotificationConverter::toNotificationLineArray(const JSValueRef &jsValue) {
-       if(JSNotificationLineArray::isObjectOfClass(m_context, jsValue))
-               return JSNotificationLineArray::getNotificationLineArray(m_context, jsValue);
-
-       if(!JSIsArrayValue(m_context, jsValue))
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "NotificationLineArray is not array.");
-
-       NotificationLineArrayPtr result(new NotificationLineArray());
-
-       JSObjectRef jsObject = toJSObjectRef(jsValue);
-       for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
-               JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
-               result->push_back(toNotificationLine(element));
-       }
-       return result;
-}
-       
-NotificationLinePtr NotificationConverter::toNotificationLine(const JSValueRef &jsValue)
-{
-       if(!JSNotificationLine::isObjectOfClass(m_context, jsValue))
-       {
-               LogError("Not a NotificationLine object");
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
-       }
-
-       return JSNotificationLine::getNotificationLine(m_context, jsValue);
-}
-
-JSValueRef NotificationConverter::toJSValueRef(const DeviceAPI::Application::ApplicationControlPtr &arg)
-{
-       DeviceAPI::Application::ApplicationConverter applicationConverter(m_context);
-       return applicationConverter.toJSValueRef(arg);
-}
-
-JSValueRef NotificationConverter::toJSValueRef(const INotificationPtr arg)
-{
-       
-       return JSStatusNotification::createJSObject(m_context, arg);
-}
-
-
-JSValueRef NotificationConverter::toJSValueRef(const NotificationType arg)
-{
-       if ( NOTI_TYPE_SIMPLE ==  arg)
-       {
-               return toJSValueRef("SIMPLE");
-       }
-       else if ( NOTI_TYPE_ONGOING ==  arg)
-       {
-               return toJSValueRef("ONGOING");
-       }
-       else if ( NOTI_TYPE_PROGRESS ==  arg)
-       {
-               return toJSValueRef("PROGRESS"); 
-       }
-       else if ( NOTI_TYPE_THUMBNAIL ==  arg)
-       {
-               return toJSValueRef("THUMBNAIL"); 
-       }
-       
-       return  JSValueMakeUndefined(m_context);
-}
-
-JSValueRef NotificationConverter::toJSValueRef(const NotificationProgressType &arg)
-{
-       if ( NOTI_PROGRESS_TYPE_SIZE ==  arg)
-       {
-               return toJSValueRef("BYTE");
-       }
-       else if ( NOTI_PROGRESS_TYPE_PERCENTAGE==  arg)
-       {
-               return toJSValueRef("PERCENTAGE");
-       }
-       
-       return  JSValueMakeUndefined(m_context);
-}
-
-JSValueRef NotificationConverter::toJSValueRef(const std::vector<INotificationPtr> &arg)
-{
-       int count = arg.size();
-       int index = 0;
-       JSObjectRef notificaitions[count];
-
-       LogDebug(count);
-       
-       for (index = 0; index < count; index++)
-       {
-               notificaitions[index] = JSStatusNotification::createJSObject(m_context, arg[index]);
-       }
-       JSObjectRef result = JSObjectMakeArray(m_context, count, notificaitions, NULL);
-       return result;
-}
-
-JSValueRef NotificationConverter::toJSValueRef(const NotificationLinePtr &arg)
-{
-       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSNotificationLine::getClassRef(), arg);
-}
-
-JSValueRef NotificationConverter::toJSValueRef(const NotificationLineArrayPtr &arg)
-{
-       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSNotificationLineArray::getClassRef(), arg);
-}
-
-StringArrayPtr NotificationConverter::toStringArray(const JSValueRef &jsValue)
-{
-       if(JSStringArray::isObjectOfClass(m_context, jsValue))
-               return JSStringArray::getStringArray(m_context, jsValue);
-
-       if(!JSIsArrayValue(m_context, jsValue))
-               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "StringArray is not array.");
-
-       StringArrayPtr result = StringArrayPtr(new StringArray());
-       JSObjectRef jsObject = toJSObjectRef(jsValue);
-    for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
-        JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
-        result->push_back(toString(element));
-    }
-    return result;
-}
-
-JSValueRef NotificationConverter::toJSValueRef(const StringArrayPtr &arg)
-{
-       return JSStringArray::createArray(m_context, arg);
-}
-
-
-}
-}
-
diff --git a/src/Notification/NotificationConverter.h b/src/Notification/NotificationConverter.h
deleted file mode 100755 (executable)
index b976536..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_TIZEN_NOTIFICATION_CONVERTER_H_
-#define TIZENAPIS_TIZEN_NOTIFICATION_CONVERTER_H_
-
-#include <CommonsJavaScript/Converter.h>
-#include <ApplicationControl.h>
-//#include <ApplicationConverter.h>
-#include <FilesystemUtils.h>
-#include "INotification.h"
-#include "NotificationLine.h"
-#include "Logger.h"
-
-namespace DeviceAPI {
-namespace Notification {
-       
-class NotificationConverter : public WrtDeviceApis::CommonsJavaScript::Converter
-{
-public:
-       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
-
-       explicit NotificationConverter(JSContextRef context);
-       virtual ~NotificationConverter();
-       INotificationPtr toINotificationPtr(const JSValueRef arg);
-       DeviceAPI::Application::ApplicationControlPtr toIApplicationPtr(const JSValueRef arg);
-       void toNotificationFromDict(INotificationPtr& notification, const JSValueRef arg);
-       NotificationType toNotificationType(const JSValueRef arg);
-       
-       NotificationLinePtr toNotificationLine(const JSValueRef &jsValue);
-       NotificationLineArrayPtr toNotificationLineArray(const JSValueRef &jsValue);
-       NotificationProgressType toNotificationProgressType(const JSValueRef arg);
-
-       JSValueRef toJSValueRef(const DeviceAPI::Application::ApplicationControlPtr &arg);
-       JSValueRef toJSValueRef(const INotificationPtr arg);
-       JSValueRef toJSValueRef(const std::vector<INotificationPtr> &arg);
-       JSValueRef toJSValueRef(const NotificationType arg);
-       
-       JSValueRef toJSValueRef(const NotificationLinePtr &arg);
-       JSValueRef toJSValueRef(const NotificationLineArrayPtr &arg);
-       JSValueRef toJSValueRef(const NotificationProgressType &arg);
-
-       // String Array
-       StringArrayPtr toStringArray(const JSValueRef &value);
-       JSValueRef toJSValueRef(const StringArrayPtr &arg);
-};
-
-typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<NotificationConverter> NotificationConverterFactory;
-
-}
-}
-
-#endif
-
diff --git a/src/Notification/NotificationDetailInfo.cpp b/src/Notification/NotificationDetailInfo.cpp
new file mode 100755 (executable)
index 0000000..d96a92b
--- /dev/null
@@ -0,0 +1,265 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 <PlatformException.h>
+#include <Logger.h>
+
+#include "NotificationDetailInfo.h"
+
+namespace DeviceAPI {
+namespace Notification {
+
+NotificationDetailInfo::NotificationDetailInfo():
+    m_updated(false),
+    m_mainText(""),
+    m_subText(""),
+    m_index(-1),
+    m_notiHandle(NULL)
+{
+       LogDebug("create by constructor");
+}
+
+NotificationDetailInfo::NotificationDetailInfo(notification_h noti):
+    m_updated(false),
+    m_mainText(""),
+    m_subText(""),
+    m_index(-1),
+    m_notiHandle(noti)
+{
+       LogDebug("create by constructor");
+}
+
+NotificationDetailInfo::NotificationDetailInfo(std::string &mainText, std::string &subText):
+    m_updated(false),
+    m_mainText(mainText),
+    m_subText(subText)
+{
+       LogDebug("create DetilaInfo mainText:"  << mainText  << " subText:" << subText);
+}
+
+NotificationDetailInfo::NotificationDetailInfo(notification_h noti, int index, std::string &mainText, std::string &subText) :
+    m_updated(false),
+    m_mainText(mainText),
+    m_subText(subText),
+    m_notiHandle(noti),
+    m_index(index)
+{
+       LogDebug("create DetilaInfo mainText:"  << mainText  << " subText:" << subText);
+       LogDebug("handle:"  << noti  << " m_index:" << index);
+}
+
+NotificationDetailInfo::~NotificationDetailInfo()
+{
+       //free.
+       LogDebug(" ~NotificationDetailInfo");
+}
+
+std::string NotificationDetailInfo::getMainText() const
+{
+#if 0
+    //return m_info;
+       if (m_notiHandle && m_index >= 0)
+       {
+               LogDebug("index = " << m_index);
+               int index = m_index;
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               switch (index)
+               {
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
+               }
+               
+               char *info = NULL;
+                       
+               if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("get notification information error");
+               }
+
+               std::string strInfo;
+               if (info)
+                       strInfo = info;         
+               LogDebug(" info " << strInfo);
+
+               return strInfo;
+       }
+       else
+       {
+               return m_mainText;
+       }
+#endif
+    LogInfo(" Main Text : " << m_mainText);
+    return m_mainText;
+}
+
+void NotificationDetailInfo::setMainText(std::string mainText)
+{
+
+    LogInfo("mainText :" << mainText);
+#if 0
+    if (m_notiHandle && m_index >= 0)
+       {
+               int idx = m_index;
+               LogDebug(" index : " << idx);
+               LogDebug(" mainText : " << mainText);
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               
+               switch (idx)
+               {
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
+               }
+
+               if ( type != NOTIFICATION_TEXT_TYPE_NONE)
+               {
+                       if (getMainText().compare(mainText))
+                       {
+                               if (notification_set_text(m_notiHandle, type, mainText.c_str(),
+                                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
+                               {
+                                       throw UnknownException("set notification sound error");
+                               }
+                               setUpdatedFlag(true);
+                       }
+               }
+       }
+       else
+       {
+               m_mainText = mainText;
+       }
+#endif
+    m_mainText = mainText;
+
+}
+
+std::string NotificationDetailInfo::getSubText() const
+{
+
+#if 0
+    if (m_notiHandle && m_index >= 0)
+       {
+               int index = m_index;
+               LogDebug(" index : " << index);
+
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               switch (index)
+               {
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
+               }
+                               
+               char *subInfo = NULL;
+               
+               if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("get notification sub information error");
+               }
+
+               std::string strSubInfo;
+               if (subInfo)
+                       strSubInfo = subInfo;
+               LogDebug(" sub info " << strSubInfo);
+               return strSubInfo;
+
+       }
+       else
+       {
+               return m_subText;
+       }
+#endif
+    LogInfo("sub Text : " << m_subText);
+    return m_subText;
+
+}
+
+void NotificationDetailInfo::setSubText(std::string subText)
+{
+    LogDebug("subText :" << subText);
+#if 0
+    if (m_notiHandle && m_index >= 0)
+       {
+               int idx = m_index;
+               LogDebug(" index : " << idx);
+               LogDebug(" input value : " << subText);
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               
+               switch (idx)
+               {
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
+               }
+
+               if ( type != NOTIFICATION_TEXT_TYPE_NONE)
+               {
+                       if (getSubText().compare(subText))
+                       {
+                               if (notification_set_text(m_notiHandle, type, subText.c_str(),
+                                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
+                               {
+                                       throw UnknownException("set notification sound error");
+                               }
+                               setUpdatedFlag(true);
+                       }
+               }
+       }
+       else
+       {
+               m_subText = subText;
+       }
+#endif
+    m_subText = subText;
+}
+
+
+} // Notification
+} // DeviceAPI
diff --git a/src/Notification/NotificationDetailInfo.h b/src/Notification/NotificationDetailInfo.h
new file mode 100755 (executable)
index 0000000..ee5b835
--- /dev/null
@@ -0,0 +1,70 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 __TIZEN_NOTIFICATION_DETAIL_INFO_H__
+#define __TIZEN_NOTIFICATION_DETAIL_INFO_H__
+
+#include <MultiCallbackUserData.h>
+#include <string>
+#include <notification.h>
+#include "NotificationTypes.h"
+
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Notification {
+
+class NotificationDetailInfo
+{
+public:
+    NotificationDetailInfo();
+     NotificationDetailInfo(notification_h noti);      
+    NotificationDetailInfo(std::string &mainText, std::string &subText);
+    NotificationDetailInfo(notification_h noti, int index, std::string &mainText, std::string &subText);
+       
+    virtual ~NotificationDetailInfo();
+
+    std::string getMainText() const;
+    void setMainText(std::string mainText);
+
+    std::string getSubText() const;
+    void setSubText(std::string subText);
+
+    void setUpdatedFlag(bool flag)
+    {
+       m_updated = flag;
+    }
+
+    bool getUpdatedFlag()
+    {
+       return m_updated; 
+    }
+
+private:
+    bool m_updated;
+    std::string m_mainText;
+    std::string m_subText;
+
+    int m_index;
+    notification_h m_notiHandle;
+       
+};
+
+} // Notification
+} // DeviceAPI
+
+#endif // __TIZEN_NOTIFICATION_DETAIL_INFO_H__
\ No newline at end of file
diff --git a/src/Notification/NotificationFactory.cpp b/src/Notification/NotificationFactory.cpp
deleted file mode 100755 (executable)
index bda6382..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 "NotificationFactory.h"
-#include "NotificationManager.h"
-#include "StatusNotification.h"
-
-using namespace DeviceAPI::Notification;
-
-namespace DeviceAPI {
-namespace Notification {
-
-INotificationManagerPtr NotificationFactory::getNotificationManager() 
-{
-       return INotificationManagerPtr(new NotificationManager());
-}              
-
-INotificationPtr NotificationFactory::getNotification(NotificationType type)
-{
-       LogDebug("type = " << type );
-       return INotificationPtr(new StatusNotification(type));
-}
-
-INotificationPtr NotificationFactory::getNotification(void* noti)
-{
-       LogDebug("noti = " << noti );
-       return INotificationPtr(new StatusNotification(noti));
-}
-
-INotificationPtr NotificationFactory::getNotification(int privID)
-{
-       LogDebug("privID = " << privID );
-       return INotificationPtr(new StatusNotification(privID));
-}
-
-
-INotificationPtr NotificationFactory::getNotification()
-{
-       LogDebug(" argu is empty");
-       return INotificationPtr(new StatusNotification(NOTI_TYPE_SIMPLE));
-}
-
-NotificationFactory& NotificationFactory::getInstance() 
-{
-       static NotificationFactory theInstance;
-       return theInstance;
-}
-
-NotificationFactory::NotificationFactory() 
-{
-}
-
-NotificationFactory::~NotificationFactory()
-{
-}
-
-}
-}
-
diff --git a/src/Notification/NotificationFactory.h b/src/Notification/NotificationFactory.h
deleted file mode 100755 (executable)
index 139e4a4..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 TIZENAPIS_API_NOTIFICATION_FACTORY_H_
-#define TIZENAPIS_API_NOTIFICATION_FACTORY_H_
-
-#include <dpl/noncopyable.h>
-#include "INotificationManager.h"
-#include "INotification.h"
-
-namespace DeviceAPI {
-namespace Notification {
-       
-class NotificationFactory : DPL::Noncopyable
-{
-public:
-       INotificationManagerPtr getNotificationManager();
-       INotificationPtr getNotification(NotificationType type);
-       INotificationPtr getNotification(void* noti);
-       INotificationPtr getNotification(int privID);
-       INotificationPtr getNotification();
-       static NotificationFactory& getInstance();
-
-protected:
-       NotificationFactory();
-       ~NotificationFactory();
-};
-
-}
-}
-
-#endif 
-
diff --git a/src/Notification/NotificationLine.h b/src/Notification/NotificationLine.h
deleted file mode 100755 (executable)
index 9fce8be..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT 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 _API_NOTIFICATION_LINE_H_
-#define _API_NOTIFICATION_LINE_H_
-
-#include <vector>
-#include <string>
-#include <dpl/shared_ptr.h>
-#include <notification.h>
-#include <ApplicationControl.h>
-
-namespace DeviceAPI {
-namespace Notification {
-
-class NotificationLine;
-typedef DPL::SharedPtr<NotificationLine> NotificationLinePtr;
-typedef std::vector<NotificationLinePtr> NotificationLineArray;
-typedef DPL::SharedPtr<NotificationLineArray> NotificationLineArrayPtr;
-
-class NotificationLine
-{
-public:
-       NotificationLine();
-       NotificationLine(notification_h noti, int index);
-       NotificationLine(notification_h noti, int index, std::string &info, std::string &subInfo);
-       ~NotificationLine();
-
-       std::string getInformation() const;
-       void setInformation(const std::string &info);
-
-       std::string getSubInformation() const;
-       void setSubInformation(const std::string &subInfo);
-
-       void setUpdatedFlag(bool flag);
-       bool getUpdatedFlag();
-
-private:
-       std::string m_info;
-       std::string m_subInfo;
-       notification_h m_notiHandle;
-       int m_index;
-       bool m_updated;
-};
-
-} // Notification
-} // DeviceAPI
-
-#endif //_API_NOTIFICATION_LINE_H_ 
index 0b7c482..78e63f4 100755 (executable)
@@ -15,6 +15,9 @@
 // limitations under the License.
 //
 
+#include <PlatformException.h>
+#include <Logger.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <cassert>
 #include <unistd.h>
 #include <fcntl.h>
 #include <bundle.h>
-#include <Commons/Exception.h>
 #include <appsvc/appsvc.h>
-#include "NotificationFactory.h"
+
 #include "NotificationManager.h"
-#include "StatusNotification.h"
-namespace DeviceAPI {
-namespace Notification{
 
+namespace DeviceAPI {
+namespace Notification {
 
 extern "C" int service_to_bundle(service_h service, bundle **data);
 
@@ -98,418 +98,44 @@ static bool notification_package_equal(notification_h handle)
        return false;
 }
 
-static bool service_extra_data_callback(service_h service, const char *key, void* user_data)
-{
-       int ret = 0;
-
-       bundle* svc_data = (bundle*)user_data;
-       LogDebug("  key      : " << key);
-       
-       bool isArray = false;
-       ret = service_is_extra_data_array(service, key, &isArray);
-       if (ret != SERVICE_ERROR_NONE)
-       {
-               LogDebug("service_is_extra_data_array passes error");
-               // fail to checking. go to next extra data.
-               return true;
-       }
-
-       std::string keyStr(key);
-
-       if(isArray)
-       {
-               int length = 0;
-               int len = 0;
-               char **value = NULL;
-
-               ret = service_get_extra_data_array(service, key, &value, &length);
-               switch(ret)
-               {
-                       case SERVICE_ERROR_NONE: {
-                               LogDebug("service_get_extra_data success");
-                               
-                               if ( bundle_get_str_array (svc_data, key, &len) )
-                               {       // overwrite any existing value
-                                       bundle_del(svc_data, key);
-                               }
-
-                               if (!bundle_add_str_array(svc_data, key, (const char**)value , length) )
-                               {
-                                       LogDebug("Error add Data Array");
-                               }
-                       
-                       for (int i = 0; i < length; i++)
-                       {
-                               if (value[i])
-                                       free(value[i]);
-                       }
-                       if (value)
-                               free(value);
-                       break;
-               }
-               case SERVICE_ERROR_INVALID_PARAMETER:
-                       LogDebug("service_get_extra_data retuns SERVICE_ERROR_INVALID_PARAMETER");
-                       break;
-               case SERVICE_ERROR_KEY_NOT_FOUND:
-                       LogDebug("service_get_extra_data retuns SERVICE_ERROR_KEY_NOT_FOUND");
-                       break;
-               case SERVICE_ERROR_OUT_OF_MEMORY:
-                       LogDebug("service_get_extra_data retuns SERVICE_ERROR_OUT_OF_MEMORY");
-                       break;
-               default:
-                       LogDebug("service_get_extra_data retuns Error");
-                       break;
-               }       
-       }
-       else // (!isArray)
-       {
-               char *value = NULL;
-               ret = service_get_extra_data(service, key, &value);
-               switch (ret)
-               {
-               case SERVICE_ERROR_NONE:
-               {
-                       if(value == NULL)
-                       {
-                               LogDebug("service_get_extra_data returns NULL");
-                               break;
-                       }
-
-                       if ( bundle_get_val (svc_data, key) )
-                       {       // overwrite any existing value
-                               bundle_del(svc_data, key);
-                       }
-
-                       if (!bundle_add(svc_data, key, (const char*)value) )
-                       {
-                               LogDebug("Error add Data Array");
-                       }
-
-                       if (value)
-                               free(value);
-
-                       break;
-               }
-               case SERVICE_ERROR_INVALID_PARAMETER:
-                       LogDebug("service_get_extra_data retuns SERVICE_ERROR_INVALID_PARAMETER");
-                       break;
-               case SERVICE_ERROR_KEY_NOT_FOUND:
-                       LogDebug("service_get_extra_data retuns SERVICE_ERROR_KEY_NOT_FOUND");
-                       break;
-               case SERVICE_ERROR_OUT_OF_MEMORY:
-                       LogDebug("service_get_extra_data retuns SERVICE_ERROR_OUT_OF_MEMORY");
-                       break;
-               default:
-                       LogDebug("service_get_extra_data retuns Error");
-                       break;
-               }
-       }
-       
-       return true;
-}
-
 NotificationManager::NotificationManager()
 {
 }
 
-NotificationManager::~NotificationManager() 
+NotificationManager::~NotificationManager()
 {
-       LogDebug("remove All noti");
-       //m_notiList.clean();   //clean map.
 }
 
-notification_h NotificationManager::createNotification(INotificationPtr notification)
-{      
-       notification_h noti = NULL;
-       
-       if (notification)
-       {
-               NotificationType statusType = notification->getNotiType();
-
-               notification_type_e type = NOTIFICATION_TYPE_NONE;
-
-               LogDebug("statusType =" << statusType);
-       
-               if (statusType == NOTI_TYPE_SIMPLE || statusType == NOTI_TYPE_MUTIPLE || statusType == NOTI_TYPE_THUMBNAIL)
-               {
-                       type = NOTIFICATION_TYPE_NOTI;
-               }
-               else if ( statusType == NOTI_TYPE_ONGOING || statusType == NOTI_TYPE_PROGRESS)
-               {
-                       type = NOTIFICATION_TYPE_ONGOING;
-               }
-               else
-               {
-                       LogDebug(" invalide noti type");
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error : noti type");
-               }
-
-               LogDebug("type =" << type);
-               
-               noti = notification_create(type);
-               if ( noti )
-               {
-                       LogDebug("noti =" << noti);
-                       notification->setNotificationHandle((void*)noti);
-                       notification->setNotificationState(NOTI_STATE_CREATED);
-#if 0
-                       int privID = 0;
-
-                       int ret = notification_get_id(noti, NULL, &privID);
-                       if ( ret != NOTIFICATION_ERROR_NONE)
-                       {
-                               LogDebug(" notification ID : " << privID);
-                               m_notiList.insert(std::make_pair( privID, notification));
-                       }
-                       else
-                       {
-                               LogDebug("can't get id = " << ret);
-                       }
-#endif
-               }
-               else
-               {       
-                       LogDebug(" notification create error...");
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set notification posted time error");
-               }
-
-       }
-       else
-       {
-               LogDebug(" notification object is null...");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, " notification object is null...");          
-       }
-
-       return noti;
-       
-}
-
-bool NotificationManager::checkFilePath(const char* filePath)
+int NotificationManager::post(StatusNotification *notification)
 {
-       LogDebug(filePath);
-       if (filePath != NULL)
-       {
-               struct stat st;
+       int id = -1;
 
-               if (stat(filePath, &st) < 0)
-               {
-                       LogDebug("Error : Invalid File path");
-                       return false;
-               }
-       }
-       else
+       if ( notification )
        {
-               return false;
-       }
-
-       return true;
-}
-
-void NotificationManager::updateNotification(notification_h noti, INotificationPtr notification)
-{
-       if (noti && notification)
-       {
-               //set title.
-               //const char *titleStr = (notification->getTitle()).c_str();
-               LogDebug("Title :" << (notification->getTitle()).c_str());
-
-               if (notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, (notification->getTitle()).c_str(), 
-                               NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
-               {
-                       LogDebug("set title Error");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification title error");
-               }
-
-               //set progress
-               double progressValue = notification->getProgressValue();
-               LogDebug("progress value :" << progressValue);
-               if (notification_set_progress(noti, progressValue) != NOTIFICATION_ERROR_NONE)
-               {
-                       LogDebug("set Progress Error");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification profress error");
-               }       
-               
-               //set content
-               //const char *contentStr = (notification->getContent()).c_str();
-               LogDebug("Content :" << (notification->getContent()).c_str());
-
-               if(notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, (notification->getContent()).c_str(), 
-                       NULL,  NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
-               {
-                       LogDebug("set Content Error");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification content error");
-               }
-
-               //set event count
-               unsigned int num = notification->getNumber();
-               std::ostringstream numStream;
-               numStream << num;
-               LogDebug("count : " << num);
-               
-               if (notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, (numStream.str()).c_str(), 
-                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
-               {
-                       LogDebug("set Event Number Error");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification event number error");
-               }
-
-               //set event
-               std::vector<std::string> infos = notification->getInformations();
-               std::vector<std::string>::iterator infoIter;
-               int i = 0;
-               
-               for(infoIter = infos.begin(); infoIter != infos.end(); infoIter++)
-               {
-                       std::string info = *infoIter;
-                       LogDebug("info : " << info);
-
-                       const char* text = info.c_str();
-
-                       if ( i == 0)
-                       {
-                               if ( notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, 
-                                               text, NULL, NOTIFICATION_VARIABLE_TYPE_NONE)  != NOTIFICATION_ERROR_NONE)
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification text error");
-                               }
-                       }
-                       else if ( i == 1 )
-                       {
-                               if ( notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, 
-                                               text, NULL, NOTIFICATION_VARIABLE_TYPE_NONE)  != NOTIFICATION_ERROR_NONE)
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification text error");
-                               }
-                       }
-                       else if ( i == 2 )
-                       {
-                               if ( notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, 
-                                               text, NULL, NOTIFICATION_VARIABLE_TYPE_NONE)  != NOTIFICATION_ERROR_NONE)
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification text error");
-                               }               
-                       }
-                       else if ( i == 3)
-                       {
-                               if ( notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, 
-                                               text, NULL, NOTIFICATION_VARIABLE_TYPE_NONE)  != NOTIFICATION_ERROR_NONE)
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification text error");
-                               }
-                       }
-               }
-
-               //thumbnail.
-               
-               //set icon
-               //const char *iconStr = (notification->getIconPath()).c_str();
-               LogDebug("icon : " << (notification->getIconPath()).c_str());
-
-               if (checkFilePath((notification->getIconPath()).c_str()) )
-               {
-                       if (notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, (notification->getIconPath()).c_str())  
-                               != NOTIFICATION_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification icon error");
-                       }
-               }
-               else
-               {
-                       LogDebug("Invailde File path");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Invaild file path");
-               }
-               
-               //set sub icon.
-               //iconStr = (notification->getSubIconPath()).c_str();
-               LogDebug("sub Icon : " << (notification->getSubIconPath()).c_str());
-
-               if (notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, (notification->getSubIconPath()).c_str())  
-                       != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification icon error");
-               }
-               
-               //set background image
-               //iconStr = (notification->getBackground()).c_str();
-               LogDebug("sub Icon : " << (notification->getBackground()).c_str());
-
-               if (notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_BACKGROUND, (notification->getBackground()).c_str())  
-                       != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification icon error");
-               }
-
-               //set vibration
-               bool vibration = (notification->getDefaultVibration());
-               LogDebug("vibration : " << vibration);
-
-               notification_vibration_type_e vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
-
-               if (vibration)
-               {
-                       vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
-               }
-               
-               if (notification_set_vibration(noti, vibration_type, NULL) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification vibration error");         
-               }
+               LogDebug(" notification id = " << notification->getID());
+               notification_h handle = (notification_h)notification->getNotificationHandle();
 
-               //set sound path.
-               //const char* sound = (notification->getSoundPath()).c_str();
-               LogDebug("sound : " << (notification->getSoundPath()).c_str());
-               if ( checkFilePath((notification->getSoundPath()).c_str()))
-               {
-                       if ( notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_USER_DATA, (notification->getSoundPath()).c_str()) 
-                               != NOTIFICATION_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
-                       }
-               }
-               else 
-               {
-                       if ( notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_DEFAULT, notification->getSoundPath().c_str()) 
-                               != NOTIFICATION_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
-                       }
-               }
-                                       
-       }
-       else
-       {
-               LogDebug(" notification object or INotification is null...");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, " NULL Error");
-       }
-}
+               LogDebug("notification hanel :" << handle);
 
-void NotificationManager::post(INotificationPtr notification)
-{
-       LogDebug(" notification id = " << notification->getID());
-       if (notification)
-       {
-               notification_h handle = (notification_h)notification->getNotificationHandle();
                if ( handle )
                {
                        //set Service
                        int ret = 0;
-                       //char *tmpStr = NULL;
-
+       
                        bundle *service_data = NULL;
                        service_h service = notification->getService();
-                       
+               
                        if (service)
                        {
-
                                if (service_to_bundle(service, &service_data)!= SERVICE_ERROR_NONE)
                                {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can't create bundle");      
+                                       throw UnknownException("Can't create bundle");  
                                }
                                else
                                {
                                        notification_set_property(handle, 0);
                                        notification_set_execute_option(handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
-                                       bundle_free(service_data);
+                                       //bundle_free(service_data);
                                }
                        }
 
@@ -553,301 +179,56 @@ void NotificationManager::post(INotificationPtr notification)
                        ret = notification_insert(handle, &privID);      //if noti already exist, it is update.
                        if (NOTIFICATION_ERROR_NONE == ret)
                        {
+                               id = privID;
                                LogDebug("private ID : " << privID);
-                               notification->setNotificationState( NOTI_STATE_POSTED );
+                               notification->setUpdatedFlag(false);
                        }
                        else
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object post fail, Error Code : " << ret);
+                                throw UnknownException("Notification Object post fail");
                        }
-#if 0
-                       
-                       bundle *service_data =  bundle_create();
-                       if (!service_data)
+
+                       if ( type == NOTI_TYPE_PROGRESS)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can't create bundle");      
-                       }
+
+                               double value = 0.0;
                                
-                       ret = service_get_operation(service,  &tmpStr);
-                       if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-                       {
-                               LogDebug("opertation : " << tmpStr );
-                               if (appsvc_set_operation(service_data, tmpStr) != 0)
-                               {
-                                       LogError("set operation is fail...");
-                               }
-                                                               
-                               free(tmpStr);
-                               tmpStr = NULL;
-                       }
-       
-                       ret = service_get_operation(service,  &tmpStr);
-                       if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-                       {
-                               LogDebug("opertation : " << tmpStr );
-                               if (appsvc_set_operation(service_data, tmpStr) != 0)
-                               {
-                                       LogError("set operation is fail...");
-                               }
-                                                               
-                               free(tmpStr);
-                               tmpStr = NULL;
-                       }
-       
-                       ret = service_get_uri(service,  &tmpStr);
-                       if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-                       {
-                               LogDebug("uri : " << tmpStr );
-                               if (appsvc_set_uri(service_data, tmpStr) != 0)
+                               if (notification_get_size(handle, &value) != NOTIFICATION_ERROR_NONE)
                                {
-                                       LogError("set uri is fail...");
+                                       throw UnknownException("get notification size error");
                                }
-                                                               
-                               free(tmpStr);
-                               tmpStr = NULL;
-                       }               
-       
-                       ret = service_get_mime(service,  &tmpStr);
-                       if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-                       {
-                               LogDebug("mime : " << tmpStr );
-                               if (appsvc_set_mime(service_data, tmpStr) != 0)
-                               {
-                                       LogError("set operation is fail...");
-                               }
-                                                               
-                               free(tmpStr);
-                               tmpStr = NULL;
-                       }
-       
-                       ret = service_get_app_id(service,  &tmpStr);
-                       if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-                       {
-                               LogDebug("app id : " << tmpStr );
-                               if (appsvc_set_pkgname(service_data, tmpStr) != 0)
+                               LogInfo("get Size : " << value);
+                               notification_update_size(handle, NOTIFICATION_PRIV_ID_NONE, value);
+                               
+                               if (notification_get_progress(handle, &value) != NOTIFICATION_ERROR_NONE)
                                {
-                                       LogError("set operation is fail...");
+                                       throw UnknownException("get notification percentage error");
                                }
-                               
-                               free(tmpStr);
-                               tmpStr = NULL;
-                       }
-               
-                       //get extra data
-                       ret = service_foreach_extra_data(service, service_extra_data_callback, &service_data);
-                       LogDebug("ret " << ret );
-                       if (ret != SERVICE_ERROR_NONE)
-                       {
-                               LogError("service_foreach_extra_data fail");
-                       }
-                       else
-                       {
-                               notification_set_property(handle, 0);
-                               notification_set_execute_option(handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
-                               bundle_free(service_data);
+                               LogInfo("get Percentage : " << value);
+                               notification_update_progress(handle, NOTIFICATION_PRIV_ID_NONE, value);
                        }
 
-                       int privID = -1;
-                       
-                       ret = notification_insert(handle, &privID);      //if noti already exist, it is update.
-                       if (NOTIFICATION_ERROR_NONE == ret)
-                       {
-                               LogDebug("private ID : " << privID);
-                               notification->setNotificationState( NOTI_STATE_POSTED );
-                       }
-                       else
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object post fail, Error Code : " << ret);
-                       }       
-#if 0
-                       //set time.
-                       time_t current = time(NULL);    //get current time.
-                       LogDebug(" Current Time_t : " << current);
-                       LogDebug("end posted Time =" << ctime(&current));
-                       LogDebug(" Handle = " << handle);
-                       
-                       if ( notification_set_time(handle, time(NULL)) != NOTIFICATION_ERROR_NONE )
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification posted time error");
-                       }
-                       
-                       time_t ret_time;
-                       if ( notification_get_time(handle, &ret_time) != NOTIFICATION_ERROR_NONE)
-                       {
-                               LogDebug(" ret Time error ");
-                       }
-                       LogDebug(":: posted Time =" << ctime(&ret_time));
-#endif
-#endif 
                }
                else
                {
                        LogDebug("it has not notification handle.");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, " It is Empty Notification.");
+                       throw UnknownException("It is Empty Notification.");
                }
-
-               
-       }
-       else
-       {       
-               LogDebug(" INotification is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, " Notificaton Error.");
-       }
-
-#if 0
-
-       int privID = 0;
-       notification_h handle = (notification_h)notification->getNotificationHandle();  
-       
-       if (!handle)
-       {       //create Notification.
-               handle = createNotification(notification);
        }
        else
        {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, " Notificaton create Error.");
+               throw UnknownException("Notification Handle is NULL.");
        }
 
-       if (notification)
-       {
-               updateNotification(handle, notification);       //update
-               //set time.
-               time_t current = time(NULL);    //get current time.
-               if ( notification_set_time(handle, current) != NOTIFICATION_ERROR_NONE )
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification posted time error");
-               }
-
-               //set Service
-               int ret = 0;
-               char *tmpStr = NULL;
-               service_h service = notification->getService();
-               
-               bundle *service_data =  bundle_create();
-               if (!service_data)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can't create bundle");      
-               }
-                       
-               ret = service_get_operation(service,  &tmpStr);
-               if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-               {
-                       LogDebug("opertation : " << tmpStr );
-                       if (appsvc_set_operation(service_data, tmpStr) != 0)
-                       {
-                               LogError("set operation is fail...");
-                       }
-                                                       
-                       free(tmpStr);
-                       tmpStr = NULL;
-               }
-
-               ret = service_get_operation(service,  &tmpStr);
-               if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-               {
-                       LogDebug("opertation : " << tmpStr );
-                       if (appsvc_set_operation(service_data, tmpStr) != 0)
-                       {
-                               LogError("set operation is fail...");
-                       }
-                                                       
-                       free(tmpStr);
-                       tmpStr = NULL;
-               }
-
-               ret = service_get_uri(service,  &tmpStr);
-               if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-               {
-                       LogDebug("uri : " << tmpStr );
-                       if (appsvc_set_uri(service_data, tmpStr) != 0)
-                       {
-                               LogError("set uri is fail...");
-                       }
-                                                       
-                       free(tmpStr);
-                       tmpStr = NULL;
-               }               
-
-               ret = service_get_mime(service,  &tmpStr);
-               if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-               {
-                       LogDebug("mime : " << tmpStr );
-                       if (appsvc_set_mime(service_data, tmpStr) != 0)
-                       {
-                               LogError("set operation is fail...");
-                       }
-                                                       
-                       free(tmpStr);
-                       tmpStr = NULL;
-               }
-
-               ret = service_get_app_id(service,  &tmpStr);
-               if (ret == SERVICE_ERROR_NONE && tmpStr != NULL)
-               {
-                       LogDebug("app id : " << tmpStr );
-                       if (appsvc_set_pkgname(service_data, tmpStr) != 0)
-                       {
-                               LogError("set operation is fail...");
-                       }
-                       
-                       free(tmpStr);
-                       tmpStr = NULL;
-               }
-       
-               //get extra data
-               ret = service_foreach_extra_data(service, service_extra_data_callback, &service_data);
-               LogDebug("ret " << ret );
-               if (ret != SERVICE_ERROR_NONE)
-               {
-                       LogError("service_foreach_extra_data fail");
-               }
-               else
-               {
-                       notification_set_property(handle, 0);
-                       ret = notification_set_execute_option(handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
-                       if (ret != NOTIFICATION_ERROR_NONE)
-                       {
-i                              LogError("notification_set_execute_option fail");
-                       }
-                       bundle_free(service_data);
-               }
-
-               ret = notification_insert(handle, &privID);
-               if (NOTIFICATION_ERROR_NONE == ret)
-               {
-                       LogDebug("private ID : " << privID);
-                       notification->setNotificationState( NOTI_STATE_POSTED );
-               }
-               else
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object post fail, Error Code : " << ret);
-               }               
-                       
-       }
-       else
-       {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, " Notificaton is NULL.");
-       }
-#endif
+       return id;
 }
-
-void NotificationManager::update(INotificationPtr notification)
+void NotificationManager::update(StatusNotification *notification)
 {
-       LogDebug(" notification id = " << notification->getID());
        if (notification)
        {
+               LogDebug(" notification id = " << notification->getID());
                notification_h handle = (notification_h)notification->getNotificationHandle();
-               /*
-               notification_h old_handle = (notification_h)notification->getNotificationHandle();
-               notification_h handle = notification_load( NULL, notification->getID());
-
-               if (notification_free(old_handle) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification title error");
-               }
-               notification->setNotificationHandle((void*)handle);
-               */
-               //LogDebug("handle = " << handle << " old handle  = " << old_handle);
+               
                LogDebug("handle = " << handle);
                
                if (handle)
@@ -877,22 +258,14 @@ void NotificationManager::update(INotificationPtr notification)
                                {
                                        if ( NOTIFICATION_ERROR_NOT_EXIST_ID == ret)
                                        {
-                                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "maybe, notification is not inserted yet.");
+                                               throw NotFoundException("maybe, notification is not inserted yet.");
                                        }
                                        else 
                                        {
-                                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object update grogress fail, Error Code : ");                         
+                                               throw UnknownException("Notification Object update grogress fail, Error Code : ");                      
                                        }
                                }
-
-                               
-#if 0                                                  
-                               if ( NOTIFICATION_ERROR_NONE
-                                               != notification_update_progress(handle, notification->getID(), notification->getProgressValue()))
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object update grogress fail, Error Code : ");
-                               }
-#endif                 
+               
                        }
                        
                        LogDebug(" updated Flag = " << notification->getUpdatedFlag());
@@ -942,7 +315,7 @@ void NotificationManager::update(INotificationPtr notification)
                                
                                if (ret != NOTIFICATION_ERROR_NONE)
                                {
-                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object update fail, Error Code : " << ret);
+                                       throw UnknownException("Notification Object update fail, Error Code : ");
                                }
                                
                                LogDebug(" get Title = " << notification->getTitle());
@@ -951,44 +324,17 @@ void NotificationManager::update(INotificationPtr notification)
                else
                {
                        LogDebug("it has not notification handle.");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, " It is Empty Notification.");
+                       throw UnknownException("It is Empty Notification.");
                }
        }
        else
        {       
                LogDebug(" INotification is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, " Notificaton Error.");
-       }
-
-#if 0
-       notification_h handle = (notification_h)notification->getNotificationHandle();  
-       LogDebug("OK");
-       
-       if (handle == NULL)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object is NULL");
-       }
-       
-       if ( notification->getNotificationState() == NOTI_STATE_POSTED)
-       {               
-               updateNotification(handle, notification);       //update
-               int ret = notification_update(handle);
-               if (ret != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object post fail, Error Code : " << ret);
-               }
-       }
-       else
-       {
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification has not posted, yet");
+               throw UnknownException("Notificaton Error.");
        }
-#endif 
-       
+   
 }
-
-
-// need to make sure id uniqueness
-void NotificationManager::cancel(std::string id)
+void NotificationManager::remove(std::string id)
 {
        int privID = -1;
        int ret = 0;
@@ -998,19 +344,18 @@ void NotificationManager::cancel(std::string id)
        std::istringstream stream(id);
        if (stream.fail())
        {
-               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Invalid notification ID, it don't match id format");
+               throw InvalidValuesException("Invalid notification ID, it don't match id format");
        }
        
-        stream >> privID;
-       //std::istringstream(id) >> privID;
+       stream >> privID;
 
        notification_list_h noti_list;
-        notification_h noti;
+       notification_h noti;
 
        if (notification_get_grouping_list( NOTIFICATION_TYPE_NONE , -1, &noti_list))
        {
                LogDebug(" get notification list failed...");
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Can't get noti list");
+               throw UnknownException("Can't get noti list");
        }
 
        while ( noti_list != NULL)
@@ -1019,7 +364,7 @@ void NotificationManager::cancel(std::string id)
                if (noti != NULL /* && notification_package_equal(noti)*/)
                {
                        int noti_priv = -1;
-                       notification_get_id(noti, NULL, &noti_priv);
+                       notification_get_id(noti, NULL, &noti_priv);
                        LogDebug(" notification id = " << noti_priv);
                        if (noti_priv == privID)
                                existFalg = true;
@@ -1032,7 +377,7 @@ void NotificationManager::cancel(std::string id)
        LogDebug(" notification ID : "<< privID);
 
        if ( !existFalg )
-               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "not exist id");
+               throw NotFoundException("not exist id");
        
        ret = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NONE, privID);
        LogDebug("ret = " << ret);
@@ -1040,243 +385,52 @@ void NotificationManager::cancel(std::string id)
        {
                if (ret == NOTIFICATION_ERROR_NOT_EXIST_ID)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "not exist id");
+                       throw NotFoundException("not exist id");
                }
                else 
                {
-                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Invalid Data Error");
+                       throw InvalidValuesException ("Invalid Data Error");
                }
        } 
 
-#if 0
-       if ( notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NONE, privID) != NOTIFICATION_ERROR_NONE)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "notification_delete error");
-       }
-#endif
-
-#if 0
-       notification_h noti = notification_load(NULL, privID);
-       if (noti)
-       {
-               notiListIterator it = m_notiList.find(privID);
-               if ( m_notiList.end() != it )
-               {
-                       LogDebug("found Notification");
-                       if (it->second)
-                       {
-                               if ( (it->second)->getNotificationState() != NOTI_STATE_DELETED)
-                               {
-                                       (it->second)->setNotificationState(NOTI_STATE_DELETED); //set state type
-                                       if ( notification_delete(noti) != NOTIFICATION_ERROR_NONE)
-                                       {
-                                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "notification_delete error");
-                                       }
-                                       else
-                                       {
-                                               LogDebug("invalid notification state");
-                                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "notification_delete error");
-                                       }
-                               }
-                       }
-               }
-               else
-               {
-                       LogDebug("can't found Notification");
-                       ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "can not found");
-               }
-               
-       }
-       else
-       {
-               LogDebug("invalide notification.");
-               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "can not found");
-       }
-#endif
-
 }
-
-
-void NotificationManager::cancelAll()
+void NotificationManager::removeAll()
 {
-       // no error??
-       //ui_notification_cancel_all();
-
+       //remove all
        if (notification_delete_all_by_type(NULL, 
                NOTIFICATION_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
        {
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, " notification delete failed...");
-       }
-       
-#if 0  
-       LogDebug(" Noti List Size " << m_notiList.size());
-       
-       notiListIterator it = m_notiList.begin();
-       
-       for ( ; it != m_notiList.end(); it++ )
-       {       
-               if (it->first)
-               {
-
-                       notification_h noti = notification_load(NULL, it->first);
-                       if (noti)
-                       {       
-                               LogDebug("Private ID : " << it->first);
-                               if (it->second)
-                               {
-                                       if ( (it->second)->getNotificationState() != NOTI_STATE_DELETED)
-                                       {
-                                               (it->second)->setNotificationState(NOTI_STATE_DELETED); //set state type
-                                               if ( notification_delete(noti) != NOTIFICATION_ERROR_NONE)
-                                               {
-                                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "notification_delete error");
-                                               }
-                                               else
-                                               {
-                                                       LogDebug("invalid notification state");
-                                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "notification_delete error");
-                                               }
-                                       }
-                               }
-                       }
-                       
-               }
-       
-       }
-#endif 
-}
-
-INotificationPtr NotificationManager::cloneNotification(notification_h noti)
-{
-       NotificationType type = NOTI_TYPE_NONE; 
-
-       notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
-       notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
-       
-       notification_get_type(noti, &noti_type);
-       notification_get_layout(noti, &noti_layout);
-       
-       if ( noti_type == NOTIFICATION_TYPE_NOTI )
-       {
-               if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE || 
-                       noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
-               {
-                       type = NOTI_TYPE_SIMPLE;
-               }
-               else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
-               {
-                       type = NOTI_TYPE_THUMBNAIL;
-               }
-       }
-       else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
-       {
-               if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
-               {
-                       type = NOTI_TYPE_ONGOING;
-               }
-               else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
-               {
-                       type = NOTI_TYPE_PROGRESS;
-               }
+               throw UnknownException(" notification delete failed...");
        }
-                       
-       INotificationPtr notification( NotificationFactory::getInstance().getNotification(type));       
-
-       return notification;
 }
 
-// need to make sure id uniqueness
-INotificationPtr NotificationManager::get(std::string id)
+StatusNotification* NotificationManager::get(std::string id)
 {
        int privID = 0;
-       std::istringstream(id) >> privID;
-       LogDebug(" Private ID : "<< privID);    
-
-       INotificationPtr notification = 
-                               NotificationFactory::getInstance().getNotification(privID);                     
-               
-       return notification;
-
-#if 0
-       notification_h noti = notification_load( NULL, privID);
-       if (noti)
-       {
-               LogDebug(" noti = " << noti);
-               INotificationPtr notification = 
-                               NotificationFactory::getInstance().getNotification(noti);                       
-               
-               return notification;
-               
-       }
-       else
-       {
-               LogDebug(" can't find notification");
-               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Can't find noti");
-       }
-#endif
-
-#if 0
-       bool foundFlag = false;
-       int privID = 0;
-       std::istringstream(id) >> privID;
-
-       LogDebug(" Private ID : "<< privID);
-
-       notification_list_h noti_list;
-        notification_h noti;
 
-       if (notification_get_grouping_list( NOTIFICATION_TYPE_NONE , -1, &noti_list))
-       {
-               LogDebug(" get notification list failed...");
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Can't get noti list");
-       }
-
-       INotificationPtr notification;
-
-       while ( noti_list != NULL)
-       {
-               noti = notification_list_get_data(noti_list);
-               if (noti != NULL /* && notification_package_equal(noti)*/)
-               {
-                       int noti_priv = -1;
-                       notification_get_id(noti, NULL, &noti_priv);
-                       
-                       if (noti_priv == privID)
-                       {
-                               foundFlag = true;
-                               notification = cloneNotification(noti);
-                       }
-
-               }
-       }
-
-       if (noti_list)
-               notification_free_list(noti_list);
-       
-       if(!foundFlag)
+       LogDebug("id : " << id);
+       std::istringstream stream(id);
+       if (stream.fail())
        {
-               LogDebug(" can't find notification");
-               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Can't find noti");
+               throw InvalidValuesException("Invalid notification ID, it don't match id format");
        }
-                       
+       stream >> privID;
 
+       StatusNotification* notification = new StatusNotification(privID);
        return notification;
-#endif
 }
-       
-std::vector<INotificationPtr> NotificationManager::getAll()
+std::vector<StatusNotification*> NotificationManager::getAll()
 {
-
        LogDebug("OK");
-       std::vector<INotificationPtr> data;
+       std::vector<StatusNotification*> data;
 
        notification_list_h noti_list;
-        notification_h noti;
+       notification_h noti;
 
        if (notification_get_grouping_list( NOTIFICATION_TYPE_NONE , -1, &noti_list))
        {
                LogDebug(" get notification list failed...");
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Can't get noti list");
+               throw UnknownException("Can't get noti list");
        }
 
        while ( noti_list != NULL)
@@ -1285,34 +439,15 @@ std::vector<INotificationPtr> NotificationManager::getAll()
                if (noti != NULL  && notification_package_equal(noti))
                {
                        int noti_priv = -1;
-                       notification_get_id(noti, NULL, &noti_priv);
+                       notification_get_id(noti, NULL, &noti_priv);
                        LogDebug(" notification id = " << noti_priv);
                        
-                       INotificationPtr notification = 
-                                       NotificationFactory::getInstance().getNotification(noti_priv); 
+                       StatusNotification* notification = new StatusNotification(noti_priv);
 
                        notification_get_id((notification_h)notification->getNotificationHandle(), NULL, &noti_priv);
                        LogDebug("loaded notification id = " << noti_priv);
-                                                                       
+                       
                        data.push_back(notification);                           
-
-#if 0                  
-                       notification_h get_noti = notification_load( NULL, noti_priv);
-                       if(get_noti)
-                       {
-                               INotificationPtr notification = 
-                                               NotificationFactory::getInstance().getNotification(get_noti); 
-                               
-                               notification_get_id(get_noti, NULL, &noti_priv);
-                               LogDebug("loaded notification id = " << noti_priv);
-                                                                       
-                               data.push_back(notification);
-                       }
-                       else
-                       {
-                               LogDebug(" can't load notification");
-                       }
-#endif         
                        
                }
                noti_list = notification_list_get_next(noti_list);
@@ -1325,37 +460,5 @@ std::vector<INotificationPtr> NotificationManager::getAll()
 
 }
 
-void NotificationManager::updateProgress(INotificationPtr notification) 
-{
-#if 0
-       if (notification->getStatusType() != TYPE_PROGRESS)
-       {
-               LogDebug("Type is not progress");
-               return;
-       }
-
-       double value = notification->getProgressValue();
-
-       if (value == 0)
-       {
-               LogDebug("Error" << value);
-               return;
-       }
-
-       LogDebug("OK" << value);
-
-       ui_notification_h handle = (ui_notification_h)notification->getNotificationHandle();
-       ui_notification_progress_type_e type = UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
-
-       if (ui_notification_update_progress(handle, type, value)
-               != UI_NOTIFICATION_ERROR_NONE) 
-       {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification progress value error");
-       }
-#endif 
-}
-
-
-}
-}
-
+} // Notification
+} // DeviceAPI
index d8a14e7..c2d4aec 100755 (executable)
 // limitations under the License.
 //
 
+#ifndef __TIZEN_NOTIFICATION_MANAGER_H__
+#define __TIZEN_NOTIFICATION_MANAGER_H__
 
-#ifndef TIZENAPIS_PLATFORM_NOTIFICATION_MANAGER_H_
-#define TIZENAPIS_PLATFORM_NOTIFICATION_MANAGER_H_
-
-#include "NotificationFactory.h"
-#include "INotificationManager.h"
-#include "INotification.h"
+#include <MultiCallbackUserData.h>
 #include <app.h>
-#include <notification.h>
+#include "NotificationTypes.h"
+#include "StatusNotification.h"
+
+using namespace DeviceAPI::Common;
 
-namespace DeviceAPI{
+namespace DeviceAPI {
 namespace Notification {
 
-class NotificationManager : INotificationManager
+class NotificationManager
 {
 public:
-       friend class NotificationFactory;
-
-       virtual ~NotificationManager();
-       void post(INotificationPtr notification);
-       void update(INotificationPtr notification);
-       void cancel(std::string id);
-       void cancelAll();
-       INotificationPtr get(std::string id);
-       std::vector<INotificationPtr> getAll();
-
-       typedef struct {
-               notification_h foundHandle;
-               std::string id;
-       } FindHandleType;
-       
-       typedef std::map<int, INotificationPtr> notiList;
-       typedef notiList::iterator notiListIterator;
-       
-protected:
-       NotificationManager();
+    NotificationManager();
+    virtual ~NotificationManager();
 
-       notification_h createNotification(INotificationPtr notification);
-       void updateNotification(notification_h noti, INotificationPtr notification);
-       
-       bool checkFilePath(const char* filePath);
+    int post(StatusNotification *notification);        //return notification id
 
-private:
+    void update(StatusNotification *notification);
 
-       INotificationPtr cloneNotification(notification_h noti);
-       void updateProgress(INotificationPtr notification);
+    void remove(std::string id);
 
-       notiList m_notiList;
-       
-};
+    void removeAll();
 
+    StatusNotification* get(std::string id);
 
-}
-}
+    std::vector<StatusNotification*> getAll();
 
-#endif 
+private:
+};
 
+} // Notification
+} // DeviceAPI
 
+#endif // __TIZEN_NOTIFICATION_MANAGER_H__
\ No newline at end of file
diff --git a/src/Notification/NotificationTypes.h b/src/Notification/NotificationTypes.h
new file mode 100755 (executable)
index 0000000..f1bd4bc
--- /dev/null
@@ -0,0 +1,68 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT 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 _NOTIFICATION_TYPES_H_
+#define _NOTIFICATION_TYPES_H_
+
+#include <string>
+#include <vector>
+#include <map>
+
+namespace DeviceAPI {
+namespace Notification {
+
+// enum NotificationType
+#define TIZEN_NOTIFICATION_TYPE_STATUS "STATUS"
+
+// enum StatusNotificationType
+#define TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE "SIMPLE"
+#define TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL "THUMBNAIL"
+#define TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING "ONGOING"
+#define TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS "PROGRESS"
+
+// enum NotificationProgressType
+#define TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE "PERCENTAGE"
+#define TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE "BYTE"
+
+// enum NotificationType
+typedef enum 
+{
+       NOTI_TYPE_NONE = 0,
+       NOTI_TYPE_SIMPLE,
+       NOTI_TYPE_ONGOING,
+       NOTI_TYPE_PROGRESS,
+       NOTI_TYPE_MUTIPLE,
+       NOTI_TYPE_THUMBNAIL,
+       NOTI_TYPE_MAX
+}NotificationType;
+
+//enum NotificationProgressType
+typedef enum 
+{
+       NOTI_PROGRESS_TYPE_NONE = 0,
+       NOTI_PROGRESS_TYPE_PERCENTAGE,
+       NOTI_PROGRESS_TYPE_SIZE,
+       NOTI_PROGRESS_TYPE_MAX  
+} NotificationProgressType;
+
+// typedef NotificationId
+typedef std::string NotificationId;
+
+} // Notification
+} // DeviceAPI
+
+#endif // _NOTIFICATION_TYPES_H_
index 8a9d3eb..e1adddd 100755 (executable)
 // limitations under the License.
 //
 
-#include <cassert>
-#include <Commons/Exception.h>
+#include <PlatformException.h>
+#include <Logger.h>
 #include <sstream>
-#include <notification.h>
 #include <appsvc/appsvc.h>
-#include "StatusNotification.h"
-#include <FilesystemUtils.h>
 
+#include "StatusNotification.h"
 
 namespace DeviceAPI {
-namespace Notification{
+namespace Notification {
 
 #define DEFAULT_ICON_PATH "/opt/share/icons/default/"
-#define MAX_NOTIFICATION_LINE_LENGTH 2
+#define MAX_NOTIFICATION_DETAIL_INFO_LENGTH 2
 #define MAX_THUMBNAIL_LENGTH 4
 
 extern "C" int service_create_event(bundle *data, struct service_s **service);
 extern "C" int service_to_bundle(service_h service, bundle **data);
 
-#if 0
-static void service_bundle_iterator(const char *key, const int type, const bundle_keyval_t *kv, void *user_data)
+//callback functions.
+static bool service_extra_data_cb(service_h service, const char *key, void *user_data)
 {
-       service_h service = (service_h)user_data;
-       LogDebug("key = " << key);
-       LogDebug(" type = " << type);
-       void *basic_val = NULL;
-       size_t basic_size = 0;
-       
-       if (bundle_keyval_type_is_array((bundle_keyval_t*)kv))
-       {
-               LogDebug("Array");
+       LogInfo("OK");
+       char **value = NULL;
+       int length = 0;
+
+       if (user_data != NULL && key != NULL)
+       {       
+               LogInfo("user data & key is existed");
+
+               DeviceAPI::Application::ApplicationControlPtr* appControl = 
+                       (DeviceAPI::Application::ApplicationControlPtr*)(user_data);
+
+               DeviceAPI::Application::ApplicationControlDataPtr data(new DeviceAPI::Application::ApplicationControlData());
+               LogInfo("key = " << key);
+               std::string keyStr = key;
+               std::vector<std::string> keyValue;
+               int index = 0;
+
+               if (service_get_extra_data_array((*appControl)->getService_h(), key, &value, &length) == SERVICE_ERROR_NONE)
+               {
+                       LogInfo("extra_data_array length = " << length);
+                       
+                       if (value != NULL && length != 0)
+                       {
+                               LogInfo("extra_data_length = " << length);
+                               data->setKey(key);
+                               for (index = 0; index < length; index++)
+                               {
+                                       LogInfo("Value=" << value[index]);
+                                       keyValue.push_back(value[index]);
+                               }
+                               
+                               data->setValue(keyValue);
+                               (*appControl)->addAppControlData(data);
+                       }
+                       
+                       if(value)
+                               free(value);
+               }
        }
-       else
-       {
-               bundle_keyval_get_basic_val((bundle_keyval_t*)kv, &basic_val, &basic_size);
+       return true;
+}
+
+static bool service_extra_data_delete_cb(service_h service, const char *key, void *user_data)
+{
+       LogInfo("OK");
+       if (key != NULL)
+       {       
+               LogInfo("del key = " << key);
                
-               service_add_extra_data(service, key, );
+               if (service_remove_extra_data(service, key) != SERVICE_ERROR_NONE)
+               {
+                       LogWarning("remove extra data failed");
+                       return false;
+               }
        }
+       return true;
 }
-#endif
 
 StatusNotification::StatusNotification(NotificationType statusType) :
+       m_notiType(NOTI_TYPE_NONE),
        m_service(NULL),
        m_notiHandle(NULL),
-       m_lines(NULL)
-{      
-       notification_type_e type = NOTIFICATION_TYPE_NONE;
+       m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
+       m_notiUpdated(false)
+{
+       LogInfo("statusType =" << statusType);
 
-       LogDebug("statusType =" << statusType);
+       notification_type_e type = NOTIFICATION_TYPE_NONE;
        setNotiType(statusType);
-       
+
        if (statusType == NOTI_TYPE_SIMPLE || statusType == NOTI_TYPE_MUTIPLE || statusType == NOTI_TYPE_THUMBNAIL)
        {
                type = NOTIFICATION_TYPE_NOTI;
@@ -76,48 +115,58 @@ StatusNotification::StatusNotification(NotificationType statusType) :
        }
        else
        {
-               LogDebug(" invalide noti type");
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error : noti type");
+               LogInfo(" invalide noti type");
+               throw TypeMismatchException("value is not notification type");
        }
 
        setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default
-       
-       LogDebug("Notification Type : " << type);
-       
-       notification_h noti = NULL;
-       noti = notification_create(type);       //create notificatin.
+
+       LogInfo("Notification Type : " << type);
+
+       notification_h noti = notification_create(type);        //create notificatin.
        if ( noti )
        {
-               LogDebug("noti =" << noti);
+               LogInfo("noti =" << noti);
                setNotificationHandle((void*)noti);
-               setNotificationState(NOTI_STATE_CREATED);
+#if 0          
                if ( statusType == NOTI_TYPE_PROGRESS)
                {
                        notification_update_progress(noti, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
                }
-       }
-       m_lines = NotificationLineArrayPtr(new NotificationLineArray());
-       m_thumbs = StringArrayPtr(new StringArray());
+#endif
                
+       }
+       else
+       {
+               throw UnknownException("can't make new notification object");
+       }
+       
+       //m_detailInfos = new std::vector<NotificationDetailInfo*>();   
+       //m_thumbs = new std::vector<std::string>();
+       
 }
 
 StatusNotification::StatusNotification(void* noti) :
+       m_notiType(NOTI_TYPE_NONE),
        m_service(NULL),
        m_notiHandle(NULL),
-       m_lines(NULL)
+       m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
+       m_notiUpdated(false)
 {
-       LogDebug("noti : " << noti);
-       notification_h notification = (notification_h)noti;
+       LogInfo("noti : " << noti);
        
+       notification_h notification = (notification_h)noti;
+
        if ( notification )
        {
-               NotificationType type = NOTI_TYPE_NONE; 
+               NotificationType type = NOTI_TYPE_NONE;
                notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
                notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
-               
+
                notification_get_type(notification, &noti_type);
                notification_get_layout(notification, &noti_layout);
-               
+
+               //get type.
                if ( noti_type == NOTIFICATION_TYPE_NOTI )
                {
                        if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE || 
@@ -142,18 +191,15 @@ StatusNotification::StatusNotification(void* noti) :
                        }
                }
 
-               LogDebug(" notification type  =" << type);
+               LogInfo(" notification type  =" << type);
                setNotiType(type);
-               setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.      
+               setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
+               
                setNotificationHandle((void*)notification);
+               loadThumbnails();
+               loadDetailInfos();
 
-               m_lines = NotificationLineArrayPtr(new NotificationLineArray());
-               m_thumbs = StringArrayPtr(new StringArray());
-
-               setNotificationLines();
-               setNotificationState(NOTI_STATE_CREATED);
-
-                if ( type  == NOTI_TYPE_PROGRESS)
+                if ( type  == NOTI_TYPE_PROGRESS)
                 {
                         notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
                 }
@@ -162,37 +208,47 @@ StatusNotification::StatusNotification(void* noti) :
                bundle *bSvc = NULL;
 
                int ret =  notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
-               LogDebug("ret = " << ret); 
+               LogInfo("ret = " << ret); 
                if (ret == NOTIFICATION_ERROR_NONE)
-               //if ( notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc) == NOTIFICATION_ERROR_NONE)
                {
-                       LogDebug(" bundle = " << bSvc);
+                       LogInfo(" bundle = " << bSvc);
                        if (bSvc)
                        {
-                               LogDebug("bundle is valid");    
+                               LogInfo("bundle is valid");     
                                int ret = service_create_event(bSvc, &m_service);
                                if (ret != SERVICE_ERROR_NONE)
                                {
-                                       LogDebug("Service Create Event Error");
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service creation error");
+                                       LogInfo("Service Create Event Error");
+                                       throw UnknownException("can't make service object");
                                }
-
-                               bundle_free(bSvc); //bundle free
                        }
                }
+               else
+               {
+                       notification_free(notification);
+                       throw UnknownException("can't get service data");
+               }
+               
+       }
+       else
+       {
+               throw InvalidValuesException("It is not notification object.");
        }
+       
 }
 
 StatusNotification::StatusNotification(int privID) :
-               m_service(NULL),
-               m_notiHandle(NULL),
-               m_lines(NULL)
+       m_notiType(NOTI_TYPE_NONE),
+       m_service(NULL),
+       m_notiHandle(NULL),
+       m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
+       m_notiUpdated(false)
 {
-       LogDebug("priv ID : " << privID);
-       
-       notification_h notification = notification_load( NULL, privID);
-       LogDebug(" notification " << notification);
-       
+       LogInfo("priv ID : " << privID);
+
+       notification_h notification = notification_load( NULL, privID); //load notification.
+       LogInfo(" notification " << notification);
+
        if ( notification )
        {
                NotificationType type = NOTI_TYPE_NONE; 
@@ -226,155 +282,139 @@ StatusNotification::StatusNotification(int privID) :
                        }
                }
 
-               LogDebug(" notification type  =" << type);
+               LogInfo(" notification type  =" << type);
                setNotiType(type);
                setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.      
                setNotificationHandle((void*)notification);
+               loadThumbnails();
+               loadDetailInfos();
 
-               m_lines = NotificationLineArrayPtr(new NotificationLineArray());
-               m_thumbs = StringArrayPtr(new StringArray());
-
-               setNotificationLines();
-               setNotificationState(NOTI_STATE_CREATED);
+                if ( type  == NOTI_TYPE_PROGRESS)
+                {
+                        notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
+                }
 
                //service
                bundle *bSvc = NULL;
 
                int ret =  notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
-               LogDebug("ret = " << ret); 
+               LogInfo("ret = " << ret); 
                if (ret == NOTIFICATION_ERROR_NONE)
-               //if ( notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc) == NOTIFICATION_ERROR_NONE)
                {
-                       LogDebug(" bundle = " << bSvc);
+                       LogInfo(" bundle = " << bSvc);
                        if (bSvc)
                        {
-                               LogDebug("bundle is valid");    
+                               LogInfo("bundle is valid");     
                                int ret = service_create_event(bSvc, &m_service);
                                if (ret != SERVICE_ERROR_NONE)
                                {
-                                       LogDebug("Service Create Event Error");
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service creation error");
+                                       LogInfo("Service Create Event Error");
+                                       throw UnknownException("can't make service object");
                                }
-                               
-                               //bundle_free(bSvc); //bundle free
                        }
                }
+               else
+               {
+                       notification_free(notification);
+                       throw UnknownException("can't get service data");
+               }
+               
        }
        else
        {
-               LogDebug(" can't find notification");
-               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Can't find noti");
+               throw NotFoundException("It is not notification ID or removed notification");
        }
        
 }
 
-
 StatusNotification::~StatusNotification() 
 {
-       LogDebug(" notification = " << m_notiHandle);
+       LogInfo(" notification = " << m_notiHandle);
 
+       //clear thumbnail.
+       //clearDetailInfos();
+       
        if (m_notiHandle)
        {
-               if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification title error");
-               }
-
 #if 0
-               LogDebug(" service = " << m_service);
+               LogInfo(" service = " << m_service);
                if (m_service != NULL)
                {
                        service_destroy(m_service);
                        m_service = NULL;
                }
-#endif
+#endif         
+               if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("notification free failed...");
+               }
+               
                m_notiHandle = NULL;
        }
 }
 
-namespace {
-       
-static bool service_extra_data_cb(service_h service, const char *key, void *user_data)
+int StatusNotification::getID()
 {
-       LogDebug("OK");
-       char **value = NULL;
-       int length = 0;
-
-       if (user_data != NULL && key != NULL)
-       {       
-               LogDebug("user data & key is existed");
-
-               DeviceAPI::Application::ApplicationControlPtr* appControl = 
-                       (DeviceAPI::Application::ApplicationControlPtr*)(user_data);
-
-               DeviceAPI::Application::ApplicationControlDataPtr data(new DeviceAPI::Application::ApplicationControlData());
-               LogDebug("key = " << key);
-               std::string keyStr = key;
-               std::vector<std::string> keyValue;
-               int index = 0;
-
-               if (service_get_extra_data_array((*appControl)->getService_h(), key, &value, &length) == SERVICE_ERROR_NONE)
-               {
-                       LogDebug("extra_data_array length = " << length);
-                       
-                       if (value != NULL && length != 0)
-                       {
-                               LogDebug("extra_data_length = " << length);
-                               data->setKey(key);
-                               for (index = 0; index < length; index++)
-                               {
-                                       LogDebug("Value=" << value[index]);
-                                       keyValue.push_back(value[index]);
-                               }
-                               
-                               data->setValue(keyValue);
-                               (*appControl)->addAppControlData(data);
-                       }
-                       
-                       if(value)
-                               free(value);
-               }
+       int id = -1;    // notification not inserted yet.
+       if (m_notiHandle)
+       {
+               notification_get_id(m_notiHandle, NULL, &id);
        }
-       return true;
+
+       return id;
 }
 
-static bool service_extra_data_delete_cb(service_h service, const char *key, void *user_data)
+std::string StatusNotification::getStatusType()
 {
-       LogDebug("OK");
-       if (key != NULL)
-       {       
-               LogDebug("del key = " << key);
-               
-               if (service_remove_extra_data(service, key) != SERVICE_ERROR_NONE)
-               {
-                       LogDebug("remove extra data failed");
-                       return false;
-               }
+       std::string type;
+       
+       if ( NOTI_TYPE_SIMPLE ==  getNotiType())
+       {
+               type = "SIMPLE";
+       }
+       else if ( NOTI_TYPE_ONGOING ==  getNotiType())
+       {
+               type = "ONGOING";
+       }
+       else if ( NOTI_TYPE_PROGRESS ==  getNotiType())
+       {
+               type = "PROGRESS"; 
+       }
+       else if ( NOTI_TYPE_THUMBNAIL ==  getNotiType())
+       {
+               type = "THUMBNAIL"; 
        }
-       return true;
-}
 
+       return type;
+               
+}
 
 
-}//namespace
 
-int StatusNotification::getID()
+void StatusNotification::setStatusType(std::string type)
 {
-       if (m_notiHandle)
-       {
-               int id = 0;
-               notification_get_id(m_notiHandle, NULL, &id);
-               return id;
-       }
+       LogInfo("type = " << type);
+       
+       NotificationType notiType = NOTI_TYPE_NONE; 
+       
+       if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
+               notiType = NOTI_TYPE_SIMPLE;
+       else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
+               notiType = NOTI_TYPE_THUMBNAIL;
+       else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
+               notiType = NOTI_TYPE_ONGOING;    
+       else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
+               notiType = NOTI_TYPE_PROGRESS;
        else
-       {
-               return -1;      // notification not inserted yet.
-       }
+       throw InvalidValuesException("Invalid Status Type.");
+
+       LogInfo("Notification type = " << notiType);
+       setNotiType(notiType);
 }
 
 time_t StatusNotification::getPostedTime()
 {
-       LogDebug("get m_notiHandle = " << m_notiHandle);
+       LogInfo("get m_notiHandle = " << m_notiHandle);
        
        time_t postedTime = 0;
        
@@ -382,11 +422,11 @@ time_t StatusNotification::getPostedTime()
        {                       
                if (notification_get_insert_time(m_notiHandle, &postedTime) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification posted time error");
+                       throw UnknownException("get notification posted time error");
                }
        }
        
-       LogDebug("posted Time =" << ctime(&postedTime));
+       LogInfo("posted Time =" << ctime(&postedTime));
        return postedTime;
 }
 
@@ -398,81 +438,79 @@ std::string StatusNotification::getTitle()
        
                if (notification_get_text(m_notiHandle,NOTIFICATION_TEXT_TYPE_TITLE, &title) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification title error");
+                       throw UnknownException("get notification title error");
                }
 
                std::string notiTitle(title);
-               return notiTitle;               
+               return notiTitle;       
        }
        else
        {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
 
 void StatusNotification::setTitle(std::string title)
 {
-       LogDebug("Title : " << title);
+       LogInfo("Title : " << title);
        if (m_notiHandle)
        {
-               LogDebug("get Title : " << getTitle());
+               LogInfo("get Title : " << getTitle());
                if((getTitle()).compare(title)) //different value.
                {
                        if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(), 
                                NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification title error");
+                               throw UnknownException("set notification title error");
                        }
                        
                        setUpdatedFlag(true);
                }
                else
                {
-                       LogDebug(" title = " << title << " getTitle = " << getTitle());
+                       LogInfo(" title = " << title << " getTitle = " << getTitle());
                }
        }
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
 
+
 std::string StatusNotification::getContent()
 {
-       LogDebug("get Content : " << m_notiHandle);
+       LogInfo("get Content handle: " << m_notiHandle);
        if (m_notiHandle)
        {
                char *content = NULL;
 
                if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification Content error");
+                       throw UnknownException("get notification Content error");
                }
                
-               LogDebug(" get Content : " << content);
+               LogInfo(" get Content : " << content);
+
+               std::string notiContent;
                
                if(content)
-               {
-                       std::string notiContent(content);
-                       return notiContent;             
-               }
-               else
-               {
-                       return std::string("");
-               }
+                       notiContent = content;
+
+               return notiContent;
+               
        }
        else
        {
-               LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
        
 }
 
 void StatusNotification::setContent(std::string content)
 {
-       LogDebug("Content : " << content);
+       LogInfo("Content : " << content);
        if (m_notiHandle)
        {
                if((getContent()).compare(content))     //different value.
@@ -480,7 +518,7 @@ void StatusNotification::setContent(std::string content)
                        if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
                                NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification content error");
+                               throw UnknownException("set notification content error");
                        }
                        setUpdatedFlag(true);
                }
@@ -488,35 +526,36 @@ void StatusNotification::setContent(std::string content)
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
-       
+
 std::string StatusNotification::getIconPath()
 {
+
+       LogInfo("m_notiHandle = " << m_notiHandle);
        if (m_notiHandle)
        {
                char *iconPath = NULL;
-       
                if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON,  &iconPath) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification icon path error");
+                       throw UnknownException("get notification icon path error");
                }
 
                std::string notiIconPath(iconPath);
-               LogDebug("icon Path = " << iconPath);
+               LogInfo("icon Path = " << iconPath);
                
                //if icon path invalid, return empty string.
                if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
                        return notiIconPath;    
                else
                {
-                       return std::string("");         
+                       return std::string(""); //return empty string.
                }
        }
        else
        {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
 
@@ -524,25 +563,27 @@ void StatusNotification::setIconPath(const std::string& iconPath)
 {
        if (m_notiHandle)
        {
-               LogDebug("icon path = " << iconPath << " origin icon path = " << getIconPath());
+               LogInfo("icon path = " << iconPath << " origin icon path = " << getIconPath());
                if( getIconPath().compare(iconPath))
                {
                        if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification icon error");
+                               throw UnknownException("set notification icon error");
                        }
                        setUpdatedFlag(true);
                }
        }
        else
-       {       
+       {
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
 
 std::string StatusNotification::getSoundPath()
 {
+       LogInfo("Handle = " << m_notiHandle);
+
        if (m_notiHandle)
        {
                const char *soundPath = NULL;
@@ -550,14 +591,13 @@ std::string StatusNotification::getSoundPath()
                
                if (notification_get_sound(m_notiHandle, &type,  &soundPath) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sound error");
+                       throw UnknownException("get notification sound error");
                }
 
-               LogDebug(" sound type = " << type << " path = " << soundPath);
-               
+               LogInfo(" sound type = " << type << " path = " << soundPath);
                if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
                {
-                       LogDebug("soundPath = " << soundPath);
+                       LogInfo("soundPath = " << soundPath);
                        return std::string(soundPath); 
                }
                else
@@ -568,7 +608,7 @@ std::string StatusNotification::getSoundPath()
        else
        {
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
 
@@ -576,32 +616,42 @@ void StatusNotification::setSoundPath(const std::string& sound)
 {
        if (m_notiHandle)
        {
-               LogDebug("sound path = " << sound << " origin sound path = " << getSoundPath());
+               LogInfo("sound path = " << sound << " origin sound path = " << getSoundPath());
                
                if( getSoundPath().compare(sound))
                {
                        if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
+                               throw UnknownException("set notification sound error");
                        }
                        setUpdatedFlag(true);
                }
+
+               if (sound.empty()) 
+               {
+                   LogInfo("sound path is NULL");
+                    if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
+                   {
+                       throw UnknownException("set notification sound error");
+                   }
+               }
        }
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
 
 bool StatusNotification::getDefaultVibration()
 {
+       LogInfo("getDefaultVibration");
        if (m_notiHandle)
        {
                notification_vibration_type_e vib_type;
                if (notification_get_vibration(m_notiHandle, &vib_type,  NULL) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
+                       throw UnknownException("set notification sound error");
                }
 
                if (vib_type == NOTIFICATION_VIBRATION_TYPE_DEFAULT)
@@ -616,6 +666,7 @@ bool StatusNotification::getDefaultVibration()
        else
        {
                LogDebug("noti Handle is NULL");
+               throw UnknownException("notification handle is null");
        }
 
        return false;
@@ -623,6 +674,7 @@ bool StatusNotification::getDefaultVibration()
 
 void StatusNotification::setDefaultVibration(const bool& vibration) 
 {
+    LogInfo("vibration = " << vibration);
        if (m_notiHandle)
        {
                notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
@@ -636,7 +688,7 @@ void StatusNotification::setDefaultVibration(const bool& vibration)
                        
                        if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
+                               throw UnknownException("set notification sound error");
                        }
                        setUpdatedFlag(true);
                }
@@ -644,94 +696,373 @@ void StatusNotification::setDefaultVibration(const bool& vibration)
        else
        {
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 
 }
 
-double StatusNotification::getProgressValue() 
+DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
 {
-       double value = 0.0;
-       
-       if (m_notiHandle)
-       {
-               NotificationProgressType progressType = getProgressType();
-       
-               if (progressType == NOTI_PROGRESS_TYPE_SIZE)
+
+    service_h service = NULL;
+    char *tempStr = NULL;
+
+    DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
+
+    try {
+               if (m_service)
                {
-                       if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
+                       appControl->setService_h(m_service);
+                       // mandatory
+                       if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification size error");
+                               LogDebug("Operation Str = " << tempStr);
+                               if (tempStr) 
+                               {
+                                       appControl->setOperation(tempStr);
+                                       free(tempStr);
+                                       tempStr = NULL;
+                               }
                        }
-               }
-               else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
-               {
-                       if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
+
+                       // optional
+                       if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification progress error");
+                               LogDebug("Mime Str = " << tempStr);
+                               if (tempStr) 
+                               {
+                                       appControl->setMime(tempStr);
+                                       free(tempStr);
+                                       tempStr = NULL;
+                               }
                        }
-               }
-               else
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification progress error");
-               }
-       }
-       else
-       {
-               LogDebug("noti Handle is NULL");
-       }
 
+                       // optional
+                       if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
+                       {
+                               LogDebug("Uri Str = " << tempStr);
+                               if (tempStr)
+                               {
+                                       appControl->setUri(tempStr);
+                                       free(tempStr);
+                                       tempStr = NULL;
+                               }
+                       }
+
+                       if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
+                       {
+                               LogDebug("Category Str = " << tempStr);
+                               if (tempStr)
+                               {
+                                       appControl->setCategory(tempStr);
+                                       free(tempStr);
+                                       tempStr = NULL;
+                               }
+                       }
+                       
+                       // optional
+                       if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
+                       }
+
+                       return appControl;
+               }
+
+       }
+       Catch (WrtDeviceApis::Commons::Exception) 
+       {
+               if (tempStr) 
+               {
+                       free(tempStr);
+                       tempStr = NULL;
+               }
+
+               if (service)
+               {
+                       free(service);
+                       service = NULL;
+               }
+
+               LogWarning(_rethrown_exception.GetMessage());
+       }
+       
+    return appControl;
+}
+
+void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
+{
+       LogInfo("Entered m_service : " << m_service << " control : " << control);
+
+       //delete old service.
+       if (m_service)
+       {
+               service_destroy(m_service);
+               m_service = NULL;
+       }
+       
+       if(service_create(&m_service) != SERVICE_ERROR_NONE)
+       {
+               throw UnknownException("service creation error");
+       }
+       else
+       {
+               LogInfo("getOperation : " << control->getOperation().c_str());
+               if (control->getOperation().size() != 0)
+               {
+                       if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
+                       {
+                               throw UnknownException("service set operation error");
+                       }
+               }
+                       
+               // optional
+               LogInfo("getUri : " << control->getUri().c_str());
+               if (control->getUri().size() != 0)
+               {
+                       if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
+                       {
+                               throw UnknownException("service set uri error");
+                       }
+               }
+       
+               // optional
+               LogInfo("getMime : " << control->getMime().c_str());
+               if (control->getMime().size() != 0)
+               {
+                       if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
+                       {
+                               throw UnknownException("service set mime error");
+                       }
+               }
+       
+               LogInfo("Category : " << control->getCategory().c_str());
+               if (control->getCategory().size() != 0)
+               {
+                       if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
+                       {
+                               throw UnknownException("service set mime error");
+                       }
+               }
+
+               //remove key
+               //if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
+               //{
+               //      throw UnknownException("get notification service uri error");
+               //}
+               
+               std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
+               size_t index = 0;
+       
+               LogInfo (" App Control Datas Count : " << appControlDataArray.size());
+       
+               DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
+       
+               for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
+               {
+                       DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
+                       std::string key = appControlData->getKey();
+                       LogInfo(" key : " << key);
+               
+                       if (key.empty())
+                               continue;
+               
+                       std::vector<std::string> value = appControlDataArray[index]->getValue();
+                       const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
+       
+                       for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
+                       {
+                               arrayValue[indexArray] = (char*)value[indexArray].c_str();
+                               LogInfo( " value : " << arrayValue[indexArray]);
+                       }
+       
+                       const char* strKey = key.c_str();
+                       LogInfo( " value size: " << value.size());
+                       if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
+                       {
+                               throw UnknownException("service set extra data error");                 
+                       }
+                        
+                       if (arrayValue)
+                               free(arrayValue);
+               }                                       
+       
+               bundle *bundle_data=NULL;
+               
+               if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
+               {
+                       throw UnknownException("service get bundle");                   
+               }
+
+               LogDebug("bundle_data : " << bundle_data);
+               
+               if (bundle_data)
+               {
+                       notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
+                               NULL,NULL, bundle_data);
+               }
+                               
+       }
+       
+}
+
+void StatusNotification::setApplicationId(const std::string& appId)
+{
+       LogInfo("m_service = "  << m_service << " appId = " << appId);
+       if (!m_service)
+       {       
+               if (service_create(&m_service) != SERVICE_ERROR_NONE)
+               {
+                       LogWarning("Create Service Failed..");
+                       throw DeviceAPI::Common::UnknownException ("service creation error");
+               }
+       }
+
+       if (m_service)
+       {
+               if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
+               {
+                       throw DeviceAPI::Common::UnknownException ("service set appId error");  
+               }
+       }
+
+}
+
+std::string StatusNotification::getApplicationId()
+{
+       std::string retString;
+       service_h service = NULL;
+       char* appIdStr = NULL;
+       
+       if (m_service != NULL)
+       {
+               int retcode;
+               retcode = service_clone(&service, m_service);   
+               
+               if (retcode != SERVICE_ERROR_NONE)
+               {
+                       if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
+                       {
+                               LogWarning("SERVICE_ERROR_OUT_OF_MEMORY");
+                       }
+                       else
+                       {
+                               LogWarning("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
+                       }
+                       throw DeviceAPI::Common::UnknownException ("get notification service error ");
+               }
+               else
+               {
+                       if (service == NULL)
+                       {
+                               throw DeviceAPI::Common::UnknownException ("get notification service ok, but service null");                    
+                       }
+               }
+       }
+
+       if (service != NULL) 
+       {
+               if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
+               {
+                       throw DeviceAPI::Common::UnknownException ("get a appId error");
+               }
+
+               if (appIdStr != NULL)
+               {
+                       retString = appIdStr;
+                       free(appIdStr);
+               }
+       }
+       LogInfo(retString);
+       
+       return retString;
+
+}
+
+double StatusNotification::getProgressValue() 
+{
+       double value = 0.0;
+       
+       if (m_notiHandle)
+       {
+               NotificationProgressType progressType = getProgressType();
+       
+               if (progressType == NOTI_PROGRESS_TYPE_SIZE)
+               {
+                       if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
+                       {
+                               throw UnknownException("get notification size error");
+                       }
+                       LogInfo("Size Val = " << value);
+               }
+               else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
+               {
+                       if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
+                       {
+                               throw UnknownException("get notification percentage error");
+                       }
+                       LogInfo("Percentage Val = " << value);
+               }
+               else
+               {
+                       throw UnknownException("get notification progress type error");
+               }
+       }
+       else
+       {
+               LogDebug("noti Handle is NULL");
+       }
+       LogInfo("value = " << value);
        return value;
        
 }
 
 void StatusNotification::setProgressValue(const double &progressValue)
 {
-       LogDebug(" ");
        if (m_notiHandle)
        {       
                NotificationProgressType progressType = getProgressType();
-               LogDebug("Progress Type : " << progressType);
-
+               LogInfo("Progress Type : " << progressType);
+               
                double val = getProgressValue();
-               LogDebug("Progress value = " << progressValue << " origin Progress Value =" << val);
+               LogInfo("Progress value = " << progressValue << " origin Progress Value =" << val);
                
                if (progressType == NOTI_PROGRESS_TYPE_SIZE)
                {
                        if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification size error");
+                               throw UnknownException("set notification progress size error");
                        }
                }
                else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
                {       
-               
                        if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification progress error");
+                               throw UnknownException("set notification percentage error");
                        }
                }
                else
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification progress error");
+                       throw UnknownException("get notification progress type error");
                }
        }
        else
        {
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException( "notification handle is null");
        }
 }
-       
+
 std::string StatusNotification::getSubIconPath()
 {
+        LogInfo("Handle = " << m_notiHandle);
        if (m_notiHandle)
        {
                char *subIconPath = NULL;
        
                if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB,  &subIconPath) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub icon error");
+                       throw UnknownException("get notification sub icon error");
                }
 
                std::string notiSubIconPath;
@@ -741,7 +1072,7 @@ std::string StatusNotification::getSubIconPath()
        }
        else
        {
-               return std::string("");
+               throw UnknownException("notification handle is null");
        }
 
 }
@@ -750,13 +1081,13 @@ void StatusNotification::setSubIconPath(const std::string& subIconPath)
 {
        if (m_notiHandle)
        {
-               LogDebug(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());     
+               LogInfo(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());      
 
                if( getSubIconPath().compare(subIconPath))
                {
                        if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
+                               throw UnknownException("set notification sound error");
                        }
                        setUpdatedFlag(true);
                }
@@ -764,90 +1095,38 @@ void StatusNotification::setSubIconPath(const std::string& subIconPath)
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
 }
 
-std::vector<std::string> StatusNotification::getInformations()
+#if 0
+std::string StatusNotification::getInformation(int index)
 {
-
-       std::vector<std::string> infos;
-
        if (m_notiHandle)
        {
-               
-               char *info = NULL;
-               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &info) != NOTIFICATION_ERROR_NONE)
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               switch (index)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification information error");
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
                }
+               char *info = NULL;
                
-               if (info)
-                       infos.push_back(info);                  //info 1 
-               else
-                       infos.push_back(std::string(""));               // insert empty String
-               info = NULL;
-               
-               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, &info) != NOTIFICATION_ERROR_NONE)
+               if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification information error");
-               }       
-       
-               if (info)
-                       infos.push_back(info);                  //info 2 
-               else
-                       infos.push_back(std::string(""));               // insert empty String
-               info = NULL;
-#if 0
-               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_INFO_3, &info) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification information error");
-               }       
-
-               if (info)
-                       infos.push_back(info);                  //info 3 
-               else
-                       infos.push_back(std::string(""));               // insert empty String
-#endif
-               info = NULL;
-
-       }
-       else
-       {       
-               LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
-       }
-
-       return infos;
-}
-
-std::string StatusNotification::getInformation(int index)
-{
-       if (m_notiHandle)
-       {
-               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
-               switch (index)
-               {
-                       case 0:
-                               type = NOTIFICATION_TEXT_TYPE_INFO_1;
-                               break;
-                       case 1:
-                               type = NOTIFICATION_TEXT_TYPE_INFO_2;
-                               break;
-                       case 2:
-                               type = NOTIFICATION_TEXT_TYPE_INFO_3;
-                               break;
-                       default :
-                               type = NOTIFICATION_TEXT_TYPE_NONE;
-               }
-               char *info = NULL;
-               
-               if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification information error");
-               }
-
-               std::string strInfo;
+                       throw UnknownException("get notification information error");
+               }
+
+               std::string strInfo;
                if (info)
                        strInfo = info;
                LogDebug(" info " << strInfo);
@@ -857,61 +1136,7 @@ std::string StatusNotification::getInformation(int index)
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
-       }
-       
-}
-
-void StatusNotification::setInformations( std::vector<std::string>& infos)
-{
-       
-       if (m_notiHandle)
-       {
-               std::vector<std::string>::iterator it;
-
-               int idx = 0;
-               for (it = infos.begin(); it != infos.end(); ++it) 
-               {
-                       std::string str = *it;
-                       LogDebug(" Info : " << str);
-
-                       notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
-                       switch (idx)
-                       {
-                               case 0:
-                                       type = NOTIFICATION_TEXT_TYPE_INFO_1;
-                                       break;
-                               case 1:
-                                       type = NOTIFICATION_TEXT_TYPE_INFO_2;
-                                       break;
-                               case 2:
-                                       type = NOTIFICATION_TEXT_TYPE_INFO_3;
-                                       break;
-                               default :
-                                       type = NOTIFICATION_TEXT_TYPE_NONE;
-                       }
-
-                       if ( type != NOTIFICATION_TEXT_TYPE_NONE)
-                       {
-                               if (getInformation(idx).compare(str))
-                               {
-                                       if (notification_set_text(m_notiHandle, type, str.c_str(),
-                                               NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
-                                       {
-                                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification information error");
-                                       }
-                                       setUpdatedFlag(true);
-                               }
-                       }
-                       idx ++;
-               }
-               
-
-       }
-       else
-       {       
-               LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
        
 }
@@ -948,64 +1173,17 @@ void StatusNotification::setInformation( const std::string& info, int index)
                                if (notification_set_text(m_notiHandle, type, info.c_str(),
                                        NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
                                {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
+                                       throw UnknownException("set notification sound error");
                                }
                                setUpdatedFlag(true);
                        }
                }
        }
-}
-
-std::vector<std::string> StatusNotification::getSubInformations()
-{
-       std::vector<std::string> subInfos;
-
-       if (m_notiHandle)
-       {
-               char *subInfo = NULL;
-               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, &subInfo) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub background error");
-               }
-
-               if (subInfo)
-                       subInfos.push_back(subInfo);    
-               else 
-                       subInfos.push_back(std::string());
-               subInfo = NULL;
-               
-               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, &subInfo) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
-               }
-               
-               if (subInfo)
-                       subInfos.push_back(subInfo);    
-               else 
-                       subInfos.push_back(std::string());
-
-               subInfo = NULL;
-#if 0
-               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_3, &subInfo) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
-               }
-               
-               if (subInfo)
-                       subInfos.push_back(subInfo);    
-               else 
-                       subInfos.push_back(std::string());
-
-               subInfo = NULL;
-#endif         
-       }
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException("notification handle is null");
        }
-
-       return subInfos;
 }
 
 std::string StatusNotification::getSubInformation(int index)
@@ -1033,7 +1211,7 @@ std::string StatusNotification::getSubInformation(int index)
                
                if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
+                       throw UnknownException( "get notification sub information error");
                }
 
                std::string strSubInfo;
@@ -1046,66 +1224,13 @@ std::string StatusNotification::getSubInformation(int index)
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
-       }
-       
-}
-
-void StatusNotification::setSubInformations(std::vector<std::string>& subInfos)
-{
-       if (m_notiHandle)
-       {
-               std::vector<std::string>::iterator it;
-
-               int idx = 0;
-               for (it = subInfos.begin(); it < subInfos.end(); ++it) 
-               {
-                       std::string str = *it;
-                       LogDebug(" sub Info : " << str);
-
-                       notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
-                       switch (idx)
-                       {
-                               case 0:
-                                       type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
-                                       break;
-                               case 1:
-                                       type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
-                                       break;
-                               case 2:
-                                       type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
-                                       break;
-                               default :
-                                       type = NOTIFICATION_TEXT_TYPE_NONE;
-                       }
-
-                       if ( type != NOTIFICATION_TEXT_TYPE_NONE)
-                       {
-                               if (getSubInformation(idx).compare(str))
-                               {
-                                       if (notification_set_text(m_notiHandle, type, str.c_str(),
-                                               NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
-                                       {
-                                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification text error");
-                                       }
-                                       setUpdatedFlag(true);
-                               }
-                       }
-                       idx ++;
-               }
-
-       }
-       else
-       {       
-               LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException( "notification handle is null");
        }
        
 }
 
 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
 {
-
        if (m_notiHandle)
        {
                int idx = index;
@@ -1135,95 +1260,104 @@ void StatusNotification::setSubInformation( const std::string& subInfo, int inde
                                if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
                                        NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
                                {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
+                                       throw UnknownException( "set notification sound error");
                                }
                                setUpdatedFlag(true);
                        }
                }
        }
+       else
+       {       
+               LogDebug("noti Handle is NULL");
+               throw UnknownException( "notification handle is null");
+       }
+               
 }
+#endif
 
-#if 0
-std::vector<std::string> StatusNotification::getThumbnails()
+void StatusNotification::loadThumbnails()
 {
-       std::vector<std::string> thumbs;
        if (m_notiHandle)
-       {
-               //clean
-               if ( !thumbs.empty() )
-                       thumbs.clear();
-               
+       {       
+               if (!m_thumbs.empty())
+                       m_thumbs.clear();
+
                char *thumb = NULL;
                if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification thumbnail error");
+                       throw UnknownException( "get notification thumbnail error");
                }
                if (thumb)
-                       thumbs.push_back(thumb);
-               else
-                       thumbs.push_back(std::string("")); //set empty
+                       m_thumbs.push_back(thumb);
+               //else
+               //      m_thumbs.push_back(std::string("")); //set empty
                thumb = NULL;
                
                if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
+                       throw UnknownException( "get notification sub information error");
                }       
                if (thumb)
-                       thumbs.push_back(thumb);
-               else
-                       thumbs.push_back(std::string("")); //set empty
+                       m_thumbs.push_back(thumb);
+               //else
+               //      m_thumbs.push_back(std::string("")); //set empty
                thumb = NULL;
                
                if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
+                       throw UnknownException( "get notification sub information error");
                }
                
                if (thumb)
-                       thumbs.push_back(thumb);
-               else
-                       thumbs.push_back(std::string("")); //set empty
+                       m_thumbs.push_back(thumb);
+               //else
+               //      m_thumbs.push_back(std::string("")); //set empty
                thumb = NULL;
 
                if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
+                       throw UnknownException( "get notification sub information error");
                }
                
                if (thumb)
-                       thumbs.push_back(thumb);
-               else
-                       thumbs.push_back(std::string("")); //set empty
+                       m_thumbs.push_back(thumb);
+               //else
+               //      m_thumbs.push_back(std::string("")); //set empty
                thumb = NULL;
-       
+#if 0  
                if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
+                       throw UnknownException( "get notification sub information error");
                }
                
                if (thumb)
-                       thumbs.push_back(thumb);
+                       m_thumbs.push_back(thumb);
                else
-                       thumbs.push_back(std::string("")); //set empty
+                       m_thumbs.push_back(std::string("")); //set empty
                thumb = NULL;
+#endif         
                
        }
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException( "notification handle is null");
        }
+}
 
-       return thumbs;
+std::vector<std::string> StatusNotification::getThumbnails()
+{
+       LogInfo(" thumbnail Size : " << m_thumbs.size());
+       return m_thumbs;
 }
-#endif
 
 std::string StatusNotification::getThumbnail(int index)
 {
-       
        if (m_notiHandle)
        {
-               notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_LIST_1;
+               LogInfo(" index : " << index);
+               
+               notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
                
                switch (index)
                {
@@ -1242,37 +1376,46 @@ std::string StatusNotification::getThumbnail(int index)
                        case 4:
                                type = NOTIFICATION_IMAGE_TYPE_LIST_5;
                                break;
-                               
                        default :
                                type = NOTIFICATION_IMAGE_TYPE_NONE;
                }
-               
-               char* thumb=NULL;
-               
-               if (NOTIFICATION_IMAGE_TYPE_NONE != type && notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
+
+               if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification thumbnail error");
-               }
+                       char *thumb = NULL;
+                       if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
+                       {
+                               throw UnknownException( "set notification thumbnail error");
+                       }
 
-               std::string strThumb;
-               
-               if (thumb)
-                       strThumb = thumb;
+                       std::string thumbnail;
+                       if(thumb)
+                               thumbnail = thumb;
+                       return thumbnail;
+               }
+               else
+               {
+                       throw UnknownException( "notification handle is null");
+               }
                
-               LogDebug(" info " << strThumb);
-               return strThumb;
-
        }
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException( "notification handle is null");
        }
+#if 0
+       if (m_thumbs.size() > index)
+               return m_thumbs[index];
+       else
+               return std::string("");
+#endif
 
 }
 
-void StatusNotification::setThumbnails(std::vector<std::string>& thumbs)
+void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
 {
+        LogInfo("set thumbnails");
        if (m_notiHandle)
        {
                std::vector<std::string>::iterator it;
@@ -1281,74 +1424,26 @@ void StatusNotification::setThumbnails(std::vector<std::string>& thumbs)
                for (it = thumbs.begin(); it < thumbs.end(); ++it)
                {
                        std::string str = *it;
-                       LogDebug(" thumbs : " << str);
-
-                       if ( idx < MAX_THUMBNAIL_LENGTH )
-                               setThumbnail(str, idx);
-#if 0
-                       notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
-                       switch (idx)
-                       {
-                               case 0:
-                                       type = NOTIFICATION_IMAGE_TYPE_LIST_1;
-                                       break;
-                               case 1:
-                                       type = NOTIFICATION_IMAGE_TYPE_LIST_2;
-                                       break;
-                               case 2:
-                                       type = NOTIFICATION_IMAGE_TYPE_LIST_3;
-                                       break;
-                               case 3:
-                                       type = NOTIFICATION_IMAGE_TYPE_LIST_4;
-                                       break;
-                               case 4:
-                                       type = NOTIFICATION_IMAGE_TYPE_LIST_5;
-                                       break;                                  
-                               default :
-                                       type = NOTIFICATION_IMAGE_TYPE_NONE;
-                       }
-                       
                        if ( idx < MAX_THUMBNAIL_LENGTH )
-                       { 
-
-                               if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
-                               {
-                                       if (getThumbnail(idx).compare(str))
-                                       {       
-                                               if (notification_set_image(m_notiHandle, type, str.c_str()) != NOTIFICATION_ERROR_NONE)
-                                               {
-                                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification thumbnail error");
-                                               }
-                                               setUpdatedFlag(true);
-                                       }
-                               }
-                       }
-
-#endif
+                               setThumbnail(str, idx); //set notification's thumbnail value.
                        idx ++;
                }
 
-               if ( idx < MAX_THUMBNAIL_LENGTH)
-               {
-                       setThumbnail("", idx);  //set empty value
-               }       
-               
-
+               m_thumbs = thumbs;
        }
        else
        {       
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException( "notification handle is null");
        }
-
 }
 
 void StatusNotification::setThumbnail( const std::string& thumb, int index)
 {
        if (m_notiHandle)
        {
-               LogDebug(" index : " << index);
-               LogDebug(" thumb : " << thumb);
+               LogInfo(" index : " << index);
+               LogInfo(" thumb : " << thumb);
                notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
                
                switch (index)
@@ -1367,223 +1462,89 @@ void StatusNotification::setThumbnail( const std::string& thumb, int index)
                                break;
                        case 4:
                                type = NOTIFICATION_IMAGE_TYPE_LIST_5;
-                               break;                                  
+                               break;
                        default :
                                type = NOTIFICATION_IMAGE_TYPE_NONE;
                }
 
                if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
                {
-                       
                        if (getThumbnail(index).compare(thumb))
                        {
                                if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
                                {
-                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification thumbnail error");
+                                       throw UnknownException( "set notification thumbnail error");
                                }
                                setUpdatedFlag(true);
                        }
                }
        }
-
 }
 
-void StatusNotification::setThumbnails(const StringArrayPtr &value)
+std::string StatusNotification::getBackground()
 {
-       if(value == NULL)
-               m_thumbs = StringArrayPtr(new StringArray());
-       else
-               m_thumbs = value;
-#if 0
+       LogInfo(" Handle : " << m_notiHandle);
+
        if (m_notiHandle)
        {
-               //set notification.
-               if (value)
+               char *background = NULL;
+       
+               if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
                {
-                       //setThumbnails
-                       std::vector<std::string>::iterator it;
-
-                       int idx = 0;
-                       for (it = m_thumbs->begin(); it < m_thumbs->end(); ++it)
-                       {
-                               std::string str = *it;
-                               LogDebug(" thumbs : " << str);
-                               DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, soundPath);
-                               str = path->getFullPath();
-                       
-                               LogDebug(" thumbs : " << str);
-                               notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
-                               switch (idx)
-                               {
-                                       case 0:
-                                               type = NOTIFICATION_IMAGE_TYPE_LIST_1;
-                                               break;
-                                       case 1:
-                                               type = NOTIFICATION_IMAGE_TYPE_LIST_2;
-                                               break;
-                                       case 2:
-                                               type = NOTIFICATION_IMAGE_TYPE_LIST_3;
-                                               break;
-                                       case 3:
-                                               type = NOTIFICATION_IMAGE_TYPE_LIST_4;
-                                               break;
-                                       case 4:
-                                               type = NOTIFICATION_IMAGE_TYPE_LIST_5;
-                                               break;                                  
-                                       default :
-                                               type = NOTIFICATION_IMAGE_TYPE_NONE;
-                               }
-
-                               if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
-                               {
-                                       if (getThumbnail(idx).compare(str))
-                                       {       
-                                               if (notification_set_image(m_notiHandle, type, str.c_str()) != NOTIFICATION_ERROR_NONE)
-                                               {
-                                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification thumbnail error");
-                                               }
-                                               setUpdatedFlag(true);
-                                       }
-                               }
-                               idx ++;
-                       }
+                       throw UnknownException( "get notification background error");
+               }
                
-
-       
-               }       
+               std::string notiBackground;
+               if (background)
+                       notiBackground = background;
+               return notiBackground;
+       }
+       else
+       {
+               LogDebug("noti Handle is NULL");
+               throw UnknownException( "notification handle is null");
        }
-#endif 
 
 }
 
-StringArrayPtr StatusNotification::getThumbnails()
-{      
+void StatusNotification::setBackground(const std::string imagePath)
+{
+       LogInfo(" imagePath : " << imagePath);
+       if (m_notiHandle)
+       {
+               if (getBackground().compare(imagePath))
+               {
+                       if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
+                       {
+                               throw UnknownException( "set notification sound error");
+                       }
+                       setUpdatedFlag(true);
+               }
+       }
+       else
+       {       
+               LogDebug("noti Handle is NULL");
+               throw UnknownException( "notification handle is null");
+       }
+}
 
+unsigned int StatusNotification::getNumber()
+{
+       LogInfo("Handle = " << m_notiHandle);
        if (m_notiHandle)
        {
-               if ( !m_thumbs->empty() )
-                               m_thumbs->clear();
+               int number = 0;
+               char *strNumber = NULL;
 
-               char *thumb = NULL;
-               if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
+               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification thumbnail error");
-               }
-               if (thumb)
-                       m_thumbs->push_back(thumb);
-               else
-                       m_thumbs->push_back(std::string("")); //set empty
-               thumb = NULL;
-               
-               if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
-               }       
-               if (thumb)
-                       m_thumbs->push_back(thumb);
-               else
-                       m_thumbs->push_back(std::string("")); //set empty
-               thumb = NULL;
-               
-               if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
-               }
-               
-               if (thumb)
-                       m_thumbs->push_back(thumb);
-               else
-                       m_thumbs->push_back(std::string("")); //set empty
-               thumb = NULL;
-
-               if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
-               }
-               
-               if (thumb)
-                       m_thumbs->push_back(thumb);
-               else
-                       m_thumbs->push_back(std::string("")); //set empty
-               thumb = NULL;
-#if 0  
-               if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
-               }
-               
-               if (thumb)
-                       m_thumbs->push_back(thumb);
-               else
-                       m_thumbs->push_back(std::string("")); //set empty
-               thumb = NULL;
-#endif         
-       }       
-       return m_thumbs;
-}
-
-
-
-std::string StatusNotification::getBackground()
-{
-       if (m_notiHandle)
-       {
-               char *background = NULL;
-       
-               if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification background error");
-               }
-               
-               std::string notiBackground;
-               if (background)
-                       notiBackground = background;
-               return notiBackground;
-       }
-       else
-       {
-               LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
-       }
-
-}
-
-void StatusNotification::setBackground(const std::string imagePath)
-{
-       if (m_notiHandle)
-       {
-               if (getBackground().compare(imagePath))
-               {
-                       if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
-                       }
-                       setUpdatedFlag(true);
-               }
-       }
-       else
-       {       
-               LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
-       }
-}
-
-unsigned int StatusNotification::getNumber()
-{
-       if (m_notiHandle)
-       {
-               int number = 0;
-               char *strNumber = NULL;
-
-               if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification background error");
+                       throw UnknownException( "get notification background error");
                }
 
                if (strNumber)
                        std::istringstream(strNumber) >> number;
 
-               LogDebug("number = " << number);
+               LogInfo("number = " << number);
 
                if (number < 0 )
                        number = 0;
@@ -1598,6 +1559,7 @@ unsigned int StatusNotification::getNumber()
 
 void StatusNotification::setNumber(const unsigned int number)
 {
+       LogInfo("Number = " << number);
        if (m_notiHandle)
        {
                if(number!=getNumber())
@@ -1605,7 +1567,7 @@ void StatusNotification::setNumber(const unsigned int number)
                        std::stringstream stream;
                        stream << number;
                        if (stream.fail()) {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                               throw UnknownException(
                                                 "Couldn't convert e-mail account id");
                        }
                        
@@ -1613,7 +1575,7 @@ void StatusNotification::setNumber(const unsigned int number)
                        if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
                                NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
+                               throw UnknownException( "set notification sound error");
                        }
                        setUpdatedFlag(true);
                }
@@ -1621,12 +1583,10 @@ void StatusNotification::setNumber(const unsigned int number)
        else
        {               
                LogDebug("noti Handle is NULL");
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle is null");
+               throw UnknownException( "notification handle is null");
        }
 }
 
-
-
 void* StatusNotification::getNotificationHandle()
 {
        return m_notiHandle;
@@ -1636,16 +1596,16 @@ void StatusNotification::setNotificationHandle(void *handle)
 {
        if (handle == NULL)
        {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle null error");
+               throw UnknownException( "notification handle null error");
        }
-       LogDebug("handle = " << handle << " m_notiHandle = " << m_notiHandle);
+       LogInfo("handle = " << handle << " m_notiHandle = " << m_notiHandle);
        
        if (m_notiHandle != NULL)
        {       
                //delete old noti.
                if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification delete error");
+                       throw UnknownException( "notification delete error");
                }
                m_notiHandle = NULL;
        }
@@ -1653,562 +1613,423 @@ void StatusNotification::setNotificationHandle(void *handle)
        m_notiHandle = (notification_h)handle;
 }
 
-void StatusNotification::setNotificationLines()
+service_h StatusNotification::getService()
 {
-       if (m_notiHandle == NULL)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle null error");
-       }
-       LogDebug("handle = " << m_notiHandle);
-
-       if (getLinesNum() > 0)
-               clearLines();
-
-       //getLine
-       std::vector<std::string> infos = getInformations();
-       std::vector<std::string> subInfos = getSubInformations();
-
-       LogDebug("info size = " << infos.size());
-       LogDebug("subInfo size = " << subInfos.size());
-
-       std::vector<std::string>::iterator it;
+       return m_service;
+}
 
-       int idx = 0;
 
-       NotificationLineArrayPtr lines = getLines();
+//Detail Info
+void StatusNotification::loadDetailInfos()
+{
+       LogInfo("noti Handle = " << m_notiHandle);
 
-       for (it = infos.begin(); it < infos.end(); ++it) 
-       {
-               std::string info = *it;
-               LogDebug(" Info : " << info);
-               LogDebug("subInfo=" << subInfos[idx]);
-       
-               if (!(info.empty() && subInfos[idx].empty()))
+        if (m_notiHandle)
+        {
+               for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
                {
-                       NotificationLinePtr line(new NotificationLine(m_notiHandle,idx,info,subInfos[idx]));
-                       lines->push_back(line);
+                   std::string main = getInformation(idx);
+                   std::string sub = getSubInformation(idx);
+                   LogInfo("Main : " << main << " Sub : " << sub);
+                   NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
+                   m_detailInfos.push_back(info);
                }
-               idx++;
+        }
+        else
+       {               
+               LogDebug("noti Handle is NULL");
+               throw UnknownException( "notification handle is null");
        }
-       
+        
 }
 
-DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
-{      
-       service_h service = NULL;
-       char *tempStr = NULL;
-       
-       DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
-
-       try {
-               if (m_service)
-               {
-                       appControl->setService_h(m_service);
-                       // mandatory
-                       if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
-                       {
-                               LogDebug("Operation Str = " << tempStr);
-                               if (tempStr) 
-                               {
-                                       appControl->setOperation(tempStr);
-                                       free(tempStr);
-                                       tempStr = NULL;
-                               }
-                       }
-
-                       // optional
-                       if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
-                       {
-                               LogDebug("Mime Str = " << tempStr);
-                               if (tempStr) 
-                               {
-                                       appControl->setMime(tempStr);
-                                       free(tempStr);
-                                       tempStr = NULL;
-                               }
-                       }
-
-                       // optional
-                       if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
-                       {
-                               LogDebug("Uri Str = " << tempStr);
-                               if (tempStr)
-                               {
-                                       appControl->setUri(tempStr);
-                                       free(tempStr);
-                                       tempStr = NULL;
-                               }
-                       }
+std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
+{
+       return m_detailInfos;
+}
 
-                       if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
-                       {
-                               LogDebug("Category Str = " << tempStr);
-                               if (tempStr)
-                               {
-                                       appControl->setCategory(tempStr);
-                                       free(tempStr);
-                                       tempStr = NULL;
-                               }
-                       }
-                       
-                       // optional
-                       if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
-                       }
+void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
+{
+    LogInfo("DetailInfos = " << value.size());
+
+    if (m_notiHandle)
+    {
+        std::vector<NotificationDetailInfo*>::const_iterator it;
+        
+        int idx = 0;
+        for (it = value.begin(); it < value.end(); ++it)
+        {
+            NotificationDetailInfo* info = *it;
+            if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
+            {
+                LogInfo("main " << info->getMainText() << " sub " << info->getSubText() );
+               setInformation(info->getMainText(), idx);
+               setSubInformation(info->getSubText(), idx);
+            }
+            idx ++;
+        }
+    
+        m_detailInfos = value;
+    }
+    else
+    {  
+        LogDebug("noti Handle is NULL");
+        throw UnknownException( "notification handle is null");
+    }
+       
+}
 
-                       return appControl;
-               }
+int StatusNotification::getDetailInfosNum() const
+{
+       return m_detailInfos.size();
+}
 
+void StatusNotification::clearDetailInfos()
+{
+       if ( !m_detailInfos.empty() )
+       {
+               std::vector<NotificationDetailInfo*>::const_iterator it;
+              
+               int idx = 0;
+               for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
+               {
+                   NotificationDetailInfo* info = *it;
+                   LogInfo("Delete Detail Info : " << info);
+                   if (info)
+                       delete info;
+                   idx ++;
+               }
+               m_detailInfos.clear();          //clear
        }
-       Catch (WrtDeviceApis::Commons::Exception) 
-       {
-               if (tempStr) 
-               {
-                       free(tempStr);
-                       tempStr = NULL;
-               }
-
-               if (service)
-               {
-                       free(service);
-                       service = NULL;
-               }       
-
-               if (_rethrown_exception.getCode() == WrtDeviceApis::Commons::ExceptionCodes::NullPointerException)
-               {
-                       ReThrowMsg(WrtDeviceApis::Commons::NullPointerException, _rethrown_exception.GetMessage());
+}
 
-               }
-               else
+std::string StatusNotification::getInformation(int index)
+{
+       if (m_notiHandle)
+       {
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               switch (index)
                {
-                       ReThrowMsg(WrtDeviceApis::Commons::UnknownException, _rethrown_exception.GetMessage());
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
                }
-       }
-
-#if 0
-       try {
+               char *info = NULL;
                
-               if (m_service != NULL)
+               if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
                {
-                       retcode = service_clone(&service, m_service);
-                       
-                       if (retcode != SERVICE_ERROR_NONE)
-                       {       
-                               
-                               if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
-                               {
-                                       LogDebug("SERVICE_ERROR_OUT_OF_MEMORY");
-                               }
-                               else
-                               {
-                                       LogDebug("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
-                               }
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service error ");
-                       }
-                       else
-                       {
-                               if (service == NULL)
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "get notification service ok, but service null");                        
-                               }
-                       }
+                       throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
                }
 
-               appControl->setService_h(service);
+               std::string strInfo;
+               if (info)
+                       strInfo = info;
+               LogInfo(" info " << strInfo);
+               return strInfo;
 
-               // mandatory
-               int ret = service_get_operation(service, &tempStr);
-               LogDebug("ret = " << ret);
-               //if (service_get_operation(service, &tempStr) != SERVICE_ERROR_NONE)
-               if(ret != SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service operation error");                 
-               }
-               
-               LogDebug("temp Str = " << tempStr);
+       }
+       else
+       {       
+               LogWarning("noti Handle is NULL");
+               throw UnknownException( "notification handle is null");
+       }
+       
+}
 
-               if (tempStr) 
+std::string StatusNotification::getSubInformation(int index)
+{
+       if (m_notiHandle)
+       {
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               switch (index)
                {
-                       appControl->setOperation(tempStr);
-                       free(tempStr);
-                       tempStr = NULL;
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
                }
-               else 
+                               
+               char *subInfo = NULL;
+               
+               if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "get notification service operation ok, but null");                      
+                       throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
                }
 
-               // optional
-               if (service_get_mime(service, &tempStr) == SERVICE_ERROR_NONE)
-               {
-                       if (tempStr) 
-                       {
-                               appControl->setMime(tempStr);
-                               free(tempStr);
-                               tempStr = NULL;
-                       }
-               }
-
-               // optional
-               if (service_get_uri(service, &tempStr) == SERVICE_ERROR_NONE)
-               {
-                       if (tempStr)
-                       {
-                               appControl->setUri(tempStr);
-                               free(tempStr);
-                               tempStr = NULL;
-                       }
-               }
-
-               // optional
-               if ( service_foreach_extra_data(service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
-               {
-                       LogDebug(error);
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
-               }
+               std::string strSubInfo;
+               if (subInfo)
+                       strSubInfo = subInfo;
+               LogInfo(" subInfo " << strSubInfo);
+               return strSubInfo;
+                               
+       }
+       else
+       {       
+               LogWarning("noti Handle is NULL");
+               throw UnknownException ("notification handle is null");
+       }
+       
+}
 
-               return appControl;
-               
-       }       
-       Catch (WrtDeviceApis::Commons::Exception) 
+void StatusNotification::setInformation( const std::string& info, int index)
+{
+       if (m_notiHandle)
        {
-               if (tempStr) 
+               int idx = index;
+               LogDebug(" index : " << idx);
+               LogDebug(" log : " << info);
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               
+               switch (idx)
                {
-                       free(tempStr);
-                       tempStr = NULL;
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
                }
 
-               if (service)
-               {
-                       free(service);
-                       service = NULL;
-               }       
-
-               if (_rethrown_exception.getCode() == WrtDeviceApis::Commons::ExceptionCodes::NullPointerException)
+               if ( type != NOTIFICATION_TEXT_TYPE_NONE)
                {
-                       ReThrowMsg(WrtDeviceApis::Commons::NullPointerException, _rethrown_exception.GetMessage());
-
+                       if (getInformation(idx).compare(info))
+                       {
+                               if (notification_set_text(m_notiHandle, type, info.c_str(),
+                                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
+                               {
+                                       throw UnknownException("set notification sound error");
+                               }
+                               setUpdatedFlag(true);
+                       }
                }
                else
-               {
-                       ReThrowMsg(WrtDeviceApis::Commons::UnknownException, _rethrown_exception.GetMessage());
+               {       
+                       LogWarning("noti Handle is NULL");
+                       throw UnknownException("notification handle is null");
                }
-
        }
-#endif
-
-       return appControl;
+       else
+       {       
+               LogWarning("noti Handle is NULL");
+               throw UnknownException("notification handle is null");
+       }
 }
 
-void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr appControl)
+void StatusNotification::setSubInformation( const std::string& subInfo, int index)
 {
 
-       LogDebug("Entered m_service : " << m_service);
-       
-       if(m_service == NULL && service_create(&m_service) != SERVICE_ERROR_NONE)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service creation error");
-       }
-       else
+       if (m_notiHandle)
        {
-               LogDebug("getOperation : " << appControl->getOperation().c_str());
-               if (appControl->getOperation().size() != 0)
-               {
-                       if (service_set_operation(m_service, appControl->getOperation().c_str()) != SERVICE_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set operation error");
-                       }
-               }
-                       
-               // optional
-               LogDebug("getUri : " << appControl->getUri().c_str());
-               if (appControl->getUri().size() != 0)
+               int idx = index;
+               LogDebug(" index : " << idx);
+               LogDebug(" log : " << subInfo);
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               
+               switch (idx)
                {
-                       if (service_set_uri(m_service, appControl->getUri().c_str() ) != SERVICE_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set uri error");
-                       }
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
                }
 
-               // optional
-               LogDebug("getMime : " << appControl->getMime().c_str());
-               if (appControl->getMime().size() != 0)
+               if ( type != NOTIFICATION_TEXT_TYPE_NONE)
                {
-                       if (service_set_mime(m_service, appControl->getMime().c_str() ) != SERVICE_ERROR_NONE)
+                       if (getSubInformation(idx).compare(subInfo))
                        {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set mime error");
+                               if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
+                                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
+                               {
+                                       throw UnknownException("set notification sound error");
+                               }
+                               setUpdatedFlag(true);
                        }
                }
+       }
+       else
+       {       
+               LogWarning("noti Handle is NULL");
+               throw UnknownException("notification handle is null");
+       }
+}
 
-               LogDebug("Category : " << appControl->getCategory().c_str());
-               if (appControl->getCategory().size() != 0)
-               {
-                       if (service_set_category(m_service, appControl->getCategory().c_str() ) != SERVICE_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set mime error");
-                       }
-               }
 
-               //remove key
-               if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
-               }
-                               
-               std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = appControl->getAppControlDataArray();
-               size_t index = 0;
+#if 0
 
-               LogDebug (" App Control Datas Count : " << appControlDataArray.size());
+StatusNotification::StatusNotification():
+    m_statusType(""),
+    m_iconPath(""),
+    m_subIconPath(""),
+    m_number(0),
+    m_backgroundImagePath(""),
+    m_soundPath(""),
+    m_vibration(false),
+    m_progressType(""),
+    m_progressValue(0)
+{
+}
 
-               DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
+StatusNotification::~StatusNotification()
+{
+}
 
-               for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
-               {
-                       DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
-                       std::string key = appControlData->getKey();
-                       LogDebug(" key : " << key);
-               
-                       if (key.empty())
-                               continue;
-               
-                       std::vector<std::string> value = appControlDataArray[index]->getValue();
-                       const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
-   
-                       for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
-                       {
-                               arrayValue[indexArray] = (char*)value[indexArray].c_str();
-                               LogDebug( " value : " << arrayValue[indexArray]);
-                       }
+std::string StatusNotification::getStatusType() const
+{
+    return m_statusType;
+}
 
-                       const char* strKey = key.c_str();
-                       LogDebug( " value size: " << value.size());
-                       if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set extra data error");                     
-                       }
-                        
-                       if (arrayValue)
-                               free(arrayValue);
-               }                                       
+void StatusNotification::setStatusType(std::string statusType)
+{
+    m_statusType = statusType;
+}
 
-               bundle *bundle_data=NULL;
-               
-               if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service get bundle");                       
-               }
-               
-               if (bundle_data)
-               {
-                       notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
-                               NULL,NULL, bundle_data);
-                       //bundle_free(bundle_data);     
-               }
-                               
-       }       
+std::string StatusNotification::getIconPath() const
+{
+    return m_iconPath;
+}
 
+void StatusNotification::setIconPath(std::string iconPath)
+{
+    m_iconPath = iconPath;
 }
 
-void StatusNotification::setApplicationId(const std::string& appId)
+std::string StatusNotification::getSubIconPath() const
 {
-       LogDebug("m_service = " << m_service << " appId = " << appId);
-       if (!m_service)
-       {       
-               LogDebug("m_service = " << m_service);
-               if (service_create(&m_service) != SERVICE_ERROR_NONE)
-               {
-                       LogDebug("Create Service Failed..");
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service creation error");
-               }
-       }
+    return m_subIconPath;
+}
 
-       if (m_service)
-       {
-               if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set appId error");  
-               }
-       }
+void StatusNotification::setSubIconPath(std::string subIconPath)
+{
+    m_subIconPath = subIconPath;
+}
 
-#if 0
-       int retcode = 0;
-       service_h service = NULL;
-       char* operation = NULL;
-       LogDebug("Entered : " << appId);
-       
-       LogDebug("m_service = " << m_service);
-       if (m_service != NULL)
-       {
-               retcode = service_clone(&service, m_service);   
-               if (retcode != SERVICE_ERROR_NONE)
-               {                       
-                       if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
-                       {
-                               LogDebug("SERVICE_ERROR_OUT_OF_MEMORY");
-                       }
-                       else
-                       {
-                               LogDebug("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
-                       }
+long StatusNotification::getNumber() const
+{
+    return m_number;
+}
 
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service error ");
-               }
-       }
+void StatusNotification::setNumber(long number)
+{
+    m_number = number;
+}
 
-       if(service == NULL)
-       {
-               if (service_create(&service) != SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service creation error");
-               }
-       }
+std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
+{
+    return m_detailInfo;
+}
 
-       if(service)
-       {       
-               if (service_get_operation(service,      &operation) != SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service get operation error");
-               }
+void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
+{
+    m_detailInfo = detailInfo;
+}
 
-               if (operation) 
-               {
-                       free(operation);
-                       operation = NULL;
-               }
-               else if (service_set_operation(service, SERVICE_OPERATION_DEFAULT) != SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set operation error");
-               }
-               
-               if (service_set_app_id(service, appId.c_str())!= SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set appId error");  
-               }
+std::string StatusNotification::getBackgroundImagePath() const
+{
+    return m_backgroundImagePath;
+}
 
-               if (m_service != NULL)
-               {
-                       service_destroy(m_service);
-                       m_service = NULL;
-               }
-               
-               m_service = service;    //set service.  
-       }
-#endif
+void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
+{
+    m_backgroundImagePath = backgroundImagePath;
 }
 
-std::string StatusNotification::getApplicationId()
+std::vector<std::string> StatusNotification::getThumbnails() const
 {
-       std::string retString;
-       service_h service = NULL;
-       char* appIdStr = NULL;
-       
-       if (m_service != NULL)
-       {
-               int retcode;
-               retcode = service_clone(&service, m_service);   
-               
-               if (retcode != SERVICE_ERROR_NONE)
-               {
-                       if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
-                       {
-                               LogDebug("SERVICE_ERROR_OUT_OF_MEMORY");
-                       }
-                       else
-                       {
-                               LogDebug("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
-                       }
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service error ");
-               }
-               else
-               {
-                       if (service == NULL)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "get notification service ok, but service null");                        
-                       }
-               }
-       }
+    return m_thumbnails;
+}
 
-       if (service != NULL) 
-       {
-               if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get a appId error");
-               }
+void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
+{
+    m_thumbnails = thumbnails;
+}
 
-               if (appIdStr != NULL)
-               {
-                       retString = appIdStr;
-                       free(appIdStr);
-               }
-       }
-       LogDebug(retString);
-       
-       return retString;
+std::string StatusNotification::getSoundPath() const
+{
+    return m_soundPath;
 }
 
-service_h StatusNotification::getService()
+void StatusNotification::setSoundPath(std::string soundPath)
 {
-       return m_service;
+    m_soundPath = soundPath;
 }
 
+bool StatusNotification::getVibration() const
+{
+    return m_vibration;
+}
 
-NotificationLineArrayPtr StatusNotification::getLines() const
+void StatusNotification::setVibration(bool vibration)
 {
-       return m_lines;
+    m_vibration = vibration;
 }
 
-int StatusNotification::getLinesNum() const
+ApplicationControl StatusNotification::getAppControl() const
 {
-       return m_lines->size();
+    return m_appControl;
 }
 
-void StatusNotification::setLines(const NotificationLineArrayPtr &value)
+void StatusNotification::setAppControl(ApplicationControl appControl)
 {
-       LogDebug("setlines");
-       if (value == NULL)
-       {
-               m_lines = NotificationLineArrayPtr(new NotificationLineArray());
-       }
-       else
-       {
-               m_lines = value;
+    m_appControl = appControl;
+}
 
-               NotificationLineArray::iterator iter;
-               int index = 0;
-                for(iter = m_lines->begin(); iter != m_lines->end(); iter++) 
-                { 
-                               NotificationLinePtr line = *iter;
-                       LogDebug("info = " << line->getInformation());
-                       LogDebug("sub info = " << line->getSubInformation());
-                       
-                       if ( index < MAX_NOTIFICATION_LINE_LENGTH)
-                       {       
-                               setInformation(line->getInformation(),index);
-                               setSubInformation(line->getSubInformation(),index);
-                       }
-                       index ++;
-               }
-               
-               //clean empty solt.`
-               for ( ;index < MAX_NOTIFICATION_LINE_LENGTH; index++)
-               {
-                       setInformation("", index);
-                       setSubInformation("", index);
-               }
-       }
+ApplicationId StatusNotification::getAppId() const
+{
+    return m_appId;
 }
 
-void StatusNotification::addLine(const NotificationLinePtr &value)
+void StatusNotification::setAppId(ApplicationId appId)
 {
-       m_lines->push_back(value);
+    m_appId = appId;
 }
-       
-void StatusNotification::clearLines()
+
+std::string StatusNotification::getProgressType() const
 {
-       m_lines->clear();
+    return m_progressType;
 }
 
+void StatusNotification::setProgressType(std::string progressType)
+{
+    m_progressType = progressType;
 }
+
+unsigned long StatusNotification::getProgressValue() const
+{
+    return m_progressValue;
 }
 
+void StatusNotification::setProgressValue(unsigned long progressValue)
+{
+    m_progressValue = progressValue;
+}
+#endif
+
+} // Notification
+} // DeviceAPI
index 6fcafa4..cd246bb 100755 (executable)
 // limitations under the License.
 //
 
+#ifndef __TIZEN_STATUS_NOTIFICATION_H__
+#define __TIZEN_STATUS_NOTIFICATION_H__
 
-#ifndef TIZENAPIS_PLATFORM_NOTIFICATION_H_
-#define TIZENAPIS_PLATFORM_NOTIFICATION_H_
+#include <MultiCallbackUserData.h>
 
-#include "NotificationFactory.h"
-#include "INotification.h"
 #include <app.h>
 #include <notification.h>
 
+#include <JSApplicationControl.h>
+#include "NotificationTypes.h"
+#include "NotificationDetailInfo.h"
+
+using namespace DeviceAPI::Common;
+
 namespace DeviceAPI {
 namespace Notification {
 
-class StatusNotification : INotification
+class StatusNotification
 {
-public:
-       friend class NotificationFactory;
 
+public:
+       StatusNotification(NotificationType type);              //type.
+       StatusNotification(void* noti);                                 // notification 
+       StatusNotification(int privID);                         //private ID of Notification.
+       
        ~StatusNotification();
-       // notification
-
+       
+        NotificationProgressType getProgressType()
+        {
+               return m_progressType;
+        }
+
+       std::string getEnumProgressType();
+        
+        void setProgressType( NotificationProgressType type)
+        {
+               m_progressType = type;
+        }
+        void setUpdatedFlag(bool value)
+        {
+             if (value)
+               LogDebug("set True");
+             m_notiUpdated = value;
+        }
+        
+        bool getUpdatedFlag()
+        {
+             return m_notiUpdated;
+        }
+
+       NotificationType getNotiType()
+       {
+               return m_notiType;
+       }
+
+       void setNotiType(NotificationType type)
+       {
+               m_notiType = type;
+       }
+       
        int getID();
+       std::string getStatusType();
+       void setStatusType(std::string type);
+       
        time_t getPostedTime();
        std::string getTitle();
        void setTitle(std::string title);
@@ -56,7 +99,8 @@ public:
        
        std::string getSubIconPath() ;
        void setSubIconPath(const std::string& subIconPath) ;
-       
+
+#if 0  
        std::vector<std::string> getInformations() ;
        std::string getInformation(int index)  ;
        void setInformations(std::vector<std::string>& infos) ;
@@ -66,15 +110,11 @@ public:
        std::string getSubInformation(int index)  ;
        void setSubInformations(std::vector<std::string>& infos) ;
        void setSubInformation( const std::string& info, int index) ;
+#endif
 
-       //std::vector<std::string> getThumbnails() ;
-       std::string getThumbnail(int index) ;
-       void setThumbnails(std::vector<std::string>& thumbs) ;
-       void setThumbnail( const std::string& info, int index) ;
-
-       void setThumbnails(const StringArrayPtr &value);
-       StringArrayPtr getThumbnails();
-               
+       std::vector<std::string> getThumbnails();
+       void setThumbnails(std::vector<std::string> thumbs);
+       
        std::string getBackground() ;
        void setBackground(const std::string imagePath) ;
        
@@ -90,37 +130,106 @@ public:
 
        void* getNotificationHandle();
        void setNotificationHandle(void *handle);
-       void setNotificationLines();
 
        service_h getService();
 
-       //Line
-       NotificationLineArrayPtr getLines() const;
-       int getLinesNum() const;
-       void setLines(const NotificationLineArrayPtr &value);
-       void addLine(const NotificationLinePtr &value);
-       void clearLines();
+       //Detail Info
+       std::vector<NotificationDetailInfo*> getDetailInfos() const;
+       void setDetailInfos(const std::vector<NotificationDetailInfo*> value);
+       int getDetailInfosNum() const;
+       void addDetailInfo(NotificationDetailInfo* value);
+       void clearDetailInfos();
 
-protected:
-       StatusNotification(NotificationType type);
-       StatusNotification(void* noti);
-       StatusNotification(int privID); 
+private:
                
-       service_h m_service;
-       notification_h m_notiHandle;
-       StringArrayPtr m_thumbs;
+       void loadThumbnails();
+       void setThumbnail( const std::string& info, int index);
+       std::string getThumbnail(int index);
+
+       std::string getInformation(int index)  ;
+       void setInformation( const std::string& info, int index) ;
+
+       std::string getSubInformation(int index)  ;
+       void setSubInformation( const std::string& info, int index) ;   
        
+       void loadDetailInfos();
+               
+protected:
+
+       //NotificationType m_notiType;
        NotificationType m_notiType;
-       NotificationLineArrayPtr m_lines;
-       
-private:
+       service_h m_service;
+       notification_h m_notiHandle;
+       NotificationProgressType m_progressType;
+       bool m_notiUpdated;
        
-};
+       std::vector<std::string> m_thumbs;                              //thumbnail images path
+       std::vector<NotificationDetailInfo*> m_detailInfos;   // detail Info
+
+#if 0
+public:
+    StatusNotification();
+    virtual ~StatusNotification();
+
+    std::string getStatusType() const;
+    void setStatusType(std::string statusType);
+
+    std::string getIconPath() const;
+    void setIconPath(std::string iconPath);
+
+    std::string getSubIconPath() const;
+    void setSubIconPath(std::string subIconPath);
 
+    long getNumber() const;
+    void setNumber(long number);
 
-}
-}
+    std::vector<NotificationDetailInfo*> getDetailInfo() const;
+    void setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo);
 
-#endif 
+    std::string getBackgroundImagePath() const;
+    void setBackgroundImagePath(std::string backgroundImagePath);
+
+    std::vector<std::string> getThumbnails() const;
+    void setThumbnails(std::vector<std::string> thumbnails);
+
+    std::string getSoundPath() const;
+    void setSoundPath(std::string soundPath);
+
+    bool getVibration() const;
+    void setVibration(bool vibration);
+
+    ApplicationControl getAppControl() const;
+    void setAppControl(ApplicationControl appControl);
+
+    ApplicationId getAppId() const;
+    void setAppId(ApplicationId appId);
+
+    std::string getProgressType() const;
+    void setProgressType(std::string progressType);
+
+    unsigned long getProgressValue() const;
+    void setProgressValue(unsigned long progressValue);
+
+private:
+    std::string m_statusType;
+    std::string m_iconPath;
+    std::string m_subIconPath;
+    long m_number;
+    std::vector<NotificationDetailInfo*> m_detailInfo;
+    std::string m_backgroundImagePath;
+    std::vector<std::string> m_thumbnails;
+    std::string m_soundPath;
+    bool m_vibration;
+    ApplicationControl m_appControl;
+    ApplicationId m_appId;
+    std::string m_progressType;
+    unsigned long m_progressValue;
+
+#endif
+       
+};
 
+} // Notification
+} // DeviceAPI
 
+#endif // __TIZEN_STATUS_NOTIFICATION_H__
\ No newline at end of file
index 48e59ab..ed780b9 100644 (file)
@@ -1,21 +1,15 @@
 <?xml version="1.0" ?>
 <!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
 <plugin-properties>
-       <library-name>libwrt-plugins-tizen-notification.so</library-name>
-       <feature-install-uri>notification.install.uri</feature-install-uri>
-       <feature-key-cn>SAMSUNG plugin group</feature-key-cn>
-       <feature-root-cn>SAMSUNG certificate authority</feature-root-cn>
-       <feature-root-fingerprint>AAAABBBBCCCCDDDEEEE0000</feature-root-fingerprint>
-       <api-feature>
-               <name>http://tizen.org/privilege/notification.read</name>
-       </api-feature>
-       <api-feature>
-               <name>http://tizen.org/privilege/notification.write</name>
-               <device-capability>notification</device-capability>
-       </api-feature>
-       <api-feature>
-               <name>http://tizen.org/privilege/notification</name>
-               <device-capability>notification</device-capability>
-       </api-feature>
-</plugin-properties>
+    <library-name>libwrt-plugins-tizen-notification.so</library-name>
+    <feature-install-uri>notification.install.uri</feature-install-uri>
+    <feature-key-cn>SAMSUNG plugin group</feature-key-cn>
+    <feature-root-cn>SAMSUNG certificate authority</feature-root-cn>
+    <feature-root-fingerprint>AAAABBBBCCCCDDDEEEE0000</feature-root-fingerprint>
 
+    <api-feature>
+        <name>http://tizen.org/privilege/notification</name>
+        <device-capability>notification</device-capability>
+    </api-feature>
+
+</plugin-properties>
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 73b4821..c2ac383
 //
 
 
-#include <map>
-#include <utility>
 #include <Commons/FunctionDefinition.h>
 #include <Commons/FunctionDeclaration.h>
 #include <Commons/Exception.h>
-#include "plugin_config.h"
+#include <map>
 
-#define NOTIFICATION_FEATURE_API "http://tizen.org/privilege/notification"
-#define NOTIFICATION_FEATURE_API_WRITE "http://tizen.org/privilege/notification.write"
+#include "plugin_config.h"
 
-#define NOTIFICATION_DEVICE_CAP "notification"
+using namespace WrtDeviceApis::Commons;
 
 namespace DeviceAPI {
 namespace Notification {
 
-static WrtDeviceApis::Commons::FunctionMapping createNotificationFunctions();
-
-static WrtDeviceApis::Commons::FunctionMapping NotificationFunctions = createNotificationFunctions();
+#define NOTIFICATION_DEVICE_CAP "notification"
+#define NOTIFICATION_FEATURE_API "http://tizen.org/privilege/notification"
+#define NOTIFICATION_FEATURE_API_WRITE "http://tizen.org/privilege/notification.write"
 
-const char *NOTIFICATION_FUNC = "Notification";
+static FunctionMapping createNotificationFunctions();
+static FunctionMapping NotificationFunctions = createNotificationFunctions();
 
 DEFINE_FUNCTION_GETTER(Notification, NotificationFunctions);
 
-static WrtDeviceApis::Commons::FunctionMapping createNotificationFunctions()
+static FunctionMapping createNotificationFunctions()
 {
-       using namespace WrtDeviceApis::Commons;
-       /**     
-       * Device capabilities
-       */
-       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NOTIFICATION, NOTIFICATION_DEVICE_CAP);
-
-       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NOTIFICATION);
-       ACE_ADD_DEVICE_CAP(DEVICE_LIST_NOTIFICATION, DEVICE_CAP_NOTIFICATION);
-
-       /**
-       * Api Features
-       */
-       ACE_CREATE_FEATURE(NOTIFICATION_FEATURE_WRITE, NOTIFICATION_FEATURE_API_WRITE);
-       ACE_CREATE_FEATURE_LIST(NOTIFICATION_FEATURES_WRITE);
-       ACE_ADD_API_FEATURE(NOTIFICATION_FEATURES_WRITE, NOTIFICATION_FEATURE_WRITE);
-
-       ACE_CREATE_FEATURE(NOTIFICATION_FEATURE, NOTIFICATION_FEATURE_API);
-       ACE_CREATE_FEATURE_LIST(NOTIFICATION_FEATURES);
-       ACE_ADD_API_FEATURE(NOTIFICATION_FEATURES, NOTIFICATION_FEATURE_WRITE);
-       ACE_ADD_API_FEATURE(NOTIFICATION_FEATURES, NOTIFICATION_FEATURE);
-
-       FunctionMapping NotificationFunctions;
-       
-       AceFunction NotificationWrite = ACE_CREATE_FUNCTION(FUNCTION_NOTIFICATION_WRITE, NOTIFICATION_FUNC, 
-               NOTIFICATION_FEATURES, DEVICE_LIST_NOTIFICATION);
-
-       //AceFunction NotificationWrite = ACE_CREATE_FUNCTION(FUNCTION_NOTIFICATION_WRITE, NOTIFICATION_FUNC_WRITE, 
-       //              NOTIFICATION_FEATURES_WRITE, DEVICE_LIST_NOTIFICATION);
-       NotificationFunctions.insert(std::make_pair(NOTIFICATION_FUNC, NotificationWrite));
-
-       return NotificationFunctions;
-}
-} 
+    FunctionMapping pushMapping;
+
+    /**        
+    * Device capabilities
+    */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NOTIFICATION, NOTIFICATION_DEVICE_CAP);
+    
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NOTIFICATION);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_NOTIFICATION, DEVICE_CAP_NOTIFICATION);
+    
+    /**
+    * Api Features
+    */
+    ACE_CREATE_FEATURE(NOTIFICATION_FEATURE_WRITE, NOTIFICATION_FEATURE_API_WRITE);
+    ACE_CREATE_FEATURE_LIST(NOTIFICATION_FEATURES_WRITE);
+    ACE_ADD_API_FEATURE(NOTIFICATION_FEATURES_WRITE, NOTIFICATION_FEATURE_WRITE);
+    
+    ACE_CREATE_FEATURE(NOTIFICATION_FEATURE, NOTIFICATION_FEATURE_API);
+    ACE_CREATE_FEATURE_LIST(NOTIFICATION_FEATURES);
+    ACE_ADD_API_FEATURE(NOTIFICATION_FEATURES, NOTIFICATION_FEATURE_WRITE);
+    ACE_ADD_API_FEATURE(NOTIFICATION_FEATURES, NOTIFICATION_FEATURE);
+
+       
+    AceFunction NotificationWrite = ACE_CREATE_FUNCTION(FUNCTION_NOTIFICATION_WRITE, NOTIFICATION_FUNC, 
+       NOTIFICATION_FEATURES, DEVICE_LIST_NOTIFICATION);
+    
+    pushMapping.insert(std::make_pair(NOTIFICATION_FUNC, NotificationWrite));
+
+    return pushMapping;
 }
 
-#undef NOTIFICATION_FEATURE_API 
-#undef NOTIFICATION_FEATURE_API_WRITE 
-#undef NOTIFICATION_DEVICE_CAP
+} // Notification
+} // DeviceAPI
old mode 100644 (file)
new mode 100755 (executable)
index 4ae52b9..71dd44c
 // limitations under the License.
 //
 
-#ifndef TIZENAPIS_TIZEN_JS_NOTIFICATION_PLUGIN_CONFIG_H_
-#define TIZENAPIS_TIZEN_JS_NOTIFICATION_PLUGIN_CONFIG_H_
 
+#ifndef _NOTIFICATION_PLUGIN_CONFIG_H_
+#define _NOTIFICATION_PLUGIN_CONFIG_H_
+
+#include <string>
 #include <Commons/FunctionDeclaration.h>
 
+#include <Logger.h>
+
 namespace DeviceAPI {
 namespace Notification {
 
-extern const char *NOTIFICATION_FUNC;
+// attributes
+#define NOTIFICATION_ID "id"
+#define NOTIFICATION_TYPE "type"
+#define NOTIFICATION_POSTED_TIME "postedTime"
+#define NOTIFICATION_TITLE "title"
+#define NOTIFICATION_CONTENT "content"
+#define STATUS_NOTIFICATION_STATUS_TYPE "statusType"
+#define STATUS_NOTIFICATION_ICON_PATH "iconPath"
+#define STATUS_NOTIFICATION_SUB_ICON_PATH "subIconPath"
+#define STATUS_NOTIFICATION_NUMBER "number"
+#define STATUS_NOTIFICATION_DETAIL_INFO "detailInfo"
+#define STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH "backgroundImagePath"
+#define STATUS_NOTIFICATION_THUMBNAILS "thumbnails"
+#define STATUS_NOTIFICATION_SOUND_PATH "soundPath"
+#define STATUS_NOTIFICATION_VIBRATION "vibration"
+#define STATUS_NOTIFICATION_APP_CONTROL "appControl"
+#define STATUS_NOTIFICATION_APP_ID "appId"
+#define STATUS_NOTIFICATION_PROGRESS_TYPE "progressType"
+#define STATUS_NOTIFICATION_PROGRESS_VALUE "progressValue"
+#define NOTIFICATION_DETAIL_INFO_MAIN_TEXT "mainText"
+#define NOTIFICATION_DETAIL_INFO_SUB_TEXT "subText"
+
+// functions
+#define NOTIFICATION_MANAGER_API_POST "post"
+#define NOTIFICATION_MANAGER_API_UPDATE "update"
+#define NOTIFICATION_MANAGER_API_REMOVE "remove"
+#define NOTIFICATION_MANAGER_API_REMOVE_ALL "removeAll"
+#define NOTIFICATION_MANAGER_API_GET "get"
+#define NOTIFICATION_MANAGER_API_GET_ALL "getAll"
+
+#define NOTIFICATION_FUNC "Notification"
 
 DECLARE_FUNCTION_GETTER(Notification);
 
-#define NOTIFICATION_CHECK_ACCESS(functionName)                       \
-    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
-        getNotificationFunctionData,             \
-        functionName)
+#define NOTIFICATION_CHECK_ACCESS(functionName) \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \
+    getNotificationFunctionData, \
+    functionName)
+
 }
 }
 
-#endif 
+#endif // _NOTIFICATION_PLUGIN_CONFIG_H_
\ No newline at end of file
index 585b13d..9a92317 100755 (executable)
 // limitations under the License.
 //
 
+
 #include <Commons/plugin_initializer_def.h>
 #include <Commons/WrtAccess/WrtAccess.h>
 
+#include <Logger.h>
+#include <GlobalContextManager.h>
+
 #include "JSNotificationManager.h"
 #include "JSStatusNotification.h"
-#include "JSNotificationLine.h"
-#include "Logger.h"
+#include "JSNotificationDetailInfo.h"
 
 using namespace WrtDeviceApis;
 using namespace WrtDeviceApis::Commons;
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Notification {
+
+class_definition_options_t ConstructorClassOptions =
+{
+    JS_INTERFACE,
+    CREATE_INSTANCE,
+    NONE_NOTICE,
+    USE_OVERLAYED, //ignored
+    NULL,
+    NULL,
+    NULL
+};
 
 void on_widget_start_callback(int widgetId)
 {
-       LogDebug("[Tizen\\Notification ] on_widget_start_callback ("<<widgetId<<")");
-       Try
-       {
+    LogDebug("[Tizen\\Notification] on_widget_start_callback (%d)" << widgetId);
+    try {
         WrtAccessSingleton::Instance().initialize(widgetId);
-       }
-       Catch(Commons::Exception)
-       {
-               LogError("WrtAccess initialization failed");
-       }
+    } catch (...) {
+        LogError("WrtAccess initialization failed");
+    }
 }
 
 void on_widget_stop_callback(int widgetId)
 {
-       LogDebug("[Tizen\\Notification] on_widget_stop_callback ("<<widgetId<<")");
-       Try
-       {
+    LogDebug("[Tizen\\Notification] on_widget_stop_callback (%d)" << widgetId);
+    try {
         WrtAccessSingleton::Instance().deinitialize(widgetId);
-       }
-       Catch(Commons::Exception)
-       {
-               LogError("WrtAccess deinitialization failed");
-       }
+    } catch (...) {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\Notification] on_frame_load_callback (%p)" << context);
+    GlobalContextManager::getInstance()->addGlobalContext(static_cast<JSContextRef>(context));
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\Notification] on_frame_unload_callback (%p)" << context);
+    GlobalContextManager::getInstance()->removeGlobalContext(static_cast<JSContextRef>(context));
 }
 
 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
-
-#define UI_NOTIFICATION "notification"
-#define UI_NOTIFICATION_SIMPLE "StatusNotification"
-#define UI_NOTIFICATION_LINE "NotificationDetailInfo"
+PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
+PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
 
 PLUGIN_CLASS_MAP_BEGIN
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, UI_NOTIFICATION,
-      (js_class_template_getter)DeviceAPI::Notification::JSNotificationManager::getClassRef,NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, UI_NOTIFICATION_SIMPLE,
-                 (js_class_template_getter)DeviceAPI::Notification::JSStatusNotification::getClassRef,NULL)
-PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, UI_NOTIFICATION_LINE,
-                 (js_class_template_getter)DeviceAPI::Notification::JSNotificationLine::getClassRef,NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "notification",
+        (js_class_template_getter)JSNotificationManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "StatusNotification",
+        (js_class_template_getter)JSStatusNotification::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(JSStatusNotification::constructor),
+        &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "NotificationDetailInfo",
+        (js_class_template_getter)JSNotificationDetailInfo::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(JSNotificationDetailInfo::constructor),
+        &ConstructorClassOptions)
 PLUGIN_CLASS_MAP_END
 
+} // Notification
+} // DeviceAPI
index 8c5f4bc..29859c2 100644 (file)
 // limitations under the License.
 //
 
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include <SecurityExceptions.h>
+#include <JSWebAPIException.h>
 
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/Utils.h>
+#include <JSUtil.h>
 
 #include <dlog.h>
 
@@ -59,16 +58,16 @@ JSClassDefinition JSPackageInformation::m_classInfo = {
 };
 
 JSStaticValue JSPackageInformation::m_property[] = {
-    { TIZEN_PACKAGE_INFORMATION_ID, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-    { TIZEN_PACKAGE_INFORMATION_NAME, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-    { TIZEN_PACKAGE_INFORMATION_ICONPATH, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-    { TIZEN_PACKAGE_INFORMATION_VERSION, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-       { TIZEN_PACKAGE_INFORMATION_TOTAL_SIZE, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-       { TIZEN_PACKAGE_INFORMATION_DATA_SIZE, getProperty, setProperty, kJSPropertyAttributeReadOnly },        
-       { TIZEN_PACKAGE_INFORMATION_LAST_MODIFIED, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-       { TIZEN_PACKAGE_INFORMATION_AUTHOR, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-       { TIZEN_PACKAGE_INFORMATION_DESCRIPTION, getProperty, setProperty, kJSPropertyAttributeReadOnly },
-       { TIZEN_PACKAGE_INFORMATION_APP_IDS, getProperty, setProperty, kJSPropertyAttributeReadOnly },
+    { TIZEN_PACKAGE_INFORMATION_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_PACKAGE_INFORMATION_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_PACKAGE_INFORMATION_ICONPATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_PACKAGE_INFORMATION_VERSION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_PACKAGE_INFORMATION_TOTAL_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_PACKAGE_INFORMATION_DATA_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },       
+       { TIZEN_PACKAGE_INFORMATION_LAST_MODIFIED, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_PACKAGE_INFORMATION_AUTHOR, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_PACKAGE_INFORMATION_DESCRIPTION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_PACKAGE_INFORMATION_APP_IDS, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { 0, 0, 0, 0 }
 };
 
@@ -82,40 +81,6 @@ JSClassRef JSPackageInformation::getClassRef() {
        return m_classRef;
 }
 
-#if 0
-JSValueRef JSPackageInformation::createJSObject(JSContextRef context,
-               const string &id,
-               const string &name,
-               const string &iconPath,
-               const string &version,
-               const long &totalSize,
-               const long &dataSize,
-               const time_t &lastModified,
-               const string &description,
-               const string &author,
-               const vector<string> &appIds);
-{
-       PackageInformation *priv = new PackageInformation();
-       priv->m_id = id;
-       priv->m_name = name;
-       priv->m_iconPath = iconPath;
-       priv->m_version = version;
-       priv->m_totalSize = totalSize;
-       priv->m_dataSize = dataSize;
-       priv->m_lastModified = lastModified;
-       priv->m_description = description;
-       priv->m_author = author;
-       priv->m_appIds = appIds;
-       
-       JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsValueRef) {
-               LogError("object creation error");
-               return JSValueMakeUndefined(context);
-       }
-       
-       return jsValueRef;
-}
-#endif
 
 JSValueRef JSPackageInformation::createJSObject(JSContextRef context, PackageInformation *pkgInfo)
 {
@@ -149,7 +114,7 @@ PackageInformation* JSPackageInformation::getPrivData(JSObjectRef object)
 {
        PackageInformation *priv = static_cast<PackageInformation*>(JSObjectGetPrivate(object));
        if (!priv) {
-               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+               throw TypeMismatchException("Private object is null");
        }
 
        return priv;
@@ -160,54 +125,43 @@ JSValueRef JSPackageInformation::getProperty(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       Try     {
-               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+       try {
+               //WrtDeviceApis::CommonsJavaScript::Converter converter(context);
                PackageInformation* privateData = getPrivData(object);
+        if (!privateData) {
+            throw TypeMismatchException("Private object is NULL");
+        }              
        
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_ID)) {
-                       return converter.toJSValueRef(privateData->m_id);
+                       return JSUtil::toJSValueRef(context, privateData->m_id);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_NAME)) {
-                       return converter.toJSValueRef(privateData->m_name);
+                       return JSUtil::toJSValueRef(context, privateData->m_name);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_ICONPATH)) {
-                       return converter.toJSValueRef(privateData->m_iconPath);
+                       return JSUtil::toJSValueRef(context, privateData->m_iconPath);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_VERSION)) {
-                       return converter.toJSValueRef(privateData->m_version);
+                       return JSUtil::toJSValueRef(context, privateData->m_version);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_TOTAL_SIZE)) {
-                       return converter.toJSValueRefLong(privateData->m_totalSize);
+                       return JSUtil::toJSValueRef(context, privateData->m_totalSize);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_DATA_SIZE)) {
-                       return converter.toJSValueRefLong(privateData->m_dataSize);
+                       return JSUtil::toJSValueRef(context, privateData->m_dataSize);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_LAST_MODIFIED)) {
-                       return converter.toJSValueRef(privateData->m_lastModified);
+                       return JSUtil::makeDateObject(context, privateData->m_lastModified);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_AUTHOR)) {
-                       return converter.toJSValueRef(privateData->m_author);
+                       return JSUtil::toJSValueRef(context, privateData->m_author);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_DESCRIPTION)) {
-                       return converter.toJSValueRef(privateData->m_description);
+                       return JSUtil::toJSValueRef(context, privateData->m_description);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_APP_IDS)) {
-                       return converter.toJSValueRef(privateData->m_appIds);
+                       return JSUtil::toJSValueRef(context, privateData->m_appIds);
                }
-#if 0
-       // type is defined to partner feature on native
-       else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_TYPE)) {
-                               return converter.toJSValueRef(privateData->m_type);
-                       } 
-#endif
-
-       } Catch(WrtDeviceApis::Commons::Exception) {
-        LogError("Exception: " << _rethrown_exception.GetMessage());
-               JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+        return JSWebAPIException::throwException(context, exception, err);
     }
        
        return JSValueMakeUndefined(context);
 }
 
-bool JSPackageInformation::setProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef value,
-               JSValueRef* exception)
-{
-       return JSValueMakeUndefined(context);
-}
-
 }
 }
index 17c6873..1869d28 100644 (file)
@@ -104,14 +104,6 @@ private:
                        JSStringRef propertyName,
                        JSValueRef* exception);
 
-       static bool setProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef value,
-                       JSValueRef* exception);
-
-
-
 };
 
 }
index cda183e..e6758e1 100644 (file)
 
 #include <ArgumentValidator.h>
 #include <PlatformException.h>
-#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 
 #include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/Utils.h>
+//#include <CommonsJavaScript/JSUtils.h>
+//#include <CommonsJavaScript/Utils.h>
 
+#include <JSUtil.h>
 #include <GlobalContextManager.h>
 #include <dlog.h>
 
@@ -121,35 +122,24 @@ JSValueRef JSPackageManager::install(JSContextRef context,
                ArgumentValidator validator(context, argumentCount, arguments);
                
                string path = validator.toString(0);
-               JSObjectRef eventCBObj = validator.toObject(1, true);
-               JSObjectRef errCB = validator.toFunction(2, true);
 
-               JSValueRef onprogress = JSUtils::getJSPropertyOrUndefined(context, eventCBObj, "onprogress");
-               JSValueRef oncomplete = JSUtils::getJSPropertyOrUndefined(context, eventCBObj, "oncomplete");
+               JSObjectRef eventCBObj = validator.toCallbackObject(1, true, "onprogress", "oncomplete", NULL);
+               JSObjectRef errCB = validator.toFunction(2, true);
 
                CallbackUserData *onprogressCb = NULL;
                CallbackUserData *oncompleteCb = NULL;
                CallbackUserData *onerrorCb = NULL;
-
-               Converter converter(context);
-               if (JSValueIsNull(context, onprogress) || JSValueIsUndefined(context, onprogress)) {
-                       LogDebug("onprogress is not defined");
-               } else if (JSObjectIsFunction(context, converter.toJSObjectRef(onprogress))) {
+               
+               JSValueRef onprogress = JSUtil::getProperty(context, eventCBObj, "onprogress", exception);
+               if (!JSValueIsUndefined(context, onprogress)) {
                        onprogressCb = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-                       onprogressCb->setSuccessCallback(onprogress);
-               } else {
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "onprogress is not function");
+                       onprogressCb->setSuccessCallback(onprogress);                   
                }
 
-               if (JSValueIsNull(context, oncomplete) || JSValueIsUndefined(context, oncomplete)) {
-                       LogDebug("oncomplete is not defined");
-               } else if (JSObjectIsFunction(context, converter.toJSObjectRef(oncomplete))) {
+               JSValueRef oncomplete = JSUtil::getProperty(context, eventCBObj, "oncomplete", exception);
+               if (!JSValueIsUndefined(context, oncomplete)) {
                        oncompleteCb = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-                       oncompleteCb->setSuccessCallback(oncomplete);
-               } else {
-                       if (onprogressCb)
-                               delete onprogressCb;
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "oncomplete is not function");
+                       oncompleteCb->setSuccessCallback(oncomplete);                   
                }
 
                if (errCB) {
@@ -159,20 +149,16 @@ JSValueRef JSPackageManager::install(JSContextRef context,
 
                PackageInstallEventCallback *pkgInstallEventCB = new PackageInstallEventCallback(GlobalContextManager::getInstance()->getGlobalContext(context), onprogressCb, oncompleteCb, onerrorCb);
                
-               PackageManager::getInstance()->install(path, pkgInstallEventCB);                
-       } catch (const TypeMismatchException& err ) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const UnknownException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const BasePlatformException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const ConversionException& err) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
-       } catch(const NullPointerException& err) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
-       }
+               PackageManager::getInstance()->install(path, pkgInstallEventCB);
 
-       return JSValueMakeUndefined(context);
+               return JSValueMakeUndefined(context);
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
@@ -192,35 +178,24 @@ JSValueRef JSPackageManager::uninstall(JSContextRef context,
                ArgumentValidator validator(context, argumentCount, arguments);
                
                string id = validator.toString(0);
-               JSObjectRef eventCBObj = validator.toObject(1, true);
+               //JSObjectRef eventCBObj = validator.toObject(1, true);
+               JSObjectRef eventCBObj = validator.toCallbackObject(1, true, "onprogress", "oncomplete", NULL);
                JSObjectRef errCB = validator.toFunction(2, true);
-       
-               JSValueRef onprogress = JSUtils::getJSPropertyOrUndefined(context, eventCBObj, "onprogress");
-               JSValueRef oncomplete = JSUtils::getJSPropertyOrUndefined(context, eventCBObj, "oncomplete");
 
                CallbackUserData *onprogressCb = NULL;
                CallbackUserData *oncompleteCb = NULL;
-               CallbackUserData *onerrorCb = NULL;
+               CallbackUserData *onerrorCb = NULL;     
 
-               Converter converter(context);
-               if (JSValueIsNull(context, onprogress) || JSValueIsUndefined(context, onprogress)) {
-                       LogDebug("onprogress is not defined");
-               } else if (JSObjectIsFunction(context, converter.toJSObjectRef(onprogress))) {
+               JSValueRef onprogress = JSUtil::getProperty(context, eventCBObj, "onprogress", exception);
+               if (!JSValueIsUndefined(context, onprogress)) {
                        onprogressCb = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-                       onprogressCb->setSuccessCallback(onprogress);
-               } else {
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "onprogress is not function");
+                       onprogressCb->setSuccessCallback(onprogress);                   
                }
 
-               if (JSValueIsNull(context, oncomplete) || JSValueIsUndefined(context, oncomplete)) {
-                       LogDebug("oncomplete is not defined");
-               } else if (JSObjectIsFunction(context, converter.toJSObjectRef(oncomplete))) {
+               JSValueRef oncomplete = JSUtil::getProperty(context, eventCBObj, "oncomplete", exception);
+               if (!JSValueIsUndefined(context, oncomplete)) {
                        oncompleteCb = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-                       oncompleteCb->setSuccessCallback(oncomplete);
-               } else {
-                       if (onprogressCb)
-                               delete onprogressCb;
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "oncomplete is not function");
+                       oncompleteCb->setSuccessCallback(oncomplete);                   
                }
 
                if (errCB) {
@@ -230,20 +205,16 @@ JSValueRef JSPackageManager::uninstall(JSContextRef context,
 
                PackageInstallEventCallback *pkgInstallEventCB = new PackageInstallEventCallback(GlobalContextManager::getInstance()->getGlobalContext(context), onprogressCb, oncompleteCb, onerrorCb);
 
-               PackageManager::getInstance()->uninstall(id, pkgInstallEventCB);                
-       } catch (const TypeMismatchException& err ) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const UnknownException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const BasePlatformException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const ConversionException& err) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
-       } catch(const NullPointerException& err) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
-       }
+               PackageManager::getInstance()->uninstall(id, pkgInstallEventCB);
 
-       return JSValueMakeUndefined(context);
+               return JSValueMakeUndefined(context);
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
@@ -271,13 +242,15 @@ JSValueRef JSPackageManager::getPackagesInfo(JSContextRef context,
                }
 
                PackageManager::getInstance()->getPackagesInfo(callback);
-       } catch (const TypeMismatchException& err ) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const BasePlatformException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       }
-       
-       return JSValueMakeUndefined(context);
+
+               return JSValueMakeUndefined(context);
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 JSValueRef JSPackageManager::getPackageInfo(JSContextRef context, 
@@ -300,13 +273,13 @@ JSValueRef JSPackageManager::getPackageInfo(JSContextRef context,
                PackageInformation* pkgInfo = PackageManager::getInstance()->getPackageInfo(id);
 
                return JSPackageInformation::createJSObject(context, pkgInfo);
-       } catch (const NotFoundException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch (const TypeMismatchException& err ) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const BasePlatformException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       }
+
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 
@@ -325,67 +298,42 @@ JSValueRef JSPackageManager::setPackageInfoEventListener(JSContextRef context,
        try {
                ArgumentValidator validator(context, argumentCount, arguments);
 
-               JSObjectRef eventCBObj = validator.toObject(0);
-               JSValueRef oninstalled = JSUtils::getJSPropertyOrUndefined(context, eventCBObj, "oninstalled");
-               JSValueRef onupdated = JSUtils::getJSPropertyOrUndefined(context, eventCBObj, "onupdated");
-               JSValueRef onuninstalled = JSUtils::getJSPropertyOrUndefined(context, eventCBObj, "onuninstalled");
+               JSObjectRef eventCBObj = validator.toCallbackObject(0, false, "oninstalled", "onupdated", "onuninstalled", NULL);
 
                CallbackUserData *oninstalledCb = NULL;
                CallbackUserData *onupdatedCb = NULL;
                CallbackUserData *onuninstalledCb = NULL;
 
-               Converter converter(context);
-               if (JSValueIsNull(context, oninstalled) || JSValueIsUndefined(context, oninstalled)) {
-                       LogDebug("oninstalled is not defined");
-               } else if (JSObjectIsFunction(context, converter.toJSObjectRef(oninstalled))) {
+               JSValueRef oninstalled = JSUtil::getProperty(context, eventCBObj, "oninstalled", exception);
+               if (!JSValueIsUndefined(context, oninstalled)) {
                        oninstalledCb = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-                       oninstalledCb->setSuccessCallback(oninstalled);
-               } else {
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "oninstalled is not function");
+                       oninstalledCb->setSuccessCallback(oninstalled);                 
                }
                
-               if (JSValueIsNull(context, onupdated) || JSValueIsUndefined(context, onupdated)) {
-                       LogDebug("onupdated is not defined");
-               } else if (JSObjectIsFunction(context, converter.toJSObjectRef(onupdated))) {
+               JSValueRef onupdated = JSUtil::getProperty(context, eventCBObj, "onupdated", exception);
+               if (!JSValueIsUndefined(context, onupdated)) {
                        onupdatedCb = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-                       onupdatedCb->setSuccessCallback(onupdated);
-               } else {
-                       if (oninstalledCb)
-                               delete oninstalledCb;
-
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "onupdated is not function");
+                       onupdatedCb->setSuccessCallback(onupdated);             
                }
-
-               if (JSValueIsNull(context, onuninstalled) || JSValueIsUndefined(context, onuninstalled)) {
-                       LogDebug("onuninstalled is not defined");
-               } else if (JSObjectIsFunction(context, converter.toJSObjectRef(onuninstalled))) {
+               
+               JSValueRef onuninstalled = JSUtil::getProperty(context, eventCBObj, "onuninstalled", exception);
+               if (!JSValueIsUndefined(context, onuninstalled)) {
                        onuninstalledCb = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
                        onuninstalledCb->setSuccessCallback(onuninstalled);
-               } else {
-                       if (oninstalledCb)
-                               delete oninstalledCb;
-                       if (onupdatedCb)
-                               delete onupdatedCb;
-       
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "onuninstalled is not function");
                }
 
                PackageInfoEventCallback *pkginfoEventCB = new PackageInfoEventCallback(oninstalledCb, onupdatedCb, onuninstalledCb);
 
                PackageManager::getInstance()->setPackageInfoEventListener(pkginfoEventCB);
-       } catch (const TypeMismatchException& err ) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const UnknownException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const BasePlatformException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
-       } catch(const ConversionException& err) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
-       } catch(const NullPointerException& err) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
-       }
 
-       return JSValueMakeUndefined(context);
+               return JSValueMakeUndefined(context);
+               
+       } catch (const BasePlatformException &err) {
+        return JSWebAPIException::throwException(context, exception, err);
+    } catch (...) {
+        DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 }
 
 JSValueRef JSPackageManager::unsetPackageInfoEventListener(JSContextRef context,
@@ -402,11 +350,11 @@ JSValueRef JSPackageManager::unsetPackageInfoEventListener(JSContextRef context,
 
        try {
                PackageManager::getInstance()->unsetPackageInfoEventListener();
+               return JSValueMakeUndefined(context);
+
        } catch(const BasePlatformException& err) {
-               return JSWebAPIError::throwException(context, exception, err);
+               return JSWebAPIException::throwException(context, exception, err);
        }
-
-       return JSValueMakeUndefined(context);   
 }
 
 
index 5cb5fca..f58f477 100644 (file)
@@ -246,28 +246,28 @@ static PackageInformation* create_pkg_info(pkgmgrinfo_pkginfo_h handle)
        int ret = 0;
 
        ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &id);
-       if (ret != PMINFO_R_OK) {
+       if ((ret != PMINFO_R_OK) || (id == NULL)) {
                LogDebug("Fail to get id");
        } else {
                pkgInfo->m_id = id;
        }
 
        ret = pkgmgrinfo_pkginfo_get_label(handle, &name);
-       if (ret != PMINFO_R_OK) {
+       if ((ret != PMINFO_R_OK) || (name == NULL)) {
                LogDebug("Fail to get labe");
        } else {
                pkgInfo->m_name = name;
        }
 
        ret = pkgmgrinfo_pkginfo_get_icon(handle, &iconPath);
-       if (ret != PMINFO_R_OK) {
+       if ((ret != PMINFO_R_OK) || (iconPath == NULL)) {
                LogDebug("Fail to get iconPath");
        } else {
                pkgInfo->m_iconPath = iconPath;
        }
 
        ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
-       if (ret != PMINFO_R_OK) {
+       if ((ret != PMINFO_R_OK) || (version == NULL)) {
                LogDebug("Fail to get version");
        } else {
                pkgInfo->m_version = version;
@@ -295,21 +295,21 @@ static PackageInformation* create_pkg_info(pkgmgrinfo_pkginfo_h handle)
        }
 
        ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
-       if (ret != PMINFO_R_OK) {
+       if ((ret != PMINFO_R_OK) || (type == NULL)) {
                LogDebug("Fail to get type");
        } else {
                pkgInfo->m_type = type;
        }
 
        ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author);
-       if (ret != PMINFO_R_OK) {
+       if ((ret != PMINFO_R_OK) || (author == NULL)) {
                LogDebug("Fail to get author");
        } else {
                pkgInfo->m_author = author;
        }
 
        ret = pkgmgrinfo_pkginfo_get_description(handle, &description);
-       if (ret != PMINFO_R_OK) {
+       if ((ret != PMINFO_R_OK) || (description == NULL)) {
                LogDebug("Fail to get description");
        } else {
                pkgInfo->m_description = description;
index e29c868..b1a7fd4 100755 (executable)
@@ -20,7 +20,7 @@
 #include <GlobalContextManager.h>
 #include <Logger.h>
 #include <JSUtil.h>
-#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 #include <ArgumentValidator.h>
 
 #include "JSPowerManager.h"
@@ -121,7 +121,7 @@ JSValueRef JSPowerManager::request(JSContextRef context,
         PowerManager::getInstance()->request( resource , state );
 
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 
     return JSValueMakeUndefined(context);
@@ -144,7 +144,7 @@ JSValueRef JSPowerManager::release(JSContextRef context,
         PowerManager::getInstance()->release( resource );
 
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
     return JSValueMakeUndefined(context);
 }
@@ -170,7 +170,7 @@ JSValueRef JSPowerManager::setScreenStateChangeListener(JSContextRef context,
         PowerManager::getInstance()->addScreenStateChangedCallback(callback);
 
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }catch( const std::bad_alloc& oom){
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Out of memory");
     }
@@ -209,7 +209,7 @@ JSValueRef JSPowerManager::getScreenBrightness(JSContextRef context,
         double brightness = PowerManager::getInstance()->getScreenBrightness();
         return JSUtil::toJSValueRef(context, brightness);
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -230,7 +230,7 @@ JSValueRef JSPowerManager::setScreenBrightness(JSContextRef context,
         LOGE(" value = %f", value);
         PowerManager::getInstance()->setScreenBrightness(value);
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
     return JSValueMakeUndefined(context);
 
@@ -249,7 +249,7 @@ JSValueRef JSPowerManager::isScreenOn(JSContextRef context,
         bool state = PowerManager::getInstance()->isScreenOn();
         return JSUtil::toJSValueRef(context,state);
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -265,7 +265,7 @@ JSValueRef JSPowerManager::restoreScreenBrightness(JSContextRef context,
     try{
         PowerManager::getInstance()->restoreScreenBrightness();
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
     return JSValueMakeUndefined(context);}
 
@@ -283,7 +283,7 @@ JSValueRef JSPowerManager::turnScreenOn(JSContextRef context,
     try{
         PowerManager::getInstance()->setScreenState(true);
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
     return JSValueMakeUndefined(context);
 }
@@ -302,7 +302,7 @@ JSValueRef JSPowerManager::turnScreenOff(JSContextRef context,
     try{
         PowerManager::getInstance()->setScreenState(false);
     }catch(const BasePlatformException& err){
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
     return JSValueMakeUndefined(context);
 }
index 5e7b706..9a690d9 100644 (file)
@@ -18,7 +18,7 @@
 #include <SecurityExceptions.h>
 
 #include <JSUtil.h>
-#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 #include <ArgumentValidator.h>
 #include <GlobalContextManager.h>
 #include <MultiCallbackUserData.h>
@@ -142,11 +142,11 @@ JSValueRef JSPushManager::registerService(JSContextRef context,
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.registerService().");
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -189,11 +189,11 @@ JSValueRef JSPushManager::unregisterService(JSContextRef context,
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.unregisterService().");
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -230,11 +230,11 @@ JSValueRef JSPushManager::connectService(JSContextRef context,
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.connectService().");
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -261,11 +261,11 @@ JSValueRef JSPushManager::disconnectService(JSContextRef context,
         return JSValueMakeUndefined(context);
     } catch (const BasePlatformException &err) {
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.disconnectService().");
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
@@ -295,11 +295,11 @@ JSValueRef JSPushManager::getRegistrationId(JSContextRef context,
         }
     } catch (const BasePlatformException &err) {
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     } catch (...) {
         DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.getRegistrationId().");
         LogError(err.getName() << ": " << err.getMessage());
-        return JSWebAPIError::throwException(context, exception, err);
+        return JSWebAPIException::throwException(context, exception, err);
     }
 }
 
index f2b535b..5880bb0 100644 (file)
@@ -198,8 +198,9 @@ static void push_connection_state_cb(push_state_e state, const char *err, void *
     PushManager *thisPushManager = static_cast<PushManager*>(user_data);
     if (!thisPushManager) {
         LogError("user_data of push_connection_state_cb() is NULL.");
+    } else {
+       thisPushManager->m_connectionState = state;
     }
-    thisPushManager->m_connectionState = state;
 }
 
 static void push_notify_cb(push_notification_h noti, void *user_data)
index c4f9d1b..888b63f 100755 (executable)
@@ -39,7 +39,7 @@ class ISEService :
        virtual                     ~ISEService();
        virtual void getReaders(const EventListSEsPtr& event) = 0;
        virtual void registerSEListener(const EventSEStateChangedEmitterPtr& emitter) = 0;
-       virtual void unregisterSEListener(long id) = 0;
+       virtual void unregisterSEListener(unsigned long id) = 0;
        virtual void shutdown() = 0;
     protected:
        ISEService();
index 23c9c96..14fb8d6 100755 (executable)
@@ -25,6 +25,8 @@
 #include <CommonsJavaScript/Utils.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
 #include <SecurityExceptions.h>
 #include "SEFactory.h"
 #include "SEResponseDispatcher.h"
@@ -98,7 +100,7 @@ JSValueRef JSSEChannel::getProperty(JSContextRef context, JSObjectRef object,
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (NullPointerException) {
                LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -181,7 +183,7 @@ JSValueRef JSSEChannel::close(JSContextRef context,
        Try {
                seChannel->close();
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -209,27 +211,24 @@ JSValueRef JSSEChannel::transmit(JSContextRef context,
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
-       if (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !validator.isCallback(arguments[1])) {
-               /* 2st argument is mandatory. And 2st argument must be Callback. */
-               LogError("ByteArraySuccessCallback TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
-               if (!validator.isCallback(arguments[2])) {
-                       /* 3nd argument must be Callback. */
-                       LogError("ErrorCallback TypeMismatchException!");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               JSObjectRef successCallbackObj = validator.toFunction(1);
+               if (successCallbackObj) {
+                       onSuccessForCbm = arguments[1];
                }
-       }
 
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if (validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
+               JSObjectRef errorCallbackObj = validator.toFunction(2, true);
+               if (errorCallbackObj) {
+                       onErrorForCbm = arguments[2];
+               }
+       } catch (const BasePlatformException &err) {
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
 
        SEChannelPrivObject* privateObject = static_cast<SEChannelPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -254,7 +253,7 @@ JSValueRef JSSEChannel::transmit(JSContextRef context,
        } Catch (ConversionException) {
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index 740e5c1..a360209 100755 (executable)
@@ -27,6 +27,8 @@
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
 #include "SEFactory.h"
 #include "SEResponseDispatcher.h"
 #include "JSSEReader.h"
@@ -102,7 +104,7 @@ JSValueRef JSSEReader::getProperty(JSContextRef context, JSObjectRef object,
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (NullPointerException) {
                LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -198,29 +200,23 @@ JSValueRef JSSEReader::openSession(JSContextRef context,
     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
        Validator validator(context, exception);
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       if ((argumentCount < 1) || JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !validator.isCallback(arguments[0])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("SessionCallback TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
-               if (!validator.isCallback(arguments[1])) {
-                       /* 2nd argument must be Callback. */
-                       LogError("ErrorCallback TypeMismatchException!");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               JSObjectRef successCallbackObj = validator.toFunction(0);
+               if (successCallbackObj) {
+                       onSuccessForCbm = arguments[0];
                }
-       }
 
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if (validator.isCallback(arguments[0])) {
-               onSuccessForCbm = arguments[0];
-       }
-
-       if ((argumentCount > 1) && validator.isCallback(arguments[1])) {
-               onErrorForCbm = arguments[1];
-       }
+               JSObjectRef errorCallbackObj = validator.toFunction(1, true);
+               if (errorCallbackObj) {
+                       onErrorForCbm = arguments[1];
+               }
+       } catch (const BasePlatformException &err) {
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
        SEReaderPrivObject* privateObject = static_cast<SEReaderPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -244,7 +240,7 @@ JSValueRef JSSEReader::openSession(JSContextRef context,
        } Catch (ConversionException) {
                LogError("ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index 9873832..8981ee8 100755 (executable)
@@ -28,6 +28,8 @@
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
 #include "SEFactory.h"
 #include "SEResponseDispatcher.h"
 #include "JSSEService.h"
@@ -90,7 +92,7 @@ void JSSEService::initialize(JSContextRef context, JSObjectRef object)
                        }
                } Catch (UnsupportedException) {
                        LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
-               } Catch (UnknownException) {
+               } Catch (WrtDeviceApis::Commons::UnknownException) {
                        LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
                } Catch (PlatformException) {
                        LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -145,28 +147,23 @@ JSValueRef JSSEService::getReaders(JSContextRef context,
     AceSecurityStatus status = SECURE_ELEMENT_CHECK_ACCESS(SECUREELEMENT_FUNCTION_API_FUNCS);
     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       if ((argumentCount < 1) || JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !validator.isCallback(arguments[0])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
-               if (!validator.isCallback(arguments[1])) {
-                       /* 2nd argument must be Callback. */
-                       LogError("ErrorCallback TypeMismatchException!");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+
+               JSObjectRef successCallbackObj = validator.toFunction(0);
+               if (successCallbackObj) {
+                       onSuccessForCbm = arguments[0];
                }
-       }
 
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if (validator.isCallback(arguments[0])) {
-               onSuccessForCbm = arguments[0];
-       }
-       if (argumentCount > 1) {
-               if (validator.isCallback(arguments[1])) {
+               JSObjectRef errorCallbackObj = validator.toFunction(1, true);
+               if (errorCallbackObj) {
                        onErrorForCbm = arguments[1];
                }
-       }
+       } catch (const BasePlatformException &err) {
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
        SEServicePrivObject* privateObject = static_cast<SEServicePrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -188,7 +185,7 @@ JSValueRef JSSEService::getReaders(JSContextRef context,
        } Catch (ConversionException) {
                LogError("ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -211,17 +208,16 @@ JSValueRef JSSEService::registerSEListener(JSContextRef context,
     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
        Validator validator(context, exception);
-
-       if ((argumentCount < 1) || JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) {
-               /* 1st argument is mandatory */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+               JSObjectRef func = validator.toObject(0);
+       }catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
        SEConverter convert(context);
        SEListener seListener;
-       if (JSValueIsObject(context, arguments[0]) &&
-            !validator.isCallback(arguments[0])) {
+       if (!validator.isCallback(arguments[0])) {
                seListener = convert.toSEListener(arguments[0]);
        } else {
                /* 1st argument must be SEListener. */
@@ -253,7 +249,7 @@ JSValueRef JSSEService::registerSEListener(JSContextRef context,
        } Catch (ConversionException) {
                LogError("ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -269,11 +265,13 @@ JSValueRef JSSEService::unregisterSEListener(JSContextRef context, JSObjectRef o
     AceSecurityStatus status = SECURE_ELEMENT_CHECK_ACCESS(SECUREELEMENT_FUNCTION_API_FUNCS);
     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       if ((argumentCount < 1) || JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+       unsigned long value;
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+          value = validator.toULong(0);
+       }catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
        SEServicePrivObject* privateObject = static_cast<SEServicePrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -285,9 +283,9 @@ JSValueRef JSSEService::unregisterSEListener(JSContextRef context, JSObjectRef o
                ISEServicePtr seService(privateObject->getObject());
 
                Converter convert(context);
-               seService->unregisterSEListener(convert.toLong(arguments[0]));
+               seService->unregisterSEListener(value);
 
-               SEListenerCancellerPtr canceller = SEListenerCancellerPtr(new SEListenerCanceller(privateObject->getContext(), thisObject,  convert.toLong(arguments[0])));
+               SEListenerCancellerPtr canceller = SEListenerCancellerPtr(new SEListenerCanceller(privateObject->getContext(), thisObject, value));
                IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
                SEListenerManagerSingleton::Instance().unregisterListener(listenerItem);
 
@@ -297,7 +295,7 @@ JSValueRef JSSEService::unregisterSEListener(JSContextRef context, JSObjectRef o
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (NullPointerException) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (NotFoundException) {
+       } Catch (WrtDeviceApis::Commons::NotFoundException) {
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Not Found ID");
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -327,7 +325,7 @@ JSValueRef JSSEService::shutdown(JSContextRef context,
        Try {
                seService->shutdown();
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index c422def..a7196e5 100755 (executable)
@@ -27,6 +27,8 @@
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
 #include "SEFactory.h"
 #include "SEResponseDispatcher.h"
 #include "JSSESession.h"
@@ -104,7 +106,7 @@ JSValueRef JSSESession::getProperty(JSContextRef context, JSObjectRef object,
                LogError("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (NullPointerException) {
                LogError("NullPointerException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
@@ -262,28 +264,23 @@ JSValueRef JSSESession::openBasicChannel(JSContextRef context,
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
-       if (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !validator.isCallback(arguments[1])) {
-               /* 2st argument is mandatory. And 1st argument must be Array. */
-               LogError("SEChannelSuccessCallback TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
-               if (!validator.isCallback(arguments[2])) {
-                       /* 3nd argument must be Callback. */
-                       LogError("ErrorCallback TypeMismatchException!");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               JSObjectRef successCallbackObj = validator.toFunction(1);
+               if (successCallbackObj) {
+                       onSuccessForCbm = arguments[1];
                }
-       }
 
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if (validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
+               JSObjectRef errorCallbackObj = validator.toFunction(2, true);
+               if (errorCallbackObj) {
+                       onErrorForCbm = arguments[2];
+               }
+       } catch (const BasePlatformException &err) {
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
        SESessionPrivObject* privateObject = static_cast<SESessionPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -312,7 +309,7 @@ JSValueRef JSSESession::openBasicChannel(JSContextRef context,
        } Catch (ConversionException) {
                LogError("ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -342,28 +339,23 @@ JSValueRef JSSESession::openLogicalChannel(JSContextRef context,
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
-       if (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !validator.isCallback(arguments[1])) {
-               /* 2st argument is mandatory. And 1st argument must be Array. */
-               LogError("SEChannelSuccessCallback TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
-               if (!validator.isCallback(arguments[2])) {
-                       /* 3nd argument must be Callback. */
-                       LogError("ErrorCallback TypeMismatchException!");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               JSObjectRef successCallbackObj = validator.toFunction(1);
+               if (successCallbackObj) {
+                       onSuccessForCbm = arguments[1];
                }
-       }
 
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if (validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
+               JSObjectRef errorCallbackObj = validator.toFunction(2, true);
+               if (errorCallbackObj) {
+                       onErrorForCbm = arguments[2];
+               }
+       } catch (const BasePlatformException &err) {
+        LogError(err.getName() << ": " << err.getMessage());
+        return JSWebAPIException::throwException(context, exception, err);
+    }
 
        SESessionPrivObject* privateObject = static_cast<SESessionPrivObject*>(JSObjectGetPrivate(thisObject));
        if (NULL == privateObject) {
@@ -392,7 +384,7 @@ JSValueRef JSSESession::openLogicalChannel(JSContextRef context,
        } Catch (ConversionException) {
                LogError("ConversionException");
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (UnknownException) {
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
                LogError("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index 896aaf2..02ca4e1 100644 (file)
@@ -69,7 +69,7 @@ public:
                Try     {
                        ISEServicePtr seService(privateObject->getObject());
 
-                       seService->unregisterSEListener(m_watchId);
+                       seService->unregisterSEListener(static_cast<unsigned long>(m_watchId));
                } Catch(WrtDeviceApis::Commons::Exception) {
                        LogError("Error on platform : " << _rethrown_exception.GetMessage());
                }
index 492c24b..1f583b0 100755 (executable)
@@ -103,7 +103,7 @@ void SEService::registerSEListener(const EventSEStateChangedEmitterPtr& emitter)
        m_EventSEStateChangedEmitterPtrs.push_back(emitter);
 }
 
-void SEService::unregisterSEListener(long id) {
+void SEService::unregisterSEListener(unsigned long id) {
        std::vector<EventSEStateChangedEmitterPtr>::iterator it;
        for (it = m_EventSEStateChangedEmitterPtrs.begin(); it != m_EventSEStateChangedEmitterPtrs.end(); ++it) {
                if (id == static_cast<long>((*it)->getId())) {
index e9527b6..b63586f 100755 (executable)
@@ -39,7 +39,7 @@ class SEService : public ISEService
 
        virtual void getReaders(const EventListSEsPtr& event);
        virtual void registerSEListener(const EventSEStateChangedEmitterPtr& emitter);
-       virtual void unregisterSEListener(long id);
+       virtual void unregisterSEListener(unsigned long id);
        virtual void shutdown();
        void getSEServiceCompleted();
        void eventChanged(char *seName, int event);
index 659f224..e03d67c 100755 (executable)
@@ -8,6 +8,7 @@ PKG_CHECK_MODULES(platform_pkgs_systeminfo REQUIRED
        capi-system-info
        capi-system-runtime-info
        capi-system-sensor
+       capi-telephony-network-info
        sensor
 )
 INCLUDE_DIRECTORIES(
index 8b3d521..1e80682 100755 (executable)
@@ -153,7 +153,7 @@ JSValueRef JSCellularNetworkInfo::getProperty(JSContextRef context, JSObjectRef
         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_FLIGHT_MODE_PROPERTY)) {
             return convert.toJSValueRef(cellularNetworkInfo->isFlightMode);
         } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IMEI_PROPERTY)) {
-            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_IMEI_VALUE);
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE);
             TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
             return convert.toJSValueRef(cellularNetworkInfo->imei);
         }            
index 8ba4021..0bed328 100755 (executable)
@@ -32,10 +32,14 @@ using namespace DeviceAPI::Common;
 namespace {
 const char* DEVICE_CAPABILITIES_BLUETOOTH = "bluetooth";
 const char* DEVICE_CAPABILITIES_NFC = "nfc";
+const char* DEVICE_CAPABILITIES_NFC_RESERVED_PUSH = "nfcReservedPush";
 const char* DEVICE_CAPABILITIES_MULTITOUCHCOUNT = "multiTouchCount";
 const char* DEVICE_CAPABILITIES_INPUTKEYBOARD = "inputKeyboard";
+const char* DEVICE_CAPABILITIES_INPUTKEYBOARD_LAYOUT = "inputKeyboardLayout";
 const char* DEVICE_CAPABILITIES_WIFI = "wifi";
 const char* DEVICE_CAPABILITIES_WIFIDIRECT = "wifiDirect";
+const char* DEVICE_CAPABILITIES_OPENGLES = "opengles";
+const char* DEVICE_CAPABILITIES_OPENGLES_TEXTURE_FORMAT = "openglestextureFormat";
 const char* DEVICE_CAPABILITIES_OPENGLESVERSION1_1 = "openglesVersion1_1";
 const char* DEVICE_CAPABILITIES_OPENGLESVERSION2_0 = "openglesVersion2_0";
 const char* DEVICE_CAPABILITIES_FMRADIO = "fmRadio";
@@ -43,6 +47,7 @@ const char* DEVICE_CAPABILITIES_PLATFORMVERSION = "platformVersion";
 const char* DEVICE_CAPABILITIES_PLATFORMNAME = "platformName";
 const char* DEVICE_CAPABILITIES_WEBAPIVERSION = "webApiVersion";
 const char* DEVICE_CAPABILITIES_NATIVEAPIVERSION = "nativeApiVersion";
+const char* DEVICE_CAPABILITIES_CAMERA = "camera";
 const char* DEVICE_CAPABILITIES_CAMERAFRONT = "cameraFront";
 const char* DEVICE_CAPABILITIES_CAMERAFRONTFLASH = "cameraFrontFlash";
 const char* DEVICE_CAPABILITIES_CAMERABACK = "cameraBack";
@@ -59,12 +64,39 @@ const char* DEVICE_CAPABILITIES_PLATFORMCORECPUARCH = "platformCoreCpuArch";
 const char* DEVICE_CAPABILITIES_PLATFORMCOREFPUARCH = "platformCoreFpuArch";
 const char* DEVICE_CAPABILITIES_SIPVOIP = "sipVoip";
 const char* DEVICE_CAPABILITIES_DUID = "duid";
-const char* DEVICE_CAPABILITIES_SPEECHROCOGNITION = "speechRecognition";
+const char* DEVICE_CAPABILITIES_SPEECH_ROCOGNITION = "speechRecognition";
+const char* DEVICE_CAPABILITIES_SPEECH_SYNTHESIS = "speechSynthesis";
 const char* DEVICE_CAPABILITIES_ACCELEROMETER = "accelerometer";
+const char* DEVICE_CAPABILITIES_ACCELEROMETER_WAKEUP = "accelerometerWakeup";
 const char* DEVICE_CAPABILITIES_BAROMETER = "barometer";
+const char* DEVICE_CAPABILITIES_BAROMETER_WAKEUP = "barometerWakeup";
 const char* DEVICE_CAPABILITIES_GYROSCOPE = "gyroscope";
+const char* DEVICE_CAPABILITIES_GYROSCOPE_WAKEUP = "gyroscopeWakeup";
 const char* DEVICE_CAPABILITIES_MAGNETOMETER = "magnetometer";
+const char* DEVICE_CAPABILITIES_MAGNETOMETER_WAKEUP = "magnetometerWakeup";
+const char* DEVICE_CAPABILITIES_PHOTOMETER = "photometer";
+const char* DEVICE_CAPABILITIES_PHOTOMETER_WAKEUP = "photometerWakeup";
 const char* DEVICE_CAPABILITIES_PROXIMITY = "proximity";
+const char* DEVICE_CAPABILITIES_PROXIMITY_WAKEUP = "proximityWakeup";
+const char* DEVICE_CAPABILITIES_TILTMETER = "tiltmeter";
+const char* DEVICE_CAPABILITIES_TILTMETER_WAKEUP = "tiltmeterWakeup";
+const char* DEVICE_CAPABILITIES_DATA_ENCRYPTION = "dataEncryption";
+const char* DEVICE_CAPABILITIES_GRAPHICS_ACCELERATION = "graphicsAcceleration";
+const char* DEVICE_CAPABILITIES_PUSH = "push";
+const char* DEVICE_CAPABILITIES_TELEPHONY = "telephony";
+const char* DEVICE_CAPABILITIES_TELEPHONY_MMS = "telephonyMms";
+const char* DEVICE_CAPABILITIES_TELEPHONY_SMS = "telephonySms";
+const char* DEVICE_CAPABILITIES_SCREENSIZE_NORMAL = "screenSizeNormal";
+const char* DEVICE_CAPABILITIES_SCREENSIZE_480_800 = "screenSize480_800";
+const char* DEVICE_CAPABILITIES_SCREENSIZE_720_1280 = "screenSize720_1280";
+const char* DEVICE_CAPABILITIES_AUTO_ROTATION = "autoRotation";
+const char* DEVICE_CAPABILITIES_SHELL_APP_WIDGET = "shellAppWidget";
+const char* DEVICE_CAPABILITIES_VISION_IMAGE_RECOGNITION = "visionImageRecognition";
+const char* DEVICE_CAPABILITIES_VISION_QRCODE_GENERATION = "visionQrcodeGeneration";
+const char* DEVICE_CAPABILITIES_VISION_QRCODE_RECOGNITION = "visionQrcodeRecognition";
+const char* DEVICE_CAPABILITIES_VISION_FACE_RECOGNITION = "visionFaceRecognition";
+const char* DEVICE_CAPABILITIES_SECURE_ELEMENT = "secureElement";
+const char* DEVICE_CAPABILITIES_NATIVE_OSP_COMPATIBLE = "nativeOspCompatible";
 } 
 
 JSClassRef JSDeviceCapabilitiesInfo::m_classRef = NULL;
@@ -92,10 +124,14 @@ JSClassDefinition JSDeviceCapabilitiesInfo::m_classInfo = {
 JSStaticValue JSDeviceCapabilitiesInfo::m_properties[] = {
     { DEVICE_CAPABILITIES_BLUETOOTH, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_NFC, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_NFC_RESERVED_PUSH, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_MULTITOUCHCOUNT, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_INPUTKEYBOARD, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_INPUTKEYBOARD_LAYOUT, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_WIFI, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_WIFIDIRECT, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_OPENGLES, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_OPENGLES_TEXTURE_FORMAT, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_OPENGLESVERSION1_1, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_OPENGLESVERSION2_0, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_FMRADIO, getProperty, NULL, kJSPropertyAttributeReadOnly },
@@ -103,6 +139,7 @@ JSStaticValue JSDeviceCapabilitiesInfo::m_properties[] = {
     { DEVICE_CAPABILITIES_PLATFORMNAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_WEBAPIVERSION, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_NATIVEAPIVERSION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_CAMERA, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_CAMERAFRONT, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_CAMERAFRONTFLASH, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_CAMERABACK, getProperty, NULL, kJSPropertyAttributeReadOnly },
@@ -119,12 +156,39 @@ JSStaticValue JSDeviceCapabilitiesInfo::m_properties[] = {
     { DEVICE_CAPABILITIES_PLATFORMCOREFPUARCH, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_SIPVOIP, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_DUID, getProperty, NULL, kJSPropertyAttributeReadOnly },
-    { DEVICE_CAPABILITIES_SPEECHROCOGNITION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SPEECH_ROCOGNITION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SPEECH_SYNTHESIS, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_ACCELEROMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_ACCELEROMETER_WAKEUP, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_BAROMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_BAROMETER_WAKEUP, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_GYROSCOPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_GYROSCOPE_WAKEUP, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_MAGNETOMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_MAGNETOMETER_WAKEUP, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PHOTOMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PHOTOMETER_WAKEUP, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { DEVICE_CAPABILITIES_PROXIMITY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PROXIMITY_WAKEUP, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_TILTMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_TILTMETER_WAKEUP, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_DATA_ENCRYPTION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_GRAPHICS_ACCELERATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PUSH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_TELEPHONY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_TELEPHONY_MMS, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_TELEPHONY_SMS, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SCREENSIZE_NORMAL, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SCREENSIZE_480_800, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SCREENSIZE_720_1280, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_AUTO_ROTATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SHELL_APP_WIDGET, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_VISION_IMAGE_RECOGNITION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_VISION_QRCODE_GENERATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_VISION_QRCODE_RECOGNITION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_VISION_FACE_RECOGNITION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SECURE_ELEMENT, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_NATIVE_OSP_COMPATIBLE, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { 0, 0, 0, 0 }
 };
 
@@ -184,14 +248,22 @@ JSValueRef JSDeviceCapabilitiesInfo::getProperty(JSContextRef context, JSObjectR
             return convert.toJSValueRef(deviceCapabilitiesInfo->bluetooth);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_NFC)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->nfc);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_NFC_RESERVED_PUSH)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->nfcReservedPush);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_MULTITOUCHCOUNT)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->multiTouchCount);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_INPUTKEYBOARD)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->inputKeyboard);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_INPUTKEYBOARD_LAYOUT)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->inputKeyboardLayout);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_WIFI)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->wifi);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_WIFIDIRECT)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->wifiDirect);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_OPENGLES)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->opengles);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_OPENGLES_TEXTURE_FORMAT)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->openglestextureFormat);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_OPENGLESVERSION1_1)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->openglesVersion1_1);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_OPENGLESVERSION2_0)) {
@@ -214,6 +286,8 @@ JSValueRef JSDeviceCapabilitiesInfo::getProperty(JSContextRef context, JSObjectR
             return convert.toJSValueRef(deviceCapabilitiesInfo->nativeApiVersion);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERAFRONT)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->cameraFront);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERA)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->camera);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERAFRONTFLASH)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->cameraFrontFlash);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERABACK)) {
@@ -244,18 +318,72 @@ JSValueRef JSDeviceCapabilitiesInfo::getProperty(JSContextRef context, JSObjectR
             return convert.toJSValueRef(deviceCapabilitiesInfo->sipVoip);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_DUID)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->duid);
-        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SPEECHROCOGNITION)) {
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SPEECH_ROCOGNITION)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->speechRecognition);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SPEECH_SYNTHESIS)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->speechSynthesis);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_ACCELEROMETER)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->accelerometer);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_ACCELEROMETER_WAKEUP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->accelerometerWakeup);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_BAROMETER)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->barometer);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_BAROMETER_WAKEUP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->barometerWakeup);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_GYROSCOPE)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->gyroscope);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_GYROSCOPE_WAKEUP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->gyroscopeWakeup);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_MAGNETOMETER)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->magnetometer);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_MAGNETOMETER_WAKEUP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->magnetometerWakeup);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PHOTOMETER)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->photometer);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PHOTOMETER_WAKEUP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->photometerWakeup);
         } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PROXIMITY)) {
             return convert.toJSValueRef(deviceCapabilitiesInfo->proximity);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PROXIMITY_WAKEUP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->proximityWakeup);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_TILTMETER)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->tiltmeter);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_TILTMETER_WAKEUP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->tiltmeterWakeup);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_DATA_ENCRYPTION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->dataEncryption);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_GRAPHICS_ACCELERATION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->graphicsAcceleration);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PUSH)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->push);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_TELEPHONY)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->telephony);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_TELEPHONY_MMS)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->telephonyMms);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_TELEPHONY_SMS)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->telephonySms);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SCREENSIZE_NORMAL)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->screenSizeNormal);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SCREENSIZE_480_800)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->screenSize480_800);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SCREENSIZE_720_1280)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->screenSize720_1280);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_AUTO_ROTATION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->autoRotation);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SHELL_APP_WIDGET)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->shellAppWidget);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_VISION_IMAGE_RECOGNITION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->visionImageRecognition);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_VISION_QRCODE_GENERATION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->visionQrcodeGeneration);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_VISION_QRCODE_RECOGNITION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->visionQrcodeRecognition);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_VISION_FACE_RECOGNITION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->visionFaceRecognition);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SECURE_ELEMENT)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->secureElement);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_NATIVE_OSP_COMPATIBLE)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->nativeOspCompatible);
         }
     }
     Catch(Exception)
index df98b0f..152e1b1 100755 (executable)
@@ -119,27 +119,38 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
         return JSValueMakeUndefined(context);
     }
 
-    AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
-    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
     Try
     {
         SIMPropertiesPtr SIMInfo = priv->getObject();
         Converter convert(context);
 
         if (JSStringIsEqualToUTF8CString(propertyName, SIM_OPERATORNAME_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
             return convert.toJSValueRef(SIMInfo->operatorName);
         } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MSISDN_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);        
             return convert.toJSValueRef(SIMInfo->msisdn);
         } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_ICCID_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);        
             return convert.toJSValueRef(SIMInfo->iccid);
         } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MCC_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);        
             return convert.toJSValueRef(SIMInfo->mcc);
         } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MNC_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);        
             return convert.toJSValueRef(SIMInfo->mnc);            
         } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MSIN_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);        
             return convert.toJSValueRef(SIMInfo->msin);            
         } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_SPN_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);        
             return convert.toJSValueRef(SIMInfo->spn);            
         }            
     }
index b804699..5579fe1 100755 (executable)
@@ -1442,35 +1442,38 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
     connection_type_e connectionType;
     connection_profile_h profileHandle = NULL;
     connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
+    network_info_service_state_e serviceState;
     char* ipAddr = NULL;
     char* apn = NULL;
     char* imei = NULL;
-    int plmn = 0, cellid = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
+    char* mcc = NULL;
+    char* mnc = NULL;
+    bool isRoaming = false;
+    int cellId = 0, lac = 0, isFlightMode = 0;
 
-    if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
-        cellularNetwork->mcc = plmn / 100;
-        cellularNetwork->mnc = plmn % 100;
+    if (network_info_get_lac(&lac) == NETWORK_INFO_ERROR_NONE) {
+        cellularNetwork->lac = lac;        
     }
-    
-    if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellid) == 0) {
-        cellularNetwork->cellId = cellid;
+
+    if (network_info_get_cell_id(&cellId) == NETWORK_INFO_ERROR_NONE) {
+        cellularNetwork->cellId = cellId;
     }
-    
-    if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
-        cellularNetwork->lac = lac;
+
+    if (network_info_is_roaming(&isRoaming) == NETWORK_INFO_ERROR_NONE) {
+        cellularNetwork->isRoaming = isRoaming;
     }
 
-    if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
-        if (isRoaming) {
-            cellularNetwork->isRoaming = true;
-        } else {
-            cellularNetwork->isRoaming = false;
-        }
+    if (network_info_get_mcc(&mcc) == NETWORK_INFO_ERROR_NONE) {
+        cellularNetwork->mcc = converter.toInt(mcc);
+    }    
+
+    if (network_info_get_mnc(&mnc) == NETWORK_INFO_ERROR_NONE) {
+        cellularNetwork->mnc = converter.toInt(mnc);
     }
 
-    if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
-        if (isFlightMode) {
-            cellularNetwork->isFlightMode = true;
+    if (network_info_get_service_state(&serviceState) == NETWORK_INFO_ERROR_NONE) {
+        if (serviceState == NETWORK_INFO_SERVICE_STATE_RADIO_OFF) {
+           cellularNetwork->isFlightMode = true;
         } else {
             cellularNetwork->isFlightMode = false;
         }
index e62c3fa..18dc061 100755 (executable)
@@ -27,6 +27,7 @@
 #include <sensors.h>
 #include <net_connection.h>
 #include <sim.h>
+#include <telephony_network.h>
 #include <system_info.h>
 #include <runtime_info.h>
 #include <JavaScriptCore/JavaScript.h>
index 626317a..1f6a011 100755 (executable)
@@ -39,10 +39,14 @@ struct DeviceCapabilitiesProperties
 {
     bool            bluetooth;
     bool            nfc;
+    bool            nfcReservedPush;
     unsigned short  multiTouchCount;
     std::string     inputKeyboard;
+    bool            inputKeyboardLayout;
     bool            wifi;
     bool            wifiDirect;
+    bool            opengles;
+    std::string     openglestextureFormat;
     bool            openglesVersion1_1;
     bool            openglesVersion2_0;
     bool            fmRadio;
@@ -50,6 +54,7 @@ struct DeviceCapabilitiesProperties
     std::string     platformName;
     std::string     webApiVersion;
     std::string     nativeApiVersion;
+    bool            camera;
     bool            cameraFront;
     bool            cameraFrontFlash;
     bool            cameraBack;
@@ -67,19 +72,50 @@ struct DeviceCapabilitiesProperties
     bool            sipVoip;
     std::string     duid;
     bool            speechRecognition;
+    bool            speechSynthesis;
     bool            accelerometer;    
+    bool            accelerometerWakeup;
     bool            barometer;
+    bool            barometerWakeup;
     bool            gyroscope;
+    bool            gyroscopeWakeup;
     bool            magnetometer;
+    bool            magnetometerWakeup;
+    bool            photometer;
+    bool            photometerWakeup;
     bool            proximity;
+    bool            proximityWakeup;
+    bool            tiltmeter;
+    bool            tiltmeterWakeup;
+    bool            dataEncryption;
+    bool            graphicsAcceleration;
+    bool            push;
+    bool            telephony;
+    bool            telephonyMms;
+    bool            telephonySms;
+    bool            screenSizeNormal;
+    bool            screenSize480_800;
+    bool            screenSize720_1280;
+    bool            autoRotation;
+    bool            shellAppWidget;
+    bool            visionImageRecognition;
+    bool            visionQrcodeGeneration;
+    bool            visionQrcodeRecognition;
+    bool            visionFaceRecognition;
+    bool            secureElement;
+    bool            nativeOspCompatible;
 
     DeviceCapabilitiesProperties() :
         bluetooth(false),
         nfc(false),
+        nfcReservedPush(false),
         multiTouchCount(0),
         inputKeyboard(""),
+        inputKeyboardLayout(false),
         wifi(false),
         wifiDirect(false),
+        opengles(false),
+        openglestextureFormat(""),
         openglesVersion1_1(false),
         openglesVersion2_0(false),
         fmRadio(false),
@@ -87,6 +123,7 @@ struct DeviceCapabilitiesProperties
         platformName(""),
         webApiVersion(""),
         nativeApiVersion(""),
+        camera(false),
         cameraFront(false),
         cameraFrontFlash(false),
         cameraBack(false),
@@ -104,11 +141,38 @@ struct DeviceCapabilitiesProperties
         sipVoip(false),
         duid(""),
         speechRecognition(false),
+        speechSynthesis(false),
         accelerometer(false),
+        accelerometerWakeup(false),        
         barometer(false),
+        barometerWakeup(false),
         gyroscope(false),
+        gyroscopeWakeup(false),
         magnetometer(false),
-        proximity(false)
+        magnetometerWakeup(false),
+        photometer(false),
+        photometerWakeup(false),
+        proximity(false),
+        proximityWakeup(false),
+        tiltmeter(false),
+        tiltmeterWakeup(false),
+        dataEncryption(false),
+        graphicsAcceleration(false),
+        push(false),
+        telephony(false),
+        telephonyMms(false),
+        telephonySms(false),
+        screenSizeNormal(false),
+        screenSize480_800(false),
+        screenSize720_1280(false),
+        autoRotation(false),
+        shellAppWidget(false),
+        visionImageRecognition(false),
+        visionQrcodeGeneration(false),
+        visionQrcodeRecognition(false),
+        visionFaceRecognition(false),
+        secureElement(false),
+        nativeOspCompatible(false)
         {
         }
 };
index d698a70..1524bc1 100755 (executable)
@@ -33,7 +33,7 @@ namespace DeviceAPI {
 namespace Systeminfo {
 
 const char* SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES = "getCapabilities";
-const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_IMEI_VALUE = "getPropertyImeiValue";
+const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE = "getPropertyPartnerValue";
 const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE = "getPropertySimValue";
 
 static WrtDeviceApis::Commons::FunctionMapping createSysteminfoFunctions();
@@ -88,12 +88,12 @@ static WrtDeviceApis::Commons::FunctionMapping createSysteminfoFunctions()
         DEVICE_LIST_SYSTEMINFO);
     SysteminfoFunctions.insert(std::make_pair(SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES, getCapabilitiesFunc));
 
-    AceFunction getPropertyImeiValueFunc = ACE_CREATE_FUNCTION(
-        FUNCTION_GET_PROPERTY_IMEI_VALUE,
-        SYSTEMINFO_FUNCTION_API_GET_PROPERTY_IMEI_VALUE,
+    AceFunction getPropertyPartnerValueFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_GET_PROPERTY_PARTNER_VALUE,
+        SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE,
         SYSTEMINFO_FEATURES_SYSTEMMANAGER,
         DEVICE_LIST_SYSTEMINFO);
-    SysteminfoFunctions.insert(std::make_pair(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_IMEI_VALUE, getPropertyImeiValueFunc));
+    SysteminfoFunctions.insert(std::make_pair(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE, getPropertyPartnerValueFunc));
 
     AceFunction getPropertySimValueFunc = ACE_CREATE_FUNCTION(
         FUNCTION_GET_PROPERTY_SIM_VALUE,
index df551f8..bc0884d 100755 (executable)
@@ -24,7 +24,7 @@ namespace DeviceAPI {
 namespace Systeminfo {
 
 extern const char* SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES;
-extern const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_IMEI_VALUE;
+extern const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE;
 extern const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE;
 
 DECLARE_FUNCTION_GETTER(Systeminfo);
index 8ed84d6..c50b560 100755 (executable)
@@ -27,6 +27,8 @@
 #include <Commons/Exception.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
 
 #include "DurationProperties.h"
 
@@ -162,7 +164,7 @@ JSObjectRef JSTZDate::createJSObject(JSContextRef context, const double millisec
                tzDate = TZDatePtr(new TZDate(timezone));
 
        if (!tzDate->setTime(milliseconds))
-               ThrowMsg(UnknownException, "Can not set UTC Time");
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can not set UTC Time");
 
        TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
        if (!priv) {
@@ -348,7 +350,7 @@ JSValueRef JSTZDate::getTimezone(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -364,13 +366,9 @@ JSValueRef JSTZDate::toTimezone(JSContextRef context, JSObjectRef function,
        JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
        LogDebug("entered");
 
-       Try {
-               TimeUtilConverter converter(context);
-               std::string timezone;
-               if (argumentCount < 1)
-                       timezone = converter.toString(JSValueMakeUndefined(context));
-               else
-                       timezone = converter.toString(arguments[0]);
+       try {
+               ArgumentValidator validator(context, argumentCount, arguments);
+               std::string timezone = validator.toString(0);
 
                TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
                if (!privateObject) {
@@ -380,10 +378,12 @@ JSValueRef JSTZDate::toTimezone(JSContextRef context, JSObjectRef function,
 
                TZDatePtr tzDate(privateObject->getObject());
                return createJSObject(context, tzDate->getTime(), timezone);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -401,11 +401,9 @@ JSValueRef JSTZDate::toTimezone(JSContextRef context, JSObjectRef function,
 JSValueRef JSTZDate::diffTZDate(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type) {
        LogDebug("entered");
 
-       if ((argumentCount < 1) || JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])
-               || !JSValueIsObjectOfClass(context, arguments[0], getClassRef())) {
-               LogError("Wrong tzDate parameters");
-               ThrowMsg(ConversionException, "Wrong tzDate parameters");
-       }
+       ArgumentValidator validator(context, argumentCount, arguments);
+       JSObjectRef obj = NULL;
+       obj = validator.toObject(0, JSTZDate::getClassRef(), false);
 
        TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
@@ -450,13 +448,15 @@ JSValueRef JSTZDate::difference(JSContextRef context, JSObjectRef function,
 
        Try {
                return diffTZDate(context, thisObject, argumentCount,  arguments, exception, DIFFERENCE);
-       } Catch(InvalidArgumentException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    } Catch(InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch(ConversionException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -474,10 +474,12 @@ JSValueRef JSTZDate::equalsTo(JSContextRef context, JSObjectRef function,
 
        Try {
                return diffTZDate(context, thisObject, argumentCount,  arguments, exception, EQUALSTO);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -497,10 +499,12 @@ JSValueRef JSTZDate::earlierThan(JSContextRef context, JSObjectRef function,
 
        Try {
                return diffTZDate(context, thisObject, argumentCount,  arguments, exception, EARLIERTHAN);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -522,10 +526,12 @@ JSValueRef JSTZDate::laterThan(JSContextRef context, JSObjectRef function,
 
        Try {
                return diffTZDate(context, thisObject, argumentCount,  arguments, exception, LATERTHAN);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -567,7 +573,7 @@ JSValueRef JSTZDate::addDuration(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -601,7 +607,7 @@ JSValueRef JSTZDate::toUTC(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -629,7 +635,7 @@ JSValueRef JSTZDate::toLocalTimezone(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -658,7 +664,7 @@ JSValueRef JSTZDate::toLocaleDateString(JSContextRef context, JSObjectRef functi
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -688,7 +694,7 @@ JSValueRef JSTZDate::toLocaleTimeString(JSContextRef context, JSObjectRef functi
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -718,7 +724,7 @@ JSValueRef JSTZDate::toLocaleString(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -748,7 +754,7 @@ JSValueRef JSTZDate::toDateString(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -778,7 +784,7 @@ JSValueRef JSTZDate::toTimeString(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -809,7 +815,7 @@ JSValueRef JSTZDate::toString(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -903,7 +909,7 @@ JSValueRef JSTZDate::getTZDateValue(JSContextRef context, JSObjectRef thisObject
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -923,10 +929,12 @@ JSValueRef JSTZDate::setDate(JSContextRef context, JSObjectRef function, JSObjec
 
        try{
                setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }  Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (InvalidArgumentException) {
@@ -951,10 +959,12 @@ JSValueRef JSTZDate::setFullYear(JSContextRef context, JSObjectRef function, JSO
 
        try{
                setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (InvalidArgumentException) {
@@ -979,10 +989,12 @@ JSValueRef JSTZDate::setHours(JSContextRef context, JSObjectRef function, JSObje
 
        Try {
                setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (InvalidArgumentException) {
@@ -1007,10 +1019,12 @@ JSValueRef JSTZDate::setMilliseconds(JSContextRef context, JSObjectRef function,
        
        Try{
                setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (InvalidArgumentException) {
@@ -1035,10 +1049,12 @@ JSValueRef JSTZDate::setMinutes(JSContextRef context, JSObjectRef function, JSOb
 
        Try {
                setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (InvalidArgumentException) {
@@ -1063,10 +1079,12 @@ JSValueRef JSTZDate::setMonth(JSContextRef context, JSObjectRef function, JSObje
 
        Try {
                setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (InvalidArgumentException) {
@@ -1091,10 +1109,12 @@ JSValueRef JSTZDate::setSeconds(JSContextRef context, JSObjectRef function, JSOb
 
        Try {
                setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
-       } Catch(NullPointerException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    }Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
        } Catch (InvalidArgumentException) {
@@ -1114,14 +1134,8 @@ JSValueRef JSTZDate::setSeconds(JSContextRef context, JSObjectRef function, JSOb
 
 JSValueRef JSTZDate::setTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
         JSValueRef * exception, TZDate::TZDateFields dateFields) {
-
-       TimeUtilConverter converter(context);
-
-       int data =0;
-       if (argumentCount == 0)
-               data = converter.toInt(JSValueMakeUndefined(context));
-       else
-               data = converter.toInt(arguments[0]);
+       ArgumentValidator validator(context, argumentCount, arguments);
+       long data = validator.toLong(0);
 
        if ((dateFields == TZDate::TZDATE_YEAR) && (data < 0))
                ThrowMsg(InvalidArgumentException, "Invalid Argument:Year can't be set to negative");
@@ -1134,7 +1148,7 @@ JSValueRef JSTZDate::setTZDateValue(JSContextRef context, JSObjectRef thisObject
        }
 
        TZDatePtr tzDate(privateObject->getObject());
-       tzDate->set(dateFields, static_cast<long> (data));
+       tzDate->set(dateFields,data);
 
        return JSValueMakeNull(context);
 }      //setTZDateValue
@@ -1205,7 +1219,7 @@ JSValueRef JSTZDate::getUTCTZDateValue(JSContextRef context, JSObjectRef thisObj
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -1294,7 +1308,7 @@ JSValueRef JSTZDate::setUTCTZDateValue(JSContextRef context, JSObjectRef thisObj
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -1328,7 +1342,7 @@ JSValueRef JSTZDate::getTimezoneAbbreviation(JSContextRef context, JSObjectRef f
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -1357,7 +1371,7 @@ JSValueRef JSTZDate::secondsFromUTC(JSContextRef context, JSObjectRef function,
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -1384,7 +1398,7 @@ JSValueRef JSTZDate::isDST(JSContextRef context, JSObjectRef function, JSObjectR
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -1417,7 +1431,7 @@ JSValueRef JSTZDate::getPreviousDSTTransition(JSContextRef context, JSObjectRef
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
@@ -1450,7 +1464,7 @@ JSValueRef JSTZDate::getNextDSTTransition(JSContextRef context, JSObjectRef func
        } Catch(NullPointerException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch(UnknownException) {
+       } Catch(WrtDeviceApis::Commons::UnknownException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
        } Catch (InvalidArgumentException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
index 7ce8ee6..310b15a 100755 (executable)
@@ -158,9 +158,7 @@ bool JSTimeDuration::setProperty(JSContextRef context, JSObjectRef object,
                TimeUtilConverter convert(context);
 
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_TIMEDURATION_LENGTH)) {
-                       duration->length = static_cast<long long>(convert.toDouble(value));
-                       if (std::isnan(duration->length)  || std::isinf(duration->length))
-                               duration->length = 0;
+                       duration->length = convert.toLongLong(value);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_TIMEDURATION_UNIT)) {
                        short unit = convert.toDurationUnit(convert.toString(value));
                        if (unit == 0xff)
@@ -204,12 +202,9 @@ JSObjectRef JSTimeDuration::constructor(JSContextRef ctx, JSObjectRef constructo
        Try {
                DurationProperties duration;
                if (argumentCount == 0)
-                       duration.length = convert.toDouble(JSValueMakeUndefined(ctx));
+                       duration.length = convert.toLongLong(JSValueMakeUndefined(ctx));
                else
-                       duration.length = convert.toDouble(arguments[0]);
-
-               if (std::isnan(duration.length) || std::isinf(duration.length))
-                       duration.length = 0;
+                       duration.length = convert.toLongLong(arguments[0]);
 
                if (argumentCount > 1) {
                        if (!JSValueIsUndefined(ctx, arguments[1]) && !JSValueIsNull(ctx, arguments[1])) {
index 7495402..0db40e5 100755 (executable)
@@ -25,6 +25,8 @@
 #include <CommonsJavaScript/JSCallbackManager.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
+#include <ArgumentValidator.h>
+#include <JSWebAPIException.h>
 
 #include "JSTimeUtil.h"
 #include "JSTZDate.h"
@@ -228,15 +230,12 @@ JSValueRef JSTimeUtil::getDateFormat(JSContextRef context,
         JSValueRef* exception)
 {
        LogDebug("entered");
-       Try {
-               bool b_shortFormat = true;
+       try
+       {
+                TimeUtilConverter converter(context);
+               ArgumentValidator validator(context, argumentCount, arguments);
+       bool value = validator.toBool(0,true,false);
                
-               TimeUtilConverter converter(context);   
-               if ((argumentCount == 0) || (JSValueIsNull(context, arguments[0])) || JSValueIsUndefined(context, arguments[0])) {
-                       b_shortFormat = false;
-               } else
-                       b_shortFormat = converter.toBool(arguments[0]);
-
                TimeUtilPrivObject* privateObject = 
                        static_cast<TimeUtilPrivObject*>(JSObjectGetPrivate(
                                                               thisObject));
@@ -245,10 +244,12 @@ JSValueRef JSTimeUtil::getDateFormat(JSContextRef context,
                }
 
                TimeUtilPtr timeutil(privateObject->getObject());
-               std::string dateformat = timeutil->getDateFormat(b_shortFormat);
+               std::string dateformat = timeutil->getDateFormat(value);
                
                return converter.toJSValueRef(dateformat);
-       } Catch(ConversionException) {
+       } catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
+    } Catch(ConversionException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (InvalidArgumentException) {
@@ -310,15 +311,11 @@ JSValueRef JSTimeUtil::getTimeFormat(JSContextRef context,
 JSValueRef JSTimeUtil::isLeapYear(JSContextRef context, JSObjectRef function, 
        JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
        LogDebug("Entered");
-       Try {
+       try{
                TimeUtilConverter converter(context);
+        ArgumentValidator validator(context, argumentCount, arguments);
+        long year  = validator.toLong(0);
 
-               long year = 0;
-               if (argumentCount < 1) {
-                       year = converter.toLong(JSValueMakeUndefined(context));
-               } else
-                       year = converter.toLong(arguments[0]);
-               
                if (year % 4 != 0)
                        return converter.toJSValueRef(false);
                if (year % 400 == 0)
@@ -327,6 +324,8 @@ JSValueRef JSTimeUtil::isLeapYear(JSContextRef context, JSObjectRef function,
                        return converter.toJSValueRef(false);
 
                return converter.toJSValueRef(true);    
+    }catch(const BasePlatformException& err){
+        return JSWebAPIException::throwException(context, exception, err);
        } Catch(ConversionException) {
                LogError("Exception: " << _rethrown_exception.GetMessage());
                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
index 13a0f06..9760caa 100644 (file)
@@ -214,9 +214,11 @@ std::string PrivateAny::toString(JSContextRef context, JSValueRef value) const
 
 AnyPtr AnyFactory::createAny(JSContextRef context, JSValueRef value, PrimitiveType type)
 {
+       AnyPtr any(NULL);
+
        try
        {
-               return AnyPtr(new PrivateAny(context, value, type));
+               any = AnyPtr(new PrivateAny(context, value, type));
        }
        catch(TypeMismatchException &e)
        {
@@ -227,7 +229,7 @@ AnyPtr AnyFactory::createAny(JSContextRef context, JSValueRef value, PrimitiveTy
                ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Unknown error occured while converting JSValueRef");
        }
 
-       return AnyPtr(new PrivateAny());
+       return any;
 }
 
 AnyPtr AnyFactory::createAnyNoException(JSContextRef context, JSValueRef value, PrimitiveType type)
index 1d770a2..3a6ec84 100644 (file)
@@ -36,16 +36,16 @@ using namespace DeviceAPI::Common;
 Any::Any() :
                m_isNullOrUndefined(false),
                m_priv(NULL),
-               m_ownership(false),
+               m_privFinalizerFunc(NULL),
                m_type(PrimitiveType_NoType)
 {
 }
 
 Any::~Any()
 {
-       if(m_priv && m_ownership)
+       if(m_priv && m_privFinalizerFunc)
        {
-               delete m_priv;
+               m_privFinalizerFunc(m_priv);
        }
 }
 
@@ -151,13 +151,13 @@ void * Any::getPriv() const
        return m_priv;
 }
 
-void Any::setPriv(void * priv, bool ownership)
+void Any::setPriv(void * priv, AnyPrivFinalizerFunc privFinalizerFunc)
 {
-       if(m_priv && m_ownership)
-               delete m_priv;
+       if(m_priv && m_privFinalizerFunc)
+               m_privFinalizerFunc(m_priv);
 
        m_priv = priv;
-       m_ownership = ownership;
+       m_privFinalizerFunc = privFinalizerFunc;
 }
 
 } // Tizen
index 11ed696..4c8965f 100644 (file)
@@ -72,6 +72,8 @@ enum PrimitiveType {
        PrimitiveType_PlatformObject
 };
 
+typedef void (*AnyPrivFinalizerFunc)(void *);
+
 class Any
 {
 public:
@@ -97,7 +99,7 @@ public:
        std::string getJSON() const;
 
        void * getPriv() const;
-       void setPriv(void * priv, bool ownership);
+       void setPriv(void * priv, AnyPrivFinalizerFunc privFinalizerFunc);
 
 protected:
        union AnyTypeUnion
@@ -112,16 +114,16 @@ protected:
                std::tm *t;
        };
 
-       AnyTypeUnion    m_value;
-       bool            m_isNullOrUndefined;
+       AnyTypeUnion            m_value;
+       bool                    m_isNullOrUndefined;
 
-       std::string     m_json;
-       std::string     m_str;
+       std::string             m_json;
+       std::string             m_str;
 
-       void *          m_priv;
-       bool            m_ownership;
+       void *                  m_priv;
+       AnyPrivFinalizerFunc    m_privFinalizerFunc;
 
-       PrimitiveType   m_type;
+       PrimitiveType           m_type;
 };
 typedef DPL::SharedPtr<Any> AnyPtr;
 
index 18cfc79..5cc449c 100644 (file)
  * @brief       Implementation of the JSAttributeFilter class
  */
 
+#include "JSAttributeFilter.h"
+
 #include <string>
 #include <dpl/log/log.h>
 #include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "AttributeFilter.h"
-#include "FilterConverter.h"
-#include "JSAttributeFilter.h"
+#include <JSWebAPIException.h>
+#include <JSUtil.h>
+#include <ArgumentValidator.h>
 #include "AnyFactory.h"
 
 #define ATTRIBUTE_FILTER_CLASS_NAME "AttributeFilter"
@@ -84,9 +82,9 @@ JSStaticFunction JSAttributeFilter::m_functions[] =
 };
 
 JSClassRef JSAttributeFilter::getClassRef() {
-       if (!m_classRef) {
+       if (!m_classRef)
                m_classRef = JSClassCreate(&m_classInfo);
-       }
+
        return m_classRef;
 }
 
@@ -97,34 +95,36 @@ bool JSAttributeFilter::isObjectOfClass(JSContextRef context, JSValueRef value)
 
 AttributeFilterPtr JSAttributeFilter::getAttributeFilter(JSContextRef context, JSValueRef value)
 {
-       if (!isObjectOfClass(context, value)) {
+       if (!isObjectOfClass(context, value))
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
+       if (!object)
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSAttributeFilterPriv *priv = static_cast<JSAttributeFilterPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
+
        return priv->getObject();
 }
 
-JSObjectRef JSAttributeFilter::createJSObject(JSContextRef context, AttributeFilterPtr privateData, JSValueRef jsValueMatchValue)
+JSObjectRef JSAttributeFilter::createJSObject(JSContextRef context,
+               AttributeFilterPtr privateData,
+               JSValueRef jsValueMatchValue)
 {
        JSAttributeFilterPriv *priv = new JSAttributeFilterPriv(context, privateData);
        JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsObjectRef) {
+       if (NULL == jsObjectRef)
+       {
                LogError("object creation error");
                return NULL;
        }
 
-       FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context);
-
        const ScopedJSStringRef jsStrMatchValue(JSStringCreateWithUTF8CString(ATTRIBUTE_FILTER_ATTR_MATCH_VALUE));
 
-       JSObjectSetProperty(context, jsObjectRef, jsStrMatchValue.get(), jsValueMatchValue, kJSPropertyAttributeNone, NULL);
+       JSObjectSetProperty(context, jsObjectRef, jsStrMatchValue.get(),
+                       jsValueMatchValue, kJSPropertyAttributeNone, NULL);
 
        return jsObjectRef;
 }
@@ -137,85 +137,78 @@ JSObjectRef JSAttributeFilter::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsString = false;
-       bool js3rdParamIsValue = false;
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
-
-               if (argumentCount >= 2)
-               {
-                       if (JSValueIsString(context, arguments[1]))
-                               js2ndParamIsString = true;
-
-                       if (!js2ndParamIsString &&
-                                       !JSValueIsNull(context, arguments[1]) &&
-                                       !JSValueIsUndefined(context, arguments[1]))
-                               ThrowMsg(InvalidArgumentException, "2nd argument is not array.");
-               }
-
-               if (argumentCount >= 3)
-               {
-                       if (!JSValueIsUndefined(context, arguments[2]))
-                               js3rdParamIsValue = true;
-               }
-
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context);
-
        std::string attributeName;
        MatchFlag matchFlag;
        AnyPtr matchValue(NULL);
+       JSValueRef jsValueMatchValue = NULL;
 
-       Try {
-               attributeName = converter->toString(arguments[0]);
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+       ArgumentValidator validator(context, argumentCount, arguments);
+
+       try
+       {
+               attributeName = validator.toString(0, false);
+       }
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
-       Try {
-               if(js2ndParamIsString)
-                       matchFlag = converter->toMatchFlag(arguments[1]);
+       try
+       {
+               std::string matchFlagStr;
+               if(argumentCount < 2 ||
+                               JSValueIsUndefined(context, arguments[1]) ||
+                               JSValueIsNull(context, arguments[1]))
+                       matchFlagStr = "EXACTLY";
                else
-                       matchFlag = MATCH_EXACTLY;
+                       matchFlagStr = validator.toString(1, true);
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+               if(matchFlagStr == "EXACTLY")
+                       matchFlag = MATCH_EXACTLY;
+               else if(matchFlagStr == "FULLSTRING")
+                       matchFlag = MATCH_FULLSTRING;
+               else if(matchFlagStr == "CONTAINS")
+                       matchFlag = MATCH_CONTAINS;
+               else if(matchFlagStr == "STARTSWITH")
+                       matchFlag = MATCH_STARTSWITH;
+               else if(matchFlagStr == "ENDSWITH")
+                       matchFlag = MATCH_ENDSWITH;
+               else if(matchFlagStr == "EXISTS")
+                       matchFlag = MATCH_EXISTS;
+               else
+                       throw TypeMismatchException("Property is not valid FilterMatchFlag value");
+       }
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        matchValue = AnyFactory::createAnyEmpty(context);
 
-       AttributeFilterPtr attributeFilter(new AttributeFilter(attributeName, matchFlag, matchValue));
-
-       JSValueRef jsValueMatchValue = NULL;
-       if(js3rdParamIsValue)
+       if(argumentCount >= 3)
                jsValueMatchValue = arguments[2];
        else
                jsValueMatchValue = JSValueMakeUndefined(context);
 
+       AttributeFilterPtr attributeFilter(new AttributeFilter(attributeName, matchFlag, matchValue));
+
        JSObjectRef jsobject;
 
-       Try {
+       Try
+       {
                jsobject = createJSObject(context, attributeFilter, jsValueMatchValue);
-       } Catch(Exception) {
+       }
+       Catch(Exception)
+       {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(
+                               context, TypeMismatchException("Error occurred while creating object"));
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        return jsobject;
@@ -227,7 +220,8 @@ void JSAttributeFilter::Initialize(JSContextRef context, JSObjectRef object)
        {
                AttributeFilterPtr filter(new AttributeFilter("", MATCH_NONE, AnyPtr(NULL)));
                JSAttributeFilterPriv *priv = new JSAttributeFilterPriv(context, AttributeFilterPtr(filter));
-               if (!JSObjectSetPrivate(object, priv)) {
+               if (!JSObjectSetPrivate(object, priv))
+               {
                        delete priv;
                }
        }
@@ -249,13 +243,13 @@ AttributeFilterPtr JSAttributeFilter::getPrivData(JSObjectRef object)
 {
        LogDebug("entered");
        JSAttributeFilterPriv *priv = static_cast<JSAttributeFilterPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        AttributeFilterPtr result = priv->getObject();
-       if (!result) {
+       if (!result)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        return result;
 }
 
@@ -265,17 +259,17 @@ JSValueRef JSAttributeFilter::getAttributeName(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                AttributeFilterPtr attributeFilter = getPrivData(object);
-               return converter->toJSValueRef(attributeFilter->getAttributeName());
+               return JSUtil::toJSValueRef(context, attributeFilter->getAttributeName());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -285,21 +279,19 @@ bool JSAttributeFilter::setAttributeName(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                AttributeFilterPtr attributeFilter = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               attributeFilter->setAttributeName(converter->toString(value));
-               return true;
+               attributeFilter->setAttributeName(JSUtil::JSValueToString(context, value));
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 JSValueRef JSAttributeFilter::getMatchFlag(JSContextRef context,
@@ -308,17 +300,34 @@ JSValueRef JSAttributeFilter::getMatchFlag(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                AttributeFilterPtr attributeFilter = getPrivData(object);
-               return converter->toJSValueRef(attributeFilter->getMatchFlag());
+               MatchFlag matchFlag = attributeFilter->getMatchFlag();
+               std::string matchFlagStr;
+               if(matchFlag == MATCH_EXACTLY)
+                       matchFlagStr = "EXACTLY";
+               else if(matchFlag == MATCH_FULLSTRING)
+                       matchFlagStr = "FULLSTRING";
+               else if(matchFlag == MATCH_CONTAINS)
+                       matchFlagStr = "CONTAINS";
+               else if(matchFlag == MATCH_STARTSWITH)
+                       matchFlagStr = "STARTSWITH";
+               else if(matchFlag == MATCH_ENDSWITH)
+                       matchFlagStr = "ENDSWITH";
+               else if(matchFlag == MATCH_EXISTS)
+                       matchFlagStr = "EXISTS";
+               else
+                       matchFlagStr = "EXACTLY";
+
+               return JSUtil::toJSValueRef(context, matchFlagStr);
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -328,23 +337,39 @@ bool JSAttributeFilter::setMatchFlag(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                AttributeFilterPtr attributeFilter = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               attributeFilter->setMatchFlag(converter->toMatchFlag(value));
-               return true;
+
+               MatchFlag matchFlag;
+               std::string matchFlagStr = JSUtil::JSValueToString(context, value);
+
+               if(matchFlagStr == "EXACTLY")
+                       matchFlag = MATCH_EXACTLY;
+               else if(matchFlagStr == "FULLSTRING")
+                       matchFlag = MATCH_FULLSTRING;
+               else if(matchFlagStr == "CONTAINS")
+                       matchFlag = MATCH_CONTAINS;
+               else if(matchFlagStr == "STARTSWITH")
+                       matchFlag = MATCH_STARTSWITH;
+               else if(matchFlagStr == "ENDSWITH")
+                       matchFlag = MATCH_ENDSWITH;
+               else if(matchFlagStr == "EXISTS")
+                       matchFlag = MATCH_EXISTS;
+               else
+                       throw TypeMismatchException("Property is not valid FilterMatchFlag value");
+
+               attributeFilter->setMatchFlag(matchFlag);
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 } // Tizen
 } // DeviceAPI
-
index 9617023..59b099e 100644 (file)
  * @brief       Implementation of the JSAttributeRangeFilter class
  */
 
+#include "JSAttributeRangeFilter.h"
+
 #include <dpl/log/log.h>
 #include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "AttributeRangeFilter.h"
-#include "FilterConverter.h"
-#include "JSAttributeRangeFilter.h"
+#include <JSWebAPIException.h>
+#include <JSUtil.h>
+#include <ArgumentValidator.h>
 #include "AnyFactory.h"
 
 #define ATTRIBUTE_RANGE_FILTER_CLASS_NAME "AttributeRangeFilter"
@@ -82,9 +80,9 @@ JSStaticFunction JSAttributeRangeFilter::m_functions[] =
 };
 
 JSClassRef JSAttributeRangeFilter::getClassRef() {
-       if (!m_classRef) {
+       if (!m_classRef)
                m_classRef = JSClassCreate(&m_classInfo);
-       }
+
        return m_classRef;
 }
 
@@ -95,17 +93,17 @@ bool JSAttributeRangeFilter::isObjectOfClass(JSContextRef context, JSValueRef va
 
 AttributeRangeFilterPtr JSAttributeRangeFilter::getAttributeRangeFilter(JSContextRef context, JSValueRef value)
 {
-       if (!isObjectOfClass(context, value)) {
+       if (!isObjectOfClass(context, value))
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
+       if (!object)
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSAttributeRangeFilterPriv *priv = static_cast<JSAttributeRangeFilterPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
+
        return priv->getObject();
 }
 
@@ -116,13 +114,12 @@ JSObjectRef JSAttributeRangeFilter::createJSObject(JSContextRef context,
 {
        JSAttributeRangeFilterPriv *priv = new JSAttributeRangeFilterPriv(context, privateData);
        JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsObjectRef) {
+       if (NULL == jsObjectRef)
+       {
                LogError("object creation error");
                return NULL;
        }
 
-       FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context);
-
        const ScopedJSStringRef jsStrInitialValue(JSStringCreateWithUTF8CString(ATTRIBUTE_FILTER_ATTR_INITIAL_VALUE));
        const ScopedJSStringRef jsStrEndValue(JSStringCreateWithUTF8CString(ATTRIBUTE_FILTER_ATTR_END_VALUE));
 
@@ -140,75 +137,54 @@ JSObjectRef JSAttributeRangeFilter::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsValue = false;
-       bool js3rdParamIsValue = false;
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
-
-               // 2nd and 3rd argument can be any type.
-               if (argumentCount >= 2)
-               {
-                       if(!JSValueIsUndefined(context, arguments[1]))
-                               js2ndParamIsValue = true;
-               }
-
-               if (argumentCount >= 3)
-               {
-                       if(!JSValueIsUndefined(context, arguments[2]))
-                               js3rdParamIsValue = true;
-               }
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context);
-
        std::string attributeName;
        AnyPtr initialValue(NULL);
+       JSValueRef jsValueInitialValue = NULL;
        AnyPtr endValue(NULL);
+       JSValueRef jsValueEndValue = NULL;
 
-       Try {
-               attributeName = converter->toString(arguments[0]);
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+       ArgumentValidator validator(context, argumentCount, arguments);
+
+       try
+       {
+               attributeName = validator.toString(0, false);
+       }
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        initialValue = AnyFactory::createAnyEmpty(context);
-       endValue = AnyFactory::createAnyEmpty(context);
-
-       AttributeRangeFilterPtr attributeRangeFilter(new AttributeRangeFilter(attributeName, initialValue, endValue));
 
-       JSValueRef jsValueInitialValue = NULL;
-       if(js2ndParamIsValue)
+       if(argumentCount >= 2)
                jsValueInitialValue = arguments[1];
        else
                jsValueInitialValue = JSValueMakeUndefined(context);
 
-       JSValueRef jsValueEndValue = NULL;
-       if(js3rdParamIsValue)
+       endValue = AnyFactory::createAnyEmpty(context);
+
+       if(argumentCount >= 3)
                jsValueEndValue = arguments[2];
        else
                jsValueEndValue = JSValueMakeUndefined(context);
 
+       AttributeRangeFilterPtr attributeRangeFilter(new AttributeRangeFilter(attributeName, initialValue, endValue));
+
        JSObjectRef jsobject;
 
-       Try {
+       Try
+       {
                jsobject = createJSObject(context, attributeRangeFilter, jsValueInitialValue, jsValueEndValue);
-       } Catch(Exception) {
+       }
+       Catch(Exception)
+       {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(
+                               context, TypeMismatchException("Error occurred while creating object"));
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        return jsobject;
@@ -219,8 +195,10 @@ void JSAttributeRangeFilter::Initialize(JSContextRef context, JSObjectRef object
        if (!JSObjectGetPrivate(object))
        {
                AttributeRangeFilterPtr filter(new AttributeRangeFilter("", AnyPtr(NULL), AnyPtr(NULL)));
-               JSAttributeRangeFilterPriv *priv = new JSAttributeRangeFilterPriv(context, AttributeRangeFilterPtr(filter));
-               if (!JSObjectSetPrivate(object, priv)) {
+               JSAttributeRangeFilterPriv *priv =
+                               new JSAttributeRangeFilterPriv(context, AttributeRangeFilterPtr(filter));
+               if (!JSObjectSetPrivate(object, priv))
+               {
                        delete priv;
                }
        }
@@ -242,13 +220,13 @@ AttributeRangeFilterPtr JSAttributeRangeFilter::getPrivData(JSObjectRef object)
 {
        LogDebug("entered");
        JSAttributeRangeFilterPriv *priv = static_cast<JSAttributeRangeFilterPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        AttributeRangeFilterPtr result = priv->getObject();
-       if (!result) {
+       if (!result)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        return result;
 }
 
@@ -258,17 +236,17 @@ JSValueRef JSAttributeRangeFilter::getAttributeName(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
-               return converter->toJSValueRef(attributeRangeFilter->getAttributeName());
+               return JSUtil::toJSValueRef(context, attributeRangeFilter->getAttributeName());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -278,23 +256,20 @@ bool JSAttributeRangeFilter::setAttributeName(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               attributeRangeFilter->setAttributeName(converter->toString(value));
-               return true;
+               attributeRangeFilter->setAttributeName(JSUtil::JSValueToString(context, value));
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 } // Tizen
 } // DeviceAPI
-
index 80afe13..f4920b8 100644 (file)
  * @brief       Implementation of the JSCompositeFilter class
  */
 
+#include "JSCompositeFilter.h"
+
 #include <string>
 #include <dpl/log/log.h>
 #include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "CompositeFilter.h"
-#include "FilterConverter.h"
-#include "JSCompositeFilter.h"
+#include <JSWebAPIException.h>
+#include <JSUtil.h>
+#include <ArgumentValidator.h>
 
 #define ATTRIBUTE_FILTER_CLASS_NAME "CompositeFilter"
 
@@ -72,7 +70,6 @@ JSClassDefinition JSCompositeFilter::m_classInfo =
 
 JSStaticValue JSCompositeFilter::m_property[] = {
        { ATTRIBUTE_FILTER_ATTR_TYPE, getType, setType, kJSPropertyAttributeNone },
-       //{ ATTRIBUTE_FILTER_ATTR_FILTERS, getFilters, setFilters, kJSPropertyAttributeNone },
        { 0, 0, 0, 0 }
 };
 
@@ -95,25 +92,28 @@ bool JSCompositeFilter::isObjectOfClass(JSContextRef context, JSValueRef value)
 
 CompositeFilterPtr JSCompositeFilter::getCompositeFilter(JSContextRef context, JSValueRef value)
 {
-       if (!isObjectOfClass(context, value)) {
+       if (!isObjectOfClass(context, value))
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
+       if (!object)
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSCompositeFilterPriv *priv = static_cast<JSCompositeFilterPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
+
        return priv->getObject();
 }
 
-JSObjectRef JSCompositeFilter::createJSObject(JSContextRef context, CompositeFilterPtr privateData, JSValueRef jsValueFilters)
+JSObjectRef JSCompositeFilter::createJSObject(JSContextRef context,
+               CompositeFilterPtr privateData,
+               JSValueRef jsValueFilters)
 {
        JSCompositeFilterPriv *priv = new JSCompositeFilterPriv(context, privateData);
        JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsObjectRef) {
+       if (NULL == jsObjectRef)
+       {
                LogError("object creation error");
                return NULL;
        }
@@ -133,62 +133,62 @@ JSObjectRef JSCompositeFilter::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsArray = false;
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
-
-               if (argumentCount >= 2)
-               {
-                       if (JSIsArrayValue(context, arguments[1]))
-                               js2ndParamIsArray = true;
+       FilterType type;
+       JSValueRef jsValueFilters = NULL;
 
-                       if (!js2ndParamIsArray &&
-                                       !JSValueIsNull(context, arguments[1]) &&
-                                       !JSValueIsUndefined(context, arguments[1]))
-                               ThrowMsg(InvalidArgumentException, "2nd argument is not array.");
-               }
+       ArgumentValidator validator(context, argumentCount, arguments);
 
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+       try
+       {
+               std::string typeStr = validator.toString(0, false);
+
+               if(typeStr == "UNION")
+                       type = UNION_FILTER;
+               else if(typeStr == "INTERSECTION")
+                       type = INTERSECTION_FILTER;
+               else
+                       throw TypeMismatchException("Property is not valid CompositeFilterType value");
        }
-
-       FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context);
-
-       FilterType type;
-       FilterArrayPtr filters(NULL);
-
-       Try {
-               type = converter->toCompositeFilterType(arguments[0]);
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
-       JSValueRef jsValueFilters = NULL;
-       if(js2ndParamIsArray)
-               jsValueFilters = arguments[1];
-       else
-               jsValueFilters = JSCreateArrayObject(context, 0, NULL);
+       try
+       {
+               if(argumentCount < 2 ||
+                               JSValueIsUndefined(context, arguments[1]) ||
+                               JSValueIsNull(context, arguments[1]))
+                       jsValueFilters = JSCreateArrayObject(context, 0, NULL);
+               else if(JSIsArrayValue(context, arguments[1]))
+                       jsValueFilters = arguments[1];
+               else
+                       throw TypeMismatchException("Property is not valid Array value");
+       }
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
+       }
 
        CompositeFilterPtr compositeFilter(new CompositeFilter(type, FilterArrayPtr(new FilterArray())));
 
        JSObjectRef jsobject;
 
-       Try {
+       Try
+       {
                jsobject = createJSObject(context, compositeFilter, jsValueFilters);
-       } Catch(Exception) {
+       }
+       Catch(Exception)
+       {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(
+                               context, TypeMismatchException("Error occurred while creating object"));
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        return jsobject;
@@ -200,7 +200,8 @@ void JSCompositeFilter::Initialize(JSContextRef context, JSObjectRef object)
        {
                CompositeFilterPtr filter(new CompositeFilter(UNION_FILTER, FilterArrayPtr(NULL)));
                JSCompositeFilterPriv *priv = new JSCompositeFilterPriv(context, CompositeFilterPtr(filter));
-               if (!JSObjectSetPrivate(object, priv)) {
+               if (!JSObjectSetPrivate(object, priv))
+               {
                        delete priv;
                }
        }
@@ -222,64 +223,14 @@ CompositeFilterPtr JSCompositeFilter::getPrivData(JSObjectRef object)
 {
        LogDebug("entered");
        JSCompositeFilterPriv *priv = static_cast<JSCompositeFilterPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        CompositeFilterPtr result = priv->getObject();
-       if (!result) {
+       if (!result)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
-       return result;
-}
-
-bool JSCompositeFilter::hasProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName)
-{
-       LogDebug("entered");
-       Try
-       {
-               CompositeFilterPtr compositeFilter = getPrivData(object);
-
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               std::string name = converter->toString(propertyName);
-
-               if(name == ATTRIBUTE_FILTER_ATTR_FILTERS ||
-                               name == ATTRIBUTE_FILTER_ATTR_TYPE )
-                       return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to get incorrect value");
-               return false;
-       }
-
-       return false;
-}
-
-JSValueRef JSCompositeFilter::getProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       LogDebug("entered");
-       Try
-       {
-               CompositeFilterPtr compositeFilter = getPrivData(object);
-
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               std::string name = converter->toString(propertyName);
-               if(name == ATTRIBUTE_FILTER_ATTR_FILTERS)
-                       return NULL;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to get incorrect value");
-       }
 
-       return JSValueMakeUndefined(context);
+       return result;
 }
 
 bool JSCompositeFilter::setProperty(JSContextRef context,
@@ -289,85 +240,53 @@ bool JSCompositeFilter::setProperty(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
                CompositeFilterPtr compositeFilter = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               std::string name = converter->toString(propertyName);
+               std::string name = JSUtil::JSStringToString(context, propertyName);
                if(name == ATTRIBUTE_FILTER_ATTR_FILTERS)
                {
                        if(!JSIsArrayValue(context, value))
                                return true;
 
                        return false;
-//                     const ScopedJSStringRef jsStrFilters(
-//                                     JSStringCreateWithUTF8CString(ATTRIBUTE_FILTER_ATTR_FILTERS));
-//
-//                     JSObjectSetProperty(context, object, jsStrFilters.get(),
-//                                     value, kJSPropertyAttributeNone, NULL);
-//
-//                     return true;
                }
        }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to set incorrect value");
-       }
-
-       return false;
-}
-
-bool JSCompositeFilter::deleteProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef propertyName,
-               JSValueRef* exception)
-{
-       LogDebug("entered");
-       Try
-       {
-               CompositeFilterPtr compositeFilter = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               std::string name = converter->toString(propertyName);
-               if(name == ATTRIBUTE_FILTER_ATTR_FILTERS)
-                       return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
        return false;
 }
 
-void JSCompositeFilter::getPropertyNames(JSContextRef context,
-               JSObjectRef object,
-               JSPropertyNameAccumulatorRef propertyNames)
-{
-       LogDebug("entered");
-
-       const ScopedJSStringRef jsStrFilters(JSStringCreateWithUTF8CString(ATTRIBUTE_FILTER_ATTR_FILTERS));
-       JSPropertyNameAccumulatorAddName(propertyNames, jsStrFilters.get());
-}
-
 JSValueRef JSCompositeFilter::getType(JSContextRef context,
                JSObjectRef object,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                CompositeFilterPtr compositeFilter = getPrivData(object);
-               return converter->toJSValueRef(compositeFilter->getFilterType());
+               FilterType type = compositeFilter->getFilterType();
+               std::string typeStr;
+               if(type == UNION_FILTER)
+                       typeStr = "UNION";
+               else if(type == INTERSECTION_FILTER)
+                       typeStr = "INTERSECTION";
+               else
+                       typeStr = "UNION";
+
+               return JSUtil::toJSValueRef(context, typeStr);
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -377,23 +296,31 @@ bool JSCompositeFilter::setType(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                CompositeFilterPtr compositeFilter = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               compositeFilter->setFilterType(converter->toCompositeFilterType(value));
-               return true;
+
+               FilterType type;
+               std::string typeStr = JSUtil::JSValueToString(context, value);
+
+               if(typeStr == "UNION")
+                       type = UNION_FILTER;
+               else if(typeStr == "INTERSECTION")
+                       type = INTERSECTION_FILTER;
+               else
+                       throw TypeMismatchException("Property is not valid CompositeFilterType value");
+
+               compositeFilter->setFilterType(type);
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 } // Tizen
 } // DeviceAPI
-
index 440f501..68cef4d 100644 (file)
@@ -88,30 +88,12 @@ private:
 
        static DeviceAPI::Tizen::CompositeFilterPtr getPrivData(JSObjectRef object);
 
-       static bool hasProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName);
-
-       static JSValueRef getProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
        static bool setProperty(JSContextRef context,
                        JSObjectRef object,
                        JSStringRef propertyName,
                        JSValueRef value,
                        JSValueRef* exception);
 
-       static bool deleteProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef propertyName,
-                       JSValueRef* exception);
-
-       static void getPropertyNames(JSContextRef context,
-                       JSObjectRef object,
-                       JSPropertyNameAccumulatorRef propertyNames);
-
        static JSValueRef getType(JSContextRef context,
                        JSObjectRef object,
                        JSStringRef propertyName,
index a503725..664095d 100644 (file)
  * @brief       Implementation of the JSSimpleCoordinates class
  */
 
+#include "JSSimpleCoordinates.h"
+
 #include <string>
 #include <dpl/log/log.h>
 #include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "SimpleCoordinates.h"
-#include "FilterConverter.h"
-#include "JSSimpleCoordinates.h"
+#include <JSWebAPIException.h>
+#include <JSUtil.h>
+#include <ArgumentValidator.h>
 
 #define ATTRIBUTE_FILTER_CLASS_NAME "SimpleCoordinates"
 
@@ -93,17 +91,17 @@ bool JSSimpleCoordinates::isObjectOfClass(JSContextRef context, JSValueRef value
 
 SimpleCoordinatesPtr JSSimpleCoordinates::getSimpleCoordinates(JSContextRef context, JSValueRef value)
 {
-       if (!isObjectOfClass(context, value)) {
+       if (!isObjectOfClass(context, value))
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
+       if (!object)
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSSimpleCoordinatesPriv *priv = static_cast<JSSimpleCoordinatesPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
+
        return priv->getObject();
 }
 
@@ -111,7 +109,8 @@ JSObjectRef JSSimpleCoordinates::createJSObject(JSContextRef context, SimpleCoor
 {
        JSSimpleCoordinatesPriv *priv = new JSSimpleCoordinatesPriv(context, privateData);
        JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsObjectRef) {
+       if (NULL == jsObjectRef)
+       {
                LogError("object creation error");
                return NULL;
        }
@@ -126,54 +125,38 @@ JSObjectRef JSSimpleCoordinates::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount < 2)
-                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
-
-               if (!JSValueIsNumber(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
-
-               if (!JSValueIsNumber(context, arguments[1]))
-                       ThrowMsg(InvalidArgumentException, "2nd argument is not string.");
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context);
+       ArgumentValidator validator(context, argumentCount, arguments);
 
        double latitude;
        double longitude;
 
-       Try {
-               latitude = converter->toDouble(arguments[0]);
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+       try
+       {
+               latitude = validator.toDouble(0, false);
+               longitude = validator.toDouble(1, false);
        }
-
-       Try {
-               longitude = converter->toDouble(arguments[1]);
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        SimpleCoordinatesPtr simpleCoordinates(new SimpleCoordinates(latitude, longitude));
 
        JSObjectRef jsobject;
 
-       Try {
+       Try
+       {
                jsobject = createJSObject(context, simpleCoordinates);
-       } Catch(Exception) {
+       }
+       Catch(Exception)
+       {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(
+                               context, TypeMismatchException("Error occurred while creating object"));
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        return jsobject;
@@ -185,7 +168,8 @@ void JSSimpleCoordinates::Initialize(JSContextRef context, JSObjectRef object)
        {
                SimpleCoordinatesPtr coord(new SimpleCoordinates(0.0, 0.0));
                JSSimpleCoordinatesPriv *priv = new JSSimpleCoordinatesPriv(context, SimpleCoordinatesPtr(coord));
-               if (!JSObjectSetPrivate(object, priv)) {
+               if (!JSObjectSetPrivate(object, priv))
+               {
                        delete priv;
                }
        }
@@ -207,13 +191,13 @@ SimpleCoordinatesPtr JSSimpleCoordinates::getPrivData(JSObjectRef object)
 {
        LogDebug("entered");
        JSSimpleCoordinatesPriv *priv = static_cast<JSSimpleCoordinatesPriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        SimpleCoordinatesPtr result = priv->getObject();
-       if (!result) {
+       if (!result)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        return result;
 }
 
@@ -223,17 +207,17 @@ JSValueRef JSSimpleCoordinates::getLatitude(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
-               return converter->toJSValueRef(simpleCoordinates->getLatitude());
+               return JSUtil::toJSValueRef(context, simpleCoordinates->getLatitude());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -243,21 +227,19 @@ bool JSSimpleCoordinates::setLatitude(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               simpleCoordinates->setLatitude(converter->toDouble(value));
-               return true;
+               simpleCoordinates->setLatitude(JSUtil::JSValueToDouble(context, value));
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 JSValueRef JSSimpleCoordinates::getLongitude(JSContextRef context,
@@ -266,17 +248,17 @@ JSValueRef JSSimpleCoordinates::getLongitude(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
-               return converter->toJSValueRef(simpleCoordinates->getLongitude());
+               return JSUtil::toJSValueRef(context, simpleCoordinates->getLongitude());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -286,23 +268,20 @@ bool JSSimpleCoordinates::setLongitude(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               simpleCoordinates->setLongitude(converter->toDouble(value));
-               return true;
+               simpleCoordinates->setLongitude(JSUtil::JSValueToDouble(context, value));
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 } // Tizen
 } // DeviceAPI
-
index 75c2277..28f878f 100644 (file)
  * @brief       Implementation of the JSSortMode class
  */
 
+#include "JSSortMode.h"
+
 #include <string>
 #include <dpl/log/log.h>
 #include <dpl/shared_ptr.h>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "SortMode.h"
-#include "FilterConverter.h"
-#include "JSSortMode.h"
+#include <JSWebAPIException.h>
+#include <JSUtil.h>
+#include <ArgumentValidator.h>
 
 #define ATTRIBUTE_FILTER_CLASS_NAME "SortMode"
 
@@ -79,10 +77,11 @@ JSStaticFunction JSSortMode::m_functions[] =
        { 0, 0, 0 }
 };
 
-JSClassRef JSSortMode::getClassRef() {
-       if (!m_classRef) {
+JSClassRef JSSortMode::getClassRef()
+{
+       if (!m_classRef)
                m_classRef = JSClassCreate(&m_classInfo);
-       }
+
        return m_classRef;
 }
 
@@ -93,17 +92,17 @@ bool JSSortMode::isObjectOfClass(JSContextRef context, JSValueRef value)
 
 SortModePtr JSSortMode::getSortMode(JSContextRef context, JSValueRef value)
 {
-       if (!isObjectOfClass(context, value)) {
+       if (!isObjectOfClass(context, value))
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSObjectRef object = JSValueToObject(context, value, NULL);
-       if (!object) {
+       if (!object)
                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
-       }
+
        JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                Throw(WrtDeviceApis::Commons::NullPointerException);
-       }
+
        return priv->getObject();
 }
 
@@ -126,68 +125,61 @@ JSObjectRef JSSortMode::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-       bool js2ndParamIsString = false;
-
-       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
-       Try {
-               if (argumentCount < 1)
-                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
-
-               if (!JSValueIsString(context, arguments[0]))
-                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
-
-               if (argumentCount >= 2)
-               {
-                       if (JSValueIsString(context, arguments[1]))
-                               js2ndParamIsString = true;
-
-                       if (!js2ndParamIsString &&
-                                       !JSValueIsNull(context, arguments[1]) &&
-                                       !JSValueIsUndefined(context, arguments[1]))
-                               ThrowMsg(InvalidArgumentException, "2nd argument is not string.");
-               }
-
-       } Catch(Exception ) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
-       }
-
-       FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context);
-
        std::string attributeName;
        SortOrder sortOrder;
 
-       Try {
-               attributeName = converter->toString(arguments[0]);
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+       ArgumentValidator validator(context, argumentCount, arguments);
+
+       try
+       {
+               attributeName = validator.toString(0, false);
+       }
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
-       Try {
-               if(js2ndParamIsString)
-                       sortOrder = converter->toSortOrder(arguments[1]);
+       try
+       {
+               std::string sortOrderStr;
+               if(argumentCount < 2 ||
+                               JSValueIsUndefined(context, arguments[1]) ||
+                               JSValueIsNull(context, arguments[1]))
+                       sortOrderStr = "ASC";
                else
-                       sortOrder = ASCENDING_SORT_ORDER;
+                       sortOrderStr = validator.toString(1, true);
 
-       } Catch(Exception) {
-               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+               if(sortOrderStr == "ASC")
+                       sortOrder = ASCENDING_SORT_ORDER;
+               else if(sortOrderStr == "DESC")
+                       sortOrder = DESCENDING_SORT_ORDER;
+               else
+                       throw TypeMismatchException("Property is not valid SortModeOrder value");
+       }
+       catch(BasePlatformException &e)
+       {
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(context, e);
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        SortModePtr sortMode(new SortMode(attributeName, sortOrder));
 
        JSObjectRef jsobject;
 
-       Try {
+       Try
+       {
                jsobject = createJSObject(context, sortMode);
-       } Catch(Exception) {
+       }
+       Catch(Exception)
+       {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
-               return NULL;
+               JSObjectRef exceptionObj = JSWebAPIException::makeJSWebAPIException(
+                               context, TypeMismatchException("Error occurred while creating object"));
+               *exception = exceptionObj;
+               return exceptionObj;
        }
 
        return jsobject;
@@ -199,7 +191,8 @@ void JSSortMode::Initialize(JSContextRef context, JSObjectRef object)
        {
                SortModePtr sortMode(new SortMode(""));
                JSSortModePriv *priv = new JSSortModePriv(context, SortModePtr(sortMode));
-               if (!JSObjectSetPrivate(object, priv)) {
+               if (!JSObjectSetPrivate(object, priv))
+               {
                        delete priv;
                }
        }
@@ -221,13 +214,13 @@ SortModePtr JSSortMode::getPrivData(JSObjectRef object)
 {
        LogDebug("entered");
        JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(object));
-       if (!priv) {
+       if (!priv)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        SortModePtr result = priv->getObject();
-       if (!result) {
+       if (!result)
                ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-       }
+
        return result;
 }
 
@@ -237,17 +230,17 @@ JSValueRef JSSortMode::getAttributeName(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                SortModePtr sortMode = getPrivData(object);
-               return converter->toJSValueRef(sortMode->getAttributeName());
+               return JSUtil::toJSValueRef(context, sortMode->getAttributeName());
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -257,21 +250,19 @@ bool JSSortMode::setAttributeName(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                SortModePtr sortMode = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               sortMode->setAttributeName(converter->toString(value));
-               return true;
+               sortMode->setAttributeName(JSUtil::JSValueToString(context, value));
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 JSValueRef JSSortMode::getOrder(JSContextRef context,
@@ -280,17 +271,26 @@ JSValueRef JSSortMode::getOrder(JSContextRef context,
                JSValueRef* exception)
 {
        LogDebug("entered");
-       Try
+
+       try
        {
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
                SortModePtr sortMode = getPrivData(object);
-               return converter->toJSValueRef(sortMode->getOrder());
+               SortOrder order = sortMode->getOrder();
+               std::string orderStr;
+               if(order == ASCENDING_SORT_ORDER)
+                       orderStr = "ASC";
+               else if(order == DESCENDING_SORT_ORDER)
+                       orderStr = "DESC";
+               else
+                       orderStr = "ASC";
+
+               return JSUtil::toJSValueRef(context, orderStr);
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to get incorrect value");
+               LogWarning("trying to get incorrect value [" << e.getName() << "] " << e.getMessage());
        }
+
        return JSValueMakeUndefined(context);
 }
 
@@ -300,21 +300,30 @@ bool JSSortMode::setOrder(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       Try
+       LogDebug("entered");
+
+       try
        {
                SortModePtr sortMode = getPrivData(object);
-               FilterConverterFactory::ConverterType converter =
-                               FilterConverterFactory::getConverter(context);
-               sortMode->setOrder(converter->toSortOrder(value));
-               return true;
+
+               SortOrder order;
+               std::string orderStr = JSUtil::JSValueToString(context, value);
+
+               if(orderStr == "ASC")
+                       order = ASCENDING_SORT_ORDER;
+               else if(orderStr == "DESC")
+                       order = DESCENDING_SORT_ORDER;
+               else
+                       throw TypeMismatchException("Property is not valid SortModeOrder value");
+
+               sortMode->setOrder(order);
        }
-       Catch(WrtDeviceApis::Commons::Exception)
+       catch(BasePlatformException &e)
        {
-               LogWarning("trying to set incorrect value");
+               LogWarning("trying to set incorrect value [" << e.getName() << "] " << e.getMessage());
        }
 
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       return true;
 }
 
 } // Tizen